mocks: add tcpc and usb mux mocks

BRANCH=none
BUG=none
TEST=use them in CL stack with tests

Change-Id: I8a970dc65f7395264a8c536977951ae305e9c24f
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1868831
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
This commit is contained in:
Jett Rink 2019-10-17 13:40:27 -06:00 committed by Commit Bot
parent 0c9970ebea
commit 1a775899f4
5 changed files with 260 additions and 0 deletions

View File

@ -6,4 +6,6 @@
mock-$(HAS_MOCK_FPSENSOR) += fpsensor_mock.o
mock-$(HAS_MOCK_ROLLBACK) += rollback_mock.o
mock-$(HAS_MOCK_TCPC) += tcpc_mock.o
mock-$(HAS_MOCK_TIMER) += timer_mock.o
mock-$(HAS_MOCK_USB_MUX) += usb_mux_mock.o

163
common/mock/tcpc_mock.c Normal file
View File

@ -0,0 +1,163 @@
/* 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.
*/
/* Mock for the TCPC interface */
#include "common.h"
#include "console.h"
#include "usb_pd_tcpm.h"
#include "tcpc_mock.h"
#include "memory.h"
/* Public API for controlling/inspecting this mock */
struct mock_tcpc_ctrl mock_tcpc;
void mock_tcpc_reset(void)
{
memset(&mock_tcpc, 0, sizeof(mock_tcpc));
}
static int mock_init(int port)
{
return EC_SUCCESS;
}
static int mock_release(int port)
{
return EC_SUCCESS;
}
static int mock_get_cc(int port,
enum tcpc_cc_voltage_status *cc1,
enum tcpc_cc_voltage_status *cc2)
{
*cc1 = mock_tcpc.cc1;
*cc2 = mock_tcpc.cc2;
return EC_SUCCESS;
}
static int mock_get_vbus_level(int port)
{
return mock_tcpc.vbus_level;
}
static int mock_select_rp_value(int port, int rp)
{
return EC_SUCCESS;
}
static int mock_set_cc(int port, int pull)
{
return EC_SUCCESS;
}
static int mock_set_polarity(int port, int polarity)
{
return EC_SUCCESS;
}
static int mock_set_vconn(int port, int enable)
{
return EC_SUCCESS;
}
static int mock_set_msg_header(int port, int power_role, int data_role)
{
++mock_tcpc.num_calls_to_set_header;
mock_tcpc.power_role = power_role;
mock_tcpc.data_role = data_role;
if (!mock_tcpc.should_print_header_changes)
return EC_SUCCESS;
ccprints("Setting TCPC header to %s %s",
power_role == PD_ROLE_SOURCE ? "SRC" : "SNK",
data_role == PD_ROLE_UFP ? "UFP" : "DFP");
return EC_SUCCESS;
}
static int mock_set_rx_enable(int port, int enable)
{
return EC_SUCCESS;
}
static int mock_get_message_raw(int port, uint32_t *payload, int *head)
{
return EC_SUCCESS;
}
static int mock_transmit(int port,
enum tcpm_transmit_type type, uint16_t header, const uint32_t *data)
{
return EC_SUCCESS;
}
void mock_tcpc_alert(int port)
{
}
void mock_tcpc_discharge_vbus(int port, int enable)
{
}
__maybe_unused static int mock_drp_toggle(int port)
{
return EC_SUCCESS;
}
static int mock_get_chip_info(int port, int live,
struct ec_response_pd_chip_info_v1 **info)
{
return EC_SUCCESS;
}
__maybe_unused static int mock_set_snk_ctrl(int port, int enable)
{
return EC_SUCCESS;
}
__maybe_unused static int mock_set_src_ctrl(int port, int enable)
{
return EC_SUCCESS;
}
__maybe_unused static int mock_enter_low_power_mode(int port)
{
return EC_SUCCESS;
}
void mock_set_frs_enable(int port, int enable)
{
}
const struct tcpm_drv mock_tcpc_driver = {
.init = &mock_init,
.release = &mock_release,
.get_cc = &mock_get_cc,
.get_vbus_level = &mock_get_vbus_level,
.select_rp_value = &mock_select_rp_value,
.set_cc = &mock_set_cc,
.set_polarity = &mock_set_polarity,
.set_vconn = &mock_set_vconn,
.set_msg_header = &mock_set_msg_header,
.set_rx_enable = &mock_set_rx_enable,
.get_message_raw = &mock_get_message_raw,
.transmit = &mock_transmit,
.tcpc_alert = &mock_tcpc_alert,
.tcpc_discharge_vbus = &mock_tcpc_discharge_vbus,
#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
.drp_toggle = &mock_drp_toggle,
#endif
.get_chip_info = &mock_get_chip_info,
#ifdef CONFIG_USBC_PPC
.set_snk_ctrl = &mock_set_snk_ctrl,
.set_src_ctrl = &mock_set_src_ctrl,
#endif
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
.enter_low_power_mode = &mock_enter_low_power_mode,
#endif
.set_frs_enable = &mock_set_frs_enable,
};

25
common/mock/tcpc_mock.h Normal file
View File

@ -0,0 +1,25 @@
/* 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.
*/
/* Mock for the TCPC interface */
#include "usb_pd_tcpm.h"
#include "usb_pd.h"
/* Controller for TCPC state */
struct mock_tcpc_ctrl {
enum tcpc_cc_voltage_status cc1;
enum tcpc_cc_voltage_status cc2;
int vbus_level;
enum pd_power_role power_role;
enum pd_data_role data_role;
int num_calls_to_set_header;
int should_print_header_changes;
};
/* Reset this TCPC mock */
void mock_tcpc_reset(void);
extern const struct tcpm_drv mock_tcpc_driver;
extern struct mock_tcpc_ctrl mock_tcpc;

View File

@ -0,0 +1,51 @@
/* 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.
*/
/* Mock USB Type-C mux */
#include "common.h"
#include "console.h"
#include "usb_mux.h"
#include "usb_mux_mock.h"
#include "memory.h"
/* Public API for controlling/inspecting this mock */
struct mock_usb_mux_ctrl mock_usb_mux;
void mock_usb_mux_reset(void)
{
memset(&mock_usb_mux, 0, sizeof(mock_usb_mux));
}
static int mock_init(int port)
{
return EC_SUCCESS;
}
static int mock_set(int port, mux_state_t mux_state)
{
mock_usb_mux.state = mux_state;
++mock_usb_mux.num_set_calls;
ccprints("Called into mux with %d", mux_state);
return EC_SUCCESS;
}
int mock_get(int port, mux_state_t *mux_state)
{
*mux_state = mock_usb_mux.state;
return EC_SUCCESS;
}
static int mock_enter_low_power_mode(int port)
{
return EC_SUCCESS;
}
const struct usb_mux_driver mock_usb_mux_driver = {
.init = &mock_init,
.set = &mock_set,
.get = &mock_get,
.enter_low_power_mode = &mock_enter_low_power_mode,
};

View File

@ -0,0 +1,19 @@
/* 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.
*/
/* Mock USB Type-C mux */
#include "usb_mux.h"
/* Controller for mux state */
struct mock_usb_mux_ctrl {
mux_state_t state;
int num_set_calls;
};
/* Resets the state of the mock */
void mock_usb_mux_reset(void);
extern const struct usb_mux_driver mock_usb_mux_driver;
extern struct mock_usb_mux_ctrl mock_usb_mux;