diff options
Diffstat (limited to 'zephyr/test/drivers/common')
-rw-r--r-- | zephyr/test/drivers/common/include/test/drivers/stubs.h | 7 | ||||
-rw-r--r-- | zephyr/test/drivers/common/include/test/drivers/test_mocks.h | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/common/include/test/drivers/test_state.h | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/common/include/test/drivers/utils.h | 76 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/main.c | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/stubs.c | 88 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/test_mocks.c | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/test_rules.c | 4 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/utils.c | 36 |
9 files changed, 145 insertions, 89 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/stubs.h b/zephyr/test/drivers/common/include/test/drivers/stubs.h index 63718649f8..98f3fa1d15 100644 --- a/zephyr/test/drivers/common/include/test/drivers/stubs.h +++ b/zephyr/test/drivers/common/include/test/drivers/stubs.h @@ -6,12 +6,15 @@ #ifndef __TEST_DRIVERS_STUBS_H #define __TEST_DRIVERS_STUBS_H -#include "power.h" - #include <zephyr/fff.h> +#include "power.h" enum usbc_port { USBC_PORT_C0 = 0, USBC_PORT_C1, USBC_PORT_COUNT }; +/* Structure used by usb_mux test. It is part of usb_muxes chain. */ +extern struct usb_mux usbc1_virtual_usb_mux; +extern struct usb_mux usbc0_mux0; + /** * @brief Set product ID that should be returned by board_get_ps8xxx_product_id * diff --git a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h index 6644de8d88..25217dfffe 100644 --- a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h +++ b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h @@ -6,8 +6,6 @@ #ifndef __TEST_DRIVERS_TEST_MOCKS_H #define __TEST_DRIVERS_TEST_MOCKS_H -#include <stdint.h> - #include <zephyr/fff.h> /* @@ -118,8 +116,4 @@ DECLARE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int); /* Mocks for common/lid_angle.c */ DECLARE_FAKE_VOID_FUNC(lid_angle_peripheral_enable, int); -/* Mocks for gpio.h */ -DECLARE_FAKE_VALUE_FUNC(int, gpio_config_unused_pins); -DECLARE_FAKE_VALUE_FUNC(int, gpio_configure_port_pin, int, int, int); - #endif /* __TEST_DRIVERS_TEST_MOCKS_H */ diff --git a/zephyr/test/drivers/common/include/test/drivers/test_state.h b/zephyr/test/drivers/common/include/test/drivers/test_state.h index b4496c6af9..98cf4a283e 100644 --- a/zephyr/test/drivers/common/include/test/drivers/test_state.h +++ b/zephyr/test/drivers/common/include/test/drivers/test_state.h @@ -6,8 +6,6 @@ #ifndef ZEPHYR_TEST_DRIVERS_INCLUDE_TEST_STATE_H_ #define ZEPHYR_TEST_DRIVERS_INCLUDE_TEST_STATE_H_ -#include <stdbool.h> - #ifdef __cplusplus extern "C" { #endif diff --git a/zephyr/test/drivers/common/include/test/drivers/utils.h b/zephyr/test/drivers/common/include/test/drivers/utils.h index 7be7dd5400..8a703108c3 100644 --- a/zephyr/test/drivers/common/include/test/drivers/utils.h +++ b/zephyr/test/drivers/common/include/test/drivers/utils.h @@ -6,21 +6,20 @@ #ifndef ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ #define ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/ztest.h> +#include <stddef.h> +#include <string.h> + #include "charger.h" +#include "lpc.h" #include "emul/tcpc/emul_tcpci_partner_src.h" #include "extpower.h" #include "host_command.h" -#include "lpc.h" #include "power.h" #include "usbc/utils.h" -#include <stddef.h> -#include <string.h> - -#include <zephyr/drivers/emul.h> -#include <zephyr/drivers/gpio/gpio_emul.h> -#include <zephyr/ztest.h> - /** * @brief Helper macro for EMUL_GET_USBC_BINDING. If @p usbc_id has the same * port number as @p port, then struct emul* for @p chip phandle is @@ -72,11 +71,21 @@ void test_set_chipset_to_power_level(enum power_state new_state); /** @brief Set chipset to G3 state. Call all necessary hooks. */ void test_set_chipset_to_g3(void); +/* + * TODO(b/217755888): Implement ztest assume API upstream + */ + +/** + * @brief Assume that this function call won't be reached + * @param msg Optional message to print if the assumption fails + */ +#define zassume_unreachable(msg, ...) zassert_unreachable(msg, ##__VA_ARGS__) + /** * Run an ACPI read to the specified address. * * This function assumes a successful ACPI read process and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will skip the calling test. * * @param acpi_addr Address to query * @return Byte read @@ -87,7 +96,7 @@ uint8_t acpi_read(uint8_t acpi_addr); * Run an ACPI write to the specified address. * * This function assumes a successful ACPI write process and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will skip the calling test. * * @param acpi_addr Address to write * @param write_byte Byte to write to address @@ -98,7 +107,7 @@ void acpi_write(uint8_t acpi_addr, uint8_t write_byte); * Run the host command to gather our EC feature flags. * * This function assumes a successful host command processing and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will abort the calling test. * * @return The result of the host command */ @@ -108,7 +117,7 @@ static inline struct ec_response_get_features host_cmd_get_features(void) struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE(EC_CMD_GET_FEATURES, 0, response); - zassert_ok(host_command_process(&args), "Failed to get features"); + zassume_ok(host_command_process(&args), "Failed to get features"); return response; } @@ -116,7 +125,7 @@ static inline struct ec_response_get_features host_cmd_get_features(void) * Run the host command to get the charge state for a given charger number. * * This function assumes a successful host command processing and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will abort the calling test. * * @param chgnum The charger number to query. * @return The result of the query. @@ -131,7 +140,7 @@ static inline struct ec_response_charge_state host_cmd_charge_state(int chgnum) struct host_cmd_handler_args args = BUILD_HOST_COMMAND(EC_CMD_CHARGE_STATE, 0, response, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to get charge state for chgnum %d", chgnum); return response; } @@ -140,7 +149,7 @@ static inline struct ec_response_charge_state host_cmd_charge_state(int chgnum) * Run the host command to get the USB PD power info for a given port. * * This function assumes a successful host command processing and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will abort the calling test. * * @param port The USB port to get info from. * @return The result of the query. @@ -152,7 +161,7 @@ static inline struct ec_response_usb_pd_power_info host_cmd_power_info(int port) struct host_cmd_handler_args args = BUILD_HOST_COMMAND( EC_CMD_USB_PD_POWER_INFO, 0, response, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to get power info for port %d", port); return response; } @@ -161,7 +170,7 @@ static inline struct ec_response_usb_pd_power_info host_cmd_power_info(int port) * Run the host command to get the Type-C status information for a given port. * * This function assumes a successful host command processing and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will abort the calling test. * * @param port The USB port to get info from. * @return The result of the query. @@ -173,7 +182,7 @@ static inline struct ec_response_typec_status host_cmd_typec_status(int port) struct host_cmd_handler_args args = BUILD_HOST_COMMAND(EC_CMD_TYPEC_STATUS, 0, response, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to get Type-C state for port %d", port); return response; } @@ -186,7 +195,7 @@ host_cmd_usb_pd_control(int port, enum usb_pd_control_swap swap) struct host_cmd_handler_args args = BUILD_HOST_COMMAND(EC_CMD_USB_PD_CONTROL, 0, response, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to process usb_pd_control_swap for port %d, swap %d", port, swap); return response; @@ -196,7 +205,7 @@ host_cmd_usb_pd_control(int port, enum usb_pd_control_swap swap) * Run the host command to suspend/resume PD ports * * This function assumes a successful host command processing and will make a - * call to the zassert_* API. A failure here will fail the calling test. + * call to the zassume_* API. A failure here will skip the calling test. * * @param port The USB port to operate on * @param cmd The sub-command to run @@ -207,7 +216,7 @@ static inline void host_cmd_pd_control(int port, enum ec_pd_control_cmd cmd) struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(EC_CMD_PD_CONTROL, 0, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to process pd_control for port %d, cmd %d", port, cmd); } @@ -231,7 +240,7 @@ host_cmd_charge_control(enum ec_charge_control_mode mode, struct host_cmd_handler_args args = BUILD_HOST_COMMAND(EC_CMD_CHARGE_CONTROL, 2, response, params); - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to get charge control values"); return response; @@ -251,7 +260,7 @@ enum ec_status host_cmd_host_event(enum ec_host_event_action action, /** * @brief Call the host command MOTION_SENSE with the dump sub-command * - * Note: this function uses the zassert_ API. It will fail the test if the host + * Note: this function uses the zassume_ API. It will skip the test if the host * command fails. * * @param max_sensor_count The maximum number of sensor data objects to populate @@ -540,15 +549,6 @@ void host_cmd_typec_control_clear_events(int port, uint32_t events); */ void host_cmd_typec_control_bist_share_mode(int port, int enable); -/** - * Run the host command to control PD port behavior, with the sub-command of - * TYPEC_CONTROL_COMMAND_SEND_VDM_REQ - * - * @param port The USB-C port number - * @param vdm_req VDM request data - */ -void host_cmd_typec_control_vdm_req(int port, struct typec_vdm_req vdm_req); - struct host_events_ctx { host_event_t lpc_host_events; host_event_t lpc_host_event_mask[LPC_HOST_EVENT_COUNT]; @@ -580,7 +580,7 @@ void host_events_restore(struct host_events_ctx *host_events_ctx); * If enabled, the device _should_ begin charging. * * This function assumes a successful gpio emulator call and will make a call - * to the zassert_* API. A failure here will fail the calling test. + * to the zassume_* API. A failure here will abort the calling test. * * This function sleeps to wait for the GPIO interrupt to take place. * @@ -591,14 +591,10 @@ static inline void set_ac_enabled(bool enabled) const struct device *acok_dev = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_ACOK_OD_NODE, gpios)); - zassert_ok(gpio_emul_input_set(acok_dev, GPIO_ACOK_OD_PIN, enabled), + zassume_ok(gpio_emul_input_set(acok_dev, GPIO_ACOK_OD_PIN, enabled), NULL); - /* - * b/253284635 - Sleep for a full second past the debounce time - * to ensure the power button debounce logic runs. - */ - k_sleep(K_MSEC(CONFIG_EXTPOWER_DEBOUNCE_MS + 1000)); - zassert_equal(enabled, extpower_is_present(), NULL); + k_sleep(K_MSEC(CONFIG_EXTPOWER_DEBOUNCE_MS + 1)); + zassume_equal(enabled, extpower_is_present(), NULL); } /** diff --git a/zephyr/test/drivers/common/src/main.c b/zephyr/test/drivers/common/src/main.c index dab681b936..1c8497ab3f 100644 --- a/zephyr/test/drivers/common/src/main.c +++ b/zephyr/test/drivers/common/src/main.c @@ -3,13 +3,12 @@ * found in the LICENSE file. */ +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> #include "ec_app_main.h" #include "hooks.h" #include "test/drivers/test_state.h" -#include <zephyr/kernel.h> -#include <zephyr/ztest.h> - /** * @brief Semaphore that signals when hooks have completed */ diff --git a/zephyr/test/drivers/common/src/stubs.c b/zephyr/test/drivers/common/src/stubs.c index 69993d8a89..d07683017f 100644 --- a/zephyr/test/drivers/common/src/stubs.c +++ b/zephyr/test/drivers/common/src/stubs.c @@ -7,11 +7,11 @@ #include "battery_fuel_gauge.h" #include "bc12/pi3usb9201_public.h" #include "charge_ramp.h" -#include "charge_state_v2.h" #include "charger.h" #include "charger/isl923x_public.h" #include "charger/isl9241_public.h" #include "config.h" +#include <zephyr/fff.h> #include "gpio/gpio_int.h" #include "hooks.h" #include "i2c/i2c.h" @@ -19,14 +19,14 @@ #include "ppc/sn5s330_public.h" #include "ppc/syv682x_public.h" #include "retimer/bb_retimer_public.h" +#include "test/drivers/stubs.h" #include "tcpm/ps8xxx_public.h" #include "tcpm/tcpci.h" -#include "test/drivers/stubs.h" #include "usb_mux.h" #include "usb_pd_tcpm.h" #include "usbc_ppc.h" +#include "charge_state_v2.h" -#include <zephyr/fff.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(stubs); @@ -40,6 +40,19 @@ LOG_MODULE_REGISTER(stubs); * device tree. */ +/* BC1.2 charger detect configuration */ +const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { + [USBC_PORT_C0] = { + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + }, + [USBC_PORT_C1] = { + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_1_FLAGS, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT); + int board_set_active_charge_port(int port) { int is_real_port = (port >= 0 && port < CONFIG_USB_PD_PORT_MAX_COUNT); @@ -98,6 +111,13 @@ int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) return 0; } +void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, + int charge_mv) +{ + charge_set_input_current_limit( + MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); +} + BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT); static uint16_t ps8xxx_product_id = PS8805_PRODUCT_ID; @@ -128,6 +148,68 @@ int board_is_sourcing_vbus(int port) return ppc_is_sourcing_vbus(port); } +/* TODO(b/239457738): Move to dts */ +struct usb_mux_chain usbc0_virtual_usb_mux_chain = { + .mux = + &(const struct usb_mux){ + .usb_port = USBC_PORT_C0, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + }, +}; + +struct usb_mux usbc1_virtual_usb_mux = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, +}; + +struct usb_mux_chain usbc1_virtual_usb_mux_chain = { + .mux = &usbc1_virtual_usb_mux, +}; + +struct usb_mux usbc0_mux0 = { + .usb_port = USBC_PORT_C0, + .driver = &tcpci_tcpm_usb_mux_driver, + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL(tcpci_emul)), +}; + +struct usb_mux_chain usb_muxes[] = { + [USBC_PORT_C0] = { + .mux = &usbc0_mux0, + .next = &usbc0_virtual_usb_mux_chain, + }, + [USBC_PORT_C1] = { +#ifdef CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB + .mux = &(const struct usb_mux){ + .usb_port = USBC_PORT_C1, + .driver = &bb_usb_retimer, + .hpd_update = bb_retimer_hpd_update, + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL( + usb_c1_bb_retimer_emul)), + }, + .next = &usbc1_virtual_usb_mux_chain, +#endif + }, +}; +BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT); + +#ifdef CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB +struct bb_usb_control bb_controls[] = { + [USBC_PORT_C0] = { + /* USB-C port 0 doesn't have a retimer */ + }, + [USBC_PORT_C1] = { + .usb_ls_en_gpio = GPIO_SIGNAL(DT_NODELABEL(usb_c1_ls_en)), + .retimer_rst_gpio = + GPIO_SIGNAL(DT_NODELABEL(usb_c1_rt_rst_odl)), + }, +}; +BUILD_ASSERT(ARRAY_SIZE(bb_controls) == USBC_PORT_COUNT); +#endif + void pd_power_supply_reset(int port) { } diff --git a/zephyr/test/drivers/common/src/test_mocks.c b/zephyr/test/drivers/common/src/test_mocks.c index 21cd4c0c1b..ab6c65313d 100644 --- a/zephyr/test/drivers/common/src/test_mocks.c +++ b/zephyr/test/drivers/common/src/test_mocks.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include "test/drivers/test_mocks.h" - #include <zephyr/ztest.h> +#include "test/drivers/test_mocks.h" + /* Mocks for common/init_rom.c */ DEFINE_FAKE_VALUE_FUNC(const void *, init_rom_map, const void *, int); DEFINE_FAKE_VOID_FUNC(init_rom_unmap, const void *, int); @@ -22,10 +22,6 @@ DEFINE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int); /* Mocks for common/lid_angle.c */ DEFINE_FAKE_VOID_FUNC(lid_angle_peripheral_enable, int); -/* Mocks for gpio.h */ -DEFINE_FAKE_VALUE_FUNC(int, gpio_config_unused_pins); -DEFINE_FAKE_VALUE_FUNC(int, gpio_configure_port_pin, int, int, int); - /** * @brief Reset all the fakes before each test. */ @@ -44,8 +40,6 @@ static void fff_reset_rule_before(const struct ztest_unit_test *test, RESET_FAKE(software_panic); RESET_FAKE(assert_post_action); RESET_FAKE(lid_angle_peripheral_enable); - RESET_FAKE(gpio_config_unused_pins); - RESET_FAKE(gpio_configure_port_pin); } ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); diff --git a/zephyr/test/drivers/common/src/test_rules.c b/zephyr/test/drivers/common/src/test_rules.c index 42195b25d7..e1b1d59480 100644 --- a/zephyr/test/drivers/common/src/test_rules.c +++ b/zephyr/test/drivers/common/src/test_rules.c @@ -3,14 +3,14 @@ * found in the LICENSE file. */ +#include <zephyr/ztest.h> + #include "emul/tcpc/emul_tcpci.h" #include "motion_sense_fifo.h" #include "test/drivers/stubs.h" #include "test/drivers/utils.h" #include "usb_pd_tcpm.h" -#include <zephyr/ztest.h> - static void motion_sense_fifo_reset_before(const struct ztest_unit_test *test, void *data) { diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c index afea5edbac..719a3fe589 100644 --- a/zephyr/test/drivers/common/src/utils.c +++ b/zephyr/test/drivers/common/src/utils.c @@ -3,34 +3,38 @@ * found in the LICENSE file. */ +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_dummy.h> /* nocheck */ +#include <zephyr/shell/shell_uart.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> + #include "acpi.h" #include "battery.h" #include "battery_smart.h" #include "charge_state.h" #include "chipset.h" +#include "lpc.h" #include "emul/emul_isl923x.h" #include "emul/emul_smart_battery.h" #include "emul/emul_stub_device.h" #include "emul/tcpc/emul_tcpci_partner_src.h" #include "hooks.h" -#include "lpc.h" #include "power.h" #include "task.h" #include "tcpm/tcpci.h" #include "test/drivers/stubs.h" #include "test/drivers/utils.h" -#include <zephyr/drivers/gpio/gpio_emul.h> -#include <zephyr/kernel.h> -#include <zephyr/shell/shell.h> -#include <zephyr/shell/shell_dummy.h> -#include <zephyr/shell/shell_uart.h> -#include <zephyr/ztest.h> - #define BATTERY_NODE DT_NODELABEL(battery) #define GPIO_BATT_PRES_ODL_PATH DT_PATH(named_gpios, ec_batt_pres_odl) #define GPIO_BATT_PRES_ODL_PORT DT_GPIO_PIN(GPIO_BATT_PRES_ODL_PATH, gpios) +/* + * TODO(b/251281997): Switch zasserts back to zassumes when they loudly fail + */ + void test_set_battery_level(int percentage) { struct sbat_emul_bat_data *bat; @@ -588,21 +592,7 @@ void host_cmd_typec_control_bist_share_mode(int port, int enable) struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params); - zassert_ok(host_command_process(&args), - "Failed to send Type-C control for port %d", port); -} - -void host_cmd_typec_control_vdm_req(int port, struct typec_vdm_req vdm_req) -{ - struct ec_params_typec_control params = { - .port = port, - .command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, - .vdm_req_params = vdm_req, - }; - struct host_cmd_handler_args args = - BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params); - - zassert_ok(host_command_process(&args), + zassume_ok(host_command_process(&args), "Failed to send Type-C control for port %d", port); } |