Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/damon: add user space selftests

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

Link: https://lkml.kernel.org/r/20210716081449.22187-13-sj38.park@gmail.com
Signed-off-by: SeongJae Park <sjpark@amazon.de>
Reviewed-by: Markus Boehme <markubo@amazon.de>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Amit Shah <amit@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: David Woodhouse <dwmw@amazon.com>
Cc: Fan Du <fan.du@intel.com>
Cc: Fernand Sieber <sieberf@amazon.com>
Cc: Greg Kroah-Hartman <greg@kroah.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joe Perches <joe@perches.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Leonard Foerster <foersleo@amazon.de>
Cc: Marco Elver <elver@google.com>
Cc: Maximilian Heyne <mheyne@amazon.de>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

SeongJae Park and committed by
Linus Torvalds
b348eb7a 17ccae8b

+110
+7
tools/testing/selftests/damon/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # Makefile for damon selftests 3 + 4 + TEST_FILES = _chk_dependency.sh 5 + TEST_PROGS = debugfs_attrs.sh 6 + 7 + include ../lib.mk
+28
tools/testing/selftests/damon/_chk_dependency.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # Kselftest framework requirement - SKIP code is 4. 5 + ksft_skip=4 6 + 7 + DBGFS=/sys/kernel/debug/damon 8 + 9 + if [ $EUID -ne 0 ]; 10 + then 11 + echo "Run as root" 12 + exit $ksft_skip 13 + fi 14 + 15 + if [ ! -d "$DBGFS" ] 16 + then 17 + echo "$DBGFS not found" 18 + exit $ksft_skip 19 + fi 20 + 21 + for f in attrs target_ids monitor_on 22 + do 23 + if [ ! -f "$DBGFS/$f" ] 24 + then 25 + echo "$f not found" 26 + exit 1 27 + fi 28 + done
+75
tools/testing/selftests/damon/debugfs_attrs.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + test_write_result() { 5 + file=$1 6 + content=$2 7 + orig_content=$3 8 + expect_reason=$4 9 + expected=$5 10 + 11 + echo "$content" > "$file" 12 + if [ $? -ne "$expected" ] 13 + then 14 + echo "writing $content to $file doesn't return $expected" 15 + echo "expected because: $expect_reason" 16 + echo "$orig_content" > "$file" 17 + exit 1 18 + fi 19 + } 20 + 21 + test_write_succ() { 22 + test_write_result "$1" "$2" "$3" "$4" 0 23 + } 24 + 25 + test_write_fail() { 26 + test_write_result "$1" "$2" "$3" "$4" 1 27 + } 28 + 29 + test_content() { 30 + file=$1 31 + orig_content=$2 32 + expected=$3 33 + expect_reason=$4 34 + 35 + content=$(cat "$file") 36 + if [ "$content" != "$expected" ] 37 + then 38 + echo "reading $file expected $expected but $content" 39 + echo "expected because: $expect_reason" 40 + echo "$orig_content" > "$file" 41 + exit 1 42 + fi 43 + } 44 + 45 + source ./_chk_dependency.sh 46 + 47 + # Test attrs file 48 + # =============== 49 + 50 + file="$DBGFS/attrs" 51 + orig_content=$(cat "$file") 52 + 53 + test_write_succ "$file" "1 2 3 4 5" "$orig_content" "valid input" 54 + test_write_fail "$file" "1 2 3 4" "$orig_content" "no enough fields" 55 + test_write_fail "$file" "1 2 3 5 4" "$orig_content" \ 56 + "min_nr_regions > max_nr_regions" 57 + test_content "$file" "$orig_content" "1 2 3 4 5" "successfully written" 58 + echo "$orig_content" > "$file" 59 + 60 + # Test target_ids file 61 + # ==================== 62 + 63 + file="$DBGFS/target_ids" 64 + orig_content=$(cat "$file") 65 + 66 + test_write_succ "$file" "1 2 3 4" "$orig_content" "valid input" 67 + test_write_succ "$file" "1 2 abc 4" "$orig_content" "still valid input" 68 + test_content "$file" "$orig_content" "1 2" "non-integer was there" 69 + test_write_succ "$file" "abc 2 3" "$orig_content" "the file allows wrong input" 70 + test_content "$file" "$orig_content" "" "wrong input written" 71 + test_write_succ "$file" "" "$orig_content" "empty input" 72 + test_content "$file" "$orig_content" "" "empty input written" 73 + echo "$orig_content" > "$file" 74 + 75 + echo "PASS"