tests: arch: arm: interrupt: add test-case for spurious exception

We add a simple test case to verify the behavior
of z_arm_exc_spurious handler. We use the SysTick
interrupt for that so the test is enabled for
platforms that have but do not use the SysTick.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2020-04-03 13:53:21 +02:00 committed by Kumar Gala
commit 56a09428e1
2 changed files with 35 additions and 1 deletions

View file

@ -7,7 +7,8 @@ Description:
The first test verifies that we can handle system fault conditions The first test verifies that we can handle system fault conditions
while running in handler mode (i.e. in an ISR). Only for ARM while running in handler mode (i.e. in an ISR). Only for ARM
Cortex-M targets. The test also verifies the behavior of the Cortex-M targets. The test also verifies the behavior of the
spurious interrupt handler. spurious interrupt handler, as well as the ARM spurious exception
handler.
The second test verifies that threads in user mode, despite being able to call The second test verifies that threads in user mode, despite being able to call
the irq_lock() and irq_unlock() functions without triggering a CPU fault, the irq_lock() and irq_unlock() functions without triggering a CPU fault,

View file

@ -47,6 +47,15 @@ void arm_isr_handler(void *args)
/* Intentional ASSERT */ /* Intentional ASSERT */
expected_reason = K_ERR_KERNEL_PANIC; expected_reason = K_ERR_KERNEL_PANIC;
__ASSERT(0, "Intentional assert\n"); __ASSERT(0, "Intentional assert\n");
} else if (test_flag == 4) {
#if defined(CONFIG_CPU_CORTEX_M_HAS_SYSTICK)
#if !defined(CONFIG_SYS_CLOCK_EXISTS) || !defined(CONFIG_CORTEX_M_SYSTICK)
expected_reason = K_ERR_CPU_EXCEPTION;
SCB->ICSR |= SCB_ICSR_PENDSTSET_Msk;
__DSB();
__ISB();
#endif
#endif
} }
} }
@ -132,6 +141,30 @@ void test_arm_interrupt(void)
post_flag = test_flag; post_flag = test_flag;
zassert_true(post_flag == j, "Test flag not set by ISR\n"); zassert_true(post_flag == j, "Test flag not set by ISR\n");
} }
#if defined(CONFIG_CPU_CORTEX_M_HAS_SYSTICK)
#if !defined(CONFIG_SYS_CLOCK_EXISTS) || !defined(CONFIG_CORTEX_M_SYSTICK)
/* Verify that triggering a Cortex-M exception (accidentally) that has
* not been installed in the vector table, leads to the reserved
* exception been called and a resulting CPU fault. We test this using
* the SysTick exception in platforms that are not expecting to use the
* SysTick timer for system timing.
*/
/* The ISR will manually set the SysTick exception to pending state. */
NVIC_SetPendingIRQ(i);
__DSB();
__ISB();
/* Verify that the spurious exception has led to the fault and the
* expected reason variable is reset.
*/
reason = expected_reason;
zassert_equal(reason, -1,
"expected_reason has not been reset (%d)\n", reason);
#endif
#endif
} }
#if defined(CONFIG_USERSPACE) #if defined(CONFIG_USERSPACE)