From: SeongJae Park <sj@kernel.org>
To: akpm@linux-foundation.org
Cc: SeongJae Park <sj@kernel.org>,
Jonathan.Cameron@Huawei.com, amit@kernel.org,
benh@kernel.crashing.org, corbet@lwn.net, david@redhat.com,
dwmw@amazon.com, elver@google.com, foersleo@amazon.de,
gthelen@google.com, markubo@amazon.de, rientjes@google.com,
shakeelb@google.com, shuah@kernel.org, linux-damon@amazon.com,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] mm/damon/dbgfs-test: Implement kunit tests for the record feature
Date: Fri, 8 Oct 2021 09:45:07 +0000 [thread overview]
Message-ID: <20211008094509.16179-2-sj@kernel.org> (raw)
In-Reply-To: <20211008094509.16179-1-sj@kernel.org>
This commit implements kunit tests for the monitoring results record
feture.
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
---
mm/damon/dbgfs-test.h | 88 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h
index 4eddcfa73996..23573ade7ac2 100644
--- a/mm/damon/dbgfs-test.h
+++ b/mm/damon/dbgfs-test.h
@@ -109,9 +109,97 @@ static void damon_dbgfs_test_set_targets(struct kunit *test)
dbgfs_destroy_ctx(ctx);
}
+static void damon_dbgfs_test_set_recording(struct kunit *test)
+{
+ struct damon_ctx *ctx = dbgfs_new_ctx();
+ struct dbgfs_recorder *rec = ctx->callback.private;
+ int err;
+
+ err = dbgfs_set_recording(ctx, 42, "foo");
+ KUNIT_EXPECT_EQ(test, err, -EINVAL);
+ dbgfs_set_recording(ctx, 4242, "foo.bar");
+ KUNIT_EXPECT_EQ(test, rec->rbuf_len, 4242u);
+ KUNIT_EXPECT_STREQ(test, rec->rfile_path, "foo.bar");
+ dbgfs_set_recording(ctx, 424242, "foo");
+ KUNIT_EXPECT_EQ(test, rec->rbuf_len, 424242u);
+ KUNIT_EXPECT_STREQ(test, rec->rfile_path, "foo");
+
+ dbgfs_destroy_ctx(ctx);
+}
+
+static void damon_dbgfs_test_write_rbuf(struct kunit *test)
+{
+ struct damon_ctx *ctx = dbgfs_new_ctx();
+ struct dbgfs_recorder *rec = ctx->callback.private;
+ char *data;
+
+ dbgfs_set_recording(ctx, 4242, "damon.data");
+
+ data = "hello";
+ dbgfs_write_rbuf(ctx, data, strnlen(data, 256));
+ KUNIT_EXPECT_EQ(test, rec->rbuf_offset, 5u);
+
+ dbgfs_write_rbuf(ctx, data, 0);
+ KUNIT_EXPECT_EQ(test, rec->rbuf_offset, 5u);
+
+ KUNIT_EXPECT_STREQ(test, (char *)rec->rbuf, data);
+
+ dbgfs_destroy_ctx(ctx);
+}
+
+/*
+ * Test dbgfs_after_aggregation()
+ *
+ * dbgfs sets dbgfs_after_aggregation() as aggregate callback. It stores the
+ * aggregated monitoring information ('->nr_accesses' of each regions) to the
+ * result buffer.
+ */
+static void damon_dbgfs_test_aggregate(struct kunit *test)
+{
+ struct damon_ctx *ctx = dbgfs_new_ctx();
+ struct dbgfs_recorder *rec = ctx->callback.private;
+ unsigned long target_ids[] = {1, 2, 3};
+ unsigned long saddr[][3] = {{10, 20, 30}, {5, 42, 49}, {13, 33, 55} };
+ unsigned long eaddr[][3] = {{15, 27, 40}, {31, 45, 55}, {23, 44, 66} };
+ unsigned long accesses[][3] = {{42, 95, 84}, {10, 20, 30}, {0, 1, 2} };
+ struct damon_target *t;
+ struct damon_region *r;
+ int it, ir;
+ ssize_t sz, sr, sp;
+
+ /* Make DAMON consider target id as plain number */
+ ctx->primitive.target_valid = NULL;
+ ctx->primitive.cleanup = NULL;
+
+ dbgfs_set_recording(ctx, 4242, "damon.data");
+ damon_set_targets(ctx, target_ids, 3);
+
+ it = 0;
+ damon_for_each_target(t, ctx) {
+ for (ir = 0; ir < 3; ir++) {
+ r = damon_new_region(saddr[it][ir], eaddr[it][ir]);
+ r->nr_accesses = accesses[it][ir];
+ damon_add_region(r, t);
+ }
+ it++;
+ }
+ dbgfs_after_aggregation(ctx);
+
+ /* The aggregated information should be written in the buffer */
+ sr = sizeof(r->ar.start) + sizeof(r->ar.end) + sizeof(r->nr_accesses);
+ sp = sizeof(t->id) + sizeof(unsigned int) + 3 * sr;
+ sz = sizeof(struct timespec64) + sizeof(unsigned int) + 3 * sp;
+ KUNIT_EXPECT_EQ(test, (unsigned int)sz, rec->rbuf_offset);
+
+ damon_destroy_ctx(ctx);
+}
+
static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_dbgfs_test_str_to_target_ids),
KUNIT_CASE(damon_dbgfs_test_set_targets),
+ KUNIT_CASE(damon_dbgfs_test_set_recording),
+ KUNIT_CASE(damon_dbgfs_test_write_rbuf),
+ KUNIT_CASE(damon_dbgfs_test_aggregate),
{},
};
--
2.17.1
next prev parent reply other threads:[~2021-10-08 9:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 9:45 [PATCH 1/4] mm/damon/dbgfs: Implement recording feature SeongJae Park
2021-10-08 9:45 ` SeongJae Park [this message]
2021-10-08 9:45 ` [PATCH 3/4] selftests/damon: Test " SeongJae Park
2021-10-08 9:45 ` [PATCH 4/4] Docs/damon/usage: Update for the record feature SeongJae Park
2021-10-10 22:01 ` [PATCH 1/4] mm/damon/dbgfs: Implement recording feature Andrew Morton
2021-10-11 9:30 ` SeongJae Park
2021-10-11 21:02 ` Andrew Morton
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=20211008094509.16179-2-sj@kernel.org \
--to=sj@kernel.org \
--cc=Jonathan.Cameron@Huawei.com \
--cc=akpm@linux-foundation.org \
--cc=amit@kernel.org \
--cc=benh@kernel.crashing.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=dwmw@amazon.com \
--cc=elver@google.com \
--cc=foersleo@amazon.de \
--cc=gthelen@google.com \
--cc=linux-damon@amazon.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=markubo@amazon.de \
--cc=rientjes@google.com \
--cc=shakeelb@google.com \
--cc=shuah@kernel.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