Skip to content

Commit ce7ae9d

Browse files
committed
Merge tag 'linux-kselftest-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest update from Shuah Khan: "This Kselftest update consists of several fixes to framework and individual tests. In addition, it enables LKDTM tests adding lkdtm target to kselftest Makefile" * tag 'linux-kselftest-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/ftrace: fix glob selftest selftests: settings: tests can be in subsubdirs kselftest: Minimise dependency of get_size on C library interfaces selftests/livepatch: Remove unused local variable in set_ftrace_enabled() selftests/livepatch: Replace set_dynamic_debug() with setup_config() in README selftests/lkdtm: Add tests for LKDTM targets selftests: Uninitialized variable in test_cgcore_proc_migration() selftests: fix build behaviour on targets' failures
2 parents 22b17db + af4ddd6 commit ce7ae9d

File tree

12 files changed

+211
-18
lines changed

12 files changed

+211
-18
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9656,6 +9656,7 @@ LINUX KERNEL DUMP TEST MODULE (LKDTM)
96569656
M: Kees Cook <[email protected]>
96579657
S: Maintained
96589658
F: drivers/misc/lkdtm/*
9659+
F: tools/testing/selftests/lkdtm/*
96599660

96609661
LINUX KERNEL MEMORY CONSISTENCY MODEL (LKMM)
96619662
M: Alan Stern <[email protected]>

tools/testing/selftests/Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TARGETS += kexec
2626
TARGETS += kvm
2727
TARGETS += lib
2828
TARGETS += livepatch
29+
TARGETS += lkdtm
2930
TARGETS += membarrier
3031
TARGETS += memfd
3132
TARGETS += memory-hotplug
@@ -146,11 +147,13 @@ else
146147
endif
147148

148149
all: khdr
149-
@for TARGET in $(TARGETS); do \
150-
BUILD_TARGET=$$BUILD/$$TARGET; \
151-
mkdir $$BUILD_TARGET -p; \
152-
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
153-
done;
150+
@ret=1; \
151+
for TARGET in $(TARGETS); do \
152+
BUILD_TARGET=$$BUILD/$$TARGET; \
153+
mkdir $$BUILD_TARGET -p; \
154+
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET; \
155+
ret=$$((ret * $$?)); \
156+
done; exit $$ret;
154157

155158
run_tests: all
156159
@for TARGET in $(TARGETS); do \
@@ -199,10 +202,12 @@ ifdef INSTALL_PATH
199202
install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
200203
install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
201204
install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
202-
@for TARGET in $(TARGETS); do \
205+
@ret=1; \
206+
for TARGET in $(TARGETS); do \
203207
BUILD_TARGET=$$BUILD/$$TARGET; \
204208
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
205-
done;
209+
ret=$$((ret * $$?)); \
210+
done; exit $$ret;
206211

207212
@# Ask all targets to emit their test scripts
208213
echo "#!/bin/sh" > $(ALL_SCRIPT)

tools/testing/selftests/cgroup/test_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static void *dummy_thread_fn(void *arg)
369369
static int test_cgcore_proc_migration(const char *root)
370370
{
371371
int ret = KSFT_FAIL;
372-
int t, c_threads, n_threads = 13;
372+
int t, c_threads = 0, n_threads = 13;
373373
char *src = NULL, *dst = NULL;
374374
pthread_t threads[n_threads];
375375

tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ftrace_filter_check '*schedule*' '^.*schedule.*$'
3030
ftrace_filter_check 'schedule*' '^schedule.*$'
3131

3232
# filter by *mid*end
33-
ftrace_filter_check '*aw*lock' '.*aw.*lock$'
33+
ftrace_filter_check '*pin*lock' '.*pin.*lock$'
3434

3535
# filter by start*mid*
3636
ftrace_filter_check 'mutex*try*' '^mutex.*try.*'

tools/testing/selftests/kselftest/runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ run_one()
9191
run_many()
9292
{
9393
echo "TAP version 13"
94-
DIR=$(basename "$PWD")
94+
DIR="${PWD#${BASE_DIR}/}"
9595
test_num=0
9696
total=$(echo "$@" | wc -w)
9797
echo "1..$total"

tools/testing/selftests/livepatch/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Adding tests
3535
------------
3636

3737
See the common functions.sh file for the existing collection of utility
38-
functions, most importantly set_dynamic_debug() and check_result(). The
38+
functions, most importantly setup_config() and check_result(). The
3939
latter function greps the kernel's ring buffer for "livepatch:" and
4040
"test_klp" strings, so tests be sure to include one of those strings for
4141
result comparison. Other utility functions include general module

tools/testing/selftests/livepatch/functions.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ function set_dynamic_debug() {
6464
}
6565

6666
function set_ftrace_enabled() {
67-
local sysctl="$1"
6867
result=$(sysctl kernel.ftrace_enabled="$1" 2>&1 | paste --serial --delimiters=' ')
6968
echo "livepatch: $result" > /dev/kmsg
7069
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Makefile for LKDTM regression tests
3+
4+
include ../lib.mk
5+
6+
# NOTE: $(OUTPUT) won't get default value if used before lib.mk
7+
TEST_FILES := tests.txt
8+
TEST_GEN_PROGS = $(patsubst %,$(OUTPUT)/%.sh,$(shell awk '{print $$1}' tests.txt | sed -e 's/\#//'))
9+
all: $(TEST_GEN_PROGS)
10+
11+
$(OUTPUT)/%: run.sh tests.txt
12+
install -m 0744 run.sh $@

tools/testing/selftests/lkdtm/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_LKDTM=y

tools/testing/selftests/lkdtm/run.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# This reads tests.txt for the list of LKDTM tests to invoke. Any marked
5+
# with a leading "#" are skipped. The rest of the line after the
6+
# test name is either the text to look for in dmesg for a "success",
7+
# or the rationale for why a test is marked to be skipped.
8+
#
9+
set -e
10+
TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT
11+
KSELFTEST_SKIP_TEST=4
12+
13+
# Verify we have LKDTM available in the kernel.
14+
if [ ! -r $TRIGGER ] ; then
15+
/sbin/modprobe -q lkdtm || true
16+
if [ ! -r $TRIGGER ] ; then
17+
echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)"
18+
else
19+
echo "Cannot write $TRIGGER (need to run as root?)"
20+
fi
21+
# Skip this test
22+
exit $KSELFTEST_SKIP_TEST
23+
fi
24+
25+
# Figure out which test to run from our script name.
26+
test=$(basename $0 .sh)
27+
# Look up details about the test from master list of LKDTM tests.
28+
line=$(egrep '^#?'"$test"'\b' tests.txt)
29+
if [ -z "$line" ]; then
30+
echo "Skipped: missing test '$test' in tests.txt"
31+
exit $KSELFTEST_SKIP_TEST
32+
fi
33+
# Check that the test is known to LKDTM.
34+
if ! egrep -q '^'"$test"'$' "$TRIGGER" ; then
35+
echo "Skipped: test '$test' missing in $TRIGGER!"
36+
exit $KSELFTEST_SKIP_TEST
37+
fi
38+
39+
# Extract notes/expected output from test list.
40+
test=$(echo "$line" | cut -d" " -f1)
41+
if echo "$line" | grep -q ' ' ; then
42+
expect=$(echo "$line" | cut -d" " -f2-)
43+
else
44+
expect=""
45+
fi
46+
47+
# If the test is commented out, report a skip
48+
if echo "$test" | grep -q '^#' ; then
49+
test=$(echo "$test" | cut -c2-)
50+
if [ -z "$expect" ]; then
51+
expect="crashes entire system"
52+
fi
53+
echo "Skipping $test: $expect"
54+
exit $KSELFTEST_SKIP_TEST
55+
fi
56+
57+
# If no expected output given, assume an Oops with back trace is success.
58+
if [ -z "$expect" ]; then
59+
expect="call trace:"
60+
fi
61+
62+
# Clear out dmesg for output reporting
63+
dmesg -c >/dev/null
64+
65+
# Prepare log for report checking
66+
LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX)
67+
cleanup() {
68+
rm -f "$LOG"
69+
}
70+
trap cleanup EXIT
71+
72+
# Most shells yell about signals and we're expecting the "cat" process
73+
# to usually be killed by the kernel. So we have to run it in a sub-shell
74+
# and silence errors.
75+
($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
76+
77+
# Record and dump the results
78+
dmesg -c >"$LOG"
79+
cat "$LOG"
80+
# Check for expected output
81+
if egrep -qi "$expect" "$LOG" ; then
82+
echo "$test: saw '$expect': ok"
83+
exit 0
84+
else
85+
if egrep -qi XFAIL: "$LOG" ; then
86+
echo "$test: saw 'XFAIL': [SKIP]"
87+
exit $KSELFTEST_SKIP_TEST
88+
else
89+
echo "$test: missing '$expect': [FAIL]"
90+
exit 1
91+
fi
92+
fi

0 commit comments

Comments
 (0)