From 7a07137ff8861509b5942a82de1c46b376c6057a Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Wed, 7 Aug 2019 12:49:34 -0600 Subject: test: add sanity check for existing state machines We want to ensure that our usb state machines - do not have any cycles - do not have any completely empty states - have names for every print statement if called These new unit tests allow us to have build-times checks for the above. BRANCH=none BUG=none TEST=tests pass. Made each test fail locally to ensure that tests were actually working. Change-Id: Idd2c4d69e83cf38c97278edd1727d86b52a85db9 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744657 Commit-Queue: Denis Brockus Reviewed-by: Denis Brockus --- test/usb_typec_ctvpd.c | 52 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'test/usb_typec_ctvpd.c') diff --git a/test/usb_typec_ctvpd.c b/test/usb_typec_ctvpd.c index 2d45b4f882..8c8b5e3897 100644 --- a/test/usb_typec_ctvpd.c +++ b/test/usb_typec_ctvpd.c @@ -15,6 +15,7 @@ #include "util.h" #include "usb_pd_tcpm.h" #include "usb_pd_test_util.h" +#include "usb_sm_checks.h" #include "vpd_api.h" #define PORT0 0 @@ -658,9 +659,9 @@ static int test_ctvpd_behavior_case1(void) /* * CASE 1: The following tests the behavior when a DRP is connected to a - * Charge-Through VCONN-Powered USB Device (abbreviated CTVPD), - * with no Power Source attached to the ChargeThrough port on - * the CTVPD. + * Charge-Through VCONN-Powered USB Device (abbreviated CTVPD), + * with no Power Source attached to the ChargeThrough port on + * the CTVPD. */ /* 1. DRP and CTVPD are both in the unattached state */ @@ -797,9 +798,9 @@ static int test_ctvpd_behavior_case2(void) /* * CASE 2: The following tests the behavior when a Power Source is - * connected to a Charge-Through VCONN-Powered USB Device - * (abbreviated CTVPD), with a Host already attached to the - * Host-Side port on the CTVPD. + * connected to a Charge-Through VCONN-Powered USB Device + * (abbreviated CTVPD), with a Host already attached to the + * Host-Side port on the CTVPD. */ /* @@ -919,9 +920,9 @@ static int test_ctvpd_behavior_case3(void) /* * CASE 3: The following describes the behavior when a Power Source is - * connected to a ChargeThrough VCONN-Powered USB Device - * (abbreviated CTVPD), with no Host attached to the Host-side - * port on the CTVPD. + * connected to a ChargeThrough VCONN-Powered USB Device + * (abbreviated CTVPD), with no Host attached to the Host-side + * port on the CTVPD. */ /* @@ -1022,9 +1023,9 @@ static int test_ctvpd_behavior_case4(void) /* * CASE 4: The following describes the behavior when a DRP is connected - * to a Charge-Through VCONN-Powered USB Device - * (abbreviated CTVPD), with a Power Source already attached to - * the Charge-Through side on the CTVPD. + * to a Charge-Through VCONN-Powered USB Device + * (abbreviated CTVPD), with a Power Source already attached to + * the Charge-Through side on the CTVPD. */ /* @@ -1177,9 +1178,9 @@ static int test_ctvpd_behavior_case5(void) /* * CASE 5: The following describes the behavior when a Power Source is - * connected to a ChargeThrough VCONN-Powered USB Device - * (abbreviated CTVPD), with a DRP (with dead battery) attached - * to the Host-side port on the CTVPD. + * connected to a ChargeThrough VCONN-Powered USB Device + * (abbreviated CTVPD), with a DRP (with dead battery) attached + * to the Host-side port on the CTVPD. */ /* @@ -1317,9 +1318,9 @@ static int test_ctvpd_behavior_case6(void) /* * CASE 6: The following describes the behavior when a DRP is connected - * to a Charge-Through VCONN-Powered USB Device - * (abbreviated CTVPD) and a Sink is attached to the - * Charge-Through port on the CTVPD. + * to a Charge-Through VCONN-Powered USB Device + * (abbreviated CTVPD) and a Sink is attached to the + * Charge-Through port on the CTVPD. */ /* @@ -1513,6 +1514,21 @@ void run_test(void) RUN_TEST(test_ctvpd_behavior_case5); RUN_TEST(test_ctvpd_behavior_case6); #endif + + /* Do basic state machine sanity checks last. */ + RUN_TEST(test_tc_no_parent_cycles); + RUN_TEST(test_tc_no_empty_state); + RUN_TEST(test_tc_all_states_named); + + /* + * Since you have to include TypeC layer when adding PE layer, the + * PE test would have the same build dependencies, so go ahead and test + * te PE statemachine here so we don't have to create another test exe + */ + RUN_TEST(test_pe_no_parent_cycles); + RUN_TEST(test_pe_no_empty_state); + RUN_TEST(test_pe_all_states_named); + test_print_result(); } -- cgit v1.2.1