backtracetest.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 void backtrace_test_bh_workfn(struct work_struct *work)
  21. {
  22. dump_stack();
  23. }
  24. static DECLARE_WORK(backtrace_bh_work, &backtrace_test_bh_workfn);
  25. static void backtrace_test_bh(void)
  26. {
  27. pr_info("Testing a backtrace from BH context.\n");
  28. pr_info("The following trace is a kernel self test and not a bug!\n");
  29. queue_work(system_bh_wq, &backtrace_bh_work);
  30. flush_work(&backtrace_bh_work);
  31. }
  32. #ifdef CONFIG_STACKTRACE
  33. static void backtrace_test_saved(void)
  34. {
  35. unsigned long entries[8];
  36. unsigned int nr_entries;
  37. pr_info("Testing a saved backtrace.\n");
  38. pr_info("The following trace is a kernel self test and not a bug!\n");
  39. nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
  40. stack_trace_print(entries, nr_entries, 0);
  41. }
  42. #else
  43. static void backtrace_test_saved(void)
  44. {
  45. pr_info("Saved backtrace test skipped.\n");
  46. }
  47. #endif
  48. static int backtrace_regression_test(void)
  49. {
  50. pr_info("====[ backtrace testing ]===========\n");
  51. backtrace_test_normal();
  52. backtrace_test_bh();
  53. backtrace_test_saved();
  54. pr_info("====[ end of backtrace testing ]====\n");
  55. return 0;
  56. }
  57. static void exitf(void)
  58. {
  59. }
  60. module_init(backtrace_regression_test);
  61. module_exit(exitf);
  62. MODULE_DESCRIPTION("Simple stack backtrace regression test module");
  63. MODULE_LICENSE("GPL");
  64. MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");