Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2898672pxa; Tue, 18 Aug 2020 00:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/w+ep+dj90nGiQenppxc4yXDOQ0+iMzls4xjN/oByRJAmQL5oZ9sfY1+LwC0CEkVd7L/8 X-Received: by 2002:a17:906:9984:: with SMTP id af4mr19530325ejc.90.1597735835045; Tue, 18 Aug 2020 00:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597735835; cv=none; d=google.com; s=arc-20160816; b=WoQBxgW+gJbeWkdlkoqzw8TeFQY/O8+LWpd8wLajgNOdo+nIlFsQ53P4FcGaC0wAuc nfG3a1q18YWpWlpW0iogT8juoTfJsPhi9UmUG9eSBSizJsBOX8ZTMejvPy65cuNFdMAV DMVd60lSPSwjyblsJmq5wwymvQhXWjaumRlXel1SIqhKNNwv0DJAxWN7DCg9kAt/3FoI Oe/taKDiZJ9AIViFkh2R1ThUbznE6ak5F/91OfvVinVcOSdaDIcnjTLf3TpwPs+Hb1PN ndch67oXZqHUSUrE/prqax8dNzURBIe6XraO9s3o8lqB//X4eXumtjr2IvSy8CsiEWAH IO4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=aibriOLYHRMEMwE9Y2Udzz9CLQ41hY8QmqPUl8w9XOY=; b=HHoEumfIminOAqPxxG2xkpxR91lS4qqfEhflrxomZB1V4mYLS+z0zidLgKt+WlvMrY xadcOGq9p2CY3LwR9EhHu5kbmbxxrrXUmkGXby5Dhp7SS9Le6I0IiQnCUImmRJc8vKg0 suvfLLGTX5iWCi6BRKqd11s5vCddm8O8PVj+i3dm642E9dPD83sPEpswln3jHWgIcz7z 65MSK88eCODtN9KximmwnfcWnRMqsodXFAwr0aMcIAsZizGWl7G5ElaLbX1CNDoYVAoh AeZyTU11zRtQsZDK8zk+TRYB8cSMWly6GaL8Z6Wx3V7YXwvQuxoLY+6pvsIMOs1znRRM BRog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=daZjWWiG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si2659805edq.34.2020.08.18.00.30.11; Tue, 18 Aug 2020 00:30:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=daZjWWiG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726592AbgHRH0n (ORCPT + 99 others); Tue, 18 Aug 2020 03:26:43 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:45680 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgHRH0m (ORCPT ); Tue, 18 Aug 2020 03:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597735601; x=1629271601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=aibriOLYHRMEMwE9Y2Udzz9CLQ41hY8QmqPUl8w9XOY=; b=daZjWWiGTYVebk6v+tA85bpo4uxc7vkCCnNcIewKfTPj0+uZT1JcYJ9A 102/sGrYIcoWfKPntRIMVHNkpxNqXqagpamRAULgoLe3plUeiRq3nMYuE i5cwbsfN242hSsWZcxNi3oh4EAaszGntaChkziw7X8uU+l7OZruB4huQg o=; X-IronPort-AV: E=Sophos;i="5.76,326,1592870400"; d="scan'208";a="48499962" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 18 Aug 2020 07:26:40 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com (Postfix) with ESMTPS id ACB9AA25F1; Tue, 18 Aug 2020 07:26:28 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:26:27 +0000 Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:26:11 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v7 03/10] mm/damon-test: Add more unit tests for 'init_regions' Date: Tue, 18 Aug 2020 09:24:54 +0200 Message-ID: <20200818072501.30396-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200818072501.30396-1-sjpark@amazon.com> References: <20200818072501.30396-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D38UWB002.ant.amazon.com (10.43.161.171) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park This commit adds more test cases for the new feature, 'init_regions'. Signed-off-by: SeongJae Park --- mm/damon-test.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mm/damon-test.h b/mm/damon-test.h index 71413ffc1dcb..e67e8fb17eca 100644 --- a/mm/damon-test.h +++ b/mm/damon-test.h @@ -161,6 +161,58 @@ static void damon_test_set_recording(struct kunit *test) KUNIT_EXPECT_STREQ(test, ctx->rfile_path, "foo"); } +static void damon_test_set_init_regions(struct kunit *test) +{ + struct damon_ctx *ctx = &damon_user_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); +} + static void __link_vmas(struct vm_area_struct *vmas, ssize_t nr_vmas) { int i, j; @@ -645,6 +697,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_regions), KUNIT_CASE(damon_test_set_targets), KUNIT_CASE(damon_test_set_recording), + KUNIT_CASE(damon_test_set_init_regions), KUNIT_CASE(damon_test_three_regions_in_vmas), KUNIT_CASE(damon_test_aggregate), KUNIT_CASE(damon_test_write_rbuf), -- 2.17.1