blob: a2a97fa3071b1c7ee6595d61a172f7ccc73ea40b [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001// SPDX-License-Identifier: GPL-2.0-only
Arjan van de Ven6dab2772008-01-30 13:33:08 +01002/*
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 Ven6dab2772008-01-30 13:33:08 +01007 */
8
Vegard Nossum4e6a0532008-06-27 18:06:54 +02009#include <linux/completion.h>
Vegard Nossumad118c52008-06-27 18:04:48 +020010#include <linux/delay.h>
Vegard Nossum4e6a0532008-06-27 18:06:54 +020011#include <linux/interrupt.h>
Arjan van de Ven6dab2772008-01-30 13:33:08 +010012#include <linux/module.h>
13#include <linux/sched.h>
Vegard Nossumad118c52008-06-27 18:04:48 +020014#include <linux/stacktrace.h>
Arjan van de Ven6dab2772008-01-30 13:33:08 +010015
Vegard Nossum4e6a0532008-06-27 18:06:54 +020016static void backtrace_test_normal(void)
17{
Fabian Frederick462b29b2014-06-04 16:11:18 -070018 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 Ven6dab2772008-01-30 13:33:08 +010020
Vegard Nossum4e6a0532008-06-27 18:06:54 +020021 dump_stack();
22}
23
24static DECLARE_COMPLETION(backtrace_work);
25
26static void backtrace_test_irq_callback(unsigned long data)
27{
28 dump_stack();
29 complete(&backtrace_work);
30}
31
32static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0);
33
34static void backtrace_test_irq(void)
Arjan van de Ven6dab2772008-01-30 13:33:08 +010035{
Fabian Frederick462b29b2014-06-04 16:11:18 -070036 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 Nossum4e6a0532008-06-27 18:06:54 +020038
39 init_completion(&backtrace_work);
40 tasklet_schedule(&backtrace_tasklet);
41 wait_for_completion(&backtrace_work);
Arjan van de Ven6dab2772008-01-30 13:33:08 +010042}
Vegard Nossumad118c52008-06-27 18:04:48 +020043
44#ifdef CONFIG_STACKTRACE
45static void backtrace_test_saved(void)
46{
Vegard Nossumad118c52008-06-27 18:04:48 +020047 unsigned long entries[8];
Thomas Gleixner1b595622019-04-25 11:44:57 +020048 unsigned int nr_entries;
Vegard Nossumad118c52008-06-27 18:04:48 +020049
Fabian Frederick462b29b2014-06-04 16:11:18 -070050 pr_info("Testing a saved backtrace.\n");
51 pr_info("The following trace is a kernel self test and not a bug!\n");
Vegard Nossumad118c52008-06-27 18:04:48 +020052
Thomas Gleixner1b595622019-04-25 11:44:57 +020053 nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
54 stack_trace_print(entries, nr_entries, 0);
Vegard Nossumad118c52008-06-27 18:04:48 +020055}
56#else
57static void backtrace_test_saved(void)
58{
Fabian Frederick462b29b2014-06-04 16:11:18 -070059 pr_info("Saved backtrace test skipped.\n");
Vegard Nossumad118c52008-06-27 18:04:48 +020060}
61#endif
62
Arjan van de Ven6dab2772008-01-30 13:33:08 +010063static int backtrace_regression_test(void)
64{
Fabian Frederick462b29b2014-06-04 16:11:18 -070065 pr_info("====[ backtrace testing ]===========\n");
Arjan van de Ven6dab2772008-01-30 13:33:08 +010066
Vegard Nossum4e6a0532008-06-27 18:06:54 +020067 backtrace_test_normal();
68 backtrace_test_irq();
Vegard Nossumad118c52008-06-27 18:04:48 +020069 backtrace_test_saved();
70
Fabian Frederick462b29b2014-06-04 16:11:18 -070071 pr_info("====[ end of backtrace testing ]====\n");
Arjan van de Ven6dab2772008-01-30 13:33:08 +010072 return 0;
73}
74
75static void exitf(void)
76{
77}
78
79module_init(backtrace_regression_test);
80module_exit(exitf);
81MODULE_LICENSE("GPL");
82MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");