tests: debug: add new coredump_backends
This adds a new coredump_backends test for coredump backends, and currently tests both the logging and flash partition backends. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
2b53f3ded2
commit
c3669c045a
6 changed files with 182 additions and 0 deletions
8
tests/subsys/debug/coredump_backends/CMakeLists.txt
Normal file
8
tests/subsys/debug/coredump_backends/CMakeLists.txt
Normal 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(hello_world)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
23
tests/subsys/debug/coredump_backends/boards/qemu_x86.overlay
Normal file
23
tests/subsys/debug/coredump_backends/boards/qemu_x86.overlay
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <mem.h>
|
||||
|
||||
&flash_sim0 {
|
||||
/*
|
||||
* Sync with qemu_x86.dts on partitions to make sure
|
||||
* size is large enough and there are no overlaps.
|
||||
*/
|
||||
|
||||
partitions {
|
||||
coredump_partition: partition@31000 {
|
||||
label = "coredump-partition";
|
||||
|
||||
reg = <0x31000 DT_SIZE_K(4)>;
|
||||
};
|
||||
|
||||
};
|
||||
};
|
8
tests/subsys/debug/coredump_backends/prj.conf
Normal file
8
tests/subsys/debug/coredump_backends/prj.conf
Normal file
|
@ -0,0 +1,8 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_LOG_MINIMAL=y
|
||||
CONFIG_DEBUG_COREDUMP=y
|
||||
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
|
||||
CONFIG_MP_NUM_CPUS=1
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM=n
|
|
@ -0,0 +1,10 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_TEST_FLASH_DRIVERS=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_LOG_MINIMAL=y
|
||||
CONFIG_DEBUG_COREDUMP=y
|
||||
CONFIG_DEBUG_COREDUMP_BACKEND_FLASH_PARTITION=y
|
||||
CONFIG_MP_NUM_CPUS=1
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM=n
|
117
tests/subsys/debug/coredump_backends/src/main.c
Normal file
117
tests/subsys/debug/coredump_backends/src/main.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <sys/printk.h>
|
||||
|
||||
#include <ztest.h>
|
||||
#include <assert.h>
|
||||
#include <tc_util.h>
|
||||
|
||||
#include <debug/coredump.h>
|
||||
|
||||
#define STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACKSIZE)
|
||||
|
||||
static struct k_thread dump_thread;
|
||||
static K_THREAD_STACK_DEFINE(dump_stack, STACK_SIZE);
|
||||
|
||||
void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf)
|
||||
{
|
||||
ARG_UNUSED(reason);
|
||||
ARG_UNUSED(pEsf);
|
||||
}
|
||||
|
||||
void dump_entry(void *p1, void *p2, void *p3)
|
||||
{
|
||||
unsigned int key;
|
||||
|
||||
key = irq_lock();
|
||||
k_oops();
|
||||
TC_ERROR("SHOULD NEVER SEE THIS\n");
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
||||
static void check_errors(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Check backend error if backend supports this query */
|
||||
ret = coredump_query(COREDUMP_QUERY_GET_ERROR, NULL);
|
||||
if (ret != -ENOTSUP) {
|
||||
zassert_equal(ret, 0, "Error encountered! (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void test_coredump(void)
|
||||
{
|
||||
k_tid_t tid;
|
||||
|
||||
/* Create a thread that crashes */
|
||||
tid = k_thread_create(&dump_thread, dump_stack,
|
||||
K_THREAD_STACK_SIZEOF(dump_stack),
|
||||
dump_entry, NULL, NULL, NULL,
|
||||
0, 0, K_NO_WAIT);
|
||||
|
||||
k_thread_join(tid, K_FOREVER);
|
||||
|
||||
check_errors();
|
||||
}
|
||||
|
||||
void test_query_stored_dump(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Cannot proceed with previous errors */
|
||||
check_errors();
|
||||
|
||||
/* There should be a stored coredump now if backend has storage */
|
||||
ret = coredump_query(COREDUMP_QUERY_HAS_STORED_DUMP, NULL);
|
||||
if (ret == -ENOTSUP) {
|
||||
ztest_test_skip();
|
||||
} else if (ret == 1) {
|
||||
check_errors();
|
||||
ztest_test_pass();
|
||||
} else if (ret == 0) {
|
||||
TC_PRINT("Should have stored dump!\n");
|
||||
ztest_test_fail();
|
||||
} else {
|
||||
TC_PRINT("Error reading stored dump! (%d)\n", ret);
|
||||
ztest_test_fail();
|
||||
}
|
||||
}
|
||||
|
||||
void test_verify_stored_dump(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Cannot proceed with previous errors */
|
||||
check_errors();
|
||||
|
||||
/* There should be a stored coredump now if backend has storage */
|
||||
ret = coredump_cmd(COREDUMP_CMD_VERIFY_STORED_DUMP, NULL);
|
||||
if (ret == -ENOTSUP) {
|
||||
ztest_test_skip();
|
||||
} else if (ret == 1) {
|
||||
check_errors();
|
||||
ztest_test_pass();
|
||||
} else if (ret == 0) {
|
||||
TC_PRINT("Verification of stored dump failed!\n");
|
||||
ztest_test_fail();
|
||||
} else {
|
||||
TC_PRINT("Error reading stored dump! (%d)\n", ret);
|
||||
ztest_test_fail();
|
||||
}
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(coredump_backends,
|
||||
ztest_unit_test(test_coredump),
|
||||
ztest_unit_test(test_query_stored_dump),
|
||||
ztest_unit_test(test_verify_stored_dump));
|
||||
ztest_run_test_suite(coredump_backends);
|
||||
|
||||
}
|
16
tests/subsys/debug/coredump_backends/testcase.yaml
Normal file
16
tests/subsys/debug/coredump_backends/testcase.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
tests:
|
||||
coredump.backends.logging:
|
||||
tags: ignore_faults ignore_qemu_crash
|
||||
filter: CONFIG_ARCH_SUPPORTS_COREDUMP
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "E: #CD:BEGIN#"
|
||||
- "E: #CD:5([aA])45([0-9a-fA-F]+)"
|
||||
- "E: #CD:END#"
|
||||
coredump.backends.flash:
|
||||
tags: ignore_faults ignore_qemu_crash
|
||||
filter: CONFIG_ARCH_SUPPORTS_COREDUMP
|
||||
extra_args: CONF_FILE=prj_flash_partition.conf
|
||||
platform_allow: qemu_x86
|
Loading…
Add table
Add a link
Reference in a new issue