aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/kselftest
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2019-04-24 16:12:30 -0700
committerShuah Khan <skhan@linuxfoundation.org>2019-04-25 13:14:13 -0600
commit42d46e57ec9718c1090e43db75f433d0841af525 (patch)
tree64ff0ca94762558142eae3f9f3a8ab68f268b81c /tools/testing/selftests/kselftest
parentselftests: build and run gpio when output directory is the src dir (diff)
downloadwireguard-linux-42d46e57ec9718c1090e43db75f433d0841af525.tar.xz
wireguard-linux-42d46e57ec9718c1090e43db75f433d0841af525.zip
selftests: Extract single-test shell logic from lib.mk
In order to improve the reusability of the kselftest test running logic, this extracts the single-test logic from lib.mk into kselftest/runner.sh which lib.mk can call directly. No changes in output. As part of the change, this moves the "summary" Makefile logic around to set a new "logfile" output. This will be used again in the future "emit_tests" target as well. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/kselftest')
-rw-r--r--tools/testing/selftests/kselftest/runner.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
new file mode 100644
index 000000000000..e1117d703887
--- /dev/null
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Runs a set of tests in a given subdirectory.
+export skip_rc=4
+export logfile=/dev/stdout
+
+run_one()
+{
+ TEST="$1"
+ NUM="$2"
+
+ BASENAME_TEST=$(basename $TEST)
+
+ TEST_HDR_MSG="selftests: "`basename $PWD`:" $BASENAME_TEST"
+ echo "$TEST_HDR_MSG"
+ echo "========================================"
+ if [ ! -x "$TEST" ]; then
+ echo "$TEST_HDR_MSG: Warning: file $TEST is not executable, correct this."
+ echo "not ok 1..$test_num $TEST_HDR_MSG [FAIL]"
+ else
+ cd `dirname $TEST` > /dev/null
+ (./$BASENAME_TEST >> "$logfile" 2>&1 &&
+ echo "ok 1..$test_num $TEST_HDR_MSG [PASS]") ||
+ (if [ $? -eq $skip_rc ]; then \
+ echo "not ok 1..$test_num $TEST_HDR_MSG [SKIP]"
+ else
+ echo "not ok 1..$test_num $TEST_HDR_MSG [FAIL]"
+ fi)
+ cd - >/dev/null
+ fi
+}