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:
Andrew Boie 2017-04-19 15:43:05 -07:00 committed by Anas Nashif
commit ca441162a7
6 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,5 @@
BOARD ?= qemu_x86
CONF_FILE = prj.conf
include ${ZEPHYR_BASE}/Makefile.test

View 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.

View file

@ -0,0 +1,2 @@
CONFIG_MAIN_THREAD_PRIORITY=7

View file

@ -0,0 +1,3 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = main.o

View 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);
}

View file

@ -0,0 +1,2 @@
[test]
tags = core