Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/tests/core-kunit: add damos_commit_quota_goals() test

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>

authored by

SeongJae Park and committed by
Andrew Morton
d9adfb8a 99f89deb

+81
+81
mm/damon/tests/core-kunit.h
··· 580 580 }); 581 581 } 582 582 583 + static void damos_test_commit_quota_goals_for(struct kunit *test, 584 + struct damos_quota_goal *dst_goals, int nr_dst_goals, 585 + struct damos_quota_goal *src_goals, int nr_src_goals) 586 + { 587 + struct damos_quota dst, src; 588 + struct damos_quota_goal *goal, *next; 589 + bool skip = true; 590 + int i; 591 + 592 + INIT_LIST_HEAD(&dst.goals); 593 + INIT_LIST_HEAD(&src.goals); 594 + 595 + for (i = 0; i < nr_dst_goals; i++) { 596 + /* 597 + * When nr_src_goals is smaller than dst_goals, 598 + * damos_commit_quota_goals() will kfree() the dst goals. 599 + * Make it kfree()-able. 600 + */ 601 + goal = damos_new_quota_goal(dst_goals[i].metric, 602 + dst_goals[i].target_value); 603 + if (!goal) 604 + goto out; 605 + damos_add_quota_goal(&dst, goal); 606 + } 607 + skip = false; 608 + for (i = 0; i < nr_src_goals; i++) 609 + damos_add_quota_goal(&src, &src_goals[i]); 610 + 611 + damos_commit_quota_goals(&dst, &src); 612 + 613 + i = 0; 614 + damos_for_each_quota_goal(goal, (&dst)) { 615 + KUNIT_EXPECT_EQ(test, goal->metric, src_goals[i].metric); 616 + KUNIT_EXPECT_EQ(test, goal->target_value, 617 + src_goals[i++].target_value); 618 + } 619 + KUNIT_EXPECT_EQ(test, i, nr_src_goals); 620 + 621 + out: 622 + damos_for_each_quota_goal_safe(goal, next, (&dst)) 623 + damos_destroy_quota_goal(goal); 624 + if (skip) 625 + kunit_skip(test, "goal alloc fail"); 626 + } 627 + 628 + static void damos_test_commit_quota_goals(struct kunit *test) 629 + { 630 + damos_test_commit_quota_goals_for(test, 631 + (struct damos_quota_goal[]){}, 0, 632 + (struct damos_quota_goal[]){ 633 + { 634 + .metric = DAMOS_QUOTA_USER_INPUT, 635 + .target_value = 123, 636 + }, 637 + }, 1); 638 + damos_test_commit_quota_goals_for(test, 639 + (struct damos_quota_goal[]){ 640 + { 641 + .metric = DAMOS_QUOTA_USER_INPUT, 642 + .target_value = 234, 643 + }, 644 + 645 + }, 1, 646 + (struct damos_quota_goal[]){ 647 + { 648 + .metric = DAMOS_QUOTA_USER_INPUT, 649 + .target_value = 345, 650 + }, 651 + }, 1); 652 + damos_test_commit_quota_goals_for(test, 653 + (struct damos_quota_goal[]){ 654 + { 655 + .metric = DAMOS_QUOTA_USER_INPUT, 656 + .target_value = 456, 657 + }, 658 + 659 + }, 1, 660 + (struct damos_quota_goal[]){}, 0); 661 + } 662 + 583 663 static void damos_test_commit_filter_for(struct kunit *test, 584 664 struct damos_filter *dst, struct damos_filter *src) 585 665 { ··· 946 866 KUNIT_CASE(damon_test_moving_sum), 947 867 KUNIT_CASE(damos_test_new_filter), 948 868 KUNIT_CASE(damos_test_commit_quota_goal), 869 + KUNIT_CASE(damos_test_commit_quota_goals), 949 870 KUNIT_CASE(damos_test_commit_filter), 950 871 KUNIT_CASE(damos_test_filter_out), 951 872 KUNIT_CASE(damon_test_feed_loop_next_input),