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>
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index 5b1e339..24f7473 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 fecfaa9..1b4c5e2 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -789,21 +789,21 @@
 	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 ab35395..6ce6cf8 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 89442fe..890c3e6 100644
--- a/tests/vb2_ui_tests.c
+++ b/tests/vb2_ui_tests.c
@@ -586,12 +586,12 @@
 	/* 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");
 
@@ -602,9 +602,9 @@
 	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 */
@@ -639,7 +639,7 @@
 	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);
@@ -648,7 +648,7 @@
 	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) {
@@ -658,19 +658,19 @@
 		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");
 
@@ -696,7 +696,7 @@
 	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);
@@ -705,7 +705,7 @@
 	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);
@@ -715,7 +715,7 @@
 		"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);
@@ -724,7 +724,7 @@
 		"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) {
@@ -734,7 +734,7 @@
 		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 */