summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-10-17 10:14:24 -0600
committerCommit Bot <commit-bot@chromium.org>2019-10-24 00:44:31 +0000
commitcb2fa8b437cb14e652f0e6374d3caf8e568a04ac (patch)
treebcb51a9ea792f8d2d40305ec78dbbe6afaf9f4fa /test
parent664d4e781063463923376bb9b557dc765d37b7e3 (diff)
downloadchrome-ec-cb2fa8b437cb14e652f0e6374d3caf8e568a04ac.tar.gz
usb: call pd_execute_data_swap within tc_set_data
We need to let board specific code run any time we change the data role on our USB-C connection. When looking at all of the calls to tc_set_data_role, I realized that we don't really reset any data role until we start a new contract with SNK/SRC ready. We will do need to call into the code that disables the MUX lines when we detach. To do this, I created a super state for SNK/SRC unattached. BRANCH=none BUG=none TEST=builds. No board has an OTG signal using the new stack yet Change-Id: I017d20b2e1973b31ebf2b8925a7f8c5488a8ee24 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1864427
Diffstat (limited to 'test')
-rw-r--r--test/test_config.h9
-rw-r--r--test/usb_typec_drp_acc_trysrc.c130
-rw-r--r--test/usb_typec_drp_acc_trysrc.mocklist8
3 files changed, 143 insertions, 4 deletions
diff --git a/test/test_config.h b/test/test_config.h
index 7771a05c0f..30a82ba863 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -299,8 +299,7 @@ int ncp15wb_calculate_temp(uint16_t adc);
/* Common TypeC tests defines */
#if defined(TEST_USB_TYPEC_VPD) || \
- defined(TEST_USB_TYPEC_CTVPD) || \
- defined(TEST_USB_TYPEC_DRP_ACC_TRYSRC)
+ defined(TEST_USB_TYPEC_CTVPD)
#define CONFIG_USB_PID 0x5036
#define VPD_HW_VERSION 0x0001
#define VPD_FW_VERSION 0x0001
@@ -335,6 +334,12 @@ int ncp15wb_calculate_temp(uint16_t adc);
#define CONFIG_USB_TYPEC_DRP_ACC_TRYSRC
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_TRY_SRC
+#define CONFIG_USB_TYPEC_SM
+#define CONFIG_USB_SM_FRAMEWORK
+#define CONFIG_USB_PD_PORT_COUNT 1
+#define CONFIG_USBC_SS_MUX
+#define CONFIG_USB_PD_VBUS_DETECT_TCPC
+#define CONFIG_USB_POWER_DELIVERY
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#endif
diff --git a/test/usb_typec_drp_acc_trysrc.c b/test/usb_typec_drp_acc_trysrc.c
index cce747e94c..5981001344 100644
--- a/test/usb_typec_drp_acc_trysrc.c
+++ b/test/usb_typec_drp_acc_trysrc.c
@@ -4,11 +4,133 @@
*
* Test USB Type-C VPD and CTVPD module.
*/
+#include "charge_manager.h"
+#include "mock/tcpc_mock.h"
+#include "mock/usb_mux_mock.h"
#include "task.h"
-#include "timer.h"
#include "test_util.h"
+#include "timer.h"
+#include "usb_mux.h"
+#include "usb_pd_tcpm.h"
#include "usb_sm_checks.h"
-#include "charge_manager.h"
+
+#define PORT0 0
+
+/* Install Mock TCPC and MUX drivers */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
+ {
+ .drv = &mock_tcpc_driver,
+ },
+};
+
+struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
+ {
+ .driver = &mock_usb_mux_driver,
+ }
+};
+
+void charge_manager_set_ceil(int port, enum ceil_requestor requestor, int ceil)
+{
+ /* Do Nothing, but needed for linking */
+}
+
+__maybe_unused static int test_mux_con_dis_as_src(void)
+{
+ /* Update CC lines send state machine event to process */
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_RD;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+
+ /* This wait trainsitions through AttachWait.SRC then Attached.SRC */
+ task_wait_event(SECOND);
+
+ /* We are in Attached.SRC now */
+ TEST_EQ(mock_usb_mux.state, TYPEC_MUX_USB, "%d");
+ TEST_EQ(mock_usb_mux.num_set_calls, 1, "%d");
+
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+
+ /* This wait will go through TryWait.SNK then to Unattached.SNK */
+ task_wait_event(10 * SECOND);
+
+ /* We are in Unattached.SNK. The mux should have detached */
+ TEST_EQ(mock_usb_mux.state, TYPEC_MUX_NONE, "%d");
+ TEST_EQ(mock_usb_mux.num_set_calls, 2, "%d");
+
+ return EC_SUCCESS;
+}
+
+__maybe_unused static int test_mux_con_dis_as_snk(void)
+{
+ /* Update CC lines send state machine event to process */
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_RP_3_0;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.vbus_level = 1;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+
+ /* This wait will go through AttachWait.SNK to Attached.SNK */
+ task_wait_event(5 * SECOND);
+
+ /* We are in Attached.SNK now */
+ TEST_EQ(mock_usb_mux.state, TYPEC_MUX_USB, "%d");
+ TEST_EQ(mock_usb_mux.num_set_calls, 1, "%d");
+
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.vbus_level = 0;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+
+ /* This wait will go through TryWait.SNK then to Unattached.SNK */
+ task_wait_event(10 * SECOND);
+
+ /* We are in Unattached.SNK. The mux should have detached */
+ TEST_EQ(mock_usb_mux.state, TYPEC_MUX_NONE, "%d");
+ TEST_EQ(mock_usb_mux.num_set_calls, 2, "%d");
+
+ return EC_SUCCESS;
+}
+
+__maybe_unused static int test_power_role_set(void)
+{
+ /* Print out header changes for easier debugging */
+ mock_tcpc.should_print_header_changes = true;
+
+ /* Update CC lines send state machine event to process */
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_RD;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+ task_wait_event(10 * SECOND);
+
+ /* We are in Attached.SRC now */
+ TEST_EQ(mock_tcpc.power_role, PD_ROLE_SOURCE, "%d");
+ TEST_EQ(mock_tcpc.data_role, PD_ROLE_DFP, "%d");
+
+ /*
+ * We allow 2 separate calls to update the header since power and data
+ * role updates can be separate calls depending on the state is came
+ * from.
+ */
+ TEST_LE(mock_tcpc.num_calls_to_set_header, 2, "%d");
+
+ return EC_SUCCESS;
+}
+
+/* Reset the mocks before each test */
+void before_test(void)
+{
+ mock_usb_mux_reset();
+ mock_tcpc_reset();
+}
+
+void after_test(void)
+{
+ /* Disconnect any CC lines */
+ mock_tcpc.cc1 = TYPEC_CC_VOLT_OPEN;
+ mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN;
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_CC, 0);
+}
void run_test(void)
{
@@ -18,6 +140,10 @@ void run_test(void)
task_wake(TASK_ID_PD_C0);
task_wait_event(5 * MSEC);
+ RUN_TEST(test_mux_con_dis_as_src);
+ RUN_TEST(test_mux_con_dis_as_snk);
+ RUN_TEST(test_power_role_set);
+
/* Do basic state machine sanity checks last. */
RUN_TEST(test_tc_no_parent_cycles);
RUN_TEST(test_tc_no_empty_state);
diff --git a/test/usb_typec_drp_acc_trysrc.mocklist b/test/usb_typec_drp_acc_trysrc.mocklist
new file mode 100644
index 0000000000..71c2e2cee9
--- /dev/null
+++ b/test/usb_typec_drp_acc_trysrc.mocklist
@@ -0,0 +1,8 @@
+/* Copyright 2019 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.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(USB_MUX) \
+ MOCK(TCPC)