summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2023-01-17 21:05:15 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-20 09:32:22 +0000
commit5c1ae7b6e46d7cad23aae21c2ee36ece45de8008 (patch)
treef540314ce2957b40bc661ca2af949493254eec0c
parentca2ec79d639bb0af5ce6ae56b48a9d109489613b (diff)
downloadchrome-ec-5c1ae7b6e46d7cad23aae21c2ee36ece45de8008.tar.gz
zephyr/test: Add EC_CMD_USB_PD_DEV_INFO coverage
Add rudimentary coverage for the EC_CMD_USB_PD_DEV_INFO host command. This is a host command used to interact with PD chips (TCPCs) running cros EC code. These are only found on very old hardware and are not really supported any more. BRANCH=none BUG=b:258110734 TEST='./twister -v -T zephyr/test' passes 'make buildall' passes Change-Id: I96e704d521fc569d31d03dcdc588727da1f11951 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4176178 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/test/drivers/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/Kconfig6
-rw-r--r--zephyr/test/drivers/common/include/test/drivers/utils.h10
-rw-r--r--zephyr/test/drivers/common/src/utils.c12
-rw-r--r--zephyr/test/drivers/testcase.yaml3
-rw-r--r--zephyr/test/drivers/usbc_legacy/CMakeLists.txt6
-rw-r--r--zephyr/test/drivers/usbc_legacy/src/ec_pd_dev_ops.c35
7 files changed, 73 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index a890dd46f8..aab3db65e0 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -49,6 +49,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_SVDM_DFP_ONLY usbc_svdm_dfp_o
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_TBT_MODE usbc_tbt_mode)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_USB4_MODE usbc_usb4_mode)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_VCONN_SWAP usbc_vconn_swap)
+add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_LEGACY usbc_legacy)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_OCP usbc_ocp)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_PPC usbc_ppc)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_HOST_COMMANDS host_cmd)
diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig
index 299e4fd3f5..321db83508 100644
--- a/zephyr/test/drivers/Kconfig
+++ b/zephyr/test/drivers/Kconfig
@@ -137,6 +137,12 @@ config LINK_TEST_SUITE_USBC_FRS
select LOG
select PLATFORM_EC_USB_PD_FRS
+config LINK_TEST_SUITE_USBC_LEGACY
+ bool "Link tests for common USBC legacy code"
+ help
+ Include test coverage for legacy USB-C code. This is typically
+ for obsolete functionality or unsupported hardware.
+
config LINK_TEST_SUITE_USBC_OCP
bool "Link tests for common USBC OCP code"
diff --git a/zephyr/test/drivers/common/include/test/drivers/utils.h b/zephyr/test/drivers/common/include/test/drivers/utils.h
index a39a36dc33..0a811eecd5 100644
--- a/zephyr/test/drivers/common/include/test/drivers/utils.h
+++ b/zephyr/test/drivers/common/include/test/drivers/utils.h
@@ -506,6 +506,16 @@ void host_cmd_usb_pd_get_amode(
int *response_size);
/**
+ * @brief Run the host command to get the PD chip information.
+ *
+ * @param port The USB-C port number
+ * @param response Destination for command response.
+ * @return The result code from the host command
+ */
+int host_cmd_usb_pd_dev_info(uint8_t port,
+ struct ec_params_usb_pd_rw_hash_entry *response);
+
+/**
* Run the host command to control PD port behavior, with the sub-command of
* TYPEC_CONTROL_COMMAND_ENTER_MODE
*
diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c
index 1086ff4dbd..83e82a090a 100644
--- a/zephyr/test/drivers/common/src/utils.c
+++ b/zephyr/test/drivers/common/src/utils.c
@@ -635,6 +635,18 @@ void host_cmd_usb_pd_get_amode(
*response_size = args.response_size;
}
+int host_cmd_usb_pd_dev_info(uint8_t port,
+ struct ec_params_usb_pd_rw_hash_entry *response)
+{
+ struct ec_params_usb_pd_info_request params = {
+ .port = port,
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_USB_PD_DEV_INFO, 0, *response, params);
+
+ return host_command_process(&args);
+}
+
void host_events_save(struct host_events_ctx *host_events_ctx)
{
host_events_ctx->lpc_host_events = lpc_get_host_events();
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index a5cfdfd206..5565bddf94 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -276,6 +276,9 @@ tests:
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_FRS=y
- CONFIG_PLATFORM_EC_USB_PD_FRS_TCPC=y
+ drivers.usbc_legacy:
+ extra_configs:
+ - CONFIG_LINK_TEST_SUITE_USBC_LEGACY=y
drivers.usbc_ocp:
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_OCP=y
diff --git a/zephyr/test/drivers/usbc_legacy/CMakeLists.txt b/zephyr/test/drivers/usbc_legacy/CMakeLists.txt
new file mode 100644
index 0000000000..b438cea943
--- /dev/null
+++ b/zephyr/test/drivers/usbc_legacy/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Copyright 2023 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/ec_pd_dev_ops.c)
diff --git a/zephyr/test/drivers/usbc_legacy/src/ec_pd_dev_ops.c b/zephyr/test/drivers/usbc_legacy/src/ec_pd_dev_ops.c
new file mode 100644
index 0000000000..e2e84d8926
--- /dev/null
+++ b/zephyr/test/drivers/usbc_legacy/src/ec_pd_dev_ops.c
@@ -0,0 +1,35 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+ * Tests for operations related to PD chips based on chrome EC
+ * source. Modern devices do not use this. These tests are primarily for
+ * code coverage purposes.
+ */
+
+#include "config.h"
+#include "ec_commands.h"
+#include "host_command.h"
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+#include <zephyr/ztest.h>
+
+#define TEST_PORT 0
+#define INVALID_TEST_PORT 99
+
+ZTEST(ec_pd_dev_ops, dev_info)
+{
+ struct ec_params_usb_pd_rw_hash_entry response;
+
+ zassert_equal(EC_RES_INVALID_PARAM,
+ host_cmd_usb_pd_dev_info(INVALID_TEST_PORT, &response));
+
+ zassert_ok(host_cmd_usb_pd_dev_info(TEST_PORT, &response), NULL);
+ /* We have not set up a device on the port, so dev_id should be 0. */
+ zassert_equal(0, response.dev_id);
+}
+
+ZTEST_SUITE(ec_pd_dev_ops, NULL, NULL, NULL, NULL, NULL);