selftests: Remove KSFT_TAP_LEVEL
[linux/fpc-iii.git] / tools / testing / selftests / kselftest / runner.sh
blobeff3ee303d0d6a5648acf335412637c4956f0c0e
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Runs a set of tests in a given subdirectory.
5 export skip_rc=4
6 export logfile=/dev/stdout
7 export per_test_logging=
9 # 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.
11 if [ -z "$BASE_DIR" ]; then
12 echo "Error: BASE_DIR must be set before sourcing." >&2
13 exit 1
16 # If Perl is unavailable, we must fall back to line-at-a-time prefixing
17 # with sed instead of unbuffered output.
18 tap_prefix()
20 if [ ! -x /usr/bin/perl ]; then
21 sed -e 's/^/# /'
22 else
23 "$BASE_DIR"/kselftest/prefix.pl
27 # If stdbuf is unavailable, we must fall back to line-at-a-time piping.
28 tap_unbuffer()
30 if ! which stdbuf >/dev/null ; then
31 "$@"
32 else
33 stdbuf -i0 -o0 -e0 "$@"
37 run_one()
39 DIR="$1"
40 TEST="$2"
41 NUM="$3"
43 BASENAME_TEST=$(basename $TEST)
45 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
46 echo "# $TEST_HDR_MSG"
47 if [ ! -x "$TEST" ]; then
48 echo -n "# Warning: file $TEST is "
49 if [ ! -e "$TEST" ]; then
50 echo "missing!"
51 else
52 echo "not executable, correct this."
54 echo "not ok $test_num $TEST_HDR_MSG"
55 else
56 cd `dirname $TEST` > /dev/null
57 (((((tap_unbuffer ./$BASENAME_TEST 2>&1; echo $? >&3) |
58 tap_prefix >&4) 3>&1) |
59 (read xs; exit $xs)) 4>>"$logfile" &&
60 echo "ok $test_num $TEST_HDR_MSG") ||
61 (if [ $? -eq $skip_rc ]; then \
62 echo "not ok $test_num $TEST_HDR_MSG # SKIP"
63 else
64 echo "not ok $test_num $TEST_HDR_MSG"
65 fi)
66 cd - >/dev/null
70 run_many()
72 echo "TAP version 13"
73 DIR=$(basename "$PWD")
74 test_num=0
75 total=$(echo "$@" | wc -w)
76 echo "1..$total"
77 for TEST in "$@"; do
78 BASENAME_TEST=$(basename $TEST)
79 test_num=$(( test_num + 1 ))
80 if [ -n "$per_test_logging" ]; then
81 logfile="/tmp/$BASENAME_TEST"
82 cat /dev/null > "$logfile"
84 run_one "$DIR" "$TEST" "$test_num"
85 done