stacktrace: add saved stack traces to backtrace self-test
[safe/jmp/linux-2.6] / kernel / backtracetest.c
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/delay.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/stacktrace.h>
17
18 static struct timer_list backtrace_timer;
19
20 static void backtrace_test_timer(unsigned long data)
21 {
22         printk("Testing a backtrace from irq context.\n");
23         printk("The following trace is a kernel self test and not a bug!\n");
24         dump_stack();
25 }
26
27 #ifdef CONFIG_STACKTRACE
28 static void backtrace_test_saved(void)
29 {
30         struct stack_trace trace;
31         unsigned long entries[8];
32
33         printk("Testing a saved backtrace.\n");
34         printk("The following trace is a kernel self test and not a bug!\n");
35
36         trace.nr_entries = 0;
37         trace.max_entries = ARRAY_SIZE(entries);
38         trace.entries = entries;
39         trace.skip = 0;
40
41         save_stack_trace(&trace);
42         print_stack_trace(&trace, 0);
43 }
44 #else
45 static void backtrace_test_saved(void)
46 {
47         printk("Saved backtrace test skipped.\n");
48 }
49 #endif
50
51 static int backtrace_regression_test(void)
52 {
53         printk("====[ backtrace testing ]===========\n");
54         printk("Testing a backtrace from process context.\n");
55         printk("The following trace is a kernel self test and not a bug!\n");
56         dump_stack();
57
58         backtrace_test_saved();
59
60         init_timer(&backtrace_timer);
61         backtrace_timer.function = backtrace_test_timer;
62         mod_timer(&backtrace_timer, jiffies + 10);
63
64         msleep(10);
65         printk("====[ end of backtrace testing ]====\n");
66         return 0;
67 }
68
69 static void exitf(void)
70 {
71 }
72
73 module_init(backtrace_regression_test);
74 module_exit(exitf);
75 MODULE_LICENSE("GPL");
76 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");