diff options
author | Edward Hill <ecgh@chromium.org> | 2020-12-17 15:30:09 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-18 02:51:57 +0000 |
commit | 2d3880546c4484501d80856183ac2b1f7640d27d (patch) | |
tree | a8f0e796357cbbd8411a5814d15f58fb9c06ee06 /test | |
parent | 8bc8a505f25f219cc1b072be87f26a61e58b6173 (diff) | |
download | chrome-ec-2d3880546c4484501d80856183ac2b1f7640d27d.tar.gz |
TCPMv2: Remove test/usb_tcpmv2_tcpci.c
Remove test/usb_tcpmv2_tcpci.c to avoid duplication with
test/usb_tcpmv2_compliance.c
BUG=none
BRANCH=none
TEST=make run-usb_tcpmv2_compliance
Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: Ie62d0f7e2cc30c3086e03103a43dede5515006b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2597598
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 5 | ||||
-rw-r--r-- | test/test_config.h | 29 | ||||
-rw-r--r-- | test/usb_tcpmv2_compliance.c | 4 | ||||
-rw-r--r-- | test/usb_tcpmv2_compliance.h | 4 | ||||
-rw-r--r-- | test/usb_tcpmv2_tcpci.c | 405 | ||||
-rw-r--r-- | test/usb_tcpmv2_tcpci.mocklist | 8 | ||||
-rw-r--r-- | test/usb_tcpmv2_tcpci.tasklist | 11 | ||||
-rw-r--r-- | test/usb_tcpmv2_td_pd_other.c | 107 |
8 files changed, 117 insertions, 456 deletions
diff --git a/test/build.mk b/test/build.mk index 20e7146e20..908665e0a6 100644 --- a/test/build.mk +++ b/test/build.mk @@ -92,7 +92,6 @@ test-list-host += usb_typec_vpd test-list-host += usb_typec_ctvpd test-list-host += usb_typec_drp_acc_trysrc test-list-host += usb_prl_old -test-list-host += usb_tcpmv2_tcpci test-list-host += usb_tcpmv2_compliance test-list-host += usb_prl test-list-host += usb_prl_noextended @@ -217,13 +216,13 @@ usb_pe_drp_old-y=usb_pe_drp_old.o usb_sm_checks.o fake_usbc.o usb_pe_drp_old_noextended-y=usb_pe_drp_old.o usb_sm_checks.o fake_usbc.o usb_pe_drp-y=usb_pe_drp.o usb_sm_checks.o usb_pe_drp_noextended-y=usb_pe_drp_noextended.o usb_sm_checks.o -usb_tcpmv2_tcpci-y=usb_tcpmv2_tcpci.o vpd_api.o usb_sm_checks.o usb_tcpmv2_compliance-y=usb_tcpmv2_compliance.o vpd_api.o usb_sm_checks.o \ usb_tcpmv2_compliance_common.o \ usb_tcpmv2_td_pd_ll_e3.o \ usb_tcpmv2_td_pd_ll_e4.o \ usb_tcpmv2_td_pd_src3_e26.o \ - usb_tcpmv2_td_pd_snk3_e12.o + usb_tcpmv2_td_pd_snk3_e12.o \ + usb_tcpmv2_td_pd_other.o utils-y=utils.o utils_str-y=utils_str.o vboot-y=vboot.o diff --git a/test/test_config.h b/test/test_config.h index fec9fd7084..eb3f428a09 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -472,35 +472,6 @@ int ncp15wb_calculate_temp(uint16_t adc); #undef CONFIG_USB_PD_HOST_CMD #endif -#ifdef TEST_USB_TCPMV2_TCPCI -#define CONFIG_USB_DRP_ACC_TRYSRC -#define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_REV30 -#undef CONFIG_PD_RETRY_COUNT -#define CONFIG_PD_RETRY_COUNT 2 -#define CONFIG_USB_PD_TCPC_LOW_POWER -#define CONFIG_USB_PD_TRY_SRC -#define CONFIG_USB_PD_TCPMV2 -#define CONFIG_USB_PD_PORT_MAX_COUNT 1 -#define CONFIG_USBC_SS_MUX -#define CONFIG_USB_PD_VBUS_DETECT_TCPC -#define CONFIG_USB_POWER_DELIVERY -#define CONFIG_TEST_USB_PE_SM -#define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USBC_VCONN -#define CONFIG_USBC_VCONN_SWAP -#define CONFIG_USB_PID 0x5036 -#define PD_VCONN_SWAP_DELAY 5000 /* us */ -#define CONFIG_USB_PD_TCPM_TCPCI -#define CONFIG_I2C -#define CONFIG_I2C_CONTROLLER -#define I2C_PORT_HOST_TCPC 0 -#define CONFIG_USB_PD_DEBUG_LEVEL 3 -#define CONFIG_USB_PD_EXTENDED_MESSAGES -#define CONFIG_USB_PD_DECODE_SOP -#endif - #ifdef TEST_USB_TCPMV2_COMPLIANCE #define CONFIG_USB_DRP_ACC_TRYSRC #define CONFIG_USB_PD_DUAL_ROLE diff --git a/test/usb_tcpmv2_compliance.c b/test/usb_tcpmv2_compliance.c index 4fbb9d32e0..6e1bbf75f5 100644 --- a/test/usb_tcpmv2_compliance.c +++ b/test/usb_tcpmv2_compliance.c @@ -34,5 +34,9 @@ void run_test(int argc, char **argv) RUN_TEST(test_td_pd_src3_e26); RUN_TEST(test_td_pd_snk3_e12); + RUN_TEST(test_connect_as_nonpd_sink); + RUN_TEST(test_retry_count_sop); + RUN_TEST(test_retry_count_hard_reset); + test_print_result(); } diff --git a/test/usb_tcpmv2_compliance.h b/test/usb_tcpmv2_compliance.h index 165344d721..1426b9f825 100644 --- a/test/usb_tcpmv2_compliance.h +++ b/test/usb_tcpmv2_compliance.h @@ -70,4 +70,8 @@ int test_td_pd_ll_e4_ufp(void); int test_td_pd_src3_e26(void); int test_td_pd_snk3_e12(void); +int test_connect_as_nonpd_sink(void); +int test_retry_count_sop(void); +int test_retry_count_hard_reset(void); + #endif /* USB_TCPMV2_COMPLIANCE_H */ diff --git a/test/usb_tcpmv2_tcpci.c b/test/usb_tcpmv2_tcpci.c deleted file mode 100644 index 30ce2ef81d..0000000000 --- a/test/usb_tcpmv2_tcpci.c +++ /dev/null @@ -1,405 +0,0 @@ -/* 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. - */ - -#include "hooks.h" -#include "mock/tcpci_i2c_mock.h" -#include "mock/usb_mux_mock.h" -#include "task.h" -#include "tcpci.h" -#include "test_util.h" -#include "timer.h" -#include "usb_mux.h" -#include "usb_tc_sm.h" -#include "usb_prl_sm.h" - -#define PORT0 0 - -enum mock_cc_state { - MOCK_CC_SRC_OPEN = 0, - MOCK_CC_SNK_OPEN = 0, - MOCK_CC_SRC_RA = 1, - MOCK_CC_SNK_RP_DEF = 1, - MOCK_CC_SRC_RD = 2, - MOCK_CC_SNK_RP_1_5 = 2, - MOCK_CC_SNK_RP_3_0 = 3, -}; -enum mock_connect_result { - MOCK_CC_WE_ARE_SRC = 0, - MOCK_CC_WE_ARE_SNK = 1, -}; - -__maybe_unused static void mock_set_cc(enum mock_connect_result cr, - enum mock_cc_state cc1, enum mock_cc_state cc2) -{ - mock_tcpci_set_reg(TCPC_REG_CC_STATUS, - TCPC_REG_CC_STATUS_SET(cr, cc1, cc2)); -} - -__maybe_unused static void mock_set_role(int drp, enum tcpc_rp_value rp, - enum tcpc_cc_pull cc1, enum tcpc_cc_pull cc2) -{ - mock_tcpci_set_reg(TCPC_REG_ROLE_CTRL, - TCPC_REG_ROLE_CTRL_SET(drp, rp, cc1, cc2)); -} - -static int mock_alert_count; - -__maybe_unused static void mock_set_alert(int alert) -{ - mock_tcpci_set_reg(TCPC_REG_ALERT, alert); - mock_alert_count = 1; - schedule_deferred_pd_interrupt(PORT0); -} - -uint16_t tcpc_get_alert_status(void) -{ - ccprints("mock_alert_count %d", mock_alert_count); - if (mock_alert_count > 0) { - mock_alert_count--; - return PD_STATUS_TCPC_ALERT_0; - } - return 0; -} - -static int rx_id; - -const struct svdm_response svdm_rsp = { - .identity = NULL, - .svids = NULL, - .modes = NULL, -}; - -bool vboot_allow_usb_pd(void) -{ - return 1; -} - -int pd_check_vconn_swap(int port) -{ - return 1; -} - -void board_reset_pd_mcu(void) {} - -const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_HOST_TCPC, - .addr_flags = MOCK_TCPCI_I2C_ADDR_FLAGS, - }, - .drv = &tcpci_tcpm_drv, - .flags = TCPC_FLAGS_TCPCI_REV2_0, - }, -}; - -const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .driver = &mock_usb_mux_driver, - } -}; - -__maybe_unused static int test_connect_as_nonpd_sink(void) -{ - task_wait_event(10 * SECOND); - - /* Simulate a non-PD power supply being plugged in. */ - mock_set_cc(MOCK_CC_WE_ARE_SNK, MOCK_CC_SNK_OPEN, MOCK_CC_SNK_RP_3_0); - mock_set_alert(TCPC_REG_ALERT_CC_STATUS); - - task_wait_event(50 * MSEC); - - mock_tcpci_set_reg(TCPC_REG_POWER_STATUS, - TCPC_REG_POWER_STATUS_VBUS_PRES); - mock_set_alert(TCPC_REG_ALERT_POWER_STATUS); - - task_wait_event(10 * SECOND); - TEST_EQ(tc_is_attached_snk(PORT0), true, "%d"); - - return EC_SUCCESS; -} - -__maybe_unused static int test_startup_and_resume(void) -{ - /* Should be in low power mode before AP boots. */ - TEST_EQ(mock_tcpci_get_reg(TCPC_REG_COMMAND), - TCPC_REG_COMMAND_I2CIDLE, "%d"); - task_wait_event(10 * SECOND); - - hook_notify(HOOK_CHIPSET_STARTUP); - task_wait_event(5 * MSEC); - hook_notify(HOOK_CHIPSET_RESUME); - - task_wait_event(10 * SECOND); - /* Should be in low power mode and DRP auto-toggling with AP in S0. */ - TEST_EQ((mock_tcpci_get_reg(TCPC_REG_ROLE_CTRL) - & TCPC_REG_ROLE_CTRL_DRP_MASK), - TCPC_REG_ROLE_CTRL_DRP_MASK, "%d"); - /* TODO: check previous command was TCPC_REG_COMMAND_LOOK4CONNECTION */ - TEST_EQ(mock_tcpci_get_reg(TCPC_REG_COMMAND), - TCPC_REG_COMMAND_I2CIDLE, "%d"); - - return EC_SUCCESS; -} - - -__maybe_unused static int test_connect_as_pd3_source(void) -{ - uint32_t rdo = RDO_FIXED(1, 500, 500, 0); - uint32_t pdo = PDO_FIXED(5000, 500, - PDO_FIXED_DUAL_ROLE | - PDO_FIXED_DATA_SWAP | - PDO_FIXED_COMM_CAP); - - /* DRP auto-toggling with AP in S0, source enabled. */ - TEST_EQ(test_startup_and_resume(), EC_SUCCESS, "%d"); - - /* - * PROC.PD.E1. Bring-up procedure for DFP(Source) UUT: - * a) The test starts in a disconnected state. - */ - mock_tcpci_set_reg(TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); - mock_set_alert(TCPC_REG_ALERT_EXT_STATUS); - task_wait_event(10 * SECOND); - - /* - * b) The Tester applies Rd and waits for Vbus for tNoResponse max. - */ - mock_set_cc(MOCK_CC_WE_ARE_SRC, MOCK_CC_SRC_OPEN, MOCK_CC_SRC_RD); - mock_set_alert(TCPC_REG_ALERT_CC_STATUS); - - /* - * c) The Tester waits for Source_Capabilities for tNoResponse max. - */ - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP), - EC_SUCCESS, "%d"); - /* - * d) The Tester replies GoodCrc on reception of the - * Source_Capabilities. - */ - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - /* - * e) The Tester requests 5V 0.5A. - */ - mock_tcpci_receive(PD_MSG_SOP, - PD_HEADER(PD_DATA_REQUEST, PD_ROLE_SINK, - PD_ROLE_UFP, rx_id, - 1, PD_REV30, 0), - &rdo); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, PD_CTRL_ACCEPT, 0), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - /* - * f) The Tester waits for PS_RDY for tPSSourceOn max. - */ - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, PD_CTRL_PS_RDY, 0), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - - /* - * PROC.PD.E3. Wait to Start AMS for DFP(Source) UUT: - * a) The Tester keeps monitoring the Rp value and if the UUT doesn't - * set the value to SinkTXOK if it doesn't have anything to send in 1s, - * the test fails. During this period, the Tester replies any message - * sent from the UUT with a proper response. - */ - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP_PRIME, 0, PD_DATA_VENDOR_DEF), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - mock_tcpci_receive(PD_MSG_SOP_PRIME, - PD_HEADER(PD_CTRL_NOT_SUPPORTED, PD_PLUG_FROM_CABLE, - PD_ROLE_UFP, rx_id, - 0, PD_REV30, 0), - NULL); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, 0, PD_DATA_VENDOR_DEF), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - mock_tcpci_receive(PD_MSG_SOP, - PD_HEADER(PD_CTRL_NOT_SUPPORTED, PD_ROLE_SINK, - PD_ROLE_UFP, rx_id, - 0, PD_REV30, 0), - NULL); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, PD_CTRL_GET_SOURCE_CAP, 0), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - mock_tcpci_receive(PD_MSG_SOP, - PD_HEADER(PD_DATA_SOURCE_CAP, PD_ROLE_SINK, - PD_ROLE_UFP, rx_id, - 1, PD_REV30, 0), - &pdo); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, PD_CTRL_GET_SINK_CAP, 0), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - mock_tcpci_receive(PD_MSG_SOP, - PD_HEADER(PD_DATA_SINK_CAP, PD_ROLE_SINK, - PD_ROLE_UFP, rx_id, - 1, PD_REV30, 0), - &pdo); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - - task_wait_event(1 * SECOND); - TEST_EQ(tc_is_attached_src(PORT0), true, "%d"); - TEST_EQ(TCPC_REG_ROLE_CTRL_RP(mock_tcpci_get_reg(TCPC_REG_ROLE_CTRL)), - SINK_TX_OK, "%d"); - - task_wait_event(10 * SECOND); - return EC_SUCCESS; -} - -__maybe_unused static int test_retry_count_sop(void) -{ - /* DRP auto-toggling with AP in S0, source enabled. */ - TEST_EQ(test_startup_and_resume(), EC_SUCCESS, "%d"); - - /* - * The test starts in a disconnected state. - */ - mock_tcpci_set_reg(TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); - mock_set_alert(TCPC_REG_ALERT_EXT_STATUS); - task_wait_event(10 * SECOND); - - /* - * The Tester applies Rd and waits for Vbus for tNoResponse max. - */ - mock_set_cc(MOCK_CC_WE_ARE_SRC, MOCK_CC_SRC_OPEN, MOCK_CC_SRC_RD); - mock_set_alert(TCPC_REG_ALERT_CC_STATUS); - - /* - * The Tester waits for Source_Capabilities for tNoResponse max. - * - * Source Caps is SOP message which should be retried at TCPC layer - */ - TEST_EQ(verify_tcpci_tx_retry_count(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP, - CONFIG_PD_RETRY_COUNT), - EC_SUCCESS, "%d"); - return EC_SUCCESS; -} - -__maybe_unused static int test_retry_count_hard_reset(void) -{ - /* DRP auto-toggling with AP in S0, source enabled. */ - TEST_EQ(test_startup_and_resume(), EC_SUCCESS, "%d"); - - /* - * The test starts in a disconnected state. - */ - mock_tcpci_set_reg(TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); - mock_set_alert(TCPC_REG_ALERT_EXT_STATUS); - task_wait_event(10 * SECOND); - - /* - * The Tester applies Rd and waits for Vbus for tNoResponse max. - */ - mock_set_cc(MOCK_CC_WE_ARE_SRC, MOCK_CC_SRC_OPEN, MOCK_CC_SRC_RD); - mock_set_alert(TCPC_REG_ALERT_CC_STATUS); - - /* - * The Tester waits for Source_Capabilities for tNoResponse max. - */ - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP), - EC_SUCCESS, "%d"); - /* - * The Tester replies GoodCrc on reception of the Source_Capabilities. - */ - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - task_wait_event(10 * MSEC); - - /* - * Now that PRL is running since we are connected, we can send a hard - * reset. - */ - - /* Request that DUT send hard reset */ - prl_execute_hard_reset(PORT0); - - /* The retry count for hard resets should be 0 */ - TEST_EQ(verify_tcpci_tx_retry_count(TCPC_TX_HARD_RESET, 0, 0, 0), - EC_SUCCESS, "%d"); - - return EC_SUCCESS; -} - -__maybe_unused static int test_pd3_source_send_soft_reset(void) -{ - /* - * TD.PD.SRC3.E26.Soft_Reset sent regardless of Rp value - * a) Run PROC.PD.E1 Bring-up according to the UUT role. - * b) The Tester waits until it can start an AMS (Run PROC.PD.E3)... - */ - TEST_EQ(test_connect_as_pd3_source(), EC_SUCCESS, "%d"); - - /* - * ...and sends a Get_Source_Cap message to the UUT. - */ - mock_tcpci_receive(PD_MSG_SOP, - PD_HEADER(PD_CTRL_GET_SOURCE_CAP, PD_ROLE_SINK, - PD_ROLE_UFP, rx_id, - 0, PD_REV30, 0), - NULL); - rx_id++; - mock_set_alert(TCPC_REG_ALERT_RX_STATUS); - - /* - * c) Upon receipt of the Source_Capabilities Message, the Tester - * doesn’t reply with GoodCRC. - */ - TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_FAILED); - - /* - * d) The Tester verifies that a Soft_Reset message is sent by the UUT - * within tReceive max (1.1 ms) + tSoftReset max (15 ms). - */ - TEST_EQ(verify_tcpci_tx_timeout( - TCPC_TX_SOP, PD_CTRL_SOFT_RESET, 0, 15 * MSEC), - EC_SUCCESS, "%d"); - mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); - - return EC_SUCCESS; -} - -void before_test(void) -{ - rx_id = 0; - - mock_usb_mux_reset(); - mock_tcpci_reset(); - - /* Restart the PD task and let it settle */ - task_set_event(TASK_ID_PD_C0, TASK_EVENT_RESET_DONE); - task_wait_event(SECOND); -} - -void run_test(int argc, char **argv) -{ - test_reset(); - - RUN_TEST(test_connect_as_nonpd_sink); - RUN_TEST(test_startup_and_resume); - RUN_TEST(test_connect_as_pd3_source); - RUN_TEST(test_retry_count_sop); - RUN_TEST(test_retry_count_hard_reset); - RUN_TEST(test_pd3_source_send_soft_reset); - - test_print_result(); -} diff --git a/test/usb_tcpmv2_tcpci.mocklist b/test/usb_tcpmv2_tcpci.mocklist deleted file mode 100644 index 58a3541412..0000000000 --- a/test/usb_tcpmv2_tcpci.mocklist +++ /dev/null @@ -1,8 +0,0 @@ -/* 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_MUX) \ - MOCK(TCPCI_I2C) diff --git a/test/usb_tcpmv2_tcpci.tasklist b/test/usb_tcpmv2_tcpci.tasklist deleted file mode 100644 index 654e4eca2b..0000000000 --- a/test/usb_tcpmv2_tcpci.tasklist +++ /dev/null @@ -1,11 +0,0 @@ -/* 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. - */ - -/** - * See CONFIG_TEST_TASK_LIST in config.h for details. - */ -#define CONFIG_TEST_TASK_LIST \ - TASK_TEST(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_TEST(PD_INT_C0, pd_interrupt_handler_task, 0, LARGER_TASK_STACK_SIZE) diff --git a/test/usb_tcpmv2_td_pd_other.c b/test/usb_tcpmv2_td_pd_other.c new file mode 100644 index 0000000000..1b2486b6f2 --- /dev/null +++ b/test/usb_tcpmv2_td_pd_other.c @@ -0,0 +1,107 @@ +/* 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. + */ + +#include "mock/tcpci_i2c_mock.h" +#include "task.h" +#include "tcpci.h" +#include "test_util.h" +#include "timer.h" +#include "usb_tcpmv2_compliance.h" +#include "usb_tc_sm.h" +#include "usb_prl_sm.h" + +int test_connect_as_nonpd_sink(void) +{ + task_wait_event(10 * SECOND); + + /* Simulate a non-PD power supply being plugged in. */ + mock_set_cc(MOCK_CC_DUT_IS_SNK, MOCK_CC_SNK_OPEN, MOCK_CC_SNK_RP_3_0); + mock_set_alert(TCPC_REG_ALERT_CC_STATUS); + + task_wait_event(50 * MSEC); + + mock_tcpci_set_reg(TCPC_REG_POWER_STATUS, + TCPC_REG_POWER_STATUS_VBUS_PRES); + mock_set_alert(TCPC_REG_ALERT_POWER_STATUS); + + task_wait_event(10 * SECOND); + TEST_EQ(tc_is_attached_snk(PORT0), true, "%d"); + + return EC_SUCCESS; +} + +int test_retry_count_sop(void) +{ + /* DRP auto-toggling with AP in S0, source enabled. */ + TEST_EQ(tcpci_startup(), EC_SUCCESS, "%d"); + + /* + * The test starts in a disconnected state. + */ + mock_tcpci_set_reg(TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); + mock_set_alert(TCPC_REG_ALERT_EXT_STATUS); + task_wait_event(10 * SECOND); + + /* + * The Tester applies Rd and waits for Vbus for tNoResponse max. + */ + mock_set_cc(MOCK_CC_DUT_IS_SRC, MOCK_CC_SRC_OPEN, MOCK_CC_SRC_RD); + mock_set_alert(TCPC_REG_ALERT_CC_STATUS); + + /* + * The Tester waits for Source_Capabilities for tNoResponse max. + * + * Source Caps is SOP message which should be retried at TCPC layer. + * The retry count for PD3 should be 2. + */ + TEST_EQ(verify_tcpci_tx_retry_count(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP, + 2), + EC_SUCCESS, "%d"); + return EC_SUCCESS; +} + +int test_retry_count_hard_reset(void) +{ + /* DRP auto-toggling with AP in S0, source enabled. */ + TEST_EQ(tcpci_startup(), EC_SUCCESS, "%d"); + + /* + * The test starts in a disconnected state. + */ + mock_tcpci_set_reg(TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); + mock_set_alert(TCPC_REG_ALERT_EXT_STATUS); + task_wait_event(10 * SECOND); + + /* + * The Tester applies Rd and waits for Vbus for tNoResponse max. + */ + mock_set_cc(MOCK_CC_DUT_IS_SRC, MOCK_CC_SRC_OPEN, MOCK_CC_SRC_RD); + mock_set_alert(TCPC_REG_ALERT_CC_STATUS); + + /* + * The Tester waits for Source_Capabilities for tNoResponse max. + */ + TEST_EQ(verify_tcpci_transmit(TCPC_TX_SOP, 0, PD_DATA_SOURCE_CAP), + EC_SUCCESS, "%d"); + /* + * The Tester replies GoodCrc on reception of the Source_Capabilities. + */ + mock_set_alert(TCPC_REG_ALERT_TX_SUCCESS); + task_wait_event(10 * MSEC); + + /* + * Now that PRL is running since we are connected, we can send a hard + * reset. + */ + + /* Request that DUT send hard reset */ + prl_execute_hard_reset(PORT0); + + /* The retry count for hard resets should be 0 */ + TEST_EQ(verify_tcpci_tx_retry_count(TCPC_TX_HARD_RESET, 0, 0, 0), + EC_SUCCESS, "%d"); + + return EC_SUCCESS; +} |