Skip to content

Commit 2157f68

Browse files
pamauryAlexJones0
authored andcommitted
[rules,qemu] Always stop QEMU after the test
Even though opentitanlib supports asking QEMU to shutdown, it is (1) optional, (2) relies on the test harness stopping cleanly. One may argue that it is not really the responsability of the test harness to shutdown QEMU anyway since it is not spawn by the harness but rather by the qemu_test.sh script. This commit makes the qemu_test.sh script always shutdown QEMU on exit. It first sends a SIGINT and after one second a SIGKILL. Signed-off-by: Amaury Pouly <[email protected]>
1 parent ea20827 commit 2157f68

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rules/scripts/qemu_test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ for this_arg in "${test_args[@]}"; do
4141
fi
4242
done
4343

44+
qemu_pid=""
45+
4446
cleanup() {
47+
set +e
48+
echo "Stopping QEMU: $qemu_pid"
49+
# Ask nicely QEMU to stop and then kill it after one second.
50+
( sleep 1 ; echo "Killing QEMU"; kill -KILL "$qemu_pid" ) &
51+
kill "$qemu_pid"
52+
wait "$qemu_pid"
53+
4554
rm -f "${mutable_otp}" "${mutable_flash}"
4655
rm -f qemu-monitor qemu.log
4756
}
@@ -60,6 +69,7 @@ mkfifo qemu.log && cat qemu.log &
6069

6170
echo "Starting QEMU: ${qemu} ${qemu_test_args[*]} ${qemu_args[*]}"
6271
"${qemu}" "${qemu_test_args[@]}" "${qemu_args[@]}"
72+
qemu_pid=$!
6373

6474
echo "Invoking test: ${test_harness} ${args[*]} ${harness_test_args[*]} ${test_cmd[*]}"
6575
"${test_harness}" "${args[@]}" "${harness_test_args[@]}" "${test_cmd[@]}"

0 commit comments

Comments
 (0)