vboot: add tests for VB2_TRY around screen changes
After these functions are called, no assumptions may be made
about which screen is currently displayed, and thus execution
should return to ui_loop:
- vb2_ui_menu_select
- vb2_ui_screen_back
- vb2_ui_screen_change
When VB2_TRY() is wrapped around these functions, the result
should be returning immediately. No code following the functions
should be executed. Add unit test coverage for this.
BUG=b:157625765
TEST=make clean && make runtests
BRANCH=none
Signed-off-by: Joel Kitching <kitching@google.com>
Change-Id: I4fc2a1eb59012eeefce34d25f010a49cb1d957de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2721377
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Hsuan Ting Chen <roccochen@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
diff --git a/tests/vb2_ui_action_tests.c b/tests/vb2_ui_action_tests.c
index 68c41c2..dc4ebfa 100644
--- a/tests/vb2_ui_action_tests.c
+++ b/tests/vb2_ui_action_tests.c
@@ -670,6 +670,12 @@
VB2_DEBUG("...done.\n");
}
+static vb2_error_t try_menu_select_helper(void)
+{
+ VB2_TRY(vb2_ui_menu_select(&mock_ui_context));
+ return VB2_ERROR_MOCK;
+}
+
static void menu_select_tests(void)
{
VB2_DEBUG("Testing menu_select...\n");
@@ -684,6 +690,13 @@
screen_state_eq(mock_ui_context.state, MOCK_SCREEN_BASE, 0,
MOCK_IGNORE);
+ /* VB2_TRY around item selection should return right away */
+ reset_common_data();
+ mock_ui_context.state->screen = &mock_screen_menu;
+ mock_ui_context.key = VB_KEY_ENTER;
+ TEST_NEQ(try_menu_select_helper(), VB2_ERROR_MOCK,
+ "continued executing after VB2_TRY(menu_select)");
+
/* Try to select an item with a target (item 2) */
reset_common_data();
mock_ui_context.state->screen = &mock_screen_menu;
diff --git a/tests/vb2_ui_utility_tests.c b/tests/vb2_ui_utility_tests.c
index 821402a..fd2eda8 100644
--- a/tests/vb2_ui_utility_tests.c
+++ b/tests/vb2_ui_utility_tests.c
@@ -268,6 +268,18 @@
VB2_DEBUG("...done.\n");
}
+static vb2_error_t try_back_helper(void)
+{
+ VB2_TRY(vb2_ui_screen_back(&mock_ui_context));
+ return VB2_ERROR_MOCK;
+}
+
+static vb2_error_t try_screen_change_helper(enum vb2_screen screen_id)
+{
+ VB2_TRY(vb2_ui_screen_change(&mock_ui_context, screen_id));
+ return VB2_ERROR_MOCK;
+}
+
static void screen_stack_tests(void)
{
VB2_DEBUG("Testing screen stack functionality...\n");
@@ -299,6 +311,16 @@
screen_state_eq(mock_ui_context.state, MOCK_SCREEN_BASE, 2, 0x10);
TEST_EQ(mock_action_called, 1, " action called once");
+ /* VB2_TRY around back should return right away */
+ reset_common_data();
+ TEST_NEQ(try_back_helper(), VB2_ERROR_MOCK,
+ "continued executing after VB2_TRY(back)");
+
+ /* VB2_TRY around screen_change should return right away */
+ reset_common_data();
+ TEST_NEQ(try_screen_change_helper(MOCK_SCREEN_ROOT), VB2_ERROR_MOCK,
+ "continued executing after VB2_TRY(screen_change)");
+
/* Change to target screen already in stack, restoring the state */
reset_common_data();
mock_screen_base.init = mock_action_base;