tests: pm: test `pm_device_driver_init`
Test that `pm_device_driver_init` puts devices into the appropriate state depending on the devicetree configuration. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
b82bbf5e31
commit
a4cfc1eb37
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) 2023, CSIRO.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(device_driver_init)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
|
@ -0,0 +1,44 @@
|
|||
/ {
|
||||
test_reg: test_reg {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 0 0>;
|
||||
};
|
||||
|
||||
test_reg_chained: test_reg_chained {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 1 0>;
|
||||
power-domain = <&test_reg>;
|
||||
};
|
||||
|
||||
test_reg_chained_auto: test_reg_chained_auto {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 2 0>;
|
||||
power-domain = <&test_reg>;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
test_reg_auto: test_reg_auto {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 3 0>;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
test_reg_auto_chained: test_reg_auto_chained {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 4 0>;
|
||||
power-domain = <&test_reg_auto>;
|
||||
};
|
||||
|
||||
test_reg_auto_chained_auto: test_reg_auto_chained_auto {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 5 0>;
|
||||
power-domain = <&test_reg_auto>;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
test_reg_disabled: test_reg_disabled {
|
||||
compatible = "power-domain-gpio";
|
||||
enable-gpios = <&gpio0 6 0>;
|
||||
status = "disabled";
|
||||
};
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2023, Commonwealth Scientific and Industrial Research
|
||||
# Organisation (CSIRO) ABN 41 687 119 230.
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_MP_MAX_NUM_CPUS=1
|
||||
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_GPIO_GET_CONFIG=y
|
||||
CONFIG_POWER_DOMAIN=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Commonwealth Scientific and Industrial Research
|
||||
* Organisation (CSIRO) ABN 41 687 119 230.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* State checking in this test is done via the GPIO state instead of
|
||||
* the PM API as this test runs without the PM api enabled.
|
||||
*/
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
|
||||
#define POWER_GPIO_CONFIG_IS(node_id, config)\
|
||||
{\
|
||||
const struct gpio_dt_spec gpio = GPIO_DT_SPEC_GET(node_id, enable_gpios);\
|
||||
gpio_flags_t gpio_config; \
|
||||
int rc = gpio_pin_get_config_dt(&gpio, &gpio_config); \
|
||||
zassert_equal(rc, 0, "GPIO config retrieval failed"); \
|
||||
zassert_equal(gpio_config, config, "Unexpected config");\
|
||||
}
|
||||
|
||||
#define DEVICE_STATE_IS(node_id, value) \
|
||||
rc = pm_device_state_get(DEVICE_DT_GET(node_id), &state); \
|
||||
zassert_equal(rc, 0, "Device state retrieval failed"); \
|
||||
zassert_equal(state, value, "Unexpected device state");
|
||||
|
||||
ZTEST(device_driver_init, test_demo)
|
||||
{
|
||||
#if !IS_ENABLED(CONFIG_PM) || !IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
|
||||
/* Every regulator should be in "active" mode automatically.
|
||||
* State checking via GPIO as PM API is disabled.
|
||||
*/
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_chained), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_chained_auto), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto_chained), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto_chained_auto), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_disabled), GPIO_DISCONNECTED);
|
||||
#endif
|
||||
|
||||
#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
|
||||
enum pm_device_state state;
|
||||
int rc;
|
||||
|
||||
/* No device runtime PM, starts on */
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg), PM_DEVICE_STATE_ACTIVE);
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg_chained), PM_DEVICE_STATE_ACTIVE);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg), GPIO_OUTPUT_HIGH);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_chained), GPIO_OUTPUT_HIGH);
|
||||
|
||||
/* Device powered, zephyr,pm-device-runtime-auto, starts suspended */
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg_chained_auto), PM_DEVICE_STATE_SUSPENDED);
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg_auto), PM_DEVICE_STATE_SUSPENDED);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_chained_auto), GPIO_OUTPUT_LOW);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto), GPIO_OUTPUT_LOW);
|
||||
/* Device not powered, starts off */
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg_auto_chained), PM_DEVICE_STATE_OFF);
|
||||
DEVICE_STATE_IS(DT_NODELABEL(test_reg_auto_chained_auto), PM_DEVICE_STATE_OFF);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto_chained), GPIO_DISCONNECTED);
|
||||
POWER_GPIO_CONFIG_IS(DT_NODELABEL(test_reg_auto_chained_auto), GPIO_DISCONNECTED);
|
||||
#endif
|
||||
}
|
||||
|
||||
ZTEST_SUITE(device_driver_init, NULL, NULL, NULL, NULL, NULL);
|
|
@ -0,0 +1,19 @@
|
|||
tests:
|
||||
pm.device_driver_init:
|
||||
tags: pm
|
||||
platform_allow: qemu_cortex_m3
|
||||
pm.device_driver_init.pm:
|
||||
tags: pm
|
||||
platform_allow: qemu_cortex_m3
|
||||
extra_configs:
|
||||
- CONFIG_PM=y
|
||||
- CONFIG_PM_DEVICE=y
|
||||
- CONFIG_PM_DEVICE_POWER_DOMAIN=y
|
||||
pm.device_driver_init.pm_device_runtime:
|
||||
tags: pm
|
||||
platform_allow: qemu_cortex_m3
|
||||
extra_configs:
|
||||
- CONFIG_PM=y
|
||||
- CONFIG_PM_DEVICE=y
|
||||
- CONFIG_PM_DEVICE_POWER_DOMAIN=y
|
||||
- CONFIG_PM_DEVICE_RUNTIME=y
|
Loading…
Reference in New Issue