Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1099894ybt; Tue, 7 Jul 2020 07:49:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznOjXQK8M6Fcudl7R/U7FumavvdDrvepgYqQ95DwtaDu2osBouc/JH4S6gqmaZXgH5cwtJ X-Received: by 2002:aa7:db53:: with SMTP id n19mr32559921edt.338.1594133360686; Tue, 07 Jul 2020 07:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594133360; cv=none; d=google.com; s=arc-20160816; b=Qm25Ds3bKE0G0fMyX9t+3vctjeE0vv7ngo7HXXAaolcdbuiB45UJRsULskqSZ2opa4 jnUZhBKmrizXYP3iz4OiZi8/9UX0WKwsROx259vjIJDzOC6qJR3hE1dLXaWcAOB4wgM8 Dy2MXEbSORVrxCXnTrhgwOGB/J7d+7HbT+tO6rMxT/Np8ihiFWdx5ZLoLx331P8HNAFB rCGYTnwd/UqbNi3Z7o9/oae6Bx1AHp+bSp0sDCJSzK3HMlx2xm3bfnljxzk1KHEtoAjm vMTmUe8SW2341axLj4/ws9cKoTpM6M77Bk3bJjh7UFEL6h8/DhIZ33bVXQU0U+lrqdKS 96WQ== 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:ironport-sdr:dkim-signature; bh=/rnhlyftvuA9Pn35wQ2J/CMbxisKU1/DGJ2IeZv/Z4M=; b=DpOPeuYp8fh/7KqcqW8aqAZyOsONH4VsDT1xMlB5V6cAssTq730lIgO+hCKUV+B2VV x9t13P6sxlaKen1Zk2qpELG6H9XfRL2vt773Sv2avnhjDHWK1e1xSYLLb/zhdIOQCkIS O/e5N801VVSWDF4V54LtVghNDCEHUxNa+wM/VVcUEG7sax0BvlKkY+huVezEgwBKxotz hxICG8b2Qhr+HhBFNRLYd81du1P1lhRV9J+oHkfOHhUuvLjW9zFWd0c2dRx2otFRIhCn /Q8AQ2o8zVP7el3wBfPpaxlZsxkuk7vI5hsoE/7k7pd5ZXuwmVU2uXRLm7Wbf0GuMIu9 Cnjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=FElo9fkY; 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 w18si15739085edx.276.2020.07.07.07.48.57; Tue, 07 Jul 2020 07:49:20 -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=FElo9fkY; 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 S1728357AbgGGOrs (ORCPT + 99 others); Tue, 7 Jul 2020 10:47:48 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:5859 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728249AbgGGOrr (ORCPT ); Tue, 7 Jul 2020 10:47:47 -0400 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 Content-Type: text/plain 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) 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 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), -- 2.17.1