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 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 33 | /* $Id: parse_opts.c,v 1.8 2005/07/11 22:28:09 robbiew Exp $ */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 34 | |
| 35 | /********************************************************** |
| 36 | * |
| 37 | * OS Testing - Silicon Graphics, Inc. |
| 38 | * |
| 39 | * FUNCTION NAME : parse_opts |
| 40 | * |
| 41 | * FUNCTION TITLE : parse standard & user options for system call tests |
| 42 | * |
| 43 | * SYNOPSIS: |
| 44 | * #include "usctest.h" |
| 45 | * |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 46 | * char *parse_opts(ac, av, user_optarr, uhf) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 47 | * int ac; |
| 48 | * char **av; |
| 49 | * option_t user_optarr[]; |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 50 | * void (*uhf)(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 51 | * |
| 52 | * AUTHOR : William Roske/Richard Logan |
| 53 | * |
| 54 | * INITIAL RELEASE : UNICOS 7.0 |
| 55 | * |
| 56 | * DESCRIPTION |
| 57 | * The parse_opts library routine takes that argc and argv parameters |
| 58 | * recevied by main() and an array of structures defining user options. |
| 59 | * It parses the command line setting flag and argument locations |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 60 | * associated with the options. It uses getopt to do the actual cmd line |
| 61 | * parsing. uhf() is a function to print user define help |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 62 | * |
| 63 | * This module contains the functions usc_global_setup_hook and |
| 64 | * usc_test_looping, which are called by marcos defined in usctest.h. |
| 65 | * |
| 66 | * RETURN VALUE |
| 67 | * parse_opts returns a pointer to an error message if an error occurs. |
| 68 | * This pointer is (char *)NULL if parsing is successful. |
| 69 | * |
| 70 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 71 | #include <errno.h> |
| 72 | #include <stdlib.h> |
| 73 | #include <string.h> |
| 74 | #include <sys/param.h> |
| 75 | #include <sys/signal.h> |
| 76 | #include <sys/types.h> |
| 77 | #include <unistd.h> |
| 78 | #include <sys/time.h> |
| 79 | |
| 80 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 81 | #if UNIT_TEST |
| 82 | #include <time.h> |
| 83 | #endif /* UNIT_TEST */ |
| 84 | |
| 85 | #include "test.h" |
| 86 | #define _USC_LIB_ 1 /* indicates we are the library to the usctest.h include */ |
| 87 | #include "usctest.h" |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 88 | |
| 89 | #ifndef USC_COPIES |
| 90 | #define USC_COPIES "USC_COPIES" |
| 91 | #endif |
| 92 | |
| 93 | #ifndef UNIT_TEST |
| 94 | #define UNIT_TEST 0 |
| 95 | #endif |
| 96 | |
| 97 | #ifndef DEBUG |
| 98 | #define DEBUG 0 |
| 99 | #endif |
| 100 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 101 | /* The timing information block. */ |
| 102 | struct tblock tblock={0,((long) -1)>>1,0,0}; |
| 103 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 104 | |
| 105 | /* Define flags and args for standard options */ |
| 106 | int STD_FUNCTIONAL_TEST=1, /* flag indicating to do functional testing code */ |
| 107 | STD_TIMING_ON=0, /* flag indicating to print timing stats */ |
| 108 | STD_PAUSE=0, /* flag indicating to pause before actual start, */ |
| 109 | /* for contention mode */ |
| 110 | STD_INFINITE=0, /* flag indciating to loop forever */ |
| 111 | STD_LOOP_COUNT=1, /* number of iterations */ |
| 112 | STD_COPIES=1, /* number of copies */ |
| 113 | STD_ERRNO_LOG=0; /* flag indicating to do errno logging */ |
| 114 | |
| 115 | float STD_LOOP_DURATION=0.0, /* duration value in fractional seconds */ |
| 116 | STD_LOOP_DELAY=0.0; /* loop delay value in fractional seconds */ |
| 117 | |
| 118 | |
| 119 | char **STD_opt_arr = NULL; /* array of option strings */ |
| 120 | int STD_nopts=0, /* number of elements in STD_opt_arr */ |
| 121 | STD_argind=1; /* argv index to next argv element */ |
| 122 | /* (first argument) */ |
| 123 | /* To getopt users, it is like optind */ |
| 124 | |
| 125 | /* |
| 126 | * The following variables are to support system testing additions. |
| 127 | */ |
| 128 | static int STD_TP_barrier=0; /* flag to do barrier in TEST_PAUSE */ |
| 129 | /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */ |
| 130 | static int STD_LP_barrier=0; /* flag to do barrier in TEST_LOOPING */ |
| 131 | /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */ |
| 132 | static int STD_TP_shmem_sz=0; /* shmalloc this many words per pe in TEST_PAUSE */ |
| 133 | static int STD_LD_shmem=0; /* flag to do shmem_puts and shmem_gets during delay */ |
| 134 | static int STD_LP_shmem=0; /* flag to do shmem_puts and gets during TEST_LOOPING */ |
| 135 | static int STD_LD_recfun=0; /* do recressive function calls in loop delay */ |
| 136 | static int STD_LP_recfun=0; /* do recressive function calls in TEST_LOOPING */ |
| 137 | static int STD_TP_sbrk=0; /* do sbrk in TEST_PAUSE */ |
| 138 | static int STD_LP_sbrk=0; /* do sbrk in TEST_LOOPING */ |
| 139 | static char *STD_start_break=0; /* original sbrk size */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 140 | static int Debug=0; |
| 141 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 142 | struct std_option_t { |
| 143 | char *optstr; |
| 144 | char *help; |
| 145 | char *flag; |
| 146 | char **arg; |
| 147 | } std_options[] = { |
nstraz | def354d | 2000-08-31 18:40:28 +0000 | [diff] [blame] | 148 | { "c:", " -c n Run n copies concurrently\n", NULL, NULL}, |
| 149 | { "e" , " -e Turn on errno logging\n", NULL, NULL}, |
| 150 | { "f" , " -f Turn off functional testing\n", NULL, NULL}, |
| 151 | { "h" , " -h Show this help screen\n", NULL, NULL}, |
| 152 | { "i:", " -i n Execute test n times\n", NULL, NULL}, |
| 153 | { "I:", " -I x Execute test for x seconds\n", NULL, NULL}, |
| 154 | { "p" , " -p Pause for SIGUSR1 before starting\n", NULL, NULL}, |
| 155 | { "P:", " -P x Pause for x seconds between iterations\n", NULL, NULL}, |
| 156 | { "t" , " -t Turn on syscall timing\n", NULL, NULL}, |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 157 | #ifdef UCLINUX |
| 158 | { "C:", " -C ARG Run the child process with arguments ARG (for internal use)\n", |
| 159 | NULL, NULL}, |
| 160 | #endif |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 161 | {NULL, NULL, NULL, NULL}}; |
| 162 | |
| 163 | void print_help(void (*user_help)()); |
| 164 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 165 | /* |
| 166 | * Structure for usc_recressive_func argument |
| 167 | */ |
| 168 | struct usc_bigstack_t { |
| 169 | char space[4096]; |
| 170 | }; |
| 171 | |
| 172 | static struct usc_bigstack_t *STD_bigstack=NULL; |
| 173 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 174 | /* |
| 175 | * Counter of errnos returned (-e option). Indexed by errno. |
| 176 | * Make the array USC_MAX_ERRNO long. That is the first Fortran |
| 177 | * Lib errno. No syscall should return an errno that high. |
| 178 | */ |
| 179 | int STD_ERRNO_LIST[USC_MAX_ERRNO]; |
| 180 | |
| 181 | /* define the string length for Mesg and Mesg2 strings */ |
| 182 | #define STRLEN 2048 |
| 183 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 184 | static char Mesg2[STRLEN]; /* holds possible return string */ |
| 185 | static void usc_recressive_func(); |
| 186 | |
| 187 | /* |
| 188 | * Define bits for options that might have env variable default |
| 189 | */ |
| 190 | #define OPT_iteration 01 |
| 191 | #define OPT_nofunccheck 02 |
| 192 | #define OPT_duration 04 |
| 193 | #define OPT_delay 010 |
| 194 | #define OPT_copies 020 |
| 195 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 196 | #ifdef UCLINUX |
| 197 | /* Allocated and used in self_exec.c: */ |
| 198 | extern char *child_args; /* Arguments to child when -C is used */ |
| 199 | #endif |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 200 | |
| 201 | /********************************************************************** |
| 202 | * parse_opts: |
| 203 | **********************************************************************/ |
| 204 | char * |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 205 | parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)()) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 206 | { |
| 207 | int found; /* flag to indicate that an option specified was */ |
| 208 | /* found in the user's list */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 209 | int k; /* scratch integer for returns and short time usage */ |
| 210 | float ftmp; /* tmp float for parsing env variables */ |
| 211 | char *ptr; /* used in getting env variables */ |
| 212 | int options=0; /* no options specified */ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 213 | int optstrlen, i; |
| 214 | char *optionstr; |
| 215 | int opt; /* return of getopt */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 216 | |
| 217 | /* |
| 218 | * If not the first time this function is called, release the old STD_opt_arr |
| 219 | * vector. |
| 220 | */ |
| 221 | |
| 222 | if ( STD_opt_arr != NULL ) { |
| 223 | free(STD_opt_arr); |
| 224 | STD_opt_arr=NULL; |
| 225 | } |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 226 | /* Calculate how much space we need for the option string */ |
| 227 | optstrlen = 0; |
| 228 | for (i = 0; std_options[i].optstr; ++i) |
| 229 | optstrlen += strlen(std_options[i].optstr); |
| 230 | if (user_optarr) |
| 231 | for (i = 0; user_optarr[i].option; ++i) { |
| 232 | if (strlen(user_optarr[i].option) > 2) |
| 233 | return "parse_opts: ERROR - Only short options are allowed"; |
| 234 | optstrlen += strlen(user_optarr[i].option); |
| 235 | } |
| 236 | optstrlen += 1; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 237 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 238 | /* Create the option string for getopt */ |
| 239 | optionstr = (char *)malloc(optstrlen); |
| 240 | if (!optionstr) |
| 241 | return "parse_opts: ERROR - Could not allocate memory for optionstr"; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 242 | |
nstraz | 829b40a | 2000-09-06 14:33:29 +0000 | [diff] [blame] | 243 | optionstr[0] = '\0'; |
| 244 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 245 | for (i = 0; std_options[i].optstr; ++i) |
| 246 | strcat(optionstr, std_options[i].optstr); |
| 247 | if (user_optarr) |
| 248 | for (i = 0; user_optarr[i].option; ++i) |
| 249 | /* only add the option if it wasn't there already */ |
| 250 | if (strchr(optionstr, user_optarr[i].option[0]) == NULL) |
| 251 | strcat(optionstr, user_optarr[i].option); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 252 | |
| 253 | #if DEBUG > 1 |
| 254 | printf("STD_nopts = %d\n", STD_nopts); |
| 255 | #endif |
| 256 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Loop through av parsing options. |
| 259 | */ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 260 | while ( (opt = getopt(ac, av, optionstr)) > 0) { |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 261 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 262 | STD_argind = optind; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 263 | #if DEBUG > 0 |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 264 | printf("parse_opts: getopt returned '%c'\n", opt); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 265 | #endif |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 266 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 267 | switch (opt) { |
| 268 | case '?': /* Unknown option */ |
| 269 | return "Unknown option"; |
| 270 | break; |
| 271 | case ':': /* Missing Arg */ |
| 272 | return "Missing argument"; |
| 273 | break; |
| 274 | case 'i': /* Iterations */ |
| 275 | options |= OPT_iteration; |
| 276 | STD_LOOP_COUNT = atoi(optarg); |
| 277 | if (STD_LOOP_COUNT == 0) STD_INFINITE = 1; |
| 278 | break; |
| 279 | case 'P': /* Delay between iterations */ |
| 280 | options |= OPT_delay; |
| 281 | STD_LOOP_DELAY = atof(optarg); |
| 282 | break; |
| 283 | case 'I': /* Time duration */ |
| 284 | options |= OPT_duration; |
| 285 | STD_LOOP_DURATION = atof(optarg); |
| 286 | if ( STD_LOOP_DURATION == 0.0 ) STD_INFINITE=1; |
| 287 | break; |
| 288 | case 'c': /* Copies */ |
| 289 | options |= OPT_copies; |
| 290 | STD_COPIES = atoi(optarg); |
| 291 | break; |
| 292 | case 'f': /* Functional testing */ |
| 293 | STD_FUNCTIONAL_TEST = 0; |
| 294 | break; |
| 295 | case 'p': /* Pause for SIGUSR1 */ |
| 296 | STD_PAUSE = 1; |
| 297 | break; |
| 298 | case 't': /* syscall timing */ |
| 299 | STD_TIMING_ON = 1; |
| 300 | break; |
| 301 | case 'e': /* errno loggin */ |
| 302 | STD_ERRNO_LOG = 1; |
| 303 | break; |
| 304 | case 'h': /* Help */ |
| 305 | print_help(uhf); |
| 306 | exit(0); |
| 307 | break; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 308 | #ifdef UCLINUX |
| 309 | case 'C': /* Run child */ |
| 310 | child_args = optarg; |
| 311 | break; |
| 312 | #endif |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 313 | default: |
| 314 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 315 | /* Check all the user specified options */ |
| 316 | found=0; |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 317 | for(i = 0; user_optarr[i].option; ++i) { |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 318 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 319 | if (opt == user_optarr[i].option[0]) { |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 320 | /* Yup, This is a user option, set the flag and look for argument */ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 321 | if ( user_optarr[i].flag ) { |
| 322 | *user_optarr[i].flag=1; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 323 | } |
| 324 | found++; |
| 325 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 326 | /* save the argument at the user's location */ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 327 | if ( user_optarr[i].option[strlen(user_optarr[i].option)-1] == ':' ) { |
| 328 | *user_optarr[i].arg=optarg; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 329 | } |
| 330 | break; /* option found - break out of the for loop */ |
| 331 | } |
| 332 | } |
| 333 | /* This condition "should never happen". SO CHECK FOR IT!!!! */ |
| 334 | if ( ! found ) { |
| 335 | sprintf(Mesg2, |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 336 | "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL ERROR", opt); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 337 | return(Mesg2); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | } /* end of while */ |
robbiew | 0ea4e1b | 2004-01-05 21:12:51 +0000 | [diff] [blame] | 342 | free(optionstr); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 343 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 344 | STD_argind = optind; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 345 | |
| 346 | /* |
| 347 | * Turn on debug |
| 348 | */ |
| 349 | if ( (ptr=getenv("USC_DEBUG")) != NULL ) { |
| 350 | Debug=1; |
| 351 | printf("env USC_DEBUG is defined, turning on debug\n"); |
| 352 | } |
| 353 | if ( (ptr=getenv("USC_VERBOSE")) != NULL ) { |
| 354 | Debug=1; |
| 355 | printf("env USC_VERBOSE is defined, turning on debug\n"); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * If the USC_ITERATION_ENV environmental variable is set to |
| 360 | * a number, use that number as iteration count (same as -c option). |
| 361 | * The -c option with arg will be used even if this env var is set. |
| 362 | */ |
| 363 | if ( !(options & OPT_iteration) && (ptr=getenv(USC_ITERATION_ENV)) != NULL ) { |
| 364 | if ( sscanf(ptr, "%i", &k) == 1) { |
| 365 | if ( k == 0 ) { /* if arg is 0, set infinite loop flag */ |
| 366 | STD_INFINITE=1; |
| 367 | if ( Debug ) |
| 368 | printf("Using env %s, set STD_INFINITE to 1\n", |
| 369 | USC_ITERATION_ENV); |
| 370 | } else { /* else, set the loop count to the arguement */ |
| 371 | STD_LOOP_COUNT=k; |
| 372 | if ( Debug ) |
| 373 | printf("Using env %s, set STD_LOOP_COUNT to %d\n", |
| 374 | USC_ITERATION_ENV, k); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * If the USC_NO_FUNC_CHECK environmental variable is set, we'll |
| 381 | * unset the STD_FUNCTIONAL_TEST variable. |
| 382 | */ |
| 383 | if ( !(options & OPT_nofunccheck) && (ptr=getenv(USC_NO_FUNC_CHECK)) != NULL ) { |
| 384 | STD_FUNCTIONAL_TEST=0; /* Turn off functional testing */ |
| 385 | if ( Debug ) |
| 386 | printf("Using env %s, set STD_FUNCTIONAL_TEST to 0\n", |
| 387 | USC_NO_FUNC_CHECK); |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * If the USC_LOOP_WALLTIME environmental variable is set, |
| 392 | * use that number as duration (same as -I option). |
| 393 | * The -I option with arg will be used even if this env var is set. |
| 394 | */ |
| 395 | |
| 396 | if ( !(options & OPT_duration) && (ptr=getenv(USC_LOOP_WALLTIME)) != NULL ) { |
| 397 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 398 | STD_LOOP_DURATION=ftmp; |
| 399 | if ( Debug ) |
| 400 | printf("Using env %s, set STD_LOOP_DURATION to %f\n", |
| 401 | USC_LOOP_WALLTIME, ftmp); |
| 402 | if ( STD_LOOP_DURATION == 0.0 ) { /* if arg is 0, set infinite loop flag */ |
| 403 | STD_INFINITE=1; |
| 404 | if ( Debug ) |
| 405 | printf("Using env %s, set STD_INFINITE to 1\n", USC_LOOP_WALLTIME); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | if ( !(options & OPT_duration) && (ptr=getenv("USC_DURATION")) != NULL ) { |
| 410 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 411 | STD_LOOP_DURATION=ftmp; |
| 412 | if ( Debug ) |
| 413 | printf("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n", ftmp); |
| 414 | if ( STD_LOOP_DURATION == 0.0 ) { /* if arg is 0, set infinite loop flag */ |
| 415 | STD_INFINITE=1; |
| 416 | if ( Debug ) |
| 417 | printf("Using env USC_DURATION, set STD_INFINITE to 1\n"); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | /* |
| 422 | * If the USC_LOOP_DELAY environmental variable is set, |
| 423 | * use that number as delay in factional seconds (same as -P option). |
| 424 | * The -P option with arg will be used even if this env var is set. |
| 425 | */ |
| 426 | if ( !(options & OPT_delay) && (ptr=getenv(USC_LOOP_DELAY)) != NULL ) { |
| 427 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 428 | STD_LOOP_DELAY=ftmp; |
| 429 | if ( Debug ) |
| 430 | printf("Using env %s, set STD_LOOP_DELAY = %f\n", |
| 431 | USC_LOOP_DELAY, ftmp); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * If the USC_COPIES environmental variable is set, |
| 437 | * use that number as copies (same as -c option). |
| 438 | * The -c option with arg will be used even if this env var is set. |
| 439 | */ |
| 440 | if ( !(options & OPT_copies) && (ptr=getenv(USC_COPIES)) != NULL ) { |
| 441 | if ( sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0 ) { |
| 442 | if ( Debug ) |
| 443 | printf("Using env %s, set STD_COPIES = %d\n", |
| 444 | USC_COPIES, STD_COPIES); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * The following are special system testing envs to turn on special |
| 450 | * hooks in the code. |
| 451 | */ |
| 452 | if ( (ptr=getenv("USC_TP_BARRIER")) != NULL ) { |
| 453 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 454 | STD_TP_barrier=k; |
| 455 | } |
| 456 | else |
| 457 | STD_TP_barrier=1; |
| 458 | if ( Debug ) |
| 459 | printf("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n", |
| 460 | STD_TP_barrier); |
| 461 | } |
| 462 | |
| 463 | if ( (ptr=getenv("USC_LP_BARRIER")) != NULL ) { |
| 464 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 465 | STD_LP_barrier=k; |
| 466 | } |
| 467 | else |
| 468 | STD_LP_barrier=1; |
| 469 | if ( Debug ) |
| 470 | printf("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n", |
| 471 | STD_LP_barrier); |
| 472 | } |
| 473 | |
| 474 | if ( (ptr=getenv("USC_TP_SHMEM")) != NULL ) { |
| 475 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 476 | STD_TP_shmem_sz=k; |
| 477 | if ( Debug ) |
| 478 | printf("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n", |
| 479 | STD_TP_shmem_sz); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if ( (ptr=getenv("USC_LP_SHMEM")) != NULL ) { |
| 484 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 485 | STD_LP_shmem=k; |
| 486 | if ( Debug ) |
| 487 | printf("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n", |
| 488 | STD_LP_shmem); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | if ( (ptr=getenv("USC_LD_SHMEM")) != NULL ) { |
| 493 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 494 | STD_LD_shmem=k; |
| 495 | if ( Debug ) |
| 496 | printf("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n", |
| 497 | STD_LD_shmem); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | if ( (ptr=getenv("USC_TP_SBRK")) != NULL ) { |
| 502 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 503 | STD_TP_sbrk=k; |
| 504 | if ( Debug ) |
| 505 | printf("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n", |
| 506 | STD_TP_sbrk); |
| 507 | } |
| 508 | } |
| 509 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 510 | #if !defined(UCLINUX) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 511 | if ( (ptr=getenv("USC_LP_SBRK")) != NULL ) { |
| 512 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 513 | STD_LP_sbrk=k; |
| 514 | if ( Debug ) |
| 515 | printf("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n", |
| 516 | STD_LP_sbrk); |
| 517 | } |
| 518 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 519 | #endif /* if !defined(UCLINUX) */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 520 | |
| 521 | if ( (ptr=getenv("USC_LP_RECFUN")) != NULL ) { |
| 522 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 523 | STD_LP_recfun=k; |
| 524 | if ( STD_bigstack != (struct usc_bigstack_t *)NULL ) |
| 525 | STD_bigstack=(struct usc_bigstack_t *) |
| 526 | malloc(sizeof(struct usc_bigstack_t)); |
| 527 | if ( Debug ) |
| 528 | printf("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n", |
| 529 | STD_LP_recfun); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if ( (ptr=getenv("USC_LD_RECFUN")) != NULL ) { |
| 534 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 535 | STD_LD_recfun=k; |
| 536 | if ( STD_bigstack != (struct usc_bigstack_t *)NULL ) |
| 537 | STD_bigstack=(struct usc_bigstack_t *) |
| 538 | malloc(sizeof(struct usc_bigstack_t)); |
| 539 | if ( Debug ) |
| 540 | printf("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n", |
| 541 | STD_LD_recfun); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | #if UNIT_TEST |
| 546 | printf("The following variables after option and env parsing:\n"); |
| 547 | printf("STD_FUNCTIONAL_TEST = %d\n", STD_FUNCTIONAL_TEST); |
| 548 | printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION); |
| 549 | printf("STD_LOOP_DELAY = %f\n", STD_LOOP_DELAY); |
| 550 | printf("STD_COPIES = %d\n", STD_COPIES); |
| 551 | printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT); |
| 552 | printf("STD_INFINITE = %d\n", STD_INFINITE); |
| 553 | printf("STD_TIMING_ON = %d\n", STD_TIMING_ON); |
| 554 | printf("STD_ERRNO_LOG = %d\n", STD_ERRNO_LOG); |
| 555 | printf("STD_PAUSE = %d\n", STD_PAUSE); |
| 556 | #endif |
| 557 | |
| 558 | return((char *) NULL); |
| 559 | |
| 560 | } /* end of parse_opts */ |
| 561 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 562 | /********************************************************************* |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 563 | * print_help() - print help message and user help message |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 564 | *********************************************************************/ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 565 | void print_help(void (*user_help)()) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 566 | { |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 567 | STD_opts_help(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 568 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 569 | if (user_help) user_help(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /********************************************************************* |
| 573 | * STD_opts_help() - return a help string for the STD_OPTIONS. |
| 574 | *********************************************************************/ |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 575 | void |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 576 | STD_opts_help() |
| 577 | { |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 578 | int i; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 579 | |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 580 | for(i = 0; std_options[i].optstr; ++i) { |
| 581 | if (std_options[i].help) |
| 582 | printf(std_options[i].help); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 583 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* |
| 587 | * routine to goto when we get the SIGUSR1 for STD_PAUSE |
| 588 | */ |
| 589 | void STD_go(int sig) |
| 590 | { |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | /*********************************************************************** |
| 595 | * This function will do desired end of global setup test |
| 596 | * hooks. |
| 597 | * Currently it will only do a pause waiting for sigusr1 if |
| 598 | * STD_PAUSE is set. |
| 599 | * |
| 600 | ***********************************************************************/ |
| 601 | int |
| 602 | usc_global_setup_hook() |
| 603 | { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 604 | #ifndef UCLINUX |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 605 | int cnt; |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 606 | /* temp variable to store old signal action to be restored after pause */ |
| 607 | int (*_TMP_FUNC)(void); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * Fork STD_COPIES-1 copies. |
| 611 | */ |
| 612 | for(cnt=1;cnt<STD_COPIES;cnt++) { |
| 613 | switch(fork() ) { |
| 614 | case -1: |
| 615 | fprintf(stderr, "%s: fork() failed, errno:%d %s\n", |
| 616 | __FILE__, errno, strerror(errno)); |
| 617 | break; |
| 618 | case 0: /* child */ |
| 619 | cnt=STD_COPIES; /* to stop the forking */ |
| 620 | break; |
| 621 | |
| 622 | default: /* parent */ |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 627 | /* |
| 628 | * pause waiting for sigusr1. |
| 629 | */ |
| 630 | if ( STD_PAUSE ) { |
| 631 | _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go); |
| 632 | pause(); |
| 633 | signal(SIGUSR1, (void (*)())_TMP_FUNC); |
| 634 | } |
| 635 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 636 | #if !defined(UCLINUX) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 637 | |
| 638 | if ( STD_TP_sbrk || STD_LP_sbrk) { |
| 639 | STD_start_break=sbrk(0); /* get original sbreak size */ |
| 640 | } |
| 641 | |
| 642 | if ( STD_TP_sbrk ) { |
| 643 | sbrk(STD_TP_sbrk); |
| 644 | if ( Debug ) |
| 645 | printf("after sbrk(%d)\n", STD_TP_sbrk); |
| 646 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 647 | |
| 648 | #endif /* if !defined(UCLINUX) */ |
| 649 | #endif |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | #define USECS_PER_SEC 1000000 /* microseconds per second */ |
| 654 | |
| 655 | /*********************************************************************** |
| 656 | * This function returns the number of get_current_time()'s return |
| 657 | * per second. |
| 658 | ***********************************************************************/ |
| 659 | |
| 660 | static int |
| 661 | get_timepersec() |
| 662 | { |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 663 | return USECS_PER_SEC; /* microseconds per second */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 664 | |
| 665 | } |
| 666 | |
| 667 | /*********************************************************************** |
nstraz | 9418108 | 2000-08-30 18:43:38 +0000 | [diff] [blame] | 668 | * this function will get current time in microseconds since 1970. |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 669 | ***********************************************************************/ |
| 670 | static int |
| 671 | get_current_time() |
| 672 | { |
| 673 | struct timeval curtime; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 674 | |
| 675 | gettimeofday(&curtime, NULL); |
| 676 | |
| 677 | /* microseconds since 1970 */ |
| 678 | return (curtime.tv_sec*USECS_PER_SEC) + curtime.tv_usec; |
| 679 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 680 | |
| 681 | } |
| 682 | |
| 683 | /*********************************************************************** |
| 684 | * |
| 685 | * This function will determine if test should continue iterating |
| 686 | * If the STD_INFINITE flag is set, return 1. |
| 687 | * If the STD_LOOP_COUNT variable is set, compare it against |
| 688 | * the counter. |
| 689 | * If the STD_LOOP_DURATION variable is set, compare current time against |
| 690 | * calculated stop_time. |
| 691 | * This function will return 1 until all desired looping methods |
| 692 | * have been met. |
| 693 | * |
| 694 | * counter integer is supplied by the user program. |
| 695 | ***********************************************************************/ |
| 696 | int |
| 697 | usc_test_looping(counter) |
| 698 | int counter; |
| 699 | { |
| 700 | static int first_time = 1; |
| 701 | static int stop_time = 0; /* stop time in rtc or usecs */ |
| 702 | static int delay; /* delay in clocks or usecs */ |
mridge | e6508f8 | 2005-01-04 21:00:17 +0000 | [diff] [blame] | 703 | int hertz=0; /* clocks per second or usecs per second */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 704 | int ct, end; /* current time, end delay time */ |
| 705 | int keepgoing=0; /* used to determine return value */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 706 | |
| 707 | /* |
| 708 | * If this is the first iteration and we are looping for |
| 709 | * duration of STD_LOOP_DURATION seconds (fractional) or |
| 710 | * doing loop delays, get the clocks per second. |
| 711 | */ |
| 712 | if ( first_time ) { |
| 713 | |
| 714 | first_time=0; |
| 715 | if ( STD_LOOP_DELAY || STD_LOOP_DURATION ) { |
mridge | e6508f8 | 2005-01-04 21:00:17 +0000 | [diff] [blame] | 716 | hertz = get_timepersec(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /* |
| 720 | * If looping for duration, calculate stop time in |
| 721 | * clocks. |
| 722 | */ |
| 723 | |
| 724 | if ( STD_LOOP_DURATION) { |
| 725 | ct=get_current_time(); |
mridge | e6508f8 | 2005-01-04 21:00:17 +0000 | [diff] [blame] | 726 | stop_time=(int)((float)hertz * STD_LOOP_DURATION) + ct; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /* |
| 730 | * If doing delay each iteration, calcuate the number |
| 731 | * of clocks for each delay. |
| 732 | */ |
| 733 | if ( STD_LOOP_DELAY ) { |
mridge | e6508f8 | 2005-01-04 21:00:17 +0000 | [diff] [blame] | 734 | delay=(int)((float)hertz * STD_LOOP_DELAY); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * if delay each iteration, loop for delay clocks. |
| 741 | * This will not be done on first iteration. |
| 742 | * The delay will happen before determining if |
| 743 | * there will be another iteration. |
| 744 | */ |
| 745 | else if ( STD_LOOP_DELAY ) { |
| 746 | ct=get_current_time(); |
| 747 | end=ct+delay; |
| 748 | while ( ct < end ) { |
| 749 | /* |
| 750 | * The following are special test hooks in the delay loop. |
| 751 | */ |
| 752 | if ( STD_LD_recfun ) { |
| 753 | if ( Debug ) |
| 754 | printf("calling usc_recressive_func(0, %d, &STD_bigstack)\n", |
| 755 | STD_LD_recfun); |
| 756 | usc_recressive_func(0, STD_LD_recfun, &STD_bigstack); |
| 757 | } |
| 758 | |
| 759 | ct=get_current_time(); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | if ( STD_INFINITE ) { |
| 764 | keepgoing++; |
| 765 | } |
| 766 | |
| 767 | if ( STD_LOOP_COUNT && counter < STD_LOOP_COUNT ) { |
| 768 | keepgoing++; |
| 769 | } |
| 770 | |
| 771 | if ( STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time ) { |
| 772 | keepgoing++; |
| 773 | } |
| 774 | |
| 775 | if ( keepgoing == 0 ) |
| 776 | return 0; |
| 777 | |
| 778 | /* |
| 779 | * The following code allows special system testing hooks. |
| 780 | */ |
| 781 | |
| 782 | if ( STD_LP_recfun ) { |
| 783 | if ( Debug ) |
| 784 | printf("calling usc_recressive_func(0, %d, &STD_bigstack)\n", |
| 785 | STD_LP_recfun); |
| 786 | usc_recressive_func(0, STD_LP_recfun, &STD_bigstack); |
| 787 | } |
| 788 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 789 | #if !defined(UCLINUX) |
| 790 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 791 | if ( STD_LP_sbrk ) { |
| 792 | if ( Debug ) |
| 793 | printf("about to do sbrk(%d)\n", STD_LP_sbrk); |
| 794 | sbrk(STD_LP_sbrk); |
| 795 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame^] | 796 | #endif |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 797 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 798 | |
| 799 | if ( keepgoing ) |
| 800 | return 1; |
| 801 | else |
| 802 | return 0; /* done - stop iterating */ |
| 803 | } |
| 804 | |
| 805 | |
| 806 | /* |
| 807 | * This function recressively calls itself max times. |
| 808 | */ |
| 809 | static void |
| 810 | usc_recressive_func(cnt, max, bstack) |
| 811 | int cnt; |
| 812 | int max; |
| 813 | struct usc_bigstack_t bstack; |
| 814 | { |
| 815 | if ( cnt < max ) |
| 816 | usc_recressive_func(cnt+1, max, bstack); |
| 817 | |
| 818 | } |
| 819 | |
| 820 | #if UNIT_TEST |
| 821 | /****************************************************************************** |
| 822 | * UNIT TEST CODE |
| 823 | * UNIT TEST CODE |
| 824 | * |
| 825 | * this following code is provide so that unit testing can |
| 826 | * be done fairly easily. |
| 827 | ******************************************************************************/ |
| 828 | |
| 829 | int Help = 0; |
| 830 | int Help2 = 0; |
| 831 | char *ptr; |
| 832 | |
| 833 | /* |
| 834 | * Code from usctest.h that not part of this file since we are the library. |
| 835 | */ |
| 836 | |
| 837 | struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO]; |
| 838 | |
| 839 | /*********************************************************************** |
| 840 | * Globals for returning the return code and errno from the system call |
| 841 | * test macros. |
| 842 | ***********************************************************************/ |
| 843 | int TEST_RETURN; |
| 844 | int TEST_ERRNO; |
| 845 | |
| 846 | /*********************************************************************** |
| 847 | * temporary variables for determining max and min times in TEST macro |
| 848 | ***********************************************************************/ |
| 849 | long btime, etime, tmptime; |
| 850 | |
| 851 | |
| 852 | |
| 853 | /* for test specific parse_opts options */ |
| 854 | option_t Options[] = { |
| 855 | { "help", &Help2, NULL }, /* -help option */ |
| 856 | { "h", &Help, NULL }, /* -h option */ |
| 857 | { TIMING, NULL, NULL}, /* disable -timing option */ |
| 858 | |
| 859 | #if INVALID_TEST_CASES |
| 860 | { "missingflag", NULL, &ptr }, /* error */ |
| 861 | { "missingarg:", &Help, NULL }, /* error */ |
| 862 | #endif /* INVALID_TEST_CASES */ |
| 863 | |
| 864 | { NULL, NULL, NULL } |
| 865 | }; |
| 866 | |
| 867 | |
| 868 | main(argc, argv) |
| 869 | int argc; |
| 870 | char **argv; |
| 871 | { |
| 872 | int lc; |
| 873 | char *msg; |
| 874 | struct timeval t; |
| 875 | int cnt; |
| 876 | |
| 877 | if ( (msg=parse_opts(argc, argv, |
| 878 | (option_t *) Options)) != (char *) NULL ) { |
| 879 | printf("ERROR : %s\n", msg); |
| 880 | exit(1); |
| 881 | } |
| 882 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 883 | TEST_PAUSE; |
| 884 | |
| 885 | for (lc=0; TEST_LOOPING(lc); lc++) { |
| 886 | |
| 887 | TEST( gettimeofday(&t, NULL) ); |
| 888 | printf("iter=%d: sec:%d, usec:%6.6d %s", lc+1, t.tv_sec, |
| 889 | t.tv_usec, ctime(&t.tv_sec)); |
| 890 | } |
| 891 | |
| 892 | |
| 893 | TEST_CLEANUP; |
| 894 | |
| 895 | exit(0); |
| 896 | } |
| 897 | |
| 898 | #endif /* UNIT_TEST */ |