2 * efi_selftest_event_groups
4 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 * SPDX-License-Identifier: GPL-2.0+
8 * This test checks the notification of group events and the
10 * CreateEventEx, CloseEvent, SignalEvent, CheckEvent.
13 #include <efi_selftest.h>
17 static struct efi_boot_services *boottime;
18 static efi_guid_t event_group =
19 EFI_GUID(0x2335905b, 0xc3b9, 0x4221, 0xa3, 0x71,
20 0x0e, 0x5b, 0x45, 0xc0, 0x56, 0x91);
23 * Notification function, increments the notfication count if parameter
24 * context is provided.
26 * @event notified event
27 * @context pointer to the notification count
29 static void EFIAPI notify(struct efi_event *event, void *context)
31 unsigned int *count = context;
40 * @handle: handle of the loaded image
41 * @systable: system table
42 * @return: EFI_ST_SUCCESS for success
44 static int setup(const efi_handle_t handle,
45 const struct efi_system_table *systable)
47 boottime = systable->boottime;
49 return EFI_ST_SUCCESS;
55 * Create multiple events in an event group. Signal each event once and check
56 * that all events are notified once in each round.
58 * @return: EFI_ST_SUCCESS for success
60 static int execute(void)
62 unsigned int counter[GROUP_SIZE] = {0};
63 struct efi_event *events[GROUP_SIZE];
67 for (i = 0; i < GROUP_SIZE; ++i) {
68 ret = boottime->create_event_ex(0, TPL_NOTIFY,
69 notify, (void *)&counter[i],
70 &event_group, &events[i]);
71 if (ret != EFI_SUCCESS) {
72 efi_st_error("Failed to create event\n");
73 return EFI_ST_FAILURE;
77 for (i = 0; i < GROUP_SIZE; ++i) {
78 ret = boottime->signal_event(events[i]);
79 if (ret != EFI_SUCCESS) {
80 efi_st_error("Failed to signal event\n");
81 return EFI_ST_FAILURE;
83 for (j = 0; j < GROUP_SIZE; ++j) {
84 if (counter[j] != i) {
85 efi_st_printf("i %u, j %u, count %u\n",
86 (unsigned int)i, (unsigned int)j,
87 (unsigned int)counter[j]);
89 "Notification function was called\n");
90 return EFI_ST_FAILURE;
92 /* Clear signaled state */
93 ret = boottime->check_event(events[j]);
94 if (ret != EFI_SUCCESS) {
95 efi_st_error("Event was not signaled\n");
96 return EFI_ST_FAILURE;
98 if (counter[j] != i) {
99 efi_st_printf("i %u, j %u, count %u\n",
100 (unsigned int)i, (unsigned int)j,
101 (unsigned int)counter[j]);
103 "Notification function was called\n");
104 return EFI_ST_FAILURE;
106 /* Call notification function */
107 ret = boottime->check_event(events[j]);
108 if (ret != EFI_NOT_READY) {
110 "Signaled state not cleared\n");
111 return EFI_ST_FAILURE;
113 if (counter[j] != i + 1) {
114 efi_st_printf("i %u, j %u, count %u\n",
115 (unsigned int)i, (unsigned int)j,
116 (unsigned int)counter[j]);
118 "Nofification function not called\n");
119 return EFI_ST_FAILURE;
124 for (i = 0; i < GROUP_SIZE; ++i) {
125 ret = boottime->close_event(events[i]);
126 if (ret != EFI_SUCCESS) {
127 efi_st_error("Failed to close event\n");
128 return EFI_ST_FAILURE;
132 return EFI_ST_SUCCESS;
135 EFI_UNIT_TEST(eventgoups) = {
136 .name = "event groups",
137 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,