selftests: Fix runner.sh breakage
cover selftests: Fix runner.sh breakage
Commit 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh") introduced several regressions by introducing dependencies on bash and GNU coreutils breaking testing on Debian based systems. Roll these changes back.
---
Mark Brown (2):
selftests: Fix runner.sh busybox support
selftests: Fix runner.sh for non-bash shells
tools/testing/selftests/kselftest/runner.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
---
base-commit: 2964f6b816c25ee094df4a143eb5b8828910045f
change-id: 20260416-selftest-fix-readlink-e-da604f02686b
Best regards,
Signature · 1 line
Mark Brown <[email protected]>
PATCH 1/2 selftests: Fix runner.sh busybox support
Commit 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh") added an import of ktap_helper.sh to runner.sh in order to standardise on these for output formatting. Rather than build on the existing requirement for the user to supply BASE_DIR to find the helpers it uses some magic which features a use of "readlink -e". Unfortunately the -e option is a GNU extension and is not available in at least busybox, meaning that runner.sh starts failing:
./run_kselftest.sh: 5: ./kselftest/runner.sh: Bad substitution ./run_kselftest.sh: 5: .: cannot open ./ktap_helpers.sh: No such file
Fix this by using the already required BASE_DIR to locate the helper library.
--- tools/testing/selftests/kselftest/runner.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
tools/testing/selftests/kselftest/runner.sh +10 -8
@@ -2,7 +2,16 @@ # SPDX-License-Identifier: GPL-2.0 # # Runs a set of tests in a given subdirectory. -. $(dirname "$(readlink -e "${BASH_SOURCE[0]}")")/ktap_helpers.sh + +# 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 + +. ${BASE_DIR}/kselftest/ktap_helpers.sh + export timeout_rc=124 export logfile=/dev/stdout export per_test_logging=
@@ -13,13 +22,6 @@ export RUN_IN_NETNS= # over our soft timeout limit. export kselftest_default_timeout=45 -# 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 - TR_CMD=$(command -v tr) # If Perl is unavailable, we must fall back to line-at-a-time prefixing
Signature · 1 line
2.47.3
PATCH 2/2 selftests: Fix runner.sh for non-bash shells
In reply to Mark BrownCommit 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh") added a number of bashisms and updated the interpreter specified for the script to be /bin/bash to reflect this. Unfortunately this does not actually achieve anything in production since the main way runner.sh is invoked is from the top level run_kselftest.sh which sources it rather than running it as a separate script and specifies the shell as /bin/sh. This means that on systems where /bin/sh is not bash (such as Debian where /bin/sh defaults to being dash) we see failures:
./run_kselftest.sh: 195: ./kselftest/runner.sh: Syntax error: "(" unexpected (expecting "}")
These bashisms come from this part of the change:
4. In runner.sh run_one(), get the return value and use ktap helpers for all pass/fail reporting. This allows counting pass/fail numbers in the main process.
which uses a bash array to track all the subtests being run. Convert this to use a simple flat variable instead.
--- tools/testing/selftests/kselftest/runner.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/kselftest/runner.sh +4 -4
@@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # # Runs a set of tests in a given subdirectory.
@@ -192,7 +192,7 @@ run_many() DIR="${PWD#${BASE_DIR}/}" test_num=0 local rc - pids=() + pids= for TEST in "$@"; do BASENAME_TEST=$(basename $TEST)
@@ -203,7 +203,7 @@ run_many() fi if [ -n "$RUN_IN_NETNS" ]; then run_in_netns & - pids+=($!) + pids="$pids $!" else run_one "$DIR" "$TEST" "$test_num" fi
@@ -211,7 +211,7 @@ run_many() # These variables are outputs of ktap_helpers.sh but since we've # run the test in a subprocess we need to update them manually - for pid in "${pids[@]}"; do + for pid in $pids; do wait "$pid" rc=$? case "$rc" in
Signature · 1 line
2.47.3
Shuah Khan
maintainerQuoted 13 lines · Mark Brown
Commit
2964f6b816c2("selftests: Use ktap helpers forrunner.sh") introduced several regressions by introducing dependencies on bash and GNU coreutils breaking testing on Debian based systems. Roll these changes back.Signed-off-by Mark Brown <[email protected]>---
Mark Brown (2):
selftests: Fixrunner.shbusybox support
selftests: Fixrunner.shfor non-bash shellstools/testing/selftests/kselftest/runner.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
Quoted 8 lines
---
base-commit:2964f6b816c25ee094df4a143eb5b8828910045f
change-id: 20260416-selftest-fix-readlink-e-da604f02686bBest regards,
--
Mark Brown <[email protected]>
Thank you. I applied these two patches to linux-kselftest next and will send pr tomorrow.
thanks,
-- Shuah