From patchwork Tue Jul 7 14:45:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11648847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F6EF618 for ; Tue, 7 Jul 2020 14:47:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62EF820738 for ; Tue, 7 Jul 2020 14:47:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="FElo9fkY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62EF820738 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 ACAD98D0016; Tue, 7 Jul 2020 10:47:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A79AF8D0007; Tue, 7 Jul 2020 10:47:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 969628D0016; Tue, 7 Jul 2020 10:47:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 803228D0007 for ; Tue, 7 Jul 2020 10:47:50 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3EFFD181AEF0B for ; Tue, 7 Jul 2020 14:47:50 +0000 (UTC) X-FDA: 77011559100.11.jam87_4d0478226eb5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id EF055180F8B9D for ; Tue, 7 Jul 2020 14:47:47 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=45007d872=sjpark@amazon.com,,RULES_HIT:30003:30012:30054:30064:30070,0,RBL:207.171.190.10:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10;04yfszhnebizxu34hyzyzhhtwtngnocykqsonfnjabsatammw7dyp67rt1m7kcj.czc74so8me8caezz6d5zfctf19n5nn8ho7fdka3dnuzr36s6wjexzqhhcyx9cpw.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: jam87_4d0478226eb5 X-Filterd-Recvd-Size: 5977 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 14:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1594133267; x=1625669267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=/rnhlyftvuA9Pn35wQ2J/CMbxisKU1/DGJ2IeZv/Z4M=; b=FElo9fkYfaL+GWRCV7DKdDfzhkIIoSZzN3FzR6KtmSxlf49/6JQ4rvLa p8qbs3kIANched0NkwFinvx4xLO7dbJjjUtqMfGN7hWbpBlhQogMQ0JTn MxaXeOKqolvDZfkAVgATk08YrhpBHPPMYX4gYs6a5fYlgYw6lLQ+gWATE k=; IronPort-SDR: ZdKgTRlPLgfeyx2AVkdxWuZZGcFjfGO240cHZqg9Pul63TkNWXDbkAppgmRtKfG/C/KCTlavjB P3oXSdjK62Fw== X-IronPort-AV: E=Sophos;i="5.75,324,1589241600"; d="scan'208";a="56719865" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 07 Jul 2020 14:47:42 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id 6291DA221C; Tue, 7 Jul 2020 14:47:40 +0000 (UTC) Received: from EX13D31EUA004.ant.amazon.com (10.43.165.161) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 14:47:39 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.214) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 14:47:18 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v5 03/11] mm/damon-test: Add more unit tests for 'init_regions' Date: Tue, 7 Jul 2020 16:45:32 +0200 Message-ID: <20200707144540.21216-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200707144540.21216-1-sjpark@amazon.com> References: <20200707144540.21216-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.214] X-ClientProxiedBy: EX13D35UWC001.ant.amazon.com (10.43.162.197) To EX13D31EUA004.ant.amazon.com (10.43.165.161) X-Rspamd-Queue-Id: EF055180F8B9D X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 more test cases for the new feature, 'init_regions'. Signed-off-by: SeongJae Park Reviewed-by: Brendan Higgins --- mm/damon-test.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mm/damon-test.h b/mm/damon-test.h index b31c7fe913ca..716594342ff1 100644 --- a/mm/damon-test.h +++ b/mm/damon-test.h @@ -152,6 +152,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; + int pids[] = {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", /* pid 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_pids(ctx, pids, 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_pids(ctx, NULL, 0); +} + static void __link_vmas(struct vm_area_struct *vmas, ssize_t nr_vmas) { int i, j; @@ -635,6 +687,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_regions), KUNIT_CASE(damon_test_set_pids), 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),