tests: drivers: pm: spi: pm integrated with spi - #877
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Zephyr ztest-based validation app under tests/drivers/pm/spi to exercise Alif RTSS power-management state transitions (runtime idle, suspend-to-idle, S2RAM where supported, and soft-off), optionally running concurrent SPI master/slave loopback traffic that is suspended/resumed around low-power entry/exit.
Changes:
- Introduces PM state transition test runner (
src/main.c) with PM notifier hooks and multiple ztest suites for HP/HE cores and boot modes. - Adds a background SPI loopback implementation (
src/spi_test.c+inc/spi_test.h) with start/suspend/resume control for tests. - Adds board snippet overlays (HP/HE variants), sample metadata (
sample.yaml), and build/config files (prj.conf,CMakeLists.txt,Kconfig,README.rst).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/drivers/pm/spi/src/spi_test.c | Implements SPI master/slave background threads and suspend/resume control used during PM transitions. |
| tests/drivers/pm/spi/src/main.c | Implements PM state transition ztests, PM notifier callbacks, and integrates SPI background activity. |
| tests/drivers/pm/spi/inc/spi_test.h | Declares SPI background thread control API used by the test runner. |
| tests/drivers/pm/spi/snippets/spi-pm-hp/spi_pm_hp_ensemble.overlay | HP board overlay enabling wake source/console and configuring SPI aliases for loopback. |
| tests/drivers/pm/spi/snippets/spi-pm-hp/snippet.yml | Snippet selector mapping HP boards to the HP overlay. |
| tests/drivers/pm/spi/snippets/spi-pm-he/spi_pm_he_ensemble.overlay | HE (Ensemble) overlay enabling wake source/console and configuring SPI aliases for loopback. |
| tests/drivers/pm/spi/snippets/spi-pm-he/spi_pm_he_balletto.overlay | HE (Balletto) overlay enabling wake source/console and configuring SPI aliases for loopback. |
| tests/drivers/pm/spi/snippets/spi-pm-he/snippet.yml | Snippet selector mapping HE boards to the appropriate HE overlay. |
| tests/drivers/pm/spi/sample.yaml | Twister metadata for running the test on supported Alif platforms with overlays/snippets. |
| tests/drivers/pm/spi/README.rst | Documentation describing the test purpose, suites, requirements, and build/run commands. |
| tests/drivers/pm/spi/prj.conf | Kconfig settings enabling PM, SPI, logging, counter, and ztest for this test app. |
| tests/drivers/pm/spi/Kconfig | Defines a Kconfig entry point for the test application. |
| tests/drivers/pm/spi/CMakeLists.txt | Zephyr app build wiring (sources + include paths). |
Comments suppressed due to low confidence (6)
tests/drivers/pm/spi/src/spi_test.c:168
- When
spi_transceive()fails, this function still runsmemcmp()and returns thememcmp()result, which can mask the actual SPI error. Return immediately on transceive failure.
ret = spi_transceive(dev, &cnfg, &tx_bufset, &rx_bufset);
if (ret) {
LOG_ERR("ERROR: SPI=%p transceive: %d", dev, ret);
}
tests/drivers/pm/spi/src/spi_test.c:279
- If thread creation fails, this function logs the error but still returns success; subsequent start/suspend calls will behave unpredictably. Propagate the failure to the caller.
if (tidm == NULL) {
LOG_ERR("Error creating Master Thread");
}
tests/drivers/pm/spi/src/spi_test.c:347
- Returning
-1loses the specific error reason and is inconsistent with Zephyr-style errno returns. Use a standard errno like-EINVALwhen threads haven't been started.
if (!spi_threads_started) {
return -1;
}
tests/drivers/pm/spi/src/main.c:426
spi_pm_thread_suspend()is currently only called for deep sleep whenCONFIG_CORTEX_M_SYSTICK_LPM_TIMER_COUNTERis set; for the counter-alarm path, SPI can continue running while the system tries to enter deep sleep. Suspend SPI before the#ifso it applies to both paths.
#ifdef SPI_PM_TEST
spi_pm_thread_suspend();
LOG_INF("==SPI Transactions are Suspended: for Deep Sleep");
#endif
tests/drivers/pm/spi/README.rst:131
- This build command references
samples/drivers/pm/spi-pm-testcode, which doesn't exist in this repository; it should point to thetests/drivers/pm/spidirectory.
../alif/samples/drivers/pm/spi-pm-testcode \
-S spi-pm-hp
tests/drivers/pm/spi/README.rst:123
- This build command references
samples/drivers/pm/spi-pm-testcode, which doesn't exist in this repository; it should point to thetests/drivers/pm/spidirectory.
../alif/samples/drivers/pm/spi-pm-testcode \
-S spi-pm-he
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| #include "spi_test.h" | ||
|
|
||
| LOG_MODULE_DECLARE(pm_system_off, LOG_LEVEL_DBG); |
| uint8_t THREAD_TO_BE_SUSPEND; | ||
| uint8_t THREAD_SUSPENDED; |
| */ | ||
| int slave_spi_transceive(const struct device *dev) | ||
| { | ||
| struct spi_config cnfg; |
| ret = spi_transceive(dev, &cnfg, &tx_bufset, &rx_bufset); | ||
| if (ret < 0) { | ||
| LOG_ERR("ERROR: Slave SPI Transceive: %d", ret); | ||
| } |
| int master_spi_transceive(const struct device *dev, | ||
| struct spi_cs_control *cs) | ||
| { | ||
| struct spi_config cnfg; |
| * | ||
| * You should have received a copy of the Alif Semiconductor Software | ||
| * License Agreement with this file. If not, please write to: | ||
| * contact@alifsemi.com, or visit: https: //alifsemi.com/license |
| #if defined(CONFIG_CORTEX_M_SYSTICK_LPM_TIMER_COUNTER) | ||
|
|
||
| #ifdef SPI_PM_TEST | ||
| spi_pm_thread_suspend(); | ||
| LOG_INF("====== SPI Transactions are Suspended"); | ||
| #endif | ||
|
|
||
| k_sleep(K_USEC(sleep_usec)); | ||
| #else |
| const struct device *const wakeup_dev = DEVICE_DT_GET(WAKEUP_SOURCE); | ||
| struct counter_alarm_cfg alarm_cfg; | ||
| int ret; | ||
| /* | ||
| * Set the alarm and delay so that idle thread can run | ||
| */ | ||
| alarm_cfg.ticks = counter_us_to_ticks(wakeup_dev, sleep_usec); | ||
| ret = counter_set_channel_alarm(wakeup_dev, 0, &alarm_cfg); |
| */ | ||
|
|
||
| /* Wait for UART to finish transmitting logs */ | ||
| k_msleep(100); /* ← add this */ |
| ../alif/samples/drivers/pm/spi-pm-testcode \ | ||
| -S spi-pm-he \ |
Zephyr ztest-based validation of power management state transitions on Alif RTSS cores, with optional SPI background. Signed-off-by: Nikhil-AlifSemi <nikhil@alifsemi.com>
35cd569 to
e11026d
Compare
Zephyr ztest-based
validation of power management state
transitions on Alif RTSS cores,
with optional SPI background.