summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-13 09:10:55 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-14 21:20:27 +0000
commit2d6218fb9b24695fd1b83965339317747fd1d83f (patch)
tree157d75fccad882124e88425c370776adc9a43ab2
parent434d9f7aabb678da45c07c2b8b2ed7bd9d911b34 (diff)
downloadchrome-ec-2d6218fb9b24695fd1b83965339317747fd1d83f.tar.gz
test: host_sleep sleep_start_suspend default time
Add a test that verifies a call to sleep_start_suspend() propagates a timeout deferred call to board/chip-specific timeout handlers after the default delay. Also clarified documentation that previously made testing the default timing functionality non-obvious and potentially confuse callers of the API. 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: Id585b5bb4ee9015c7448b4da26460a690e2990b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3953474 Reviewed-by: Yuval Peress <peress@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--include/power.h4
-rw-r--r--power/host_sleep.c3
-rw-r--r--zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c22
3 files changed, 28 insertions, 1 deletions
diff --git a/include/power.h b/include/power.h
index c32b2714e5..461e69748b 100644
--- a/include/power.h
+++ b/include/power.h
@@ -363,6 +363,10 @@ power_board_handle_sleep_hang(enum sleep_hang_type hang_type);
* power_chipset_handle_sleep_hang() and power_board_handle_sleep_hang() will
* be called when a sleep hang is detected.
*
+ * If called with a sleep_timeout_ms of EC_HOST_SLEEP_TIMEOUT_DEFAULT, the
+ * timeout will be picked based on CONFIG_SLEEP_TIMEOUT_MS or whatever is set as
+ * the default timeout by the sleeptimeout console command.
+ *
* @param ctx Possible sleep parameters and return values, depending on state.
*/
void sleep_start_suspend(struct host_sleep_event_context *ctx);
diff --git a/power/host_sleep.c b/power/host_sleep.c
index b6f0de498e..da7189083a 100644
--- a/power/host_sleep.c
+++ b/power/host_sleep.c
@@ -108,6 +108,7 @@ void sleep_notify_transition(int check_state, int hook_id)
#ifdef CONFIG_POWER_SLEEP_FAILURE_DETECTION
static uint16_t sleep_signal_timeout;
+/* Non-const because it may be set by sleeptimeout console cmd */
static uint16_t host_sleep_timeout_default = CONFIG_SLEEP_TIMEOUT_MS;
static uint32_t sleep_signal_transitions;
static enum sleep_hang_type timeout_hang_type;
@@ -175,7 +176,7 @@ void sleep_start_suspend(struct host_sleep_event_context *ctx)
sleep_signal_transitions = 0;
- /* Use zero internally to indicate no timeout. */
+ /* Use default to indicate no timeout given. */
if (timeout == EC_HOST_SLEEP_TIMEOUT_DEFAULT) {
timeout = host_sleep_timeout_default;
}
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 47d9d3ed13..f1c3a2bcc9 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
@@ -178,5 +178,27 @@ ZTEST(power_host_sleep, test_sleep_start_suspend_custom_timeout)
SLEEP_HANG_S0IX_SUSPEND);
}
+ZTEST(power_host_sleep, test_sleep_start_suspend_default_timeout)
+{
+ struct host_sleep_event_context context = {
+ .sleep_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT,
+ };
+
+ sleep_start_suspend(&context);
+
+ /*
+ * TODO(b/253284635): Why can't we just wait CONFIG_SLEEP_TIMEOUT_MS?
+ */
+ k_msleep(CONFIG_SLEEP_TIMEOUT_MS * 2);
+
+ 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);