summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2016-06-24 12:11:19 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2016-06-24 16:07:16 +0200
commitb2ecd099dc7371aafb988145ab40a631f7050d41 (patch)
treeb3c65c452b1baa718afbcee5247692304d7de53a
parent633736bbf49e31d62e7a8a16b330efa6866723db (diff)
tests: track and check for timeouts
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.
-rwxr-xr-xtest/TEST-08-ISSUE-2730/test.sh1
-rwxr-xr-xtest/TEST-09-ISSUE-2691/test.sh1
-rw-r--r--test/test-functions26
3 files changed, 24 insertions, 4 deletions
diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh
index e3b42a5254..44831983b3 100755
--- a/test/TEST-08-ISSUE-2730/test.sh
+++ b/test/TEST-08-ISSUE-2730/test.sh
@@ -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
}
diff --git a/test/TEST-09-ISSUE-2691/test.sh b/test/TEST-09-ISSUE-2691/test.sh
index a782cad37d..8ae02e61ac 100755
--- a/test/TEST-09-ISSUE-2691/test.sh
+++ b/test/TEST-09-ISSUE-2691/test.sh
@@ -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
}
diff --git a/test/test-functions b/test/test-functions
index 5f95a8129e..d8b7109671 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -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
}