summaryrefslogtreecommitdiff
path: root/zephyr/test
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2023-01-28 10:35:26 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-07 23:24:10 +0000
commit7884deec9f9c255724cf3d32566e7876e0dc3b71 (patch)
tree3a618941b71ea047762631d3c6c0f7effa144846 /zephyr/test
parentd9b9cb6e89a9d3082421e26a3bd20ce08e73379b (diff)
downloadchrome-ec-7884deec9f9c255724cf3d32566e7876e0dc3b71.tar.gz
TCPMv2: Gate DP module support on a CONFIG
Add a CONFIG option to gate DP mode support within the embedded controller. By default, turn the DP module off if the AP is controlling the VDMs for mode entry. For modules which do not implement the DP config option, the header now defines stubs for DP specific functions to use. This obsoletes some of the stub functions from older unit tests. BRANCH=None BUG=b:266714542 TEST=on skyrim, compile with DP disabled and observe 3162 bytes saved, run zmake compare-builds -a and util/compare_build.sh -b all, ./twister -T ./zephyr/test passes (note: ECOS compare builds needed all assert statements removed to pass, as they grab the line number, zephyr compare builds passed before HC mode entry was revamped) Change-Id: I9619eb5d34e418f1972c4bf16d4cf9c8d551eac5 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4201454 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Diffstat (limited to 'zephyr/test')
-rw-r--r--zephyr/test/drivers/ap_vdm_control/prj.conf3
-rw-r--r--zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c118
2 files changed, 121 insertions, 0 deletions
diff --git a/zephyr/test/drivers/ap_vdm_control/prj.conf b/zephyr/test/drivers/ap_vdm_control/prj.conf
index 685fa4c15d..215a8ab36d 100644
--- a/zephyr/test/drivers/ap_vdm_control/prj.conf
+++ b/zephyr/test/drivers/ap_vdm_control/prj.conf
@@ -5,3 +5,6 @@
CONFIG_PLATFORM_EC_USB_MUX_AP_CONTROL=y
CONFIG_PLATFORM_EC_USB_MUX_TASK=y
CONFIG_PLATFORM_EC_USB_PD_VDM_AP_CONTROL=y
+
+CONFIG_PLATFORM_EC_USB_PD_TBT_COMPAT_MODE=n
+CONFIG_PLATFORM_EC_USB_PD_USB4=n
diff --git a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c
index 2758b5bc52..897155485c 100644
--- a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c
+++ b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c
@@ -7,6 +7,7 @@
#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"
@@ -154,6 +155,39 @@ static void verify_vdm_req(struct ap_vdm_control_fixture *fixture,
zassert_true(message_seen, "Expected message not found");
}
+static void verify_no_vdms(struct ap_vdm_control_fixture *fixture)
+{
+ struct tcpci_partner_log_msg *msg;
+
+ /* LCOV_EXCL_START */
+ /*
+ * Code is not expected to be reached, but this check is
+ * written to be tolerant of unrelated messages coming through
+ * during the test run to avoid needlessly brittle test code.
+ */
+ 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;
+ }
+
+ zassert_unreachable();
+ }
+ /* LCOV_EXCL_STOP */
+}
+
static void *ap_vdm_control_setup(void)
{
static struct ap_vdm_control_fixture fixture;
@@ -765,3 +799,87 @@ ZTEST_F(ap_vdm_control, test_vdm_attention_disconnect_clear)
zassert_equal(vdm_resp.vdm_attention_left, 0,
"Failed to see no more messages");
}
+
+ZTEST_F(ap_vdm_control, test_no_ec_dp_enter)
+{
+ struct ec_params_typec_control params = {
+ .port = TEST_PORT,
+ .command = TYPEC_CONTROL_COMMAND_ENTER_MODE,
+ .mode_to_enter = TYPEC_MODE_DP,
+ };
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params);
+
+ /*
+ * Confirm that the EC doesn't try to send EnterMode messages for DP on
+ * its own through the EC DPM logic
+ */
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, true);
+ zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM);
+ k_sleep(K_SECONDS(1));
+
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, false);
+
+ verify_no_vdms(fixture);
+}
+
+ZTEST_F(ap_vdm_control, test_no_ec_dp_exit)
+{
+ /*
+ * Confirm that the EC won't try to exit DP mode on its own through the
+ * EC's DPM logic
+ */
+ run_verify_dp_entry(fixture, 1);
+
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, true);
+ host_cmd_typec_control_exit_modes(TEST_PORT);
+ k_sleep(K_SECONDS(1));
+
+ tcpci_partner_common_enable_pd_logging(&fixture->partner, false);
+
+ verify_no_vdms(fixture);
+}
+
+ZTEST_F(ap_vdm_control, test_dp_stub_returns)
+{
+ int temp;
+ uint32_t data[2];
+
+ /*
+ * Confirm that the DP stubs return what we expect them to without
+ * the EC running its DP module
+ */
+ run_verify_dp_entry(fixture, 1);
+
+ zassert_false(dp_is_active(TEST_PORT));
+ zassert_true(dp_is_idle(TEST_PORT));
+ zassert_false(dp_entry_is_done(TEST_PORT));
+ zassert_equal(dp_setup_next_vdm(TEST_PORT, &temp, data),
+ MSG_SETUP_ERROR);
+}
+
+ZTEST_F(ap_vdm_control, test_no_ec_dp_mode)
+{
+ struct ec_response_typec_status status;
+ struct ec_response_usb_pd_control_v2 legacy_status;
+ struct ec_params_usb_pd_control params = {
+ .port = TEST_PORT,
+ .role = USB_PD_CTRL_ROLE_NO_CHANGE,
+ .mux = USB_PD_CTRL_MUX_NO_CHANGE,
+ .swap = USB_PD_CTRL_SWAP_NONE
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_USB_PD_CONTROL, 2, legacy_status, params);
+
+ /*
+ * Confirm that neither old nor new APIs see the EC selecting a DP pin
+ * mode
+ */
+ run_verify_dp_entry(fixture, 1);
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(legacy_status.dp_mode, 0);
+
+ status = host_cmd_typec_status(TEST_PORT);
+ zassert_equal(status.dp_pin, 0);
+}