Skip to content

Commit f0f0a5d

Browse files
keesshuahkh
authored andcommitted
selftests: Extract run_kselftest.sh and generate stand-alone test list
Instead of building a script on the fly (which just repeats the same thing for each test collection), move the script out of the Makefile and into run_kselftest.sh, which reads kselftest-list.txt. Adjust the emit_tests target to report each test on a separate line so that test running tools (e.g. LAVA) can easily remove individual tests (for example, as seen in [1]). [1] Linaro/test-definitions@2e7b621 Signed-off-by: Kees Cook <keescook@chromium.org> Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 997a91f commit f0f0a5d

3 files changed

Lines changed: 37 additions & 22 deletions

File tree

tools/testing/selftests/Makefile

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
206206
# Avoid changing the rest of the logic here and lib.mk.
207207
INSTALL_PATH := $(KSFT_INSTALL_PATH)
208208
ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
209+
TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
209210

210211
install: all
211212
ifdef INSTALL_PATH
@@ -214,6 +215,8 @@ ifdef INSTALL_PATH
214215
install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
215216
install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
216217
install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
218+
install -m 744 run_kselftest.sh $(INSTALL_PATH)/
219+
rm -f $(TEST_LIST)
217220
@ret=1; \
218221
for TARGET in $(TARGETS); do \
219222
BUILD_TARGET=$$BUILD/$$TARGET; \
@@ -222,33 +225,18 @@ ifdef INSTALL_PATH
222225
ret=$$((ret * $$?)); \
223226
done; exit $$ret;
224227

225-
@# Ask all targets to emit their test scripts
226-
echo "#!/bin/sh" > $(ALL_SCRIPT)
227-
echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
228-
echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
229-
echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
230-
echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
231-
echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
232-
echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
233-
echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
234-
echo "fi" >> $(ALL_SCRIPT)
235228

236-
@# While building run_kselftest.sh skip also non-existent TARGET dirs:
229+
@# Ask all targets to emit their test scripts
230+
@# While building kselftest-list.text skip also non-existent TARGET dirs:
237231
@# they could be the result of a build failure and should NOT be
238232
@# included in the generated runlist.
239233
for TARGET in $(TARGETS); do \
240234
BUILD_TARGET=$$BUILD/$$TARGET; \
241235
[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
242-
echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
243-
echo "cd $$TARGET" >> $(ALL_SCRIPT); \
244-
echo -n "run_many" >> $(ALL_SCRIPT); \
245236
echo -n "Emit Tests for $$TARGET\n"; \
246-
$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
247-
echo "" >> $(ALL_SCRIPT); \
248-
echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
237+
$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
238+
-C $$TARGET emit_tests >> $(TEST_LIST); \
249239
done;
250-
251-
chmod u+x $(ALL_SCRIPT)
252240
else
253241
$(error Error: set INSTALL_PATH to use install)
254242
endif

tools/testing/selftests/lib.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ endif
107107
emit_tests:
108108
for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
109109
BASENAME_TEST=`basename $$TEST`; \
110-
echo " \\"; \
111-
echo -n " \"$$BASENAME_TEST\""; \
112-
done; \
110+
echo "$(COLLECTION):$$BASENAME_TEST"; \
111+
done
113112

114113
# define if isn't already. It is undefined in make O= case.
115114
ifeq ($(RM),)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Run installed kselftest tests.
5+
#
6+
BASE_DIR=$(realpath $(dirname $0))
7+
cd $BASE_DIR
8+
TESTS="$BASE_DIR"/kselftest-list.txt
9+
if [ ! -r "$TESTS" ] ; then
10+
echo "$0: Could not find list of tests to run ($TESTS)" >&2
11+
exit 1
12+
fi
13+
available="$(cat "$TESTS")"
14+
15+
. ./kselftest/runner.sh
16+
ROOT=$PWD
17+
18+
if [ "$1" = "--summary" ] ; then
19+
logfile="$BASE_DIR"/output.log
20+
cat /dev/null > $logfile
21+
fi
22+
23+
collections=$(echo "$available" | cut -d: -f1 | uniq)
24+
for collection in $collections ; do
25+
[ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg
26+
tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2)
27+
(cd "$collection" && run_many $tests)
28+
done

0 commit comments

Comments
 (0)