mm/damon/tests: add more tests for online parameters commit
Subsystems (3)
SeongJae Park
maintainercover mm/damon/tests: add more tests for online parameters commit
A DAMON feature called parameters "commit" allows DAMON API callers and ABI users to update nearly every DAMON parameter while DAMON is running. This is being used for flexible DAMON use cases such as taking a snapshot of the monitoring results with minimum overhead, or adjusting access-aware system operations (DAMOS) for user-space driven auto-tuning or investigations.
Compared to the usefulness of the feature and size of the implementation, the test coverage is pretty small. Only the filter commit part has a single test case, namely damos_test_commit_filter(). Actually, we found and fixed a few bugs of the feature in the past. The single existing test was also added to avoid reintroduction of a found bug.
Add more unit tests for the feature.
First four patches (1-4) refactor and extend the existing test for DAMOS filter commit for multiple test cases.
Next three patches (5-7) add tests for DAMOS quota commit.
Next two patches (8 and 9) refactor damos_commit_dests() for ease of code reading and test writing, and implement a new unit test of the function that is being refactored in a test-friendly way.
Final two patches (10 and 11) further add new unit tests for damos_commit() and damon_commit_target_regions().
SeongJae Park (11):
mm/damon/tests/core-kunit: remove dynamic allocs on
damos_test_commit_filter()
mm/damon/tests/core-kunit: split out damos_test_commit_filter() core
logic
mm/damon/tests/core-kunit: extend damos_test_commit_filter_for() for
union fields
mm/damon/tests/core-kunit: add test cases to
damos_test_commit_filter()
mm/damon/tests/core-kunit: add damos_commit_quota_goal() test mm/damon/tests/core-kunit: add damos_commit_quota_goals() test mm/damon/tests/core-kunit: add damos_commit_quota() test mm/damon/core: pass migrate_dests to damos_commit_dests() mm/damon/tests/core-kunit: add damos_commit_dests() test mm/damon/tests/core-kunit: add damos_commit() test mm/damon/tests/core-kunit: add damon_commit_target_regions() test
mm/damon/core.c | 38 ++- mm/damon/tests/core-kunit.h | 544 +++++++++++++++++++++++++++++++++++- 2 files changed, 547 insertions(+), 35 deletions(-)
base-commit: 620a4c1c5116eb811807ea7e63d61846015f69c8
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 1/11 mm/damon/tests/core-kunit: remove dynamic allocs on damos_test_commit_filter()
damos_test_commit_filter() is dynamically allocating test-purpose DAMOS filters. Allocation failure checks are making the code longer, complicated, and difficult to extend for more test cases. Refactor the code to remove the dynamic allocation.
--- mm/damon/tests/core-kunit.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
mm/damon/tests/core-kunit.h +13 -16
@@ -499,23 +499,20 @@ static void damos_test_new_filter(struct kunit *test)static void damos_test_commit_filter (struct kunit *test) { -struct damos_filter *src_filter, *dst_filter; - - src_filter =damos_new_filter (DAMOS_FILTER_TYPE_ANON , true, true); -if (!src_filter) -kunit_skip (test,"src filter alloc fail" ); - dst_filter =damos_new_filter (DAMOS_FILTER_TYPE_ACTIVE , false, false); -if (!dst_filter) { -damos_destroy_filter (src_filter); -kunit_skip (test,"dst filter alloc fail" ); - } -damos_commit_filter (dst_filter, src_filter); -KUNIT_EXPECT_EQ (test, dst_filter->type, src_filter->type); -KUNIT_EXPECT_EQ (test, dst_filter->matching, src_filter->matching); -KUNIT_EXPECT_EQ (test, dst_filter->allow, src_filter->allow); +struct damos_filter src_filter = { + .type =DAMOS_FILTER_TYPE_ANON , + .matching = true, + .allow = true}; +struct damos_filter dst_filter = { + .type =DAMOS_FILTER_TYPE_ACTIVE , + .matching = false, + .allow = false, + }; -damos_destroy_filter (src_filter); -damos_destroy_filter (dst_filter); +damos_commit_filter (&dst_filter, &src_filter); +KUNIT_EXPECT_EQ (test, dst_filter.type, src_filter.type); +KUNIT_EXPECT_EQ (test, dst_filter.matching, src_filter.matching); +KUNIT_EXPECT_EQ (test, dst_filter.allow, src_filter.allow); }static void damos_test_filter_out (struct kunit *test)
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 2/11 mm/damon/tests/core-kunit: split out damos_test_commit_filter() core logic
In reply to SeongJae Parkdamos_test_commit_filter() is written for only a single test case. Split out the core logic of damos_test_commit_filter() as a general one so that it can be reused for multiple test cases.
--- mm/damon/tests/core-kunit.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
mm/damon/tests/core-kunit.h +10 -4
@@ -497,6 +497,15 @@ static void damos_test_new_filter(struct kunit *test)damos_destroy_filter (filter); } +static void damos_test_commit_filter_for (struct kunit *test, +struct damos_filter *dst,struct damos_filter *src) +{ +damos_commit_filter (dst, src); +KUNIT_EXPECT_EQ (test, dst->type, src->type); +KUNIT_EXPECT_EQ (test, dst->matching, src->matching); +KUNIT_EXPECT_EQ (test, dst->allow, src->allow); +} +static void damos_test_commit_filter (struct kunit *test) {struct damos_filter src_filter = {
@@ -509,10 +518,7 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, }; -damos_commit_filter (&dst_filter, &src_filter); -KUNIT_EXPECT_EQ (test, dst_filter.type, src_filter.type); -KUNIT_EXPECT_EQ (test, dst_filter.matching, src_filter.matching); -KUNIT_EXPECT_EQ (test, dst_filter.allow, src_filter.allow); +damos_test_commit_filter_for (test, &dst_filter, &src_filter); }static void damos_test_filter_out (struct kunit *test)
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 3/11 mm/damon/tests/core-kunit: extend damos_test_commit_filter_for() for union fields
In reply to SeongJae Parkdamos_commit_filter() also updates union fields of 'struct damos_filter'. Extend damos_test_commit_filter_for() to cover the expectations of the union fields.
--- mm/damon/tests/core-kunit.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
mm/damon/tests/core-kunit.h +20 -0
@@ -504,6 +504,26 @@ static void damos_test_commit_filter_for(struct kunit *test,KUNIT_EXPECT_EQ (test, dst->type, src->type);KUNIT_EXPECT_EQ (test, dst->matching, src->matching);KUNIT_EXPECT_EQ (test, dst->allow, src->allow); +switch (src->type) { +case DAMOS_FILTER_TYPE_MEMCG : +KUNIT_EXPECT_EQ (test, dst->memcg_id, src->memcg_id); +break ; +case DAMOS_FILTER_TYPE_ADDR : +KUNIT_EXPECT_EQ (test, dst->addr_range.start, + src->addr_range.start); +KUNIT_EXPECT_EQ (test, dst->addr_range.end, + src->addr_range.end); +break ; +case DAMOS_FILTER_TYPE_TARGET : +KUNIT_EXPECT_EQ (test, dst->target_idx, src->target_idx); +break ; +case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE : +KUNIT_EXPECT_EQ (test, dst->sz_range.min, src->sz_range.min); +KUNIT_EXPECT_EQ (test, dst->sz_range.max, src->sz_range.max); +break ; +default : +break ; + } }static void damos_test_commit_filter (struct kunit *test)
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 4/11 mm/damon/tests/core-kunit: add test cases to damos_test_commit_filter()
In reply to SeongJae Parkdamos_test_commit_filter() is covering only a single test case. Extend it to cover multiple combinations of inputs.
--- mm/damon/tests/core-kunit.h | 53 ++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-)
mm/damon/tests/core-kunit.h +47 -6
@@ -528,17 +528,58 @@ static void damos_test_commit_filter_for(struct kunit *test,static void damos_test_commit_filter (struct kunit *test) { -struct damos_filter src_filter = { - .type =DAMOS_FILTER_TYPE_ANON , - .matching = true, - .allow = true}; -struct damos_filter dst_filter = { +struct damos_filter dst = { .type =DAMOS_FILTER_TYPE_ACTIVE , .matching = false, .allow = false, }; -damos_test_commit_filter_for (test, &dst_filter, &src_filter); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_ANON , + .matching = true, + .allow = true, + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_MEMCG , + .matching = false, + .allow = false, + .memcg_id =123 , + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_YOUNG , + .matching = true, + .allow = true, + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_HUGEPAGE_SIZE , + .matching = false, + .allow = false, + .sz_range = {.min =234 , .max =345 }, + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_UNMAPPED , + .matching = true, + .allow = true, + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_ADDR , + .matching = false, + .allow = false, + .addr_range = {.start =456 , .end =567 }, + }); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_TARGET , + .matching = true, + .allow = true, + .target_idx =6 , + }); }static void damos_test_filter_out (struct kunit *test)
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 5/11 mm/damon/tests/core-kunit: add damos_commit_quota_goal() test
In reply to SeongJae ParkAdd a new unit test for damos_commit_quota_goal().
--- mm/damon/tests/core-kunit.h | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
mm/damon/tests/core-kunit.h +84 -0
@@ -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),
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 6/11 mm/damon/tests/core-kunit: add damos_commit_quota_goals() test
In reply to SeongJae ParkAdd a new unit test for damos_commit_quota_goals().
--- mm/damon/tests/core-kunit.h | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
mm/damon/tests/core-kunit.h +81 -0
@@ -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),
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 7/11 mm/damon/tests/core-kunit: add damos_commit_quota() test
In reply to SeongJae ParkAdd a new unit test for damos_commit_quota().
--- mm/damon/tests/core-kunit.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
mm/damon/tests/core-kunit.h +33 -0
@@ -660,6 +660,38 @@ static void damos_test_commit_quota_goals(struct kunit *test) (struct damos_quota_goal[]){}, 0); } +static void damos_test_commit_quota (struct kunit *test) +{ +struct damos_quota dst = { + .reset_interval =1 , + .ms =2 , + .sz =3 , + .weight_sz =4 , + .weight_nr_accesses =5 , + .weight_age =6 , + }; +struct damos_quota src = { + .reset_interval =7 , + .ms =8 , + .sz =9 , + .weight_sz =10 , + .weight_nr_accesses =11 , + .weight_age =12 , + }; + +INIT_LIST_HEAD (&dst.goals); +INIT_LIST_HEAD (&src.goals); + +damos_commit_quota (&dst, &src); + +KUNIT_EXPECT_EQ (test, dst.reset_interval, src.reset_interval); +KUNIT_EXPECT_EQ (test, dst.ms, src.ms); +KUNIT_EXPECT_EQ (test, dst.sz, src.sz); +KUNIT_EXPECT_EQ (test, dst.weight_sz, src.weight_sz); +KUNIT_EXPECT_EQ (test, dst.weight_nr_accesses, src.weight_nr_accesses); +KUNIT_EXPECT_EQ (test, dst.weight_age, src.weight_age); +} +static void damos_test_commit_filter_for (struct kunit *test,struct damos_filter *dst,struct damos_filter *src) {
@@ -947,6 +979,7 @@ static struct kunit_case damon_test_cases[] = {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_quota),KUNIT_CASE (damos_test_commit_filter),KUNIT_CASE (damos_test_filter_out), KUNIT_CASE(damon_test_feed_loop_next_input),
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 8/11 mm/damon/core: pass migrate_dests to damos_commit_dests()
In reply to SeongJae Parkdamos_commit_dests() receives 'struct damos' pointers, while it uses only their ->migrate_dests fields. This makes code unnecessarily difficult to read. It also makes unit tests writing complicated. Refactor the function to receive pointers to the ->migrate_dests fields.
--- mm/damon/core.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
mm/damon/core.c +17 -21
@@ -1000,36 +1000,32 @@ static void damos_set_filters_default_reject(struct damos *s)damos_filters_default_reject (&s->ops_filters); } -static int damos_commit_dests (struct damos *dst,struct damos *src) +static int damos_commit_dests (struct damos_migrate_dests *dst, +struct damos_migrate_dests *src) { -struct damos_migrate_dests *dst_dests, *src_dests; +if (dst->nr_dests != src->nr_dests) { +kfree (dst->node_id_arr); +kfree (dst->weight_arr); - dst_dests = &dst->migrate_dests; - src_dests = &src->migrate_dests; - -if (dst_dests->nr_dests != src_dests->nr_dests) { -kfree (dst_dests->node_id_arr); -kfree (dst_dests->weight_arr); - - dst_dests->node_id_arr =kmalloc_array (src_dests->nr_dests, -sizeof (*dst_dests->node_id_arr),GFP_KERNEL ); -if (!dst_dests->node_id_arr) { - dst_dests->weight_arr =NULL ; + dst->node_id_arr =kmalloc_array (src->nr_dests, +sizeof (*dst->node_id_arr),GFP_KERNEL ); +if (!dst->node_id_arr) { + dst->weight_arr =NULL ;return -ENOMEM ; } - dst_dests->weight_arr =kmalloc_array (src_dests->nr_dests, -sizeof (*dst_dests->weight_arr),GFP_KERNEL ); -if (!dst_dests->weight_arr) { + dst->weight_arr =kmalloc_array (src->nr_dests, +sizeof (*dst->weight_arr),GFP_KERNEL ); +if (!dst->weight_arr) {/* ->node_id_arr will be freed by scheme destruction */ return -ENOMEM ; } } - dst_dests->nr_dests = src_dests->nr_dests; -for (int i =0 ; i < src_dests->nr_dests; i++) { - dst_dests->node_id_arr[i] = src_dests->node_id_arr[i]; - dst_dests->weight_arr[i] = src_dests->weight_arr[i]; + dst->nr_dests = src->nr_dests; +for (int i =0 ; i < src->nr_dests; i++) { + dst->node_id_arr[i] = src->node_id_arr[i]; + dst->weight_arr[i] = src->weight_arr[i]; }return 0 ;
@@ -1076,7 +1072,7 @@ static int damos_commit(struct damos *dst, struct damos *src) dst->wmarks = src->wmarks; dst->target_nid = src->target_nid; - err =damos_commit_dests (dst, src); + err =damos_commit_dests (&dst->migrate_dests, &src->migrate_dests);if (err)return err;
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 9/11 mm/damon/tests/core-kunit: add damos_commit_dests() test
In reply to SeongJae ParkAdd a new unit test for damos_commit_dests().
--- mm/damon/tests/core-kunit.h | 97 +++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
mm/damon/tests/core-kunit.h +97 -0
@@ -692,6 +692,102 @@ static void damos_test_commit_quota(struct kunit *test)KUNIT_EXPECT_EQ (test, dst.weight_age, src.weight_age); } +static int damos_test_help_dests_setup (struct damos_migrate_dests *dests, +unsigned int *node_id_arr,unsigned int *weight_arr, +size_t nr_dests) +{ +size_t i; + + dests->node_id_arr =kmalloc_array (nr_dests, +sizeof (*dests->node_id_arr),GFP_KERNEL ); +if (!dests->node_id_arr) +return -ENOMEM ; + dests->weight_arr =kmalloc_array (nr_dests, +sizeof (*dests->weight_arr),GFP_KERNEL ); +if (!dests->weight_arr) { +kfree (dests->node_id_arr); + dests->node_id_arr =NULL ; +return -ENOMEM ; + } + +for (i =0 ; i < nr_dests; i++) { + dests->node_id_arr[i] = node_id_arr[i]; + dests->weight_arr[i] = weight_arr[i]; + } + dests->nr_dests = nr_dests; +return 0 ; +} + +static void damos_test_help_dests_free (struct damos_migrate_dests *dests) +{ +kfree (dests->node_id_arr); +kfree (dests->weight_arr); +} + +static void damos_test_commit_dests_for (struct kunit *test, +unsigned int *dst_node_id_arr,unsigned int *dst_weight_arr, +size_t dst_nr_dests, +unsigned int *src_node_id_arr,unsigned int *src_weight_arr, +size_t src_nr_dests) +{ +struct damos_migrate_dests dst = {}, src = {}; +int i, err; +bool skip = true; + + err =damos_test_help_dests_setup (&dst, dst_node_id_arr, + dst_weight_arr, dst_nr_dests); +if (err) +kunit_skip (test,"dests setup fail" ); + err =damos_test_help_dests_setup (&src, src_node_id_arr, + src_weight_arr, src_nr_dests); +if (err) { +damos_test_help_dests_free (&dst); +kunit_skip (test,"src setup fail" ); + } + err =damos_commit_dests (&dst, &src); +if (err) + goto out; + skip = false; + +KUNIT_EXPECT_EQ (test, dst.nr_dests, src_nr_dests); +for (i =0 ; i < dst.nr_dests; i++) { +KUNIT_EXPECT_EQ (test, dst.node_id_arr[i], src_node_id_arr[i]); +KUNIT_EXPECT_EQ (test, dst.weight_arr[i], src_weight_arr[i]); + } + +out: +damos_test_help_dests_free (&dst); +damos_test_help_dests_free (&src); +if (skip) +kunit_skip (test,"skip" ); +} + +static void damos_test_commit_dests (struct kunit *test) +{ +damos_test_commit_dests_for (test, + (unsigned int []){1 ,2 ,3 }, (unsigned int []){2 ,3 ,4 }, +3 , + (unsigned int []){4 ,5 ,6 }, (unsigned int []){5 ,6 ,7 }, +3 ); +damos_test_commit_dests_for (test, + (unsigned int []){1 ,2 }, (unsigned int []){2 ,3 }, +2 , + (unsigned int []){4 ,5 ,6 }, (unsigned int []){5 ,6 ,7 }, +3 ); +damos_test_commit_dests_for (test, +NULL ,NULL ,0 , + (unsigned int []){4 ,5 ,6 }, (unsigned int []){5 ,6 ,7 }, +3 ); +damos_test_commit_dests_for (test, + (unsigned int []){1 ,2 ,3 }, (unsigned int []){2 ,3 ,4 }, +3 , + (unsigned int []){4 ,5 }, (unsigned int []){5 ,6 },2 ); +damos_test_commit_dests_for (test, + (unsigned int []){1 ,2 ,3 }, (unsigned int []){2 ,3 ,4 }, +3 , +NULL ,NULL ,0 ); +} +static void damos_test_commit_filter_for (struct kunit *test,struct damos_filter *dst,struct damos_filter *src) {
@@ -980,6 +1076,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damos_test_commit_quota_goal),KUNIT_CASE (damos_test_commit_quota_goals),KUNIT_CASE (damos_test_commit_quota), +KUNIT_CASE (damos_test_commit_dests),KUNIT_CASE (damos_test_commit_filter),KUNIT_CASE (damos_test_filter_out), KUNIT_CASE(damon_test_feed_loop_next_input),
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 10/11 mm/damon/tests/core-kunit: add damos_commit() test
In reply to SeongJae ParkAdd a new unit test for damos_commit().
--- mm/damon/tests/core-kunit.h | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)
mm/damon/tests/core-kunit.h +92 -0
@@ -873,6 +873,97 @@ static void damos_test_commit_filter(struct kunit *test) }); } +static void damos_test_help_initailize_scheme (struct damos *scheme) +{ +INIT_LIST_HEAD (&scheme->quota.goals); +INIT_LIST_HEAD (&scheme->filters); +INIT_LIST_HEAD (&scheme->ops_filters); +} + +static void damos_test_commit_for (struct kunit *test,struct damos *dst, +struct damos *src) +{ +int err; + +damos_test_help_initailize_scheme (dst); +damos_test_help_initailize_scheme (src); + + err =damos_commit (dst, src); +if (err) +kunit_skip (test,"damos_commit fail" ); + +KUNIT_EXPECT_EQ (test, dst->pattern.min_sz_region, + src->pattern.min_sz_region); +KUNIT_EXPECT_EQ (test, dst->pattern.max_sz_region, + src->pattern.max_sz_region); +KUNIT_EXPECT_EQ (test, dst->pattern.min_nr_accesses, + src->pattern.min_nr_accesses); +KUNIT_EXPECT_EQ (test, dst->pattern.max_nr_accesses, + src->pattern.max_nr_accesses); +KUNIT_EXPECT_EQ (test, dst->pattern.min_age_region, + src->pattern.min_age_region); +KUNIT_EXPECT_EQ (test, dst->pattern.max_age_region, + src->pattern.max_age_region); + +KUNIT_EXPECT_EQ (test, dst->action, src->action); +KUNIT_EXPECT_EQ (test, dst->apply_interval_us, src->apply_interval_us); + +KUNIT_EXPECT_EQ (test, dst->wmarks.metric, src->wmarks.metric); +KUNIT_EXPECT_EQ (test, dst->wmarks.interval, src->wmarks.interval); +KUNIT_EXPECT_EQ (test, dst->wmarks.high, src->wmarks.high); +KUNIT_EXPECT_EQ (test, dst->wmarks.mid, src->wmarks.mid); +KUNIT_EXPECT_EQ (test, dst->wmarks.low, src->wmarks.low); + +switch (src->action) { +case DAMOS_MIGRATE_COLD : +case DAMOS_MIGRATE_HOT : +KUNIT_EXPECT_EQ (test, dst->target_nid, src->target_nid); +break ; +default : +break ; + } +} + +static void damos_test_commit (struct kunit *test) +{ +damos_test_commit_for (test, + &(struct damos ){ + .pattern = (struct damos_access_pattern ){ +1 ,2 ,3 ,4 ,5 ,6 }, + .action =DAMOS_PAGEOUT , + .apply_interval_us =1000000 , + .wmarks = (struct damos_watermarks ){ +DAMOS_WMARK_FREE_MEM_RATE , +900 ,100 ,50 }, + }, + &(struct damos ){ + .pattern = (struct damos_access_pattern ){ +2 ,3 ,4 ,5 ,6 ,7 }, + .action =DAMOS_PAGEOUT , + .apply_interval_us =2000000 , + .wmarks = (struct damos_watermarks ){ +DAMOS_WMARK_FREE_MEM_RATE , +800 ,50 ,30 }, + }); +damos_test_commit_for (test, + &(struct damos ){ + .pattern = (struct damos_access_pattern ){ +1 ,2 ,3 ,4 ,5 ,6 }, + .action =DAMOS_PAGEOUT , + .apply_interval_us =1000000 , + .wmarks = (struct damos_watermarks ){ +DAMOS_WMARK_FREE_MEM_RATE , +900 ,100 ,50 }, + }, + &(struct damos ){ + .pattern = (struct damos_access_pattern ){ +2 ,3 ,4 ,5 ,6 ,7 }, + .action =DAMOS_MIGRATE_HOT , + .apply_interval_us =2000000 , + .target_nid =5 , + }); +} +static void damos_test_filter_out (struct kunit *test) {struct damon_target *t;
@@ -1078,6 +1169,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damos_test_commit_quota),KUNIT_CASE (damos_test_commit_dests),KUNIT_CASE (damos_test_commit_filter), +KUNIT_CASE (damos_test_commit),KUNIT_CASE (damos_test_filter_out),KUNIT_CASE (damon_test_feed_loop_next_input), KUNIT_CASE(damon_test_set_filters_default_reject),
Signature · 1 line
2.47.3
SeongJae Park
maintainerPATCH 11/11 mm/damon/tests/core-kunit: add damon_commit_target_regions() test
In reply to SeongJae ParkAdd a new test for damon_commit_target_regions().
--- mm/damon/tests/core-kunit.h | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
mm/damon/tests/core-kunit.h +65 -0
@@ -964,6 +964,70 @@ static void damos_test_commit(struct kunit *test) }); } +static struct damon_target *damon_test_help_setup_target ( +unsigned long region_start_end[][2 ],int nr_regions) +{ +struct damon_target *t; +struct damon_region *r; +int i; + + t =damon_new_target (); +if (!t) +return NULL ; +for (i =0 ; i < nr_regions; i++) { + r =damon_new_region (region_start_end[i][0 ], + region_start_end[i][1 ]); +if (!r) { +damon_free_target (t); +return NULL ; + } +damon_add_region (r, t); + } +return t; +} + +static void damon_test_commit_target_regions_for (struct kunit *test, +unsigned long dst_start_end[][2 ],int nr_dst_regions, +unsigned long src_start_end[][2 ],int nr_src_regions, +unsigned long expect_start_end[][2 ],int nr_expect_regions) +{ +struct damon_target *dst_target, *src_target; +struct damon_region *r; +int i; + + dst_target =damon_test_help_setup_target (dst_start_end, nr_dst_regions); +if (!dst_target) +kunit_skip (test,"dst target setup fail" ); + src_target =damon_test_help_setup_target (src_start_end, nr_src_regions); +if (!src_target) { +damon_free_target (dst_target); +kunit_skip (test,"src target setup fail" ); + } +damon_commit_target_regions (dst_target, src_target,1 ); + i =0 ; +damon_for_each_region (r, dst_target) { +KUNIT_EXPECT_EQ (test, r->ar.start, expect_start_end[i][0 ]); +KUNIT_EXPECT_EQ (test, r->ar.end, expect_start_end[i][1 ]); + i++; + } +KUNIT_EXPECT_EQ (test,damon_nr_regions (dst_target), nr_expect_regions); +KUNIT_EXPECT_EQ (test, i, nr_expect_regions); +damon_free_target (dst_target); +damon_free_target (src_target); +} + +static void damon_test_commit_target_regions (struct kunit *test) +{ +damon_test_commit_target_regions_for (test, + (unsigned long [][2 ]) {{3 ,8 }, {8 ,10 }},2 , + (unsigned long [][2 ]) {{4 ,6 }},1 , + (unsigned long [][2 ]) {{4 ,6 }},1 ); +damon_test_commit_target_regions_for (test, + (unsigned long [][2 ]) {{3 ,8 }, {8 ,10 }},2 , + (unsigned long [][2 ]) {},0 , + (unsigned long [][2 ]) {{3 ,8 }, {8 ,10 }},2 ); +} +static void damos_test_filter_out (struct kunit *test) {struct damon_target *t;
@@ -1170,6 +1234,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damos_test_commit_dests),KUNIT_CASE (damos_test_commit_filter),KUNIT_CASE (damos_test_commit), +KUNIT_CASE (damon_test_commit_target_regions),KUNIT_CASE (damos_test_filter_out),KUNIT_CASE (damon_test_feed_loop_next_input), KUNIT_CASE(damon_test_set_filters_default_reject),
Signature · 1 line
2.47.3