]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: Fix runner.sh for non-bash shells
authorMark Brown <broonie@kernel.org>
Thu, 16 Apr 2026 19:03:59 +0000 (20:03 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 16 Apr 2026 21:17:32 +0000 (15:17 -0600)
Commit 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.

Link: https://lore.kernel.org/r/20260416-selftest-fix-readlink-e-v1-2-94e4cabbdec4@kernel.org
Fixes: 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh")
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/kselftest/runner.sh

index 58cd6a738d541766c8552cebeb0344c99c0799f6..1115ee7e525c8dbf4a65b59db749915d25593baa 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 #
 # Runs a set of tests in a given subdirectory.
@@ -193,7 +193,7 @@ run_many()
        DIR="${PWD#${BASE_DIR}/}"
        test_num=0
        local rc
-       pids=()
+       pids=
 
        for TEST in "$@"; do
                BASENAME_TEST=$(basename $TEST)
@@ -204,7 +204,7 @@ run_many()
                fi
                if [ -n "$RUN_IN_NETNS" ]; then
                        run_in_netns &
-                       pids+=($!)
+                       pids="$pids $!"
                else
                        run_one "$DIR" "$TEST" "$test_num"
                fi
@@ -212,7 +212,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