diff mbox series

[kvm-unit-tests,v2,06/10] x86 UEFI: Exit QEMU with return code

Message ID 20211116204053.220523-7-zxwang42@gmail.com (mailing list archive)
State New, archived
Headers show
Series x86_64 UEFI set up process refactor and scripts fixes | expand

Commit Message

Zixuan Wang Nov. 16, 2021, 8:40 p.m. UTC
From: Zixuan Wang <zxwang42@gmail.com>

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@gmail.com>
---
 lib/efi.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;