at v5.2 3.3 kB view raw
1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Common functions for in-kernel torture tests. 4 * 5 * Copyright IBM Corporation, 2014 6 * 7 * Author: Paul E. McKenney <paulmck@linux.ibm.com> 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 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 31#define TORTURE_FLAG "-torture:" 32#define TOROUT_STRING(s) \ 33 pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s) 34#define VERBOSE_TOROUT_STRING(s) \ 35 do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0) 36#define VERBOSE_TOROUT_ERRSTRING(s) \ 37 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0) 38 39/* Definitions for online/offline exerciser. */ 40typedef void torture_ofl_func(void); 41bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes, 42 unsigned long *sum_offl, int *min_onl, int *max_onl); 43bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, 44 unsigned long *sum_onl, int *min_onl, int *max_onl); 45int torture_onoff_init(long ooholdoff, long oointerval, torture_ofl_func *f); 46void torture_onoff_stats(void); 47bool torture_onoff_failures(void); 48 49/* Low-rider random number generator. */ 50struct torture_random_state { 51 unsigned long trs_state; 52 long trs_count; 53}; 54#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } 55#define DEFINE_TORTURE_RANDOM_PERCPU(name) \ 56 DEFINE_PER_CPU(struct torture_random_state, name) 57unsigned long torture_random(struct torture_random_state *trsp); 58 59/* Task shuffler, which causes CPUs to occasionally go idle. */ 60void torture_shuffle_task_register(struct task_struct *tp); 61int torture_shuffle_init(long shuffint); 62 63/* Test auto-shutdown handling. */ 64void torture_shutdown_absorb(const char *title); 65int torture_shutdown_init(int ssecs, void (*cleanup)(void)); 66 67/* Task stuttering, which forces load/no-load transitions. */ 68bool stutter_wait(const char *title); 69int torture_stutter_init(int s); 70 71/* Initialization and cleanup. */ 72bool torture_init_begin(char *ttype, int v); 73void torture_init_end(void); 74bool torture_cleanup_begin(void); 75void torture_cleanup_end(void); 76bool torture_must_stop(void); 77bool torture_must_stop_irq(void); 78void torture_kthread_stopping(char *title); 79int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, 80 char *f, struct task_struct **tp); 81void _torture_stop_kthread(char *m, struct task_struct **tp); 82 83#define torture_create_kthread(n, arg, tp) \ 84 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \ 85 "Failed to create " #n, &(tp)) 86#define torture_stop_kthread(n, tp) \ 87 _torture_stop_kthread("Stopping " #n " task", &(tp)) 88 89#ifdef CONFIG_PREEMPT 90#define torture_preempt_schedule() preempt_schedule() 91#else 92#define torture_preempt_schedule() 93#endif 94 95#endif /* __LINUX_TORTURE_H */