There was a bug [1] in damon_is_last_region().  Add a kunit test to not
reintroduce the bug.

[1] https://lore.kernel.org/[email protected]/

Signed-off-by: SeongJae Park <[email protected]>
---
 mm/damon/tests/core-kunit.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 2289f9e4610c0..e86d4f4fe261a 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1311,6 +1311,28 @@ static void damon_test_apply_min_nr_regions(struct kunit 
*test)
        damon_test_apply_min_nr_regions_for(test, 10, 2, 10, 2, 5);
 }
 
+static void damon_test_is_last_region(struct kunit *test)
+{
+       struct damon_region *r;
+       struct damon_target *t;
+       int i;
+
+       t = damon_new_target();
+       if (!t)
+               kunit_skip(test, "target alloc fail\n");
+
+       for (i = 0; i < 4; i++) {
+               r = damon_new_region(i * 2, (i + 1) * 2);
+               if (!r) {
+                       damon_free_target(t);
+                       kunit_skip(test, "region alloc %d fail\n", i);
+               }
+               damon_add_region(r, t);
+               KUNIT_EXPECT_TRUE(test, damon_is_last_region(r, t));
+       }
+       damon_free_target(t);
+}
+
 static struct kunit_case damon_test_cases[] = {
        KUNIT_CASE(damon_test_target),
        KUNIT_CASE(damon_test_regions),
@@ -1339,6 +1361,7 @@ static struct kunit_case damon_test_cases[] = {
        KUNIT_CASE(damon_test_feed_loop_next_input),
        KUNIT_CASE(damon_test_set_filters_default_reject),
        KUNIT_CASE(damon_test_apply_min_nr_regions),
+       KUNIT_CASE(damon_test_is_last_region),
        {},
 };
 
-- 
2.47.3

Reply via email to