Skip to content

Commit

Permalink
tests: pm: Test pm_state_cpu_get_all
Browse files Browse the repository at this point in the history
Add test for pm_state_cpu_get_all API

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin committed Oct 19, 2023
1 parent 625d1bf commit 0c3bb8d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/subsys/pm/power_states_api/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

menu "Zephyr"
source "Kconfig.zephyr"
endmenu

config TEST_PROVIDE_PM_HOOKS
bool "Provide PM hooks for test purposes"
default y
select HAS_PM
1 change: 1 addition & 0 deletions tests/subsys/pm/power_states_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_PM=y
25 changes: 25 additions & 0 deletions tests/subsys/pm/power_states_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@ static enum pm_state states[] = {PM_STATE_SUSPEND_TO_IDLE,
static enum pm_state wrong_states[] = {PM_STATE_SUSPEND_TO_DISK,
PM_STATE_SUSPEND_TO_RAM, PM_STATE_SUSPEND_TO_RAM};

void pm_state_set(enum pm_state state, uint8_t substate_id)
{
ARG_UNUSED(substate_id);
ARG_UNUSED(state);
}

void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
{
ARG_UNUSED(state);
ARG_UNUSED(substate_id);

irq_unlock(0);
}

ZTEST(power_states_1cpu, test_power_states)
{
uint8_t ret;
const struct pm_state_info *cpu_states;
enum pm_state dts_states[] =
PM_STATE_LIST_FROM_DT_CPU(DT_NODELABEL(cpu0));
struct pm_state_info dts_infos[] =
Expand All @@ -36,6 +52,15 @@ ZTEST(power_states_1cpu, test_power_states)

zassert_false(memcmp(wrong_states, dts_states, sizeof(dts_states)) == 0,
"Invalid pm-states array");

ret = pm_state_cpu_get_all(CONFIG_MP_MAX_NUM_CPUS + 1, &cpu_states);
zassert_true(ret == 0, "Invalid pm_state_cpu_get_all return");

ret = pm_state_cpu_get_all(0U, &cpu_states);
zassert_true(ret == dts_states_len,
"Invalid number of pm states");
zassert_true(memcmp(cpu_states, dts_infos, sizeof(dts_infos)) == 0,
"Invalid pm_state_info array");
}

ZTEST_SUITE(power_states_1cpu, NULL, NULL, ztest_simple_1cpu_before,
Expand Down

0 comments on commit 0c3bb8d

Please sign in to comment.