summaryrefslogtreecommitdiff
path: root/common/mock
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-10-17 13:40:27 -0600
committerCommit Bot <commit-bot@chromium.org>2019-10-23 18:19:43 +0000
commit1a775899f44dbb682b2dce94d27493d9dda82588 (patch)
tree9b4b9c1ac398972373198d7c4ea5d1a10aa4c240 /common/mock
parent0c9970ebeab1810667f49ebe6d7f3a14c5c7fe71 (diff)
downloadchrome-ec-1a775899f44dbb682b2dce94d27493d9dda82588.tar.gz
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>
Diffstat (limited to 'common/mock')
-rw-r--r--common/mock/build.mk2
-rw-r--r--common/mock/tcpc_mock.c163
-rw-r--r--common/mock/tcpc_mock.h25
-rw-r--r--common/mock/usb_mux_mock.c51
-rw-r--r--common/mock/usb_mux_mock.h19
5 files changed, 260 insertions, 0 deletions
diff --git a/common/mock/build.mk b/common/mock/build.mk
index 56ef715cf7..882cf6ccb9 100644
--- a/common/mock/build.mk
+++ b/common/mock/build.mk
@@ -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
diff --git a/common/mock/tcpc_mock.c b/common/mock/tcpc_mock.c
new file mode 100644
index 0000000000..dabe5cda70
--- /dev/null
+++ b/common/mock/tcpc_mock.c
@@ -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,
+};
diff --git a/common/mock/tcpc_mock.h b/common/mock/tcpc_mock.h
new file mode 100644
index 0000000000..267856f463
--- /dev/null
+++ b/common/mock/tcpc_mock.h
@@ -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;
diff --git a/common/mock/usb_mux_mock.c b/common/mock/usb_mux_mock.c
new file mode 100644
index 0000000000..28f07c54f7
--- /dev/null
+++ b/common/mock/usb_mux_mock.c
@@ -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,
+};
diff --git a/common/mock/usb_mux_mock.h b/common/mock/usb_mux_mock.h
new file mode 100644
index 0000000000..128286796b
--- /dev/null
+++ b/common/mock/usb_mux_mock.h
@@ -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;