linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core-test: add a test for damon_set_attrs()
@ 2023-06-15 18:33 SeongJae Park
  2023-06-16  1:48 ` Kefeng Wang
  0 siblings, 1 reply; 2+ messages in thread
From: SeongJae Park @ 2023-06-15 18:33 UTC (permalink / raw)
  To: akpm; +Cc: SeongJae Park, wangkefeng.wang, damon, linux-mm, linux-kernel

Commit 5ff6e2fff88e ("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.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core-test.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index fae64d32b925..c11210124344 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -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),
@@ -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),
 	{},
 };
 
-- 
2.25.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/damon/core-test: add a test for damon_set_attrs()
  2023-06-15 18:33 [PATCH] mm/damon/core-test: add a test for damon_set_attrs() SeongJae Park
@ 2023-06-16  1:48 ` Kefeng Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Kefeng Wang @ 2023-06-16  1:48 UTC (permalink / raw)
  To: SeongJae Park, akpm; +Cc: damon, linux-mm, linux-kernel



On 2023/6/16 2:33, SeongJae Park wrote:
> Commit 5ff6e2fff88e ("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.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>


Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>

> ---
>   mm/damon/core-test.h | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> index fae64d32b925..c11210124344 100644
> --- a/mm/damon/core-test.h
> +++ b/mm/damon/core-test.h
> @@ -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),
> @@ -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),
>   	{},
>   };
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-16  1:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 18:33 [PATCH] mm/damon/core-test: add a test for damon_set_attrs() SeongJae Park
2023-06-16  1:48 ` Kefeng Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox