summaryrefslogtreecommitdiff
path: root/zephyr/test/kingler/src
diff options
context:
space:
mode:
authorIvan Chen <yulunchen@google.com>2023-05-17 03:32:45 +0000
committerIvan Chen <yulunchen@google.com>2023-05-17 03:32:45 +0000
commitd7c9c6beb03ee5725232b9ac3bfe4825e1e227cb (patch)
tree3a0d6776c0e76e325d1b087cd51a850cb871358e /zephyr/test/kingler/src
parent8641442366bd7c2c133e302a57f904dfac3c896b (diff)
parentb34dc2ae9022e2fbb57ae6477891ff32954c62fd (diff)
downloadchrome-ec-d7c9c6beb03ee5725232b9ac3bfe4825e1e227cb.tar.gz
Merge remote-tracking branch cros/main into firmware-brya-14505.B-mainfirmware-brya-14505.B-main
Generated by: util/update_release_branch.py --board brya firmware-brya-14505.B-main Relevant changes: git log --oneline 8641442366..b34dc2ae90 -- board/brya board/brya util/getversion.sh BRANCH=None TEST=`make -j buildall` Force-Relevant-Builds: all Change-Id: I63149b4c1782b3ed57f2556755901c21f5f1e3e9 Signed-off-by: Ivan Chen <yulunchen@google.com>
Diffstat (limited to 'zephyr/test/kingler/src')
-rw-r--r--zephyr/test/kingler/src/fakes.c15
-rw-r--r--zephyr/test/kingler/src/kingler_usbc.c78
-rw-r--r--zephyr/test/kingler/src/usb_port_count.c90
3 files changed, 181 insertions, 2 deletions
diff --git a/zephyr/test/kingler/src/fakes.c b/zephyr/test/kingler/src/fakes.c
index 412e02fef9..c4a7cf0a6d 100644
--- a/zephyr/test/kingler/src/fakes.c
+++ b/zephyr/test/kingler/src/fakes.c
@@ -9,16 +9,27 @@
FAKE_VOID_FUNC(power_button_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(button_interrupt, enum gpio_signal);
-FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(chipset_reset_request_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(power_signal_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(chipset_watchdog_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(extpower_interrupt, enum gpio_signal);
-FAKE_VOID_FUNC(xhci_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(switch_interrupt, enum gpio_signal);
+#if !(defined(CONFIG_TEST_KINGLER_USBC) || \
+ defined(CONFIG_TEST_DB_DETECTION_USB_COUNT))
+FAKE_VOID_FUNC(xhci_interrupt, enum gpio_signal);
+#endif
+#ifndef CONFIG_TEST_KINGLER_USBC
+FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(usb_a0_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(tcpc_alert_event, enum gpio_signal);
FAKE_VOID_FUNC(ppc_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(bc12_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(pd_power_supply_reset, int);
+FAKE_VOID_FUNC(pd_set_power_supply_ready, int);
+FAKE_VALUE_FUNC(int, board_set_active_charge_port, int);
+FAKE_VALUE_FUNC(int, pd_snk_is_vbus_provided, int);
+FAKE_VALUE_FUNC(int, pd_check_vconn_swap, int);
+#endif
FAKE_VOID_FUNC(chipset_warm_reset_interrupt, enum gpio_signal);
#ifndef CONFIG_TEST_KINGLER_CCD
FAKE_VOID_FUNC(ccd_interrupt, enum gpio_signal);
diff --git a/zephyr/test/kingler/src/kingler_usbc.c b/zephyr/test/kingler/src/kingler_usbc.c
new file mode 100644
index 0000000000..afd8cdbccd
--- /dev/null
+++ b/zephyr/test/kingler/src/kingler_usbc.c
@@ -0,0 +1,78 @@
+/* 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 "driver/tcpm/tcpm.h"
+#include "ec_app_main.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+#define LOG_LEVEL 0
+LOG_MODULE_REGISTER(npcx_usbc);
+
+FAKE_VALUE_FUNC(enum corsola_db_type, corsola_get_db_type);
+FAKE_VALUE_FUNC(bool, in_interrupt_context);
+FAKE_VOID_FUNC(bmi3xx_interrupt);
+FAKE_VOID_FUNC(hdmi_hpd_interrupt);
+FAKE_VOID_FUNC(ps185_hdmi_hpd_mux_set);
+FAKE_VALUE_FUNC(bool, ps8743_field_update, const struct usb_mux *, uint8_t,
+ uint8_t, uint8_t);
+
+#define FFF_FAKES_LIST(FAKE) \
+ FAKE(corsola_get_db_type) \
+ FAKE(in_interrupt_context) \
+ FAKE(bmi3xx_interrupt) \
+ FAKE(hdmi_hpd_interrupt) \
+ FAKE(ps185_hdmi_hpd_mux_set) \
+ FAKE(ps8743_field_update)
+
+struct kingler_usbc_fixture {
+ int place_holder;
+};
+
+static void *kingler_usbc_setup(void)
+{
+ static struct kingler_usbc_fixture f;
+
+ return &f;
+}
+
+static void kingler_usbc_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ FFF_FAKES_LIST(RESET_FAKE);
+ FFF_RESET_HISTORY();
+}
+
+ZTEST_RULE(kingler_usbc_reset_rule, kingler_usbc_reset_rule_before, NULL);
+ZTEST_SUITE(kingler_usbc, NULL, kingler_usbc_setup, NULL, NULL, NULL);
+
+ZTEST_F(kingler_usbc, test_power_supply)
+{
+ pd_power_supply_reset(0);
+ zassert_equal(0, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ zassert_equal(EC_SUCCESS, pd_set_power_supply_ready(0));
+ zassert_equal(1, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ pd_power_supply_reset(0);
+ zassert_equal(0, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ /* TODO: test C1 port after resolve the PPC emulator always accessing
+ * the same one with different index.
+ */
+}
diff --git a/zephyr/test/kingler/src/usb_port_count.c b/zephyr/test/kingler/src/usb_port_count.c
new file mode 100644
index 0000000000..4f55bdc693
--- /dev/null
+++ b/zephyr/test/kingler/src/usb_port_count.c
@@ -0,0 +1,90 @@
+/* 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 "driver/tcpm/tcpm.h"
+#include "ec_app_main.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+#define LOG_LEVEL 0
+LOG_MODULE_REGISTER(usb_port_count);
+
+FAKE_VALUE_FUNC(enum corsola_db_type, corsola_get_db_type);
+FAKE_VALUE_FUNC(bool, in_interrupt_context);
+FAKE_VOID_FUNC(bmi3xx_interrupt);
+FAKE_VOID_FUNC(hdmi_hpd_interrupt);
+FAKE_VOID_FUNC(ps185_hdmi_hpd_mux_set);
+FAKE_VALUE_FUNC(bool, ps8743_field_update, const struct usb_mux *, uint8_t,
+ uint8_t, uint8_t);
+FAKE_VOID_FUNC(pd_set_dual_role, int, enum pd_dual_role_states);
+FAKE_VALUE_FUNC(int, tc_is_attached_src, int);
+
+#define FFF_FAKES_LIST(FAKE) \
+ FAKE(corsola_get_db_type) \
+ FAKE(in_interrupt_context) \
+ FAKE(bmi3xx_interrupt) \
+ FAKE(hdmi_hpd_interrupt) \
+ FAKE(ps185_hdmi_hpd_mux_set) \
+ FAKE(ps8743_field_update) \
+ FAKE(pd_set_dual_role) \
+ FAKE(tc_is_attached_src)
+
+struct usb_port_count_fixture {
+ int place_holder;
+};
+
+static void *usb_port_count_setup(void)
+{
+ static struct usb_port_count_fixture f;
+
+ return &f;
+}
+
+static void usb_port_count_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ FFF_FAKES_LIST(RESET_FAKE);
+ FFF_RESET_HISTORY();
+}
+
+ZTEST_RULE(usb_port_count_reset_rule, usb_port_count_reset_rule_before, NULL);
+ZTEST_SUITE(usb_port_count, NULL, usb_port_count_setup, NULL, NULL, NULL);
+
+ZTEST_F(usb_port_count, test_detect_db)
+{
+ struct {
+ enum corsola_db_type test_type;
+ int expected_board_get_port_count;
+ int expected_board_get_adjusted_port_count;
+ } testdata[] = { { CORSOLA_DB_UNINIT, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_NO_DETECTION,
+ CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_NONE, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_TYPEC, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_HDMI, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 } };
+ for (int i = 0; i < ARRAY_SIZE(testdata); i++) {
+ corsola_get_db_type_fake.return_val = testdata[i].test_type;
+ zassert_equal(board_get_usb_pd_port_count(),
+ testdata[i].expected_board_get_port_count);
+ zassert_equal(
+ board_get_adjusted_usb_pd_port_count(),
+ testdata[i].expected_board_get_adjusted_port_count);
+ }
+}