diff options
author | YH Lin <yueherngl@google.com> | 2023-05-11 20:47:00 +0000 |
---|---|---|
committer | YH Lin <yueherngl@google.com> | 2023-05-11 20:47:00 +0000 |
commit | 8641442366bd7c2c133e302a57f904dfac3c896b (patch) | |
tree | d0dca100ca02a89210decc54b7124d26bb75ef6a /zephyr/test | |
parent | e79a9dab1721c3d7da1475f3f802c4ea871a48ec (diff) | |
parent | 5df400b0377c9e1b5bb6cfc53ba7dfedde91f944 (diff) | |
download | chrome-ec-8641442366bd7c2c133e302a57f904dfac3c896b.tar.gz |
Merge remote-tracking branch cros/main into firmware-brya-14505.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file
baseboard/brya/relevant-paths.txt firmware-brya-14505.B-main
Relevant changes:
git log --oneline e79a9dab17..5df400b037 -- baseboard/brya board/agah
board/anahera board/banshee board/brya board/crota board/felwinter
board/gimble board/hades board/kano board/marasov board/mithrax
board/omnigul board/osiris board/primus board/redrix board/taeko
board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.*
driver/charger/bq25710.* driver/ppc/nx20p348x.*
driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.*
driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.*
include/power/alderlake* include/intel_x86.h power/alderlake*
power/intel_x86.c util/getversion.sh
76d2b9b1e4 battery: Deprecate CONFIG_BATTERY_LEVEL_NEAR_FULL
3d5b996f73 Hades: Fast forward DSW_PWROK to PCH_PWROK
56af450c1a Agah: Fast forward DSW_PWROK to PCH_PWROK
b729eab7c7 charger: Move charger_state_v2.h into charge_state.h
47acf64182 charger: Rename charge_get_state() to led_pwr_get_state()
632c7c935a power/x86: Add dedicated interrupt handler for pwrok
0fff3a0bd4 omnigul: Add condition use Accel and Gyro by FWCONFIG.
7540daff3f driver/tcpm/nct38xx: Remove write to RO register
3f279f30d4 GPU: Rename DC_ATLEAST_SOC to DC_ATMOST_SOC
BRANCH=None
BUG=b:218332694 b:216485035 b:280818345 b:280351196 b:280001153
BUG=b:279918234
TEST=`emerge-[brya,hades,draco] chromeos-ec`
Force-Relevant-Builds: all
Change-Id: I19f2f6c5573d8c748ac63b488a808f10de352b1d
Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'zephyr/test')
25 files changed, 1236 insertions, 32 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 417d96bf36..f8c778bee2 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -26,10 +26,12 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_COMMON_CBI_GPIO common_cbi_gpio) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_COMMON_CHARGER common_charger) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_CHARGESPLASH chargesplash) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_FLASH flash) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_ICM42607 icm42607) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_ISL923X isl923x) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_ISL9241 isl9241) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_I2C_CONTROLLER i2c_controller) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_IT8XXX2_HW_SHA256 it8xxx2_hw_sha256) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_KEYBOARD_8042 keyboard_8042) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_KEYBOARD_SCAN keyboard_scan) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MKBP mkbp) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index c3aaac274b..634eb00a71 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -65,6 +65,9 @@ config LINK_TEST_SUITE_HOST_COMMANDS config LINK_TEST_SUITE_HOST_COMMAND_READ_MEMMAP bool "Link and test the host command read memmap tests" +config LINK_TEST_SUITE_ICM42607 + bool "Link and test the icm42607 tests" + config LINK_TEST_SUITE_ISL923X bool "Link and test the isl923x tests" @@ -80,6 +83,9 @@ config LINK_TEST_SUITE_IT8XXX2_HW_SHA256 Include the it8xxx2_hw_sha256 test suite in the binary. +config LINK_TEST_SUITE_KEYBOARD_8042 + bool "Link and test the keyboard_8042 tests" + config LINK_TEST_SUITE_KEYBOARD_SCAN bool "Link and test the keyboard_scan tests" select PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK diff --git a/zephyr/test/drivers/ap_vdm_control/prj.conf b/zephyr/test/drivers/ap_vdm_control/prj.conf index 215a8ab36d..5267603e32 100644 --- a/zephyr/test/drivers/ap_vdm_control/prj.conf +++ b/zephyr/test/drivers/ap_vdm_control/prj.conf @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +CONFIG_PLATFORM_EC_USB_PD_DP_HPD_GPIO=y CONFIG_PLATFORM_EC_USB_MUX_AP_CONTROL=y CONFIG_PLATFORM_EC_USB_MUX_TASK=y CONFIG_PLATFORM_EC_USB_PD_VDM_AP_CONTROL=y diff --git a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c index 6c31880625..a5f5fbd7ef 100644 --- a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c +++ b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c @@ -13,10 +13,13 @@ #include <stdint.h> +#include <zephyr/drivers/gpio/gpio_emul.h> #include <zephyr/kernel.h> #include <zephyr/sys/byteorder.h> #include <zephyr/ztest.h> +#include <gpio.h> + #define TEST_PORT USBC_PORT_C0 struct ap_vdm_control_fixture { @@ -871,3 +874,242 @@ ZTEST_F(ap_vdm_control, test_no_ec_dp_mode) status = host_cmd_typec_status(TEST_PORT); zassert_equal(status.dp_pin, 0); } + +ZTEST_F(ap_vdm_control, test_vdm_hpd_level) +{ + uint32_t vdm_attention_data[2]; + int opos = 1; + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + /* HPD GPIO should be low before the test */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + run_verify_dp_entry(fixture, opos); + + /* Now send Attention to change HPD */ + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(opos) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION) | + VDO_SVDM_VERS(VDM_VER20); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_MSEC(100)); + /* + * Verify the HPD GPIO is set now + */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); +} + +ZTEST_F(ap_vdm_control, test_vdm_hpd_irq_ignored) +{ + uint32_t vdm_attention_data[2]; + int opos = 1; + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + /* HPD GPIO should be low before the test */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + run_verify_dp_entry(fixture, opos); + + /* Send our bad Attention message */ + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(opos) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION) | + VDO_SVDM_VERS(VDM_VER20); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + false, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_MSEC(100)); + /* + * Verify the HPD IRQ was rejected since HPD is low + */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); +} + +ZTEST_F(ap_vdm_control, test_vdm_status_hpd) +{ + int opos = 1; + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + /* HPD GPIO should be low before the test */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + /* Set up our slightly different DP Status */ + fixture->partner.dp_status_vdm[VDO_INDEX_HDR + 1] = + VDO_DP_STATUS(0, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 1, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + + /* Run Entry step by step to check HPD at each point */ + struct typec_vdm_req req = { + .vdm_data = { VDO(USB_SID_DISPLAYPORT, 1, + CMD_ENTER_MODE | VDO_OPOS(opos)) | + VDO_SVDM_VERS(VDM_VER20) }, + .vdm_data_objects = 1, + .partner_type = TYPEC_PARTNER_SOP, + }; + + /* Step 1: EnterMode */ + host_cmd_typec_control_vdm_req(TEST_PORT, req); + k_sleep(K_MSEC(100)); + + verify_expected_reply(req.partner_type, + fixture->partner.enter_mode_vdos, + fixture->partner.enter_mode_vdm); + + /* Step 2: DP Status */ + req.vdm_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_STATUS | VDO_OPOS(opos)) | + VDO_SVDM_VERS(VDM_VER20); + req.vdm_data[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ + 0, /* HPD level ... not applicable */ + 0, /* exit DP? ... no */ + 0, /* usb mode? ... no */ + 0, /* multi-function ... no */ + 0, /* currently enabled ... no */ + 0, /* power low? ... no */ + 1 /* DP source connected */); + req.vdm_data_objects = 2; + req.partner_type = TYPEC_PARTNER_SOP; + + host_cmd_typec_control_vdm_req(TEST_PORT, req); + k_sleep(K_MSEC(100)); + + verify_expected_reply(req.partner_type, fixture->partner.dp_status_vdos, + fixture->partner.dp_status_vdm); + /* Wait for it... */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + /* Step 3: DP Configure */ + req.vdm_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_CONFIG | VDO_OPOS(opos)) | + VDO_SVDM_VERS(VDM_VER20); + req.vdm_data[1] = VDO_DP_CFG(MODE_DP_PIN_D, /* pin mode */ + 1, /* DPv1.3 signaling */ + 2); /* Set that partner should be DP sink + */ + req.vdm_data_objects = 2; + req.partner_type = TYPEC_PARTNER_SOP; + + host_cmd_typec_control_vdm_req(TEST_PORT, req); + k_sleep(K_MSEC(100)); + + verify_expected_reply(req.partner_type, fixture->partner.dp_config_vdos, + fixture->partner.dp_config_vdm); + /* Now! */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); +} + +ZTEST_F(ap_vdm_control, test_vdm_hpd_disconnect_clear) +{ + uint32_t vdm_attention_data[2]; + int opos = 1; + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + run_verify_dp_entry(fixture, opos); + + /* Test that we see our Attention message */ + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(opos) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION) | + VDO_SVDM_VERS(VDM_VER20); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_MSEC(100)); + /* + * Verify the HPD GPIO is set now + */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); + + /* And disconnect */ + disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); +} + +ZTEST_F(ap_vdm_control, test_vdm_wake_on_dock) +{ + uint32_t vdm_attention_data[2]; + int opos = 1; + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + /* HPD GPIO should be low before the test */ + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); + + run_verify_dp_entry(fixture, opos); + + /* Now put the AP to "sleep" */ + test_set_chipset_to_power_level(POWER_S3); + + /* Drain the MKBP event queue first */ + struct host_cmd_handler_args args; + struct ec_response_get_next_event event; + + args.version = 0; + args.command = EC_CMD_GET_NEXT_EVENT; + args.params = NULL; + args.params_size = 0; + args.response = &event; + args.response_max = sizeof(event); + args.response_size = 0; + + while (host_command_process(&args) == EC_RES_SUCCESS) { + } + + /* Test that we see our Attention message cause an event */ + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(opos) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION) | + VDO_SVDM_VERS(VDM_VER20); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_MSEC(100)); + + /* Look for our MKBP event */ + zassert_equal(host_command_process(&args), EC_RES_SUCCESS); + zassert_equal(event.event_type, EC_MKBP_EVENT_DP_ALT_MODE_ENTERED); +} diff --git a/zephyr/test/drivers/common/src/stubs.c b/zephyr/test/drivers/common/src/stubs.c index cdb1a0f6a4..c623b95a82 100644 --- a/zephyr/test/drivers/common/src/stubs.c +++ b/zephyr/test/drivers/common/src/stubs.c @@ -7,7 +7,7 @@ #include "battery_fuel_gauge.h" #include "bc12/pi3usb9201_public.h" #include "charge_ramp.h" -#include "charge_state_v2.h" +#include "charge_state.h" #include "charger.h" #include "charger/isl923x_public.h" #include "charger/isl9241_public.h" diff --git a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c index 9dfeb5e734..a62ec2b0ea 100644 --- a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c +++ b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c @@ -4,7 +4,7 @@ */ #include "battery.h" -#include "charge_state_v2.h" +#include "charge_state.h" #include "math_util.h" #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/default/src/charge_state_prevent_power_on.c b/zephyr/test/drivers/default/src/charge_state_prevent_power_on.c index ce47ff8042..07e15ea1f6 100644 --- a/zephyr/test/drivers/default/src/charge_state_prevent_power_on.c +++ b/zephyr/test/drivers/default/src/charge_state_prevent_power_on.c @@ -4,7 +4,6 @@ */ #include "charge_state.h" -#include "charge_state_v2.h" #include "test/drivers/test_state.h" #include <zephyr/ztest.h> diff --git a/zephyr/test/drivers/default/src/console_cmd/charge_state.c b/zephyr/test/drivers/default/src/console_cmd/charge_state.c index 8cfd11324f..851725af36 100644 --- a/zephyr/test/drivers/default/src/console_cmd/charge_state.c +++ b/zephyr/test/drivers/default/src/console_cmd/charge_state.c @@ -4,7 +4,6 @@ */ #include "charge_state.h" -#include "charge_state_v2.h" #include "console.h" #include "ec_commands.h" #include "test/drivers/test_state.h" diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_20v_3a_pd_charger.c b/zephyr/test/drivers/default/src/integration/usbc/usb_20v_3a_pd_charger.c index f2afa5be9a..8b1bd1a6f1 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_20v_3a_pd_charger.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_20v_3a_pd_charger.c @@ -166,20 +166,20 @@ ZTEST_F(usb_attach_20v_3a_pd_charger, test_disconnect_battery_not_charging) ZTEST_F(usb_attach_20v_3a_pd_charger, test_disconnect_charge_state) { - struct ec_response_charge_state charge_state; + struct ec_response_charge_state state; disconnect_charger_from_port(fixture); - charge_state = host_cmd_charge_state(0); + state = host_cmd_charge_state(0); - zassert_false(charge_state.get_state.ac, "AC_OK not triggered"); - zassert_equal(charge_state.get_state.chg_current, 0, + zassert_false(state.get_state.ac, "AC_OK not triggered"); + zassert_equal(state.get_state.chg_current, 0, "Max charge current expected 0mA, but was %dmA", - charge_state.get_state.chg_current); - zassert_equal(charge_state.get_state.chg_input_current, + state.get_state.chg_current); + zassert_equal(state.get_state.chg_input_current, CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, "Charge input current limit expected %dmA, but was %dmA", CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, - charge_state.get_state.chg_input_current); + state.get_state.chg_input_current); } ZTEST_F(usb_attach_20v_3a_pd_charger, test_disconnect_typec_status) diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c index 930e393691..bff3d9661e 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c @@ -149,20 +149,20 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_battery_discharging) ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_charge_state) { - struct ec_response_charge_state charge_state; + struct ec_response_charge_state state; disconnect_sink_from_port(fixture->tcpci_emul); - charge_state = host_cmd_charge_state(0); + state = host_cmd_charge_state(0); - zassert_false(charge_state.get_state.ac, "AC_OK not triggered"); - zassert_equal(charge_state.get_state.chg_current, 0, + zassert_false(state.get_state.ac, "AC_OK not triggered"); + zassert_equal(state.get_state.chg_current, 0, "Max charge current expected 0mA, but was %dmA", - charge_state.get_state.chg_current); - zassert_equal(charge_state.get_state.chg_input_current, + state.get_state.chg_current); + zassert_equal(state.get_state.chg_input_current, CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, "Charge input current limit expected %dmA, but was %dmA", CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, - charge_state.get_state.chg_input_current); + state.get_state.chg_input_current); } ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_typec_status) diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c index c23fe6ed38..252509f9ba 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c @@ -162,20 +162,20 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_battery_not_charging) ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_charge_state) { - struct ec_response_charge_state charge_state; + struct ec_response_charge_state state; disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); - charge_state = host_cmd_charge_state(TEST_PORT); + state = host_cmd_charge_state(TEST_PORT); - zassert_false(charge_state.get_state.ac, "AC_OK not triggered"); - zassert_equal(charge_state.get_state.chg_current, 0, + zassert_false(state.get_state.ac, "AC_OK not triggered"); + zassert_equal(state.get_state.chg_current, 0, "Max charge current expected 0mA, but was %dmA", - charge_state.get_state.chg_current); - zassert_equal(charge_state.get_state.chg_input_current, + state.get_state.chg_current); + zassert_equal(state.get_state.chg_input_current, CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, "Charge input current limit expected %dmA, but was %dmA", CONFIG_PLATFORM_EC_CHARGER_DEFAULT_CURRENT_LIMIT, - charge_state.get_state.chg_input_current); + state.get_state.chg_input_current); } ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_typec_status) diff --git a/zephyr/test/drivers/dps/src/dps_selection.c b/zephyr/test/drivers/dps/src/dps_selection.c index 4fd0175ffa..bc897ae0bb 100644 --- a/zephyr/test/drivers/dps/src/dps_selection.c +++ b/zephyr/test/drivers/dps/src/dps_selection.c @@ -4,7 +4,7 @@ */ #include "battery.h" -#include "charge_state_v2.h" +#include "charge_state.h" #include "console.h" #include "dps.h" #include "ec_commands.h" diff --git a/zephyr/test/drivers/icm42607/CMakeLists.txt b/zephyr/test/drivers/icm42607/CMakeLists.txt new file mode 100644 index 0000000000..6b4b8a083b --- /dev/null +++ b/zephyr/test/drivers/icm42607/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright 2023 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Add source files +target_sources(app PRIVATE src/icm42607.c) diff --git a/zephyr/test/drivers/icm42607/prj.conf b/zephyr/test/drivers/icm42607/prj.conf new file mode 100644 index 0000000000..16c1ae7c03 --- /dev/null +++ b/zephyr/test/drivers/icm42607/prj.conf @@ -0,0 +1,6 @@ +# Copyright 2023 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +CONFIG_PLATFORM_EC_ACCELGYRO_ICM42607=y +CONFIG_PLATFORM_EC_ACCELGYRO_ICM_COMM_I2C=y diff --git a/zephyr/test/drivers/icm42607/sensor.dts b/zephyr/test/drivers/icm42607/sensor.dts new file mode 100644 index 0000000000..8734ce001a --- /dev/null +++ b/zephyr/test/drivers/icm42607/sensor.dts @@ -0,0 +1,74 @@ +/ { + aliases { + icm42607-int = &ms_icm42607_accel; + }; + + motionsense-mutex { + mutex_icm42607: icm42607-mutex { + }; + }; + + motionsense-sensor-data { + icm42607_data: icm42607-drv-data { + compatible = "cros-ec,drvdata-icm42607"; + status = "okay"; + }; + }; + + motionsense-sensor { + ms_icm42607_accel: ms-icm42607-accel { + compatible = "cros-ec,icm42607-accel"; + status = "okay"; + + location = "MOTIONSENSE_LOC_BASE"; + mutex = <&mutex_icm42607>; + port = <&named_i2c1>; + drv-data = <&icm42607_data>; + i2c-spi-addr-flags = "ICM42607_ADDR1_FLAGS"; + active-mask = "SENSOR_ACTIVE_S0_S3_S5"; + configs { + compatible = + "cros-ec,motionsense-sensor-config"; + ec-s0 { + odr = <10000>; + }; + ec-s3 { + odr = <10000>; + }; + ec-s5 { + odr = <10000>; + }; + }; + }; + + ms_icm42607_gyro: ms-icm42607-gryo { + compatible = "cros-ec,icm42607-gyro"; + status = "okay"; + + location = "MOTIONSENSE_LOC_BASE"; + mutex = <&mutex_icm42607>; + port = <&named_i2c1>; + drv-data = <&icm42607_data>; + i2c-spi-addr-flags = "ICM42607_ADDR1_FLAGS"; + active-mask = "SENSOR_ACTIVE_S0_S3_S5"; + }; + }; +}; + +&i2c1 { + icm42607_emul: icm42607@69 { + compatible = "zephyr,icm42607-emul"; + status = "okay"; + reg = <0x69>; + }; +}; + +/* motionsense framework supports at most 8 sensors, remove two so we can add + * our test target. + */ +&ms_bmi160_accel { + status = "disabled"; +}; +&ms_bmi160_gyro { + status = "disabled"; +}; diff --git a/zephyr/test/drivers/icm42607/src/icm42607.c b/zephyr/test/drivers/icm42607/src/icm42607.c new file mode 100644 index 0000000000..20d2736063 --- /dev/null +++ b/zephyr/test/drivers/icm42607/src/icm42607.c @@ -0,0 +1,466 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "accelgyro.h" +#include "driver/accelgyro_icm42607.h" +#include "driver/accelgyro_icm_common.h" +#include "emul/emul_icm42607.h" +#include "motion_sense.h" +#include "motion_sense_fifo.h" +#include "test/drivers/test_state.h" + +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> + +#define ICM42607_NODE DT_NODELABEL(icm42607_emul) +#define ACC_SENSOR_ID SENSOR_ID(DT_NODELABEL(ms_icm42607_accel)) +#define GYR_SENSOR_ID SENSOR_ID(DT_NODELABEL(ms_icm42607_gyro)) + +static const struct emul *emul = EMUL_DT_GET(ICM42607_NODE); +static struct motion_sensor_t *acc = &motion_sensors[ACC_SENSOR_ID]; +static struct motion_sensor_t *gyr = &motion_sensors[GYR_SENSOR_ID]; + +static void icm42607_set_temp(uint16_t val) +{ + icm42607_emul_write_reg(emul, ICM42607_REG_TEMP_DATA, val >> 8); + icm42607_emul_write_reg(emul, ICM42607_REG_TEMP_DATA + 1, val & 0xFF); +} + +static bool check_sensor_enabled(enum motionsensor_type type) +{ + int reg = icm42607_emul_peek_reg(emul, ICM42607_REG_PWR_MGMT0); + + if (type == MOTIONSENSE_TYPE_ACCEL) { + int mode = reg & 3; + + return mode == 2; + } else if (type == MOTIONSENSE_TYPE_GYRO) { + int mode = (reg >> 2) & 3; + + return mode == 3; + } + + return false; +} + +static void icm42607_push_packet(const int16_t *acc, const int16_t *gyr) +{ + uint8_t buf[16]; + int packet_size = 0; + + if (acc && gyr) { + buf[0] = BIT(6) | BIT(5); /* acc + gyr */ + memcpy(buf + 1, acc, 6); + memcpy(buf + 7, gyr, 6); + packet_size = 16; + } else if (acc) { + buf[0] = BIT(6); /* acc */ + memcpy(buf + 1, acc, 6); + packet_size = 8; + } else if (gyr) { + buf[0] = BIT(5); /* gyr */ + memcpy(buf + 1, gyr, 6); + packet_size = 8; + } + + icm42607_emul_write_reg(emul, ICM42607_REG_INT_STATUS, BIT(2)); + icm42607_emul_push_fifo(emul, buf, packet_size); +} + +static int motion_sense_fifo_pop(int *sensor_num, int16_t *data) +{ + struct ec_response_motion_sensor_data resp = {}; + uint16_t resp_size; + + while (motion_sense_fifo_read(sizeof(resp), 1, &resp, &resp_size)) { + if (resp.flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP) { + continue; + } + + *sensor_num = resp.sensor_num; + memcpy(data, resp.data, sizeof(resp.data)); + + return 0; + } + + return -1; +} + +static void test_fifo(const int16_t *acc_expected, const int16_t *gyr_expected) +{ + int sensor_num = -1; + int16_t data[3] = {}; + + motion_sense_fifo_reset(); + acc->oversampling_ratio = 1; + gyr->oversampling_ratio = 1; + + icm42607_push_packet(acc_expected, gyr_expected); + icm42607_interrupt(0); + k_sleep(K_SECONDS(1)); + + if (acc_expected) { + zassert_equal(motion_sense_fifo_pop(&sensor_num, data), 0); + zassert_equal(sensor_num, ACC_SENSOR_ID); + zassert_equal(acc_expected[0], data[0]); + zassert_equal(acc_expected[1], data[1]); + zassert_equal(acc_expected[2], data[2]); + } + + if (gyr_expected) { + zassert_equal(motion_sense_fifo_pop(&sensor_num, data), 0); + zassert_equal(sensor_num, GYR_SENSOR_ID); + zassert_equal(gyr_expected[0], data[0]); + zassert_equal(gyr_expected[1], data[1]); + zassert_equal(gyr_expected[2], data[2]); + } +} + +/* verify that icm42607 driver returns error when too many data in fifo */ +ZTEST_USER(icm42607, test_fifo_full) +{ + const uint8_t junk[512] = {}; + int sensor_num = -1; + int16_t data[3] = {}; + + icm42607_push_packet((int16_t[]){ -32768, -32768, -32768 }, NULL); + icm42607_emul_push_fifo(emul, junk, sizeof(junk)); + icm42607_interrupt(0); + k_sleep(K_SECONDS(1)); + + zassert_not_equal(motion_sense_fifo_pop(&sensor_num, data), 0); +} + +ZTEST_USER(icm42607, test_invalid_packet) +{ + const uint8_t junk[16] = { + 0x80, + }; /* bad packet header */ + int sensor_num = -1; + int16_t data[3] = {}; + + icm42607_emul_push_fifo(emul, junk, sizeof(junk)); + icm42607_interrupt(0); + k_sleep(K_SECONDS(1)); + + zassert_not_equal(motion_sense_fifo_pop(&sensor_num, data), 0); +} + +/* verify that icm42607 driver doesn't send bad data to motionsense fifo */ +ZTEST_USER(icm42607, test_invalid_sensor_data) +{ + int sensor_num = -1; + int16_t data[3] = {}; + + icm42607_push_packet((int16_t[]){ -32768, -32768, -32768 }, NULL); + icm42607_interrupt(0); + k_sleep(K_SECONDS(1)); + + zassert_not_equal(motion_sense_fifo_pop(&sensor_num, data), 0); +} + +ZTEST_USER(icm42607, test_fifo_read) +{ + /* 2 sensor packet */ + test_fifo((int16_t[]){ 1111, 2222, 3333 }, + (int16_t[]){ 4444, 5555, 6666 }); + + /* acc only */ + test_fifo((int16_t[]){ 1111, 2222, 3333 }, NULL); + + /* gyr only */ + test_fifo(NULL, (int16_t[]){ 4444, 5555, 6666 }); +} + +ZTEST_USER(icm42607, test_resolution) +{ + zassert_equal(acc->drv->get_resolution(acc), 16); +} + +/* verify that set_data_rate enables or disables the sensor */ +ZTEST_USER(icm42607, test_sensor_enable) +{ + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_ACCEL)); + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_GYRO)); + + zassert_ok(acc->drv->set_data_rate(acc, 12500, 1)); + zassert_true(check_sensor_enabled(MOTIONSENSE_TYPE_ACCEL)); + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_GYRO)); + + zassert_ok(acc->drv->set_data_rate(gyr, 12500, 1)); + zassert_true(check_sensor_enabled(MOTIONSENSE_TYPE_ACCEL)); + zassert_true(check_sensor_enabled(MOTIONSENSE_TYPE_GYRO)); + + zassert_ok(acc->drv->set_data_rate(gyr, 0, 1)); + zassert_true(check_sensor_enabled(MOTIONSENSE_TYPE_ACCEL)); + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_GYRO)); + + zassert_ok(acc->drv->set_data_rate(acc, 0, 1)); + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_ACCEL)); + zassert_false(check_sensor_enabled(MOTIONSENSE_TYPE_GYRO)); +} + +ZTEST_USER(icm42607, test_data_rate) +{ + zassert_ok(acc->drv->set_data_rate(acc, 12500, 1)); + zassert_equal(acc->drv->get_data_rate(acc), 12500); + zassert_equal(icm42607_emul_peek_reg(emul, ICM42607_REG_ACCEL_CONFIG0) & + 0xF, + 0xC); + + /* 24Hz should round up to 25Hz */ + zassert_ok(gyr->drv->set_data_rate(gyr, 24000, 1)); + zassert_equal(gyr->drv->get_data_rate(gyr), 25000); + zassert_equal(icm42607_emul_peek_reg(emul, ICM42607_REG_GYRO_CONFIG0) & + 0xF, + 0xB); + + /* return error if data rate is out of supported range */ + zassert_not_equal(gyr->drv->set_data_rate(gyr, 6250, 0), 0); + zassert_not_equal(acc->drv->set_data_rate(acc, 1600000, 0), 0); +} + +ZTEST_USER(icm42607, test_offset_out_of_range) +{ + int16_t acc_offset[3]; + int16_t acc_offset_input[3] = { 10000, -10000, 0 }; + int16_t acc_temp; + + zassert_ok(acc->drv->init(acc)); + + zassert_ok(acc->drv->set_offset(acc, acc_offset_input, 40)); + zassert_ok(acc->drv->get_offset(acc, acc_offset, &acc_temp)); + + /* icm42607 internally stores offset in 12bit signed integer, + * input is clamped into range [2047, -2048], and then scaled to + * ec unit, so the result is [1023.5, -1024] => [1024, -1024] + */ + zassert_equal(acc_offset[0], 1024); + zassert_equal(acc_offset[1], -1024, "got %d", acc_offset[1]); + zassert_equal(acc_offset[2], 0); + zassert_equal(acc_temp, EC_MOTION_SENSE_INVALID_CALIB_TEMP); +} + +ZTEST_USER(icm42607, test_offset) +{ + int16_t acc_offset[3], gyr_offset[3]; + /* use multiplies of 32 to avoid rounding error */ + int16_t acc_offset_expected[3] = { 32, 32 * 2, 32 * 3 }; + int16_t gyr_offset_expected[3] = { 32 * 4, 32 * 5, 32 * 6 }; + int16_t acc_temp, gyr_temp; + + zassert_ok(acc->drv->init(acc)); + zassert_ok(gyr->drv->init(gyr)); + + zassert_ok(acc->drv->set_offset(acc, acc_offset_expected, 40)); + zassert_ok(gyr->drv->set_offset(gyr, gyr_offset_expected, 80)); + zassert_ok(acc->drv->get_offset(acc, acc_offset, &acc_temp)); + zassert_ok(gyr->drv->get_offset(gyr, gyr_offset, &gyr_temp)); + + zassert_equal(acc_offset[0], acc_offset_expected[0]); + zassert_equal(acc_offset[1], acc_offset_expected[1]); + zassert_equal(acc_offset[2], acc_offset_expected[2]); + zassert_equal(acc_temp, EC_MOTION_SENSE_INVALID_CALIB_TEMP); + zassert_equal(gyr_offset[0], gyr_offset_expected[0]); + zassert_equal(gyr_offset[1], gyr_offset_expected[1]); + zassert_equal(gyr_offset[2], gyr_offset_expected[2]); + zassert_equal(gyr_temp, EC_MOTION_SENSE_INVALID_CALIB_TEMP); +} + +ZTEST_USER(icm42607, test_scale) +{ + uint16_t acc_scale[3], gyr_scale[3]; + int16_t acc_temp, gyr_temp; + + zassert_ok(acc->drv->init(acc)); + zassert_ok(gyr->drv->init(gyr)); + + zassert_ok(acc->drv->set_scale(acc, (uint16_t[3]){ 1, 2, 3 }, 4)); + zassert_ok(gyr->drv->set_scale(gyr, (uint16_t[3]){ 5, 6, 7 }, 8)); + zassert_ok(gyr->drv->get_scale(acc, acc_scale, &acc_temp)); + zassert_ok(gyr->drv->get_scale(gyr, gyr_scale, &gyr_temp)); + + zassert_equal(acc_scale[0], 1); + zassert_equal(acc_scale[1], 2); + zassert_equal(acc_scale[2], 3); + zassert_equal(acc_temp, EC_MOTION_SENSE_INVALID_CALIB_TEMP); + zassert_equal(gyr_scale[0], 5); + zassert_equal(gyr_scale[1], 6); + zassert_equal(gyr_scale[2], 7); + zassert_equal(gyr_temp, EC_MOTION_SENSE_INVALID_CALIB_TEMP); +} + +ZTEST_USER(icm42607, test_invalid_read) +{ + intv3_t v; + + zassert_ok(acc->drv->init(acc)); + zassert_ok(gyr->drv->init(gyr)); + + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ, 0x00); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 1, 0x80); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 2, 0x00); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 3, 0x80); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 4, 0x00); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 5, 0x80); + + /* return cached value (raw_xyz) on invalid data */ + zassert_ok(acc->drv->read(acc, v)); + zassert_equal(v[0], 0); + zassert_equal(v[1], 0); + zassert_equal(v[2], 0); +} + +/* verify that read() works correctly, and scale is applied */ +ZTEST_USER(icm42607, test_read) +{ + intv3_t v; + const uint16_t scale[3] = { 16384, 16384, 16384 }; /* 0.5x scale */ + + zassert_ok(acc->drv->init(acc)); + zassert_ok(gyr->drv->init(gyr)); + + /* verify that sensor data format is configured to little endian */ + int intf_config0 = + icm42607_emul_peek_reg(emul, ICM42607_REG_INTF_CONFIG0); + zassert_equal(intf_config0 & ICM42607_SENSOR_DATA_ENDIAN, 0); + zassert_ok(acc->drv->set_scale(acc, scale, 0)); + + /* test accel read, 16bit LE */ + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ, 0x01); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 1, 0x02); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 2, 0x03); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 3, 0x04); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 4, 0x05); + icm42607_emul_write_reg(emul, ICM42607_REG_ACCEL_DATA_XYZ + 5, 0x06); + + zassert_ok(acc->drv->read(acc, v)); + zassert_equal(v[0], 0x0201 / 2); + zassert_equal(v[1], 0x0403 / 2); + zassert_equal(v[2], 0x0605 / 2); + + /* test gyro read, 16bit LE */ + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ, 0x0A); + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ + 1, 0x0B); + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ + 2, 0x0C); + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ + 3, 0x0D); + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ + 4, 0x0E); + icm42607_emul_write_reg(emul, ICM42607_REG_GYRO_DATA_XYZ + 5, 0x0F); + + zassert_ok(gyr->drv->read(gyr, v)); + zassert_equal(v[0], 0x0B0A); + zassert_equal(v[1], 0x0D0C); + zassert_equal(v[2], 0x0F0E); +} + +/* read() immediately after sensor enabled should fail */ +ZTEST_USER(icm42607, test_read_not_stabilized) +{ + intv3_t v; + + zassert_ok(acc->drv->set_data_rate(acc, 0, 1)); + zassert_ok(acc->drv->set_data_rate(acc, 10000, 1)); + zassert_not_equal(acc->drv->read(acc, v), 0); + + sleep(1); + zassert_equal(acc->drv->read(acc, v), 0); +} + +ZTEST_USER(icm42607, test_set_range) +{ + int reg_val; + + /* set 5G, round down to 4G, expect reg val = 2 */ + zassert_ok(acc->drv->set_range(acc, 5, 0)); + reg_val = (icm42607_emul_peek_reg(emul, ICM42607_REG_ACCEL_CONFIG0) >> + 5) & + 3; + zassert_equal(reg_val, 2); + + /* set 5G, round up to 8G, expect reg val = 1 */ + zassert_ok(acc->drv->set_range(acc, 5, 1)); + reg_val = (icm42607_emul_peek_reg(emul, ICM42607_REG_ACCEL_CONFIG0) >> + 5) & + 3; + zassert_equal(reg_val, 1); + + /* set 1500dps, round down to 1000dps, expect reg val = 1 */ + zassert_ok(gyr->drv->set_range(gyr, 1500, 0)); + reg_val = + (icm42607_emul_peek_reg(emul, ICM42607_REG_GYRO_CONFIG0) >> 5) & + 3; + zassert_equal(reg_val, 1); + + /* set 1500dps, round down to 2000dps, expect reg val = 0 */ + zassert_ok(gyr->drv->set_range(gyr, 1500, 1)); + reg_val = + (icm42607_emul_peek_reg(emul, ICM42607_REG_GYRO_CONFIG0) >> 5) & + 3; + zassert_equal(reg_val, 0); +} + +/* Verify the temperature matches following formula: + * Temperature in C = (REG_DATA / 128) + 25 + */ +ZTEST_USER(icm42607, test_read_temp) +{ + int temp; + + /* expect 0C = 273.15K */ + icm42607_set_temp(-25 * 128); + zassert_ok(acc->drv->read_temp(acc, &temp)); + zassert_equal(temp, 273); + + /* expect 100C = 373.15K */ + icm42607_set_temp(75 * 128); + zassert_ok(acc->drv->read_temp(acc, &temp)); + zassert_equal(temp, 373); + + /* expect 25C = 298K */ + icm42607_set_temp(0); + zassert_ok(acc->drv->read_temp(acc, &temp)); + zassert_equal(temp, 298); + + /* reset value */ + icm42607_set_temp(-32768); + zassert_not_equal(acc->drv->read_temp(acc, &temp), 0); +} + +ZTEST_USER(icm42607, test_init) +{ + struct i2c_common_emul_data *common_data = + emul_icm42607_get_i2c_common_data(emul); + + icm42607_emul_write_reg(emul, ICM42607_REG_WHO_AM_I, + ICM42607_CHIP_ICM42607P); + zassert_ok(acc->drv->init(acc)); + + icm42607_emul_write_reg(emul, ICM42607_REG_WHO_AM_I, 0x87); + zassert_not_equal(acc->drv->init(acc), 0); + + i2c_common_emul_set_read_fail_reg(common_data, ICM42607_REG_WHO_AM_I); + zassert_not_equal(acc->drv->init(acc), 0); +} + +static void icm42607_before(void *fixture) +{ + struct i2c_common_emul_data *common_data = + emul_icm42607_get_i2c_common_data(emul); + + ARG_UNUSED(fixture); + + i2c_common_emul_set_read_fail_reg(common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + icm42607_emul_reset(emul); + icm_reset_stabilize_ts(acc); + icm_reset_stabilize_ts(gyr); + memset(acc->raw_xyz, 0, sizeof(intv3_t)); + memset(gyr->raw_xyz, 0, sizeof(intv3_t)); + motion_sense_fifo_reset(); + acc->oversampling_ratio = 1; + gyr->oversampling_ratio = 1; +} + +ZTEST_SUITE(icm42607, drivers_predicate_post_main, NULL, icm42607_before, NULL, + NULL); diff --git a/zephyr/test/drivers/keyboard_8042/CMakeLists.txt b/zephyr/test/drivers/keyboard_8042/CMakeLists.txt new file mode 100644 index 0000000000..ed131ec38e --- /dev/null +++ b/zephyr/test/drivers/keyboard_8042/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2022 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +target_sources(app PRIVATE + src/keyboard_8042.c +) + diff --git a/zephyr/test/drivers/keyboard_8042/src/keyboard_8042.c b/zephyr/test/drivers/keyboard_8042/src/keyboard_8042.c new file mode 100644 index 0000000000..82779bfdb2 --- /dev/null +++ b/zephyr/test/drivers/keyboard_8042/src/keyboard_8042.c @@ -0,0 +1,196 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "console.h" +#include "keyboard_8042.h" +#include "test/drivers/test_mocks.h" +#include "test/drivers/test_state.h" + +#include <string.h> + +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/fff.h> +#include <zephyr/shell/shell_dummy.h> +#include <zephyr/ztest.h> + +ZTEST(keyboard_8042, test_console_cmd__typematic__status) +{ + const char *outbuffer; + size_t buffer_size; + + /* Set a typematic scan code to verify */ + const uint8_t scan_code[] = { 0x01, 0x02, 0x03 }; + + set_typematic_key(scan_code, ARRAY_SIZE(scan_code)); + + /* With no args, print current state */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 typematic")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + /* Check for some expected lines based off default typematic state */ + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "From host: 0x2b")); + zassert_ok(!strstr(outbuffer, "First delay: 500 ms")); + zassert_ok(!strstr(outbuffer, "Inter delay: 91 ms")); + zassert_ok( + !strstr(outbuffer, "Repeat scan code: {0x01, 0x02, 0x03, }")); +} + +ZTEST(keyboard_8042, test_console_cmd__typematic__set_delays) +{ + const char *outbuffer; + size_t buffer_size; + + /* Set first delay and inter delay */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 typematic 123 456")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + /* Check for some expected lines */ + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "First delay: 123 ms")); + zassert_ok(!strstr(outbuffer, "Inter delay: 456 ms")); +} + +ZTEST(keyboard_8042, test_console_cmd__codeset__set_codeset1) +{ + const char *outbuffer; + size_t buffer_size; + + /* Switch to codeset 1 and verify output */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 codeset 1")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "Set: 1")); +} + +ZTEST(keyboard_8042, test_console_cmd__codeset__set_invalid) +{ + zassert_equal(EC_ERROR_PARAM1, + shell_execute_cmd(get_ec_shell(), "8042 codeset 999")); +} + +ZTEST(keyboard_8042, test_console_cmd__ram__writeread) +{ + const char *outbuffer; + size_t buffer_size; + + /* Write a byte and verify the readback in console output */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 ctrlram 0x1f 0xaa")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "31 = 0xaa")); +} + +ZTEST(keyboard_8042, test_console_cmd__ram__invalid) +{ + /* Missing args */ + zassert_equal(EC_ERROR_PARAM_COUNT, + shell_execute_cmd(get_ec_shell(), "8042 ctrlram")); + + /* Address out of bounds */ + zassert_equal(EC_ERROR_PARAM1, + shell_execute_cmd(get_ec_shell(), "8042 ctrlram 9999")); +} + +ZTEST(keyboard_8042, test_console_cmd__enable__true) +{ + const char *outbuffer; + size_t buffer_size; + + /* Enable the keyboard and verify in console output */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 kbd y")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "Enabled: 1")); +} + +ZTEST(keyboard_8042, test_console_cmd__enable__invalid) +{ + /* Non-bool arg */ + zassert_equal(EC_ERROR_PARAM1, + shell_execute_cmd(get_ec_shell(), "8042 kbd abc")); +} + +ZTEST(keyboard_8042, test_console_cmd__internal) +{ + const char *outbuffer; + size_t buffer_size; + + uint8_t resend_command[] = { 7, 8, 9 }; + + test_keyboard_8042_set_resend_command(resend_command, + ARRAY_SIZE(resend_command)); + + /* Dump the internal state of the keyboard driver */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042 internal")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "keyboard_enabled=0")); + zassert_ok(!strstr(outbuffer, "i8042_keyboard_irq_enabled=0")); + zassert_ok(!strstr(outbuffer, "i8042_aux_irq_enabled=0")); + zassert_ok(!strstr(outbuffer, "keyboard_enabled=0")); + zassert_ok(!strstr(outbuffer, "keystroke_enabled=0")); + zassert_ok(!strstr(outbuffer, "aux_chan_enabled=0")); + zassert_ok(!strstr(outbuffer, "controller_ram_address=0x00")); + zassert_ok(!strstr(outbuffer, "resend_command[]={0x07, 0x08, 0x09, }")); + zassert_ok(!strstr(outbuffer, "A20_status=0")); +} + +ZTEST(keyboard_8042, test_console_cmd__invalid) +{ + /* Non-existent subcommand */ + zassert_equal(EC_ERROR_PARAM1, + shell_execute_cmd(get_ec_shell(), "8042 foobar")); +} + +ZTEST(keyboard_8042, test_console_cmd__all) +{ + const char *outbuffer; + size_t buffer_size; + + /* Run all the subcommands */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "8042")); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + /* Just look for the headers since we already tested the individual + * subcommands + */ + + zassert_true(buffer_size > 0); + zassert_ok(!strstr(outbuffer, "- Typematic:")); + zassert_ok(!strstr(outbuffer, "- Codeset:")); + zassert_ok(!strstr(outbuffer, "- Control RAM:")); + zassert_ok(!strstr(outbuffer, "- Keyboard:")); + zassert_ok(!strstr(outbuffer, "- Internal:")); +} + +static void reset(void *fixture) +{ + ARG_UNUSED(fixture); + + test_keyboard_8042_reset(); +} + +ZTEST_SUITE(keyboard_8042, drivers_predicate_post_main, NULL, reset, reset, + NULL); diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 695a2bcc66..06d75f9720 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -90,6 +90,7 @@ tests: - prj.conf - ap_mux_control/prj.conf drivers.ap_vdm_control: + timeout: 360 extra_configs: - CONFIG_LINK_TEST_SUITE_AP_VDM_CONTROL=y extra_conf_files: @@ -202,6 +203,15 @@ tests: - CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI=n - CONFIG_PLATFORM_EC_HOST_INTERFACE_SHI=y - CONFIG_PLATFORM_EC_SWITCH=n + drivers.icm42607: + extra_configs: + - CONFIG_PLATFORM_EC_ACCELGYRO_BMI160=n + - CONFIG_LINK_TEST_SUITE_ICM42607=y + - CONFIG_PLATFORM_EC_ACCELGYRO_ICM42607=y + - CONFIG_PLATFORM_EC_ACCELGYRO_ICM_COMM_I2C=y + extra_dtc_overlay_files: + - ./boards/native_posix.overlay + - ./icm42607/sensor.dts drivers.isl923x: extra_configs: - CONFIG_LINK_TEST_SUITE_ISL923X=y @@ -227,6 +237,11 @@ tests: extra_configs: - CONFIG_LINK_TEST_SUITE_IT8XXX2_HW_SHA256=y - CONFIG_PLATFORM_EC_SHA256_HW_ACCELERATE=y + drivers.keyboard_8042: + extra_configs: + - CONFIG_PLATFORM_EC_KEYBOARD_PROTOCOL_MKBP=n + - CONFIG_PLATFORM_EC_KEYBOARD_PROTOCOL_8042=y + - CONFIG_LINK_TEST_SUITE_KEYBOARD_8042=y drivers.keyboard_scan: extra_configs: - CONFIG_LINK_TEST_SUITE_KEYBOARD_SCAN=y diff --git a/zephyr/test/ocpc/src/ocpc.c b/zephyr/test/ocpc/src/ocpc.c index dd7e2733e7..5d0da0c117 100644 --- a/zephyr/test/ocpc/src/ocpc.c +++ b/zephyr/test/ocpc/src/ocpc.c @@ -2,7 +2,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include "charge_state_v2.h" +#include "charge_state.h" #include "console.h" #include "host_command.h" #include "ocpc.h" diff --git a/zephyr/test/skyrim/testcase.yaml b/zephyr/test/skyrim/testcase.yaml index 403b8f7e6c..1dfae464cf 100644 --- a/zephyr/test/skyrim/testcase.yaml +++ b/zephyr/test/skyrim/testcase.yaml @@ -126,3 +126,9 @@ tests: extra_configs: - CONFIG_TEST_BOARD_WINTERHOLD=y - CONFIG_TEST_BOARD_USB_MUX_CONFIG_CUSTOM=y + + skyrim.winterhold.fan: + extra_configs: + - CONFIG_TEST_BOARD_WINTERHOLD=y + - CONFIG_TEST_BOARD_FAN=y + - CONFIG_TEST_BOARD_FAN_CUSTOM=y diff --git a/zephyr/test/skyrim/tests/baseboard/src/power_signals.c b/zephyr/test/skyrim/tests/baseboard/src/power_signals.c index c4bfba04a7..82e42acaa1 100644 --- a/zephyr/test/skyrim/tests/baseboard/src/power_signals.c +++ b/zephyr/test/skyrim/tests/baseboard/src/power_signals.c @@ -87,19 +87,31 @@ ZTEST(power_signals, test_baseboard_suspend_change) { const struct gpio_dt_spec *gpio_ec_disable_disp_bl = GPIO_DT_FROM_NODELABEL(gpio_ec_disable_disp_bl); - const struct gpio_dt_spec *usb_a1_retimer_en = - GPIO_DT_FROM_NODELABEL(usb_a1_retimer_en); struct ap_power_ev_data data; data.event = AP_POWER_SUSPEND; baseboard_suspend_change(NULL, data); zassert_true(gpio_emul_output_get_dt(gpio_ec_disable_disp_bl)); - zassert_false(gpio_emul_output_get_dt(usb_a1_retimer_en)); data.event = AP_POWER_RESUME; baseboard_suspend_change(NULL, data); zassert_false(gpio_emul_output_get_dt(gpio_ec_disable_disp_bl)); +} + +ZTEST(power_signals, test_baseboard_shutdown_change) +{ + const struct gpio_dt_spec *usb_a1_retimer_en = + GPIO_DT_FROM_NODELABEL(usb_a1_retimer_en); + + struct ap_power_ev_data data; + + data.event = AP_POWER_SHUTDOWN; + baseboard_suspend_change(NULL, data); + zassert_false(gpio_emul_output_get_dt(usb_a1_retimer_en)); + + data.event = AP_POWER_STARTUP; + baseboard_suspend_change(NULL, data); zassert_true(gpio_emul_output_get_dt(usb_a1_retimer_en)); } diff --git a/zephyr/test/skyrim/tests/winterhold/CMakeLists.txt b/zephyr/test/skyrim/tests/winterhold/CMakeLists.txt index 673b09bdcd..39ded69058 100644 --- a/zephyr/test/skyrim/tests/winterhold/CMakeLists.txt +++ b/zephyr/test/skyrim/tests/winterhold/CMakeLists.txt @@ -3,4 +3,5 @@ # found in the LICENSE file. target_sources(app PRIVATE src/common.c) -target_sources_ifdef(CONFIG_TEST_BOARD_PPC_CONFIG app PRIVATE src/ppc_config.c)
\ No newline at end of file +target_sources_ifdef(CONFIG_TEST_BOARD_PPC_CONFIG app PRIVATE src/ppc_config.c) +target_sources_ifdef(CONFIG_TEST_BOARD_FAN_CUSTOM app PRIVATE src/fan.c) diff --git a/zephyr/test/skyrim/tests/winterhold/src/fan.c b/zephyr/test/skyrim/tests/winterhold/src/fan.c new file mode 100644 index 0000000000..a7af0d2da1 --- /dev/null +++ b/zephyr/test/skyrim/tests/winterhold/src/fan.c @@ -0,0 +1,165 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include <zephyr/fff.h> +#include <zephyr/kernel.h> +#include <zephyr/logging/log.h> +#include <zephyr/ztest.h> + +#include <cros_board_info.h> +#include <cros_cbi.h> +#include <fan.h> +#include <hooks.h> + +FAKE_VOID_FUNC(fan_set_duty, int, int); +FAKE_VALUE_FUNC(int, fan_get_duty, int); + +struct fan_conf conf; +struct fan_rpm rpm; + +const struct fan_t fans[1] = { { .conf = &conf, .rpm = &rpm } }; +struct fan_data fan_data[1]; + +K_TIMER_DEFINE(ktimer, NULL, NULL); + +static void fan_set_duty_mock(int ch, int duty) +{ + zassert_equal(ch, 0); + zassert_between_inclusive(duty, 0, 100); + + fan_data[ch].pwm_percent = duty; +} + +static int fan_get_duty_mock(int ch) +{ + zassert_equal(ch, 0); + zassert_between_inclusive(fan_data[ch].pwm_percent, 0, 100); + + return fan_data[ch].pwm_percent; +} + +static int duty_to_rpm(int duty) +{ + const float ratio = 0.015; + + zassert_between_inclusive(duty, 0, 100); + + return (int)((float)duty / ratio); +} + +static void fan_tick(void) +{ + int rpm_diff; + int duty; + + duty = fan_data[0].pwm_percent; + + rpm_diff = duty_to_rpm(duty) - fan_data[0].rpm_actual; + + /* Clamp rpm_diff. This essentially emulates fan inertia. */ + if (rpm_diff > 0) + rpm_diff = MIN(rpm_diff, 500); + if (rpm_diff < 0) + rpm_diff = MAX(rpm_diff, -500); + + fan_data[0].rpm_actual += rpm_diff; +} + +static void fan_test_begin(void *fixture) +{ + ARG_UNUSED(fixture); + RESET_FAKE(fan_set_duty); + RESET_FAKE(fan_get_duty); + + fan_set_duty_fake.custom_fake = fan_set_duty_mock; + fan_get_duty_fake.custom_fake = fan_get_duty_mock; + + /* + * This is normally read from DT. + * The problem is that we don't want to pull the entire fan framework + * for this test. Instead initialize it here. + * All the values come from + * zephyr/program/skyrim/winterhold/project.overlay. + */ + memset(&conf, 0, sizeof(conf)); + memset(&rpm, 0, sizeof(rpm)); + + rpm.rpm_max = 4800; + rpm.rpm_deviation = 3; + + memset(&fan_data[0], 0, sizeof(fan_data[0])); +} + +/* Only FAN 0 should be supported. */ +ZTEST(fan, test_fan_invalid_arg) +{ + enum fan_status status; + + status = board_override_fan_control_duty(1); + zassert_equal(status, FAN_STATUS_FRUSTRATED); +} + +/* + * Check whether we can ramp up into rpm_max in 5s. + * The time limit is selected on a per board basis. + * It depends on the thermal capacity of the radiator and CPU TDP. + * Basically we want to ensure that fan ramps up fast enough + * to prevent the CPU from thermal throttling. + */ +ZTEST(fan, test_fan_max_rpm) +{ + enum fan_status status; + int deviation; + + fan_data[0].rpm_target = rpm.rpm_max; + k_timer_start(&ktimer, K_SECONDS(5), K_NO_WAIT); + + while (k_timer_remaining_ticks(&ktimer) != 0) { + status = board_override_fan_control_duty(0); + zassert_not_equal(status, FAN_STATUS_FRUSTRATED); + fan_tick(); + k_sleep(K_TICKS(1)); + } + + deviation = rpm.rpm_deviation * rpm.rpm_max / 100; + zassert_true(fan_set_duty_fake.call_count > 1); + zassert_within(fan_data[0].rpm_actual, rpm.rpm_max, deviation); + zassert_equal(status, FAN_STATUS_LOCKED); +} + +/* Check for FAN_STATUS_STOPPED when the fan is in fact stopped. */ +ZTEST(fan, test_fan_off) +{ + enum fan_status status; + + status = board_override_fan_control_duty(0); + zassert_equal(status, FAN_STATUS_STOPPED); + zassert_equal(fan_set_duty_fake.call_count, 0); +} + +/* If we can't achieve selected RPM, FAN_STATUS_FRUSTRATED is expected. */ +ZTEST(fan, test_fan_frustrated_max) +{ + enum fan_status status; + + /* + * 10 seconds should be more than enough for implementation to realize + * that it can't get up to 10k RPM + */ + fan_data[0].rpm_target = 10000; + k_timer_start(&ktimer, K_SECONDS(10), K_NO_WAIT); + + while (k_timer_remaining_ticks(&ktimer) != 0) { + status = board_override_fan_control_duty(0); + if (status == FAN_STATUS_FRUSTRATED) + break; + + fan_tick(); + k_sleep(K_TICKS(1)); + } + zassert_true(fan_set_duty_fake.call_count > 1); + zassert_equal(status, FAN_STATUS_FRUSTRATED); +} + +ZTEST_SUITE(fan, NULL, NULL, fan_test_begin, NULL, NULL); diff --git a/zephyr/test/system_safe_mode/src/system_safe_mode.c b/zephyr/test/system_safe_mode/src/system_safe_mode.c index f75a27ec84..036bc4c8e0 100644 --- a/zephyr/test/system_safe_mode/src/system_safe_mode.c +++ b/zephyr/test/system_safe_mode/src/system_safe_mode.c @@ -177,7 +177,7 @@ ZTEST_USER(system_safe_mode, test_print_stack_contents) uint16_t write_count; regex_t regex; - char *regex_str = "========== Stack Contents ===========\n" + char *regex_str = "Stack Contents\n" "[0-9a-f]{8}: 00000000 00000001 00000002 00000003\n" "[0-9a-f]{8}: 00000004 00000005 00000006 00000007\n" "[0-9a-f]{8}: 00000008 00000009 0000000a 0000000b\n" |