diff options
-rw-r--r-- | common/mock/build.mk | 4 | ||||
-rw-r--r-- | common/mock/tcpm_mock.c | 22 | ||||
-rw-r--r-- | common/mock/usb_pd_mock.c | 80 | ||||
-rw-r--r-- | common/mock/usb_pe_sm_mock.c | 58 | ||||
-rw-r--r-- | common/mock/usb_tc_sm_mock.c | 38 | ||||
-rw-r--r-- | include/mock/tcpm_mock.h | 7 | ||||
-rw-r--r-- | include/mock/usb_pd_mock.h | 20 | ||||
-rw-r--r-- | include/mock/usb_pe_sm_mock.h | 27 | ||||
-rw-r--r-- | include/mock/usb_tc_sm_mock.h | 20 | ||||
-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 |
14 files changed, 356 insertions, 0 deletions
diff --git a/common/mock/build.mk b/common/mock/build.mk index 387a517cb9..e5e8511812 100644 --- a/common/mock/build.mk +++ b/common/mock/build.mk @@ -10,5 +10,9 @@ mock-$(HAS_MOCK_FPSENSOR_STATE) += fpsensor_state_mock.o mock-$(HAS_MOCK_MKBP_EVENTS) += mkbp_events_mock.o mock-$(HAS_MOCK_ROLLBACK) += rollback_mock.o mock-$(HAS_MOCK_TCPC) += tcpc_mock.o +mock-$(HAS_MOCK_TCPM) += tcpm_mock.o mock-$(HAS_MOCK_TIMER) += timer_mock.o mock-$(HAS_MOCK_USB_MUX) += usb_mux_mock.o +mock-$(HAS_MOCK_USB_PD) += usb_pd_mock.o +mock-$(HAS_MOCK_USB_PE_SM) += usb_pe_sm_mock.o +mock-$(HAS_MOCK_USB_TC_SM) += usb_tc_sm_mock.o
\ No newline at end of file diff --git a/common/mock/tcpm_mock.c b/common/mock/tcpm_mock.c new file mode 100644 index 0000000000..efd07a9967 --- /dev/null +++ b/common/mock/tcpm_mock.c @@ -0,0 +1,22 @@ +/* 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. + */ +/* Mock for the TCPM interface */ + +#include "common.h" +#include "console.h" +#include "memory.h" +#include "mock/tcpm_mock.h" + +int tcpm_dequeue_message(int port, uint32_t *payload, int *header) +{ + /* TODO flesh out the mock*/ + return 0; +} + +int tcpm_has_pending_message(int port) +{ + /* TODO flesh out the mock*/ + return 0; +} diff --git a/common/mock/usb_pd_mock.c b/common/mock/usb_pd_mock.c new file mode 100644 index 0000000000..2223e9153d --- /dev/null +++ b/common/mock/usb_pd_mock.c @@ -0,0 +1,80 @@ +/* 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. + */ + +/* Mock USB Type-C PD */ + +#include "common.h" +#include "console.h" +#include "usb_pd.h" +#include "mock/usb_pd_mock.h" +#include "memory.h" + +struct mock_pd_port_t mock_pd_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + +enum pd_dual_role_states pd_get_dual_role(int port) +{ + return PD_DRP_TOGGLE_ON; +} + +enum pd_data_role pd_get_data_role(int port) +{ + return mock_pd_port[port].data_role; +} +__overridable void tc_set_data_role(int port, enum pd_data_role role) +{ + mock_pd_port[port].data_role = role; +} + +enum pd_power_role pd_get_power_role(int port) +{ + return mock_pd_port[port].power_role; +} +__overridable void tc_set_power_role(int port, enum pd_power_role role) +{ + mock_pd_port[port].power_role = role; +} + +enum pd_cc_states pd_get_task_cc_state(int port) +{ + return PD_CC_NONE; +} + +/* TODO remove when usbc_fake is cleaned up */ +#if !defined(CONFIG_USB_DRP_ACC_TRYSRC) && \ + !defined(CONFIG_USB_CTVPD) +int pd_is_connected(int port) +{ + return 1; +} + +bool pd_is_disconnected(int port) +{ + return false; +} +#endif /* !CONFIG_USB_DRP_ACC_TRYSRC && !CONFIG_USB_CTVPD */ + +const uint32_t * const pd_get_src_caps(int port) +{ + return NULL; +} + +uint8_t pd_get_src_cap_cnt(int port) +{ + return 0; +} + +void pd_set_src_caps(int port, int cnt, uint32_t *src_caps) +{ +} + +bool pd_get_partner_usb_comm_capable(int port) +{ + return true; +} + +inline uint8_t board_get_usb_pd_port_count(void) +{ + return CONFIG_USB_PD_PORT_MAX_COUNT; +} diff --git a/common/mock/usb_pe_sm_mock.c b/common/mock/usb_pe_sm_mock.c new file mode 100644 index 0000000000..3edc3babd3 --- /dev/null +++ b/common/mock/usb_pe_sm_mock.c @@ -0,0 +1,58 @@ +/* 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. + */ + +/* Mock USB PE state machine */ + +#include "common.h" +#include "console.h" +#include "usb_pe_sm.h" +#include "mock/usb_pe_sm_mock.h" +#include "memory.h" + +#ifndef CONFIG_COMMON_RUNTIME +#define cprints(format, args...) +#endif + + +struct mock_pe_port_t mock_pe_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + + +void pe_report_error(int port, enum pe_error e, enum tcpm_transmit_type type) +{ + mock_pe_port[port].mock_pe_error = e; + mock_pe_port[port].sop = type; +} + +void pe_got_hard_reset(int port) +{ + mock_pe_port[port].mock_pe_got_hard_reset = 1; +} + +void pe_message_received(int port) +{ + mock_pe_port[port].mock_pe_message_received = 1; +} + +void pe_message_sent(int port) +{ + mock_pe_port[port].mock_pe_message_sent = 1; +} + +void pe_hard_reset_sent(int port) +{ + mock_pe_port[port].mock_pe_hard_reset_sent = 1; +} + +void pe_got_soft_reset(int port) +{ + mock_pe_port[port].mock_got_soft_reset = 1; +} + +bool pe_in_local_ams(int port) +{ + /* We will probably want to change this in the future */ + return false; +} + diff --git a/common/mock/usb_tc_sm_mock.c b/common/mock/usb_tc_sm_mock.c new file mode 100644 index 0000000000..88326cebe1 --- /dev/null +++ b/common/mock/usb_tc_sm_mock.c @@ -0,0 +1,38 @@ +/* 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. + */ + +/* Mock USB TC state machine */ + +#include "common.h" +#include "console.h" +#include "usb_tc_sm.h" +#include "mock/usb_tc_sm_mock.h" +#include "memory.h" + +#ifndef CONFIG_COMMON_RUNTIME +#define cprints(format, args...) +#endif + +struct mock_tc_port_t mock_tc_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + +enum pd_cable_plug tc_get_cable_plug(int port) +{ + return PD_PLUG_FROM_DFP_UFP; +} + +uint8_t tc_get_pd_enabled(int port) +{ + return mock_tc_port[port].pd_enable; +} + +void typec_select_src_collision_rp(int port, enum tcpc_rp_value rp) +{ + mock_tc_port[port].lcl_rp = rp; +} + +int typec_update_cc(int port) +{ + return EC_SUCCESS; +} diff --git a/include/mock/tcpm_mock.h b/include/mock/tcpm_mock.h new file mode 100644 index 0000000000..8d4dec4092 --- /dev/null +++ b/include/mock/tcpm_mock.h @@ -0,0 +1,7 @@ +/* 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. + */ + /* Mock for the TCPM interface */ + +#include "usb_pd_tcpm.h" diff --git a/include/mock/usb_pd_mock.h b/include/mock/usb_pd_mock.h new file mode 100644 index 0000000000..55bc663001 --- /dev/null +++ b/include/mock/usb_pd_mock.h @@ -0,0 +1,20 @@ +/* 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. + */ +/* Mock USB PD */ + +#ifndef __MOCK_USB_PD_MOCK_H +#define __MOCK_USB_PD_MOCK_H + +#include "common.h" +#include "usb_pd.h" + +struct mock_pd_port_t { + enum pd_data_role data_role; + enum pd_power_role power_role; +}; + +extern struct mock_pd_port_t mock_pd_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + +#endif /* __MOCK_USB_PD_MOCK_H */ diff --git a/include/mock/usb_pe_sm_mock.h b/include/mock/usb_pe_sm_mock.h new file mode 100644 index 0000000000..b678df9d7b --- /dev/null +++ b/include/mock/usb_pe_sm_mock.h @@ -0,0 +1,27 @@ +/* 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. + */ +/* Mock USB PE state machine */ + +#ifndef __MOCK_USB_PE_SM_MOCK_H +#define __MOCK_USB_PE_SM_MOCK_H + +#include "common.h" +#include "usb_pe_sm.h" + +struct mock_pe_port_t { + enum tcpm_transmit_type sop; + + int mock_pe_message_sent; + int mock_pe_error; + int mock_pe_hard_reset_sent; + int mock_pe_got_hard_reset; + int mock_pe_message_received; + int mock_got_soft_reset; +}; + +extern struct mock_pe_port_t mock_pe_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + + +#endif /* __MOCK_USB_PE_SM_MOCK_H */ diff --git a/include/mock/usb_tc_sm_mock.h b/include/mock/usb_tc_sm_mock.h new file mode 100644 index 0000000000..f56f6c7a0d --- /dev/null +++ b/include/mock/usb_tc_sm_mock.h @@ -0,0 +1,20 @@ +/* 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. + */ +/* Mock USB TC state machine*/ + +#ifndef __MOCK_USB_TC_SM_MOCK_H +#define __MOCK_USB_TC_SM_MOCK_H + +#include "common.h" +#include "usb_tc_sm.h" + +struct mock_tc_port_t { + int pd_enable; + enum tcpc_rp_value lcl_rp; +}; + +extern struct mock_tc_port_t mock_tc_port[CONFIG_USB_PD_PORT_MAX_COUNT]; + +#endif /* __MOCK_USB_TC_SM_MOCK_H */ 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) |