diff options
author | Paul Fagerburg <pfagerburg@google.com> | 2020-06-18 16:32:30 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-23 02:29:14 +0000 |
commit | 01705adbfa51d14e986c76605c995b9ec2d42170 (patch) | |
tree | 3d5d7f12010d90f8f1d42222bad7ef749f2100bc /test | |
parent | ae40ebba225fefeb802db2bdce843080eecae081 (diff) | |
download | chrome-ec-01705adbfa51d14e986c76605c995b9ec2d42170.tar.gz |
usb_prl: new unit test with mocks
Now that the old usb_prl unit test is under usb_prl_old, add a new
unit test for usb_prl with mocks for the various subsystems that it
will use.
BUG=b:158608129
BRANCH=None
TEST=`TEST_LIST_HOST="usb_prl_old usb_prl" make runhosttests`
Signed-off-by: Paul Fagerburg <pfagerburg@google.com>
Change-Id: Ie1bf9a4494cd933473caa4ceb594eddd97c277c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2252662
Tested-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/build.mk | 2 | ||||
-rw-r--r-- | test/test_config.h | 11 | ||||
-rw-r--r-- | test/usb_prl.c | 46 | ||||
-rw-r--r-- | test/usb_prl.mocklist | 11 | ||||
-rw-r--r-- | test/usb_prl.tasklist | 10 |
5 files changed, 80 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 053896aca9..e889ea6400 100644 --- a/test/build.mk +++ b/test/build.mk @@ -87,6 +87,7 @@ 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_prl test-list-host += usb_pe_drp test-list-host += utils test-list-host += utils_str @@ -194,6 +195,7 @@ usb_typec_ctvpd-y=usb_typec_ctvpd.o vpd_api.o usb_sm_checks.o fake_usbc.o usb_typec_drp_acc_trysrc-y=usb_typec_drp_acc_trysrc.o vpd_api.o \ usb_sm_checks.o usb_prl_old-y=usb_prl_old.o usb_sm_checks.o fake_usbc.o +usb_prl-y=usb_prl.o usb_sm_checks.o usb_pe_drp-y=usb_pe_drp.o usb_sm_checks.o \ fake_battery.o fake_prl.o fake_usbc.o utils-y=utils.o diff --git a/test/test_config.h b/test/test_config.h index 5bc5f48316..8fcadd044d 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -327,6 +327,17 @@ int ncp15wb_calculate_temp(uint16_t adc); #define CONFIG_SW_CRC #endif +#if defined(TEST_USB_PRL) +#define CONFIG_USB_PD_PORT_MAX_COUNT 1 +#define CONFIG_USB_PD_REV30 +#define CONFIG_USB_PD_TCPMV2 +#undef CONFIG_USB_PE_SM +#undef CONFIG_USB_TYPEC_SM +#undef CONFIG_USB_PD_HOST_CMD +#define CONFIG_USB_PRL_SM +#define CONFIG_USB_POWER_DELIVERY +#endif + #if defined(TEST_USB_PE_DRP) #define CONFIG_TEST_USB_PE_SM #define CONFIG_USB_PD_PORT_MAX_COUNT 1 diff --git a/test/usb_prl.c b/test/usb_prl.c new file mode 100644 index 0000000000..702aa8ec64 --- /dev/null +++ b/test/usb_prl.c @@ -0,0 +1,46 @@ +/* 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. + * + * Test USB Protocol Layer module. + */ +#include "common.h" +#include "task.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_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" + +#define PORT0 0 + +/* Install Mock TCPC and MUX drivers */ +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .drv = &mock_tcpc_driver, + }, +}; + +void before_test(void) +{ +} + +void run_test(int argc, char **argv) +{ + /* TODO add tests here */ + + /* Do basic state machine sanity checks last. */ + RUN_TEST(test_prl_no_parent_cycles); + RUN_TEST(test_prl_no_empty_state); + RUN_TEST(test_prl_all_states_named); + + test_print_result(); +} + diff --git a/test/usb_prl.mocklist b/test/usb_prl.mocklist new file mode 100644 index 0000000000..c89e12e78b --- /dev/null +++ b/test/usb_prl.mocklist @@ -0,0 +1,11 @@ +/* Copyright 2019 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(TCPC) \ + MOCK(TCPM) \ + MOCK(USB_PD) \ + MOCK(USB_PE_SM) \ + MOCK(USB_TC_SM) diff --git a/test/usb_prl.tasklist b/test/usb_prl.tasklist new file mode 100644 index 0000000000..eb41326e3e --- /dev/null +++ b/test/usb_prl.tasklist @@ -0,0 +1,10 @@ +/* Copyright 2019 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) |