]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/tests/core-kunit: add damos_commit_quota_goals() test
authorSeongJae Park <sj@kernel.org>
Tue, 11 Nov 2025 18:44:05 +0000 (10:44 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 20 Nov 2025 21:44:00 +0000 (13:44 -0800)
Add a new unit test for damos_commit_quota_goals().

Link: https://lkml.kernel.org/r/20251111184415.141757-7-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/tests/core-kunit.h

index 0fdf9c7eedc3484508a819b6f6565707c6418ad6..3abf31fb1074aa5c08c0061ba93e2f16a1decd4d 100644 (file)
@@ -580,6 +580,86 @@ static void damos_test_commit_quota_goal(struct kunit *test)
                        });
 }
 
+static void damos_test_commit_quota_goals_for(struct kunit *test,
+               struct damos_quota_goal *dst_goals, int nr_dst_goals,
+               struct damos_quota_goal *src_goals, int nr_src_goals)
+{
+       struct damos_quota dst, src;
+       struct damos_quota_goal *goal, *next;
+       bool skip = true;
+       int i;
+
+       INIT_LIST_HEAD(&dst.goals);
+       INIT_LIST_HEAD(&src.goals);
+
+       for (i = 0; i < nr_dst_goals; i++) {
+               /*
+                * When nr_src_goals is smaller than dst_goals,
+                * damos_commit_quota_goals() will kfree() the dst goals.
+                * Make it kfree()-able.
+                */
+               goal = damos_new_quota_goal(dst_goals[i].metric,
+                               dst_goals[i].target_value);
+               if (!goal)
+                       goto out;
+               damos_add_quota_goal(&dst, goal);
+       }
+       skip = false;
+       for (i = 0; i < nr_src_goals; i++)
+               damos_add_quota_goal(&src, &src_goals[i]);
+
+       damos_commit_quota_goals(&dst, &src);
+
+       i = 0;
+       damos_for_each_quota_goal(goal, (&dst)) {
+               KUNIT_EXPECT_EQ(test, goal->metric, src_goals[i].metric);
+               KUNIT_EXPECT_EQ(test, goal->target_value,
+                               src_goals[i++].target_value);
+       }
+       KUNIT_EXPECT_EQ(test, i, nr_src_goals);
+
+out:
+       damos_for_each_quota_goal_safe(goal, next, (&dst))
+               damos_destroy_quota_goal(goal);
+       if (skip)
+               kunit_skip(test, "goal alloc fail");
+}
+
+static void damos_test_commit_quota_goals(struct kunit *test)
+{
+       damos_test_commit_quota_goals_for(test,
+                       (struct damos_quota_goal[]){}, 0,
+                       (struct damos_quota_goal[]){
+                               {
+                               .metric = DAMOS_QUOTA_USER_INPUT,
+                               .target_value = 123,
+                               },
+                       }, 1);
+       damos_test_commit_quota_goals_for(test,
+                       (struct damos_quota_goal[]){
+                               {
+                               .metric = DAMOS_QUOTA_USER_INPUT,
+                               .target_value = 234,
+                               },
+
+                       }, 1,
+                       (struct damos_quota_goal[]){
+                               {
+                               .metric = DAMOS_QUOTA_USER_INPUT,
+                               .target_value = 345,
+                               },
+                       }, 1);
+       damos_test_commit_quota_goals_for(test,
+                       (struct damos_quota_goal[]){
+                               {
+                               .metric = DAMOS_QUOTA_USER_INPUT,
+                               .target_value = 456,
+                               },
+
+                       }, 1,
+                       (struct damos_quota_goal[]){}, 0);
+}
+
 static void damos_test_commit_filter_for(struct kunit *test,
                struct damos_filter *dst, struct damos_filter *src)
 {
@@ -866,6 +946,7 @@ static struct kunit_case damon_test_cases[] = {
        KUNIT_CASE(damon_test_moving_sum),
        KUNIT_CASE(damos_test_new_filter),
        KUNIT_CASE(damos_test_commit_quota_goal),
+       KUNIT_CASE(damos_test_commit_quota_goals),
        KUNIT_CASE(damos_test_commit_filter),
        KUNIT_CASE(damos_test_filter_out),
        KUNIT_CASE(damon_test_feed_loop_next_input),