diff options
author | Al Semjonovs <asemjonovs@google.com> | 2022-05-06 21:10:49 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-11 20:28:52 +0000 |
commit | 1ad60ff66e3399d2efd1d8a7c48a082a77c44621 (patch) | |
tree | bd291c963fa2b54ad365e3b656dce85dcc5fdb84 | |
parent | a7dcd8bee64670e98d6169bcd512cc851a7613f3 (diff) | |
download | chrome-ec-1ad60ff66e3399d2efd1d8a7c48a082a77c44621.tar.gz |
zephyr:test: Add USB pd console tests
Validate PD console commands
BUG=b:222240738
BRANCH=NONE
TEST=zmake test test-drivers
Signed-off-by: Al Semjonovs <asemjonovs@google.com>
Change-Id: I643f90d9b349991df09a7cd2c512e33340f41c5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3636186
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/src/console_cmd/usb_pd_console.c | 255 |
2 files changed, 256 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 315d1cabd6..b4c85defa2 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -29,6 +29,7 @@ target_sources(app PRIVATE src/console_cmd/accelrange.c src/console_cmd/accelread.c src/console_cmd/accelres.c + src/console_cmd/usb_pd_console.c src/cros_cbi.c src/espi.c src/gpio.c diff --git a/zephyr/test/drivers/src/console_cmd/usb_pd_console.c b/zephyr/test/drivers/src/console_cmd/usb_pd_console.c new file mode 100644 index 0000000000..417c4bc472 --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/usb_pd_console.c @@ -0,0 +1,255 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <shell/shell.h> +#include <ztest.h> + +#include "console.h" +#include "ec_commands.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +static void console_cmd_usb_pd_after(void *fixture) +{ + ARG_UNUSED(fixture); + + /* TODO (b/230059737) */ + test_set_chipset_to_g3(); + k_sleep(K_SECONDS(1)); + test_set_chipset_to_s0(); + k_sleep(K_SECONDS(10)); +} + +ZTEST_SUITE(console_cmd_usb_pd, drivers_predicate_post_main, NULL, NULL, + console_cmd_usb_pd_after, NULL); + +ZTEST_USER(console_cmd_usb_pd, test_too_few_args) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dump) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd dump 0"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump 4"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump -4"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump x"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_trysrc) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 0"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 2"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 5"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_version) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd version"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_bad_port) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 5"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 5 tx"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_tx) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 tx"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_charger) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 charger"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dev) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev 20"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev x"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_disable) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 disable"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_enable) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 enable"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_hard) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 hard"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_soft) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 soft"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_swap) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap power"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap data"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap vconn"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap x"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dualrole) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole on"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole off"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole freeze"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole sink"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole source"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole x"); + zassert_equal(rv, EC_ERROR_PARAM4, "Expected %d, but got %d", + EC_ERROR_PARAM4, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_state) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 state"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_srccaps) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 srccaps"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_timer) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 timer"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} |