selftests/kselftest/runner.sh: Add 45 second timeout per test
Commit a745f7af3c
("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>
This commit is contained in:
Родитель
131b30c94f
Коммит
852c8cbf34
|
@ -3,9 +3,14 @@
|
||||||
#
|
#
|
||||||
# Runs a set of tests in a given subdirectory.
|
# Runs a set of tests in a given subdirectory.
|
||||||
export skip_rc=4
|
export skip_rc=4
|
||||||
|
export timeout_rc=124
|
||||||
export logfile=/dev/stdout
|
export logfile=/dev/stdout
|
||||||
export per_test_logging=
|
export per_test_logging=
|
||||||
|
|
||||||
|
# Defaults for "settings" file fields:
|
||||||
|
# "timeout" how many seconds to let each test run before failing.
|
||||||
|
export kselftest_default_timeout=45
|
||||||
|
|
||||||
# There isn't a shell-agnostic way to find the path of a sourced file,
|
# There isn't a shell-agnostic way to find the path of a sourced file,
|
||||||
# so we must rely on BASE_DIR being set to find other tools.
|
# so we must rely on BASE_DIR being set to find other tools.
|
||||||
if [ -z "$BASE_DIR" ]; then
|
if [ -z "$BASE_DIR" ]; then
|
||||||
|
@ -24,6 +29,16 @@ tap_prefix()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tap_timeout()
|
||||||
|
{
|
||||||
|
# Make sure tests will time out if utility is available.
|
||||||
|
if [ -x /usr/bin/timeout ] ; then
|
||||||
|
/usr/bin/timeout "$kselftest_timeout" "$1"
|
||||||
|
else
|
||||||
|
"$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
run_one()
|
run_one()
|
||||||
{
|
{
|
||||||
DIR="$1"
|
DIR="$1"
|
||||||
|
@ -32,6 +47,18 @@ run_one()
|
||||||
|
|
||||||
BASENAME_TEST=$(basename $TEST)
|
BASENAME_TEST=$(basename $TEST)
|
||||||
|
|
||||||
|
# Reset any "settings"-file variables.
|
||||||
|
export kselftest_timeout="$kselftest_default_timeout"
|
||||||
|
# Load per-test-directory kselftest "settings" file.
|
||||||
|
settings="$BASE_DIR/$DIR/settings"
|
||||||
|
if [ -r "$settings" ] ; then
|
||||||
|
while read line ; do
|
||||||
|
field=$(echo "$line" | cut -d= -f1)
|
||||||
|
value=$(echo "$line" | cut -d= -f2-)
|
||||||
|
eval "kselftest_$field"="$value"
|
||||||
|
done < "$settings"
|
||||||
|
fi
|
||||||
|
|
||||||
TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
|
TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
|
||||||
echo "# $TEST_HDR_MSG"
|
echo "# $TEST_HDR_MSG"
|
||||||
if [ ! -x "$TEST" ]; then
|
if [ ! -x "$TEST" ]; then
|
||||||
|
@ -44,14 +71,17 @@ run_one()
|
||||||
echo "not ok $test_num $TEST_HDR_MSG"
|
echo "not ok $test_num $TEST_HDR_MSG"
|
||||||
else
|
else
|
||||||
cd `dirname $TEST` > /dev/null
|
cd `dirname $TEST` > /dev/null
|
||||||
(((((./$BASENAME_TEST 2>&1; echo $? >&3) |
|
((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
|
||||||
tap_prefix >&4) 3>&1) |
|
tap_prefix >&4) 3>&1) |
|
||||||
(read xs; exit $xs)) 4>>"$logfile" &&
|
(read xs; exit $xs)) 4>>"$logfile" &&
|
||||||
echo "ok $test_num $TEST_HDR_MSG") ||
|
echo "ok $test_num $TEST_HDR_MSG") ||
|
||||||
(if [ $? -eq $skip_rc ]; then \
|
(rc=$?; \
|
||||||
|
if [ $rc -eq $skip_rc ]; then \
|
||||||
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
|
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
|
||||||
|
elif [ $rc -eq $timeout_rc ]; then \
|
||||||
|
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
|
||||||
else
|
else
|
||||||
echo "not ok $test_num $TEST_HDR_MSG"
|
echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
|
||||||
fi)
|
fi)
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
timeout=90
|
Загрузка…
Ссылка в новой задаче