[Devel] [PATCH 06/11] cr_tests: Cleanup error handling in futex/run.sh

Matt Helsley matthltc at us.ibm.com
Wed Aug 19 21:58:09 PDT 2009


The previous trap handler didn't properly handle errors. It could leave
extra tasks around if the group was frozen or checkpoint-done hadn't
been touched. Add code to handle the errors as a special do_err()
function so that we don't bother the body of the test loop very much.

We use an error message to indicate if the problem seems to be a test
failure ("FAIL") or if it's probably the test itself that is broken
("BROK"). This means we don't constantly need to change the trap
-- just assign a different value to err_msg before and after executing
the interesting parts of the test.

We also need to recover if the cgroup has been frozen. Add that to the
trap temporarily.

Also, to avoid spurious messages about "break" only being valid inside
a loop, reset the trap after exiting the loop.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
Cc: containers at lists.linux-foundation.org
---
 futex/run.sh |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/futex/run.sh b/futex/run.sh
index e54c228..434a844 100755
--- a/futex/run.sh
+++ b/futex/run.sh
@@ -37,12 +37,27 @@ fi
 # mkdir /cg/1
 # chown -R $(id --name -u).$(id --name -g) /cg/1
 
+# Most failures indicate a broken test environment
+err_msg="BROK"
+function do_err()
+{
+	if [ -n "${TEST_PID}" ]; then
+		local PIDLIST=( $(ps --ppid ${TEST_PID} -o pid=) ${TEST_PID} )
+		kill ${PIDLIST[@]}
+	fi
+	echo "${err_msg}"
+	((failed++))
+	wait
+}
+
+failed=0
+
 NUMTESTS=${#TESTS[@]}
 CURTEST=0
 
 while [ $CURTEST -lt $NUMTESTS ]; do
 	T=${TESTS[$CURTEST]}
-	trap 'break' ERR EXIT
+	trap 'do_err; break' ERR EXIT
 	rm -f ./checkpoint-* TBROK
 	echo "Running test: ${T}"
 	./${T} &
@@ -51,8 +66,12 @@ while [ $CURTEST -lt $NUMTESTS ]; do
 		sleep 1
 	done
 	freeze
+	trap 'thaw; do_err; break' ERR EXIT
+	err_msg="FAIL"
 	ckpt ${TEST_PID} > checkpoint-${T}
+	err_msg="BROK"
 	thaw
+	trap 'do_err; break' ERR EXIT
 	touch "./checkpoint-done"
 	wait ${TEST_PID}
 	retval=$?
@@ -78,9 +97,10 @@ while [ $CURTEST -lt $NUMTESTS ]; do
 	else
 		echo PASS
 	fi
-	trap "" ERR EXIT
+	trap '' ERR EXIT
 	CURTEST=$((CURTEST+1))
 done
+trap '' ERR EXIT
 
 #rm -f ./checkpoint-*
 
-- 
1.5.6.3


_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list