[Opendnssec-commits] jerry r6985 - branches/OpenDNSSEC-1.3/testing branches/OpenDNSSEC-enforcer-ng/testing releases/softHSM-1.3.4/testing trunk/OpenDNSSEC/testing trunk/softHSM/testing trunk/softHSMv2/testing trunk/testing/framework

commits at svn.opendnssec.org commits at svn.opendnssec.org
Fri Jan 25 11:03:59 CET 2013


Author: jerry
Date: Fri Jan 25 11:03:59 2013
New Revision: 6985
URL: http://fisheye.opendnssec.org/changelog/opendnssec?cs=6985

Log:
OPENDNSSEC-357: Deploy JUnit support in test framework for Jenkins

Modified:
   branches/OpenDNSSEC-1.3/testing/functions-opendnssec.sh
   branches/OpenDNSSEC-1.3/testing/lib.sh
   branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec-mysql.sh
   branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec.sh
   branches/OpenDNSSEC-1.3/testing/test-opendnssec-mysql.sh
   branches/OpenDNSSEC-1.3/testing/test-opendnssec.sh
   branches/OpenDNSSEC-enforcer-ng/testing/functions-opendnssec.sh
   branches/OpenDNSSEC-enforcer-ng/testing/lib.sh
   branches/OpenDNSSEC-enforcer-ng/testing/test-opendnssec.sh
   releases/softHSM-1.3.4/testing/lib.sh
   trunk/OpenDNSSEC/testing/functions-opendnssec.sh
   trunk/OpenDNSSEC/testing/lib.sh
   trunk/OpenDNSSEC/testing/test-daily-opendnssec-mysql.sh
   trunk/OpenDNSSEC/testing/test-daily-opendnssec.sh
   trunk/OpenDNSSEC/testing/test-opendnssec-mysql.sh
   trunk/OpenDNSSEC/testing/test-opendnssec.sh
   trunk/softHSM/testing/lib.sh
   trunk/softHSMv2/testing/lib.sh
   trunk/testing/framework/lib.sh

Modified: branches/OpenDNSSEC-1.3/testing/functions-opendnssec.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/functions-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/functions-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -15,6 +15,13 @@
 	true
 }
 
+ods_interrupt_test ()
+{
+    ods_kill
+    ods_ldns_testns_kill
+    ods_bind9_kill
+}
+
 ods_nuke_env ()
 {
 	local kasp_files=`cd "$INSTALL_ROOT/var/opendnssec/" && ls kasp*db* 2>/dev/null`

Modified: branches/OpenDNSSEC-1.3/testing/lib.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec-mysql.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec-mysql.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec-mysql.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -11,6 +11,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/test-daily-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -9,6 +9,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: branches/OpenDNSSEC-1.3/testing/test-opendnssec-mysql.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/test-opendnssec-mysql.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/test-opendnssec-mysql.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -11,6 +11,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: branches/OpenDNSSEC-1.3/testing/test-opendnssec.sh
==============================================================================
--- branches/OpenDNSSEC-1.3/testing/test-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-1.3/testing/test-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -9,6 +9,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: branches/OpenDNSSEC-enforcer-ng/testing/functions-opendnssec.sh
==============================================================================
--- branches/OpenDNSSEC-enforcer-ng/testing/functions-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-enforcer-ng/testing/functions-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -15,6 +15,13 @@
 	true
 }
 
+ods_interrupt_test ()
+{
+    ods_kill
+    ods_ldns_testns_kill
+    ods_bind9_kill
+}
+
 ods_nuke_env ()
 {
 	local kasp_files=`cd "$INSTALL_ROOT/var/opendnssec/" && ls kasp*db* 2>/dev/null`

Modified: branches/OpenDNSSEC-enforcer-ng/testing/lib.sh
==============================================================================
--- branches/OpenDNSSEC-enforcer-ng/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-enforcer-ng/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: branches/OpenDNSSEC-enforcer-ng/testing/test-opendnssec.sh
==============================================================================
--- branches/OpenDNSSEC-enforcer-ng/testing/test-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ branches/OpenDNSSEC-enforcer-ng/testing/test-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -9,6 +9,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: releases/softHSM-1.3.4/testing/lib.sh
==============================================================================
--- releases/softHSM-1.3.4/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ releases/softHSM-1.3.4/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: trunk/OpenDNSSEC/testing/functions-opendnssec.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/functions-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/functions-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -15,6 +15,13 @@
 	true
 }
 
+ods_interrupt_test ()
+{
+    ods_kill
+    ods_ldns_testns_kill
+    ods_bind9_kill
+}
+
 ods_nuke_env ()
 {
 	local kasp_files=`cd "$INSTALL_ROOT/var/opendnssec/" && ls kasp*db* 2>/dev/null`

Modified: trunk/OpenDNSSEC/testing/lib.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: trunk/OpenDNSSEC/testing/test-daily-opendnssec-mysql.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/test-daily-opendnssec-mysql.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/test-daily-opendnssec-mysql.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -11,6 +11,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: trunk/OpenDNSSEC/testing/test-daily-opendnssec.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/test-daily-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/test-daily-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -9,6 +9,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: trunk/OpenDNSSEC/testing/test-opendnssec-mysql.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/test-opendnssec-mysql.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/test-opendnssec-mysql.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -11,6 +11,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: trunk/OpenDNSSEC/testing/test-opendnssec.sh
==============================================================================
--- trunk/OpenDNSSEC/testing/test-opendnssec.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/OpenDNSSEC/testing/test-opendnssec.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -9,6 +9,7 @@
 
 PRE_TEST=ods_pre_test
 POST_TEST=ods_post_test
+INTERRUPT_TEST=ods_interrupt_test
 RETRY_TEST=1
 test_ok=0
 (

Modified: trunk/softHSM/testing/lib.sh
==============================================================================
--- trunk/softHSM/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/softHSM/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: trunk/softHSMv2/testing/lib.sh
==============================================================================
--- trunk/softHSMv2/testing/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/softHSMv2/testing/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then

Modified: trunk/testing/framework/lib.sh
==============================================================================
--- trunk/testing/framework/lib.sh	Fri Jan 25 11:02:50 2013	(r6984)
+++ trunk/testing/framework/lib.sh	Fri Jan 25 11:03:59 2013	(r6985)
@@ -566,6 +566,10 @@
 	find_date || exit 1
 	find_tail || exit 1
 	
+	# prevent CTRL-Z and CTRL-C
+    trap "" SIGINT 2>/dev/null >/dev/null
+    trap "" SIGTSTP 2>/dev/null >/dev/null
+    
 	return 0
 }
 
@@ -702,6 +706,9 @@
 				local build_svn_rev=`cat "$INSTALL_ROOT/.$name_tag.test" 2>/dev/null`
 				
 				if [ "$SVN_REVISION" = "$build_svn_rev" ]; then
+				    if [ -f junit.xml ]; then
+				        touch junit.xml
+				    fi
 					return 0
 				fi
 			fi
@@ -1388,9 +1395,19 @@
 	local test_path
 	local test_status
 	local test_failed=0
+	local test_start
+	local test_stop
+	local test_time
 	local pwd=`pwd`
 	local pwd2
 	local retry
+	local junit="$WORKSPACE/junit.xml"
+    local junit_head="$WORKSPACE/junit.xml.head"
+    local junit_test="$WORKSPACE/junit.xml.test"
+    local junit_foot="$WORKSPACE/junit.xml.foot"
+    local tail_pid
+    local test_name
+    local test_classname
 
 	if [ -n "$PRE_TEST" ]; then
 		if ! declare -F "$PRE_TEST" >/dev/null 2>/dev/null; then
@@ -1404,6 +1421,12 @@
 		fi
 	fi
 	
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+    
 	if [ -n "$RETRY_TEST" ]; then
 		if [ ! "$RETRY_TEST" -gt 0 ] 2>/dev/null; then
 			RETRY_TEST=0
@@ -1425,29 +1448,68 @@
 		return 1
 	fi
 		
+    rm -f "$junit" "$junit_test"
+    echo '<?xml version="1.0" encoding="UTF-8"?>' > "$junit_head"
+    echo '<testsuites>' > "$junit_head"
+
 	ls -1 2>/dev/null | $GREP '^[0-9]*' | $GREP -v '\.off$' 2>/dev/null >"_tests.$BUILD_TAG"
 	while read entry; do
-		if [ -d "$entry" -a -f "$entry/test.sh" -a ! -f "$entry/off" ]; then
-			test[test_num]="$entry"
-			test_num=$(( test_num + 1 ))
+		if [ -d "$entry" -a -f "$entry/test.sh" ]; then
+		    if [ -f "$entry/off" ]; then
+		        test_name=`echo "$entry"|sed 's%\.% %g'|awk '{print $3}'`
+		        if [ -z "$test_name" ]; then
+		            test_name='unknown'
+		        fi
+		        test_classname=`echo "$entry"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+		        if [ -z "$test_classname" ]; then
+		            test_classname='unknown.unknown'
+		        fi
+	            echo '<testsuite name="'"$entry"'" tests="1" skip="1">' >> "$junit_test"
+	            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'">' >> "$junit_test"
+                echo '<skipped message="Skipped">Test skipped, disabled with off file</skipped>' >> "$junit_test"
+	            echo '</testcase>' >> "$junit_test"
+	            echo '</testsuite>' >> "$junit_test"
+	        else
+				test[test_num]="$entry"
+				test_num=$(( test_num + 1 ))
+			fi
 		fi
 	done <"_tests.$BUILD_TAG"
 	rm -f "_tests.$BUILD_TAG" 2>/dev/null
 	
 	if [ "$test_num" -le 0 ] 2>/dev/null; then
-		echo "run_tests: no tests found!" >&2
+		echo "run_tests: no active tests found!" >&2
 		cd "$pwd"
+		# Do not generate JUnit if there is no tests or all tests skipped because
+        # Jenkins might mark it failed otherwise
+	    rm -f "$junit_head" "$junit_test" "$junit_foot"
 		return 1
 	fi
-
+	
+    if [ -n "$INTERRUPT_TEST" ]; then
+		STOP_TEST=0
+		trap "STOP_TEST=1" SIGINT
+	fi
+	
 	echo "Running tests ..."	
 	while [ "$test_iter" -lt "$test_num" ] 2>/dev/null; do
 		retry=0
 		test_path="${test[test_iter]}"
 		test_iter=$(( test_iter + 1 ))
+		test_start=`date +%s`
+        test_name=`echo "$test_path"|sed 's%\.% %g'|awk '{print $3}'`
+        if [ -z "$test_name" ]; then
+            test_name='unknown'
+        fi
+        test_classname=`echo "$test_path"|sed 's%\.% %g'|awk '{print $1 "." $2}'`
+        if [ -z "$test_classname" ]; then
+            test_classname='unknown.unknown'
+        fi
 		echo "##### `date` $test_iter/$test_num $test_path ... "
 		pwd2=`pwd`
 		cd "$test_path" 2>/dev/null &&
+		rm -f "_test.$BUILD_TAG" &&
+		touch "_test.$BUILD_TAG" &&
 		while [ "$retry" -le "$RETRY_TEST" ] 2>/dev/null; do
 			if [ "$retry" -gt 0 ] 2>/dev/null; then
 				syslog_stop &&
@@ -1460,30 +1522,66 @@
 				}
 				echo "##### `date` $test_iter/$test_num $test_path ... RETRY $retry in $RETRY_SLEEP seconds"
 				sleep "$RETRY_SLEEP"
+                rm -f "_test.$BUILD_TAG"
+                touch "_test.$BUILD_TAG"
 			fi
 			syslog_trace &&
 			if [ -n "$PRE_TEST" ]; then
 				$PRE_TEST "$test_path"
 			fi &&
-			( source ./test.sh )
-			test_status="$?"
+			( source ./test.sh ) >> "_test.$BUILD_TAG" 2>&1
+            test_status="$?"
+			if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+                cat "_test.$BUILD_TAG"
+			    echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+			    break
+			fi
 			if [ "$test_status" -eq 0 ] 2>/dev/null; then
 				break
 			fi
 			retry=$(( retry + 1 ))
 		done
+		test_stop=`date +%s`
+		test_time=0
+        if [ "$test_start" -gt 0 -a "$test_stop" -gt 0 ] 2>/dev/null; then
+            test_time=$(( test_stop - test_start ))
+        fi
 		syslog_stop
-		if [ -n "$POST_TEST" ]; then
+        if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+            $INTERRUPT_TEST "$test_path"
+            test_failed=1
+            break
+        elif [ -n "$POST_TEST" ]; then
 			$POST_TEST "$test_path" "$test_status"
 		fi
 		if [ "$test_status" -eq 0 ] 2>/dev/null; then
+			cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... OK"
 			log_cleanup
 			syslog_cleanup
+
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+    		echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-out>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-out>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		else
 			test_failed=$(( test_failed + 1 ))
+            cat "_test.$BUILD_TAG"
 			echo "##### `date` $test_iter/$test_num $test_path ... FAILED!"
+			
+            echo '<testsuite name="'"$test_path"'" tests="1" time="'"$test_time"'">' >> "$junit_test"
+            echo '<testcase name="'"$test_name"'" classname="'"$test_classname"'" time="'"$test_time"'">' >> "$junit_test"
+            echo '<failure message="Failed">Test failed, exit code '"$test_status"'</failure>' >> "$junit_test"
+            echo '</testcase>' >> "$junit_test"
+            echo '<system-err>' >> "$junit_test"
+            cat "_test.$BUILD_TAG" | sed 's%&%\&%g' | sed 's%<%\<%g' | sed 's%>%\>%g' >> "$junit_test" 2>/dev/null
+            echo '</system-err>' >> "$junit_test"
+            echo '</testsuite>' >> "$junit_test"
 		fi
+		rm -f "_test.$BUILD_TAG"
 
 		if ! cd "$pwd2" 2>/dev/null; then
 			echo "run_tests: unable to change back to test directory $pwd2 after running a test!" >&2
@@ -1492,6 +1590,14 @@
 		fi
 	done
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        trap "" SIGINT
+    fi
+
+    echo '</testsuites>' > "$junit_foot"
+    cat "$junit_head" "$junit_test" "$junit_foot" > "$junit" 2>/dev/null
+    rm -f "$junit_head" "$junit_test" "$junit_foot"
+
 	if ! cd "$pwd" 2>/dev/null; then
 		echo "run_tests: unable to change back to directory $pwd after running tests!" >&2
 		return 1
@@ -1526,6 +1632,12 @@
 		fi
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        if ! declare -F "$INTERRUPT_TEST" >/dev/null 2>/dev/null; then
+            unset INTERRUPT_TEST
+        fi
+    fi
+	
 	if [ ! -f "$test_dir/test.sh" ]; then
 		echo "run_test: no test.sh in test $test_name ($test_dir)!" >&2
 		return 1
@@ -1536,6 +1648,11 @@
 		return 1
 	fi
 
+    if [ -n "$INTERRUPT_TEST" ]; then
+        STOP_TEST=0
+        trap "STOP_TEST=1" SIGINT
+    fi
+
 	echo "##### Running test $test_name ..." 
 	if [ -n "$PRE_TEST" ]; then
 		$PRE_TEST "$test_name"
@@ -1544,7 +1661,12 @@
 	( source ./test.sh )
 	test_status="$?"
 	syslog_stop
-	if [ -n "$POST_TEST" ]; then
+    if [ -n "$INTERRUPT_TEST" -a "$STOP_TEST" = "1" ]; then
+        echo "##### `date` $test_iter/$test_num $test_path ... INTERRUPTED"
+	    $INTERRUPT_TEST "$test_path"
+	    trap "" SIGINT
+	    return 1
+    elif [ -n "$POST_TEST" ]; then
 		$POST_TEST "$test_name" "$test_status"
 	fi
 	if [ "$test_status" -eq 0 ] 2>/dev/null; then



More information about the Opendnssec-commits mailing list