Subject: [PATCH] selftests: panic: Add test module to trigger kernel panic
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 Subject: [PATCH] selftests: panic: Add test module to trigger kernel panic
This patch adds a new test module under tools/testing/selftests/panic that intentionally triggers a kernel panic for test and diagnostic purposes. The goal is to provide a reproducible and isolated kernel panic event for testing crash dump mechanisms or validating kernel panic handling behavior.
The test includes:
- A kernel module that calls panic() in init.
- A Makefile to build the kernel module.
- A run.sh script to load the module and capture panic logs.
Changes in v2:
- Added run.sh
- Added reference output log of run.sh
Signed-off-by Vishal Parmar <[email protected]>
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/panic/Makefile | 13 +++++++++ .../selftests/panic/panic_trigger_test.c | 26 +++++++++++++++++ .../selftests/panic/reference_output_log.txt | 29 +++++++++++++++++++ tools/testing/selftests/panic/run.sh | 17 +++++++++++ 5 files changed, 86 insertions(+) create mode 100644 tools/testing/selftests/panic/Makefile create mode 100644 tools/testing/selftests/panic/panic_trigger_test.c create mode 100644 tools/testing/selftests/panic/reference_output_log.txt create mode 100755 tools/testing/selftests/panic/run.sh
tools/testing/selftests/Makefile +1 -0
@@ -78,6 +78,7 @@ TARGETS += net/packetdrill TARGETS += net/rds TARGETS += net/tcp_ao TARGETS += nsfs +TARGETS += panic TARGETS += pci_endpoint TARGETS += pcie_bwctrl TARGETS += perf_events
tools/testing/selftests/panic/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-m := panic_trigger_test.o + +KDIR := $(abspath ../../../../) +PWD := $(shell pwd) + +all: + $(MAKE) -C $(KDIR) M=$(PWD) modules + +clean: + $(MAKE) -C $(KDIR) M=$(PWD) clean + rm -f *.mod.c *.o *.ko *.order *.symvers
tools/testing/selftests/panic/panic_trigger_test.c new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* panic_test.c - Module to test kernel panic +*/ + +#include <linux/module.h> +#include <linux/init.h> + +static int __init panic_test_init (void ) +{ +pr_info ("Triggering a deliberate kernel panic now.\n" ); +panic ("Triggered by panic_test module." ); +return 0 ; +} + +static void __exit panic_test_exit(void) +{ +pr_info ("This should not be printed, as system panics on init.\n" ); +} + +module_init (panic_test_init); +module_exit (panic_test_exit); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Vishal Parmar" ); +MODULE_DESCRIPTION ("Module to trigger kernel panic for testing" );
tools/testing/selftests/panic/reference_output_log.txt new file +29 -0
@@ -0,0 +1,29 @@ +[*] Inserting module: panic_trigger_test.ko +[ 30.377307] panic_trigger_test: loading out-of-tree module taints kernel. +[ 30.380328] Triggering a deliberate kernel panic now. +[ 30.382369] Kernel panic - not syncing: Triggered by panic_test module. +[ 30.383349] CPU: 1 UID: 0 PID: 99 Comm: insmod Tainted: G O 6.16.0-rc7-00140-gec2df4364666 #1 PREEMPT(voluntary) +[ 30.383349] Tainted: [O]=OOT_MODULE +[ 30.383349] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 +[ 30.383349] Call Trace: +[ 30.383349] <TASK> +[ 30.383349] panic+0x325/0x380 +[ 30.383349] ? __pfx_panic_test_init+0x10/0x10 [panic_trigger_test] +[ 30.383349] panic_test_init+0x1c/0xff0 [panic_trigger_test] +[ 30.383349] do_one_initcall+0x55/0x220 +[ 30.383349] do_init_module+0x5b/0x230 +[ 30.383349] __do_sys_init_module+0x150/0x180 +[ 30.383349] do_syscall_64+0xa4/0x260 +[ 30.383349] entry_SYSCALL_64_after_hwframe+0x77/0x7f +[ 30.383349] RIP: 0033:0x7f88f09177d9 +[ 30.383349] Code: 08 89 e8 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d f7 05 8 +[ 30.383349] RSP: 002b:00007ffc16317848 EFLAGS: 00000206 ORIG_RAX: 00000000000000af +[ 30.383349] RAX: ffffffffffffffda RBX: 000055a4a84b0eae RCX: 00007f88f09177d9 +[ 30.383349] RDX: 000055a4a84b0eae RSI: 00000000000019e8 RDI: 000055a4c9b4b370 +[ 30.383349] RBP: 00007ffc16317bd0 R08: 000055a4c9b4b310 R09: 00000000000019e8 +[ 30.383349] R10: 0000000000000007 R11: 0000000000000206 R12: 00007ffc16317bd8 +[ 30.383349] R13: 00007ffc16317be0 R14: 000055a4a84b0eae R15: 00007f88f0b25020 +[ 30.383349] </TASK> +[ 30.383349] Kernel Offset: 0x10000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) +[ 30.383349] ---[ end Kernel panic - not syncing: Triggered by panic_test module. ]--- +
tools/testing/selftests/panic/run.sh new file +17 -0
@@ -0,0 +1,17 @@ +# tools/testing/selftests/panic/run.sh + +#!/bin/sh +set -e + +MOD_NAME="panic_trigger_test.ko" +LOG_FILE="panic_log.txt" + +echo "[*] Clearing dmesg..." +dmesg -c + +echo "[*] Inserting module: $MOD_NAME" +insmod ./$MOD_NAME + +echo "[*] Capturing dmesg..." +dmesg > "$LOG_FILE" +
Signature · 1 line
2.39.5