diff --git a/tests/arch/common/stack_unwind/CMakeLists.txt b/tests/arch/common/stack_unwind/CMakeLists.txt new file mode 100644 index 0000000000..65858efd2f --- /dev/null +++ b/tests/arch/common/stack_unwind/CMakeLists.txt @@ -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}) diff --git a/tests/arch/common/stack_unwind/prj.conf b/tests/arch/common/stack_unwind/prj.conf new file mode 100644 index 0000000000..31d2f11f46 --- /dev/null +++ b/tests/arch/common/stack_unwind/prj.conf @@ -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 diff --git a/tests/arch/common/stack_unwind/src/main.c b/tests/arch/common/stack_unwind/src/main.c new file mode 100644 index 0000000000..0436712983 --- /dev/null +++ b/tests/arch/common/stack_unwind/src/main.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +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; +} diff --git a/tests/arch/common/stack_unwind/testcase.yaml b/tests/arch/common/stack_unwind/testcase.yaml new file mode 100644 index 0000000000..7d963bed29 --- /dev/null +++ b/tests/arch/common/stack_unwind/testcase.yaml @@ -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+"