2 * efi_selftest_exitbootservices
6 * SPDX-License-Identifier: GPL-2.0+
8 * This unit test checks that the notification function of an
9 * EVT_SIGNAL_EXIT_BOOT_SERVICES event is called exactly once.
12 #include <efi_selftest.h>
14 static struct efi_boot_services *boottime;
15 static struct efi_event *event_notify;
16 static unsigned int notification_count;
19 * Notification function, increments the notification count.
21 * @event notified event
22 * @context pointer to the notification count
24 static void EFIAPI notify(struct efi_event *event, void *context)
26 unsigned int *count = context;
34 * Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event.
36 * @handle: handle of the loaded image
37 * @systable: system table
38 * @return: EFI_ST_SUCCESS for success
40 static int setup(const efi_handle_t handle,
41 const struct efi_system_table *systable)
45 boottime = systable->boottime;
47 notification_count = 0;
48 ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
50 (void *)¬ification_count,
52 if (ret != EFI_SUCCESS) {
53 efi_st_error("could not create event\n");
54 return EFI_ST_FAILURE;
56 return EFI_ST_SUCCESS;
60 * Tear down unit test.
62 * Close the event created in setup.
64 * @return: EFI_ST_SUCCESS for success
66 static int teardown(void)
71 ret = boottime->close_event(event_notify);
73 if (ret != EFI_SUCCESS) {
74 efi_st_error("could not close event\n");
75 return EFI_ST_FAILURE;
78 return EFI_ST_SUCCESS;
84 * Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES
85 * event has been called.
87 * Call ExitBootServices again and check that the notification function is
90 * @return: EFI_ST_SUCCESS for success
92 static int execute(void)
94 if (notification_count != 1) {
95 efi_st_error("ExitBootServices was not notified\n");
96 return EFI_ST_FAILURE;
98 efi_st_exit_boot_services();
99 if (notification_count != 1) {
100 efi_st_error("ExitBootServices was notified twice\n");
101 return EFI_ST_FAILURE;
103 return EFI_ST_SUCCESS;
106 EFI_UNIT_TEST(exitbootservices) = {
107 .name = "ExitBootServices",
108 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
111 .teardown = teardown,