summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2020-11-02 15:34:21 +0800
committerCommit Bot <commit-bot@chromium.org>2020-12-04 13:13:26 +0000
commit3b4b439b6450ceacd36d91036e4509b8b6f7880c (patch)
tree8325eb39e2f4c2c817ddcf0170966818432021f9 /tests
parent03d6cc6106bd72503a669c8640335fe858ebeaf2 (diff)
downloadvboot-3b4b439b6450ceacd36d91036e4509b8b6f7880c.tar.gz
vboot: deprecate and remove legacy UI code
BUG=b:146399181, b:167643628 TEST=make clean && make runtests TEST=Build and flash to device BRANCH=none Cq-Depend: chromium:2512739 Signed-off-by: Joel Kitching <kitching@google.com> Change-Id: Ia8d95451d55142fbe9acaa6e49de9b5abe134083 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2512740 Reviewed-by: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/vb2_auxfw_sync_tests.c1
-rw-r--r--tests/vb2_ec_sync_tests.c1
-rw-r--r--tests/vboot_api_kernel4_tests.c38
-rw-r--r--tests/vboot_ui_legacy_clamshell_beep_tests.c274
-rw-r--r--tests/vboot_ui_legacy_clamshell_tests.c1655
-rw-r--r--tests/vboot_ui_legacy_menu_tests.c2349
-rw-r--r--tests/vboot_ui_legacy_tests.c124
7 files changed, 0 insertions, 4442 deletions
diff --git a/tests/vb2_auxfw_sync_tests.c b/tests/vb2_auxfw_sync_tests.c
index 358f706b..f779ac05 100644
--- a/tests/vb2_auxfw_sync_tests.c
+++ b/tests/vb2_auxfw_sync_tests.c
@@ -19,7 +19,6 @@
#include "vboot_audio.h"
#include "vboot_kernel.h"
#include "vboot_struct.h"
-#include "vboot_ui_legacy.h"
/* Mock data */
static struct vb2_context *ctx;
diff --git a/tests/vb2_ec_sync_tests.c b/tests/vb2_ec_sync_tests.c
index 6c06caf0..be86fbb4 100644
--- a/tests/vb2_ec_sync_tests.c
+++ b/tests/vb2_ec_sync_tests.c
@@ -16,7 +16,6 @@
#include "vboot_audio.h"
#include "vboot_kernel.h"
#include "vboot_struct.h"
-#include "vboot_ui_legacy.h"
/* Mock data */
static int ec_ro_updated;
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index 1e687484..5229ee55 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -144,16 +144,6 @@ vb2_error_t vb2_developer_menu(struct vb2_context *c)
return boot_dev(c);
}
-vb2_error_t VbBootDeveloperLegacyClamshell(struct vb2_context *c)
-{
- return boot_dev(c);
-}
-
-vb2_error_t VbBootDeveloperLegacyMenu(struct vb2_context *c)
-{
- return boot_dev(c);
-}
-
static void rec_check(struct vb2_context *c)
{
TEST_EQ(current_recovery_reason, expected_recovery_reason,
@@ -179,34 +169,6 @@ vb2_error_t vb2_broken_recovery_menu(struct vb2_context *c)
vb2_error_t vb2_diagnostic_menu(struct vb2_context *c)
{
- TEST_TRUE(MENU_UI, "Using menu_ui");
- if (vbboot_retval == -5)
- return VB2_ERROR_MOCK;
-
- return vbboot_retval;
-}
-
-vb2_error_t VbBootRecoveryLegacyClamshell(struct vb2_context *c)
-{
- rec_check(c);
- /* Don't care if it's manual recovery or not */
- if (vbboot_retval == -3 || vbboot_retval == -4)
- return VB2_ERROR_MOCK;
- return vbboot_retval;
-}
-
-vb2_error_t VbBootRecoveryLegacyMenu(struct vb2_context *c)
-{
- rec_check(c);
- /* Don't care if it's manual recovery or not */
- if (vbboot_retval == -3 || vbboot_retval == -4)
- return VB2_ERROR_MOCK;
- return vbboot_retval;
-}
-
-vb2_error_t VbBootDiagnosticLegacyClamshell(struct vb2_context *c)
-{
- TEST_TRUE(!MENU_UI, "Not using menu_ui");
if (vbboot_retval == -5)
return VB2_ERROR_MOCK;
diff --git a/tests/vboot_ui_legacy_clamshell_beep_tests.c b/tests/vboot_ui_legacy_clamshell_beep_tests.c
deleted file mode 100644
index cb0b4765..00000000
--- a/tests/vboot_ui_legacy_clamshell_beep_tests.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests for vboot_api_firmware
- */
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "2common.h"
-#include "2misc.h"
-#include "2nvstorage.h"
-#include "2secdata.h"
-#include "2sysincludes.h"
-#include "crc32.h"
-#include "host_common.h"
-#include "load_kernel_fw.h"
-#include "test_common.h"
-#include "vboot_kernel.h"
-#include "vboot_struct.h"
-
-/* Expected results */
-
-#define MAX_NOTE_EVENTS 10
-#define TIME_FUZZ 500
-#define KBD_READ_TIME 60
-
-typedef struct {
- uint16_t msec;
- uint16_t freq;
- int time;
-} note_event_t;
-
-typedef struct {
- const char *name;
- uint32_t gbb_flags;
- uint32_t keypress_key;
- int keypress_at_count;
- int num_events;
- note_event_t notes[MAX_NOTE_EVENTS];
-} test_case_t;
-
-test_case_t test[] = {
-
- { "VbBootDeveloperSoundTest( fast )",
- VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY, 0, 0,
- 1,
- {
- {0, 0, 2000}, // off and return at 2 seconds
- }},
-
- { "VbBootDeveloperSoundTest( normal )",
- 0, 0, 0,
- 3,
- {
- {250, 400, 20000}, // first beep at 20 seconds
- {250, 400, 20510}, // second beep shortly after
- {0, 0, 30020}, // off and return at 30 seconds
- }},
-
- // Now with some keypresses
-
- { "VbBootDeveloperSoundTest( normal, Ctrl-D )",
- 0, 4, 20400, // Ctrl-D between beeps
- 2,
- {
- {250, 400, 20000}, // first beep at 20 seconds
- {0, 0, 20400}, // sees Ctrl-D, sound off, return
- }},
-
- { "VbBootDeveloperSoundTest( normal, Ctrl-U not allowed )",
- 0, 21, 10000, // Ctrl-U at 10 seconds
- 5,
- {
- {120, 400, 10000}, // complains about Ctrl-U (one beep)
- {120, 400, 10240}, // complains about Ctrl-U (two beeps)
- {250, 400, 20000}, // starts first beep at 20 seconds
- {250, 400, 20510}, // starts second beep
- {0, 0, 30020}, // returns at 30 seconds + 360ms
- }},
-};
-
-/* Mock data */
-static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]
- __attribute__((aligned(VB2_WORKBUF_ALIGN)));
-static struct vb2_context *ctx;
-static struct vb2_shared_data *sd;
-static struct vb2_gbb_header gbb;
-static uint32_t current_time;
-static uint32_t current_ticks;
-static int current_event;
-static int max_events;
-static int matched_events;
-static int kbd_fire_at;
-static uint32_t kbd_fire_key;
-static note_event_t *expected_event;
-
-/* Audio open count, so we can reset it */
-extern int audio_open_count;
-
-/* Reset mock data (for use before each test) */
-static void ResetMocks(void)
-{
- TEST_SUCC(vb2api_init(workbuf, sizeof(workbuf), &ctx),
- "vb2api_init failed");
- vb2_nv_init(ctx);
-
- sd = vb2_get_sd(ctx);
-
- ctx->flags |= VB2_CONTEXT_NO_SECDATA_FWMP;
- sd->status |= VB2_SD_STATUS_SECDATA_FWMP_INIT;
-
- memset(&gbb, 0, sizeof(gbb));
-
- current_ticks = 0;
- current_time = 0;
-
- current_event = 0;
- kbd_fire_at = 0;
- kbd_fire_key = 0;
- audio_open_count = 0;
-
- matched_events = 0;
- max_events = 0;
-}
-
-/****************************************************************************/
-/* Mocked verification functions */
-struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
-{
- return &gbb;
-}
-
-vb2_error_t vb2ex_commit_data(struct vb2_context *c)
-{
- return VB2_SUCCESS;
-}
-
-vb2_error_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count,
- uint32_t disk_flags)
-{
- return VB2_ERROR_UNKNOWN;
-}
-
-vb2_error_t VbExDiskFreeInfo(VbDiskInfo* infos,
- VbExDiskHandle_t preserve_handle)
-{
- return VB2_SUCCESS;
-}
-
-vb2_error_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, void* buffer)
-{
- return VB2_ERROR_UNKNOWN;
-}
-
-vb2_error_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, const void* buffer)
-{
- return VB2_ERROR_UNKNOWN;
-}
-
-uint32_t VbExIsShutdownRequested(void)
-{
- return 0;
-}
-
-uint32_t VbExKeyboardRead(void)
-{
- uint32_t tmp;
- uint32_t now;
-
- vb2ex_msleep(KBD_READ_TIME);
- now = current_time;
-
- if (kbd_fire_key && now >= kbd_fire_at) {
- VB2_DEBUG("returning %d at %d msec\n",
- kbd_fire_key, now);
- tmp = kbd_fire_key;
- kbd_fire_key = 0;
- return tmp;
- }
- VB2_DEBUG("returning %d at %d msec\n", 0, now);
- return 0;
-}
-
-void vb2ex_msleep(uint32_t msec)
-{
- current_ticks += msec;
- current_time = current_ticks;
- VB2_DEBUG("msec=%d at %d msec\n", msec, current_time);
-}
-
-uint32_t vb2ex_mtime(void)
-{
- return current_ticks;
-}
-
-void vb2ex_beep(uint32_t msec, uint32_t frequency)
-{
- VB2_DEBUG("msec=%d, frequency=%d at %d msec\n",
- msec, frequency, current_time);
-
- if (current_event < max_events &&
- msec == expected_event[current_event].msec &&
- frequency == expected_event[current_event].freq &&
- (current_time - expected_event[current_event].time) < TIME_FUZZ)
- matched_events++;
-
- if (msec)
- vb2ex_msleep(msec);
- current_event++;
-}
-
-vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale,
- const VbScreenData *data)
-{
- switch (screen_type) {
- case VB_SCREEN_BLANK:
- VB2_DEBUG("screen_type=BLANK\n");
- break;
- case VB_SCREEN_DEVELOPER_WARNING:
- VB2_DEBUG("screen_type=DEV\n");
- break;
- case VB_SCREEN_RECOVERY_INSERT:
- VB2_DEBUG("screen_type=INSERT\n");
- break;
- case VB_SCREEN_RECOVERY_NO_GOOD:
- VB2_DEBUG("screen_type=NO_GOOD\n");
- break;
- case VB_SCREEN_OS_BROKEN:
- VB2_DEBUG("screen_type=BROKEN\n");
- break;
- default:
- VB2_DEBUG("screen_type=%#x\n", screen_type);
- }
-
- VB2_DEBUG("current_time is %d msec\n", current_time);
-
- return VB2_SUCCESS;
-}
-
-/****************************************************************************/
-
-static void VbBootDeveloperSoundTest(void)
-{
- int i;
- int num_tests = sizeof(test) / sizeof(test_case_t);
-
- for (i = 0; i < num_tests; i++) {
- VB2_DEBUG("STARTING %s ...\n", test[i].name);
- ResetMocks();
- gbb.flags = test[i].gbb_flags;
- kbd_fire_key = test[i].keypress_key;
- kbd_fire_at = test[i].keypress_at_count;
- max_events = test[i].num_events;
- expected_event = test[i].notes;
- VbBootDeveloperLegacyClamshell(ctx);
- vb2ex_beep(0, 0); /* Dummy call to determine end time */
- VB2_DEBUG("INFO: matched %d total %d expected %d\n",
- matched_events, current_event, test[i].num_events);
- TEST_TRUE(matched_events == test[i].num_events &&
- current_event == test[i].num_events, test[i].name);
- }
-}
-
-int main(int argc, char* argv[])
-{
- VbBootDeveloperSoundTest();
- return gTestSuccess ? 0 : 255;
-}
diff --git a/tests/vboot_ui_legacy_clamshell_tests.c b/tests/vboot_ui_legacy_clamshell_tests.c
deleted file mode 100644
index d33cb71e..00000000
--- a/tests/vboot_ui_legacy_clamshell_tests.c
+++ /dev/null
@@ -1,1655 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests for vboot_api_kernel, part 2
- */
-
-#include "2common.h"
-#include "2misc.h"
-#include "2nvstorage.h"
-#include "2secdata.h"
-#include "2secdata_struct.h"
-#include "host_common.h"
-#include "load_kernel_fw.h"
-#include "test_common.h"
-#include "tss_constants.h"
-#include "vboot_audio.h"
-#include "vboot_kernel.h"
-#include "vboot_struct.h"
-#include "vboot_test.h"
-#include "vboot_ui_legacy.h"
-
-/* Mock data */
-static LoadKernelParams lkp;
-static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]
- __attribute__((aligned(VB2_WORKBUF_ALIGN)));
-static struct vb2_context *ctx;
-static struct vb2_shared_data *sd;
-static struct vb2_gbb_header gbb;
-static struct vb2_secdata_fwmp *fwmp;
-
-static int audio_looping_calls_left;
-static uint32_t vbtlk_retval;
-static int vbtlk_expect_fixed;
-static int vbtlk_expect_removable;
-static int vbexlegacy_called;
-static enum VbAltFwIndex_t altfw_num;
-static uint32_t current_ticks;
-static int trust_ec;
-static int virtdev_set;
-static uint32_t virtdev_fail;
-static uint32_t mock_keypress[16];
-static uint32_t mock_keyflags[8];
-static uint32_t mock_keypress_count;
-
-#define GPIO_SHUTDOWN 1
-#define GPIO_PRESENCE 2
-#define GPIO_LID_CLOSED 4
-typedef struct GpioState {
- uint32_t gpio_flags;
- uint32_t count;
-} GpioState;
-struct GpioState mock_gpio[8];
-static uint32_t mock_gpio_count;
-
-static uint32_t screens_displayed[8];
-static uint32_t screens_count = 0;
-static uint32_t mock_num_disks[8];
-static uint32_t mock_num_disks_count;
-static int tpm_set_mode_called;
-static enum vb2_tpm_mode tpm_mode;
-
-/* Extra character to guarantee null termination. */
-static char set_vendor_data[VENDOR_DATA_LENGTH + 2];
-static int set_vendor_data_called;
-
-/*
- * Mocks the assertion of 1 or more gpios in |gpio_flags| for 100 ticks after
- * an optional |ticks| delay.
- */
-static void MockGpioAfter(uint32_t ticks, uint32_t gpio_flags)
-{
- uint32_t index = 0;
- if (ticks > 0)
- mock_gpio[index++].count = ticks - 1;
-
- mock_gpio[index].gpio_flags = gpio_flags;
- mock_gpio[index].count = 100;
-}
-
-/* Reset mock data (for use before each test) */
-static void ResetMocks(void)
-{
- vb2_reset_power_button();
-
- memset(&lkp, 0, sizeof(lkp));
-
- TEST_SUCC(vb2api_init(workbuf, sizeof(workbuf), &ctx),
- "vb2api_init failed");
- vb2_nv_init(ctx);
-
- sd = vb2_get_sd(ctx);
- sd->flags |= VB2_SD_FLAG_DISPLAY_AVAILABLE;
-
- /* CRC will be invalid after here, but nobody's checking */
- sd->status |= VB2_SD_STATUS_SECDATA_FWMP_INIT;
- fwmp = (struct vb2_secdata_fwmp *)ctx->secdata_fwmp;
-
- memset(&gbb, 0, sizeof(gbb));
-
- audio_looping_calls_left = 30;
- vbtlk_retval = VB2_ERROR_MOCK;
- vbtlk_expect_fixed = 0;
- vbtlk_expect_removable = 0;
- vbexlegacy_called = 0;
- altfw_num = -100;
- current_ticks = 0;
- trust_ec = 0;
- virtdev_set = 0;
- virtdev_fail = 0;
- set_vendor_data_called = 0;
-
- memset(screens_displayed, 0, sizeof(screens_displayed));
- screens_count = 0;
-
- memset(mock_keypress, 0, sizeof(mock_keypress));
- memset(mock_keyflags, 0, sizeof(mock_keyflags));
- mock_keypress_count = 0;
- memset(mock_gpio, 0, sizeof(mock_gpio));
- mock_gpio_count = 0;
- memset(mock_num_disks, 0, sizeof(mock_num_disks));
- mock_num_disks_count = 0;
-
- tpm_set_mode_called = 0;
- tpm_mode = VB2_TPM_MODE_ENABLED_TENTATIVE;
-}
-
-/* Mock functions */
-
-struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
-{
- return &gbb;
-}
-
-uint32_t VbExIsShutdownRequested(void)
-{
- uint32_t result = 0;
- if (mock_gpio_count >= ARRAY_SIZE(mock_gpio))
- return 0;
- if (mock_gpio[mock_gpio_count].gpio_flags & GPIO_SHUTDOWN)
- result |= VB_SHUTDOWN_REQUEST_POWER_BUTTON;
- if (mock_gpio[mock_gpio_count].gpio_flags & GPIO_LID_CLOSED)
- result |= VB_SHUTDOWN_REQUEST_LID_CLOSED;
- if (mock_gpio[mock_gpio_count].count > 0) {
- --mock_gpio[mock_gpio_count].count;
- } else {
- ++mock_gpio_count;
- }
- return result;
-}
-
-uint32_t VbExKeyboardRead(void)
-{
- return VbExKeyboardReadWithFlags(NULL);
-}
-
-uint32_t VbExKeyboardReadWithFlags(uint32_t *key_flags)
-{
- if (mock_keypress_count < ARRAY_SIZE(mock_keypress)) {
- if (key_flags != NULL &&
- mock_keypress_count < ARRAY_SIZE(mock_keyflags))
- *key_flags = mock_keyflags[mock_keypress_count];
- return mock_keypress[mock_keypress_count++];
- } else
- return 0;
-}
-
-int vb2ex_physical_presence_pressed(void)
-{
- uint32_t result = 0;
-
- if (mock_gpio_count >= ARRAY_SIZE(mock_gpio))
- return 0;
-
- if ((mock_gpio[mock_gpio_count].gpio_flags & GPIO_PRESENCE))
- result = 1;
-
- if (mock_gpio[mock_gpio_count].count > 0)
- --mock_gpio[mock_gpio_count].count;
- else
- ++mock_gpio_count;
-
- return result;
-}
-
-vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
-{
- vbexlegacy_called++;
- altfw_num = _altfw_num;
-
- /* VbExLegacy() can only return failure, or not return at all. */
- return VB2_ERROR_UNKNOWN;
-}
-
-void vb2ex_msleep(uint32_t msec)
-{
- current_ticks += msec;
-}
-
-uint32_t vb2ex_mtime(void)
-{
- return current_ticks;
-}
-
-vb2_error_t VbExDiskGetInfo(VbDiskInfo **infos_ptr, uint32_t *count,
- uint32_t disk_flags)
-{
- if (mock_num_disks_count < ARRAY_SIZE(mock_num_disks)) {
- if (mock_num_disks[mock_num_disks_count] == -1)
- return VB2_ERROR_MOCK;
- else
- *count = mock_num_disks[mock_num_disks_count++];
- } else {
- *count = 0;
- }
- return VB2_SUCCESS;
-}
-
-vb2_error_t VbExDiskFreeInfo(VbDiskInfo *infos,
- VbExDiskHandle_t preserve_handle)
-{
- return VB2_SUCCESS;
-}
-
-int vb2ex_ec_trusted(void)
-{
- return trust_ec;
-}
-
-int vb2_audio_looping(void)
-{
- if (audio_looping_calls_left == 0)
- return 0;
- else if (audio_looping_calls_left > 0)
- audio_looping_calls_left--;
-
- return 1;
-}
-
-vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
-{
- /*
- * TODO: Currently we don't have a good way of testing for an ordered
- * sequence of VB_DISK_FLAG_FIXED and then VB_DISK_FLAG_REMOVABLE. If
- * both are set, then just assume success.
- */
- if (vbtlk_expect_fixed && vbtlk_expect_removable)
- return vbtlk_retval;
-
- TEST_EQ(!!vbtlk_expect_fixed,
- !!(get_info_flags & VB_DISK_FLAG_FIXED),
- " VbTryLoadKernel unexpected fixed disk call");
- TEST_EQ(!!vbtlk_expect_removable,
- !!(get_info_flags & VB_DISK_FLAG_REMOVABLE),
- " VbTryLoadKernel unexpected removable disk call");
-
- return vbtlk_retval;
-}
-
-vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force,
- const VbScreenData *data)
-{
- if (screens_count < ARRAY_SIZE(screens_displayed))
- screens_displayed[screens_count++] = screen;
-
- return VB2_SUCCESS;
-}
-
-void vb2_enable_developer_mode(struct vb2_context *c)
-{
- VB2_ASSERT(!virtdev_fail);
- virtdev_set = 1;
-}
-
-vb2_error_t VbExSetVendorData(const char *vendor_data_value)
-{
- set_vendor_data_called = 1;
- /*
- * set_vendor_data is a global variable, so it is automatically
- * initialized to zero, and so the -1 will ensure the string is null
- * terminated.
- */
- strncpy(set_vendor_data, vendor_data_value, sizeof(set_vendor_data) - 1);
-
- return VB2_SUCCESS;
-}
-
-vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
-{
- tpm_set_mode_called = 1;
-
- /* Fail if the TPM is already disabled. */
- if (tpm_mode == VB2_TPM_MODE_DISABLED)
- return VB2_ERROR_UNKNOWN;
-
- tpm_mode = mode_val;
- return VB2_SUCCESS;
-}
-
-/* Tests */
-
-/*
- * Helper function to test VbUserConfirms against a sequence of gpio events.
- * caller specifies a sequence of gpio events and the expected confirm vs.
- * reboot result.
- *
- * Non-asserted gpios are used for 5 events, then 'first' for 5 events,
- * 'second' for 5 events, and 'third' for 5 events.
- * Typically most tests want 5 events of each type (so they'll specify 0 for
- * 'first' and use 'second' through 'fourth'), but a few tests want the
- * shutdown event to be seen once.
- */
-static void VbUserConfirmsTestGpio(uint32_t first, uint32_t second,
- uint32_t third, uint32_t confirm,
- const char *msg)
-{
- ResetMocks();
- mock_gpio[0].gpio_flags = 0;
- mock_gpio[0].count = 4;
- mock_gpio[1].gpio_flags = first;
- mock_gpio[1].count = 4;
- mock_gpio[2].gpio_flags = second;
- mock_gpio[2].count = 4;
- mock_gpio[3].gpio_flags = third;
- mock_gpio[3].count = 4;
- if (confirm) {
- TEST_EQ(VbUserConfirms(ctx,
- VB_CONFIRM_SPACE_MEANS_NO |
- VB_CONFIRM_MUST_TRUST_KEYBOARD),
- 1, msg);
- } else {
- TEST_EQ(VbUserConfirms(ctx,
- VB_CONFIRM_SPACE_MEANS_NO |
- VB_CONFIRM_MUST_TRUST_KEYBOARD),
- -1, msg);
- }
-}
-
-static void VbUserConfirmsKeyboardTest(void)
-{
- VB2_DEBUG("Testing VbUserConfirms()...\n");
-
- ResetMocks();
- MockGpioAfter(1, GPIO_SHUTDOWN);
- TEST_EQ(VbUserConfirms(ctx, 0), -1, "Shutdown requested");
-
- ResetMocks();
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbUserConfirms(ctx, 0), -1, "Shutdown requested");
-
- ResetMocks();
- mock_keypress[0] = VB_KEY_ENTER;
- TEST_EQ(VbUserConfirms(ctx, 0), 1, "Enter");
-
- ResetMocks();
- mock_keypress[0] = VB_KEY_ESC;
- TEST_EQ(VbUserConfirms(ctx, 0), 0, "Esc");
-
- ResetMocks();
- mock_keypress[0] = ' ';
- MockGpioAfter(1, GPIO_SHUTDOWN);
- TEST_EQ(VbUserConfirms(ctx, VB_CONFIRM_SPACE_MEANS_NO), 0,
- "Space means no");
-
- ResetMocks();
- mock_keypress[0] = ' ';
- MockGpioAfter(1, GPIO_SHUTDOWN);
- TEST_EQ(VbUserConfirms(ctx, 0), -1, "Space ignored");
-
- ResetMocks();
- mock_keypress[0] = VB_KEY_ENTER;
- mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- TEST_EQ(VbUserConfirms(ctx, VB_CONFIRM_MUST_TRUST_KEYBOARD),
- 1, "Enter with trusted keyboard");
-
- ResetMocks();
- mock_keypress[0] = VB_KEY_ENTER; /* untrusted */
- mock_keypress[1] = ' ';
- TEST_EQ(VbUserConfirms(ctx,
- VB_CONFIRM_SPACE_MEANS_NO |
- VB_CONFIRM_MUST_TRUST_KEYBOARD),
- 0, "Untrusted keyboard");
-
- ResetMocks();
- mock_keypress[0] = VB_KEY_ENTER;
- mock_keypress[1] = 'y';
- mock_keypress[2] = 'z';
- mock_keypress[3] = ' ';
- mock_gpio[0].gpio_flags = GPIO_PRESENCE;
- mock_gpio[0].count = ~0;
- TEST_EQ(VbUserConfirms(ctx,
- VB_CONFIRM_SPACE_MEANS_NO |
- VB_CONFIRM_MUST_TRUST_KEYBOARD),
- 0, "Recovery button stuck");
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbUserConfirmsPhysicalPresenceTest(void)
-{
- ResetMocks();
- MockGpioAfter(0, GPIO_PRESENCE);
- TEST_EQ(VbUserConfirms(ctx,
- VB_CONFIRM_SPACE_MEANS_NO |
- VB_CONFIRM_MUST_TRUST_KEYBOARD),
- 1, "Presence button");
-
- /*
- * List of possiblities for shutdown and physical presence events that
- * occur over time. Time advanced from left to right (where each
- * represents the gpio[s] that are seen during a given iteration of
- * the loop). The meaning of the characters:
- *
- * _ means no gpio
- * s means shutdown gpio
- * p means presence gpio
- * B means both shutdown and presence gpio
- *
- * 1: ______ppp______ -> confirm
- * 2: ______sss______ -> shutdown
- * 3: ___pppsss______ -> confirm
- * 4: ___sssppp______ -> shutdown
- * 5: ___pppBBB______ -> confirm
- * 6: ___pppBBBppp___ -> shutdown
- * 7: ___pppBBBsss___ -> confirm
- * 8: ___sssBBB______ -> confirm
- * 9: ___sssBBBppp___ -> shutdown
- * 10: ___sssBBBsss___ -> confirm
- * 11: ______BBB______ -> confirm
- * 12: ______BBBsss___ -> confirm
- * 13: ______BBBppp___ -> shutdown
- */
-
- /* 1: presence means confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE, 0, 0, 1, "presence");
-
- /* 2: shutdown means shutdown */
- VbUserConfirmsTestGpio(GPIO_SHUTDOWN, 0, 0, 0, "shutdown");
-
- /* 3: presence then shutdown means confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_SHUTDOWN, 0, 1,
- "presence then shutdown");
-
- /* 4: shutdown then presence means shutdown */
- VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0,
- "shutdown then presence");
-
- /* 5: presence then shutdown+presence then none mean confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN,
- 0, 1, "presence, both, none");
-
- /* 6: presence then shutdown+presence then presence means shutdown */
- VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_PRESENCE, 0, "presence, both, presence");
-
- /* 7: presence then shutdown+presence then shutdown means confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_SHUTDOWN, 1, "presence, both, shutdown");
-
- /* 8: shutdown then shutdown+presence then none means confirm */
- VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN,
- 0, 1, "shutdown, both, none");
-
- /* 9: shutdown then shutdown+presence then presence means shutdown */
- VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_PRESENCE, 0, "shutdown, both, presence");
-
- /* 10: shutdown then shutdown+presence then shutdown means confirm */
- VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_SHUTDOWN, 1, "shutdown, both, shutdown");
-
- /* 11: shutdown+presence then none means confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 0, 1,
- "both");
-
- /* 12: shutdown+presence then shutdown means confirm */
- VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_SHUTDOWN, 0, 1, "both, shutdown");
-
- /* 13: shutdown+presence then presence means shutdown */
- VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_PRESENCE, 0, 0, "both, presence");
-
-}
-
-static void VbBootDevTest(void)
-{
- int key;
-
- VB2_DEBUG("Testing VbBootDeveloperLegacyClamshell()...\n");
-
- /* Proceed after timeout */
- ResetMocks();
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING,
- " warning screen");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
-
- /* Proceed to legacy after timeout if GBB flag set */
- ResetMocks();
- gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY |
- VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Proceed to legacy after timeout if GBB flag set */
- ResetMocks();
- gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY |
- VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Proceed to legacy after timeout if boot legacy and default boot
- legacy are set */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_LEGACY);
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Proceed to legacy boot mode only if enabled */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_LEGACY);
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Proceed to external disk after timeout if boot external and default
- * boot external are set */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vbtlk_retval = VB2_SUCCESS;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), 0, "Ctrl+U external");
-
- /* Proceed to external boot mode only if enabled */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Timeout");
-
- /* If no external tries fixed disk */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- vbtlk_expect_fixed = 1;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+U enabled");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Up arrow is uninteresting / passed to VbCheckDisplayKey() */
- ResetMocks();
- mock_keypress[0] = VB_KEY_UP;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Up arrow");
-
- /* Shutdown requested in loop */
- ResetMocks();
- mock_gpio[0].gpio_flags = 0;
- mock_gpio[0].count = 2;
- mock_gpio[1].gpio_flags = GPIO_SHUTDOWN;
- mock_gpio[1].count = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
-
- /* Shutdown requested by keyboard in loop */
- ResetMocks();
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested by keyboard");
-
- /* Space asks to disable virtual dev switch */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = ' ';
- mock_keypress[1] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Space = tonorm");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_TO_NORM_CONFIRMED,
- " confirm screen");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
- " disable dev request");
-
- /* Space-space doesn't disable it */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = ' ';
- mock_keypress[1] = ' ';
- mock_keypress[2] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Space-space");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING,
- " warning screen");
-
- /* Enter doesn't by default */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = VB_KEY_ENTER;
- mock_keypress[1] = VB_KEY_ENTER;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter ignored");
-
- /* Enter does if GBB flag set */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- gbb.flags |= VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM;
- mock_keypress[0] = VB_KEY_ENTER;
- mock_keypress[1] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter = tonorm");
-
- /* Tonorm ignored if GBB forces dev switch on */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON;
- mock_keypress[0] = ' ';
- mock_keypress[1] = VB_KEY_ENTER;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Can't tonorm gbb-dev");
-
- /* Shutdown requested at tonorm screen */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = ' ';
- MockGpioAfter(3, GPIO_SHUTDOWN);
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested at tonorm");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
-
- /* Shutdown requested by keyboard at tonorm screen */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested by keyboard at nonorm");
-
- /* Ctrl+D dismisses warning */
- ResetMocks();
- mock_keypress[0] = VB_KEY_CTRL('D');
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Ctrl+D");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Ctrl+D doesn't boot legacy even if GBB flag is set */
- ResetMocks();
- mock_keypress[0] = VB_KEY_CTRL('D');
- gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK, "Ctrl+D");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Ctrl+L tries legacy boot mode only if enabled */
- ResetMocks();
- mock_keypress[0] = VB_KEY_CTRL('L');
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L normal");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Enter altfw menu and time out */
- ResetMocks();
- MockGpioAfter(1000, GPIO_SHUTDOWN);
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = VB_KEY_CTRL('L');
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_SHUTDOWN,
- "Ctrl+L force legacy");
- TEST_EQ(vbexlegacy_called, 0, " try legacy");
-
- /* Enter altfw menu and select firmware 0 */
- ResetMocks();
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = '0';
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L force legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Enter altfw menu and then exit it */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L nv legacy");
- TEST_EQ(vbexlegacy_called, 0, " try legacy");
-
- /* Enter altfw menu and select firmware 0 */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = '0';
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L nv legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Enter altfw menu and select firmware 0 */
- ResetMocks();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_LEGACY;
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = '0';
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L fwmp legacy");
- TEST_EQ(vbexlegacy_called, 1, " fwmp legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
-
- /* Pressing 1-9 boots alternative firmware only if enabled */
- for (key = '1'; key <= '9'; key++) {
- ResetMocks();
- mock_keypress[0] = key;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "'1' normal");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- ResetMocks();
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = key;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L force legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, key - '0', " check altfw_num");
-
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = key;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L nv legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, key - '0', " check altfw_num");
-
- ResetMocks();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_LEGACY;
- mock_keypress[0] = key;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+L fwmp legacy");
- TEST_EQ(vbexlegacy_called, 1, " fwmp legacy");
- TEST_EQ(altfw_num, key - '0', " check altfw_num");
- }
-
- /* Ctrl+U boots external only if enabled */
- ResetMocks();
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+U normal");
-
- /* Ctrl+U enabled, with good external boot */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval = VB2_SUCCESS;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), 0, "Ctrl+U external");
-
- /* Ctrl+U enabled via GBB */
- ResetMocks();
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_USB;
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval = VB2_SUCCESS;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), 0, "Ctrl+U force external");
-
- /* Ctrl+U enabled via FWMP */
- ResetMocks();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_EXTERNAL;
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval = VB2_SUCCESS;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), 0, "Ctrl+U force external");
-
- /* If no external disk, eventually times out and tries internal disk */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_KEY_CTRL('U');
- /* TODO: Currently the test suite has no way of specifying the order in
- which the expected VbTryLoadKernel calls occur. */
- vbtlk_expect_fixed = 1;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Ctrl+U enabled");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
-
- /* If dev mode is disabled, goes to TONORM screen repeatedly */
- ResetMocks();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- mock_keypress[0] = VB_KEY_ESC; /* Just causes TONORM again */
- mock_keypress[1] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "FWMP dev disabled");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_TO_NORM_CONFIRMED,
- " confirm screen");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
- " disable dev request");
-
- /* Shutdown requested when dev disabled */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- MockGpioAfter(1, GPIO_SHUTDOWN);
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested when dev disabled");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM,
- " tonorm screen");
-
- /* Shutdown requested by keyboard when dev disabled */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_DEV_MODE_ENABLED;
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested by keyboard when dev disabled");
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbBootDevVendorDataTest(void)
-{
- /* Enter set vendor data and reboot */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[6] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data, don't confirm, esc");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct");
-
- /* Enter set vendor data; don't confirm and esc */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[6] = VB_KEY_RIGHT; /* Select NO */
- mock_keypress[7] = VB_KEY_ENTER; /* Do not confirm vendor data */
- mock_keypress[8] = VB_KEY_ESC; /* Escape to boot */
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data, don't confirm, esc");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- /* Enter set vendor data; esc, don't confirm, and change last character */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = VB_KEY_ENTER;
- mock_keypress[6] = VB_KEY_RIGHT; /* Select NO */
- mock_keypress[7] = VB_KEY_ENTER; /* Do not confirm vendor data */
- mock_keypress[8] = VB_KEY_BACKSPACE; /* Remove last character */
- mock_keypress[9] = 'B';
- mock_keypress[10] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[11] = VB_KEY_ENTER; /* Confirm vendor data */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data esc, don't confirm, change last character");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "432B", " Vendor data correct");
-
- /* Enter set vendor data; extra keys ignored */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = '5';
- mock_keypress[6] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[7] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data extra keys ignored");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct");
-
- /* Enter set vendor data; converts case */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = 'a';
- mock_keypress[2] = 'B';
- mock_keypress[3] = 'Y';
- mock_keypress[4] = 'z';
- mock_keypress[5] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[6] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data converts case");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "ABYZ", " Vendor data correct");
-
- /* Enter set vendor data; backspace works */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = 'A';
- mock_keypress[2] = 'B';
- mock_keypress[3] = 'C';
- mock_keypress[4] = VB_KEY_BACKSPACE;
- mock_keypress[5] = VB_KEY_BACKSPACE;
- mock_keypress[6] = '3';
- mock_keypress[7] = '2';
- mock_keypress[8] = '1';
- mock_keypress[9] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[10] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data backspace works");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "A321", " Vendor data correct");
-
- /* Enter set vendor data; invalid chars don't print */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '-';
- mock_keypress[3] = '^';
- mock_keypress[4] = '&';
- mock_keypress[5] = '$';
- mock_keypress[6] = '.';
- mock_keypress[7] = '3';
- mock_keypress[8] = '2';
- mock_keypress[9] = '1';
- mock_keypress[10] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[11] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data invalid chars don't print");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct");
-
- /* Enter set vendor data; invalid chars don't print with backspace */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '-';
- mock_keypress[3] = VB_KEY_BACKSPACE; /* Should delete 4 */
- mock_keypress[4] = '3';
- mock_keypress[5] = '2';
- mock_keypress[6] = '1';
- mock_keypress[7] = '0';
- mock_keypress[8] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[9] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data invalid chars don't print with backspace");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "3210", " Vendor data correct");
-
- /* Enter set vendor data; backspace only doesn't underrun */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = 'A';
- mock_keypress[2] = VB_KEY_BACKSPACE;
- mock_keypress[3] = VB_KEY_BACKSPACE;
- mock_keypress[4] = '4';
- mock_keypress[5] = '3';
- mock_keypress[6] = '2';
- mock_keypress[7] = '1';
- mock_keypress[8] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[9] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data backspace only doesn't underrun");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct");
-
- /* Enter set vendor data; vowels not allowed after first char */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = 'A';
- mock_keypress[2] = 'A';
- mock_keypress[3] = 'B';
- mock_keypress[4] = 'E';
- mock_keypress[5] = 'i';
- mock_keypress[6] = 'C';
- mock_keypress[7] = 'O';
- mock_keypress[8] = 'u';
- mock_keypress[9] = 'D';
- mock_keypress[10] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[11] = VB_KEY_ENTER; /* Confirm vendor data (Default YES) */
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Enter set vendor data vowels not allowed after first char");
- TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called");
- TEST_STR_EQ(set_vendor_data, "ABCD", " Vendor data correct");
-
- /* Enter set vendor data; too short */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '1';
- mock_keypress[2] = '2';
- mock_keypress[3] = '3';
- /* Set vendor data (nothing happens) */
- mock_keypress[4] = VB_KEY_ENTER;
- /* Confirm vendor data (nothing happens) */
- mock_keypress[5] = VB_KEY_ENTER;
- mock_keypress[6] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data too short");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- /* Enter set vendor data; esc from set screen */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data esc from set screen");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- /* Enter set vendor data; esc from set screen with tag */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data esc from set screen with tag");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- /* Enter set vendor data; esc from confirm screen */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ENTER; /* Enter vendor data setting */
- mock_keypress[1] = '4';
- mock_keypress[2] = '3';
- mock_keypress[3] = '2';
- mock_keypress[4] = '1';
- mock_keypress[5] = VB_KEY_ENTER; /* Set vendor data */
- mock_keypress[6] = VB_KEY_ESC;
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data esc from set screen");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- /* Escape from vendor data warning screen */
- ResetMocks();
- ctx->flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE;
- mock_keypress[0] = VB_KEY_ESC; /* Enter vendor data setting */
- vbtlk_expect_fixed = 1;
- TEST_EQ(VbBootDeveloperLegacyClamshell(ctx), VB2_ERROR_MOCK,
- "Enter set vendor data esc, don't confirm, change last character");
- TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called");
-
- VB2_DEBUG("...done.\n");
-}
-
-/*
- * Helper function to test VbBootRecovery against a sequence of gpio events.
- * caller specifies a sequence of gpio events and the expected confirm vs.
- * reboot result.
- *
- * Non-asserted gpios are used for 5 events, then 'first' for 5 events,
- * 'second' for 5 events, and 'third' for 5 events.
- */
-static void VbBootRecTestGpio(uint32_t first, uint32_t second, uint32_t third,
- uint32_t confirm, const char *msg)
-{
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- trust_ec = 1;
- mock_keypress[0] = VB_KEY_CTRL('D');
- mock_gpio[0].gpio_flags = 0;
- mock_gpio[0].count = 4;
- mock_gpio[1].gpio_flags = first;
- mock_gpio[1].count = 4;
- mock_gpio[2].gpio_flags = second;
- mock_gpio[2].count = 4;
- mock_gpio[3].gpio_flags = third;
- mock_gpio[3].count = 4;
- vbtlk_expect_removable = 1;
-
- if (confirm) {
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_REBOOT_EC_TO_RO, msg);
- TEST_EQ(virtdev_set, 1, " virtual dev mode on");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DEV_BOOT_EXTERNAL),
- !!BOOT_EXTERNAL_ON_DEV,
- " NV_DEV_BOOT_EXTERNAL enabled");
- } else {
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN, msg);
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- }
-}
-
-static void VbBootRecTest(void)
-{
- VB2_DEBUG("Testing VbBootRecoveryLegacyClamshell()...\n");
-
- /* Shutdown requested in loop */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested");
-
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Shutdown requested by keyboard */
- ResetMocks();
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Shutdown requested by keyboard");
-
- /* Ignore power button held on boot */
- ResetMocks();
- mock_gpio[0].gpio_flags = GPIO_SHUTDOWN;
- mock_gpio[0].count = 10;
- mock_gpio[1].gpio_flags = 0;
- mock_gpio[1].count = 10;
- mock_gpio[2].gpio_flags = GPIO_SHUTDOWN;
- mock_gpio[2].count = 10;
- mock_gpio[3].gpio_flags = 0;
- mock_gpio[3].count = 100;
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- trust_ec = 1;
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ignore power button held on boot");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- /* Shutdown should happen while we're sending the 2nd block of events */
-
- /* Broken screen */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_num_disks[0] = 1;
- mock_num_disks[1] = 1;
- mock_num_disks[2] = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Broken");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Broken screen even if dev switch is on */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_num_disks[0] = 1;
- mock_num_disks[1] = 1;
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Broken (dev)");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Force insert screen with GBB flag */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- gbb.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY;
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Insert (forced by GBB)");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
-
- /* No removal if recovery button physically pressed */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_num_disks[0] = 1;
- mock_num_disks[1] = 1;
- sd->flags |= VB2_SD_FLAG_MANUAL_RECOVERY;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "No remove in rec");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Removal if no disk initially found, but found on second attempt */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_num_disks[0] = 0;
- mock_num_disks[1] = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Remove");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Bad disk count doesn't require removal */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_num_disks[0] = -1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Bad disk count");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
-
- /* Ctrl+D ignored for many reasons... */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_CTRL('D');
- trust_ec = 0;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+D ignored if EC not trusted");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV,
- " todev screen");
-
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY | VB2_SD_FLAG_DEV_MODE_ENABLED;
- trust_ec = 1;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_CTRL('D');
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+D ignored if already in dev mode");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV,
- " todev screen");
-
- ResetMocks();
- trust_ec = 1;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_CTRL('D');
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+D ignored if recovery not manually triggered");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV,
- " todev screen");
-
- /* Ctrl+D then space means don't enable */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- MockGpioAfter(2, GPIO_SHUTDOWN);
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- trust_ec = 1;
- mock_keypress[0] = VB_KEY_CTRL('D');
- mock_keypress[1] = ' ';
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+D todev abort");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV,
- " todev screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
-
- /* Ctrl+D then enter means enable */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- trust_ec = 1;
- mock_keypress[0] = VB_KEY_CTRL('D');
- mock_keypress[1] = VB_KEY_ENTER;
- mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_REBOOT_EC_TO_RO,
- "Ctrl+D todev confirm via enter");
- TEST_EQ(virtdev_set, 1, " virtual dev mode on");
-
- /* Don't handle TPM error in enabling dev mode */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- trust_ec = 1;
- mock_keypress[0] = VB_KEY_CTRL('D');
- mock_keypress[1] = VB_KEY_ENTER;
- mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- virtdev_fail = 1;
- vbtlk_expect_removable = 1;
- TEST_ABORT(VbBootRecoveryLegacyClamshell(ctx),
- "Ctrl+D todev failure");
- TEST_EQ(virtdev_set, 0, " virtual dev mode still off");
-
- /* Test Diagnostic Mode via Ctrl-C - display available */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- trust_ec = 1;
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_CTRL('C');
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), 0,
- "todiag is zero");
- vbtlk_expect_removable = 1;
- if (DIAGNOSTIC_UI)
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_REBOOT,
- "Ctrl+C todiag - enabled");
- else
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+C todiag - disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI,
- " todiag is updated for Ctrl-C");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISPLAY_REQUEST), 0,
- " todiag doesn't set unneeded DISPLAY_REQUEST");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
-
- /* Test Diagnostic Mode via F12 - display disabled */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- sd->flags &= ~VB2_SD_FLAG_DISPLAY_AVAILABLE;
- trust_ec = 1;
- vbtlk_retval = VB2_ERROR_LK_NO_DISK_FOUND;
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_F(12);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), 0,
- "todiag is zero");
- vbtlk_expect_removable = 1;
- if (DIAGNOSTIC_UI)
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_REBOOT,
- "F12 todiag - enabled");
- else
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "F12 todiag - disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI,
- " todiag is updated for F12");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISPLAY_REQUEST), 0,
- " todiag doesn't set unneeded DISPLAY_REQUEST");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
-
- /* Test Diagnostic Mode via Ctrl-C OS broken - display available */
- ResetMocks();
- MockGpioAfter(10, GPIO_SHUTDOWN);
- mock_keypress[0] = VB_KEY_CTRL('C');
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), 0,
- "todiag is zero");
- if (DIAGNOSTIC_UI)
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_REBOOT,
- "Ctrl+C todiag os broken - enabled");
- else
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+C todiag os broken - disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI,
- " todiag is updated for Ctrl-C");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISPLAY_REQUEST), 0,
- " todiag doesn't set unneeded DISPLAY_REQUEST");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " os broken screen");
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbBootRecPhysicalPresenceTest(void)
-{
-
- /* Ctrl+D ignored because the physical presence switch is still pressed
- and we don't like that. */
- ResetMocks();
- sd->flags = VB2_SD_FLAG_MANUAL_RECOVERY;
- trust_ec = 1;
- mock_keypress[0] = VB_KEY_CTRL('D');
- mock_gpio[0].gpio_flags = GPIO_PRESENCE;
- mock_gpio[0].count = 100;
- mock_gpio[1].gpio_flags = GPIO_PRESENCE | GPIO_SHUTDOWN;
- mock_gpio[1].count = 100;
- vbtlk_expect_removable = 1;
- TEST_EQ(VbBootRecoveryLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN,
- "Ctrl+D ignored if phys pres button is still pressed");
- TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV,
- " todev screen");
-
- /*
- * List of possiblities for shutdown and physical presence events that
- * occur over time. Time advanced from left to right (where each
- * represents the gpio[s] that are seen during a given iteration of
- * the loop). The meaning of the characters:
- *
- * _ means no gpio
- * s means shutdown gpio
- * p means presence gpio
- * B means both shutdown and presence gpio
- *
- * 1: ______ppp______ -> confirm
- * 2: ______sss______ -> shutdown
- * 3: ___pppsss______ -> confirm
- * 4: ___sssppp______ -> shutdown
- * 5: ___pppBBB______ -> confirm
- * 6: ___pppBBBppp___ -> shutdown
- * 7: ___pppBBBsss___ -> confirm
- * 8: ___sssBBB______ -> confirm
- * 9: ___sssBBBppp___ -> shutdown
- * 10: ___sssBBBsss___ -> confirm
- * 11: ______BBB______ -> confirm
- * 12: ______BBBsss___ -> confirm
- * 13: ______BBBppp___ -> shutdown
- */
-
- /* 1: Ctrl+D then presence means enable */
- VbBootRecTestGpio(GPIO_PRESENCE, 0, 0, 1,
- "Ctrl+D todev confirm via presence");
-
- /* 2: Ctrl+D then shutdown means shutdown */
- VbBootRecTestGpio(GPIO_SHUTDOWN, 0, 0, 0,
- "Ctrl+D todev then shutdown");
-
- /* 3: Ctrl+D then presence then shutdown means confirm */
- VbBootRecTestGpio(GPIO_PRESENCE, GPIO_SHUTDOWN, 0, 1,
- "Ctrl+D todev confirm via presence then shutdown");
-
- /* 4: Ctrl+D then 2+ instance shutdown then presence means shutdown */
- VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0,
- "Ctrl+D todev then 2+ shutdown then presence");
-
- /* 5: Ctrl+D then presence then shutdown+presence then none */
- VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 1,
- "Ctrl+D todev confirm via presence, both, none");
-
- /* 6: Ctrl+D then presence then shutdown+presence then presence */
- VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_PRESENCE, 0,
- "Ctrl+D todev confirm via presence, both, presence");
-
- /* 7: Ctrl+D then presence then shutdown+presence then shutdown */
- VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_SHUTDOWN, 1,
- "Ctrl+D todev confirm via presence, both, shutdown");
-
- /* 8: Ctrl+D then shutdown then shutdown+presence then none */
- VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 1,
- "Ctrl+D todev then 2+ shutdown, both, none");
-
- /* 9: Ctrl+D then shutdown then shutdown+presence then presence */
- VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_PRESENCE, 0,
- "Ctrl+D todev then 2+ shutdown, both, presence");
-
- /* 10: Ctrl+D then shutdown then shutdown+presence then shutdown */
- VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN,
- GPIO_SHUTDOWN, 1,
- "Ctrl+D todev then 2+ shutdown, both, shutdown");
-
- /* 11: Ctrl+D then shutdown+presence then none */
- VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 0, 1,
- "Ctrl+D todev confirm via both then none");
-
- /* 12: Ctrl+D then shutdown+presence then shutdown */
- VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, GPIO_SHUTDOWN, 0, 1,
- "Ctrl+D todev confirm via both then shutdown");
-
- /* 13: Ctrl+D then shutdown+presence then presence */
- VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0,
- "Ctrl+D todev confirm via both then presence");
-}
-
-static void VbBootDiagTest(void)
-{
- VB2_DEBUG("Testing VbBootDiagnosticLegacyClamshell()...\n");
-
- /* No key pressed - timeout. */
- ResetMocks();
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Timeout");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(current_ticks, 30 * VB2_MSEC_PER_SEC,
- " waited for 30 seconds");
-
- /* Esc key pressed. */
- ResetMocks();
- mock_keypress[0] = VB_KEY_ESC;
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Esc key");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(current_ticks, 0, " didn't wait at all");
-
- /* Shutdown requested via lid close */
- ResetMocks();
- MockGpioAfter(10, GPIO_LID_CLOSED);
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx),
- VB2_REQUEST_SHUTDOWN, "Shutdown");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_TRUE(current_ticks < VB2_MSEC_PER_SEC, " didn't wait long");
-
- /* Power button pressed but not released. */
- ResetMocks();
- mock_gpio[0].gpio_flags = GPIO_PRESENCE;
- mock_gpio[0].count = ~0;
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Power held");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Power button is pressed and released. */
- ResetMocks();
- MockGpioAfter(3, GPIO_PRESENCE);
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Confirm");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 1, " tpm call");
- TEST_EQ(tpm_mode, VB2_TPM_MODE_DISABLED, " tpm disabled");
- TEST_EQ(vbexlegacy_called, 1, " legacy");
- TEST_EQ(altfw_num, VB_ALTFW_DIAGNOSTIC, " check altfw_num");
- /*
- * Ideally we'd that no recovery request was recorded, but
- * VbExLegacy() can only fail or crash the tests.
- */
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST),
- VB2_RECOVERY_ALTFW_HASH_FAILED,
- " recovery request");
-
- /* Power button confirm, but now with a TPM failure. */
- ResetMocks();
- tpm_mode = VB2_TPM_MODE_DISABLED;
- mock_gpio[0].gpio_flags = 0;
- mock_gpio[0].count = 2;
- mock_gpio[1].gpio_flags = GPIO_PRESENCE;
- mock_gpio[1].count = 2;
- TEST_EQ(VbBootDiagnosticLegacyClamshell(ctx), VB2_REQUEST_REBOOT,
- "Confirm but tpm fail");
- TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG,
- " confirm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK,
- " blank screen");
- TEST_EQ(tpm_set_mode_called, 1, " tpm call");
- TEST_EQ(tpm_mode, VB2_TPM_MODE_DISABLED, " tpm disabled");
- TEST_EQ(vbexlegacy_called, 0, " legacy not called");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST),
- VB2_RECOVERY_TPM_DISABLE_FAILED,
- " recovery request");
-
- VB2_DEBUG("...done.\n");
-}
-
-
-int main(void)
-{
- VbUserConfirmsKeyboardTest();
- if (!PHYSICAL_PRESENCE_KEYBOARD)
- VbUserConfirmsPhysicalPresenceTest();
- VbBootDevTest();
- VbBootDevVendorDataTest();
- VbBootRecTest();
- if (!PHYSICAL_PRESENCE_KEYBOARD)
- VbBootRecPhysicalPresenceTest();
- if (DIAGNOSTIC_UI)
- VbBootDiagTest();
-
- return gTestSuccess ? 0 : 255;
-}
diff --git a/tests/vboot_ui_legacy_menu_tests.c b/tests/vboot_ui_legacy_menu_tests.c
deleted file mode 100644
index 1dc92535..00000000
--- a/tests/vboot_ui_legacy_menu_tests.c
+++ /dev/null
@@ -1,2349 +0,0 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests legacy menu UI
- */
-
-#include "2common.h"
-#include "2misc.h"
-#include "2nvstorage.h"
-#include "2secdata.h"
-#include "2secdata_struct.h"
-#include "host_common.h"
-#include "load_kernel_fw.h"
-#include "test_common.h"
-#include "tss_constants.h"
-#include "vboot_api.h"
-#include "vboot_audio.h"
-#include "vboot_kernel.h"
-#include "vboot_struct.h"
-#include "vboot_test.h"
-#include "vboot_ui_legacy.h"
-#include "vboot_ui_legacy_menu_private.h"
-
-/* Mock data */
-static LoadKernelParams lkp;
-static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]
- __attribute__((aligned(VB2_WORKBUF_ALIGN)));
-static struct vb2_context *ctx;
-static struct vb2_shared_data *sd;
-static struct vb2_gbb_header gbb;
-static struct vb2_secdata_fwmp *fwmp;
-
-static int shutdown_request_calls_left;
-static int audio_looping_calls_left;
-static vb2_error_t vbtlk_retval[5];
-static vb2_error_t vbtlk_last_retval;
-static int vbtlk_retval_count;
-static const vb2_error_t vbtlk_retval_fixed = 1002;
-static int vbexlegacy_called;
-static enum VbAltFwIndex_t altfw_num;
-static int debug_info_displayed;
-static int trust_ec;
-static int virtdev_set;
-static uint32_t virtdev_fail;
-static uint32_t mock_keypress[64];
-static uint32_t mock_keyflags[64];
-static uint32_t mock_keypress_count;
-static uint32_t screens_displayed[64];
-static uint32_t screens_count = 0;
-static uint32_t beeps_played[64];
-static uint32_t beeps_count = 0;
-static uint32_t mock_altfw_mask;
-static int vbexaltfwmask_called;
-
-/* Reset mock data (for use before each test) */
-static void ResetMocks(void)
-{
- memset(&lkp, 0, sizeof(lkp));
-
- TEST_SUCC(vb2api_init(workbuf, sizeof(workbuf), &ctx),
- "vb2api_init failed");
- vb2_nv_init(ctx);
-
- sd = vb2_get_sd(ctx);
-
- /* CRC will be invalid after here, but nobody's checking */
- sd->status |= VB2_SD_STATUS_SECDATA_FWMP_INIT;
- fwmp = (struct vb2_secdata_fwmp *)ctx->secdata_fwmp;
-
- memset(&gbb, 0, sizeof(gbb));
-
- /* In recovery we have 50 keyscans per disk scan, this must be high. */
- shutdown_request_calls_left = 301;
- audio_looping_calls_left = 60;
- vbexlegacy_called = 0;
- altfw_num = -100;
- debug_info_displayed = 0;
- trust_ec = 0;
- virtdev_set = 0;
- virtdev_fail = 0;
-
- vbtlk_last_retval = vbtlk_retval_fixed - VB_DISK_FLAG_FIXED;
- memset(vbtlk_retval, 0, sizeof(vbtlk_retval));
- vbtlk_retval_count = 0;
-
- memset(screens_displayed, 0, sizeof(screens_displayed));
- screens_count = 0;
- memset(beeps_played, 0, sizeof(beeps_played));
- beeps_count = 0;
-
- memset(mock_keypress, 0, sizeof(mock_keypress));
- memset(mock_keyflags, 0, sizeof(mock_keyflags));
- mock_keypress_count = 0;
-
- mock_altfw_mask = 3 << 1; /* This mask selects 1 and 2 */
- vbexaltfwmask_called = 0;
-}
-
-static void ResetMocksForDeveloper(void)
-{
- ResetMocks();
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- shutdown_request_calls_left = -1;
-}
-
-static void ResetMocksForManualRecovery(void)
-{
- ResetMocks();
- sd->flags |= VB2_SD_FLAG_MANUAL_RECOVERY;
- trust_ec = 1;
-}
-
-/* Mock functions */
-
-struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
-{
- return &gbb;
-}
-
-uint32_t vb2ex_get_locale_count(void) {
- return 1;
-}
-
-uint32_t VbExGetAltFwIdxMask() {
-
- vbexaltfwmask_called++;
-
- return mock_altfw_mask;
-}
-
-uint32_t VbExIsShutdownRequested(void)
-{
- if (shutdown_request_calls_left == 0)
- return 1;
- else if (shutdown_request_calls_left > 0)
- shutdown_request_calls_left--;
-
- return 0;
-}
-
-uint32_t VbExKeyboardRead(void)
-{
- return VbExKeyboardReadWithFlags(NULL);
-}
-
-uint32_t VbExKeyboardReadWithFlags(uint32_t *key_flags)
-{
- if (mock_keypress_count < ARRAY_SIZE(mock_keypress)) {
- if (key_flags != NULL)
- *key_flags = mock_keyflags[mock_keypress_count];
- return mock_keypress[mock_keypress_count++];
- } else
- return 0;
-}
-
-vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
-{
- vbexlegacy_called++;
- altfw_num = _altfw_num;
-
- return 0;
-}
-
-int vb2ex_ec_trusted(void)
-{
- return trust_ec;
-}
-
-int vb2_audio_looping(void)
-{
- if (audio_looping_calls_left == 0)
- return 0;
- else if (audio_looping_calls_left > 0)
- audio_looping_calls_left--;
-
- return 1;
-}
-
-vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
-{
- if (vbtlk_retval_count < ARRAY_SIZE(vbtlk_retval) &&
- vbtlk_retval[vbtlk_retval_count] != 0)
- vbtlk_last_retval = vbtlk_retval[vbtlk_retval_count++];
- return vbtlk_last_retval + get_info_flags;
-}
-
-vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force,
- const VbScreenData *data)
-{
- if (screens_count < ARRAY_SIZE(screens_displayed))
- screens_displayed[screens_count++] = screen;
- VB2_DEBUG("screens_displayed[%d] = %#x\n",
- screens_count - 1, screen);
- return VB2_SUCCESS;
-}
-
-vb2_error_t VbDisplayMenu(struct vb2_context *c, uint32_t screen, int force,
- uint32_t selected_index, uint32_t disabled_idx_mask)
-{
- if (screens_count < ARRAY_SIZE(screens_displayed))
- screens_displayed[screens_count++] = screen;
- else
- VB2_DEBUG("Ran out of screens_displayed entries!\n");
- VB2_DEBUG("screens_displayed[%d] = %#x,"
- " selected_index = %u, disabled_idx_mask = %#x\n",
- screens_count - 1, screen,
- selected_index, disabled_idx_mask);
-
- return VB2_SUCCESS;
-}
-
-vb2_error_t VbDisplayDebugInfo(struct vb2_context *c)
-{
- debug_info_displayed = 1;
- return VB2_SUCCESS;
-}
-
-void vb2ex_beep(uint32_t msec, uint32_t frequency)
-{
- if (beeps_count < ARRAY_SIZE(beeps_played))
- beeps_played[beeps_count++] = frequency;
- VB2_DEBUG("beeps_played[%d] = %dHz for %dms\n",
- beeps_count - 1, frequency, msec);
-}
-
-void vb2_enable_developer_mode(struct vb2_context *c)
-{
- VB2_ASSERT(!virtdev_fail);
- virtdev_set = 1;
-}
-
-/* Tests */
-
-static void VbBootDevTest(void)
-{
- int i;
-
- VB2_DEBUG("Testing VbBootDeveloperLegacyMenu()...\n");
-
- /* Proceed after timeout */
- ResetMocksForDeveloper();
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed, "Timeout");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 0, " no beeps on normal boot");
-
- /* Proceed to legacy after timeout if GBB flag set */
- ResetMocksForDeveloper();
- gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY |
- VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "default legacy GBB");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Proceed to legacy after timeout if boot legacy and default boot
- * legacy are set */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_LEGACY);
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "default legacy NV");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 0, " check altfw_num");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Proceed to legacy boot mode only if enabled */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_LEGACY);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "default legacy not enabled");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 2, " error beeps: legacy boot not enabled");
- TEST_EQ(beeps_played[0], 400, " first error beep");
- TEST_EQ(beeps_played[1], 400, " second error beep");
-
- /* Proceed to usb after timeout if boot usb and default boot
- * usb are set */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), 0, "Ctrl+U USB");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Proceed to usb boot mode only if enabled */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "default USB not enabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 2, " error beeps: USB boot not enabled");
- TEST_EQ(beeps_played[0], 400, " first error beep");
- TEST_EQ(beeps_played[1], 400, " second error beep");
-
- /* If no USB tries fixed disk */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "default USB with no disk");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 1, " error beep: USB not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Shutdown requested in loop */
- ResetMocksForDeveloper();
- shutdown_request_calls_left = 2;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /*
- * Pushing power should shut down the DUT because default
- * selection is power off
- */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "dev warning menu: default to power off");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Selecting Power Off in developer options. */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Power Off in DEVELOPER");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Pressing ENTER is equivalent to power button. */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "dev warning menu: ENTER is power button");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* ENTER functionality is unaffected by GBB flag in detachable UI. */
- ResetMocksForDeveloper();
- gbb.flags |= VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM;
- mock_keypress[0] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "dev warning menu: ENTER unaffected by GBB");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Pressing SPACE or VolUp+Down combo has no effect in dev mode */
- ResetMocksForDeveloper();
- mock_keypress[0] = ' ';
- mock_keypress[1] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS;
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS; // select Power Off
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "SPACE or VolUp+Down have no effect");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Disable developer mode */
- ResetMocksForDeveloper();
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_REBOOT,
- "disable developer mode");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_TO_NORM_CONFIRMED,
- " confirm screen");
- TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 5, " no extra screens");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
- " disable dev request");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on reboot");
-
- /* Tonorm ignored if GBB forces dev switch on */
- ResetMocksForDeveloper();
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON;
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Can't tonorm gbb-dev");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: power off");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " wanring screen: enable verification");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen: confirm");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK,
- " blank (error flash)");
- TEST_EQ(screens_displayed[4], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen: confirm");
- TEST_EQ(screens_displayed[5], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 6, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Shutdown requested at tonorm screen */
- ResetMocksForDeveloper();
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS;
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- shutdown_request_calls_left = 2;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested at tonorm");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " developer warning screen: power off");
- TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " developer warning screen: enable root verification");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " developer warning screen: power off");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on shutdown");
-
- /* Ctrl+D dismisses warning */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_KEY_CTRL('D');
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed, "Ctrl+D");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on normal boot");
-
- /* Ctrl+D doesn't boot legacy even if GBB flag is set */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_KEY_CTRL('D');
- gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed, "Ctrl+D");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
-
- /* Volume-down long press shortcut acts like Ctrl+D */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "VolDown long press");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0,
- " recovery reason");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on normal boot");
-
- /* Ctrl+L tries legacy boot mode only if enabled */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_KEY_CTRL('L');
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+L normal");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Ctrl+L boots legacy if enabled by GBB flag */
- ResetMocksForDeveloper();
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+L force legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(altfw_num, 1, " check altfw_num");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_count, 5, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Ctrl+L boots legacy if enabled by NVRAM */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+L nv legacy");
- TEST_EQ(vbexlegacy_called, 1, " try legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_count, 5, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Ctrl+L boots legacy if enabled by FWMP */
- ResetMocksForDeveloper();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_LEGACY;
- mock_keypress[0] = VB_KEY_CTRL('L');
- mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+L fwmp legacy");
- TEST_EQ(vbexlegacy_called, 1, " fwmp legacy");
- TEST_EQ(altfw_num, 1, " check altfw_num");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[3], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[4], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 5, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* TODO(sjg@chromium.org): Add a test for there being no bootloaders */
-
- /* Ctrl+U boots USB only if enabled */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_KEY_CTRL('U');
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+U not enabled");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Ctrl+U enabled, with good USB boot */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS, "Ctrl+U USB");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Ctrl+U enabled, without valid USB */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_KEY_CTRL('U');
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+U without valid USB");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 1, " error beep: USB not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Ctrl+U enabled via GBB */
- ResetMocksForDeveloper();
- gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_USB;
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "Ctrl+U force USB");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Ctrl+U enabled via FWMP */
- ResetMocksForDeveloper();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_EXTERNAL;
- mock_keypress[0] = VB_KEY_CTRL('U');
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "Ctrl+U force USB");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* If no valid USB, eventually times out and tries fixed disk */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_KEY_CTRL('U');
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Ctrl+U failed - no USB");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: USB not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Now go to USB boot through menus */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "Menu selected USB boot");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* If default USB, the option is preselected */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL);
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "Menu selected USB default boot");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* If invalid USB, we still timeout after selecting it in menu */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Menu selected invalid USB boot");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: USB not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* If USB is disabled, we error flash/beep from the menu option */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Menu selected disabled USB boot");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Boot Legacy via menu and default */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Enter altfw menu
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Select first option
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // and again
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- vb2_nv_set(ctx, VB2_NV_DEV_DEFAULT_BOOT,
- VB2_DEV_DEFAULT_BOOT_TARGET_LEGACY);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Menu selected legacy boot");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vbexlegacy_called, 2, " tried legacy boot twice");
- TEST_EQ(altfw_num, 0, " check altfw_num");
- TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: legacy boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 2, " two error beeps: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
- TEST_EQ(beeps_played[1], 200, " low-frequency error beep");
-
- /* Refuse to boot legacy via menu if not enabled */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot Legacy BIOS
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Menu selected legacy boot when not enabled");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vbexlegacy_called, 0, " did not attempt legacy boot");
- TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: legacy boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: legacy boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Use volume-up long press shortcut to boot USB */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS, "VolUp USB");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Can boot a valid USB image after failing to boot invalid image */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
- mock_keypress[1] = VB_BUTTON_VOL_UP_LONG_PRESS;
- vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "VolUp USB valid after invalid");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: first USB invalid");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Volume-up long press only works if USB is enabled */
- ResetMocksForDeveloper();
- mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "VolUp not enabled");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Volume-up long press without valid USB will still time out */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- mock_keypress[0] = VB_BUTTON_VOL_UP_LONG_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "VolUp without valid USB");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)");
- TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(audio_looping_calls_left, 0, " used up audio");
- TEST_EQ(beeps_count, 1, " error beep: USB not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-
- /* Volume-up long press works from other menus, like LANGUAGE */
- ResetMocksForDeveloper();
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_EXTERNAL, 1);
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_SUCCESS,
- "VolUp USB from LANGUAGE");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on USB boot");
-
- /* Can disable developer mode through TONORM screen */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enable os verification
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // confirm is the default
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_REBOOT,
- "TONORM via menu");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
- " disable dev request");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning: enable os verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm: confirm");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_TO_NORM_CONFIRMED,
- " confirm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps on reboot");
-
- /* If dev mode is disabled, goes to TONORM screen repeatedly */
- ResetMocksForDeveloper();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- audio_looping_calls_left = 1; /* Confirm audio doesn't tick down. */
- i = 0;
- mock_keypress[i++] = VB_KEY_CTRL('D'); /* Just stays on TONORM and flashes */
- mock_keypress[i++] = VB_KEY_CTRL('U'); /* same */
- mock_keypress[i++] = VB_KEY_CTRL('L'); /* same */
- mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS; /* same */
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS; /* same */
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; /* noop */
- mock_keypress[i++] = VB_KEY_ENTER;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_REBOOT,
- "FWMP dev disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
- " disable dev request");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_TO_NORM_CONFIRMED,
- " confirm screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 10, " 5 * 2 error beeps: booting not allowed");
- TEST_EQ(beeps_played[0], 400, " first error beep");
- TEST_EQ(beeps_played[1], 400, " second error beep");
- TEST_EQ(beeps_played[2], 400, " first error beep");
- TEST_EQ(beeps_played[3], 400, " second error beep");
- TEST_EQ(beeps_played[4], 400, " first error beep");
- TEST_EQ(beeps_played[5], 400, " second error beep");
- TEST_EQ(beeps_played[6], 400, " first error beep");
- TEST_EQ(beeps_played[7], 400, " second error beep");
- TEST_EQ(beeps_played[8], 400, " first error beep");
- TEST_EQ(beeps_played[9], 400, " second error beep");
-
- /* Shutdown requested when dev disabled */
- ResetMocksForDeveloper();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- shutdown_request_calls_left = 1;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested when dev disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 0,
- " did not exit dev mode");
- TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Explicit Power Off when dev disabled */
- ResetMocksForDeveloper();
- fwmp->flags |= VB2_SECDATA_FWMP_DEV_DISABLE_BOOT;
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Power Off when dev disabled");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_DISABLE_DEV_REQUEST), 0,
- " did not exit dev mode");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen: confirm enabling OS verification");
- /* Cancel option is removed with dev_disable_boot! */
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " tonorm screen: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps for power off");
-
- /* Show Debug Info displays debug info, then times out to boot */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS Verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Show Debug Info");
- TEST_EQ(debug_info_displayed, 1, " debug info displayed");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps for debug info");
-
- /* Pressing Tab displays debug info, then times out to boot */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = '\t';
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "Show Debug Info (Tab shortcut)");
- TEST_EQ(debug_info_displayed, 1, " debug info displayed");
- TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(audio_looping_calls_left, 0, " audio timed out");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps for debug info");
-
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbBootRecTest(void)
-{
- int i;
-
- VB2_DEBUG("Testing VbBootRecoveryLegacyMenu()...\n");
-
- /* Shutdown requested in BROKEN */
- ResetMocks();
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in BROKEN");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
- TEST_EQ(vbexaltfwmask_called, 0, " VbExGetAltFwIdxMask not called");
-
- /* BROKEN screen with disks inserted */
- ResetMocks();
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[2] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[3] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in BROKEN with disks");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* BROKEN screen with disks on second attempt */
- ResetMocks();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in BROKEN with later disk");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* BROKEN screen even if dev switch is on */
- ResetMocks();
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[2] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in BROKEN with dev switch");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* go to INSERT if recovery button physically pressed and EC trusted */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in INSERT with manual rec");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* go to INSERT if forced by GBB flag */
- ResetMocks();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- gbb.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shutdown requested in INSERT forced by GBB flag");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Stay at BROKEN if recovery button not physically pressed */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- sd->flags &= ~VB2_SD_FLAG_MANUAL_RECOVERY;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Go to BROKEN if recovery not manually requested");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Stay at BROKEN if EC is untrusted */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- trust_ec = 0;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Go to BROKEN if EC is not trusted");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* INSERT boots without screens if we have a valid image on first try */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_SUCCESS,
- "INSERT boots without screens if valid on first try");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(screens_displayed[0], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 1, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* INSERT boots eventually if we get a valid image later */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[2] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[3] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[4] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_SUCCESS,
- "INSERT boots after valid image appears");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* invalid image, then remove, then valid image */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[2] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[3] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[4] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_SUCCESS,
- "INSERT boots after valid image appears");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 3, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep on shutdown");
-
- /* Shortcuts that are always ignored in BROKEN for detachables. */
- ResetMocks();
- i = 0;
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('D');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('U');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('L');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS;
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shortcuts ignored in BROKEN");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from invalid keys");
-
- /* Shortcuts that are always ignored in INSERT for detachables. */
- ResetMocksForManualRecovery();
- i = 0;
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('D');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('U');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_KEY_CTRL('L');
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
- mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Shortcuts ignored in INSERT");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from invalid keys");
-
- /* Power Off BROKEN through OPTIONS menu */
- ResetMocks();
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
- mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Power Off BROKEN through OPTIONS");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
- " options: power off");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from power off");
-
- /* Power Off NOGOOD through OPTIONS menu */
- ResetMocksForManualRecovery();
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
- mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Power Off NOGOOD through OPTIONS");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
- " options: power off");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from power off");
-
- /* Power Off INSERT through TO_DEV menu */
- ResetMocksForManualRecovery();
- mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[0] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
- mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Power Off INSERT through TO_DEV");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to_dev: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to_dev: power off");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from power off");
-
- /* Show Debug Info from BROKEN through OPTIONS menu */
- ResetMocks();
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter options
- mock_keypress[1] = VB_BUTTON_VOL_UP_SHORT_PRESS; // show debug info
- mock_keypress[2] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Show Debug info from BROKEN through OPTIONS");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 1, " no debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
- " options: show debug info");
- TEST_EQ(screens_displayed[3], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 4, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from power off");
-
- /* Show Debug Info on NOGOOD with Tab */
- ResetMocksForManualRecovery();
- mock_keypress[0] = '\t';
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Show Debug info on NOGOOD with Tab");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 1, " no debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 2, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beep from power off");
-
- /* Navigate to confirm dev mode selection and then cancel */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- i = 0;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm disabling
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // power off
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "go to TO_DEV screen and cancel");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: confirm disabling");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " back to insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Navigate to confirm dev mode selection and then confirm */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- i = 0;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_REBOOT_EC_TO_RO,
- "go to TO_DEV screen and confirm");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(virtdev_set, 1, " virtual dev mode on");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: confirm disabling os verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Untrusted keyboard cannot enter TO_DEV (must be malicious anyway) */
- ResetMocksForManualRecovery();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // try to_dev
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // try confirm
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Untrusted keyboard cannot enter TO_DEV");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Untrusted keyboard cannot navigate in TO_DEV menu if already there */
- ResetMocksForManualRecovery();
- i = 0;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // try to confirm...
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Untrusted keyboard cannot navigate in TO_DEV");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Don't handle TPM error in enabling dev mode */
- ResetMocksForManualRecovery();
- i = 0;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm enabling
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- virtdev_fail = 1;
- TEST_ABORT(VbBootRecoveryLegacyMenu(ctx), "todev TPM failure");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " aborted explicitly");
- TEST_EQ(virtdev_set, 0, " virtual dev mode still off");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " recovery to_dev menu: confirm disabling os verification");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Cannot enable dev mode if already enabled. */
- ResetMocksForManualRecovery();
- sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- i = 0;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter to_dev
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Ctrl+D ignored if already in dev mode");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- TEST_EQ(virtdev_set, 0, " virtual dev mode wasn't enabled again");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 2, " played error beeps");
- TEST_EQ(beeps_played[0], 400, " first beep");
- TEST_EQ(beeps_played[1], 400, " second beep");
-
- /* Removing invalid USB drops back to INSERT from TO_DEV menu. */
- ResetMocksForManualRecovery();
- mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[0] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
- /* asynchronous transition to INSERT before keypress[50] */
- mock_keypress[55] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[56] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[57] = VB_BUTTON_POWER_SHORT_PRESS;
- vbtlk_retval[0] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Drop back to INSERT from TO_DEV when removing invalid USB");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev menu");
- TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[3], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[4], VB_SCREEN_OPTIONS_MENU,
- " options menu: power off");
- TEST_EQ(screens_displayed[5], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 6, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Plugging in invalid USB drops back to NOGOOD from LANGUAGE. */
- ResetMocksForManualRecovery();
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[1] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[2] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[3] = VB_BUTTON_POWER_SHORT_PRESS;
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[2] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[3] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[4] = VB2_ERROR_MOCK - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "Drop back to NOGOOD from LANGUAGE when inserting invalid USB");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_OPTIONS_MENU,
- " options menu: power off");
- TEST_EQ(screens_displayed[3], VB_SCREEN_OPTIONS_MENU,
- " options menu: language");
- TEST_EQ(screens_displayed[4], VB_SCREEN_LANGUAGES_MENU,
- " languages menu");
- TEST_EQ(screens_displayed[5], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[6], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 7, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Plugging in valid USB boots straight from OPTIONS menu. */
- ResetMocksForManualRecovery();
- mock_keypress[0] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- vbtlk_retval[1] = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_SUCCESS,
- "Boot by plugging in USB straight from OPTIONS menu");
- TEST_NEQ(shutdown_request_calls_left, 0, " booted explicitly");
- TEST_EQ(virtdev_set, 0, " virtual dev mode off");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[1], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[2], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, 3, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbTestLanguageMenu(void)
-{
- int i;
-
- VB2_DEBUG("Testing VbTestLanguageMenu()...\n");
-
- /* Navigate to language menu from BROKEN */
- ResetMocks();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // languages
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // enter languages
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // cancel -> BROKEN
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // power off
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "go to language menu from BROKEN");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OS_BROKEN,
- " broken screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Navigate to all language menus from recovery */
- ResetMocksForManualRecovery();
- vbtlk_retval[0] = VB2_ERROR_LK_NO_DISK_FOUND -
- VB_DISK_FLAG_REMOVABLE;
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // languages
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm disabling
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "go to language menus from INSERT");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_INSERT,
- " insert screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: confirm disabling os verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: power_off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " to dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* Navigate to all language menus from developer menu */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enable OS verif
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // return to dev_warn
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enable OS verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // show debug info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // developer options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- " scroll through all language menus in developer options");
- TEST_EQ(debug_info_displayed, 0, " no debug info");
- TEST_NEQ(shutdown_request_calls_left, 0, " powered down explicitly");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu: select current language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: cancel ");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu: select current language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: confirm enabling os verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to norm screen: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " warning screen: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " select developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: boot developer image");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " language menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: boot from disk");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " developer menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- VB2_DEBUG("...done.\n");
-}
-
-static void VbNavigationTest(void)
-{
- int i;
-
- VB2_DEBUG("Testing long navigation sequences...");
-
- /*
- * NOGOOD, OPTIONS, LANGUAGE, TODEV, LANGUAGE, TODEV,
- * LANGUAGE, select, Cancel, OPTIONS, LANGUAGE
- */
- ResetMocksForManualRecovery();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // confirm enabling
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; // enter TO_DEV
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // select current lang
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // power off
- mock_keyflags[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // enter OPTIONS
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // show debug info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // power off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // language
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- TEST_EQ(VbBootRecoveryLegacyMenu(ctx), VB2_REQUEST_SHUTDOWN,
- "recovery mode long navigation");
- TEST_EQ(debug_info_displayed, 1, " showed debug info");
- TEST_EQ(shutdown_request_calls_left, 0, " timed out");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " languages menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: confirm enabling");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: confirm enabling");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " languages menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " languages menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_TO_DEV_MENU,
- " todev: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_RECOVERY_NO_GOOD,
- " nogood screen");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_OPTIONS_MENU,
- " options: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_LANGUAGES_MENU,
- " languages menu");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 0, " no beeps");
-
- /* DEVELOPER, Cancel, Show Debug, TO_NORM, Cancel, Boot Legacy */
- ResetMocksForDeveloper();
- i = 0;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot Legacy
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Boot From Disk
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Enable OS verif
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Language
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Enable OS verif
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Show Debug Info
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Developer Options
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS;
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Language
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Power Off
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From Disk
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot Legacy
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Select altfw menu
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Second altfw
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Cancel
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // (end of menu)
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Back to dev options
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From Disk
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot From USB
- mock_keypress[i++] = VB_BUTTON_VOL_UP_SHORT_PRESS; // Boot Legacy
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Select altfw menu
- mock_keypress[i++] = VB_BUTTON_VOL_DOWN_SHORT_PRESS; // Second altfw
- mock_keypress[i++] = VB_BUTTON_POWER_SHORT_PRESS; // Select 2nd altfw
- vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- TEST_EQ(VbBootDeveloperLegacyMenu(ctx), vbtlk_retval_fixed,
- "developer mode long navigation");
- TEST_EQ(debug_info_displayed, 1, " showed debug info");
- TEST_EQ(vbexlegacy_called, 1, " tried legacy");
- TEST_EQ(altfw_num, 2, " check altfw_num");
- TEST_EQ(audio_looping_calls_left, 0, " audio timeout");
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
- i = 0;
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: Legacy boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: Legacy boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: USB boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: disk boot");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: confirm enabling");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_TO_NORM_MENU,
- " to dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: enable root verification");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: show debug info");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_WARNING_MENU,
- " dev warning menu: developer options");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot from disk");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: language");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: power off");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot from disk");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot from USB");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot legacy");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot legacy");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw 1");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw 2");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU,
- " altfw cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU,
- " altfw end");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: cancel");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot from disk");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot from USB");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_DEVELOPER_MENU,
- " dev menu: boot legacy");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK, " blank (flash)");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_ALT_FW_MENU, " altfw");
- TEST_EQ(screens_displayed[i++], VB_SCREEN_BLANK," final blank screen");
- TEST_EQ(screens_count, i, " no extra screens");
- TEST_EQ(beeps_count, 1, " error beep: legacy BIOS not found");
- TEST_EQ(beeps_played[0], 200, " low-frequency error beep");
-}
-
-int main(void)
-{
- VbBootDevTest();
- VbBootRecTest();
- VbTestLanguageMenu();
- VbNavigationTest();
-
- return gTestSuccess ? 0 : 255;
-}
diff --git a/tests/vboot_ui_legacy_tests.c b/tests/vboot_ui_legacy_tests.c
deleted file mode 100644
index 04da02e5..00000000
--- a/tests/vboot_ui_legacy_tests.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests for firmware display library.
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "2common.h"
-#include "2misc.h"
-#include "2nvstorage.h"
-#include "2struct.h"
-#include "2sysincludes.h"
-#include "host_common.h"
-#include "test_common.h"
-#include "vboot_kernel.h"
-#include "vboot_ui_legacy.h"
-
-/* Mock data */
-static char debug_info[4096];
-static struct vb2_context *ctx;
-static struct vb2_shared_data *sd;
-static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]
- __attribute__((aligned(VB2_WORKBUF_ALIGN)));
-static uint32_t mock_localization_count;
-static uint32_t mock_altfw_mask;
-
-/* Reset mock data (for use before each test) */
-static void ResetMocks(void)
-{
- mock_localization_count = 3;
- mock_altfw_mask = 3 << 1; /* This mask selects 1 and 2 */
-
- TEST_SUCC(vb2api_init(workbuf, sizeof(workbuf), &ctx),
- "vb2api_init failed");
- vb2_nv_init(ctx);
-
- sd = vb2_get_sd(ctx);
-
- *debug_info = 0;
-}
-
-/* Mocks */
-uint32_t vb2ex_get_locale_count(void) {
-
- return mock_localization_count;
-}
-
-uint32_t VbExGetAltFwIdxMask() {
- return mock_altfw_mask;
-}
-
-vb2_error_t VbExDisplayDebugInfo(const char *info_str, int full_info)
-{
- strncpy(debug_info, info_str, sizeof(debug_info));
- debug_info[sizeof(debug_info) - 1] = '\0';
- return VB2_SUCCESS;
-}
-
-vb2_error_t vb2ex_commit_data(struct vb2_context *c)
-{
- return VB2_SUCCESS;
-}
-
-/* Test displaying debug info */
-static void DebugInfoTest(void)
-{
- /* Display debug info */
- ResetMocks();
- TEST_SUCC(VbDisplayDebugInfo(ctx),
- "Display debug info");
- TEST_NEQ(*debug_info, '\0', " Some debug info was displayed");
-}
-
-/* Test display key checking */
-static void DisplayKeyTest(void)
-{
- ResetMocks();
- VbCheckDisplayKey(ctx, 'q', 0, NULL);
- TEST_EQ(*debug_info, '\0', "DisplayKey q = does nothing");
-
- ResetMocks();
- VbCheckDisplayKey(ctx, '\t', 0, NULL);
- TEST_NEQ(*debug_info, '\0', "DisplayKey tab = display");
-
- /* Toggle localization */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_LOCALIZATION_INDEX, 0);
- VbCheckDisplayKey(ctx, VB_KEY_DOWN, 0, NULL);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 2,
- "DisplayKey up");
- VbCheckDisplayKey(ctx, VB_KEY_LEFT, 0, NULL);
- vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 1,
- "DisplayKey left");
- VbCheckDisplayKey(ctx, VB_KEY_RIGHT, 0, NULL);
- vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 2,
- "DisplayKey right");
- VbCheckDisplayKey(ctx, VB_KEY_UP, 0, NULL);
- vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 0,
- "DisplayKey up");
-
- /* Reset localization if localization count is invalid */
- ResetMocks();
- vb2_nv_set(ctx, VB2_NV_LOCALIZATION_INDEX, 1);
- mock_localization_count = 0;
- VbCheckDisplayKey(ctx, VB_KEY_UP, 0, NULL);
- TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 0,
- "DisplayKey invalid");
-}
-
-int main(void)
-{
- DebugInfoTest();
- DisplayKeyTest();
-
- return gTestSuccess ? 0 : 255;
-}