On 6/5/25 8:56 PM, Shin'ichiro Kawasaki wrote:
The second problem is impact on following test cases. When the error-
checking is enabled for a test case, the test case script exits
immediately encountering an error. This skips the cleanup steps in the
test case, potentially leaving the test system in a dirty state, which
may affect subsequent test cases.
To address the two problems, introduce the new flag ERR_EXIT. When a
test case sets ERR_EXIT=1 at the beginning of its file, the blktests
check script calls "set -e" for the test case. The test case does not
need to call "set -e". This allows the strict error-checking to be
applied to test cases selectively.
If a test case with ERR_EXIT=1 exits due to a non-zero status, catch the
exit in _cleanup(). Then print an error message to the user and stop the
test script. This ensures the following test cases are not run.
Has the following alternative been considered? Let test script authors
add "set -e" and "set +e" where appropriate but only in a subshell. If a
failure occurs, only the subshell will be exited and cleanup code will
still be executed if it occurs past the subshell. A disadvantage of this
approach is that global variables can't be set from inside the subshell
and that another mechanism is needed than local variables to pass output
from the subshell to the context outside it, e.g. a pipe.
@@ -372,6 +380,7 @@ _call_test() {
fi
TIMEFORMAT="%Rs"
+ ((ERR_EXIT)) && set -e
pushd . >/dev/null || return
{ time "$test_func" >"${seqres}.out" 2>&1; } 2>"${seqres}.runtime"
TEST_RUN["exit_status"]=$?
This change makes it harder to write test code because it forces authors
to surround cleanup code with something like if cleanup_code; then :; fi.
Thanks,
Bart.