Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp601934pxj; Fri, 11 Jun 2021 07:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFCitZzPdVpuv2g8RQd4CT01cSu1cU5gI3/uAclqjnq4wOgoO+rhxXnD8Xzio0hCAe1/bo X-Received: by 2002:a17:906:8810:: with SMTP id zh16mr3743388ejb.268.1623420104590; Fri, 11 Jun 2021 07:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623420104; cv=none; d=google.com; s=arc-20160816; b=CM1n/+/SVoArlSmoyja9wjh20lyPb1QpF93PQ+G7vZzh72X1SEG8/hlZHuT7Da1w4C iqu3O3g3HWXf8OApAqoCPnkYQcNvQ/uWBTLVvqGrroTvkWp9mXFr70lr6XvgjJTxWfsx NeOdHBzc0XjKHs8JLITxKHyUo+wqUHSym3hZPutN5Cio5pVwUV75k/QE8Q9dYBg1hrFF XjEOWnHupoCevR0KxPBASTxFSJ/csQyJemGNTgi0bW/zNVy7YmfDJVZbsxzqVyTp5s6m jpVbN1uvYg87oZrv5EQBHVcNat1+DpOl7nh0qb+HBqdyNzVdngRt3POeUK/eeadT54QX O+fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=BVa8dCIXdhHLUqpBplTYlwUjgrxEgZUsmYcBq30zA3M=; b=0rMQhDWwUwmMhVslTkNMGvtMCp403ZjD8P5AaRDyxh0OFMNGceaOw4cY7oVhZIq+06 gBtThO/BMOHsQU5QJVUjTWFHKH+MCy83kCjOoZON9QjmwpnBVaLm4TPRUxTwE6StHFs7 6v4By1KLqIFqNRKpt4Owg8BGh43qML4M4m1TS2ZCRhVQQFg3mBakYndugi/YnaADq+Wy ezYZiIUIfJ1bdiU7PkSiqIsFYDT7krEmUUukNmCnpJo5swSXsMJ8AG7pmDcMvt+bM8a8 wt7dwqLVvsDDI3XjzJ5zrLXhY42sDpjOr+uvZNaHMBactk11c+yRcZvoxpiBOmSHzt5M cuPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=tYzSmKZs; 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.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da25si4792748edb.3.2021.06.11.07.01.18; Fri, 11 Jun 2021 07:01:44 -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.de header.s=amazon201209 header.b=tYzSmKZs; 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.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231627AbhFKOAU (ORCPT + 99 others); Fri, 11 Jun 2021 10:00:20 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:32813 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbhFKOAT (ORCPT ); Fri, 11 Jun 2021 10:00:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1623419902; x=1654955902; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=BVa8dCIXdhHLUqpBplTYlwUjgrxEgZUsmYcBq30zA3M=; b=tYzSmKZsjnPwj1G2oS2TFhIdxRU64ZvbATCEFG6lwgAGju/zOpi+J9Bi Uuii91Yr3fQIjyHgbK8aFll3+10GIcxgqE09PEMqTuBqb88b3wPrFMgEz xqo7BAyoLBKTxR81fyCmHc+XdJuDkLGTwUvsLhlf6A47NBS0ZcKj6lLeS A=; X-IronPort-AV: E=Sophos;i="5.83,265,1616457600"; d="scan'208";a="115269106" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP; 11 Jun 2021 13:58:10 +0000 Received: from EX13MTAUEE001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id BD792A1C38; Fri, 11 Jun 2021 13:58:08 +0000 (UTC) Received: from EX13D08UEB004.ant.amazon.com (10.43.60.142) by EX13MTAUEE001.ant.amazon.com (10.43.62.226) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 11 Jun 2021 13:57:44 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D08UEB004.ant.amazon.com (10.43.60.142) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 11 Jun 2021 13:57:43 +0000 Received: from dev-dsk-mheyne-60001.pdx1.corp.amazon.com (10.184.85.242) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 11 Jun 2021 13:57:43 +0000 Received: by dev-dsk-mheyne-60001.pdx1.corp.amazon.com (Postfix, from userid 5466572) id 3BF0021D11; Fri, 11 Jun 2021 13:57:41 +0000 (UTC) From: Maximilian Heyne To: SeongJae Park CC: , SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v29 12/13] mm/damon: Add user space selftests Date: Fri, 11 Jun 2021 13:57:37 +0000 Message-ID: <20210611135737.104838-1-mheyne@amazon.de> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20210520075629.4332-13-sj38.park@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 20 May 2021 07:56:28 +0000 SeongJae Park wrote: > From: SeongJae Park > > This commit adds a simple user space tests for DAMON. The tests are > using kselftest framework. > > Signed-off-by: SeongJae Park > --- > tools/testing/selftests/damon/Makefile | 7 ++ > .../selftests/damon/_chk_dependency.sh | 28 ++++++ > .../testing/selftests/damon/debugfs_attrs.sh | 98 +++++++++++++++++++ > 3 files changed, 133 insertions(+) > create mode 100644 tools/testing/selftests/damon/Makefile > create mode 100644 tools/testing/selftests/damon/_chk_dependency.sh > create mode 100755 tools/testing/selftests/damon/debugfs_attrs.sh > > diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile > new file mode 100644 > index 000000000000..8a3f2cd9fec0 > --- /dev/null > +++ b/tools/testing/selftests/damon/Makefile > @@ -0,0 +1,7 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# Makefile for damon selftests > + > +TEST_FILES = _chk_dependency.sh > +TEST_PROGS = debugfs_attrs.sh > + > +include ../lib.mk > diff --git a/tools/testing/selftests/damon/_chk_dependency.sh b/tools/testing/selftests/damon/_chk_dependency.sh > new file mode 100644 > index 000000000000..e090836c2bf7 > --- /dev/null > +++ b/tools/testing/selftests/damon/_chk_dependency.sh > @@ -0,0 +1,28 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-2.0 > + > +# Kselftest framework requirement - SKIP code is 4. > +ksft_skip=4 > + > +DBGFS=/sys/kernel/debug/damon > + > +if [ $EUID -ne 0 ]; > +then > + echo "Run as root" > + exit $ksft_skip > +fi > + > +if [ ! -d $DBGFS ] > +then > + echo "$DBGFS not found" > + exit $ksft_skip > +fi > + > +for f in attrs target_ids monitor_on > +do > + if [ ! -f "$DBGFS/$f" ] > + then > + echo "$f not found" > + exit 1 > + fi > +done > diff --git a/tools/testing/selftests/damon/debugfs_attrs.sh b/tools/testing/selftests/damon/debugfs_attrs.sh > new file mode 100755 > index 000000000000..4a8ab4910ee4 > --- /dev/null > +++ b/tools/testing/selftests/damon/debugfs_attrs.sh > @@ -0,0 +1,98 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-2.0 > + > +source ./_chk_dependency.sh > + > +# Test attrs file > +file="$DBGFS/attrs" > + > +ORIG_CONTENT=$(cat $file) Missing quotes around $file. Can you run shellcheck on this code and fix all reportings, please? > + > +echo 1 2 3 4 5 > $file > +if [ $? -ne 0 ] > +then > + echo "$file write failed" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +echo 1 2 3 4 > $file > +if [ $? -eq 0 ] > +then > + echo "$file write success (should failed)" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +CONTENT=$(cat $file) > +if [ "$CONTENT" != "1 2 3 4 5" ] > +then > + echo "$file not written" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi I'd add test cases for the contents written to the attrs, like checking that input min_nr_regions is actually smaller than the input max_nr_regions values. > + > +echo $ORIG_CONTENT > $file > + > +# Test target_ids file > +file="$DBGFS/target_ids" > + > +ORIG_CONTENT=$(cat $file) > + > +echo "1 2 3 4" > $file > +if [ $? -ne 0 ] > +then > + echo "$file write fail" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +echo "1 2 abc 4" > $file > +if [ $? -ne 0 ] > +then > + echo "$file write fail" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi I've seen this construct more than once. Any chance to refactor this code? Or is this selftest not expected to grow in the future? > + > +CONTENT=$(cat $file) > +if [ "$CONTENT" != "1 2" ] > +then > + echo "$file not written" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +echo abc 2 3 > $file > +if [ $? -ne 0 ] > +then > + echo "$file wrong value write fail" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +if [ ! -z "$(cat $file)" ] > +then > + echo "$file not cleared" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +echo > $file > +if [ $? -ne 0 ] > +then > + echo "$file init fail" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +if [ ! -z "$(cat $file)" ] > +then > + echo "$file not initialized" > + echo $ORIG_CONTENT > $file > + exit 1 > +fi > + > +echo $ORIG_CONTENT > $file > + > +echo "PASS" > -- > 2.17.1 > > > > Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879