Skip to content

Commit f154634

Browse files
committed
Merge tag 'linux_kselftest-next-7.1-next-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest fixes from Shuah Khan: "Fix regressions in non-bash shells and busybox support, and revert a commit that regressed in build and installation when one or more tests fail to build. Fix duplicated test number reporting introduced in ktap support patch" * tag 'linux_kselftest-next-7.1-next-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: Fix duplicated test number reporting selftests: Fix runner.sh for non-bash shells selftests: Fix runner.sh busybox support selftests: Deescalate error reporting
2 parents 13f2458 + 83ef26f commit f154634

2 files changed

Lines changed: 28 additions & 29 deletions

File tree

tools/testing/selftests/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ export KHDR_INCLUDES
214214
.DEFAULT_GOAL := all
215215

216216
all:
217-
@ret=0; \
217+
@ret=1; \
218218
for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
219219
BUILD_TARGET=$$BUILD/$$TARGET; \
220220
mkdir $$BUILD_TARGET -p; \
221221
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
222222
O=$(abs_objtree) \
223223
$(if $(FORCE_TARGETS),|| exit); \
224-
[ $$? -eq 0 ] || ret=1; \
224+
ret=$$((ret * $$?)); \
225225
done; exit $$ret;
226226

227227
run_tests: all
@@ -279,7 +279,7 @@ ifdef INSTALL_PATH
279279
install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
280280
install -m 744 run_kselftest.sh $(INSTALL_PATH)/
281281
rm -f $(TEST_LIST)
282-
@ret=0; \
282+
@ret=1; \
283283
for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
284284
BUILD_TARGET=$$BUILD/$$TARGET; \
285285
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
@@ -288,7 +288,7 @@ ifdef INSTALL_PATH
288288
OBJ_PATH=$(INSTALL_PATH) \
289289
O=$(abs_objtree) \
290290
$(if $(FORCE_TARGETS),|| exit); \
291-
[ $$? -eq 0 ] || ret=1; \
291+
ret=$$((ret * $$?)); \
292292
done; exit $$ret;
293293

294294

tools/testing/selftests/kselftest/runner.sh

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33
#
44
# Runs a set of tests in a given subdirectory.
5-
. $(dirname "$(readlink -e "${BASH_SOURCE[0]}")")/ktap_helpers.sh
5+
6+
# There isn't a shell-agnostic way to find the path of a sourced file,
7+
# so we must rely on BASE_DIR being set to find other tools.
8+
if [ -z "$BASE_DIR" ]; then
9+
echo "Error: BASE_DIR must be set before sourcing." >&2
10+
exit 1
11+
fi
12+
13+
. ${BASE_DIR}/kselftest/ktap_helpers.sh
14+
615
export timeout_rc=124
716
export logfile=/dev/stdout
817
export per_test_logging=
@@ -14,13 +23,6 @@ export RUN_IN_NETNS=
1423
# over our soft timeout limit.
1524
export kselftest_default_timeout=45
1625

17-
# There isn't a shell-agnostic way to find the path of a sourced file,
18-
# so we must rely on BASE_DIR being set to find other tools.
19-
if [ -z "$BASE_DIR" ]; then
20-
echo "Error: BASE_DIR must be set before sourcing." >&2
21-
exit 1
22-
fi
23-
2426
TR_CMD=$(command -v tr)
2527

2628
# If Perl is unavailable, we must fall back to line-at-a-time prefixing
@@ -49,7 +51,6 @@ run_one()
4951
{
5052
DIR="$1"
5153
TEST="$2"
52-
local rc test_num="$3"
5354

5455
BASENAME_TEST=$(basename $TEST)
5556

@@ -106,7 +107,7 @@ run_one()
106107
echo "# $TEST_HDR_MSG"
107108
if [ ! -e "$TEST" ]; then
108109
ktap_print_msg "Warning: file $TEST is missing!"
109-
ktap_test_fail "$test_num $TEST_HDR_MSG"
110+
ktap_test_fail "$TEST_HDR_MSG"
110111
rc=$KSFT_FAIL
111112
else
112113
if [ -x /usr/bin/stdbuf ]; then
@@ -125,7 +126,7 @@ run_one()
125126
interpreter=$(head -n 1 "$TEST" | cut -c 3-)
126127
cmd="$stdbuf $interpreter ./$BASENAME_TEST"
127128
else
128-
ktap_test_fail "$test_num $TEST_HDR_MSG"
129+
ktap_test_fail "$TEST_HDR_MSG"
129130
return $KSFT_FAIL
130131
fi
131132
fi
@@ -136,15 +137,15 @@ run_one()
136137
rc=$?
137138
case "$rc" in
138139
"$KSFT_PASS")
139-
ktap_test_pass "$test_num $TEST_HDR_MSG";;
140+
ktap_test_pass "$TEST_HDR_MSG";;
140141
"$KSFT_SKIP")
141-
ktap_test_skip "$test_num $TEST_HDR_MSG";;
142+
ktap_test_skip "$TEST_HDR_MSG";;
142143
"$KSFT_XFAIL")
143-
ktap_test_xfail "$test_num $TEST_HDR_MSG";;
144+
ktap_test_xfail "$TEST_HDR_MSG";;
144145
"$timeout_rc")
145-
ktap_test_fail "$test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds";;
146+
ktap_test_fail "$TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds";;
146147
*)
147-
ktap_test_fail "$test_num $TEST_HDR_MSG # exit=$rc";;
148+
ktap_test_fail "$TEST_HDR_MSG # exit=$rc";;
148149
esac
149150
cd - >/dev/null
150151
fi
@@ -159,7 +160,7 @@ in_netns()
159160
BASE_DIR=$BASE_DIR
160161
source $BASE_DIR/kselftest/runner.sh
161162
logfile=$logfile
162-
run_one $DIR $TEST $test_num
163+
run_one $DIR $TEST
163164
EOF
164165
}
165166

@@ -172,7 +173,7 @@ run_in_netns()
172173
ip netns add $netns
173174
if [ $? -ne 0 ]; then
174175
ktap_print_msg "Warning: Create namespace failed for $BASENAME_TEST"
175-
ktap_test_fail "$test_num selftests: $DIR: $BASENAME_TEST # Create NS failed"
176+
ktap_test_fail "selftests: $DIR: $BASENAME_TEST # Create NS failed"
176177
fi
177178
ip -n $netns link set lo up
178179

@@ -189,28 +190,26 @@ run_in_netns()
189190
run_many()
190191
{
191192
DIR="${PWD#${BASE_DIR}/}"
192-
test_num=0
193193
local rc
194-
pids=()
194+
pids=
195195

196196
for TEST in "$@"; do
197197
BASENAME_TEST=$(basename $TEST)
198-
test_num=$(( test_num + 1 ))
199198
if [ -n "$per_test_logging" ]; then
200199
logfile="$per_test_log_dir/$BASENAME_TEST"
201200
cat /dev/null > "$logfile"
202201
fi
203202
if [ -n "$RUN_IN_NETNS" ]; then
204203
run_in_netns &
205-
pids+=($!)
204+
pids="$pids $!"
206205
else
207-
run_one "$DIR" "$TEST" "$test_num"
206+
run_one "$DIR" "$TEST"
208207
fi
209208
done
210209

211210
# These variables are outputs of ktap_helpers.sh but since we've
212211
# run the test in a subprocess we need to update them manually
213-
for pid in "${pids[@]}"; do
212+
for pid in $pids; do
214213
wait "$pid"
215214
rc=$?
216215
case "$rc" in

0 commit comments

Comments
 (0)