diff options
author | Diana Z <dzigterman@chromium.org> | 2022-08-26 09:31:05 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-26 20:32:00 +0000 |
commit | d44122bbd05f735ac6bea2ca7e22bf374f2d2ef6 (patch) | |
tree | 5f6ce835394b6ed38ffdd7a1dbd6cb74dd215d63 | |
parent | a7651e681c46a38e2e5670595a2a40068a16846b (diff) | |
download | chrome-ec-d44122bbd05f735ac6bea2ca7e22bf374f2d2ef6.tar.gz |
Zephyr test: Add a test for PD_CHIP_INFO
The command EC_CMD_PD_CHIP_INFO is an important part of the TCPC upgrade
process, so add a test for it.
BRANCH=None
BUG=None
TEST=./twister -T ./zephyr/test
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I2f2822b3a062bbffb7362706cac8a7a31406fb80
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3858392
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/test/drivers/host_cmd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/host_cmd/src/pd_chip_info.c | 65 |
2 files changed, 66 insertions, 0 deletions
diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt index 3f1d423e3d..f733559906 100644 --- a/zephyr/test/drivers/host_cmd/CMakeLists.txt +++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources(app PRIVATE src/host_event_commands_deprecated.c src/motion_sense.c src/pd_control.c + src/pd_chip_info.c ) diff --git a/zephyr/test/drivers/host_cmd/src/pd_chip_info.c b/zephyr/test/drivers/host_cmd/src/pd_chip_info.c new file mode 100644 index 0000000000..e41c1b2e7a --- /dev/null +++ b/zephyr/test/drivers/host_cmd/src/pd_chip_info.c @@ -0,0 +1,65 @@ +/* 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/shell/shell.h> +#include <zephyr/ztest.h> + +#include "console.h" +#include "ec_commands.h" +#include "test/drivers/stubs.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +#define TEST_PORT USBC_PORT_C0 +#define BAD_PORT 65 + +static enum ec_status run_pd_chip_info(int port, + struct ec_response_pd_chip_info_v1 *resp) +{ + struct ec_params_pd_chip_info params = { .port = port, .live = true }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_PD_CHIP_INFO, 1, resp, params); + + return host_command_process(&args); +} + +ZTEST_USER(host_cmd_pd_chip_info, test_good_index) +{ + struct ec_response_pd_chip_info_v1 response; + + zassert_ok(run_pd_chip_info(TEST_PORT, &response), + "Failed to process pd_get_chip_info for port %d", TEST_PORT); + /* + * Note: verification of the specific fields depends on the chips used + * and therefore would belong in a driver-level test + */ +} + +ZTEST_USER(host_cmd_pd_chip_info, test_bad_index) +{ + struct ec_response_pd_chip_info_v1 response; + + zassume_true(board_get_usb_pd_port_count() < BAD_PORT, + "Intended bad port exists"); + zassert_equal(run_pd_chip_info(BAD_PORT, &response), + EC_RES_INVALID_PARAM, + "Failed to fail pd_chip_info for port %d", BAD_PORT); +} + +static void host_cmd_pd_chip_info_begin(void *data) +{ + ARG_UNUSED(data); + + /* Assume we have at least one USB-C port */ + zassume_true(board_get_usb_pd_port_count() > 0, + "Insufficient TCPCs found"); + + /* Set the system into S0, since the AP would drive these commands */ + test_set_chipset_to_s0(); + k_sleep(K_SECONDS(1)); +} + +ZTEST_SUITE(host_cmd_pd_chip_info, drivers_predicate_post_main, NULL, + host_cmd_pd_chip_info_begin, NULL, NULL); |