diff options
author | Diana Z <dzigterman@chromium.org> | 2021-05-26 14:57:42 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-03 02:17:29 +0000 |
commit | bce4d38c3b6665aee9d303eaa753557cac0f8c28 (patch) | |
tree | c582697f5e336dbd853c0c415e73895c2fc058af /test | |
parent | 4497c92d1cf6eb837718642516163cddd3c24449 (diff) | |
download | chrome-ec-bce4d38c3b6665aee9d303eaa753557cac0f8c28.tar.gz |
Test: Add TC unit test for source disconnect detection
Add a TC layer test for source disconnect, and also add some
infrastructure to detect the test board's Vbus output.
BRANCH=None
BUG=b:153071799
TEST=make -j buildall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I72f2553d59b939bf236e0ae3ea6248df899ef4ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2921283
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/usb_typec_drp_acc_trysrc.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/test/usb_typec_drp_acc_trysrc.c b/test/usb_typec_drp_acc_trysrc.c index 3d329606ba..e65a92196d 100644 --- a/test/usb_typec_drp_acc_trysrc.c +++ b/test/usb_typec_drp_acc_trysrc.c @@ -50,6 +50,38 @@ void pd_resume_check_pr_swap_needed(int port) /* Do Nothing, but needed for linking */ } +/* Vbus is turned on at the board level, so mock it here for our purposes */ +static bool board_vbus_enabled[CONFIG_USB_PD_PORT_MAX_COUNT]; + +static bool mock_get_vbus_enabled(int port) +{ + return board_vbus_enabled[port]; +} + +static void mock_set_vbus_enabled(int port, bool enabled) +{ + board_vbus_enabled[port] = enabled; +} + +static void mock_reset_vbus_enabled(void) +{ + int i; + + for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) + mock_set_vbus_enabled(i, false); +} + +int pd_set_power_supply_ready(int port) +{ + mock_set_vbus_enabled(port, true); + return EC_SUCCESS; +} + +void pd_power_supply_reset(int port) +{ + mock_set_vbus_enabled(port, false); +} + __maybe_unused static int test_mux_con_dis_as_src(void) { mock_tcpc.should_print_call = false; @@ -711,13 +743,51 @@ __maybe_unused static int test_auto_toggle_delay_early_connect(void) } /* TODO(b/153071799): test as SNK monitor for Vbus disconnect (not CC line) */ -/* TODO(b/153071799): test as SRC monitor for CC line state change */ +__maybe_unused static int test_typec_dis_as_src(void) +{ + mock_tcpc.should_print_call = false; + + /* 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); + pd_set_dual_role(0, PD_DRP_TOGGLE_ON); + + /* This wait trainsitions through AttachWait.SRC then Attached.SRC */ + task_wait_event(SECOND); + + /* + * We are in Attached.SRC now, verify: + * - Vbus was turned on + * - Rp is set + * - polarity is detected as CC1 + * - Rp was set to default configured level + */ + TEST_EQ(mock_tcpc.last.cc, TYPEC_CC_RP, "%d"); + TEST_EQ(mock_tcpc.last.polarity, POLARITY_CC1, "%d"); + TEST_EQ(mock_tcpc.last.rp, CONFIG_USB_PD_PULLUP, "%d"); + TEST_EQ(mock_get_vbus_enabled(0), true, "%d"); + + /* Force a detach through CC open */ + mock_tcpc.cc1 = TYPEC_CC_VOLT_OPEN; + mock_tcpc.cc2 = TYPEC_CC_VOLT_OPEN; + task_set_event(TASK_ID_PD_C0, PD_EVENT_CC); + + /* This wait will go through TryWait.SNK then to Unattached.SNK */ + task_wait_event(10 * SECOND); + + /* We are in Unattached.SNK. Verify Vbus has been removed */ + TEST_EQ(mock_get_vbus_enabled(0), false, "%d"); + + return EC_SUCCESS; +} /* Reset the mocks before each test */ void before_test(void) { mock_usb_mux_reset(); mock_tcpc_reset(); + mock_reset_vbus_enabled(); /* Restart the PD task and let it settle */ task_set_event(TASK_ID_PD_C0, TASK_EVENT_RESET_DONE); @@ -751,6 +821,8 @@ void run_test(int argc, char **argv) RUN_TEST(test_mux_con_dis_as_snk); RUN_TEST(test_power_role_set); + RUN_TEST(test_typec_dis_as_src); + RUN_TEST(test_try_src_disabled); RUN_TEST(test_try_src_partner_switches); RUN_TEST(test_try_src_partner_does_not_switch_vbus); |