Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 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 | |
| 23 | #ifndef __LINUX_TORTURE_H |
| 24 | #define __LINUX_TORTURE_H |
| 25 | |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/cache.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/threads.h> |
| 30 | #include <linux/cpumask.h> |
| 31 | #include <linux/seqlock.h> |
| 32 | #include <linux/lockdep.h> |
| 33 | #include <linux/completion.h> |
| 34 | #include <linux/debugobjects.h> |
| 35 | #include <linux/bug.h> |
| 36 | #include <linux/compiler.h> |
| 37 | |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 38 | /* Definitions for a non-string torture-test module parameter. */ |
| 39 | #define torture_param(type, name, init, msg) \ |
| 40 | static type name = init; \ |
| 41 | module_param(name, type, 0444); \ |
| 42 | MODULE_PARM_DESC(name, msg); |
| 43 | |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 44 | #define TORTURE_FLAG "-torture:" |
| 45 | #define TOROUT_STRING(s) \ |
| 46 | pr_alert("%s" TORTURE_FLAG s "\n", torture_type) |
| 47 | #define VERBOSE_TOROUT_STRING(s) \ |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 48 | do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0) |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 49 | #define VERBOSE_TOROUT_ERRSTRING(s) \ |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 50 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0) |
Paul E. McKenney | c2884de | 2014-01-29 07:30:50 -0800 | [diff] [blame] | 51 | |
Paul E. McKenney | 2e9e808 | 2014-01-28 15:58:22 -0800 | [diff] [blame] | 52 | /* Definitions for online/offline exerciser. */ |
| 53 | int torture_onoff_init(long ooholdoff, long oointerval); |
Joe Perches | eea203f | 2014-07-14 09:16:15 -0400 | [diff] [blame] | 54 | void torture_onoff_stats(void); |
Paul E. McKenney | 2e9e808 | 2014-01-28 15:58:22 -0800 | [diff] [blame] | 55 | bool torture_onoff_failures(void); |
| 56 | |
Paul E. McKenney | 9e25022 | 2014-01-27 16:27:00 -0800 | [diff] [blame] | 57 | /* Low-rider random number generator. */ |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 58 | struct torture_random_state { |
| 59 | unsigned long trs_state; |
| 60 | long trs_count; |
| 61 | }; |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 62 | #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 63 | unsigned long torture_random(struct torture_random_state *trsp); |
| 64 | |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 65 | /* Task shuffler, which causes CPUs to occasionally go idle. */ |
| 66 | void torture_shuffle_task_register(struct task_struct *tp); |
| 67 | int torture_shuffle_init(long shuffint); |
Paul E. McKenney | 3808dc9 | 2014-01-28 15:29:21 -0800 | [diff] [blame] | 68 | |
Paul E. McKenney | e991dbc | 2014-01-31 14:52:13 -0800 | [diff] [blame] | 69 | /* Test auto-shutdown handling. */ |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 70 | void torture_shutdown_absorb(const char *title); |
Paul E. McKenney | e991dbc | 2014-01-31 14:52:13 -0800 | [diff] [blame] | 71 | int torture_shutdown_init(int ssecs, void (*cleanup)(void)); |
Paul E. McKenney | f67a335 | 2014-01-29 07:40:27 -0800 | [diff] [blame] | 72 | |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 73 | /* Task stuttering, which forces load/no-load transitions. */ |
| 74 | void stutter_wait(const char *title); |
| 75 | int torture_stutter_init(int s); |
Paul E. McKenney | 628edaa | 2014-01-31 11:57:43 -0800 | [diff] [blame] | 76 | |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 77 | /* Initialization and cleanup. */ |
Paul E. McKenney | 5228084 | 2014-04-07 09:14:11 -0700 | [diff] [blame] | 78 | bool torture_init_begin(char *ttype, bool v, int *runnable); |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 79 | void torture_init_end(void); |
Davidlohr Bueso | d36a7a0 | 2014-09-11 20:40:21 -0700 | [diff] [blame] | 80 | bool torture_cleanup_begin(void); |
| 81 | void torture_cleanup_end(void); |
Paul E. McKenney | 36970bb | 2014-01-30 15:49:29 -0800 | [diff] [blame] | 82 | bool torture_must_stop(void); |
| 83 | bool torture_must_stop_irq(void); |
Paul E. McKenney | 7fafaac | 2014-01-31 17:37:28 -0800 | [diff] [blame] | 84 | void torture_kthread_stopping(char *title); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 85 | int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, |
| 86 | char *f, struct task_struct **tp); |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 87 | void _torture_stop_kthread(char *m, struct task_struct **tp); |
Paul E. McKenney | 47cf29b | 2014-02-03 11:52:27 -0800 | [diff] [blame] | 88 | |
| 89 | #define torture_create_kthread(n, arg, tp) \ |
| 90 | _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \ |
| 91 | "Failed to create " #n, &(tp)) |
Paul E. McKenney | 9c029b8 | 2014-02-04 11:47:08 -0800 | [diff] [blame] | 92 | #define torture_stop_kthread(n, tp) \ |
| 93 | _torture_stop_kthread("Stopping " #n " task", &(tp)) |
Paul E. McKenney | b5daa8f | 2014-01-30 13:38:09 -0800 | [diff] [blame] | 94 | |
Paul E. McKenney | 51b1130 | 2014-01-27 11:49:39 -0800 | [diff] [blame] | 95 | #endif /* __LINUX_TORTURE_H */ |