In bash script development, it is a good practices to handle errors strictly using "set -e" or "set -o errexit". When this option is enabled, bash exits immediately upon encountering an error. There have been discussions about implementing this strict error-checking mechanism in blktests test cases [1]. Recently, these discussions were revisited, and it has been proposed to enable this strict error-checking for a limited subset of test cases [2]. However, the error-checking does not work as expected, even when each test case does "set -e", because the error-checking has certain exceptions relevant to execution contexts. According to the bash man page, "The shell doe not exit ... part of the test following the if or elif reserved words, ... or if the command's return value is being inverted with !". The blktests test case execution context applies to these exceptions. To ensure that "set -e" behaves as intended in test cases, avoid the if statements and the return value inversions (!) in the test case execution context. Link: [1] https://github.com/linux-blktests/blktests/issues/89 Link: [2] https://lore.kernel.org/linux-block/ckctv7ioomqpxe2iwcg6eh6fvtzamoihnmwxvavd7lanr4y2y6@fbznem3nvw3w/ Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- check | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/check b/check index dad5e70..3cf741a 100755 --- a/check +++ b/check @@ -502,9 +502,9 @@ _check_and_call_test_device() { fi fi RESULTS_DIR="$OUTPUT/$(basename "$TEST_DEV")""$postfix" - if ! _call_test test_device; then - ret=1 - fi + _call_test test_device + # shellcheck disable=SC2181 + (($? != 0)) && ret=1 if (( unset_skip_reason )); then unset SKIP_REASONS fi @@ -637,9 +637,9 @@ _run_group() { local ret=0 local test_name for test_name in "${tests[@]}"; do - if ! ( _run_test "$test_name" ); then - ret=1 - fi + ( _run_test "$test_name" ) + # shellcheck disable=SC2181 + (($? != 0)) && ret=1 done return $ret } @@ -695,9 +695,9 @@ _check() { if [[ $group != "$prev_group" ]]; then prev_group="$group" if [[ ${#tests[@]} -gt 0 ]]; then - if ! ( _run_group "${tests[@]}" ); then - ret=1 - fi + ( _run_group "${tests[@]}" ) + # shellcheck disable=SC2181 + (($? != 0)) && ret=1 tests=() fi fi @@ -705,9 +705,9 @@ _check() { done < <(_find_tests "$@" | sort -zu) if [[ ${#tests[@]} -gt 0 ]]; then - if ! ( _run_group "${tests[@]}" ); then - ret=1 - fi + ( _run_group "${tests[@]}" ) + # shellcheck disable=SC2181 + (($? != 0)) && ret=1 fi return $ret -- 2.49.0