Skip to content

Commit 9ab3b0c

Browse files
sjp38torvalds
authored andcommitted
selftests/damon: split test cases
Currently, the single test program, debugfs.sh, contains all test cases for DAMON. When one of the cases fails, finding which case is failed from the test log is not so easy, and all remaining tests will be skipped. To improve the situation, this commit splits the single program into small test programs having their own names. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Brendan Higgins <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b4a0028 commit 9ab3b0c

File tree

7 files changed

+129
-112
lines changed

7 files changed

+129
-112
lines changed

tools/testing/selftests/damon/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
TEST_GEN_FILES += huge_count_read_write
55

6-
TEST_FILES = _chk_dependency.sh
7-
TEST_PROGS = debugfs_attrs.sh
6+
TEST_FILES = _chk_dependency.sh _debugfs_common.sh
7+
TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
8+
TEST_PROGS += debugfs_empty_targets.sh debugfs_huge_count_read_write.sh
89

910
include ../lib.mk
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
damon_onoff="$DBGFS/monitor_on"
48+
if [ $(cat "$damon_onoff") = "on" ]
49+
then
50+
echo "monitoring is on"
51+
exit $ksft_skip
52+
fi
Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

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-
ksft_skip=4
48-
49-
damon_onoff="$DBGFS/monitor_on"
50-
if [ $(cat "$damon_onoff") = "on" ]
51-
then
52-
echo "monitoring is on"
53-
exit $ksft_skip
54-
fi
4+
source _debugfs_common.sh
555

566
# Test attrs file
577
# ===============
@@ -65,62 +15,3 @@ test_write_fail "$file" "1 2 3 5 4" "$orig_content" \
6515
"min_nr_regions > max_nr_regions"
6616
test_content "$file" "$orig_content" "1 2 3 4 5" "successfully written"
6717
echo "$orig_content" > "$file"
68-
69-
# Test schemes file
70-
# =================
71-
72-
file="$DBGFS/schemes"
73-
orig_content=$(cat "$file")
74-
75-
test_write_succ "$file" "1 2 3 4 5 6 4 0 0 0 1 2 3 1 100 3 2 1" \
76-
"$orig_content" "valid input"
77-
test_write_fail "$file" "1 2
78-
3 4 5 6 3 0 0 0 1 2 3 1 100 3 2 1" "$orig_content" "multi lines"
79-
test_write_succ "$file" "" "$orig_content" "disabling"
80-
test_write_fail "$file" "2 1 2 1 10 1 3 10 1 1 1 1 1 1 1 1 2 3" \
81-
"$orig_content" "wrong condition ranges"
82-
echo "$orig_content" > "$file"
83-
84-
# Test target_ids file
85-
# ====================
86-
87-
file="$DBGFS/target_ids"
88-
orig_content=$(cat "$file")
89-
90-
test_write_succ "$file" "1 2 3 4" "$orig_content" "valid input"
91-
test_write_succ "$file" "1 2 abc 4" "$orig_content" "still valid input"
92-
test_content "$file" "$orig_content" "1 2" "non-integer was there"
93-
test_write_succ "$file" "abc 2 3" "$orig_content" "the file allows wrong input"
94-
test_content "$file" "$orig_content" "" "wrong input written"
95-
test_write_succ "$file" "" "$orig_content" "empty input"
96-
test_content "$file" "$orig_content" "" "empty input written"
97-
echo "$orig_content" > "$file"
98-
99-
# Test empty targets case
100-
# =======================
101-
102-
orig_target_ids=$(cat "$DBGFS/target_ids")
103-
echo "" > "$DBGFS/target_ids"
104-
orig_monitor_on=$(cat "$DBGFS/monitor_on")
105-
test_write_fail "$DBGFS/monitor_on" "on" "orig_monitor_on" "empty target ids"
106-
echo "$orig_target_ids" > "$DBGFS/target_ids"
107-
108-
# Test huge count read write
109-
# ==========================
110-
111-
dmesg -C
112-
113-
for file in "$DBGFS/"*
114-
do
115-
./huge_count_read_write "$file"
116-
done
117-
118-
if dmesg | grep -q WARNING
119-
then
120-
dmesg
121-
exit 1
122-
else
123-
exit 0
124-
fi
125-
126-
echo "PASS"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
source _debugfs_common.sh
5+
6+
# Test empty targets case
7+
# =======================
8+
9+
orig_target_ids=$(cat "$DBGFS/target_ids")
10+
echo "" > "$DBGFS/target_ids"
11+
orig_monitor_on=$(cat "$DBGFS/monitor_on")
12+
test_write_fail "$DBGFS/monitor_on" "on" "orig_monitor_on" "empty target ids"
13+
echo "$orig_target_ids" > "$DBGFS/target_ids"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
source _debugfs_common.sh
5+
6+
# Test huge count read write
7+
# ==========================
8+
9+
dmesg -C
10+
11+
for file in "$DBGFS/"*
12+
do
13+
./huge_count_read_write "$file"
14+
done
15+
16+
if dmesg | grep -q WARNING
17+
then
18+
dmesg
19+
exit 1
20+
else
21+
exit 0
22+
fi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
source _debugfs_common.sh
5+
6+
# Test schemes file
7+
# =================
8+
9+
file="$DBGFS/schemes"
10+
orig_content=$(cat "$file")
11+
12+
test_write_succ "$file" "1 2 3 4 5 6 4 0 0 0 1 2 3 1 100 3 2 1" \
13+
"$orig_content" "valid input"
14+
test_write_fail "$file" "1 2
15+
3 4 5 6 3 0 0 0 1 2 3 1 100 3 2 1" "$orig_content" "multi lines"
16+
test_write_succ "$file" "" "$orig_content" "disabling"
17+
test_write_fail "$file" "2 1 2 1 10 1 3 10 1 1 1 1 1 1 1 1 2 3" \
18+
"$orig_content" "wrong condition ranges"
19+
echo "$orig_content" > "$file"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
source _debugfs_common.sh
5+
6+
# Test target_ids file
7+
# ====================
8+
9+
file="$DBGFS/target_ids"
10+
orig_content=$(cat "$file")
11+
12+
test_write_succ "$file" "1 2 3 4" "$orig_content" "valid input"
13+
test_write_succ "$file" "1 2 abc 4" "$orig_content" "still valid input"
14+
test_content "$file" "$orig_content" "1 2" "non-integer was there"
15+
test_write_succ "$file" "abc 2 3" "$orig_content" "the file allows wrong input"
16+
test_content "$file" "$orig_content" "" "wrong input written"
17+
test_write_succ "$file" "" "$orig_content" "empty input"
18+
test_content "$file" "$orig_content" "" "empty input written"
19+
echo "$orig_content" > "$file"

0 commit comments

Comments
 (0)