diff options
author | Jeremy Bettis <jbettis@google.com> | 2021-04-09 10:21:39 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-12 17:54:21 +0000 |
commit | bd2b1eb38349dcc736c5ec6763abdeb87e48aa16 (patch) | |
tree | c1c939743baaa263171c4d5b524f1e4886e5b5ba /zephyr/test/drivers | |
parent | f334d6f9d4116eeb4999293108abf8fe147d6f83 (diff) | |
download | chrome-ec-bd2b1eb38349dcc736c5ec6763abdeb87e48aa16.tar.gz |
zephyr: Shell of driver ztest.
Create a shell of a test that can have many test suites for device
drivers. Currently this test only checks that the EC_BATT_PRES_ODL can
be read correctly by battery_is_present(). But it links in many device
drivers and is a starting point for the next test.
BUG=b:185118990
TEST=It is one
BRANCH=none
Signed-off-by: Jeremy Bettis <jbettis@google.com>
Change-Id: I07c8835015cbe0fec6aaf82f782400e894043a90
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2819029
Tested-by: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/test/drivers')
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 13 | ||||
-rw-r--r-- | zephyr/test/drivers/README.md | 50 | ||||
-rw-r--r-- | zephyr/test/drivers/gpio_map.h | 12 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 54 | ||||
-rw-r--r-- | zephyr/test/drivers/prj.conf | 39 | ||||
-rw-r--r-- | zephyr/test/drivers/shimmed_test_tasks.h | 20 | ||||
-rw-r--r-- | zephyr/test/drivers/src/battery.c | 35 | ||||
-rw-r--r-- | zephyr/test/drivers/src/main.c | 20 | ||||
-rw-r--r-- | zephyr/test/drivers/src/stubs.c | 181 | ||||
-rw-r--r-- | zephyr/test/drivers/stubs.h | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/zmake.yaml | 12 |
11 files changed, 442 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt new file mode 100644 index 0000000000..cea2f5600a --- /dev/null +++ b/zephyr/test/drivers/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright 2021 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. + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(drivers) + +# Include the local test directory for shimmed_test_tasks.h +zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}") + +FILE(GLOB test_sources src/*.c) +target_sources(app PRIVATE ${test_sources}) diff --git a/zephyr/test/drivers/README.md b/zephyr/test/drivers/README.md new file mode 100644 index 0000000000..8ea3dcdde1 --- /dev/null +++ b/zephyr/test/drivers/README.md @@ -0,0 +1,50 @@ +This is the combined driver test. The goal is to have many driver test suites +in one binary, so that compile time will be faster than many small tests, and +so we can test interactions between different subsystems easily. + +## Run all the test suites + +```bash +(chroot) zmake configure --test zephyr/test/drivers +``` + +To see all the output of zmake (for example if the build fails) + +```bash +(chroot) zmake -l DEBUG -j 1 configure --test zephyr/test/drivers +``` + +## Code coverage + +To calculate code coverage for this test only + +```bash +(chroot) zmake configure --coverage --test zephyr/test/drivers +(chroot) lcov --gcov-tool ~/trunk/src/platform/ec/util/llvm-gcov.sh -q \ + -o build/zephyr/test/drivers/lcov.info -c -d build/zephyr/test/drivers +(chroot) genhtml -q -o build/zephyr/test/drivers/coverage_rpt \ + build/zephyr/test/drivers/lcov.info +``` + +The report will be in build/zephyr/test/drivers/coverage_rpt/index.html + +## Debugging + +You need the host version of gdb: + +```bash +(chroot) sudo emerge -j sys-devel/gdb +``` + +Build the test +```bash +(chroot) zmake configure --build zephyr/test/drivers +``` + +Then run gdb + +``` +(chroot) gdb build/zephyr/test/drivers/build-singleimage/zephyr/zephyr.exe +# Set breakpoints, run, etc. +``` + diff --git a/zephyr/test/drivers/gpio_map.h b/zephyr/test/drivers/gpio_map.h new file mode 100644 index 0000000000..08542f33d7 --- /dev/null +++ b/zephyr/test/drivers/gpio_map.h @@ -0,0 +1,12 @@ +/* Copyright 2021 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. + */ + +#ifndef __ZEPHYR_GPIO_MAP_H +#define __ZEPHYR_GPIO_MAP_H + +#include <devicetree.h> +#include <gpio_signal.h> + +#endif /* __ZEPHYR_GPIO_MAP_H */ diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts new file mode 100644 index 0000000000..9ae4569a2a --- /dev/null +++ b/zephyr/test/drivers/overlay.dts @@ -0,0 +1,54 @@ +/* Copyright 2021 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 <dt-bindings/gpio_defines.h> + +/ { + named-gpios { + compatible = "named-gpios"; + + ec_batt_pres_odl { + gpios = <&gpio0 1 GPIO_INPUT>; + enum-name = "GPIO_BATT_PRES_ODL"; + label = "EC_BATT_PRES_ODL"; + }; + }; + named-i2c-ports { + compatible = "named-i2c-ports"; + + usb-c0 { + i2c-port = <&i2c0>; + enum-name = "I2C_PORT_USB_C0"; + label = "USB_C0"; + }; + usb-c1 { + i2c-port = <&i2c0>; + enum-name = "I2C_PORT_USB_C1"; + label = "USB_C1"; + }; + battery { + i2c-port = <&i2c0>; + enum-name = "I2C_PORT_BATTERY"; + label = "BATTERY"; + }; + charger { + i2c-port = <&i2c0>; + enum-name = "I2C_PORT_CHARGER"; + label = "CHARGER"; + }; + }; + + named-batteries { + compatible = "named-batteries"; + + lgc011 { + enum-name = "lgc011"; + }; + }; +}; + +&gpio0 { + ngpios = <2>; +}; diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf new file mode 100644 index 0000000000..89ca3b4c19 --- /dev/null +++ b/zephyr/test/drivers/prj.conf @@ -0,0 +1,39 @@ +# Copyright 2021 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. + +CONFIG_ZTEST=y +CONFIG_PLATFORM_EC=y +CONFIG_CROS_EC=y +CONFIG_HAS_TEST_TASKS=y +CONFIG_SHIMMED_TASKS=y +CONFIG_EMUL=y +CONFIG_I2C=y +CONFIG_I2C_EMUL=y +CONFIG_GPIO=y +CONFIG_GPIO_EMUL=y + +CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y + +CONFIG_PLATFORM_EC_USB_PID=0x5000 +CONFIG_PLATFORM_EC_USBC=y +CONFIG_PLATFORM_EC_USB_CHARGER=y +CONFIG_PLATFORM_EC_BC12_DETECT_PI3USB9201=y +CONFIG_PLATFORM_EC_USB_POWER_DELIVERY=y +CONFIG_PLATFORM_EC_USB_PD_5V_EN_CUSTOM=y +CONFIG_PLATFORM_EC_I2C=y +CONFIG_PLATFORM_EC_BATTERY=y +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10 +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=10 +CONFIG_PLATFORM_EC_CHARGER_ISL9241=y +CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y +CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y +CONFIG_PLATFORM_EC_HOSTCMD=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_TUSB422=y +CONFIG_PLATFORM_EC_USB_MUX_VIRTUAL=y +CONFIG_PLATFORM_EC_USBC_PPC_SN5S330=y + +# Things that default to on, but aren't working yet +CONFIG_PLATFORM_EC_BACKLIGHT_LID=n +CONFIG_PLATFORM_EC_SWITCH=n +CONFIG_PLATFORM_EC_VBOOT_HASH=n diff --git a/zephyr/test/drivers/shimmed_test_tasks.h b/zephyr/test/drivers/shimmed_test_tasks.h new file mode 100644 index 0000000000..e78e4dac76 --- /dev/null +++ b/zephyr/test/drivers/shimmed_test_tasks.h @@ -0,0 +1,20 @@ +/* Copyright 2021 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. + */ + +#ifndef __CROS_EC_SHIMMED_TEST_TASKS_H +#define __CROS_EC_SHIMMED_TEST_TASKS_H + +/* Highest priority on bottom same as in platform/ec */ +#define CROS_EC_TASK_LIST \ + CROS_EC_TASK(HOOKS, hook_task, 0, CONFIG_TASK_HOOKS_STACK_SIZE) \ + CROS_EC_TASK(CHG_RAMP, chg_ramp_task, 0, \ + CONFIG_TASK_CHG_RAMP_STACK_SIZE) \ + CROS_EC_TASK(USB_CHG_P0, usb_charger_task, 0, \ + CONFIG_TASK_USB_CHG_STACK_SIZE) \ + CROS_EC_TASK(CHARGER, charger_task, 0, CONFIG_TASK_CHARGER_STACK_SIZE) \ + CROS_EC_TASK(HOSTCMD, host_command_task, 0, \ + CONFIG_TASK_HOSTCMD_STACK_SIZE) \ + CROS_EC_TASK(PD_C0, pd_task, 0, CONFIG_TASK_PD_STACK_SIZE) +#endif /* __CROS_EC_SHIMMED_TEST_TASKS_H */ diff --git a/zephyr/test/drivers/src/battery.c b/zephyr/test/drivers/src/battery.c new file mode 100644 index 0000000000..315f822985 --- /dev/null +++ b/zephyr/test/drivers/src/battery.c @@ -0,0 +1,35 @@ +/* Copyright 2021 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.h> +#include <ztest.h> +#include <drivers/gpio.h> +#include <drivers/gpio/gpio_emul.h> + +#include "battery.h" + +#define GPIO_BATT_PRES_ODL_PATH DT_PATH(named_gpios, ec_batt_pres_odl) +#define GPIO_BATT_PRES_ODL_PORT DT_GPIO_PIN(GPIO_BATT_PRES_ODL_PATH, gpios) + +static void test_battery_is_present_gpio(void) +{ + const struct device *dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_BATT_PRES_ODL_PATH, gpios)); + + zassert_not_null(dev, NULL); + /* ec_batt_pres_odl = 0 means battery present. */ + zassert_ok(gpio_emul_input_set(dev, GPIO_BATT_PRES_ODL_PORT, 0), NULL); + zassert_equal(BP_YES, battery_is_present(), NULL); + /* ec_batt_pres_odl = 1 means battery missing. */ + zassert_ok(gpio_emul_input_set(dev, GPIO_BATT_PRES_ODL_PORT, 1), NULL); + zassert_equal(BP_NO, battery_is_present(), NULL); +} + +void test_suite_battery(void) +{ + ztest_test_suite(battery, + ztest_user_unit_test(test_battery_is_present_gpio)); + ztest_run_test_suite(battery); +} diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c new file mode 100644 index 0000000000..7c5113d4ab --- /dev/null +++ b/zephyr/test/drivers/src/main.c @@ -0,0 +1,20 @@ +/* Copyright 2021 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.h> +#include <ztest.h> +#include "ec_app_main.h" + +extern void test_suite_battery(void); + +void test_main(void) +{ + /* Test suites to run before ec_app_main.*/ + + ec_app_main(); + + /* Test suites to run after ec_app_main.*/ + test_suite_battery(); +} diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c new file mode 100644 index 0000000000..afa3f2f2d6 --- /dev/null +++ b/zephyr/test/drivers/src/stubs.c @@ -0,0 +1,181 @@ +/* Copyright 2021 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 "battery.h" +#include "battery_fuel_gauge.h" +#include "bc12/pi3usb9201_public.h" +#include "charge_ramp.h" +#include "charger.h" +#include "charger/isl9241_public.h" +#include "config.h" +#include "i2c/i2c.h" +#include "ppc/sn5s330_public.h" +#include "ppc/syv682x_public.h" +#include "retimer/bb_retimer_public.h" +#include "stubs.h" +#include "tcpm/tusb422_public.h" +#include "tcpm/tusb422_public.h" +#include "usb_mux.h" +#include "usb_pd_tcpm.h" +#include "usbc_ppc.h" + +/* All of these definitions are just to get the test to link. None of these + * functions are useful or behave as they should. Please remove them once the + * real code is able to be added. Most of the things here should either be + * in emulators or in the native_posix board-specific code or part of the + * device tree. + */ + +/* BC1.2 charger detect configuration */ +const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { + [USBC_PORT_C0] = { + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + }, + [USBC_PORT_C1] = { + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT); + +/* Charger Chip Configuration */ +const struct charger_config_t chg_chips[] = { + { + .i2c_port = I2C_PORT_CHARGER, + .i2c_addr_flags = ISL9241_ADDR_FLAGS, + .drv = &isl9241_drv, + }, +}; + +const struct board_batt_params board_battery_info[] = { + /* LGC\011 L17L3PB0 Battery Information */ + /* + * Battery info provided by ODM on b/143477210, comment #11 + */ + [BATTERY_LGC011] = { + .fuel_gauge = { + .manuf_name = "LGC", + .ship_mode = { + .reg_addr = 0x00, + .reg_data = { 0x10, 0x10 }, + }, + .fet = { + .reg_addr = 0x0, + .reg_mask = 0x6000, + .disconnect_val = 0x6000, + } + }, + .batt_info = { + .voltage_max = TARGET_WITH_MARGIN(13200, 5), + .voltage_normal = 11550, /* mV */ + .voltage_min = 9000, /* mV */ + .precharge_current = 256, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 75, + }, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); + +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_LGC011; + +int board_set_active_charge_port(int port) +{ + return EC_SUCCESS; +} + +int extpower_is_present(void) +{ + return 0; +} + +int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) +{ + return 0; +} + +void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, + int charge_mv) +{ +} + +struct tcpc_config_t tcpc_config[] = { + [USBC_PORT_C0] = { + .bus_type = EC_BUS_TYPE_I2C, + .i2c_info = { + .port = I2C_PORT_USB_C0, + .addr_flags = TUSB422_I2C_ADDR_FLAGS, + }, + .drv = &tusb422_tcpm_drv, + }, + [USBC_PORT_C1] = { + .bus_type = EC_BUS_TYPE_I2C, + .i2c_info = { + .port = I2C_PORT_USB_C1, + .addr_flags = TUSB422_I2C_ADDR_FLAGS, + }, + .drv = &tusb422_tcpm_drv, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == USBC_PORT_COUNT); +BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT); + +int board_is_sourcing_vbus(int port) +{ + return 0; +} + +struct usb_mux usb_muxes[] = { + [USBC_PORT_C0] = { + .usb_port = USBC_PORT_C0, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + }, + [USBC_PORT_C1] = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT); + +void pd_power_supply_reset(int port) +{ +} + +int pd_check_vconn_swap(int port) +{ + return 0; +} + +int pd_set_power_supply_ready(int port) +{ + return EC_SUCCESS; +} + +/* USBC PPC configuration */ +struct ppc_config_t ppc_chips[] = { + [USBC_PORT_C0] = { + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = SN5S330_ADDR0_FLAGS, + .drv = &sn5s330_drv, + }, + [USBC_PORT_C1] = { + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = SN5S330_ADDR1_FLAGS, + .drv = &sn5s330_drv, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT); +unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); + +void system_hibernate(uint32_t seconds, uint32_t microseconds) +{ +} diff --git a/zephyr/test/drivers/stubs.h b/zephyr/test/drivers/stubs.h new file mode 100644 index 0000000000..847de8e083 --- /dev/null +++ b/zephyr/test/drivers/stubs.h @@ -0,0 +1,6 @@ +/* Copyright 2021 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. + */ + +enum usbc_port { USBC_PORT_C0 = 0, USBC_PORT_C1, USBC_PORT_COUNT }; diff --git a/zephyr/test/drivers/zmake.yaml b/zephyr/test/drivers/zmake.yaml new file mode 100644 index 0000000000..2ca03ac8dd --- /dev/null +++ b/zephyr/test/drivers/zmake.yaml @@ -0,0 +1,12 @@ +# Copyright 2021 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. + +board: native_posix +supported-zephyr-versions: + - v2.5 +toolchain: llvm +output-type: elf +is-test: true +dts-overlays: + - overlay.dts |