1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * Simple stack backtrace regression test modu 2 * Simple stack backtrace regression test module 4 * 3 * 5 * (C) Copyright 2008 Intel Corporation 4 * (C) Copyright 2008 Intel Corporation 6 * Author: Arjan van de Ven <arjan@linux.intel 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. 7 */ 11 */ 8 12 9 #include <linux/completion.h> 13 #include <linux/completion.h> 10 #include <linux/delay.h> 14 #include <linux/delay.h> 11 #include <linux/interrupt.h> 15 #include <linux/interrupt.h> 12 #include <linux/module.h> 16 #include <linux/module.h> 13 #include <linux/sched.h> 17 #include <linux/sched.h> 14 #include <linux/stacktrace.h> 18 #include <linux/stacktrace.h> 15 19 16 static void backtrace_test_normal(void) 20 static void backtrace_test_normal(void) 17 { 21 { 18 pr_info("Testing a backtrace from proc 22 pr_info("Testing a backtrace from process context.\n"); 19 pr_info("The following trace is a kern 23 pr_info("The following trace is a kernel self test and not a bug!\n"); 20 24 21 dump_stack(); 25 dump_stack(); 22 } 26 } 23 27 24 static void backtrace_test_bh_workfn(struct wo !! 28 static DECLARE_COMPLETION(backtrace_work); >> 29 >> 30 static void backtrace_test_irq_callback(unsigned long data) 25 { 31 { 26 dump_stack(); 32 dump_stack(); >> 33 complete(&backtrace_work); 27 } 34 } 28 35 29 static DECLARE_WORK(backtrace_bh_work, &backtr !! 36 static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0); 30 37 31 static void backtrace_test_bh(void) !! 38 static void backtrace_test_irq(void) 32 { 39 { 33 pr_info("Testing a backtrace from BH c !! 40 pr_info("Testing a backtrace from irq context.\n"); 34 pr_info("The following trace is a kern 41 pr_info("The following trace is a kernel self test and not a bug!\n"); 35 42 36 queue_work(system_bh_wq, &backtrace_bh !! 43 init_completion(&backtrace_work); 37 flush_work(&backtrace_bh_work); !! 44 tasklet_schedule(&backtrace_tasklet); >> 45 wait_for_completion(&backtrace_work); 38 } 46 } 39 47 40 #ifdef CONFIG_STACKTRACE 48 #ifdef CONFIG_STACKTRACE 41 static void backtrace_test_saved(void) 49 static void backtrace_test_saved(void) 42 { 50 { >> 51 struct stack_trace trace; 43 unsigned long entries[8]; 52 unsigned long entries[8]; 44 unsigned int nr_entries; << 45 53 46 pr_info("Testing a saved backtrace.\n" 54 pr_info("Testing a saved backtrace.\n"); 47 pr_info("The following trace is a kern 55 pr_info("The following trace is a kernel self test and not a bug!\n"); 48 56 49 nr_entries = stack_trace_save(entries, !! 57 trace.nr_entries = 0; 50 stack_trace_print(entries, nr_entries, !! 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); 51 } 64 } 52 #else 65 #else 53 static void backtrace_test_saved(void) 66 static void backtrace_test_saved(void) 54 { 67 { 55 pr_info("Saved backtrace test skipped. 68 pr_info("Saved backtrace test skipped.\n"); 56 } 69 } 57 #endif 70 #endif 58 71 59 static int backtrace_regression_test(void) 72 static int backtrace_regression_test(void) 60 { 73 { 61 pr_info("====[ backtrace testing ]==== 74 pr_info("====[ backtrace testing ]===========\n"); 62 75 63 backtrace_test_normal(); 76 backtrace_test_normal(); 64 backtrace_test_bh(); !! 77 backtrace_test_irq(); 65 backtrace_test_saved(); 78 backtrace_test_saved(); 66 79 67 pr_info("====[ end of backtrace testin 80 pr_info("====[ end of backtrace testing ]====\n"); 68 return 0; 81 return 0; 69 } 82 } 70 83 71 static void exitf(void) 84 static void exitf(void) 72 { 85 { 73 } 86 } 74 87 75 module_init(backtrace_regression_test); 88 module_init(backtrace_regression_test); 76 module_exit(exitf); 89 module_exit(exitf); 77 MODULE_DESCRIPTION("Simple stack backtrace reg << 78 MODULE_LICENSE("GPL"); 90 MODULE_LICENSE("GPL"); 79 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.i 91 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>"); 80 92
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.