backtracetest.c 2.1 KB

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