test: arm: no-multithreading: test triggering PendSV

Add a test case to verify that triggering a
PendSV will lead to a Reserved Exception and
a CPU error, in the no-multithreading case.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2021-06-18 11:38:55 +02:00 committed by Christopher Friedt
commit ab7258a9d5
2 changed files with 35 additions and 1 deletions

View file

@ -11,6 +11,7 @@ ARM Cortex-M targets. In detail the test verifies that
- FPU state is reset (if applicable)
- Interrupts are enabled when switching to main()
- Interrupts may be registerd and serviced
- Activating PendSV triggers a Reserved Exception error
---------------------------------------------------------------------------
@ -38,8 +39,16 @@ or
Sample Output:
*** Booting Zephyr OS build zephyr-v2.3.0-1561-ge877a95387ae ***
*** Booting Zephyr OS build zephyr-v2.6.0-349-g032d10878792 ***
ARM no-multithreading test
E: ***** Reserved Exception ( -2) *****
E: r0/a1: 0x0000001b r1/a2: 0x000044d8 r2/a3: 0xe000ed00
E: r3/a4: 0x10000000 r12/ip: 0x0000000a r14/lr: 0x00001473
E: xpsr: 0x61000000
E: Faulting instruction address (r15/pc): 0x00001510
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: (nil) (unknown)
Caught system error -- reason 0
Available IRQ line: 25
ARM no multithreading test successful
===================================================================

View file

@ -16,6 +16,7 @@
extern K_THREAD_STACK_DEFINE(z_main_stack, CONFIG_MAIN_STACK_SIZE);
static volatile int test_flag;
static unsigned int expected_reason;
void arm_isr_handler(const void *args)
{
@ -24,6 +25,24 @@ void arm_isr_handler(const void *args)
test_flag++;
}
void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf)
{
printk("Caught system error -- reason %d\n", reason);
if (expected_reason == -1) {
printk("Was not expecting a crash\n");
k_fatal_halt(reason);
}
if (reason != expected_reason) {
printk("Wrong crash type got %d expected %d\n", reason,
expected_reason);
k_fatal_halt(reason);
}
expected_reason = -1;
}
void test_main(void)
{
printk("ARM no-multithreading test\n");
@ -57,6 +76,12 @@ void test_main(void)
arch_irq_unlock(key);
/* Verify activating the PendSV IRQ triggers a K_ERR_SPURIOUS_IRQ */
expected_reason = K_ERR_CPU_EXCEPTION;
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
__DSB();
__ISB();
/* Determine an NVIC IRQ line that is not currently in use. */
int i, flag = test_flag;