mm/damon/tests/core-kunit: extend existing test scenarios
Subsystems (2)
v2 cover mm/damon/tests/core-kunit: extend existing test scenarios
Improve the KUnit test coverage for DAMON.
The five patches in this series respectively extend damon_test_split_at(), damon_test_merge_two(), damon_test_merge_regions_of(), damon_test_split_regions_of(), and damos_test_commit_quota_goal().
Changes from v1:
- Split the original patch into five smaller patches.
- Remove a newly added region from damon_test_merge_regions_of() to avoid an obvious test case.
- Restore the test case in damon_test_split_regions_of() that was previously removed.
Shu Anzai (5):
mm/damon/tests/core-kunit: verify the 'age' field in
damon_test_split_at()
mm/damon/tests/core-kunit: verify the 'age' and 'nr_accesses_bp'
fields in damon_test_merge_two()
mm/damon/tests/core-kunit: add a test case for region merge size limit
in damon_test_merge_regions_of()
mm/damon/tests/core-kunit: add test cases for multiple regions in
damon_test_split_regions_of()
mm/damon/tests/core-kunit: remove a redundant test case and add a new
test case in damos_test_commit_quota_goal()
mm/damon/tests/core-kunit.h | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/5 mm/damon/tests/core-kunit: verify the 'age' field in damon_test_split_at()
Extend damon_test_split_at() to verify the 'age' field.
--- mm/damon/tests/core-kunit.h | 2 ++ 1 file changed, 2 insertions(+)
mm/damon/tests/core-kunit.h +2 -0
@@ -158,6 +158,7 @@ static void damon_test_split_at(struct kunit *test) r->nr_accesses_bp =420000 ; r->nr_accesses =42 ; r->last_nr_accesses =15 ; + r->age =10 ;damon_add_region (r, t);damon_split_region_at (t, r,25 );KUNIT_EXPECT_EQ (test, r->ar.start,0ul );
@@ -170,6 +171,7 @@ static void damon_test_split_at(struct kunit *test)KUNIT_EXPECT_EQ (test, r->nr_accesses_bp, r_new->nr_accesses_bp);KUNIT_EXPECT_EQ (test, r->nr_accesses, r_new->nr_accesses);KUNIT_EXPECT_EQ (test, r->last_nr_accesses, r_new->last_nr_accesses); +KUNIT_EXPECT_EQ (test, r->age, r_new->age);damon_free_target (t); }
Signature · 1 line
2.43.0
Re: [PATCH v2 1/5] mm/damon/tests/core-kunit: verify the 'age' field in damon_test_split_at()
Quoted 3 lines · On Wed, 24 Dec 2025 04:21:56 +0000 Shu Anzai <[email protected]> wrote:
Extend
damon_test_split_at()to verify the 'age' field.Signed-off-by Shu Anzai <[email protected]>
Quoted 26 lines
--- mm/damon/tests/core-kunit.h | 2 ++ 1 file changed, 2 insertions(+)mm/damon/tests/core-kunit.h +2
-0@@ -158,6 +158,7 @@ static void damon_test_split_at(struct kunit *test) r->nr_accesses_bp =420000 ; r->nr_accesses =42 ; r->last_nr_accesses =15 ; + r->age =10 ;damon_add_region (r, t);damon_split_region_at (t, r,25 );KUNIT_EXPECT_EQ (test, r->ar.start,0ul );@@ -170,6 +171,7 @@ static void damon_test_split_at(struct kunit *test)KUNIT_EXPECT_EQ (test, r->nr_accesses_bp, r_new->nr_accesses_bp);KUNIT_EXPECT_EQ (test, r->nr_accesses, r_new->nr_accesses);KUNIT_EXPECT_EQ (test, r->last_nr_accesses, r_new->last_nr_accesses); +KUNIT_EXPECT_EQ (test, r->age, r_new->age);damon_free_target (t); }Signature · 1 line
2.43.0
Thanks,
SJ
PATCH v2 2/5 mm/damon/tests/core-kunit: verify the 'age' and 'nr_accesses_bp' fields in damon_test_merge_two()
In reply to Shu AnzaiExtend damon_test_merge_two() to verify the 'age' and 'nr_accesses_bp' fields.
--- mm/damon/tests/core-kunit.h | 4 ++++ 1 file changed, 4 insertions(+)
mm/damon/tests/core-kunit.h +4 -0
@@ -192,6 +192,7 @@ static void damon_test_merge_two(struct kunit *test) } r->nr_accesses =10 ; r->nr_accesses_bp =100000 ; + r->age =9 ;damon_add_region (r, t); r2 =damon_new_region (100 ,300 );if (!r2) {
@@ -200,12 +201,15 @@ static void damon_test_merge_two(struct kunit *test) } r2->nr_accesses =20 ; r2->nr_accesses_bp =200000 ; + r2->age =21 ;damon_add_region (r2, t);damon_merge_two_regions (t, r, r2);KUNIT_EXPECT_EQ (test, r->ar.start,0ul );KUNIT_EXPECT_EQ (test, r->ar.end,300ul );KUNIT_EXPECT_EQ (test, r->nr_accesses,16u ); +KUNIT_EXPECT_EQ (test, r->nr_accesses_bp,160000u ); +KUNIT_EXPECT_EQ (test, r->age,17u ); i =0 ;damon_for_each_region (r3, t) {
Signature · 1 line
2.43.0
Re: [PATCH v2 2/5] mm/damon/tests/core-kunit: verify the 'age' and 'nr_accesses_bp' fields in damon_test_merge_two()
Quoted 4 lines · On Wed, 24 Dec 2025 04:21:57 +0000 Shu Anzai <[email protected]> wrote:
Extend
damon_test_merge_two()to verify the 'age' and 'nr_accesses_bp' fields.Signed-off-by Shu Anzai <[email protected]>
Thanks,
SJ
[...]
PATCH v2 3/5 mm/damon/tests/core-kunit: add a test case for region merge size limit in damon_test_merge_regions_of()
In reply to Shu AnzaiAdd a test case in damon_test_merge_regions_of() to verify that two adjacent regions are not merged if the resulting region would exceed the specified size limit.
--- mm/damon/tests/core-kunit.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
mm/damon/tests/core-kunit.h +8 -8
@@ -238,12 +238,12 @@ static void damon_test_merge_regions_of(struct kunit *test) {struct damon_target *t;struct damon_region *r; -unsigned long sa[] = {0 ,100 ,114 ,122 ,130 ,156 ,170 ,184 }; -unsigned long ea[] = {100 ,112 ,122 ,130 ,156 ,170 ,184 ,230 }; -unsigned int nrs[] = {0 ,0 ,10 ,10 ,20 ,30 ,1 ,2 }; +unsigned long sa[] = {0 ,100 ,114 ,122 ,130 ,156 ,170 ,184 ,230 }; +unsigned long ea[] = {100 ,112 ,122 ,130 ,156 ,170 ,184 ,230 ,10170 }; +unsigned int nrs[] = {0 ,0 ,10 ,10 ,20 ,30 ,1 ,2 ,5 }; -unsigned long saddrs[] = {0 ,114 ,130 ,156 ,170 }; -unsigned long eaddrs[] = {112 ,130 ,156 ,170 ,230 }; +unsigned long saddrs[] = {0 ,114 ,130 ,156 ,170 ,230 }; +unsigned long eaddrs[] = {112 ,130 ,156 ,170 ,230 ,10170 };int i; t =damon_new_target ();
@@ -261,9 +261,9 @@ static void damon_test_merge_regions_of(struct kunit *test) }damon_merge_regions_of (t,9 ,9999 ); -/* 0-112, 114-130, 130-156, 156-170 */ -KUNIT_EXPECT_EQ (test,damon_nr_regions (t),5u ); -for (i =0 ; i <5 ; i++) { +/* 0-112, 114-130, 130-156, 156-170, 170-230, 230-10170 */ +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),6u ); +for (i =0 ; i <6 ; i++) { r =__nth_region_of (t, i);KUNIT_EXPECT_EQ (test, r->ar.start, saddrs[i]);KUNIT_EXPECT_EQ (test, r->ar.end, eaddrs[i]);
Signature · 1 line
2.43.0
Re: [PATCH v2 3/5] mm/damon/tests/core-kunit: add a test case for region merge size limit in damon_test_merge_regions_of()
Quoted 5 lines · On Wed, 24 Dec 2025 04:21:58 +0000 Shu Anzai <[email protected]> wrote:
Add a test case in
damon_test_merge_regions_of()to verify that two adjacent regions are not merged if the resulting region would exceed the specified size limit.Signed-off-by Shu Anzai <[email protected]>
Thanks,
SJ
[...]
PATCH v2 4/5 mm/damon/tests/core-kunit: add test cases for multiple regions in damon_test_split_regions_of()
In reply to Shu AnzaiExtend damon_test_split_regions_of() to verify that it correctly handles multiple regions with various 'min_sz_region'.
--- mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
mm/damon/tests/core-kunit.h +21 -0
@@ -275,6 +275,9 @@ static void damon_test_split_regions_of(struct kunit *test) {struct damon_target *t;struct damon_region *r; +unsigned long sa[] = {0 ,300 ,500 }; +unsigned long ea[] = {220 ,400 ,700 }; +int i; t =damon_new_target ();if (!t)
@@ -301,6 +304,24 @@ static void damon_test_split_regions_of(struct kunit *test)damon_split_regions_of (t,4 ,1 );KUNIT_EXPECT_LE (test,damon_nr_regions (t),4u );damon_free_target (t); + + t =damon_new_target (); +if (!t) +kunit_skip (test,"third target alloc fail" ); +for (i =0 ; i <ARRAY_SIZE (sa); i++) { + r =damon_new_region (sa[i], ea[i]); +if (!r) { +damon_free_target (t); +kunit_skip (test,"region alloc fail" ); + } +damon_add_region (r, t); + } +damon_split_regions_of (t,4 ,5 ); +KUNIT_EXPECT_LE (test,damon_nr_regions (t),12u ); +damon_for_each_region (r, t) { +KUNIT_EXPECT_GE (test,damon_sz_region (r) %5ul ,0ul ); + } +damon_free_target (t); }static void damon_test_ops_registration (struct kunit *test)
Signature · 1 line
2.43.0
Re: [PATCH v2 4/5] mm/damon/tests/core-kunit: add test cases for multiple regions in damon_test_split_regions_of()
Quoted 33 lines · On Wed, 24 Dec 2025 04:21:59 +0000 Shu Anzai <[email protected]> wrote:
Extend
damon_test_split_regions_of()to verify that it correctly handles multiple regions with various 'min_sz_region'.Signed-off-by Shu Anzai <[email protected]>--- mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)mm/damon/tests/core-kunit.h +10
-0@@ -275,6 +275,9 @@ static void damon_test_split_regions_of(struct kunit *test) {struct damon_target *t;struct damon_region *r; +unsigned long sa[] = {0 ,300 ,500 }; +unsigned long ea[] = {220 ,400 ,700 }; +int i; t =damon_new_target ();if (!t)@@ -301,6 +304,24 @@ static void damon_test_split_regions_of(struct kunit *test)damon_split_regions_of (t,4 ,1 );KUNIT_EXPECT_LE (test,damon_nr_regions (t),4u );damon_free_target (t); + + t =damon_new_target (); +if (!t) +kunit_skip (test,"third target alloc fail" ); +for (i =0 ; i <ARRAY_SIZE (sa); i++) { + r =damon_new_region (sa[i], ea[i]); +if (!r) {
mm/damon/tests/core-kunit.h static void damon_test_split_regions_of(struct kunit *test) · line 323
Quoted 10 lines
mm/damon/tests/core-kunit.h +10
-0+damon_free_target (t); +kunit_skip (test,"region alloc fail" ); + } +damon_add_region (r, t); + } +damon_split_regions_of (t,4 ,5 ); +KUNIT_EXPECT_LE (test,damon_nr_regions (t),12u ); +damon_for_each_region (r, t) { +KUNIT_EXPECT_GE (test,damon_sz_region (r) %5ul ,0ul ); + }
Nit. The above braces for single statement is unnecessary.
Quoted 6 lines
mm/damon/tests/core-kunit.h +1
-0+damon_free_target (t); }static void damon_test_ops_registration (struct kunit *test)Signature · 1 line
2.43.0
Other than the above trivial nit for the unnecessary braces,
Thanks,
SJ
SeongJae Park
maintainerRe: [PATCH v2 4/5] mm/damon/tests/core-kunit: add test cases for multiple regions in damon_test_split_regions_of()
Quoted 39 lines · On Tue, 23 Dec 2025 21:34:06 -0800 SeongJae Park <[email protected]> wrote:
Quoted 37 lines · On Wed, 24 Dec 2025 04:21:59 +0000 Shu Anzai <[email protected]> wrote:
Extend
damon_test_split_regions_of()to verify that it correctly handles multiple regions with various 'min_sz_region'.Signed-off-by Shu Anzai <[email protected]>--- mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)mm/damon/tests/core-kunit.h +14
-0@@ -275,6 +275,9 @@ static void damon_test_split_regions_of(struct kunit *test) {struct damon_target *t;struct damon_region *r; +unsigned long sa[] = {0 ,300 ,500 }; +unsigned long ea[] = {220 ,400 ,700 }; +int i; t =damon_new_target ();if (!t)@@ -301,6 +304,24 @@ static void damon_test_split_regions_of(struct kunit *test)damon_split_regions_of (t,4 ,1 );KUNIT_EXPECT_LE (test,damon_nr_regions (t),4u );damon_free_target (t); + + t =damon_new_target (); +if (!t) +kunit_skip (test,"third target alloc fail" ); +for (i =0 ; i <ARRAY_SIZE (sa); i++) { + r =damon_new_region (sa[i], ea[i]); +if (!r) { +damon_free_target (t); +kunit_skip (test,"region alloc fail" ); + } +damon_add_region (r, t);
Quoted 8 lines
mm/damon/tests/core-kunit.h static void damon_test_split_regions_of(struct kunit *test) · line 323
Quoted 6 lines
mm/damon/tests/core-kunit.h +6
-0+ } +damon_split_regions_of (t,4 ,5 ); +KUNIT_EXPECT_LE (test,damon_nr_regions (t),12u ); +damon_for_each_region (r, t) { +KUNIT_EXPECT_GE (test,damon_sz_region (r) %5ul ,0ul ); + }Nit. The above braces for single statement is unnecessary.
Andrew, could you please pick this series with below attaching fixup for this one?
Quoted 10 lines
Quoted 7 lines
mm/damon/tests/core-kunit.h +1
-0+damon_free_target (t); }static void damon_test_ops_registration (struct kunit *test)Signature · 1 line
2.43.0Other than the above trivial nit for the unnecessary braces,
Quoted 5 lines
Reviewed-by SeongJae Park <[email protected]>Thanks,
SJ
Thanks,
SJ
==== >8 ====
From dde3e0e84056f85cd5cbface38c1f617bfbd0bd4 Mon Sep 17 00:00:00 2001
From: SeongJae Park <[email protected]>
Date: Wed, 24 Dec 2025 07:27:04 -0800
Subject: [PATCH] mm/damon/tests/core-kunit: remove braces for a single
statement
damon_test_split_regions_of() has braces for a single statement, which is unnecessary. Remove it.
--- mm/damon/tests/core-kunit.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/damon/tests/core-kunit.h +1 -2
@@ -318,9 +318,8 @@ static void damon_test_split_regions_of(struct kunit *test) }damon_split_regions_of (t,4 ,5 );KUNIT_EXPECT_LE (test,damon_nr_regions (t),12u ); -damon_for_each_region (r, t) { +damon_for_each_region (r, t)KUNIT_EXPECT_GE (test,damon_sz_region (r) %5ul ,0ul ); - }damon_free_target (t); }
Signature · 1 line
2.47.3
PATCH v2 5/5 mm/damon/tests/core-kunit: remove a redundant test case and add a new test case in damos_test_commit_quota_goal()
In reply to Shu AnzaiRemove a redundant test case from damos_test_commit_quota_goal() as it is already covered. Instead, add a new test for DAMOS_QUOTA_SOME_MEM_PSI_US, which was previously not tested.
--- mm/damon/tests/core-kunit.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mm/damon/tests/core-kunit.h +4 -3
@@ -601,9 +601,10 @@ static void damos_test_commit_quota_goal(struct kunit *test) });damos_test_commit_quota_goal_for (test, &dst, &(struct damos_quota_goal ) { - .metric =DAMOS_QUOTA_USER_INPUT , - .target_value =789 , - .current_value =12 , + .metric =DAMOS_QUOTA_SOME_MEM_PSI_US , + .target_value =234 , + .current_value =345 , + .last_psi_total =567 , }); }
Signature · 1 line
2.43.0
Re: [PATCH v2 5/5] mm/damon/tests/core-kunit: remove a redundant test case and add a new test case in damos_test_commit_quota_goal()
Quoted 29 lines · On Wed, 24 Dec 2025 04:22:00 +0000 Shu Anzai <[email protected]> wrote:
Remove a redundant test case from
damos_test_commit_quota_goal()as it is already covered. Instead, add a new test forDAMOS_QUOTA_SOME_MEM_PSI_US, which was previously not tested.Signed-off-by Shu Anzai <[email protected]>--- mm/damon/tests/core-kunit.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)mm/damon/tests/core-kunit.h +4
-3@@ -601,9 +601,10 @@ static void damos_test_commit_quota_goal(struct kunit *test) });damos_test_commit_quota_goal_for (test, &dst, &(struct damos_quota_goal ) { - .metric =DAMOS_QUOTA_USER_INPUT , - .target_value =789 , - .current_value =12 , + .metric =DAMOS_QUOTA_SOME_MEM_PSI_US , + .target_value =234 , + .current_value =345 , + .last_psi_total =567 , }); }Signature · 1 line
2.43.0
Thanks,
SJ
SeongJae Park
maintainerQuoted 6 lines · On Wed, 24 Dec 2025 04:21:55 +0000 Shu Anzai <[email protected]> wrote:
Improve the KUnit test coverage for DAMON.
The five patches in this series respectively extend
damon_test_split_at(),damon_test_merge_two(),damon_test_merge_regions_of(),damon_test_split_regions_of(), anddamos_test_commit_quota_goal().
Quoted 6 lines
Changes from v1:
- Split the original patch into five smaller patches.
- Remove a newly added region fromdamon_test_merge_regions_of()to avoid an obvious test case.
- Restore the test case indamon_test_split_regions_of()that was previously removed.
Thank you for revisioning, Shu!
Quoted 10 lines
Shu Anzai (5):
mm/damon/tests/core-kunit: verify the 'age' field in
damon_test_split_at()
mm/damon/tests/core-kunit: verify the 'age' and 'nr_accesses_bp'
fields indamon_test_merge_two()
mm/damon/tests/core-kunit: add a test case for region merge size limit
indamon_test_merge_regions_of()
mm/damon/tests/core-kunit: add test cases for multiple regions in
damon_test_split_regions_of()
I left a trivial comment on this fourth patch for unnecessary braces enclosing a single statement. Other than that, all look good to me.
Quoted 8 lines
mm/damon/tests/core-kunit: remove a redundant test case and add a new
test case indamos_test_commit_quota_goal()mm/damon/tests/core-kunit.h | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-)Signature · 1 line
2.43.0
Thanks,
SJ
[...]