From 513eb4337793c4aeadfca938d2f01cdaa7767410 Mon Sep 17 00:00:00 2001 From: Arkadiusz Cholewinski Date: Thu, 27 Mar 2025 14:53:09 +0100 Subject: [PATCH] tests: power_states: Verifies the transition to all available power states During the test, pytest detects each step and calculates the RMS (Root Mean Square) current for every detected state. The test then compares the calculated RMS values against the expected values. Signed-off-by: Arkadiusz Cholewinski --- tests/subsys/pm/power_states/CMakeLists.txt | 9 ++++ .../power_states/boards/stm32l562e_dk.overlay | 29 +++++++++++ tests/subsys/pm/power_states/prj.conf | 4 ++ tests/subsys/pm/power_states/src/main.c | 36 +++++++++++++ tests/subsys/pm/power_states/testcase.yaml | 50 +++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 tests/subsys/pm/power_states/CMakeLists.txt create mode 100644 tests/subsys/pm/power_states/boards/stm32l562e_dk.overlay create mode 100644 tests/subsys/pm/power_states/prj.conf create mode 100644 tests/subsys/pm/power_states/src/main.c create mode 100644 tests/subsys/pm/power_states/testcase.yaml diff --git a/tests/subsys/pm/power_states/CMakeLists.txt b/tests/subsys/pm/power_states/CMakeLists.txt new file mode 100644 index 00000000000..83e018923b6 --- /dev/null +++ b/tests/subsys/pm/power_states/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(power_states) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/subsys/pm/power_states/boards/stm32l562e_dk.overlay b/tests/subsys/pm/power_states/boards/stm32l562e_dk.overlay new file mode 100644 index 00000000000..d128ff520ca --- /dev/null +++ b/tests/subsys/pm/power_states/boards/stm32l562e_dk.overlay @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +/ { + zephyr,user { + k_idle_state_min_residency_time = <400000>; + }; +}; + +&stop0{ + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <500000>; +}; +&stop1{ + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <1000000>; +}; +&stop2{ + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <1500000>; +}; diff --git a/tests/subsys/pm/power_states/prj.conf b/tests/subsys/pm/power_states/prj.conf new file mode 100644 index 00000000000..76be0e2b554 --- /dev/null +++ b/tests/subsys/pm/power_states/prj.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2025 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_PM=y diff --git a/tests/subsys/pm/power_states/src/main.c b/tests/subsys/pm/power_states/src/main.c new file mode 100644 index 00000000000..fb043b36d78 --- /dev/null +++ b/tests/subsys/pm/power_states/src/main.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +int main(void) +{ + int k_idle_min_residency_time = + DT_PROP(DT_PATH(zephyr_user), k_idle_state_min_residency_time); + int stop0_min_residency_time = DT_PROP(DT_NODELABEL(stop0), min_residency_us); + int stop1_min_residency_time = DT_PROP(DT_NODELABEL(stop1), min_residency_us); + int stop2_min_residency_time = DT_PROP(DT_NODELABEL(stop2), min_residency_us); + + while (1) { + printk("\nGoing to k_cpu_idle.\n"); + k_usleep(k_idle_min_residency_time); + printk("\nWake Up.\n"); + printk("\nGoing to state 0.\n"); + k_usleep(stop0_min_residency_time); + printk("\nWake Up.\n"); + printk("\nGoing to state 1.\n"); + k_usleep(stop1_min_residency_time); + printk("\nWake Up.\n"); + printk("\nGoing to state 2.\n"); + k_usleep(stop2_min_residency_time); + printk("\nWake Up.\n"); + + /* Anti-sleeping loop */ + while (1) { + arch_nop(); + } + } + return 0; +} diff --git a/tests/subsys/pm/power_states/testcase.yaml b/tests/subsys/pm/power_states/testcase.yaml new file mode 100644 index 00000000000..34415520059 --- /dev/null +++ b/tests/subsys/pm/power_states/testcase.yaml @@ -0,0 +1,50 @@ +# Copyright (c) 2025 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +common: + harness: power + harness_config: + fixture: pm_probe + pytest_dut_scope: session + power_measurements: + elements_to_trim: 100 + min_peak_distance: 40 + min_peak_height: 0.008 + peak_padding: 40 + measurement_duration: 6 + num_of_transitions: 4 + expected_rms_values: [56.0, 4.0, 1.4, 0.26, 140] + tolerance_percentage: 10 + +tests: + pm.power_states: + platform_allow: + - stm32l562e_dk + tags: + - pm + + pm.power_states.pm_device: + platform_allow: + - stm32l562e_dk + tags: + - pm + extra_args: + - CONFIG_PM_DEVICE=y + + pm.power_states.pm_device_runtime: + platform_allow: + - stm32l562e_dk + tags: + - pm + extra_args: + - CONFIG_PM_DEVICE=y + - CONFIG_PM_DEVICE_RUNTIME=y + + pm.power_states.pm_device_system_managed: + platform_allow: + - stm32l562e_dk + tags: + - pm + extra_args: + - CONFIG_PM_DEVICE=y + - CONFIG_PM_DEVICE_SYSTEM_MANAGED=y