selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue
Subsystems (3)
PATCH 1/1 selftests: net: tcp_fastopen_backup_key.sh: fix shellcheck issue
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.
--- tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/tcp_fastopen_backup_key.sh +1 -1
@@ -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
Signature · 1 line
2.20.1
Quoted 30 lines
-----Original Message-----
From: Anders RoxellWhen running
tcp_fastopen_backup_key.shthe following issue was seen in a busybox environment.
./tcp_fastopen_backup_key.sh: line 33: [: -ne: unary operator expectedShellcheck showed the following issue.
$ shellcheck tools/testing/selftests/net/tcp_fastopen_backup_key.shIn
tools/testing/selftests/net/tcp_fastopen_backup_key.shline 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 <[email protected]>--- tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/net/tcp_fastopen_backup_key.sh +0
-0
tools/testing/selftests/net/tcp_fastopen_backup_key.sh do_test() { · line 33
Quoted 5 lines
tools/testing/selftests/net/tcp_fastopen_backup_key.sh +1
-1@@ -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
Quoted 5 lines
tools/testing/selftests/net/tcp_fastopen_backup_key.sh +0
-1echo "FAIL: TcpExtTCPFastOpenPassiveFail non-zero" return 1 fi --2.20.1
Quoted 25 lines · On Thu, 15 Aug 2019 at 01:35, <[email protected]> wrote:
Quoted 25 lines
-----Original Message-----
From: Anders RoxellWhen running
tcp_fastopen_backup_key.shthe following issue was seen in a busybox environment.
./tcp_fastopen_backup_key.sh: line 33: [: -ne: unary operator expectedShellcheck showed the following issue.
$ shellcheck tools/testing/selftests/net/tcp_fastopen_backup_key.shIn
tools/testing/selftests/net/tcp_fastopen_backup_key.shline 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 <[email protected]>--- tools/testing/selftests/net/tcp_fastopen_backup_key.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
tools/testing/selftests/net/tcp_fastopen_backup_key.sh do_test() { · line 33
Quoted 11 lines
tools/testing/selftests/net/tcp_fastopen_backup_key.sh +1
-1@@ -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 ]; thenDid you test this in the failing environment?
I thought I did that but the environment wasn't exactly the same. =/
Quoted 7 lines
With a busybox shell, I get:
$ [ "" -ne 0 ] sh: bad numberYou 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
Quoted 9 lines
-- TimQuoted 5 lines
tools/testing/selftests/net/tcp_fastopen_backup_key.sh +0
-1echo "FAIL: TcpExtTCPFastOpenPassiveFail non-zero" return 1 fi --2.20.1