4 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
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 counter;
19 * Notification function, increments a counter.
21 * @event notified event
22 * @context pointer to the counter
24 static void EFIAPI notify(struct efi_event *event, void *context)
28 ++*(unsigned int *)context;
34 * Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event.
36 * @handle: handle of the loaded image
37 * @systable: system table
39 static int setup(const efi_handle_t handle,
40 const struct efi_system_table *systable)
44 boottime = systable->boottime;
47 ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
48 TPL_CALLBACK, notify, (void *)&counter,
50 if (ret != EFI_SUCCESS) {
51 efi_st_error("could not create event\n");
58 * Tear down unit test.
60 * Close the event created in setup.
62 static int teardown(void)
67 ret = boottime->close_event(event_notify);
69 if (ret != EFI_SUCCESS) {
70 efi_st_error("could not close event\n");
80 * Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES
81 * event has been called.
83 * Call ExitBootServices again and check that the notification function is
86 static int execute(void)
89 efi_st_error("ExitBootServices was not notified");
92 efi_st_exit_boot_services();
94 efi_st_error("ExitBootServices was notified twice");
100 EFI_UNIT_TEST(exitbootservices) = {
101 .name = "ExitBootServices",
102 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
105 .teardown = teardown,