tests: add fatal test case
We want to show that if a non-essential thread gets a fatal exception, that thread gets aborted but the rest of the system works properly. We also test that k_oops() does the same. Issue: ZEP-2052 Change-Id: I0f88bcae865bf12bb91bb55e50e8ac9721672434 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
75caa2b084
commit
ca441162a7
6 changed files with 91 additions and 0 deletions
5
tests/kernel/fatal/Makefile
Normal file
5
tests/kernel/fatal/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.test
|
4
tests/kernel/fatal/README
Normal file
4
tests/kernel/fatal/README
Normal file
|
@ -0,0 +1,4 @@
|
|||
This test case verifies that kernel fatal error handling works correctly.
|
||||
|
||||
If a thread causes a CPU exception, and it is not in an ISR or "essential"
|
||||
thread, the thread gets aborted and the rest of the system executes normally.
|
2
tests/kernel/fatal/prj.conf
Normal file
2
tests/kernel/fatal/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_MAIN_THREAD_PRIORITY=7
|
||||
|
3
tests/kernel/fatal/src/Makefile
Normal file
3
tests/kernel/fatal/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
ccflags-y += -I${ZEPHYR_BASE}/tests/include
|
||||
|
||||
obj-y = main.o
|
75
tests/kernel/fatal/src/main.c
Normal file
75
tests/kernel/fatal/src/main.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <tc_util.h>
|
||||
#include <kernel_structs.h>
|
||||
#include <irq_offload.h>
|
||||
|
||||
#define STACKSIZE 1024
|
||||
#define PRIORITY 5
|
||||
|
||||
static char __noinit __stack alt_stack[STACKSIZE];
|
||||
volatile int rv;
|
||||
|
||||
void alt_thread1(void)
|
||||
{
|
||||
#if defined(CONFIG_X86)
|
||||
__asm__ volatile ("ud2");
|
||||
#elif defined(CONFIG_NIOS2)
|
||||
__asm__ volatile ("trap");
|
||||
#else
|
||||
/* Triggers usage fault on ARM, illegal instruction on RISCV32, ARC,
|
||||
* and xtensa
|
||||
*/
|
||||
{
|
||||
int illegal = 0;
|
||||
((void(*)(void))&illegal)();
|
||||
}
|
||||
#endif
|
||||
rv = TC_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void alt_thread2(void)
|
||||
{
|
||||
k_oops();
|
||||
rv = TC_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
rv = TC_PASS;
|
||||
|
||||
TC_START("test_fatal");
|
||||
|
||||
printk("test alt thread 1: generic CPU exception\n");
|
||||
k_thread_spawn(alt_stack, STACKSIZE, (k_thread_entry_t)alt_thread1,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(PRIORITY), 0,
|
||||
K_NO_WAIT);
|
||||
if (rv == TC_FAIL) {
|
||||
printk("thread was not aborted\n");
|
||||
goto out;
|
||||
} else {
|
||||
printk("PASS\n");
|
||||
}
|
||||
|
||||
printk("test alt thread 2: initiate kernel oops\n");
|
||||
k_thread_spawn(alt_stack, STACKSIZE, (k_thread_entry_t)alt_thread2,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(PRIORITY), 0,
|
||||
K_NO_WAIT);
|
||||
if (rv == TC_FAIL) {
|
||||
printk("thread was not aborted\n");
|
||||
goto out;
|
||||
} else {
|
||||
printk("PASS\n");
|
||||
}
|
||||
|
||||
out:
|
||||
TC_END_RESULT(rv);
|
||||
TC_END_REPORT(rv);
|
||||
}
|
2
tests/kernel/fatal/testcase.ini
Normal file
2
tests/kernel/fatal/testcase.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
[test]
|
||||
tags = core
|
Loading…
Add table
Add a link
Reference in a new issue