1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_event_groups
7 * This test checks the notification of group events and the
9 * CreateEventEx, CloseEvent, SignalEvent, CheckEvent.
12 #include <efi_selftest.h>
16 static struct efi_boot_services *boottime;
17 static efi_guid_t event_group =
18 EFI_GUID(0x2335905b, 0xc3b9, 0x4221, 0xa3, 0x71,
19 0x0e, 0x5b, 0x45, 0xc0, 0x56, 0x91);
22 * Notification function, increments the notification count if parameter
23 * context is provided.
25 * @event notified event
26 * @context pointer to the notification count
28 static void EFIAPI notify(struct efi_event *event, void *context)
30 unsigned int *count = context;
39 * @handle: handle of the loaded image
40 * @systable: system table
41 * @return: EFI_ST_SUCCESS for success
43 static int setup(const efi_handle_t handle,
44 const struct efi_system_table *systable)
46 boottime = systable->boottime;
48 return EFI_ST_SUCCESS;
54 * Create multiple events in an event group. Signal each event once and check
55 * that all events are notified once in each round.
57 * @return: EFI_ST_SUCCESS for success
59 static int execute(void)
61 unsigned int counter[GROUP_SIZE] = {0};
62 struct efi_event *events[GROUP_SIZE];
66 for (i = 0; i < GROUP_SIZE; ++i) {
67 ret = boottime->create_event_ex(0, TPL_NOTIFY,
68 notify, (void *)&counter[i],
69 &event_group, &events[i]);
70 if (ret != EFI_SUCCESS) {
71 efi_st_error("Failed to create event\n");
72 return EFI_ST_FAILURE;
76 for (i = 0; i < GROUP_SIZE; ++i) {
77 ret = boottime->signal_event(events[i]);
78 if (ret != EFI_SUCCESS) {
79 efi_st_error("Failed to signal event\n");
80 return EFI_ST_FAILURE;
82 for (j = 0; j < GROUP_SIZE; ++j) {
83 if (counter[j] != i) {
84 efi_st_printf("i %u, j %u, count %u\n",
85 (unsigned int)i, (unsigned int)j,
86 (unsigned int)counter[j]);
88 "Notification function was called\n");
89 return EFI_ST_FAILURE;
91 /* Clear signaled state */
92 ret = boottime->check_event(events[j]);
93 if (ret != EFI_SUCCESS) {
94 efi_st_error("Event was not signaled\n");
95 return EFI_ST_FAILURE;
97 if (counter[j] != i) {
98 efi_st_printf("i %u, j %u, count %u\n",
99 (unsigned int)i, (unsigned int)j,
100 (unsigned int)counter[j]);
102 "Notification function was called\n");
103 return EFI_ST_FAILURE;
105 /* Call notification function */
106 ret = boottime->check_event(events[j]);
107 if (ret != EFI_NOT_READY) {
109 "Signaled state not cleared\n");
110 return EFI_ST_FAILURE;
112 if (counter[j] != i + 1) {
113 efi_st_printf("i %u, j %u, count %u\n",
114 (unsigned int)i, (unsigned int)j,
115 (unsigned int)counter[j]);
117 "Notification function not called\n");
118 return EFI_ST_FAILURE;
123 for (i = 0; i < GROUP_SIZE; ++i) {
124 ret = boottime->close_event(events[i]);
125 if (ret != EFI_SUCCESS) {
126 efi_st_error("Failed to close event\n");
127 return EFI_ST_FAILURE;
131 return EFI_ST_SUCCESS;
134 EFI_UNIT_TEST(eventgoups) = {
135 .name = "event groups",
136 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,