From 5eb597575c2fe2759deaffc06731b42722e4a8a7 Mon Sep 17 00:00:00 2001 From: Robert Zieba Date: Thu, 16 Feb 2023 22:31:28 +0000 Subject: zephyr/test/skyrim: Refactor USB mux config test Move USB mux config test to match new code structure. Add fake functions to allow frostflow test to compile pending implementation of full test. BRANCH=none BUG=b:247151116 TEST=Ran skyrim tests Change-Id: I63d62b9957846dd761c83db9f58f9900f722be45 Signed-off-by: Robert Zieba Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4263559 Reviewed-by: Abe Levkoy --- .../program/skyrim/frostflow/src/usb_mux_config.c | 7 +++ zephyr/program/skyrim/skyrim/src/usb_mux_config.c | 7 +++ zephyr/test/skyrim/CMakeLists.txt | 3 +- zephyr/test/skyrim/Kconfig | 8 +-- zephyr/test/skyrim/boards/native_posix.overlay | 18 ++++++ zephyr/test/skyrim/src/frostflow/usb_mux_config.c | 60 -------------------- zephyr/test/skyrim/testcase.yaml | 9 ++- zephyr/test/skyrim/tests/common/CMakeLists.txt | 5 ++ zephyr/test/skyrim/tests/frostflow/CMakeLists.txt | 5 ++ .../skyrim/tests/frostflow/src/usb_mux_config.c | 65 ++++++++++++++++++++++ 10 files changed, 115 insertions(+), 72 deletions(-) delete mode 100644 zephyr/test/skyrim/src/frostflow/usb_mux_config.c create mode 100644 zephyr/test/skyrim/tests/frostflow/CMakeLists.txt create mode 100644 zephyr/test/skyrim/tests/frostflow/src/usb_mux_config.c diff --git a/zephyr/program/skyrim/frostflow/src/usb_mux_config.c b/zephyr/program/skyrim/frostflow/src/usb_mux_config.c index f2c5bd2444..d018ff12f3 100644 --- a/zephyr/program/skyrim/frostflow/src/usb_mux_config.c +++ b/zephyr/program/skyrim/frostflow/src/usb_mux_config.c @@ -17,6 +17,13 @@ #include "usbc/usb_muxes.h" #include "util.h" +#ifdef CONFIG_ZTEST +/* Verify this is still needed for b/247151116. */ +#undef I2C_PORT_NODELABEL +#define I2C_PORT_NODELABEL(x) 0 + +#endif /* CONFIG_ZTEST */ + #define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args) #define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ##args) diff --git a/zephyr/program/skyrim/skyrim/src/usb_mux_config.c b/zephyr/program/skyrim/skyrim/src/usb_mux_config.c index 8d409dffdd..17e452a778 100644 --- a/zephyr/program/skyrim/skyrim/src/usb_mux_config.c +++ b/zephyr/program/skyrim/skyrim/src/usb_mux_config.c @@ -16,6 +16,13 @@ #include +#ifdef CONFIG_ZTEST + +#undef USB_MUX_ENABLE_ALTERNATIVE +#define USB_MUX_ENABLE_ALTERNATIVE(x) + +#endif /* CONFIG_ZTEST */ + #define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args) #define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ##args) diff --git a/zephyr/test/skyrim/CMakeLists.txt b/zephyr/test/skyrim/CMakeLists.txt index 3a6c866a7b..25eb4a333a 100644 --- a/zephyr/test/skyrim/CMakeLists.txt +++ b/zephyr/test/skyrim/CMakeLists.txt @@ -12,8 +12,7 @@ add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils) add_subdirectory(tests/common) add_subdirectory_ifdef(CONFIG_TEST_BOARD_BASEBOARD tests/baseboard) +add_subdirectory_ifdef(CONFIG_TEST_BOARD_FROSTFLOW tests/frostflow) add_subdirectory_ifdef(CONFIG_TEST_BOARD_WINTERHOLD tests/winterhold) target_sources(app PRIVATE src/${CONFIG_TEST_BOARD_NAME}/common.c) - -target_sources_ifdef(CONFIG_TEST_BOARD_USB_MUX_CONFIG app PRIVATE src/${TEST_BOARD_USB_MUX_CONFIG_SRC} ${PLATFORM_EC_PROGRAM_DIR}/skyrim/${CONFIG_TEST_BOARD_NAME}/src/usb_mux_config.c) diff --git a/zephyr/test/skyrim/Kconfig b/zephyr/test/skyrim/Kconfig index b96d5ce05b..c6193e0325 100644 --- a/zephyr/test/skyrim/Kconfig +++ b/zephyr/test/skyrim/Kconfig @@ -76,12 +76,10 @@ config TEST_BOARD_PPC_CONFIG_CUSTOM config TEST_BOARD_USB_MUX_CONFIG bool "Enable USB mux config tests" - default n -config TEST_BOARD_USB_MUX_CONFIG_SRC - string "Source file to use for this test" - default "common/usb_mux_config.c" - depends on TEST_BOARD_USB_MUX_CONFIG +config TEST_BOARD_USB_MUX_CONFIG_CUSTOM + bool "Enable USB mux config tests with a variant-specific test file" + select TEST_BOARD_USB_MUX_CONFIG config SKYRIM_LOG_LEVEL int "Fake config to allow building" diff --git a/zephyr/test/skyrim/boards/native_posix.overlay b/zephyr/test/skyrim/boards/native_posix.overlay index 5bf8c86ec7..cbf687b743 100644 --- a/zephyr/test/skyrim/boards/native_posix.overlay +++ b/zephyr/test/skyrim/boards/native_posix.overlay @@ -59,6 +59,24 @@ skyrim-fw-config { compatible = "cros-ec,cbi-fw-config"; + io-db { + enum-name = "FW_IO_DB"; + start = <6>; + size = <2>; + + io-db-ps8811-ps8818 { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_IO_DB_PS8811_PS8818"; + value = <0>; + }; + io-db-none-anx7483 { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_IO_DB_NONE_ANX7483"; + value = <1>; + default; + }; + }; + fan { enum-name = "FW_FAN"; start = <10>; diff --git a/zephyr/test/skyrim/src/frostflow/usb_mux_config.c b/zephyr/test/skyrim/src/frostflow/usb_mux_config.c deleted file mode 100644 index 929bd318d4..0000000000 --- a/zephyr/test/skyrim/src/frostflow/usb_mux_config.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2023 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#include -#include -#include - -#include -#include - -int board_c0_amd_fp6_mux_set(const struct usb_mux *me, mux_state_t mux_state); -int board_c1_ps8818_mux_set(const struct usb_mux *me, mux_state_t mux_state); - -ZTEST_SUITE(usb_mux_config, NULL, NULL, NULL, NULL, NULL); - -ZTEST(usb_mux_config, board_c0_amd_fp6_mux_set) -{ - const struct gpio_dt_spec *c0 = - GPIO_DT_FROM_NODELABEL(ioex_usb_c0_sbu_flip); - const struct gpio_dt_spec *c1 = - GPIO_DT_FROM_NODELABEL(ioex_usb_c1_sbu_flip); - struct usb_mux mux; - int rv; - - /* Output for each port should match inverted status. */ - mux.usb_port = 0; - rv = board_c0_amd_fp6_mux_set(&mux, 0); - zassert_equal(rv, EC_SUCCESS); - zassert_equal(gpio_emul_output_get(c0->port, c0->pin), 0); - - rv = board_c0_amd_fp6_mux_set(&mux, USB_PD_MUX_POLARITY_INVERTED); - zassert_equal(rv, EC_SUCCESS); - zassert_equal(gpio_emul_output_get(c0->port, c0->pin), 1); - - mux.usb_port = 1; - rv = board_c0_amd_fp6_mux_set(&mux, 0); - zassert_equal(rv, EC_SUCCESS); - zassert_equal(gpio_emul_output_get(c1->port, c1->pin), 0); - - rv = board_c0_amd_fp6_mux_set(&mux, USB_PD_MUX_POLARITY_INVERTED); - zassert_equal(rv, EC_SUCCESS); - zassert_equal(gpio_emul_output_get(c1->port, c1->pin), 1); -} - -ZTEST(usb_mux_config, board_c1_ps8818_mux_set) -{ - const struct gpio_dt_spec *gpio = - GPIO_DT_FROM_NODELABEL(gpio_usb_c1_in_hpd); - struct usb_mux mux; - - /* gpio_usb_c1_in_hpd should match if DP is enabled. */ - mux.usb_port = 0; - zassert_ok(board_c1_ps8818_mux_set(&mux, 0)); - zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); - - mux.usb_port = 1; - zassert_ok(board_c1_ps8818_mux_set(&mux, USB_PD_MUX_DP_ENABLED)); - zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); -} diff --git a/zephyr/test/skyrim/testcase.yaml b/zephyr/test/skyrim/testcase.yaml index 83c7727a7a..c718e888d7 100644 --- a/zephyr/test/skyrim/testcase.yaml +++ b/zephyr/test/skyrim/testcase.yaml @@ -51,11 +51,10 @@ tests: - CONFIG_TEST_BOARD_FROSTFLOW=y - CONFIG_TEST_BOARD_PPC_CONFIG=y -# skyrim.frostflow.usb_mux_config: -# extra_configs: -# - CONFIG_TEST_BOARD_FROSTFLOW=y -# - CONFIG_TEST_BOARD_USB_MUX_CONFIG=y -# - CONFIG_TEST_BOARD_USB_MUX_CONFIG_SRC="frostflow/usb_mux_config.c" + skyrim.frostflow.usb_mux_config: + extra_configs: + - CONFIG_TEST_BOARD_FROSTFLOW=y + - CONFIG_TEST_BOARD_USB_MUX_CONFIG_CUSTOM=y # Markarth tests skyrim.markarth: diff --git a/zephyr/test/skyrim/tests/common/CMakeLists.txt b/zephyr/test/skyrim/tests/common/CMakeLists.txt index efe8703fe1..49da87b372 100644 --- a/zephyr/test/skyrim/tests/common/CMakeLists.txt +++ b/zephyr/test/skyrim/tests/common/CMakeLists.txt @@ -26,4 +26,9 @@ if (DEFINED CONFIG_TEST_BOARD_PPC_CONFIG) if (NOT DEFINED CONFIG_TEST_BOARD_PPC_CONFIG_CUSTOM) target_sources(app PRIVATE src/ppc_config.c) endif() +endif() + +# USB mux config +if (DEFINED CONFIG_TEST_BOARD_USB_MUX_CONFIG) + target_sources(app PRIVATE ${PLATFORM_EC_PROGRAM_DIR}/skyrim/${CONFIG_TEST_BOARD_NAME}/src/usb_mux_config.c) endif() \ No newline at end of file diff --git a/zephyr/test/skyrim/tests/frostflow/CMakeLists.txt b/zephyr/test/skyrim/tests/frostflow/CMakeLists.txt new file mode 100644 index 0000000000..c195c83093 --- /dev/null +++ b/zephyr/test/skyrim/tests/frostflow/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2023 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +target_sources_ifdef(CONFIG_TEST_BOARD_USB_MUX_CONFIG app PRIVATE src/usb_mux_config.c) \ No newline at end of file diff --git a/zephyr/test/skyrim/tests/frostflow/src/usb_mux_config.c b/zephyr/test/skyrim/tests/frostflow/src/usb_mux_config.c new file mode 100644 index 0000000000..3a4b80d347 --- /dev/null +++ b/zephyr/test/skyrim/tests/frostflow/src/usb_mux_config.c @@ -0,0 +1,65 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include +#include +#include + +#include +#include + +FAKE_VALUE_FUNC(int, ps8811_i2c_read, const struct usb_mux *, int, int, int *); +FAKE_VALUE_FUNC(int, ps8811_i2c_field_update, const struct usb_mux *, int, int, + uint8_t, uint8_t); +FAKE_VALUE_FUNC(int, ps8811_i2c_write, const struct usb_mux *, int, int, int); + +int board_c0_amd_fp6_mux_set(const struct usb_mux *me, mux_state_t mux_state); +int board_c1_ps8818_mux_set(const struct usb_mux *me, mux_state_t mux_state); + +ZTEST_SUITE(usb_mux_config, NULL, NULL, NULL, NULL, NULL); + +ZTEST(usb_mux_config, board_c0_amd_fp6_mux_set) +{ + const struct gpio_dt_spec *c0 = + GPIO_DT_FROM_NODELABEL(ioex_usb_c0_sbu_flip); + const struct gpio_dt_spec *c1 = + GPIO_DT_FROM_NODELABEL(ioex_usb_c1_sbu_flip); + struct usb_mux mux; + int rv; + + /* Output for each port should match inverted status. */ + mux.usb_port = 0; + rv = board_c0_amd_fp6_mux_set(&mux, 0); + zassert_equal(rv, EC_SUCCESS); + zassert_equal(gpio_emul_output_get(c0->port, c0->pin), 0); + + rv = board_c0_amd_fp6_mux_set(&mux, USB_PD_MUX_POLARITY_INVERTED); + zassert_equal(rv, EC_SUCCESS); + zassert_equal(gpio_emul_output_get(c0->port, c0->pin), 1); + + mux.usb_port = 1; + rv = board_c0_amd_fp6_mux_set(&mux, 0); + zassert_equal(rv, EC_SUCCESS); + zassert_equal(gpio_emul_output_get(c1->port, c1->pin), 0); + + rv = board_c0_amd_fp6_mux_set(&mux, USB_PD_MUX_POLARITY_INVERTED); + zassert_equal(rv, EC_SUCCESS); + zassert_equal(gpio_emul_output_get(c1->port, c1->pin), 1); +} + +ZTEST(usb_mux_config, board_c1_ps8818_mux_set) +{ + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c1_in_hpd); + struct usb_mux mux; + + /* gpio_usb_c1_in_hpd should match if DP is enabled. */ + mux.usb_port = 0; + zassert_ok(board_c1_ps8818_mux_set(&mux, 0)); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + mux.usb_port = 1; + zassert_ok(board_c1_ps8818_mux_set(&mux, USB_PD_MUX_DP_ENABLED)); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); +} -- cgit v1.2.1