Subject: [PATCH 1/4] test/zdtm: add -g option to generate binary only
From: Yicheng Qin <[email-masked]>

Add -g option in zdtm.sh.

Using -g option can just generate binaries of all
tests to run in zdtm. Moreover, appending test name after
-g option can just generate the binary for the test.

Signed-off-by: Yicheng Qin <[email-masked]>
---
 test/zdtm.sh | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index f640cd7..9e72fa3 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -156,10 +156,11 @@ TMP_TREE=""
 SCRIPTDIR=`dirname $CRIU`/test
 POSTDUMP="--action-script $SCRIPTDIR/post-dump.sh"
 
-test -x $CRIU || {
+# it doesn't need criu binary for compiling test programs
+if [[ "$1" != "-g" && ! -x $CRIU ]]; then
 	echo "$CRIU is unavailable"
 	exit 1
-}
+fi
 
 ARGS=""
 
@@ -538,6 +539,19 @@ checkout()
 	make -C $TMP_TREE -j 32
 }
 
+compile_test()
+{
+	local test=$1
+
+	test=${ZP}/${test#ns/}
+	local tname=`basename $test`
+	local tdir=`dirname $test`
+
+	echo "Compile $test"
+
+	make -C $tdir $tname || return 1
+}
+
 cd `dirname $0` || exit 1
 
 while :; do
@@ -621,6 +635,16 @@ if [ $# -eq 0 ]; then
 	done
 elif [ "$1" = "-l" ]; then
 	echo $TEST_LIST $UTS_TEST_LIST $MNT_TEST_LIST $IPC_TEST_LIST | tr ' ' '\n'
+elif [ "$1" = "-g" ]; then
+	shift
+	if [ $# -eq 0 ]; then
+		for t in $TEST_LIST $UTS_TEST_LIST \
+			$MNT_TEST_LIST $IPC_TEST_LIST; do
+			compile_test $t || case_error $t
+		done
+	else
+		compile_test $1 || case_error $1
+	fi
 elif [ "$1" = "-h" ]; then
 	cat >&2 <<EOF
 This script is used for executing unit tests.
@@ -637,6 +661,7 @@ Options:
 	-x <PATTERN>: Exclude pattern
 	-t : mount tmpfs for dump files
 	-a <FILE>.tar.gz : save archive with dump files and logs
+	-g : Generate executables only
 EOF
 elif [ "${1:0:1}" = '-' ]; then
 	echo "unrecognized option $1"
-- 
1.8.3

From: Yicheng Qin <[email-masked]>
Subject: [PATCH 2/4] test: adjust the output for tests

Adjust the format of information printed.
Print out more necessary debug information.
Display error message in STDERR and make it more readable.

Signed-off-by: Yicheng Qin <[email-masked]>
---
 test/tcp/run.sh | 10 ++++++++--
 test/zdtm.sh    | 34 +++++++++++++++++++++++++++-------
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/test/tcp/run.sh b/test/tcp/run.sh
index 0dd0e70..873c7d1 100644
--- a/test/tcp/run.sh
+++ b/test/tcp/run.sh
@@ -34,12 +34,16 @@ echo "Make it run"
 echo "${TEXT}" >&3
 
 function fail {
-	echo "$@"
+	echo "$@" >&2
 	kill -9 ${CLN_PID}
 	kill -9 ${SRV_PID}
+	echo ${CLN_LOG}: >&2
+	cat ${CLN_LOG} >&2
 	exit 1
 }
 
+kill -s 0 ${CLN_PID} || fail "Client is dead"
+
 echo "Suspend server"
 ${CRIU} dump -D ${DDIR} -o dump.log -t ${SRV_PID} --tcp-established -vvvv || fail "Fail to dump server"
 sleep 1
@@ -51,5 +55,7 @@ echo "${TEXT}" >&3
 
 echo "Collect results"
 exec 3>&-
-wait ${CLN_PID}
+wait ${CLN_PID} || fail "Client exits abruptly"
 kill -9 ${SRV_PID}
+
+echo PASS
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 9e72fa3..5b064f7 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -179,6 +179,10 @@ check_mainstream()
 	local -a ver_arr
 	local ver_str=`uname -r`
 
+	cat >&2 <<EOF
+========================== CRIU CHECK =============================
+EOF
+
 	$CRIU check && return 0
 	MAINSTREAM_KERNEL=1
 
@@ -262,6 +266,8 @@ export MAKEFLAGS=--no-print-directory
 
 start_test()
 {
+	echo Start test $2 at $(date)
+
 	local tdir=$1
 	local tname=$2
 	export ZDTM_ROOT
@@ -500,6 +506,7 @@ EOF
 	cat $test.out
 	cat $test.out | grep -q PASS || return 2
 	[ "$CLEANUP" -ne 0 ] && rm -rf `dirname $ddump`
+	echo "Test: $test, Result: PASS"
 	return 0
 }
 
@@ -510,23 +517,36 @@ case_error()
 
 	ZDTM_FAILED=1
 
-	echo "Test: $test"
-	echo "====================== ERROR ======================"
+	echo "Test: $test, Result: FAIL"
+	echo "====================== ERROR ======================" >&2
+	echo "Test: $test, Namespace: ${PIDNS}" >&2
 
 	if [ -n "$DUMP_PATH" ]; then
 		[ -e "$DUMP_PATH/dump.log" ] && {
-			echo "Dump log   : $DUMP_PATH/dump.log"
-			cat $DUMP_PATH/dump.log* | grep Error
+			echo "Dump log   : $DUMP_PATH/dump.log" >&2
+			cat $DUMP_PATH/dump.log* | grep Error >&2
+			echo "* * * * * * * * * * * * * * *" >&2
+			tail -n 40 $DUMP_PATH/dump.log* >&2
+			echo "*****************************" >&2
 		}
 		[ -e "$DUMP_PATH/restore.log" ] && {
-			echo "Restore log: $DUMP_PATH/restore.log"
-			cat $DUMP_PATH/restore.log* | grep Error
+			echo "Restore log: $DUMP_PATH/restore.log" >&2
+			cat $DUMP_PATH/restore.log* | grep Error >&2
+			echo "* * * * * * * * * * * * * * *" >&2
+			tail -n 40 $DUMP_PATH/restore.log* >&2
+			echo "*****************************" >&2
 		}
 	fi
 	[ -e "$test_log" ] &&
-		echo "Output file: $test_log"
+		echo "Output file: $test_log" >&2
+		cat $test_log* >&2
+		echo "*****************************" >&2
+
 	[ -n "$HEAD" ] &&
 		echo "The initial HEAD was $HEAD"
+
+	echo "==================== ERROR OVER ====================" >&2
+
 	exit 1
 }
 
-- 
1.8.3

From: Yicheng Qin <[email-masked]>
Subject: [PATCH 3/4] test/zdtm: add -n option to run in-namespace tests only

Support -n option in zdtm, which means that only in-namespace tests
will be run.

Signed-off-by: Yicheng Qin <[email-masked]>
---
 test/zdtm.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 5b064f7..6db2bf0 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -173,6 +173,7 @@ CLEANUP=0
 PAGE_SERVER=0
 PS_PORT=12345
 TCPDUMP_PID=
+NS_TEST_ONLY=0
 
 check_mainstream()
 {
@@ -358,6 +359,11 @@ run_test()
 	expr "$test" : 'ns/' > /dev/null && PIDNS=1 || PIDNS=""
 	test=${ZP}/${test#ns/}
 
+	# option '-n' to skip tests without namespace
+	if [[ $NS_TEST_ONLY -eq 1 ]] && [[ "$PIDNS" == "" ]]; then
+		return
+	fi
+
 	shift
 	local args=$*
 	local tname=`basename $test`
@@ -629,6 +635,11 @@ while :; do
 		shift
 		continue;
 	fi
+	if [ "$1" = "-n" ]; then
+		shift
+		NS_TEST_ONLY=1
+		continue
+	fi
 	if [ "$1" = "-s" ]; then
 		SNAPSHOT=1
 		shift
@@ -682,6 +693,7 @@ Options:
 	-t : mount tmpfs for dump files
 	-a <FILE>.tar.gz : save archive with dump files and logs
 	-g : Generate executables only
+	-n : Run tests in namespace only
 EOF
 elif [ "${1:0:1}" = '-' ]; then
 	echo "unrecognized option $1"
-- 
1.8.3

From: Yicheng Qin <[email-masked]>
Subject: [PATCH 4/4] test/zdtm: skip failed individual tests instead of
 exiting

This ensures that all tests can be run in one pass, which can provide
better overview of test result.

Signed-off-by: Yicheng Qin <[email-masked]>
---
 test/zdtm.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 6db2bf0..094ea53 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -174,6 +174,7 @@ PAGE_SERVER=0
 PS_PORT=12345
 TCPDUMP_PID=
 NS_TEST_ONLY=0
+EXIT_VALUE=0
 
 check_mainstream()
 {
@@ -439,7 +440,7 @@ EOF
 		# with some error code, or checkpoint is complete but return
 		# code is non-zero because of post dump action.
 		if [ "$retcode" -ne 0 ] && [[ "$retcode" -ne 32 || -z "$dump_only" ]]; then
-			echo WARNING: $tname returned $retcode and left running for debug needs
+			echo WARNING: $tname failed and returned $retcode
 			return 1
 		fi
 
@@ -553,7 +554,14 @@ case_error()
 
 	echo "==================== ERROR OVER ====================" >&2
 
-	exit 1
+	# cleanout failed test to prepare for next one
+	local tname=`basename $test`
+	local tdir=`dirname $test`
+	killall -9 $tname > /dev/null 2>&1
+	make -C $tdir $tname.cleanout
+
+	# record the error
+	EXIT_VALUE=1
 }
 
 checkout()
@@ -664,6 +672,12 @@ if [ $# -eq 0 ]; then
 	for t in $IPC_TEST_LIST; do
 		run_test $t -n ipc || case_error $t
 	done
+
+	if [ $EXIT_VALUE -eq 0 ]; then
+		echo ZDTM tests PASS.
+	else
+		echo ZDTM tests FAIL.
+	fi
 elif [ "$1" = "-l" ]; then
 	echo $TEST_LIST $UTS_TEST_LIST $MNT_TEST_LIST $IPC_TEST_LIST | tr ' ' '\n'
 elif [ "$1" = "-g" ]; then
@@ -711,4 +725,5 @@ else
 	fi
 fi
 
-[ -n "$TMP_TREE" ] && rm -rf $TMP_TREE || exit 0
+[ -n "$TMP_TREE" ] && rm -rf $TMP_TREE
+exit $EXIT_VALUE
-- 
1.8.3