Skip to content

Commit af0176d

Browse files
committed
tests: arch: riscv: fatal: test z_riscv_fault() path
- Updated the testcase to test `z_riscv_fault()` error handling path. - The main file is now fully assembly so that we can use precompiler guards more easily to test with/without frame pointer enabled. Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com> Signed-off-by: Yong Cong Sin <ycsin@meta.com>
1 parent fb84640 commit af0176d

File tree

5 files changed

+174
-64
lines changed

5 files changed

+174
-64
lines changed

tests/arch/riscv/fatal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
55
project(riscv_fatal)
66

7-
FILE(GLOB app_sources src/*.c)
7+
FILE(GLOB app_sources src/*.S)
88
target_sources(app PRIVATE ${app_sources})

tests/arch/riscv/fatal/Kconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 Meta Platforms
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
choice
5+
prompt "Fatal type"
6+
default TEST_RISCV_FATAL_PANIC
7+
8+
config TEST_RISCV_FATAL_PANIC
9+
bool "Panic induced fault"
10+
help
11+
Tests the error handling via `z_riscv_fatal_error()`
12+
13+
config TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION
14+
bool "Illegal instruction induced fault"
15+
help
16+
Tests the error handling via `_Fault()`
17+
18+
endchoice
19+
20+
source "Kconfig.zephyr"

tests/arch/riscv/fatal/src/main.S

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2025 Meta Platforms.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/toolchain.h>
8+
#include <zephyr/linker/sections.h>
9+
10+
/**
11+
* Load up a bunch of known values into registers
12+
* and expect them to show up in the core dump.
13+
* Value is register ABI name kinda spelled out,
14+
* followed by zeros to pad to 32 bits,
15+
* followed by FF00, followed by hex number of the register,
16+
* follwed by the "hex-coded-decimal" number of the register.
17+
*/
18+
19+
GTEXT(main)
20+
SECTION_FUNC(TEXT, main)
21+
22+
li ra, 0xDADA0000FF000101
23+
24+
/* SP is skipped because it can messes stuff up */
25+
26+
#ifndef CONFIG_RISCV_GP
27+
li gp, 0xDADA0000FF000101
28+
#endif
29+
30+
#ifndef CONFIG_THREAD_LOCAL_STORAGE
31+
li tp, 0xE2E20000FF000404
32+
#endif /* CONFIG_THREAD_LOCAL_STORAGE */
33+
34+
#ifndef CONFIG_TEST_RISCV_FATAL_PANIC
35+
/* We will load `0` (RV_ECALL_RUNTIME_EXCEPT) to `t0` */
36+
li t0, 0xD0FF0000FF000505
37+
#endif /* CONFIG_TEST_RISCV_FATAL_PANIC */
38+
li t1, 0xD1FF0000FF000606
39+
li t2, 0xD2FF0000FF000707
40+
41+
#ifndef CONFIG_FRAME_POINTER
42+
li s0, 0xC0FF0000FF000808
43+
#endif /* CONFIG_FRAME_POINTER */
44+
45+
li s1, 0xC1FF0000FF000909
46+
47+
li a0, 0xA0FF0000FF000A10
48+
li a1, 0xA1FF0000FF000B11
49+
li a2, 0xA2FF0000FF000C12
50+
li a3, 0xA3FF0000FF000D13
51+
li a4, 0xA4FF0000FF000E14
52+
li a5, 0xA5FF0000FF000F15
53+
54+
#ifndef CONFIG_RISCV_ISA_RV32E
55+
li a6, 0xA6FF0000FF001016
56+
li a7, 0xA7FF0000FF001117
57+
58+
li s2, 0xC2FF0000FF001218
59+
li s3, 0xC3FF0000FF001319
60+
li s4, 0xC4FF0000FF001420
61+
li s5, 0xC5FF0000FF001521
62+
li s6, 0xC6FF0000FF001622
63+
li s7, 0xC7FF0000FF001723
64+
li s8, 0xC8FF0000FF001824
65+
li s9, 0xC9FF0000FF001925
66+
li s10, 0xC10FF000FF001A26
67+
li s11, 0xC11FF000FF001B27
68+
69+
li t3, 0xD3FF0000FF001C28
70+
li t4, 0xD4FF0000FF001D29
71+
li t5, 0xD5FF0000FF001E30
72+
li t6, 0xD6FF0000FF001F31
73+
#endif /* CONFIG_RISCV_ISA_RV32E */
74+
75+
#ifdef CONFIG_TEST_RISCV_FATAL_PANIC
76+
li a0, 4 /* K_ERR_KERNEL_PANIC */
77+
li t0, 0 /* RV_ECALL_RUNTIME_EXCEPT */
78+
ecall
79+
80+
#else /* CONFIG_TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION */
81+
.insn 2, 0
82+
.insn 2, 0
83+
#endif /* CONFIG_TEST_RISCV_FATAL_PANIC */

tests/arch/riscv/fatal/src/main.c

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/arch/riscv/fatal/testcase.yaml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ common:
88
platform_allow:
99
- qemu_riscv64
1010
tests:
11-
arch.riscv64.fatal:
11+
arch.riscv64.fatal.panic_sp:
12+
extra_configs:
13+
- CONFIG_FRAME_POINTER=n
14+
- CONFIG_TEST_RISCV_FATAL_PANIC=y
1215
harness_config:
1316
type: multi_line
1417
regex:
@@ -27,3 +30,69 @@ tests:
2730
- "E: s3: c3ff0000ff001319 s9: c9ff0000ff001925"
2831
- "E: s4: c4ff0000ff001420 s10: c10ff000ff001a26"
2932
- "E: s5: c5ff0000ff001521 s11: c11ff000ff001b27"
33+
arch.riscv64.fatal.fault_sp:
34+
extra_configs:
35+
- CONFIG_FRAME_POINTER=n
36+
- CONFIG_TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION=y
37+
harness_config:
38+
type: multi_line
39+
regex:
40+
- "E: a0: a0ff0000ff000a10 t0: d0ff0000ff000505"
41+
- "E: a1: a1ff0000ff000b11 t1: d1ff0000ff000606"
42+
- "E: a2: a2ff0000ff000c12 t2: d2ff0000ff000707"
43+
- "E: a3: a3ff0000ff000d13 t3: d3ff0000ff001c28"
44+
- "E: a4: a4ff0000ff000e14 t4: d4ff0000ff001d29"
45+
- "E: a5: a5ff0000ff000f15 t5: d5ff0000ff001e30"
46+
- "E: a6: a6ff0000ff001016 t6: d6ff0000ff001f31"
47+
- "E: a7: a7ff0000ff001117"
48+
- "E: ra: dada0000ff000101"
49+
- "E: s0: c0ff0000ff000808 s6: c6ff0000ff001622"
50+
- "E: s1: c1ff0000ff000909 s7: c7ff0000ff001723"
51+
- "E: s2: c2ff0000ff001218 s8: c8ff0000ff001824"
52+
- "E: s3: c3ff0000ff001319 s9: c9ff0000ff001925"
53+
- "E: s4: c4ff0000ff001420 s10: c10ff000ff001a26"
54+
- "E: s5: c5ff0000ff001521 s11: c11ff000ff001b27"
55+
arch.riscv64.fatal.panic_fp:
56+
extra_configs:
57+
- CONFIG_FRAME_POINTER=y
58+
- CONFIG_TEST_RISCV_FATAL_PANIC=y
59+
harness_config:
60+
type: multi_line
61+
regex:
62+
- "E: a0: 0000000000000004 t0: 0000000000000000"
63+
- "E: a1: a1ff0000ff000b11 t1: d1ff0000ff000606"
64+
- "E: a2: a2ff0000ff000c12 t2: d2ff0000ff000707"
65+
- "E: a3: a3ff0000ff000d13 t3: d3ff0000ff001c28"
66+
- "E: a4: a4ff0000ff000e14 t4: d4ff0000ff001d29"
67+
- "E: a5: a5ff0000ff000f15 t5: d5ff0000ff001e30"
68+
- "E: a6: a6ff0000ff001016 t6: d6ff0000ff001f31"
69+
- "E: a7: a7ff0000ff001117"
70+
- "E: ra: dada0000ff000101"
71+
- "E: s0: \\w+ s6: c6ff0000ff001622"
72+
- "E: s1: c1ff0000ff000909 s7: c7ff0000ff001723"
73+
- "E: s2: c2ff0000ff001218 s8: c8ff0000ff001824"
74+
- "E: s3: c3ff0000ff001319 s9: c9ff0000ff001925"
75+
- "E: s4: c4ff0000ff001420 s10: c10ff000ff001a26"
76+
- "E: s5: c5ff0000ff001521 s11: c11ff000ff001b27"
77+
arch.riscv64.fatal.fault_fp:
78+
extra_configs:
79+
- CONFIG_FRAME_POINTER=y
80+
- CONFIG_TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION=y
81+
harness_config:
82+
type: multi_line
83+
regex:
84+
- "E: a0: a0ff0000ff000a10 t0: d0ff0000ff000505"
85+
- "E: a1: a1ff0000ff000b11 t1: d1ff0000ff000606"
86+
- "E: a2: a2ff0000ff000c12 t2: d2ff0000ff000707"
87+
- "E: a3: a3ff0000ff000d13 t3: d3ff0000ff001c28"
88+
- "E: a4: a4ff0000ff000e14 t4: d4ff0000ff001d29"
89+
- "E: a5: a5ff0000ff000f15 t5: d5ff0000ff001e30"
90+
- "E: a6: a6ff0000ff001016 t6: d6ff0000ff001f31"
91+
- "E: a7: a7ff0000ff001117"
92+
- "E: ra: dada0000ff000101"
93+
- "E: s0: \\w+ s6: c6ff0000ff001622"
94+
- "E: s1: c1ff0000ff000909 s7: c7ff0000ff001723"
95+
- "E: s2: c2ff0000ff001218 s8: c8ff0000ff001824"
96+
- "E: s3: c3ff0000ff001319 s9: c9ff0000ff001925"
97+
- "E: s4: c4ff0000ff001420 s10: c10ff000ff001a26"
98+
- "E: s5: c5ff0000ff001521 s11: c11ff000ff001b27"

0 commit comments

Comments
 (0)