summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2023-02-22 15:13:42 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-23 22:01:36 +0000
commit0714f88fdba22af0bbc258d1783f7452a4092680 (patch)
tree4f1ec9f4e3a0334330fb66b097ed2b0b640ec0be
parent2444aa135973716b25fed01e0b5163a932643617 (diff)
downloadchrome-ec-stabilize-15361.B-main.tar.gz
Zephyr test: Add a test for mfallow commandstabilize-15361.B-main
The mfallow console command was created for developer testing to switch between preferred DP pin modes. Add a test for it, and have the test snoop the PD traffic to ensure the command functions correctly. BRANCH=None BUG=None TEST=./twister -T ./zephyr/test Change-Id: I98c02ecd4cfd9b2df57adb900df8a0d83af44d22 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4283690 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/test/drivers/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/Kconfig3
-rw-r--r--zephyr/test/drivers/console_cmd_mfallow/CMakeLists.txt15
-rw-r--r--zephyr/test/drivers/console_cmd_mfallow/prj.conf6
-rw-r--r--zephyr/test/drivers/console_cmd_mfallow/src/console_cmd_mfallow.c235
-rw-r--r--zephyr/test/drivers/testcase.yaml4
6 files changed, 264 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index 96e1126711..d21912cce3 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -18,6 +18,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_ANX7447 anx7447)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_AP_MUX_CONTROL ap_mux_control)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_AP_VDM_CONTROL ap_vdm_control)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_CONSOLE_CMD_CRASH console_cmd_crash)
+add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_CONSOLE_CMD_MFALLOW console_cmd_mfallow)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_COMMON_CBI common_cbi)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_COMMON_CBI_GPIO common_cbi_gpio)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_COMMON_CHARGER common_charger)
diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig
index 65c881de1a..9bbe66e687 100644
--- a/zephyr/test/drivers/Kconfig
+++ b/zephyr/test/drivers/Kconfig
@@ -14,6 +14,9 @@ config LINK_TEST_SUITE_DEFAULT_CONSOLE_CMDS
config LINK_TEST_SUITE_CONSOLE_CMD_CRASH
bool "Link and test the console command crash test suite"
+config LINK_TEST_SUITE_CONSOLE_CMD_MFALLOW
+ bool "Link and test the console command mfallow test suite"
+
config LINK_TEST_SUITE_ANX7447
bool "Link and test the anx7447 tests"
diff --git a/zephyr/test/drivers/console_cmd_mfallow/CMakeLists.txt b/zephyr/test/drivers/console_cmd_mfallow/CMakeLists.txt
new file mode 100644
index 0000000000..abaf5246ba
--- /dev/null
+++ b/zephyr/test/drivers/console_cmd_mfallow/CMakeLists.txt
@@ -0,0 +1,15 @@
+# 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.
+
+# Create library name based on current directory
+zephyr_library_get_current_dir_lib_name(${ZEPHYR_BASE} lib_name)
+
+# Create interface library
+zephyr_interface_library_named(${lib_name})
+
+# Add source files
+zephyr_library_sources("${CMAKE_CURRENT_SOURCE_DIR}/src/console_cmd_mfallow.c")
+
+# Link in the library
+zephyr_library_link_libraries(${lib_name})
diff --git a/zephyr/test/drivers/console_cmd_mfallow/prj.conf b/zephyr/test/drivers/console_cmd_mfallow/prj.conf
new file mode 100644
index 0000000000..4caf617623
--- /dev/null
+++ b/zephyr/test/drivers/console_cmd_mfallow/prj.conf
@@ -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.
+
+CONFIG_PLATFORM_EC_CONSOLE_CMD_MFALLOW=y
+CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY=y
diff --git a/zephyr/test/drivers/console_cmd_mfallow/src/console_cmd_mfallow.c b/zephyr/test/drivers/console_cmd_mfallow/src/console_cmd_mfallow.c
new file mode 100644
index 0000000000..97b3150017
--- /dev/null
+++ b/zephyr/test/drivers/console_cmd_mfallow/src/console_cmd_mfallow.c
@@ -0,0 +1,235 @@
+/* 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.
+ */
+
+#include "console.h"
+#include "ec_commands.h"
+#include "test/drivers/stubs.h"
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+#include "usb_dp_alt_mode.h"
+#include "usb_mux.h"
+#include "usb_pd_vdo.h"
+
+#include <stdint.h>
+
+#include <zephyr/kernel.h>
+#include <zephyr/shell/shell.h>
+#include <zephyr/sys/byteorder.h>
+#include <zephyr/ztest.h>
+
+#define TEST_PORT USBC_PORT_C0
+
+struct console_cmd_mfallow_fixture {
+ const struct emul *tcpci_emul;
+ const struct emul *charger_emul;
+ struct tcpci_partner_data partner;
+ struct tcpci_src_emul_data src_ext;
+};
+
+static void add_dp_discovery(struct tcpci_partner_data *partner)
+{
+ /* Add Discover Identity response */
+ partner->identity_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_PD, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_IDENT) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->identity_vdm[VDO_INDEX_IDH] = VDO_IDH(
+ /* USB host */ false, /* USB device */ true, IDH_PTYPE_HUB,
+ /* modal operation */ true, USB_VID_GOOGLE);
+ partner->identity_vdm[VDO_INDEX_CSTAT] = 0;
+ partner->identity_vdm[VDO_INDEX_PRODUCT] = VDO_PRODUCT(0x1234, 0x5678);
+ /* Hardware version 1, firmware version 2 */
+ partner->identity_vdm[VDO_INDEX_PTYPE_UFP1_VDO] = VDO_UFP1(
+ (VDO_UFP1_CAPABILITY_USB20 | VDO_UFP1_CAPABILITY_USB32),
+ USB_TYPEC_RECEPTACLE, VDO_UFP1_ALT_MODE_RECONFIGURE,
+ USB_R30_SS_U32_U40_GEN2);
+ partner->identity_vdos = VDO_INDEX_PTYPE_UFP1_VDO + 1;
+
+ /* Add Discover Modes response */
+ /* Support one mode for DisplayPort VID.*/
+ partner->modes_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_DISPLAYPORT, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_MODES) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->modes_vdm[VDO_INDEX_HDR + 1] =
+ VDO_MODE_DP(MODE_DP_PIN_C | MODE_DP_PIN_D, 0, 1,
+ CABLE_RECEPTACLE, MODE_DP_V13, MODE_DP_SNK);
+ partner->modes_vdos = VDO_INDEX_HDR + 2;
+
+ /* Add Discover SVIDs response */
+ /* Support DisplayPort VID. */
+ partner->svids_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_PD, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_SVID) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->svids_vdm[VDO_INDEX_HDR + 1] =
+ VDO_SVID(USB_SID_DISPLAYPORT, 0);
+ partner->svids_vdos = VDO_INDEX_HDR + 2;
+}
+
+static void add_displayport_mode_responses(struct tcpci_partner_data *partner)
+{
+ /* Add DisplayPort EnterMode response */
+ partner->enter_mode_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_DISPLAYPORT, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_ENTER_MODE) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->enter_mode_vdos = VDO_INDEX_HDR + 1;
+
+ /* Add DisplayPort StatusUpdate response */
+ partner->dp_status_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_DISPLAYPORT, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_DP_STATUS) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->dp_status_vdm[VDO_INDEX_HDR + 1] =
+ VDO_DP_STATUS(0, /* IRQ_HPD */
+ false, /* HPD_HI|LOW - Changed*/
+ 0, /* request exit DP */
+ 0, /* request exit USB */
+ 1, /* MF pref - must be 1 for this test */
+ true, /* DP Enabled */
+ 0, /* power low e.g. normal */
+ 0x2 /* Connected as Sink */);
+ partner->dp_status_vdos = VDO_INDEX_HDR + 2;
+
+ /* Add DisplayPort Configure Response */
+ partner->dp_config_vdm[VDO_INDEX_HDR] =
+ VDO(USB_SID_DISPLAYPORT, /* structured VDM */ true,
+ VDO_CMDT(CMDT_RSP_ACK) | CMD_DP_CONFIG) |
+ VDO_SVDM_VERS(VDM_VER20);
+ partner->dp_config_vdos = VDO_INDEX_HDR + 1;
+}
+
+static uint32_t dp_config_extract(struct console_cmd_mfallow_fixture *fixture)
+{
+ struct tcpci_partner_log_msg *msg;
+
+ SYS_SLIST_FOR_EACH_CONTAINER(&fixture->partner.msg_log, msg, node)
+ {
+ uint16_t header = sys_get_le16(msg->buf);
+
+ /* Ignore messages from ourselves */
+ if (msg->sender == TCPCI_PARTNER_SENDER_PARTNER)
+ continue;
+
+ /*
+ * Control messages, non-VDMs, and extended messages are not of
+ * interest
+ */
+ if ((PD_HEADER_CNT(header) == 0) ||
+ (PD_HEADER_TYPE(header) != PD_DATA_VENDOR_DEF) ||
+ (PD_HEADER_EXT(header) != 0)) {
+ continue;
+ }
+
+ uint32_t vdm_header = sys_get_le32(msg->buf + 2);
+
+ /* We have a VDM, return if it's DP:Configure */
+ if (PD_VDO_SVDM(vdm_header) &&
+ (PD_VDO_CMD(vdm_header) == CMD_DP_CONFIG))
+ return sys_get_le32(msg->buf + 6);
+ }
+
+ zassert_unreachable();
+ return 0;
+}
+
+static void *console_cmd_mfallow_setup(void)
+{
+ static struct console_cmd_mfallow_fixture fixture;
+ struct tcpci_partner_data *partner = &fixture.partner;
+ struct tcpci_src_emul_data *src_ext = &fixture.src_ext;
+
+ tcpci_partner_init(partner, PD_REV30);
+ partner->extensions = tcpci_src_emul_init(src_ext, partner, NULL);
+
+ /* Get references for the emulators */
+ fixture.tcpci_emul = EMUL_DT_GET(DT_NODELABEL(tcpci_emul));
+ fixture.charger_emul = EMUL_DT_GET(DT_NODELABEL(isl923x_emul));
+
+ return &fixture;
+}
+
+static void console_cmd_mfallow_before(void *data)
+{
+ struct console_cmd_mfallow_fixture *fix = data;
+ struct tcpci_partner_data *partner = &fix->partner;
+
+ /* Set chipset on so the "AP" is on to give us commands */
+ test_set_chipset_to_s0();
+
+ /* Set up the partner as DP-capable with pin modes C and D */
+ add_dp_discovery(partner);
+ add_displayport_mode_responses(partner);
+
+ /* Connect our port partner */
+ connect_source_to_port(&fix->partner, &fix->src_ext, 0, fix->tcpci_emul,
+ fix->charger_emul);
+}
+
+static void console_cmd_mfallow_after(void *data)
+{
+ struct console_cmd_mfallow_fixture *fix = data;
+
+ disconnect_source_from_port(fix->tcpci_emul, fix->charger_emul);
+ tcpci_partner_common_clear_logged_msgs(&fix->partner);
+}
+
+ZTEST_SUITE(console_cmd_mfallow, drivers_predicate_post_main,
+ console_cmd_mfallow_setup, console_cmd_mfallow_before,
+ console_cmd_mfallow_after, NULL);
+
+ZTEST_F(console_cmd_mfallow, test_mfallow_bad_arg_num)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "mfallow");
+
+ zassert_equal(EC_ERROR_PARAM_COUNT, rv);
+}
+
+ZTEST_F(console_cmd_mfallow, test_mfallow_bad_port)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "mfallow fish true");
+
+ zassert_equal(EC_ERROR_PARAM1, rv);
+}
+
+ZTEST_F(console_cmd_mfallow, test_mfallow_bad_boolean)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "mfallow 0 sardine");
+
+ zassert_equal(EC_ERROR_PARAM2, rv);
+}
+
+ZTEST_F(console_cmd_mfallow, test_mfallow_true)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "mfallow 0 true");
+
+ zassert_equal(EC_SUCCESS, rv);
+
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, true);
+ host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP);
+ k_sleep(K_MSEC(500));
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, false);
+
+ uint32_t config_vdo = dp_config_extract(fixture);
+
+ zassert_equal(PD_DP_CFG_PIN(config_vdo), MODE_DP_PIN_D);
+}
+
+ZTEST_F(console_cmd_mfallow, test_mfallow_false)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "mfallow 0 false");
+
+ zassert_equal(EC_SUCCESS, rv);
+
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, true);
+ host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP);
+ k_sleep(K_MSEC(500));
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, false);
+
+ uint32_t config_vdo = dp_config_extract(fixture);
+
+ zassert_equal(PD_DP_CFG_PIN(config_vdo), MODE_DP_PIN_C);
+}
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index 9bdedb6fc3..d7bfeceddf 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -108,6 +108,10 @@ tests:
- CONFIG_LINK_TEST_SUITE_CONSOLE_CMD_CRASH=y
- CONFIG_PLATFORM_EC_CONSOLE_CMD_CRASH=y
- CONFIG_ASSERT_TEST=y
+ drivers.console_cmd_mfallow:
+ extra_args: CONF_FILE="prj.conf;console_cmd_mfallow/prj.conf"
+ extra_configs:
+ - CONFIG_LINK_TEST_SUITE_CONSOLE_CMD_MFALLOW=y
drivers.dps:
extra_args: CONF_FILE="prj.conf;dps/prj.conf"
extra_configs: