blob: 2dfe66b9ed76602990478593ae44093f5ca92335 [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
Tejun Heo7245d24f2024-02-04 11:34:28 -100024static void backtrace_test_bh_workfn(struct work_struct *work)
Vegard Nossum4e6a0532008-06-27 18:06:54 +020025{
26 dump_stack();
Vegard Nossum4e6a0532008-06-27 18:06:54 +020027}
28
Tejun Heo7245d24f2024-02-04 11:34:28 -100029static DECLARE_WORK(backtrace_bh_work, &backtrace_test_bh_workfn);
Vegard Nossum4e6a0532008-06-27 18:06:54 +020030
Tejun Heo7245d24f2024-02-04 11:34:28 -100031static void backtrace_test_bh(void)
Arjan van de Ven6dab2772008-01-30 13:33:08 +010032{
Tejun Heo7245d24f2024-02-04 11:34:28 -100033 pr_info("Testing a backtrace from BH context.\n");
Fabian Frederick462b29b2014-06-04 16:11:18 -070034 pr_info("The following trace is a kernel self test and not a bug!\n");
Vegard Nossum4e6a0532008-06-27 18:06:54 +020035
Tejun Heo7245d24f2024-02-04 11:34:28 -100036 queue_work(system_bh_wq, &backtrace_bh_work);
37 flush_work(&backtrace_bh_work);
Arjan van de Ven6dab2772008-01-30 13:33:08 +010038}
Vegard Nossumad118c52008-06-27 18:04:48 +020039
40#ifdef CONFIG_STACKTRACE
41static void backtrace_test_saved(void)
42{
Vegard Nossumad118c52008-06-27 18:04:48 +020043 unsigned long entries[8];
Thomas Gleixner1b595622019-04-25 11:44:57 +020044 unsigned int nr_entries;
Vegard Nossumad118c52008-06-27 18:04:48 +020045
Fabian Frederick462b29b2014-06-04 16:11:18 -070046 pr_info("Testing a saved backtrace.\n");
47 pr_info("The following trace is a kernel self test and not a bug!\n");
Vegard Nossumad118c52008-06-27 18:04:48 +020048
Thomas Gleixner1b595622019-04-25 11:44:57 +020049 nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
50 stack_trace_print(entries, nr_entries, 0);
Vegard Nossumad118c52008-06-27 18:04:48 +020051}
52#else
53static void backtrace_test_saved(void)
54{
Fabian Frederick462b29b2014-06-04 16:11:18 -070055 pr_info("Saved backtrace test skipped.\n");
Vegard Nossumad118c52008-06-27 18:04:48 +020056}
57#endif
58
Arjan van de Ven6dab2772008-01-30 13:33:08 +010059static int backtrace_regression_test(void)
60{
Fabian Frederick462b29b2014-06-04 16:11:18 -070061 pr_info("====[ backtrace testing ]===========\n");
Arjan van de Ven6dab2772008-01-30 13:33:08 +010062
Vegard Nossum4e6a0532008-06-27 18:06:54 +020063 backtrace_test_normal();
Tejun Heo7245d24f2024-02-04 11:34:28 -100064 backtrace_test_bh();
Vegard Nossumad118c52008-06-27 18:04:48 +020065 backtrace_test_saved();
66
Fabian Frederick462b29b2014-06-04 16:11:18 -070067 pr_info("====[ end of backtrace testing ]====\n");
Arjan van de Ven6dab2772008-01-30 13:33:08 +010068 return 0;
69}
70
71static void exitf(void)
72{
73}
74
75module_init(backtrace_regression_test);
76module_exit(exitf);
Jeff Johnson82a9d6b2024-05-18 16:12:05 -070077MODULE_DESCRIPTION("Simple stack backtrace regression test module");
Arjan van de Ven6dab2772008-01-30 13:33:08 +010078MODULE_LICENSE("GPL");
79MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");