Skip to content

Commit b2ecd09

Browse files
committed
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.
1 parent 633736b commit b2ecd09

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

test/TEST-08-ISSUE-2730/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ check_result_qemu() {
1919
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
2020
ls -l $TESTDIR/journal/*/*.journal
2121
test -s $TESTDIR/failed && ret=$(($ret+1))
22+
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
2223
return $ret
2324
}
2425

test/TEST-09-ISSUE-2691/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ check_result_qemu() {
1818
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
1919
ls -l $TESTDIR/journal/*/*.journal
2020
test -s $TESTDIR/failed && ret=$(($ret+1))
21+
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
2122
return $ret
2223
}
2324

test/test-functions

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ KERNEL_VER=${KERNEL_VER-$(uname -r)}
99
KERNEL_MODS="/lib/modules/$KERNEL_VER/"
1010
QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}"
1111
NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-infinity}"
12+
TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out
1213
FSTYPE="${FSTYPE:-ext3}"
1314
UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-no}"
1415

@@ -46,6 +47,8 @@ function find_qemu_bin() {
4647
fi
4748
}
4849

50+
# Return 0 if QEMU did run (then you must check the result state/logs for actual
51+
# success), or 1 if QEMU is not available.
4952
run_qemu() {
5053
if [ -f /etc/machine-id ]; then
5154
read MACHINE_ID < /etc/machine-id
@@ -94,8 +97,15 @@ $KERNEL_APPEND \
9497
if [[ "$QEMU_TIMEOUT" != "infinity" ]]; then
9598
QEMU_BIN="timeout --foreground $QEMU_TIMEOUT $QEMU_BIN"
9699
fi
97-
( set -x
98-
$QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" ) || return 1
100+
(set -x; $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND")
101+
rc=$?
102+
if [ "$rc" = 124 ] && [ "$QEMU_TIMEOUT" != "infinity" ]; then
103+
derror "test timed out after $QEMU_TIMEOUT s"
104+
TIMED_OUT=1
105+
else
106+
[ "$rc" != 0 ] && derror "QEMU failed with exit code $rc"
107+
fi
108+
return 0
99109
}
100110

101111
run_nspawn() {
@@ -106,8 +116,15 @@ run_nspawn() {
106116

107117
_nspawn_cmd="env UNIFIED_CGROUP_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd"
108118

109-
set -x
110-
$_nspawn_cmd
119+
(set -x; $_nspawn_cmd)
120+
rc=$?
121+
if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then
122+
derror "test timed out after $NSPAWN_TIMEOUT s"
123+
TIMED_OUT=1
124+
else
125+
[ "$rc" != 0 ] && derror "nspawn failed with exit code $rc"
126+
fi
127+
return 0
111128
}
112129

113130
setup_basic_environment() {
@@ -290,6 +307,7 @@ check_result_nspawn() {
290307
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
291308
ls -l $TESTDIR/journal/*/*.journal
292309
test -s $TESTDIR/failed && ret=$(($ret+1))
310+
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
293311
return $ret
294312
}
295313

0 commit comments

Comments
 (0)