From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
Brendan Higgins <brendanhiggins@google.com>,
damon@lists.linux.dev, linux-mm@kvack.org,
kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 02/13] mm/damon/sysfs-schemes: support address range type DAMOS filter
Date: Fri, 28 Jul 2023 20:34:34 +0000 [thread overview]
Message-ID: <20230728203444.70703-4-sj@kernel.org> (raw)
In-Reply-To: <20230728203444.70703-1-sj@kernel.org>
Date: Sat, 22 Jul 2023 19:45:58 +0000
Subject: [RFC PATCH 03/13] mm/damon/core-test: add a unit test for
__damos_filter_out()
Implement a kunit test for the core of address range DAMOS filter
handling, namely __damos_filter_out(). The test especially focus on
regions that overlap with given filter's target address range.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core-test.h | 61 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index bb07721909e1..44e925bbb094 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -341,6 +341,66 @@ static void damon_test_set_attrs(struct kunit *test)
KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL);
}
+static void damos_test_filter_out(struct kunit *test)
+{
+ struct damon_target *t;
+ struct damon_region *r, *r2;
+ struct damos_filter *f;
+
+ f = damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true);
+ f->addr_range = (struct damon_addr_range){
+ .start = DAMON_MIN_REGION * 2, .end = DAMON_MIN_REGION * 6};
+
+ t = damon_new_target();
+ r = damon_new_region(DAMON_MIN_REGION * 3, DAMON_MIN_REGION * 5);
+ damon_add_region(r, t);
+
+ /* region in the range */
+ KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f));
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1);
+
+ /* region before the range */
+ r->ar.start = DAMON_MIN_REGION * 1;
+ r->ar.end = DAMON_MIN_REGION * 2;
+ KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f));
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1);
+
+ /* region after the range */
+ r->ar.start = DAMON_MIN_REGION * 6;
+ r->ar.end = DAMON_MIN_REGION * 8;
+ KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f));
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1);
+
+ /* region started before the range */
+ r->ar.start = DAMON_MIN_REGION * 1;
+ r->ar.end = DAMON_MIN_REGION * 4;
+ KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f));
+ /* filter should have split the region */
+ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1);
+ KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2);
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
+ r2 = damon_next_region(r);
+ KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 2);
+ KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 4);
+ damon_destroy_region(r2, t);
+
+ /* region started in the range */
+ r->ar.start = DAMON_MIN_REGION * 2;
+ r->ar.end = DAMON_MIN_REGION * 8;
+ KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f));
+ /* filter should have split the region */
+ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2);
+ KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6);
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
+ r2 = damon_next_region(r);
+ KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 6);
+ KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 8);
+ damon_destroy_region(r2, t);
+
+ damon_free_target(t);
+ damos_free_filter(f);
+}
+
static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_target),
KUNIT_CASE(damon_test_regions),
@@ -353,6 +413,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_filter_out),
{},
};
--
2.25.1
next prev parent reply other threads:[~2023-07-28 20:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 20:34 [RFC PATCH 00/13] Extedn DAMOS filters for address ranges and SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 01/13] mm/damon/core: introduce address range type damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 02/13] mm/damon/sysfs-schemes: support address range type DAMOS filter SeongJae Park
2023-07-28 20:34 ` SeongJae Park [this message]
2023-07-28 20:34 ` [RFC PATCH 04/13] selftests/damon/sysfs: test address range damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 05/13] Docs/mm/damon/design: update for address range filters SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 06/13] Docs/ABI/damon: update for address range DAMOS filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 07/13] Docs/admin-guide/mm/damon/usage: update for address range type " SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 08/13] mm/damon/core: implement target type damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 09/13] mm/damon/sysfs-schemes: support target " SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 10/13] selftests/damon/sysfs: test damon_target filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 11/13] Docs/mm/damon/design: update for DAMON monitoring target type DAMOS filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 12/13] Docs/ABI/damon: " SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 13/13] Docs/admin-guide/mm/damon/usage: " SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230728203444.70703-4-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendanhiggins@google.com \
--cc=damon@lists.linux.dev \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox