backtracetest.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <linux/completion.h>
  9. #include <linux/delay.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/module.h>
  12. #include <linux/sched.h>
  13. #include <linux/stacktrace.h>
  14. static void backtrace_test_normal(void)
  15. {
  16. pr_info("Testing a backtrace from process context.\n");
  17. pr_info("The following trace is a kernel self test and not a bug!\n");
  18. dump_stack();
  19. }
  20. static DECLARE_COMPLETION(backtrace_work);
  21. static void backtrace_test_irq_callback(unsigned long data)
  22. {
  23. dump_stack();
  24. complete(&backtrace_work);
  25. }
  26. static DECLARE_TASKLET_OLD(backtrace_tasklet, &backtrace_test_irq_callback);
  27. static void backtrace_test_irq(void)
  28. {
  29. pr_info("Testing a backtrace from irq context.\n");
  30. pr_info("The following trace is a kernel self test and not a bug!\n");
  31. init_completion(&backtrace_work);
  32. tasklet_schedule(&backtrace_tasklet);
  33. wait_for_completion(&backtrace_work);
  34. }
  35. #ifdef CONFIG_STACKTRACE
  36. static void backtrace_test_saved(void)
  37. {
  38. unsigned long entries[8];
  39. unsigned int nr_entries;
  40. pr_info("Testing a saved backtrace.\n");
  41. pr_info("The following trace is a kernel self test and not a bug!\n");
  42. nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
  43. stack_trace_print(entries, nr_entries, 0);
  44. }
  45. #else
  46. static void backtrace_test_saved(void)
  47. {
  48. pr_info("Saved backtrace test skipped.\n");
  49. }
  50. #endif
  51. static int backtrace_regression_test(void)
  52. {
  53. pr_info("====[ backtrace testing ]===========\n");
  54. backtrace_test_normal();
  55. backtrace_test_irq();
  56. backtrace_test_saved();
  57. pr_info("====[ end of backtrace testing ]====\n");
  58. return 0;
  59. }
  60. static void exitf(void)
  61. {
  62. }
  63. module_init(backtrace_regression_test);
  64. module_exit(exitf);
  65. MODULE_LICENSE("GPL");
  66. MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");