Add a simple unit test for damon_nr_accesses_mvsum()'s internal core
logic, damon_mvsum().  The test contains cases for just-started windows,
partially completed windows, and just-completed windows.

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

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 4e448c08c724a..cdab14396250f 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -623,6 +623,30 @@ static void damon_test_moving_sum(struct kunit *test)
        }
 }
 
+static void damon_test_mvsum(struct kunit *test)
+{
+       unsigned long input_expects[] = {
+               /* current value, last value, remaining window (bp) */
+               0, 49, 10000, 49,       /* 0 + 49 * 1 */
+               3, 10, 7000, 10,        /* 3 + 10 * 0.7 */
+               3, 10, 5000, 8,         /* 3 + 10 * 0.5 */
+               32, 100, 1000, 42,      /* 32 + 100 * 0.1 */
+               42, 49, 0, 42,          /* 42 + 49 * 0 */
+       };
+
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(input_expects); i += 4) {
+               unsigned long current_nr = input_expects[i];
+               unsigned long last_nr = input_expects[i + 1];
+               unsigned long left_window_bp = input_expects[i + 2];
+               unsigned long expect = input_expects[i + 3];
+
+               KUNIT_EXPECT_EQ(test, damon_mvsum(current_nr, last_nr,
+                                       left_window_bp), expect);
+       }
+}
+
 static void damos_test_new_filter(struct kunit *test)
 {
        struct damos_filter *filter;
@@ -1501,6 +1525,7 @@ static struct kunit_case damon_test_cases[] = {
        KUNIT_CASE(damon_test_update_monitoring_result),
        KUNIT_CASE(damon_test_set_attrs),
        KUNIT_CASE(damon_test_moving_sum),
+       KUNIT_CASE(damon_test_mvsum),
        KUNIT_CASE(damos_test_new_filter),
        KUNIT_CASE(damos_test_commit_quota_goal),
        KUNIT_CASE(damos_test_commit_quota_goals),
-- 
2.47.3

Reply via email to