1
2
3
4
5
6
7
8
9
10
11#include <efi_selftest.h>
12
13static struct efi_boot_services *boottime;
14static struct efi_event *event_notify;
15static unsigned int notification_count;
16
17
18
19
20
21
22
23static void EFIAPI notify(struct efi_event *event, void *context)
24{
25 unsigned int *count = context;
26
27 ++*count;
28}
29
30
31
32
33
34
35
36
37
38
39static int setup(const efi_handle_t handle,
40 const struct efi_system_table *systable)
41{
42 efi_status_t ret;
43
44 boottime = systable->boottime;
45
46 notification_count = 0;
47 ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
48 TPL_CALLBACK, notify,
49 (void *)¬ification_count,
50 &event_notify);
51 if (ret != EFI_SUCCESS) {
52 efi_st_error("could not create event\n");
53 return EFI_ST_FAILURE;
54 }
55 return EFI_ST_SUCCESS;
56}
57
58
59
60
61
62
63
64
65
66
67
68
69static int execute(void)
70{
71 if (notification_count != 1) {
72 efi_st_error("ExitBootServices was not notified\n");
73 return EFI_ST_FAILURE;
74 }
75 efi_st_exit_boot_services();
76 if (notification_count != 1) {
77 efi_st_error("ExitBootServices was notified twice\n");
78 return EFI_ST_FAILURE;
79 }
80 return EFI_ST_SUCCESS;
81}
82
83EFI_UNIT_TEST(exitbootservices) = {
84 .name = "ExitBootServices",
85 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
86 .setup = setup,
87 .execute = execute,
88};
89