]> git.ipfire.org Git - thirdparty/linux.git/blame - kernel/backtracetest.c
Linux 6.9-rc7
[thirdparty/linux.git] / kernel / backtracetest.c
CommitLineData
b886d83c 1// SPDX-License-Identifier: GPL-2.0-only
6dab2778
AV
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>
6dab2778
AV
7 */
8
4e6a0535 9#include <linux/completion.h>
ad118c54 10#include <linux/delay.h>
4e6a0535 11#include <linux/interrupt.h>
6dab2778
AV
12#include <linux/module.h>
13#include <linux/sched.h>
ad118c54 14#include <linux/stacktrace.h>
6dab2778 15
4e6a0535
VN
16static void backtrace_test_normal(void)
17{
462b29b8
FF
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");
4e6a0535
VN
20
21 dump_stack();
22}
23
7245d24f 24static void backtrace_test_bh_workfn(struct work_struct *work)
4e6a0535
VN
25{
26 dump_stack();
4e6a0535
VN
27}
28
7245d24f 29static DECLARE_WORK(backtrace_bh_work, &backtrace_test_bh_workfn);
6dab2778 30
7245d24f 31static void backtrace_test_bh(void)
6dab2778 32{
7245d24f 33 pr_info("Testing a backtrace from BH context.\n");
462b29b8 34 pr_info("The following trace is a kernel self test and not a bug!\n");
4e6a0535 35
7245d24f
TH
36 queue_work(system_bh_wq, &backtrace_bh_work);
37 flush_work(&backtrace_bh_work);
6dab2778 38}
ad118c54
VN
39
40#ifdef CONFIG_STACKTRACE
41static void backtrace_test_saved(void)
42{
ad118c54 43 unsigned long entries[8];
1b59562d 44 unsigned int nr_entries;
ad118c54 45
462b29b8
FF
46 pr_info("Testing a saved backtrace.\n");
47 pr_info("The following trace is a kernel self test and not a bug!\n");
ad118c54 48
1b59562d
TG
49 nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
50 stack_trace_print(entries, nr_entries, 0);
ad118c54
VN
51}
52#else
53static void backtrace_test_saved(void)
54{
462b29b8 55 pr_info("Saved backtrace test skipped.\n");
ad118c54
VN
56}
57#endif
58
6dab2778
AV
59static int backtrace_regression_test(void)
60{
462b29b8 61 pr_info("====[ backtrace testing ]===========\n");
6dab2778 62
4e6a0535 63 backtrace_test_normal();
7245d24f 64 backtrace_test_bh();
ad118c54
VN
65 backtrace_test_saved();
66
462b29b8 67 pr_info("====[ end of backtrace testing ]====\n");
6dab2778
AV
68 return 0;
69}
70
71static void exitf(void)
72{
73}
74
75module_init(backtrace_regression_test);
76module_exit(exitf);
77MODULE_LICENSE("GPL");
78MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");