summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsuan Ting Chen <roccochen@chromium.org>2020-11-02 19:32:29 +0800
committerCommit Bot <commit-bot@chromium.org>2020-12-02 07:46:00 +0000
commitef837639da5731f860e7850df4a4139c5523883b (patch)
treeef8ae3ede2a7aa9efe668ac140f2ac65afc064b5
parentbe58e2ff2f9a4fdfc612cd3f26baa203965f175d (diff)
downloadvboot-ef837639da5731f860e7850df4a4139c5523883b.tar.gz
vboot/ui/tests: Add time-related constants in 2ui_private.h
Add several constants in 2ui_private.h for testing: - KEY_DELAY_MS - DEV_DELAY_SHORT_MS - DEV_DELAY_NORMAL_MS - DEV_DELAY_BEEP1_MS - DEV_DELAY_BEEP2_MS BUG=b:156448738 BRANCH=none TEST=CC=x86_64-pc-linux-gnu-clang; make clean && make runtests Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org> Change-Id: I7349d5214a90699fda67135329d7a6b93022bb27 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2513418 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2569274 Reviewed-by: Shelley Chen <shchen@chromium.org> Commit-Queue: Shelley Chen <shchen@chromium.org> Tested-by: Shelley Chen <shchen@chromium.org>
-rw-r--r--firmware/2lib/2ui.c2
-rw-r--r--firmware/2lib/2ui_screens.c8
-rw-r--r--firmware/2lib/include/2ui_private.h8
-rw-r--r--tests/vb2_ui_tests.c32
4 files changed, 28 insertions, 22 deletions
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index 5b1e3394..24f74736 100644
--- a/firmware/2lib/2ui.c
+++ b/firmware/2lib/2ui.c
@@ -15,8 +15,6 @@
#include "vboot_api.h" /* For VB_SHUTDOWN_REQUEST_POWER_BUTTON */
#include "vboot_kernel.h"
-#define KEY_DELAY_MS 20 /* Delay between key scans in UI loops */
-
/*****************************************************************************/
/* Utility functions */
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index 6129ab9e..a2f642ff 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -793,21 +793,21 @@ vb2_error_t developer_mode_action(struct vb2_ui_context *ui)
elapsed_ms = vb2ex_mtime() - ui->start_time_ms;
/* If we're using short delay, wait 2 seconds and don't beep. */
- if (use_short && elapsed_ms > 2 * VB2_MSEC_PER_SEC) {
+ if (use_short && elapsed_ms > DEV_DELAY_SHORT_MS) {
VB2_DEBUG("Booting default target after 2s\n");
ui->disable_timer = 1;
return vb2_ui_menu_select(ui);
}
/* Otherwise, beep at 20 and 20.5 seconds. */
- if ((ui->beep_count == 0 && elapsed_ms > 20 * VB2_MSEC_PER_SEC) ||
- (ui->beep_count == 1 && elapsed_ms > 20 * VB2_MSEC_PER_SEC + 500)) {
+ if ((ui->beep_count == 0 && elapsed_ms > DEV_DELAY_BEEP1_MS) ||
+ (ui->beep_count == 1 && elapsed_ms > DEV_DELAY_BEEP2_MS)) {
vb2ex_beep(250, 400);
ui->beep_count++;
}
/* Stop after 30 seconds. */
- if (elapsed_ms > 30 * VB2_MSEC_PER_SEC) {
+ if (elapsed_ms > DEV_DELAY_NORMAL_MS) {
VB2_DEBUG("Booting default target after 30s\n");
ui->disable_timer = 1;
return vb2_ui_menu_select(ui);
diff --git a/firmware/2lib/include/2ui_private.h b/firmware/2lib/include/2ui_private.h
index ab353955..6ce6cf80 100644
--- a/firmware/2lib/include/2ui_private.h
+++ b/firmware/2lib/include/2ui_private.h
@@ -6,10 +6,18 @@
*/
#include "2api.h"
+#include "2common.h"
#ifndef VBOOT_REFERENCE_2UI_PRIVATE_H_
#define VBOOT_REFERENCE_2UI_PRIVATE_H_
+/* Time-related constants */
+#define KEY_DELAY_MS 20 /* Delay between key scans in UI loops */
+#define DEV_DELAY_SHORT_MS (2 * VB2_MSEC_PER_SEC) /* 2 seconds */
+#define DEV_DELAY_NORMAL_MS (30 * VB2_MSEC_PER_SEC) /* 30 seconds */
+#define DEV_DELAY_BEEP1_MS (20 * VB2_MSEC_PER_SEC) /* 20 seconds */
+#define DEV_DELAY_BEEP2_MS (20 * VB2_MSEC_PER_SEC + 500) /* 20.5 seconds */
+
/* From 2ui.c */
vb2_error_t check_shutdown_request(struct vb2_ui_context *ui);
const struct vb2_menu *get_menu(struct vb2_ui_context *ui);
diff --git a/tests/vb2_ui_tests.c b/tests/vb2_ui_tests.c
index 5c1cc93f..f98829ac 100644
--- a/tests/vb2_ui_tests.c
+++ b/tests/vb2_ui_tests.c
@@ -587,12 +587,12 @@ static void developer_tests(void)
/* Proceed to internal disk after timeout */
reset_common_data(FOR_DEVELOPER);
add_mock_vbtlk(VB2_SUCCESS, VB_DISK_FLAG_FIXED);
- expect_beep(250, 400, 20 * VB2_MSEC_PER_SEC);
- expect_beep(250, 400, 20 * VB2_MSEC_PER_SEC + 500);
+ expect_beep(250, 400, DEV_DELAY_BEEP1_MS);
+ expect_beep(250, 400, DEV_DELAY_BEEP2_MS);
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"proceed to internal disk after timeout");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms >=
- 30 * VB2_MSEC_PER_SEC, " finished delay");
+ DEV_DELAY_NORMAL_MS, " finished delay");
TEST_EQ(mock_beep_count, 2, " beeped twice");
TEST_TRUE(mock_iters >= mock_vbtlk_total, " used up mock_vbtlk");
@@ -603,9 +603,9 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"use short delay");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms >=
- 2 * VB2_MSEC_PER_SEC, " finished delay");
+ DEV_DELAY_SHORT_MS, " finished delay");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " not a 30s delay");
+ DEV_DELAY_NORMAL_MS, " not a 30s delay");
TEST_EQ(mock_beep_count, 0, " never beeped");
/* Stop timer on any user input: normal delay */
@@ -640,7 +640,7 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"select boot internal in dev menu");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* Ctrl+D = boot internal */
reset_common_data(FOR_DEVELOPER);
@@ -649,7 +649,7 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"ctrl+d = boot internal");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* VB_BUTTON_VOL_DOWN_LONG_PRESS = boot internal */
if (DETACHABLE) {
@@ -659,19 +659,19 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"VB_BUTTON_VOL_DOWN_LONG_PRESS = boot internal");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
}
/* Proceed to external disk after timeout */
reset_common_data(FOR_DEVELOPER);
add_mock_vbtlk(VB2_SUCCESS, VB_DISK_FLAG_REMOVABLE);
mock_default_boot = VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL;
- expect_beep(250, 400, 20 * VB2_MSEC_PER_SEC);
- expect_beep(250, 400, 20 * VB2_MSEC_PER_SEC + 500);
+ expect_beep(250, 400, DEV_DELAY_BEEP1_MS);
+ expect_beep(250, 400, DEV_DELAY_BEEP2_MS);
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"proceed to external disk after timeout");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms >=
- 30 * VB2_MSEC_PER_SEC, " finished delay");
+ DEV_DELAY_NORMAL_MS, " finished delay");
TEST_EQ(mock_beep_count, 2, " beeped twice");
TEST_TRUE(mock_iters >= mock_vbtlk_total, " used up mock_vbtlk");
@@ -697,7 +697,7 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"select boot external in dev menu");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* Ctrl+U = boot external */
reset_common_data(FOR_DEVELOPER);
@@ -706,7 +706,7 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"ctrl+u = boot external");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* Ctrl+L = boot legacy (allowed) */
reset_common_data(FOR_DEVELOPER);
@@ -716,7 +716,7 @@ static void developer_tests(void)
"ctrl+l = boot legacy");
TEST_EQ(mock_vbexlegacy_called, 1, " VbExLegacy called");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* Ctrl+L = boot legacy (disallowed) */
reset_common_data(FOR_DEVELOPER);
@@ -725,7 +725,7 @@ static void developer_tests(void)
"ctrl+l = boot legacy");
TEST_EQ(mock_vbexlegacy_called, 0, " VbExLegacy not called");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
/* VB_BUTTON_VOL_UP_LONG_PRESS = boot external */
if (DETACHABLE) {
@@ -735,7 +735,7 @@ static void developer_tests(void)
TEST_EQ(vb2_developer_menu(ctx), VB2_SUCCESS,
"VB_BUTTON_VOL_UP_LONG_PRESS = boot external");
TEST_TRUE(mock_get_timer_last_ms - mock_time_start_ms <
- 30 * VB2_MSEC_PER_SEC, " delay aborted");
+ DEV_DELAY_NORMAL_MS, " delay aborted");
}
/* If dev mode is disabled, goes to to_norm screen repeatedly */