[PATCH 01/11] mm/damon/tests/core-kunit: remove dynamic allocs on damos_test_commit_filter()

SeongJae Park posted 11 patches 2 months, 4 weeks ago
[PATCH 01/11] mm/damon/tests/core-kunit: remove dynamic allocs on damos_test_commit_filter()
Posted by SeongJae Park 2 months, 4 weeks ago
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.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/tests/core-kunit.h | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 96a4cd489b39..ae97886137dc 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)
-- 
2.47.3