mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
Subsystems (2)
PATCH v2 1/1 mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
Test the zero sample interval case with a non-zero aggregation interval, and keep the zero/zero case to cover the zero-result fallback.
Also make the overflow case use an explicit sample interval so that it does not depend on the zero sample interval fallback.
---
Changes in v2:
- Use 0/0 for the zero-result case, consistent with damon_set_attrs().
- Update commit msg and add Reviewed-by tag.
- Link to v1: https://lore.kernel.org/damon/[email protected]/
--- mm/damon/tests/core-kunit.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
mm/damon/tests/core-kunit.h +15 -4
@@ -627,12 +627,20 @@ static void damon_test_set_regions(struct kunit *test)static void damon_test_nr_samples_per_aggr (struct kunit *test) { -struct damon_attrs attrs = { +struct damon_attrs attrs; + +/* Zero sample interval is treated as one. */ + attrs = (struct damon_attrs ){ .sample_interval =0 , - .aggr_interval =0 , + .aggr_interval =5000 , }; +KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),5000 ); -/* Zero aggregation interval doesn't cause division by zero */ +/* Zero sample and aggregation intervals cover the zero-result fallback. */ + attrs = (struct damon_attrs ){ + .sample_interval =0 , + .aggr_interval =0 , + };KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),1 );/*
@@ -640,7 +648,10 @@ static void damon_test_nr_samples_per_aggr(struct kunit *test)* overflow */ if (ULONG_MAX >UINT_MAX ) { - attrs.aggr_interval = (unsigned long )UINT_MAX +1 ; + attrs = (struct damon_attrs ){ + .sample_interval =1 , + .aggr_interval = (unsigned long )UINT_MAX +1 , + };KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),UINT_MAX ); }
base-commit: d118502628f8b673be9023db8bdf878f64a7ed45
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
Test the zero sample interval case with a non-zero aggregation interval, and keep the zero/zero case to cover the zero-result fallback.
Also make the overflow case use an explicit sample interval so that it does not depend on the zero sample interval fallback.
Signed-off-by Kunwu Chan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 6 lines · On Wed, 9 Sep 2026 15:07:11 +0800 Kunwu Chan <[email protected]> wrote:
Test the zero sample interval case with a non-zero aggregation interval, and keep the zero/zero case to cover the zero-result fallback.
Also make the overflow case use an explicit sample interval so that it does not depend on the zero sample interval fallback.
Thank you for improving the test. This looks good to me :)
Quoted 3 lines
Signed-off-by Kunwu Chan <[email protected]>Reviewed-by Lian Wang <[email protected]>
This patch is applied to damon/next [1] tree. If this patch 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
[...]