test: fatal exception: add test case

Add regex in testcase.yaml to verify the kernel will dump
thread id information and error type when exception occurs.

Signed-off-by: Ying ming <mingx.ying@intel.com>
This commit is contained in:
Ying ming 2020-09-14 14:43:24 +08:00 committed by Anas Nashif
commit 13e1c919d4
5 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(message_capture)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1,5 @@
This test case verifies that kernel fatal error logging message can be captured.
When the fatal error is triggered, if the debugging message function is turned on,
the system can capture the print information.

View file

@ -0,0 +1,2 @@
CONFIG_LOG=y
CONFIG_LOG_MINIMAL=y

View file

@ -0,0 +1,77 @@
/*
* Copyright (c) Copyright (c) 2020 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <sys/printk.h>
static volatile int expected_reason = -1;
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;
}
/**
* @brief This test case verifies when fatal error
* log message can be captured.
* @details
* Test Objective:
* - When the fatal error is triggered, if the debugging message function
* is turned on, the system can capture the log information.
*
* Prerequisite Conditions:
* - N/A
*
* Input Specifications:
* - N/A
*
* Test Procedure:
* -# Writing a function deliberately triggers a koops exception.
* -# When the log module is enabled, it will log some information
* in the process of exception.
* -# The regex in testcase.yaml verify the kernel will dump thread id
* information and error type when exception occurs.
*
* Expected Test Result:
* - The expected log message is caught.
*
* Pass/Fail Criteria:
* - Success if the log matching regex in step 3.
* - Failure if the log is not matching regex in step 3.
*
* Assumptions and Constraints:
* - N/A
* @ingroup kernel_fatal_tests
*/
void test_message_capture(void)
{
unsigned int key;
expected_reason = K_ERR_KERNEL_OOPS;
key = irq_lock();
k_oops();
printk("SHOULD NEVER SEE THIS\n");
irq_unlock(key);
}
void main(void)
{
test_message_capture();
}

View file

@ -0,0 +1,9 @@
tests:
kernel.logging.message_capture:
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Current thread: (.*)"
- "Caught system error -- reason (.*)"