1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 4 * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz 5 */ 6 7 #ifndef __TEST_H__ 8 #define __TEST_H__ 9 10 #ifdef TST_TEST_H__ 11 # error Newlib tst_test.h already included 12 #endif /* TST_TEST_H__ */ 13 14 #include <stdio.h> 15 #include <signal.h> 16 #include <unistd.h> 17 #include <string.h> 18 #include <stdlib.h> 19 #include <stdint.h> 20 21 #include "usctest.h" 22 23 #include "tst_common.h" 24 #include "old_safe_file_ops.h" 25 #include "old_checkpoint.h" 26 #include "tst_process_state.h" 27 #include "old_resource.h" 28 #include "tst_res_flags.h" 29 #include "tst_kvercmp.h" 30 #include "tst_fs.h" 31 #include "tst_pid.h" 32 #include "tst_cmd.h" 33 #include "tst_cpu.h" 34 #include "old_device.h" 35 #include "old_tmpdir.h" 36 #include "tst_minmax.h" 37 #include "tst_get_bad_addr.h" 38 #include "tst_path_has_mnt_flags.h" 39 40 /* 41 * Ensure that NUMSIGS is defined. 42 * It should be defined in signal.h or sys/signal.h on 43 * UNICOS/mk and IRIX systems. On UNICOS systems, 44 * it is not defined, thus it is being set to UNICOS's NSIG. 45 * Note: IRIX's NSIG (signals are 1-(NSIG-1)) 46 * is not same meaning as UNICOS/UMK's NSIG (signals 1-NSIG) 47 */ 48 #ifndef NUMSIGS 49 #define NUMSIGS NSIG 50 #endif 51 52 53 /* defines for unexpected signal setup routine (set_usig.c) */ 54 #define FORK 1 /* SIGCHLD is to be ignored */ 55 #define NOFORK 0 /* SIGCHLD is to be caught */ 56 #define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */ 57 58 /* 59 * The following defines are used to control tst_res and t_result reporting. 60 */ 61 62 #define TOUTPUT "TOUTPUT" /* The name of the environment variable */ 63 /* that can be set to one of the following */ 64 /* strings to control tst_res output */ 65 /* If not set, TOUT_VERBOSE_S is assumed */ 66 67 /* 68 * Macro to use for making functions called only once in 69 * multi-threaded tests such as init or cleanup function. 70 * The first call to @name_fn function by any thread shall 71 * call the @exec_fn. Subsequent calls shall not call @exec_fn. 72 * *_fn functions must not take any arguments. 73 */ 74 #define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \ 75 void name_fn(void) \ 76 { \ 77 static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \ 78 pthread_once(<p_once, exec_fn); \ 79 } 80 81 /* 82 * lib/forker.c 83 */ 84 extern int Forker_pids[]; 85 extern int Forker_npids; 86 87 typedef struct { 88 char *option; /* Valid option string (one option only) like "a:" */ 89 int *flag; /* Pointer to location to set true if option given */ 90 char **arg; /* Pointer to location to place argument, if needed */ 91 } option_t; 92 93 /* lib/tst_parse_opts.c */ 94 void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg, 95 void (*user_help)(void)); 96 97 /* lib/tst_res.c */ 98 const char *strttype(int ttype); 99 100 void tst_resm_(const char *file, const int lineno, int ttype, 101 const char *arg_fmt, ...) 102 __attribute__ ((format (printf, 4, 5))); 103 #define tst_resm(ttype, arg_fmt, ...) \ 104 tst_resm_(__FILE__, __LINE__, (ttype), \ 105 (arg_fmt), ##__VA_ARGS__) 106 107 void tst_resm_hexd_(const char *file, const int lineno, int ttype, 108 const void *buf, size_t size, const char *arg_fmt, ...) 109 __attribute__ ((format (printf, 6, 7))); 110 #define tst_resm_hexd(ttype, buf, size, arg_fmt, ...) \ 111 tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \ 112 (arg_fmt), ##__VA_ARGS__) 113 114 void tst_brkm__(const char *file, const int lineno, int ttype, 115 void (*func)(void), const char *arg_fmt, ...) 116 __attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN; 117 118 #ifdef LTPLIB 119 # include "ltp_priv.h" 120 # define tst_brkm(flags, cleanup, fmt, ...) do { \ 121 if (tst_test) \ 122 tst_brk_(__FILE__, __LINE__, flags, fmt, ##__VA_ARGS__); \ 123 else \ 124 tst_brkm__(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \ 125 } while (0) 126 127 #define tst_brkm_(file, lineno, flags, cleanup, fmt, ...) do { \ 128 if (tst_test) \ 129 tst_brk_(file, lineno, flags, fmt, ##__VA_ARGS__); \ 130 else \ 131 tst_brkm__(file, lineno, flags, cleanup, fmt, ##__VA_ARGS__); \ 132 } while (0) 133 #else 134 # define tst_brkm(flags, cleanup, fmt, ...) do { \ 135 tst_brkm__(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \ 136 } while (0) 137 #endif 138 139 void tst_require_root(void); 140 void tst_exit(void) LTP_ATTRIBUTE_NORETURN; 141 void tst_old_flush(void); 142 143 /* 144 * tst_old_flush() + fork 145 * NOTE: tst_fork() will reset T_exitval to 0 for child process. 146 */ 147 pid_t tst_fork(void); 148 149 /* lib/tst_res.c */ 150 /* 151 * In case we need do real test work in child process parent process can use 152 * tst_record_childstatus() to make child process's test results propagated to 153 * parent process correctly. 154 * 155 * The child can use tst_resm(), tst_brkm() followed by the tst_exit() or 156 * plain old exit() (with TPASS, TFAIL and TBROK). 157 * 158 * WARNING: Be wary that the child cleanup function passed to tst_brkm() 159 * must clean only resources the child has allocated. E.g. the 160 * child cleanup is different function from the parent cleanup. 161 */ 162 void tst_record_childstatus(void (*cleanup)(void), pid_t child); 163 164 extern int tst_count; 165 166 /* lib/tst_sig.c */ 167 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()); 168 169 /* lib/tst_mkfs.c 170 * 171 * @dev: path to a device 172 * @fs_type: filesystem type 173 * @fs_opts: NULL or NULL terminated array of mkfs options 174 * @extra_opts: NULL or NULL terminated array of extra mkfs options which are 175 * passed after the device name. 176 */ 177 #define tst_mkfs(cleanup, dev, fs_type, fs_opts, extra_opts) \ 178 tst_mkfs_(__FILE__, __LINE__, cleanup, dev, fs_type, \ 179 fs_opts, extra_opts) 180 void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void), 181 const char *dev, const char *fs_type, 182 const char *const fs_opts[], const char *const extra_opts[]); 183 184 /* lib/tst_res.c 185 * tst_strsig converts signal's value to corresponding string. 186 * tst_strerrno converts errno to corresponding string. 187 */ 188 const char *tst_strsig(int sig); 189 const char *tst_strerrno(int err); 190 191 #ifdef TST_USE_COMPAT16_SYSCALL 192 #define TCID_BIT_SUFFIX "_16" 193 #elif TST_USE_NEWER64_SYSCALL 194 #define TCID_BIT_SUFFIX "_64" 195 #else 196 #define TCID_BIT_SUFFIX "" 197 #endif 198 #define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX) 199 200 #endif /* __TEST_H__ */ 201