Skip to content

Commit 6dab277

Browse files
Arjan van de VenIngo Molnar
authored andcommitted
x86: add a simple backtrace test module
During the work on the x86 32 and 64 bit backtrace code I found it useful to have a simple test module to test a process and irq context backtrace. Since the existing backtrace code was buggy, I figure it might be useful to have such a test module in the kernel so that maybe we can even detect such bugs earlier.. [ mingo@elte.hu: build fix ] Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 80b51f3 commit 6dab277

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ obj-$(CONFIG_KALLSYMS) += kallsyms.o
3636
obj-$(CONFIG_PM) += power/
3737
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
3838
obj-$(CONFIG_KEXEC) += kexec.o
39+
obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
3940
obj-$(CONFIG_COMPAT) += compat.o
4041
obj-$(CONFIG_CGROUPS) += cgroup.o
4142
obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o

‎kernel/backtracetest.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Simple stack backtrace regression test module
3+
*
4+
* (C) Copyright 2008 Intel Corporation
5+
* Author: Arjan van de Ven <arjan@linux.intel.com>
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; version 2
10+
* of the License.
11+
*/
12+
13+
#include <linux/module.h>
14+
#include <linux/sched.h>
15+
#include <linux/delay.h>
16+
17+
static struct timer_list backtrace_timer;
18+
19+
static void backtrace_test_timer(unsigned long data)
20+
{
21+
printk("Testing a backtrace from irq context.\n");
22+
printk("The following trace is a kernel self test and not a bug!\n");
23+
dump_stack();
24+
}
25+
static int backtrace_regression_test(void)
26+
{
27+
printk("====[ backtrace testing ]===========\n");
28+
printk("Testing a backtrace from process context.\n");
29+
printk("The following trace is a kernel self test and not a bug!\n");
30+
dump_stack();
31+
32+
init_timer(&backtrace_timer);
33+
backtrace_timer.function = backtrace_test_timer;
34+
mod_timer(&backtrace_timer, jiffies + 10);
35+
36+
msleep(10);
37+
printk("====[ end of backtrace testing ]====\n");
38+
return 0;
39+
}
40+
41+
static void exitf(void)
42+
{
43+
}
44+
45+
module_init(backtrace_regression_test);
46+
module_exit(exitf);
47+
MODULE_LICENSE("GPL");
48+
MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");

‎lib/Kconfig.debug‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,18 @@ config KPROBES_SANITY_TEST
506506

507507
Say N if you are unsure.
508508

509+
config BACKTRACE_SELF_TEST
510+
tristate "Self test for the backtrace code"
511+
depends on DEBUG_KERNEL
512+
default n
513+
help
514+
This option provides a kernel module that can be used to test
515+
the kernel stack backtrace code. This option is not useful
516+
for distributions or general kernels, but only for kernel
517+
developers working on architecture code.
518+
519+
Say N if you are unsure.
520+
509521
config LKDTM
510522
tristate "Linux Kernel Dump Test Tool Module"
511523
depends on DEBUG_KERNEL

0 commit comments

Comments
 (0)