Skip to content

Commit

Permalink
tests: arch: common: add stack_unwind test
Browse files Browse the repository at this point in the history
Added test for archs that support it. It triggers an exception
and verify that the fatal message has stack unwind info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
  • Loading branch information
ycsin committed Apr 11, 2024
1 parent 4479cdd commit 7f9debb
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/arch/common/stack_unwind/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024 Meta
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(stack_unwind_test)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
11 changes: 11 additions & 0 deletions tests/arch/common/stack_unwind/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_TEST=y

CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=2048

CONFIG_EXCEPTION_STACK_TRACE=y
CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y
CONFIG_OMIT_FRAME_POINTER=n
CONFIG_DEBUG=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_OPTIMIZATIONS=y
39 changes: 39 additions & 0 deletions tests/arch/common/stack_unwind/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <stdbool.h>

#include <zephyr/kernel.h>

static void func1(int a);
static void func2(int a);

static void func2(int a)
{
printf("%d: %s\n", a, __func__);

if (a >= 5) {
k_oops();
}

func1(a + 1);
}

static void func1(int a)
{
printf("%d: %s\n", a, __func__);
func2(a + 1);
}

int main(void)
{
printf("Hello World! %s\n", CONFIG_BOARD);

func1(1);

return 0;
}
39 changes: 39 additions & 0 deletions tests/arch/common/stack_unwind/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
common:
harness: console
ignore_faults: true
ignore_qemu_crash: true
tags: kernel
tests:
arch.common.stack_unwind.riscv:
arch_allow: riscv
integration_platforms:
- qemu_riscv32
- qemu_riscv64
harness_config:
type: multi_line
regex:
- "E: call trace:"
- "E: 0: fp: \\w+ ra: \\w+"
- "E: 1: fp: \\w+ ra: \\w+"
arch.common.stack_unwind.x86:
arch_allow: x86
extra_configs:
- CONFIG_NO_OPTIMIZATIONS=y
integration_platforms:
- qemu_x86
- qemu_x86_64
harness_config:
type: multi_line
regex:
- "E: call trace:"
- "E: (E|R)IP: \\w+"
arch.common.stack_unwind.arm:
arch_allow:
- arm64
integration_platforms:
- qemu_cortex_a53
harness_config:
type: multi_line
regex:
- "E: backtrace 0: fp: \\w+ lr: \\w+"
- "E: backtrace 1: fp: \\w+ lr: \\w+"

0 comments on commit 7f9debb

Please sign in to comment.