Currently QEMU exits with code 0 on both panic an shutdown. For tests
it is useful to return 1 on panic, so that it counts as a test
failure.
Introduce a new exit-failure PanicAction that makes main() return
EXIT_FAILURE. Tests can use -action panic=exit-failure option to
activate this behavior.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-Id: <
20220725223746.227063-2-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
bool defaults_enabled(void);
void qemu_init(int argc, char **argv, char **envp);
-void qemu_main_loop(void);
+int qemu_main_loop(void);
void qemu_cleanup(void);
extern QemuOptsList qemu_legacy_drive_opts;
#
# @shutdown: Shutdown the VM and exit, according to the shutdown action
#
+# @exit-failure: Shutdown the VM and exit with nonzero status
+# (since 7.1)
+#
# Since: 6.0
##
{ 'enum': 'PanicAction',
- 'data': [ 'pause', 'shutdown', 'none' ] }
+ 'data': [ 'pause', 'shutdown', 'exit-failure', 'none' ] }
##
# @watchdog-set-action:
" action when guest reboots [default=reset]\n"
"-action shutdown=poweroff|pause\n"
" action when guest shuts down [default=poweroff]\n"
- "-action panic=pause|shutdown|none\n"
+ "-action panic=pause|shutdown|exit-failure|none\n"
" action when guest panics [default=shutdown]\n"
"-action watchdog=reset|shutdown|poweroff|inject-nmi|pause|debug|none\n"
" action when watchdog fires [default=reset]\n",
int qemu_main(int argc, char **argv, char **envp)
{
+ int status;
+
qemu_init(argc, argv, envp);
- qemu_main_loop();
+ status = qemu_main_loop();
qemu_cleanup();
- return 0;
+ return status;
}
#ifndef CONFIG_COCOA
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
!!info, info);
vm_stop(RUN_STATE_GUEST_PANICKED);
- } else if (panic_action == PANIC_ACTION_SHUTDOWN) {
+ } else if (panic_action == PANIC_ACTION_SHUTDOWN ||
+ panic_action == PANIC_ACTION_EXIT_FAILURE) {
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
!!info, info);
vm_stop(RUN_STATE_GUEST_PANICKED);
qemu_notify_event();
}
-static bool main_loop_should_exit(void)
+static bool main_loop_should_exit(int *status)
{
RunState r;
ShutdownCause request;
if (shutdown_action == SHUTDOWN_ACTION_PAUSE) {
vm_stop(RUN_STATE_SHUTDOWN);
} else {
+ if (request == SHUTDOWN_CAUSE_GUEST_PANIC &&
+ panic_action == PANIC_ACTION_EXIT_FAILURE) {
+ *status = EXIT_FAILURE;
+ }
return true;
}
}
return false;
}
-void qemu_main_loop(void)
+int qemu_main_loop(void)
{
+ int status = EXIT_SUCCESS;
#ifdef CONFIG_PROFILER
int64_t ti;
#endif
- while (!main_loop_should_exit()) {
+
+ while (!main_loop_should_exit(&status)) {
#ifdef CONFIG_PROFILER
ti = profile_getclock();
#endif
dev_time += profile_getclock() - ti;
#endif
}
+
+ return status;
}
void qemu_add_exit_notifier(Notifier *notify)