]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: track and check for timeouts
authorMartin Pitt <martin.pitt@ubuntu.com>
Fri, 24 Jun 2016 10:11:19 +0000 (12:11 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Fri, 24 Jun 2016 14:07:16 +0000 (16:07 +0200)
If run_qemu() exits with non-zero, this either meant that QEMU was not
available (which should be a SKIP) or that QEMU timed out if $QEMU_TIMEOUT was
set (which then should be a FAIL).

Limit the exit code of run_qemu() to QEMU availability only, and track timeouts
separately through the new $TIMED_OUT variable, which is then checked in
check_result_qemu().

Do the same for $NSPAWN_TIMEOUT and run_nspawn() so that nspawn and QEMU work
similarly.

test/TEST-08-ISSUE-2730/test.sh
test/TEST-09-ISSUE-2691/test.sh
test/test-functions

index e3b42a5254b00128f64956c30e5416bba1f837b8..44831983b3bfd5cf7620b7d353558aebc964270e 100755 (executable)
@@ -19,6 +19,7 @@ check_result_qemu() {
     [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
     ls -l $TESTDIR/journal/*/*.journal
     test -s $TESTDIR/failed && ret=$(($ret+1))
+    [ -n "$TIMED_OUT" ] && ret=$(($ret+1))
     return $ret
 }
 
index a782cad37d0c72c277ed25bee133ed8b78b804af..8ae02e61ac594f4864cb0ea3bda419c7ed1a1e5e 100755 (executable)
@@ -18,6 +18,7 @@ check_result_qemu() {
     [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
     ls -l $TESTDIR/journal/*/*.journal
     test -s $TESTDIR/failed && ret=$(($ret+1))
+    [ -n "$TIMED_OUT" ] && ret=$(($ret+1))
     return $ret
 }
 
index 5f95a8129efb048f79bfb6edac7e4b42e1b91364..d8b7109671e726e0d513b95ce72286e4f460df00 100644 (file)
@@ -9,6 +9,7 @@ KERNEL_VER=${KERNEL_VER-$(uname -r)}
 KERNEL_MODS="/lib/modules/$KERNEL_VER/"
 QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}"
 NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-infinity}"
+TIMED_OUT=  # will be 1 after run_* if *_TIMEOUT is set and test timed out
 FSTYPE="${FSTYPE:-ext3}"
 UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-no}"
 
@@ -46,6 +47,8 @@ function find_qemu_bin() {
     fi
 }
 
+# Return 0 if QEMU did run (then you must check the result state/logs for actual
+# success), or 1 if QEMU is not available.
 run_qemu() {
     if [ -f /etc/machine-id ]; then
         read MACHINE_ID < /etc/machine-id
@@ -94,8 +97,15 @@ $KERNEL_APPEND \
     if [[ "$QEMU_TIMEOUT" != "infinity" ]]; then
         QEMU_BIN="timeout --foreground $QEMU_TIMEOUT $QEMU_BIN"
     fi
-    ( set -x
-      $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" ) || return 1
+    (set -x; $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND")
+    rc=$?
+    if [ "$rc" = 124 ] && [ "$QEMU_TIMEOUT" != "infinity" ]; then
+        derror "test timed out after $QEMU_TIMEOUT s"
+        TIMED_OUT=1
+    else
+        [ "$rc" != 0 ] && derror "QEMU failed with exit code $rc"
+    fi
+    return 0
 }
 
 run_nspawn() {
@@ -106,8 +116,15 @@ run_nspawn() {
 
     _nspawn_cmd="env UNIFIED_CGROUP_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd"
 
-    set -x
-    $_nspawn_cmd
+    (set -x; $_nspawn_cmd)
+    rc=$?
+    if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then
+        derror "test timed out after $NSPAWN_TIMEOUT s"
+        TIMED_OUT=1
+    else
+        [ "$rc" != 0 ] && derror "nspawn failed with exit code $rc"
+    fi
+    return 0
 }
 
 setup_basic_environment() {
@@ -290,6 +307,7 @@ check_result_nspawn() {
     [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
     ls -l $TESTDIR/journal/*/*.journal
     test -s $TESTDIR/failed && ret=$(($ret+1))
+    [ -n "$TIMED_OUT" ] && ret=$(($ret+1))
     return $ret
 }