diff options
author | Peter Marheine <pmarheine@chromium.org> | 2023-04-06 14:31:58 +1000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-19 01:39:51 +0000 |
commit | 1b5cbe58be80e428aced08ac0692019822ddf81a (patch) | |
tree | 7f43287eb8d88f5d60cf3d31bb94156e24fd412b | |
parent | a9b2f8893bff2cb6576b456fa1582382ef6f9418 (diff) | |
download | chrome-ec-1b5cbe58be80e428aced08ac0692019822ddf81a.tar.gz |
nissa: implement tests for project common.c
This file contains some utility functions that are fairly straightforward
to test, but requires more complex build configuration than the existing
sub_board tests because it requires the charger code be built in.
The SM5803 input voltage checks are not fully tested because the
isl923x driver does not implement get_battery_cells(); testing that will
require a SM5803 emulator.
BUG=b:267959470
TEST=./twister -T zephyr/test/nissa
BRANCH=nissa
Change-Id: Ic89f8f84b1889cfb4fe588fdd7c6f06a817e76c1
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4402420
Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r-- | zephyr/test/nissa/CMakeLists.txt | 15 | ||||
-rw-r--r-- | zephyr/test/nissa/Kconfig | 18 | ||||
-rw-r--r-- | zephyr/test/nissa/boards/chargers.dts | 53 | ||||
-rw-r--r-- | zephyr/test/nissa/boards/generic_npcx.dts | 6 | ||||
-rw-r--r-- | zephyr/test/nissa/charger.conf | 24 | ||||
-rw-r--r-- | zephyr/test/nissa/prj.conf | 1 | ||||
-rw-r--r-- | zephyr/test/nissa/src/common.c | 115 | ||||
-rw-r--r-- | zephyr/test/nissa/src/log_module.c | 8 | ||||
-rw-r--r-- | zephyr/test/nissa/src/stubs.c | 7 | ||||
-rw-r--r-- | zephyr/test/nissa/testcase.yaml | 11 |
10 files changed, 255 insertions, 3 deletions
diff --git a/zephyr/test/nissa/CMakeLists.txt b/zephyr/test/nissa/CMakeLists.txt index dc351aa3b6..6574575a09 100644 --- a/zephyr/test/nissa/CMakeLists.txt +++ b/zephyr/test/nissa/CMakeLists.txt @@ -10,8 +10,17 @@ add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils) zephyr_include_directories("${PLATFORM_EC_PROGRAM_DIR}/nissa/include") -target_sources(app PRIVATE src/stubs.c src/sub_board.c) +target_sources(app PRIVATE src/stubs.c) -target_sources(app PRIVATE - ${PLATFORM_EC_PROGRAM_DIR}/nissa/src/sub_board.c +target_sources_ifdef( + CONFIG_TEST_NISSA_SUB_BOARD + app PRIVATE + src/sub_board.c + src/log_module.c + ${PLATFORM_EC_PROGRAM_DIR}/nissa/src/sub_board.c) + +target_sources_ifdef( + CONFIG_TEST_NISSA_COMMON + app PRIVATE + src/common.c ${PLATFORM_EC_PROGRAM_DIR}/nissa/src/common.c) diff --git a/zephyr/test/nissa/Kconfig b/zephyr/test/nissa/Kconfig index f8215bbf37..9e6d4de468 100644 --- a/zephyr/test/nissa/Kconfig +++ b/zephyr/test/nissa/Kconfig @@ -2,6 +2,24 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +choice TEST_TARGET + prompt "Select test target to build" + help + Select the build target for a given test. Each test target must select + exactly one, because some tests assume configuration that conflicts with + others. + + config TEST_NISSA_SUB_BOARD + bool "Tests for sub_board.c" + help + The test target that exercises nissa/src/sub_board.c. + + config TEST_NISSA_COMMON + bool "Tests for common.c" + help + The test target that exercises nissa/src/common.c. +endchoice + module = NISSA module-str = Nissa board-specific code (unit tests) source "subsys/logging/Kconfig.template.log_config" diff --git a/zephyr/test/nissa/boards/chargers.dts b/zephyr/test/nissa/boards/chargers.dts new file mode 100644 index 0000000000..a14e9fbf10 --- /dev/null +++ b/zephyr/test/nissa/boards/chargers.dts @@ -0,0 +1,53 @@ +/ { + named-i2c-ports { + i2c_ec_i2c_batt: ec_i2c_batt { + i2c-port = <&i2c_ctrl7>; + enum-names = "I2C_PORT_BATTERY"; + }; + }; + + usbc { + port0@0 { + chg = <&chg_port0>; + }; + port1@1 { + chg = <&chg_port1>; + }; + }; + + batteries { + default_battery: lgc { + compatible = "lgc,ap18c8k", "battery-smart"; + }; + }; +}; + +&i2c_ctrl3 { + chg_port0: isl923x@9 { + compatible = "cros,isl923x-emul", "intersil,isl923x"; + status = "okay"; + reg = <0x9>; + battery = <&battery>; + }; +}; + +&i2c_ctrl5 { + chg_port1: isl923x@9 { + compatible = "cros,isl923x-emul", "intersil,isl923x"; + status = "okay"; + reg = <0x9>; + }; +}; + +&i2c_ctrl7 { + battery: sb@b { + compatible = "zephyr,smart-battery-emul"; + reg = <0xb>; + cycle-count = <6>; + version = "BATTERY_SPEC_VER_1_1_WITH_PEC"; + desired-charg-volt = <11250>; + desired-charg-cur = <2400>; + mf-name = "LGC"; + dev-name = "AP18C8K"; + }; +}; diff --git a/zephyr/test/nissa/boards/generic_npcx.dts b/zephyr/test/nissa/boards/generic_npcx.dts index 1639dc80c8..7849f19473 100644 --- a/zephyr/test/nissa/boards/generic_npcx.dts +++ b/zephyr/test/nissa/boards/generic_npcx.dts @@ -20,6 +20,8 @@ gpio-hpd-odl = &gpio_sb_4; /* LTE */ gpio-en-sub-s5-rails = &gpio_sb_2; + + gpio-wp = &gpio_ec_wp_odl; }; gpio-interrupts { @@ -49,6 +51,10 @@ gpios = <&gpioe 4 GPIO_OUTPUT>; }; + gpio_ec_wp_odl: ec_wp_odl { + gpios = <&gpioa 1 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; + }; + entering_rw { gpios = <&gpio0 3 GPIO_OUTPUT>; enum-name = "GPIO_ENTERING_RW"; diff --git a/zephyr/test/nissa/charger.conf b/zephyr/test/nissa/charger.conf new file mode 100644 index 0000000000..d96973deb5 --- /dev/null +++ b/zephyr/test/nissa/charger.conf @@ -0,0 +1,24 @@ +# 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. + +# Additional configuration for emulated Nissa boards where tests require +# charger-related code. + +CONFIG_PLATFORM_EC_HOSTCMD=y +CONFIG_PLATFORM_EC_CHARGER=y +CONFIG_PLATFORM_EC_OCPC=y +CONFIG_PLATFORM_EC_CHARGER_SM5803=y +CONFIG_PLATFORM_EC_CHARGER_RAA489000=y +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10 +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=10 +CONFIG_PLATFORM_EC_OCPC_DEF_RBATT_MOHMS=22 +CONFIG_PLATFORM_EC_CONSOLE_CMD_CHARGER_ADC_AMON_BMON=n +CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y +CONFIG_PLATFORM_EC_BACKLIGHT_LID=n +CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y +# charger_get_system_power() in RAA489000 driver +CONFIG_PLATFORM_EC_CHARGER_PSYS_READ=n +CONFIG_ADC_SHELL=n +CONFIG_PLATFORM_EC_PD_MAX_VOLTAGE_MV=15000 +CONFIG_PLATFORM_EC_VBOOT_HASH=n diff --git a/zephyr/test/nissa/prj.conf b/zephyr/test/nissa/prj.conf index 3d4f0e5f3d..62c2b29782 100644 --- a/zephyr/test/nissa/prj.conf +++ b/zephyr/test/nissa/prj.conf @@ -19,6 +19,7 @@ CONFIG_PLATFORM_EC_USB_PD_DISCHARGE=n CONFIG_PLATFORM_EC_USB_CHARGER=n CONFIG_PLATFORM_EC_USB_PD_HOST_CMD=n CONFIG_PLATFORM_EC_USB_PORT_ENABLE_DYNAMIC=y +CONFIG_PLATFORM_EC_SWITCH=n # Allow the test fixture to use k_malloc CONFIG_HEAP_MEM_POOL_SIZE=1024
\ No newline at end of file diff --git a/zephyr/test/nissa/src/common.c b/zephyr/test/nissa/src/common.c new file mode 100644 index 0000000000..a90520902a --- /dev/null +++ b/zephyr/test/nissa/src/common.c @@ -0,0 +1,115 @@ +/* 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 "ap_power/ap_power_events.h" +#include "battery.h" +#include "charger.h" +#include "hooks.h" +#include "ocpc.h" +#include "usb_pd.h" + +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/fff.h> +#include <zephyr/ztest.h> + +FAKE_VALUE_FUNC(enum battery_present, battery_is_present); +FAKE_VALUE_FUNC(int, board_set_active_charge_port, int); +FAKE_VALUE_FUNC(uint8_t, board_get_usb_pd_port_count); +FAKE_VALUE_FUNC(int, power_button_is_pressed); + +static void suite_before(void *fixture) +{ + RESET_FAKE(battery_is_present); + RESET_FAKE(board_get_usb_pd_port_count); + RESET_FAKE(board_set_active_charge_port); + RESET_FAKE(power_button_is_pressed); +} + +ZTEST_SUITE(nissa_common, NULL, NULL, suite_before, NULL, NULL); + +ZTEST(nissa_common, test_pen_power_control) +{ + const struct gpio_dt_spec *const pen_power = + GPIO_DT_FROM_NODELABEL(gpio_en_pp5000_pen_x); + + hook_notify(HOOK_INIT); + zassert_false(gpio_emul_output_get(pen_power->port, pen_power->pin), + "Pen power should be off by default"); + + ap_power_ev_send_callbacks(AP_POWER_STARTUP); + zassert_true(gpio_emul_output_get(pen_power->port, pen_power->pin), + "Pen power should be on after AP startup"); + + ap_power_ev_send_callbacks(AP_POWER_SHUTDOWN); + zassert_false(gpio_emul_output_get(pen_power->port, pen_power->pin), + "Pen power should be off after AP shutdown"); +} + +ZTEST(nissa_common, test_hibernate) +{ + const struct gpio_dt_spec *const hibernate_enable = + GPIO_DT_FROM_NODELABEL(gpio_en_slp_z); + + zassert_false(gpio_emul_output_get(hibernate_enable->port, + hibernate_enable->pin), + "Hibernate pin should be low by default"); + board_hibernate_late(); + zassert_true(gpio_emul_output_get(hibernate_enable->port, + hibernate_enable->pin), + "Hibernate pin should go high to hibernate"); +} + +ZTEST(nissa_common, test_vconn_swap) +{ + const struct gpio_dt_spec *const dsw_pwrok = + GPIO_DT_FROM_NODELABEL(gpio_ec_soc_dsw_pwrok); + + /* AP 5V rail is off. */ + zassert_false(gpio_pin_get_dt(dsw_pwrok)); + zassert_false(pd_check_vconn_swap(0)); + zassert_false(pd_check_vconn_swap(1)); + + /* + * Case with the rail on is untestable because emulated GPIOs don't + * allow getting the current value of output pins. + */ +} + +ZTEST(nissa_common, test_ocpc_configuration) +{ + int kp, kp_div; + int ki, ki_div; + int kd, kd_div; + struct ocpc_data ocpc_data = {}; + + ocpc_get_pid_constants(&kp, &kp_div, &ki, &ki_div, &kd, &kd_div); + + /* + * Only proportional control is used, at 1/32 gain. Gain of integral and + * derivative terms is zero. + */ + zassert_equal(kp, 1); + zassert_equal(kp_div, 32); + zassert_equal(ki, 0); + zassert_not_equal(ki_div, 0); + zassert_equal(kd, 0); + zassert_not_equal(kd_div, 0); + + /* With two chargers, we note that Isys can't be measured. */ + zassert_equal(CONFIG_USB_PD_PORT_MAX_COUNT, 2); + board_get_usb_pd_port_count_fake.return_val = 2; + board_ocpc_init(&ocpc_data); + zassert_equal(ocpc_data.chg_flags[1], OCPC_NO_ISYS_MEAS_CAP); +} + +ZTEST(nissa_common, test_sm5803_buck_boost_forbidden) +{ + zassert_true(pd_is_valid_input_voltage(12000)); + + /* + * TODO(b:267959470): use SM5803 emulator for this test so behavior can + * be verified with assorted battery cell counts. + */ +} diff --git a/zephyr/test/nissa/src/log_module.c b/zephyr/test/nissa/src/log_module.c new file mode 100644 index 0000000000..e8556a5886 --- /dev/null +++ b/zephyr/test/nissa/src/log_module.c @@ -0,0 +1,8 @@ +/* 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/logging/log.h> + +LOG_MODULE_REGISTER(nissa, CONFIG_NISSA_LOG_LEVEL); diff --git a/zephyr/test/nissa/src/stubs.c b/zephyr/test/nissa/src/stubs.c index 970232197e..0e45fefc17 100644 --- a/zephyr/test/nissa/src/stubs.c +++ b/zephyr/test/nissa/src/stubs.c @@ -8,6 +8,8 @@ #include "common.h" +#include <zephyr/fff.h> + __overridable void pd_power_supply_reset(int port) { } @@ -22,6 +24,11 @@ __overridable void pd_set_input_current_limit(int port, uint32_t max_ma, { } +__overridable int pd_check_vconn_swap(int port) +{ + return 0; +} + __overridable void usb_interrupt_c0(enum gpio_signal signal) { } diff --git a/zephyr/test/nissa/testcase.yaml b/zephyr/test/nissa/testcase.yaml index c9b568e326..cd519cbefb 100644 --- a/zephyr/test/nissa/testcase.yaml +++ b/zephyr/test/nissa/testcase.yaml @@ -8,3 +8,14 @@ tests: nissa.sub_board: extra_dtc_overlay_files: - "boards/generic_npcx.dts" + extra_configs: + - CONFIG_TEST_NISSA_SUB_BOARD=y + nissa.common: + extra_dtc_overlay_files: + - "boards/generic_npcx.dts" + - "boards/chargers.dts" + extra_conf_files: + - "prj.conf" + - "charger.conf" + extra_configs: + - CONFIG_TEST_NISSA_COMMON=y |