Skip to content

Commit

Permalink
mm/damon/core-test: add a test for damos_new_filter()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SeongJae Park authored and Andrew Morton committed Aug 21, 2023
1 parent ca39c5e commit 2a158e9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mm/damon/core-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
{},
};

Expand Down

0 comments on commit 2a158e9

Please sign in to comment.