Commit e67e7249c8000d72b4c4b985fdeb3e103d65aa9e
Committed by
Alexander Graf
1 parent
e190e8972f
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
efi_selftest: make tests easier to read
Rename counter to more illustrative names. Update notification function description. Simplify notification function. Add comment for arbitrary non-zero value. Document @return. Use constants for return values of setup, execute, teardown. Reported-by: Simon Glass <sjg@chromium.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
Showing 5 changed files with 129 additions and 100 deletions Side-by-side Diff
include/efi_selftest.h
lib/efi_selftest/efi_selftest.c
... | ... | @@ -66,16 +66,17 @@ |
66 | 66 | * |
67 | 67 | * @test the test to be executed |
68 | 68 | * @failures counter that will be incremented if a failure occurs |
69 | + * @return EFI_ST_SUCCESS for success | |
69 | 70 | */ |
70 | 71 | static int setup(struct efi_unit_test *test, unsigned int *failures) |
71 | 72 | { |
72 | 73 | int ret; |
73 | 74 | |
74 | 75 | if (!test->setup) |
75 | - return 0; | |
76 | + return EFI_ST_SUCCESS; | |
76 | 77 | efi_st_printf("\nSetting up '%s'\n", test->name); |
77 | 78 | ret = test->setup(handle, systable); |
78 | - if (ret) { | |
79 | + if (ret != EFI_ST_SUCCESS) { | |
79 | 80 | efi_st_error("Setting up '%s' failed\n", test->name); |
80 | 81 | ++*failures; |
81 | 82 | } else { |
82 | 83 | |
83 | 84 | |
... | ... | @@ -89,16 +90,17 @@ |
89 | 90 | * |
90 | 91 | * @test the test to be executed |
91 | 92 | * @failures counter that will be incremented if a failure occurs |
93 | + * @return EFI_ST_SUCCESS for success | |
92 | 94 | */ |
93 | 95 | static int execute(struct efi_unit_test *test, unsigned int *failures) |
94 | 96 | { |
95 | 97 | int ret; |
96 | 98 | |
97 | 99 | if (!test->execute) |
98 | - return 0; | |
100 | + return EFI_ST_SUCCESS; | |
99 | 101 | efi_st_printf("\nExecuting '%s'\n", test->name); |
100 | 102 | ret = test->execute(); |
101 | - if (ret) { | |
103 | + if (ret != EFI_ST_SUCCESS) { | |
102 | 104 | efi_st_error("Executing '%s' failed\n", test->name); |
103 | 105 | ++*failures; |
104 | 106 | } else { |
105 | 107 | |
106 | 108 | |
... | ... | @@ -112,16 +114,17 @@ |
112 | 114 | * |
113 | 115 | * @test the test to be torn down |
114 | 116 | * @failures counter that will be incremented if a failure occurs |
117 | + * @return EFI_ST_SUCCESS for success | |
115 | 118 | */ |
116 | 119 | static int teardown(struct efi_unit_test *test, unsigned int *failures) |
117 | 120 | { |
118 | 121 | int ret; |
119 | 122 | |
120 | 123 | if (!test->teardown) |
121 | - return 0; | |
124 | + return EFI_ST_SUCCESS; | |
122 | 125 | efi_st_printf("\nTearing down '%s'\n", test->name); |
123 | 126 | ret = test->teardown(); |
124 | - if (ret) { | |
127 | + if (ret != EFI_ST_SUCCESS) { | |
125 | 128 | efi_st_error("Tearing down '%s' failed\n", test->name); |
126 | 129 | ++*failures; |
127 | 130 | } else { |
lib/efi_selftest/efi_selftest_events.c
... | ... | @@ -14,20 +14,22 @@ |
14 | 14 | |
15 | 15 | static struct efi_event *event_notify; |
16 | 16 | static struct efi_event *event_wait; |
17 | -static unsigned int counter; | |
17 | +static unsigned int timer_ticks; | |
18 | 18 | static struct efi_boot_services *boottime; |
19 | 19 | |
20 | 20 | /* |
21 | - * Notification function, increments a counter. | |
21 | + * Notification function, increments the notfication count if parameter | |
22 | + * context is provided. | |
22 | 23 | * |
23 | 24 | * @event notified event |
24 | - * @context pointer to the counter | |
25 | + * @context pointer to the notification count | |
25 | 26 | */ |
26 | 27 | static void EFIAPI notify(struct efi_event *event, void *context) |
27 | 28 | { |
28 | - if (!context) | |
29 | - return; | |
30 | - ++*(unsigned int *)context; | |
29 | + unsigned int *count = context; | |
30 | + | |
31 | + if (count) | |
32 | + ++*count; | |
31 | 33 | } |
32 | 34 | |
33 | 35 | /* |
... | ... | @@ -38,6 +40,7 @@ |
38 | 40 | * |
39 | 41 | * @handle: handle of the loaded image |
40 | 42 | * @systable: system table |
43 | + * @return: EFI_ST_SUCCESS for success | |
41 | 44 | */ |
42 | 45 | static int setup(const efi_handle_t handle, |
43 | 46 | const struct efi_system_table *systable) |
44 | 47 | |
45 | 48 | |
46 | 49 | |
47 | 50 | |
... | ... | @@ -47,25 +50,27 @@ |
47 | 50 | boottime = systable->boottime; |
48 | 51 | |
49 | 52 | ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, |
50 | - TPL_CALLBACK, notify, (void *)&counter, | |
53 | + TPL_CALLBACK, notify, (void *)&timer_ticks, | |
51 | 54 | &event_notify); |
52 | 55 | if (ret != EFI_SUCCESS) { |
53 | 56 | efi_st_error("could not create event\n"); |
54 | - return 1; | |
57 | + return EFI_ST_FAILURE; | |
55 | 58 | } |
56 | 59 | ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT, |
57 | 60 | TPL_CALLBACK, notify, NULL, &event_wait); |
58 | 61 | if (ret != EFI_SUCCESS) { |
59 | 62 | efi_st_error("could not create event\n"); |
60 | - return 1; | |
63 | + return EFI_ST_FAILURE; | |
61 | 64 | } |
62 | - return 0; | |
65 | + return EFI_ST_SUCCESS; | |
63 | 66 | } |
64 | 67 | |
65 | 68 | /* |
66 | 69 | * Tear down unit test. |
67 | 70 | * |
68 | 71 | * Close the events created in setup. |
72 | + * | |
73 | + * @return: EFI_ST_SUCCESS for success | |
69 | 74 | */ |
70 | 75 | static int teardown(void) |
71 | 76 | { |
... | ... | @@ -76,7 +81,7 @@ |
76 | 81 | event_notify = NULL; |
77 | 82 | if (ret != EFI_SUCCESS) { |
78 | 83 | efi_st_error("could not close event\n"); |
79 | - return 1; | |
84 | + return EFI_ST_FAILURE; | |
80 | 85 | } |
81 | 86 | } |
82 | 87 | if (event_wait) { |
83 | 88 | |
... | ... | @@ -84,10 +89,10 @@ |
84 | 89 | event_wait = NULL; |
85 | 90 | if (ret != EFI_SUCCESS) { |
86 | 91 | efi_st_error("could not close event\n"); |
87 | - return 1; | |
92 | + return EFI_ST_FAILURE; | |
88 | 93 | } |
89 | 94 | } |
90 | - return 0; | |
95 | + return EFI_ST_SUCCESS; | |
91 | 96 | } |
92 | 97 | |
93 | 98 | /* |
... | ... | @@ -98,6 +103,8 @@ |
98 | 103 | * |
99 | 104 | * Run a 100 ms single shot timer and check that it is called once |
100 | 105 | * while waiting for 100 ms periodic timer for two periods. |
106 | + * | |
107 | + * @return: EFI_ST_SUCCESS for success | |
101 | 108 | */ |
102 | 109 | static int execute(void) |
103 | 110 | { |
104 | 111 | |
105 | 112 | |
106 | 113 | |
107 | 114 | |
108 | 115 | |
109 | 116 | |
110 | 117 | |
111 | 118 | |
112 | 119 | |
113 | 120 | |
114 | 121 | |
115 | 122 | |
116 | 123 | |
117 | 124 | |
118 | 125 | |
119 | 126 | |
120 | 127 | |
121 | 128 | |
122 | 129 | |
123 | 130 | |
... | ... | @@ -105,85 +112,86 @@ |
105 | 112 | efi_status_t ret; |
106 | 113 | |
107 | 114 | /* Set 10 ms timer */ |
108 | - counter = 0; | |
115 | + timer_ticks = 0; | |
109 | 116 | ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000); |
110 | 117 | if (ret != EFI_SUCCESS) { |
111 | 118 | efi_st_error("Could not set timer\n"); |
112 | - return 1; | |
119 | + return EFI_ST_FAILURE; | |
113 | 120 | } |
114 | 121 | /* Set 100 ms timer */ |
115 | 122 | ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000); |
116 | 123 | if (ret != EFI_SUCCESS) { |
117 | 124 | efi_st_error("Could not set timer\n"); |
118 | - return 1; | |
125 | + return EFI_ST_FAILURE; | |
119 | 126 | } |
120 | 127 | |
128 | + /* Set some arbitrary non-zero value to make change detectable. */ | |
121 | 129 | index = 5; |
122 | 130 | ret = boottime->wait_for_event(1, &event_wait, &index); |
123 | 131 | if (ret != EFI_SUCCESS) { |
124 | 132 | efi_st_error("Could not wait for event\n"); |
125 | - return 1; | |
133 | + return EFI_ST_FAILURE; | |
126 | 134 | } |
127 | 135 | ret = boottime->check_event(event_wait); |
128 | 136 | if (ret != EFI_NOT_READY) { |
129 | 137 | efi_st_error("Signaled state was not cleared.\n"); |
130 | 138 | efi_st_printf("ret = %u\n", (unsigned int)ret); |
131 | - return 1; | |
139 | + return EFI_ST_FAILURE; | |
132 | 140 | } |
133 | 141 | if (index != 0) { |
134 | 142 | efi_st_error("WaitForEvent returned wrong index\n"); |
135 | - return 1; | |
143 | + return EFI_ST_FAILURE; | |
136 | 144 | } |
137 | - efi_st_printf("Counter periodic: %u\n", counter); | |
138 | - if (counter < 8 || counter > 12) { | |
145 | + efi_st_printf("Notification count periodic: %u\n", timer_ticks); | |
146 | + if (timer_ticks < 8 || timer_ticks > 12) { | |
139 | 147 | efi_st_error("Incorrect timing of events\n"); |
140 | - return 1; | |
148 | + return EFI_ST_FAILURE; | |
141 | 149 | } |
142 | 150 | ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0); |
143 | 151 | if (index != 0) { |
144 | 152 | efi_st_error("Could not cancel timer\n"); |
145 | - return 1; | |
153 | + return EFI_ST_FAILURE; | |
146 | 154 | } |
147 | 155 | /* Set 10 ms timer */ |
148 | - counter = 0; | |
156 | + timer_ticks = 0; | |
149 | 157 | ret = boottime->set_timer(event_notify, EFI_TIMER_RELATIVE, 100000); |
150 | 158 | if (index != 0) { |
151 | 159 | efi_st_error("Could not set timer\n"); |
152 | - return 1; | |
160 | + return EFI_ST_FAILURE; | |
153 | 161 | } |
154 | 162 | /* Set 100 ms timer */ |
155 | 163 | ret = boottime->set_timer(event_wait, EFI_TIMER_PERIODIC, 1000000); |
156 | 164 | if (index != 0) { |
157 | 165 | efi_st_error("Could not set timer\n"); |
158 | - return 1; | |
166 | + return EFI_ST_FAILURE; | |
159 | 167 | } |
160 | 168 | ret = boottime->wait_for_event(1, &event_wait, &index); |
161 | 169 | if (ret != EFI_SUCCESS) { |
162 | 170 | efi_st_error("Could not wait for event\n"); |
163 | - return 1; | |
171 | + return EFI_ST_FAILURE; | |
164 | 172 | } |
165 | - efi_st_printf("Counter single shot: %u\n", counter); | |
166 | - if (counter != 1) { | |
173 | + efi_st_printf("Notification count single shot: %u\n", timer_ticks); | |
174 | + if (timer_ticks != 1) { | |
167 | 175 | efi_st_error("Single shot timer failed\n"); |
168 | - return 1; | |
176 | + return EFI_ST_FAILURE; | |
169 | 177 | } |
170 | 178 | ret = boottime->wait_for_event(1, &event_wait, &index); |
171 | 179 | if (ret != EFI_SUCCESS) { |
172 | 180 | efi_st_error("Could not wait for event\n"); |
173 | - return 1; | |
181 | + return EFI_ST_FAILURE; | |
174 | 182 | } |
175 | - efi_st_printf("Stopped counter: %u\n", counter); | |
176 | - if (counter != 1) { | |
183 | + efi_st_printf("Notification count stopped timer: %u\n", timer_ticks); | |
184 | + if (timer_ticks != 1) { | |
177 | 185 | efi_st_error("Stopped timer fired\n"); |
178 | - return 1; | |
186 | + return EFI_ST_FAILURE; | |
179 | 187 | } |
180 | 188 | ret = boottime->set_timer(event_wait, EFI_TIMER_STOP, 0); |
181 | 189 | if (index != 0) { |
182 | 190 | efi_st_error("Could not cancel timer\n"); |
183 | - return 1; | |
191 | + return EFI_ST_FAILURE; | |
184 | 192 | } |
185 | 193 | |
186 | - return 0; | |
194 | + return EFI_ST_SUCCESS; | |
187 | 195 | } |
188 | 196 | |
189 | 197 | EFI_UNIT_TEST(events) = { |
lib/efi_selftest/efi_selftest_exitbootservices.c
1 | 1 | /* |
2 | - * efi_selftest_events | |
2 | + * efi_selftest_exitbootservices | |
3 | 3 | * |
4 | 4 | * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> |
5 | 5 | * |
6 | 6 | |
7 | 7 | |
8 | 8 | |
... | ... | @@ -13,19 +13,19 @@ |
13 | 13 | |
14 | 14 | static struct efi_boot_services *boottime; |
15 | 15 | static struct efi_event *event_notify; |
16 | -static unsigned int counter; | |
16 | +static unsigned int notification_count; | |
17 | 17 | |
18 | 18 | /* |
19 | - * Notification function, increments a counter. | |
19 | + * Notification function, increments the notification count. | |
20 | 20 | * |
21 | 21 | * @event notified event |
22 | - * @context pointer to the counter | |
22 | + * @context pointer to the notification count | |
23 | 23 | */ |
24 | 24 | static void EFIAPI notify(struct efi_event *event, void *context) |
25 | 25 | { |
26 | - if (!context) | |
27 | - return; | |
28 | - ++*(unsigned int *)context; | |
26 | + unsigned int *count = context; | |
27 | + | |
28 | + ++*count; | |
29 | 29 | } |
30 | 30 | |
31 | 31 | /* |
... | ... | @@ -35,6 +35,7 @@ |
35 | 35 | * |
36 | 36 | * @handle: handle of the loaded image |
37 | 37 | * @systable: system table |
38 | + * @return: EFI_ST_SUCCESS for success | |
38 | 39 | */ |
39 | 40 | static int setup(const efi_handle_t handle, |
40 | 41 | const struct efi_system_table *systable) |
41 | 42 | |
42 | 43 | |
43 | 44 | |
44 | 45 | |
... | ... | @@ -43,21 +44,24 @@ |
43 | 44 | |
44 | 45 | boottime = systable->boottime; |
45 | 46 | |
46 | - counter = 0; | |
47 | + notification_count = 0; | |
47 | 48 | ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES, |
48 | - TPL_CALLBACK, notify, (void *)&counter, | |
49 | + TPL_CALLBACK, notify, | |
50 | + (void *)¬ification_count, | |
49 | 51 | &event_notify); |
50 | 52 | if (ret != EFI_SUCCESS) { |
51 | 53 | efi_st_error("could not create event\n"); |
52 | - return 1; | |
54 | + return EFI_ST_FAILURE; | |
53 | 55 | } |
54 | - return 0; | |
56 | + return EFI_ST_SUCCESS; | |
55 | 57 | } |
56 | 58 | |
57 | 59 | /* |
58 | 60 | * Tear down unit test. |
59 | 61 | * |
60 | 62 | * Close the event created in setup. |
63 | + * | |
64 | + * @return: EFI_ST_SUCCESS for success | |
61 | 65 | */ |
62 | 66 | static int teardown(void) |
63 | 67 | { |
64 | 68 | |
... | ... | @@ -68,10 +72,10 @@ |
68 | 72 | event_notify = NULL; |
69 | 73 | if (ret != EFI_SUCCESS) { |
70 | 74 | efi_st_error("could not close event\n"); |
71 | - return 1; | |
75 | + return EFI_ST_FAILURE; | |
72 | 76 | } |
73 | 77 | } |
74 | - return 0; | |
78 | + return EFI_ST_SUCCESS; | |
75 | 79 | } |
76 | 80 | |
77 | 81 | /* |
78 | 82 | |
79 | 83 | |
80 | 84 | |
... | ... | @@ -82,19 +86,21 @@ |
82 | 86 | * |
83 | 87 | * Call ExitBootServices again and check that the notification function is |
84 | 88 | * not called again. |
89 | + * | |
90 | + * @return: EFI_ST_SUCCESS for success | |
85 | 91 | */ |
86 | 92 | static int execute(void) |
87 | 93 | { |
88 | - if (counter != 1) { | |
89 | - efi_st_error("ExitBootServices was not notified"); | |
90 | - return 1; | |
94 | + if (notification_count != 1) { | |
95 | + efi_st_error("ExitBootServices was not notified\n"); | |
96 | + return EFI_ST_FAILURE; | |
91 | 97 | } |
92 | 98 | efi_st_exit_boot_services(); |
93 | - if (counter != 1) { | |
94 | - efi_st_error("ExitBootServices was notified twice"); | |
95 | - return 1; | |
99 | + if (notification_count != 1) { | |
100 | + efi_st_error("ExitBootServices was notified twice\n"); | |
101 | + return EFI_ST_FAILURE; | |
96 | 102 | } |
97 | - return 0; | |
103 | + return EFI_ST_SUCCESS; | |
98 | 104 | } |
99 | 105 | |
100 | 106 | EFI_UNIT_TEST(exitbootservices) = { |
lib/efi_selftest/efi_selftest_tpl.c
... | ... | @@ -13,20 +13,20 @@ |
13 | 13 | |
14 | 14 | static struct efi_event *event_notify; |
15 | 15 | static struct efi_event *event_wait; |
16 | -static unsigned int counter; | |
16 | +static unsigned int notification_count; | |
17 | 17 | static struct efi_boot_services *boottime; |
18 | 18 | |
19 | 19 | /* |
20 | - * Notification function, increments a counter. | |
20 | + * Notification function, increments the notification count. | |
21 | 21 | * |
22 | 22 | * @event notified event |
23 | - * @context pointer to the counter | |
23 | + * @context pointer to the notification count | |
24 | 24 | */ |
25 | 25 | static void EFIAPI notify(struct efi_event *event, void *context) |
26 | 26 | { |
27 | - if (!context) | |
28 | - return; | |
29 | - ++*(unsigned int *)context; | |
27 | + unsigned int *count = context; | |
28 | + | |
29 | + ++*count; | |
30 | 30 | } |
31 | 31 | |
32 | 32 | /* |
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | * |
38 | 38 | * @handle: handle of the loaded image |
39 | 39 | * @systable: system table |
40 | + * @return: EFI_ST_SUCCESS for success | |
40 | 41 | */ |
41 | 42 | static int setup(const efi_handle_t handle, |
42 | 43 | const struct efi_system_table *systable) |
43 | 44 | |
44 | 45 | |
45 | 46 | |
46 | 47 | |
... | ... | @@ -46,25 +47,28 @@ |
46 | 47 | boottime = systable->boottime; |
47 | 48 | |
48 | 49 | ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, |
49 | - TPL_CALLBACK, notify, (void *)&counter, | |
50 | + TPL_CALLBACK, notify, | |
51 | + (void *)¬ification_count, | |
50 | 52 | &event_notify); |
51 | 53 | if (ret != EFI_SUCCESS) { |
52 | 54 | efi_st_error("could not create event\n"); |
53 | - return 1; | |
55 | + return EFI_ST_FAILURE; | |
54 | 56 | } |
55 | 57 | ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT, |
56 | 58 | TPL_HIGH_LEVEL, notify, NULL, &event_wait); |
57 | 59 | if (ret != EFI_SUCCESS) { |
58 | 60 | efi_st_error("could not create event\n"); |
59 | - return 1; | |
61 | + return EFI_ST_FAILURE; | |
60 | 62 | } |
61 | - return 0; | |
63 | + return EFI_ST_SUCCESS; | |
62 | 64 | } |
63 | 65 | |
64 | 66 | /* |
65 | 67 | * Tear down unit test. |
66 | 68 | * |
67 | 69 | * Close the events created in setup. |
70 | + * | |
71 | + * @return: EFI_ST_SUCCESS for success | |
68 | 72 | */ |
69 | 73 | static int teardown(void) |
70 | 74 | { |
... | ... | @@ -75,7 +79,7 @@ |
75 | 79 | event_notify = NULL; |
76 | 80 | if (ret != EFI_SUCCESS) { |
77 | 81 | efi_st_error("could not close event\n"); |
78 | - return 1; | |
82 | + return EFI_ST_FAILURE; | |
79 | 83 | } |
80 | 84 | } |
81 | 85 | if (event_wait) { |
82 | 86 | |
... | ... | @@ -83,11 +87,11 @@ |
83 | 87 | event_wait = NULL; |
84 | 88 | if (ret != EFI_SUCCESS) { |
85 | 89 | efi_st_error("could not close event\n"); |
86 | - return 1; | |
90 | + return EFI_ST_FAILURE; | |
87 | 91 | } |
88 | 92 | } |
89 | 93 | boottime->restore_tpl(TPL_APPLICATION); |
90 | - return 0; | |
94 | + return EFI_ST_SUCCESS; | |
91 | 95 | } |
92 | 96 | |
93 | 97 | /* |
... | ... | @@ -101,6 +105,8 @@ |
101 | 105 | * |
102 | 106 | * Lower the TPL level and check that the queued notification |
103 | 107 | * function is called. |
108 | + * | |
109 | + * @return: EFI_ST_SUCCESS for success | |
104 | 110 | */ |
105 | 111 | static int execute(void) |
106 | 112 | { |
107 | 113 | |
108 | 114 | |
109 | 115 | |
110 | 116 | |
111 | 117 | |
112 | 118 | |
113 | 119 | |
114 | 120 | |
115 | 121 | |
116 | 122 | |
117 | 123 | |
118 | 124 | |
119 | 125 | |
120 | 126 | |
121 | 127 | |
122 | 128 | |
123 | 129 | |
124 | 130 | |
125 | 131 | |
126 | 132 | |
127 | 133 | |
... | ... | @@ -109,100 +115,103 @@ |
109 | 115 | UINTN old_tpl; |
110 | 116 | |
111 | 117 | /* Set 10 ms timer */ |
112 | - counter = 0; | |
118 | + notification_count = 0; | |
113 | 119 | ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000); |
114 | 120 | if (ret != EFI_SUCCESS) { |
115 | 121 | efi_st_error("Could not set timer\n"); |
116 | - return 1; | |
122 | + return EFI_ST_FAILURE; | |
117 | 123 | } |
118 | 124 | /* Set 100 ms timer */ |
119 | 125 | ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000); |
120 | 126 | if (ret != EFI_SUCCESS) { |
121 | 127 | efi_st_error("Could not set timer\n"); |
122 | - return 1; | |
128 | + return EFI_ST_FAILURE; | |
123 | 129 | } |
124 | 130 | index = 5; |
125 | 131 | ret = boottime->wait_for_event(1, &event_wait, &index); |
126 | 132 | if (ret != EFI_SUCCESS) { |
127 | 133 | efi_st_error("Could not wait for event\n"); |
128 | - return 1; | |
134 | + return EFI_ST_FAILURE; | |
129 | 135 | } |
130 | 136 | ret = boottime->check_event(event_wait); |
131 | 137 | if (ret != EFI_NOT_READY) { |
132 | 138 | efi_st_error("Signaled state was not cleared.\n"); |
133 | 139 | efi_st_printf("ret = %u\n", (unsigned int)ret); |
134 | - return 1; | |
140 | + return EFI_ST_FAILURE; | |
135 | 141 | } |
136 | 142 | if (index != 0) { |
137 | 143 | efi_st_error("WaitForEvent returned wrong index\n"); |
138 | - return 1; | |
144 | + return EFI_ST_FAILURE; | |
139 | 145 | } |
140 | - efi_st_printf("Counter with TPL level TPL_APPLICATION: %u\n", counter); | |
141 | - if (counter < 8 || counter > 12) { | |
146 | + efi_st_printf("Notification count with TPL level TPL_APPLICATION: %u\n", | |
147 | + notification_count); | |
148 | + if (notification_count < 8 || notification_count > 12) { | |
142 | 149 | efi_st_error("Incorrect timing of events\n"); |
143 | - return 1; | |
150 | + return EFI_ST_FAILURE; | |
144 | 151 | } |
145 | 152 | ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0); |
146 | 153 | if (index != 0) { |
147 | 154 | efi_st_error("Could not cancel timer\n"); |
148 | - return 1; | |
155 | + return EFI_ST_FAILURE; | |
149 | 156 | } |
150 | 157 | /* Raise TPL level */ |
151 | 158 | old_tpl = boottime->raise_tpl(TPL_CALLBACK); |
152 | 159 | if (old_tpl != TPL_APPLICATION) { |
153 | 160 | efi_st_error("Initial TPL level was not TPL_APPLICATION"); |
154 | - return 1; | |
161 | + return EFI_ST_FAILURE; | |
155 | 162 | } |
156 | 163 | /* Set 10 ms timer */ |
157 | - counter = 0; | |
164 | + notification_count = 0; | |
158 | 165 | ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000); |
159 | 166 | if (index != 0) { |
160 | 167 | efi_st_error("Could not set timer\n"); |
161 | - return 1; | |
168 | + return EFI_ST_FAILURE; | |
162 | 169 | } |
163 | 170 | /* Set 100 ms timer */ |
164 | 171 | ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000); |
165 | 172 | if (ret != EFI_SUCCESS) { |
166 | 173 | efi_st_error("Could not set timer\n"); |
167 | - return 1; | |
174 | + return EFI_ST_FAILURE; | |
168 | 175 | } |
169 | 176 | do { |
170 | 177 | ret = boottime->check_event(event_wait); |
171 | 178 | } while (ret == EFI_NOT_READY); |
172 | 179 | if (ret != EFI_SUCCESS) { |
173 | 180 | efi_st_error("Could not check event\n"); |
174 | - return 1; | |
181 | + return EFI_ST_FAILURE; | |
175 | 182 | } |
176 | - efi_st_printf("Counter with TPL level TPL_CALLBACK: %u\n", counter); | |
177 | - if (counter != 0) { | |
183 | + efi_st_printf("Notification count with TPL level TPL_CALLBACK: %u\n", | |
184 | + notification_count); | |
185 | + if (notification_count != 0) { | |
178 | 186 | efi_st_error("Suppressed timer fired\n"); |
179 | - return 1; | |
187 | + return EFI_ST_FAILURE; | |
180 | 188 | } |
181 | 189 | /* Set 1 ms timer */ |
182 | 190 | ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000); |
183 | 191 | if (ret != EFI_SUCCESS) { |
184 | 192 | efi_st_error("Could not set timer\n"); |
185 | - return 1; | |
193 | + return EFI_ST_FAILURE; | |
186 | 194 | } |
187 | 195 | /* Restore the old TPL level */ |
188 | 196 | boottime->restore_tpl(TPL_APPLICATION); |
189 | 197 | ret = boottime->wait_for_event(1, &event_wait, &index); |
190 | 198 | if (ret != EFI_SUCCESS) { |
191 | 199 | efi_st_error("Could not wait for event\n"); |
192 | - return 1; | |
200 | + return EFI_ST_FAILURE; | |
193 | 201 | } |
194 | - efi_st_printf("Counter with TPL level TPL_APPLICATION: %u\n", counter); | |
195 | - if (counter < 1) { | |
202 | + efi_st_printf("Notification count with TPL level TPL_APPLICATION: %u\n", | |
203 | + notification_count); | |
204 | + if (notification_count < 1) { | |
196 | 205 | efi_st_error("Queued timer event did not fire\n"); |
197 | - return 1; | |
206 | + return EFI_ST_FAILURE; | |
198 | 207 | } |
199 | 208 | ret = boottime->set_timer(event_wait, EFI_TIMER_STOP, 0); |
200 | 209 | if (index != 0) { |
201 | 210 | efi_st_error("Could not cancel timer\n"); |
202 | - return 1; | |
211 | + return EFI_ST_FAILURE; | |
203 | 212 | } |
204 | 213 | |
205 | - return 0; | |
214 | + return EFI_ST_SUCCESS; | |
206 | 215 | } |
207 | 216 | |
208 | 217 | EFI_UNIT_TEST(tpl) = { |