1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_exitbootservices
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * This unit test checks that the notification function of an
8 * EVT_SIGNAL_EXIT_BOOT_SERVICES event is called exactly once.
11 #include <efi_selftest.h>
13 static struct efi_boot_services *boottime;
14 static struct efi_event *event_notify;
15 static unsigned int notification_count;
18 * Notification function, increments the notification count.
20 * @event notified event
21 * @context pointer to the notification count
23 static void EFIAPI notify(struct efi_event *event, void *context)
25 unsigned int *count = context;
33 * Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event.
35 * @handle: handle of the loaded image
36 * @systable: system table
37 * @return: EFI_ST_SUCCESS for success
39 static int setup(const efi_handle_t handle,
40 const struct efi_system_table *systable)
44 boottime = systable->boottime;
46 notification_count = 0;
47 ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
49 (void *)¬ification_count,
51 if (ret != EFI_SUCCESS) {
52 efi_st_error("could not create event\n");
53 return EFI_ST_FAILURE;
55 return EFI_ST_SUCCESS;
59 * Tear down unit test.
61 * Close the event created in setup.
63 * @return: EFI_ST_SUCCESS for success
65 static int teardown(void)
70 ret = boottime->close_event(event_notify);
72 if (ret != EFI_SUCCESS) {
73 efi_st_error("could not close event\n");
74 return EFI_ST_FAILURE;
77 return EFI_ST_SUCCESS;
83 * Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES
84 * event has been called.
86 * Call ExitBootServices again and check that the notification function is
89 * @return: EFI_ST_SUCCESS for success
91 static int execute(void)
93 if (notification_count != 1) {
94 efi_st_error("ExitBootServices was not notified\n");
95 return EFI_ST_FAILURE;
97 efi_st_exit_boot_services();
98 if (notification_count != 1) {
99 efi_st_error("ExitBootServices was notified twice\n");
100 return EFI_ST_FAILURE;
102 return EFI_ST_SUCCESS;
105 EFI_UNIT_TEST(exitbootservices) = {
106 .name = "ExitBootServices",
107 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
110 .teardown = teardown,