Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm: Fix possible undefined reference #64154

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/zephyr/pm/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ struct pm_state_info {
}


#if defined(CONFIG_PM) || defined(__DOXYGEN__)
/**
* Obtain information about all supported states by a CPU.
*
Expand All @@ -343,6 +344,18 @@ uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states);
* @}
*/

#else /* CONFIG_PM */

static inline uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states)
{
ARG_UNUSED(cpu);
ARG_UNUSED(states);

return 0;
}

#endif /* CONFIG_PM */

#ifdef __cplusplus
}
#endif
Expand Down
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_PM=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=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
Loading