From: Zixuan Wang <zxwang42@xxxxxxxxx> kvm-unit-tests runner scripts parse QEMU exit code to determine if a test case runs successfully. But the UEFI 'reset_system' function always exits QEMU with code 0, even if the test case returns a non-zero code. This commit fixes this issue by calling 'exit' function to exit QEMU with the correct code. Signed-off-by: Zixuan Wang <zxwang42@xxxxxxxxx> --- lib/efi.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/efi.c b/lib/efi.c index 99eb00c..64cc978 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -85,6 +85,17 @@ efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table) return EFI_NOT_FOUND; } +static void efi_exit(efi_status_t code) +{ + exit(code); + + /* + * Fallback to UEFI reset_system() service, in case testdev is + * missing and exit() does not properly exit. + */ + efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, code, 0, NULL); +} + efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) { int ret; @@ -134,14 +145,14 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) ret = main(__argc, __argv, __environ); /* Shutdown the guest VM */ - efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, ret, 0, NULL); + efi_exit(ret); /* Unreachable */ return EFI_UNSUPPORTED; efi_main_error: /* Shutdown the guest with error EFI status */ - efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, status, 0, NULL); + efi_exit(status); /* Unreachable */ return EFI_UNSUPPORTED; -- 2.33.0