Commit 7bbae6f2938382567fd86521ad15412c27e882f7
Committed by
Alexander Graf
1 parent
b57f48a87c
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
efi_selftest: test reboot by watchdog
A test is added that verifies that the watchdog timer actually causes a reboot upon timeout. The test is only executed on request using setenv efi_selftest watchdog reboot bootefi selftest Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Showing 1 changed file with 57 additions and 11 deletions Side-by-side Diff
lib/efi_selftest/efi_selftest_watchdog.c
... | ... | @@ -5,11 +5,16 @@ |
5 | 5 | * |
6 | 6 | * SPDX-License-Identifier: GPL-2.0+ |
7 | 7 | * |
8 | - * This unit test checks that the watchdog timer will not cause | |
9 | - * a system restart during the timeout period after a timer reset. | |
8 | + * The 'watchdog timer' unit test checks that the watchdog timer | |
9 | + * will not cause a system restart during the timeout period after | |
10 | + * a timer reset. | |
10 | 11 | * |
11 | - * Testing that the watchdog timer actually will reset the system | |
12 | - * after a timeout is not possible within the used framework. | |
12 | + * The 'watchdog reboot' unit test checks that the watchdog timer | |
13 | + * actually reboots the system after a timeout. The test is only | |
14 | + * executed on explicit request. Use the following commands: | |
15 | + * | |
16 | + * setenv efi_selftest watchdog reboot | |
17 | + * bootefi selftest | |
13 | 18 | */ |
14 | 19 | |
15 | 20 | #include <efi_selftest.h> |
... | ... | @@ -28,6 +33,7 @@ |
28 | 33 | static struct efi_event *event_wait; |
29 | 34 | static struct efi_boot_services *boottime; |
30 | 35 | static struct notify_context notification_context; |
36 | +static bool watchdog_reset; | |
31 | 37 | |
32 | 38 | /* |
33 | 39 | * Notification function, increments the notfication count if parameter |
... | ... | @@ -89,6 +95,34 @@ |
89 | 95 | } |
90 | 96 | |
91 | 97 | /* |
98 | + * Execute the test resetting the watchdog in a timely manner. No reboot occurs. | |
99 | + * | |
100 | + * @handle: handle of the loaded image | |
101 | + * @systable: system table | |
102 | + * @return: EFI_ST_SUCCESS for success | |
103 | + */ | |
104 | +static int setup_timer(const efi_handle_t handle, | |
105 | + const struct efi_system_table *systable) | |
106 | +{ | |
107 | + watchdog_reset = true; | |
108 | + return setup(handle, systable); | |
109 | +} | |
110 | + | |
111 | +/* | |
112 | + * Execute the test without resetting the watchdog. A system reboot occurs. | |
113 | + * | |
114 | + * @handle: handle of the loaded image | |
115 | + * @systable: system table | |
116 | + * @return: EFI_ST_SUCCESS for success | |
117 | + */ | |
118 | +static int setup_reboot(const efi_handle_t handle, | |
119 | + const struct efi_system_table *systable) | |
120 | +{ | |
121 | + watchdog_reset = false; | |
122 | + return setup(handle, systable); | |
123 | +} | |
124 | + | |
125 | +/* | |
92 | 126 | * Tear down unit test. |
93 | 127 | * |
94 | 128 | * Close the events created in setup. |
... | ... | @@ -146,11 +180,14 @@ |
146 | 180 | efi_st_error("Setting watchdog timer failed\n"); |
147 | 181 | return EFI_ST_FAILURE; |
148 | 182 | } |
149 | - /* Set 600 ms timer */ | |
150 | - ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 6000000); | |
151 | - if (ret != EFI_SUCCESS) { | |
152 | - efi_st_error("Could not set timer\n"); | |
153 | - return EFI_ST_FAILURE; | |
183 | + if (watchdog_reset) { | |
184 | + /* Set 600 ms timer */ | |
185 | + ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, | |
186 | + 6000000); | |
187 | + if (ret != EFI_SUCCESS) { | |
188 | + efi_st_error("Could not set timer\n"); | |
189 | + return EFI_ST_FAILURE; | |
190 | + } | |
154 | 191 | } |
155 | 192 | /* Set 1350 ms timer */ |
156 | 193 | ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 13500000); |
157 | 194 | |
158 | 195 | |
... | ... | @@ -176,11 +213,20 @@ |
176 | 213 | return EFI_ST_SUCCESS; |
177 | 214 | } |
178 | 215 | |
179 | -EFI_UNIT_TEST(watchdog) = { | |
216 | +EFI_UNIT_TEST(watchdog1) = { | |
180 | 217 | .name = "watchdog timer", |
181 | 218 | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
182 | - .setup = setup, | |
219 | + .setup = setup_timer, | |
183 | 220 | .execute = execute, |
184 | 221 | .teardown = teardown, |
222 | +}; | |
223 | + | |
224 | +EFI_UNIT_TEST(watchdog2) = { | |
225 | + .name = "watchdog reboot", | |
226 | + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, | |
227 | + .setup = setup_reboot, | |
228 | + .execute = execute, | |
229 | + .teardown = teardown, | |
230 | + .on_request = true, | |
185 | 231 | }; |