blob: 14e0aa30324e7de37bc289337e673776267b0b1e [file] [log] [blame]
Shelley Chene109b1e2017-10-16 14:52:59 -07001/* Copyright 2017 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Tests detachable menu UI
6 */
7
8#include <stdint.h>
9#include <stdio.h>
10#include <stdlib.h>
11
Joel Kitchingde2cae62019-05-21 12:20:38 +080012#include "2common.h"
Shelley Chene109b1e2017-10-16 14:52:59 -070013#include "2misc.h"
14#include "2nvstorage.h"
Shelley Chene109b1e2017-10-16 14:52:59 -070015#include "host_common.h"
16#include "load_kernel_fw.h"
17#include "rollback_index.h"
18#include "test_common.h"
19#include "vboot_api.h"
20#include "vboot_audio.h"
21#include "vboot_common.h"
22#include "vboot_display.h"
23#include "vboot_kernel.h"
24#include "vboot_struct.h"
Julius Werner52fa8c12019-05-07 12:59:47 -070025#include "vboot_test.h"
Shelley Chene109b1e2017-10-16 14:52:59 -070026#include "vboot_ui_menu_private.h"
27
28/* Mock data */
Shelley Chene109b1e2017-10-16 14:52:59 -070029static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
30static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data;
Shelley Chene109b1e2017-10-16 14:52:59 -070031static LoadKernelParams lkp;
32static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
33static struct vb2_context ctx;
Randall Spangler51421322017-12-14 15:43:17 -080034static struct vb2_shared_data *sd;
Joel Kitchingde2cae62019-05-21 12:20:38 +080035static struct vb2_gbb_header gbb;
Shelley Chene109b1e2017-10-16 14:52:59 -070036
37static int shutdown_request_calls_left;
38static int audio_looping_calls_left;
Joel Kitching90671fa2019-07-31 13:17:08 +080039static vb2_error_t vbtlk_retval[5];
40static vb2_error_t vbtlk_last_retval;
Julius Wernerf41a5032018-01-30 18:20:03 -080041static int vbtlk_retval_count;
Joel Kitching90671fa2019-07-31 13:17:08 +080042static const vb2_error_t vbtlk_retval_fixed = 1002;
Shelley Chene109b1e2017-10-16 14:52:59 -070043static int vbexlegacy_called;
Matt Delco3bfaab12019-02-13 11:13:27 -080044static enum VbAltFwIndex_t altfw_num;
Julius Wernerf41a5032018-01-30 18:20:03 -080045static int debug_info_displayed;
Shelley Chene109b1e2017-10-16 14:52:59 -070046static int trust_ec;
47static int virtdev_set;
48static uint32_t virtdev_retval;
Julius Wernerf41a5032018-01-30 18:20:03 -080049static uint32_t mock_keypress[64];
50static uint32_t mock_keyflags[64];
Shelley Chene109b1e2017-10-16 14:52:59 -070051static uint32_t mock_keypress_count;
52static uint32_t mock_switches[8];
53static uint32_t mock_switches_count;
54static int mock_switches_are_stuck;
Julius Wernerf41a5032018-01-30 18:20:03 -080055static uint32_t screens_displayed[64];
Shelley Chene109b1e2017-10-16 14:52:59 -070056static uint32_t screens_count = 0;
Julius Wernerf41a5032018-01-30 18:20:03 -080057static uint32_t beeps_played[64];
58static uint32_t beeps_count = 0;
Simon Glassa0ae3182018-10-16 19:36:48 -060059static uint32_t mock_altfw_mask;
60static int vbexaltfwmask_called;
Shelley Chene109b1e2017-10-16 14:52:59 -070061
Shelley Chene109b1e2017-10-16 14:52:59 -070062/* Reset mock data (for use before each test) */
63static void ResetMocks(void)
64{
Shelley Chene109b1e2017-10-16 14:52:59 -070065 memset(VbApiKernelGetFwmp(), 0, sizeof(struct RollbackSpaceFwmp));
66
67 memset(&shared_data, 0, sizeof(shared_data));
68 VbSharedDataInit(shared, sizeof(shared_data));
Joel Kitchinge1761d62019-03-18 16:36:36 +080069 shared->flags = VBSD_BOOT_FIRMWARE_VBOOT2;
Shelley Chene109b1e2017-10-16 14:52:59 -070070
71 memset(&lkp, 0, sizeof(lkp));
72
73 memset(&ctx, 0, sizeof(ctx));
74 ctx.workbuf = workbuf;
75 ctx.workbuf_size = sizeof(workbuf);
76 vb2_init_context(&ctx);
77 vb2_nv_init(&ctx);
Randall Spangler79c1c612018-01-03 13:42:40 -080078
Randall Spangler51421322017-12-14 15:43:17 -080079 sd = vb2_get_sd(&ctx);
Randall Spangler79c1c612018-01-03 13:42:40 -080080 sd->vbsd = shared;
Shelley Chene109b1e2017-10-16 14:52:59 -070081
Joel Kitchingde2cae62019-05-21 12:20:38 +080082 memset(&gbb, 0, sizeof(gbb));
83
Julius Wernerf41a5032018-01-30 18:20:03 -080084 /* In recovery we have 50 keyscans per disk scan, this must be high. */
85 shutdown_request_calls_left = 301;
86 audio_looping_calls_left = 60;
Shelley Chene109b1e2017-10-16 14:52:59 -070087 vbexlegacy_called = 0;
Matt Delco3bfaab12019-02-13 11:13:27 -080088 altfw_num = -100;
Julius Wernerf41a5032018-01-30 18:20:03 -080089 debug_info_displayed = 0;
Shelley Chene109b1e2017-10-16 14:52:59 -070090 trust_ec = 0;
91 virtdev_set = 0;
92 virtdev_retval = 0;
93
Julius Wernerf41a5032018-01-30 18:20:03 -080094 vbtlk_last_retval = vbtlk_retval_fixed - VB_DISK_FLAG_FIXED;
95 memset(vbtlk_retval, 0, sizeof(vbtlk_retval));
96 vbtlk_retval_count = 0;
97
Shelley Chene109b1e2017-10-16 14:52:59 -070098 memset(screens_displayed, 0, sizeof(screens_displayed));
99 screens_count = 0;
Julius Wernerf41a5032018-01-30 18:20:03 -0800100 memset(beeps_played, 0, sizeof(beeps_played));
101 beeps_count = 0;
Shelley Chene109b1e2017-10-16 14:52:59 -0700102
103 memset(mock_keypress, 0, sizeof(mock_keypress));
104 memset(mock_keyflags, 0, sizeof(mock_keyflags));
105 mock_keypress_count = 0;
106
107 memset(mock_switches, 0, sizeof(mock_switches));
108 mock_switches_count = 0;
109 mock_switches_are_stuck = 0;
Simon Glassa0ae3182018-10-16 19:36:48 -0600110
111 mock_altfw_mask = 3 << 1; /* This mask selects 1 and 2 */
112 vbexaltfwmask_called = 0;
Julius Wernerf41a5032018-01-30 18:20:03 -0800113}
Shelley Chene109b1e2017-10-16 14:52:59 -0700114
Julius Wernerf41a5032018-01-30 18:20:03 -0800115static void ResetMocksForDeveloper(void)
116{
117 ResetMocks();
118 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
119 VbExEcEnteringMode(0, VB_EC_DEVELOPER);
120 shutdown_request_calls_left = -1;
121}
122
123static void ResetMocksForManualRecovery(void)
124{
125 ResetMocks();
126 shared->flags |= VBSD_BOOT_REC_SWITCH_ON;
127 trust_ec = 1;
128 VbExEcEnteringMode(0, VB_EC_RECOVERY);
Shelley Chene109b1e2017-10-16 14:52:59 -0700129}
130
131/* Mock functions */
Joel Kitchingd0dae802019-08-22 16:32:05 +0800132uint32_t RollbackKernelLock(int recovery_mode)
133{
134 return TPM_SUCCESS;
135}
136
Joel Kitchingde2cae62019-05-21 12:20:38 +0800137struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
138{
139 return &gbb;
140}
Shelley Chene109b1e2017-10-16 14:52:59 -0700141
Joel Kitching7ceb2ae2019-08-01 12:45:47 +0800142vb2_error_t VbExGetLocalizationCount(uint32_t *count) {
143 *count = 1;
144 return VB2_SUCCESS;
145}
146
Simon Glassa0ae3182018-10-16 19:36:48 -0600147uint32_t VbExGetAltFwIdxMask() {
148
149 vbexaltfwmask_called++;
150
151 return mock_altfw_mask;
152}
153
Shelley Chene109b1e2017-10-16 14:52:59 -0700154uint32_t VbExIsShutdownRequested(void)
155{
156 if (shutdown_request_calls_left == 0)
157 return 1;
158 else if (shutdown_request_calls_left > 0)
159 shutdown_request_calls_left--;
160
161 return 0;
162}
163
164uint32_t VbExKeyboardRead(void)
165{
166 return VbExKeyboardReadWithFlags(NULL);
167}
168
169uint32_t VbExKeyboardReadWithFlags(uint32_t *key_flags)
170{
171 if (mock_keypress_count < ARRAY_SIZE(mock_keypress)) {
172 if (key_flags != NULL)
173 *key_flags = mock_keyflags[mock_keypress_count];
174 return mock_keypress[mock_keypress_count++];
175 } else
176 return 0;
177}
178
179uint32_t VbExGetSwitches(uint32_t request_mask)
180{
181 if (mock_switches_are_stuck)
182 return mock_switches[0] & request_mask;
183 if (mock_switches_count < ARRAY_SIZE(mock_switches))
184 return mock_switches[mock_switches_count++] & request_mask;
185 else
186 return 0;
187}
188
Joel Kitchinge6700f42019-07-31 14:12:30 +0800189vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
Shelley Chene109b1e2017-10-16 14:52:59 -0700190{
191 vbexlegacy_called++;
Simon Glass89a51772018-04-08 23:26:57 -0400192 altfw_num = _altfw_num;
193
Shelley Chene109b1e2017-10-16 14:52:59 -0700194 return 0;
195}
196
Shelley Chene109b1e2017-10-16 14:52:59 -0700197int VbExTrustEC(int devidx)
198{
199 return trust_ec;
200}
201
Randall Spanglerde818cc2017-12-12 14:05:19 -0800202int vb2_audio_looping(void)
Shelley Chene109b1e2017-10-16 14:52:59 -0700203{
204 if (audio_looping_calls_left == 0)
205 return 0;
206 else if (audio_looping_calls_left > 0)
207 audio_looping_calls_left--;
208
209 return 1;
210}
211
Joel Kitching90671fa2019-07-31 13:17:08 +0800212vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
Shelley Chene109b1e2017-10-16 14:52:59 -0700213{
Julius Wernerf41a5032018-01-30 18:20:03 -0800214 if (vbtlk_retval_count < ARRAY_SIZE(vbtlk_retval) &&
215 vbtlk_retval[vbtlk_retval_count] != 0)
216 vbtlk_last_retval = vbtlk_retval[vbtlk_retval_count++];
217 return vbtlk_last_retval + get_info_flags;
Shelley Chene109b1e2017-10-16 14:52:59 -0700218}
219
Joel Kitching90671fa2019-07-31 13:17:08 +0800220vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force,
221 const VbScreenData *data)
Shelley Chene109b1e2017-10-16 14:52:59 -0700222{
223 if (screens_count < ARRAY_SIZE(screens_displayed))
224 screens_displayed[screens_count++] = screen;
225 printf("VbDisplayScreen: screens_displayed[%d] = 0x%x\n",
Julius Wernerf41a5032018-01-30 18:20:03 -0800226 screens_count - 1, screen);
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800227 return VB2_SUCCESS;
Shelley Chene109b1e2017-10-16 14:52:59 -0700228}
229
Joel Kitching90671fa2019-07-31 13:17:08 +0800230vb2_error_t VbDisplayMenu(struct vb2_context *c, uint32_t screen, int force,
231 uint32_t selected_index, uint32_t disabled_idx_mask)
Shelley Chene109b1e2017-10-16 14:52:59 -0700232{
233 if (screens_count < ARRAY_SIZE(screens_displayed))
234 screens_displayed[screens_count++] = screen;
235 else
236 printf("Ran out of screens_displayed entries!\n");
237 printf("VbDisplayMenu: screens_displayed[%d] = 0x%x,"
238 " selected_index = %u, disabled_idx_mask = 0x%x\n",
Julius Wernerf41a5032018-01-30 18:20:03 -0800239 screens_count - 1, screen,
Shelley Chene109b1e2017-10-16 14:52:59 -0700240 selected_index, disabled_idx_mask);
241
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800242 return VB2_SUCCESS;
Shelley Chene109b1e2017-10-16 14:52:59 -0700243}
244
Joel Kitching90671fa2019-07-31 13:17:08 +0800245vb2_error_t VbDisplayDebugInfo(struct vb2_context *c)
Julius Wernerf41a5032018-01-30 18:20:03 -0800246{
247 debug_info_displayed = 1;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800248 return VB2_SUCCESS;
Julius Wernerf41a5032018-01-30 18:20:03 -0800249}
250
Joel Kitching90671fa2019-07-31 13:17:08 +0800251vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
Julius Wernerf41a5032018-01-30 18:20:03 -0800252{
253 if (beeps_count < ARRAY_SIZE(beeps_played))
254 beeps_played[beeps_count++] = frequency;
255 printf("VbExBeep: beeps_played[%d] = %dHz for %dms\n",
256 beeps_count - 1, frequency, msec);
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800257 return VB2_SUCCESS;
Julius Wernerf41a5032018-01-30 18:20:03 -0800258}
259
Joel Kitchinge6700f42019-07-31 14:12:30 +0800260vb2_error_t SetVirtualDevMode(int val)
Shelley Chene109b1e2017-10-16 14:52:59 -0700261{
262 virtdev_set = val;
263 return virtdev_retval;
264}
265
266/* Tests */
267
Joel Kitchingefd0dc22019-05-29 16:25:05 +0800268/*
269 * VbBootNormal tests: Please see VbBootTest in vboot_api_kernel2_tests.c
270 */
Shelley Chene109b1e2017-10-16 14:52:59 -0700271
272static void VbBootDevTest(void)
273{
Julius Wernerf41a5032018-01-30 18:20:03 -0800274 int i;
275
Shelley Chene109b1e2017-10-16 14:52:59 -0700276 printf("Testing VbBootDeveloperMenu()...\n");
277
278 /* Proceed after timeout */
Julius Wernerf41a5032018-01-30 18:20:03 -0800279 ResetMocksForDeveloper();
280 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Timeout");
Shelley Chene109b1e2017-10-16 14:52:59 -0700281 TEST_EQ(VbGetMode(), VB_EC_DEVELOPER, "vboot_mode developer");
282 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
283 " warning screen");
Julius Wernerf41a5032018-01-30 18:20:03 -0800284 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
285 TEST_EQ(screens_count, 2, " no extra screens");
Shelley Chene109b1e2017-10-16 14:52:59 -0700286 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
287 " recovery reason");
Julius Wernerf41a5032018-01-30 18:20:03 -0800288 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -0700289 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
Julius Wernerf41a5032018-01-30 18:20:03 -0800290 TEST_EQ(beeps_count, 0, " no beeps on normal boot");
Shelley Chene109b1e2017-10-16 14:52:59 -0700291
292 /* Proceed to legacy after timeout if GBB flag set */
Julius Wernerf41a5032018-01-30 18:20:03 -0800293 ResetMocksForDeveloper();
Joel Kitchingde2cae62019-05-21 12:20:38 +0800294 gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY |
295 VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
Julius Wernerf41a5032018-01-30 18:20:03 -0800296 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
297 "default legacy GBB");
Shelley Chene109b1e2017-10-16 14:52:59 -0700298 TEST_EQ(vbexlegacy_called, 1, " try legacy");
Simon Glass89a51772018-04-08 23:26:57 -0400299 TEST_EQ(altfw_num, 0, " check altfw_num");
Julius Wernerf41a5032018-01-30 18:20:03 -0800300 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
301 " warning screen");
302 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
303 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
304 " warning screen");
305 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
306 TEST_EQ(screens_count, 4, " no extra screens");
307 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
308 TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
309 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700310
311 /* Proceed to legacy after timeout if boot legacy and default boot
312 * legacy are set */
Julius Wernerf41a5032018-01-30 18:20:03 -0800313 ResetMocksForDeveloper();
314 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_LEGACY);
Shelley Chene109b1e2017-10-16 14:52:59 -0700315 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
Julius Wernerf41a5032018-01-30 18:20:03 -0800316 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
317 "default legacy NV");
Shelley Chene109b1e2017-10-16 14:52:59 -0700318 TEST_EQ(vbexlegacy_called, 1, " try legacy");
Simon Glass89a51772018-04-08 23:26:57 -0400319 TEST_EQ(altfw_num, 0, " check altfw_num");
Julius Wernerf41a5032018-01-30 18:20:03 -0800320 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
321 " warning screen");
322 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
323 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
324 " warning screen");
325 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
326 TEST_EQ(screens_count, 4, " no extra screens");
327 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
328 TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
329 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700330
331 /* Proceed to legacy boot mode only if enabled */
Julius Wernerf41a5032018-01-30 18:20:03 -0800332 ResetMocksForDeveloper();
333 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_LEGACY);
334 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
335 "default legacy not enabled");
Shelley Chene109b1e2017-10-16 14:52:59 -0700336 TEST_EQ(vbexlegacy_called, 0, " not legacy");
Julius Wernerf41a5032018-01-30 18:20:03 -0800337 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
338 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
339 " warning screen");
340 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
341 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
342 " warning screen");
343 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
344 TEST_EQ(screens_count, 4, " no extra screens");
345 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
346 TEST_EQ(beeps_count, 2, " error beeps: legacy boot not enabled");
347 TEST_EQ(beeps_played[0], 400, " first error beep");
348 TEST_EQ(beeps_played[1], 400, " second error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700349
350 /* Proceed to usb after timeout if boot usb and default boot
351 * usb are set */
Julius Wernerf41a5032018-01-30 18:20:03 -0800352 ResetMocksForDeveloper();
353 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_USB);
Shelley Chene109b1e2017-10-16 14:52:59 -0700354 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800355 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Randall Spanglerb07b4b92018-01-04 17:58:01 -0800356 TEST_EQ(VbBootDeveloperMenu(&ctx), 0, "Ctrl+U USB");
Julius Wernerf41a5032018-01-30 18:20:03 -0800357 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
358 " warning screen");
359 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
360 TEST_EQ(screens_count, 2, " no extra screens");
361 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
362 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
Shelley Chene109b1e2017-10-16 14:52:59 -0700363
364 /* Proceed to usb boot mode only if enabled */
Julius Wernerf41a5032018-01-30 18:20:03 -0800365 ResetMocksForDeveloper();
366 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_USB);
367 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
368 "default USB not enabled");
369 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
370 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
371 " warning screen");
372 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
373 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
374 " warning screen");
375 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
376 TEST_EQ(screens_count, 4, " no extra screens");
377 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
378 TEST_EQ(beeps_count, 2, " error beeps: USB boot not enabled");
379 TEST_EQ(beeps_played[0], 400, " first error beep");
380 TEST_EQ(beeps_played[1], 400, " second error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700381
382 /* If no USB tries fixed disk */
Julius Wernerf41a5032018-01-30 18:20:03 -0800383 ResetMocksForDeveloper();
Shelley Chene109b1e2017-10-16 14:52:59 -0700384 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Julius Wernerf41a5032018-01-30 18:20:03 -0800385 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_USB);
386 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
387 "default USB with no disk");
Shelley Chene109b1e2017-10-16 14:52:59 -0700388 TEST_EQ(vbexlegacy_called, 0, " not legacy");
Julius Wernerf41a5032018-01-30 18:20:03 -0800389 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
390 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
391 " warning screen");
392 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
393 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
394 " warning screen");
395 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
396 TEST_EQ(screens_count, 4, " no extra screens");
397 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
398 TEST_EQ(beeps_count, 1, " error beep: USB not found");
399 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700400
401 /* Shutdown requested in loop */
Julius Wernerf41a5032018-01-30 18:20:03 -0800402 ResetMocksForDeveloper();
Shelley Chene109b1e2017-10-16 14:52:59 -0700403 shutdown_request_calls_left = 2;
Julius Wernerf41a5032018-01-30 18:20:03 -0800404 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Shelley Chene109b1e2017-10-16 14:52:59 -0700405 "Shutdown requested");
Julius Wernerf41a5032018-01-30 18:20:03 -0800406 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
407 TEST_EQ(debug_info_displayed, 0, " no debug info");
408 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
409 " warning screen");
410 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
411 TEST_EQ(screens_count, 2, " no extra screens");
Shelley Chene109b1e2017-10-16 14:52:59 -0700412 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
Julius Wernerf41a5032018-01-30 18:20:03 -0800413 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -0700414
Shelley Chene109b1e2017-10-16 14:52:59 -0700415 /*
416 * Pushing power should shut down the DUT because default
417 * selection is power off
418 */
Julius Wernerf41a5032018-01-30 18:20:03 -0800419 ResetMocksForDeveloper();
420 mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
421 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Shelley Chene109b1e2017-10-16 14:52:59 -0700422 "dev warning menu: default to power off");
Julius Wernerf41a5032018-01-30 18:20:03 -0800423 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
Shelley Chene109b1e2017-10-16 14:52:59 -0700424 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
425 " warning screen");
Julius Wernerf41a5032018-01-30 18:20:03 -0800426 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
427 TEST_EQ(screens_count, 2, " no extra screens");
428 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
429 TEST_EQ(beeps_count, 0, " no beep on shutdown");
430
431 /* Selecting Power Off in developer options. */
432 ResetMocksForDeveloper();
433 i = 0;
434 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
435 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
436 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
437 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
438 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
439 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
440 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
441 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
442 "Power Off in DEVELOPER");
443 TEST_EQ(debug_info_displayed, 0, " no debug info");
444 TEST_EQ(vbexlegacy_called, 0, " not legacy");
445 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
446 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
447 i = 0;
448 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
449 " dev warning menu: power off");
450 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
451 " dev warning menu: enable root verification");
452 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
453 " dev warning menu: show debug info");
454 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
455 " dev warning menu: developer options");
456 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
457 " dev menu: disk boot");
458 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
459 " dev menu: cancel");
460 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
461 " dev menu: power off");
462 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
463 TEST_EQ(screens_count, i, " no extra screens");
464 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
465
466 /* Pressing ENTER is equivalent to power button. */
467 ResetMocksForDeveloper();
Mathew Kingaf26dc12019-02-19 10:43:32 -0700468 mock_keypress[0] = VB_KEY_ENTER;
Julius Wernerf41a5032018-01-30 18:20:03 -0800469 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
470 "dev warning menu: ENTER is power button");
471 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
472 " warning screen");
473 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
474 TEST_EQ(screens_count, 2, " no extra screens");
475 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
476 TEST_EQ(beeps_count, 0, " no beep on shutdown");
477
478 /* ENTER functionality is unaffected by GBB flag in detachable UI. */
479 ResetMocksForDeveloper();
Joel Kitchingde2cae62019-05-21 12:20:38 +0800480 gbb.flags |= VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM;
Mathew Kingaf26dc12019-02-19 10:43:32 -0700481 mock_keypress[0] = VB_KEY_ENTER;
Julius Wernerf41a5032018-01-30 18:20:03 -0800482 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
483 "dev warning menu: ENTER unaffected by GBB");
484 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
485 " warning screen");
486 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
487 TEST_EQ(screens_count, 2, " no extra screens");
488 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
489 TEST_EQ(beeps_count, 0, " no beep on shutdown");
490
491 /* Pressing SPACE or VolUp+Down combo has no effect in dev mode */
492 ResetMocksForDeveloper();
493 mock_keypress[0] = ' ';
494 mock_keypress[1] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS;
495 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS; // select Power Off
496 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
497 "SPACE or VolUp+Down have no effect");
498 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
499 TEST_EQ(debug_info_displayed, 0, " no debug info");
500 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
501 " warning screen");
502 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
503 TEST_EQ(screens_count, 2, " no extra screens");
504 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
505 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -0700506
507 /* Disable developer mode */
Julius Wernerf41a5032018-01-30 18:20:03 -0800508 ResetMocksForDeveloper();
509 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
510 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
511 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
512 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
Randall Spanglerb07b4b92018-01-04 17:58:01 -0800513 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_REBOOT_REQUIRED,
Shelley Chene109b1e2017-10-16 14:52:59 -0700514 "disable developer mode");
Julius Wernerf41a5032018-01-30 18:20:03 -0800515 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
Shelley Chene109b1e2017-10-16 14:52:59 -0700516 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
517 " warning screen");
518 TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
519 " warning screen");
520 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
521 " tonorm screen");
Julius Wernerc76e7362018-01-25 17:41:09 -0800522 TEST_EQ(screens_displayed[3], VB_SCREEN_TO_NORM_CONFIRMED,
Shelley Chene109b1e2017-10-16 14:52:59 -0700523 " confirm screen");
Julius Wernerf41a5032018-01-30 18:20:03 -0800524 TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " final blank screen");
525 TEST_EQ(screens_count, 5, " no extra screens");
Shelley Chene109b1e2017-10-16 14:52:59 -0700526 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
527 " disable dev request");
Julius Wernerf41a5032018-01-30 18:20:03 -0800528 TEST_EQ(debug_info_displayed, 0, " no debug info");
529 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
530 TEST_EQ(beeps_count, 0, " no beep on reboot");
Shelley Chene109b1e2017-10-16 14:52:59 -0700531
532 /* Tonorm ignored if GBB forces dev switch on */
Julius Wernerf41a5032018-01-30 18:20:03 -0800533 ResetMocksForDeveloper();
534 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
Joel Kitchingde2cae62019-05-21 12:20:38 +0800535 gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON;
Julius Wernerf41a5032018-01-30 18:20:03 -0800536 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
537 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
538 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
539 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
Shelley Chene109b1e2017-10-16 14:52:59 -0700540 "Can't tonorm gbb-dev");
Julius Wernerf41a5032018-01-30 18:20:03 -0800541 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
Shelley Chene109b1e2017-10-16 14:52:59 -0700542 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
Julius Wernerc76e7362018-01-25 17:41:09 -0800543 " warning screen: power off");
Shelley Chene109b1e2017-10-16 14:52:59 -0700544 TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
Julius Wernerc76e7362018-01-25 17:41:09 -0800545 " wanring screen: enable verification");
Shelley Chene109b1e2017-10-16 14:52:59 -0700546 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
Julius Wernerc76e7362018-01-25 17:41:09 -0800547 " tonorm screen: confirm");
Julius Wernerf41a5032018-01-30 18:20:03 -0800548 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK,
549 " blank (error flash)");
550 TEST_EQ(screens_displayed[4], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
551 " tonorm screen: confirm");
552 TEST_EQ(screens_displayed[5], VB_SCREEN_BLANK, " final blank screen");
553 TEST_EQ(screens_count, 6, " no extra screens");
554 TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
555 TEST_EQ(beeps_count, 2, " played error beeps");
556 TEST_EQ(beeps_played[0], 400, " first beep");
557 TEST_EQ(beeps_played[1], 400, " second beep");
Shelley Chene109b1e2017-10-16 14:52:59 -0700558
559 /* Shutdown requested at tonorm screen */
Julius Wernerf41a5032018-01-30 18:20:03 -0800560 ResetMocksForDeveloper();
561 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
562 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
563 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
Shelley Chene109b1e2017-10-16 14:52:59 -0700564 shutdown_request_calls_left = 2;
Julius Wernerf41a5032018-01-30 18:20:03 -0800565 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Shelley Chene109b1e2017-10-16 14:52:59 -0700566 "Shutdown requested at tonorm");
Julius Wernerf41a5032018-01-30 18:20:03 -0800567 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
Shelley Chene109b1e2017-10-16 14:52:59 -0700568 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
569 " developer warning screen: power off");
570 TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
571 " developer warning screen: enable root verification");
572 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
573 " developer warning screen: power off");
Julius Wernerf41a5032018-01-30 18:20:03 -0800574 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
575 TEST_EQ(screens_count, 4, " no extra screens");
576 TEST_EQ(beeps_count, 0, " no beeps on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -0700577
578 /* Ctrl+D dismisses warning */
Julius Wernerf41a5032018-01-30 18:20:03 -0800579 ResetMocksForDeveloper();
Mathew Kingaf26dc12019-02-19 10:43:32 -0700580 mock_keypress[0] = VB_KEY_CTRL('D');
Julius Wernerf41a5032018-01-30 18:20:03 -0800581 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+D");
Shelley Chene109b1e2017-10-16 14:52:59 -0700582 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
583 " recovery reason");
584 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
585 TEST_EQ(vbexlegacy_called, 0, " not legacy");
Julius Wernerf41a5032018-01-30 18:20:03 -0800586 TEST_EQ(debug_info_displayed, 0, " no debug info");
587 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
588 " warning screen");
589 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
590 TEST_EQ(screens_count, 2, " no extra screens");
591 TEST_EQ(beeps_count, 0, " no beeps on normal boot");
Shelley Chene109b1e2017-10-16 14:52:59 -0700592
593 /* Ctrl+D doesn't boot legacy even if GBB flag is set */
Julius Wernerf41a5032018-01-30 18:20:03 -0800594 ResetMocksForDeveloper();
Mathew Kingaf26dc12019-02-19 10:43:32 -0700595 mock_keypress[0] = VB_KEY_CTRL('D');
Joel Kitchingde2cae62019-05-21 12:20:38 +0800596 gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY;
Julius Wernerf41a5032018-01-30 18:20:03 -0800597 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+D");
Shelley Chene109b1e2017-10-16 14:52:59 -0700598 TEST_EQ(vbexlegacy_called, 0, " not legacy");
599
Julius Wernerf41a5032018-01-30 18:20:03 -0800600 /* Volume-down long press shortcut acts like Ctrl+D */
601 ResetMocksForDeveloper();
602 mock_keypress[0] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
603 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
604 "VolDown long press");
Shelley Chene109b1e2017-10-16 14:52:59 -0700605 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
606 " recovery reason");
Julius Wernerf41a5032018-01-30 18:20:03 -0800607 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
608 TEST_EQ(vbexlegacy_called, 0, " not legacy");
609 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
610 " warning screen");
611 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
612 TEST_EQ(screens_count, 2, " no extra screens");
613 TEST_EQ(beeps_count, 0, " no beeps on normal boot");
Shelley Chene109b1e2017-10-16 14:52:59 -0700614
Julius Wernerf41a5032018-01-30 18:20:03 -0800615 /* Ctrl+L tries legacy boot mode only if enabled */
616 ResetMocksForDeveloper();
Mathew Kingaf26dc12019-02-19 10:43:32 -0700617 mock_keypress[0] = VB_KEY_CTRL('L');
Julius Wernerf41a5032018-01-30 18:20:03 -0800618 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+L normal");
619 TEST_EQ(vbexlegacy_called, 0, " not legacy");
620 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
621 TEST_EQ(debug_info_displayed, 0, " no debug info");
622 TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
623 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
624 " warning screen");
625 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
626 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
627 " warning screen");
628 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
629 TEST_EQ(screens_count, 4, " no extra screens");
630 TEST_EQ(beeps_count, 2, " played error beeps");
631 TEST_EQ(beeps_played[0], 400, " first beep");
632 TEST_EQ(beeps_played[1], 400, " second beep");
633
634 /* Ctrl+L boots legacy if enabled by GBB flag */
635 ResetMocksForDeveloper();
Joel Kitchingde2cae62019-05-21 12:20:38 +0800636 gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
Mathew Kingaf26dc12019-02-19 10:43:32 -0700637 mock_keypress[0] = VB_KEY_CTRL('L');
Simon Glassa0ae3182018-10-16 19:36:48 -0600638 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
Julius Wernerf41a5032018-01-30 18:20:03 -0800639 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
640 "Ctrl+L force legacy");
641 TEST_EQ(vbexlegacy_called, 1, " try legacy");
Simon Glassa0ae3182018-10-16 19:36:48 -0600642 TEST_EQ(altfw_num, 1, " check altfw_num");
Julius Wernerf41a5032018-01-30 18:20:03 -0800643 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
644 " warning screen");
Simon Glassa0ae3182018-10-16 19:36:48 -0600645 TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
646 TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
647 TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
648 TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " blank (error flash)");
649 TEST_EQ(screens_count, 5, " no extra screens");
Julius Wernerf41a5032018-01-30 18:20:03 -0800650 TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
651 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
652
653 /* Ctrl+L boots legacy if enabled by NVRAM */
654 ResetMocksForDeveloper();
655 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
Mathew Kingaf26dc12019-02-19 10:43:32 -0700656 mock_keypress[0] = VB_KEY_CTRL('L');
Simon Glassa0ae3182018-10-16 19:36:48 -0600657 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
Julius Wernerf41a5032018-01-30 18:20:03 -0800658 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
659 "Ctrl+L nv legacy");
660 TEST_EQ(vbexlegacy_called, 1, " try legacy");
661 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
662 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
663 " warning screen");
Simon Glassa0ae3182018-10-16 19:36:48 -0600664 TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
665 TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
666 TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
667 TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " blank (error flash)");
668 TEST_EQ(screens_count, 5, " no extra screens");
Julius Wernerf41a5032018-01-30 18:20:03 -0800669 TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
670 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
671
672 /* Ctrl+L boots legacy if enabled by FWMP */
673 ResetMocksForDeveloper();
674 VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY;
Mathew Kingaf26dc12019-02-19 10:43:32 -0700675 mock_keypress[0] = VB_KEY_CTRL('L');
Simon Glassa0ae3182018-10-16 19:36:48 -0600676 mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
Julius Wernerf41a5032018-01-30 18:20:03 -0800677 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
678 "Ctrl+L fwmp legacy");
679 TEST_EQ(vbexlegacy_called, 1, " fwmp legacy");
Simon Glassa0ae3182018-10-16 19:36:48 -0600680 TEST_EQ(altfw_num, 1, " check altfw_num");
Julius Wernerf41a5032018-01-30 18:20:03 -0800681 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
682 " warning screen");
Simon Glassa0ae3182018-10-16 19:36:48 -0600683 TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
684 TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
685 TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
686 TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " final blank screen");
687 TEST_EQ(screens_count, 5, " no extra screens");
Julius Wernerf41a5032018-01-30 18:20:03 -0800688 TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
689 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
690
Simon Glassa0ae3182018-10-16 19:36:48 -0600691 /* TODO(sjg@chromium.org): Add a test for there being no bootloaders */
692
Julius Wernerf41a5032018-01-30 18:20:03 -0800693 /* Ctrl+U boots USB only if enabled */
694 ResetMocksForDeveloper();
Mathew Kingaf26dc12019-02-19 10:43:32 -0700695 mock_keypress[0] = VB_KEY_CTRL('U');
Julius Wernerf41a5032018-01-30 18:20:03 -0800696 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
697 "Ctrl+U not enabled");
698 TEST_EQ(vbexlegacy_called, 0, " not legacy");
699 TEST_EQ(debug_info_displayed, 0, " no debug info");
700 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
701 TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
702 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
703 " warning screen");
704 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
705 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
706 " warning screen");
707 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
708 TEST_EQ(screens_count, 4, " no extra screens");
709 TEST_EQ(beeps_count, 2, " played error beeps");
710 TEST_EQ(beeps_played[0], 400, " first beep");
711 TEST_EQ(beeps_played[1], 400, " second beep");
712
713 /* Ctrl+U enabled, with good USB boot */
714 ResetMocksForDeveloper();
715 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Mathew Kingaf26dc12019-02-19 10:43:32 -0700716 mock_keypress[0] = VB_KEY_CTRL('U');
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800717 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
718 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS, "Ctrl+U USB");
Julius Wernerf41a5032018-01-30 18:20:03 -0800719 TEST_EQ(vbexlegacy_called, 0, " not legacy");
720 TEST_EQ(debug_info_displayed, 0, " no debug info");
721 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
722 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
723 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
724 " warning screen");
725 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
726 TEST_EQ(screens_count, 2, " no extra screens");
727 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
728
729 /* Ctrl+U enabled, without valid USB */
730 ResetMocksForDeveloper();
731 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Mathew Kingaf26dc12019-02-19 10:43:32 -0700732 mock_keypress[0] = VB_KEY_CTRL('U');
Julius Wernerf41a5032018-01-30 18:20:03 -0800733 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
734 "Ctrl+U without valid USB");
735 TEST_EQ(vbexlegacy_called, 0, " not legacy");
736 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
737 TEST_EQ(debug_info_displayed, 0, " no debug info");
738 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
739 " warning screen");
740 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
741 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
742 " warning screen");
743 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
744 TEST_EQ(screens_count, 4, " no extra screens");
745 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
746 TEST_EQ(beeps_count, 1, " error beep: USB not found");
747 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
748
749 /* Ctrl+U enabled via GBB */
750 ResetMocksForDeveloper();
Joel Kitchingde2cae62019-05-21 12:20:38 +0800751 gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_USB;
Mathew Kingaf26dc12019-02-19 10:43:32 -0700752 mock_keypress[0] = VB_KEY_CTRL('U');
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800753 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
754 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS, "Ctrl+U force USB");
Julius Wernerf41a5032018-01-30 18:20:03 -0800755 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
756 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
757 " warning screen");
758 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
759 TEST_EQ(screens_count, 2, " no extra screens");
760 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
761
762 /* Ctrl+U enabled via FWMP */
763 ResetMocksForDeveloper();
764 VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_USB;
Mathew Kingaf26dc12019-02-19 10:43:32 -0700765 mock_keypress[0] = VB_KEY_CTRL('U');
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800766 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
767 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS, "Ctrl+U force USB");
Julius Wernerf41a5032018-01-30 18:20:03 -0800768 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
769 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
770 " warning screen");
771 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
772 TEST_EQ(screens_count, 2, " no extra screens");
773 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
774
775 /* If no valid USB, eventually times out and tries fixed disk */
776 ResetMocksForDeveloper();
777 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Mathew Kingaf26dc12019-02-19 10:43:32 -0700778 mock_keypress[0] = VB_KEY_CTRL('U');
Julius Wernerf41a5032018-01-30 18:20:03 -0800779 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
780 "Ctrl+U failed - no USB");
781 TEST_EQ(vbexlegacy_called, 0, " not legacy");
782 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
783 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
784 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
785 " warning screen");
786 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
787 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
788 " warning screen");
789 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
790 TEST_EQ(screens_count, 4, " no extra screens");
791 TEST_EQ(beeps_count, 1, " error beep: USB not found");
792 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
793
794 /* Now go to USB boot through menus */
795 ResetMocksForDeveloper();
796 i = 0;
797 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
798 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
799 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
800 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
801 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
802 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
803 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800804 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
805 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -0800806 "Menu selected USB boot");
807 TEST_EQ(debug_info_displayed, 0, " no debug info");
808 TEST_EQ(vbexlegacy_called, 0, " not legacy");
809 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
810 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
811 i = 0;
812 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
813 " dev warning menu: power off");
814 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
815 " dev warning menu: enable root verification");
816 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
817 " dev warning menu: show debug info");
818 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
819 " dev warning menu: developer options");
820 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
821 " dev menu: disk boot");
822 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
823 " dev menu: USB boot");
824 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " final blank screen");
825 TEST_EQ(screens_count, i, " no extra screens");
826 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
827
828 /* If default USB, the option is preselected */
829 ResetMocksForDeveloper();
830 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_USB);
831 i = 0;
832 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
833 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
834 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
835 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
836 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
837 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
Joel Kitchingcf49e7b2019-07-29 18:51:00 +0800838 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
839 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -0800840 "Menu selected USB default boot");
841 TEST_EQ(vbexlegacy_called, 0, " not legacy");
842 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
843 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
844 i = 0;
845 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
846 " dev warning menu: power off");
847 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
848 " dev warning menu: enable root verification");
849 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
850 " dev warning menu: show debug info");
851 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
852 " dev warning menu: developer options");
853 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
854 " dev menu: USB boot");
855 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
856 TEST_EQ(screens_count, i, " no extra screens");
857 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
858
859 /* If invalid USB, we still timeout after selecting it in menu */
860 ResetMocksForDeveloper();
861 i = 0;
862 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
863 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
864 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
865 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
866 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
867 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
868 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
869 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
870 "Menu selected invalid USB boot");
871 TEST_EQ(vbexlegacy_called, 0, " not legacy");
872 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
873 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
874 i = 0;
875 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
876 " dev warning menu: power off");
877 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
878 " dev warning menu: enable root verification");
879 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
880 " dev warning menu: show debug info");
881 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
882 " dev warning menu: developer options");
883 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
884 " dev menu: disk boot");
885 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
886 " dev menu: USB boot");
887 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
888 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
889 " dev menu: USB boot");
890 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
891 TEST_EQ(screens_count, i, " no extra screens");
892 TEST_EQ(beeps_count, 1, " error beep: USB not found");
893 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
894
895 /* If USB is disabled, we error flash/beep from the menu option */
896 ResetMocksForDeveloper();
897 i = 0;
898 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
899 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
900 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
901 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
902 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
903 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
904 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
905 "Menu selected disabled USB boot");
906 TEST_EQ(vbexlegacy_called, 0, " not legacy");
907 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
908 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
909 i = 0;
910 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
911 " dev warning menu: power off");
912 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
913 " dev warning menu: enable root verification");
914 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
915 " dev warning menu: show debug info");
916 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
917 " dev warning menu: developer options");
918 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
919 " dev menu: disk boot");
920 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
921 " dev menu: USB boot");
922 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
923 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
924 " dev menu: USB boot");
925 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " final blank screen");
926 TEST_EQ(screens_count, i, " no extra screens");
927 TEST_EQ(beeps_count, 2, " played error beeps");
928 TEST_EQ(beeps_played[0], 400, " first beep");
929 TEST_EQ(beeps_played[1], 400, " second beep");
930
931 /* Boot Legacy via menu and default */
932 ResetMocksForDeveloper();
933 i = 0;
934 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
935 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
936 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
Simon Glassa0ae3182018-10-16 19:36:48 -0600937 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Enter altfw menu
938 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Select first option
939 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // and again
Julius Wernerf41a5032018-01-30 18:20:03 -0800940 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
941 vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, VB2_DEV_DEFAULT_BOOT_LEGACY);
942 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
943 "Menu selected legacy boot");
944 TEST_EQ(debug_info_displayed, 0, " no debug info");
945 TEST_EQ(vbexlegacy_called, 2, " tried legacy boot twice");
Simon Glass89a51772018-04-08 23:26:57 -0400946 TEST_EQ(altfw_num, 0, " check altfw_num");
Julius Wernerf41a5032018-01-30 18:20:03 -0800947 TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
948 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
949 i = 0;
950 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
951 " dev warning menu: power off");
952 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
953 " dev warning menu: enable root verification");
954 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
955 " dev warning menu: show debug info");
956 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
957 " dev warning menu: developer options");
958 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
959 " dev menu: legacy boot");
Simon Glassa0ae3182018-10-16 19:36:48 -0600960 TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
Julius Wernerf41a5032018-01-30 18:20:03 -0800961 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
Simon Glassa0ae3182018-10-16 19:36:48 -0600962 TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
Julius Wernerf41a5032018-01-30 18:20:03 -0800963 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
Simon Glassa0ae3182018-10-16 19:36:48 -0600964 TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
965 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
Julius Wernerf41a5032018-01-30 18:20:03 -0800966 TEST_EQ(screens_count, i, " no extra screens");
967 TEST_EQ(beeps_count, 2, " two error beeps: legacy BIOS not found");
968 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
969 TEST_EQ(beeps_played[1], 200, " low-frequency error beep");
970
971 /* Refuse to boot legacy via menu if not enabled */
972 ResetMocksForDeveloper();
973 i = 0;
974 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
975 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
976 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
977 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
978 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
979 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot Legacy BIOS
980 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
981 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
982 "Menu selected legacy boot when not enabled");
983 TEST_EQ(debug_info_displayed, 0, " no debug info");
984 TEST_EQ(vbexlegacy_called, 0, " did not attempt legacy boot");
985 TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
986 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
987 i = 0;
988 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
989 " dev warning menu: power off");
990 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
991 " dev warning menu: enable root verification");
992 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
993 " dev warning menu: show debug info");
994 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
995 " dev warning menu: developer options");
996 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
997 " dev menu: disk boot");
998 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
999 " dev menu: USB boot");
1000 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1001 " dev menu: legacy boot");
1002 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1003 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1004 " dev menu: legacy boot");
1005 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1006 TEST_EQ(screens_count, i, " no extra screens");
1007 TEST_EQ(beeps_count, 2, " played error beeps");
1008 TEST_EQ(beeps_played[0], 400, " first beep");
1009 TEST_EQ(beeps_played[1], 400, " second beep");
1010
1011 /* Use volume-up long press shortcut to boot USB */
1012 ResetMocksForDeveloper();
1013 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
1014 mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001015 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1016 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS, "VolUp USB");
Julius Wernerf41a5032018-01-30 18:20:03 -08001017 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1018 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1019 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1020 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
1021 " warning screen");
1022 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1023 TEST_EQ(screens_count, 2, " no extra screens");
1024 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
1025
1026 /* Can boot a valid USB image after failing to boot invalid image */
1027 ResetMocksForDeveloper();
1028 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
1029 mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
1030 mock_keypress[1] = VB_BUTTON_VOL_UP_LONG_PRESS;
Joel Kitching166a07d2019-07-29 18:55:59 +08001031 vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001032 vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1033 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001034 "VolUp USB valid after invalid");
1035 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1036 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1037 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1038 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
1039 " warning screen");
1040 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
1041 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
1042 " warning screen");
1043 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1044 TEST_EQ(screens_count, 4, " no extra screens");
1045 TEST_EQ(beeps_count, 1, " error beep: first USB invalid");
1046 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
1047
1048 /* Volume-up long press only works if USB is enabled */
1049 ResetMocksForDeveloper();
1050 mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
1051 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
1052 "VolUp not enabled");
1053 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1054 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1055 TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
1056 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
1057 " warning screen");
1058 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
1059 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
1060 " warning screen");
1061 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1062 TEST_EQ(screens_count, 4, " no extra screens");
1063 TEST_EQ(beeps_count, 2, " played error beeps");
1064 TEST_EQ(beeps_played[0], 400, " first beep");
1065 TEST_EQ(beeps_played[1], 400, " second beep");
1066
1067 /* Volume-up long press without valid USB will still time out */
1068 ResetMocksForDeveloper();
1069 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
1070 mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
1071 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
1072 "VolUp without valid USB");
1073 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1074 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1075 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
1076 " warning screen");
1077 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
1078 TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
1079 " warning screen");
1080 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1081 TEST_EQ(screens_count, 4, " no extra screens");
1082 TEST_EQ(audio_looping_calls_left, 0, " used up audio");
1083 TEST_EQ(beeps_count, 1, " error beep: USB not found");
1084 TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
1085
1086 /* Volume-up long press works from other menus, like LANGUAGE */
1087 ResetMocksForDeveloper();
1088 vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
1089 i = 0;
1090 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
1091 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
1092 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
1093 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1094 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
1095 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
1096 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Language
1097 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1098 mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001099 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1100 TEST_EQ(VbBootDeveloperMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001101 "VolUp USB from LANGUAGE");
1102 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1103 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1104 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1105 i = 0;
1106 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1107 " dev warning menu: power off");
1108 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1109 " dev warning menu: enable root verification");
1110 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1111 " dev warning menu: show debug info");
1112 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1113 " dev warning menu: developer options");
1114 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1115 " dev menu: disk boot");
1116 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1117 " dev menu: cancel");
1118 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1119 " dev menu: power off");
1120 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
1121 " dev menu: language");
1122 TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
1123 " language menu");
1124 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1125 TEST_EQ(screens_count, i, " no extra screens");
1126 TEST_EQ(beeps_count, 0, " no beeps on USB boot");
1127
1128 /* Can disable developer mode through TONORM screen */
1129 ResetMocksForDeveloper();
1130 i = 0;
1131 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enable os verification
1132 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1133 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // confirm is the default
Randall Spanglerb07b4b92018-01-04 17:58:01 -08001134 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_REBOOT_REQUIRED,
Julius Wernerf41a5032018-01-30 18:20:03 -08001135 "TONORM via menu");
Shelley Chene109b1e2017-10-16 14:52:59 -07001136 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
1137 " disable dev request");
Julius Wernerf41a5032018-01-30 18:20:03 -08001138 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1139 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1140 TEST_EQ(debug_info_displayed, 0, " no debug info");
1141 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1142 i = 0;
1143 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1144 " dev warning: power off");
1145 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1146 " dev warning: enable os verification");
1147 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1148 " tonorm: confirm");
1149 TEST_EQ(screens_displayed[i++], VB_SCREEN_TO_NORM_CONFIRMED,
1150 " confirm screen");
1151 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1152 TEST_EQ(screens_count, i, " no extra screens");
1153 TEST_EQ(beeps_count, 0, " no beeps on reboot");
1154
1155 /* If dev mode is disabled, goes to TONORM screen repeatedly */
1156 ResetMocksForDeveloper();
1157 VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT;
1158 audio_looping_calls_left = 1; /* Confirm audio doesn't tick down. */
1159 i = 0;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001160 mock_keypress[i++] = VB_KEY_CTRL('D'); /* Just stays on TONORM and flashes */
1161 mock_keypress[i++] = VB_KEY_CTRL('U'); /* same */
1162 mock_keypress[i++] = VB_KEY_CTRL('L'); /* same */
Julius Wernerf41a5032018-01-30 18:20:03 -08001163 mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS; /* same */
1164 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS; /* same */
1165 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; /* noop */
Mathew Kingaf26dc12019-02-19 10:43:32 -07001166 mock_keypress[i++] = VB_KEY_ENTER;
Julius Wernerf41a5032018-01-30 18:20:03 -08001167 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_REBOOT_REQUIRED,
1168 "FWMP dev disabled");
1169 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
1170 " disable dev request");
1171 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1172 TEST_EQ(debug_info_displayed, 0, " no debug info");
1173 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1174 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1175 i = 0;
1176 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1177 " tonorm screen");
1178 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1179 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1180 " tonorm screen");
1181 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1182 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1183 " tonorm screen");
1184 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1185 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1186 " tonorm screen");
1187 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1188 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1189 " tonorm screen");
1190 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1191 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1192 " tonorm screen");
1193 TEST_EQ(screens_displayed[i++], VB_SCREEN_TO_NORM_CONFIRMED,
1194 " confirm screen");
1195 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1196 TEST_EQ(screens_count, i, " no extra screens");
1197 TEST_EQ(beeps_count, 10, " 5 * 2 error beeps: booting not allowed");
1198 TEST_EQ(beeps_played[0], 400, " first error beep");
1199 TEST_EQ(beeps_played[1], 400, " second error beep");
1200 TEST_EQ(beeps_played[2], 400, " first error beep");
1201 TEST_EQ(beeps_played[3], 400, " second error beep");
1202 TEST_EQ(beeps_played[4], 400, " first error beep");
1203 TEST_EQ(beeps_played[5], 400, " second error beep");
1204 TEST_EQ(beeps_played[6], 400, " first error beep");
1205 TEST_EQ(beeps_played[7], 400, " second error beep");
1206 TEST_EQ(beeps_played[8], 400, " first error beep");
1207 TEST_EQ(beeps_played[9], 400, " second error beep");
Shelley Chene109b1e2017-10-16 14:52:59 -07001208
1209 /* Shutdown requested when dev disabled */
Julius Wernerf41a5032018-01-30 18:20:03 -08001210 ResetMocksForDeveloper();
Shelley Chene109b1e2017-10-16 14:52:59 -07001211 VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT;
1212 shutdown_request_calls_left = 1;
Julius Wernerf41a5032018-01-30 18:20:03 -08001213 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Shelley Chene109b1e2017-10-16 14:52:59 -07001214 "Shutdown requested when dev disabled");
Julius Wernerf41a5032018-01-30 18:20:03 -08001215 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1216 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 0,
1217 " did not exit dev mode");
Shelley Chene109b1e2017-10-16 14:52:59 -07001218 TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1219 " tonorm screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001220 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1221 TEST_EQ(screens_count, 2, " no extra screens");
1222 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1223 TEST_EQ(beeps_count, 0, " no beep on shutdown");
1224
1225 /* Explicit Power Off when dev disabled */
1226 ResetMocksForDeveloper();
1227 VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT;
1228 i = 0;
1229 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
1230 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1231 TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1232 "Power Off when dev disabled");
1233 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1234 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 0,
1235 " did not exit dev mode");
1236 TEST_EQ(debug_info_displayed, 0, " no debug info");
1237 TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
1238 i = 0;
1239 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1240 " tonorm screen: confirm enabling OS verification");
1241 /* Cancel option is removed with dev_disable_boot! */
1242 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
1243 " tonorm screen: power off");
1244 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1245 TEST_EQ(screens_count, i, " no extra screens");
1246 TEST_EQ(beeps_count, 0, " no beeps for power off");
1247
1248 /* Show Debug Info displays debug info, then times out to boot */
1249 ResetMocksForDeveloper();
1250 i = 0;
1251 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
1252 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
1253 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1254 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
1255 "Show Debug Info");
1256 TEST_EQ(debug_info_displayed, 1, " debug info displayed");
1257 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1258 TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
1259 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1260 i = 0;
1261 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1262 " dev warning menu: power off");
1263 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1264 " dev warning menu: enable root verification");
1265 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1266 " dev warning menu: show debug info");
1267 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1268 TEST_EQ(screens_count, i, " no extra screens");
1269 TEST_EQ(beeps_count, 0, " no beeps for debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001270
Julius Wernerdff3a852018-02-07 15:36:41 -08001271 /* Pressing Tab displays debug info, then times out to boot */
1272 ResetMocksForDeveloper();
1273 i = 0;
1274 mock_keypress[i++] = '\t';
1275 TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
1276 "Show Debug Info (Tab shortcut)");
1277 TEST_EQ(debug_info_displayed, 1, " debug info displayed");
1278 TEST_EQ(vbexlegacy_called, 0, " not legacy");
1279 TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
1280 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1281 i = 0;
1282 TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
1283 " dev warning menu: power off");
1284 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1285 TEST_EQ(screens_count, i, " no extra screens");
1286 TEST_EQ(beeps_count, 0, " no beeps for debug info");
1287
1288
Shelley Chene109b1e2017-10-16 14:52:59 -07001289 printf("...done.\n");
1290}
1291
1292static void VbBootRecTest(void)
1293{
Shelley Chene6e177d2017-11-14 12:35:55 -08001294 int i;
1295
Shelley Chene109b1e2017-10-16 14:52:59 -07001296 printf("Testing VbBootRecoveryMenu()...\n");
1297
Julius Wernerf41a5032018-01-30 18:20:03 -08001298 /* Shutdown requested in BROKEN */
Shelley Chene109b1e2017-10-16 14:52:59 -07001299 ResetMocks();
Shelley Chene109b1e2017-10-16 14:52:59 -07001300 VbExEcEnteringMode(0, VB_EC_RECOVERY);
Julius Wernerf41a5032018-01-30 18:20:03 -08001301 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1302 "Shutdown requested in BROKEN");
Shelley Chene109b1e2017-10-16 14:52:59 -07001303 TEST_EQ(VbGetMode(), VB_EC_RECOVERY, "vboot_mode recovery");
Julius Wernerf41a5032018-01-30 18:20:03 -08001304 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1305 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001306 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1307 " broken screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001308 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1309 TEST_EQ(screens_count, 2, " no extra screens");
1310 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Simon Glassa0ae3182018-10-16 19:36:48 -06001311 TEST_EQ(vbexaltfwmask_called, 0, " VbExGetAltFwIdxMask not called");
Shelley Chene109b1e2017-10-16 14:52:59 -07001312
Julius Wernerf41a5032018-01-30 18:20:03 -08001313 /* BROKEN screen with disks inserted */
Shelley Chene109b1e2017-10-16 14:52:59 -07001314 ResetMocks();
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001315 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1316 vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1317 vbtlk_retval[2] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Julius Wernerf41a5032018-01-30 18:20:03 -08001318 vbtlk_retval[3] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1319 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1320 "Shutdown requested in BROKEN with disks");
1321 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1322 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001323 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1324 " broken screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001325 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1326 TEST_EQ(screens_count, 2, " no extra screens");
1327 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001328
Julius Wernerf41a5032018-01-30 18:20:03 -08001329 /* BROKEN screen with disks on second attempt */
Shelley Chene109b1e2017-10-16 14:52:59 -07001330 ResetMocks();
Julius Wernerf41a5032018-01-30 18:20:03 -08001331 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001332 vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Julius Wernerf41a5032018-01-30 18:20:03 -08001333 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1334 "Shutdown requested in BROKEN with later disk");
1335 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1336 TEST_EQ(debug_info_displayed, 0, " no debug info");
1337 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1338 " broken screen");
1339 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1340 TEST_EQ(screens_count, 2, " no extra screens");
1341 TEST_EQ(beeps_count, 0, " no beep on shutdown");
1342
Julius Werner5b26e402018-02-16 13:19:42 -08001343 /* BROKEN screen even if dev switch is on */
Julius Wernerf41a5032018-01-30 18:20:03 -08001344 ResetMocks();
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001345 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Julius Werner5b26e402018-02-16 13:19:42 -08001346 vbtlk_retval[1] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001347 vbtlk_retval[2] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Shelley Chene109b1e2017-10-16 14:52:59 -07001348 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
Julius Wernerf41a5032018-01-30 18:20:03 -08001349 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Julius Werner5b26e402018-02-16 13:19:42 -08001350 "Shutdown requested in BROKEN with dev switch");
Julius Wernerf41a5032018-01-30 18:20:03 -08001351 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1352 TEST_EQ(debug_info_displayed, 0, " no debug info");
Julius Werner5b26e402018-02-16 13:19:42 -08001353 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1354 " broken screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001355 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1356 TEST_EQ(screens_count, 2, " no extra screens");
1357 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001358
Julius Wernerf41a5032018-01-30 18:20:03 -08001359 /* go to INSERT if recovery button physically pressed and EC trusted */
1360 ResetMocksForManualRecovery();
1361 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1362 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1363 "Shutdown requested in INSERT with manual rec");
1364 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1365 TEST_EQ(debug_info_displayed, 0, " no debug info");
1366 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1367 " insert screen");
1368 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1369 TEST_EQ(screens_count, 2, " no extra screens");
1370 TEST_EQ(beeps_count, 0, " no beep on shutdown");
1371
Julius Werner3f896a52018-03-22 14:38:11 -07001372 /* go to INSERT if forced by GBB flag */
1373 ResetMocks();
1374 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingde2cae62019-05-21 12:20:38 +08001375 gbb.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY;
Julius Werner3f896a52018-03-22 14:38:11 -07001376 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1377 "Shutdown requested in INSERT forced by GBB flag");
1378 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1379 TEST_EQ(debug_info_displayed, 0, " no debug info");
1380 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1381 " insert screen");
1382 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1383 TEST_EQ(screens_count, 2, " no extra screens");
1384 TEST_EQ(beeps_count, 0, " no beep on shutdown");
1385
Julius Wernerf41a5032018-01-30 18:20:03 -08001386 /* Stay at BROKEN if recovery button not physically pressed */
1387 ResetMocksForManualRecovery();
1388 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1389 shared->flags &= ~VBSD_BOOT_REC_SWITCH_ON;
1390 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1391 "Go to BROKEN if recovery not manually requested");
1392 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1393 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001394 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1395 " broken screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001396 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1397 TEST_EQ(screens_count, 2, " no extra screens");
1398 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001399
Julius Wernerf41a5032018-01-30 18:20:03 -08001400 /* Stay at BROKEN if EC is untrusted */
1401 ResetMocksForManualRecovery();
1402 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Shelley Chene109b1e2017-10-16 14:52:59 -07001403 trust_ec = 0;
Julius Wernerf41a5032018-01-30 18:20:03 -08001404 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1405 "Go to BROKEN if EC is not trusted");
1406 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1407 TEST_EQ(debug_info_displayed, 0, " no debug info");
1408 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1409 " broken screen");
1410 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1411 TEST_EQ(screens_count, 2, " no extra screens");
1412 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001413
Julius Wernerf41a5032018-01-30 18:20:03 -08001414 /* INSERT boots without screens if we have a valid image on first try */
1415 ResetMocksForManualRecovery();
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001416 vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
Joel Kitching166a07d2019-07-29 18:55:59 +08001417 vbtlk_retval[1] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001418 TEST_EQ(VbBootRecoveryMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001419 "INSERT boots without screens if valid on first try");
1420 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1421 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001422 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
Julius Wernerf41a5032018-01-30 18:20:03 -08001423 TEST_EQ(screens_displayed[0], VB_SCREEN_BLANK, " final blank screen");
1424 TEST_EQ(screens_count, 1, " no extra screens");
1425 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001426
Julius Wernerf41a5032018-01-30 18:20:03 -08001427 /* INSERT boots eventually if we get a valid image later */
1428 ResetMocksForManualRecovery();
1429 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1430 vbtlk_retval[1] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1431 vbtlk_retval[2] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1432 vbtlk_retval[3] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001433 vbtlk_retval[4] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1434 TEST_EQ(VbBootRecoveryMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001435 "INSERT boots after valid image appears");
1436 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1437 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001438 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
Julius Wernerf41a5032018-01-30 18:20:03 -08001439 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1440 " insert screen");
1441 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1442 TEST_EQ(screens_count, 2, " no extra screens");
1443 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001444
Julius Wernerf41a5032018-01-30 18:20:03 -08001445 /* invalid image, then remove, then valid image */
1446 ResetMocksForManualRecovery();
Joel Kitching166a07d2019-07-29 18:55:59 +08001447 vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
Julius Wernerf41a5032018-01-30 18:20:03 -08001448 vbtlk_retval[1] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1449 vbtlk_retval[2] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1450 vbtlk_retval[3] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001451 vbtlk_retval[4] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1452 TEST_EQ(VbBootRecoveryMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001453 "INSERT boots after valid image appears");
1454 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1455 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene109b1e2017-10-16 14:52:59 -07001456 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
Julius Wernerf41a5032018-01-30 18:20:03 -08001457 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
1458 " nogood screen");
1459 TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_INSERT,
1460 " insert screen");
1461 TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " final blank screen");
1462 TEST_EQ(screens_count, 3, " no extra screens");
1463 TEST_EQ(beeps_count, 0, " no beep on shutdown");
Shelley Chene109b1e2017-10-16 14:52:59 -07001464
Julius Wernerf41a5032018-01-30 18:20:03 -08001465 /* Shortcuts that are always ignored in BROKEN for detachables. */
Shelley Chene109b1e2017-10-16 14:52:59 -07001466 ResetMocks();
Julius Wernerf41a5032018-01-30 18:20:03 -08001467 i = 0;
1468 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001469 mock_keypress[i++] = VB_KEY_CTRL('D');
Julius Wernerf41a5032018-01-30 18:20:03 -08001470 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001471 mock_keypress[i++] = VB_KEY_CTRL('U');
Julius Wernerf41a5032018-01-30 18:20:03 -08001472 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001473 mock_keypress[i++] = VB_KEY_CTRL('L');
Julius Wernerf41a5032018-01-30 18:20:03 -08001474 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1475 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS;
1476 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1477 mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
1478 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1479 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
1480 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1481 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1482 "Shortcuts ignored in BROKEN");
1483 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1484 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1485 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1486 TEST_EQ(debug_info_displayed, 0, " no debug info");
1487 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1488 " broken screen");
1489 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1490 TEST_EQ(screens_count, 2, " no extra screens");
1491 TEST_EQ(beeps_count, 0, " no beep from invalid keys");
1492
1493 /* Shortcuts that are always ignored in INSERT for detachables. */
1494 ResetMocksForManualRecovery();
1495 i = 0;
1496 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001497 mock_keypress[i++] = VB_KEY_CTRL('D');
Julius Wernerf41a5032018-01-30 18:20:03 -08001498 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001499 mock_keypress[i++] = VB_KEY_CTRL('U');
Julius Wernerf41a5032018-01-30 18:20:03 -08001500 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Mathew Kingaf26dc12019-02-19 10:43:32 -07001501 mock_keypress[i++] = VB_KEY_CTRL('L');
Julius Wernerf41a5032018-01-30 18:20:03 -08001502 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1503 mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
1504 mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1505 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
1506 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1507 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1508 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1509 "Shortcuts ignored in INSERT");
1510 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1511 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1512 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1513 TEST_EQ(debug_info_displayed, 0, " no debug info");
1514 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1515 " insert screen");
1516 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1517 TEST_EQ(screens_count, 2, " no extra screens");
1518 TEST_EQ(beeps_count, 0, " no beep from invalid keys");
1519
1520 /* Power Off BROKEN through OPTIONS menu */
1521 ResetMocks();
1522 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
1523 mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1524 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
1525 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1526 "Power Off BROKEN through OPTIONS");
1527 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1528 TEST_EQ(debug_info_displayed, 0, " no debug info");
1529 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1530 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1531 " broken screen");
1532 TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
1533 " options: cancel");
1534 TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
1535 " options: power off");
1536 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1537 TEST_EQ(screens_count, 4, " no extra screens");
1538 TEST_EQ(beeps_count, 0, " no beep from power off");
1539
1540 /* Power Off NOGOOD through OPTIONS menu */
1541 ResetMocksForManualRecovery();
1542 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
1543 mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1544 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
1545 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1546 "Power Off NOGOOD through OPTIONS");
1547 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1548 TEST_EQ(debug_info_displayed, 0, " no debug info");
1549 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1550 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
1551 " nogood screen");
1552 TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
1553 " options: cancel");
1554 TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
1555 " options: power off");
1556 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1557 TEST_EQ(screens_count, 4, " no extra screens");
1558 TEST_EQ(beeps_count, 0, " no beep from power off");
1559
1560 /* Power Off INSERT through TO_DEV menu */
1561 ResetMocksForManualRecovery();
1562 mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1563 mock_keypress[0] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
1564 mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1565 mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1566 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
1567 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1568 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1569 "Power Off INSERT through TO_DEV");
1570 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1571 TEST_EQ(debug_info_displayed, 0, " no debug info");
1572 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1573 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1574 " insert screen");
1575 TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1576 " to_dev: cancel");
1577 TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1578 " to_dev: power off");
1579 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1580 TEST_EQ(screens_count, 4, " no extra screens");
1581 TEST_EQ(beeps_count, 0, " no beep from power off");
Shelley Chene109b1e2017-10-16 14:52:59 -07001582
Julius Wernerdff3a852018-02-07 15:36:41 -08001583 /* Show Debug Info from BROKEN through OPTIONS menu */
1584 ResetMocks();
1585 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
1586 mock_keypress[1] = VB_BUTTON_VOL_UP_SHORT_PRESS; // show debug info
1587 mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
1588 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1589 "Show Debug info from BROKEN through OPTIONS");
1590 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1591 TEST_EQ(debug_info_displayed, 1, " no debug info");
1592 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1593 TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
1594 " broken screen");
1595 TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
1596 " options: cancel");
1597 TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
1598 " options: show debug info");
1599 TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
1600 TEST_EQ(screens_count, 4, " no extra screens");
1601 TEST_EQ(beeps_count, 0, " no beep from power off");
1602
1603 /* Show Debug Info on NOGOOD with Tab */
1604 ResetMocksForManualRecovery();
1605 mock_keypress[0] = '\t';
1606 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1607 "Show Debug info on NOGOOD with Tab");
1608 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1609 TEST_EQ(debug_info_displayed, 1, " no debug info");
1610 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1611 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
1612 " nogood screen");
1613 TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
1614 TEST_EQ(screens_count, 2, " no extra screens");
1615 TEST_EQ(beeps_count, 0, " no beep from power off");
1616
Shelley Chene109b1e2017-10-16 14:52:59 -07001617 /* Navigate to confirm dev mode selection and then cancel */
Julius Wernerf41a5032018-01-30 18:20:03 -08001618 ResetMocksForManualRecovery();
1619 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Shelley Chene6e177d2017-11-14 12:35:55 -08001620 i = 0;
1621 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Julius Wernerf41a5032018-01-30 18:20:03 -08001622 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
Shelley Chene6e177d2017-11-14 12:35:55 -08001623 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Julius Wernerf41a5032018-01-30 18:20:03 -08001624 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm disabling
Shelley Chene6e177d2017-11-14 12:35:55 -08001625 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Julius Wernerf41a5032018-01-30 18:20:03 -08001626 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
1627 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1628 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // power off
1629 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Shelley Chene109b1e2017-10-16 14:52:59 -07001630 "go to TO_DEV screen and cancel");
Julius Wernerf41a5032018-01-30 18:20:03 -08001631 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1632 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1633 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1634 TEST_EQ(debug_info_displayed, 0, " no debug info");
Shelley Chene6e177d2017-11-14 12:35:55 -08001635 i = 0;
1636 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
Shelley Chene109b1e2017-10-16 14:52:59 -07001637 " insert screen");
Shelley Chene6e177d2017-11-14 12:35:55 -08001638 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
Shelley Chene109b1e2017-10-16 14:52:59 -07001639 " recovery to_dev menu: cancel");
Shelley Chene6e177d2017-11-14 12:35:55 -08001640 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1641 " recovery to_dev menu: confirm disabling");
1642 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1643 " recovery to_dev menu: cancel");
1644 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
1645 " back to insert screen");
Julius Wernerf41a5032018-01-30 18:20:03 -08001646 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1647 TEST_EQ(screens_count, i, " no extra screens");
1648 TEST_EQ(beeps_count, 0, " no beeps");
Shelley Chene109b1e2017-10-16 14:52:59 -07001649
1650 /* Navigate to confirm dev mode selection and then confirm */
Julius Wernerf41a5032018-01-30 18:20:03 -08001651 ResetMocksForManualRecovery();
1652 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Shelley Chene6e177d2017-11-14 12:35:55 -08001653 i = 0;
1654 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Julius Wernerf41a5032018-01-30 18:20:03 -08001655 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
Shelley Chene6e177d2017-11-14 12:35:55 -08001656 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
Julius Wernerf41a5032018-01-30 18:20:03 -08001657 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS;
1658 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
Randall Spanglerb07b4b92018-01-04 17:58:01 -08001659 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_REBOOT_REQUIRED,
Shelley Chene109b1e2017-10-16 14:52:59 -07001660 "go to TO_DEV screen and confirm");
Julius Wernerf41a5032018-01-30 18:20:03 -08001661 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1662 TEST_EQ(debug_info_displayed, 0, " no debug info");
1663 TEST_EQ(virtdev_set, 1, " virtual dev mode on");
Shelley Chene6e177d2017-11-14 12:35:55 -08001664 i = 0;
1665 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
Shelley Chene109b1e2017-10-16 14:52:59 -07001666 " insert screen");
Shelley Chene6e177d2017-11-14 12:35:55 -08001667 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
Shelley Chene109b1e2017-10-16 14:52:59 -07001668 " recovery to_dev menu: cancel");
Shelley Chene6e177d2017-11-14 12:35:55 -08001669 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
Shelley Chene109b1e2017-10-16 14:52:59 -07001670 " recovery to_dev menu: confirm disabling os verification");
Julius Wernerf41a5032018-01-30 18:20:03 -08001671 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1672 TEST_EQ(screens_count, i, " no extra screens");
1673 TEST_EQ(beeps_count, 0, " no beeps");
Shelley Chene109b1e2017-10-16 14:52:59 -07001674
Julius Wernerf41a5032018-01-30 18:20:03 -08001675 /* Untrusted keyboard cannot enter TO_DEV (must be malicious anyway) */
1676 ResetMocksForManualRecovery();
1677 i = 0;
1678 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // try to_dev
1679 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // try confirm
1680 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1681 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1682 "Untrusted keyboard cannot enter TO_DEV");
1683 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1684 TEST_EQ(debug_info_displayed, 0, " no debug info");
1685 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1686 i = 0;
1687 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
1688 " nogood screen");
1689 TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
1690 " options menu");
1691 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
1692 " nogood screen");
1693 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1694 TEST_EQ(screens_count, i, " no extra screens");
1695 TEST_EQ(beeps_count, 0, " no beeps");
1696
1697 /* Untrusted keyboard cannot navigate in TO_DEV menu if already there */
1698 ResetMocksForManualRecovery();
1699 i = 0;
1700 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1701 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
1702 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // try to confirm...
1703 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1704 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1705 "Untrusted keyboard cannot navigate in TO_DEV");
1706 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1707 TEST_EQ(debug_info_displayed, 0, " no debug info");
1708 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1709 i = 0;
1710 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
1711 " nogood screen");
1712 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1713 " todev menu: cancel");
1714 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1715 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1716 " todev menu: cancel");
1717 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
1718 " nogood screen");
1719 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1720 TEST_EQ(screens_count, i, " no extra screens");
1721 TEST_EQ(beeps_count, 2, " played error beeps");
1722 TEST_EQ(beeps_played[0], 400, " first beep");
1723 TEST_EQ(beeps_played[1], 400, " second beep");
1724
Shelley Chene109b1e2017-10-16 14:52:59 -07001725 /* Handle TPM error in enabling dev mode */
Julius Wernerf41a5032018-01-30 18:20:03 -08001726 ResetMocksForManualRecovery();
1727 i = 0;
1728 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1729 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
1730 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1731 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm enabling
1732 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
Joel Kitching166a07d2019-07-29 18:55:59 +08001733 virtdev_retval = VB2_ERROR_MOCK;
Julius Wernerf41a5032018-01-30 18:20:03 -08001734 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_TPM_SET_BOOT_MODE_STATE,
1735 "todev TPM failure");
1736 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1737 TEST_EQ(debug_info_displayed, 0, " no debug info");
1738 TEST_NEQ(shutdown_request_calls_left, 0, " aborted explicitly");
1739 TEST_EQ(virtdev_set, 1, " virtual dev mode on");
1740 i = 0;
1741 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
1742 " nogood screen");
1743 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1744 " recovery to_dev menu: cancel");
1745 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1746 " recovery to_dev menu: confirm disabling os verification");
1747 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1748 TEST_EQ(screens_count, i, " no extra screens");
1749 TEST_EQ(beeps_count, 0, " no beeps");
1750
1751 /* Cannot enable dev mode if already enabled. */
1752 ResetMocksForManualRecovery();
1753 shared->flags |= VBSD_BOOT_DEV_SWITCH_ON;
1754 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1755 i = 0;
1756 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1757 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
1758 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1759 "Ctrl+D ignored if already in dev mode");
1760 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1761 TEST_EQ(debug_info_displayed, 0, " no debug info");
1762 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1763 TEST_EQ(virtdev_set, 0, " virtual dev mode wasn't enabled again");
1764 i = 0;
1765 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
1766 " insert screen");
1767 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
1768 TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
1769 " insert screen");
1770 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1771 TEST_EQ(screens_count, i, " no extra screens");
1772 TEST_EQ(beeps_count, 2, " played error beeps");
1773 TEST_EQ(beeps_played[0], 400, " first beep");
1774 TEST_EQ(beeps_played[1], 400, " second beep");
1775
1776 /* Removing invalid USB drops back to INSERT from TO_DEV menu. */
1777 ResetMocksForManualRecovery();
1778 mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1779 mock_keypress[0] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
1780 /* asynchronous transition to INSERT before keypress[50] */
1781 mock_keypress[55] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
1782 mock_keypress[56] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1783 mock_keypress[57] = VB_BUTTON_POWER_SHORT_PRESS;
Joel Kitching166a07d2019-07-29 18:55:59 +08001784 vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
Julius Wernerf41a5032018-01-30 18:20:03 -08001785 vbtlk_retval[1] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1786 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1787 "Drop back to INSERT from TO_DEV when removing invalid USB");
1788 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1789 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1790 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1791 TEST_EQ(debug_info_displayed, 0, " no debug info");
1792 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
1793 " nogood screen");
1794 TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV_MENU,
1795 " todev menu");
1796 TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_INSERT,
1797 " insert screen");
1798 TEST_EQ(screens_displayed[3], VB_SCREEN_OPTIONS_MENU,
1799 " options menu: cancel");
1800 TEST_EQ(screens_displayed[4], VB_SCREEN_OPTIONS_MENU,
1801 " options menu: power off");
1802 TEST_EQ(screens_displayed[5], VB_SCREEN_BLANK, " final blank screen");
1803 TEST_EQ(screens_count, 6, " no extra screens");
1804 TEST_EQ(beeps_count, 0, " no beeps");
1805
1806 /* Plugging in invalid USB drops back to NOGOOD from LANGUAGE. */
1807 ResetMocksForManualRecovery();
1808 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
1809 mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1810 mock_keypress[2] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
1811 mock_keypress[3] = VB_BUTTON_POWER_SHORT_PRESS;
1812 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitching166a07d2019-07-29 18:55:59 +08001813 vbtlk_retval[1] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
Julius Wernerf41a5032018-01-30 18:20:03 -08001814 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
1815 "Drop back to NOGOOD from LANGUAGE when inserting invalid USB");
1816 TEST_EQ(shutdown_request_calls_left, 0, " timed out");
1817 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1818 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1819 TEST_EQ(debug_info_displayed, 0, " no debug info");
1820 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1821 " insert screen");
1822 TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
1823 " options menu: cancel");
1824 TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
1825 " options menu: power off");
1826 TEST_EQ(screens_displayed[3], VB_SCREEN_OPTIONS_MENU,
1827 " options menu: language");
1828 TEST_EQ(screens_displayed[4], VB_SCREEN_LANGUAGES_MENU,
1829 " languages menu");
1830 TEST_EQ(screens_displayed[5], VB_SCREEN_RECOVERY_NO_GOOD,
1831 " nogood screen");
1832 TEST_EQ(screens_displayed[6], VB_SCREEN_BLANK, " final blank screen");
1833 TEST_EQ(screens_count, 7, " no extra screens");
1834 TEST_EQ(beeps_count, 0, " no beeps");
1835
1836 /* Plugging in valid USB boots straight from OPTIONS menu. */
1837 ResetMocksForManualRecovery();
1838 mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
1839 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
Joel Kitchingcf49e7b2019-07-29 18:51:00 +08001840 vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
1841 TEST_EQ(VbBootRecoveryMenu(&ctx), VB2_SUCCESS,
Julius Wernerf41a5032018-01-30 18:20:03 -08001842 "Boot by plugging in USB straight from OPTIONS menu");
1843 TEST_NEQ(shutdown_request_calls_left, 0, " booted explicitly");
1844 TEST_EQ(virtdev_set, 0, " virtual dev mode off");
1845 TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
1846 TEST_EQ(debug_info_displayed, 0, " no debug info");
1847 TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
1848 " insert screen");
1849 TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
1850 " options menu: cancel");
1851 TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " final blank screen");
1852 TEST_EQ(screens_count, 3, " no extra screens");
1853 TEST_EQ(beeps_count, 0, " no beeps");
Shelley Chene109b1e2017-10-16 14:52:59 -07001854
1855 printf("...done.\n");
1856}
1857
1858static void VbTestLanguageMenu(void)
1859{
Shelley Chene6e177d2017-11-14 12:35:55 -08001860 int i;
1861
Shelley Chene109b1e2017-10-16 14:52:59 -07001862 printf("Testing VbTestLanguageMenu()...\n");
1863
Julius Wernerf41a5032018-01-30 18:20:03 -08001864 /* Navigate to language menu from BROKEN */
Shelley Chene109b1e2017-10-16 14:52:59 -07001865 ResetMocks();
Shelley Chene6e177d2017-11-14 12:35:55 -08001866 i = 0;
Julius Wernerf41a5032018-01-30 18:20:03 -08001867 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
1868 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1869 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // languages
1870 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // enter languages
1871 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
1872 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // cancel -> BROKEN
1873 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // power off
Randall Spanglerb07b4b92018-01-04 17:58:01 -08001874 TEST_EQ(VbBootRecoveryMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
Julius Wernerf41a5032018-01-30 18:20:03 -08001875 "go to language menu from BROKEN");
1876 TEST_EQ(debug_info_displayed, 0, " no debug info");
1877 TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
1878 i = 0;
1879 TEST_EQ(screens_displayed[i++], VB_SCREEN_OS_BROKEN,
1880 " broken screen");
1881 TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
1882 " options menu: cancel");
1883 TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
1884 " options menu: power off");
1885 TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
1886 " options menu: language");
1887 TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
1888 " language menu");
1889 TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
1890 " options menu: cancel");
1891 TEST_EQ(screens_displayed[i++], VB_SCREEN_OS_BROKEN,
1892 " broken screen");
1893 TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
1894 TEST_EQ(screens_count, i, " no extra screens");
1895 TEST_EQ(beeps_count, 0, " no beeps");
1896
1897 /* Navigate to all language menus from recovery */
1898 ResetMocksForManualRecovery();
1899 vbtlk_retval[0] = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
1900 i = 0;
1901 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
1902 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
1903 mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // languages
1904 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
1905 mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
1906 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1907 mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
1908 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1909 mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm disabling
1910 mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
1911 mock_keypress[i++] = VB_BUTTON_VOL