Commit graph

36 commits

Author SHA1 Message Date
Flavio Ceolin
3fb4e70306 tests: pm/device_runtime: Test pm_device_runtime_usage
Add tests covering possible branches in pm_device_runtime_usage()

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-05-22 15:08:39 -05:00
Flavio Ceolin
1ed452b295 tests: pm/device_runtime: Run in native_sim only
This is an API test and it was not designed to run in a real target.
Some attempts to run this test in devices cause the device to hang
after the test execution because the device sleeps and no wake up
source is set.

Fixes #68453

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-04-22 21:03:06 -04:00
Flavio Ceolin
3b895064af pm: Remove state lock/unlock API
This API is not widely used and it is actually broken since device
runtime power management is not checking it when suspending and
resuming.

On top of that, this API is very close to pm_device_busy* API,
close enough to consolidate in only one API.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-04-09 20:11:48 +02:00
Krzysztof Chruściński
ee13631362 pm: device_runtime: Extend existing API with ISR_SAFE mode
Extend macros from creating a PM device with an optional argument
which indicate whether type of device is ISR_SAFE or not.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-02-01 15:03:42 +01:00
Krzysztof Chruściński
5ce4348311 tests: pm: device_runtime_api: Extend with synchronous device
Extended test to support case when PM device is defined as
synchronous.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-02-01 15:03:42 +01:00
Mateusz Junkier
949e5120d3 pm: increase coverage - add missing api tests
add missing api tests reported by codecov

Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
2023-12-27 15:57:39 +00:00
Mateusz Junkier
501e67acd2 pm: increase coverage - add missing test assert
cover missing lines reported by codecov

Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
2023-12-27 15:57:39 +00:00
Flavio Ceolin
c724a6c5ef tests: pm: device_runtime_api: Check async behavior
Additional test to check if getting a device while there
is a pending async put does not trigger unnecessary device
state changes.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:57:34 +01:00
Flavio Ceolin
3f7325e34b tests: pm: device_runtime: Checks async put with delay
Checks that async put respects the given delay.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:57:34 +01:00
Flavio Ceolin
b5ca7a06b4 pm: device_runtime: Add delay to async put
Add a delay parameter to asynchronous device runtim put. This allows
to delay the put operation what is useful to avoid multiple states
transitions.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:57:34 +01:00
Alberto Escolar Piedras
b39d7c2c3d tests/subsys/pm/*: Switch to native_sim
Enable all these tests which run in native_posix in native_sim,
Switch from native_posix to native_sim as default test platform
And switch native_posix overlays to native_sim.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-22 09:53:54 +01:00
Anas Nashif
345735d0a8 tests: remove CONFIG_ZTEST_NEW_API in all tests
Remove all usage of CONFIG_ZTEST_NEW_API from tests and sample as this
is now enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Gerard Marull-Paretas
724274247a tests: pm: move all devices to POST_KERNEL
There's no need to use APPLICATION level.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-15 16:04:19 +02:00
Daniel Leung
a206764878 tests: pm: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Anas Nashif
0064b6e8b6 tests: samples: cleanup test tags, add integration_platforms
Use integration platforms and sanitize tags.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-06-02 04:47:06 -04:00
Gerard Marull-Paretas
1eb683a514 device: remove redundant init functions
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-19 10:00:25 +02:00
Jordan Yates
cf9c34462c tests: pm: device_runtime: test zephyr,pm-device-runtime-auto
Test that the `zephyr,pm-device-runtime-auto` flag correctly enables
PM device runtime on the device instance.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-03-29 12:21:13 -04:00
Jordan Yates
c11e5d82ba tests: pm: device_runtime_api: update expected return values
Update the expected return values for `pm_device_runtime_get/put` when
PM is not supported.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-03-28 17:36:32 -04:00
Kumar Gala
4f0166088c tests: move to using CONFIG_MP_MAX_NUM_CPUS
For tests that set CONFIG_MP_NUM_CPUS, switch to using
CONFIG_MP_MAX_NUM_CPUS instead as we work to phase out
CONFIG_MP_NUM_CPUS.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-20 22:04:10 +09:00
Michał Barnaś
dae8efa692 ztest: remove the obsolete NULL appended to zassert macros
This commit removes the usage of NULL parameter as message in
zassert_* macros after making it optional

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-09-09 07:05:38 -04:00
Gerard Marull-Paretas
a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Yinfang Wang
0f8be291eb tests: subsys: pm: move device_runtime_api to new ztest API.
move device_runtime_api to new ztest API.

Signed-off-by: Yinfang Wang <yinfang.wang@intel.com>
2022-08-15 18:40:17 +00:00
Fabio Baltieri
def230187b test: fix more legacy #include paths
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Jordan Yates
782480313e tests: pm: device_runtime: test PM unsupported behaviour
Test the behaviour of the PM device_runtime API on devices that do not
support power management.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-05-15 21:34:46 +02:00
Gerard Marull-Paretas
ade7ccb918 tests: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:02:14 +02:00
Anas Nashif
97af0c8c33 tests: remove subsys prefix from test identifier
No need for subsys, the subsystem is expected to be the first component
of the identifier.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-03-18 10:50:57 -04:00
Gerard Marull-Paretas
ddc168fa78 pm: s/PM_DEVICE_(DT_(INST))_REF/PM_DEVICE_(DT_(INST))_GET
In order to align with macros used to obtain a device reference (e.g.
DEVICE_DT_GET), align the PM macros to use "GET" instead of "REF". This
change should have low impact since no official release has gone out yet
with the "REF" macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-18 12:14:06 -05:00
Gerard Marull-Paretas
91b8abfb4d pm: device_runtime: suspend device on enable
The pm_device_runtime_enable did not suspend devices, so it assumed that
the device was in a physically suspended state. This change makes sure
that device is left in a suspended state if the device is initially
active.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-12-16 10:41:04 +01:00
Gerard Marull-Paretas
59b455eb9c pm: device_runtime: simplify error handling for get/put
In case runtime PM is not enabled (or not built-in), the get/put
functions always return 0 (instead of -ENOTSUP/-ENOSYS). When runtime PM
is disabled, a device is left into active state. Similarly, when device
runtime PM is not built-in, it is safe to assume that a device will
be active when it is called. If a user implements a custom solution, it
is its responsability to make sure that a device is active when using
it. For all these reasons, the -ENOTSUP/-ENOSYS are error codes that
should always be ignored by devices using get/put, since in practice it
means that: device is active, function is a no-op. The example below
illustrates how error handling is simplified:

```c
/* before: safe to ignore -ENOSYS/-ENOTSUP since device is active (we
 * can continue)
 */
ret = pm_device_runtime_get(dev);
if ((ret < 0) && (ret != -ENOSYS) && (ret != -ENOTSUP)) {
	return ret;
}

/* now */
ret = pm_device_runtime_get(dev);
if (ret < 0) {
	return ret;
}
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-12-16 10:41:04 +01:00
Flavio Ceolin
8cd6744498 tests: pm: Test state lock with runtime
Add device pm state lock to device runtime test.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-12-14 19:23:05 -05:00
Gerard Marull-Paretas
89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Gerard Marull-Paretas
39f21dc116 tests: pm: use new PM macros
Use PM_DEVICE_STATE_DEFINE to define PM state.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-19 10:11:32 +01:00
Flavio Ceolin
d7a2f6e8de tests: pm: device_runtime: Avoid race condition
The test was done with one cpu in mind. In a SMP environment there is
race condition where the semaphor can be given before the other thread
take block waiting for it.

Fixes #40068

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-09 08:31:42 -05:00
Gerard Marull-Paretas
18519ffe8d tests: use common PM action callback naming
The PM callback is no longer referenced as "pm_control" but
"pm_action_cb", so reflect this new naming on the callbacks.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 20:27:18 -04:00
Gerard Marull-Paretas
1cee284a46 pm: device: runtime: use pm_device_runtime* namespace
Move all PM device runtime API calls from pm_device* to the
pm_device_runtime* namespace.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 16:37:33 -04:00
Gerard Marull-Paretas
05e5a72e03 tests: pm: device_runtime: add test for the API
Add a test for the device runtime API that makes sure most common usage
scenarios behave as expected:

- get + put
- get + asynchronous put until suspended
- get + asynchronous put + get (while suspend still ongoing)

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 16:37:33 -04:00