Commit 99f89deb authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton
Browse files

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: default avatarSeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 3caf767e
Loading
Loading
Loading
Loading
+84 −0
Original line number Diff line number Diff line
@@ -497,6 +497,89 @@ static void damos_test_new_filter(struct kunit *test)
	damos_destroy_filter(filter);
}

static void damos_test_commit_quota_goal_for(struct kunit *test,
		struct damos_quota_goal *dst,
		struct damos_quota_goal *src)
{
	u64 dst_last_psi_total = 0;

	if (dst->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
		dst_last_psi_total = dst->last_psi_total;
	damos_commit_quota_goal(dst, src);

	KUNIT_EXPECT_EQ(test, dst->metric, src->metric);
	KUNIT_EXPECT_EQ(test, dst->target_value, src->target_value);
	if (src->metric == DAMOS_QUOTA_USER_INPUT)
		KUNIT_EXPECT_EQ(test, dst->current_value, src->current_value);
	if (dst_last_psi_total && src->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
		KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);
	switch (dst->metric) {
	case DAMOS_QUOTA_NODE_MEM_USED_BP:
	case DAMOS_QUOTA_NODE_MEM_FREE_BP:
		KUNIT_EXPECT_EQ(test, dst->nid, src->nid);
		break;
	case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
	case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
		KUNIT_EXPECT_EQ(test, dst->nid, src->nid);
		KUNIT_EXPECT_EQ(test, dst->memcg_id, src->memcg_id);
		break;
	default:
		break;
	}
}

static void damos_test_commit_quota_goal(struct kunit *test)
{
	struct damos_quota_goal dst = {
		.metric = DAMOS_QUOTA_SOME_MEM_PSI_US,
		.target_value = 1000,
		.current_value = 123,
		.last_psi_total = 456,
	};

	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal){
			.metric = DAMOS_QUOTA_USER_INPUT,
			.target_value = 789,
			.current_value = 12});
	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal){
			.metric = DAMOS_QUOTA_NODE_MEM_FREE_BP,
			.target_value = 345,
			.current_value = 678,
			.nid = 9,
			});
	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal){
			.metric = DAMOS_QUOTA_NODE_MEM_USED_BP,
			.target_value = 12,
			.current_value = 345,
			.nid = 6,
			});
	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal){
			.metric = DAMOS_QUOTA_NODE_MEMCG_USED_BP,
			.target_value = 456,
			.current_value = 567,
			.nid = 6,
			.memcg_id = 7,
			});
	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal){
			.metric = DAMOS_QUOTA_NODE_MEMCG_FREE_BP,
			.target_value = 890,
			.current_value = 901,
			.nid = 10,
			.memcg_id = 1,
			});
	damos_test_commit_quota_goal_for(test, &dst,
			&(struct damos_quota_goal) {
			.metric = DAMOS_QUOTA_USER_INPUT,
			.target_value = 789,
			.current_value = 12,
			});
}

static void damos_test_commit_filter_for(struct kunit *test,
		struct damos_filter *dst, struct damos_filter *src)
{
@@ -782,6 +865,7 @@ static struct kunit_case damon_test_cases[] = {
	KUNIT_CASE(damon_test_set_attrs),
	KUNIT_CASE(damon_test_moving_sum),
	KUNIT_CASE(damos_test_new_filter),
	KUNIT_CASE(damos_test_commit_quota_goal),
	KUNIT_CASE(damos_test_commit_filter),
	KUNIT_CASE(damos_test_filter_out),
	KUNIT_CASE(damon_test_feed_loop_next_input),