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>
This commit is contained in:
parent
ae40ebba22
commit
01705adbfa
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -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"
|
|
@ -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 */
|
|
@ -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 */
|
|
@ -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 */
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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)
|
|
@ -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)
|
Loading…
Reference in New Issue