From patchwork Fri Oct 8 09:45:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12544821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFADEC433FE for ; Fri, 8 Oct 2021 09:45:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 40EBA61037 for ; Fri, 8 Oct 2021 09:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 40EBA61037 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D8C6B6B0072; Fri, 8 Oct 2021 05:45:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D14826B0073; Fri, 8 Oct 2021 05:45:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C03976B0074; Fri, 8 Oct 2021 05:45:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id B2E566B0072 for ; Fri, 8 Oct 2021 05:45:21 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 556A58249980 for ; Fri, 8 Oct 2021 09:45:21 +0000 (UTC) X-FDA: 78672787242.06.8687562 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id E7189700197B for ; Fri, 8 Oct 2021 09:45:20 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id A403E61027; Fri, 8 Oct 2021 09:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633686320; bh=PPuno9RwwKhrsxW1OCwnBrO3F3JbkyV/+tb99kiysMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eIdrN/uowGfC64APYFC65W+kS1MtrWFzA+q7e/i7dySTX3mtccLcjWBwfxBfeoM/U tzjRK272HiuDexC/Mh6qDFk1QUTPtL1YHolYRF6QZyePQJRef963BAWPPVSRQWmnyn LZB9hh4A+TZsWdy1TWdAqiPP20WL4GglJn3rrGhmjs00WhcNdKTX+ApuRJ8jgX82Lj atBEdDEG6E4/m2V68bwWFWCepnZovoN45DA0aA4rlHltwJRDsJm1y0XCbed2pxZI9f vio7w3Pd8D+oPK3GUJ70JVhQ3JX4lX+TT0ltZXNUYNRhiGX6b1c0z/BfiLywlRZv6Q 8dUlraEISTXxw== From: SeongJae Park To: akpm@linux-foundation.org Cc: SeongJae Park , 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 Message-Id: <20211008094509.16179-2-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211008094509.16179-1-sj@kernel.org> References: <20211008094509.16179-1-sj@kernel.org> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E7189700197B X-Stat-Signature: gyzwcdrmqqkughtkeo38rzpiggn6tw1y Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="eIdrN/uo"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1633686320-29239 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This commit implements kunit tests for the monitoring results record feture. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- 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), {}, };