alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | */ |
| 32 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 33 | /* $Id: usctest.h,v 1.2 2000/08/30 18:43:38 nstraz Exp $ */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 34 | |
| 35 | /********************************************************** |
| 36 | * |
| 37 | * IRIX/Linux Feature Test and Evaluation - Silicon Graphics, Inc. |
| 38 | * |
| 39 | * FUNCTION NAME : usctest.h |
| 40 | * |
| 41 | * FUNCTION TITLE : System Call Test Macros |
| 42 | * |
| 43 | * SYNOPSIS: |
| 44 | * See DESCRIPTION below. |
| 45 | * |
| 46 | * AUTHOR : William Roske |
| 47 | * |
| 48 | * INITIAL RELEASE : UNICOS 7.0 |
| 49 | * |
| 50 | * DESCRIPTION |
| 51 | * TEST(SCALL) - calls a system call |
| 52 | * TEST_VOID(SCALL) - same as TEST() but for syscalls with no return value. |
| 53 | * TEST_CLEANUP - print the log of errno return counts if STD_ERRNO_LOG |
| 54 | * is set. |
| 55 | * TEST_PAUSEF(HAND) - Pause for SIGUSR1 if the pause flag is set. |
| 56 | * Use "hand" as the interrupt handling function |
| 57 | * TEST_PAUSE - Pause for SIGUSR1 if the pause flag is set. |
| 58 | * Use internal function to do nothing on signal and go on. |
| 59 | * TEST_LOOPING(COUNTER) - Conditional to check if test should |
| 60 | * loop. Evaluates to TRUE (1) or FALSE (0). |
| 61 | * TEST_ERROR_LOG(eno) - log that this errno was received, |
| 62 | * if STD_ERRNO_LOG is set. |
| 63 | * TEST_EXP_ENOS(array) - set the bits in TEST_VALID_ENO array at |
| 64 | * positions specified in integer "array" |
| 65 | * |
| 66 | * RETURN VALUE |
| 67 | * TEST(SCALL) - Global Variables set: |
| 68 | * int TEST_RETURN=return code from SCALL |
| 69 | * int TEST_ERRNO=value of errno at return from SCALL |
| 70 | * TEST_VOID(SCALL) - Global Variables set: |
| 71 | * int TEST_ERRNO=value of errno at return from SCALL |
| 72 | * TEST_CLEANUP - None. |
| 73 | * TEST_PAUSEF(HAND) - None. |
| 74 | * TEST_PAUSE - None. |
| 75 | * TEST_LOOPING(COUNTER) - True if COUNTER < STD_LOOP_COUNT or |
| 76 | * STD_INFINITE is set. |
| 77 | * TEST_ERROR_LOG(eno) - None |
| 78 | * TEST_EXP_ENOS(array) - None |
| 79 | * |
| 80 | * KNOWN BUGS |
| 81 | * If you use the TEST_PAUSE or TEST_LOOPING macros, you must |
| 82 | * link in parse_opts.o, which contains the code for those functions. |
| 83 | * |
| 84 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 85 | |
| 86 | #ifndef __USCTEST_H__ |
| 87 | #define __USCTEST_H__ 1 |
| 88 | |
| 89 | #ifndef _SC_CLK_TCK |
| 90 | #include <unistd.h> |
| 91 | #endif |
| 92 | |
| 93 | #include <sys/param.h> |
| 94 | |
| 95 | /* |
| 96 | * Ensure that PATH_MAX is defined |
| 97 | */ |
| 98 | #ifndef PATH_MAX |
| 99 | #ifdef MAXPATHLEN |
| 100 | #define PATH_MAX MAXPATHLEN |
| 101 | #else |
| 102 | #define PATH_MAX 1024 |
| 103 | #endif |
| 104 | #endif |
| 105 | |
| 106 | #ifndef CRAY |
| 107 | #ifndef BSIZE |
| 108 | #define BSIZE BBSIZE |
| 109 | #endif |
| 110 | #endif |
| 111 | |
| 112 | /* |
| 113 | * Define standard options. |
| 114 | * These value should match the values in USC_common.h. |
| 115 | */ |
| 116 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 117 | #define NOFUNC "f" /* no func check flag */ |
| 118 | #define ITERATIONS "i:" /* # iterations */ |
| 119 | #define DURATION "I:" /* walltime floating point */ |
| 120 | #define DELAY "P:" /* delay each iteration */ |
| 121 | #define TIMING "t" /* sys call timing flag */ |
| 122 | #define ERRNO_LOGGING "e" /* errno logging flag */ |
| 123 | #define SETUP_PAUSE "p" /* wait sigusr1 signal in setup */ |
| 124 | #define COPIES "c:" /* number copies */ |
| 125 | #define USC_HELP "h" /* basic help */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 126 | |
| 127 | #define ITERATIONS_HELP \ |
| 128 | " -iterations cnt : Execute test \"cnt\" times (Default is 1).\n\ |
| 129 | A value of 0 will cause the test to run indefinitely.\n" |
| 130 | |
| 131 | #define DELAY_HELP \ |
| 132 | " -delay secs : Delay for \"secs\" seconds each iteration (def 0.0)\n" |
| 133 | |
| 134 | #define DURATION_HELP \ |
| 135 | " -duration secs : Iterate for elapsed time of \"secs\" (def 0.0)\n" |
| 136 | |
| 137 | #define NOFUNC_HELP \ |
| 138 | " -nofunc : Turn OFF Functional testing. Just exercise the system call.\n" |
| 139 | |
| 140 | #define SETUP_PAUSE_HELP \ |
| 141 | " -pause_for_sigusr1 : Pause for SIGUSR1 before entering testing loop.\n" |
| 142 | |
| 143 | #define TIMING_HELP \ |
| 144 | " -timing : Turn ON timing statistics (min, max and avg time in system call).\n" |
| 145 | |
| 146 | #define ERRNO_LOGGING_HELP \ |
| 147 | " -errno_logging : Turn ON errno logging.\n" |
| 148 | |
| 149 | #define COPIES_HELP \ |
| 150 | " -copies num : fork so there num copies (def 1)\n" |
| 151 | |
| 152 | #define USC_HELP_HELP \ |
| 153 | " -Help : parse_opts standard help and exit.\n" |
| 154 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 155 | /*********************************************************************** |
| 156 | * Define option_t structure type. |
| 157 | * Entries in this struct are used by the parse_opts routine |
| 158 | * to indicate valid options and return option arguments |
| 159 | ***********************************************************************/ |
| 160 | typedef struct { |
| 161 | char *option; /* Valid option string (one option only) like "a:" */ |
| 162 | int *flag; /* pointer to location to set true if option given */ |
| 163 | char **arg; /* pointer to location to place argument, if needed */ |
| 164 | } option_t; |
| 165 | |
| 166 | /*********************************************************************** |
| 167 | * The following globals are defined in parse_opts.c but must be |
| 168 | * externed here because they are used in the macros defined below. |
| 169 | ***********************************************************************/ |
| 170 | extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */ |
| 171 | STD_TIMING_ON, /* turned on by -t to print timing stats */ |
| 172 | STD_PAUSE, /* turned on by -p to pause before loop */ |
| 173 | STD_INFINITE, /* turned on by -c0 to loop forever */ |
| 174 | STD_LOOP_COUNT, /* changed by -cn to set loop count to n */ |
| 175 | STD_ERRNO_LOG, /* turned on by -e to log errnos returned */ |
| 176 | STD_ERRNO_LIST[], /* counts of errnos returned. indexed by errno */ |
| 177 | STD_COPIES, |
| 178 | STD_argind; |
| 179 | |
| 180 | extern float STD_LOOP_DURATION, /* wall clock time to iterate */ |
| 181 | STD_LOOP_DELAY; /* delay time after each iteration */ |
| 182 | |
| 183 | #define USC_MAX_ERRNO 2000 |
| 184 | |
| 185 | /********************************************************************** |
| 186 | * Prototype for parse_opts routine |
| 187 | **********************************************************************/ |
| 188 | extern char *parse_opts(); |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 189 | extern void STD_set_user_help(void (*uhf)()); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * define a structure |
| 193 | */ |
| 194 | struct usc_errno_t { |
| 195 | int flag; |
| 196 | }; |
| 197 | |
| 198 | /*********************************************************************** |
| 199 | **** |
| 200 | **** |
| 201 | **** |
| 202 | **********************************************************************/ |
| 203 | #ifdef _USC_LIB_ |
| 204 | |
| 205 | extern int TEST_RETURN; |
| 206 | extern int TEST_ERRNO; |
| 207 | |
| 208 | #else |
| 209 | /*********************************************************************** |
| 210 | * Global array of bit masks to indicate errnos that are expected. |
| 211 | * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro. |
| 212 | ***********************************************************************/ |
| 213 | struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO]; |
| 214 | |
| 215 | /*********************************************************************** |
| 216 | * Globals for returning the return code and errno from the system call |
| 217 | * test macros. |
| 218 | ***********************************************************************/ |
| 219 | int TEST_RETURN; |
| 220 | int TEST_ERRNO; |
| 221 | |
| 222 | /*********************************************************************** |
| 223 | * temporary variables for determining max and min times in TEST macro |
| 224 | ***********************************************************************/ |
| 225 | long btime, etime, tmptime; |
| 226 | |
| 227 | #endif /* _USC_LIB_ */ |
| 228 | |
| 229 | /*********************************************************************** |
| 230 | * structure for timing accumulator and counters |
| 231 | ***********************************************************************/ |
| 232 | struct tblock { |
| 233 | long tb_max; |
| 234 | long tb_min; |
| 235 | long tb_total; |
| 236 | long tb_count; |
| 237 | }; |
| 238 | |
| 239 | /*********************************************************************** |
| 240 | * The following globals are externed here so that they are accessable |
| 241 | * in the macros that follow. |
| 242 | ***********************************************************************/ |
| 243 | extern struct tblock tblock; |
| 244 | extern void STD_go(); |
| 245 | extern int (*_TMP_FUNC)(void); |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 246 | extern void STD_opts_help(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 247 | |
| 248 | |
| 249 | /*********************************************************************** |
| 250 | * TEST: calls a system call |
| 251 | * |
| 252 | * parameters: |
| 253 | * SCALL = system call and parameters to execute |
| 254 | * |
| 255 | ***********************************************************************/ |
| 256 | #define TEST(SCALL) TEST_RETURN = (unsigned) SCALL; TEST_ERRNO=errno; |
| 257 | |
| 258 | /*********************************************************************** |
| 259 | * TEST_VOID: calls a system call |
| 260 | * |
| 261 | * parameters: |
| 262 | * SCALL = system call and parameters to execute |
| 263 | * |
| 264 | * Note: This is IDENTICAL to the TEST() macro except that it is intended |
| 265 | * for use with syscalls returning no values (void syscall()). The |
| 266 | * Typecasting nothing (void) into an unsigned integer causes compilation |
| 267 | * errors. |
| 268 | * |
| 269 | ***********************************************************************/ |
| 270 | #define TEST_VOID(SCALL) SCALL; TEST_ERRNO=errno; |
| 271 | |
| 272 | /*********************************************************************** |
| 273 | * TEST_CLEANUP: print system call timing stats and errno log entries |
| 274 | * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively. |
| 275 | * Do NOT print ANY information if no system calls logged. |
| 276 | * |
| 277 | * parameters: |
| 278 | * none |
| 279 | * |
| 280 | ***********************************************************************/ |
| 281 | #define TEST_CLEANUP \ |
| 282 | if ( STD_ERRNO_LOG ) { \ |
| 283 | for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) { \ |
| 284 | if ( STD_ERRNO_LIST[tmptime] ) { \ |
| 285 | if ( TEST_VALID_ENO[tmptime].flag ) \ |
| 286 | tst_resm(TINFO, "ERRNO %d:\tReceived %d Times", \ |
| 287 | tmptime, STD_ERRNO_LIST[tmptime]); \ |
| 288 | else \ |
| 289 | tst_resm(TINFO, \ |
| 290 | "ERRNO %d:\tReceived %d Times ** UNEXPECTED **", \ |
| 291 | tmptime, STD_ERRNO_LIST[tmptime]); \ |
| 292 | } \ |
| 293 | } \ |
| 294 | } |
| 295 | |
| 296 | /*********************************************************************** |
| 297 | * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set. |
| 298 | * Set the user specified function as the interrupt |
| 299 | * handler instead of "STD_go" |
| 300 | * |
| 301 | * parameters: |
| 302 | * none |
| 303 | * |
| 304 | ***********************************************************************/ |
| 305 | #define TEST_PAUSEF(HANDLER) \ |
| 306 | if ( STD_PAUSE ) { \ |
| 307 | _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER); \ |
| 308 | pause(); \ |
| 309 | signal(SIGUSR1, (void (*)())_TMP_FUNC); \ |
| 310 | } |
| 311 | |
| 312 | /*********************************************************************** |
| 313 | * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set. |
| 314 | * Just continue when signal comes in. |
| 315 | * |
| 316 | * parameters: |
| 317 | * none |
| 318 | * |
| 319 | ***********************************************************************/ |
| 320 | #define TEST_PAUSE usc_global_setup_hook(); |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 321 | int usc_global_setup_hook(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 322 | |
| 323 | /*********************************************************************** |
| 324 | * TEST_LOOPING now call the usc_test_looping function. |
| 325 | * The function will return 1 if the test should continue |
| 326 | * iterating. |
| 327 | * |
| 328 | ***********************************************************************/ |
| 329 | #define TEST_LOOPING usc_test_looping |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame^] | 330 | int usc_test_looping(int counter); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 331 | |
| 332 | /*********************************************************************** |
| 333 | * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set |
| 334 | * |
| 335 | * parameters: |
| 336 | * int eno: the errno location in STD_ERRNO_LIST to log. |
| 337 | * |
| 338 | ***********************************************************************/ |
| 339 | #define TEST_ERROR_LOG(eno) \ |
| 340 | if ( STD_ERRNO_LOG ) \ |
| 341 | if ( eno < USC_MAX_ERRNO ) \ |
| 342 | STD_ERRNO_LIST[eno]++; \ |
| 343 | |
| 344 | |
| 345 | /*********************************************************************** |
| 346 | * TEST_EXP_ENOS(array): set the bits associated with the nput errnos |
| 347 | * in the TEST_VALID_ENO array. |
| 348 | * |
| 349 | * parameters: |
| 350 | * int array[]: a zero terminated array of errnos expected. |
| 351 | * |
| 352 | ***********************************************************************/ |
| 353 | #define TEST_EXP_ENOS(array) \ |
| 354 | tmptime=0; \ |
| 355 | while (array[tmptime] != 0) { \ |
| 356 | if (array[tmptime] < USC_MAX_ERRNO) \ |
| 357 | TEST_VALID_ENO[array[tmptime]].flag=1; \ |
| 358 | tmptime++; \ |
| 359 | } |
| 360 | |
| 361 | |
| 362 | #endif /* end of __USCTEST_H__ */ |