Skip to content

Commit 14149b1

Browse files
committed
tests: arch: common: add stack_unwind test
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 <[email protected]>
1 parent 93ba9e5 commit 14149b1

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024 Meta
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(stack_unwind_test)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CONFIG_TEST=y
2+
3+
CONFIG_LOG=y
4+
CONFIG_LOG_BUFFER_SIZE=2048
5+
6+
CONFIG_EXCEPTION_STACK_TRACE=y
7+
CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y
8+
CONFIG_OMIT_FRAME_POINTER=n
9+
CONFIG_DEBUG=y
10+
CONFIG_DEBUG_INFO=y
11+
CONFIG_DEBUG_OPTIMIZATIONS=y
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <stdbool.h>
9+
10+
#include <zephyr/kernel.h>
11+
12+
static void func1(int a);
13+
static void func2(int a);
14+
15+
static void func2(int a)
16+
{
17+
printf("%d: %s\n", a, __func__);
18+
19+
if (a >= 5) {
20+
k_oops();
21+
}
22+
23+
func1(a + 1);
24+
}
25+
26+
static void func1(int a)
27+
{
28+
printf("%d: %s\n", a, __func__);
29+
func2(a + 1);
30+
}
31+
32+
int main(void)
33+
{
34+
printf("Hello World! %s\n", CONFIG_BOARD);
35+
36+
func1(1);
37+
38+
return 0;
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
common:
2+
harness: console
3+
ignore_faults: true
4+
ignore_qemu_crash: true
5+
tags: kernel
6+
tests:
7+
arch.common.stack_unwind.riscv:
8+
arch_allow: riscv
9+
integration_platforms:
10+
- qemu_riscv32
11+
- qemu_riscv64
12+
harness_config:
13+
type: multi_line
14+
regex:
15+
- "E: call trace:"
16+
- "E: 0: fp: \\w+ ra: \\w+"
17+
- "E: 1: fp: \\w+ ra: \\w+"
18+
arch.common.stack_unwind.x86:
19+
arch_allow: x86
20+
extra_configs:
21+
- CONFIG_NO_OPTIMIZATIONS=y
22+
integration_platforms:
23+
- qemu_x86
24+
- qemu_x86_64
25+
harness_config:
26+
type: multi_line
27+
regex:
28+
- "E: call trace:"
29+
- "E: (E|R)IP: \\w+"
30+
arch.common.stack_unwind.arm:
31+
arch_allow:
32+
- arm64
33+
integration_platforms:
34+
- qemu_cortex_a53
35+
harness_config:
36+
type: multi_line
37+
regex:
38+
- "E: backtrace 0: fp: \\w+ lr: \\w+"
39+
- "E: backtrace 1: fp: \\w+ lr: \\w+"

0 commit comments

Comments
 (0)