diff options
Diffstat (limited to 'zephyr/test/ap_power')
-rw-r--r-- | zephyr/test/ap_power/BUILD.py | 7 | ||||
-rw-r--r-- | zephyr/test/ap_power/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/test/ap_power/Kconfig | 2 | ||||
-rw-r--r-- | zephyr/test/ap_power/boards/native_posix.overlay (renamed from zephyr/test/ap_power/overlay.dts) | 4 | ||||
-rw-r--r-- | zephyr/test/ap_power/include/test_state.h | 2 | ||||
-rw-r--r-- | zephyr/test/ap_power/prj.conf | 7 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/board.c | 6 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/events.c | 47 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/main.c | 6 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/signals.c | 117 | ||||
-rw-r--r-- | zephyr/test/ap_power/testcase.yaml | 4 |
11 files changed, 118 insertions, 88 deletions
diff --git a/zephyr/test/ap_power/BUILD.py b/zephyr/test/ap_power/BUILD.py deleted file mode 100644 index e3dac8c77e..0000000000 --- a/zephyr/test/ap_power/BUILD.py +++ /dev/null @@ -1,7 +0,0 @@ -# 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. - -"""Register zmake project for ap_power test.""" - -register_host_test("ap_power", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/ap_power/CMakeLists.txt b/zephyr/test/ap_power/CMakeLists.txt index 523db95ede..7b44013961 100644 --- a/zephyr/test/ap_power/CMakeLists.txt +++ b/zephyr/test/ap_power/CMakeLists.txt @@ -1,9 +1,9 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # 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}) +find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}") project(ap_power) # Include the local test directory for shimmed_test_tasks.h diff --git a/zephyr/test/ap_power/Kconfig b/zephyr/test/ap_power/Kconfig index 6faf452ac6..ac7b264855 100644 --- a/zephyr/test/ap_power/Kconfig +++ b/zephyr/test/ap_power/Kconfig @@ -1,4 +1,4 @@ -# Copyright 2022 The Chromium OS Authors. All rights reserved. +# 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. diff --git a/zephyr/test/ap_power/overlay.dts b/zephyr/test/ap_power/boards/native_posix.overlay index d961788c7a..c6cd8c3790 100644 --- a/zephyr/test/ap_power/overlay.dts +++ b/zephyr/test/ap_power/boards/native_posix.overlay @@ -1,8 +1,9 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ +#include <board-overlays/native_posix.dts> #include <cros/binman.dtsi> #include <dt-bindings/gpio_defines.h> #include <freq.h> @@ -187,7 +188,6 @@ status = "okay"; compatible = "zephyr,espi-emul-espi-host"; reg = <0x0>; - label = "ESPI_HOST"; }; }; diff --git a/zephyr/test/ap_power/include/test_state.h b/zephyr/test/ap_power/include/test_state.h index c993fe8ff0..cb91f2b7c7 100644 --- a/zephyr/test/ap_power/include/test_state.h +++ b/zephyr/test/ap_power/include/test_state.h @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ diff --git a/zephyr/test/ap_power/prj.conf b/zephyr/test/ap_power/prj.conf index 86c3f5082d..4dd31085bd 100644 --- a/zephyr/test/ap_power/prj.conf +++ b/zephyr/test/ap_power/prj.conf @@ -1,4 +1,4 @@ -# Copyright 2022 The Chromium OS Authors. All rights reserved. +# 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. @@ -43,8 +43,8 @@ CONFIG_HEAP_MEM_POOL_SIZE=1024 CONFIG_AP_PWRSEQ=y CONFIG_X86_NON_DSX_PWRSEQ_ADL=y CONFIG_AP_X86_INTEL_ADL=y -CONFIG_PLATFORM_EC_ESPI_VW_SLP_S4=y -CONFIG_PLATFORM_EC_ESPI_VW_SLP_S5=y +CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI_VW_SLP_S4=y +CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI_VW_SLP_S5=y CONFIG_AP_PWRSEQ_STACK_SIZE=1024 CONFIG_ESPI=y @@ -54,6 +54,7 @@ CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION=y CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE=y CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD=y CONFIG_PLATFORM_EC_HOSTCMD=y +CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK=y # These items are not required. CONFIG_PLATFORM_EC_BACKLIGHT_LID=n diff --git a/zephyr/test/ap_power/src/board.c b/zephyr/test/ap_power/src/board.c index 96b30d21d3..26c9448396 100644 --- a/zephyr/test/ap_power/src/board.c +++ b/zephyr/test/ap_power/src/board.c @@ -1,10 +1,10 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ -#include <zephyr/zephyr.h> -#include <ztest.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> #include <ap_power_override_functions.h> #include <ap_power/ap_power_interface.h> diff --git a/zephyr/test/ap_power/src/events.c b/zephyr/test/ap_power/src/events.c index de695e945f..ae7d2b870f 100644 --- a/zephyr/test/ap_power/src/events.c +++ b/zephyr/test/ap_power/src/events.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ @@ -10,9 +10,11 @@ #include <zephyr/device.h> +#include <zephyr/drivers/espi.h> +#include <zephyr/drivers/espi_emul.h> #include <zephyr/logging/log.h> -#include <zephyr/zephyr.h> -#include <ztest.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> #include "ap_power/ap_power.h" #include "ap_power/ap_power_events.h" @@ -66,7 +68,7 @@ ZTEST(events, test_registration) ap_power_ev_remove_callback(&cb.cb); ap_power_ev_send_callbacks(AP_POWER_RESET); zassert_equal(1, cb.count, "Callback called"); - cb.count = 0; /* Reset to make it clear */ + cb.count = 0; /* Reset to make it clear */ cb.event = 0; /* Add it twice */ ap_power_ev_add_callback(&cb.cb); @@ -80,6 +82,36 @@ ZTEST(events, test_registration) } /** + * @brief TestPurpose: Verify reset callback from ESPI + * + * @details + * Validate that the reset callback is sent with ESPI PLTRST# + * + * Expected Results + * - The AP_POWER_RESET event is sent + */ +ZTEST(events, test_pltrst) +{ + static struct events cb; + const struct device *espi = + DEVICE_DT_GET_ANY(zephyr_espi_emul_controller); + + zassert_not_null(espi, "Cannot get ESPI device"); + + ap_power_ev_init_callback(&cb.cb, ev_handler, AP_POWER_RESET); + ap_power_ev_add_callback(&cb.cb); + + emul_espi_host_send_vw(espi, ESPI_VWIRE_SIGNAL_PLTRST, 0); + /* + * Since the event is being sent via a deferred function, + * wait for the deferral time. + */ + k_usleep(2 * 1000); + zassert_equal(1, cb.count, "Callback not called"); + zassert_equal(AP_POWER_RESET, cb.event, "Wrong event"); +} + +/** * @brief TestPurpose: Check event mask changes * * @details @@ -145,9 +177,9 @@ ZTEST(events, test_hooks) zassert_equal(0, count_hook_shutdown, "shutdown hook called"); zassert_equal(1, count_hook_startup, "startup hook not called"); zassert_equal(0, count_hook_shutdown, - "reset event, shutdown hook called"); + "reset event, shutdown hook called"); zassert_equal(1, count_hook_startup, - "reset event, startup hook called"); + "reset event, startup hook called"); ap_power_ev_send_callbacks(AP_POWER_SHUTDOWN); zassert_equal(1, count_hook_shutdown, "shutdown hook not called"); zassert_equal(1, count_hook_startup, "startup hook called"); @@ -156,5 +188,4 @@ ZTEST(events, test_hooks) /** * @brief Test Suite: Verifies AP power notification functionality. */ -ZTEST_SUITE(events, ap_power_predicate_post_main, - NULL, NULL, NULL, NULL); +ZTEST_SUITE(events, ap_power_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/ap_power/src/main.c b/zephyr/test/ap_power/src/main.c index 761fcfd997..d653b51164 100644 --- a/zephyr/test/ap_power/src/main.c +++ b/zephyr/test/ap_power/src/main.c @@ -1,10 +1,10 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ -#include <zephyr/zephyr.h> -#include <ztest.h> +#include <zephyr/kernel.h> +#include <zephyr/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 c2ccffb8c9..e8bc6e426c 100644 --- a/zephyr/test/ap_power/src/signals.c +++ b/zephyr/test/ap_power/src/signals.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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. */ @@ -14,12 +14,13 @@ #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 <zephyr/kernel.h> +#include <zephyr/ztest.h> #include "power_signals.h" #include "ec_tasks.h" +#include "emul/emul_stub_device.h" #include "gpio.h" #include "gpio/gpio.h" #include "gpio/gpio_int.h" @@ -37,19 +38,13 @@ static struct { enum power_signal signal; int pin; } signal_to_pin_table[] = { -{ PWR_EN_PP5000_A, 10}, -{ PWR_EN_PP3300_A, 11}, -{ PWR_RSMRST, 12}, -{ PWR_EC_PCH_RSMRST, 13}, -{ PWR_SLP_S0, 14}, -{ PWR_SLP_S3, 15}, -{ PWR_SLP_SUS, 16}, -{ PWR_EC_SOC_DSW_PWROK, 17}, -{ PWR_VCCST_PWRGD, 18}, -{ PWR_IMVP9_VRRDY, 19}, -{ PWR_PCH_PWROK, 20}, -{ PWR_EC_PCH_SYS_PWROK, 21}, -{ PWR_SYS_RST, 22}, + { PWR_EN_PP5000_A, 10 }, { PWR_EN_PP3300_A, 11 }, + { PWR_RSMRST, 12 }, { PWR_EC_PCH_RSMRST, 13 }, + { PWR_SLP_S0, 14 }, { PWR_SLP_S3, 15 }, + { PWR_SLP_SUS, 16 }, { PWR_EC_SOC_DSW_PWROK, 17 }, + { PWR_VCCST_PWRGD, 18 }, { PWR_IMVP9_VRRDY, 19 }, + { PWR_PCH_PWROK, 20 }, { PWR_EC_PCH_SYS_PWROK, 21 }, + { PWR_SYS_RST, 22 }, }; /* @@ -106,9 +101,9 @@ ZTEST(signals, test_validate_request) zassert_equal(-EINVAL, power_signal_enable(PWR_IMVP9_VRRDY), "enable interrupt on input pin without interrupt config"); /* Can't disable interrupt on input with no interrupt flags */ - zassert_equal(-EINVAL, - power_signal_disable(PWR_IMVP9_VRRDY), - "disable interrupt on input pin without interrupt config"); + zassert_equal( + -EINVAL, power_signal_disable(PWR_IMVP9_VRRDY), + "disable interrupt on input pin without interrupt config"); /* Invalid signal - should be rejectde */ zassert_equal(-EINVAL, power_signal_get(-1), "power_signal_get with -1 signal should fail"); @@ -135,7 +130,7 @@ ZTEST(signals, test_board_signals) * Check that the board level signals get correctly invoked. */ zassert_ok(power_signal_set(PWR_ALL_SYS_PWRGD, 1), - "power_signal_set on board signal failed"); + "power_signal_set on board signal failed"); zassert_equal(1, power_signal_get(PWR_ALL_SYS_PWRGD), "power_signal_get on board signal should return 1"); } @@ -153,12 +148,13 @@ ZTEST(signals, test_signal_name) { for (int signal = 0; signal < POWER_SIGNAL_COUNT; signal++) { zassert_not_null(power_signal_name(signal), - "Signal name for %d should be not null", signal); + "Signal name for %d should be not null", + signal); } zassert_is_null(power_signal_name(-1), - "Out of bounds signal name should be null"); + "Out of bounds signal name should be null"); zassert_is_null(power_signal_name(POWER_SIGNAL_COUNT), - "Out of bounds signal name should be null"); + "Out of bounds signal name should be null"); } /** @@ -180,18 +176,19 @@ ZTEST(signals, test_init_outputs) static const enum power_signal active_high[] = { PWR_EN_PP5000_A, PWR_EN_PP3300_A, PWR_EC_PCH_RSMRST, PWR_EC_SOC_DSW_PWROK, PWR_PCH_PWROK - }; + }; static const enum power_signal active_low[] = { PWR_SYS_RST }; for (int i = 0; i < ARRAY_SIZE(active_high); i++) { zassert_equal(0, emul_get(active_high[i]), - "Signal %d (%s) init to de-asserted state failed", - active_high[i], power_signal_name(active_high[i])); + "Signal %d (%s) init to de-asserted state failed", + active_high[i], + power_signal_name(active_high[i])); } for (int i = 0; i < ARRAY_SIZE(active_low); i++) { zassert_equal(1, emul_get(active_low[i]), - "Signal %d (%s) init to de-asserted state failed", - active_low[i], power_signal_name(active_low[i])); + "Signal %d (%s) init to de-asserted state failed", + active_low[i], power_signal_name(active_low[i])); } } @@ -212,14 +209,15 @@ ZTEST(signals, test_gpio_input) "power_signal_get of PWR_RSMRST should be 1"); emul_set(PWR_RSMRST, 0); zassert_equal(0, power_signal_get(PWR_RSMRST), - "power_signal_get of PWR_RSMRST should be 0"); + "power_signal_get of PWR_RSMRST should be 0"); /* ACTIVE_LOW input */ emul_set(PWR_SLP_S0, 0); - zassert_equal(1, power_signal_get(PWR_SLP_S0), - "power_signal_get of active-low signal PWR_SLP_S0 should be 1"); + zassert_equal( + 1, power_signal_get(PWR_SLP_S0), + "power_signal_get of active-low signal PWR_SLP_S0 should be 1"); emul_set(PWR_SLP_S0, 1); zassert_equal(0, power_signal_get(PWR_SLP_S0), - "power_signal_get of active-low PWR_SLP_S0 should be 0"); + "power_signal_get of active-low PWR_SLP_S0 should be 0"); } /** @@ -235,17 +233,17 @@ ZTEST(signals, test_gpio_output) { power_signal_set(PWR_PCH_PWROK, 1); zassert_equal(1, emul_get(PWR_PCH_PWROK), - "power_signal_set of PWR_PCH_PWROK should be 1"); + "power_signal_set of PWR_PCH_PWROK should be 1"); power_signal_set(PWR_PCH_PWROK, 0); zassert_equal(0, emul_get(PWR_PCH_PWROK), - "power_signal_set of PWR_PCH_PWROK should be 0"); + "power_signal_set of PWR_PCH_PWROK should be 0"); /* ACTIVE_LOW output */ power_signal_set(PWR_SYS_RST, 0); zassert_equal(1, emul_get(PWR_SYS_RST), - "power_signal_set of PWR_SYS_RST should be 1"); + "power_signal_set of PWR_SYS_RST should be 1"); power_signal_set(PWR_SYS_RST, 1); zassert_equal(0, emul_get(PWR_SYS_RST), - "power_signal_set of PWR_SYS_RST should be 0"); + "power_signal_set of PWR_SYS_RST should be 0"); } /** @@ -269,7 +267,8 @@ ZTEST(signals, test_signal_mask) * Set board level (polled) signal. */ power_signal_set(PWR_ALL_SYS_PWRGD, 1); - zassert_equal(bm, (power_get_signals() & bm), + zassert_equal( + bm, (power_get_signals() & bm), "Expected PWR_ALL_SYS_PWRGD signal to be present in mask"); /* * Use GPIO that does not interrupt to confirm that a pin change @@ -281,11 +280,11 @@ ZTEST(signals, test_signal_mask) emul_set(PWR_IMVP9_VRRDY, 1); zassert_equal(0, (power_get_signals() & vm), "Expected mask to be 0"); zassert_equal(true, power_signals_match(bm, bm), - "Expected match of mask to signal match"); + "Expected match of mask to signal match"); zassert_equal(-ETIMEDOUT, power_wait_mask_signals_timeout(bm, 0, 5), - "Expected timeout waiting for mask to be 0"); + "Expected timeout waiting for mask to be 0"); zassert_ok(power_wait_mask_signals_timeout(0, vm, 5), - "expected match with a 0 mask (always true)"); + "expected match with a 0 mask (always true)"); } /** @@ -305,7 +304,7 @@ ZTEST(signals, test_debug_mask) old = power_get_debug(); power_set_debug(dm); zassert_equal(dm, power_get_debug(), - "Debug mask does not match set value"); + "Debug mask does not match set value"); /* * Reset back to default. */ @@ -332,10 +331,10 @@ ZTEST(signals, test_gpio_interrupts) /* Check that GPIO pin changes update the signal mask. */ emul_set(PWR_RSMRST, 1); zassert_equal(true, power_signals_on(rsm), - "PWR_RSMRST not updated in mask"); + "PWR_RSMRST not updated in mask"); emul_set(PWR_RSMRST, 0); zassert_equal(true, power_signals_off(rsm), - "PWR_RSMRST not updated in mask"); + "PWR_RSMRST not updated in mask"); /* * Check that an ACTIVE_LOW signal gets asserted in @@ -343,10 +342,10 @@ ZTEST(signals, test_gpio_interrupts) */ emul_set(PWR_SLP_S3, 0); zassert_equal(true, power_signals_on(s3), - "SLP_S3 signal should be on in mask"); + "SLP_S3 signal should be on in mask"); emul_set(PWR_SLP_S3, 1); zassert_equal(true, power_signals_off(s3), - "SLP_S3 should be off in mask"); + "SLP_S3 should be off in mask"); /* * Check that disabled interrupt on the GPIO does not trigger @@ -354,18 +353,18 @@ ZTEST(signals, test_gpio_interrupts) */ emul_set(PWR_SLP_S0, 0); zassert_equal(false, power_signals_on(s0), - "SLP_S0 should not have updated"); + "SLP_S0 should not have updated"); emul_set(PWR_SLP_S0, 1); zassert_equal(false, power_signals_on(s0), - "SLP_S0 should not have updated"); + "SLP_S0 should not have updated"); power_signal_enable(PWR_SLP_S0); emul_set(PWR_SLP_S0, 0); zassert_equal(true, power_signals_on(s0), - "SLP_S0 should have updated the mask"); + "SLP_S0 should have updated the mask"); emul_set(PWR_SLP_S0, 1); zassert_equal(true, power_signals_off(s0), - "SLP_S0 should have updated the mask"); + "SLP_S0 should have updated the mask"); /* * Disable the GPIO interrupt again. @@ -373,10 +372,10 @@ ZTEST(signals, test_gpio_interrupts) power_signal_disable(PWR_SLP_S0); emul_set(PWR_SLP_S0, 0); zassert_equal(false, power_signals_on(s0), - "SLP_S0 should not have updated the mask"); + "SLP_S0 should not have updated the mask"); emul_set(PWR_SLP_S0, 1); zassert_equal(true, power_signals_off(s0), - "SLP_S0 should not have updated the mask"); + "SLP_S0 should not have updated the mask"); } /** @@ -400,16 +399,14 @@ ZTEST(signals, test_espi_vw) * so sending a 0 value should be received as a signal. */ emul_espi_host_send_vw(espi, ESPI_VWIRE_SIGNAL_SLP_S5, 0); - zassert_equal(1, power_signal_get(PWR_SLP_S5), - "VW SLP_S5 should be 1"); + zassert_equal(1, power_signal_get(PWR_SLP_S5), "VW SLP_S5 should be 1"); emul_espi_host_send_vw(espi, ESPI_VWIRE_SIGNAL_SLP_S5, 1); - zassert_equal(0, power_signal_get(PWR_SLP_S5), - "VW SLP_S5 should be 0"); + zassert_equal(0, power_signal_get(PWR_SLP_S5), "VW SLP_S5 should be 0"); } static void *init_dev(void) { - emul_port = device_get_binding("GPIO_0"); + emul_port = DEVICE_DT_GET(DT_NODELABEL(gpio0)); return NULL; } @@ -422,5 +419,9 @@ static void init_signals(void *data) /** * @brief Test Suite: Verifies power signal functionality. */ -ZTEST_SUITE(signals, ap_power_predicate_post_main, - init_dev, init_signals, NULL, NULL); +ZTEST_SUITE(signals, ap_power_predicate_post_main, init_dev, init_signals, NULL, + NULL); + +/* These 2 lines are needed because we don't define an espi host driver */ +#define DT_DRV_COMPAT zephyr_espi_emul_espi_host +DT_INST_FOREACH_STATUS_OKAY(EMUL_STUB_DEVICE); diff --git a/zephyr/test/ap_power/testcase.yaml b/zephyr/test/ap_power/testcase.yaml new file mode 100644 index 0000000000..aaf8a530a6 --- /dev/null +++ b/zephyr/test/ap_power/testcase.yaml @@ -0,0 +1,4 @@ +common: + platform_allow: native_posix +tests: + ap_power.default: {} |