Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp875602pxk; Mon, 31 Aug 2020 03:50:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNZP+zlWGJDqyQ/7IwgHh87Nq8QU74ohbAyOhk5GD47dzdUIB++Ch92LMiy3HckXbVillG X-Received: by 2002:a17:907:20e5:: with SMTP id rh5mr553045ejb.194.1598871057001; Mon, 31 Aug 2020 03:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598871056; cv=none; d=google.com; s=arc-20160816; b=shU5HEAUuoZ4zP2SoFlLCL2lofj3GKi+unCdSn6ADLQpwuSGbTSXeDWaYMz7+3zsar +8AWn4ENdruqjvMM3A2dpPd1vvy79FDoD0M1Y3O/bs4rY2GNYEHxHhwjEGnVNzpjz7+3 BXiadaCy3N13UR8pVkmbhP+A5MXa3K1J9I6hbktqNjS3AINMMizdhwYIzHtxh9X5bGVm AMpEQu14nv2EUJFUic1sUu3pBjT+E8FBjlGm14uaw2b2+9Xc03/W9aAxDSrd6fjrDiL3 rzS06Oxe7+XravvU/xxCGcDt6/DA48qFZs6l8BIo9u6KPLUQixS1NX7T5s2Xr+QWlq4h mbBA== 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=t83U6iMpHB5Ra5CmTIpP+H+t+wsO9yd9cZKiYQA2Yh0=; b=OKeDn06L3PXCNrIi9OGtbWmGPFCXe30shk/ItAMGv4jq5lbdKreB0YSUVJ5S5KFqOX ZilW7T9Ghp/WH0KL2p7TgqlJdUWYOq2fd/IZeuDiBK/BfoDW7jJC4uJvN6jLLqcUd3GU Yminv0HD/JosqR8U6NOofBDL3cyDyeL2OVpzqfwFXGfRI8DIYt4xk0P2+/jnI8rPaaVe tE/2YXsqG0Oty2J1r76FpuBVKM8c3cFMtPnlFZ/+lqnVHz7lmLURBXX7ZqyGG6nxj1wx URoxzVtB8WJsJzVMNJpITJ1YmKCpTVT8OZtfFPhSCsvKGdAXXQrp6N233akJmt0N85pg L1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=pkVMhSSo; 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 t23si4840311ejs.145.2020.08.31.03.50.33; Mon, 31 Aug 2020 03:50:56 -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=pkVMhSSo; 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 S1726880AbgHaKtN (ORCPT + 99 others); Mon, 31 Aug 2020 06:49:13 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:61225 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbgHaKtB (ORCPT ); Mon, 31 Aug 2020 06:49:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1598870942; x=1630406942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=t83U6iMpHB5Ra5CmTIpP+H+t+wsO9yd9cZKiYQA2Yh0=; b=pkVMhSSo6D7LvBTUYQOvnX+mErPFRreplBZcRRdTEQ5khesWNo/e4/S3 Jb79/lTYSI2T5WS2qYjB5K5A5xVnrBVZAu+413hrsGwCDQyI3dwAd+Kzf LbjMd1CXRo1DHlTwpgwOumxRZG3a+j+MrsRCa88Nq02nSPsYt/YTszstH U=; X-IronPort-AV: E=Sophos;i="5.76,375,1592870400"; d="scan'208";a="72355524" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 31 Aug 2020 10:48:59 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (Postfix) with ESMTPS id CE26CA261F; Mon, 31 Aug 2020 10:48:56 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.100) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 Aug 2020 10:48:38 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v8 03/10] mm/damon-test: Add more unit tests for 'init_regions' Date: Mon, 31 Aug 2020 12:47:23 +0200 Message-ID: <20200831104730.28970-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831104730.28970-1-sjpark@amazon.com> References: <20200831104730.28970-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.100] X-ClientProxiedBy: EX13D49UWB002.ant.amazon.com (10.43.163.68) To EX13D31EUB001.ant.amazon.com (10.43.166.210) 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 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 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