aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeongJae Park <sj@kernel.org>2025-11-11 10:44:00 -0800
committerAndrew Morton <akpm@linux-foundation.org>2025-11-20 13:43:59 -0800
commit37104286f9390a3da330c299b01cabfb4c98af7c (patch)
tree41af3a4a6e51ec70c1c55208fa3ff585e318e9af
parent7370f8e1b3a8b908b2a4a9d5d02970697e9aba62 (diff)
downloadtip-37104286f9390a3da330c299b01cabfb4c98af7c.tar.gz
mm/damon/tests/core-kunit: remove dynamic allocs on damos_test_commit_filter()
Patch series "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(). This patch (of 11): 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. Link: https://lkml.kernel.org/r/20251111184415.141757-1-sj@kernel.org Link: https://lkml.kernel.org/r/20251111184415.141757-2-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>
-rw-r--r--mm/damon/tests/core-kunit.h29
1 files changed, 13 insertions, 16 deletions
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 96a4cd489b393d..ae97886137dc5e 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -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)