Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Simple stack backtrace regression test module |
| 4 | * |
| 5 | * (C) Copyright 2008 Intel Corporation |
| 6 | * Author: Arjan van de Ven <arjan@linux.intel.com> |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 9 | #include <linux/completion.h> |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 10 | #include <linux/delay.h> |
Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/sched.h> |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 14 | #include <linux/stacktrace.h> |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 15 | |
Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 16 | static void backtrace_test_normal(void) |
| 17 | { |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 18 | pr_info("Testing a backtrace from process context.\n"); |
| 19 | pr_info("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] | 20 | |
Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 21 | dump_stack(); |
| 22 | } |
| 23 | |
| 24 | static DECLARE_COMPLETION(backtrace_work); |
| 25 | |
| 26 | static void backtrace_test_irq_callback(unsigned long data) |
| 27 | { |
| 28 | dump_stack(); |
| 29 | complete(&backtrace_work); |
| 30 | } |
| 31 | |
| 32 | static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0); |
| 33 | |
| 34 | static void backtrace_test_irq(void) |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 35 | { |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 36 | pr_info("Testing a backtrace from irq context.\n"); |
| 37 | pr_info("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] | 38 | |
| 39 | init_completion(&backtrace_work); |
| 40 | tasklet_schedule(&backtrace_tasklet); |
| 41 | wait_for_completion(&backtrace_work); |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 42 | } |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 43 | |
| 44 | #ifdef CONFIG_STACKTRACE |
| 45 | static void backtrace_test_saved(void) |
| 46 | { |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 47 | unsigned long entries[8]; |
Thomas Gleixner | 1b59562 | 2019-04-25 11:44:57 +0200 | [diff] [blame] | 48 | unsigned int nr_entries; |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 49 | |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 50 | pr_info("Testing a saved backtrace.\n"); |
| 51 | pr_info("The following trace is a kernel self test and not a bug!\n"); |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 52 | |
Thomas Gleixner | 1b59562 | 2019-04-25 11:44:57 +0200 | [diff] [blame] | 53 | nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0); |
| 54 | stack_trace_print(entries, nr_entries, 0); |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 55 | } |
| 56 | #else |
| 57 | static void backtrace_test_saved(void) |
| 58 | { |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 59 | pr_info("Saved backtrace test skipped.\n"); |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 60 | } |
| 61 | #endif |
| 62 | |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 63 | static int backtrace_regression_test(void) |
| 64 | { |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 65 | pr_info("====[ backtrace testing ]===========\n"); |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 66 | |
Vegard Nossum | 4e6a053 | 2008-06-27 18:06:54 +0200 | [diff] [blame] | 67 | backtrace_test_normal(); |
| 68 | backtrace_test_irq(); |
Vegard Nossum | ad118c5 | 2008-06-27 18:04:48 +0200 | [diff] [blame] | 69 | backtrace_test_saved(); |
| 70 | |
Fabian Frederick | 462b29b | 2014-06-04 16:11:18 -0700 | [diff] [blame] | 71 | pr_info("====[ end of backtrace testing ]====\n"); |
Arjan van de Ven | 6dab277 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static void exitf(void) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | module_init(backtrace_regression_test); |
| 80 | module_exit(exitf); |
| 81 | MODULE_LICENSE("GPL"); |
| 82 | MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>"); |