summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c42
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;