Commit | Line | Data |
---|---|---|
082dfb3c | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
51b1130e PM |
2 | /* |
3 | * Common functions for in-kernel torture tests. | |
4 | * | |
51b1130e PM |
5 | * Copyright IBM Corporation, 2014 |
6 | * | |
082dfb3c | 7 | * Author: Paul E. McKenney <paulmck@linux.ibm.com> |
51b1130e PM |
8 | */ |
9 | ||
10 | #ifndef __LINUX_TORTURE_H | |
11 | #define __LINUX_TORTURE_H | |
12 | ||
13 | #include <linux/types.h> | |
14 | #include <linux/cache.h> | |
15 | #include <linux/spinlock.h> | |
16 | #include <linux/threads.h> | |
17 | #include <linux/cpumask.h> | |
18 | #include <linux/seqlock.h> | |
19 | #include <linux/lockdep.h> | |
20 | #include <linux/completion.h> | |
21 | #include <linux/debugobjects.h> | |
22 | #include <linux/bug.h> | |
23 | #include <linux/compiler.h> | |
24 | ||
9e250225 PM |
25 | /* Definitions for a non-string torture-test module parameter. */ |
26 | #define torture_param(type, name, init, msg) \ | |
27 | static type name = init; \ | |
28 | module_param(name, type, 0444); \ | |
29 | MODULE_PARM_DESC(name, msg); | |
30 | ||
c2884de3 PM |
31 | #define TORTURE_FLAG "-torture:" |
32 | #define TOROUT_STRING(s) \ | |
489bb3d2 | 33 | pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s) |
c2884de3 | 34 | #define VERBOSE_TOROUT_STRING(s) \ |
8a67a20b PM |
35 | do { \ |
36 | if (verbose) { \ | |
37 | verbose_torout_sleep(); \ | |
38 | pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); \ | |
39 | } \ | |
40 | } while (0) | |
c2884de3 | 41 | #define VERBOSE_TOROUT_ERRSTRING(s) \ |
8a67a20b PM |
42 | do { \ |
43 | if (verbose) { \ | |
44 | verbose_torout_sleep(); \ | |
45 | pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); \ | |
46 | } \ | |
47 | } while (0) | |
48 | void verbose_torout_sleep(void); | |
c2884de3 | 49 | |
2e9e8081 | 50 | /* Definitions for online/offline exerciser. */ |
3a6cb58f | 51 | typedef void torture_ofl_func(void); |
d95f5ba9 PM |
52 | bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes, |
53 | unsigned long *sum_offl, int *min_onl, int *max_onl); | |
54 | bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, | |
55 | unsigned long *sum_onl, int *min_onl, int *max_onl); | |
3a6cb58f | 56 | int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f); |
eea203fe | 57 | void torture_onoff_stats(void); |
2e9e8081 PM |
58 | bool torture_onoff_failures(void); |
59 | ||
9e250225 | 60 | /* Low-rider random number generator. */ |
51b1130e PM |
61 | struct torture_random_state { |
62 | unsigned long trs_state; | |
63 | long trs_count; | |
64 | }; | |
51b1130e | 65 | #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } |
3025520e PM |
66 | #define DEFINE_TORTURE_RANDOM_PERCPU(name) \ |
67 | DEFINE_PER_CPU(struct torture_random_state, name) | |
51b1130e | 68 | unsigned long torture_random(struct torture_random_state *trsp); |
4a5f133c PM |
69 | static inline void torture_random_init(struct torture_random_state *trsp) |
70 | { | |
71 | trsp->trs_state = 0; | |
72 | trsp->trs_count = 0; | |
73 | } | |
51b1130e | 74 | |
ae19aaaf PM |
75 | /* Definitions for high-resolution-timer sleeps. */ |
76 | int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp); | |
77 | int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp); | |
78 | int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp); | |
79 | int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp); | |
80 | int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp); | |
81 | ||
3808dc9f PM |
82 | /* Task shuffler, which causes CPUs to occasionally go idle. */ |
83 | void torture_shuffle_task_register(struct task_struct *tp); | |
84 | int torture_shuffle_init(long shuffint); | |
3808dc9f | 85 | |
e991dbc0 | 86 | /* Test auto-shutdown handling. */ |
f67a3356 | 87 | void torture_shutdown_absorb(const char *title); |
e991dbc0 | 88 | int torture_shutdown_init(int ssecs, void (*cleanup)(void)); |
f67a3356 | 89 | |
628edaa5 | 90 | /* Task stuttering, which forces load/no-load transitions. */ |
474e59b4 | 91 | bool stutter_wait(const char *title); |
ff3bf92d | 92 | int torture_stutter_init(int s, int sgap); |
628edaa5 | 93 | |
b5daa8f3 | 94 | /* Initialization and cleanup. */ |
90127d60 | 95 | bool torture_init_begin(char *ttype, int v); |
b5daa8f3 | 96 | void torture_init_end(void); |
d36a7a0d DB |
97 | bool torture_cleanup_begin(void); |
98 | void torture_cleanup_end(void); | |
36970bb9 PM |
99 | bool torture_must_stop(void); |
100 | bool torture_must_stop_irq(void); | |
7fafaac5 | 101 | void torture_kthread_stopping(char *title); |
47cf29b9 PM |
102 | int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, |
103 | char *f, struct task_struct **tp); | |
9c029b86 | 104 | void _torture_stop_kthread(char *m, struct task_struct **tp); |
47cf29b9 PM |
105 | |
106 | #define torture_create_kthread(n, arg, tp) \ | |
107 | _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \ | |
108 | "Failed to create " #n, &(tp)) | |
9c029b86 PM |
109 | #define torture_stop_kthread(n, tp) \ |
110 | _torture_stop_kthread("Stopping " #n " task", &(tp)) | |
b5daa8f3 | 111 | |
01b1d88b | 112 | #ifdef CONFIG_PREEMPTION |
cc1321c9 PM |
113 | #define torture_preempt_schedule() preempt_schedule() |
114 | #else | |
be44ae62 | 115 | #define torture_preempt_schedule() do { } while (0) |
cc1321c9 PM |
116 | #endif |
117 | ||
51b1130e | 118 | #endif /* __LINUX_TORTURE_H */ |