Skip to content

Commit 1cda0ee

Browse files
bjarki-andreasenkartben
authored andcommitted
tests: drivers: spi: spi_loopback: impl pm_device_runtime support
Implement pm_device_runtime support to spi_loopback test suite. Specifically: - call pm_device_runtime_get() on SPI bus before using SPI bus - call pm_device_runtime_put() once SPI bus is no longer needed. This is after transceive has been performed, or after calling spi_release_dt() after a transceive has been performed. This addition has no affect if PM_DEVICE_RUNTIME is not enabled on a board/test case basis. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
1 parent cbd9535 commit 1cda0ee

File tree

1 file changed

+8
-3
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+8
-3
lines changed

tests/drivers/spi/spi_loopback/src/spi.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <zephyr/ztest.h>
1717
#include <zephyr/drivers/spi.h>
18+
#include <zephyr/pm/device_runtime.h>
1819
#include <zephyr/kernel.h>
1920
#include <stdio.h>
2021
#include <stdarg.h>
@@ -104,9 +105,12 @@ static void spi_loopback_transceive(struct spi_dt_spec *const spec,
104105
const struct spi_buf_set *const tx,
105106
const struct spi_buf_set *const rx)
106107
{
107-
int ret = spi_transceive_dt(spec, tx, rx);
108+
int ret;
108109

109-
zassert_false(ret, "SPI transceive failed, code %d", ret);
110+
zassert_ok(pm_device_runtime_get(spec->bus));
111+
ret = spi_transceive_dt(spec, tx, rx);
112+
zassert_ok(ret, "SPI transceive failed, code %d", ret);
113+
zassert_ok(pm_device_runtime_put(spec->bus));
110114
}
111115

112116
/* The most spi buf currently used by any test case is 4, change if needed */
@@ -443,9 +447,10 @@ ZTEST(spi_extra_api_features, test_spi_lock_release)
443447

444448
lock_spec->config.operation |= SPI_LOCK_ON;
445449

450+
zassert_ok(pm_device_runtime_get(lock_spec->bus));
446451
spi_loopback_transceive(lock_spec, &tx, &rx);
447-
448452
zassert_false(spi_release_dt(lock_spec), "SPI release failed");
453+
zassert_ok(pm_device_runtime_put(lock_spec->bus));
449454

450455
spi_loopback_transceive(try_spec, &tx, &rx);
451456

0 commit comments

Comments
 (0)