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