0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __LINUX_TORTURE_H
0011 #define __LINUX_TORTURE_H
0012
0013 #include <linux/types.h>
0014 #include <linux/cache.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/threads.h>
0017 #include <linux/cpumask.h>
0018 #include <linux/seqlock.h>
0019 #include <linux/lockdep.h>
0020 #include <linux/completion.h>
0021 #include <linux/debugobjects.h>
0022 #include <linux/bug.h>
0023 #include <linux/compiler.h>
0024
0025
0026 #define torture_param(type, name, init, msg) \
0027 static type name = init; \
0028 module_param(name, type, 0444); \
0029 MODULE_PARM_DESC(name, msg);
0030
0031 #define TORTURE_FLAG "-torture:"
0032 #define TOROUT_STRING(s) \
0033 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
0034 #define VERBOSE_TOROUT_STRING(s) \
0035 do { \
0036 if (verbose) { \
0037 verbose_torout_sleep(); \
0038 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); \
0039 } \
0040 } while (0)
0041 #define TOROUT_ERRSTRING(s) \
0042 pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s)
0043 void verbose_torout_sleep(void);
0044
0045 #define torture_init_error(firsterr) \
0046 ({ \
0047 int ___firsterr = (firsterr); \
0048 \
0049 WARN_ONCE(!IS_MODULE(CONFIG_RCU_TORTURE_TEST) && ___firsterr < 0, "Torture-test initialization failed with error code %d\n", ___firsterr); \
0050 ___firsterr < 0; \
0051 })
0052
0053
0054 #ifdef CONFIG_HOTPLUG_CPU
0055 int torture_num_online_cpus(void);
0056 #else
0057 static inline int torture_num_online_cpus(void) { return 1; }
0058 #endif
0059 typedef void torture_ofl_func(void);
0060 bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
0061 unsigned long *sum_offl, int *min_onl, int *max_onl);
0062 bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
0063 unsigned long *sum_onl, int *min_onl, int *max_onl);
0064 int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f);
0065 void torture_onoff_stats(void);
0066 bool torture_onoff_failures(void);
0067
0068
0069 struct torture_random_state {
0070 unsigned long trs_state;
0071 long trs_count;
0072 };
0073 #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
0074 #define DEFINE_TORTURE_RANDOM_PERCPU(name) \
0075 DEFINE_PER_CPU(struct torture_random_state, name)
0076 unsigned long torture_random(struct torture_random_state *trsp);
0077 static inline void torture_random_init(struct torture_random_state *trsp)
0078 {
0079 trsp->trs_state = 0;
0080 trsp->trs_count = 0;
0081 }
0082
0083
0084 int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
0085 int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
0086 int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
0087 int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
0088 int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
0089
0090
0091 void torture_shuffle_task_register(struct task_struct *tp);
0092 int torture_shuffle_init(long shuffint);
0093
0094
0095 void torture_shutdown_absorb(const char *title);
0096 int torture_shutdown_init(int ssecs, void (*cleanup)(void));
0097
0098
0099 bool stutter_wait(const char *title);
0100 int torture_stutter_init(int s, int sgap);
0101
0102
0103 bool torture_init_begin(char *ttype, int v);
0104 void torture_init_end(void);
0105 bool torture_cleanup_begin(void);
0106 void torture_cleanup_end(void);
0107 bool torture_must_stop(void);
0108 bool torture_must_stop_irq(void);
0109 void torture_kthread_stopping(char *title);
0110 int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
0111 char *f, struct task_struct **tp);
0112 void _torture_stop_kthread(char *m, struct task_struct **tp);
0113
0114 #define torture_create_kthread(n, arg, tp) \
0115 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
0116 "Failed to create " #n, &(tp))
0117 #define torture_stop_kthread(n, tp) \
0118 _torture_stop_kthread("Stopping " #n " task", &(tp))
0119
0120 #ifdef CONFIG_PREEMPTION
0121 #define torture_preempt_schedule() __preempt_schedule()
0122 #else
0123 #define torture_preempt_schedule() do { } while (0)
0124 #endif
0125
0126 #endif