Skip to content

Commit

Permalink
mm/damon/core-test: add a test for damon_set_attrs()
Browse files Browse the repository at this point in the history
Commit 5ff6e2f ("mm/damon/core: fix divide error in
damon_nr_accesses_to_accesses_bp()") fixed a bug by adding arguments
validation in damon_set_attrs().  Add a unit test for the added validation
to ensure the bug cannot occur again.

Link: https://lkml.kernel.org/r/20230615183323.87561-1-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
sjp38 authored and akpm00 committed Jun 19, 2023
1 parent 5d94995 commit aa13779
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mm/damon/core-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,29 @@ static void damon_test_update_monitoring_result(struct kunit *test)
KUNIT_EXPECT_EQ(test, r->age, 20);
}

static void damon_test_set_attrs(struct kunit *test)
{
struct damon_ctx ctx;
struct damon_attrs valid_attrs = {
.min_nr_regions = 10, .max_nr_regions = 1000,
.sample_interval = 5000, .aggr_interval = 100000,};
struct damon_attrs invalid_attrs;

KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &valid_attrs), 0);

invalid_attrs = valid_attrs;
invalid_attrs.min_nr_regions = 1;
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);

invalid_attrs = valid_attrs;
invalid_attrs.max_nr_regions = 9;
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);

invalid_attrs = valid_attrs;
invalid_attrs.aggr_interval = 4999;
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);
}

static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_target),
KUNIT_CASE(damon_test_regions),
Expand All @@ -329,6 +352,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_ops_registration),
KUNIT_CASE(damon_test_set_regions),
KUNIT_CASE(damon_test_update_monitoring_result),
KUNIT_CASE(damon_test_set_attrs),
{},
};

Expand Down

0 comments on commit aa13779

Please sign in to comment.