diff options
Diffstat (limited to 'zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c')
-rw-r--r-- | zephyr/test/drivers/power_host_sleep/src/test_power_host_sleep.c | 78 |
1 files changed, 78 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 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); |