diff options
author | Yuval Peress <peress@google.com> | 2022-10-18 23:20:32 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-21 17:24:31 +0000 |
commit | 70ee19b25c19a5938e1e7042383bcce24a1461cc (patch) | |
tree | c0cd478084cb669a3a89570abcb981d7acbebe54 | |
parent | 650a67c64c0f14bf8ad1d63fcbb0b48b6375c8b3 (diff) | |
download | chrome-ec-70ee19b25c19a5938e1e7042383bcce24a1461cc.tar.gz |
test: Add tests for all paths leading to warm reset
Add tests for all the code paths (including error and timeout cases)
that lead up to a warm reset being initiated.
BRANCH=none
BUG=none
TEST=twister
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: Idbb8b90efe31bc36f415809a0eb234b073f8037f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3965713
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/test/drivers/button/src/main.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/zephyr/test/drivers/button/src/main.c b/zephyr/test/drivers/button/src/main.c index 8e2b133c5f..c26a62dfa1 100644 --- a/zephyr/test/drivers/button/src/main.c +++ b/zephyr/test/drivers/button/src/main.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ +#include <zephyr/fff.h> #include <zephyr/kernel.h> #include <zephyr/shell/shell.h> #include <zephyr/ztest.h> @@ -11,9 +12,18 @@ #include "console.h" #include "hooks.h" #include "mkbp_fifo.h" +#include "power.h" #include "test/drivers/test_state.h" #include "timer.h" +/* + * TODO (b/b/253284635) Timeouts here don't quite align with the button press + * duration. This is caused by an issue with the Zephyr scheduling for delayed + * work that's causing us to need to sleep longer than "reasonable". + */ + +FAKE_VOID_FUNC(chipset_reset, enum chipset_shutdown_reason); + static char *button_debug_state_strings[] = { "STATE_DEBUG_NONE", "STATE_DEBUG_CHECK", "STATE_STAGING", "STATE_DEBUG_MODE_ACTIVE", @@ -52,6 +62,8 @@ static void button_before(void *f) /* Sleep for 30s to flush any pending tasks */ k_sleep(K_SECONDS(30)); mkbp_clear_fifo(); + + RESET_FAKE(chipset_reset); } ZTEST_SUITE(button, drivers_predicate_post_main, button_setup, button_before, @@ -256,3 +268,82 @@ ZTEST(button, test_activate_sysrq_exec) EC_MKBP_EVENT_SYSRQ)); zassert_equal((uint32_t)'x', event_data); } + +ZTEST(button, test_activate_warm_reset_then_timeout) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume down button to put in warm_reset_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into warm_reset_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_WARM_RESET_PATH); + + /* Now sleep and move the clock forward to timeout the debug process */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); +} + +ZTEST(button, test_activate_warm_reset_exec) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume down button to put in warm_reset_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into warm_reset_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_WARM_RESET_PATH); + + /* Now sleep and move the clock forward to timeout the debug process. + * Doing this in two steps verifies that even after the handler executes + * "too early" we can still recover via the vup button that's coming + * next. This is caused by effectively, sleeping so the scheduler runs, + * but not ticking the clock forward yet until the next sleep. + */ + k_msleep(11000); + pass_time(11000); + + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); + zassert_equal(1, chipset_reset_fake.call_count); + zassert_equal(CHIPSET_RESET_DBG_WARM_REBOOT, + chipset_reset_fake.arg0_val); +} |