summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2021-01-15 12:12:14 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-22 00:01:53 +0000
commit2034650b0b3aeb6685f26334491e9f5cacbe915e (patch)
tree9c5b3a686fb9a2a0db0cd8452f07f4183d424ff6 /test
parentea4a53732db48588bb77f853e574d52b0b70a528 (diff)
downloadchrome-ec-2034650b0b3aeb6685f26334491e9f5cacbe915e.tar.gz
TCPMv2: Test that PE ignores invalid BIST requests
Send the PE BIST requests with inappropriate VBUS voltages or inappropriate BIST modes. Verify that the PE ignores them. BUG=b:173023378,b:169385081,b:172709198,b:173028832,b:173028791 BUG=b:173141941,b:173142113 TEST=run-usb_pe_drp passes BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I240ff6746debcf49934419940ab4f49b54e2b7e9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2639585 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/test_config.h4
-rw-r--r--test/usb_pe_drp.c81
-rw-r--r--test/usb_pe_drp.mocklist1
l---------[-rw-r--r--]test/usb_pe_drp_noextended.mocklist13
4 files changed, 86 insertions, 13 deletions
diff --git a/test/test_config.h b/test/test_config.h
index 89ee2ba3fa..c240021501 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -418,7 +418,9 @@ int ncp15wb_calculate_temp(uint16_t adc);
#undef CONFIG_USB_PD_HOST_CMD
#define CONFIG_USB_PD_ALT_MODE_DFP
#define CONFIG_USBC_SS_MUX
-#endif
+#define I2C_PORT_HOST_TCPC 0
+#define CONFIG_CHARGE_MANAGER
+#endif /* TEST_USB_PE_DRP || TEST_USB_PE_DRP_NOEXTENDED */
/* Common TypeC tests defines */
#if defined(TEST_USB_TYPEC_VPD) || \
diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c
index 0b22c41c9c..749d144e9e 100644
--- a/test/usb_pe_drp.c
+++ b/test/usb_pe_drp.c
@@ -13,6 +13,7 @@
#include "usb_pe.h"
#include "usb_pe_sm.h"
#include "usb_sm_checks.h"
+#include "mock/charge_manager_mock.h"
#include "mock/usb_tc_sm_mock.h"
#include "mock/tcpc_mock.h"
#include "mock/usb_mux_mock.h"
@@ -143,6 +144,85 @@ test_static int finish_src_discovery(int startup_cable_probes)
}
/*
+ * Verify that the PE will ignore BIST packets when not at vSafe5V and BIST
+ * packets with unsupported BIST modes.
+ */
+test_static int test_bist_ignore(void)
+{
+ /* Bring up port as Source/DFP. Get to ready state. */
+ /* Enable PE as source, expect SOURCE_CAP. */
+ mock_tc_port[PORT0].power_role = PD_ROLE_SOURCE;
+ mock_tc_port[PORT0].pd_enable = 1;
+ mock_tc_port[PORT0].vconn_src = true;
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP,
+ 0, PD_DATA_SOURCE_CAP, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+ task_wait_event(10 * MSEC);
+
+ /* REQUEST 5V, expect ACCEPT, PS_RDY. */
+ rx_message(PD_MSG_SOP, 0, PD_DATA_REQUEST,
+ PD_ROLE_SINK, PD_ROLE_UFP, RDO_FIXED(1, 500, 500, 0));
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP,
+ PD_CTRL_ACCEPT, 0, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP,
+ PD_CTRL_PS_RDY, 0, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+
+ TEST_EQ(finish_src_discovery(0), EC_SUCCESS, "%d");
+
+ task_wait_event(5 * SECOND);
+
+
+ /* Set VBUS to 1.5V; the PE should ignore the BIST message. */
+ mock_charge_manager_set_vbus_voltage(1500);
+ rx_message(PD_MSG_SOP, 0, PD_DATA_BIST, PD_ROLE_SINK, PD_ROLE_UFP,
+ BDO(BDO_MODE_TEST_DATA, 0));
+ /*
+ * If the PE ignored the BIST message, it should respond normally to a
+ * subsequent Get Source Caps request.
+ */
+ rx_message(PD_MSG_SOP, PD_CTRL_GET_SINK_CAP, 0, PD_ROLE_SINK,
+ PD_ROLE_UFP, 0);
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP, 0,
+ PD_DATA_SINK_CAP, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+
+ /* Set VBUS to 20V; the PE should still ignore the BIST message. */
+ mock_charge_manager_set_vbus_voltage(20000);
+ rx_message(PD_MSG_SOP, 0, PD_DATA_BIST, PD_ROLE_SINK, PD_ROLE_UFP,
+ BDO(BDO_MODE_TEST_DATA, 0));
+ task_wait_event(1 * SECOND);
+ rx_message(PD_MSG_SOP, PD_CTRL_GET_SINK_CAP, 0, PD_ROLE_SINK,
+ PD_ROLE_UFP, 0);
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP, 0,
+ PD_DATA_SINK_CAP, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+
+ /*
+ * Set VBUS to 5V but request an unsupported BIST mode; the PE should
+ * still ignore the BIST message.
+ */
+ mock_charge_manager_set_vbus_voltage(5000);
+ rx_message(PD_MSG_SOP, 0, PD_DATA_BIST, PD_ROLE_SINK, PD_ROLE_UFP,
+ BDO(BDO_MODE_RECV, 0));
+ task_wait_event(1 * SECOND);
+ rx_message(PD_MSG_SOP, PD_CTRL_GET_SINK_CAP, 0, PD_ROLE_SINK,
+ PD_ROLE_UFP, 0);
+ TEST_EQ(mock_prl_wait_for_tx_msg(PORT0, TCPC_TX_SOP, 0,
+ PD_DATA_SINK_CAP, 10 * MSEC),
+ EC_SUCCESS, "%d");
+ mock_prl_message_sent(PORT0);
+
+ return EC_SUCCESS;
+}
+
+/*
* Verify that, before connection, PE_SRC_Send_Capabilities goes to
* PE_SRC_Discovery on send error, not PE_Send_Soft_Reset.
*/
@@ -275,6 +355,7 @@ void run_test(int argc, char **argv)
{
test_reset();
+ RUN_TEST(test_bist_ignore);
RUN_TEST(test_send_caps_error_before_connected);
RUN_TEST(test_send_caps_error_when_connected);
diff --git a/test/usb_pe_drp.mocklist b/test/usb_pe_drp.mocklist
index 1d8e4c8a81..b8879415d8 100644
--- a/test/usb_pe_drp.mocklist
+++ b/test/usb_pe_drp.mocklist
@@ -4,6 +4,7 @@
*/
#define CONFIG_TEST_MOCK_LIST \
+ MOCK(CHARGE_MANAGER) \
MOCK(USB_TC_SM) \
MOCK(TCPC) \
MOCK(USB_MUX) \
diff --git a/test/usb_pe_drp_noextended.mocklist b/test/usb_pe_drp_noextended.mocklist
index 1d8e4c8a81..c481115571 100644..120000
--- a/test/usb_pe_drp_noextended.mocklist
+++ b/test/usb_pe_drp_noextended.mocklist
@@ -1,12 +1 @@
-/* Copyright 2020 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_TC_SM) \
- MOCK(TCPC) \
- MOCK(USB_MUX) \
- MOCK(USB_PD_DPM) \
- MOCK(DP_ALT_MODE) \
- MOCK(USB_PRL)
+usb_pe_drp.mocklist \ No newline at end of file