summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2022-07-17 22:12:01 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-20 20:01:15 +0000
commit56d1f9440b2b07961a7e3e84e7fd4d75f9da5482 (patch)
tree30fe2b672ccfb78142ce738d7de9d2d57f4d073a
parentb210e6e41577b491cedfe108e215b8361a108f0b (diff)
downloadchrome-ec-56d1f9440b2b07961a7e3e84e7fd4d75f9da5482.tar.gz
Zephyr: Add AP mux control test
Add a unit test to exercise the new command to allow the AP to set muxes, and verify we notify the AP of their sets completing. BRANCH=None BUG=b:234839764 TEST=zmake testall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I27ba90bfcb3a79479560a392e848ebc684459557 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3768919 Reviewed-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/test/drivers/BUILD.py5
-rw-r--r--zephyr/test/drivers/ap_mux_control/CMakeLists.txt19
-rw-r--r--zephyr/test/drivers/ap_mux_control/prj.conf6
-rw-r--r--zephyr/test/drivers/ap_mux_control/src/ap_mux_control.c87
-rw-r--r--zephyr/test/drivers/src/stubs.c1
5 files changed, 118 insertions, 0 deletions
diff --git a/zephyr/test/drivers/BUILD.py b/zephyr/test/drivers/BUILD.py
index 5d8bde6668..159e0d2e0c 100644
--- a/zephyr/test/drivers/BUILD.py
+++ b/zephyr/test/drivers/BUILD.py
@@ -17,6 +17,11 @@ drivers = register_host_test(
# Per Suite Builds
+ap_mux_control = drivers.variant(
+ project_name="test-drivers-ap_mux_control",
+ kconfig_files=[here / "ap_mux_control" / "prj.conf"],
+)
+
chargesplash = drivers.variant(
project_name="test-drivers-chargesplash",
)
diff --git a/zephyr/test/drivers/ap_mux_control/CMakeLists.txt b/zephyr/test/drivers/ap_mux_control/CMakeLists.txt
new file mode 100644
index 0000000000..e497140878
--- /dev/null
+++ b/zephyr/test/drivers/ap_mux_control/CMakeLists.txt
@@ -0,0 +1,19 @@
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Create library name based on current directory
+zephyr_library_get_current_dir_lib_name(${ZEPHYR_BASE} lib_name)
+
+# Create interface library
+zephyr_interface_library_named(${lib_name})
+
+# Add include paths
+zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
+zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
+
+# Add source files
+zephyr_library_sources("${CMAKE_CURRENT_SOURCE_DIR}/src/ap_mux_control.c")
+
+# Link in the library
+zephyr_library_link_libraries(${lib_name})
diff --git a/zephyr/test/drivers/ap_mux_control/prj.conf b/zephyr/test/drivers/ap_mux_control/prj.conf
new file mode 100644
index 0000000000..490f891ff6
--- /dev/null
+++ b/zephyr/test/drivers/ap_mux_control/prj.conf
@@ -0,0 +1,6 @@
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+CONFIG_PLATFORM_EC_USB_MUX_AP_CONTROL=y
+CONFIG_PLATFORM_EC_USB_MUX_TASK=y
diff --git a/zephyr/test/drivers/ap_mux_control/src/ap_mux_control.c b/zephyr/test/drivers/ap_mux_control/src/ap_mux_control.c
new file mode 100644
index 0000000000..15ea7b8374
--- /dev/null
+++ b/zephyr/test/drivers/ap_mux_control/src/ap_mux_control.c
@@ -0,0 +1,87 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/ztest.h>
+
+#include "usb_mux.h"
+#include "test/drivers/stubs.h"
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+static void ap_mux_control_before(void *data)
+{
+ /* Set chipset on to ensure muxes are "powered" */
+ test_set_chipset_to_s0();
+
+ /*
+ * Set all muxes to NONE to begin with and give time for the USB_MUX
+ * task to process them.
+ */
+ usb_mux_set(USBC_PORT_C0, USB_PD_MUX_NONE, USB_SWITCH_CONNECT, 0);
+ k_sleep(K_SECONDS(1));
+
+ /* And test the assumption that setting NONE worked */
+ zassume_equal(usb_mux_get(USBC_PORT_C0), USB_PD_MUX_NONE,
+ "Failed to set mux to initial state");
+}
+
+static void ap_mux_control_after(void *data)
+{
+ /*
+ * Set all muxes to NONE now that we're done and give time for the
+ * USB_MUX task to process them.
+ */
+ usb_mux_set(USBC_PORT_C0, USB_PD_MUX_NONE, USB_SWITCH_CONNECT, 0);
+ k_sleep(K_SECONDS(1));
+}
+
+ZTEST_SUITE(ap_mux_control, drivers_predicate_post_main, NULL,
+ ap_mux_control_before, ap_mux_control_after, NULL);
+
+ZTEST(ap_mux_control, test_set_muxes)
+{
+ struct ec_response_typec_status status;
+ struct typec_usb_mux_set mux_set;
+ uint32_t port_events;
+ int index;
+ uint8_t set_mode = USB_PD_MUX_DOCK;
+
+ /* Test setting both mux indexes and receiving their events */
+ /* TODO(b/239457738): Loop counter should come from device tree */
+ for (index = 0; index < 2; index++) {
+ mux_set.mux_index = index;
+ mux_set.mux_flags = set_mode;
+
+ host_cmd_typec_control_usb_mux_set(USBC_PORT_C0, mux_set);
+
+ /* Give the task processing time */
+ k_sleep(K_SECONDS(1));
+
+ /*
+ * TODO(b/239460181): The "AP" should receive
+ * EC_HOST_EVENT_PD_MCU
+ */
+
+ /* We should see the right index's event set on the port */
+ status = host_cmd_typec_status(USBC_PORT_C0);
+ port_events = index ? PD_STATUS_EVENT_MUX_1_SET_DONE :
+ PD_STATUS_EVENT_MUX_0_SET_DONE;
+ zassert_true(status.events & port_events, "Port event missing");
+
+ /* Clear this mux's event */
+ host_cmd_typec_control_clear_events(USBC_PORT_C0, port_events);
+ }
+
+ /*
+ * Verify our mux mode is reported as set, and that our mux events are
+ * cleared out
+ */
+ status = host_cmd_typec_status(USBC_PORT_C0);
+ port_events = PD_STATUS_EVENT_MUX_0_SET_DONE |
+ PD_STATUS_EVENT_MUX_1_SET_DONE;
+ zassert_false(status.events & port_events, "Port events still set");
+ zassert_equal(status.mux_state, set_mode,
+ "Mux set to unexpected state");
+}
diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c
index 6ca43eb6b9..bc6c526108 100644
--- a/zephyr/test/drivers/src/stubs.c
+++ b/zephyr/test/drivers/src/stubs.c
@@ -167,6 +167,7 @@ int board_is_sourcing_vbus(int port)
return ppc_is_sourcing_vbus(port);
}
+/* TODO(b/239457738): Move to dts */
struct usb_mux usbc0_virtual_usb_mux = {
.usb_port = USBC_PORT_C0,
.driver = &virtual_usb_mux_driver,