summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2020-09-17 21:05:59 -0600
committerCommit Bot <commit-bot@chromium.org>2020-09-22 02:19:29 +0000
commitd03abea4c36062f922182b95e046fc6817e98eec (patch)
treecb90c1fe95ca5660d4055e0663f58b1ead034c40 /test
parent17838629321431d8248f3ade35993a9f21242477 (diff)
downloadchrome-ec-d03abea4c36062f922182b95e046fc6817e98eec.tar.gz
test: Add test_send_caps_error to usb_pe_drp
As requested in CL:2321869 review, make a new version of test_send_caps_error that uses the external interface of the PE layer. BUG=b:161835483 BRANCH=none TEST=make run-usb_pe_drp Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I983b145cd1e731e844363955896898a2374a0a30 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2419834 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/usb_pe_drp.c90
-rw-r--r--test/usb_prl.c23
2 files changed, 102 insertions, 11 deletions
diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c
index b210db4ae9..8c59dcf180 100644
--- a/test/usb_pe_drp.c
+++ b/test/usb_pe_drp.c
@@ -43,12 +43,102 @@ void before_test(void)
mock_dpm_reset();
mock_dp_alt_mode_reset();
mock_prl_reset();
+
+ /* Restart the PD task and let it settle */
+ task_set_event(TASK_ID_PD_C0, TASK_EVENT_RESET_DONE, 0);
+ task_wait_event(SECOND);
+}
+
+test_static int test_send_caps_error(void)
+{
+ /* Enable PE as source, expect SOURCE_CAP. */
+ mock_pd_port[PORT0].power_role = PD_ROLE_SOURCE;
+ mock_tc_port[PORT0].pd_enable = 1;
+ task_wait_event(10 * MSEC);
+ TEST_EQ(fake_prl_get_last_sent_data_msg_type(PORT0),
+ PD_DATA_SOURCE_CAP, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(10 * MSEC);
+
+ /* REQUEST 5V, expect ACCEPT, PS_RDY. */
+ rx_emsg[PORT0].header = PD_HEADER(PD_DATA_REQUEST, PD_ROLE_SINK,
+ PD_ROLE_UFP, 0,
+ 1, PD_REV30, 0);
+ rx_emsg[PORT0].len = 4;
+ *(uint32_t *)rx_emsg[PORT0].buf = RDO_FIXED(1, 500, 500, 0);
+ fake_prl_message_received(PORT0);
+ task_wait_event(10 * MSEC);
+ TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0),
+ PD_CTRL_ACCEPT, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(10 * MSEC);
+ TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0),
+ PD_CTRL_PS_RDY, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(30 * MSEC);
+
+ /* Expect VENDOR_DEF, reply NOT_SUPPORTED. */
+ TEST_EQ(fake_prl_get_last_sent_data_msg_type(PORT0),
+ PD_DATA_VENDOR_DEF, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(10 * MSEC);
+ rx_emsg[PORT0].header = PD_HEADER(PD_CTRL_NOT_SUPPORTED, PD_ROLE_SINK,
+ PD_ROLE_UFP, 2,
+ 0, PD_REV30, 0);
+ rx_emsg[PORT0].len = 0;
+ fake_prl_message_received(PORT0);
+ task_wait_event(30 * MSEC);
+
+ /* Expect GET_SOURCE_CAP, reply NOT_SUPPORTED. */
+ TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0),
+ PD_CTRL_GET_SOURCE_CAP, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(10 * MSEC);
+ rx_emsg[PORT0].header = PD_HEADER(PD_CTRL_NOT_SUPPORTED, PD_ROLE_SINK,
+ PD_ROLE_UFP, 2,
+ 0, PD_REV30, 0);
+ rx_emsg[PORT0].len = 0;
+ fake_prl_message_received(PORT0);
+ task_wait_event(200 * MSEC);
+
+ /*
+ * Now connected. Send GET_SOURCE_CAP, to check how error sending
+ * SOURCE_CAP is handled.
+ */
+ rx_emsg[PORT0].header = PD_HEADER(PD_CTRL_GET_SOURCE_CAP, PD_ROLE_SINK,
+ PD_ROLE_UFP, 3,
+ 0, PD_REV30, 0);
+ rx_emsg[PORT0].len = 0;
+ fake_prl_message_received(PORT0);
+ task_wait_event(10 * MSEC);
+ TEST_EQ(fake_prl_get_last_sent_data_msg_type(PORT0),
+ PD_DATA_SOURCE_CAP, "%d");
+
+ /* Simulate error sending SOURCE_CAP. */
+ fake_prl_report_error(PORT0, ERR_TCH_XMIT);
+ task_wait_event(20 * MSEC);
+
+ /*
+ * Expect SOFT_RESET.
+ * See section 8.3.3.4.1.1 PE_SRC_Send_Soft_Reset State and section
+ * 8.3.3.2.3 PE_SRC_Send_Capabilities State.
+ * "The PE_SRC_Send_Soft_Reset state Shall be entered from any state
+ * when ... A Message has not been sent after retries to the Sink"
+ */
+ TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0),
+ PD_CTRL_SOFT_RESET, "%d");
+ fake_prl_message_sent(PORT0);
+ task_wait_event(5 * SECOND);
+
+ return EC_SUCCESS;
}
void run_test(int argc, char **argv)
{
test_reset();
+ RUN_TEST(test_send_caps_error);
+
/* Do basic state machine validity checks last. */
RUN_TEST(test_pe_no_parent_cycles);
diff --git a/test/usb_prl.c b/test/usb_prl.c
index fa5444c85c..d0f3d48322 100644
--- a/test/usb_prl.c
+++ b/test/usb_prl.c
@@ -5,23 +5,24 @@
* Test USB Protocol Layer module.
*/
#include "common.h"
+#include "mock/tcpc_mock.h"
+#include "mock/tcpm_mock.h"
+#include "mock/usb_pd_mock.h"
+#include "mock/usb_pe_sm_mock.h"
+#include "mock/usb_tc_sm_mock.h"
#include "task.h"
#include "tcpci.h"
#include "tcpm.h"
#include "test_util.h"
#include "timer.h"
#include "usb_emsg.h"
-#include "usb_pd_test_util.h"
#include "usb_pd.h"
+#include "usb_pd_test_util.h"
#include "usb_pe_sm.h"
#include "usb_prl_sm.h"
#include "usb_sm_checks.h"
#include "usb_tc_sm.h"
#include "util.h"
-#include "mock/tcpc_mock.h"
-#include "mock/tcpm_mock.h"
-#include "mock/usb_tc_sm_mock.h"
-#include "mock/usb_pe_sm_mock.h"
#define PORT0 0
@@ -47,8 +48,8 @@ static int test_receive_control_msg(void)
{
int port = PORT0;
uint16_t header = PD_HEADER(PD_CTRL_DR_SWAP,
- mock_tc_port[port].power_role,
- mock_tc_port[port].data_role,
+ pd_get_power_role(port),
+ pd_get_data_role(port),
mock_tc_port[port].msg_rx_id,
0, mock_tc_port[port].rev, 0);
@@ -99,8 +100,8 @@ static int test_discard_queued_tx_when_rx_happens(void)
{
int port = PORT0;
uint16_t header = PD_HEADER(PD_CTRL_DR_SWAP,
- mock_tc_port[port].power_role,
- mock_tc_port[port].data_role,
+ pd_get_power_role(port),
+ pd_get_data_role(port),
mock_tc_port[port].msg_rx_id,
0, mock_tc_port[port].rev, 0);
uint8_t *buf = tx_emsg[port].buf;
@@ -139,8 +140,8 @@ void before_test(void)
{
mock_tc_port_reset();
mock_tc_port[PORT0].rev = PD_REV30;
- mock_tc_port[PORT0].power_role = PD_ROLE_SOURCE;
- mock_tc_port[PORT0].data_role = PD_ROLE_DFP;
+ mock_pd_port[PORT0].power_role = PD_ROLE_SOURCE;
+ mock_pd_port[PORT0].data_role = PD_ROLE_DFP;
mock_tcpm_reset();
mock_pe_port_reset();