torture.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Common functions for in-kernel torture tests.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, you can access it online at
  16. * http://www.gnu.org/licenses/gpl-2.0.html.
  17. *
  18. * Copyright IBM Corporation, 2014
  19. *
  20. * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  21. */
  22. #ifndef __LINUX_TORTURE_H
  23. #define __LINUX_TORTURE_H
  24. #include <linux/types.h>
  25. #include <linux/cache.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/threads.h>
  28. #include <linux/cpumask.h>
  29. #include <linux/seqlock.h>
  30. #include <linux/lockdep.h>
  31. #include <linux/completion.h>
  32. #include <linux/debugobjects.h>
  33. #include <linux/bug.h>
  34. #include <linux/compiler.h>
  35. /* Definitions for a non-string torture-test module parameter. */
  36. #define torture_param(type, name, init, msg) \
  37. static type name = init; \
  38. module_param(name, type, 0444); \
  39. MODULE_PARM_DESC(name, msg);
  40. #define TORTURE_FLAG "-torture:"
  41. #define TOROUT_STRING(s) \
  42. pr_alert("%s" TORTURE_FLAG s "\n", torture_type)
  43. #define VERBOSE_TOROUT_STRING(s) \
  44. do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0)
  45. #define VERBOSE_TOROUT_ERRSTRING(s) \
  46. do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0)
  47. /* Definitions for online/offline exerciser. */
  48. int torture_onoff_init(long ooholdoff, long oointerval);
  49. void torture_onoff_stats(void);
  50. bool torture_onoff_failures(void);
  51. /* Low-rider random number generator. */
  52. struct torture_random_state {
  53. unsigned long trs_state;
  54. long trs_count;
  55. };
  56. #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
  57. unsigned long torture_random(struct torture_random_state *trsp);
  58. /* Task shuffler, which causes CPUs to occasionally go idle. */
  59. void torture_shuffle_task_register(struct task_struct *tp);
  60. int torture_shuffle_init(long shuffint);
  61. /* Test auto-shutdown handling. */
  62. void torture_shutdown_absorb(const char *title);
  63. int torture_shutdown_init(int ssecs, void (*cleanup)(void));
  64. /* Task stuttering, which forces load/no-load transitions. */
  65. void stutter_wait(const char *title);
  66. int torture_stutter_init(int s);
  67. /* Initialization and cleanup. */
  68. bool torture_init_begin(char *ttype, bool v, int *runnable);
  69. void torture_init_end(void);
  70. bool torture_cleanup_begin(void);
  71. void torture_cleanup_end(void);
  72. bool torture_must_stop(void);
  73. bool torture_must_stop_irq(void);
  74. void torture_kthread_stopping(char *title);
  75. int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
  76. char *f, struct task_struct **tp);
  77. void _torture_stop_kthread(char *m, struct task_struct **tp);
  78. #define torture_create_kthread(n, arg, tp) \
  79. _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
  80. "Failed to create " #n, &(tp))
  81. #define torture_stop_kthread(n, tp) \
  82. _torture_stop_kthread("Stopping " #n " task", &(tp))
  83. #endif /* __LINUX_TORTURE_H */