diff options
author | Joel Kitching <kitching@google.com> | 2021-02-26 14:33:53 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-28 11:15:08 +0000 |
commit | c6cc2d6aacbceb07e28d6b99bf75fd40f150c79f (patch) | |
tree | 8ea84d4595132939fb2a1b6cdb2451a5751b2041 | |
parent | 5b1e2e75b48db4f056dc952616c9a9fecf3535c1 (diff) | |
download | vboot-c6cc2d6aacbceb07e28d6b99bf75fd40f150c79f.tar.gz |
vboot: add tests for VB2_TRY around screen changesstabilize-13821.B
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>
-rw-r--r-- | tests/vb2_ui_action_tests.c | 13 | ||||
-rw-r--r-- | tests/vb2_ui_utility_tests.c | 22 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/vb2_ui_action_tests.c b/tests/vb2_ui_action_tests.c index 68c41c25..dc4ebfa8 100644 --- a/tests/vb2_ui_action_tests.c +++ b/tests/vb2_ui_action_tests.c @@ -670,6 +670,12 @@ static void menu_next_tests(void) 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 @@ static void menu_select_tests(void) 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 821402a9..fd2eda8c 100644 --- a/tests/vb2_ui_utility_tests.c +++ b/tests/vb2_ui_utility_tests.c @@ -268,6 +268,18 @@ static void check_shutdown_request_tests(void) 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 @@ static void screen_stack_tests(void) 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; |