blob: 358106ed8549848791d6ea7d615aad1a271ba967 [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>
80
81
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 */
297 options |= OPT_copies;
298 STD_COPIES = atoi(optarg);
299 break;
300 case 'f': /* Functional testing */
301 STD_FUNCTIONAL_TEST = 0;
302 break;
303 case 'p': /* Pause for SIGUSR1 */
304 STD_PAUSE = 1;
305 break;
306 case 't': /* syscall timing */
307 STD_TIMING_ON = 1;
308 break;
309 case 'e': /* errno loggin */
310 STD_ERRNO_LOG = 1;
311 break;
312 case 'h': /* Help */
313 print_help(uhf);
314 exit(0);
315 break;
robbiewd34d5812005-07-11 22:28:09 +0000316#ifdef UCLINUX
317 case 'C': /* Run child */
318 child_args = optarg;
319 break;
320#endif
nstraz94181082000-08-30 18:43:38 +0000321 default:
vapier45a8ba02009-07-20 10:59:32 +0000322
alaffincc2e5552000-07-27 17:13:18 +0000323 /* Check all the user specified options */
324 found=0;
Garrett Cooper903910d2010-11-23 09:27:44 -0800325 for (i = 0; user_optarr[i].option; ++i) {
alaffincc2e5552000-07-27 17:13:18 +0000326
nstraz94181082000-08-30 18:43:38 +0000327 if (opt == user_optarr[i].option[0]) {
alaffincc2e5552000-07-27 17:13:18 +0000328 /* Yup, This is a user option, set the flag and look for argument */
Garrett Cooper903910d2010-11-23 09:27:44 -0800329 if (user_optarr[i].flag) {
nstraz94181082000-08-30 18:43:38 +0000330 *user_optarr[i].flag=1;
alaffincc2e5552000-07-27 17:13:18 +0000331 }
332 found++;
333
alaffincc2e5552000-07-27 17:13:18 +0000334 /* save the argument at the user's location */
Garrett Cooper903910d2010-11-23 09:27:44 -0800335 if (user_optarr[i].option[strlen(user_optarr[i].option)-1] == ':') {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800336 *user_optarr[i].arg = optarg;
alaffincc2e5552000-07-27 17:13:18 +0000337 }
338 break; /* option found - break out of the for loop */
339 }
340 }
341 /* This condition "should never happen". SO CHECK FOR IT!!!! */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800342 if (!found) {
alaffincc2e5552000-07-27 17:13:18 +0000343 sprintf(Mesg2,
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800344 "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
345 "ERROR", opt);
alaffincc2e5552000-07-27 17:13:18 +0000346 return(Mesg2);
347 }
348 }
349
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800350 } /* end of while */
robbiew0ea4e1b2004-01-05 21:12:51 +0000351 free(optionstr);
alaffincc2e5552000-07-27 17:13:18 +0000352
nstraz94181082000-08-30 18:43:38 +0000353 STD_argind = optind;
alaffincc2e5552000-07-27 17:13:18 +0000354
355 /*
356 * Turn on debug
357 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800358 if ((ptr = getenv("USC_DEBUG")) != NULL) {
359 Debug = 1;
alaffincc2e5552000-07-27 17:13:18 +0000360 printf("env USC_DEBUG is defined, turning on debug\n");
361 }
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800362 if ((ptr = getenv("USC_VERBOSE")) != NULL) {
363 Debug = 1;
alaffincc2e5552000-07-27 17:13:18 +0000364 printf("env USC_VERBOSE is defined, turning on debug\n");
365 }
366
367 /*
368 * If the USC_ITERATION_ENV environmental variable is set to
369 * a number, use that number as iteration count (same as -c option).
370 * The -c option with arg will be used even if this env var is set.
371 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800372 if (!(options & OPT_iteration) && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800373 if (sscanf(ptr, "%i", &k) == 1) {
374 if (k == 0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800375 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800376 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000377 printf("Using env %s, set STD_INFINITE to 1\n",
378 USC_ITERATION_ENV);
379 } else { /* else, set the loop count to the arguement */
380 STD_LOOP_COUNT=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800381 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000382 printf("Using env %s, set STD_LOOP_COUNT to %d\n",
383 USC_ITERATION_ENV, k);
384 }
385 }
386 }
387
388 /*
389 * If the USC_NO_FUNC_CHECK environmental variable is set, we'll
390 * unset the STD_FUNCTIONAL_TEST variable.
391 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800392 if (!(options & OPT_nofunccheck) &&
393 (ptr = getenv(USC_NO_FUNC_CHECK)) != NULL) {
alaffincc2e5552000-07-27 17:13:18 +0000394 STD_FUNCTIONAL_TEST=0; /* Turn off functional testing */
Garrett Cooper903910d2010-11-23 09:27:44 -0800395 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000396 printf("Using env %s, set STD_FUNCTIONAL_TEST to 0\n",
397 USC_NO_FUNC_CHECK);
398 }
399
400 /*
401 * If the USC_LOOP_WALLTIME environmental variable is set,
402 * use that number as duration (same as -I option).
403 * The -I option with arg will be used even if this env var is set.
404 */
405
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800406 if (!(options & OPT_duration) &&
407 (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800408 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800409 STD_LOOP_DURATION = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800410 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000411 printf("Using env %s, set STD_LOOP_DURATION to %f\n",
412 USC_LOOP_WALLTIME, ftmp);
Garrett Cooper903910d2010-11-23 09:27:44 -0800413 if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800414 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800415 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000416 printf("Using env %s, set STD_INFINITE to 1\n", USC_LOOP_WALLTIME);
417 }
418 }
419 }
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800420 if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800421 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800422 STD_LOOP_DURATION = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800423 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000424 printf("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n", ftmp);
Garrett Cooper903910d2010-11-23 09:27:44 -0800425 if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800426 STD_INFINITE = 1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800427 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000428 printf("Using env USC_DURATION, set STD_INFINITE to 1\n");
429 }
430 }
431 }
432 /*
433 * If the USC_LOOP_DELAY environmental variable is set,
434 * use that number as delay in factional seconds (same as -P option).
435 * The -P option with arg will be used even if this env var is set.
436 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800437 if (!(options & OPT_delay) && (ptr = getenv(USC_LOOP_DELAY)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800438 if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800439 STD_LOOP_DELAY = ftmp;
Garrett Cooper903910d2010-11-23 09:27:44 -0800440 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000441 printf("Using env %s, set STD_LOOP_DELAY = %f\n",
442 USC_LOOP_DELAY, ftmp);
443 }
444 }
445
446 /*
447 * If the USC_COPIES environmental variable is set,
448 * use that number as copies (same as -c option).
449 * The -c option with arg will be used even if this env var is set.
450 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800451 if (!(options & OPT_copies) && (ptr = getenv(USC_COPIES)) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800452 if (sscanf(ptr, "%d", &STD_COPIES) == 1 && STD_COPIES >= 0) {
453 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000454 printf("Using env %s, set STD_COPIES = %d\n",
455 USC_COPIES, STD_COPIES);
456 }
457 }
458
459 /*
460 * The following are special system testing envs to turn on special
461 * hooks in the code.
462 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800463 if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
464 if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
alaffincc2e5552000-07-27 17:13:18 +0000465 STD_TP_barrier=k;
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800466 else
alaffincc2e5552000-07-27 17:13:18 +0000467 STD_TP_barrier=1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800468 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000469 printf("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
470 STD_TP_barrier);
471 }
472
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800473 if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
474 if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
alaffincc2e5552000-07-27 17:13:18 +0000475 STD_LP_barrier=k;
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800476 else
alaffincc2e5552000-07-27 17:13:18 +0000477 STD_LP_barrier=1;
Garrett Cooper903910d2010-11-23 09:27:44 -0800478 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000479 printf("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
480 STD_LP_barrier);
481 }
482
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800483 if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800484 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000485 STD_TP_shmem_sz=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800486 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000487 printf("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
488 STD_TP_shmem_sz);
489 }
490 }
491
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800492 if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800493 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000494 STD_LP_shmem=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800495 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000496 printf("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
497 STD_LP_shmem);
498 }
499 }
500
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800501 if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800502 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000503 STD_LD_shmem=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800504 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000505 printf("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
506 STD_LD_shmem);
507 }
508 }
509
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800510 if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800511 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
alaffincc2e5552000-07-27 17:13:18 +0000512 STD_TP_sbrk=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800513 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000514 printf("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
515 STD_TP_sbrk);
516 }
517 }
518
robbiewd34d5812005-07-11 22:28:09 +0000519#if !defined(UCLINUX)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800520 if ((ptr = getenv("USC_LP_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_LP_sbrk=k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800523 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000524 printf("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
525 STD_LP_sbrk);
526 }
527 }
robbiewd34d5812005-07-11 22:28:09 +0000528#endif /* if !defined(UCLINUX) */
alaffincc2e5552000-07-27 17:13:18 +0000529
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800530 if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800531 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800532 STD_LP_recfun = k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800533 if (STD_bigstack != NULL)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800534 STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
Garrett Cooper903910d2010-11-23 09:27:44 -0800535 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000536 printf("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
537 STD_LP_recfun);
538 }
539 }
540
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800541 if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
Garrett Cooper903910d2010-11-23 09:27:44 -0800542 if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800543 STD_LD_recfun = k;
Garrett Cooper903910d2010-11-23 09:27:44 -0800544 if (STD_bigstack != NULL)
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800545 STD_bigstack = malloc(sizeof(struct usc_bigstack_t));
Garrett Cooper903910d2010-11-23 09:27:44 -0800546 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000547 printf("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
548 STD_LD_recfun);
549 }
550 }
vapier45a8ba02009-07-20 10:59:32 +0000551
alaffincc2e5552000-07-27 17:13:18 +0000552#if UNIT_TEST
553 printf("The following variables after option and env parsing:\n");
554 printf("STD_FUNCTIONAL_TEST = %d\n", STD_FUNCTIONAL_TEST);
555 printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION);
556 printf("STD_LOOP_DELAY = %f\n", STD_LOOP_DELAY);
557 printf("STD_COPIES = %d\n", STD_COPIES);
558 printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT);
559 printf("STD_INFINITE = %d\n", STD_INFINITE);
560 printf("STD_TIMING_ON = %d\n", STD_TIMING_ON);
561 printf("STD_ERRNO_LOG = %d\n", STD_ERRNO_LOG);
562 printf("STD_PAUSE = %d\n", STD_PAUSE);
563#endif
564
565 return((char *) NULL);
566
567} /* end of parse_opts */
568
alaffincc2e5552000-07-27 17:13:18 +0000569/*********************************************************************
nstraz94181082000-08-30 18:43:38 +0000570 * print_help() - print help message and user help message
alaffincc2e5552000-07-27 17:13:18 +0000571 *********************************************************************/
nstraz94181082000-08-30 18:43:38 +0000572void print_help(void (*user_help)())
alaffincc2e5552000-07-27 17:13:18 +0000573{
nstraz94181082000-08-30 18:43:38 +0000574 STD_opts_help();
alaffincc2e5552000-07-27 17:13:18 +0000575
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800576 if (user_help)
577 user_help();
alaffincc2e5552000-07-27 17:13:18 +0000578}
579
580/*********************************************************************
581 * STD_opts_help() - return a help string for the STD_OPTIONS.
582 *********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800583void STD_opts_help()
alaffincc2e5552000-07-27 17:13:18 +0000584{
nstraz94181082000-08-30 18:43:38 +0000585 int i;
alaffincc2e5552000-07-27 17:13:18 +0000586
Garrett Cooper903910d2010-11-23 09:27:44 -0800587 for (i = 0; std_options[i].optstr; ++i) {
nstraz94181082000-08-30 18:43:38 +0000588 if (std_options[i].help)
vapier1820d282009-07-20 04:48:17 +0000589 printf("%s", std_options[i].help);
alaffincc2e5552000-07-27 17:13:18 +0000590 }
alaffincc2e5552000-07-27 17:13:18 +0000591}
592
vapier45a8ba02009-07-20 10:59:32 +0000593/*
alaffincc2e5552000-07-27 17:13:18 +0000594 * routine to goto when we get the SIGUSR1 for STD_PAUSE
595 */
596void STD_go(int sig)
597{
598 return;
599}
600
601/***********************************************************************
602 * This function will do desired end of global setup test
603 * hooks.
604 * Currently it will only do a pause waiting for sigusr1 if
605 * STD_PAUSE is set.
606 *
607 ***********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800608int usc_global_setup_hook()
alaffincc2e5552000-07-27 17:13:18 +0000609{
robbiewd34d5812005-07-11 22:28:09 +0000610#ifndef UCLINUX
alaffincc2e5552000-07-27 17:13:18 +0000611 int cnt;
nstraz94181082000-08-30 18:43:38 +0000612 /* temp variable to store old signal action to be restored after pause */
613 int (*_TMP_FUNC)(void);
alaffincc2e5552000-07-27 17:13:18 +0000614
615 /*
616 * Fork STD_COPIES-1 copies.
617 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800618 for (cnt=1;cnt<STD_COPIES;cnt++) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800619 switch (fork() ) {
alaffincc2e5552000-07-27 17:13:18 +0000620 case -1:
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800621 fprintf(stderr, "%s: fork failed: %d - %s\n",
622 __FILE__, errno, strerror(errno));
alaffincc2e5552000-07-27 17:13:18 +0000623 break;
624 case 0: /* child */
625 cnt=STD_COPIES; /* to stop the forking */
626 break;
627
628 default: /* parent */
629 break;
630 }
631 }
vapier45a8ba02009-07-20 10:59:32 +0000632
alaffincc2e5552000-07-27 17:13:18 +0000633 /*
634 * pause waiting for sigusr1.
635 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800636 if (STD_PAUSE) {
vapier45a8ba02009-07-20 10:59:32 +0000637 _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go);
638 pause();
639 signal(SIGUSR1, (void (*)())_TMP_FUNC);
alaffincc2e5552000-07-27 17:13:18 +0000640 }
641
robbiewd34d5812005-07-11 22:28:09 +0000642#if !defined(UCLINUX)
alaffincc2e5552000-07-27 17:13:18 +0000643
Garrett Cooper903910d2010-11-23 09:27:44 -0800644 if (STD_TP_sbrk || STD_LP_sbrk) {
alaffincc2e5552000-07-27 17:13:18 +0000645 STD_start_break=sbrk(0); /* get original sbreak size */
646 }
647
Garrett Cooper903910d2010-11-23 09:27:44 -0800648 if (STD_TP_sbrk) {
alaffincc2e5552000-07-27 17:13:18 +0000649 sbrk(STD_TP_sbrk);
Garrett Cooper903910d2010-11-23 09:27:44 -0800650 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000651 printf("after sbrk(%d)\n", STD_TP_sbrk);
652 }
robbiewd34d5812005-07-11 22:28:09 +0000653
654#endif /* if !defined(UCLINUX) */
655#endif
alaffincc2e5552000-07-27 17:13:18 +0000656 return 0;
657}
658
659#define USECS_PER_SEC 1000000 /* microseconds per second */
660
661/***********************************************************************
662 * This function returns the number of get_current_time()'s return
663 * per second.
664 ***********************************************************************/
665
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800666static int get_timepersec()
alaffincc2e5552000-07-27 17:13:18 +0000667{
alaffincc2e5552000-07-27 17:13:18 +0000668 return USECS_PER_SEC; /* microseconds per second */
alaffincc2e5552000-07-27 17:13:18 +0000669
670}
671
672/***********************************************************************
nstraz94181082000-08-30 18:43:38 +0000673 * this function will get current time in microseconds since 1970.
alaffincc2e5552000-07-27 17:13:18 +0000674 ***********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800675static int get_current_time()
alaffincc2e5552000-07-27 17:13:18 +0000676{
677 struct timeval curtime;
alaffincc2e5552000-07-27 17:13:18 +0000678
679 gettimeofday(&curtime, NULL);
680
681 /* microseconds since 1970 */
682 return (curtime.tv_sec*USECS_PER_SEC) + curtime.tv_usec;
alaffincc2e5552000-07-27 17:13:18 +0000683}
684
685/***********************************************************************
686 *
687 * This function will determine if test should continue iterating
688 * If the STD_INFINITE flag is set, return 1.
689 * If the STD_LOOP_COUNT variable is set, compare it against
690 * the counter.
691 * If the STD_LOOP_DURATION variable is set, compare current time against
692 * calculated stop_time.
693 * This function will return 1 until all desired looping methods
vapier45a8ba02009-07-20 10:59:32 +0000694 * have been met.
alaffincc2e5552000-07-27 17:13:18 +0000695 *
696 * counter integer is supplied by the user program.
697 ***********************************************************************/
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800698int usc_test_looping(int counter)
alaffincc2e5552000-07-27 17:13:18 +0000699{
700 static int first_time = 1;
701 static int stop_time = 0; /* stop time in rtc or usecs */
702 static int delay; /* delay in clocks or usecs */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800703 int hertz = 0; /* clocks per second or usecs per second */
alaffincc2e5552000-07-27 17:13:18 +0000704 int ct, end; /* current time, end delay time */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800705 int keepgoing = 0; /* used to determine return value */
alaffincc2e5552000-07-27 17:13:18 +0000706
707 /*
vapier45a8ba02009-07-20 10:59:32 +0000708 * If this is the first iteration and we are looping for
alaffincc2e5552000-07-27 17:13:18 +0000709 * duration of STD_LOOP_DURATION seconds (fractional) or
710 * doing loop delays, get the clocks per second.
711 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800712 if (first_time) {
alaffincc2e5552000-07-27 17:13:18 +0000713
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800714 first_time = 0;
Garrett Cooper903910d2010-11-23 09:27:44 -0800715 if (STD_LOOP_DELAY || STD_LOOP_DURATION) {
mridgee6508f82005-01-04 21:00:17 +0000716 hertz = get_timepersec();
alaffincc2e5552000-07-27 17:13:18 +0000717 }
718
719 /*
720 * If looping for duration, calculate stop time in
721 * clocks.
722 */
vapier45a8ba02009-07-20 10:59:32 +0000723
Garrett Cooper903910d2010-11-23 09:27:44 -0800724 if (STD_LOOP_DURATION) {
alaffincc2e5552000-07-27 17:13:18 +0000725 ct=get_current_time();
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800726 stop_time = (int)((float)hertz * STD_LOOP_DURATION) + ct;
alaffincc2e5552000-07-27 17:13:18 +0000727 }
728
729 /*
730 * If doing delay each iteration, calcuate the number
731 * of clocks for each delay.
732 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800733 if (STD_LOOP_DELAY) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800734 delay = (int)((float)hertz * STD_LOOP_DELAY);
alaffincc2e5552000-07-27 17:13:18 +0000735 }
736
737 }
vapier45a8ba02009-07-20 10:59:32 +0000738
alaffincc2e5552000-07-27 17:13:18 +0000739 /*
740 * if delay each iteration, loop for delay clocks.
741 * This will not be done on first iteration.
742 * The delay will happen before determining if
743 * there will be another iteration.
744 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800745 else if (STD_LOOP_DELAY) {
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800746 ct = get_current_time();
747 end = ct + delay;
Garrett Cooper903910d2010-11-23 09:27:44 -0800748 while (ct < end) {
alaffincc2e5552000-07-27 17:13:18 +0000749 /*
750 * The following are special test hooks in the delay loop.
751 */
Garrett Cooper903910d2010-11-23 09:27:44 -0800752 if (STD_LD_recfun) {
753 if (Debug)
vapier45a8ba02009-07-20 10:59:32 +0000754 printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
alaffincc2e5552000-07-27 17:13:18 +0000755 STD_LD_recfun);
subrata_modakb2f47f32007-04-11 04:17:56 +0000756 usc_recressive_func(0, STD_LD_recfun, *STD_bigstack);
alaffincc2e5552000-07-27 17:13:18 +0000757 }
758
759 ct=get_current_time();
760 }
761 }
762
Garrett Cooper903910d2010-11-23 09:27:44 -0800763 if (STD_INFINITE) {
mreed10ef038182006-04-19 18:23:40 +0000764 keepgoing++;
alaffincc2e5552000-07-27 17:13:18 +0000765 }
766
Garrett Cooper903910d2010-11-23 09:27:44 -0800767 if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT) {
alaffincc2e5552000-07-27 17:13:18 +0000768 keepgoing++;
mreed10ef038182006-04-19 18:23:40 +0000769 }
alaffincc2e5552000-07-27 17:13:18 +0000770
Garrett Cooper903910d2010-11-23 09:27:44 -0800771 if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time) {
alaffincc2e5552000-07-27 17:13:18 +0000772 keepgoing++;
mreed10ef038182006-04-19 18:23:40 +0000773 }
alaffincc2e5552000-07-27 17:13:18 +0000774
Garrett Cooper903910d2010-11-23 09:27:44 -0800775 if (keepgoing == 0)
alaffincc2e5552000-07-27 17:13:18 +0000776 return 0;
777
778 /*
779 * The following code allows special system testing hooks.
780 */
781
Garrett Cooper903910d2010-11-23 09:27:44 -0800782 if (STD_LP_recfun) {
783 if (Debug)
vapier45a8ba02009-07-20 10:59:32 +0000784 printf("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
alaffincc2e5552000-07-27 17:13:18 +0000785 STD_LP_recfun);
subrata_modakb2f47f32007-04-11 04:17:56 +0000786 usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
alaffincc2e5552000-07-27 17:13:18 +0000787 }
788
robbiewd34d5812005-07-11 22:28:09 +0000789#if !defined(UCLINUX)
790
Garrett Cooper903910d2010-11-23 09:27:44 -0800791 if (STD_LP_sbrk) {
792 if (Debug)
alaffincc2e5552000-07-27 17:13:18 +0000793 printf("about to do sbrk(%d)\n", STD_LP_sbrk);
794 sbrk(STD_LP_sbrk);
795 }
robbiewd34d5812005-07-11 22:28:09 +0000796#endif
alaffincc2e5552000-07-27 17:13:18 +0000797
alaffincc2e5552000-07-27 17:13:18 +0000798
Garrett Cooper903910d2010-11-23 09:27:44 -0800799 if (keepgoing)
alaffincc2e5552000-07-27 17:13:18 +0000800 return 1;
801 else
802 return 0; /* done - stop iterating */
803}
804
805
806/*
807 * This function recressively calls itself max times.
vapier45a8ba02009-07-20 10:59:32 +0000808 */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800809static void usc_recressive_func(int cnt, int max, struct usc_bigstack_t bstack)
alaffincc2e5552000-07-27 17:13:18 +0000810{
Garrett Cooper903910d2010-11-23 09:27:44 -0800811 if (cnt < max)
alaffincc2e5552000-07-27 17:13:18 +0000812 usc_recressive_func(cnt+1, max, bstack);
813
814}
815
816#if UNIT_TEST
817/******************************************************************************
818 * UNIT TEST CODE
819 * UNIT TEST CODE
vapier45a8ba02009-07-20 10:59:32 +0000820 *
alaffincc2e5552000-07-27 17:13:18 +0000821 * this following code is provide so that unit testing can
822 * be done fairly easily.
823 ******************************************************************************/
824
825int Help = 0;
826int Help2 = 0;
827char *ptr;
828
829/*
830 * Code from usctest.h that not part of this file since we are the library.
831 */
832
833struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
834
alaffincc2e5552000-07-27 17:13:18 +0000835int TEST_RETURN;
836int TEST_ERRNO;
837
alaffincc2e5552000-07-27 17:13:18 +0000838/* for test specific parse_opts options */
839option_t Options[] = {
840 { "help", &Help2, NULL }, /* -help option */
841 { "h", &Help, NULL }, /* -h option */
842 { TIMING, NULL, NULL}, /* disable -timing option */
843
844#if INVALID_TEST_CASES
845 { "missingflag", NULL, &ptr }, /* error */
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800846 { "missingarg:", &Help, NULL }, /* error */
847#endif /* INVALID_TEST_CASES */
alaffincc2e5552000-07-27 17:13:18 +0000848
849 { NULL, NULL, NULL }
850};
851
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800852int main(int argc, char **argv)
alaffincc2e5552000-07-27 17:13:18 +0000853{
854 int lc;
855 char *msg;
856 struct timeval t;
857 int cnt;
858
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800859 if ((msg = parse_opts(argc, argv, Options)) != NULL) {
860 printf("ERROR: %s\n", msg);
alaffincc2e5552000-07-27 17:13:18 +0000861 exit(1);
862 }
863
alaffincc2e5552000-07-27 17:13:18 +0000864 TEST_PAUSE;
865
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800866 for (lc = 0; TEST_LOOPING(lc); lc++) {
vapier45a8ba02009-07-20 10:59:32 +0000867
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800868 TEST(gettimeofday(&t, NULL));
alaffincc2e5552000-07-27 17:13:18 +0000869 printf("iter=%d: sec:%d, usec:%6.6d %s", lc+1, t.tv_sec,
870 t.tv_usec, ctime(&t.tv_sec));
871 }
872
873
874 TEST_CLEANUP;
875
876 exit(0);
877}
878
Garrett Cooper8b02c1c2011-01-26 01:34:49 -0800879#endif /* UNIT_TEST */