diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-10-13 15:28:39 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-14 21:20:36 +0000 |
commit | be5488f5a418e402c897bf0ac8f61bc4429f4a5f (patch) | |
tree | 1e7f22aef164a9bded86e71dfb178e6df5d1070c | |
parent | 2c78ade6deabe07143840e01e97e2d2db09890e5 (diff) | |
download | chrome-ec-be5488f5a418e402c897bf0ac8f61bc4429f4a5f.tar.gz |
test: host_sleep.c suspend then resume w/ timeout
Add a host_sleep.c test that:
1. Starts the suspend process
2. Registers the suspend state transition
3. Starts the resume process
4. Timesout during the resume process state transition.
5. Finally completes resume process state transition.
As a whole, this test validates that suspend/resume state transitions
are being tracked and also cancel hang timeout deferred hooks.
BRANCH=none
BUG=b:252887178
TEST=twister -s zephyr/test/drivers/drivers.power_host_sleep
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I3f9dcdf12698015d5df2816198dfaf36a5ee458b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3953259
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r-- | zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c b/zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c index 2ff7b64e9e..804a839ff0 100644 --- a/zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c +++ b/zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c @@ -60,6 +60,8 @@ static void power_host_sleep_before_after(void *test_data) RESET_FAKE(power_chipset_handle_sleep_hang); RESET_FAKE(power_board_handle_sleep_hang); memset(&test_saved_context, 0, sizeof(struct host_sleep_event_context)); + + sleep_reset_tracking(); } ZTEST_USER(power_host_sleep, test_non_existent_sleep_event_v1__bad_event) @@ -216,6 +218,46 @@ ZTEST(power_host_sleep, test_sleep_start_suspend_infinite_timeout) zassert_equal(power_board_handle_sleep_hang_fake.call_count, 0); } +ZTEST(power_host_sleep, test_suspend_then_resume_with_timeout) +{ + struct host_sleep_event_context context = { + .sleep_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT, + .sleep_transitions = 0. + }; + + /* Start then suspend process with deferred hook call */ + sleep_start_suspend(&context); + /* Register the suspend transition (cancels timeout hook) */ + sleep_suspend_transition(); + k_sleep(K_MSEC(CONFIG_SLEEP_TIMEOUT_MS * 2)); + + /* No timeout hooks should've fired */ + zassert_equal(power_chipset_handle_sleep_hang_fake.call_count, 0); + zassert_equal(power_board_handle_sleep_hang_fake.call_count, 0); + + /* Transition to resume state and wait for hang timeout */ + sleep_resume_transition(); + k_sleep(K_MSEC(CONFIG_SLEEP_TIMEOUT_MS * 2)); + + /* Resume state transition timeout hook should've fired */ + zassert_equal(power_chipset_handle_sleep_hang_fake.call_count, 1); + zassert_equal(power_board_handle_sleep_hang_fake.call_count, 1); + zassert_equal(power_chipset_handle_sleep_hang_fake.arg0_val, + SLEEP_HANG_S0IX_RESUME); + zassert_equal(power_board_handle_sleep_hang_fake.arg0_val, + SLEEP_HANG_S0IX_RESUME); + + /* Complete resume so we can inspect the state transitions */ + sleep_complete_resume(&context); + + /* Transitioned to suspend and then to resume state. */ + zassert_equal(context.sleep_transitions & + EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK, + 2); + /* There was a timeout */ + zassert_true(context.sleep_transitions & EC_HOST_RESUME_SLEEP_TIMEOUT); +} + /* Only used in test_sleep_set_notify */ static bool _test_host_sleep_hook_called; |