diff options
author | Patryk Duda <pdk@semihalf.com> | 2022-06-07 14:53:26 +0200 |
---|---|---|
committer | Patryk Duda <patrykd@google.com> | 2022-06-07 15:56:12 +0200 |
commit | ad46fafb27c419bd416bfecc76df6c6426a99b32 (patch) | |
tree | c06f1438b73115db8af42bc05d3df2483c6abf29 /zephyr/test | |
parent | 727a419e2c62465d6afe7f1c78416f7f7517839f (diff) | |
parent | 38b9c4b824f34b3aa81f2399ce91b88077197d52 (diff) | |
download | chrome-ec-ad46fafb27c419bd416bfecc76df6c6426a99b32.tar.gz |
Merge remote-tracking branch cros/main into firmware-fpmcu-bloonchipper-release
Generated by: ./util/update_release_branch.py --board bloonchipper --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware-fpmcu-bloonchipper-release
Relevant changes:
git log --oneline 727a419e2c..38b9c4b824 -- board/hatch_fp
board/bloonchipper common/fpsensor docs/fingerprint driver/fingerprint
util/getversion.sh
42db333f60 docs/fingerprint: Add links to TPM design doc
9f63d3f400 docs/fingerprint: Fix typo
28c0e2d4e0 Docs: Replace Chrome OS with ChromeOS in FP docs
BRANCH=None
BUG=b:200828093
TEST=`make -j buildall`
TEST=`./test/run_device_tests.py --board bloonchipper`
Test "aes": PASSED
Test "cec": PASSED
Test "cortexm_fpu": PASSED
Test "crc": PASSED
Test "flash_physical": PASSED
Test "flash_write_protect": PASSED
Test "fpsensor_hw": PASSED
Test "fpsensor_spi_ro": PASSED
Test "fpsensor_spi_rw": PASSED
Test "fpsensor_uart_ro": PASSED
Test "fpsensor_uart_rw": PASSED
Test "mpu_ro": PASSED
Test "mpu_rw": PASSED
Test "mutex": PASSED
Test "pingpong": PASSED
Test "printf": PASSED
Test "queue": PASSED
Test "rollback_region0": PASSED
Test "rollback_region1": PASSED
Test "rollback_entropy": PASSED
Test "rtc": PASSED
Test "sha256": PASSED
Test "sha256_unrolled": PASSED
Test "static_if": PASSED
Test "system_is_locked_wp_on": PASSED
Test "system_is_locked_wp_off": PASSED
Test "timer_dos": PASSED
Test "utils": PASSED
Test "utils_str": PASSED
Test "stm32f_rtc": PASSED
Test "panic_data_bloonchipper_v2.0.4277": PASSED
Test "panic_data_bloonchipper_v2.0.5938": PASSED
Cq-Include-Trybots: chromeos/cq:cq-orchestrator
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Change-Id: If68b4647a40d7a8aec30411edf29e67747497db8
Diffstat (limited to 'zephyr/test')
70 files changed, 3245 insertions, 308 deletions
diff --git a/zephyr/test/ap_power/src/board.c b/zephyr/test/ap_power/src/board.c index 73bf0f9e49..96b30d21d3 100644 --- a/zephyr/test/ap_power/src/board.c +++ b/zephyr/test/ap_power/src/board.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include <ap_power_override_functions.h> @@ -78,6 +78,11 @@ void board_ap_power_action_s0(void) { } +bool board_ap_power_check_power_rails_enabled(void) +{ + return false; +} + int extpower_is_present(void) { return 0; diff --git a/zephyr/test/ap_power/src/events.c b/zephyr/test/ap_power/src/events.c index 1b4eb84bca..de695e945f 100644 --- a/zephyr/test/ap_power/src/events.c +++ b/zephyr/test/ap_power/src/events.c @@ -8,10 +8,10 @@ * @brief Unit Tests for AP power events */ -#include <device.h> +#include <zephyr/device.h> -#include <logging/log.h> -#include <zephyr.h> +#include <zephyr/logging/log.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ap_power/ap_power.h" diff --git a/zephyr/test/ap_power/src/main.c b/zephyr/test/ap_power/src/main.c index 0fa88536f6..761fcfd997 100644 --- a/zephyr/test/ap_power/src/main.c +++ b/zephyr/test/ap_power/src/main.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ec_app_main.h" #include "test_state.h" diff --git a/zephyr/test/ap_power/src/signals.c b/zephyr/test/ap_power/src/signals.c index debd459807..c2ccffb8c9 100644 --- a/zephyr/test/ap_power/src/signals.c +++ b/zephyr/test/ap_power/src/signals.c @@ -8,13 +8,13 @@ * @brief Unit Tests for power signals API */ -#include <device.h> +#include <zephyr/device.h> -#include <drivers/espi.h> -#include <drivers/espi_emul.h> -#include <drivers/gpio/gpio_emul.h> -#include <logging/log.h> -#include <zephyr.h> +#include <zephyr/drivers/espi.h> +#include <zephyr/drivers/espi_emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/logging/log.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "power_signals.h" diff --git a/zephyr/test/crc/main.c b/zephyr/test/crc/main.c index 34fec7199a..50f7be79a0 100644 --- a/zephyr/test/crc/main.c +++ b/zephyr/test/crc/main.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <kernel.h> +#include <zephyr/kernel.h> #include <ztest.h> #include "crc8.h" diff --git a/zephyr/test/drivers/BUILD.py b/zephyr/test/drivers/BUILD.py index 04449e2f8e..9e3465c18e 100644 --- a/zephyr/test/drivers/BUILD.py +++ b/zephyr/test/drivers/BUILD.py @@ -4,4 +4,8 @@ """Register zmake project for drivers test.""" -register_host_test("drivers", dts_overlays=["overlay.dts"]) +register_host_test( + "drivers", + dts_overlays=["overlay.dts"], + test_args=["-flash={test_temp_dir}/flash.bin"], +) diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 93dfe7c043..b4c85defa2 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -19,11 +19,17 @@ target_sources(app PRIVATE src/bmi160.c src/bmi260.c src/charge_manager.c + src/chargesplash.c src/console_cmd/charge_manager.c src/console_cmd/charge_state.c + src/console_cmd/accelinit.c src/console_cmd/accelinfo.c src/console_cmd/accelspoof.c + src/console_cmd/accelrate.c src/console_cmd/accelrange.c + src/console_cmd/accelread.c + src/console_cmd/accelres.c + src/console_cmd/usb_pd_console.c src/cros_cbi.c src/espi.c src/gpio.c @@ -35,6 +41,7 @@ target_sources(app PRIVATE src/integration/usbc/usb_alt_mode.c src/integration/usbc/usb_attach_src_snk.c src/integration/usbc/usb_pd_ctrl_msg.c + src/integration/usbc/usb_malfunction_sink.c src/i2c_passthru.c src/isl923x.c src/keyboard_scan.c @@ -58,6 +65,7 @@ target_sources(app PRIVATE src/test_mocks.c src/test_rules.c src/thermistor.c + src/uart_hostcmd.c src/usb_mux.c src/usb_pd_host_cmd.c src/utils.c @@ -66,3 +74,5 @@ target_sources(app PRIVATE ) add_subdirectory(isl923x) + +set_compiler_property(APPEND PROPERTY coverage -O0) diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index 37daebf8b3..17ea860dfd 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -6,8 +6,8 @@ #ifndef ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ #define ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ -#include <drivers/emul.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <string.h> #include "charger.h" @@ -277,6 +277,149 @@ int host_cmd_motion_sense_ec_rate(uint8_t sensor_num, int data_rate_ms, struct ec_response_motion_sense *response); /** + * @brief Call the host command MOTION_SENSE with the odr sub-command + * + * This function performs a read of the current odr by passing + * EC_MOTION_SENSE_NO_VALUE as the data rate. Otherwise, the data rate should be + * updated. + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param odr The new ODR to set + * @param round_up Whether or not to round up the ODR + * @param response Pointer to the response data structure to fill on success + * @return The result code form the host command + */ +int host_cmd_motion_sense_odr(uint8_t sensor_num, int32_t odr, bool round_up, + struct ec_response_motion_sense *response); + +/** + * @brief Call the host command MOTION_SENSE with the sensor range sub-command + * + * This function attempts to set the sensor range and returns the range value. + * If the range value is EC_MOTION_SENSE_NO_VALUE, then the host command will + * not attempt to update the range. + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param range The new range to set + * @param round_up Whether or not to round up the range. + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_range(uint8_t sensor_num, int32_t range, + bool round_up, + struct ec_response_motion_sense *response); + +/** + * @brief Call the host command MOTION_SENSE with the sensor offset sub-command + * + * This function attempts to set the offset if the flags field includes + * MOTION_SENSE_SET_OFFSET. Otherwise, the temperature and offsets are ignored. + * The response field will include the current (after modification) offsets and + * temperature. + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param flags The flags to pass to the host command + * @param temperature The temperature at which the offsets were attained (set) + * @param offset_x The X offset to set + * @param offset_y The Y offset to set + * @param offset_z The Z offset to set + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_offset(uint8_t sensor_num, uint16_t flags, + int16_t temperature, int16_t offset_x, + int16_t offset_y, int16_t offset_z, + struct ec_response_motion_sense *response); + +/** + * @brief Call the host command MOTION_SENSE with the sensor scale sub-command + * + * This function attempts to set the scale if the flags field includes + * MOTION_SENSE_SET_OFFSET. Otherwise, the temperature and scales are ignored. + * The response field will include the current (after modification) scales and + * temperature. + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param flags The flags to pass to the host command + * @param temperature The temperature at which the scales were attained (set) + * @param scale_x The X scale to set + * @param scale_y The Y scale to set + * @param scale_z The Z scale to set + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_scale(uint8_t sensor_num, uint16_t flags, + int16_t temperature, int16_t scale_x, + int16_t scale_y, int16_t scale_z, + struct ec_response_motion_sense *response); + +/** + * @brief Enable/disable sensor calibration via host command + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param enable Whether to enable or disable the calibration + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_calib(uint8_t sensor_num, bool enable, + struct ec_response_motion_sense *response); + +/** + * @brief Set the sensor's fifo flush bit + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_fifo_flush(uint8_t sensor_num, + struct ec_response_motion_sense *response); + +/** + * @brief Get the current fifo info + * + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_fifo_info(struct ec_response_motion_sense *response); + +/** + * @brief Get the current fifo data + * + * @param buffer_length The number of entries available on the response pointer + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_fifo_read(uint8_t buffer_length, + struct ec_response_motion_sense *response); + +/** + * @brief Call the int_enable motionsense host command + * + * @param enable 0 for disable, 1 for enable. All others are invalid + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_int_enable(int8_t enable, + struct ec_response_motion_sense *response); + +/** + * @brief Call the spoof motion_sense subcommand + * + * @param sensor_num The sensor index in motion_sensors + * @param enable The enable field, for normal operations this will be one of + * enum motionsense_spoof_mode + * @param values0 The X value to set if using custom mode + * @param values1 The Y value to set if using custom mode + * @param values2 The Z value to set if using custom mode + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, + int16_t values0, int16_t values1, + int16_t values2, + struct ec_response_motion_sense *response); + +/** * Run the host command to get the PD discovery responses. * * @param port The USB-C port number @@ -320,12 +463,14 @@ static inline void set_ac_enabled(bool enabled) * * Note: this is function currently only supports an ISL923X charger chip. * - * @param src Pointer to the emulated source + * @param partner Pointer to the emulated TCPCI partner device + * @param src Pointer to the emulated source extension * @param pdo_index The index of the PDO object within the src to use * @param tcpci_emul The TCPCI emulator that the source will connect to * @param charger_emul The charger chip emulator */ -void connect_source_to_port(struct tcpci_src_emul *src, int pdo_index, +void connect_source_to_port(struct tcpci_partner_data *partner, + struct tcpci_src_emul_data *src, int pdo_index, const struct emul *tcpci_emul, const struct emul *charger_emul); diff --git a/zephyr/test/drivers/isl923x/src/console_cmd_amon_bmon.c b/zephyr/test/drivers/isl923x/src/console_cmd_amon_bmon.c index b70d67a750..bdbdd083ba 100644 --- a/zephyr/test/drivers/isl923x/src/console_cmd_amon_bmon.c +++ b/zephyr/test/drivers/isl923x/src/console_cmd_amon_bmon.c @@ -3,9 +3,9 @@ * found in the LICENSE file. */ -#include <drivers/adc.h> -#include <drivers/adc/adc_emul.h> -#include <shell/shell.h> +#include <zephyr/drivers/adc.h> +#include <zephyr/drivers/adc/adc_emul.h> +#include <zephyr/shell/shell.h> #include <ztest.h> #include "adc.h" diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index 3a9fb4c0b1..df0888175f 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -19,7 +19,6 @@ aliases { bmi260-int = &ms_bmi260_accel; bmi160-int = &ms_bmi160_accel; - lis2dw12-int = &ms_lis2dw12_accel; tcs3400-int = &tcs3400_clear; gpio-wp = &gpio_wp_l; gpio-kbd-kso2 = &gpio_ec_kso_02_inv; @@ -32,6 +31,12 @@ port0@0 { compatible = "named-usbc-port"; reg = <0>; + + chg { + compatible = "intersil,isl923x"; + status = "okay"; + port = <&i2c_charger>; + }; }; port1@1 { @@ -232,7 +237,7 @@ i2c-port = <&i2c0>; enum-name = "I2C_PORT_POWER"; }; - charger { + i2c_charger: charger { i2c-port = <&i2c0>; enum-name = "I2C_PORT_CHARGER"; }; @@ -666,7 +671,7 @@ motionsense-sensor-info { compatible = "cros-ec,motionsense-sensor-info"; - accel-force-mode-sensors = <&ms_bma255>; + accel-force-mode-sensors = <&ms_bma255 &ms_lis2dw12_accel>; }; /* diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index 5bf8650505..aadf8e44eb 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -61,8 +61,10 @@ CONFIG_EMUL_TCS3400=y CONFIG_EMUL_BB_RETIMER=y CONFIG_EMUL_PS8XXX=y CONFIG_EMUL_TCPCI_PARTNER_DRP=y +CONFIG_EMUL_TCPCI_PARTNER_FAULTY_SNK=y CONFIG_PLATFORM_EC_CHARGE_MANAGER=y CONFIG_PLATFORM_EC_CHARGE_RAMP_SW=y +CONFIG_PLATFORM_EC_CHARGESPLASH=y CONFIG_PLATFORM_EC_POWERSEQ=y @@ -104,7 +106,6 @@ CONFIG_PLATFORM_EC_MOTIONSENSE=y CONFIG_PLATFORM_EC_ACCELGYRO_BMI160=y CONFIG_PLATFORM_EC_ACCELGYRO_BMI260=y CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y -CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS=y CONFIG_PLATFORM_EC_ACCEL_FIFO=y CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=y CONFIG_PLATFORM_EC_ALS_TCS3400=y diff --git a/zephyr/test/drivers/src/battery.c b/zephyr/test/drivers/src/battery.c index 71d45ac6af..e454262aa2 100644 --- a/zephyr/test/drivers/src/battery.c +++ b/zephyr/test/drivers/src/battery.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "battery.h" #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/src/bb_retimer.c b/zephyr/test/drivers/src/bb_retimer.c index 26a89860ff..dbe4d3143f 100644 --- a/zephyr/test/drivers/src/bb_retimer.c +++ b/zephyr/test/drivers/src/bb_retimer.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "common.h" #include "ec_tasks.h" diff --git a/zephyr/test/drivers/src/bc12.c b/zephyr/test/drivers/src/bc12.c index df65d2f7a4..d1a96131c1 100644 --- a/zephyr/test/drivers/src/bc12.c +++ b/zephyr/test/drivers/src/bc12.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "emul/emul_pi3usb9201.h" @@ -17,7 +17,7 @@ #include "test/drivers/stubs.h" #include "test/drivers/test_state.h" -#include <logging/log.h> +#include <zephyr/logging/log.h> LOG_MODULE_REGISTER(test_drivers_bc12, LOG_LEVEL_DBG); #define EMUL_LABEL DT_NODELABEL(pi3usb9201_emul) @@ -105,7 +105,7 @@ static void test_bc12_pi3usb9201_host_mode(void) * Pretend that the USB-C Port Manager (TCPMv2) has set the port data * role to DFP. */ - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_DR_DFP); + usb_charger_task_set_event(0, USB_CHG_EVENT_DR_DFP); msleep(1); /* * Expect the pi3usb9201 driver to configure CDP host mode and unmask @@ -119,7 +119,7 @@ static void test_bc12_pi3usb9201_host_mode(void) msleep(500); pi3usb9201_emul_set_reg(emul, PI3USB9201_REG_HOST_STS, PI3USB9201_REG_HOST_STS_DEV_PLUG); - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12); + usb_charger_task_set_event(0, USB_CHG_EVENT_BC12); msleep(1); /* Expect the pi3usb9201 driver to configure SDP host mode. */ pi3usb9201_emul_get_reg(emul, PI3USB9201_REG_CTRL_1, &a); @@ -131,7 +131,7 @@ static void test_bc12_pi3usb9201_host_mode(void) msleep(500); pi3usb9201_emul_set_reg(emul, PI3USB9201_REG_HOST_STS, PI3USB9201_REG_HOST_STS_DEV_UNPLUG); - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12); + usb_charger_task_set_event(0, USB_CHG_EVENT_BC12); msleep(1); /* Expect the pi3usb9201 driver to configure CDP host mode. */ pi3usb9201_emul_get_reg(emul, PI3USB9201_REG_CTRL_1, &a); @@ -153,7 +153,7 @@ static void test_bc12_pi3usb9201_client_mode( * role to UFP and decided charging from the port is allowed. */ msleep(500); - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_DR_UFP); + usb_charger_task_set_event(0, USB_CHG_EVENT_DR_UFP); charge_manager_update_dualrole(USBC_PORT_C0, CAP_DEDICATED); msleep(1); /* @@ -171,7 +171,7 @@ static void test_bc12_pi3usb9201_client_mode( msleep(500); pi3usb9201_emul_set_reg(emul, PI3USB9201_REG_CLIENT_STS, 1 << detect_result); - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12); + usb_charger_task_set_event(0, USB_CHG_EVENT_BC12); msleep(1); /* Expect the pi3usb9201 driver to clear the start bit. */ pi3usb9201_emul_get_reg(emul, PI3USB9201_REG_CTRL_2, &a); @@ -202,7 +202,7 @@ static void test_bc12_pi3usb9201_client_mode( * role to disconnected. */ msleep(500); - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_CC_OPEN); + usb_charger_task_set_event(0, USB_CHG_EVENT_CC_OPEN); msleep(1); /* * Expect the pi3usb9201 driver to configure power down mode and mask @@ -254,8 +254,8 @@ ZTEST_USER(bc12, test_bc12_pi3usb9201) * Pretend that the USB-C Port Manager (TCPMv2) has set the port data * role to disconnected. */ - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_CC_OPEN); - task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_CC_OPEN); + usb_charger_task_set_event(0, USB_CHG_EVENT_CC_OPEN); + usb_charger_task_set_event(1, USB_CHG_EVENT_CC_OPEN); msleep(1); /* * Expect the pi3usb9201 driver to configure power down mode and mask diff --git a/zephyr/test/drivers/src/bma2x2.c b/zephyr/test/drivers/src/bma2x2.c index 4277ed1245..1995adc571 100644 --- a/zephyr/test/drivers/src/bma2x2.c +++ b/zephyr/test/drivers/src/bma2x2.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/bmi160.c b/zephyr/test/drivers/src/bmi160.c index 5578b4a796..56e38e6f9a 100644 --- a/zephyr/test/drivers/src/bmi160.c +++ b/zephyr/test/drivers/src/bmi160.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/bmi260.c b/zephyr/test/drivers/src/bmi260.c index 0146b37fe6..abcab72898 100644 --- a/zephyr/test/drivers/src/bmi260.c +++ b/zephyr/test/drivers/src/bmi260.c @@ -4,7 +4,7 @@ */ #include <fff.h> -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/chargesplash.c b/zephyr/test/drivers/src/chargesplash.c new file mode 100644 index 0000000000..3eec11bbe4 --- /dev/null +++ b/zephyr/test/drivers/src/chargesplash.c @@ -0,0 +1,326 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/kernel.h> +#include <stdbool.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_uart.h> +#include <zephyr/sys/__assert.h> +#include <ztest.h> + +#include "chipset.h" +#include "config.h" +#include "ec_commands.h" +#include "extpower.h" +#include "hooks.h" +#include "host_command.h" +#include "lid_switch.h" +#include "timer.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +/* Do a chargesplash host cmd */ +static enum ec_status +chargesplash_hostcmd(enum ec_chargesplash_cmd cmd, + struct ec_response_chargesplash *response) +{ + struct ec_params_chargesplash params = { .cmd = cmd }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_CHARGESPLASH, 0, *response, params); + + return host_command_process(&args); +} + +static bool is_chargesplash_requested(void) +{ + struct ec_response_chargesplash response; + + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_GET_STATE, &response), + NULL); + + return response.requested; +} + +static struct k_poll_signal shutdown_complete_signal = + K_POLL_SIGNAL_INITIALIZER(shutdown_complete_signal); +static struct k_poll_event shutdown_complete_event = K_POLL_EVENT_INITIALIZER( + K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &shutdown_complete_signal); + +static void handle_chipset_shutdown_complete_event(void) +{ + k_poll_signal_raise(&shutdown_complete_signal, 0); +} +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN_COMPLETE, + handle_chipset_shutdown_complete_event, HOOK_PRIO_LAST); + +static void force_chipset_off(void) +{ + if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) { + k_poll_signal_reset(&shutdown_complete_signal); + chipset_force_shutdown(CHIPSET_RESET_INIT); + k_poll(&shutdown_complete_event, 1, K_MSEC(1000)); + } + + /* + * Signal will trigger during S3->S5, but we want to wait until we're + * actually at S5. Give it a quick sleep if required. + */ + while (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) { + msleep(5); + } +} + +static struct k_poll_signal s0_signal = K_POLL_SIGNAL_INITIALIZER(s0_signal); +static struct k_poll_event s0_event = K_POLL_EVENT_INITIALIZER( + K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &s0_signal); + +static void handle_chipset_s0_event(void) +{ + k_poll_signal_raise(&s0_signal, 0); +} +DECLARE_HOOK(HOOK_CHIPSET_RESUME, handle_chipset_s0_event, HOOK_PRIO_LAST); + +static void wait_for_chipset_startup(void) +{ + if (!chipset_in_state(CHIPSET_STATE_ON)) { + k_poll_signal_reset(&s0_signal); + k_poll(&s0_event, 1, K_FOREVER); + } + + /* + * TODO(b/230362548): We need to give the EC a bit to "calm down" + * after reaching S0. + */ + msleep(2000); +} + +#define GPIO_LID_OPEN_EC_NODE DT_NODELABEL(gpio_lid_open_ec) +#define GPIO_LID_OPEN_EC_CTLR DT_GPIO_CTLR(GPIO_LID_OPEN_EC_NODE, gpios) +#define GPIO_LID_OPEN_EC_PORT DT_GPIO_PIN(GPIO_LID_OPEN_EC_NODE, gpios) + +static void set_lid(bool open, bool inhibit_boot) +{ + const struct device *lid_switch_dev = + DEVICE_DT_GET(GPIO_LID_OPEN_EC_CTLR); + + __ASSERT(lid_is_open() != open, + "Lid change was requested, but it's already in that state"); + + if (!open) { + __ASSERT(!inhibit_boot, + "inhibit_boot should not be used with a lid close"); + } + + zassume_ok(gpio_emul_input_set(lid_switch_dev, GPIO_LID_OPEN_EC_PORT, + open), + "Failed to set lid switch GPIO"); + + while (lid_is_open() != open) { + usleep(LID_DEBOUNCE_US + 1); + } + + if (inhibit_boot) { + wait_for_chipset_startup(); + force_chipset_off(); + } +} + +/* Simulate a regular power button press */ +static void pulse_power_button(void) +{ + zassert_ok(shell_execute_cmd(get_ec_shell(), "powerbtn"), NULL); +} + +static void reset_state(void *unused) +{ + force_chipset_off(); + + if (lid_is_open()) { + set_lid(false, false); + } + + if (extpower_is_present()) { + set_ac_enabled(false); + } + + zassume_ok(shell_execute_cmd(get_ec_shell(), "chargesplash reset"), + "'chargesplash reset' shell command failed"); +} + +ZTEST_SUITE(chargesplash, drivers_predicate_post_main, NULL, reset_state, NULL, + reset_state); + +/* + * When the lid is open and AC is connected, the chargesplash should + * be requested. + */ +ZTEST_USER(chargesplash, test_connect_ac) +{ + set_lid(true, true); + + set_ac_enabled(true); + zassert_true(is_chargesplash_requested(), + "chargesplash should be requested"); + wait_for_chipset_startup(); +} + +/* + * When AC is not connected and we open the lid, the chargesplash + * should not be requested. + */ +ZTEST_USER(chargesplash, test_no_connect_ac) +{ + set_lid(true, false); + zassert_false(is_chargesplash_requested(), + "chargesplash should not be requested"); + wait_for_chipset_startup(); +} + +/* + * When we connect AC with the lid closed, the chargesplash should not + * be requested. + */ +ZTEST_USER(chargesplash, test_ac_connect_when_lid_closed) +{ + set_ac_enabled(true); + zassert_false(is_chargesplash_requested(), + "chargesplash should not be requested"); +} + +/* + * Test that, after many repeated requests, the chargesplash + * feature becomes locked and non-functional. This condition + * replicates a damaged charger or port which cannot maintain a + * reliable connection. + * + * Then, ensure the lockout clears after the chargesplash period + * passes. + */ +ZTEST_USER(chargesplash, test_lockout) +{ + int i; + + set_lid(true, true); + + for (i = 0; i < CONFIG_CHARGESPLASH_MAX_REQUESTS_PER_PERIOD; i++) { + set_ac_enabled(true); + + zassert_true(is_chargesplash_requested(), + "chargesplash should be requested"); + wait_for_chipset_startup(); + + set_ac_enabled(false); + force_chipset_off(); + } + + set_ac_enabled(true); + zassert_false(is_chargesplash_requested(), + "chargesplash should be locked out"); + set_ac_enabled(false); + + sleep(CONFIG_CHARGESPLASH_PERIOD); + + set_ac_enabled(true); + zassert_true(is_chargesplash_requested(), + "lockout should have cleared"); + wait_for_chipset_startup(); +} + +/* Test cancel chargesplash request by power button push */ +ZTEST_USER(chargesplash, test_power_button) +{ + set_lid(true, true); + + set_ac_enabled(true); + zassert_true(is_chargesplash_requested(), + "chargesplash should be requested"); + wait_for_chipset_startup(); + zassert_true(is_chargesplash_requested(), + "chargesplash should still be requested"); + + pulse_power_button(); + zassert_false(is_chargesplash_requested(), + "chargesplash should be canceled by power button push"); + zassert_true(chipset_in_state(CHIPSET_STATE_ON), + "chipset should be on"); +} + +/* Manually lockout the feature via the shell */ +ZTEST_USER(chargesplash, test_manual_lockout_via_console) +{ + /* + * Put an entry in the request log so the lockout has + * something to wait on to clear. + */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "chargesplash request"), + NULL); + zassert_true(is_chargesplash_requested(), + "chargesplash should be requested"); + wait_for_chipset_startup(); + force_chipset_off(); + + zassert_ok(shell_execute_cmd(get_ec_shell(), "chargesplash lockout"), + NULL); + zassert_ok(shell_execute_cmd(get_ec_shell(), "chargesplash request"), + NULL); + zassert_false(is_chargesplash_requested(), + "chargesplash should be not requested due to lockout"); + + sleep(CONFIG_CHARGESPLASH_PERIOD); + + zassert_ok(shell_execute_cmd(get_ec_shell(), "chargesplash request"), + NULL); + zassert_true(is_chargesplash_requested(), + "lockout should have cleared"); + wait_for_chipset_startup(); +} + +/* Manually lockout the feature via host command */ +ZTEST_USER(chargesplash, test_manual_lockout_via_hostcmd) +{ + struct ec_response_chargesplash response; + + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_REQUEST, &response), + NULL); + zassert_true(is_chargesplash_requested(), + "chargesplash should be requested"); + wait_for_chipset_startup(); + force_chipset_off(); + + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_LOCKOUT, &response), + NULL); + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_REQUEST, &response), + NULL); + zassert_false(is_chargesplash_requested(), + "chargesplash should be not requested due to lockout"); + + sleep(CONFIG_CHARGESPLASH_PERIOD); + + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_REQUEST, &response), + NULL); + zassert_true(is_chargesplash_requested(), + "lockout should have cleared"); + wait_for_chipset_startup(); +} + +/* Simulate an actual run of the display loop */ +ZTEST_USER(chargesplash, test_display_loop) +{ + struct ec_response_chargesplash response; + + set_lid(true, true); + set_ac_enabled(true); + zassert_true(is_chargesplash_requested(), NULL); + wait_for_chipset_startup(); + + zassert_ok(chargesplash_hostcmd(EC_CHARGESPLASH_DISPLAY_READY, + &response), + NULL); + + zassert_true(is_chargesplash_requested(), NULL); + pulse_power_button(); + zassert_false(is_chargesplash_requested(), NULL); +} diff --git a/zephyr/test/drivers/src/console_cmd/accelinfo.c b/zephyr/test/drivers/src/console_cmd/accelinfo.c index 5df520f300..e60d00b596 100644 --- a/zephyr/test/drivers/src/console_cmd/accelinfo.c +++ b/zephyr/test/drivers/src/console_cmd/accelinfo.c @@ -3,12 +3,14 @@ * found in the LICENSE file. */ -#include <shell/shell.h> +#include <zephyr/shell/shell.h> #include <ztest.h> +#include "config.h" #include "console.h" #include "ec_commands.h" #include "test/drivers/test_state.h" +#include "timer.h" static void console_cmd_accelinfo_after(void *fixture) { @@ -47,5 +49,7 @@ ZTEST_USER(console_cmd_accelinfo, test_enable_disable) * just assert that the command executed and returned 0. */ zassert_ok(shell_execute_cmd(get_ec_shell(), "accelinfo on"), NULL); + k_msleep(CONFIG_MOTION_MIN_SENSE_WAIT_TIME * MSEC * 2); + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelinfo off"), NULL); } diff --git a/zephyr/test/drivers/src/console_cmd/accelinit.c b/zephyr/test/drivers/src/console_cmd/accelinit.c new file mode 100644 index 0000000000..24538ef648 --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/accelinit.c @@ -0,0 +1,93 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <fff.h> +#include <zephyr/shell/shell.h> +#include <ztest.h> + +#include "accelgyro.h" +#include "console.h" +#include "motion_sense.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +FAKE_VALUE_FUNC(int, mock_init, struct motion_sensor_t *); + +struct console_cmd_accelinit_fixture { + const struct accelgyro_drv *sensor_0_drv; + struct accelgyro_drv mock_drv; +}; + +static void *console_cmd_accelinit_setup(void) +{ + static struct console_cmd_accelinit_fixture fixture = { + .mock_drv = { + .init = mock_init, + }, + }; + fixture.sensor_0_drv = motion_sensors[0].drv; + + return &fixture; +} + +static void console_cmd_accelinit_before(void *fixture) +{ + ARG_UNUSED(fixture); + RESET_FAKE(mock_init); + FFF_RESET_HISTORY(); +} +static void console_cmd_accelinit_after(void *fixture) +{ + struct console_cmd_accelinit_fixture *this = fixture; + + motion_sensors[0].drv = this->sensor_0_drv; + motion_sensors[0].drv->init(&motion_sensors[0]); +} + +ZTEST_SUITE(console_cmd_accelinit, drivers_predicate_post_main, + console_cmd_accelinit_setup, console_cmd_accelinit_before, + console_cmd_accelinit_after, NULL); + +ZTEST_USER(console_cmd_accelinit, test_invalid_sensor_num) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "accelinit f"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelinit -1"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelinit 100"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); +} + +ZTEST_USER(console_cmd_accelinit, test_state_was_set) +{ + motion_sensors[0].state = SENSOR_INIT_ERROR; + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelinit 0"), NULL); + zassert_equal(SENSOR_INITIALIZED, motion_sensors[0].state, + "Expected %d, but got %d", SENSOR_INITIALIZED, + motion_sensors[0].state); +} + +ZTEST_USER_F(console_cmd_accelinit, test_fail_3_times) +{ + mock_init_fake.return_val = 1; + motion_sensors[0].drv = &this->mock_drv; + motion_sensors[0].state = SENSOR_INITIALIZED; + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelinit 0"), NULL); + zassert_equal(3, mock_init_fake.call_count, + "Expected 3 calls, but got %d", + mock_init_fake.call_count); + zassert_equal(SENSOR_INIT_ERROR, motion_sensors[0].state, + "Expected %d, but got %d", SENSOR_INIT_ERROR, + motion_sensors[0].state); +} diff --git a/zephyr/test/drivers/src/console_cmd/accelrange.c b/zephyr/test/drivers/src/console_cmd/accelrange.c index 34c70db9e0..b78702e486 100644 --- a/zephyr/test/drivers/src/console_cmd/accelrange.c +++ b/zephyr/test/drivers/src/console_cmd/accelrange.c @@ -3,8 +3,8 @@ * found in the LICENSE file. */ -#include <shell/shell.h> -#include <devicetree.h> +#include <zephyr/shell/shell.h> +#include <zephyr/devicetree.h> #include <ztest.h> #include "console.h" diff --git a/zephyr/test/drivers/src/console_cmd/accelrate.c b/zephyr/test/drivers/src/console_cmd/accelrate.c new file mode 100644 index 0000000000..6ae4b96343 --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/accelrate.c @@ -0,0 +1,104 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/shell/shell.h> +#include <ztest.h> + +#include "console.h" +#include "ec_commands.h" +#include "motion_sense.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +static int original_sensor_0_s0_config_odr; + +static void *console_cmd_accelrate_setup(void) +{ + original_sensor_0_s0_config_odr = + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr; + return NULL; +} + +static void console_cmd_accelrate_after(void *state) +{ + ARG_UNUSED(state); + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr = + original_sensor_0_s0_config_odr; +} + +ZTEST_SUITE(console_cmd_accelrate, drivers_predicate_post_main, + console_cmd_accelrate_setup, NULL, console_cmd_accelrate_after, + NULL); + +ZTEST_USER(console_cmd_accelrate, test_bad_arg_count) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "accelrate"); + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelrate 1 2 3 4"); + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_accelrate, test_invalid_sensor_num) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "accelrate f"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelrate -1"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelrate 100"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); +} + +ZTEST_USER(console_cmd_accelrate, test_print_rate) +{ + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelrate 0"), NULL); +} + +ZTEST_USER(console_cmd_accelrate, test_bad_rate_value) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelrate 0 f"); + + zassert_equal(EC_ERROR_PARAM2, rv, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_accelrate, test_set_ap_rate) +{ + test_set_chipset_to_s0(); + + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr = 0; + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelrate 0 100"), NULL); + zassert_equal(100 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr, + "Expected %d, but got %d", 100 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr); + + /* Try explicit round up value: 1 */ + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr = 0; + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelrate 0 100 1"), + NULL); + zassert_equal(100 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr, + "Expected %d, but got %d", 100 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr); + + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr = 0; + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelrate 0 100 0"), + NULL); + zassert_equal(100, motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr, + "Expected %d, but got %d", 100 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_EC_S0].odr); +} diff --git a/zephyr/test/drivers/src/console_cmd/accelread.c b/zephyr/test/drivers/src/console_cmd/accelread.c new file mode 100644 index 0000000000..8ab9407dfe --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/accelread.c @@ -0,0 +1,123 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <fff.h> +#include <zephyr/shell/shell.h> +#include <ztest.h> + +#include "accelgyro.h" +#include "console.h" +#include "ec_commands.h" +#include "motion_sense.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +FAKE_VALUE_FUNC(int, mock_read, const struct motion_sensor_t *, int *); +FAKE_VALUE_FUNC(int, mock_set_data_rate, const struct motion_sensor_t *, int, + int); +FAKE_VALUE_FUNC(int, mock_get_data_rate, const struct motion_sensor_t *); + +struct console_cmd_accelread_fixture { + const struct accelgyro_drv *sensor_0_drv; + struct accelgyro_drv mock_drv; +}; + +static void *console_cmd_accelread_setup(void) +{ + static struct console_cmd_accelread_fixture fixture = { + .mock_drv = { + .read = mock_read, + /* + * Data rate functions are required so that motion_sense + * task doesn't segfault. + */ + .set_data_rate = mock_set_data_rate, + .get_data_rate = mock_get_data_rate, + }, + }; + fixture.sensor_0_drv = motion_sensors[0].drv; + + return &fixture; +} + +static void console_cmd_accelread_before(void *fixture) +{ + ARG_UNUSED(fixture); + RESET_FAKE(mock_read); + RESET_FAKE(mock_set_data_rate); + RESET_FAKE(mock_get_data_rate); + FFF_RESET_HISTORY(); +} + +static void console_cmd_accelread_after(void *fixture) +{ + struct console_cmd_accelread_fixture *this = fixture; + + motion_sensors[0].drv = this->sensor_0_drv; +} + +ZTEST_SUITE(console_cmd_accelread, drivers_predicate_post_main, + console_cmd_accelread_setup, console_cmd_accelread_before, + console_cmd_accelread_after, NULL); + +ZTEST_USER(console_cmd_accelread, test_too_few_arguments) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelread"); + + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_accelread, test_invalid_sensor_num) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "accelread f"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelread -1"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelread 100"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); +} + +static struct console_cmd_accelread_fixture *current_fixture; + +int mock_read_call_super(const struct motion_sensor_t *s, int *v) +{ + return current_fixture->sensor_0_drv->read(s, v); +} + +ZTEST_USER_F(console_cmd_accelread, test_read) +{ + current_fixture = this; + mock_read_fake.custom_fake = mock_read_call_super; + motion_sensors[0].drv = &this->mock_drv; + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelread 0"), NULL); + zassert_equal(1, mock_read_fake.call_count, + "Expected only 1 call to read, but got %d", + mock_read_fake.call_count); + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelread 0 2"), NULL); + zassert_equal(3, mock_read_fake.call_count, + "Expected only 3 call to read, but got %d", + mock_read_fake.call_count); +} + +ZTEST_USER_F(console_cmd_accelread, test_read_fail) +{ + mock_read_fake.return_val = 1; + motion_sensors[0].drv = &this->mock_drv; + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelread 0"), NULL); + zassert_equal(1, mock_read_fake.call_count, + "Expected only 1 call to read, but got %d", + mock_read_fake.call_count); +} diff --git a/zephyr/test/drivers/src/console_cmd/accelres.c b/zephyr/test/drivers/src/console_cmd/accelres.c new file mode 100644 index 0000000000..72b52b1c58 --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/accelres.c @@ -0,0 +1,127 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <fff.h> +#include <zephyr/shell/shell.h> +#include <ztest.h> + +#include "accelgyro.h" +#include "console.h" +#include "driver/accel_bma2x2.h" +#include "ec_commands.h" +#include "motion_sense.h" +#include "test/drivers/test_state.h" + +FAKE_VALUE_FUNC(int, set_resolution, const struct motion_sensor_t *, int, int); + +struct console_cmd_accelres_fixture { + const struct accelgyro_drv *sensor_0_drv; + struct accelgyro_drv mock_drv; +}; + +void *console_cmd_accelres_setup(void) +{ + static struct console_cmd_accelres_fixture fixture = { + .mock_drv = { + .set_resolution = set_resolution, + }, + }; + + fixture.sensor_0_drv = motion_sensors[0].drv; + + return &fixture; +} + +void console_cmd_accelres_before(void *fixture) +{ + ARG_UNUSED(fixture); + RESET_FAKE(set_resolution); + FFF_RESET_HISTORY(); +} + +void console_cmd_accelres_after(void *fixture) +{ + struct console_cmd_accelres_fixture *this = fixture; + + motion_sensors[0].drv = this->sensor_0_drv; +} + +ZTEST_SUITE(console_cmd_accelres, drivers_predicate_post_main, + console_cmd_accelres_setup, NULL, console_cmd_accelres_after, NULL); + +ZTEST_USER(console_cmd_accelres, test_too_few_args) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelres"); + + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_accelres, test_too_many_args) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelres 1 2 3 4"); + + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_accelres, test_invalid_sensor_num) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "accelres f"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelres -1"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); + + rv = shell_execute_cmd(get_ec_shell(), "accelres 100"); + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); +} + +ZTEST_USER(console_cmd_accelres, test_print_res) +{ + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelres 0"), NULL); +} + +ZTEST_USER(console_cmd_accelres, test_set_res__invalid_data) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelres 0 f"); + + zassert_equal(EC_ERROR_PARAM2, rv, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_accelres, test_set_res__no_setter) +{ + int resolution; + + zassert_ok(shell_execute_cmd(get_ec_shell(), "accelres 0 4"), NULL); + resolution = motion_sensors[0].drv->get_resolution(&motion_sensors[0]); + zassert_equal(BMA2x2_RESOLUTION, resolution, "Expected %d, but got %d", + BMA2x2_RESOLUTION, resolution); +} + +ZTEST_USER_F(console_cmd_accelres, test_set_res__bad_res_value) +{ + int rv; + + set_resolution_fake.return_val = EC_ERROR_INVAL; + motion_sensors[0].drv = &this->mock_drv; + rv = shell_execute_cmd(get_ec_shell(), "accelres 0 0"); + zassert_equal(EC_ERROR_PARAM2, rv, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_accelres, test_invalid_rounding_arg) +{ + int rv = shell_execute_cmd(get_ec_shell(), "accelres 0 12 f"); + + zassert_equal(EC_ERROR_PARAM3, rv, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} diff --git a/zephyr/test/drivers/src/console_cmd/accelspoof.c b/zephyr/test/drivers/src/console_cmd/accelspoof.c index f8295e55f4..2d9887a2ab 100644 --- a/zephyr/test/drivers/src/console_cmd/accelspoof.c +++ b/zephyr/test/drivers/src/console_cmd/accelspoof.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <shell/shell.h> +#include <zephyr/shell/shell.h> #include <ztest.h> #include "console.h" diff --git a/zephyr/test/drivers/src/console_cmd/charge_manager.c b/zephyr/test/drivers/src/console_cmd/charge_manager.c index 8d66c4a7b8..c6e4821623 100644 --- a/zephyr/test/drivers/src/console_cmd/charge_manager.c +++ b/zephyr/test/drivers/src/console_cmd/charge_manager.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <shell/shell.h> +#include <zephyr/shell/shell.h> #include <ztest.h> #include "charge_manager.h" @@ -16,7 +16,7 @@ static void connect_sink_to_port(const struct emul *charger_emul, const struct emul *tcpci_emul, - struct tcpci_snk_emul *sink) + struct tcpci_partner_data *partner) { isl923x_emul_set_adc_vbus(charger_emul, 0); tcpci_emul_set_reg(tcpci_emul, TCPC_REG_POWER_STATUS, @@ -24,9 +24,7 @@ static void connect_sink_to_port(const struct emul *charger_emul, tcpci_emul_set_reg(tcpci_emul, TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); tcpci_tcpc_alert(0); - zassume_ok(tcpci_snk_emul_connect_to_tcpci(&sink->data, - &sink->common_data, - &sink->ops, tcpci_emul), + zassume_ok(tcpci_partner_connect_to_tcpci(partner, tcpci_emul), NULL); /* Wait for PD negotiation and current ramp. @@ -42,7 +40,8 @@ static inline void disconnect_sink_from_port(const struct emul *tcpci_emul) } struct console_cmd_charge_manager_fixture { - struct tcpci_snk_emul sink_5v_3a; + struct tcpci_partner_data sink_5v_3a; + struct tcpci_snk_emul_data sink_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; }; @@ -59,8 +58,11 @@ static void *console_cmd_charge_manager_setup(void) tcpci_emul_set_rev(test_fixture.tcpci_emul, TCPCI_EMUL_REV2_0_VER1_1); /* Initialized the sink to request 5V and 3A */ - tcpci_snk_emul_init(&test_fixture.sink_5v_3a); - test_fixture.sink_5v_3a.data.pdo[1] = + tcpci_partner_init(&test_fixture.sink_5v_3a, PD_REV20); + test_fixture.sink_5v_3a.extensions = + tcpci_snk_emul_init(&test_fixture.sink_ext, + &test_fixture.sink_5v_3a, NULL); + test_fixture.sink_ext.pdo[1] = PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); return &test_fixture; @@ -118,6 +120,9 @@ ZTEST_USER(console_cmd_charge_manager, test_chgoverride_0_from_off) ZTEST_USER_F(console_cmd_charge_manager, test_chgoverride_0_from_sink) { + test_set_chipset_to_g3(); + k_sleep(K_SECONDS(1)); + /* Set chipset to ON, this will set TCPM to DRP */ test_set_chipset_to_s0(); diff --git a/zephyr/test/drivers/src/console_cmd/charge_state.c b/zephyr/test/drivers/src/console_cmd/charge_state.c index 0b9378cbb7..25c03928d4 100644 --- a/zephyr/test/drivers/src/console_cmd/charge_state.c +++ b/zephyr/test/drivers/src/console_cmd/charge_state.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <shell/shell.h> +#include <zephyr/shell/shell.h> #include <ztest.h> #include "charge_state.h" @@ -162,7 +162,8 @@ ZTEST_USER(console_cmd_charge_state, test_sustain_invalid_params) } struct console_cmd_charge_state_fixture { - struct tcpci_src_emul source_5v_3a; + struct tcpci_partner_data source_5v_3a; + struct tcpci_src_emul_data source_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; }; @@ -178,8 +179,11 @@ static void *console_cmd_charge_state_setup(void) emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul))); /* Initialized the source to supply 5V and 3A */ - tcpci_src_emul_init(&fixture.source_5v_3a); - fixture.source_5v_3a.data.pdo[1] = + tcpci_partner_init(&fixture.source_5v_3a, PD_REV20); + fixture.source_5v_3a.extensions = + tcpci_src_emul_init(&fixture.source_ext, + &fixture.source_5v_3a, NULL); + fixture.source_ext.pdo[1] = PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); return &fixture; @@ -201,8 +205,8 @@ ZTEST_SUITE(console_cmd_charge_state, drivers_predicate_post_main, ZTEST_USER_F(console_cmd_charge_state, test_idle_on_from_normal) { /* Connect a source so we start charging */ - connect_source_to_port(&this->source_5v_3a, 1, this->tcpci_emul, - this->charger_emul); + connect_source_to_port(&this->source_5v_3a, &this->source_ext, 1, + this->tcpci_emul, this->charger_emul); /* Verify that we're in "normal" mode */ zassume_equal(get_chg_ctrl_mode(), CHARGE_CONTROL_NORMAL, NULL); @@ -215,8 +219,8 @@ ZTEST_USER_F(console_cmd_charge_state, test_idle_on_from_normal) ZTEST_USER_F(console_cmd_charge_state, test_normal_from_idle) { /* Connect a source so we start charging */ - connect_source_to_port(&this->source_5v_3a, 1, this->tcpci_emul, - this->charger_emul); + connect_source_to_port(&this->source_5v_3a, &this->source_ext, 1, + this->tcpci_emul, this->charger_emul); /* Verify that we're in "normal" mode */ zassume_equal(get_chg_ctrl_mode(), CHARGE_CONTROL_NORMAL, NULL); @@ -234,8 +238,8 @@ ZTEST_USER_F(console_cmd_charge_state, test_normal_from_idle) ZTEST_USER_F(console_cmd_charge_state, test_discharge_on) { /* Connect a source so we start charging */ - connect_source_to_port(&this->source_5v_3a, 1, this->tcpci_emul, - this->charger_emul); + connect_source_to_port(&this->source_5v_3a, &this->source_ext, 1, + this->tcpci_emul, this->charger_emul); /* Verify that we're in "normal" mode */ zassume_equal(get_chg_ctrl_mode(), CHARGE_CONTROL_NORMAL, NULL); @@ -249,8 +253,8 @@ ZTEST_USER_F(console_cmd_charge_state, test_discharge_on) ZTEST_USER_F(console_cmd_charge_state, test_discharge_off) { /* Connect a source so we start charging */ - connect_source_to_port(&this->source_5v_3a, 1, this->tcpci_emul, - this->charger_emul); + connect_source_to_port(&this->source_5v_3a, &this->source_ext, 1, + this->tcpci_emul, this->charger_emul); /* Verify that we're in "normal" mode */ zassume_equal(get_chg_ctrl_mode(), CHARGE_CONTROL_NORMAL, NULL); diff --git a/zephyr/test/drivers/src/console_cmd/usb_pd_console.c b/zephyr/test/drivers/src/console_cmd/usb_pd_console.c new file mode 100644 index 0000000000..4902591c67 --- /dev/null +++ b/zephyr/test/drivers/src/console_cmd/usb_pd_console.c @@ -0,0 +1,255 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/shell/shell.h> +#include <ztest.h> + +#include "console.h" +#include "ec_commands.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +static void console_cmd_usb_pd_after(void *fixture) +{ + ARG_UNUSED(fixture); + + /* TODO (b/230059737) */ + test_set_chipset_to_g3(); + k_sleep(K_SECONDS(1)); + test_set_chipset_to_s0(); + k_sleep(K_SECONDS(10)); +} + +ZTEST_SUITE(console_cmd_usb_pd, drivers_predicate_post_main, NULL, NULL, + console_cmd_usb_pd_after, NULL); + +ZTEST_USER(console_cmd_usb_pd, test_too_few_args) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dump) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd dump 0"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump 4"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump -4"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd dump x"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_trysrc) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 0"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 2"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd trysrc 5"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_version) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd version"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_bad_port) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 5"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 5 tx"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_tx) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 tx"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_charger) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 charger"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dev) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev 20"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dev x"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_disable) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 disable"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_enable) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 enable"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_hard) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 hard"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_soft) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 soft"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_swap) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap power"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap data"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap vconn"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 swap x"); + zassert_equal(rv, EC_ERROR_PARAM3, "Expected %d, but got %d", + EC_ERROR_PARAM3, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_dualrole) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole on"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole off"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole freeze"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole sink"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole source"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 dualrole x"); + zassert_equal(rv, EC_ERROR_PARAM4, "Expected %d, but got %d", + EC_ERROR_PARAM4, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_state) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 state"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_srccaps) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 srccaps"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_timer) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pd 0 timer"); + zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, + rv); +} diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c index 9acd6741ed..d0afdaecdb 100644 --- a/zephyr/test/drivers/src/cros_cbi.c +++ b/zephyr/test/drivers/src/cros_cbi.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <device.h> +#include <zephyr/device.h> #include <ztest.h> #include "cros_cbi.h" diff --git a/zephyr/test/drivers/src/espi.c b/zephyr/test/drivers/src/espi.c index f8293b4591..91746e7c45 100644 --- a/zephyr/test/drivers/src/espi.c +++ b/zephyr/test/drivers/src/espi.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ec_commands.h" diff --git a/zephyr/test/drivers/src/gpio.c b/zephyr/test/drivers/src/gpio.c index 8e8b166092..e49222f08f 100644 --- a/zephyr/test/drivers/src/gpio.c +++ b/zephyr/test/drivers/src/gpio.c @@ -8,11 +8,11 @@ * @brief Unit Tests for GPIO. */ -#include <device.h> +#include <zephyr/device.h> -#include <drivers/gpio/gpio_emul.h> -#include <logging/log.h> -#include <zephyr.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/logging/log.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c index 4063007401..07952ed285 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -3,12 +3,27 @@ * found in the LICENSE file. */ +#include <fff.h> #include <ztest.h> +#include "atomic.h" +#include "driver/accel_bma2x2.h" #include "motion_sense.h" +#include "motion_sense_fifo.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" +FAKE_VALUE_FUNC(int, mock_set_range, struct motion_sensor_t *, int, int); +FAKE_VALUE_FUNC(int, mock_set_offset, const struct motion_sensor_t *, + const int16_t *, int16_t); +FAKE_VALUE_FUNC(int, mock_get_offset, const struct motion_sensor_t *, int16_t *, + int16_t *); +FAKE_VALUE_FUNC(int, mock_set_scale, const struct motion_sensor_t *, + const uint16_t *, int16_t); +FAKE_VALUE_FUNC(int, mock_get_scale, const struct motion_sensor_t *, uint16_t *, + int16_t *); +FAKE_VALUE_FUNC(int, mock_perform_calib, struct motion_sensor_t *, int); + /** * Get the size needed for a struct ec_response_motion_sense */ @@ -16,13 +31,61 @@ (sizeof(struct ec_response_motion_sense) + \ n * sizeof(struct ec_response_motion_sensor_data)) -static void host_cmd_motion_sense_before(void *state) +#define RESPONSE_SENSOR_FIFO_SIZE(n) \ + (sizeof(struct ec_response_motion_sense) + n * sizeof(uint16_t)) + +struct host_cmd_motion_sense_fixture { + const struct accelgyro_drv *sensor_0_drv; + struct accelgyro_drv mock_drv; +}; + +static void *host_cmd_motion_sense_setup(void) { + static struct host_cmd_motion_sense_fixture fixture = { + .mock_drv = { + .set_range = mock_set_range, + .set_offset = mock_set_offset, + .get_offset = mock_get_offset, + .set_scale = mock_set_scale, + .get_scale = mock_get_scale, + .perform_calib = mock_perform_calib, + }, + }; + + fixture.sensor_0_drv = motion_sensors[0].drv; + + return &fixture; +} + +static void host_cmd_motion_sense_before(void *fixture) +{ + ARG_UNUSED(fixture); + RESET_FAKE(mock_set_range); + RESET_FAKE(mock_set_offset); + RESET_FAKE(mock_get_offset); + RESET_FAKE(mock_set_scale); + RESET_FAKE(mock_get_scale); + RESET_FAKE(mock_perform_calib); + FFF_RESET_HISTORY(); + + atomic_clear(&motion_sensors[0].flush_pending); + motion_sensors[0].config[SENSOR_CONFIG_AP].odr = 0; motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 1000 * MSEC; } -ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, NULL, - host_cmd_motion_sense_before, NULL, NULL); +static void host_cmd_motion_sense_after(void *fixture) +{ + struct host_cmd_motion_sense_fixture *this = fixture; + struct ec_response_motion_sense response; + + motion_sensors[0].drv = this->sensor_0_drv; + host_cmd_motion_sense_int_enable(0, &response); + motion_sensors[0].flags &= ~MOTIONSENSE_FLAG_IN_SPOOF_MODE; +} + +ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, + host_cmd_motion_sense_setup, host_cmd_motion_sense_before, + host_cmd_motion_sense_after, NULL); ZTEST_USER(host_cmd_motion_sense, test_dump) { @@ -185,8 +248,598 @@ ZTEST_USER(host_cmd_motion_sense, test_set_ec_rate) /*sensor_num=*/0, /*data_rate_ms=*/2000, &response), NULL); /* The command should return the previous rate */ - zassert_equal(response.ec_rate.ret, 1000, NULL); + zassert_equal(response.ec_rate.ret, 1000, "Expected 1000, but got %d", + response.ec_rate.ret); /* The sensor's AP config value should be updated */ zassert_equal(motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate, 2000 * MSEC, NULL); } + +ZTEST_USER(host_cmd_motion_sense, test_odr_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_odr( + /*sensor_num=*/0xff, + /*odr=*/EC_MOTION_SENSE_NO_VALUE, + /*round_up=*/false, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_odr_get) +{ + struct ec_response_motion_sense response; + + zassume_ok(motion_sensors[0].drv->set_data_rate(&motion_sensors[0], + 1000000, false), + NULL); + zassert_ok(host_cmd_motion_sense_odr(/*sensor_num=*/0, + /*odr=*/EC_MOTION_SENSE_NO_VALUE, + /*round_up=*/false, &response), + NULL); + zassert_equal(BMA2x2_REG_TO_BW(BMA2x2_BW_1000HZ), + response.sensor_odr.ret, "Expected %d, but got %d", + BMA2x2_REG_TO_BW(BMA2x2_BW_1000HZ), + response.sensor_odr.ret); +} + +ZTEST_USER(host_cmd_motion_sense, test_odr_set) +{ + struct ec_response_motion_sense response; + + zassume_ok(motion_sensors[0].drv->set_data_rate(&motion_sensors[0], 0, + false), + NULL); + zassert_ok(host_cmd_motion_sense_odr(/*sensor_num=*/0, + /*odr=*/1000000, + /*round_up=*/true, &response), + NULL); + /* Check the set value */ + zassert_equal(1000000 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_AP].odr, + "Expected %d, but got %d", 1000000 | ROUND_UP_FLAG, + motion_sensors[0].config[SENSOR_CONFIG_AP].odr); + /* Check the returned value */ + zassert_equal(BMA2x2_REG_TO_BW(BMA2x2_BW_7_81HZ), + response.sensor_odr.ret, "Expected %d, but got %d", + BMA2x2_REG_TO_BW(BMA2x2_BW_7_81HZ), + response.sensor_odr.ret); +} + +ZTEST_USER(host_cmd_motion_sense, test_range_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_range( + /*sensor_num=*/0xff, + /*range=*/EC_MOTION_SENSE_NO_VALUE, + /*round_up=*/false, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_get_range) +{ + struct ec_response_motion_sense response; + + zassert_ok(host_cmd_motion_sense_range( + /*sensor_num=*/0, /*range=*/EC_MOTION_SENSE_NO_VALUE, + /*round_up=*/false, &response), + NULL); + zassert_equal(motion_sensors[0].current_range, + response.sensor_range.ret, "Expected %d, but got %d", + motion_sensors[0].current_range, + response.sensor_range.ret); +} + +ZTEST_USER(host_cmd_motion_sense, test_null_set_range_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = { 0 }; + + motion_sensors[0].drv = &drv; + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_range(/*sensor_num=*/0, /*range=*/4, + /*round_up=*/false, + &response), + NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_set_range_error) +{ + struct ec_response_motion_sense response; + + mock_set_range_fake.return_val = 1; + motion_sensors[0].drv = &this->mock_drv; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_range(/*sensor_num=*/0, /*range=*/4, + /*round_up=*/false, + &response), + NULL); + zassert_equal(1, mock_set_range_fake.call_count, NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_set_range) +{ + struct ec_response_motion_sense response; + + mock_set_range_fake.return_val = 0; + motion_sensors[0].drv = &this->mock_drv; + + zassert_ok(host_cmd_motion_sense_range(/*sensor_num=*/0, /*range=*/4, + /*round_up=*/false, &response), + NULL); + zassert_equal(1, mock_set_range_fake.call_count, NULL); + zassert_equal(4, mock_set_range_fake.arg1_history[0], NULL); + zassert_equal(0, mock_set_range_fake.arg2_history[0], NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_offset_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_offset( + /*sensor_num=*/0xff, /*flags=*/0, + /*temperature=*/0, /*offset_x=*/0, + /*offset_y=*/0, /*offset_z=*/0, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_offset_missing_get_offset_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = { 0 }; + + motion_sensors[0].drv = &drv; + + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_offset( + /*sensor_num=*/0, /*flags=*/0, + /*temperature=*/0, /*offset_x=*/0, + /*offset_y=*/0, /*offset_z=*/0, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_offset_missing_set_offset_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = { 0 }; + + motion_sensors[0].drv = &drv; + + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_offset( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/0, /*offset_x=*/0, + /*offset_y=*/0, /*offset_z=*/0, &response), + NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_offset_fail_to_set) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_set_offset_fake.return_val = EC_RES_ERROR; + + zassert_equal(EC_RES_ERROR, + host_cmd_motion_sense_offset( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/0, /*offset_x=*/0, + /*offset_y=*/0, /*offset_z=*/0, &response), + NULL); + zassert_equal(1, mock_set_offset_fake.call_count, NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_offset_fail_to_get) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_set_offset_fake.return_val = EC_RES_SUCCESS; + mock_get_offset_fake.return_val = EC_RES_ERROR; + + zassert_equal(EC_RES_ERROR, + host_cmd_motion_sense_offset( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/0, /*offset_x=*/0, + /*offset_y=*/0, /*offset_z=*/0, &response), + NULL); + zassert_equal(1, mock_set_offset_fake.call_count, NULL); + zassert_equal(1, mock_get_offset_fake.call_count, NULL); + zassert_equal((int16_t *)&response.sensor_offset.offset, + mock_get_offset_fake.arg1_history[0], NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_get_offset) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_get_offset_fake.return_val = EC_RES_SUCCESS; + mock_set_offset_fake.return_val = EC_RES_SUCCESS; + + zassert_ok(host_cmd_motion_sense_offset( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/1, /*offset_x=*/2, + /*offset_y=*/3, /*offset_z=*/4, &response), + NULL); + zassert_equal(1, mock_set_offset_fake.call_count, NULL); + zassert_equal(1, mock_get_offset_fake.call_count, NULL); + zassert_equal((int16_t *)&response.sensor_offset.offset, + mock_get_offset_fake.arg1_history[0], NULL); + zassert_equal(1, mock_set_offset_fake.arg2_history[0], NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_scale_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_scale( + /*sensor_num=*/0xff, + /*flags=*/0, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_get_scale_not_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = *motion_sensors[0].drv; + + drv.get_scale = NULL; + motion_sensors[0].drv = &drv; + + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_scale( + /*sensor_num=*/0, + /*flags=*/0, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_set_scale_not_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = *motion_sensors[0].drv; + + drv.set_scale = NULL; + motion_sensors[0].drv = &drv; + + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_scale( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_get_scale_fail) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_get_scale_fake.return_val = 1; + + zassert_equal(1, + host_cmd_motion_sense_scale( + /*sensor_num=*/0, + /*flags=*/0, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); + zassert_equal(1, mock_get_scale_fake.call_count, NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_set_scale_fail) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_set_scale_fake.return_val = 1; + + zassert_equal(1, + host_cmd_motion_sense_scale( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); + zassert_equal(1, mock_set_scale_fake.call_count, NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_set_get_scale) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_set_scale_fake.return_val = 0; + mock_get_scale_fake.return_val = 0; + + zassert_ok(host_cmd_motion_sense_scale( + /*sensor_num=*/0, + /*flags=*/MOTION_SENSE_SET_OFFSET, + /*temperature=*/1, /*scale_x=*/2, + /*scale_y=*/3, /*scale_z=*/4, &response), + NULL); + zassert_equal(1, mock_set_scale_fake.call_count, NULL); + zassert_equal(1, mock_get_scale_fake.call_count, NULL); + zassert_equal(1, mock_set_scale_fake.arg2_history[0], NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_calib_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_calib(/*sensor_num=*/0xff, + /*enable=*/false, &response), + NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_calib_not_in_driver) +{ + struct ec_response_motion_sense response; + struct accelgyro_drv drv = { 0 }; + + motion_sensors[0].drv = &drv; + zassert_equal(EC_RES_INVALID_COMMAND, + host_cmd_motion_sense_calib(/*sensor_num=*/0, + /*enable=*/false, &response), + NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_calib_fail) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_perform_calib_fake.return_val = 1; + + zassert_equal(1, + host_cmd_motion_sense_calib(/*sensor_num=*/0, + /*enable=*/false, &response), + NULL); + zassert_equal(1, mock_perform_calib_fake.call_count, NULL); + zassert_false(mock_perform_calib_fake.arg1_history[0], NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_calib_success__fail_get_offset) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_perform_calib_fake.return_val = 0; + mock_get_offset_fake.return_val = 1; + + zassert_equal(1, + host_cmd_motion_sense_calib(/*sensor_num=*/0, + /*enable=*/false, &response), + NULL); + zassert_equal(1, mock_perform_calib_fake.call_count, NULL); + zassert_equal(1, mock_get_offset_fake.call_count, NULL); + zassert_false(mock_perform_calib_fake.arg1_history[0], NULL); +} + +ZTEST_USER_F(host_cmd_motion_sense, test_calib) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].drv = &this->mock_drv; + mock_perform_calib_fake.return_val = 0; + mock_get_offset_fake.return_val = 0; + + zassert_ok(host_cmd_motion_sense_calib(/*sensor_num=*/0, + /*enable=*/true, &response), + NULL); + zassert_equal(1, mock_perform_calib_fake.call_count, NULL); + zassert_equal(1, mock_get_offset_fake.call_count, NULL); + zassert_true(mock_perform_calib_fake.arg1_history[0], NULL); +} + +ZTEST(host_cmd_motion_sense, test_fifo_flush__invalid_sensor_num) +{ + int rv; + struct ec_response_motion_sense response; + + rv = host_cmd_motion_sense_fifo_flush(/*sensor_num=*/0xff, &response); + zassert_equal(rv, EC_RES_INVALID_PARAM, NULL); +} + +ZTEST(host_cmd_motion_sense, test_fifo_flush) +{ + uint8_t response_buffer[RESPONSE_SENSOR_FIFO_SIZE(ALL_MOTION_SENSORS)]; + struct ec_response_motion_sense *response = + (struct ec_response_motion_sense *)response_buffer; + + motion_sensors[0].lost = 5; + zassert_ok(host_cmd_motion_sense_fifo_flush(/*sensor_num=*/0, response), + NULL); + zassert_equal(1, motion_sensors[0].flush_pending, NULL); + zassert_equal(5, response->fifo_info.lost[0], NULL); + zassert_equal(0, motion_sensors[0].lost, NULL); +} + +ZTEST(host_cmd_motion_sense, test_fifo_info) +{ + uint8_t response_buffer[RESPONSE_SENSOR_FIFO_SIZE(ALL_MOTION_SENSORS)]; + struct ec_response_motion_sense *response = + (struct ec_response_motion_sense *)response_buffer; + + motion_sensors[0].lost = 4; + zassert_ok(host_cmd_motion_sense_fifo_info(response), NULL); + zassert_equal(4, response->fifo_info.lost[0], NULL); + zassert_equal(0, motion_sensors[0].lost, NULL); +} + +ZTEST(host_cmd_motion_sense, test_fifo_read) +{ + struct ec_response_motion_sensor_data data; + uint8_t response_buffer[RESPONSE_MOTION_SENSE_BUFFER_SIZE(2)]; + struct ec_response_motion_sense *response = + (struct ec_response_motion_sense *)response_buffer; + + motion_sensors[0].oversampling_ratio = 1; + motion_sensors[1].oversampling_ratio = 1; + + data = (struct ec_response_motion_sensor_data){ + .flags = 0, + .sensor_num = 0, + .data = { 0, 1, 2 }, + }; + motion_sense_fifo_stage_data(&data, &motion_sensors[0], 1, 0); + + data = (struct ec_response_motion_sensor_data){ + .flags = 0, + .sensor_num = 1, + .data = { 3, 4, 5 }, + }; + motion_sense_fifo_stage_data(&data, &motion_sensors[1], 1, 5); + motion_sense_fifo_commit_data(); + + /* Read 2 samples */ + zassert_ok(host_cmd_motion_sense_fifo_read(4, response), NULL); + zassert_equal(2, response->fifo_read.number_data, NULL); + + zassert_equal(MOTIONSENSE_SENSOR_FLAG_TIMESTAMP, + response->fifo_read.data[0].flags, NULL); + zassert_equal(0, response->fifo_read.data[0].sensor_num, NULL); + zassert_equal(0, response->fifo_read.data[0].timestamp, NULL); + + zassert_equal(0, response->fifo_read.data[1].flags, NULL); + zassert_equal(0, response->fifo_read.data[1].sensor_num, NULL); + zassert_equal(0, response->fifo_read.data[1].data[0], NULL); + zassert_equal(1, response->fifo_read.data[1].data[1], NULL); + zassert_equal(2, response->fifo_read.data[1].data[2], NULL); + + /* Read the next 2 samples */ + zassert_ok(host_cmd_motion_sense_fifo_read(4, response), NULL); + zassert_equal(2, response->fifo_read.number_data, NULL); + zassert_equal(MOTIONSENSE_SENSOR_FLAG_TIMESTAMP, + response->fifo_read.data[0].flags, NULL); + zassert_equal(1, response->fifo_read.data[0].sensor_num, NULL); + zassert_equal(5, response->fifo_read.data[0].timestamp, NULL); + + zassert_equal(0, response->fifo_read.data[1].flags, NULL); + zassert_equal(1, response->fifo_read.data[1].sensor_num, NULL); + zassert_equal(3, response->fifo_read.data[1].data[0], NULL); + zassert_equal(4, response->fifo_read.data[1].data[1], NULL); + zassert_equal(5, response->fifo_read.data[1].data[2], NULL); +} + +ZTEST(host_cmd_motion_sense, test_int_enable) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_int_enable(2, &response), NULL); + + /* Make sure we start off disabled */ + zassume_ok(host_cmd_motion_sense_int_enable(0, &response), NULL); + + /* Test enable */ + zassert_ok(host_cmd_motion_sense_int_enable(1, &response), NULL); + zassert_ok(host_cmd_motion_sense_int_enable(EC_MOTION_SENSE_NO_VALUE, + &response), + NULL); + zassert_equal(1, response.fifo_int_enable.ret, NULL); + + /* Test disable */ + zassert_ok(host_cmd_motion_sense_int_enable(0, &response), NULL); + zassert_ok(host_cmd_motion_sense_int_enable(EC_MOTION_SENSE_NO_VALUE, + &response), + NULL); + zassert_equal(0, response.fifo_int_enable.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_spoof(0xff, 0, 0, 0, 0, &response), + NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_disable) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].flags |= MOTIONSENSE_FLAG_IN_SPOOF_MODE; + zassert_ok(host_cmd_motion_sense_spoof(0, + MOTIONSENSE_SPOOF_MODE_DISABLE, + 0, 0, 0, &response), + NULL); + zassert_equal(0, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_false(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_custom) +{ + struct ec_response_motion_sense response; + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_CUSTOM, + -8, 16, -32, &response), + NULL); + zassert_equal(MOTIONSENSE_FLAG_IN_SPOOF_MODE, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + zassert_equal(-8, motion_sensors[0].spoof_xyz[0], NULL); + zassert_equal(16, motion_sensors[0].spoof_xyz[1], NULL); + zassert_equal(-32, motion_sensors[0].spoof_xyz[2], NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_true(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_lock_current) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].raw_xyz[0] = 64; + motion_sensors[0].raw_xyz[1] = 48; + motion_sensors[0].raw_xyz[2] = 32; + zassert_ok(host_cmd_motion_sense_spoof( + 0, MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, 0, 0, 0, + &response), + NULL); + zassert_equal(MOTIONSENSE_FLAG_IN_SPOOF_MODE, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + zassert_equal(64, motion_sensors[0].spoof_xyz[0], NULL); + zassert_equal(48, motion_sensors[0].spoof_xyz[1], NULL); + zassert_equal(32, motion_sensors[0].spoof_xyz[2], NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_true(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_invalid_mode) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_spoof(0, 0xff, 0, 0, 0, &response), + NULL); +} diff --git a/zephyr/test/drivers/src/i2c_passthru.c b/zephyr/test/drivers/src/i2c_passthru.c index 98bc181d84..bab6a15b28 100644 --- a/zephyr/test/drivers/src/i2c_passthru.c +++ b/zephyr/test/drivers/src/i2c_passthru.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ec_commands.h" diff --git a/zephyr/test/drivers/src/integration/usbc/usb.c b/zephyr/test/drivers/src/integration/usbc/usb.c index 3c2898b363..0a6443ded9 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb.c +++ b/zephyr/test/drivers/src/integration/usbc/usb.c @@ -3,9 +3,9 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "battery_smart.h" #include "ec_commands.h" @@ -108,7 +108,10 @@ ZTEST(integration_usb, test_attach_drp) { const struct emul *tcpci_emul = emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL)); - struct tcpci_drp_emul my_drp; + struct tcpci_partner_data my_drp; + struct tcpci_drp_emul_data drp_ext; + struct tcpci_src_emul_data src_ext; + struct tcpci_snk_emul_data snk_ext; /* Set chipset to ON, this will set TCPM to DRP */ test_set_chipset_to_s0(); @@ -117,12 +120,14 @@ ZTEST(integration_usb, test_attach_drp) k_sleep(K_SECONDS(1)); /* Attach emulated sink */ - tcpci_drp_emul_init(&my_drp); - zassert_ok(tcpci_drp_emul_connect_to_tcpci(&my_drp.data, - &my_drp.src_data, - &my_drp.snk_data, - &my_drp.common_data, - &my_drp.ops, tcpci_emul), + tcpci_partner_init(&my_drp, PD_REV20); + my_drp.extensions = + tcpci_drp_emul_init( + &drp_ext, &my_drp, PD_ROLE_SINK, + tcpci_src_emul_init(&src_ext, &my_drp, NULL), + tcpci_snk_emul_init(&snk_ext, &my_drp, NULL)); + + zassert_ok(tcpci_partner_connect_to_tcpci(&my_drp, tcpci_emul), NULL); /* Wait for PD negotiation */ diff --git a/zephyr/test/drivers/src/integration/usbc/usb_20v_3a_pd_charger.c b/zephyr/test/drivers/src/integration/usbc/usb_20v_3a_pd_charger.c index 78029dd3ff..79cbb21b96 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_20v_3a_pd_charger.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_20v_3a_pd_charger.c @@ -16,7 +16,8 @@ #define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery)) struct usb_attach_20v_3a_pd_charger_fixture { - struct tcpci_src_emul charger_20v; + struct tcpci_partner_data charger_20v; + struct tcpci_src_emul_data src_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; }; @@ -25,15 +26,13 @@ static inline void connect_charger_to_port(struct usb_attach_20v_3a_pd_charger_fixture *fixture) { set_ac_enabled(true); - zassume_ok(tcpci_src_emul_connect_to_tcpci( - &fixture->charger_20v.data, - &fixture->charger_20v.common_data, - &fixture->charger_20v.ops, fixture->tcpci_emul), + zassume_ok(tcpci_partner_connect_to_tcpci( + &fixture->charger_20v, fixture->tcpci_emul), NULL); isl923x_emul_set_adc_vbus( fixture->charger_emul, - PDO_FIXED_GET_VOLT(fixture->charger_20v.data.pdo[1])); + PDO_FIXED_GET_VOLT(fixture->src_ext.pdo[1])); /* Wait for PD negotiation and current ramp. * TODO(b/213906889): Check message timing and contents. @@ -61,8 +60,11 @@ static void *usb_attach_20v_3a_pd_charger_setup(void) emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul))); /* Initialized the charger to supply 20V and 3A */ - tcpci_src_emul_init(&test_fixture.charger_20v); - test_fixture.charger_20v.data.pdo[1] = + tcpci_partner_init(&test_fixture.charger_20v, PD_REV20); + test_fixture.charger_20v.extensions = + tcpci_src_emul_init(&test_fixture.src_ext, + &test_fixture.charger_20v, NULL); + test_fixture.src_ext.pdo[1] = PDO_FIXED(20000, 3000, PDO_FIXED_UNCONSTRAINED); return &test_fixture; diff --git a/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_sink.c b/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_sink.c index 9a4df7d11e..1cbdda49b0 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_sink.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_sink.c @@ -13,14 +13,26 @@ #include "tcpm/tcpci.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" +#include "timer.h" +#include "usb_common.h" #include "usb_pd.h" struct usb_attach_5v_3a_pd_sink_fixture { - struct tcpci_snk_emul sink_5v_3a; + struct tcpci_partner_data sink_5v_3a; + struct tcpci_snk_emul_data snk_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; }; +/* Chromebooks only charge PD partners at 5v */ +#define TEST_SRC_PORT_VBUS_MV 5000 +#define TEST_SRC_PORT_TARGET_MA 3000 + +#define TEST_INITIAL_SINK_CAP \ + PDO_FIXED(TEST_SRC_PORT_VBUS_MV, TEST_SRC_PORT_TARGET_MA, 0) +/* Only used to verify sink capabilities being received by SRC port */ +#define TEST_ADDITIONAL_SINK_CAP PDO_FIXED(TEST_SRC_PORT_VBUS_MV, 5000, 0) + static void connect_sink_to_port(struct usb_attach_5v_3a_pd_sink_fixture *fixture) { @@ -38,10 +50,9 @@ connect_sink_to_port(struct usb_attach_5v_3a_pd_sink_fixture *fixture) tcpci_tcpc_alert(0); k_sleep(K_SECONDS(1)); - zassume_ok(tcpci_snk_emul_connect_to_tcpci( - &fixture->sink_5v_3a.data, - &fixture->sink_5v_3a.common_data, - &fixture->sink_5v_3a.ops, fixture->tcpci_emul), + zassume_ok(tcpci_partner_connect_to_tcpci( + &fixture->sink_5v_3a, + fixture->tcpci_emul), NULL); /* Wait for PD negotiation and current ramp. @@ -82,9 +93,12 @@ static void usb_attach_5v_3a_pd_sink_before(void *data) k_sleep(K_SECONDS(1)); /* Initialized the sink to request 5V and 3A */ - tcpci_snk_emul_init(&test_fixture->sink_5v_3a); - test_fixture->sink_5v_3a.data.pdo[1] = - PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); + tcpci_partner_init(&test_fixture->sink_5v_3a, PD_REV20); + test_fixture->sink_5v_3a.extensions = + tcpci_snk_emul_init(&test_fixture->snk_ext, + &test_fixture->sink_5v_3a, NULL); + test_fixture->snk_ext.pdo[0] = TEST_INITIAL_SINK_CAP; + test_fixture->snk_ext.pdo[1] = TEST_ADDITIONAL_SINK_CAP; connect_sink_to_port(test_fixture); } @@ -101,7 +115,7 @@ ZTEST_SUITE(usb_attach_5v_3a_pd_sink, drivers_predicate_post_main, ZTEST_F(usb_attach_5v_3a_pd_sink, test_partner_pd_completed) { - zassert_true(this->sink_5v_3a.data.pd_completed, NULL); + zassert_true(this->snk_ext.pd_completed, NULL); } ZTEST(usb_attach_5v_3a_pd_sink, test_battery_is_discharging) @@ -146,10 +160,10 @@ ZTEST(usb_attach_5v_3a_pd_sink, test_power_info) "Expected charge voltage max of 0mV, but got %dmV", info.meas.voltage_max); zassert_within( - info.meas.voltage_now, 5000, 500, + info.meas.voltage_now, TEST_SRC_PORT_VBUS_MV, 500, "Charging voltage expected to be near 5000mV, but was %dmV", info.meas.voltage_now); - zassert_equal(info.meas.current_max, 1500, + zassert_equal(info.meas.current_max, TEST_SRC_PORT_TARGET_MA, "Current max expected to be 1500mV, but was %dmV", info.meas.current_max); zassert_equal(info.meas.current_lim, 0, @@ -239,3 +253,66 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_power_info) "Expected the PD current limit to be >= 0, but got %dmA", power_info.meas.current_lim); } + +/** + * @brief TestPurpose: Verify GotoMin message. + * + * @details + * - TCPM is configured initially as Source + * - Initiate Goto_Min request + * - Verify emulated sink PD negotiation is completed + * + * Expected Results + * - Sink completes Goto Min PD negotiation + */ +ZTEST_F(usb_attach_5v_3a_pd_sink, verify_goto_min) +{ + pd_dpm_request(0, DPM_REQUEST_GOTO_MIN); + k_sleep(K_SECONDS(1)); + + zassert_true(this->snk_ext.pd_completed, NULL); +} + +/** + * @brief TestPurpose: Verify Ping message. + * + * @details + * - TCPM is configured initially as Source + * - Initiate Ping request + * - Verify emulated sink received ping message + * + * Expected Results + * - Sink received ping message + */ +ZTEST_F(usb_attach_5v_3a_pd_sink, verify_ping_msg) +{ + tcpci_snk_emul_clear_ping_received(&this->snk_ext); + + pd_dpm_request(0, DPM_REQUEST_SEND_PING); + k_sleep(K_USEC(PD_T_SOURCE_ACTIVITY)); + + zassert_true(this->snk_ext.ping_received, NULL); +} + +/** + * @brief TestPurpose: Verify Alert message. + * + * @details + * - Clear alert_received in emulated partner + * - Broadcast PD Alert + * - Check pd_broadcast_alert_msg can set the ADO and run pd_dpm_request + * - Check that emulated partner received a PD_DATA_ALERT message + * + * Expected Results + * - EC_SUCCESS returned from pd_broadcast_alert_msg + * - sink_5v_3a.data.alert_received is true + */ +ZTEST_F(usb_attach_5v_3a_pd_sink, verify_alert_msg) +{ + tcpci_snk_emul_clear_alert_received(&this->snk_ext); + zassert_false(this->snk_ext.alert_received, NULL); + zassert_equal(pd_broadcast_alert_msg(ADO_OTP_EVENT), EC_SUCCESS, NULL); + + k_sleep(K_SECONDS(2)); + zassert_true(this->snk_ext.alert_received, NULL); +} diff --git a/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_source.c b/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_source.c index 970870950c..39745dd70b 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_source.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_5v_3a_pd_source.c @@ -9,14 +9,20 @@ #include "emul/emul_isl923x.h" #include "emul/emul_smart_battery.h" #include "emul/tcpc/emul_tcpci_partner_src.h" +#include "hooks.h" +#include "test/drivers/stubs.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" #include "usb_pd.h" +#include "usb_prl_sm.h" #define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery)) +#define TEST_USB_PORT USBC_PORT_C0 + struct usb_attach_5v_3a_pd_source_fixture { - struct tcpci_src_emul source_5v_3a; + struct tcpci_partner_data source_5v_3a; + struct tcpci_src_emul_data src_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; }; @@ -31,9 +37,16 @@ static void *usb_attach_5v_3a_pd_source_setup(void) test_fixture.charger_emul = emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul))); + /* Configure TCPCI revision in board config and emulator */ + tcpc_config[0].flags |= TCPC_FLAGS_TCPCI_REV2_0; + tcpci_emul_set_rev(test_fixture.tcpci_emul, TCPCI_EMUL_REV2_0_VER1_1); + /* Initialized the charger to supply 5V and 3A */ - tcpci_src_emul_init(&test_fixture.source_5v_3a); - test_fixture.source_5v_3a.data.pdo[1] = + tcpci_partner_init(&test_fixture.source_5v_3a, PD_REV20); + test_fixture.source_5v_3a.extensions = + tcpci_src_emul_init(&test_fixture.src_ext, + &test_fixture.source_5v_3a, NULL); + test_fixture.src_ext.pdo[1] = PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); return &test_fixture; @@ -43,8 +56,8 @@ static void usb_attach_5v_3a_pd_source_before(void *data) { struct usb_attach_5v_3a_pd_source_fixture *fixture = data; - connect_source_to_port(&fixture->source_5v_3a, 1, fixture->tcpci_emul, - fixture->charger_emul); + connect_source_to_port(&fixture->source_5v_3a, &fixture->src_ext, 1, + fixture->tcpci_emul, fixture->charger_emul); } static void usb_attach_5v_3a_pd_source_after(void *data) @@ -205,3 +218,58 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_power_info) "Expected the PD current limit to be >= 0, but got %dmA", power_info.meas.current_lim); } + +ZTEST_F(usb_attach_5v_3a_pd_source, verify_dock_with_power_button) +{ + /* Clear Alert and Status receive checks */ + tcpci_src_emul_clear_alert_received(&this->src_ext); + tcpci_src_emul_clear_status_received(&this->src_ext); + zassert_false(this->src_ext.alert_received, NULL); + zassert_false(this->src_ext.status_received, NULL); + + /* Setting up revision for the full Status message */ + prl_set_rev(TEST_USB_PORT, TCPCI_MSG_SOP, PD_REV30); + k_sleep(K_MSEC(10)); + pd_dpm_request(TEST_USB_PORT, DPM_REQUEST_GET_REVISION); + k_sleep(K_MSEC(10)); + + /* Suspend and check partner received Alert and Status messages */ + hook_notify(HOOK_CHIPSET_SUSPEND); + k_sleep(K_SECONDS(2)); + zassert_true(this->src_ext.alert_received, NULL); + zassert_true(this->src_ext.status_received, NULL); + tcpci_src_emul_clear_alert_received(&this->src_ext); + tcpci_src_emul_clear_status_received(&this->src_ext); + zassert_false(this->src_ext.alert_received, NULL); + zassert_false(this->src_ext.status_received, NULL); + + /* Shutdown and check partner received Alert and Status messages */ + hook_notify(HOOK_CHIPSET_SHUTDOWN); + k_sleep(K_SECONDS(2)); + zassert_true(this->src_ext.alert_received, NULL); + zassert_true(this->src_ext.status_received, NULL); + tcpci_src_emul_clear_alert_received(&this->src_ext); + tcpci_src_emul_clear_status_received(&this->src_ext); + zassert_false(this->src_ext.alert_received, NULL); + zassert_false(this->src_ext.status_received, NULL); + + /* Startup and check partner received Alert and Status messages */ + hook_notify(HOOK_CHIPSET_STARTUP); + k_sleep(K_SECONDS(2)); + zassert_true(this->src_ext.alert_received, NULL); + zassert_true(this->src_ext.status_received, NULL); + tcpci_src_emul_clear_alert_received(&this->src_ext); + tcpci_src_emul_clear_status_received(&this->src_ext); + zassert_false(this->src_ext.alert_received, NULL); + zassert_false(this->src_ext.status_received, NULL); + + /* Resume and check partner received Alert and Status messages */ + hook_notify(HOOK_CHIPSET_RESUME); + k_sleep(K_SECONDS(2)); + zassert_true(this->src_ext.alert_received, NULL); + zassert_true(this->src_ext.status_received, NULL); + tcpci_src_emul_clear_alert_received(&this->src_ext); + tcpci_src_emul_clear_status_received(&this->src_ext); + zassert_false(this->src_ext.alert_received, NULL); + zassert_false(this->src_ext.status_received, NULL); +} diff --git a/zephyr/test/drivers/src/integration/usbc/usb_alt_mode.c b/zephyr/test/drivers/src/integration/usbc/usb_alt_mode.c index abef3f0b78..472c57d978 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_alt_mode.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_alt_mode.c @@ -4,9 +4,9 @@ */ #include <stdint.h> -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "ec_commands.h" #include "ec_tasks.h" @@ -23,13 +23,14 @@ struct usbc_alt_mode_fixture { const struct emul *tcpci_emul; const struct emul *charger_emul; - struct tcpci_snk_emul partner_emul; + struct tcpci_partner_data partner; + struct tcpci_snk_emul_data snk_ext; }; static void connect_partner_to_port(struct usbc_alt_mode_fixture *fixture) { const struct emul *tcpc_emul = fixture->tcpci_emul; - struct tcpci_snk_emul *partner_emul = &fixture->partner_emul; + struct tcpci_partner_data *partner_emul = &fixture->partner; /* Set VBUS to vSafe0V initially. */ isl923x_emul_set_adc_vbus(fixture->charger_emul, 0); @@ -38,9 +39,7 @@ static void connect_partner_to_port(struct usbc_alt_mode_fixture *fixture) tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); tcpci_tcpc_alert(0); - zassume_ok(tcpci_snk_emul_connect_to_tcpci( - &partner_emul->data, &partner_emul->common_data, - &partner_emul->ops, tcpc_emul), + zassume_ok(tcpci_partner_connect_to_tcpci(partner_emul, tcpc_emul), NULL); /* Wait for PD negotiation and current ramp. */ @@ -57,10 +56,11 @@ static void disconnect_partner_from_port(struct usbc_alt_mode_fixture *fixture) static void *usbc_alt_mode_setup(void) { static struct usbc_alt_mode_fixture fixture; - struct tcpci_partner_data *partner_common = - &fixture.partner_emul.common_data; + struct tcpci_partner_data *partner = &fixture.partner; + struct tcpci_snk_emul_data *snk_ext = &fixture.snk_ext; - tcpci_snk_emul_init(&fixture.partner_emul); + tcpci_partner_init(partner, PD_REV20); + partner->extensions = tcpci_snk_emul_init(snk_ext, partner, NULL); /* Get references for the emulators */ fixture.tcpci_emul = @@ -72,38 +72,36 @@ static void *usbc_alt_mode_setup(void) emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul))); /* Set up SOP discovery responses for DP adapter. */ - partner_common->identity_vdm[VDO_INDEX_HDR] = + partner->identity_vdm[VDO_INDEX_HDR] = VDO(USB_SID_PD, /* structured VDM */ true, VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_IDENT); - partner_common->identity_vdm[VDO_INDEX_IDH] = VDO_IDH( + partner->identity_vdm[VDO_INDEX_IDH] = VDO_IDH( /* USB host */ false, /* USB device */ false, IDH_PTYPE_AMA, /* modal operation */ true, USB_VID_GOOGLE); - partner_common->identity_vdm[VDO_INDEX_CSTAT] = 0xabcdabcd; - partner_common->identity_vdm[VDO_INDEX_PRODUCT] = - VDO_PRODUCT(0x1234, 0x5678); + partner->identity_vdm[VDO_INDEX_CSTAT] = 0xabcdabcd; + partner->identity_vdm[VDO_INDEX_PRODUCT] = VDO_PRODUCT(0x1234, 0x5678); /* Hardware version 1, firmware version 2 */ - partner_common->identity_vdm[VDO_INDEX_AMA] = 0x12000000; - partner_common->identity_vdos = VDO_INDEX_AMA + 1; + partner->identity_vdm[VDO_INDEX_AMA] = 0x12000000; + partner->identity_vdos = VDO_INDEX_AMA + 1; /* Support DisplayPort VID. */ - partner_common->svids_vdm[VDO_INDEX_HDR] = + partner->svids_vdm[VDO_INDEX_HDR] = VDO(USB_SID_PD, /* structured VDM */ true, VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_SVID); - partner_common->svids_vdm[VDO_INDEX_HDR + 1] = + partner->svids_vdm[VDO_INDEX_HDR + 1] = VDO_SVID(USB_SID_DISPLAYPORT, 0); - partner_common->svids_vdos = VDO_INDEX_HDR + 2; + partner->svids_vdos = VDO_INDEX_HDR + 2; /* Support one mode for DisplayPort VID. Copied from Hoho. */ - partner_common->modes_vdm[VDO_INDEX_HDR] = + partner->modes_vdm[VDO_INDEX_HDR] = VDO(USB_SID_DISPLAYPORT, /* structured VDM */ true, VDO_CMDT(CMDT_RSP_ACK) | CMD_DISCOVER_MODES); - partner_common->modes_vdm[VDO_INDEX_HDR + 1] = VDO_MODE_DP( + partner->modes_vdm[VDO_INDEX_HDR + 1] = VDO_MODE_DP( 0, MODE_DP_PIN_C, 1, CABLE_PLUG, MODE_DP_V13, MODE_DP_SNK); - partner_common->modes_vdos = VDO_INDEX_HDR + 2; + partner->modes_vdos = VDO_INDEX_HDR + 2; /* Sink 5V 3A. */ - fixture.partner_emul.data.pdo[1] = - PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); + snk_ext->pdo[1] = PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); return &fixture; } @@ -134,12 +132,12 @@ ZTEST_F(usbc_alt_mode, verify_discovery) /* The host command does not count the VDM header in identity_count. */ zassert_equal(discovery->identity_count, - this->partner_emul.common_data.identity_vdos - 1, + this->partner.identity_vdos - 1, "Expected %d identity VDOs, got %d", - this->partner_emul.common_data.identity_vdos - 1, + this->partner.identity_vdos - 1, discovery->identity_count); zassert_mem_equal(discovery->discovery_vdo, - this->partner_emul.common_data.identity_vdm + 1, + this->partner.identity_vdm + 1, discovery->identity_count * sizeof(*discovery->discovery_vdo), "Discovered SOP identity ACK did not match"); @@ -152,7 +150,7 @@ ZTEST_F(usbc_alt_mode, verify_discovery) "Expected 1 DP mode, got %d", discovery->svids[0].mode_count); zassert_equal(discovery->svids[0].mode_vdo[0], - this->partner_emul.common_data.modes_vdm[1], + this->partner.modes_vdm[1], "DP mode VDOs did not match"); } diff --git a/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c b/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c index 54598c4685..31d5c329b1 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c @@ -3,9 +3,9 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "ec_commands.h" #include "ec_tasks.h" @@ -13,7 +13,6 @@ #include "emul/emul_isl923x.h" #include "emul/tcpc/emul_ps8xxx.h" #include "emul/tcpc/emul_tcpci.h" -#include "emul/tcpc/emul_tcpci_partner_drp.h" #include "emul/tcpc/emul_tcpci_partner_snk.h" #include "emul/tcpc/emul_tcpci_partner_src.h" #include "host_command.h" @@ -45,8 +44,10 @@ struct emul_state { const struct emul *tcpci_generic_emul; const struct emul *tcpci_ps8xxx_emul; const struct emul *charger_isl923x_emul; - struct tcpci_src_emul my_src; - struct tcpci_snk_emul my_snk; + struct tcpci_partner_data my_src; + struct tcpci_src_emul_data src_ext; + struct tcpci_partner_data my_snk; + struct tcpci_snk_emul_data snk_ext; }; struct integration_usb_attach_src_then_snk_fixture { @@ -76,6 +77,14 @@ static void integration_usb_setup(struct emul_state *fixture) fixture->tcpci_ps8xxx_emul = tcpci_emul2; fixture->charger_isl923x_emul = charger_emul; + tcpci_partner_init(&fixture->my_snk, PD_REV20); + fixture->my_snk.extensions = + tcpci_snk_emul_init(&fixture->snk_ext, &fixture->my_snk, NULL); + + tcpci_partner_init(&fixture->my_src, PD_REV20); + fixture->my_src.extensions = + tcpci_src_emul_init(&fixture->src_ext, &fixture->my_src, NULL); + /* * TODO(b/221288815): TCPCI config flags should be compile-time * constants @@ -155,11 +164,10 @@ static void attach_src_snk_common_after(struct emul_state *my_emul_state) static void attach_emulated_snk(struct emul_state *my_emul_state) { const struct emul *tcpci_emul_snk = my_emul_state->tcpci_ps8xxx_emul; - struct tcpci_snk_emul *my_snk = &my_emul_state->my_snk; + struct tcpci_partner_data *my_snk = &my_emul_state->my_snk; uint16_t power_reg_val; /* Attach emulated sink */ - tcpci_snk_emul_init(my_snk); tcpci_emul_set_rev(tcpci_emul_snk, TCPCI_EMUL_REV2_0_VER1_1); /* Turn on VBUS detection */ @@ -178,9 +186,7 @@ static void attach_emulated_snk(struct emul_state *my_emul_state) tcpci_emul_set_reg(tcpci_emul_snk, TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); - zassume_ok(tcpci_snk_emul_connect_to_tcpci( - &my_snk->data, &my_snk->common_data, &my_snk->ops, - tcpci_emul_snk), + zassume_ok(tcpci_partner_connect_to_tcpci(my_snk, tcpci_emul_snk), NULL); /* TODO(b/214401892): Check why need to give time TCPM to spin */ @@ -191,11 +197,10 @@ static void attach_emulated_src(struct emul_state *my_emul_state) { const struct emul *tcpci_emul_src = my_emul_state->tcpci_generic_emul; const struct emul *charger_emul = my_emul_state->charger_isl923x_emul; - struct tcpci_src_emul *my_src = &my_emul_state->my_src; + struct tcpci_partner_data *my_src = &my_emul_state->my_src; uint16_t power_reg_val; /* Attach emulated charger. */ - tcpci_src_emul_init(my_src); tcpci_emul_set_rev(tcpci_emul_src, TCPCI_EMUL_REV2_0_VER1_1); /* Turn on VBUS detection */ @@ -214,9 +219,7 @@ static void attach_emulated_src(struct emul_state *my_emul_state) tcpci_emul_set_reg(tcpci_emul_src, TCPC_REG_EXT_STATUS, TCPC_REG_EXT_STATUS_SAFE0V); - zassume_ok(tcpci_src_emul_connect_to_tcpci( - &my_src->data, &my_src->common_data, &my_src->ops, - tcpci_emul_src), + zassume_ok(tcpci_partner_connect_to_tcpci(my_src, tcpci_emul_src), NULL); isl923x_emul_set_adc_vbus(charger_emul, DEFAULT_VBUS_MV); } @@ -334,7 +337,7 @@ ZTEST_F(integration_usb_attach_src_then_snk, verify_src_port_pd_info) "Expected Charging at VBUS %dmV, but PD reports %dmV", DEFAULT_VBUS_MV, response.meas.voltage_now); - zassume_equal(response.meas.current_max, DEFAULT_VBUS_SRC_PORT_MA, + zassert_equal(response.meas.current_max, DEFAULT_VBUS_SRC_PORT_MA, "Charging at VBUS max %dmA, but PD reports %dmA", DEFAULT_VBUS_SRC_PORT_MA, response.meas.current_max); @@ -405,7 +408,7 @@ ZTEST_F(integration_usb_attach_snk_then_src, verify_src_port_pd_info) "Expected Charging at VBUS %dmV, but PD reports %dmV", DEFAULT_VBUS_MV, response.meas.voltage_now); - zassume_equal(response.meas.current_max, DEFAULT_VBUS_SRC_PORT_MA, + zassert_equal(response.meas.current_max, DEFAULT_VBUS_SRC_PORT_MA, "Charging at VBUS max %dmA, but PD reports %dmA", DEFAULT_VBUS_SRC_PORT_MA, response.meas.current_max); @@ -657,7 +660,7 @@ ZTEST_F(usb_detach_test, verify_detach_src_snk) "Expected Charging at VBUS %dmV, but PD reports %dmV", DEFAULT_VBUS_MV, src_power_info.meas.voltage_now); - zassume_equal(src_power_info.meas.current_max, 0, + zassert_equal(src_power_info.meas.current_max, 0, "Charging at VBUS max %dmA, but PD reports %dmA", 0, src_power_info.meas.current_max); } @@ -719,7 +722,7 @@ ZTEST_F(usb_detach_test, verify_detach_snk_src) "Expected Charging at VBUS %dmV, but PD reports %dmV", DEFAULT_VBUS_MV, src_power_info.meas.voltage_now); - zassume_equal(src_power_info.meas.current_max, 0, + zassert_equal(src_power_info.meas.current_max, 0, "Charging at VBUS max %dmA, but PD reports %dmA", 0, src_power_info.meas.current_max); } @@ -791,7 +794,7 @@ ZTEST_F(usb_detach_test, verify_detach_source) "Expected Charging at VBUS %dmV, but PD reports %dmV", DEFAULT_VBUS_MV, pd_power_info.meas.voltage_now); - zassume_equal(pd_power_info.meas.current_max, 0, + zassert_equal(pd_power_info.meas.current_max, 0, "Charging at VBUS max %dmA, but PD reports %dmA", 0, pd_power_info.meas.current_max); } diff --git a/zephyr/test/drivers/src/integration/usbc/usb_malfunction_sink.c b/zephyr/test/drivers/src/integration/usbc/usb_malfunction_sink.c new file mode 100644 index 0000000000..c3788791e2 --- /dev/null +++ b/zephyr/test/drivers/src/integration/usbc/usb_malfunction_sink.c @@ -0,0 +1,259 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <stdint.h> +#include <zephyr/sys/byteorder.h> +#include <ztest.h> + +#include "battery_smart.h" +#include "emul/emul_isl923x.h" +#include "emul/emul_smart_battery.h" +#include "emul/tcpc/emul_tcpci_partner_faulty_snk.h" +#include "emul/tcpc/emul_tcpci_partner_snk.h" +#include "tcpm/tcpci.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" +#include "usb_pd.h" + +struct usb_malfunction_sink_fixture { + struct tcpci_partner_data sink; + struct tcpci_faulty_snk_emul_data faulty_snk_ext; + struct tcpci_snk_emul_data snk_ext; + const struct emul *tcpci_emul; + const struct emul *charger_emul; + struct tcpci_faulty_snk_action actions[2]; +}; + +static void +connect_sink_to_port(struct usb_malfunction_sink_fixture *fixture) +{ + /* + * TODO(b/221439302) Updating the TCPCI emulator registers, updating the + * vbus, as well as alerting should all be a part of the connect + * function. + */ + isl923x_emul_set_adc_vbus(fixture->charger_emul, 0); + tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_POWER_STATUS, + TCPC_REG_POWER_STATUS_VBUS_DET); + tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_EXT_STATUS, + TCPC_REG_EXT_STATUS_SAFE0V); + tcpci_tcpc_alert(0); + /* + * TODO(b/226567798) Wait for TCPC init and DRPToggle. It is required, + * because tcpci_emul_reset_rule_before reset registers including + * Looking4Connection bit in CC_STATUS register. + */ + k_sleep(K_SECONDS(1)); + zassume_ok(tcpci_partner_connect_to_tcpci(&fixture->sink, + fixture->tcpci_emul), + NULL); + + /* Wait for PD negotiation and current ramp. + * TODO(b/213906889): Check message timing and contents. + */ + k_sleep(K_SECONDS(10)); +} + +static inline void disconnect_sink_from_port( + struct usb_malfunction_sink_fixture *fixture) +{ + zassume_ok(tcpci_emul_disconnect_partner(fixture->tcpci_emul), NULL); + k_sleep(K_SECONDS(1)); +} + +static void *usb_malfunction_sink_setup(void) +{ + static struct usb_malfunction_sink_fixture test_fixture; + + /* Get references for the emulators */ + test_fixture.tcpci_emul = + emul_get_binding(DT_LABEL(DT_NODELABEL(tcpci_emul))); + test_fixture.charger_emul = + emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul))); + tcpci_emul_set_rev(test_fixture.tcpci_emul, TCPCI_EMUL_REV2_0_VER1_1); + tcpc_config[0].flags = tcpc_config[0].flags | + TCPC_FLAGS_TCPCI_REV2_0; + + /* Initialized the sink to request 5V and 3A */ + tcpci_partner_init(&test_fixture.sink, PD_REV20); + test_fixture.sink.extensions = + tcpci_faulty_snk_emul_init( + &test_fixture.faulty_snk_ext, &test_fixture.sink, + tcpci_snk_emul_init(&test_fixture.snk_ext, + &test_fixture.sink, NULL)); + test_fixture.snk_ext.pdo[1] = + PDO_FIXED(5000, 3000, PDO_FIXED_UNCONSTRAINED); + + return &test_fixture; +} + +static void usb_malfunction_sink_before(void *data) +{ + /* Set chipset to ON, this will set TCPM to DRP */ + test_set_chipset_to_s0(); + + /* TODO(b/214401892): Check why need to give time TCPM to spin */ + k_sleep(K_SECONDS(1)); + +} + +static void usb_malfunction_sink_after(void *data) +{ + struct usb_malfunction_sink_fixture *fixture = data; + + tcpci_faulty_snk_emul_clear_actions_list(&fixture->faulty_snk_ext); + disconnect_sink_from_port(fixture); + tcpci_partner_common_clear_logged_msgs(&fixture->sink); +} + +ZTEST_SUITE(usb_malfunction_sink, drivers_predicate_post_main, + usb_malfunction_sink_setup, + usb_malfunction_sink_before, + usb_malfunction_sink_after, NULL); + +ZTEST_F(usb_malfunction_sink, test_fail_source_cap_and_pd_disable) +{ + struct ec_response_typec_status typec_status; + + /* + * Fail on SourceCapabilities message to make TCPM change PD port state + * to disabled + */ + this->actions[0].action_mask = TCPCI_FAULTY_SNK_FAIL_SRC_CAP; + this->actions[0].count = TCPCI_FAULTY_SNK_INFINITE_ACTION; + tcpci_faulty_snk_emul_append_action(&this->faulty_snk_ext, + &this->actions[0]); + + connect_sink_to_port(this); + + typec_status = host_cmd_typec_status(0); + + /* Device is connected, but PD wasn't able to establish contract */ + zassert_true(typec_status.pd_enabled, NULL); + zassert_true(typec_status.dev_connected, NULL); + zassert_false(typec_status.sop_connected, NULL); +} + +ZTEST_F(usb_malfunction_sink, test_fail_source_cap_and_pd_connect) +{ + struct ec_response_usb_pd_power_info info; + struct ec_response_typec_status typec_status; + + /* + * Fail only few times on SourceCapabilities message to prevent entering + * PE_SRC_Disabled state by TCPM + */ + this->actions[0].action_mask = TCPCI_FAULTY_SNK_FAIL_SRC_CAP; + this->actions[0].count = 3; + tcpci_faulty_snk_emul_append_action(&this->faulty_snk_ext, + &this->actions[0]); + + connect_sink_to_port(this); + + typec_status = host_cmd_typec_status(0); + + zassert_true(typec_status.pd_enabled, NULL); + zassert_true(typec_status.dev_connected, NULL); + zassert_true(typec_status.sop_connected, NULL); + + info = host_cmd_power_info(0); + + zassert_equal(info.role, USB_PD_PORT_POWER_SOURCE, + "Expected role to be %d, but got %d", + USB_PD_PORT_POWER_SOURCE, info.role); + zassert_equal(info.type, USB_CHG_TYPE_NONE, + "Expected type to be %d, but got %d", USB_CHG_TYPE_NONE, + info.type); + zassert_equal(info.meas.voltage_max, 0, + "Expected charge voltage max of 0mV, but got %dmV", + info.meas.voltage_max); + zassert_within( + info.meas.voltage_now, 5000, 500, + "Charging voltage expected to be near 5000mV, but was %dmV", + info.meas.voltage_now); + zassert_equal(info.meas.current_max, 1500, + "Current max expected to be 1500mV, but was %dmV", + info.meas.current_max); + zassert_equal(info.meas.current_lim, 0, + "VBUS max is set to 0mA, but PD is reporting %dmA", + info.meas.current_lim); + zassert_equal(info.max_power, 0, + "Charging expected to be at %duW, but PD max is %duW", + 0, info.max_power); +} + +ZTEST_F(usb_malfunction_sink, test_ignore_source_cap) +{ + struct tcpci_partner_log_msg *msg; + uint16_t header; + bool expect_hard_reset = false; + int msg_cnt = 0; + + this->actions[0].action_mask = TCPCI_FAULTY_SNK_IGNORE_SRC_CAP; + this->actions[0].count = TCPCI_FAULTY_SNK_INFINITE_ACTION; + tcpci_faulty_snk_emul_append_action(&this->faulty_snk_ext, + &this->actions[0]); + + tcpci_partner_common_enable_pd_logging(&this->sink, true); + connect_sink_to_port(this); + tcpci_partner_common_enable_pd_logging(&this->sink, false); + + /* + * If test is failing, printing logged message may be useful to diagnose + * problem: + * tcpci_partner_common_print_logged_msgs(&this->sink); + */ + + /* Check if SourceCapability message alternate with HardReset */ + SYS_SLIST_FOR_EACH_CONTAINER(&this->sink.msg_log, msg, node) { + if (expect_hard_reset) { + zassert_equal(msg->sop, TCPCI_MSG_TX_HARD_RESET, + "Expected message %d to be hard reset", + msg_cnt); + } else { + header = sys_get_le16(msg->buf); + zassert_equal(msg->sop, TCPCI_MSG_SOP, + "Expected message %d to be SOP message, not 0x%x", + msg_cnt, msg->sop); + zassert_not_equal(PD_HEADER_CNT(header), 0, + "Expected message %d to has at least one data object", + msg_cnt); + zassert_equal(PD_HEADER_TYPE(header), + PD_DATA_SOURCE_CAP, + "Expected message %d to be SourceCapabilities, not 0x%x", + msg_cnt, PD_HEADER_TYPE(header)); + } + + msg_cnt++; + expect_hard_reset = !expect_hard_reset; + } +} + +ZTEST_F(usb_malfunction_sink, test_ignore_source_cap_and_pd_disable) +{ + struct ec_response_typec_status typec_status; + + /* + * Ignore first SourceCapabilities message and discard others by sending + * different messages. This will lead to PD disable. + */ + this->actions[0].action_mask = TCPCI_FAULTY_SNK_IGNORE_SRC_CAP; + this->actions[0].count = 1; + tcpci_faulty_snk_emul_append_action(&this->faulty_snk_ext, + &this->actions[0]); + this->actions[1].action_mask = TCPCI_FAULTY_SNK_DISCARD_SRC_CAP; + this->actions[1].count = TCPCI_FAULTY_SNK_INFINITE_ACTION; + tcpci_faulty_snk_emul_append_action(&this->faulty_snk_ext, + &this->actions[1]); + + connect_sink_to_port(this); + + typec_status = host_cmd_typec_status(0); + + /* Device is connected, but PD wasn't able to establish contract */ + zassert_true(typec_status.pd_enabled, NULL); + zassert_true(typec_status.dev_connected, NULL); + zassert_false(typec_status.sop_connected, NULL); +} diff --git a/zephyr/test/drivers/src/integration/usbc/usb_pd_ctrl_msg.c b/zephyr/test/drivers/src/integration/usbc/usb_pd_ctrl_msg.c index ea8a84117a..dd4c805590 100644 --- a/zephyr/test/drivers/src/integration/usbc/usb_pd_ctrl_msg.c +++ b/zephyr/test/drivers/src/integration/usbc/usb_pd_ctrl_msg.c @@ -14,17 +14,23 @@ #include "test/drivers/stubs.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" +#include "test/usb_pe.h" #include "usb_pd.h" #define TEST_USB_PORT USBC_PORT_C0 #define TCPCI_EMUL_LABEL DT_NODELABEL(tcpci_emul) +#define TEST_ADDED_PDO PDO_FIXED(10000, 3000, PDO_FIXED_UNCONSTRAINED) + struct usb_pd_ctrl_msg_test_fixture { - struct tcpci_drp_emul partner_emul; + struct tcpci_partner_data partner_emul; + struct tcpci_snk_emul_data snk_ext; + struct tcpci_src_emul_data src_ext; + struct tcpci_drp_emul_data drp_ext; const struct emul *tcpci_emul; const struct emul *charger_emul; - bool drp_partner_is_sink; + enum pd_power_role drp_partner_pd_role; }; struct usb_pd_ctrl_msg_test_sink_fixture { @@ -35,9 +41,10 @@ struct usb_pd_ctrl_msg_test_source_fixture { struct usb_pd_ctrl_msg_test_fixture fixture; }; -static void tcpci_drp_emul_connect_partner(struct tcpci_drp_emul *partner_emul, - const struct emul *tcpci_emul, - const struct emul *charger_emul) +static void tcpci_drp_emul_connect_partner( + struct tcpci_partner_data *partner_emul, + const struct emul *tcpci_emul, + const struct emul *charger_emul) { /* * TODO(b/221439302) Updating the TCPCI emulator registers, updating the @@ -53,10 +60,7 @@ static void tcpci_drp_emul_connect_partner(struct tcpci_drp_emul *partner_emul, tcpci_tcpc_alert(TEST_USB_PORT); - zassume_ok(tcpci_drp_emul_connect_to_tcpci( - &partner_emul->data, &partner_emul->src_data, - &partner_emul->snk_data, &partner_emul->common_data, - &partner_emul->ops, tcpci_emul), + zassume_ok(tcpci_partner_connect_to_tcpci(partner_emul, tcpci_emul), NULL); } @@ -86,7 +90,7 @@ static void *usb_pd_ctrl_msg_sink_setup(void) struct usb_pd_ctrl_msg_test_fixture *fixture = usb_pd_ctrl_msg_setup_emul(); - fixture->drp_partner_is_sink = true; + fixture->drp_partner_pd_role = PD_ROLE_SINK; return fixture; } @@ -96,7 +100,7 @@ static void *usb_pd_ctrl_msg_source_setup(void) struct usb_pd_ctrl_msg_test_fixture *fixture = usb_pd_ctrl_msg_setup_emul(); - fixture->drp_partner_is_sink = false; + fixture->drp_partner_pd_role = PD_ROLE_SOURCE; return fixture; } @@ -116,16 +120,26 @@ static void usb_pd_ctrl_msg_before(void *data) /* TODO(b/214401892): Check why need to give time TCPM to spin */ k_sleep(K_SECONDS(1)); - tcpci_drp_emul_init(&fixture->partner_emul); - - fixture->partner_emul.data.sink = fixture->drp_partner_is_sink; + /* Initialized DRP */ + tcpci_partner_init(&fixture->partner_emul, PD_REV20); + fixture->partner_emul.extensions = + tcpci_drp_emul_init(&fixture->drp_ext, &fixture->partner_emul, + fixture->drp_partner_pd_role, + tcpci_src_emul_init(&fixture->src_ext, + &fixture->partner_emul, + NULL), + tcpci_snk_emul_init(&fixture->snk_ext, + &fixture->partner_emul, + NULL)); + /* Add additional Sink PDO to partner to verify + * PE_DR_SNK_Get_Sink_Cap/PE_SRC_Get_Sink_Cap (these are shared PE + * states) state was reached + */ + fixture->snk_ext.pdo[1] = TEST_ADDED_PDO; /* Turn TCPCI rev 2 ON */ tcpc_config[TEST_USB_PORT].flags |= TCPC_FLAGS_TCPCI_REV2_0; - /* Reset to disconnected state */ - disconnect_partner(fixture); - tcpci_drp_emul_connect_partner(&fixture->partner_emul, fixture->tcpci_emul, fixture->charger_emul); @@ -162,7 +176,7 @@ ZTEST_F(usb_pd_ctrl_msg_test_sink, verify_vconn_swap) "SNK Returned vconn_role=%u", snk_resp.vconn_role); /* Send VCONN_SWAP request */ - rv = tcpci_partner_send_control_msg(&fixture->partner_emul.common_data, + rv = tcpci_partner_send_control_msg(&fixture->partner_emul, PD_CTRL_VCONN_SWAP, 0); zassert_ok(rv, "Failed to send VCONN_SWAP request, rv=%d", rv); @@ -187,16 +201,16 @@ ZTEST_F(usb_pd_ctrl_msg_test_sink, verify_pr_swap) /* Ignore ACCEPT in common handler for PR Swap request, * causes soft reset */ - tcpci_partner_common_handler_mask_msg( - &fixture->partner_emul.common_data, PD_CTRL_ACCEPT, true); + tcpci_partner_common_handler_mask_msg(&fixture->partner_emul, + PD_CTRL_ACCEPT, true); /* Send PR_SWAP request */ - rv = tcpci_partner_send_control_msg(&fixture->partner_emul.common_data, + rv = tcpci_partner_send_control_msg(&fixture->partner_emul, PD_CTRL_PR_SWAP, 0); zassert_ok(rv, "Failed to send PR_SWAP request, rv=%d", rv); /* Send PS_RDY request */ - rv = tcpci_partner_send_control_msg(&fixture->partner_emul.common_data, + rv = tcpci_partner_send_control_msg(&fixture->partner_emul, PD_CTRL_PS_RDY, 15); zassert_ok(rv, "Failed to send PS_RDY request, rv=%d", rv); @@ -250,7 +264,7 @@ ZTEST_F(usb_pd_ctrl_msg_test_source, verify_dr_swap_rejected) "Returned data_role=%u", typec_status.data_role); /* Send DR_SWAP request */ - rv = tcpci_partner_send_control_msg(&fixture->partner_emul.common_data, + rv = tcpci_partner_send_control_msg(&fixture->partner_emul, PD_CTRL_DR_SWAP, 0); zassert_ok(rv, "Failed to send DR_SWAP request, rv=%d", rv); @@ -290,3 +304,99 @@ ZTEST_F(usb_pd_ctrl_msg_test_source, verify_dpm_dr_swap) zassert_equal(PD_ROLE_UFP, typec_status.data_role, "Returned data_role=%u", typec_status.data_role); } + +/** + * @brief TestPurpose: Verify TCPM initiates Get_Sink_Cap message during a typec + * status host command and receives sink_capabilities message. + * + * @details + * - TCPM is configured initially as Sink + * - TypeC Status Host Command is Invoked + * + * Expected Results + * - TypeC Status Host Command reveals sink capabilility PDOs. + */ +ZTEST(usb_pd_ctrl_msg_test_source, verify_dpm_get_sink_cap) +{ + struct ec_response_typec_status typec_status = { 0 }; + + typec_status = host_cmd_typec_status(TEST_USB_PORT); + + zassert_true(typec_status.sink_cap_count > 1, NULL); + zassert_equal(typec_status.sink_cap_pdos[1], TEST_ADDED_PDO, NULL); +} + +/** + * @brief TestPurpose: Verify TCPM initiates Get_Sink_Cap message during a typec + * status host command and receives sink_capabilities message. + * + * @details + * - TCPM is configured initially as Source + * - TypeC Status Host Command is Invoked + * + * Expected Results + * - TypeC Status Host Command reveals sink capabilility PDOs. + */ +ZTEST(usb_pd_ctrl_msg_test_sink, verify_get_sink_cap) +{ + struct ec_response_typec_status typec_status = { 0 }; + + typec_status = host_cmd_typec_status(TEST_USB_PORT); + + zassert_true(typec_status.sink_cap_count > 1, NULL); + zassert_equal(typec_status.sink_cap_pdos[1], TEST_ADDED_PDO, NULL); +} + +/** + * @brief TestPurpose: Verify BIST TX MODE 2. + * + * @details + * - TCPM is configured initially as Sink + * - Initiate BIST TX + * + * Expected Results + * - BIST occurs and we transition back to READY state + */ +ZTEST_F(usb_pd_ctrl_msg_test_source, verify_bist_tx_mode2) +{ + struct usb_pd_ctrl_msg_test_fixture *fixture = &this->fixture; + uint32_t bdo = BDO(BDO_MODE_CARRIER2, 0); + + tcpci_partner_send_data_msg(&fixture->partner_emul, + PD_DATA_BIST, &bdo, 1, 0); + + pd_dpm_request(TEST_USB_PORT, DPM_REQUEST_BIST_TX); + k_sleep(K_MSEC(10)); + zassert_equal(get_state_pe(TEST_USB_PORT), PE_BIST_TX, NULL); + + k_sleep(K_SECONDS(5)); + zassert_equal(get_state_pe(TEST_USB_PORT), PE_SNK_READY, NULL); +} + +/** + * @brief TestPurpose: Verify BIST TX TEST DATA. + * + * @details + * - TCPM is configured initially as Sink + * - Initiate BIST TX + * - End testing via signaling a Hard Reset + * + * Expected Results + * - Partner remains in BIST_TX state until hard reset is received. + */ +ZTEST_F(usb_pd_ctrl_msg_test_source, verify_bist_tx_test_data) +{ + struct usb_pd_ctrl_msg_test_fixture *fixture = &this->fixture; + uint32_t bdo = BDO(BDO_MODE_TEST_DATA, 0); + + tcpci_partner_send_data_msg(&fixture->partner_emul, + PD_DATA_BIST, &bdo, 1, 0); + + pd_dpm_request(TEST_USB_PORT, DPM_REQUEST_BIST_TX); + k_sleep(K_SECONDS(5)); + zassert_equal(get_state_pe(TEST_USB_PORT), PE_BIST_TX, NULL); + + tcpci_partner_common_send_hard_reset(&fixture->partner_emul); + k_sleep(K_SECONDS(1)); + zassert_equal(get_state_pe(TEST_USB_PORT), PE_SNK_READY, NULL); +} diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c index 047090ebbb..203a2ed979 100644 --- a/zephyr/test/drivers/src/isl923x.c +++ b/zephyr/test/drivers/src/isl923x.c @@ -4,7 +4,7 @@ */ #include <ztest.h> -#include <drivers/emul.h> +#include <zephyr/drivers/emul.h> #include <fff.h> #include "battery.h" @@ -597,7 +597,7 @@ ZTEST(isl923x, test_init) &input_current), NULL); zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", input_current); + "Expected input current 0mA but got %dmA", input_current); /* Test failed CTRL2 register write */ isl923x_emul_reset_registers(isl923x_emul); @@ -609,7 +609,7 @@ ZTEST(isl923x, test_init) &input_current), NULL); zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", input_current); + "Expected input current 0mA but got %dmA", input_current); /* Test failed CTRL 0 read */ isl923x_emul_reset_registers(isl923x_emul); @@ -620,15 +620,10 @@ ZTEST(isl923x, test_init) zassert_ok(isl923x_drv.get_input_current_limit(CHARGER_NUM, &input_current), NULL); - if (IS_ENABLED(CONFIG_CHARGE_RAMP_HW)) { - zassert_equal(512, input_current, - "Expected input current 512mV but got %dmV", - input_current); - } else { - zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", + + zassert_equal(0, input_current, + "Expected input current 0mA but got %dmA", input_current); - } /* Test failed CTRL 0 write */ isl923x_emul_reset_registers(isl923x_emul); @@ -639,15 +634,10 @@ ZTEST(isl923x, test_init) zassert_ok(isl923x_drv.get_input_current_limit(CHARGER_NUM, &input_current), NULL); - if (IS_ENABLED(CONFIG_CHARGE_RAMP_HW)) { - zassert_equal(512, input_current, - "Expected input current 512mV but got %dmV", - input_current); - } else { - zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", + + zassert_equal(0, input_current, + "Expected input current 0mA but got %dmA", input_current); - } /* Test failed CTRL 3 read */ isl923x_emul_reset_registers(isl923x_emul); @@ -659,7 +649,7 @@ ZTEST(isl923x, test_init) &input_current), NULL); zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", input_current); + "Expected input current 0mA but got %dmA", input_current); /* Test failed CTRL 3 write */ isl923x_emul_reset_registers(isl923x_emul); @@ -671,7 +661,7 @@ ZTEST(isl923x, test_init) &input_current), NULL); zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", input_current); + "Expected input current 0mA but got %dmA", input_current); /* Test failed write adapter current limit */ isl923x_emul_reset_registers(isl923x_emul); @@ -684,7 +674,7 @@ ZTEST(isl923x, test_init) &input_current), NULL); zassert_equal(0, input_current, - "Expected input current 0mV but got %dmV", input_current); + "Expected input current 0mA but got %dmA", input_current); } ZTEST(isl923x, test_init_late_jump) @@ -1067,9 +1057,8 @@ ZTEST(isl923x_hibernate, test_isl9238c_resume) /* Part 1: Happy path */ control1_expected = - (isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL1) & - ~ISL923X_C1_DISABLE_MON) | ISL923X_C1_ENABLE_PSYS - ; + isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL1) | + ISL923X_C1_ENABLE_PSYS; control2_expected = isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL2) & ~ISL923X_C2_COMPARATOR; diff --git a/zephyr/test/drivers/src/keyboard_scan.c b/zephyr/test/drivers/src/keyboard_scan.c index 6d438c2b76..209c5320e0 100644 --- a/zephyr/test/drivers/src/keyboard_scan.c +++ b/zephyr/test/drivers/src/keyboard_scan.c @@ -3,9 +3,9 @@ * found in the LICENSE file. */ #include <ztest.h> -#include <drivers/emul.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <emul/emul_kb_raw.h> #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/src/lid_switch.c b/zephyr/test/drivers/src/lid_switch.c index c4794741fb..42d91495f4 100644 --- a/zephyr/test/drivers/src/lid_switch.c +++ b/zephyr/test/drivers/src/lid_switch.c @@ -4,11 +4,11 @@ */ #include <ztest.h> -#include <drivers/emul.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <lid_switch.h> -#include <shell/shell_dummy.h> +#include <zephyr/shell/shell_dummy.h> #include <console.h> #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/src/lis2dw12.c b/zephyr/test/drivers/src/lis2dw12.c index 07faee0427..56f71cc406 100644 --- a/zephyr/test/drivers/src/lis2dw12.c +++ b/zephyr/test/drivers/src/lis2dw12.c @@ -4,7 +4,7 @@ */ #include <ztest.h> -#include <drivers/emul.h> +#include <zephyr/drivers/emul.h> #include "driver/accel_lis2dw12.h" #include "emul/emul_common_i2c.h" #include "emul/emul_lis2dw12.h" diff --git a/zephyr/test/drivers/src/ln9310.c b/zephyr/test/drivers/src/ln9310.c index 9ff018fdba..e4bf37c4bd 100644 --- a/zephyr/test/drivers/src/ln9310.c +++ b/zephyr/test/drivers/src/ln9310.c @@ -4,10 +4,10 @@ */ #include <ztest.h> -#include <drivers/emul.h> -#include <kernel.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/kernel.h> #include <ztest_assert.h> -#include <drivers/i2c_emul.h> +#include <zephyr/drivers/i2c_emul.h> #include "driver/ln9310.h" #include "emul/emul_ln9310.h" diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c index 062d8224bd..319d42e3ad 100644 --- a/zephyr/test/drivers/src/main.c +++ b/zephyr/test/drivers/src/main.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ec_app_main.h" #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/src/panic.c b/zephyr/test/drivers/src/panic.c index 3dba6e0cfd..2615c22156 100644 --- a/zephyr/test/drivers/src/panic.c +++ b/zephyr/test/drivers/src/panic.c @@ -8,10 +8,10 @@ * @brief Unit Tests for panic. */ -#include <device.h> +#include <zephyr/device.h> -#include <logging/log.h> -#include <zephyr.h> +#include <zephyr/logging/log.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/power_common.c b/zephyr/test/drivers/src/power_common.c index 59e8db1f45..03832b6c0c 100644 --- a/zephyr/test/drivers/src/power_common.c +++ b/zephyr/test/drivers/src/power_common.c @@ -4,10 +4,10 @@ */ #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> -#include <shell/shell.h> -#include <shell/shell_uart.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_uart.h> #include "chipset.h" #include "common.h" @@ -496,6 +496,9 @@ ZTEST(power_common_hibernation, test_power_hc_hibernation_delay) uint32_t h_delay; int sleep_time; + /* Ensure the lid is closed so AC connect does not boot system */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "lidclose"), NULL); + zassert_equal(power_get_state(), POWER_G3, "Power state is %d, expected G3", power_get_state()); /* This is a no-op, but it will reset the last_shutdown_time. */ diff --git a/zephyr/test/drivers/src/ppc_sn5s330.c b/zephyr/test/drivers/src/ppc_sn5s330.c index bede67c52e..bd38f874f7 100644 --- a/zephyr/test/drivers/src/ppc_sn5s330.c +++ b/zephyr/test/drivers/src/ppc_sn5s330.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <kernel.h> -#include <device.h> -#include <devicetree.h> -#include <drivers/emul.h> +#include <zephyr/kernel.h> +#include <zephyr/device.h> +#include <zephyr/devicetree.h> +#include <zephyr/drivers/emul.h> #include <ztest.h> #include <fff.h> diff --git a/zephyr/test/drivers/src/ppc_syv682c.c b/zephyr/test/drivers/src/ppc_syv682c.c index 4e257c8dee..9707f374ac 100644 --- a/zephyr/test/drivers/src/ppc_syv682c.c +++ b/zephyr/test/drivers/src/ppc_syv682c.c @@ -3,15 +3,16 @@ * found in the LICENSE file. */ -#include <device.h> -#include <devicetree/gpio.h> -#include <drivers/gpio/gpio_emul.h> -#include <zephyr.h> +#include <zephyr/device.h> +#include <zephyr/devicetree/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <fff.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include <ztest_assert.h> +#include "emul/emul_common_i2c.h" #include "emul/emul_syv682x.h" - #include "test/drivers/stubs.h" #include "syv682x.h" #include "timer.h" @@ -23,8 +24,32 @@ #define GPIO_USB_C1_FRS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_FRS_EN_PATH, gpios) +/* Configuration for a mock I2C access function that sometimes fails. */ +struct reg_to_fail_data { + int reg_access_to_fail; + int reg_access_fail_countdown; +}; + static const int syv682x_port = 1; +static void syv682x_test_after(void *data) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + ARG_UNUSED(data); + + syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + SYV682X_CONTROL_4_NONE); + + /* Clear the mock read/write functions */ + i2c_common_emul_set_read_func(emul, NULL, NULL); + i2c_common_emul_set_write_func(emul, NULL, NULL); + + /* Don't fail on any register access */ + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + ZTEST(ppc_syv682c, test_syv682x_board_is_syv682c) { zassert_true(syv682x_board_is_syv682c(syv682x_port), NULL); @@ -522,6 +547,16 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_sink_oc_limit) "Sink disable failed"); } +ZTEST(ppc_syv682c, test_syv682x_set_vconn) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + SYV682X_CONTROL_4_VBAT_OVP); + zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, + "VBAT OVP, but ppc_set_vconn succeeded"); +} + ZTEST(ppc_syv682c, test_syv682x_ppc_dump) { /* @@ -533,4 +568,150 @@ ZTEST(ppc_syv682c, test_syv682x_ppc_dump) zassert_ok(drv->reg_dump(syv682x_port), "ppc_dump command failed"); } -ZTEST_SUITE(ppc_syv682c, drivers_predicate_post_main, NULL, NULL, NULL, NULL); +/* Intercepts I2C reads as a mock. Fails to read for the register at offset + * reg_access_to_fail on read number N, where N is the initial value of + * reg_access_fail_countdown. + */ +static int mock_read_intercept_reg_fail(struct i2c_emul *emul, int reg, + uint8_t *val, int bytes, void *data) +{ + struct reg_to_fail_data *test_data = data; + + if (reg == test_data->reg_access_to_fail) { + test_data->reg_access_fail_countdown--; + if (test_data->reg_access_fail_countdown <= 0) + return -1; + } + return 1; +} + +ZTEST(ppc_syv682c, test_syv682x_i2c_error_status) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + /* Failed STATUS read should cause init to fail. */ + i2c_common_emul_set_read_fail_reg(emul, SYV682X_STATUS_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "STATUS read error, but init succeeded"); + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + +ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_1) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + const struct ppc_drv *drv = ppc_chips[syv682x_port].drv; + struct reg_to_fail_data reg_fail = { + .reg_access_to_fail = 0, + .reg_access_fail_countdown = 0, + }; + + /* Failed CONTROL_1 read */ + i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_1_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_1 read error, but init succeeded"); + zassert_not_equal(ppc_vbus_source_enable(syv682x_port, true), + EC_SUCCESS, + "CONTROL_1 read error, but VBUS source enable " + "succeeded"); + zassert_not_equal(ppc_vbus_sink_enable(syv682x_port, true), EC_SUCCESS, + "CONTROL_1 read error, but VBUS sink enable " + "succeeded"); + zassert_not_equal(ppc_set_vbus_source_current_limit(syv682x_port, + TYPEC_RP_USB), + EC_SUCCESS, + "CONTROL_1 read error, but set current limit " + "succeeded"); + zassert_ok(drv->reg_dump(syv682x_port), + "CONTROL_1 read error, and ppc_dump failed"); + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Init reads CONTROL_1 several times. The 3rd read happens while + * setting the source current limit. Check that init fails when that + * read fails. + */ + i2c_common_emul_set_read_func(emul, &mock_read_intercept_reg_fail, + ®_fail); + reg_fail.reg_access_to_fail = SYV682X_CONTROL_1_REG; + reg_fail.reg_access_fail_countdown = 3; + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_1 read error, but init succeeded"); + i2c_common_emul_set_read_func(emul, NULL, NULL); + + /* Failed CONTROL_1 write */ + i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_1_REG); + + /* During init, the driver will write CONTROL_1 either to disable all + * power paths (normal case) or to enable the sink path (dead battery + * case). vSafe0V in STATUS is one indication of the normal case. + */ + syv682x_emul_set_condition(emul, SYV682X_STATUS_VSAFE_0V, + SYV682X_CONTROL_4_NONE); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_1 write error, but init succeeded"); + syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + SYV682X_CONTROL_4_NONE); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_1 write error, but init succeeded"); + + zassert_not_equal(ppc_vbus_source_enable(syv682x_port, true), + EC_SUCCESS, + "CONTROL_1 write error, but VBUS source " + "enable succeeded"); + i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + +ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_2) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + /* Failed CONTROL_2 read */ + i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_2_REG); + zassert_not_equal(ppc_discharge_vbus(syv682x_port, true), EC_SUCCESS, + "CONTROL_2 read error, but VBUS discharge succeeded"); + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Failed CONTROL_2 write */ + i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_2_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_2 write error, but init succeeded"); + i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + +ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_3) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + /* Failed CONTROL_3 read */ + i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_3_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_3 read error, but VBUS discharge succeeded"); + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Failed CONTROL_3 write */ + i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_3_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_3 write error, but init succeeded"); + i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + +ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_4) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + + /* Failed CONTROL_4 read */ + i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_4_REG); + zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, + "CONTROL_2 read error, but VCONN set succeeded"); + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Failed CONTROL_4 write */ + i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_4_REG); + zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, + "CONTROL_4 write error, but init succeeded"); + zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, + "CONTROL_4 write error, but VCONN set succeeded"); + i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); +} + +ZTEST_SUITE(ppc_syv682c, drivers_predicate_post_main, NULL, NULL, + syv682x_test_after, NULL); diff --git a/zephyr/test/drivers/src/ps8xxx.c b/zephyr/test/drivers/src/ps8xxx.c index b30d9ef0c3..dc1695d793 100644 --- a/zephyr/test/drivers/src/ps8xxx.c +++ b/zephyr/test/drivers/src/ps8xxx.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/smart.c b/zephyr/test/drivers/src/smart.c index f80563a40f..3628a68d3e 100644 --- a/zephyr/test/drivers/src/smart.c +++ b/zephyr/test/drivers/src/smart.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <shell/shell.h> -#include <shell/shell_uart.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_uart.h> #include "common.h" #include "console.h" diff --git a/zephyr/test/drivers/src/stm_mems_common.c b/zephyr/test/drivers/src/stm_mems_common.c index 358c20ee3d..fef0766c7d 100644 --- a/zephyr/test/drivers/src/stm_mems_common.c +++ b/zephyr/test/drivers/src/stm_mems_common.c @@ -4,8 +4,8 @@ */ #include <ztest.h> -#include <device.h> -#include <devicetree.h> +#include <zephyr/device.h> +#include <zephyr/devicetree.h> #include <errno.h> #include "common.h" diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c index d1a56b5fec..84ae387fb4 100644 --- a/zephyr/test/drivers/src/stubs.c +++ b/zephyr/test/drivers/src/stubs.c @@ -27,7 +27,7 @@ #include "usbc_ppc.h" #include "charge_state_v2.h" -#include <logging/log.h> +#include <zephyr/logging/log.h> LOG_MODULE_REGISTER(stubs); #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) @@ -53,22 +53,6 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { }; BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT); -/* Charger Chip Configuration */ -const struct charger_config_t chg_chips[] = { -#ifdef CONFIG_PLATFORM_EC_CHARGER_ISL9238 - { - .i2c_port = I2C_PORT_CHARGER, - .i2c_addr_flags = ISL923X_ADDR_FLAGS, - .drv = &isl923x_drv, - }, -#endif -}; - -uint8_t board_get_charger_chip_count(void) -{ - return ARRAY_SIZE(chg_chips); -} - int board_set_active_charge_port(int port) { int is_real_port = (port >= 0 && diff --git a/zephyr/test/drivers/src/tcpci.c b/zephyr/test/drivers/src/tcpci.c index 972f9fd326..167744f3a9 100644 --- a/zephyr/test/drivers/src/tcpci.c +++ b/zephyr/test/drivers/src/tcpci.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "common.h" #include "ec_tasks.h" diff --git a/zephyr/test/drivers/src/tcpci_test_common.c b/zephyr/test/drivers/src/tcpci_test_common.c index 41b0c2db99..ccd250e11f 100644 --- a/zephyr/test/drivers/src/tcpci_test_common.c +++ b/zephyr/test/drivers/src/tcpci_test_common.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/tcs3400.c b/zephyr/test/drivers/src/tcs3400.c index 8b29259244..66955481f7 100644 --- a/zephyr/test/drivers/src/tcs3400.c +++ b/zephyr/test/drivers/src/tcs3400.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/drivers/src/temp_sensor.c b/zephyr/test/drivers/src/temp_sensor.c index c9469476e1..1a49dba8ca 100644 --- a/zephyr/test/drivers/src/temp_sensor.c +++ b/zephyr/test/drivers/src/temp_sensor.c @@ -3,12 +3,12 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/adc.h> -#include <drivers/adc/adc_emul.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/adc.h> +#include <zephyr/drivers/adc/adc_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <math.h> diff --git a/zephyr/test/drivers/src/thermistor.c b/zephyr/test/drivers/src/thermistor.c index bc7bc35214..e760e0cf33 100644 --- a/zephyr/test/drivers/src/thermistor.c +++ b/zephyr/test/drivers/src/thermistor.c @@ -3,12 +3,12 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/adc.h> -#include <drivers/adc/adc_emul.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/drivers/adc.h> +#include <zephyr/drivers/adc/adc_emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <temp_sensor.h> #include "common.h" diff --git a/zephyr/test/drivers/src/uart_hostcmd.c b/zephyr/test/drivers/src/uart_hostcmd.c new file mode 100644 index 0000000000..0e68c440ce --- /dev/null +++ b/zephyr/test/drivers/src/uart_hostcmd.c @@ -0,0 +1,231 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/zephyr.h> +#include <ztest.h> + +#include "console.h" +#include "host_command.h" +#include "uart.h" +#include "test/drivers/test_state.h" + +/** Messages used in test */ +static const char msg1[] = "test"; +static const char msg2[] = "uart_hostcmd"; +static const char msg3[] = "message3"; + +/** Length of message excluding NULL char at the end */ +#define MSG_LEN(msg) (sizeof(msg) - 1) + +/** + * Write message 1 before first snapshot. Read everything from buffer. Create + * second snapshot. Write message 2 after it. + */ +static void setup_snapshots_and_messages(void *unused) +{ + char response[1024]; + struct host_cmd_handler_args read_args = + BUILD_HOST_COMMAND_RESPONSE(EC_CMD_CONSOLE_READ, 0, response); + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_SIMPLE(EC_CMD_CONSOLE_SNAPSHOT, 0); + + /* Set first snapshot before first message */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&args), NULL); + cputs(CC_COMMAND, msg1); + + /* Read everything from buffer */ + do { + /* Clear response size before executing command */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), + NULL); + } while (read_args.response_size != 0); + + /* Set second snapshot after first message */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&args), NULL); + cputs(CC_COMMAND, msg2); +} + +/** + * Test if read next variant of console read host command is working. ver + * argument allows to change version of command. In case of version 1, parameter + * with sub command is provided. + */ +static void test_uart_hc_read_next(int ver) +{ + /* Should be able to read whole buffer in one command */ + char response[CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE_BUF_SIZE + 1]; + struct ec_params_console_read_v1 params; + struct host_cmd_handler_args read_args = + BUILD_HOST_COMMAND_RESPONSE(EC_CMD_CONSOLE_READ, ver, response); + struct host_cmd_handler_args snap_args = + BUILD_HOST_COMMAND_SIMPLE(EC_CMD_CONSOLE_SNAPSHOT, 0); + char *msg1_start; + char *msg2_start; + char *msg3_start; + + /* Set up host command parameters */ + if (ver == 1) { + read_args.params = ¶ms; + read_args.params_size = sizeof(params); + params.subcmd = CONSOLE_READ_NEXT; + } + + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + + /* + * Whole buffer until snapshot should be in response, check if it ends + * with message 1 which should start at the end of response excluding + * NULL char. + */ + msg1_start = response + read_args.response_size - 1 - MSG_LEN(msg1); + zassert_mem_equal(msg1, msg1_start, MSG_LEN(msg1), + "expected \"%s\", got \"%.*s\"", + msg1, MSG_LEN(msg1), msg1_start); + + /* Set new snapshot which should include message 2 */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&snap_args), NULL); + + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + + /* + * Whole buffer should be in response, check if it ends with both + * messages. Message 2 should start at the end of response excluding + * NULL char. + */ + msg2_start = response + read_args.response_size - 1 - MSG_LEN(msg2); + msg1_start = msg2_start - MSG_LEN(msg1); + zassert_mem_equal(msg2, msg2_start, MSG_LEN(msg2), + "expected \"%s\", got \"%.*s\"", + msg2, MSG_LEN(msg2), msg2_start); + zassert_mem_equal(msg1, msg1_start, MSG_LEN(msg1), + "expected \"%s\", got \"%.*s\"", + msg1, MSG_LEN(msg1), msg1_start); + + /* Append third message */ + cputs(CC_COMMAND, msg3); + + /* Check read next without new snapshot, no data should be read */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal(0, read_args.response_size, + "expected message length 0, got %d", + read_args.response_size); + + /* Set new snapshot which should include message 3 */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&snap_args), NULL); + + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + + msg3_start = response + read_args.response_size - 1 - MSG_LEN(msg3); + msg2_start = msg3_start - MSG_LEN(msg2); + msg1_start = msg2_start - MSG_LEN(msg1); + zassert_mem_equal(msg3, msg3_start, MSG_LEN(msg3), + "expected \"%s\", got \"%.*s\"", + msg3, MSG_LEN(msg3), msg3_start); + zassert_mem_equal(msg2, msg2_start, MSG_LEN(msg2), + "expected \"%s\", got \"%.*s\"", + msg2, MSG_LEN(msg2), msg2_start); + zassert_mem_equal(msg1, msg1_start, MSG_LEN(msg1), + "expected \"%s\", got \"%.*s\"", + msg1, MSG_LEN(msg1), msg1_start); +} + +ZTEST_USER(uart_hostcmd, test_uart_hc_read_next_v0) +{ + test_uart_hc_read_next(0); +} + +ZTEST_USER(uart_hostcmd, test_uart_hc_read_next_v1) +{ + test_uart_hc_read_next(1); +} + +/** Test if read recent variant of console read host command is working */ +ZTEST_USER(uart_hostcmd, test_uart_hc_read_recent_v1) +{ + /* Should be able to read whole buffer in one command */ + char response[CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE_BUF_SIZE + 1]; + struct ec_params_console_read_v1 params; + struct host_cmd_handler_args read_args = + BUILD_HOST_COMMAND(EC_CMD_CONSOLE_READ, 1, response, params); + struct host_cmd_handler_args snap_args = + BUILD_HOST_COMMAND_SIMPLE(EC_CMD_CONSOLE_SNAPSHOT, 0); + + params.subcmd = CONSOLE_READ_RECENT; + + /* Only message 1 which is between two last snapshots should be read */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + /* Account additional NULL char at the end */ + zassert_equal(MSG_LEN(msg1) + 1, read_args.response_size, + "expected message length %d, got %d", + MSG_LEN(msg1) + 1, read_args.response_size); + zassert_mem_equal(msg1, response, MSG_LEN(msg1), + "expected \"%s\", got \"%.*s\"", + msg1, MSG_LEN(msg1), response); + + /* Set new snapshot after second message */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&snap_args), NULL); + + /* Only message between two last snapshots should be read */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + /* Account additional NULL char at the end */ + zassert_equal(MSG_LEN(msg2) + 1, read_args.response_size, + "expected message length %d, got %d", + MSG_LEN(msg2) + 1, read_args.response_size); + zassert_mem_equal(msg2, response, MSG_LEN(msg2), + "expected \"%s\", got \"%.*s\"", + msg2, MSG_LEN(msg2), response); + + /* Append third message */ + cputs(CC_COMMAND, msg3); + + /* Check that message is not read without setting snapshot */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal(0, read_args.response_size, + "expected message length 0, got %d", + read_args.response_size); + + /* Set new snapshot */ + zassert_equal(EC_RES_SUCCESS, host_command_process(&snap_args), NULL); + + /* This time only third message should be read */ + read_args.response_size = 0; + zassert_equal(EC_RES_SUCCESS, host_command_process(&read_args), NULL); + zassert_equal('\0', response[read_args.response_size], + "Last byte of response is not '\\0' (got 0x%x)", + response[read_args.response_size]); + /* Account additional NULL char at the end */ + zassert_equal(MSG_LEN(msg3) + 1, read_args.response_size, + "expected message length %d, got %d", + MSG_LEN(msg3) + 1, read_args.response_size); + zassert_mem_equal(msg3, response, MSG_LEN(msg3), + "expected \"%s\", got \"%.*s\"", + msg3, MSG_LEN(msg3), response); +} + +ZTEST_SUITE(uart_hostcmd, drivers_predicate_post_main, NULL, + setup_snapshots_and_messages, NULL, NULL); diff --git a/zephyr/test/drivers/src/usb_mux.c b/zephyr/test/drivers/src/usb_mux.c index bd3024ae44..09aa3c47d6 100644 --- a/zephyr/test/drivers/src/usb_mux.c +++ b/zephyr/test/drivers/src/usb_mux.c @@ -3,13 +3,13 @@ * found in the LICENSE file. */ -#include <kernel.h> -#include <zephyr.h> +#include <zephyr/kernel.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <drivers/gpio.h> -#include <drivers/gpio/gpio_emul.h> -#include <shell/shell.h> -#include <shell/shell_uart.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_uart.h> #include "common.h" #include "ec_commands.h" diff --git a/zephyr/test/drivers/src/usb_pd_host_cmd.c b/zephyr/test/drivers/src/usb_pd_host_cmd.c index 520973a248..5eb589043c 100644 --- a/zephyr/test/drivers/src/usb_pd_host_cmd.c +++ b/zephyr/test/drivers/src/usb_pd_host_cmd.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "ec_commands.h" diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index a639b63d17..5ba78043b1 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -3,10 +3,10 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> -#include <shell/shell_uart.h> -#include <drivers/gpio/gpio_emul.h> +#include <zephyr/shell/shell_uart.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include "battery.h" #include "battery_smart.h" @@ -71,18 +71,16 @@ void test_set_chipset_to_g3(void) power_get_state()); } -void connect_source_to_port(struct tcpci_src_emul *src, int pdo_index, +void connect_source_to_port(struct tcpci_partner_data *partner, + struct tcpci_src_emul_data *src, int pdo_index, const struct emul *tcpci_emul, const struct emul *charger_emul) { set_ac_enabled(true); - zassume_ok(tcpci_src_emul_connect_to_tcpci(&src->data, - &src->common_data, &src->ops, - tcpci_emul), - NULL); + zassume_ok(tcpci_partner_connect_to_tcpci(partner, tcpci_emul), NULL); isl923x_emul_set_adc_vbus(charger_emul, - PDO_FIXED_GET_VOLT(src->data.pdo[pdo_index])); + PDO_FIXED_GET_VOLT(src->pdo[pdo_index])); k_sleep(K_SECONDS(10)); } @@ -155,7 +153,172 @@ int host_cmd_motion_sense_ec_rate(uint8_t sensor_num, int data_rate_ms, struct host_cmd_handler_args args = BUILD_HOST_COMMAND( EC_CMD_MOTION_SENSE_CMD, 1, *response, params); - printk("sensor_num=%u/%u\n", params.sensor_odr.sensor_num, sensor_num); + return host_command_process(&args); +} + +int host_cmd_motion_sense_odr(uint8_t sensor_num, int32_t odr, bool round_up, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SENSOR_ODR, + .sensor_odr = { + .sensor_num = sensor_num, + .data = odr, + .roundup = round_up, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_range(uint8_t sensor_num, int32_t range, + bool round_up, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SENSOR_RANGE, + .sensor_range = { + .sensor_num = sensor_num, + .data = range, + .roundup = round_up, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_offset(uint8_t sensor_num, uint16_t flags, + int16_t temperature, int16_t offset_x, + int16_t offset_y, int16_t offset_z, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SENSOR_OFFSET, + .sensor_offset = { + .sensor_num = sensor_num, + .flags = flags, + .temp = temperature, + .offset = { offset_x, offset_y, offset_z }, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_scale(uint8_t sensor_num, uint16_t flags, + int16_t temperature, int16_t scale_x, + int16_t scale_y, int16_t scale_z, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SENSOR_SCALE, + .sensor_scale = { + .sensor_num = sensor_num, + .flags = flags, + .temp = temperature, + .scale = { scale_x, scale_y, scale_z }, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_calib(uint8_t sensor_num, bool enable, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_PERFORM_CALIB, + .perform_calib = { + .sensor_num = sensor_num, + .enable = enable, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_fifo_flush(uint8_t sensor_num, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_FLUSH, + .sensor_odr = { + .sensor_num = sensor_num, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_fifo_info(struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_INFO, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_fifo_read(uint8_t buffer_length, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_READ, + .fifo_read = { + .max_data_vector = buffer_length, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_int_enable(int8_t enable, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_INT_ENABLE, + .fifo_int_enable = { + .enable = enable, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + +int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, + int16_t values0, int16_t values1, + int16_t values2, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SPOOF, + .spoof = { + .sensor_id = sensor_num, + .spoof_enable = enable, + .components = { values0, values1, values2 }, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + return host_command_process(&args); } @@ -165,8 +328,8 @@ void host_cmd_typec_discovery(int port, enum typec_partner_type partner_type, struct ec_params_typec_discovery params = { .port = port, .partner_type = partner_type }; - struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS( - EC_CMD_TYPEC_DISCOVERY, 0, params); + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_DISCOVERY, 0, params); /* The expected response to EC_CMD_TYPEC_DISCOVERY extends beyond the * bounds of struct ec_response_typec_discovery. */ diff --git a/zephyr/test/drivers/src/vboot_hash.c b/zephyr/test/drivers/src/vboot_hash.c index aabffbbe74..ac23b95b02 100644 --- a/zephyr/test/drivers/src/vboot_hash.c +++ b/zephyr/test/drivers/src/vboot_hash.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <zephyr.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include <sha256.h> diff --git a/zephyr/test/drivers/src/watchdog.c b/zephyr/test/drivers/src/watchdog.c index acd8edc41a..d66ee77bd8 100644 --- a/zephyr/test/drivers/src/watchdog.c +++ b/zephyr/test/drivers/src/watchdog.c @@ -8,11 +8,11 @@ * @brief Unit Tests for watchdog. */ -#include <device.h> -#include <drivers/watchdog.h> +#include <zephyr/device.h> +#include <zephyr/drivers/watchdog.h> -#include <logging/log.h> -#include <zephyr.h> +#include <zephyr/logging/log.h> +#include <zephyr/zephyr.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/i2c/src/main.c b/zephyr/test/i2c/src/main.c index 091f2b8a81..dbe9878da5 100644 --- a/zephyr/test/i2c/src/main.c +++ b/zephyr/test/i2c/src/main.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <devicetree.h> +#include <zephyr/devicetree.h> #include <ztest.h> #include "common.h" diff --git a/zephyr/test/i2c_dts/src/main.c b/zephyr/test/i2c_dts/src/main.c index ccd58dde67..7cb1052798 100644 --- a/zephyr/test/i2c_dts/src/main.c +++ b/zephyr/test/i2c_dts/src/main.c @@ -3,8 +3,8 @@ * found in the LICENSE file. */ -#include <device.h> -#include <devicetree.h> +#include <zephyr/device.h> +#include <zephyr/devicetree.h> #include <ztest.h> static void test_i2c_get_device(void) diff --git a/zephyr/test/system/test_system.c b/zephyr/test/system/test_system.c index 96befde553..ce83a684d1 100644 --- a/zephyr/test/system/test_system.c +++ b/zephyr/test/system/test_system.c @@ -3,9 +3,9 @@ * found in the LICENSE file. */ -#include <device.h> -#include <drivers/bbram.h> -#include <logging/log.h> +#include <zephyr/device.h> +#include <zephyr/drivers/bbram.h> +#include <zephyr/logging/log.h> #include <ztest.h> #include "system.h" diff --git a/zephyr/test/tasks/main.c b/zephyr/test/tasks/main.c index 91216b9518..ebf271d9b7 100644 --- a/zephyr/test/tasks/main.c +++ b/zephyr/test/tasks/main.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include <kernel.h> +#include <zephyr/kernel.h> #include <stdbool.h> #include <ztest.h> |