1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// SPDX-License-Identifier: GPL-2.0+
/*
* efi_selftest_event_groups
*
* Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
*
* This test checks the notification of group events and the
* following services:
* CreateEventEx, CloseEvent, SignalEvent, CheckEvent.
*/
#include <efi_selftest.h>
#define GROUP_SIZE 16
static struct efi_boot_services *boottime;
static efi_guid_t event_group =
EFI_GUID(0x2335905b, 0xc3b9, 0x4221, 0xa3, 0x71,
0x0e, 0x5b, 0x45, 0xc0, 0x56, 0x91);
/*
* Notification function, increments the notification count if parameter
* context is provided.
*
* @event notified event
* @context pointer to the notification count
*/
static void EFIAPI notify(struct efi_event *event, void *context)
{
unsigned int *count = context;
if (count)
++*count;
}
/*
* Setup unit test.
*
* @handle: handle of the loaded image
* @systable: system table
* Return: EFI_ST_SUCCESS for success
*/
static int setup(const efi_handle_t handle,
const struct efi_system_table *systable)
{
boottime = systable->boottime;
return EFI_ST_SUCCESS;
}
/*
* Execute unit test.
*
* Create multiple events in an event group. Signal each event once and check
* that all events are notified once in each round.
*
* Return: EFI_ST_SUCCESS for success
*/
static int execute(void)
{
unsigned int counter[GROUP_SIZE] = {0};
struct efi_event *events[GROUP_SIZE];
size_t i, j;
efi_status_t ret;
for (i = 0; i < GROUP_SIZE; ++i) {
ret = boottime->create_event_ex(0, TPL_NOTIFY,
notify, (void *)&counter[i],
&event_group, &events[i]);
if (ret != EFI_SUCCESS) {
efi_st_error("Failed to create event\n");
return EFI_ST_FAILURE;
}
}
for (i = 0; i < GROUP_SIZE; ++i) {
ret = boottime->signal_event(events[i]);
if (ret != EFI_SUCCESS) {
efi_st_error("Failed to signal event\n");
return EFI_ST_FAILURE;
}
for (j = 0; j < GROUP_SIZE; ++j) {
if (counter[j] != 2 * i + 1) {
efi_st_printf("i %u, j %u, count %u\n",
(unsigned int)i, (unsigned int)j,
(unsigned int)counter[j]);
efi_st_error("Notification function was not called\n");
return EFI_ST_FAILURE;
}
/* Clear signaled state */
ret = boottime->check_event(events[j]);
if (ret != EFI_SUCCESS) {
efi_st_error("Event was not signaled\n");
return EFI_ST_FAILURE;
}
if (counter[j] != 2 * i + 1) {
efi_st_printf("i %u, j %u, count %u\n",
(unsigned int)i, (unsigned int)j,
(unsigned int)counter[j]);
efi_st_error(
"Notification function was called\n");
return EFI_ST_FAILURE;
}
/* Call notification function */
ret = boottime->check_event(events[j]);
if (ret != EFI_NOT_READY) {
efi_st_error(
"Signaled state not cleared\n");
return EFI_ST_FAILURE;
}
if (counter[j] != 2 * i + 2) {
efi_st_printf("i %u, j %u, count %u\n",
(unsigned int)i, (unsigned int)j,
(unsigned int)counter[j]);
efi_st_error(
"Notification function not called\n");
return EFI_ST_FAILURE;
}
}
}
for (i = 0; i < GROUP_SIZE; ++i) {
ret = boottime->close_event(events[i]);
if (ret != EFI_SUCCESS) {
efi_st_error("Failed to close event\n");
return EFI_ST_FAILURE;
}
}
return EFI_ST_SUCCESS;
}
EFI_UNIT_TEST(eventgoups) = {
.name = "event groups",
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
.setup = setup,
.execute = execute,
};
|