selftests/damon: test no-op commit broke DAMON status
Subsystems (3)
PATCH v3 1/1 selftests/damon: test no-op commit broke DAMON status
Add test to verify that DAMON status is not changed after a no-op commit.
--- tools/testing/selftests/damon/Makefile | 1 + .../damon/sysfs_no_op_commit_break.py | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 tools/testing/selftests/damon/sysfs_no_op_commit_break.py
tools/testing/selftests/damon/Makefile +1 -0
@@ -17,6 +17,7 @@ TEST_PROGS += reclaim.sh lru_sort.sh TEST_PROGS += sysfs_update_removed_scheme_dir.sh TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py TEST_PROGS += sysfs_memcg_path_leak.sh +TEST_PROGS += sysfs_no_op_commit_break.py EXTRA_CLEAN = __pycache__
tools/testing/selftests/damon/sysfs_no_op_commit_break.py new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 6 lines · Sang-Heon Jeon
Add test to verify that DAMON status is not changed after a no-op commit.
Signed-off-by Sang-Heon Jeon <[email protected]>---
I just forgot to add change logs.
Changes from v1 [1]:
1. Fix code and commit message style.
2. Merge patch set into one patch.
3. Add fixes and cc section for backporting.
Changes from v2 [2]:
1. Separate the patch into two parts(code modifications and tests) And this is part of test
2. Improve warning message on dump failure.
[1] https://lore.kernel.org/damon/[email protected]/
[2] https://lore.kernel.org/damon/[email protected]/
Quoted 98 lines
tools/testing/selftests/damon/Makefile | 1 + .../damon/sysfs_no_op_commit_break.py | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 tools/testing/selftests/damon/sysfs_no_op_commit_break.pytools/testing/selftests/damon/Makefile +1
-0@@ -17,6 +17,7 @@ TEST_PROGS += reclaim.sh lru_sort.sh TEST_PROGS += sysfs_update_removed_scheme_dir.sh TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py TEST_PROGS += sysfs_memcg_path_leak.sh +TEST_PROGS += sysfs_no_op_commit_break.py EXTRA_CLEAN = __pycache__tools/testing/selftests/damon/sysfs_no_op_commit_break.py new file +72
-1@@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import json +import os +import subprocess +import sys + +import _damon_sysfs + +def dump_damon_status_dict(pid): + try: + subprocess.check_output(['which', 'drgn'], stderr=subprocess.DEVNULL) + except: + return None, 'drgn not found' + file_dir = os.path.dirname(os.path.abspath(__file__)) + dump_script = os.path.join(file_dir, 'drgn_dump_damon_status.py') + rc = subprocess.call(['drgn', dump_script, pid, 'damon_dump_output'], + stderr=subprocess.DEVNULL) + + if rc != 0: + return None, f'drgn fail: return code({rc})' + try: + with open('damon_dump_output', 'r') as f: + return json.load(f), None + except Exception as e: + return None, 'json.load fail (%s)' % e + +def main(): + kdamonds = _damon_sysfs.Kdamonds( + [_damon_sysfs.Kdamond( + contexts=[_damon_sysfs.DamonCtx( + schemes=[_damon_sysfs.Damos( + ops_filters=[ + _damon_sysfs.DamosFilter( + type_='anon', + matching=True, + allow=True, + ) + ] + )], + )])] + ) + + err = kdamonds.start() + if err is not None: + print('kdamond start failed: %s' % err) + exit(1) + + before_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('before-commit status dump failed: %s' % err) + exit(1) + + kdamonds.kdamonds[0].commit() + + after_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('after-commit status dump failed: %s' % err) + exit(1) + + if before_commit_status != after_commit_status: + print(f'before: {json.dump(before_commit_status, indent=2)}') + print(f'after: {json.dump(after_commit_status, indent=2)}') + exit(1) + + kdamonds.stop() + +if __name__ == '__main__': + main() --2.43.0
+ Andrew
Quoted 4 lines · On Sun, 10 Aug 2025 21:43:54 +0900 Sang-Heon Jeon <[email protected]> wrote:
Add test to verify that DAMON status is not changed after a no-op commit.
Signed-off-by Sang-Heon Jeon <[email protected]>
Andrew, please note that this patch should be applied _after_ Sang-Heon's other fix[1] titled "mm/damon/core: fix commit_ops_filters by using correct nth function". Otherwise, selftest will fail until the fix is applied, and hence bisections could be distracted.
[1] https://lore.kernel.org/[email protected]
Thanks,
SJ
[...]