diff options
author | Kees Cook <keescook@chromium.org> | 2019-09-19 14:06:44 -0400 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2019-10-01 15:33:28 -0400 |
commit | 852c8cbf34d3b3130a05c38064dd98614f97d3a8 (patch) | |
tree | 8222cc49a8994be03006e4ae53f1cea8d942ea30 /tools | |
parent | 131b30c94fbc0adb15f911609884dd39dada8f00 (diff) |
selftests/kselftest/runner.sh: Add 45 second timeout per test
Commit a745f7af3cbd ("selftests/harness: Add 30 second timeout per
test") solves the problem of kselftest_harness.h-using binary tests
possibly hanging forever. However, scripts and other binaries can still
hang forever. This adds a global timeout to each test script run.
To make this configurable (e.g. as needed in the "rtc" test case),
include a new per-test-directory "settings" file (similar to "config")
that can contain kselftest-specific settings. The first recognized field
is "timeout".
Additionally, this splits the reporting for timeouts into a specific
"TIMEOUT" not-ok (and adds exit code reporting in the remaining case).
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/kselftest/runner.sh | 36 | ||||
-rw-r--r-- | tools/testing/selftests/rtc/settings | 1 |
2 files changed, 34 insertions, 3 deletions
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index 00c9020bdda8..84de7bc74f2c 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh | |||
@@ -3,9 +3,14 @@ | |||
3 | # | 3 | # |
4 | # Runs a set of tests in a given subdirectory. | 4 | # Runs a set of tests in a given subdirectory. |
5 | export skip_rc=4 | 5 | export skip_rc=4 |
6 | export timeout_rc=124 | ||
6 | export logfile=/dev/stdout | 7 | export logfile=/dev/stdout |
7 | export per_test_logging= | 8 | export per_test_logging= |
8 | 9 | ||
10 | # Defaults for "settings" file fields: | ||
11 | # "timeout" how many seconds to let each test run before failing. | ||
12 | export kselftest_default_timeout=45 | ||
13 | |||
9 | # There isn't a shell-agnostic way to find the path of a sourced file, | 14 | # There isn't a shell-agnostic way to find the path of a sourced file, |
10 | # so we must rely on BASE_DIR being set to find other tools. | 15 | # so we must rely on BASE_DIR being set to find other tools. |
11 | if [ -z "$BASE_DIR" ]; then | 16 | if [ -z "$BASE_DIR" ]; then |
@@ -24,6 +29,16 @@ tap_prefix() | |||
24 | fi | 29 | fi |
25 | } | 30 | } |
26 | 31 | ||
32 | tap_timeout() | ||
33 | { | ||
34 | # Make sure tests will time out if utility is available. | ||
35 | if [ -x /usr/bin/timeout ] ; then | ||
36 | /usr/bin/timeout "$kselftest_timeout" "$1" | ||
37 | else | ||
38 | "$1" | ||
39 | fi | ||
40 | } | ||
41 | |||
27 | run_one() | 42 | run_one() |
28 | { | 43 | { |
29 | DIR="$1" | 44 | DIR="$1" |
@@ -32,6 +47,18 @@ run_one() | |||
32 | 47 | ||
33 | BASENAME_TEST=$(basename $TEST) | 48 | BASENAME_TEST=$(basename $TEST) |
34 | 49 | ||
50 | # Reset any "settings"-file variables. | ||
51 | export kselftest_timeout="$kselftest_default_timeout" | ||
52 | # Load per-test-directory kselftest "settings" file. | ||
53 | settings="$BASE_DIR/$DIR/settings" | ||
54 | if [ -r "$settings" ] ; then | ||
55 | while read line ; do | ||
56 | field=$(echo "$line" | cut -d= -f1) | ||
57 | value=$(echo "$line" | cut -d= -f2-) | ||
58 | eval "kselftest_$field"="$value" | ||
59 | done < "$settings" | ||
60 | fi | ||
61 | |||
35 | TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" | 62 | TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" |
36 | echo "# $TEST_HDR_MSG" | 63 | echo "# $TEST_HDR_MSG" |
37 | if [ ! -x "$TEST" ]; then | 64 | if [ ! -x "$TEST" ]; then |
@@ -44,14 +71,17 @@ run_one() | |||
44 | echo "not ok $test_num $TEST_HDR_MSG" | 71 | echo "not ok $test_num $TEST_HDR_MSG" |
45 | else | 72 | else |
46 | cd `dirname $TEST` > /dev/null | 73 | cd `dirname $TEST` > /dev/null |
47 | (((((./$BASENAME_TEST 2>&1; echo $? >&3) | | 74 | ((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) | |
48 | tap_prefix >&4) 3>&1) | | 75 | tap_prefix >&4) 3>&1) | |
49 | (read xs; exit $xs)) 4>>"$logfile" && | 76 | (read xs; exit $xs)) 4>>"$logfile" && |
50 | echo "ok $test_num $TEST_HDR_MSG") || | 77 | echo "ok $test_num $TEST_HDR_MSG") || |
51 | (if [ $? -eq $skip_rc ]; then \ | 78 | (rc=$?; \ |
79 | if [ $rc -eq $skip_rc ]; then \ | ||
52 | echo "not ok $test_num $TEST_HDR_MSG # SKIP" | 80 | echo "not ok $test_num $TEST_HDR_MSG # SKIP" |
81 | elif [ $rc -eq $timeout_rc ]; then \ | ||
82 | echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT" | ||
53 | else | 83 | else |
54 | echo "not ok $test_num $TEST_HDR_MSG" | 84 | echo "not ok $test_num $TEST_HDR_MSG # exit=$rc" |
55 | fi) | 85 | fi) |
56 | cd - >/dev/null | 86 | cd - >/dev/null |
57 | fi | 87 | fi |
diff --git a/tools/testing/selftests/rtc/settings b/tools/testing/selftests/rtc/settings new file mode 100644 index 000000000000..ba4d85f74cd6 --- /dev/null +++ b/tools/testing/selftests/rtc/settings | |||
@@ -0,0 +1 @@ | |||
timeout=90 | |||