Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Simple stack backtrace regression test module
0004  *
0005  * (C) Copyright 2008 Intel Corporation
0006  * Author: Arjan van de Ven <arjan@linux.intel.com>
0007  */
0008 
0009 #include <linux/completion.h>
0010 #include <linux/delay.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/module.h>
0013 #include <linux/sched.h>
0014 #include <linux/stacktrace.h>
0015 
0016 static void backtrace_test_normal(void)
0017 {
0018     pr_info("Testing a backtrace from process context.\n");
0019     pr_info("The following trace is a kernel self test and not a bug!\n");
0020 
0021     dump_stack();
0022 }
0023 
0024 static DECLARE_COMPLETION(backtrace_work);
0025 
0026 static void backtrace_test_irq_callback(unsigned long data)
0027 {
0028     dump_stack();
0029     complete(&backtrace_work);
0030 }
0031 
0032 static DECLARE_TASKLET_OLD(backtrace_tasklet, &backtrace_test_irq_callback);
0033 
0034 static void backtrace_test_irq(void)
0035 {
0036     pr_info("Testing a backtrace from irq context.\n");
0037     pr_info("The following trace is a kernel self test and not a bug!\n");
0038 
0039     init_completion(&backtrace_work);
0040     tasklet_schedule(&backtrace_tasklet);
0041     wait_for_completion(&backtrace_work);
0042 }
0043 
0044 #ifdef CONFIG_STACKTRACE
0045 static void backtrace_test_saved(void)
0046 {
0047     unsigned long entries[8];
0048     unsigned int nr_entries;
0049 
0050     pr_info("Testing a saved backtrace.\n");
0051     pr_info("The following trace is a kernel self test and not a bug!\n");
0052 
0053     nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
0054     stack_trace_print(entries, nr_entries, 0);
0055 }
0056 #else
0057 static void backtrace_test_saved(void)
0058 {
0059     pr_info("Saved backtrace test skipped.\n");
0060 }
0061 #endif
0062 
0063 static int backtrace_regression_test(void)
0064 {
0065     pr_info("====[ backtrace testing ]===========\n");
0066 
0067     backtrace_test_normal();
0068     backtrace_test_irq();
0069     backtrace_test_saved();
0070 
0071     pr_info("====[ end of backtrace testing ]====\n");
0072     return 0;
0073 }
0074 
0075 static void exitf(void)
0076 {
0077 }
0078 
0079 module_init(backtrace_regression_test);
0080 module_exit(exitf);
0081 MODULE_LICENSE("GPL");
0082 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");