linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue
@ 2019-08-14 21:49 Anders Roxell
  2019-08-14 23:34 ` Tim.Bird
  0 siblings, 1 reply; 3+ messages in thread
From: Anders Roxell @ 2019-08-14 21:49 UTC (permalink / raw)
  To: davem, shuah; +Cc: netdev, linux-kselftest, linux-kernel, Anders Roxell

When running tcp_fastopen_backup_key.sh the following issue was seen in
a busybox environment.
./tcp_fastopen_backup_key.sh: line 33: [: -ne: unary operator expected

Shellcheck showed the following issue.
$ shellcheck tools/testing/selftests/net/tcp_fastopen_backup_key.sh

In tools/testing/selftests/net/tcp_fastopen_backup_key.sh line 33:
        if [ $val -ne 0 ]; then
             ^-- SC2086: Double quote to prevent globbing and word splitting.

Rework to add double quotes around the variable 'val' that shellcheck
recommends.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
index 41476399e184..ba5ec3eb314e 100755
--- a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
+++ b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
@@ -30,7 +30,7 @@ do_test() {
 	ip netns exec "${NETNS}" ./tcp_fastopen_backup_key "$1"
 	val=$(ip netns exec "${NETNS}" nstat -az | \
 		grep TcpExtTCPFastOpenPassiveFail | awk '{print $2}')
-	if [ $val -ne 0 ]; then
+	if [ "$val" -ne 0 ]; then
 		echo "FAIL: TcpExtTCPFastOpenPassiveFail non-zero"
 		return 1
 	fi
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue
  2019-08-14 21:49 [PATCH] selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue Anders Roxell
@ 2019-08-14 23:34 ` Tim.Bird
  2019-08-15  7:57   ` Anders Roxell
  0 siblings, 1 reply; 3+ messages in thread
From: Tim.Bird @ 2019-08-14 23:34 UTC (permalink / raw)
  To: anders.roxell, davem, shuah; +Cc: netdev, linux-kselftest, linux-kernel



> -----Original Message-----
> From: Anders Roxell
> 
> When running tcp_fastopen_backup_key.sh the following issue was seen in
> a busybox environment.
> ./tcp_fastopen_backup_key.sh: line 33: [: -ne: unary operator expected
> 
> Shellcheck showed the following issue.
> $ shellcheck tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> 
> In tools/testing/selftests/net/tcp_fastopen_backup_key.sh line 33:
>         if [ $val -ne 0 ]; then
>              ^-- SC2086: Double quote to prevent globbing and word splitting.
> 
> Rework to add double quotes around the variable 'val' that shellcheck
> recommends.
> 
> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> ---
>  tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> index 41476399e184..ba5ec3eb314e 100755
> --- a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> +++ b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> @@ -30,7 +30,7 @@ do_test() {
>  	ip netns exec "${NETNS}" ./tcp_fastopen_backup_key "$1"
>  	val=$(ip netns exec "${NETNS}" nstat -az | \
>  		grep TcpExtTCPFastOpenPassiveFail | awk '{print $2}')
> -	if [ $val -ne 0 ]; then
> +	if [ "$val" -ne 0 ]; then

Did you test this in the failing environment?

With a busybox shell, I get:
 $ [ "" -ne 0 ]
sh: bad number

You might need to explicitly check for empty string here, or switch to a string comparison instead:
if [ "$val" != 0 ]; then

   -- Tim

>  		echo "FAIL: TcpExtTCPFastOpenPassiveFail non-zero"
>  		return 1
>  	fi
> --
> 2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue
  2019-08-14 23:34 ` Tim.Bird
@ 2019-08-15  7:57   ` Anders Roxell
  0 siblings, 0 replies; 3+ messages in thread
From: Anders Roxell @ 2019-08-15  7:57 UTC (permalink / raw)
  To: Tim.Bird
  Cc: David Miller, Shuah Khan, Networking,
	open list:KERNEL SELFTEST FRAMEWORK, Linux Kernel Mailing List

On Thu, 15 Aug 2019 at 01:35, <Tim.Bird@sony.com> wrote:
>
>
>
> > -----Original Message-----
> > From: Anders Roxell
> >
> > When running tcp_fastopen_backup_key.sh the following issue was seen in
> > a busybox environment.
> > ./tcp_fastopen_backup_key.sh: line 33: [: -ne: unary operator expected
> >
> > Shellcheck showed the following issue.
> > $ shellcheck tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> >
> > In tools/testing/selftests/net/tcp_fastopen_backup_key.sh line 33:
> >         if [ $val -ne 0 ]; then
> >              ^-- SC2086: Double quote to prevent globbing and word splitting.
> >
> > Rework to add double quotes around the variable 'val' that shellcheck
> > recommends.
> >
> > Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> > ---
> >  tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> > b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> > index 41476399e184..ba5ec3eb314e 100755
> > --- a/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> > +++ b/tools/testing/selftests/net/tcp_fastopen_backup_key.sh
> > @@ -30,7 +30,7 @@ do_test() {
> >       ip netns exec "${NETNS}" ./tcp_fastopen_backup_key "$1"
> >       val=$(ip netns exec "${NETNS}" nstat -az | \
> >               grep TcpExtTCPFastOpenPassiveFail | awk '{print $2}')
> > -     if [ $val -ne 0 ]; then
> > +     if [ "$val" -ne 0 ]; then
>
> Did you test this in the failing environment?

I thought I did that but the environment wasn't exactly the same. =/

>
> With a busybox shell, I get:
>  $ [ "" -ne 0 ]
> sh: bad number
>
> You might need to explicitly check for empty string here, or switch to a string comparison instead:
> if [ "$val" != 0 ]; then

I'll do that instead.

Sending out a v2 shortly.

Cheers,
Anders

>
>    -- Tim
>
> >               echo "FAIL: TcpExtTCPFastOpenPassiveFail non-zero"
> >               return 1
> >       fi
> > --
> > 2.20.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-15  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14 21:49 [PATCH] selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue Anders Roxell
2019-08-14 23:34 ` Tim.Bird
2019-08-15  7:57   ` Anders Roxell

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).