blob: ee1b36aaccf91d7d36fc7bf80948b7dd40224d4e [file] [log] [blame]
alaffincc2e5552000-07-27 17:13:18 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
vapier45a8ba02009-07-20 10:59:32 +00003 *
alaffincc2e5552000-07-27 17:13:18 +00004 * 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.
vapier45a8ba02009-07-20 10:59:32 +00007 *
alaffincc2e5552000-07-27 17:13:18 +00008 * 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.
vapier45a8ba02009-07-20 10:59:32 +000011 *
alaffincc2e5552000-07-27 17:13:18 +000012 * 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.
vapier45a8ba02009-07-20 10:59:32 +000018 *
alaffincc2e5552000-07-27 17:13:18 +000019 * 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.
vapier45a8ba02009-07-20 10:59:32 +000022 *
alaffincc2e5552000-07-27 17:13:18 +000023 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
vapier45a8ba02009-07-20 10:59:32 +000025 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
alaffincc2e5552000-07-27 17:13:18 +000030 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
32
vapier3dc04702009-08-28 09:59:52 +000033/* $Id: parse_opts.c,v 1.14 2009/08/28 09:59:52 vapier Exp $ */
alaffincc2e5552000-07-27 17:13:18 +000034
35/**********************************************************
vapier45a8ba02009-07-20 10:59:32 +000036 *
alaffincc2e5552000-07-27 17:13:18 +000037 * OS Testing - Silicon Graphics, Inc.
vapier45a8ba02009-07-20 10:59:32 +000038 *
alaffincc2e5552000-07-27 17:13:18 +000039 * FUNCTION NAME : parse_opts
vapier45a8ba02009-07-20 10:59:32 +000040 *
alaffincc2e5552000-07-27 17:13:18 +000041 * FUNCTION TITLE : parse standard & user options for system call tests
vapier45a8ba02009-07-20 10:59:32 +000042 *
alaffincc2e5552000-07-27 17:13:18 +000043 * SYNOPSIS:
44 * #include "usctest.h"
45 *
nstraz94181082000-08-30 18:43:38 +000046 * char *parse_opts(ac, av, user_optarr, uhf)
alaffincc2e5552000-07-27 17:13:18 +000047 * int ac;
48 * char **av;
49 * option_t user_optarr[];
nstraz94181082000-08-30 18:43:38 +000050 * void (*uhf)();
vapier45a8ba02009-07-20 10:59:32 +000051 *
alaffincc2e5552000-07-27 17:13:18 +000052 * AUTHOR : William Roske/Richard Logan
vapier45a8ba02009-07-20 10:59:32 +000053 *
alaffincc2e5552000-07-27 17:13:18 +000054 * INITIAL RELEASE : UNICOS 7.0
vapier45a8ba02009-07-20 10:59:32 +000055 *
alaffincc2e5552000-07-27 17:13:18 +000056 * 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
nstraz94181082000-08-30 18:43:38 +000060 * associated with the options. It uses getopt to do the actual cmd line
61 * parsing. uhf() is a function to print user define help
alaffincc2e5552000-07-27 17:13:18 +000062 *
63 * This module contains the functions usc_global_setup_hook and
64 * usc_test_looping, which are called by marcos defined in usctest.h.
vapier45a8ba02009-07-20 10:59:32 +000065 *
alaffincc2e5552000-07-27 17:13:18 +000066 * 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.
vapier45a8ba02009-07-20 10:59:32 +000069 *
alaffincc2e5552000-07-27 17:13:18 +000070 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
Mike Frysinger28606c12010-08-17 17:22:45 -040071#include "config.h"
alaffincc2e5552000-07-27 17:13:18 +000072#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 Hrubis4d964f62012-03-07 18:02:37 +010080#include <stdint.h>
alaffincc2e5552000-07-27 17:13:18 +000081
alaffincc2e5552000-07-27 17:13:18 +000082#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"
alaffincc2e5552000-07-27 17:13:18 +000089
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
alaffincc2e5552000-07-27 17:13:18 +0000102/* The timing information block. */
103struct tblock tblock={0,((long) -1)>>1,0,0};
104
Garrett Cooperd3e6e8f2010-12-13 02:55:35 -0800105#ifdef GARRETT_IS_A_PEDANTIC_BASTARD
106extern pid_t spawned_program_pid;
107#endif
alaffincc2e5552000-07-27 17:13:18 +0000108
109/* Define flags and args for standard options */
110int 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
119float STD_LOOP_DURATION=0.0, /* duration value in fractional seconds */
120 STD_LOOP_DELAY=0.0; /* loop delay value in fractional seconds */
121
122
123char **STD_opt_arr = NULL; /* array of option strings */
124int 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 */
132static int STD_TP_barrier=0; /* flag to do barrier in TEST_PAUSE */
133 /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
134static int STD_LP_barrier=0; /* flag to do barrier in TEST_LOOPING */
135 /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
136static int STD_TP_shmem_sz=0; /* shmalloc this many words per pe in TEST_PAUSE */
137static int STD_LD_shmem=0; /* flag to do shmem_puts and shmem_gets during delay */
138static int STD_LP_shmem=0; /* flag to do shmem_puts and gets during TEST_LOOPING */
139static int STD_LD_recfun=0; /* do recressive function calls in loop delay */
140static int STD_LP_recfun=0; /* do recressive function calls in TEST_LOOPING */
141static int STD_TP_sbrk=0; /* do sbrk in TEST_PAUSE */
142static int STD_LP_sbrk=0; /* do sbrk in TEST_LOOPING */
143static char *STD_start_break=0; /* original sbrk size */
alaffincc2e5552000-07-27 17:13:18 +0000144static int Debug=0;
145
nstraz94181082000-08-30 18:43:38 +0000146struct std_option_t {
147 char *optstr;
148 char *help;
149 char *flag;
150 char **arg;
151} std_options[] = {
nstrazdef354d2000-08-31 18:40:28 +0000152 { "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},
vapier45a8ba02009-07-20 10:59:32 +0000158 { "p" , " -p Pause for SIGUSR1 before starting\n", NULL, NULL},
nstrazdef354d2000-08-31 18:40:28 +0000159 { "P:", " -P x Pause for x seconds between iterations\n", NULL, NULL},
160 { "t" , " -t Turn on syscall timing\n", NULL, NULL},
robbiewd34d5812005-07-11 22:28:09 +0000161#ifdef UCLINUX
162 { "C:", " -C ARG Run the child process with arguments ARG (for internal use)\n",
163 NULL, NULL},
164#endif
nstraz94181082000-08-30 18:43:38 +0000165 {NULL, NULL, NULL, NULL}};
166
167void print_help(void (*user_help)());
168
alaffincc2e5552000-07-27 17:13:18 +0000169/*
170 * Structure for usc_recressive_func argument
171 */
172struct usc_bigstack_t {
173 char space[4096];
174};
175
176static struct usc_bigstack_t *STD_bigstack=NULL;
177
alaffincc2e5552000-07-27 17:13:18 +0000178/*
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 */
183int STD_ERRNO_LIST[USC_MAX_ERRNO];
184
185/* define the string length for Mesg and Mesg2 strings */
186#define STRLEN 2048
187
alaffincc2e5552000-07-27 17:13:18 +0000188static char Mesg2[STRLEN]; /* holds possible return string */
189static 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
robbiewd34d5812005-07-11 22:28:09 +0000200#ifdef UCLINUX
201/* Allocated and used in self_exec.c: */
202extern char *child_args; /* Arguments to child when -C is used */
203#endif
alaffincc2e5552000-07-27 17:13:18 +0000204
205/**********************************************************************
vapier45a8ba02009-07-20 10:59:32 +0000206 * parse_opts:
alaffincc2e5552000-07-27 17:13:18 +0000207 **********************************************************************/
208char *
Mike Frysingerc3190202010-10-13 10:10:45 -0400209parse_opts(int ac, char **av, const option_t *user_optarr, void (*uhf)())
alaffincc2e5552000-07-27 17:13:18 +0000210{
211 int found; /* flag to indicate that an option specified was */
212 /* found in the user's list */
alaffincc2e5552000-07-27 17:13:18 +0000213 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 */
nstraz94181082000-08-30 18:43:38 +0000217 int optstrlen, i;
218 char *optionstr;
219 int opt; /* return of getopt */
alaffincc2e5552000-07-27 17:13:18 +0000220
221 /*
222 * If not the first time this function is called, release the old STD_opt_arr
223 * vector.
224 */
225
Garrett Cooperd3e6e8f2010-12-13 02:55:35 -0800226#ifdef GARRETT_IS_A_PEDANTIC_BASTARD
227 spawned_program_pid = getpid();
228#endif
229
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800230 if (STD_opt_arr != NULL) {
alaffincc2e5552000-07-27 17:13:18 +0000231 free(STD_opt_arr);
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800232 STD_opt_arr = NULL;
alaffincc2e5552000-07-27 17:13:18 +0000233 }
nstraz94181082000-08-30 18:43:38 +0000234 /* Calculate how much space we need for the option string */
235 optstrlen = 0;
vapier45a8ba02009-07-20 10:59:32 +0000236 for (i = 0; std_options[i].optstr; ++i)
nstraz94181082000-08-30 18:43:38 +0000237 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;
alaffincc2e5552000-07-27 17:13:18 +0000245
nstraz94181082000-08-30 18:43:38 +0000246 /* Create the option string for getopt */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800247 optionstr = malloc(optstrlen);
vapier45a8ba02009-07-20 10:59:32 +0000248 if (!optionstr)
nstraz94181082000-08-30 18:43:38 +0000249 return "parse_opts: ERROR - Could not allocate memory for optionstr";
alaffincc2e5552000-07-27 17:13:18 +0000250
nstraz829b40a2000-09-06 14:33:29 +0000251 optionstr[0] = '\0';
252
nstraz94181082000-08-30 18:43:38 +0000253 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 */
vapier45a8ba02009-07-20 10:59:32 +0000258 if (strchr(optionstr, user_optarr[i].option[0]) == NULL)
nstraz94181082000-08-30 18:43:38 +0000259 strcat(optionstr, user_optarr[i].option);
alaffincc2e5552000-07-27 17:13:18 +0000260
261#if DEBUG > 1
262 printf("STD_nopts = %d\n", STD_nopts);
263#endif
264
alaffincc2e5552000-07-27 17:13:18 +0000265 /*
266 * Loop through av parsing options.
267 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800268 while ((opt = getopt(ac, av, optionstr)) > 0) {
alaffincc2e5552000-07-27 17:13:18 +0000269
nstraz94181082000-08-30 18:43:38 +0000270 STD_argind = optind;
alaffincc2e5552000-07-27 17:13:18 +0000271#if DEBUG > 0
nstraz94181082000-08-30 18:43:38 +0000272 printf("parse_opts: getopt returned '%c'\n", opt);
alaffincc2e5552000-07-27 17:13:18 +0000273#endif
alaffincc2e5552000-07-27 17:13:18 +0000274
nstraz94181082000-08-30 18:43:38 +0000275 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 Cooper903910d2010-11-23 09:27:44 -0800294 if (STD_LOOP_DURATION == 0.0) STD_INFINITE=1;
nstraz94181082000-08-30 18:43:38 +0000295 break;
296 case 'c': /* Copies */
Cyril Hrubis2ef059e2012-02-02 15:53:07 +0100297 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");
nstraz94181082000-08-30 18:43:38 +0000307 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;
robbiewd34d5812005-07-11 22:28:09 +0000326#ifdef UCLINUX
327 case 'C': /* Run child */
328 child_args = optarg;
329 break;
330#endif
nstraz94181082000-08-30 18:43:38 +0000331 default:
vapier45a8ba02009-07-20 10:59:32 +0000332
alaffincc2e5552000-07-27 17:13:18 +0000333 /* Check all the user specified options */
334 found=0;
Garrett Cooper903910d2010-11-23 09:27:44 -0800335 for (i = 0; user_optarr[i].option; ++i) {
alaffincc2e5552000-07-27 17:13:18 +0000336
nstraz94181082000-08-30 18:43:38 +0000337 if (opt == user_optarr[i].option[0]) {
alaffincc2e5552000-07-27 17:13:18 +0000338 /* Yup, This is a user option, set the flag and look for argument */
Garrett Cooper903910d2010-11-23 09:27:44 -0800339 if (user_optarr[i].flag) {
nstraz94181082000-08-30 18:43:38 +0000340 *user_optarr[i].flag=1;
alaffincc2e5552000-07-27 17:13:18 +0000341 }
342 found++;
343
alaffincc2e5552000-07-27 17:13:18 +0000344 /* save the argument at the user's location */
Garrett Cooper903910d2010-11-23 09:27:44 -0800345 if (user_optarr[i].option[strlen(user_optarr[i].option)-1] == ':') {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800346 *user_optarr[i].arg = optarg;
alaffincc2e5552000-07-27 17:13:18 +0000347 }
348 break; /* option found - break out of the for loop */
349 }
350 }
351 /* This condition "should never happen". SO CHECK FOR IT!!!! */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800352 if (!found) {
alaffincc2e5552000-07-27 17:13:18 +0000353 sprintf(Mesg2,
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800354 "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
355 "ERROR", opt);
alaffincc2e5552000-07-27 17:13:18 +0000356 return(Mesg2);
357 }
358 }
359
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800360 } /* end of while */
robbiew0ea4e1b2004-01-05 21:12:51 +0000361 free(optionstr);
alaffincc2e5552000-07-27 17:13:18 +0000362
nstraz94181082000-08-30 18:43:38 +0000363 STD_argind = optind;
alaffincc2e5552000-07-27 17:13:18 +0000364
365 /*
366 * Turn on debug
367 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800368 if ((ptr = getenv("USC_DEBUG")) != NULL) {
369 Debug = 1;
alaffincc2e5552000-07-27 17:13:18 +0000370 printf("env USC_DEBUG is defined, turning on debug\n");
371 }
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800372 if ((ptr = getenv("USC_VERBOSE")) != NULL) {
373 Debug = 1;
alaffincc2e5552000-07-27 17:13:18 +0000374 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 Cooper8b02c1c2011-01-26 01:34:49 -0800382 if (!(options & OPT_iteration) && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800383 if (sscanf(ptr, "%i", &k) == 1) {
384 if (k == 0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800385 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800386 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000387 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 Cooper903910d2010-11-23 09:27:44 -0800391 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000392 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 Cooper8b02c1c2011-01-26 01:34:49 -0800402 if (!(options & OPT_nofunccheck) &&
403 (ptr = getenv(USC_NO_FUNC_CHECK)) != NULL) {
alaffincc2e5552000-07-27 17:13:18 +0000404 STD_FUNCTIONAL_TEST=0; /* Turn off functional testing */
Garrett Cooper903910d2010-11-23 09:27:44 -0800405 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000406 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 Cooper8b02c1c2011-01-26 01:34:49 -0800416 if (!(options & OPT_duration) &&
417 (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800418 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800419 STD_LOOP_DURATION = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800420 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000421 printf("Using env %s, set STD_LOOP_DURATION to %f\n",
422 USC_LOOP_WALLTIME, ftmp);
Garrett Cooper903910d2010-11-23 09:27:44 -0800423 if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800424 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800425 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000426 printf("Using env %s, set STD_INFINITE to 1\n", USC_LOOP_WALLTIME);
427 }
428 }
429 }
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800430 if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800431 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800432 STD_LOOP_DURATION = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800433 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000434 printf("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n", ftmp);
Garrett Cooper903910d2010-11-23 09:27:44 -0800435 if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800436 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800437 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000438 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 Cooper8b02c1c2011-01-26 01:34:49 -0800447 if (!(options & OPT_delay) && (ptr = getenv(USC_LOOP_DELAY)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800448 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800449 STD_LOOP_DELAY = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800450 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000451 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 Cooper8b02c1c2011-01-26 01:34:49 -0800461 if (!(options & OPT_copies) && (ptr = getenv(USC_COPIES)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800462 if (sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0) {
463 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000464 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 Cooper8b02c1c2011-01-26 01:34:49 -0800473 if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
474 if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
alaffincc2e5552000-07-27 17:13:18 +0000475 STD_TP_barrier=k;
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800476 else
alaffincc2e5552000-07-27 17:13:18 +0000477 STD_TP_barrier=1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800478 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000479 printf("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
480 STD_TP_barrier);
481 }
482
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800483 if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
484 if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
alaffincc2e5552000-07-27 17:13:18 +0000485 STD_LP_barrier=k;
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800486 else
alaffincc2e5552000-07-27 17:13:18 +0000487 STD_LP_barrier=1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800488 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000489 printf("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
490 STD_LP_barrier);
491 }
492
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800493 if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800494 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000495 STD_TP_shmem_sz=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800496 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000497 printf("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
498 STD_TP_shmem_sz);
499 }
500 }
501
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800502 if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800503 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000504 STD_LP_shmem=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800505 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000506 printf("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
507 STD_LP_shmem);
508 }
509 }
510
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800511 if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800512 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000513 STD_LD_shmem=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800514 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000515 printf("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
516 STD_LD_shmem);
517 }
518 }
519
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800520 if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800521 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000522 STD_TP_sbrk=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800523 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000524 printf("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
525 STD_TP_sbrk);
526 }
527 }
528
robbiewd34d5812005-07-11 22:28:09 +0000529#if !defined(UCLINUX)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800530 if ((ptr = getenv("USC_LP_SBRK")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800531 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000532 STD_LP_sbrk=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800533 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000534 printf("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
535 STD_LP_sbrk);
536 }
537 }
robbiewd34d5812005-07-11 22:28:09 +0000538#endif /* if !defined(UCLINUX) */
alaffincc2e5552000-07-27 17:13:18 +0000539
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800540 if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800541 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800542 STD_LP_recfun = k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800543 if (STD_bigstack != NULL)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800544 STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
Garrett Cooper903910d2010-11-23 09:27:44 -0800545 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000546 printf("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
547 STD_LP_recfun);
548 }
549 }
550
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800551 if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800552 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800553 STD_LD_recfun = k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800554 if (STD_bigstack != NULL)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800555 STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
Garrett Cooper903910d2010-11-23 09:27:44 -0800556 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000557 printf("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
558 STD_LD_recfun);
559 }
560 }
vapier45a8ba02009-07-20 10:59:32 +0000561
alaffincc2e5552000-07-27 17:13:18 +0000562#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
alaffincc2e5552000-07-27 17:13:18 +0000579/*********************************************************************
nstraz94181082000-08-30 18:43:38 +0000580 * print_help() - print help message and user help message
alaffincc2e5552000-07-27 17:13:18 +0000581 *********************************************************************/
nstraz94181082000-08-30 18:43:38 +0000582void print_help(void (*user_help)())
alaffincc2e5552000-07-27 17:13:18 +0000583{
nstraz94181082000-08-30 18:43:38 +0000584 STD_opts_help();
alaffincc2e5552000-07-27 17:13:18 +0000585
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800586 if (user_help)
587 user_help();
alaffincc2e5552000-07-27 17:13:18 +0000588}
589
590/*********************************************************************
591 * STD_opts_help() - return a help string for the STD_OPTIONS.
592 *********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800593void STD_opts_help()
alaffincc2e5552000-07-27 17:13:18 +0000594{
nstraz94181082000-08-30 18:43:38 +0000595 int i;
alaffincc2e5552000-07-27 17:13:18 +0000596
Garrett Cooper903910d2010-11-23 09:27:44 -0800597 for (i = 0; std_options[i].optstr; ++i) {
nstraz94181082000-08-30 18:43:38 +0000598 if (std_options[i].help)
vapier1820d282009-07-20 04:48:17 +0000599 printf("%s", std_options[i].help);
alaffincc2e5552000-07-27 17:13:18 +0000600 }
alaffincc2e5552000-07-27 17:13:18 +0000601}
602
vapier45a8ba02009-07-20 10:59:32 +0000603/*
alaffincc2e5552000-07-27 17:13:18 +0000604 * routine to goto when we get the SIGUSR1 for STD_PAUSE
605 */
606void 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 Cooper8b02c1c2011-01-26 01:34:49 -0800618int usc_global_setup_hook()
alaffincc2e5552000-07-27 17:13:18 +0000619{
robbiewd34d5812005-07-11 22:28:09 +0000620#ifndef UCLINUX
alaffincc2e5552000-07-27 17:13:18 +0000621 int cnt;
nstraz94181082000-08-30 18:43:38 +0000622 /* temp variable to store old signal action to be restored after pause */
623 int (*_TMP_FUNC)(void);
alaffincc2e5552000-07-27 17:13:18 +0000624
625 /*
626 * Fork STD_COPIES-1 copies.
627 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800628 for (cnt=1;cnt<STD_COPIES;cnt++) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800629 switch (fork() ) {
alaffincc2e5552000-07-27 17:13:18 +0000630 case -1:
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800631 fprintf(stderr, "%s: fork failed: %d - %s\n",
632 __FILE__, errno, strerror(errno));
alaffincc2e5552000-07-27 17:13:18 +0000633 break;
634 case 0: /* child */
635 cnt=STD_COPIES; /* to stop the forking */
636 break;
637
638 default: /* parent */
639 break;
640 }
641 }
vapier45a8ba02009-07-20 10:59:32 +0000642
alaffincc2e5552000-07-27 17:13:18 +0000643 /*
644 * pause waiting for sigusr1.
645 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800646 if (STD_PAUSE) {
vapier45a8ba02009-07-20 10:59:32 +0000647 _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go);
648 pause();
649 signal(SIGUSR1, (void (*)())_TMP_FUNC);
alaffincc2e5552000-07-27 17:13:18 +0000650 }
651
robbiewd34d5812005-07-11 22:28:09 +0000652#if !defined(UCLINUX)
alaffincc2e5552000-07-27 17:13:18 +0000653
Garrett Cooper903910d2010-11-23 09:27:44 -0800654 if (STD_TP_sbrk || STD_LP_sbrk) {
alaffincc2e5552000-07-27 17:13:18 +0000655 STD_start_break=sbrk(0); /* get original sbreak size */
656 }
657
Garrett Cooper903910d2010-11-23 09:27:44 -0800658 if (STD_TP_sbrk) {
alaffincc2e5552000-07-27 17:13:18 +0000659 sbrk(STD_TP_sbrk);
Garrett Cooper903910d2010-11-23 09:27:44 -0800660 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000661 printf("after sbrk(%d)\n", STD_TP_sbrk);
662 }
robbiewd34d5812005-07-11 22:28:09 +0000663
664#endif /* if !defined(UCLINUX) */
665#endif
alaffincc2e5552000-07-27 17:13:18 +0000666 return 0;
667}
668
669#define USECS_PER_SEC 1000000 /* microseconds per second */
670
671/***********************************************************************
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100672 * Returns current time in microseconds since 1970.
alaffincc2e5552000-07-27 17:13:18 +0000673 ***********************************************************************/
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100674static uint64_t get_current_time(void)
alaffincc2e5552000-07-27 17:13:18 +0000675{
676 struct timeval curtime;
alaffincc2e5552000-07-27 17:13:18 +0000677
678 gettimeofday(&curtime, NULL);
679
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100680 return (((uint64_t)curtime.tv_sec)*USECS_PER_SEC) + curtime.tv_usec;
alaffincc2e5552000-07-27 17:13:18 +0000681}
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
vapier45a8ba02009-07-20 10:59:32 +0000692 * have been met.
alaffincc2e5552000-07-27 17:13:18 +0000693 *
694 * counter integer is supplied by the user program.
695 ***********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800696int usc_test_looping(int counter)
alaffincc2e5552000-07-27 17:13:18 +0000697{
698 static int first_time = 1;
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100699 static uint64_t stop_time = 0;
700 static uint64_t delay;
701 uint64_t ct, end;
702 int keepgoing = 0;
alaffincc2e5552000-07-27 17:13:18 +0000703
704 /*
vapier45a8ba02009-07-20 10:59:32 +0000705 * If this is the first iteration and we are looping for
alaffincc2e5552000-07-27 17:13:18 +0000706 * duration of STD_LOOP_DURATION seconds (fractional) or
707 * doing loop delays, get the clocks per second.
708 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800709 if (first_time) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800710 first_time = 0;
alaffincc2e5552000-07-27 17:13:18 +0000711
712 /*
713 * If looping for duration, calculate stop time in
714 * clocks.
715 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800716 if (STD_LOOP_DURATION) {
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100717 stop_time = (uint64_t)(USECS_PER_SEC * STD_LOOP_DURATION)
718 + get_current_time();
alaffincc2e5552000-07-27 17:13:18 +0000719 }
720
721 /*
722 * If doing delay each iteration, calcuate the number
723 * of clocks for each delay.
724 */
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100725 if (STD_LOOP_DELAY)
726 delay = USECS_PER_SEC * STD_LOOP_DELAY;
alaffincc2e5552000-07-27 17:13:18 +0000727 }
vapier45a8ba02009-07-20 10:59:32 +0000728
alaffincc2e5552000-07-27 17:13:18 +0000729 /*
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 Cooper903910d2010-11-23 09:27:44 -0800735 else if (STD_LOOP_DELAY) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800736 ct = get_current_time();
737 end = ct + delay;
Garrett Cooper903910d2010-11-23 09:27:44 -0800738 while (ct < end) {
alaffincc2e5552000-07-27 17:13:18 +0000739 /*
740 * The following are special test hooks in the delay loop.
741 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800742 if (STD_LD_recfun) {
743 if (Debug)
vapier45a8ba02009-07-20 10:59:32 +0000744 printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
alaffincc2e5552000-07-27 17:13:18 +0000745 STD_LD_recfun);
subrata_modakb2f47f32007-04-11 04:17:56 +0000746 usc_recressive_func(0, STD_LD_recfun, *STD_bigstack);
alaffincc2e5552000-07-27 17:13:18 +0000747 }
748
749 ct=get_current_time();
750 }
751 }
752
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100753 if (STD_INFINITE)
mreed10ef038182006-04-19 18:23:40 +0000754 keepgoing++;
alaffincc2e5552000-07-27 17:13:18 +0000755
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100756 if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT)
alaffincc2e5552000-07-27 17:13:18 +0000757 keepgoing++;
alaffincc2e5552000-07-27 17:13:18 +0000758
Cyril Hrubis4d964f62012-03-07 18:02:37 +0100759 if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time)
alaffincc2e5552000-07-27 17:13:18 +0000760 keepgoing++;
alaffincc2e5552000-07-27 17:13:18 +0000761
Garrett Cooper903910d2010-11-23 09:27:44 -0800762 if (keepgoing == 0)
alaffincc2e5552000-07-27 17:13:18 +0000763 return 0;
764
765 /*
766 * The following code allows special system testing hooks.
767 */
768
Garrett Cooper903910d2010-11-23 09:27:44 -0800769 if (STD_LP_recfun) {
770 if (Debug)
vapier45a8ba02009-07-20 10:59:32 +0000771 printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
alaffincc2e5552000-07-27 17:13:18 +0000772 STD_LP_recfun);
subrata_modakb2f47f32007-04-11 04:17:56 +0000773 usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
alaffincc2e5552000-07-27 17:13:18 +0000774 }
775
robbiewd34d5812005-07-11 22:28:09 +0000776#if !defined(UCLINUX)
Garrett Cooper903910d2010-11-23 09:27:44 -0800777 if (STD_LP_sbrk) {
778 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000779 printf("about to do sbrk(%d)\n", STD_LP_sbrk);
780 sbrk(STD_LP_sbrk);
781 }
robbiewd34d5812005-07-11 22:28:09 +0000782#endif
alaffincc2e5552000-07-27 17:13:18 +0000783
alaffincc2e5552000-07-27 17:13:18 +0000784
Garrett Cooper903910d2010-11-23 09:27:44 -0800785 if (keepgoing)
alaffincc2e5552000-07-27 17:13:18 +0000786 return 1;
787 else
788 return 0; /* done - stop iterating */
789}
790
791
792/*
793 * This function recressively calls itself max times.
vapier45a8ba02009-07-20 10:59:32 +0000794 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800795static void usc_recressive_func(int cnt, int max, struct usc_bigstack_t bstack)
alaffincc2e5552000-07-27 17:13:18 +0000796{
Garrett Cooper903910d2010-11-23 09:27:44 -0800797 if (cnt < max)
alaffincc2e5552000-07-27 17:13:18 +0000798 usc_recressive_func(cnt+1, max, bstack);
799
800}
801
802#if UNIT_TEST
803/******************************************************************************
804 * UNIT TEST CODE
805 * UNIT TEST CODE
vapier45a8ba02009-07-20 10:59:32 +0000806 *
alaffincc2e5552000-07-27 17:13:18 +0000807 * this following code is provide so that unit testing can
808 * be done fairly easily.
809 ******************************************************************************/
810
811int Help = 0;
812int Help2 = 0;
813char *ptr;
814
815/*
816 * Code from usctest.h that not part of this file since we are the library.
817 */
818
819struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
820
Markos Chandrasfd4ada72012-01-03 11:10:37 +0000821long TEST_RETURN;
alaffincc2e5552000-07-27 17:13:18 +0000822int TEST_ERRNO;
823
alaffincc2e5552000-07-27 17:13:18 +0000824/* for test specific parse_opts options */
825option_t Options[] = {
826 { "help", &Help2, NULL }, /* -help option */
827 { "h", &Help, NULL }, /* -h option */
alaffincc2e5552000-07-27 17:13:18 +0000828
829#if INVALID_TEST_CASES
830 { "missingflag", NULL, &ptr }, /* error */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800831 { "missingarg:", &Help, NULL }, /* error */
832#endif /* INVALID_TEST_CASES */
alaffincc2e5552000-07-27 17:13:18 +0000833
834 { NULL, NULL, NULL }
835};
836
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800837int main(int argc, char **argv)
alaffincc2e5552000-07-27 17:13:18 +0000838{
839 int lc;
840 char *msg;
841 struct timeval t;
842 int cnt;
843
Markos Chandrasfd4ada72012-01-03 11:10:37 +0000844 if ((msg = parse_opts(argc, argv, Options, NULL)) != NULL) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800845 printf("ERROR: %s\n", msg);
alaffincc2e5552000-07-27 17:13:18 +0000846 exit(1);
847 }
848
alaffincc2e5552000-07-27 17:13:18 +0000849 TEST_PAUSE;
850
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800851 for (lc = 0; TEST_LOOPING(lc); lc++) {
vapier45a8ba02009-07-20 10:59:32 +0000852
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800853 TEST(gettimeofday(&t, NULL));
alaffincc2e5552000-07-27 17:13:18 +0000854 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 Cooper8b02c1c2011-01-26 01:34:49 -0800864#endif /* UNIT_TEST */