summaryrefslogtreecommitdiff
path: root/mm/damon
diff options
context:
space:
mode:
authorSeongJae Park <sj@kernel.org>2023-07-29 20:37:33 +0000
committerAndrew Morton <akpm@linux-foundation.org>2023-08-21 13:37:33 -0700
commit2a158e956b98e0c5f37b5ce9953048654348ad6b (patch)
tree7d215c4cf0dfa47761882e4f626b0e894e8319af /mm/damon
parentca39c5e7d10f09983293f064caa447690cb3ec92 (diff)
downloadlinux-starfive-2a158e956b98e0c5f37b5ce9953048654348ad6b.tar.gz
linux-starfive-2a158e956b98e0c5f37b5ce9953048654348ad6b.tar.bz2
linux-starfive-2a158e956b98e0c5f37b5ce9953048654348ad6b.zip
mm/damon/core-test: add a test for damos_new_filter()
damos_new_filter() was having a bug that not initializing ->list field of the returning damos_filter struct, which results in access to uninitialized memory. Add a unit test for the function. Link: https://lkml.kernel.org/r/20230729203733.38949-3-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/damon')
-rw-r--r--mm/damon/core-test.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index bb07721909e1..4bddbfe243c3 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -341,6 +341,18 @@ static void damon_test_set_attrs(struct kunit *test)
KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL);
}
+static void damos_test_new_filter(struct kunit *test)
+{
+ struct damos_filter *filter;
+
+ filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true);
+ KUNIT_EXPECT_EQ(test, filter->type, DAMOS_FILTER_TYPE_ANON);
+ KUNIT_EXPECT_EQ(test, filter->matching, true);
+ KUNIT_EXPECT_PTR_EQ(test, filter->list.prev, &filter->list);
+ KUNIT_EXPECT_PTR_EQ(test, filter->list.next, &filter->list);
+ damos_destroy_filter(filter);
+}
+
static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_target),
KUNIT_CASE(damon_test_regions),
@@ -353,6 +365,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_set_regions),
KUNIT_CASE(damon_test_update_monitoring_result),
KUNIT_CASE(damon_test_set_attrs),
+ KUNIT_CASE(damos_test_new_filter),
{},
};