* [PATCH] selftest: net: Fix error message if empty variable
@ 2025-09-24 23:04 Alessandro Zanni
2025-09-25 10:49 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Alessandro Zanni @ 2025-09-24 23:04 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms, shuah
Cc: Alessandro Zanni, netdev, linux-kselftest, linux-kernel
Fix to avoid cases where the `res` shell variable is
empty in script comparisons.
The issue can be reproduced with the command:
make kselftest TARGETS=net
It solves the error:
./tfo_passive.sh: line 98: [: -eq: unary operator expected
Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---
tools/testing/selftests/net/tfo_passive.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/tfo_passive.sh b/tools/testing/selftests/net/tfo_passive.sh
index 80bf11fdc046..2655931b2396 100755
--- a/tools/testing/selftests/net/tfo_passive.sh
+++ b/tools/testing/selftests/net/tfo_passive.sh
@@ -95,7 +95,7 @@ wait
res=$(cat $out_file)
rm $out_file
-if [ $res -eq 0 ]; then
+if [ -n "$res" ] && [ $res -eq 0 ]; then
echo "got invalid NAPI ID from passive TFO socket"
cleanup_ns
exit 1
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftest: net: Fix error message if empty variable
2025-09-24 23:04 [PATCH] selftest: net: Fix error message if empty variable Alessandro Zanni
@ 2025-09-25 10:49 ` Simon Horman
2025-09-25 12:40 ` Alessandro Zanni
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2025-09-25 10:49 UTC (permalink / raw)
To: Alessandro Zanni
Cc: davem, edumazet, kuba, pabeni, shuah, netdev, linux-kselftest,
linux-kernel
On Thu, Sep 25, 2025 at 01:04:07AM +0200, Alessandro Zanni wrote:
> Fix to avoid cases where the `res` shell variable is
> empty in script comparisons.
>
> The issue can be reproduced with the command:
> make kselftest TARGETS=net
>
> It solves the error:
> ./tfo_passive.sh: line 98: [: -eq: unary operator expected
>
> Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
> ---
> tools/testing/selftests/net/tfo_passive.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/net/tfo_passive.sh b/tools/testing/selftests/net/tfo_passive.sh
> index 80bf11fdc046..2655931b2396 100755
> --- a/tools/testing/selftests/net/tfo_passive.sh
> +++ b/tools/testing/selftests/net/tfo_passive.sh
> @@ -95,7 +95,7 @@ wait
> res=$(cat $out_file)
> rm $out_file
>
> -if [ $res -eq 0 ]; then
> +if [ -n "$res" ] && [ $res -eq 0 ]; then
> echo "got invalid NAPI ID from passive TFO socket"
> cleanup_ns
> exit 1
Hi Alessandro,
I'm not sure what $res can be in practice.
But as it is the contents of $out_file (or more specifically,
the stdout of running cat $outfile), in theory it could be anything.
So while your patch addresses one error case.
I think there are others.
f.e. if res is not empty but not numeric, then we may see
bash: [: b: integer expression expected
Or if res contains a newline, then we may see
bash: [: too many arguments
So I wonder if it is better to treat $res as a string,
and quote it to avoid unexpected side effects.
[ "$res" = "0" ]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftest: net: Fix error message if empty variable
2025-09-25 10:49 ` Simon Horman
@ 2025-09-25 12:40 ` Alessandro Zanni
0 siblings, 0 replies; 3+ messages in thread
From: Alessandro Zanni @ 2025-09-25 12:40 UTC (permalink / raw)
To: Simon Horman
Cc: Alessandro Zanni, davem, edumazet, kuba, pabeni, shuah, netdev,
linux-kselftest, linux-kernel
On Thu, Sep 25, 2025 at 11:49:30AM +0100, Simon Horman wrote:
> On Thu, Sep 25, 2025 at 01:04:07AM +0200, Alessandro Zanni wrote:
> > Fix to avoid cases where the `res` shell variable is
> > empty in script comparisons.
> >
> > The issue can be reproduced with the command:
> > make kselftest TARGETS=net
> >
> > It solves the error:
> > ./tfo_passive.sh: line 98: [: -eq: unary operator expected
> >
> > Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
> > ---
> > tools/testing/selftests/net/tfo_passive.sh | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/net/tfo_passive.sh b/tools/testing/selftests/net/tfo_passive.sh
> > index 80bf11fdc046..2655931b2396 100755
> > --- a/tools/testing/selftests/net/tfo_passive.sh
> > +++ b/tools/testing/selftests/net/tfo_passive.sh
> > @@ -95,7 +95,7 @@ wait
> > res=$(cat $out_file)
> > rm $out_file
> >
> > -if [ $res -eq 0 ]; then
> > +if [ -n "$res" ] && [ $res -eq 0 ]; then
> > echo "got invalid NAPI ID from passive TFO socket"
> > cleanup_ns
> > exit 1
>
> Hi Alessandro,
>
> I'm not sure what $res can be in practice.
> But as it is the contents of $out_file (or more specifically,
> the stdout of running cat $outfile), in theory it could be anything.
>
> So while your patch addresses one error case.
> I think there are others.
>
> f.e. if res is not empty but not numeric, then we may see
>
> bash: [: b: integer expression expected
>
> Or if res contains a newline, then we may see
>
> bash: [: too many arguments
>
>
> So I wonder if it is better to treat $res as a string,
> and quote it to avoid unexpected side effects.
>
> [ "$res" = "0" ]
I'm not sure about the possible values in $res neither.
I assumed it was numeric because of the "-eq" operator but,
if it can be any value, a string comparison would be better.
I'm going to edit it.
Thanks,
Alessandro
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-25 12:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24 23:04 [PATCH] selftest: net: Fix error message if empty variable Alessandro Zanni
2025-09-25 10:49 ` Simon Horman
2025-09-25 12:40 ` Alessandro Zanni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).