diff --git a/subsys/testsuite/ztest/Kconfig b/subsys/testsuite/ztest/Kconfig index 6d1998576d3..afdd6964cb8 100644 --- a/subsys/testsuite/ztest/Kconfig +++ b/subsys/testsuite/ztest/Kconfig @@ -79,6 +79,14 @@ config ZTEST_ASSERT_HOOK error test case. Remember to add ignore_fault tag in yaml file when using twister to run testing. +config ZTEST_NO_YIELD + bool "Do not yield to the idle thread after tests complete" + help + When the tests complete, do not yield to the idle thread and instead + spin in a loop. This is useful for low power mode tests, where + yielding to the idle thread may put the board into a low power state + where a debugger cannot connect to it. + if ZTEST_NEW_API menu "ztest provided rules" diff --git a/subsys/testsuite/ztest/src/ztest.c b/subsys/testsuite/ztest/src/ztest.c index bbf15663f5d..58c440b5fe6 100644 --- a/subsys/testsuite/ztest/src/ztest.c +++ b/subsys/testsuite/ztest/src/ztest.c @@ -579,5 +579,17 @@ void main(void) state.boots = 0; } } +#ifdef CONFIG_ZTEST_NO_YIELD + /* + * Rather than yielding to idle thread, keep the part awake so debugger can + * still access it, since some SOCs cannot be debugged in low power states. + */ + uint32_t key = irq_lock(); + + while (1) { + ; /* Spin */ + } + irq_unlock(key); +#endif } #endif