diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-10-12 13:50:15 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-13 16:26:40 +0000 |
commit | f4192e223940d2802168d1eea6973d4f68c0407d (patch) | |
tree | 79804d730eaae31201f4723d0e57190908f0eed7 | |
parent | eb859ecdb21d67a74641b1485072d621087ae0ac (diff) | |
download | chrome-ec-f4192e223940d2802168d1eea6973d4f68c0407d.tar.gz |
test: host_sleep.c sleep_start_suspend custom time
Add a test that verifies a call to sleep_start_suspend() propagates a
timeout deferred call to board/chip-specific timeout handlers after some
delay. Also verifies that this timeout event is idempotent with respect
to calling the handlers.
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: If9f20912942f25a217c4f0952eb6512958ba3e44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3949625
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c | 37 |
1 files changed, 37 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 f5028af537..47d9d3ed13 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 @@ -25,6 +25,8 @@ const struct power_signal_info power_signal_list[] = {}; FAKE_VOID_FUNC(power_chipset_handle_host_sleep_event, enum host_sleep_event, struct host_sleep_event_context *); +FAKE_VOID_FUNC(power_chipset_handle_sleep_hang, enum sleep_hang_type); +FAKE_VOID_FUNC(power_board_handle_sleep_hang, enum sleep_hang_type); /* Per-Test storage of host_sleep_event_context to validate argument values */ static struct host_sleep_event_context test_saved_context; @@ -54,6 +56,8 @@ static void power_host_sleep_before_after(void *test_data) ARG_UNUSED(test_data); RESET_FAKE(power_chipset_handle_host_sleep_event); + 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)); } @@ -141,5 +145,38 @@ ZTEST_USER(power_host_sleep, test_non_existent_sleep_event_v1__s3_resume) ARBITRARY_SLEEP_TRANSITIONS); } +ZTEST(power_host_sleep, test_sleep_start_suspend_custom_timeout) +{ + struct host_sleep_event_context context = { + /* Arbitrary 5ms timeout */ + .sleep_timeout_ms = 5, + }; + + sleep_start_suspend(&context); + /* + * Validate that function idempotent wrt calling chip-specific handlers + */ + sleep_start_suspend(&context); + + /* Verify handlers not called because timeout didn't occur yet */ + zassert_equal(power_chipset_handle_sleep_hang_fake.call_count, 0); + zassert_equal(power_board_handle_sleep_hang_fake.call_count, 0); + + /* Allow timeout to occur */ + /* + * TODO(b/253284635): Why can't we just wait 5ms? + */ + k_sleep(K_SECONDS(1)); + + /* Check timeout handlers fired only *once* after multiple calls */ + 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_SUSPEND); + zassert_equal(power_board_handle_sleep_hang_fake.arg0_val, + SLEEP_HANG_S0IX_SUSPEND); +} + ZTEST_SUITE(power_host_sleep, drivers_predicate_post_main, NULL, power_host_sleep_before_after, power_host_sleep_before_after, NULL); |