From 8714154338d639f0073cb257d174c7676641b548 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 20 Jan 2022 22:42:15 +0100 Subject: [PATCH] tests: pm: policy_api: check status lock behavior Test that policy manager behavior is correct when allowing/forbidding certain states. Signed-off-by: Gerard Marull-Paretas --- tests/subsys/pm/policy_api/src/main.c | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/subsys/pm/policy_api/src/main.c b/tests/subsys/pm/policy_api/src/main.c index fc5a35c540c..4f3ab1fd7d8 100644 --- a/tests/subsys/pm/policy_api/src/main.c +++ b/tests/subsys/pm/policy_api/src/main.c @@ -56,11 +56,57 @@ static void test_pm_policy_next_state_default(void) next = pm_policy_next_state(1U, K_TICKS_FOREVER); zassert_equal(next->state, PM_STATE_SUSPEND_TO_RAM, NULL); } + +/** + * @brief Test the behavior of pm_policy_next_state() when + * states are allowed/disallowed and CONFIG_PM_POLICY_DEFAULT=y. + */ +static void test_pm_policy_next_state_default_allowed(void) +{ + bool active; + const struct pm_state_info *next; + + /* initial state: PM_STATE_RUNTIME_IDLE allowed + * next state: PM_STATE_RUNTIME_IDLE + */ + active = pm_policy_state_lock_is_active(PM_STATE_RUNTIME_IDLE); + zassert_false(active, NULL); + + next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000)); + zassert_equal(next->state, PM_STATE_RUNTIME_IDLE, NULL); + + /* disallow PM_STATE_RUNTIME_IDLE + * next state: NULL (active) + */ + pm_policy_state_lock_get(PM_STATE_RUNTIME_IDLE); + + active = pm_policy_state_lock_is_active(PM_STATE_RUNTIME_IDLE); + zassert_true(active, NULL); + + next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000)); + zassert_equal(next, NULL, NULL); + + /* allow PM_STATE_RUNTIME_IDLE again + * next state: PM_STATE_RUNTIME_IDLE + */ + pm_policy_state_lock_put(PM_STATE_RUNTIME_IDLE); + + active = pm_policy_state_lock_is_active(PM_STATE_RUNTIME_IDLE); + zassert_false(active, NULL); + + next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000)); + zassert_equal(next->state, PM_STATE_RUNTIME_IDLE, NULL); +} #else static void test_pm_policy_next_state_default(void) { ztest_test_skip(); } + +static void test_pm_policy_next_state_default_allowed(void) +{ + ztest_test_skip(); +} #endif /* CONFIG_PM_POLICY_DEFAULT */ #ifdef CONFIG_PM_POLICY_CUSTOM @@ -96,6 +142,7 @@ void test_main(void) { ztest_test_suite(policy_api, ztest_unit_test(test_pm_policy_next_state_default), + ztest_unit_test(test_pm_policy_next_state_default_allowed), ztest_unit_test(test_pm_policy_next_state_custom)); ztest_run_test_suite(policy_api); }