summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@google.com>2020-08-14 17:20:04 -0600
committerCommit Bot <commit-bot@chromium.org>2020-08-31 17:06:13 +0000
commit33db71602297092026bb714f8b038ac0e7ac593d (patch)
tree4f40eb0fbcc63acd5d8f4387f7d2d554f80ae6b4 /test
parentbd018841f6f2856c949dcf9b6dd462872cd18d7f (diff)
downloadchrome-ec-33db71602297092026bb714f8b038ac0e7ac593d.tar.gz
usb_pe_drp: new unit test with mocks
Add a new unit test for usb_pe_drp with mocks for the various subsystems that it will use. The fake_prl module is already essentially a mock for the PRL layer, so just move it into the mocks directory and make it available as mock to other tests. BUG=b:163421994 BRANCH=None TEST=`make runhosttests` succeeds Signed-off-by: Paul Fagerburg <pfagerburg@google.com> Change-Id: I2aea3fa0694e8d9e6bae1f47516cb4d5d2a1e714 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2364050 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.mk9
-rw-r--r--test/fake_prl.c81
-rw-r--r--test/test_config.h24
-rw-r--r--test/usb_pe_drp.c56
-rw-r--r--test/usb_pe_drp.mocklist13
-rw-r--r--test/usb_pe_drp.tasklist10
-rw-r--r--test/usb_pe_drp_noextended.c46
-rw-r--r--test/usb_pe_drp_noextended.mocklist13
-rw-r--r--test/usb_pe_drp_noextended.tasklist10
-rw-r--r--test/usb_pe_drp_old.mocklist7
-rw-r--r--test/usb_pe_drp_old_noextended.mocklist7
11 files changed, 192 insertions, 84 deletions
diff --git a/test/build.mk b/test/build.mk
index 6c69f639c1..5ea7a56304 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -94,6 +94,8 @@ test-list-host += usb_prl
test-list-host += usb_prl_noextended
test-list-host += usb_pe_drp_old
test-list-host += usb_pe_drp_old_noextended
+test-list-host += usb_pe_drp
+test-list-host += usb_pe_drp_noextended
test-list-host += utils
test-list-host += utils_str
test-list-host += vboot
@@ -204,9 +206,10 @@ usb_typec_drp_acc_trysrc-y=usb_typec_drp_acc_trysrc.o vpd_api.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_prl_noextended-y=usb_prl_noextended.o usb_sm_checks.o fake_usbc.o
-usb_pe_drp_old-y=usb_pe_drp_old.o usb_sm_checks.o fake_prl.o fake_usbc.o
-usb_pe_drp_old_noextended-y=usb_pe_drp_old.o usb_sm_checks.o fake_prl.o \
- fake_usbc.o
+usb_pe_drp_old-y=usb_pe_drp_old.o usb_sm_checks.o fake_usbc.o
+usb_pe_drp_old_noextended-y=usb_pe_drp_old.o usb_sm_checks.o fake_usbc.o
+usb_pe_drp-y=usb_pe_drp.o usb_sm_checks.o
+usb_pe_drp_noextended-y=usb_pe_drp_noextended.o usb_sm_checks.o
usb_tcpmv2_tcpci-y=usb_tcpmv2_tcpci.o vpd_api.o usb_sm_checks.o
utils-y=utils.o
utils_str-y=utils_str.o
diff --git a/test/fake_prl.c b/test/fake_prl.c
deleted file mode 100644
index 3674953c45..0000000000
--- a/test/fake_prl.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* 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.
- *
- * Fake Protocol Layer module.
- */
-#include "common.h"
-#include "usb_emsg.h"
-#include "usb_prl_sm.h"
-
-struct extended_msg rx_emsg[CONFIG_USB_PD_PORT_MAX_COUNT];
-struct extended_msg tx_emsg[CONFIG_USB_PD_PORT_MAX_COUNT];
-
-void prl_end_ams(int port)
-{}
-
-void prl_execute_hard_reset(int port)
-{}
-
-enum pd_rev_type prl_get_rev(int port, enum tcpm_transmit_type partner)
-{
- return PD_REV30;
-}
-
-void prl_hard_reset_complete(int port)
-{}
-
-int prl_is_running(int port)
-{
- return 1;
-}
-
-void prl_reset(int port)
-{}
-
-void prl_reset_soft(int port)
-{}
-
-static enum pd_ctrl_msg_type last_ctrl_msg[CONFIG_USB_PD_PORT_MAX_COUNT];
-static enum pd_data_msg_type last_data_msg_type[CONFIG_USB_PD_PORT_MAX_COUNT];
-
-void prl_send_ctrl_msg(int port, enum tcpm_transmit_type type,
- enum pd_ctrl_msg_type msg)
-{
- last_ctrl_msg[port] = msg;
-}
-
-void prl_send_data_msg(int port, enum tcpm_transmit_type type,
- enum pd_data_msg_type msg)
-{
- last_data_msg_type[port] = msg;
-}
-
-void prl_send_ext_data_msg(int port, enum tcpm_transmit_type type,
- enum pd_ext_msg_type msg)
-{}
-
-void prl_set_rev(int port, enum tcpm_transmit_type partner,
- enum pd_rev_type rev)
-{}
-
-
-enum pd_ctrl_msg_type fake_prl_get_last_sent_ctrl_msg(int port)
-{
- return last_ctrl_msg[port];
-}
-
-void fake_prl_clear_last_sent_ctrl_msg(int port)
-{
- last_ctrl_msg[port] = 0;
-}
-
-enum pd_data_msg_type fake_prl_get_last_sent_data_msg_type(int port)
-{
- return last_data_msg_type[port];
-}
-
-void fake_prl_clear_last_sent_data_msg(int port)
-{
- last_data_msg_type[port] = 0;
-}
diff --git a/test/test_config.h b/test/test_config.h
index ed07f73983..74393e0133 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -378,6 +378,30 @@ int ncp15wb_calculate_temp(uint16_t adc);
#define CONFIG_USBC_SS_MUX
#endif
+#if defined(TEST_USB_PE_DRP) || defined(TEST_USB_PE_DRP_NOEXTENDED)
+#define CONFIG_TEST_USB_PE_SM
+#define CONFIG_USB_PD_PORT_MAX_COUNT 1
+#define CONFIG_USB_PE_SM
+#define CONFIG_USB_PID 0x5036
+#define CONFIG_USB_POWER_DELIVERY
+#undef CONFIG_USB_PRL_SM
+#define CONFIG_USB_PD_REV30
+
+#if defined(TEST_USB_PE_DRP)
+#define CONFIG_USB_PD_EXTENDED_MESSAGES
+#endif
+
+#define CONFIG_USB_PD_TCPMV2
+#define CONFIG_USB_PD_DECODE_SOP
+#undef CONFIG_USB_TYPEC_SM
+#define CONFIG_USBC_VCONN
+#define PD_VCONN_SWAP_DELAY 5000 /* us */
+#define CONFIG_USB_PD_DISCHARGE_GPIO
+#undef CONFIG_USB_PD_HOST_CMD
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USBC_SS_MUX
+#endif
+
/* Common TypeC tests defines */
#if defined(TEST_USB_TYPEC_VPD) || \
defined(TEST_USB_TYPEC_CTVPD)
diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c
new file mode 100644
index 0000000000..b210db4ae9
--- /dev/null
+++ b/test/usb_pe_drp.c
@@ -0,0 +1,56 @@
+/* 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 PE module.
+ */
+#include "common.h"
+#include "task.h"
+#include "test_util.h"
+#include "timer.h"
+#include "usb_emsg.h"
+#include "usb_mux.h"
+#include "usb_pe.h"
+#include "usb_pe_sm.h"
+#include "usb_sm_checks.h"
+#include "mock/usb_tc_sm_mock.h"
+#include "mock/tcpc_mock.h"
+#include "mock/usb_mux_mock.h"
+#include "mock/usb_pd_mock.h"
+#include "mock/usb_pd_dpm_mock.h"
+#include "mock/dp_alt_mode_mock.h"
+#include "mock/usb_prl_mock.h"
+
+/* Install Mock TCPC and MUX drivers */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .drv = &mock_tcpc_driver,
+ },
+};
+
+const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .driver = &mock_usb_mux_driver,
+ }
+};
+
+void before_test(void)
+{
+ mock_tc_port_reset();
+ mock_tcpc_reset();
+ mock_usb_mux_reset();
+ mock_pd_reset();
+ mock_dpm_reset();
+ mock_dp_alt_mode_reset();
+ mock_prl_reset();
+}
+
+void run_test(int argc, char **argv)
+{
+ test_reset();
+
+ /* Do basic state machine validity checks last. */
+ RUN_TEST(test_pe_no_parent_cycles);
+
+ test_print_result();
+}
diff --git a/test/usb_pe_drp.mocklist b/test/usb_pe_drp.mocklist
new file mode 100644
index 0000000000..b690044789
--- /dev/null
+++ b/test/usb_pe_drp.mocklist
@@ -0,0 +1,13 @@
+/* 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.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(USB_TC_SM) \
+ MOCK(USB_PD) \
+ MOCK(TCPC) \
+ MOCK(USB_MUX) \
+ MOCK(USB_PD_DPM) \
+ MOCK(DP_ALT_MODE) \
+ MOCK(USB_PRL)
diff --git a/test/usb_pe_drp.tasklist b/test/usb_pe_drp.tasklist
new file mode 100644
index 0000000000..eb41326e3e
--- /dev/null
+++ b/test/usb_pe_drp.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)
diff --git a/test/usb_pe_drp_noextended.c b/test/usb_pe_drp_noextended.c
new file mode 100644
index 0000000000..68da7426e2
--- /dev/null
+++ b/test/usb_pe_drp_noextended.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 PE module.
+ */
+#include "common.h"
+#include "task.h"
+#include "test_util.h"
+#include "timer.h"
+#include "usb_emsg.h"
+#include "usb_mux.h"
+#include "usb_pe.h"
+#include "usb_pe_sm.h"
+#include "usb_sm_checks.h"
+#include "mock/usb_tc_sm_mock.h"
+#include "mock/tcpc_mock.h"
+#include "mock/usb_mux_mock.h"
+
+/* Install Mock TCPC and MUX drivers */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .drv = &mock_tcpc_driver,
+ },
+};
+
+const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .driver = &mock_usb_mux_driver,
+ }
+};
+
+void before_test(void)
+{
+ mock_tc_port_reset();
+}
+
+void run_test(int argc, char **argv)
+{
+ test_reset();
+
+ /* Do basic state machine validity checks last. */
+ RUN_TEST(test_pe_no_parent_cycles);
+
+ test_print_result();
+}
diff --git a/test/usb_pe_drp_noextended.mocklist b/test/usb_pe_drp_noextended.mocklist
new file mode 100644
index 0000000000..b690044789
--- /dev/null
+++ b/test/usb_pe_drp_noextended.mocklist
@@ -0,0 +1,13 @@
+/* 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.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(USB_TC_SM) \
+ MOCK(USB_PD) \
+ MOCK(TCPC) \
+ MOCK(USB_MUX) \
+ MOCK(USB_PD_DPM) \
+ MOCK(DP_ALT_MODE) \
+ MOCK(USB_PRL)
diff --git a/test/usb_pe_drp_noextended.tasklist b/test/usb_pe_drp_noextended.tasklist
new file mode 100644
index 0000000000..eb41326e3e
--- /dev/null
+++ b/test/usb_pe_drp_noextended.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)
diff --git a/test/usb_pe_drp_old.mocklist b/test/usb_pe_drp_old.mocklist
new file mode 100644
index 0000000000..0582e5cbb3
--- /dev/null
+++ b/test/usb_pe_drp_old.mocklist
@@ -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.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(USB_PRL)
diff --git a/test/usb_pe_drp_old_noextended.mocklist b/test/usb_pe_drp_old_noextended.mocklist
new file mode 100644
index 0000000000..0582e5cbb3
--- /dev/null
+++ b/test/usb_pe_drp_old_noextended.mocklist
@@ -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.
+ */
+
+ #define CONFIG_TEST_MOCK_LIST \
+ MOCK(USB_PRL)