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 | |
vapier | b3691d7 | 2006-05-26 06:06:06 +0000 | [diff] [blame] | 33 | /* $Id: usctest.h,v 1.10 2006/05/26 06:06:06 vapier 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 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 112 | /*********************************************************************** |
| 113 | * Define option_t structure type. |
| 114 | * Entries in this struct are used by the parse_opts routine |
| 115 | * to indicate valid options and return option arguments |
| 116 | ***********************************************************************/ |
| 117 | typedef struct { |
| 118 | char *option; /* Valid option string (one option only) like "a:" */ |
| 119 | int *flag; /* pointer to location to set true if option given */ |
| 120 | char **arg; /* pointer to location to place argument, if needed */ |
| 121 | } option_t; |
| 122 | |
| 123 | /*********************************************************************** |
| 124 | * The following globals are defined in parse_opts.c but must be |
| 125 | * externed here because they are used in the macros defined below. |
| 126 | ***********************************************************************/ |
| 127 | extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */ |
| 128 | STD_TIMING_ON, /* turned on by -t to print timing stats */ |
| 129 | STD_PAUSE, /* turned on by -p to pause before loop */ |
nstraz | 829b40a | 2000-09-06 14:33:29 +0000 | [diff] [blame] | 130 | STD_INFINITE, /* turned on by -i0 to loop forever */ |
| 131 | STD_LOOP_COUNT, /* changed by -in to set loop count to n */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 132 | STD_ERRNO_LOG, /* turned on by -e to log errnos returned */ |
| 133 | STD_ERRNO_LIST[], /* counts of errnos returned. indexed by errno */ |
| 134 | STD_COPIES, |
| 135 | STD_argind; |
| 136 | |
| 137 | extern float STD_LOOP_DURATION, /* wall clock time to iterate */ |
| 138 | STD_LOOP_DELAY; /* delay time after each iteration */ |
| 139 | |
| 140 | #define USC_MAX_ERRNO 2000 |
| 141 | |
| 142 | /********************************************************************** |
| 143 | * Prototype for parse_opts routine |
| 144 | **********************************************************************/ |
nstraz | 6a91881 | 2000-08-31 19:20:35 +0000 | [diff] [blame] | 145 | extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)()); |
| 146 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * define a structure |
| 150 | */ |
| 151 | struct usc_errno_t { |
| 152 | int flag; |
| 153 | }; |
| 154 | |
| 155 | /*********************************************************************** |
| 156 | **** |
| 157 | **** |
| 158 | **** |
| 159 | **********************************************************************/ |
| 160 | #ifdef _USC_LIB_ |
| 161 | |
robbiew | 2e6837d | 2005-07-11 18:56:53 +0000 | [diff] [blame] | 162 | extern long TEST_RETURN; |
| 163 | extern long TEST_ERRNO; |
robbiew | 6eaecb2 | 2005-12-22 20:18:22 +0000 | [diff] [blame] | 164 | extern struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO]; |
| 165 | extern long btime, etime, tmptime; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 166 | |
| 167 | #else |
| 168 | /*********************************************************************** |
| 169 | * Global array of bit masks to indicate errnos that are expected. |
| 170 | * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro. |
| 171 | ***********************************************************************/ |
| 172 | struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO]; |
| 173 | |
| 174 | /*********************************************************************** |
| 175 | * Globals for returning the return code and errno from the system call |
| 176 | * test macros. |
| 177 | ***********************************************************************/ |
robbiew | 2e6837d | 2005-07-11 18:56:53 +0000 | [diff] [blame] | 178 | long TEST_RETURN; |
| 179 | long TEST_ERRNO; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 180 | |
| 181 | /*********************************************************************** |
| 182 | * temporary variables for determining max and min times in TEST macro |
| 183 | ***********************************************************************/ |
| 184 | long btime, etime, tmptime; |
| 185 | |
| 186 | #endif /* _USC_LIB_ */ |
| 187 | |
| 188 | /*********************************************************************** |
| 189 | * structure for timing accumulator and counters |
| 190 | ***********************************************************************/ |
| 191 | struct tblock { |
| 192 | long tb_max; |
| 193 | long tb_min; |
| 194 | long tb_total; |
| 195 | long tb_count; |
| 196 | }; |
| 197 | |
| 198 | /*********************************************************************** |
| 199 | * The following globals are externed here so that they are accessable |
| 200 | * in the macros that follow. |
| 201 | ***********************************************************************/ |
| 202 | extern struct tblock tblock; |
| 203 | extern void STD_go(); |
| 204 | extern int (*_TMP_FUNC)(void); |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 205 | extern void STD_opts_help(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 206 | |
| 207 | |
| 208 | /*********************************************************************** |
| 209 | * TEST: calls a system call |
| 210 | * |
| 211 | * parameters: |
| 212 | * SCALL = system call and parameters to execute |
| 213 | * |
| 214 | ***********************************************************************/ |
vapier | b3691d7 | 2006-05-26 06:06:06 +0000 | [diff] [blame] | 215 | #define TEST(SCALL) \ |
| 216 | do { \ |
| 217 | errno = 0; \ |
| 218 | TEST_RETURN = SCALL; \ |
| 219 | TEST_ERRNO = errno; \ |
| 220 | } while (0) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 221 | |
| 222 | /*********************************************************************** |
| 223 | * TEST_VOID: calls a system call |
| 224 | * |
| 225 | * parameters: |
| 226 | * SCALL = system call and parameters to execute |
| 227 | * |
| 228 | * Note: This is IDENTICAL to the TEST() macro except that it is intended |
| 229 | * for use with syscalls returning no values (void syscall()). The |
| 230 | * Typecasting nothing (void) into an unsigned integer causes compilation |
| 231 | * errors. |
| 232 | * |
| 233 | ***********************************************************************/ |
plars | 90b1698 | 2002-04-11 15:03:03 +0000 | [diff] [blame] | 234 | #define TEST_VOID(SCALL) errno=0; SCALL; TEST_ERRNO=errno; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 235 | |
| 236 | /*********************************************************************** |
| 237 | * TEST_CLEANUP: print system call timing stats and errno log entries |
| 238 | * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively. |
| 239 | * Do NOT print ANY information if no system calls logged. |
| 240 | * |
| 241 | * parameters: |
| 242 | * none |
| 243 | * |
| 244 | ***********************************************************************/ |
| 245 | #define TEST_CLEANUP \ |
| 246 | if ( STD_ERRNO_LOG ) { \ |
| 247 | for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) { \ |
| 248 | if ( STD_ERRNO_LIST[tmptime] ) { \ |
| 249 | if ( TEST_VALID_ENO[tmptime].flag ) \ |
| 250 | tst_resm(TINFO, "ERRNO %d:\tReceived %d Times", \ |
| 251 | tmptime, STD_ERRNO_LIST[tmptime]); \ |
| 252 | else \ |
| 253 | tst_resm(TINFO, \ |
| 254 | "ERRNO %d:\tReceived %d Times ** UNEXPECTED **", \ |
| 255 | tmptime, STD_ERRNO_LIST[tmptime]); \ |
| 256 | } \ |
| 257 | } \ |
| 258 | } |
| 259 | |
| 260 | /*********************************************************************** |
| 261 | * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set. |
| 262 | * Set the user specified function as the interrupt |
| 263 | * handler instead of "STD_go" |
| 264 | * |
| 265 | * parameters: |
| 266 | * none |
| 267 | * |
| 268 | ***********************************************************************/ |
| 269 | #define TEST_PAUSEF(HANDLER) \ |
| 270 | if ( STD_PAUSE ) { \ |
| 271 | _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER); \ |
| 272 | pause(); \ |
| 273 | signal(SIGUSR1, (void (*)())_TMP_FUNC); \ |
| 274 | } |
| 275 | |
| 276 | /*********************************************************************** |
| 277 | * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set. |
| 278 | * Just continue when signal comes in. |
| 279 | * |
| 280 | * parameters: |
| 281 | * none |
| 282 | * |
| 283 | ***********************************************************************/ |
| 284 | #define TEST_PAUSE usc_global_setup_hook(); |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 285 | int usc_global_setup_hook(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 286 | |
| 287 | /*********************************************************************** |
| 288 | * TEST_LOOPING now call the usc_test_looping function. |
| 289 | * The function will return 1 if the test should continue |
| 290 | * iterating. |
| 291 | * |
| 292 | ***********************************************************************/ |
| 293 | #define TEST_LOOPING usc_test_looping |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 294 | int usc_test_looping(int counter); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 295 | |
| 296 | /*********************************************************************** |
| 297 | * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set |
| 298 | * |
| 299 | * parameters: |
| 300 | * int eno: the errno location in STD_ERRNO_LIST to log. |
| 301 | * |
| 302 | ***********************************************************************/ |
| 303 | #define TEST_ERROR_LOG(eno) \ |
| 304 | if ( STD_ERRNO_LOG ) \ |
| 305 | if ( eno < USC_MAX_ERRNO ) \ |
| 306 | STD_ERRNO_LIST[eno]++; \ |
| 307 | |
| 308 | |
| 309 | /*********************************************************************** |
| 310 | * TEST_EXP_ENOS(array): set the bits associated with the nput errnos |
| 311 | * in the TEST_VALID_ENO array. |
| 312 | * |
| 313 | * parameters: |
| 314 | * int array[]: a zero terminated array of errnos expected. |
| 315 | * |
| 316 | ***********************************************************************/ |
| 317 | #define TEST_EXP_ENOS(array) \ |
| 318 | tmptime=0; \ |
| 319 | while (array[tmptime] != 0) { \ |
| 320 | if (array[tmptime] < USC_MAX_ERRNO) \ |
| 321 | TEST_VALID_ENO[array[tmptime]].flag=1; \ |
| 322 | tmptime++; \ |
| 323 | } |
| 324 | |
| 325 | |
| 326 | #endif /* end of __USCTEST_H__ */ |