From: Shuah Khan <skhan@linuxfoundation.org>
To: "Jori Koolstra (CIQ)" <jkoolstra@xs4all.nl>,
"Shuah Khan" <shuah@kernel.org>,
"David Ahern" <dsahern@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Hangbin Liu" <hangbin.liu@linux.dev>,
"Ricardo B. Marlière" <ricardo@marliere.net>
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH 1/3] selftests: use local variables consistently in runner.sh
Date: Wed, 18 Nov 2026 09:13:30 -0700 [thread overview]
Message-ID: <8a436334-d306-4a34-bb7b-efc713aed0f8@linuxfoundation.org> (raw)
In-Reply-To: <20261118-kselftest-run-timer-v1-1-53a838b2d62b@xs4all.nl>
On 11/18/26 06:40, Jori Koolstra (CIQ) wrote:
> run_one() and run_many() assign their working variables without
> declaring them local, so they leak into the global namespace of
> whichever shell sources runner.sh, i.e. run_kselftest.sh or the
> RUN_TESTS recipe in lib.mk.
>
Hmm. so if a timeout value of say 60 seconds comes from a test
settings file, does it persist? Can you see that if you run a
few tests using TARGETS variable?
> Declare these variables local so that local is used consistently
> throughout the file and the sourcing shell's namespace is not polluted.
> This does not add a new requirement on the shell: local is already used
> in run_many(), in_netns() and run_in_netns().
Makes sense.
>
> Also, obey the convention to use upper case names for variables that are
> constant once assigned.
Can you elaborate on this convention?
I don't want to see these changes combined. We don't combine
cleanup and convention changes with real changes.
>
> Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
> ---
> tools/testing/selftests/kselftest/runner.sh | 29 ++++++++++++++++++-----------
> 1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
> index 45fb8ec38493..9b1dad5441ea 100644
> --- a/tools/testing/selftests/kselftest/runner.sh
> +++ b/tools/testing/selftests/kselftest/runner.sh
> @@ -58,13 +58,18 @@ tap_timeout()
>
> run_one()
> {
> + local DIR TEST BASENAME_TEST BASENAME_SANITIZED SETTINGS TEST_HDR_MSG
> + local line field value interpreter stdbuf cmd rc
> +
> DIR="$1"
> TEST="$2"
>
> BASENAME_TEST=$(basename $TEST)
>
> # Reset any "settings"-file variables.
> - export kselftest_timeout="$kselftest_default_timeout"
> + local kselftest_timeout="$kselftest_default_timeout"
> + # Make kselftest_timeout variables available to tests
> + export kselftest_timeout
>
> # Safe default if tr not available
> kselftest_cmd_args_ref="KSELFTEST_ARGS"
> @@ -91,8 +96,8 @@ run_one()
> fi
>
> # Load per-test-directory kselftest "settings" file.
> - settings="$BASE_DIR/$DIR/settings"
> - if [ -r "$settings" ] ; then
> + SETTINGS="$BASE_DIR/$DIR/settings"
> + if [ -r "$SETTINGS" ] ; then
> while read line ; do
> # Skip comments.
> if echo "$line" | grep -q '^#'; then
> @@ -100,8 +105,8 @@ run_one()
> fi
> field=$(echo "$line" | cut -d= -f1)
> value=$(echo "$line" | cut -d= -f2-)
> - eval "kselftest_$field"="$value"
> - done < "$settings"
> + eval "local kselftest_$field"="$value"
> + done < "$SETTINGS"
> fi
>
> # Command line timeout overrides the settings file
> @@ -164,8 +169,8 @@ run_one()
>
> in_netns()
> {
> - local name=$1
> - ip netns exec $name bash <<-EOF
> + local NAME=$1
> + ip netns exec $NAME bash <<-EOF
> BASE_DIR=$BASE_DIR
> source $BASE_DIR/kselftest/runner.sh
> logfile=$logfile
> @@ -175,9 +180,9 @@ in_netns()
>
> run_in_netns()
> {
> - local tmplog="/tmp/$(mktemp -u ${BASENAME_TEST}-XXXXXX)"
> - local netns=$(mktemp -u ${BASENAME_TEST}-XXXXXX)
> - local rc
> + local tmplog netns rc
> + tmplog="/tmp/$(mktemp -u ${BASENAME_TEST}-XXXXXX)"
> + netns=$(mktemp -u ${BASENAME_TEST}-XXXXXX)
>
> ip netns add $netns
> if [ $? -ne 0 ]; then
> @@ -198,8 +203,10 @@ run_in_netns()
>
> run_many()
> {
> + local DIR TEST BASENAME_TEST
> + local pids pid rc
> +
> DIR="${PWD#${BASE_DIR}/}"
> - local rc
> pids=
>
> for TEST in "$@"; do
>
thanks,
-- Shuah
next prev parent reply other threads:[~2026-11-18 16:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:40 [PATCH 0/3] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
2026-11-18 13:40 ` [PATCH 1/3] selftests: use local variables consistently in runner.sh Jori Koolstra (CIQ)
2026-11-18 16:13 ` Shuah Khan [this message]
2026-11-18 13:40 ` [PATCH 2/3] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
2026-11-18 13:40 ` [PATCH 3/3] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
2026-11-18 16:15 ` [PATCH 0/3] " Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8a436334-d306-4a34-bb7b-efc713aed0f8@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=jkoolstra@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=ricardo@marliere.net \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®