[PATCH blktests RFC 2/2] check: abort test run when a test case exits by "set -e" error-checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a test case does "set -e" for the string error-checking, the test
case 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 avoid such impacts, detect the test case exit due to "set -e". If a
test case uses "set -e", set the global flag ERR_EXIT. If this flag is
on in _cleanup(), exit the sub-shell with an exit code ABORT_RUN, then
stop the test script.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx>
---
 check | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/check b/check
index 3cf741a..81bb84d 100755
--- a/check
+++ b/check
@@ -4,6 +4,8 @@
 
 shopt -s extglob
 
+readonly ABORT_RUN=255
+
 _warning() {
 	echo "$0: $*" >&2
 }
@@ -332,6 +334,12 @@ _cleanup() {
 	fi
 
 	_exit_cgroup2
+
+	if ((ERR_EXIT)); then
+		echo "${TEST_NAME} should be error free but caused an error."
+		echo "It might have left dirty status. Abort the test run."
+		exit $ABORT_RUN
+	fi
 }
 
 _call_test() {
@@ -379,6 +387,12 @@ _call_test() {
 		TEST_RUN["runtime"]="$(cat "${seqres}.runtime")"
 		rm -f "${seqres}.runtime"
 
+		# The test case did not exit due to error for "set -e". Clear
+		# ERR_EXIT flag to not abort in _cleanup(). Also ensure to
+		# disable the error check.
+		unset ERR_EXIT
+		set +e
+
 		_cleanup
 
 		if [[ -v SKIP_REASONS ]]; then
@@ -522,6 +536,7 @@ _run_test() {
 	COND_DESC=""
 	FALLBACK_DEVICE=0
 	MODULES_TO_UNLOAD=()
+	ERR_EXIT=0
 
 	local nr_conds cond_i
 	local ret=0
@@ -533,6 +548,10 @@ _run_test() {
 	# shellcheck disable=SC1090
 	. "tests/${TEST_NAME}"
 
+	if grep --quiet "set -e" "tests/${TEST_NAME}"; then
+		ERR_EXIT=1
+	fi
+
 	if declare -fF test >/dev/null; then
 		if ((RUN_ZONED_TESTS && CAN_BE_ZONED)); then
 			. "common/zoned"
@@ -634,12 +653,14 @@ _run_group() {
 		unset TEST_DEV
 	fi
 
-	local ret=0
+	local ret=0 run_test_ret
 	local test_name
 	for test_name in "${tests[@]}"; do
 		( _run_test "$test_name" )
 		# shellcheck disable=SC2181
-		(($? != 0)) && ret=1
+		run_test_ret=$?
+		((run_test_ret != 0)) && ret=1
+		((run_test_ret == ABORT_RUN)) && break
 	done
 	return $ret
 }
-- 
2.49.0





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux