Skip to content

Commit aa13779

Browse files
sjp38akpm00
authored andcommitted
mm/damon/core-test: add a test for damon_set_attrs()
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/[email protected] Signed-off-by: SeongJae Park <[email protected]> Reviewed-by: Kefeng Wang <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5d94995 commit aa13779

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

mm/damon/core-test.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,29 @@ static void damon_test_update_monitoring_result(struct kunit *test)
318318
KUNIT_EXPECT_EQ(test, r->age, 20);
319319
}
320320

321+
static void damon_test_set_attrs(struct kunit *test)
322+
{
323+
struct damon_ctx ctx;
324+
struct damon_attrs valid_attrs = {
325+
.min_nr_regions = 10, .max_nr_regions = 1000,
326+
.sample_interval = 5000, .aggr_interval = 100000,};
327+
struct damon_attrs invalid_attrs;
328+
329+
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &valid_attrs), 0);
330+
331+
invalid_attrs = valid_attrs;
332+
invalid_attrs.min_nr_regions = 1;
333+
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);
334+
335+
invalid_attrs = valid_attrs;
336+
invalid_attrs.max_nr_regions = 9;
337+
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);
338+
339+
invalid_attrs = valid_attrs;
340+
invalid_attrs.aggr_interval = 4999;
341+
KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL);
342+
}
343+
321344
static struct kunit_case damon_test_cases[] = {
322345
KUNIT_CASE(damon_test_target),
323346
KUNIT_CASE(damon_test_regions),
@@ -329,6 +352,7 @@ static struct kunit_case damon_test_cases[] = {
329352
KUNIT_CASE(damon_test_ops_registration),
330353
KUNIT_CASE(damon_test_set_regions),
331354
KUNIT_CASE(damon_test_update_monitoring_result),
355+
KUNIT_CASE(damon_test_set_attrs),
332356
{},
333357
};
334358

0 commit comments

Comments
 (0)