@@ -30,7 +30,7 @@ M+=",accel=$ACCEL"
command="$qemu -nodefaults -nographic $M"
command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
command+=" -kernel"
-command="$(migration_cmd) $(timeout_cmd) $command"
+command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
# We return the exit code via stdout, not via the QEMU return code
run_qemu_status $command "$@"
@@ -104,6 +104,14 @@ qmp ()
echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | ncat -U $1
}
+qmp_events ()
+{
+ while ! test -S "$1"; do sleep 0.1; done
+ echo '{ "execute": "qmp_capabilities" }{ "execute": "cont" }' |
+ ncat --no-shutdown -U $1 |
+ jq -c 'select(has("event"))'
+}
+
run_migration ()
{
if ! command -v ncat >/dev/null 2>&1; then
@@ -164,6 +172,40 @@ run_migration ()
return $ret
}
+run_panic ()
+{
+ if ! command -v ncat >/dev/null 2>&1; then
+ echo "${FUNCNAME[0]} needs ncat (netcat)" >&2
+ return 77
+ fi
+
+ if ! command -v jq >/dev/null 2>&1; then
+ echo "${FUNCNAME[0]} needs jq" >&2
+ return 77
+ fi
+
+ qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX)
+
+ trap 'kill 0; exit 2' INT TERM
+ trap 'rm -f ${qmp}' RETURN EXIT
+
+ # start VM stopped so we don't miss any events
+ eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
+ -mon chardev=mon1,mode=control -S &
+
+ panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l)
+ if [ "$panic_event_count" -lt 1 ]; then
+ echo "FAIL: guest did not panic"
+ ret=3
+ else
+ # some QEMU versions report multiple panic events
+ echo "PASS: guest panicked"
+ ret=1
+ fi
+
+ return $ret
+}
+
migration_cmd ()
{
if [ "$MIGRATION" = "yes" ]; then
@@ -171,6 +213,13 @@ migration_cmd ()
fi
}
+panic_cmd ()
+{
+ if [ "$PANIC" = "yes" ]; then
+ echo "run_panic"
+ fi
+}
+
search_qemu_binary ()
{
local save_path=$PATH
@@ -145,6 +145,9 @@ function run()
if find_word "migration" "$groups"; then
cmdline="MIGRATION=yes $cmdline"
fi
+ if find_word "panic" "$groups"; then
+ cmdline="PANIC=yes $cmdline"
+ fi
if [ "$verbose" = "yes" ]; then
echo $cmdline
fi