Skip to content

Commit ccba8b6

Browse files
compudjKAGA-KOKO
authored andcommitted
rseq/selftests: Provide Makefile, scripts, gitignore
A run_param_test.sh script runs many variants of the parametrizable tests. Wire up the rseq Makefile, add directory entry into MAINTAINERS file. Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Dave Watson <[email protected]> Cc: Will Deacon <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Andi Kleen <[email protected]> Cc: [email protected] Cc: "H . Peter Anvin" <[email protected]> Cc: Chris Lameter <[email protected]> Cc: Russell King <[email protected]> Cc: Andrew Hunter <[email protected]> Cc: Michael Kerrisk <[email protected]> Cc: "Paul E . McKenney" <[email protected]> Cc: Paul Turner <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Josh Triplett <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Ben Maurer <[email protected]> Cc: [email protected] Cc: Andy Lutomirski <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c960e99 commit ccba8b6

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11986,6 +11986,7 @@ S: Supported
1198611986
F: kernel/rseq.c
1198711987
F: include/uapi/linux/rseq.h
1198811988
F: include/trace/events/rseq.h
11989+
F: tools/testing/selftests/rseq/
1198911990

1199011991
RFKILL
1199111992
M: Johannes Berg <[email protected]>

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TARGETS += powerpc
2828
TARGETS += proc
2929
TARGETS += pstore
3030
TARGETS += ptrace
31+
TARGETS += rseq
3132
TARGETS += seccomp
3233
TARGETS += sigaltstack
3334
TARGETS += size
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
basic_percpu_ops_test
2+
basic_test
3+
basic_rseq_op_test
4+
param_test
5+
param_test_benchmark
6+
param_test_compare_twice

tools/testing/selftests/rseq/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: GPL-2.0+ OR MIT
2+
CFLAGS += -O2 -Wall -g -I./ -I../../../../usr/include/ -L./ -Wl,-rpath=./
3+
LDLIBS += -lpthread
4+
5+
# Own dependencies because we only want to build against 1st prerequisite, but
6+
# still track changes to header files and depend on shared object.
7+
OVERRIDE_TARGETS = 1
8+
9+
TEST_GEN_PROGS = basic_test basic_percpu_ops_test param_test \
10+
param_test_benchmark param_test_compare_twice
11+
12+
TEST_GEN_PROGS_EXTENDED = librseq.so
13+
14+
TEST_PROGS = run_param_test.sh
15+
16+
include ../lib.mk
17+
18+
$(OUTPUT)/librseq.so: rseq.c rseq.h rseq-*.h
19+
$(CC) $(CFLAGS) -shared -fPIC $< $(LDLIBS) -o $@
20+
21+
$(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h
22+
$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
23+
24+
$(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
25+
rseq.h rseq-*.h
26+
$(CC) $(CFLAGS) -DBENCHMARK $< $(LDLIBS) -lrseq -o $@
27+
28+
$(OUTPUT)/param_test_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
29+
rseq.h rseq-*.h
30+
$(CC) $(CFLAGS) -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0+ or MIT
3+
4+
EXTRA_ARGS=${@}
5+
6+
OLDIFS="$IFS"
7+
IFS=$'\n'
8+
TEST_LIST=(
9+
"-T s"
10+
"-T l"
11+
"-T b"
12+
"-T b -M"
13+
"-T m"
14+
"-T m -M"
15+
"-T i"
16+
)
17+
18+
TEST_NAME=(
19+
"spinlock"
20+
"list"
21+
"buffer"
22+
"buffer with barrier"
23+
"memcpy"
24+
"memcpy with barrier"
25+
"increment"
26+
)
27+
IFS="$OLDIFS"
28+
29+
REPS=1000
30+
SLOW_REPS=100
31+
32+
function do_tests()
33+
{
34+
local i=0
35+
while [ "$i" -lt "${#TEST_LIST[@]}" ]; do
36+
echo "Running test ${TEST_NAME[$i]}"
37+
./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
38+
echo "Running compare-twice test ${TEST_NAME[$i]}"
39+
./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
40+
let "i++"
41+
done
42+
}
43+
44+
echo "Default parameters"
45+
do_tests
46+
47+
echo "Loop injection: 10000 loops"
48+
49+
OLDIFS="$IFS"
50+
IFS=$'\n'
51+
INJECT_LIST=(
52+
"1"
53+
"2"
54+
"3"
55+
"4"
56+
"5"
57+
"6"
58+
"7"
59+
"8"
60+
"9"
61+
)
62+
IFS="$OLDIFS"
63+
64+
NR_LOOPS=10000
65+
66+
i=0
67+
while [ "$i" -lt "${#INJECT_LIST[@]}" ]; do
68+
echo "Injecting at <${INJECT_LIST[$i]}>"
69+
do_tests -${INJECT_LIST[i]} ${NR_LOOPS}
70+
let "i++"
71+
done
72+
NR_LOOPS=
73+
74+
function inject_blocking()
75+
{
76+
OLDIFS="$IFS"
77+
IFS=$'\n'
78+
INJECT_LIST=(
79+
"7"
80+
"8"
81+
"9"
82+
)
83+
IFS="$OLDIFS"
84+
85+
NR_LOOPS=-1
86+
87+
i=0
88+
while [ "$i" -lt "${#INJECT_LIST[@]}" ]; do
89+
echo "Injecting at <${INJECT_LIST[$i]}>"
90+
do_tests -${INJECT_LIST[i]} -1 ${@}
91+
let "i++"
92+
done
93+
NR_LOOPS=
94+
}
95+
96+
echo "Yield injection (25%)"
97+
inject_blocking -m 4 -y
98+
99+
echo "Yield injection (50%)"
100+
inject_blocking -m 2 -y
101+
102+
echo "Yield injection (100%)"
103+
inject_blocking -m 1 -y
104+
105+
echo "Kill injection (25%)"
106+
inject_blocking -m 4 -k
107+
108+
echo "Kill injection (50%)"
109+
inject_blocking -m 2 -k
110+
111+
echo "Kill injection (100%)"
112+
inject_blocking -m 1 -k
113+
114+
echo "Sleep injection (1ms, 25%)"
115+
inject_blocking -m 4 -s 1
116+
117+
echo "Sleep injection (1ms, 50%)"
118+
inject_blocking -m 2 -s 1
119+
120+
echo "Sleep injection (1ms, 100%)"
121+
inject_blocking -m 1 -s 1

0 commit comments

Comments
 (0)