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 | |
| 33 | /* $Id: parse_opts.c,v 1.1 2000/07/27 17:13:18 alaffin Exp $ */ |
| 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 | * |
| 46 | * char *parse_opts(ac, av, user_optarr) |
| 47 | * int ac; |
| 48 | * char **av; |
| 49 | * option_t user_optarr[]; |
| 50 | * |
| 51 | * AUTHOR : William Roske/Richard Logan |
| 52 | * |
| 53 | * INITIAL RELEASE : UNICOS 7.0 |
| 54 | * |
| 55 | * DESCRIPTION |
| 56 | * The parse_opts library routine takes that argc and argv parameters |
| 57 | * recevied by main() and an array of structures defining user options. |
| 58 | * It parses the command line setting flag and argument locations |
| 59 | * associated with the options. It uses mc_getoptv to do the actual |
| 60 | * cmd line parsing. |
| 61 | * |
| 62 | * This module contains the functions usc_global_setup_hook and |
| 63 | * usc_test_looping, which are called by marcos defined in usctest.h. |
| 64 | * |
| 65 | * RETURN VALUE |
| 66 | * parse_opts returns a pointer to an error message if an error occurs. |
| 67 | * This pointer is (char *)NULL if parsing is successful. |
| 68 | * |
| 69 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 70 | #include <errno.h> |
| 71 | #include <stdlib.h> |
| 72 | #include <string.h> |
| 73 | #include <sys/param.h> |
| 74 | #include <sys/signal.h> |
| 75 | #include <sys/types.h> |
| 76 | #include <unistd.h> |
| 77 | #include <sys/time.h> |
| 78 | |
| 79 | |
| 80 | #ifdef _CRAYMPP |
| 81 | #include <mpp/shmem.h> |
| 82 | #endif /* _CRAYMPP */ |
| 83 | |
| 84 | #if UNIT_TEST |
| 85 | #include <time.h> |
| 86 | #endif /* UNIT_TEST */ |
| 87 | |
| 88 | #include "test.h" |
| 89 | #define _USC_LIB_ 1 /* indicates we are the library to the usctest.h include */ |
| 90 | #include "usctest.h" |
| 91 | #include "mc_getopt.h" |
| 92 | |
| 93 | #ifndef USC_COPIES |
| 94 | #define USC_COPIES "USC_COPIES" |
| 95 | #endif |
| 96 | |
| 97 | #ifndef UNIT_TEST |
| 98 | #define UNIT_TEST 0 |
| 99 | #endif |
| 100 | |
| 101 | #ifndef DEBUG |
| 102 | #define DEBUG 0 |
| 103 | #endif |
| 104 | |
| 105 | #ifndef NULL |
| 106 | #define NULL 0 |
| 107 | #endif |
| 108 | |
| 109 | extern int errno; |
| 110 | |
| 111 | /* The timing information block. */ |
| 112 | struct tblock tblock={0,((long) -1)>>1,0,0}; |
| 113 | |
| 114 | /* temp variable to store old signal action to be restored after pause */ |
| 115 | int (*_TMP_FUNC)(void); |
| 116 | |
| 117 | /* Define flags and args for standard options */ |
| 118 | int STD_FUNCTIONAL_TEST=1, /* flag indicating to do functional testing code */ |
| 119 | STD_TIMING_ON=0, /* flag indicating to print timing stats */ |
| 120 | STD_PAUSE=0, /* flag indicating to pause before actual start, */ |
| 121 | /* for contention mode */ |
| 122 | STD_INFINITE=0, /* flag indciating to loop forever */ |
| 123 | STD_LOOP_COUNT=1, /* number of iterations */ |
| 124 | STD_COPIES=1, /* number of copies */ |
| 125 | STD_ERRNO_LOG=0; /* flag indicating to do errno logging */ |
| 126 | |
| 127 | float STD_LOOP_DURATION=0.0, /* duration value in fractional seconds */ |
| 128 | STD_LOOP_DELAY=0.0; /* loop delay value in fractional seconds */ |
| 129 | |
| 130 | |
| 131 | char **STD_opt_arr = NULL; /* array of option strings */ |
| 132 | int STD_nopts=0, /* number of elements in STD_opt_arr */ |
| 133 | STD_argind=1; /* argv index to next argv element */ |
| 134 | /* (first argument) */ |
| 135 | /* To getopt users, it is like optind */ |
| 136 | |
| 137 | /* |
| 138 | * The following variables are to support system testing additions. |
| 139 | */ |
| 140 | static int STD_TP_barrier=0; /* flag to do barrier in TEST_PAUSE */ |
| 141 | /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */ |
| 142 | static int STD_LP_barrier=0; /* flag to do barrier in TEST_LOOPING */ |
| 143 | /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */ |
| 144 | static int STD_TP_shmem_sz=0; /* shmalloc this many words per pe in TEST_PAUSE */ |
| 145 | static int STD_LD_shmem=0; /* flag to do shmem_puts and shmem_gets during delay */ |
| 146 | static int STD_LP_shmem=0; /* flag to do shmem_puts and gets during TEST_LOOPING */ |
| 147 | static int STD_LD_recfun=0; /* do recressive function calls in loop delay */ |
| 148 | static int STD_LP_recfun=0; /* do recressive function calls in TEST_LOOPING */ |
| 149 | static int STD_TP_sbrk=0; /* do sbrk in TEST_PAUSE */ |
| 150 | static int STD_LP_sbrk=0; /* do sbrk in TEST_LOOPING */ |
| 151 | static char *STD_start_break=0; /* original sbrk size */ |
| 152 | #ifdef _CRAYMPP |
| 153 | static long *STD_shmem=NULL; /* array of shmalloc space */ |
| 154 | static int MyPE=-1, Npe=-1; /* */ |
| 155 | #endif |
| 156 | static int Debug=0; |
| 157 | |
| 158 | /* |
| 159 | * Structure for usc_recressive_func argument |
| 160 | */ |
| 161 | struct usc_bigstack_t { |
| 162 | char space[4096]; |
| 163 | }; |
| 164 | |
| 165 | static struct usc_bigstack_t *STD_bigstack=NULL; |
| 166 | |
| 167 | static int add_option(char *option, char **opt_arr[], int *nopts); |
| 168 | static int rm_option(char *option, char **opt_arr[], int *nopts); |
| 169 | |
| 170 | |
| 171 | /* |
| 172 | * Counter of errnos returned (-e option). Indexed by errno. |
| 173 | * Make the array USC_MAX_ERRNO long. That is the first Fortran |
| 174 | * Lib errno. No syscall should return an errno that high. |
| 175 | */ |
| 176 | int STD_ERRNO_LIST[USC_MAX_ERRNO]; |
| 177 | |
| 178 | /* define the string length for Mesg and Mesg2 strings */ |
| 179 | #define STRLEN 2048 |
| 180 | |
| 181 | static char Mesg[STRLEN]; /* holds possible return string */ |
| 182 | static char Mesg2[STRLEN]; /* holds possible return string */ |
| 183 | static void usc_recressive_func(); |
| 184 | |
| 185 | /* |
| 186 | * Define bits for options that might have env variable default |
| 187 | */ |
| 188 | #define OPT_iteration 01 |
| 189 | #define OPT_nofunccheck 02 |
| 190 | #define OPT_duration 04 |
| 191 | #define OPT_delay 010 |
| 192 | #define OPT_copies 020 |
| 193 | |
| 194 | |
| 195 | /********************************************************************** |
| 196 | * parse_opts: |
| 197 | **********************************************************************/ |
| 198 | char * |
| 199 | parse_opts(int ac, char **av, option_t *user_optarr) |
| 200 | { |
| 201 | int found; /* flag to indicate that an option specified was */ |
| 202 | /* found in the user's list */ |
| 203 | char chr; /* used in converting option arguments */ |
| 204 | int k; /* scratch integer for returns and short time usage */ |
| 205 | float ftmp; /* tmp float for parsing env variables */ |
| 206 | char *ptr; /* used in getting env variables */ |
| 207 | int options=0; /* no options specified */ |
| 208 | int ind; /* index */ |
| 209 | int cnt; /* counter */ |
| 210 | int num; /* size of a string */ |
| 211 | char *opt; /* return of mc_getoptv */ |
| 212 | |
| 213 | /* |
| 214 | * If not the first time this function is called, release the old STD_opt_arr |
| 215 | * vector. |
| 216 | */ |
| 217 | |
| 218 | if ( STD_opt_arr != NULL ) { |
| 219 | free(STD_opt_arr); |
| 220 | STD_opt_arr=NULL; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Define standard options known to the parse_opts package. |
| 225 | * Each option is added to the end of the STD_opt_arr array. |
| 226 | */ |
| 227 | if ( add_option(ITERATIONS, &STD_opt_arr, &STD_nopts) == -1) |
| 228 | return Mesg2; |
| 229 | if ( add_option(DELAY, &STD_opt_arr, &STD_nopts) == -1 ) |
| 230 | return Mesg2; |
| 231 | if ( add_option(DURATION, &STD_opt_arr, &STD_nopts) == -1 ) |
| 232 | return Mesg2; |
| 233 | if ( add_option(NOFUNC, &STD_opt_arr, &STD_nopts) == -1 ) |
| 234 | return Mesg2; |
| 235 | if ( add_option(SETUP_PAUSE, &STD_opt_arr, &STD_nopts) == -1 ) |
| 236 | return Mesg2; |
| 237 | if ( add_option(COPIES, &STD_opt_arr, &STD_nopts) == -1 ) |
| 238 | return Mesg2; |
| 239 | if ( add_option(USC_HELP, &STD_opt_arr, &STD_nopts) == -1 ) |
| 240 | return Mesg2; |
| 241 | if ( add_option(TIMING, &STD_opt_arr, &STD_nopts) == -1 ) |
| 242 | return Mesg2; |
| 243 | if ( add_option(ERRNO_LOGGING, &STD_opt_arr, &STD_nopts) == -1 ) |
| 244 | return Mesg2; |
| 245 | |
| 246 | /* validate input array of options and build STD_opt_arr */ |
| 247 | |
| 248 | if ( user_optarr != (option_t *) NULL ) { |
| 249 | for(cnt=0; user_optarr[cnt].option != (char *) NULL; cnt++ ) { |
| 250 | /* |
| 251 | * Determine if user option already in STD_opt_arr. |
| 252 | * If the option is listed twice (in even numbers), it is disabled. |
| 253 | * To disable the option, remove it from the option from STD_opt_arr. |
| 254 | */ |
| 255 | for(ind=0; ind<STD_nopts; ind++) { |
| 256 | if (strcmp(user_optarr[cnt].option, STD_opt_arr[ind]) == 0 ) { |
| 257 | /* |
| 258 | * user option already in STD_opt_arry, which means to |
| 259 | * disable that option. Remove that option from STD_opt_arr. |
| 260 | */ |
| 261 | rm_option(user_optarr[cnt].option, &STD_opt_arr, &STD_nopts); |
| 262 | break; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * User's option is not already in STD_opt_arr so it needs to be |
| 268 | * added. |
| 269 | */ |
| 270 | if ( ind >= STD_nopts ) { |
| 271 | num=strlen(user_optarr[cnt].option); |
| 272 | |
| 273 | /* |
| 274 | * If the last character is ":", make sure arg pointer |
| 275 | * is not NULL. |
| 276 | */ |
| 277 | if ( user_optarr[cnt].option[num-1] == ':' ) { |
| 278 | |
| 279 | if ( user_optarr[cnt].arg == NULL ) { |
| 280 | sprintf(Mesg2, |
| 281 | "parse_opts: ERROR - option:\"%s\" expecting argument, NO POINTER GIVEN", |
| 282 | user_optarr[cnt].option); |
| 283 | return(Mesg2); |
| 284 | } |
| 285 | |
| 286 | } else { |
| 287 | /* |
| 288 | * The option does not require an argument, make sure |
| 289 | * user_optarr[cnt].flag is pointing to something. |
| 290 | * The flag is optional when argument is required. |
| 291 | */ |
| 292 | if ( user_optarr[cnt].flag == NULL ) { |
| 293 | sprintf(Mesg2, |
| 294 | "parse_opts: ERROR - option:\"%s\" NO FLAG LOCATION GIVEN", |
| 295 | user_optarr[cnt].option); |
| 296 | return(Mesg2); |
| 297 | |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Add the users option to the STD_opt_arr array. |
| 303 | */ |
| 304 | if ( add_option(user_optarr[cnt].option, &STD_opt_arr, &STD_nopts) == -1 ) |
| 305 | return Mesg2; |
| 306 | |
| 307 | } /* new option */ |
| 308 | } /* end of options loop */ |
| 309 | } /* end of user options */ |
| 310 | |
| 311 | #if DEBUG > 1 |
| 312 | printf("STD_nopts = %d\n", STD_nopts); |
| 313 | #endif |
| 314 | |
| 315 | |
| 316 | /* |
| 317 | * Loop through av parsing options. |
| 318 | */ |
| 319 | while ( (opt=mc_getoptv(ac, av, 0, STD_nopts, STD_opt_arr)) != MC_DONE ) { |
| 320 | |
| 321 | STD_argind = mc_optind; |
| 322 | |
| 323 | #if DEBUG > 0 |
| 324 | printf("parse_opts: mc_getoptv returned '%s'\n", opt); |
| 325 | #endif |
| 326 | if ( strcmp(opt, MC_UNKNOWN_OPTION) == 0 ) { |
| 327 | sprintf(Mesg2, |
| 328 | "parse_opts: ERROR - Unknown option: \"-%s\"", |
| 329 | mc_optopt); |
| 330 | return Mesg2; |
| 331 | |
| 332 | } else if ( strcmp(opt, MC_AMBIGUOUS_OPTION) == 0 ) { |
| 333 | sprintf(Mesg2, |
| 334 | "parse_opts: ERROR - option \"-%s\" is not unique, be more specific", |
| 335 | mc_optopt); |
| 336 | return Mesg2; |
| 337 | |
| 338 | } else if ( strcmp(opt, MC_MISSING_OPTARG) == 0 ) { |
| 339 | sprintf(Mesg2, |
| 340 | "parse_opts: ERROR - option \"-%s\" is missing its argument", |
| 341 | mc_optopt); |
| 342 | return Mesg2; |
| 343 | |
| 344 | } else if ( strcmp(opt, ITERATIONS) == 0 ) { |
| 345 | options |= OPT_iteration; |
| 346 | if ( sscanf(mc_optarg, "%i%c", &STD_LOOP_COUNT, &chr) != 1) { |
| 347 | sprintf(Mesg2, |
| 348 | "parse_opts: ERROR - Argument for -%s option MUST be NUMERIC", |
| 349 | mc_optopt); |
| 350 | return(Mesg2); |
| 351 | } |
| 352 | |
| 353 | if ( STD_LOOP_COUNT == 0 ) /* if arg is 0, set infinite loop flag */ |
| 354 | STD_INFINITE=1; |
| 355 | |
| 356 | } else if ( strcmp(opt, DELAY) == 0 ) { |
| 357 | options |= OPT_delay; |
| 358 | if ( sscanf(mc_optarg, "%f%c", &STD_LOOP_DELAY, &chr) != 1 ) { |
| 359 | sprintf(Mesg2, |
| 360 | "parse_opts: ERROR - Argument for -%s option MUST be NUMERIC", |
| 361 | mc_optopt); |
| 362 | return(Mesg2); |
| 363 | } |
| 364 | |
| 365 | } else if ( strcmp(opt, DURATION) == 0 ) { |
| 366 | options |= OPT_duration; |
| 367 | if ( sscanf(mc_optarg, "%f%c", &STD_LOOP_DURATION, &chr) != 1 ) { |
| 368 | sprintf(Mesg2, |
| 369 | "parse_opts: ERROR - Argument for -%s option MUST be NUMERIC", |
| 370 | mc_optopt); |
| 371 | return(Mesg2); |
| 372 | } |
| 373 | |
| 374 | if ( STD_LOOP_DURATION == 0.0 ) { |
| 375 | STD_INFINITE=1; |
| 376 | } |
| 377 | |
| 378 | } else if ( strcmp(opt, COPIES) == 0 ) { |
| 379 | options |= OPT_copies; |
| 380 | if ( sscanf(mc_optarg, "%i%c", &STD_COPIES, &chr) != 1 ) { |
| 381 | sprintf(Mesg2, |
| 382 | "parse_opts: ERROR - Argument for -%s option MUST be NUMERIC", |
| 383 | mc_optopt); |
| 384 | return(Mesg2); |
| 385 | } |
| 386 | |
| 387 | } else if ( strcmp(opt, NOFUNC) == 0 ) { |
| 388 | STD_FUNCTIONAL_TEST=0; |
| 389 | } else if ( strcmp(opt, SETUP_PAUSE) == 0 ) { |
| 390 | STD_PAUSE=1; |
| 391 | } else if ( strcmp(opt, TIMING) == 0 ) { |
| 392 | STD_TIMING_ON=1; |
| 393 | } else if ( strcmp(opt, ERRNO_LOGGING) == 0 ) { |
| 394 | STD_ERRNO_LOG=1; |
| 395 | } else if ( strcmp(opt, USC_HELP) == 0 ) { |
| 396 | printf(STD_opts_help()); |
| 397 | exit(0); |
| 398 | } else { |
| 399 | /* Check all the user specified options */ |
| 400 | found=0; |
| 401 | for(ind=0; user_optarr[ind].option != (char *) NULL; ind++) { |
| 402 | |
| 403 | if ( strcmp(opt, user_optarr[ind].option) == 0 ) { |
| 404 | /* Yup, This is a user option, set the flag and look for argument */ |
| 405 | if ( user_optarr[ind].flag != NULL ) { |
| 406 | *user_optarr[ind].flag=1; |
| 407 | } |
| 408 | found++; |
| 409 | |
| 410 | /* If option requires arg, save pointer */ |
| 411 | num=strlen(user_optarr[ind].option); |
| 412 | /* save the argument at the user's location */ |
| 413 | if ( user_optarr[ind].option[num-1] == ':' ) { |
| 414 | *user_optarr[ind].arg=mc_optarg; |
| 415 | } |
| 416 | break; /* option found - break out of the for loop */ |
| 417 | } |
| 418 | } |
| 419 | /* This condition "should never happen". SO CHECK FOR IT!!!! */ |
| 420 | if ( ! found ) { |
| 421 | sprintf(Mesg2, |
| 422 | "parse_opts: ERROR - option:\"%s\" NOT FOUND... INTERNAL ERROR", opt); |
| 423 | return(Mesg2); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | } /* end of while */ |
| 428 | |
| 429 | STD_argind = mc_optind; |
| 430 | |
| 431 | /* |
| 432 | * Turn on debug |
| 433 | */ |
| 434 | if ( (ptr=getenv("USC_DEBUG")) != NULL ) { |
| 435 | Debug=1; |
| 436 | printf("env USC_DEBUG is defined, turning on debug\n"); |
| 437 | } |
| 438 | if ( (ptr=getenv("USC_VERBOSE")) != NULL ) { |
| 439 | Debug=1; |
| 440 | printf("env USC_VERBOSE is defined, turning on debug\n"); |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * If the USC_ITERATION_ENV environmental variable is set to |
| 445 | * a number, use that number as iteration count (same as -c option). |
| 446 | * The -c option with arg will be used even if this env var is set. |
| 447 | */ |
| 448 | if ( !(options & OPT_iteration) && (ptr=getenv(USC_ITERATION_ENV)) != NULL ) { |
| 449 | if ( sscanf(ptr, "%i", &k) == 1) { |
| 450 | if ( k == 0 ) { /* if arg is 0, set infinite loop flag */ |
| 451 | STD_INFINITE=1; |
| 452 | if ( Debug ) |
| 453 | printf("Using env %s, set STD_INFINITE to 1\n", |
| 454 | USC_ITERATION_ENV); |
| 455 | } else { /* else, set the loop count to the arguement */ |
| 456 | STD_LOOP_COUNT=k; |
| 457 | if ( Debug ) |
| 458 | printf("Using env %s, set STD_LOOP_COUNT to %d\n", |
| 459 | USC_ITERATION_ENV, k); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * If the USC_NO_FUNC_CHECK environmental variable is set, we'll |
| 466 | * unset the STD_FUNCTIONAL_TEST variable. |
| 467 | */ |
| 468 | if ( !(options & OPT_nofunccheck) && (ptr=getenv(USC_NO_FUNC_CHECK)) != NULL ) { |
| 469 | STD_FUNCTIONAL_TEST=0; /* Turn off functional testing */ |
| 470 | if ( Debug ) |
| 471 | printf("Using env %s, set STD_FUNCTIONAL_TEST to 0\n", |
| 472 | USC_NO_FUNC_CHECK); |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * If the USC_LOOP_WALLTIME environmental variable is set, |
| 477 | * use that number as duration (same as -I option). |
| 478 | * The -I option with arg will be used even if this env var is set. |
| 479 | */ |
| 480 | |
| 481 | if ( !(options & OPT_duration) && (ptr=getenv(USC_LOOP_WALLTIME)) != NULL ) { |
| 482 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 483 | STD_LOOP_DURATION=ftmp; |
| 484 | if ( Debug ) |
| 485 | printf("Using env %s, set STD_LOOP_DURATION to %f\n", |
| 486 | USC_LOOP_WALLTIME, ftmp); |
| 487 | if ( STD_LOOP_DURATION == 0.0 ) { /* if arg is 0, set infinite loop flag */ |
| 488 | STD_INFINITE=1; |
| 489 | if ( Debug ) |
| 490 | printf("Using env %s, set STD_INFINITE to 1\n", USC_LOOP_WALLTIME); |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | if ( !(options & OPT_duration) && (ptr=getenv("USC_DURATION")) != NULL ) { |
| 495 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 496 | STD_LOOP_DURATION=ftmp; |
| 497 | if ( Debug ) |
| 498 | printf("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n", ftmp); |
| 499 | if ( STD_LOOP_DURATION == 0.0 ) { /* if arg is 0, set infinite loop flag */ |
| 500 | STD_INFINITE=1; |
| 501 | if ( Debug ) |
| 502 | printf("Using env USC_DURATION, set STD_INFINITE to 1\n"); |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | /* |
| 507 | * If the USC_LOOP_DELAY environmental variable is set, |
| 508 | * use that number as delay in factional seconds (same as -P option). |
| 509 | * The -P option with arg will be used even if this env var is set. |
| 510 | */ |
| 511 | if ( !(options & OPT_delay) && (ptr=getenv(USC_LOOP_DELAY)) != NULL ) { |
| 512 | if ( sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0 ) { |
| 513 | STD_LOOP_DELAY=ftmp; |
| 514 | if ( Debug ) |
| 515 | printf("Using env %s, set STD_LOOP_DELAY = %f\n", |
| 516 | USC_LOOP_DELAY, ftmp); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * If the USC_COPIES environmental variable is set, |
| 522 | * use that number as copies (same as -c option). |
| 523 | * The -c option with arg will be used even if this env var is set. |
| 524 | */ |
| 525 | if ( !(options & OPT_copies) && (ptr=getenv(USC_COPIES)) != NULL ) { |
| 526 | if ( sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0 ) { |
| 527 | if ( Debug ) |
| 528 | printf("Using env %s, set STD_COPIES = %d\n", |
| 529 | USC_COPIES, STD_COPIES); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * The following are special system testing envs to turn on special |
| 535 | * hooks in the code. |
| 536 | */ |
| 537 | if ( (ptr=getenv("USC_TP_BARRIER")) != NULL ) { |
| 538 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 539 | STD_TP_barrier=k; |
| 540 | } |
| 541 | else |
| 542 | STD_TP_barrier=1; |
| 543 | if ( Debug ) |
| 544 | printf("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n", |
| 545 | STD_TP_barrier); |
| 546 | } |
| 547 | |
| 548 | if ( (ptr=getenv("USC_LP_BARRIER")) != NULL ) { |
| 549 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 550 | STD_LP_barrier=k; |
| 551 | } |
| 552 | else |
| 553 | STD_LP_barrier=1; |
| 554 | if ( Debug ) |
| 555 | printf("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n", |
| 556 | STD_LP_barrier); |
| 557 | } |
| 558 | |
| 559 | if ( (ptr=getenv("USC_TP_SHMEM")) != NULL ) { |
| 560 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 561 | STD_TP_shmem_sz=k; |
| 562 | if ( Debug ) |
| 563 | printf("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n", |
| 564 | STD_TP_shmem_sz); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | if ( (ptr=getenv("USC_LP_SHMEM")) != NULL ) { |
| 569 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 570 | STD_LP_shmem=k; |
| 571 | if ( Debug ) |
| 572 | printf("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n", |
| 573 | STD_LP_shmem); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | if ( (ptr=getenv("USC_LD_SHMEM")) != NULL ) { |
| 578 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 579 | STD_LD_shmem=k; |
| 580 | if ( Debug ) |
| 581 | printf("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n", |
| 582 | STD_LD_shmem); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | if ( (ptr=getenv("USC_TP_SBRK")) != NULL ) { |
| 587 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 588 | STD_TP_sbrk=k; |
| 589 | if ( Debug ) |
| 590 | printf("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n", |
| 591 | STD_TP_sbrk); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if ( (ptr=getenv("USC_LP_SBRK")) != NULL ) { |
| 596 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 597 | STD_LP_sbrk=k; |
| 598 | if ( Debug ) |
| 599 | printf("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n", |
| 600 | STD_LP_sbrk); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | if ( (ptr=getenv("USC_LP_RECFUN")) != NULL ) { |
| 605 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 606 | STD_LP_recfun=k; |
| 607 | if ( STD_bigstack != (struct usc_bigstack_t *)NULL ) |
| 608 | STD_bigstack=(struct usc_bigstack_t *) |
| 609 | malloc(sizeof(struct usc_bigstack_t)); |
| 610 | if ( Debug ) |
| 611 | printf("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n", |
| 612 | STD_LP_recfun); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | if ( (ptr=getenv("USC_LD_RECFUN")) != NULL ) { |
| 617 | if ( sscanf(ptr, "%i", &k) == 1 && k >= 0 ) { |
| 618 | STD_LD_recfun=k; |
| 619 | if ( STD_bigstack != (struct usc_bigstack_t *)NULL ) |
| 620 | STD_bigstack=(struct usc_bigstack_t *) |
| 621 | malloc(sizeof(struct usc_bigstack_t)); |
| 622 | if ( Debug ) |
| 623 | printf("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n", |
| 624 | STD_LD_recfun); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | #if UNIT_TEST |
| 629 | printf("The following variables after option and env parsing:\n"); |
| 630 | printf("STD_FUNCTIONAL_TEST = %d\n", STD_FUNCTIONAL_TEST); |
| 631 | printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION); |
| 632 | printf("STD_LOOP_DELAY = %f\n", STD_LOOP_DELAY); |
| 633 | printf("STD_COPIES = %d\n", STD_COPIES); |
| 634 | printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT); |
| 635 | printf("STD_INFINITE = %d\n", STD_INFINITE); |
| 636 | printf("STD_TIMING_ON = %d\n", STD_TIMING_ON); |
| 637 | printf("STD_ERRNO_LOG = %d\n", STD_ERRNO_LOG); |
| 638 | printf("STD_PAUSE = %d\n", STD_PAUSE); |
| 639 | #endif |
| 640 | |
| 641 | return((char *) NULL); |
| 642 | |
| 643 | } /* end of parse_opts */ |
| 644 | |
| 645 | /*********************************************************************** |
| 646 | * This function will remove option from the opt_arr array and |
| 647 | * decrement the value of nopts. If option is not at the end |
| 648 | * of the opt_arr, the remaining elements are moved up in the array. |
| 649 | * |
| 650 | ***********************************************************************/ |
| 651 | static int |
| 652 | rm_option(char *option, char **opt_arr[], int *nopts) |
| 653 | { |
| 654 | int ind; |
| 655 | int found=0; |
| 656 | |
| 657 | for (ind=0; ind<*nopts; ind++) { |
| 658 | if ( found ) { |
| 659 | /* |
| 660 | * Move all opt_arr elements down in the array |
| 661 | */ |
| 662 | if ( ind == (*nopts) ) { |
| 663 | (*opt_arr)[ind] = NULL; |
| 664 | } else { |
| 665 | (*opt_arr)[ind-1] = (*opt_arr)[ind]; |
| 666 | } |
| 667 | |
| 668 | } else if ( strcmp(option, (*opt_arr)[ind]) == 0 ) { |
| 669 | found=ind+1; |
| 670 | } |
| 671 | } |
| 672 | if ( found ) { |
| 673 | (*nopts)--; |
| 674 | #if DEBUG > 1 |
| 675 | printf("removed %s option from opt_arr, opt_arr[%d] = %s\n", |
| 676 | option, found-1, (*opt_arr)[found-1]); |
| 677 | #endif |
| 678 | } |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | /*********************************************************************** |
| 684 | * This function will add option to the end of opt_arr array and |
| 685 | * increment the value of nopts. The array space will be realloc'ed |
| 686 | * to make space for the element. |
| 687 | * |
| 688 | ***********************************************************************/ |
| 689 | static int |
| 690 | add_option(char *option, char **opt_arr[], int *nopts) |
| 691 | { |
| 692 | |
| 693 | if ( (*opt_arr=(char **)realloc(*opt_arr, sizeof(char * ) * (*nopts+1))) == |
| 694 | (char **)NULL ) { |
| 695 | sprintf(Mesg2, "parse_opts: ERROR: realloc(arr, %ld) failed, errno:%d %s", |
| 696 | (long)sizeof(char * ) * (*nopts+1), errno, strerror(errno)); |
| 697 | return -1; |
| 698 | } |
| 699 | |
| 700 | (*opt_arr)[*nopts] = option; |
| 701 | |
| 702 | #if DEBUG > 1 |
| 703 | printf("adding opt_arr[%d] = %s\n", *nopts, (*opt_arr)[*nopts]); |
| 704 | #endif |
| 705 | (*nopts)++; |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | /********************************************************************* |
| 711 | * STD_opts() - return a usage string for the STD_OPTIONS. |
| 712 | *********************************************************************/ |
| 713 | char * |
| 714 | STD_opts() |
| 715 | { |
| 716 | int ind; |
| 717 | |
| 718 | Mesg2[0] = '\0'; |
| 719 | |
| 720 | /* |
| 721 | * generate usage string from the standard options in STD_opt_arr |
| 722 | */ |
| 723 | for(ind=0; ind<STD_nopts; ind++) { |
| 724 | if ( strcmp(ITERATIONS, STD_opt_arr[ind]) == 0 ) { |
| 725 | strcat(Mesg2, ITERATIONS_USE); |
| 726 | }else if ( strcmp(DELAY, STD_opt_arr[ind]) == 0 ) { |
| 727 | strcat(Mesg2, DELAY_USE); |
| 728 | }else if ( strcmp(DURATION, STD_opt_arr[ind]) == 0 ) { |
| 729 | strcat(Mesg2, DURATION_USE); |
| 730 | }else if ( strcmp(COPIES, STD_opt_arr[ind]) == 0 ) { |
| 731 | strcat(Mesg2, COPIES_USE); |
| 732 | }else if ( strcmp(NOFUNC, STD_opt_arr[ind]) == 0 ) { |
| 733 | strcat(Mesg2, NOFUNC_USE); |
| 734 | }else if ( strcmp(SETUP_PAUSE, STD_opt_arr[ind]) == 0 ) { |
| 735 | strcat(Mesg2, SETUP_PAUSE_USE); |
| 736 | }else if ( strcmp(TIMING, STD_opt_arr[ind]) == 0 ) { |
| 737 | strcat(Mesg2, TIMING_USE); |
| 738 | }else if ( strcmp(ERRNO_LOGGING, STD_opt_arr[ind]) == 0 ) { |
| 739 | strcat(Mesg2, ERRNO_LOGGING_USE); |
| 740 | }else if ( strcmp(USC_HELP, STD_opt_arr[ind]) == 0 ) { |
| 741 | strcat(Mesg2, HELP_USE); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | return Mesg2; |
| 746 | } |
| 747 | |
| 748 | /********************************************************************* |
| 749 | * STD_opts_help() - return a help string for the STD_OPTIONS. |
| 750 | *********************************************************************/ |
| 751 | char * |
| 752 | STD_opts_help() |
| 753 | { |
| 754 | int ind; |
| 755 | |
| 756 | sprintf(Mesg, " Options and option args can NOT be concatenated.\n\ |
| 757 | You can use smallest unique string that identifies an option\n"); |
| 758 | |
| 759 | /* |
| 760 | * generate usage string from the standard options in STD_opt_arr |
| 761 | */ |
| 762 | for(ind=0; ind<STD_nopts; ind++) { |
| 763 | if ( strcmp(ITERATIONS, STD_opt_arr[ind]) == 0 ) { |
| 764 | strcat(Mesg, ITERATIONS_HELP); |
| 765 | }else if ( strcmp(DELAY, STD_opt_arr[ind]) == 0 ) { |
| 766 | strcat(Mesg, DELAY_HELP); |
| 767 | }else if ( strcmp(DURATION, STD_opt_arr[ind]) == 0 ) { |
| 768 | strcat(Mesg, DURATION_HELP); |
| 769 | }else if ( strcmp(COPIES, STD_opt_arr[ind]) == 0 ) { |
| 770 | strcat(Mesg, COPIES_HELP); |
| 771 | }else if ( strcmp(NOFUNC, STD_opt_arr[ind]) == 0 ) { |
| 772 | strcat(Mesg, NOFUNC_HELP); |
| 773 | }else if ( strcmp(SETUP_PAUSE, STD_opt_arr[ind]) == 0 ) { |
| 774 | strcat(Mesg, SETUP_PAUSE_HELP); |
| 775 | }else if ( strcmp(TIMING, STD_opt_arr[ind]) == 0 ) { |
| 776 | strcat(Mesg, TIMING_HELP); |
| 777 | }else if ( strcmp(ERRNO_LOGGING, STD_opt_arr[ind]) == 0 ) { |
| 778 | strcat(Mesg, ERRNO_LOGGING_HELP); |
| 779 | }else if ( strcmp(USC_HELP, STD_opt_arr[ind]) == 0 ) { |
| 780 | strcat(Mesg, USC_HELP_HELP); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | return Mesg; |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | * routine to goto when we get the SIGUSR1 for STD_PAUSE |
| 789 | */ |
| 790 | void STD_go(int sig) |
| 791 | { |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | /*********************************************************************** |
| 796 | * This function will do desired end of global setup test |
| 797 | * hooks. |
| 798 | * Currently it will only do a pause waiting for sigusr1 if |
| 799 | * STD_PAUSE is set. |
| 800 | * |
| 801 | ***********************************************************************/ |
| 802 | int |
| 803 | usc_global_setup_hook() |
| 804 | { |
| 805 | int cnt; |
| 806 | |
| 807 | /* |
| 808 | * Fork STD_COPIES-1 copies. |
| 809 | */ |
| 810 | for(cnt=1;cnt<STD_COPIES;cnt++) { |
| 811 | switch(fork() ) { |
| 812 | case -1: |
| 813 | fprintf(stderr, "%s: fork() failed, errno:%d %s\n", |
| 814 | __FILE__, errno, strerror(errno)); |
| 815 | break; |
| 816 | case 0: /* child */ |
| 817 | cnt=STD_COPIES; /* to stop the forking */ |
| 818 | break; |
| 819 | |
| 820 | default: /* parent */ |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | |
| 827 | #ifdef _CRAYMPP |
| 828 | MyPE = sysconf(_SC_CRAY_VPE); |
| 829 | Npe = sysconf(_SC_CRAY_NPES); |
| 830 | #endif |
| 831 | |
| 832 | /* |
| 833 | * pause waiting for sigusr1. |
| 834 | */ |
| 835 | if ( STD_PAUSE ) { |
| 836 | _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go); |
| 837 | pause(); |
| 838 | signal(SIGUSR1, (void (*)())_TMP_FUNC); |
| 839 | } |
| 840 | |
| 841 | #ifdef _CRAYMPP |
| 842 | if ( STD_TP_shmem_sz ) { |
| 843 | if ( (STD_shmem=(long *)shmalloc(STD_TP_shmem_sz*sizeof(long)*Npe)) == NULL ) { |
| 844 | STD_TP_shmem_sz=0; |
| 845 | } |
| 846 | else { |
| 847 | bzero(STD_shmem, STD_TP_shmem_sz*sizeof(long)*Npe); |
| 848 | if ( Debug ) |
| 849 | printf("shmalloc(%d*%d*%d=%d) successful, pid:%d\n", |
| 850 | STD_TP_shmem_sz, sizeof(long), Npe, |
| 851 | STD_TP_shmem_sz*sizeof(long)*Npe, getpid()); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | if ( STD_TP_barrier ) { |
| 856 | switch (STD_TP_barrier) { |
| 857 | case 2: |
| 858 | wait_barrier(); |
| 859 | if ( Debug ) |
| 860 | printf("after wait_barrier, pid : %d\n", getpid()); |
| 861 | break; |
| 862 | |
| 863 | case 3: |
| 864 | set_barrier(); |
| 865 | if ( Debug ) |
| 866 | printf("after set_barrier, pid : %d\n", getpid()); |
| 867 | break; |
| 868 | |
| 869 | default: |
| 870 | barrier(); |
| 871 | if ( Debug ) |
| 872 | printf("after barrier, pid : %d\n", getpid()); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | #endif /* _CRAYMPP */ |
| 877 | |
| 878 | if ( STD_TP_sbrk || STD_LP_sbrk) { |
| 879 | STD_start_break=sbrk(0); /* get original sbreak size */ |
| 880 | } |
| 881 | |
| 882 | if ( STD_TP_sbrk ) { |
| 883 | sbrk(STD_TP_sbrk); |
| 884 | if ( Debug ) |
| 885 | printf("after sbrk(%d)\n", STD_TP_sbrk); |
| 886 | } |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | #define USECS_PER_SEC 1000000 /* microseconds per second */ |
| 891 | |
| 892 | /*********************************************************************** |
| 893 | * This function returns the number of get_current_time()'s return |
| 894 | * per second. |
| 895 | ***********************************************************************/ |
| 896 | |
| 897 | static int |
| 898 | get_timepersec() |
| 899 | { |
| 900 | #if CRAY |
| 901 | return sysconf(_SC_CLK_TCK); /* clocks per second */ |
| 902 | #else |
| 903 | return USECS_PER_SEC; /* microseconds per second */ |
| 904 | #endif /* CRAY */ |
| 905 | |
| 906 | } |
| 907 | |
| 908 | /*********************************************************************** |
| 909 | * this function will get current time in clocks if on a CRAY system |
| 910 | * or in microseconds since 1970. |
| 911 | ***********************************************************************/ |
| 912 | static int |
| 913 | get_current_time() |
| 914 | { |
| 915 | struct timeval curtime; |
| 916 | #if CRAY |
| 917 | return _rtc(); /* clocks since last boot */ |
| 918 | #else |
| 919 | |
| 920 | gettimeofday(&curtime, NULL); |
| 921 | |
| 922 | /* microseconds since 1970 */ |
| 923 | return (curtime.tv_sec*USECS_PER_SEC) + curtime.tv_usec; |
| 924 | |
| 925 | #endif |
| 926 | |
| 927 | } |
| 928 | |
| 929 | /*********************************************************************** |
| 930 | * |
| 931 | * This function will determine if test should continue iterating |
| 932 | * If the STD_INFINITE flag is set, return 1. |
| 933 | * If the STD_LOOP_COUNT variable is set, compare it against |
| 934 | * the counter. |
| 935 | * If the STD_LOOP_DURATION variable is set, compare current time against |
| 936 | * calculated stop_time. |
| 937 | * This function will return 1 until all desired looping methods |
| 938 | * have been met. |
| 939 | * |
| 940 | * counter integer is supplied by the user program. |
| 941 | ***********************************************************************/ |
| 942 | int |
| 943 | usc_test_looping(counter) |
| 944 | int counter; |
| 945 | { |
| 946 | static int first_time = 1; |
| 947 | static int stop_time = 0; /* stop time in rtc or usecs */ |
| 948 | static int delay; /* delay in clocks or usecs */ |
| 949 | int hz=0; /* clocks per second or usecs per second */ |
| 950 | int ct, end; /* current time, end delay time */ |
| 951 | int keepgoing=0; /* used to determine return value */ |
| 952 | #ifdef _CRAYMPP |
| 953 | long word; |
| 954 | int pe; |
| 955 | #endif |
| 956 | |
| 957 | /* |
| 958 | * If this is the first iteration and we are looping for |
| 959 | * duration of STD_LOOP_DURATION seconds (fractional) or |
| 960 | * doing loop delays, get the clocks per second. |
| 961 | */ |
| 962 | if ( first_time ) { |
| 963 | |
| 964 | first_time=0; |
| 965 | if ( STD_LOOP_DELAY || STD_LOOP_DURATION ) { |
| 966 | hz = get_timepersec(); |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * If looping for duration, calculate stop time in |
| 971 | * clocks. |
| 972 | */ |
| 973 | |
| 974 | if ( STD_LOOP_DURATION) { |
| 975 | ct=get_current_time(); |
| 976 | stop_time=(int)((float)hz * STD_LOOP_DURATION) + ct; |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | * If doing delay each iteration, calcuate the number |
| 981 | * of clocks for each delay. |
| 982 | */ |
| 983 | if ( STD_LOOP_DELAY ) { |
| 984 | delay=(int)((float)hz * STD_LOOP_DELAY); |
| 985 | } |
| 986 | |
| 987 | } |
| 988 | |
| 989 | /* |
| 990 | * if delay each iteration, loop for delay clocks. |
| 991 | * This will not be done on first iteration. |
| 992 | * The delay will happen before determining if |
| 993 | * there will be another iteration. |
| 994 | */ |
| 995 | else if ( STD_LOOP_DELAY ) { |
| 996 | ct=get_current_time(); |
| 997 | end=ct+delay; |
| 998 | while ( ct < end ) { |
| 999 | /* |
| 1000 | * The following are special test hooks in the delay loop. |
| 1001 | */ |
| 1002 | if ( STD_LD_recfun ) { |
| 1003 | if ( Debug ) |
| 1004 | printf("calling usc_recressive_func(0, %d, &STD_bigstack)\n", |
| 1005 | STD_LD_recfun); |
| 1006 | usc_recressive_func(0, STD_LD_recfun, &STD_bigstack); |
| 1007 | } |
| 1008 | |
| 1009 | ct=get_current_time(); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if ( STD_INFINITE ) { |
| 1014 | keepgoing++; |
| 1015 | } |
| 1016 | |
| 1017 | if ( STD_LOOP_COUNT && counter < STD_LOOP_COUNT ) { |
| 1018 | keepgoing++; |
| 1019 | } |
| 1020 | |
| 1021 | if ( STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time ) { |
| 1022 | keepgoing++; |
| 1023 | } |
| 1024 | |
| 1025 | if ( keepgoing == 0 ) |
| 1026 | return 0; |
| 1027 | |
| 1028 | /* |
| 1029 | * The following code allows special system testing hooks. |
| 1030 | */ |
| 1031 | |
| 1032 | if ( STD_LP_recfun ) { |
| 1033 | if ( Debug ) |
| 1034 | printf("calling usc_recressive_func(0, %d, &STD_bigstack)\n", |
| 1035 | STD_LP_recfun); |
| 1036 | usc_recressive_func(0, STD_LP_recfun, &STD_bigstack); |
| 1037 | } |
| 1038 | |
| 1039 | if ( STD_LP_sbrk ) { |
| 1040 | if ( Debug ) |
| 1041 | printf("about to do sbrk(%d)\n", STD_LP_sbrk); |
| 1042 | sbrk(STD_LP_sbrk); |
| 1043 | } |
| 1044 | |
| 1045 | #ifdef _CRAYMPP |
| 1046 | if ( STD_LP_shmem ) { |
| 1047 | if ( (pe=MyPE-1) < 0 ) /* put to be lower pe #*/ |
| 1048 | pe=Npe; |
| 1049 | word=MyPE; |
| 1050 | |
| 1051 | if ( Debug ) |
| 1052 | printf("about to do shmem_put\n"); |
| 1053 | shmem_put(&STD_shmem[pe], &STD_shmem[MyPE], STD_TP_shmem_sz, pe); |
| 1054 | |
| 1055 | |
| 1056 | } |
| 1057 | if ( STD_TP_barrier ) { |
| 1058 | switch (STD_TP_barrier) { |
| 1059 | case 2: |
| 1060 | wait_barrier(); |
| 1061 | if ( Debug ) |
| 1062 | printf("after wait_barrier, pid : %d\n", getpid()); |
| 1063 | break; |
| 1064 | |
| 1065 | case 3: |
| 1066 | set_barrier(); |
| 1067 | if ( Debug ) |
| 1068 | printf("after set_barrier, pid : %d\n", getpid()); |
| 1069 | break; |
| 1070 | |
| 1071 | default: |
| 1072 | barrier(); |
| 1073 | if ( Debug ) |
| 1074 | printf("after barrier, pid : %d\n", getpid()); |
| 1075 | } |
| 1076 | } |
| 1077 | if ( STD_LP_shmem > 1) { |
| 1078 | if ( (pe=MyPE+1) > Npe ) /* get from higher pe # */ |
| 1079 | pe=0; |
| 1080 | word=MyPE; |
| 1081 | |
| 1082 | if ( Debug ) |
| 1083 | printf("about to do shmem_get\n"); |
| 1084 | shmem_get(&STD_shmem[MyPE], &STD_shmem[pe], STD_TP_shmem_sz, pe); |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | #endif /* _CRAYMPP */ |
| 1089 | |
| 1090 | |
| 1091 | if ( keepgoing ) |
| 1092 | return 1; |
| 1093 | else |
| 1094 | return 0; /* done - stop iterating */ |
| 1095 | } |
| 1096 | |
| 1097 | |
| 1098 | /* |
| 1099 | * This function recressively calls itself max times. |
| 1100 | */ |
| 1101 | static void |
| 1102 | usc_recressive_func(cnt, max, bstack) |
| 1103 | int cnt; |
| 1104 | int max; |
| 1105 | struct usc_bigstack_t bstack; |
| 1106 | { |
| 1107 | if ( cnt < max ) |
| 1108 | usc_recressive_func(cnt+1, max, bstack); |
| 1109 | |
| 1110 | } |
| 1111 | |
| 1112 | #if UNIT_TEST |
| 1113 | /****************************************************************************** |
| 1114 | * UNIT TEST CODE |
| 1115 | * UNIT TEST CODE |
| 1116 | * |
| 1117 | * this following code is provide so that unit testing can |
| 1118 | * be done fairly easily. |
| 1119 | ******************************************************************************/ |
| 1120 | |
| 1121 | int Help = 0; |
| 1122 | int Help2 = 0; |
| 1123 | char *ptr; |
| 1124 | |
| 1125 | /* |
| 1126 | * Code from usctest.h that not part of this file since we are the library. |
| 1127 | */ |
| 1128 | |
| 1129 | struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO]; |
| 1130 | |
| 1131 | /*********************************************************************** |
| 1132 | * Globals for returning the return code and errno from the system call |
| 1133 | * test macros. |
| 1134 | ***********************************************************************/ |
| 1135 | int TEST_RETURN; |
| 1136 | int TEST_ERRNO; |
| 1137 | |
| 1138 | /*********************************************************************** |
| 1139 | * temporary variables for determining max and min times in TEST macro |
| 1140 | ***********************************************************************/ |
| 1141 | long btime, etime, tmptime; |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | /* for test specific parse_opts options */ |
| 1146 | option_t Options[] = { |
| 1147 | { "help", &Help2, NULL }, /* -help option */ |
| 1148 | { "h", &Help, NULL }, /* -h option */ |
| 1149 | { TIMING, NULL, NULL}, /* disable -timing option */ |
| 1150 | |
| 1151 | #if INVALID_TEST_CASES |
| 1152 | { "missingflag", NULL, &ptr }, /* error */ |
| 1153 | { "missingarg:", &Help, NULL }, /* error */ |
| 1154 | #endif /* INVALID_TEST_CASES */ |
| 1155 | |
| 1156 | { NULL, NULL, NULL } |
| 1157 | }; |
| 1158 | |
| 1159 | |
| 1160 | main(argc, argv) |
| 1161 | int argc; |
| 1162 | char **argv; |
| 1163 | { |
| 1164 | int lc; |
| 1165 | char *msg; |
| 1166 | struct timeval t; |
| 1167 | int cnt; |
| 1168 | |
| 1169 | if ( (msg=parse_opts(argc, argv, |
| 1170 | (option_t *) Options)) != (char *) NULL ) { |
| 1171 | printf("ERROR : %s\n", msg); |
| 1172 | exit(1); |
| 1173 | } |
| 1174 | |
| 1175 | if ( Help ) { |
| 1176 | printf("****** -h option *****\n"); |
| 1177 | printf("Usage %s %s[-help]\n", argv[0], STD_opts()); |
| 1178 | printf("%s -help : print this help message and exit\n", |
| 1179 | STD_opts_help()); |
| 1180 | exit(0); |
| 1181 | } |
| 1182 | |
| 1183 | if ( Help2 ) { |
| 1184 | printf("****** -help option *****\n"); |
| 1185 | printf("Usage %s %s[-help]\n", argv[0], STD_opts()); |
| 1186 | printf("%s -help : print this help message and exit\n", |
| 1187 | STD_opts_help()); |
| 1188 | exit(0); |
| 1189 | } |
| 1190 | |
| 1191 | TEST_PAUSE; |
| 1192 | |
| 1193 | for (lc=0; TEST_LOOPING(lc); lc++) { |
| 1194 | |
| 1195 | TEST( gettimeofday(&t, NULL) ); |
| 1196 | printf("iter=%d: sec:%d, usec:%6.6d %s", lc+1, t.tv_sec, |
| 1197 | t.tv_usec, ctime(&t.tv_sec)); |
| 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | TEST_CLEANUP; |
| 1202 | |
| 1203 | exit(0); |
| 1204 | } |
| 1205 | |
| 1206 | #endif /* UNIT_TEST */ |