2019-04-25 07:12:30 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
#
|
|
|
|
# Runs a set of tests in a given subdirectory.
|
|
|
|
export skip_rc=4
|
2019-09-20 02:06:44 +08:00
|
|
|
export timeout_rc=124
|
2019-04-25 07:12:30 +08:00
|
|
|
export logfile=/dev/stdout
|
2019-04-25 07:12:32 +08:00
|
|
|
export per_test_logging=
|
2019-04-25 07:12:30 +08:00
|
|
|
|
2019-09-20 02:06:44 +08:00
|
|
|
# Defaults for "settings" file fields:
|
|
|
|
# "timeout" how many seconds to let each test run before failing.
|
|
|
|
export kselftest_default_timeout=45
|
|
|
|
|
2019-04-25 07:12:35 +08:00
|
|
|
# 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.
|
|
|
|
if [ -z "$BASE_DIR" ]; then
|
|
|
|
echo "Error: BASE_DIR must be set before sourcing." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If Perl is unavailable, we must fall back to line-at-a-time prefixing
|
|
|
|
# with sed instead of unbuffered output.
|
|
|
|
tap_prefix()
|
|
|
|
{
|
|
|
|
if [ ! -x /usr/bin/perl ]; then
|
|
|
|
sed -e 's/^/# /'
|
|
|
|
else
|
|
|
|
"$BASE_DIR"/kselftest/prefix.pl
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-09-20 02:06:44 +08:00
|
|
|
tap_timeout()
|
|
|
|
{
|
|
|
|
# Make sure tests will time out if utility is available.
|
|
|
|
if [ -x /usr/bin/timeout ] ; then
|
2020-04-10 18:02:59 +08:00
|
|
|
/usr/bin/timeout --foreground "$kselftest_timeout" "$1"
|
2019-09-20 02:06:44 +08:00
|
|
|
else
|
|
|
|
"$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-25 07:12:30 +08:00
|
|
|
run_one()
|
|
|
|
{
|
2019-04-25 07:12:32 +08:00
|
|
|
DIR="$1"
|
|
|
|
TEST="$2"
|
|
|
|
NUM="$3"
|
2019-04-25 07:12:30 +08:00
|
|
|
|
|
|
|
BASENAME_TEST=$(basename $TEST)
|
|
|
|
|
2019-09-20 02:06:44 +08:00
|
|
|
# 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
|
|
|
|
|
2019-04-25 07:12:32 +08:00
|
|
|
TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
|
2019-04-25 07:12:35 +08:00
|
|
|
echo "# $TEST_HDR_MSG"
|
2019-04-25 07:12:30 +08:00
|
|
|
if [ ! -x "$TEST" ]; then
|
2019-04-25 07:12:35 +08:00
|
|
|
echo -n "# Warning: file $TEST is "
|
2019-04-25 07:12:34 +08:00
|
|
|
if [ ! -e "$TEST" ]; then
|
|
|
|
echo "missing!"
|
|
|
|
else
|
|
|
|
echo "not executable, correct this."
|
|
|
|
fi
|
2019-04-25 07:12:33 +08:00
|
|
|
echo "not ok $test_num $TEST_HDR_MSG"
|
2019-04-25 07:12:30 +08:00
|
|
|
else
|
|
|
|
cd `dirname $TEST` > /dev/null
|
2019-09-20 02:06:44 +08:00
|
|
|
((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
|
2019-04-25 07:12:35 +08:00
|
|
|
tap_prefix >&4) 3>&1) |
|
|
|
|
(read xs; exit $xs)) 4>>"$logfile" &&
|
2019-04-25 07:12:33 +08:00
|
|
|
echo "ok $test_num $TEST_HDR_MSG") ||
|
2019-09-20 02:06:44 +08:00
|
|
|
(rc=$?; \
|
|
|
|
if [ $rc -eq $skip_rc ]; then \
|
2019-04-25 07:12:33 +08:00
|
|
|
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
|
2019-09-20 02:06:44 +08:00
|
|
|
elif [ $rc -eq $timeout_rc ]; then \
|
2019-12-02 19:42:20 +08:00
|
|
|
echo "#"
|
2019-09-20 02:06:44 +08:00
|
|
|
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
|
2019-04-25 07:12:30 +08:00
|
|
|
else
|
2019-09-20 02:06:44 +08:00
|
|
|
echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
|
2019-04-25 07:12:30 +08:00
|
|
|
fi)
|
|
|
|
cd - >/dev/null
|
|
|
|
fi
|
|
|
|
}
|
2019-04-25 07:12:32 +08:00
|
|
|
|
|
|
|
run_many()
|
|
|
|
{
|
|
|
|
echo "TAP version 13"
|
2019-10-23 01:12:20 +08:00
|
|
|
DIR="${PWD#${BASE_DIR}/}"
|
2019-04-25 07:12:32 +08:00
|
|
|
test_num=0
|
2019-04-25 07:12:33 +08:00
|
|
|
total=$(echo "$@" | wc -w)
|
|
|
|
echo "1..$total"
|
2019-04-25 07:12:32 +08:00
|
|
|
for TEST in "$@"; do
|
|
|
|
BASENAME_TEST=$(basename $TEST)
|
|
|
|
test_num=$(( test_num + 1 ))
|
|
|
|
if [ -n "$per_test_logging" ]; then
|
|
|
|
logfile="/tmp/$BASENAME_TEST"
|
|
|
|
cat /dev/null > "$logfile"
|
|
|
|
fi
|
|
|
|
run_one "$DIR" "$TEST" "$test_num"
|
|
|
|
done
|
|
|
|
}
|