From: Jori Koolstra <jkoolstra@xs4all.nl>
To: "Shuah Khan" <skhan@linuxfoundation.org>,
"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
Subject: Re: [PATCH 1/3] selftests: use local variables consistently in runner.sh
Date: Fri, 20 Nov 2026 12:14:36 +0100 (CET) [thread overview]
Message-ID: <1254980601.2097872.1795173276553@kpc.webmail.kpnmail.nl> (raw)
In-Reply-To: <8a436334-d306-4a34-bb7b-efc713aed0f8@linuxfoundation.org>
> Op 18-11-2026 11:13 EST schreef Shuah Khan <skhan@linuxfoundation.org>:
>
>
> 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?
>
No, because it is doing
export kselftest_timeout="$kselftest_default_timeout"
at the start of run_once(). I was just trying to get it to be a bit more
consistent and less bug-prone. We could also add readonly, which is in
POSIX. But that seemed too much.
> > 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?
>
It seems to be what was used for runner.sh, local variables set once are in
uppercase.
> I don't want to see these changes combined. We don't combine
> cleanup and convention changes with real changes.
>
I'll separate it out.
> >
> > 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-20 11:14 UTC|newest]
Thread overview: 8+ 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
2026-11-20 11:14 ` Jori Koolstra [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
2026-11-20 11:27 ` Jori Koolstra
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=1254980601.2097872.1795173276553@kpc.webmail.kpnmail.nl \
--to=jkoolstra@xs4all.nl \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=ricardo@marliere.net \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.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®