Skip to contentSkip to conversation

selftests/damon: misc fixes for test bugs

PATCH In review Kunwu Chan 2 participants 10 messages Jun 1 – Jun 3

Subsystems (3)
lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

v2 cover selftests/damon: misc fixes for test bugs

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Patch 1 fixes mutable default arguments in DamonCtx.__init__() that cause state to leak between test instances.

Patch 2 fixes wrong operator precedence and join TypeError in damos_tried_regions.py.

Patch 3 fixes several wrong strings that produce dead elif branches, skipped file existence checks, and broken dict key lookups.

Based on next-20260529.
base-commit: 7da7f07112610a520567421dd2ffcb51beaefbcc
---
Changes in v2:
- Fix From:/Signed-off-by mismatch.
- Add Reviewed-by tags from SeongJae Park.
- Drop the duplicate memcg_path fix.
- Drop the empty aggregation-cycle retry fix pending root-cause investigation.
- No code change

Kunwu Chan (3):
selftests/damon: prevent cross-context state pollution in DamonCtx selftests/damon/damos_tried_regions: fix expectation output and join
TypeError
selftests/damon: fix dead code, skipped checks, and broken lookups

 tools/testing/selftests/damon/_damon_sysfs.py        | 12 +++++++++---
 .../testing/selftests/damon/damos_apply_interval.py  |  2 +-
 tools/testing/selftests/damon/damos_quota_goal.py    |  2 +-
 tools/testing/selftests/damon/damos_tried_regions.py |  4 ++--
 .../selftests/damon/drgn_dump_damon_status.py        |  2 +-
 tools/testing/selftests/damon/sysfs.py               |  4 ++--
 tools/testing/selftests/damon/sysfs.sh               |  6 +++---
 ...fs_update_schemes_tried_regions_wss_estimation.py |  2 +-
 8 files changed, 20 insertions(+), 14 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/3 selftests/damon: prevent cross-context state pollution in DamonCtx

From: Kunwu Chan <[email protected]>

DamonCtx.__init__() uses mutable default values for monitoring_attrs, targets, and schemes. In Python these are evaluated once at function definition time, so multiple DamonCtx instances can unintentionally share the same lists and DamonAttrs instance.

Replace the mutable defaults with None sentinels and initialize the objects when needed.

---
 tools/testing/selftests/damon/_damon_sysfs.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/damon/_damon_sysfs.py +8 -2
index 8b12cc048440..2f6f2699db25 100644
@@ -624,17 +624,23 @@ class DamonCtx:
     pause = None
     idx = None
 
-    def __init__(self, ops='paddr', monitoring_attrs=DamonAttrs(), targets=[],
-            schemes=[], pause=False):
+    def __init__(self, ops='paddr', monitoring_attrs=None, targets=None,
+            schemes=None, pause=False):
         self.ops = ops
+        if monitoring_attrs is None:
+            monitoring_attrs = DamonAttrs()
         self.monitoring_attrs = monitoring_attrs
         self.monitoring_attrs.context = self
 
+        if targets is None:
+            targets = []
         self.targets = targets
         for idx, target in enumerate(self.targets):
             target.idx = idx
             target.context = self
 
+        if schemes is None:
+            schemes = []
         self.schemes = schemes
         for idx, scheme in enumerate(self.schemes):
             scheme.idx = idx
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/3 selftests/damon/damos_tried_regions: fix expectation output and join TypeError

In reply to Kunwu Chan

From: Kunwu Chan <[email protected]>

The expectation print has wrong operator precedence: '%' binds before the conditional expression, so the else branch prints 'not met' without the prefix 'expectation (>= 14) is'. Add parentheses to fix it.

Also, '\n'.join() on the list of ints raises TypeError; convert to str in the list comprehension.

---
 tools/testing/selftests/damon/damos_tried_regions.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/damon/damos_tried_regions.py +2 -2
index 3b347eb28bd2..d6472e6a6e08 100755
@@ -55,10 +55,10 @@ def main():
     collected_nr_regions.sort()
     sample = collected_nr_regions[4]
     print('50-th percentile nr_regions: %d' % sample)
-    print('expectation (>= 14) is %s' % 'met' if sample >= 14 else 'not met')
+    print('expectation (>= 14) is %s' % ('met' if sample >= 14 else 'not met'))
     if collected_nr_regions[4] < 14:
         print('full nr_regions:')
-        print('\n'.join(collected_nr_regions))
+        print('\n'.join(['%d' % x for x in collected_nr_regions]))
         exit(1)
 
 if __name__ == '__main__':
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v2 3/3 selftests/damon: fix dead code, skipped checks, and broken lookups

In reply to Kunwu Chan

From: Kunwu Chan <[email protected]>

'hugeapge_size' in drgn_dump_damon_status.py was a dead elif branch. $fail_reason in sysfs.sh was undefined, silently emptying the error message. 'exit' instead of 'exist' in sysfs.sh skipped a file existence check. 'nohugeapge' in sysfs.py broke an action dict lookup.

Fix other wrong strings in the same files.

---
 tools/testing/selftests/damon/_damon_sysfs.py               | 2 +-
 tools/testing/selftests/damon/damos_apply_interval.py       | 2 +-
 tools/testing/selftests/damon/damos_quota_goal.py           | 2 +-
 tools/testing/selftests/damon/drgn_dump_damon_status.py     | 2 +-
 tools/testing/selftests/damon/sysfs.py                      | 4 ++--
 tools/testing/selftests/damon/sysfs.sh                      | 6 +++---
 .../sysfs_update_schemes_tried_regions_wss_estimation.py    | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)
tools/testing/selftests/damon/_damon_sysfs.py +1 -1
index 2f6f2699db25..f6127081dfb2 100644
@@ -837,7 +837,7 @@ class Kdamond:
                 for goal in scheme.quota.goals:
                     err = goal.stage()
                     if err is not None:
-                        print('commit_schemes_quota_goals failed stagign: %s'%
+                        print('commit_schemes_quota_goals failed staging: %s'%
                               err)
                         exit(1)
         return write_file(os.path.join(self.sysfs_dir(), 'state'),
tools/testing/selftests/damon/damos_apply_interval.py +1 -1
index f04d43702481..0f2f36584e48 100755
@@ -56,7 +56,7 @@ def main():
     # Because the second scheme was having the apply interval that is ten times
     # lower than that of the first scheme, the second scheme should be tried
     # about ten times more frequently than the first scheme.  For possible
-    # timing errors, check if it was at least nine times more freuqnetly tried.
+    # timing errors, check if it was at least nine times more frequently tried.
     ratio = nr_tried_stats[1] / nr_tried_stats[0]
     if ratio < 9:
         print('%d / %d = %f (< 9)' %
tools/testing/selftests/damon/damos_quota_goal.py +1 -1
index f76e0412b564..661e4ba4765a 100755
@@ -66,7 +66,7 @@ def main():
             # effective quota was already minimum that cannot be more reduced
             if expect_increase is False and last_effective_bytes == 1:
                 continue
-            print('efective bytes not changed: %d' % goal.effective_bytes)
+            print('effective bytes not changed: %d' % goal.effective_bytes)
             exit(1)
 
         increased = last_effective_bytes < goal.effective_bytes
tools/testing/selftests/damon/drgn_dump_damon_status.py +1 -1
index 972948e6215f..26b207e44268 100755
@@ -163,7 +163,7 @@ def damos_filter_to_dict(damos_filter):
                                int(damos_filter.addr_range.end)]
     elif type_ == 'target':
         dict_['target_idx'] = int(damos_filter.target_idx)
-    elif type_ == 'hugeapge_size':
+    elif type_ == 'hugepage_size':
         dict_['sz_range'] = [int(damos_filter.sz_range.min),
                              int(damos_filter.sz_range.max)]
     return dict_
tools/testing/selftests/damon/sysfs.py +2 -2
index aa03a1187489..99412f0d31f3 100755
@@ -119,7 +119,7 @@ def assert_access_pattern_committed(pattern, dump):
                 'max_nr_accesses', dump)
     assert_true(dump['min_age_region'] == pattern.age[0], 'min_age_region',
                 dump)
-    assert_true(dump['max_age_region'] == pattern.age[1], 'miaxage_region',
+    assert_true(dump['max_age_region'] == pattern.age[1], 'max_age_region',
                 dump)
 
 def assert_scheme_committed(scheme, dump):
@@ -129,7 +129,7 @@ def assert_scheme_committed(scheme, dump):
             'cold': 1,
             'pageout': 2,
             'hugepage': 3,
-            'nohugeapge': 4,
+            'nohugepage': 4,
             'collapse': 5,
             'lru_prio': 6,
             'lru_deprio': 7,
tools/testing/selftests/damon/sysfs.sh +3 -3
index 78f4badb5beb..2eaaa5ae3c5e 100755
@@ -3,7 +3,7 @@
 
 source _common.sh
 
-# Kselftest frmework requirement - SKIP code is 4.
+# Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
 ensure_write_succ()
@@ -28,7 +28,7 @@ ensure_write_fail()
 
 	if (echo "$content" > "$file") 2> /dev/null
 	then
-		echo "writing $content to $file succeed ($fail_reason)"
+		echo "writing $content to $file succeeded ($reason)"
 		echo "expected failure because $reason"
 		exit 1
 	fi
@@ -363,7 +363,7 @@ test_context()
 {
 	context_dir=$1
 	ensure_dir "$context_dir" "exist"
-	ensure_file "$context_dir/avail_operations" "exit" 400
+	ensure_file "$context_dir/avail_operations" "exist" 400
 	ensure_file "$context_dir/operations" "exist" 600
 	ensure_file "$context_dir/addr_unit" "exist" 600
 	ensure_file "$context_dir/pause" "exist" 600
tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py +1 -1
index 35c724a63f6c..16fdc6e7fc56 100755
@@ -7,7 +7,7 @@ import time
 import _damon_sysfs
 
 def pass_wss_estimation(sz_region):
-    # access two regions of given size, 2 seocnds per each region
+    # access two regions of given size, 2 seconds per each region
     proc = subprocess.Popen(
             ['./access_memory', '2', '%d' % sz_region, '2000', 'repeat'])
     kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
Signature · 1 line
2.43.0
maintainer
#4 lore raw
In reply to Kunwu Chan
Quoted 5 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Nit. Only patch 3 fixes a fake test pass for "avail_operations" file existence test, and the series is not doing something for slow machines, right? I think the last sentence should be updated, for example:

'''
Most are trivial but makes test output wrong or even silently pass the one for 'avail_operation' file existence check.
'''

Other than that, all look good to me, and already have my Reviewed-by: tag.

Asssuming you are ok with the above change, I applied this series to damon/next
[1] tree with the above change. If this series is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees

Thanks,
SJ

[...]

author
#5 lore raw

2026年6月1日 22:22, "SeongJae Park" <[email protected] mailto:[email protected]?to=%22SeongJae%20Park%22%20%3Csj%40kernel.org%3E > 写到:

Quoted 21 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:
Quoted 8 lines

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Nit. Only patch 3 fixes a fake test pass for "avail_operations" file existence test, and the series is not doing something for slow machines, right? I think the last sentence should be updated, for example:

'''
Most are trivial but makes test output wrong or even silently pass the one for 'avail_operation' file existence check.
'''

Other than that, all look good to me, and already have my Reviewed-by: tag.

Quoted 9 lines

Asssuming you are ok with the above change, I applied this series to damon/next
[1] tree with the above change. If this series is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees

Hi SJ,

The updated cover letter looks good to me, thanks for fixing it. Thanks also for applying to damon/next.
No further action needed on my side.

Regards,
Kunwu

Quoted 5 lines

Thanks,
SJ

[...]

maintainer
#6 lore raw
Quoted 27 lines · On Wed, 03 Jun 2026 02:11:33 +0000 "Kunwu Chan" <[email protected]> wrote:

2026年6月1日 22:22, "SeongJae Park" <[email protected] mailto:[email protected]?to=%22SeongJae%20Park%22%20%3Csj%40kernel.org%3E > 写到:

Quoted 24 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:
Quoted 8 lines

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Nit. Only patch 3 fixes a fake test pass for "avail_operations" file existence test, and the series is not doing something for slow machines, right? I think the last sentence should be updated, for example:

'''
Most are trivial but makes test output wrong or even silently pass the one for 'avail_operation' file existence check.
'''

Other than that, all look good to me, and already have my Reviewed-by: tag.

Asssuming you are ok with the above change, I applied this series to damon/next
[1] tree with the above change. If this series is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this.

FYI, we are now quite close to next merge window. We want to focus on making mm.git more stabilized and therefore ready for the next merge window, rather than adding more changes that no really urgent. I understand this series is not really urgent. Hence, I will request adding this to mm.git after next -rc1 release. Let me know if you think this is really urgent.

Quoted 11 lines
Quoted 6 lines

So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees

Hi SJ,

The updated cover letter looks good to me, thanks for fixing it. Thanks also for applying to damon/next.
No further action needed on my side.

Thank you for confirming!

Thanks,
SJ

[...]

author
#7 lore raw

2026年6月3日 13:02, "SeongJae Park" <[email protected] mailto:[email protected]?to=%22SeongJae%20Park%22%20%3Csj%40kernel.org%3E > 写到:

Quoted 32 lines · On Wed, 03 Jun 2026 02:11:33 +0000 "Kunwu Chan" <[email protected]> wrote:
Quoted 24 lines

2026年6月1日 22:22, "SeongJae Park" <[email protected] mailto:[email protected]?to=%22SeongJae%20Park%22%20%3Csj%40kernel.org%3E > 写到:

Quoted 7 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Nit. Only patch 3 fixes a fake test pass for "avail_operations" file existence test, and the series is not doing something for slow machines, right? I think the last sentence should be updated, for example:

'''
Most are trivial but makes test output wrong or even silently pass the one for 'avail_operation' file existence check.
'''

Quoted 6 lines

Other than that, all look good to me, and already have my Reviewed-by: tag.

Asssuming you are ok with the above change, I applied this series to damon/next
[1] tree with the above change. If this series is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this.

Quoted 6 lines

FYI, we are now quite close to next merge window. We want to focus on making mm.git more stabilized and therefore ready for the next merge window, rather than adding more changes that no really urgent. I understand this series is not really urgent. Hence, I will request adding this to mm.git after next -rc1 release. Let me know if you think this is really urgent.

Waiting until after -rc1 is perfectly fine, this series isn't urgent. Thanks for letting me know.

Regards,
Kunwu

Quoted 20 lines
Quoted 5 lines

So, no action from your side is needed for now. If it seems I also forgot
doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.

Quoted 8 lines

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees

Hi SJ,

The updated cover letter looks good to me, thanks for fixing it. Thanks also for applying to damon/next.
No further action needed on my side.

Thank you for confirming!

Thanks,
SJ

[...]

maintainer
#8 lore raw
In reply to Kunwu Chan
Quoted 16 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Patch 1 fixes mutable default arguments in DamonCtx.__init__() that cause state to leak between test instances.

Patch 2 fixes wrong operator precedence and join TypeError in damos_tried_regions.py.

Patch 3 fixes several wrong strings that produce dead elif branches, skipped file existence checks, and broken dict key lookups.

Quoted 10 lines

Based on next-20260529.
base-commit: 7da7f07112610a520567421dd2ffcb51beaefbcc
---
Changes in v2:
- Fix From:/Signed-off-by mismatch.
- Add Reviewed-by tags from SeongJae Park.
- Drop the duplicate memcg_path fix.
- Drop the empty aggregation-cycle retry fix pending root-cause investigation.
- No code change

From the next time, please add links to previous versions [1]. For other readers, the v1 of this series is available on the mailing list [2].

[1] https://docs.kernel.org/process/submitting-patches.html#commentary
[2] https://lore.kernel.org/[email protected]

Thanks,
SJ

[....]

author
#9 lore raw

2026年6月1日 22:28, "SeongJae Park" <[email protected] mailto:[email protected]?to=%22SeongJae%20Park%22%20%3Csj%40kernel.org%3E > 写到:

Quoted 31 lines · On Mon, 1 Jun 2026 11:23:11 +0800 Kunwu Chan <[email protected]> wrote:
Quoted 18 lines

From: Kunwu Chan <[email protected]>

This series fixes several bugs in the DAMON selftests. Most are trivial but cause tests to silently pass when they shouldn't, or fail prematurely on slow machines.

Patch 1 fixes mutable default arguments in DamonCtx.__init__() that cause state to leak between test instances.

Patch 2 fixes wrong operator precedence and join TypeError in damos_tried_regions.py.

Patch 3 fixes several wrong strings that produce dead elif branches, skipped file existence checks, and broken dict key lookups.

Quoted 11 lines

Based on next-20260529.
base-commit: 7da7f07112610a520567421dd2ffcb51beaefbcc
---
Changes in v2:
- Fix From:/Signed-off-by mismatch.
- Add Reviewed-by tags from SeongJae Park.
- Drop the duplicate memcg_path fix.
- Drop the empty aggregation-cycle retry fix pending root-cause investigation.
- No code change

Quoted 6 lines

From the next time, please add links to previous versions [1]. For other readers, the v1 of this series is available on the mailing list [2].

[1] https://docs.kernel.org/process/submitting-patches.html#commentary
[2] https://lore.kernel.org/[email protected]

Hi SJ,

Noted, will add the link to previous versions next time. Thanks for the reminder and for providing the v1 link.

Regards,
Kunwu

Quoted 5 lines

Thanks,
SJ

[....]