Skip to contentSkip to conversation

selftests/damon: fix memcg_path staging handling

PATCH New SJ Park 1 participant 3 messages Jun 29

Subsystems (3)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

v5 cover selftests/damon: fix memcg_path staging handling

Fix a bug in _damon_sysfs.py for damos_filter memcg_path setup, and add a test case of it in sysfs.py.

Changes from v4:
- v4: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes from v3:
- v3: https://lore.kernel.org/[email protected]
- call stop() for cleanup without checking its return value
Changes from v2:
- v2: https://lore.kernel.org/4CDA28DC581FDCF8+20260529090845.1696845-1-niecheng1@uniontech.com
- configure memcg filter before start(), remove commit(), ignore
start() failure, verify memcg_path staging readback only
- use print-style error messages as suggested
Changes from v1:
- v1: https://lore.kernel.org/406BD1BA0F6AE326+20260528081039.1192194-3-niecheng1@uniontech.com
- unknown.

Cheng Nie (2):
selftests/damon/_damon_sysfs.py: fix memcg_path assignment selftests/damon/sysfs.py: validate memcg_path staging readback

 tools/testing/selftests/damon/_damon_sysfs.py |  2 +-
 tools/testing/selftests/damon/sysfs.py        | 31 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

base-commit: 544856bcdccf456fc27f85e5d5b0a49f7b8e6019

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v5 1/2 selftests/damon/_damon_sysfs.py: fix memcg_path assignment

From: Cheng Nie <[email protected]>

DamosFilter stores memcg_path for sysfs staging, but the constructor assigns it with a trailing comma and therefore turns it into a tuple.

Fix the assignment so memcg_path is stored as the intended string. This makes memcg filter staging and follow-up validation use the written path correctly.

---
 tools/testing/selftests/damon/_damon_sysfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/damon/_damon_sysfs.py +1 -1
index f6127081dfb2e..c197ab99bcc0a 100644
@@ -271,7 +271,7 @@ class DamosFilter:
         self.type_ = type_
         self.matching = matching
         self.allow = allow
-        self.memcg_path = memcg_path,
+        self.memcg_path = memcg_path
         self.addr_start = addr_start
         self.addr_end = addr_end
         self.target_idx = target_idx
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH v5 2/2 selftests/damon/sysfs.py: validate memcg_path staging readback

In reply to SJ Park

From: Cheng Nie <[email protected]>

Add a dedicated test at the end of main() that stages memcg_path via sysfs and verifies its readback. Configure the memcg filter before start(), do not call commit(), and ignore start() failures so the test does not depend on CONFIG_MEMCG or cgroup layout. Call stop() for cleanup without checking its return value.

---
 tools/testing/selftests/damon/sysfs.py | 31 ++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/testing/selftests/damon/sysfs.py +31 -0
index 99412f0d31f37..3ffa054b63867 100755
@@ -250,6 +250,35 @@ def assert_ctxs_committed(kdamonds):
             if ctx in ctxs_paused_for_dump:
                 ctx.pause = False
 
+def test_memcg_filter_memcg_path_staging():
+    global kdamonds
+    memcg_filter = _damon_sysfs.DamosFilter(
+            type_='memcg', matching=True, allow=True, memcg_path='/')
+    kdamonds = _damon_sysfs.Kdamonds(
+            [_damon_sysfs.Kdamond(
+                contexts=[_damon_sysfs.DamonCtx(
+                    targets=[_damon_sysfs.DamonTarget(pid=-1)],
+                    schemes=[_damon_sysfs.Damos(
+                        ops_filters=[memcg_filter])],
+                    )])])
+    kdamonds.start()
+
+    shown, rd_err = _damon_sysfs.read_file(
+            os.path.join(memcg_filter.sysfs_dir(), 'memcg_path'))
+    if rd_err is not None:
+        print('memcg_path staging: sysfs read (%s)' % rd_err)
+        kdamonds.stop()
+        exit(1)
+    if shown.rstrip('\n') != memcg_filter.memcg_path:
+        print('memcg_path staging: memcg_path readback '
+              '(shown=%s, expected=%s)' %
+              (shown.rstrip('\n'), memcg_filter.memcg_path))
+        kdamonds.stop()
+        exit(1)
+
+    kdamonds.stop()
+    kdamonds = None
+
 def main():
     global kdamonds
     kdamonds = _damon_sysfs.Kdamonds(
@@ -356,5 +385,7 @@ def main():
     assert_ctxs_committed(kdamonds)
     kdamonds.stop()
 
+    test_memcg_filter_memcg_path_staging()
+
 if __name__ == '__main__':
     main()
Signature · 1 line
2.47.3