Back to home page

LXR

 
 

    


0001 /*
0002  * Simple stack backtrace regression test module
0003  *
0004  * (C) Copyright 2008 Intel Corporation
0005  * Author: Arjan van de Ven <arjan@linux.intel.com>
0006  *
0007  * This program is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU General Public License
0009  * as published by the Free Software Foundation; version 2
0010  * of the License.
0011  */
0012 
0013 #include <linux/completion.h>
0014 #include <linux/delay.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/module.h>
0017 #include <linux/sched.h>
0018 #include <linux/stacktrace.h>
0019 
0020 static void backtrace_test_normal(void)
0021 {
0022     pr_info("Testing a backtrace from process context.\n");
0023     pr_info("The following trace is a kernel self test and not a bug!\n");
0024 
0025     dump_stack();
0026 }
0027 
0028 static DECLARE_COMPLETION(backtrace_work);
0029 
0030 static void backtrace_test_irq_callback(unsigned long data)
0031 {
0032     dump_stack();
0033     complete(&backtrace_work);
0034 }
0035 
0036 static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0);
0037 
0038 static void backtrace_test_irq(void)
0039 {
0040     pr_info("Testing a backtrace from irq context.\n");
0041     pr_info("The following trace is a kernel self test and not a bug!\n");
0042 
0043     init_completion(&backtrace_work);
0044     tasklet_schedule(&backtrace_tasklet);
0045     wait_for_completion(&backtrace_work);
0046 }
0047 
0048 #ifdef CONFIG_STACKTRACE
0049 static void backtrace_test_saved(void)
0050 {
0051     struct stack_trace trace;
0052     unsigned long entries[8];
0053 
0054     pr_info("Testing a saved backtrace.\n");
0055     pr_info("The following trace is a kernel self test and not a bug!\n");
0056 
0057     trace.nr_entries = 0;
0058     trace.max_entries = ARRAY_SIZE(entries);
0059     trace.entries = entries;
0060     trace.skip = 0;
0061 
0062     save_stack_trace(&trace);
0063     print_stack_trace(&trace, 0);
0064 }
0065 #else
0066 static void backtrace_test_saved(void)
0067 {
0068     pr_info("Saved backtrace test skipped.\n");
0069 }
0070 #endif
0071 
0072 static int backtrace_regression_test(void)
0073 {
0074     pr_info("====[ backtrace testing ]===========\n");
0075 
0076     backtrace_test_normal();
0077     backtrace_test_irq();
0078     backtrace_test_saved();
0079 
0080     pr_info("====[ end of backtrace testing ]====\n");
0081     return 0;
0082 }
0083 
0084 static void exitf(void)
0085 {
0086 }
0087 
0088 module_init(backtrace_regression_test);
0089 module_exit(exitf);
0090 MODULE_LICENSE("GPL");
0091 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");