summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-10 17:08:17 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-12 17:14:53 +0000
commit638aeeb863582aa3571101fda0d01d7613276518 (patch)
treedb7a77c14bbb60177c85c4ed03fd57a7f9aec059
parenta1dbdc91ae1b3d60d307e5bad9514f5ed2d6b65f (diff)
downloadchrome-ec-638aeeb863582aa3571101fda0d01d7613276518.tar.gz
test: EC_CMD_HOST_SLEEP_EVENT bad arg
Add a test that verifies the EC_CMD_HOST_SLEEP_EVENT host command may be invoked with an invalid sleep event and not return an error to the caller. Also verify that this invocation results in the bad event being propagated down to chip specific event handler with zero sleep transitions. Also adds a new test target for validating the power/host_sleep.c code. 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: I0f177dc660746740b5380254583df426c9b903ca Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3947524 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Al Semjonovs <asemjonovs@google.com>
-rw-r--r--zephyr/test/drivers/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/Kconfig3
-rw-r--r--zephyr/test/drivers/power_host_sleep/CMakeLists.txt6
-rw-r--r--zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c78
-rw-r--r--zephyr/test/drivers/testcase.yaml9
5 files changed, 97 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index 203c40b181..3610a9a9f2 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -21,6 +21,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_I2C_CONTROLLER i2c_controller)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_KEYBOARD_SCAN keyboard_scan)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MKBP mkbp)
+add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_POWER_HOST_SLEEP power_host_sleep)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_RT9490 rt9490)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC shim_pwm_hc)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_SHIM_RTC shim_rtc)
diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig
index fcc06dee9b..26cc540e3c 100644
--- a/zephyr/test/drivers/Kconfig
+++ b/zephyr/test/drivers/Kconfig
@@ -38,6 +38,9 @@ config LINK_TEST_SUITE_MKBP
config LINK_TEST_SUITE_SHIM_PWM_HC
bool "Link and run the shim pwm_hc tests"
+config LINK_TEST_SUITE_POWER_HOST_SLEEP
+ bool "Link and run the power/host_sleep.c specific tests"
+
config LINK_TEST_SUITE_RT9490
bool "Link and test the rt9490 tests"
diff --git a/zephyr/test/drivers/power_host_sleep/CMakeLists.txt b/zephyr/test/drivers/power_host_sleep/CMakeLists.txt
new file mode 100644
index 0000000000..8b5f356719
--- /dev/null
+++ b/zephyr/test/drivers/power_host_sleep/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Add source files
+target_sources(app PRIVATE src/test_power_host_sleep.c)
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
new file mode 100644
index 0000000000..e494cb4b13
--- /dev/null
+++ b/zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c
@@ -0,0 +1,78 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/kernel.h>
+#include <zephyr/ztest.h>
+#include <zephyr/ztest_assert.h>
+
+#include "ec_commands.h"
+#include "host_command.h"
+#include "power.h"
+#include "test/drivers/test_mocks.h"
+#include "test/drivers/test_state.h"
+
+/*
+ * TODO(b/253224061): Reorganize fakes by public interface
+ */
+/* Fake to allow full linking */
+FAKE_VOID_FUNC(chipset_reset, enum chipset_shutdown_reason);
+FAKE_VALUE_FUNC(enum power_state, power_chipset_init);
+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 *);
+
+/* Per-Test storage of host_sleep_event_context to validate argument values */
+static struct host_sleep_event_context test_saved_context;
+
+/* Test-specific custom fake */
+static void _test_power_chipset_handle_host_sleep_event(
+ enum host_sleep_event state, struct host_sleep_event_context *ctx)
+{
+ memcpy(&test_saved_context, ctx,
+ sizeof(struct host_sleep_event_context));
+}
+
+static void power_host_sleep_before_after(void *test_data)
+{
+ ARG_UNUSED(test_data);
+
+ RESET_FAKE(power_chipset_handle_host_sleep_event);
+ memset(&test_saved_context, 0, sizeof(struct host_sleep_event_context));
+}
+
+ZTEST_USER(power_host_sleep, test_non_existent_sleep_event_v1__bad_event)
+{
+ struct ec_params_host_sleep_event_v1 p = {
+ /* No such sleep event */
+ .sleep_event = UINT8_MAX,
+ /* Non-existent sleep event, so suspend params don't matter */
+ .suspend_params = { 0 },
+ };
+ struct ec_response_host_sleep_event_v1 r;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND(EC_CMD_HOST_SLEEP_EVENT, 1, r, p);
+
+ /* Clear garbage for verifiable value */
+ r.resume_response.sleep_transitions = 0;
+
+ power_chipset_handle_host_sleep_event_fake.custom_fake =
+ _test_power_chipset_handle_host_sleep_event;
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(args.response_size, 0);
+ zassert_equal(power_chipset_handle_host_sleep_event_fake.call_count, 1);
+ zassert_equal(power_chipset_handle_host_sleep_event_fake.arg0_val,
+ p.sleep_event);
+
+ /*
+ * Unknown host sleep events don't retrieve sleep transitions from
+ * chip-specific handler.
+ */
+ zassert_equal(r.resume_response.sleep_transitions, 0);
+}
+
+ZTEST_SUITE(power_host_sleep, drivers_predicate_post_main, NULL,
+ power_host_sleep_before_after, power_host_sleep_before_after, NULL);
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index c173edc872..164eeedf3a 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -82,6 +82,15 @@ tests:
drivers.shim_pwm_hc:
extra_configs:
- CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC=y
+ drivers.power_host_sleep:
+ extra_configs:
+ - CONFIG_LINK_TEST_SUITE_POWER_HOST_SLEEP=y
+ # Make tests independent of chipset specific code
+ - CONFIG_AP_ARM_QUALCOMM_SC7280=n
+ - CONFIG_PLATFORM_EC_POWERSEQ_SC7280=n
+
+ - CONFIG_POWER_SEQUENCE_MOCK=y
+ - CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y
drivers.rt9490:
extra_args: CONF_FILE="prj.conf;rt9490/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./rt9490/charger.dts"
extra_configs: