1 /* 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 3 * Copyright (c) 2009-2013 Cyril Hrubis chrubis (at) suse.cz 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * Further, this software is distributed without any warranty that it is 14 * free of the rightful claim of any third person regarding infringement 15 * or the like. Any license provided herein, whether implied or 16 * otherwise, applies only to this software file. Patent licenses, if 17 * any, provided herein do not apply to combinations of this program with 18 * other software, or any other product whatsoever. 19 * 20 * You should have received a copy of the GNU General Public License along 21 * with this program; if not, write the Free Software Foundation, Inc., 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 * 24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 25 * Mountain View, CA 94043, or: 26 * 27 * http://www.sgi.com 28 * 29 * For further information regarding this notice, see: 30 * 31 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 32 */ 33 34 #ifndef __TEST_H__ 35 #define __TEST_H__ 36 37 #ifdef TST_TEST_H__ 38 # error Newlib tst_test.h already included 39 #endif /* TST_TEST_H__ */ 40 41 #include <stdio.h> 42 #include <signal.h> 43 #include <unistd.h> 44 #include <string.h> 45 #include <stdlib.h> 46 #include <stdint.h> 47 48 #include "usctest.h" 49 50 #include "tst_common.h" 51 #include "old_safe_file_ops.h" 52 #include "old_checkpoint.h" 53 #include "tst_process_state.h" 54 #include "old_resource.h" 55 #include "tst_res_flags.h" 56 #include "tst_timer.h" 57 #include "tst_kvercmp.h" 58 #include "tst_fs.h" 59 #include "tst_pid.h" 60 #include "tst_cmd.h" 61 #include "tst_cpu.h" 62 #include "tst_clone.h" 63 #include "old_device.h" 64 #include "old_tmpdir.h" 65 #include "tst_minmax.h" 66 67 /* 68 * Ensure that NUMSIGS is defined. 69 * It should be defined in signal.h or sys/signal.h on 70 * UNICOS/mk and IRIX systems. On UNICOS systems, 71 * it is not defined, thus it is being set to UNICOS's NSIG. 72 * Note: IRIX's NSIG (signals are 1-(NSIG-1)) 73 * is not same meaning as UNICOS/UMK's NSIG (signals 1-NSIG) 74 */ 75 #ifndef NUMSIGS 76 #define NUMSIGS NSIG 77 #endif 78 79 80 /* defines for unexpected signal setup routine (set_usig.c) */ 81 #define FORK 1 /* SIGCHLD is to be ignored */ 82 #define NOFORK 0 /* SIGCHLD is to be caught */ 83 #define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */ 84 85 /* 86 * The following defines are used to control tst_res and t_result reporting. 87 */ 88 89 #define TOUTPUT "TOUTPUT" /* The name of the environment variable */ 90 /* that can be set to one of the following */ 91 /* strings to control tst_res output */ 92 /* If not set, TOUT_VERBOSE_S is assumed */ 93 94 /* 95 * fork() can't be used on uClinux systems, so use FORK_OR_VFORK instead, 96 * which will run vfork() on uClinux. 97 * mmap() doesn't support MAP_PRIVATE on uClinux systems, so use 98 * MAP_PRIVATE_EXCEPT_UCLINUX instead, which will skip the option on uClinux. 99 * If MAP_PRIVATE really is required, the test can not be run on uClinux. 100 */ 101 #ifdef UCLINUX 102 # define FORK_OR_VFORK tst_vfork 103 # define MAP_PRIVATE_EXCEPT_UCLINUX 0 104 /* tst_flush() + vfork() */ 105 pid_t tst_vfork(void); 106 #else 107 # define FORK_OR_VFORK tst_fork 108 # define MAP_PRIVATE_EXCEPT_UCLINUX MAP_PRIVATE 109 #endif 110 111 /* 112 * Macro to use for making functions called only once in 113 * multi-threaded tests such as init or cleanup function. 114 * The first call to @name_fn function by any thread shall 115 * call the @exec_fn. Subsequent calls shall not call @exec_fn. 116 * *_fn functions must not take any arguments. 117 */ 118 #define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \ 119 void name_fn(void) \ 120 { \ 121 static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \ 122 pthread_once(<p_once, exec_fn); \ 123 } 124 125 /* 126 * lib/forker.c 127 */ 128 extern int Forker_pids[]; 129 extern int Forker_npids; 130 131 typedef struct { 132 char *option; /* Valid option string (one option only) like "a:" */ 133 int *flag; /* Pointer to location to set true if option given */ 134 char **arg; /* Pointer to location to place argument, if needed */ 135 } option_t; 136 137 /* lib/tst_parse_opts.c */ 138 void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg, 139 void (*user_help)(void)); 140 141 /* lib/tst_res.c */ 142 const char *strttype(int ttype); 143 144 void tst_resm_(const char *file, const int lineno, int ttype, 145 const char *arg_fmt, ...) 146 __attribute__ ((format (printf, 4, 5))); 147 #define tst_resm(ttype, arg_fmt, ...) \ 148 tst_resm_(__FILE__, __LINE__, (ttype), \ 149 (arg_fmt), ##__VA_ARGS__) 150 151 void tst_resm_hexd_(const char *file, const int lineno, int ttype, 152 const void *buf, size_t size, const char *arg_fmt, ...) 153 __attribute__ ((format (printf, 6, 7))); 154 #define tst_resm_hexd(ttype, buf, size, arg_fmt, ...) \ 155 tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \ 156 (arg_fmt), ##__VA_ARGS__) 157 158 void tst_brkm_(const char *file, const int lineno, int ttype, 159 void (*func)(void), const char *arg_fmt, ...) 160 __attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN; 161 162 #ifdef LTPLIB 163 # include "ltp_priv.h" 164 # define tst_brkm(flags, cleanup, fmt, ...) do { \ 165 if (tst_test) \ 166 tst_brk_(__FILE__, __LINE__, flags, fmt, ##__VA_ARGS__); \ 167 else \ 168 tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \ 169 } while (0) 170 #else 171 # define tst_brkm(flags, cleanup, fmt, ...) do { \ 172 tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \ 173 } while (0) 174 #endif 175 176 void tst_require_root(void); 177 void tst_exit(void) LTP_ATTRIBUTE_NORETURN; 178 void tst_flush(void); 179 180 /* 181 * tst_flush() + fork 182 * NOTE: tst_fork() will reset T_exitval to 0 for child process. 183 */ 184 pid_t tst_fork(void); 185 186 /* lib/tst_res.c */ 187 /* 188 * In case we need do real test work in child process parent process can use 189 * tst_record_childstatus() to make child process's test results propagated to 190 * parent process correctly. 191 * 192 * The child can use tst_resm(), tst_brkm() followed by the tst_exit() or 193 * plain old exit() (with TPASS, TFAIL and TBROK). 194 * 195 * WARNING: Be wary that the child cleanup function passed to tst_brkm() 196 * must clean only resources the child has allocated. E.g. the 197 * child cleanup is different function from the parent cleanup. 198 */ 199 void tst_record_childstatus(void (*cleanup)(void), pid_t child); 200 201 extern int tst_count; 202 203 /* lib/tst_sig.c */ 204 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()); 205 206 /* lib/get_high_address.c */ 207 char *get_high_address(void); 208 209 /* lib/self_exec.c */ 210 void maybe_run_child(void (*child)(), const char *fmt, ...); 211 int self_exec(const char *argv0, const char *fmt, ...); 212 213 /* lib/tst_mkfs.c 214 * 215 * @dev: path to a device 216 * @fs_type: filesystem type 217 * @fs_opts: NULL or NULL terminated array of mkfs options 218 * @extra_opt: extra mkfs option which is passed after the device name 219 */ 220 #define tst_mkfs(cleanup, dev, fs_type, fs_opts, extra_opt) \ 221 tst_mkfs_(__FILE__, __LINE__, cleanup, dev, fs_type, \ 222 fs_opts, extra_opt) 223 void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void), 224 const char *dev, const char *fs_type, 225 const char *const fs_opts[], const char *extra_opt); 226 227 /* lib/tst_net.c 228 * 229 * Return unused port 230 */ 231 unsigned short tst_get_unused_port(void (cleanup_fn)(void), 232 unsigned short family, int type); 233 234 /* lib/tst_res.c 235 * tst_strsig converts signal's value to corresponding string. 236 * tst_strerrno converts errno to corresponding string. 237 */ 238 const char *tst_strsig(int sig); 239 const char *tst_strerrno(int err); 240 241 /* lib/tst_path_has_mnt_flags.c 242 * 243 * Check whether a path is on a filesystem that is mounted with 244 * specified flags 245 * @path: path to file, if path is NULL tst_tmpdir is used. 246 * @flags: NULL or NULL terminated array of mount flags 247 * 248 * Return: 0..n - number of flags matched 249 */ 250 int tst_path_has_mnt_flags(void (cleanup_fn)(void), 251 const char *path, const char *flags[]); 252 253 #ifdef TST_USE_COMPAT16_SYSCALL 254 #define TCID_BIT_SUFFIX "_16" 255 #elif TST_USE_NEWER64_SYSCALL 256 #define TCID_BIT_SUFFIX "_64" 257 #else 258 #define TCID_BIT_SUFFIX "" 259 #endif 260 #define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX) 261 262 #endif /* __TEST_H__ */ 263