Skip to contentSkip to conversation

tests: run-tests.sh: ensure non-zero exit when $failed != 0

PATCH In review Štěpán Němec 3 participants 6 messages Oct 20, 2021 – Nov 2, 2021 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: run-tests.sh: ensure non-zero exit when $failed != 0

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#exit
[2] https://git.savannah.gnu.org/cgit/bash.git/tree/builtins/common.c#n579

Fixes 0c6592420586 ("tests: fix return codes")
---
 tests/build/run-tests.sh | 2 +-
 tests/shell/run-tests.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/build/run-tests.sh +1 -1
index 9ce93a8ed381..f78cc9019a30 100755
@@ -52,4 +52,4 @@ done
 rm -rf $tmpdir
 
 echo "results: [OK] $ok [FAILED] $failed [TOTAL] $((ok+failed))"
-exit $failed
+[ "$failed" -eq 0 ]
tests/shell/run-tests.sh +1 -1
index 349ec6cb1b16..f77d850ef285 100755
@@ -160,4 +160,4 @@ echo ""
 msg_info "results: [OK] $ok [FAILED] $failed [TOTAL] $((ok+failed))"
 
 kernel_cleanup
-exit $failed
+[ "$failed" -eq 0 ]

base-commit: 2139913694a9850c9160920b2c638aac4828f9bb

Signature · 1 line
2.33.1
reviewer
#1 lore raw

Hi,

Quoted 4 lines · Štěpán Němec

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

Standards aside, failed=256 is an actual bug:

| % bash -c "exit 255"; echo $?
| 255
| % bash -c "exit 256"; echo $?
| 0
| % bash -c "exit 257"; echo $?
| 1

Thanks, Phil

#2 lore raw

Hi Phil,

Quoted 8 lines · Phil Sutter

Hi,

Quoted 4 lines · Štěpán Němec

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

Quoted 8 lines

Standards aside, failed=256 is an actual bug:

| % bash -c "exit 255"; echo $?
| 255
| % bash -c "exit 256"; echo $?
| 0
| % bash -c "exit 257"; echo $?
| 1

This is extra information you provided here for the commit message for completion?

Thanks.

reviewer
#3 lore raw

Hi Pablo,

Quoted 16 lines · Pablo Neira Ayuso
Quoted 6 lines · Phil Sutter
Quoted 4 lines · Štěpán Němec

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

Quoted 8 lines

Standards aside, failed=256 is an actual bug:

| % bash -c "exit 255"; echo $?
| 255
| % bash -c "exit 256"; echo $?
| 0
| % bash -c "exit 257"; echo $?
| 1
Quoted 2 lines

This is extra information you provided here for the commit message for completion?

No need to extend the commit message IMO. I was just curious and played a bit with exit values in bash. So although unlikely, the unpatched code indeed confuses a result of 256 errors for a pass. :)

Cheers, Phil

#4 lore raw
Quoted 19 lines · Phil Sutter

Hi Pablo,

Quoted 16 lines · Pablo Neira Ayuso
Quoted 14 lines · Phil Sutter
Quoted 4 lines · Štěpán Němec

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

Standards aside, failed=256 is an actual bug:

| % bash -c "exit 255"; echo $?
| 255
| % bash -c "exit 256"; echo $?
| 0
| % bash -c "exit 257"; echo $?
| 1
Quoted 6 lines
Quoted 2 lines

This is extra information you provided here for the commit message for completion?

No need to extend the commit message IMO. I was just curious and played a bit with exit values in bash. So although unlikely, the unpatched code indeed confuses a result of 256 errors for a pass. :)

OK, then please go push out this patch if you're fine with it.

reviewer
#5 lore raw
Quoted 20 lines · Pablo Neira Ayuso
Quoted 19 lines · Phil Sutter

Hi Pablo,

Quoted 16 lines · Pablo Neira Ayuso
Quoted 14 lines · Phil Sutter
Quoted 4 lines · Štěpán Němec

POSIX [1] does not specify the behavior of `exit' with arguments outside the 0-255 range, but what generally (bash, dash, zsh, OpenBSD ksh, busybox) seems to happen is the shell exiting with status & 255 [2], which results in zero exit for certain non-zero arguments.

Standards aside, failed=256 is an actual bug:

| % bash -c "exit 255"; echo $?
| 255
| % bash -c "exit 256"; echo $?
| 0
| % bash -c "exit 257"; echo $?
| 1
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This is extra information you provided here for the commit message for completion?

No need to extend the commit message IMO. I was just curious and played a bit with exit values in bash. So although unlikely, the unpatched code indeed confuses a result of 256 errors for a pass. :)

OK, then please go push out this patch if you're fine with it.

DONE. Sorry for the confusion.

Cheers, Phil