Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp266105pxa; Wed, 5 Aug 2020 00:04:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg+Apx8wkHxb1VV4zPE45MNVwU5PXLgyRgV9Zqv4lI7j0SIok9geQ4ImCwIzlH+/+yiD/L X-Received: by 2002:aa7:d8d7:: with SMTP id k23mr1566884eds.54.1596611070404; Wed, 05 Aug 2020 00:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596611070; cv=none; d=google.com; s=arc-20160816; b=AbpG7GqUtePk3SPf0//6uhAuvzsGM/pROSr3mzomvA76LsqbvZ6H9szYYaXbouIief 3JKGzliUFZA7K6su8lFB4Y7hotS+ONK0qV0iIhGDcbm8m0s7ulRrOzj1w5H8HFZdfCys 0Goeq793fA8dIAOSVLMWgvwIt9Kexks+KQRdHpYndo/DIJiLcUAWEBsGS7Jn1JLrYIkP l2YtCE+nko5nlVNKqPogqePrRolxyL9Gw9SgGiI/x4ZJwI2iiddhVC+wKYjTCOCdKLVf UXJhEnIt2jpRK6blD1jriIlXBFosFXN/QxGYJ05pWjeLez3ElukTgTtYlzTAParshXgJ mCVQ== 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=aibriOLYHRMEMwE9Y2Udzz9CLQ41hY8QmqPUl8w9XOY=; b=Gu1AKH83q7ucrp65Tn1UwDgdedDfcAfMm1jpIYG5AmnlIRiwueJE04Ahtq4yuwZHKg zOPm1nnFN/F0cr5+RDPwDMlPLmbNXmT/9jhPNx+f0E79lX+lyrBvcx5Ca5zimmgXST26 WyI2MnNwC/VAhYvwGPQYIkKlNrwErBpk3off2UFt/BpvE/3gj5uNkvq/qWa1BclPBIp9 FpBthMFPrzORixS8YoHCA5LoMXdJ/OAdwF7gWdUOaW/YfRW44G+7HgTftoNVQK4UtGuW LI4I1TsvPaaTH1TVKmoIaDQJOn3rNnzERLph5YrrESsYgje88yA3cPSAkk8ivt6feWBa sf1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=aUuHI7n6; 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 bd8si687802edb.477.2020.08.05.00.04.08; Wed, 05 Aug 2020 00:04:30 -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=aUuHI7n6; 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 S1728194AbgHEHBj (ORCPT + 99 others); Wed, 5 Aug 2020 03:01:39 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:2019 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbgHEHBh (ORCPT ); Wed, 5 Aug 2020 03:01:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1596610897; x=1628146897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=aibriOLYHRMEMwE9Y2Udzz9CLQ41hY8QmqPUl8w9XOY=; b=aUuHI7n6nGf4WMnSz5qN0POkgSWQmHfp5QfSk6GhmDTzKUnKxafOu3o3 LhouhmyUOLu1tqVpg/vZ3QXWnKo+NQpDyh30fWfOgpyGlAhYZ6DBSx/BB bLCsFTL0XQXnEASnJP06K7RF9DsFyRNkY1qZXLeyc4eFFVVJ0wd4YuJjI A=; IronPort-SDR: g7xX2ZiEGAAydKxhpjSpQoqzc7Yz9Vph5HZcCCxnv9oX5PCZ/vVFrEfrX0wkSYdRju8ez+HWqZ coIz3lxphkfw== X-IronPort-AV: E=Sophos;i="5.75,436,1589241600"; d="scan'208";a="65698123" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 05 Aug 2020 07:01:33 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (Postfix) with ESMTPS id B435D2820BC; Wed, 5 Aug 2020 07:01:29 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 5 Aug 2020 07:01:29 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.26) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 5 Aug 2020 07:01:12 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v6 03/10] mm/damon-test: Add more unit tests for 'init_regions' Date: Wed, 5 Aug 2020 08:59:44 +0200 Message-ID: <20200805065951.18221-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200805065951.18221-1-sjpark@amazon.com> References: <20200805065951.18221-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.26] X-ClientProxiedBy: EX13D24UWB002.ant.amazon.com (10.43.161.159) 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