Linux Audio

Check our new training course

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