summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/src/usb_mux.c
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2021-11-10 12:53:27 +0100
committerCommit Bot <commit-bot@chromium.org>2021-11-15 12:00:19 +0000
commit304eef2fadf54307eee3ee35a06326f5c52672c9 (patch)
tree6ca1d7965ea873e9f8a77ef86126306b4406e132 /zephyr/test/drivers/src/usb_mux.c
parentea789cdeaae45ad0473ffc3ea7c68dfca6e82966 (diff)
downloadchrome-ec-304eef2fadf54307eee3ee35a06326f5c52672c9.tar.gz
zephyr: drivers: add usb_mux typec command test
Add unit test for command_typec(). It is tested that command is checking arguments and correct usb_mux functions are called depending on arguments. BUG=b:184857076 BRANCH=none TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: Idf78320a791c20440da3f5b66d524dc7161e0f69 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3270686 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Tested-by: Tomasz Michalec <tmichalec@google.com> Commit-Queue: Tomasz Michalec <tmichalec@google.com>
Diffstat (limited to 'zephyr/test/drivers/src/usb_mux.c')
-rw-r--r--zephyr/test/drivers/src/usb_mux.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/usb_mux.c b/zephyr/test/drivers/src/usb_mux.c
index c782101fee..cf6190eec9 100644
--- a/zephyr/test/drivers/src/usb_mux.c
+++ b/zephyr/test/drivers/src/usb_mux.c
@@ -8,6 +8,8 @@
#include <ztest.h>
#include <drivers/gpio.h>
#include <drivers/gpio/gpio_emul.h>
+#include <shell/shell.h>
+#include <shell/shell_uart.h>
#include "common.h"
#include "ec_commands.h"
@@ -632,6 +634,77 @@ static void test_usb_mux_hc_mux_info(void)
response.flags, exp_mode);
}
+/** Test typec console command */
+static void test_usb_mux_typec_command(void)
+{
+ mux_state_t exp_mode;
+
+ /* Test error on command with no argument */
+ zassert_equal(EC_ERROR_PARAM_COUNT,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec"), NULL);
+
+ /*
+ * Test success on passing "debug" as first argument. This will enable
+ * debug prints, but it is not possible to test that in unit test
+ * without accessing cprints output.
+ */
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec debug"), NULL);
+
+ /* Test error on port argument that is not a number */
+ zassert_equal(EC_ERROR_PARAM1,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec test1"), NULL);
+
+ /* Test error on invalid port number */
+ zassert_equal(EC_ERROR_PARAM1,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 5"), NULL);
+
+ /*
+ * Test success on correct port number. Command should print mux state
+ * on console, but it is not possible to check that in unit test.
+ */
+ setup_ztest_proxy_get(0, 2, EC_SUCCESS, USB_PD_MUX_TBT_COMPAT_ENABLED);
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 1"), NULL);
+
+ /* Test setting none mode */
+ exp_mode = USB_PD_MUX_NONE;
+ setup_ztest_proxy_set(0, 2, EC_SUCCESS, exp_mode);
+ /* Mux will enter low power mode */
+ setup_ztest_proxy_enter_lpm(0, 2, EC_SUCCESS);
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 1 none"), NULL);
+
+ /* Test setting USB mode */
+ exp_mode = USB_PD_MUX_USB_ENABLED;
+ setup_ztest_proxy_set(0, 2, EC_SUCCESS, exp_mode);
+ /* Mux will exit low power mode */
+ setup_ztest_proxy_init(0, 2, EC_SUCCESS);
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 1 usb"), NULL);
+
+ /* Test setting DP mode */
+ exp_mode = USB_PD_MUX_DP_ENABLED;
+ setup_ztest_proxy_set(0, 2, EC_SUCCESS, exp_mode);
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 1 dp"), NULL);
+
+ /* Test setting dock mode */
+ exp_mode = USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED;
+ setup_ztest_proxy_set(0, 2, EC_SUCCESS, exp_mode);
+ zassert_equal(EC_SUCCESS,
+ shell_execute_cmd(shell_backend_uart_get_ptr(),
+ "typec 1 dock"), NULL);
+}
+
/** Setup proxy chain and uninit usb muxes */
void setup_uninit_mux(void)
{
@@ -681,6 +754,9 @@ void test_suite_usb_mux(void)
setup_init_mux, resotre_usb_mux_chain),
ztest_unit_test_setup_teardown(
test_usb_mux_hc_mux_info,
+ setup_init_mux, resotre_usb_mux_chain),
+ ztest_unit_test_setup_teardown(
+ test_usb_mux_typec_command,
setup_init_mux, resotre_usb_mux_chain));
ztest_run_test_suite(usb_mux);
}