| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 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 |  | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 13 | #include <linux/completion.h> | 
| Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 14 | #include <linux/delay.h> | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 15 | #include <linux/interrupt.h> | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 16 | #include <linux/module.h> | 
|  | 17 | #include <linux/sched.h> | 
| Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 18 | #include <linux/stacktrace.h> | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 19 |  | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 20 | static void backtrace_test_normal(void) | 
|  | 21 | { | 
|  | 22 | printk("Testing a backtrace from process context.\n"); | 
|  | 23 | printk("The following trace is a kernel self test and not a bug!\n"); | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 24 |  | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 25 | dump_stack(); | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | static DECLARE_COMPLETION(backtrace_work); | 
|  | 29 |  | 
|  | 30 | static void backtrace_test_irq_callback(unsigned long data) | 
|  | 31 | { | 
|  | 32 | dump_stack(); | 
|  | 33 | complete(&backtrace_work); | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0); | 
|  | 37 |  | 
|  | 38 | static void backtrace_test_irq(void) | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 39 | { | 
|  | 40 | printk("Testing a backtrace from irq context.\n"); | 
|  | 41 | printk("The following trace is a kernel self test and not a bug!\n"); | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 42 |  | 
|  | 43 | init_completion(&backtrace_work); | 
|  | 44 | tasklet_schedule(&backtrace_tasklet); | 
|  | 45 | wait_for_completion(&backtrace_work); | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 46 | } | 
| Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 47 |  | 
|  | 48 | #ifdef CONFIG_STACKTRACE | 
|  | 49 | static void backtrace_test_saved(void) | 
|  | 50 | { | 
|  | 51 | struct stack_trace trace; | 
|  | 52 | unsigned long entries[8]; | 
|  | 53 |  | 
|  | 54 | printk("Testing a saved backtrace.\n"); | 
|  | 55 | printk("The following trace is a kernel self test and not a bug!\n"); | 
|  | 56 |  | 
|  | 57 | trace.nr_entries = 0; | 
|  | 58 | trace.max_entries = ARRAY_SIZE(entries); | 
|  | 59 | trace.entries = entries; | 
|  | 60 | trace.skip = 0; | 
|  | 61 |  | 
|  | 62 | save_stack_trace(&trace); | 
|  | 63 | print_stack_trace(&trace, 0); | 
|  | 64 | } | 
|  | 65 | #else | 
|  | 66 | static void backtrace_test_saved(void) | 
|  | 67 | { | 
|  | 68 | printk("Saved backtrace test skipped.\n"); | 
|  | 69 | } | 
|  | 70 | #endif | 
|  | 71 |  | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 72 | static int backtrace_regression_test(void) | 
|  | 73 | { | 
|  | 74 | printk("====[ backtrace testing ]===========\n"); | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 75 |  | 
| Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 76 | backtrace_test_normal(); | 
|  | 77 | backtrace_test_irq(); | 
| Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 78 | backtrace_test_saved(); | 
|  | 79 |  | 
| Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 80 | printk("====[ end of backtrace testing ]====\n"); | 
|  | 81 | return 0; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | static void exitf(void) | 
|  | 85 | { | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | module_init(backtrace_regression_test); | 
|  | 89 | module_exit(exitf); | 
|  | 90 | MODULE_LICENSE("GPL"); | 
|  | 91 | MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>"); |