summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/damon/sysfs.py
diff options
context:
space:
mode:
authorSeongJae Park <sj@kernel.org>2025-06-28 09:04:25 -0700
committerAndrew Morton <akpm@linux-foundation.org>2025-07-13 16:38:20 -0700
commit4ece01897627ddeefcede4ac709cd99763994dc4 (patch)
tree69f0934001ff747c110b4fbb3f34c4cedc0a8932 /tools/testing/selftests/damon/sysfs.py
parente227472ebf00b6b5187915826c41258c472edb0a (diff)
selftests/damon: add python and drgn-based DAMON sysfs test
Add a python-written DAMON sysfs functionality selftest. It sets DAMON parameters using Python module _damon_sysfs, reads updated kernel internal DAMON status and parameters using a 'drgn' script, namely drgn_dump_damon_status.py, and compare if the resulted DAMON internal status is as expected. The test is very minimum at the moment. Link: https://lkml.kernel.org/r/20250628160428.53115-4-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests/damon/sysfs.py')
-rwxr-xr-xtools/testing/selftests/damon/sysfs.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
new file mode 100755
index 000000000000..4ff99db0d247
--- /dev/null
+++ b/tools/testing/selftests/damon/sysfs.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import json
+import os
+import subprocess
+
+import _damon_sysfs
+
+def dump_damon_status_dict(pid):
+ 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, 'drgn fail'
+ 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()])])
+ err = kdamonds.start()
+ if err is not None:
+ print('kdamond start failed: %s' % err)
+ exit(1)
+
+ status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid)
+ if err is not None:
+ print(err)
+ exit(1)
+
+ if len(status['contexts']) != 1:
+ print('number of contexts: %d' % len(status['contexts']))
+ exit(1)
+ kdamonds.stop()
+
+if __name__ == '__main__':
+ main()