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_goal() test

Add a new unit test for damos_commit_quota_goal().

Link: https://lkml.kernel.org/r/20251111184415.141757-6-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
99f89deb 3caf767e

+84
+84
mm/damon/tests/core-kunit.h
··· 497 497 damos_destroy_filter(filter); 498 498 } 499 499 500 + static void damos_test_commit_quota_goal_for(struct kunit *test, 501 + struct damos_quota_goal *dst, 502 + struct damos_quota_goal *src) 503 + { 504 + u64 dst_last_psi_total = 0; 505 + 506 + if (dst->metric == DAMOS_QUOTA_SOME_MEM_PSI_US) 507 + dst_last_psi_total = dst->last_psi_total; 508 + damos_commit_quota_goal(dst, src); 509 + 510 + KUNIT_EXPECT_EQ(test, dst->metric, src->metric); 511 + KUNIT_EXPECT_EQ(test, dst->target_value, src->target_value); 512 + if (src->metric == DAMOS_QUOTA_USER_INPUT) 513 + KUNIT_EXPECT_EQ(test, dst->current_value, src->current_value); 514 + if (dst_last_psi_total && src->metric == DAMOS_QUOTA_SOME_MEM_PSI_US) 515 + KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total); 516 + switch (dst->metric) { 517 + case DAMOS_QUOTA_NODE_MEM_USED_BP: 518 + case DAMOS_QUOTA_NODE_MEM_FREE_BP: 519 + KUNIT_EXPECT_EQ(test, dst->nid, src->nid); 520 + break; 521 + case DAMOS_QUOTA_NODE_MEMCG_USED_BP: 522 + case DAMOS_QUOTA_NODE_MEMCG_FREE_BP: 523 + KUNIT_EXPECT_EQ(test, dst->nid, src->nid); 524 + KUNIT_EXPECT_EQ(test, dst->memcg_id, src->memcg_id); 525 + break; 526 + default: 527 + break; 528 + } 529 + } 530 + 531 + static void damos_test_commit_quota_goal(struct kunit *test) 532 + { 533 + struct damos_quota_goal dst = { 534 + .metric = DAMOS_QUOTA_SOME_MEM_PSI_US, 535 + .target_value = 1000, 536 + .current_value = 123, 537 + .last_psi_total = 456, 538 + }; 539 + 540 + damos_test_commit_quota_goal_for(test, &dst, 541 + &(struct damos_quota_goal){ 542 + .metric = DAMOS_QUOTA_USER_INPUT, 543 + .target_value = 789, 544 + .current_value = 12}); 545 + damos_test_commit_quota_goal_for(test, &dst, 546 + &(struct damos_quota_goal){ 547 + .metric = DAMOS_QUOTA_NODE_MEM_FREE_BP, 548 + .target_value = 345, 549 + .current_value = 678, 550 + .nid = 9, 551 + }); 552 + damos_test_commit_quota_goal_for(test, &dst, 553 + &(struct damos_quota_goal){ 554 + .metric = DAMOS_QUOTA_NODE_MEM_USED_BP, 555 + .target_value = 12, 556 + .current_value = 345, 557 + .nid = 6, 558 + }); 559 + damos_test_commit_quota_goal_for(test, &dst, 560 + &(struct damos_quota_goal){ 561 + .metric = DAMOS_QUOTA_NODE_MEMCG_USED_BP, 562 + .target_value = 456, 563 + .current_value = 567, 564 + .nid = 6, 565 + .memcg_id = 7, 566 + }); 567 + damos_test_commit_quota_goal_for(test, &dst, 568 + &(struct damos_quota_goal){ 569 + .metric = DAMOS_QUOTA_NODE_MEMCG_FREE_BP, 570 + .target_value = 890, 571 + .current_value = 901, 572 + .nid = 10, 573 + .memcg_id = 1, 574 + }); 575 + damos_test_commit_quota_goal_for(test, &dst, 576 + &(struct damos_quota_goal) { 577 + .metric = DAMOS_QUOTA_USER_INPUT, 578 + .target_value = 789, 579 + .current_value = 12, 580 + }); 581 + } 582 + 500 583 static void damos_test_commit_filter_for(struct kunit *test, 501 584 struct damos_filter *dst, struct damos_filter *src) 502 585 { ··· 865 782 KUNIT_CASE(damon_test_set_attrs), 866 783 KUNIT_CASE(damon_test_moving_sum), 867 784 KUNIT_CASE(damos_test_new_filter), 785 + KUNIT_CASE(damos_test_commit_quota_goal), 868 786 KUNIT_CASE(damos_test_commit_filter), 869 787 KUNIT_CASE(damos_test_filter_out), 870 788 KUNIT_CASE(damon_test_feed_loop_next_input),