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 efi_guid_t guid_before_exit_boot_services =
14 EFI_GUID(0x8be0e274, 0x3970, 0x4b44, 0x80, 0xc5,
15 0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc);
18 struct notification_record {
20 unsigned int type[CAPACITY];
23 struct notification_context {
24 struct notification_record *record;
28 static struct efi_boot_services *boottime;
29 static struct efi_event *efi_st_event_notify;
30 static struct notification_record record;
32 struct notification_context context_before = {
37 struct notification_context context = {
43 * Notification function, increments the notification count.
45 * @event notified event
46 * @context pointer to the notification count
48 static void EFIAPI ebs_notify(struct efi_event *event, void *context)
50 struct notification_context *ctx = context;
52 if (ctx->record->count >= CAPACITY)
55 ctx->record->type[ctx->record->count] = ctx->type;
62 * Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event.
64 * @handle: handle of the loaded image
65 * @systable: system table
66 * Return: EFI_ST_SUCCESS for success
68 static int setup(const efi_handle_t handle,
69 const struct efi_system_table *systable)
73 boottime = systable->boottime;
75 ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
76 TPL_CALLBACK, ebs_notify,
78 &efi_st_event_notify);
79 if (ret != EFI_SUCCESS) {
80 efi_st_error("could not create event\n");
81 return EFI_ST_FAILURE;
83 ret = boottime->create_event_ex(0, TPL_CALLBACK, ebs_notify,
85 &guid_before_exit_boot_services,
86 &efi_st_event_notify);
87 if (ret != EFI_SUCCESS) {
88 efi_st_error("could not create event\n");
89 return EFI_ST_FAILURE;
92 return EFI_ST_SUCCESS;
98 * Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES
99 * event has been called.
101 * Call ExitBootServices again and check that the notification function is
104 * Return: EFI_ST_SUCCESS for success
106 static int execute(void)
108 if (record.count != 2) {
109 efi_st_error("Incorrect event count %u\n", record.count);
110 return EFI_ST_FAILURE;
112 if (record.type[0] != 1) {
113 efi_st_error("EFI_GROUP_BEFORE_EXIT_BOOT_SERVICE not notified\n");
114 return EFI_ST_FAILURE;
116 if (record.type[1] != 2) {
117 efi_st_error("EVT_SIGNAL_EXIT_BOOT_SERVICES was not notified\n");
118 return EFI_ST_FAILURE;
120 efi_st_exit_boot_services();
121 if (record.count != 2) {
122 efi_st_error("Incorrect event count %u\n", record.count);
123 return EFI_ST_FAILURE;
125 return EFI_ST_SUCCESS;
128 EFI_UNIT_TEST(exitbootservices) = {
129 .name = "ExitBootServices",
130 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,