tests: device: update test case
Update pm test case to fix some error last time submission. Add test case that simply check device_pm_enable and device_pm_disable interface. Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
This commit is contained in:
parent
8f9c4e2a1b
commit
9ec3983c3e
1 changed files with 74 additions and 11 deletions
|
@ -202,6 +202,47 @@ static void test_build_suspend_device_list(void)
|
|||
zassert_false((devcount == 0), NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test APIs to enable and disable automatic idle power management
|
||||
*
|
||||
* @details Test the API enable and disable, cause we do not implement our PM
|
||||
* API here, it will use the default function to handle power status. So when
|
||||
* we try to get power state by device_get_power_state(), it will default
|
||||
* return power state zero. And we check it.
|
||||
*
|
||||
* @ingroup kernel_device_tests
|
||||
*/
|
||||
static void test_enable_and_disable_automatic_idle_pm(void)
|
||||
{
|
||||
const struct device *dev;
|
||||
int ret;
|
||||
unsigned int device_power_state = 0;
|
||||
|
||||
dev = device_get_binding(DUMMY_PORT_2);
|
||||
zassert_false((dev == NULL), NULL);
|
||||
|
||||
/* check its status at first */
|
||||
/* for cases that cannot run IDLE power, we skip it now */
|
||||
ret = device_get_power_state(dev, &device_power_state);
|
||||
if (ret == -ENOTSUP) {
|
||||
TC_PRINT("Power management not supported on device");
|
||||
ztest_test_skip();
|
||||
return;
|
||||
}
|
||||
|
||||
zassert_true((ret == 0),
|
||||
"Unable to get active state to device");
|
||||
|
||||
/* enable automatic idle PM and check its status */
|
||||
device_pm_enable(dev);
|
||||
zassert_not_null((dev->pm), "No device pm");
|
||||
zassert_true((dev->pm->enable), "Pm is not enable");
|
||||
|
||||
/* disable automatic idle PM and check its status */
|
||||
device_pm_disable(dev);
|
||||
zassert_false((dev->pm->enable), "Pm shall not be enable");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test device binding for existing device with PM enabled.
|
||||
*
|
||||
|
@ -217,6 +258,7 @@ void test_dummy_device_pm(void)
|
|||
{
|
||||
const struct device *dev;
|
||||
int busy, ret;
|
||||
unsigned int device_power_state = 0;
|
||||
|
||||
dev = device_get_binding(DUMMY_PORT_2);
|
||||
zassert_false((dev == NULL), NULL);
|
||||
|
@ -224,15 +266,6 @@ void test_dummy_device_pm(void)
|
|||
busy = device_any_busy_check();
|
||||
zassert_true((busy == 0), NULL);
|
||||
|
||||
/* Set device state to DEVICE_PM_ACTIVE_STATE */
|
||||
ret = device_set_power_state(dev, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
|
||||
if (ret == -ENOTSUP) {
|
||||
zassert_true((ret == -ENOTSUP),
|
||||
"Power management not supported on device");
|
||||
return;
|
||||
}
|
||||
zassert_true((ret == 0), "Unable to set active state to device");
|
||||
|
||||
/* Set device state to BUSY*/
|
||||
device_busy_set(dev);
|
||||
|
||||
|
@ -248,14 +281,43 @@ void test_dummy_device_pm(void)
|
|||
busy = device_busy_check(dev);
|
||||
zassert_true((busy == 0), NULL);
|
||||
|
||||
test_build_suspend_device_list();
|
||||
|
||||
/* Set device state to DEVICE_PM_ACTIVE_STATE */
|
||||
ret = device_set_power_state(dev, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
|
||||
if (ret == -ENOTSUP) {
|
||||
TC_PRINT("Power management not supported on device");
|
||||
ztest_test_skip();
|
||||
return;
|
||||
}
|
||||
|
||||
zassert_true((ret == 0),
|
||||
"Unable to set active state to device");
|
||||
|
||||
ret = device_get_power_state(dev, &device_power_state);
|
||||
zassert_true((ret == 0),
|
||||
"Unable to get active state to device");
|
||||
zassert_true((device_power_state == DEVICE_PM_ACTIVE_STATE),
|
||||
"Error power status");
|
||||
|
||||
/* Set device state to DEVICE_PM_FORCE_SUSPEND_STATE */
|
||||
ret = device_set_power_state(dev,
|
||||
DEVICE_PM_FORCE_SUSPEND_STATE, NULL, NULL);
|
||||
DEVICE_PM_FORCE_SUSPEND_STATE, NULL, NULL);
|
||||
|
||||
zassert_true((ret == 0), "Unable to force suspend device");
|
||||
|
||||
test_build_suspend_device_list();
|
||||
ret = device_get_power_state(dev, &device_power_state);
|
||||
zassert_true((ret == 0),
|
||||
"Unable to get suspend state to device");
|
||||
zassert_true((device_power_state == DEVICE_PM_ACTIVE_STATE),
|
||||
"Error power status");
|
||||
}
|
||||
#else
|
||||
static void test_enable_and_disable_automatic_idle_pm(void)
|
||||
{
|
||||
ztest_test_skip();
|
||||
}
|
||||
|
||||
static void test_build_suspend_device_list(void)
|
||||
{
|
||||
ztest_test_skip();
|
||||
|
@ -381,6 +443,7 @@ void test_main(void)
|
|||
ztest_unit_test(test_dummy_device_pm),
|
||||
ztest_unit_test(test_build_suspend_device_list),
|
||||
ztest_unit_test(test_dummy_device),
|
||||
ztest_unit_test(test_enable_and_disable_automatic_idle_pm),
|
||||
ztest_unit_test(test_pre_kernel_detection),
|
||||
ztest_user_unit_test(test_bogus_dynamic_name),
|
||||
ztest_user_unit_test(test_dynamic_name),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue