Skip to content

tests: drivers: pm: spi: pm integrated with spi - #877

Open
Nikhil-AlifSemi wants to merge 1 commit into
alifsemi:mainfrom
Nikhil-AlifSemi:spi_test_code
Open

tests: drivers: pm: spi: pm integrated with spi#877
Nikhil-AlifSemi wants to merge 1 commit into
alifsemi:mainfrom
Nikhil-AlifSemi:spi_test_code

Conversation

@Nikhil-AlifSemi

Copy link
Copy Markdown

Zephyr ztest-based
validation of power management state
transitions on Alif RTSS cores,
with optional SPI background.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 runs memcmp() and returns the memcmp() 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 -1 loses the specific error reason and is inconsistent with Zephyr-style errno returns. Use a standard errno like -EINVAL when 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 when CONFIG_CORTEX_M_SYSTICK_LPM_TIMER_COUNTER is set; for the counter-alarm path, SPI can continue running while the system tries to enter deep sleep. Suspend SPI before the #if so 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 the tests/drivers/pm/spi directory.
       ../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 the tests/drivers/pm/spi directory.
       ../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.

Comment thread tests/drivers/pm/spi/src/spi_test.c Outdated

#include "spi_test.h"

LOG_MODULE_DECLARE(pm_system_off, LOG_LEVEL_DBG);
Comment thread tests/drivers/pm/spi/src/spi_test.c Outdated
Comment on lines +72 to +73
uint8_t THREAD_TO_BE_SUSPEND;
uint8_t THREAD_SUSPENDED;
Comment thread tests/drivers/pm/spi/src/spi_test.c Outdated
*/
int slave_spi_transceive(const struct device *dev)
{
struct spi_config cnfg;
Comment on lines +116 to +119
ret = spi_transceive(dev, &cnfg, &tx_bufset, &rx_bufset);
if (ret < 0) {
LOG_ERR("ERROR: Slave SPI Transceive: %d", ret);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already fixed

Comment thread tests/drivers/pm/spi/src/spi_test.c Outdated
int master_spi_transceive(const struct device *dev,
struct spi_cs_control *cs)
{
struct spi_config cnfg;
Comment thread tests/drivers/pm/spi/src/main.c Outdated
*
* 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
Comment thread tests/drivers/pm/spi/src/main.c Outdated
Comment on lines +382 to +390
#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
Comment on lines +438 to +445
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);
Comment thread tests/drivers/pm/spi/src/main.c Outdated
*/

/* Wait for UART to finish transmitting logs */
k_msleep(100); /* ← add this */
Comment thread tests/drivers/pm/spi/README.rst Outdated
Comment on lines +111 to +112
../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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants