Re: [PATCH 2/2] riscv: Add KUnit test for stack trace start frames

From: Shuai Xue

Date: Mon Oct 12 2026 - 05:39:12 EST




On 10/10/26 9:27 PM, Karl Mehltretter wrote:
stack_trace_save() and return_address() depend on the first frame reported
by arch_stack_walk(), but no test checks their frame numbering.

Add a test that calls both through a chain of three noinline functions
and compares the symbol of the result with the function expected for
each skip count or level.

Require FRAME_POINTER because the stack-scanning walker cannot provide an
exact start frame.

Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
arch/riscv/kernel/tests/Kconfig.debug | 12 ++
arch/riscv/kernel/tests/Makefile | 1 +
arch/riscv/kernel/tests/stacktrace_test.c | 142 ++++++++++++++++++++++
3 files changed, 155 insertions(+)

diff --git a/arch/riscv/kernel/tests/Kconfig.debug b/arch/riscv/kernel/tests/Kconfig.debug
index 40f8dafffa0a..eb79df5b2c5a 100644
--- a/arch/riscv/kernel/tests/Kconfig.debug
+++ b/arch/riscv/kernel/tests/Kconfig.debug
@@ -42,6 +42,18 @@ config RISCV_KPROBES_KUNIT
If unsure, say N.
+config RISCV_STACKTRACE_KUNIT_TEST
+ bool "KUnit tests for RISC-V stack trace start frames"
+ depends on KUNIT && STACKTRACE && FRAME_POINTER && KALLSYMS

Hi, Karl

One small nit: the new RISCV_STACKTRACE_KUNIT_TEST entry does
not follow the KUNIT_ALL_TESTS pattern of the two existing entries
right next to it (RISCV_KPROBES_KUNIT, RISCV_MODULE_LINKING_KUNIT):

config RISCV_STACKTRACE_KUNIT_TEST
bool "KUnit tests for RISC-V stack trace start frames" if !KUNIT_ALL_TESTS
default KUNIT_ALL_TESTS

Without "default KUNIT_ALL_TESTS" the suite is never enabled by
kunit.all_tests, and without the "if !KUNIT_ALL_TESTS" prompt guard
it shows up as a redundant prompt when KUNIT_ALL_TESTS is already
set. This is not a blocker in any way, just a nice tweak for a
potential v2.

Please feel free to add

Tested-by: Shuai Xue <xueshuai@xxxxxxxxxxxxxxxxx>

to both patches, and additionally on 1/2

Reviewed-by: Shuai Xue <xueshuai@xxxxxxxxxxxxxxxxx>

Thanks!
Shuai