Skip to contentSkip to conversation

selftests/damon/_damon_sysfs.py: fix memcg_path assignment

PATCH Superseded Cheng Nie 2 participants 5 messages Jun 1 1 message not in the archive

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Cheng Nie

author
#1 lore raw

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

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 8b12cc048440..43075892215e 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.51.0
author
#2 lore raw

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

In reply to a message not in the archive

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 8b12cc048440..43075892215e 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.51.0
author
#3 lore raw

Hi SJ,

Sorry for the noise. This patch email was sent by mistake with incorrect send-email settings (wrong To and In-Reply-To). Please ignore this message and any other duplicate v3 patch emails outside the cover thread below.

The correct v3 series is here:

https://lore.kernel.org/damon/[email protected]/T/

Please use the latest [PATCH v3 1/2] and [PATCH v3 2/2] in that thread.

Sorry for the confusion.

Thanks,
Cheng Nie

author
#4 lore raw

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

In reply to a message not in the archive

Add a dedicated test at the end of main() that writes memcg_path to sysfs and checks the readback path. Configure the memcg filter before start(), verify staging readback without commit(), and ignore start() failures so the test does not depend on CONFIG_MEMCG or cgroup layout.

---
 tools/testing/selftests/damon/sysfs.py | 34 ++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
tools/testing/selftests/damon/sysfs.py +34 -0
index aa03a1187489..7a17ab88361b 100755
@@ -250,6 +250,38 @@ 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)
+
+    err = kdamonds.stop()
+    if err is not None:
+        print('memcg_path staging: kdamond stop (%s)' % err)
+        exit(1)
+    kdamonds = None
+
 def main():
     global kdamonds
     kdamonds = _damon_sysfs.Kdamonds(
@@ -356,5 +388,7 @@ def main():
     assert_ctxs_committed(kdamonds)
     kdamonds.stop()
 
+    test_memcg_filter_memcg_path_staging()
+
 if __name__ == '__main__':
     main()
Signature · 1 line
2.51.0
#5 lore raw

Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Test fails on teardown when `start()` fails, defeating the stated intent of decoupling the test…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Test fails on teardown when start() fails, defeating the stated intent of decoupling the test from CONFIG_MEMCG. --

commit 995afe8f607b12ca4f4469ac19ac53b1340cae11
Author: Cheng Nie <[email protected]>

selftests/damon/sysfs.py: validate memcg_path staging readback

This commit adds a dedicated test to write memcg_path to sysfs and verify the readback path. It intentionally ignores kdamonds.start() failures so the test operates independently of CONFIG_MEMCG or cgroup layout.

Quoted 5 lines
tools/testing/selftests/damon/sysfs.py +0 -0
index aa03a1187489f..7a17ab88361bc 100755
@@ -250,6 +250,38 @@ def assert_ctxs_committed(kdamonds):

[ ... ]

Quoted 1 line

+def test_memcg_filter_memcg_path_staging():

[ ... ]

Quoted 9 lines
tools/testing/selftests/damon/sysfs.py +9 -0
+    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:

tools/testing/selftests/damon/sysfs.py def assert_ctxs_committed(kdamonds): · line 282

Quoted 10 lines
tools/testing/selftests/damon/sysfs.py +10 -0
+        print('memcg_path staging: memcg_path readback '
+              '(shown=%s, expected=%s)' %
+              (shown.rstrip('\n'), memcg_filter.memcg_path))
+        kdamonds.stop()
+        exit(1)
+
+    err = kdamonds.stop()
+    if err is not None:
+        print('memcg_path staging: kdamond stop (%s)' % err)
+        exit(1)

[Severity: Medium]
If start() fails as expected when CONFIG_MEMCG is disabled, won't this subsequent call to kdamonds.stop() return an error?

Writing 'off' to the 'state' sysfs file of an unstarted kdamond causes damon_sysfs_turn_damon_off() to unconditionally return -EINVAL. This error propagates back to the Python script via write_file(), causing the script to exit with status 1.

Does checking this error and exiting with a failure defeat the stated intent of ignoring the start() failure in the first place?

Quoted 2 lines
tools/testing/selftests/damon/sysfs.py +2 -0
+    kdamonds = None
+
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2