diff mbox series

[v30,12/13] mm/damon: Add user space selftests

Message ID 20210616073119.16758-13-sj38.park@gmail.com (mailing list archive)
State New, archived
Headers show
Series Introduce Data Access MONitor (DAMON) | expand

Commit Message

SeongJae Park June 16, 2021, 7:31 a.m. UTC
From: SeongJae Park <sjpark@amazon.de>

This commit adds a simple user space tests for DAMON.  The tests are
using kselftest framework.

Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
 tools/testing/selftests/damon/Makefile        |  7 ++
 .../selftests/damon/_chk_dependency.sh        | 28 +++++++
 .../testing/selftests/damon/debugfs_attrs.sh  | 75 +++++++++++++++++++
 3 files changed, 110 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

Comments

Boehme, Markus June 17, 2021, 11:28 a.m. UTC | #1
On Wed, 2021-06-16 at 07:31 +0000, SeongJae Park wrote:
> From: SeongJae Park <sjpark@amazon.de>
> 
> This commit adds a simple user space tests for DAMON.  The tests are
> using kselftest framework.
> 
> Signed-off-by: SeongJae Park <sjpark@amazon.de>
> ---
>  tools/testing/selftests/damon/Makefile        |  7 ++
>  .../selftests/damon/_chk_dependency.sh        | 28 +++++++
>  .../testing/selftests/damon/debugfs_attrs.sh  | 75 +++++++++++++++++++
>  3 files changed, 110 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/debugfs_attrs.sh b/tools/testing/selftests/damon/debugfs_attrs.sh
> new file mode 100755
> index 000000000000..60342d6c86d8
> --- /dev/null
> +++ b/tools/testing/selftests/damon/debugfs_attrs.sh
> @@ -0,0 +1,75 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +test_write_result() {
> +	file=$1
> +	content=$2
> +	orig_content=$3
> +	expect_reason=$4
> +	expected=$5
> +
> +	echo "$content" > "$file"
> +	if [ $? -ne "$expected" ]
> +	then
> +		echo "writing $content to $file doesn't return $expected"
> +		echo "expected because: $expect_reason"
> +		echo "$orig_content" > "$file"
> +		exit 1
> +	fi
> +}
> +
> +test_write_succ() {
> +	test_write_result "$1" "$2" "$3" "$4" 0
> +}
> +
> +test_write_fail() {
> +	test_write_result "$1" "$2" "$3" "$4" 1
> +}
> +
> +test_content() {
> +	file=$1
> +	orig_content=$2
> +	expected=$3
> +	expect_reason=$4
> +
> +	content=$(cat "$file")
> +	if [ "$content" != "$content" ]

That'll always evaluate false and should compare against "expected"
instead.

> +	then
> +		echo "reading $file expected $expected but $content"
> +		echo "expected because: $expect_reason"
> +		echo "$orig_content" > "$file"
> +		exit 1
> +	fi
> +}
> 
> [...]


Otherwise looking good.

Best regards,
Markus



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
Boehme, Markus June 17, 2021, 11:29 a.m. UTC | #2
On Thu, 2021-06-17 at 11:28 +0000, Boehme, Markus wrote:
> On Wed, 2021-06-16 at 07:31 +0000, SeongJae Park wrote:
> > From: SeongJae Park <sjpark@amazon.de>
> > 
> > This commit adds a simple user space tests for DAMON.  The tests
> > are
> > using kselftest framework.
> > 
> > Signed-off-by: SeongJae Park <sjpark@amazon.de>
> > ---
> >  tools/testing/selftests/damon/Makefile        |  7 ++
> >  .../selftests/damon/_chk_dependency.sh        | 28 +++++++
> >  .../testing/selftests/damon/debugfs_attrs.sh  | 75
> > +++++++++++++++++++
> >  3 files changed, 110 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/debugfs_attrs.sh
> > b/tools/testing/selftests/damon/debugfs_attrs.sh
> > new file mode 100755
> > index 000000000000..60342d6c86d8
> > --- /dev/null
> > +++ b/tools/testing/selftests/damon/debugfs_attrs.sh
> > @@ -0,0 +1,75 @@
> > +#!/bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +test_write_result() {
> > +	file=$1
> > +	content=$2
> > +	orig_content=$3
> > +	expect_reason=$4
> > +	expected=$5
> > +
> > +	echo "$content" > "$file"
> > +	if [ $? -ne "$expected" ]
> > +	then
> > +		echo "writing $content to $file doesn't return
> > $expected"
> > +		echo "expected because: $expect_reason"
> > +		echo "$orig_content" > "$file"
> > +		exit 1
> > +	fi
> > +}
> > +
> > +test_write_succ() {
> > +	test_write_result "$1" "$2" "$3" "$4" 0
> > +}
> > +
> > +test_write_fail() {
> > +	test_write_result "$1" "$2" "$3" "$4" 1
> > +}
> > +
> > +test_content() {
> > +	file=$1
> > +	orig_content=$2
> > +	expected=$3
> > +	expect_reason=$4
> > +
> > +	content=$(cat "$file")
> > +	if [ "$content" != "$content" ]
> 
> That'll always evaluate false and should compare against "expected"
> instead.
> 

Feel free to add Reviewed-by: Markus Boehme <markubo@amazon.de> when
this is fixed.

> > +	then
> > +		echo "reading $file expected $expected but $content"
> > +		echo "expected because: $expect_reason"
> > +		echo "$orig_content" > "$file"
> > +		exit 1
> > +	fi
> > +}
> > 
> > [...]
> 
> Otherwise looking good.
> 
> Best regards,
> Markus



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
SeongJae Park June 17, 2021, 11:35 a.m. UTC | #3
From: SeongJae Park <sjpark@amazon.de>

Hello Markus,

On Thu, 17 Jun 2021 11:29:41 +0000 "Boehme, Markus" <markubo@amazon.de> wrote:

> On Thu, 2021-06-17 at 11:28 +0000, Boehme, Markus wrote:
> > On Wed, 2021-06-16 at 07:31 +0000, SeongJae Park wrote:
> > > From: SeongJae Park <sjpark@amazon.de>
> > > 
> > > This commit adds a simple user space tests for DAMON.  The tests
> > > are
> > > using kselftest framework.
> > > 
> > > Signed-off-by: SeongJae Park <sjpark@amazon.de>
> > > ---
> > >  tools/testing/selftests/damon/Makefile        |  7 ++
> > >  .../selftests/damon/_chk_dependency.sh        | 28 +++++++
> > >  .../testing/selftests/damon/debugfs_attrs.sh  | 75
> > > +++++++++++++++++++
> > >  3 files changed, 110 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/debugfs_attrs.sh
> > > b/tools/testing/selftests/damon/debugfs_attrs.sh
> > > new file mode 100755
> > > index 000000000000..60342d6c86d8
> > > --- /dev/null
> > > +++ b/tools/testing/selftests/damon/debugfs_attrs.sh
[...]
> > > +
> > > +test_content() {
> > > +	file=$1
> > > +	orig_content=$2
> > > +	expected=$3
> > > +	expect_reason=$4
> > > +
> > > +	content=$(cat "$file")
> > > +	if [ "$content" != "$content" ]
> > 
> > That'll always evaluate false and should compare against "expected"
> > instead.

Good catch, I will fix so in the next spin.

> > 
> 
> Feel free to add Reviewed-by: Markus Boehme <markubo@amazon.de> when
> this is fixed.

Thank you!

> 
> > > +	then
> > > +		echo "reading $file expected $expected but $content"
> > > +		echo "expected because: $expect_reason"
> > > +		echo "$orig_content" > "$file"
> > > +		exit 1
> > > +	fi
> > > +}


Thanks,
SeongJae Park

[...]
diff mbox series

Patch

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..0189db81550b
--- /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..60342d6c86d8
--- /dev/null
+++ b/tools/testing/selftests/damon/debugfs_attrs.sh
@@ -0,0 +1,75 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+test_write_result() {
+	file=$1
+	content=$2
+	orig_content=$3
+	expect_reason=$4
+	expected=$5
+
+	echo "$content" > "$file"
+	if [ $? -ne "$expected" ]
+	then
+		echo "writing $content to $file doesn't return $expected"
+		echo "expected because: $expect_reason"
+		echo "$orig_content" > "$file"
+		exit 1
+	fi
+}
+
+test_write_succ() {
+	test_write_result "$1" "$2" "$3" "$4" 0
+}
+
+test_write_fail() {
+	test_write_result "$1" "$2" "$3" "$4" 1
+}
+
+test_content() {
+	file=$1
+	orig_content=$2
+	expected=$3
+	expect_reason=$4
+
+	content=$(cat "$file")
+	if [ "$content" != "$content" ]
+	then
+		echo "reading $file expected $expected but $content"
+		echo "expected because: $expect_reason"
+		echo "$orig_content" > "$file"
+		exit 1
+	fi
+}
+
+source ./_chk_dependency.sh
+
+# Test attrs file
+# ===============
+
+file="$DBGFS/attrs"
+orig_content=$(cat "$file")
+
+test_write_succ "$file" "1 2 3 4 5" "$orig_content" "valid input"
+test_write_fail "$file" "1 2 3 4" "$orig_content" "no enough fields"
+test_write_fail "$file" "1 2 3 5 4" "$orig_content" \
+	"min_nr_regions > max_nr_regions"
+test_content "$file" "$orig_content" "1 2 3 4 5" "successfully written"
+echo "$orig_content" > "$file"
+
+# Test target_ids file
+# ====================
+
+file="$DBGFS/target_ids"
+orig_content=$(cat "$file")
+
+test_write_succ "$file" "1 2 3 4" "$orig_content" "valid input"
+test_write_succ "$file" "1 2 abc 4" "$orig_content" "still valid input"
+test_content "$file" "$orig_content" "1 2" "non-integer was there"
+test_write_succ "$file" "abc 2 3" "$orig_content" "the file allows wrong input"
+test_content "$file" "$orig_content" "" "wrong input written"
+test_write_succ "$file" "" "$orig_content" "empty input"
+test_content "$file" "$orig_content" "" "empty input written"
+echo "$orig_content" > "$file"
+
+echo "PASS"