runner.sh (fd63b2eae5f6ff91ab60819ef083136aebb0e88b) runner.sh (5c069b6dedef1fab5420ca8658ed7f9ee4d26007)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Runs a set of tests in a given subdirectory.
5export KSFT_TAP_LEVEL=1
6export skip_rc=4
7export logfile=/dev/stdout
8export per_test_logging=
9
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Runs a set of tests in a given subdirectory.
5export KSFT_TAP_LEVEL=1
6export skip_rc=4
7export logfile=/dev/stdout
8export per_test_logging=
9
10# There isn't a shell-agnostic way to find the path of a sourced file,
11# so we must rely on BASE_DIR being set to find other tools.
12if [ -z "$BASE_DIR" ]; then
13 echo "Error: BASE_DIR must be set before sourcing." >&2
14 exit 1
15fi
16
17# If Perl is unavailable, we must fall back to line-at-a-time prefixing
18# with sed instead of unbuffered output.
19tap_prefix()
20{
21 if [ ! -x /usr/bin/perl ]; then
22 sed -e 's/^/# /'
23 else
24 "$BASE_DIR"/kselftest/prefix.pl
25 fi
26}
27
28# If stdbuf is unavailable, we must fall back to line-at-a-time piping.
29tap_unbuffer()
30{
31 if ! which stdbuf >/dev/null ; then
32 "$@"
33 else
34 stdbuf -i0 -o0 -e0 "$@"
35 fi
36}
37
10run_one()
11{
12 DIR="$1"
13 TEST="$2"
14 NUM="$3"
15
16 BASENAME_TEST=$(basename $TEST)
17
18 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
38run_one()
39{
40 DIR="$1"
41 TEST="$2"
42 NUM="$3"
43
44 BASENAME_TEST=$(basename $TEST)
45
46 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
19 echo "$TEST_HDR_MSG"
20 echo "========================================"
47 echo "# $TEST_HDR_MSG"
21 if [ ! -x "$TEST" ]; then
48 if [ ! -x "$TEST" ]; then
22 echo -n "$TEST_HDR_MSG: Warning: file $TEST is "
49 echo -n "# Warning: file $TEST is "
23 if [ ! -e "$TEST" ]; then
24 echo "missing!"
25 else
26 echo "not executable, correct this."
27 fi
28 echo "not ok $test_num $TEST_HDR_MSG"
29 else
30 cd `dirname $TEST` > /dev/null
50 if [ ! -e "$TEST" ]; then
51 echo "missing!"
52 else
53 echo "not executable, correct this."
54 fi
55 echo "not ok $test_num $TEST_HDR_MSG"
56 else
57 cd `dirname $TEST` > /dev/null
31 (./$BASENAME_TEST >> "$logfile" 2>&1 &&
58 (((((tap_unbuffer ./$BASENAME_TEST 2>&1; echo $? >&3) |
59 tap_prefix >&4) 3>&1) |
60 (read xs; exit $xs)) 4>>"$logfile" &&
32 echo "ok $test_num $TEST_HDR_MSG") ||
33 (if [ $? -eq $skip_rc ]; then \
34 echo "not ok $test_num $TEST_HDR_MSG # SKIP"
35 else
36 echo "not ok $test_num $TEST_HDR_MSG"
37 fi)
38 cd - >/dev/null
39 fi

--- 19 unchanged lines hidden ---
61 echo "ok $test_num $TEST_HDR_MSG") ||
62 (if [ $? -eq $skip_rc ]; then \
63 echo "not ok $test_num $TEST_HDR_MSG # SKIP"
64 else
65 echo "not ok $test_num $TEST_HDR_MSG"
66 fi)
67 cd - >/dev/null
68 fi

--- 19 unchanged lines hidden ---