From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0013C4363C for ; Wed, 7 Oct 2020 07:22:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E66792083B for ; Wed, 7 Oct 2020 07:22:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="HfWHpnNJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E66792083B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DD22C6B005C; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5B8B900002; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFE456B0068; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 94AD96B005C for ; Wed, 7 Oct 2020 03:22:17 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 38FF2180364CE for ; Wed, 7 Oct 2020 07:22:17 +0000 (UTC) X-FDA: 77344285914.27.tax25_3811411271cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id F3DE117F1B for ; Wed, 7 Oct 2020 07:15:56 +0000 (UTC) X-HE-Tag: tax25_3811411271cd X-Filterd-Recvd-Size: 5797 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 07:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1602054957; x=1633590957; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nbNskFUf5I9SudJVFLFnLIHvjIM0C7eogr6WrZtj68U=; b=HfWHpnNJJSY3LIr8UNrrt8B7AVTd/ZaAh2qpL07S0E2AYoUFDVbB+BqR JE91DGzIOXXwrqO0E6ChUl/gsXhHz6AuWGmavEpL+/hDrOKdpj/gqFP9u bccm/ap4BB5ew1xoWoeJQDg2KyK8ArSJfZ54a8+SdGCN/X/1ZvwYJi55z w=; X-IronPort-AV: E=Sophos;i="5.77,345,1596499200"; d="scan'208";a="74032971" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Oct 2020 07:15:53 +0000 Received: from EX13D31EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-57e1d233.us-east-1.amazon.com (Postfix) with ESMTPS id B8F73141641; Wed, 7 Oct 2020 07:15:40 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Oct 2020 07:15:24 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v9 03/10] damon/dbgfs-test: Add a unit test case for 'init_regions' Date: Wed, 7 Oct 2020 09:14:02 +0200 Message-ID: <20201007071409.12174-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007071409.12174-1-sjpark@amazon.com> References: <20201007071409.12174-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D31UWA003.ant.amazon.com (10.43.160.130) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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: From: SeongJae Park This commit adds another test case for the new feature, 'init_regions'. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- mm/damon/dbgfs-test.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h index ce9c6784ad47..2189f8f2a28e 100644 --- a/mm/damon/dbgfs-test.h +++ b/mm/damon/dbgfs-test.h @@ -189,12 +189,67 @@ static void damon_dbgfs_test_aggregate(struct kunit *test) damon_destroy_ctx(ctx); } + +static void damon_dbgfs_test_set_init_regions(struct kunit *test) +{ + struct damon_ctx *ctx = damon_new_ctx(); + unsigned long ids[] = {1, 2, 3}; + /* Each line represents one region in `` `` */ + char * const valid_inputs[] = {"2 10 20\n 2 20 30\n2 35 45", + "2 10 20\n", + "2 10 20\n1 39 59\n1 70 134\n 2 20 25\n", + ""}; + /* Reading the file again will show sorted, clean output */ + char * const valid_expects[] = {"2 10 20\n2 20 30\n2 35 45\n", + "2 10 20\n", + "1 39 59\n1 70 134\n2 10 20\n2 20 25\n", + ""}; + char * const invalid_inputs[] = {"4 10 20\n", /* target not exists */ + "2 10 20\n 2 14 26\n", /* regions overlap */ + "1 10 20\n2 30 40\n 1 5 8"}; /* not sorted by address */ + char *input, *expect; + int i, rc; + char buf[256]; + + damon_set_targets(ctx, ids, 3); + + /* Put valid inputs and check the results */ + for (i = 0; i < ARRAY_SIZE(valid_inputs); i++) { + input = valid_inputs[i]; + expect = valid_expects[i]; + + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, 0); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, expect); + } + /* Put invlid inputs and check the return error code */ + for (i = 0; i < ARRAY_SIZE(invalid_inputs); i++) { + input = invalid_inputs[i]; + pr_info("input: %s\n", input); + rc = set_init_regions(ctx, input, strnlen(input, 256)); + KUNIT_EXPECT_EQ(test, rc, -EINVAL); + + memset(buf, 0, 256); + sprint_init_regions(ctx, buf, 256); + + KUNIT_EXPECT_STREQ(test, (char *)buf, ""); + } + + damon_set_targets(ctx, NULL, 0); + 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), + KUNIT_CASE(damon_dbgfs_test_set_init_regions), {}, }; -- 2.17.1