1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : William Roske/Richard Logan
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify it
6*49cdfc7eSAndroid Build Coastguard Worker * under the terms of version 2 of the GNU General Public License as
7*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation.
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful, but
10*49cdfc7eSAndroid Build Coastguard Worker * WITHOUT ANY WARRANTY; without even the implied warranty of
11*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12*49cdfc7eSAndroid Build Coastguard Worker *
13*49cdfc7eSAndroid Build Coastguard Worker * Further, this software is distributed without any warranty that it is
14*49cdfc7eSAndroid Build Coastguard Worker * free of the rightful claim of any third person regarding infringement
15*49cdfc7eSAndroid Build Coastguard Worker * or the like. Any license provided herein, whether implied or
16*49cdfc7eSAndroid Build Coastguard Worker * otherwise, applies only to this software file. Patent licenses, if
17*49cdfc7eSAndroid Build Coastguard Worker * any, provided herein do not apply to combinations of this program with
18*49cdfc7eSAndroid Build Coastguard Worker * other software, or any other product whatsoever.
19*49cdfc7eSAndroid Build Coastguard Worker *
20*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License along
21*49cdfc7eSAndroid Build Coastguard Worker * with this program; if not, write the Free Software Foundation, Inc.,
22*49cdfc7eSAndroid Build Coastguard Worker * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23*49cdfc7eSAndroid Build Coastguard Worker *
24*49cdfc7eSAndroid Build Coastguard Worker * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25*49cdfc7eSAndroid Build Coastguard Worker * Mountain View, CA 94043, or:
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * http://www.sgi.com
28*49cdfc7eSAndroid Build Coastguard Worker *
29*49cdfc7eSAndroid Build Coastguard Worker * For further information regarding this notice, see:
30*49cdfc7eSAndroid Build Coastguard Worker *
31*49cdfc7eSAndroid Build Coastguard Worker * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
32*49cdfc7eSAndroid Build Coastguard Worker */
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker #include "config.h"
35*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
36*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
37*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
38*49cdfc7eSAndroid Build Coastguard Worker #include <sys/param.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <sys/signal.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h>
44*49cdfc7eSAndroid Build Coastguard Worker
45*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
46*49cdfc7eSAndroid Build Coastguard Worker #include "ltp_priv.h"
47*49cdfc7eSAndroid Build Coastguard Worker #include "usctest.h"
48*49cdfc7eSAndroid Build Coastguard Worker #include "tst_clocks.h"
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker #ifndef UNIT_TEST
51*49cdfc7eSAndroid Build Coastguard Worker #define UNIT_TEST 0
52*49cdfc7eSAndroid Build Coastguard Worker #endif
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker /* Define flags and args for standard options */
55*49cdfc7eSAndroid Build Coastguard Worker static int STD_INFINITE = 0; /* flag indciating to loop forever */
56*49cdfc7eSAndroid Build Coastguard Worker int STD_LOOP_COUNT = 1; /* number of iterations */
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker static float STD_LOOP_DURATION = 0.0; /* duration value in fractional seconds */
59*49cdfc7eSAndroid Build Coastguard Worker
60*49cdfc7eSAndroid Build Coastguard Worker static char **STD_opt_arr = NULL; /* array of option strings */
61*49cdfc7eSAndroid Build Coastguard Worker static int STD_argind = 1; /* argv index to next argv element */
62*49cdfc7eSAndroid Build Coastguard Worker /* (first argument) */
63*49cdfc7eSAndroid Build Coastguard Worker /* To getopt users, it is like optind */
64*49cdfc7eSAndroid Build Coastguard Worker
65*49cdfc7eSAndroid Build Coastguard Worker /*
66*49cdfc7eSAndroid Build Coastguard Worker * The following variables are to support system testing additions.
67*49cdfc7eSAndroid Build Coastguard Worker */
68*49cdfc7eSAndroid Build Coastguard Worker static int STD_TP_barrier = 0; /* flag to do barrier in TEST_PAUSE */
69*49cdfc7eSAndroid Build Coastguard Worker /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
70*49cdfc7eSAndroid Build Coastguard Worker static int STD_LP_barrier = 0; /* flag to do barrier in TEST_LOOPING */
71*49cdfc7eSAndroid Build Coastguard Worker /* 2 - wait_barrier(), 3 - set_barrier(), * - barrier() */
72*49cdfc7eSAndroid Build Coastguard Worker static int STD_TP_shmem_sz = 0; /* shmalloc this many words per pe in TEST_PAUSE */
73*49cdfc7eSAndroid Build Coastguard Worker static int STD_LD_shmem = 0; /* flag to do shmem_puts and shmem_gets during delay */
74*49cdfc7eSAndroid Build Coastguard Worker static int STD_LP_shmem = 0; /* flag to do shmem_puts and gets during TEST_LOOPING */
75*49cdfc7eSAndroid Build Coastguard Worker static int STD_LD_recfun = 0; /* do recressive function calls in loop delay */
76*49cdfc7eSAndroid Build Coastguard Worker static int STD_LP_recfun = 0; /* do recressive function calls in TEST_LOOPING */
77*49cdfc7eSAndroid Build Coastguard Worker static int STD_TP_sbrk = 0; /* do sbrk in TEST_PAUSE */
78*49cdfc7eSAndroid Build Coastguard Worker static int STD_LP_sbrk = 0; /* do sbrk in TEST_LOOPING */
79*49cdfc7eSAndroid Build Coastguard Worker static char *STD_start_break = 0; /* original sbrk size */
80*49cdfc7eSAndroid Build Coastguard Worker static int Debug = 0;
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker static struct std_option_t {
83*49cdfc7eSAndroid Build Coastguard Worker char *optstr;
84*49cdfc7eSAndroid Build Coastguard Worker char *help;
85*49cdfc7eSAndroid Build Coastguard Worker char *flag;
86*49cdfc7eSAndroid Build Coastguard Worker char **arg;
87*49cdfc7eSAndroid Build Coastguard Worker } std_options[] = {
88*49cdfc7eSAndroid Build Coastguard Worker {"h", " -h Show this help screen\n", NULL, NULL},
89*49cdfc7eSAndroid Build Coastguard Worker {"i:", " -i n Execute test n times\n", NULL, NULL},
90*49cdfc7eSAndroid Build Coastguard Worker {"I:", " -I x Execute test for x seconds\n", NULL, NULL},
91*49cdfc7eSAndroid Build Coastguard Worker {NULL, NULL, NULL, NULL}
92*49cdfc7eSAndroid Build Coastguard Worker };
93*49cdfc7eSAndroid Build Coastguard Worker
94*49cdfc7eSAndroid Build Coastguard Worker /*
95*49cdfc7eSAndroid Build Coastguard Worker * Structure for usc_recressive_func argument
96*49cdfc7eSAndroid Build Coastguard Worker */
97*49cdfc7eSAndroid Build Coastguard Worker struct usc_bigstack_t {
98*49cdfc7eSAndroid Build Coastguard Worker char space[4096];
99*49cdfc7eSAndroid Build Coastguard Worker };
100*49cdfc7eSAndroid Build Coastguard Worker
101*49cdfc7eSAndroid Build Coastguard Worker static struct usc_bigstack_t *STD_bigstack = NULL;
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker /* define the string length for Mesg and Mesg2 strings */
104*49cdfc7eSAndroid Build Coastguard Worker #define STRLEN 2048
105*49cdfc7eSAndroid Build Coastguard Worker
106*49cdfc7eSAndroid Build Coastguard Worker static char Mesg2[STRLEN]; /* holds possible return string */
107*49cdfc7eSAndroid Build Coastguard Worker static void usc_recressive_func();
108*49cdfc7eSAndroid Build Coastguard Worker
109*49cdfc7eSAndroid Build Coastguard Worker /*
110*49cdfc7eSAndroid Build Coastguard Worker * Define bits for options that might have env variable default
111*49cdfc7eSAndroid Build Coastguard Worker */
112*49cdfc7eSAndroid Build Coastguard Worker #define OPT_iteration 01
113*49cdfc7eSAndroid Build Coastguard Worker #define OPT_duration 04
114*49cdfc7eSAndroid Build Coastguard Worker #define OPT_delay 010
115*49cdfc7eSAndroid Build Coastguard Worker
print_help(void (* user_help)(void))116*49cdfc7eSAndroid Build Coastguard Worker static void print_help(void (*user_help)(void))
117*49cdfc7eSAndroid Build Coastguard Worker {
118*49cdfc7eSAndroid Build Coastguard Worker int i;
119*49cdfc7eSAndroid Build Coastguard Worker
120*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; std_options[i].optstr; ++i) {
121*49cdfc7eSAndroid Build Coastguard Worker if (std_options[i].help)
122*49cdfc7eSAndroid Build Coastguard Worker printf("%s", std_options[i].help);
123*49cdfc7eSAndroid Build Coastguard Worker }
124*49cdfc7eSAndroid Build Coastguard Worker
125*49cdfc7eSAndroid Build Coastguard Worker if (user_help)
126*49cdfc7eSAndroid Build Coastguard Worker user_help();
127*49cdfc7eSAndroid Build Coastguard Worker }
128*49cdfc7eSAndroid Build Coastguard Worker
129*49cdfc7eSAndroid Build Coastguard Worker /**********************************************************************
130*49cdfc7eSAndroid Build Coastguard Worker * parse_opts:
131*49cdfc7eSAndroid Build Coastguard Worker **********************************************************************/
parse_opts(int ac,char ** av,const option_t * user_optarr,void (* uhf)(void))132*49cdfc7eSAndroid Build Coastguard Worker const char *parse_opts(int ac, char **av, const option_t * user_optarr,
133*49cdfc7eSAndroid Build Coastguard Worker void (*uhf)(void))
134*49cdfc7eSAndroid Build Coastguard Worker {
135*49cdfc7eSAndroid Build Coastguard Worker int found; /* flag to indicate that an option specified was */
136*49cdfc7eSAndroid Build Coastguard Worker /* found in the user's list */
137*49cdfc7eSAndroid Build Coastguard Worker int k; /* scratch integer for returns and short time usage */
138*49cdfc7eSAndroid Build Coastguard Worker float ftmp; /* tmp float for parsing env variables */
139*49cdfc7eSAndroid Build Coastguard Worker char *ptr; /* used in getting env variables */
140*49cdfc7eSAndroid Build Coastguard Worker int options = 0; /* no options specified */
141*49cdfc7eSAndroid Build Coastguard Worker int optstrlen, i;
142*49cdfc7eSAndroid Build Coastguard Worker char *optionstr;
143*49cdfc7eSAndroid Build Coastguard Worker int opt;
144*49cdfc7eSAndroid Build Coastguard Worker
145*49cdfc7eSAndroid Build Coastguard Worker /*
146*49cdfc7eSAndroid Build Coastguard Worker * If not the first time this function is called, release the old STD_opt_arr
147*49cdfc7eSAndroid Build Coastguard Worker * vector.
148*49cdfc7eSAndroid Build Coastguard Worker */
149*49cdfc7eSAndroid Build Coastguard Worker if (STD_opt_arr != NULL) {
150*49cdfc7eSAndroid Build Coastguard Worker free(STD_opt_arr);
151*49cdfc7eSAndroid Build Coastguard Worker STD_opt_arr = NULL;
152*49cdfc7eSAndroid Build Coastguard Worker }
153*49cdfc7eSAndroid Build Coastguard Worker /* Calculate how much space we need for the option string */
154*49cdfc7eSAndroid Build Coastguard Worker optstrlen = 0;
155*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; std_options[i].optstr; ++i)
156*49cdfc7eSAndroid Build Coastguard Worker optstrlen += strlen(std_options[i].optstr);
157*49cdfc7eSAndroid Build Coastguard Worker if (user_optarr)
158*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; user_optarr[i].option; ++i) {
159*49cdfc7eSAndroid Build Coastguard Worker if (strlen(user_optarr[i].option) > 2)
160*49cdfc7eSAndroid Build Coastguard Worker return
161*49cdfc7eSAndroid Build Coastguard Worker "parse_opts: ERROR - Only short options are allowed";
162*49cdfc7eSAndroid Build Coastguard Worker optstrlen += strlen(user_optarr[i].option);
163*49cdfc7eSAndroid Build Coastguard Worker }
164*49cdfc7eSAndroid Build Coastguard Worker optstrlen += 1;
165*49cdfc7eSAndroid Build Coastguard Worker
166*49cdfc7eSAndroid Build Coastguard Worker /* Create the option string for getopt */
167*49cdfc7eSAndroid Build Coastguard Worker optionstr = malloc(optstrlen);
168*49cdfc7eSAndroid Build Coastguard Worker if (!optionstr)
169*49cdfc7eSAndroid Build Coastguard Worker return
170*49cdfc7eSAndroid Build Coastguard Worker "parse_opts: ERROR - Could not allocate memory for optionstr";
171*49cdfc7eSAndroid Build Coastguard Worker
172*49cdfc7eSAndroid Build Coastguard Worker optionstr[0] = '\0';
173*49cdfc7eSAndroid Build Coastguard Worker
174*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; std_options[i].optstr; ++i)
175*49cdfc7eSAndroid Build Coastguard Worker strcat(optionstr, std_options[i].optstr);
176*49cdfc7eSAndroid Build Coastguard Worker if (user_optarr)
177*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; user_optarr[i].option; ++i)
178*49cdfc7eSAndroid Build Coastguard Worker /* only add the option if it wasn't there already */
179*49cdfc7eSAndroid Build Coastguard Worker if (strchr(optionstr, user_optarr[i].option[0]) == NULL)
180*49cdfc7eSAndroid Build Coastguard Worker strcat(optionstr, user_optarr[i].option);
181*49cdfc7eSAndroid Build Coastguard Worker
182*49cdfc7eSAndroid Build Coastguard Worker /*
183*49cdfc7eSAndroid Build Coastguard Worker * Loop through av parsing options.
184*49cdfc7eSAndroid Build Coastguard Worker */
185*49cdfc7eSAndroid Build Coastguard Worker while ((opt = getopt(ac, av, optionstr)) > 0) {
186*49cdfc7eSAndroid Build Coastguard Worker
187*49cdfc7eSAndroid Build Coastguard Worker STD_argind = optind;
188*49cdfc7eSAndroid Build Coastguard Worker
189*49cdfc7eSAndroid Build Coastguard Worker switch (opt) {
190*49cdfc7eSAndroid Build Coastguard Worker case '?': /* Unknown option */
191*49cdfc7eSAndroid Build Coastguard Worker return "Unknown option";
192*49cdfc7eSAndroid Build Coastguard Worker break;
193*49cdfc7eSAndroid Build Coastguard Worker case ':': /* Missing Arg */
194*49cdfc7eSAndroid Build Coastguard Worker return "Missing argument";
195*49cdfc7eSAndroid Build Coastguard Worker break;
196*49cdfc7eSAndroid Build Coastguard Worker case 'i': /* Iterations */
197*49cdfc7eSAndroid Build Coastguard Worker options |= OPT_iteration;
198*49cdfc7eSAndroid Build Coastguard Worker STD_LOOP_COUNT = atoi(optarg);
199*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_COUNT == 0)
200*49cdfc7eSAndroid Build Coastguard Worker STD_INFINITE = 1;
201*49cdfc7eSAndroid Build Coastguard Worker break;
202*49cdfc7eSAndroid Build Coastguard Worker case 'I': /* Time duration */
203*49cdfc7eSAndroid Build Coastguard Worker options |= OPT_duration;
204*49cdfc7eSAndroid Build Coastguard Worker STD_LOOP_DURATION = atof(optarg);
205*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_DURATION == 0.0)
206*49cdfc7eSAndroid Build Coastguard Worker STD_INFINITE = 1;
207*49cdfc7eSAndroid Build Coastguard Worker break;
208*49cdfc7eSAndroid Build Coastguard Worker case 'h': /* Help */
209*49cdfc7eSAndroid Build Coastguard Worker print_help(uhf);
210*49cdfc7eSAndroid Build Coastguard Worker exit(0);
211*49cdfc7eSAndroid Build Coastguard Worker break;
212*49cdfc7eSAndroid Build Coastguard Worker default:
213*49cdfc7eSAndroid Build Coastguard Worker
214*49cdfc7eSAndroid Build Coastguard Worker /* Check all the user specified options */
215*49cdfc7eSAndroid Build Coastguard Worker found = 0;
216*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; user_optarr[i].option; ++i) {
217*49cdfc7eSAndroid Build Coastguard Worker
218*49cdfc7eSAndroid Build Coastguard Worker if (opt == user_optarr[i].option[0]) {
219*49cdfc7eSAndroid Build Coastguard Worker /* Yup, This is a user option, set the flag and look for argument */
220*49cdfc7eSAndroid Build Coastguard Worker if (user_optarr[i].flag) {
221*49cdfc7eSAndroid Build Coastguard Worker *user_optarr[i].flag = 1;
222*49cdfc7eSAndroid Build Coastguard Worker }
223*49cdfc7eSAndroid Build Coastguard Worker found++;
224*49cdfc7eSAndroid Build Coastguard Worker
225*49cdfc7eSAndroid Build Coastguard Worker /* save the argument at the user's location */
226*49cdfc7eSAndroid Build Coastguard Worker if (user_optarr[i].
227*49cdfc7eSAndroid Build Coastguard Worker option[strlen(user_optarr[i].option)
228*49cdfc7eSAndroid Build Coastguard Worker - 1] == ':') {
229*49cdfc7eSAndroid Build Coastguard Worker *user_optarr[i].arg = optarg;
230*49cdfc7eSAndroid Build Coastguard Worker }
231*49cdfc7eSAndroid Build Coastguard Worker break; /* option found - break out of the for loop */
232*49cdfc7eSAndroid Build Coastguard Worker }
233*49cdfc7eSAndroid Build Coastguard Worker }
234*49cdfc7eSAndroid Build Coastguard Worker /* This condition "should never happen". SO CHECK FOR IT!!!! */
235*49cdfc7eSAndroid Build Coastguard Worker if (!found) {
236*49cdfc7eSAndroid Build Coastguard Worker sprintf(Mesg2,
237*49cdfc7eSAndroid Build Coastguard Worker "parse_opts: ERROR - option:\"%c\" NOT FOUND... INTERNAL "
238*49cdfc7eSAndroid Build Coastguard Worker "ERROR", opt);
239*49cdfc7eSAndroid Build Coastguard Worker return (Mesg2);
240*49cdfc7eSAndroid Build Coastguard Worker }
241*49cdfc7eSAndroid Build Coastguard Worker }
242*49cdfc7eSAndroid Build Coastguard Worker
243*49cdfc7eSAndroid Build Coastguard Worker }
244*49cdfc7eSAndroid Build Coastguard Worker free(optionstr);
245*49cdfc7eSAndroid Build Coastguard Worker
246*49cdfc7eSAndroid Build Coastguard Worker STD_argind = optind;
247*49cdfc7eSAndroid Build Coastguard Worker
248*49cdfc7eSAndroid Build Coastguard Worker /*
249*49cdfc7eSAndroid Build Coastguard Worker * Turn on debug
250*49cdfc7eSAndroid Build Coastguard Worker */
251*49cdfc7eSAndroid Build Coastguard Worker if (getenv("USC_DEBUG") != NULL) {
252*49cdfc7eSAndroid Build Coastguard Worker Debug = 1;
253*49cdfc7eSAndroid Build Coastguard Worker printf("env USC_DEBUG is defined, turning on debug\n");
254*49cdfc7eSAndroid Build Coastguard Worker }
255*49cdfc7eSAndroid Build Coastguard Worker if (getenv("USC_VERBOSE") != NULL) {
256*49cdfc7eSAndroid Build Coastguard Worker Debug = 1;
257*49cdfc7eSAndroid Build Coastguard Worker printf("env USC_VERBOSE is defined, turning on debug\n");
258*49cdfc7eSAndroid Build Coastguard Worker }
259*49cdfc7eSAndroid Build Coastguard Worker
260*49cdfc7eSAndroid Build Coastguard Worker /*
261*49cdfc7eSAndroid Build Coastguard Worker * If the USC_ITERATION_ENV environmental variable is set to
262*49cdfc7eSAndroid Build Coastguard Worker * a number, use that number as iteration count (same as -c option).
263*49cdfc7eSAndroid Build Coastguard Worker * The -c option with arg will be used even if this env var is set.
264*49cdfc7eSAndroid Build Coastguard Worker */
265*49cdfc7eSAndroid Build Coastguard Worker if (!(options & OPT_iteration)
266*49cdfc7eSAndroid Build Coastguard Worker && (ptr = getenv(USC_ITERATION_ENV)) != NULL) {
267*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1) {
268*49cdfc7eSAndroid Build Coastguard Worker if (k == 0) { /* if arg is 0, set infinite loop flag */
269*49cdfc7eSAndroid Build Coastguard Worker STD_INFINITE = 1;
270*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
271*49cdfc7eSAndroid Build Coastguard Worker printf
272*49cdfc7eSAndroid Build Coastguard Worker ("Using env %s, set STD_INFINITE to 1\n",
273*49cdfc7eSAndroid Build Coastguard Worker USC_ITERATION_ENV);
274*49cdfc7eSAndroid Build Coastguard Worker } else { /* else, set the loop count to the arguement */
275*49cdfc7eSAndroid Build Coastguard Worker STD_LOOP_COUNT = k;
276*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
277*49cdfc7eSAndroid Build Coastguard Worker printf
278*49cdfc7eSAndroid Build Coastguard Worker ("Using env %s, set STD_LOOP_COUNT to %d\n",
279*49cdfc7eSAndroid Build Coastguard Worker USC_ITERATION_ENV, k);
280*49cdfc7eSAndroid Build Coastguard Worker }
281*49cdfc7eSAndroid Build Coastguard Worker }
282*49cdfc7eSAndroid Build Coastguard Worker }
283*49cdfc7eSAndroid Build Coastguard Worker
284*49cdfc7eSAndroid Build Coastguard Worker /*
285*49cdfc7eSAndroid Build Coastguard Worker * If the USC_LOOP_WALLTIME environmental variable is set,
286*49cdfc7eSAndroid Build Coastguard Worker * use that number as duration (same as -I option).
287*49cdfc7eSAndroid Build Coastguard Worker * The -I option with arg will be used even if this env var is set.
288*49cdfc7eSAndroid Build Coastguard Worker */
289*49cdfc7eSAndroid Build Coastguard Worker
290*49cdfc7eSAndroid Build Coastguard Worker if (!(options & OPT_duration) &&
291*49cdfc7eSAndroid Build Coastguard Worker (ptr = getenv(USC_LOOP_WALLTIME)) != NULL) {
292*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
293*49cdfc7eSAndroid Build Coastguard Worker STD_LOOP_DURATION = ftmp;
294*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
295*49cdfc7eSAndroid Build Coastguard Worker printf
296*49cdfc7eSAndroid Build Coastguard Worker ("Using env %s, set STD_LOOP_DURATION to %f\n",
297*49cdfc7eSAndroid Build Coastguard Worker USC_LOOP_WALLTIME, ftmp);
298*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
299*49cdfc7eSAndroid Build Coastguard Worker STD_INFINITE = 1;
300*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
301*49cdfc7eSAndroid Build Coastguard Worker printf
302*49cdfc7eSAndroid Build Coastguard Worker ("Using env %s, set STD_INFINITE to 1\n",
303*49cdfc7eSAndroid Build Coastguard Worker USC_LOOP_WALLTIME);
304*49cdfc7eSAndroid Build Coastguard Worker }
305*49cdfc7eSAndroid Build Coastguard Worker }
306*49cdfc7eSAndroid Build Coastguard Worker }
307*49cdfc7eSAndroid Build Coastguard Worker if (!(options & OPT_duration) && (ptr = getenv("USC_DURATION")) != NULL) {
308*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%f", &ftmp) == 1 && ftmp >= 0.0) {
309*49cdfc7eSAndroid Build Coastguard Worker STD_LOOP_DURATION = ftmp;
310*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
311*49cdfc7eSAndroid Build Coastguard Worker printf
312*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_DURATION, set STD_LOOP_DURATION to %f\n",
313*49cdfc7eSAndroid Build Coastguard Worker ftmp);
314*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_DURATION == 0.0) { /* if arg is 0, set infinite loop flag */
315*49cdfc7eSAndroid Build Coastguard Worker STD_INFINITE = 1;
316*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
317*49cdfc7eSAndroid Build Coastguard Worker printf
318*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_DURATION, set STD_INFINITE to 1\n");
319*49cdfc7eSAndroid Build Coastguard Worker }
320*49cdfc7eSAndroid Build Coastguard Worker }
321*49cdfc7eSAndroid Build Coastguard Worker }
322*49cdfc7eSAndroid Build Coastguard Worker
323*49cdfc7eSAndroid Build Coastguard Worker /*
324*49cdfc7eSAndroid Build Coastguard Worker * The following are special system testing envs to turn on special
325*49cdfc7eSAndroid Build Coastguard Worker * hooks in the code.
326*49cdfc7eSAndroid Build Coastguard Worker */
327*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_TP_BARRIER")) != NULL) {
328*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
329*49cdfc7eSAndroid Build Coastguard Worker STD_TP_barrier = k;
330*49cdfc7eSAndroid Build Coastguard Worker else
331*49cdfc7eSAndroid Build Coastguard Worker STD_TP_barrier = 1;
332*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
333*49cdfc7eSAndroid Build Coastguard Worker printf
334*49cdfc7eSAndroid Build Coastguard Worker ("using env USC_TP_BARRIER, Set STD_TP_barrier to %d\n",
335*49cdfc7eSAndroid Build Coastguard Worker STD_TP_barrier);
336*49cdfc7eSAndroid Build Coastguard Worker }
337*49cdfc7eSAndroid Build Coastguard Worker
338*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LP_BARRIER")) != NULL) {
339*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0)
340*49cdfc7eSAndroid Build Coastguard Worker STD_LP_barrier = k;
341*49cdfc7eSAndroid Build Coastguard Worker else
342*49cdfc7eSAndroid Build Coastguard Worker STD_LP_barrier = 1;
343*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
344*49cdfc7eSAndroid Build Coastguard Worker printf
345*49cdfc7eSAndroid Build Coastguard Worker ("using env USC_LP_BARRIER, Set STD_LP_barrier to %d\n",
346*49cdfc7eSAndroid Build Coastguard Worker STD_LP_barrier);
347*49cdfc7eSAndroid Build Coastguard Worker }
348*49cdfc7eSAndroid Build Coastguard Worker
349*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_TP_SHMEM")) != NULL) {
350*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
351*49cdfc7eSAndroid Build Coastguard Worker STD_TP_shmem_sz = k;
352*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
353*49cdfc7eSAndroid Build Coastguard Worker printf
354*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_TP_SHMEM, Set STD_TP_shmem_sz to %d\n",
355*49cdfc7eSAndroid Build Coastguard Worker STD_TP_shmem_sz);
356*49cdfc7eSAndroid Build Coastguard Worker }
357*49cdfc7eSAndroid Build Coastguard Worker }
358*49cdfc7eSAndroid Build Coastguard Worker
359*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LP_SHMEM")) != NULL) {
360*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
361*49cdfc7eSAndroid Build Coastguard Worker STD_LP_shmem = k;
362*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
363*49cdfc7eSAndroid Build Coastguard Worker printf
364*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_LP_SHMEM, Set STD_LP_shmem to %d\n",
365*49cdfc7eSAndroid Build Coastguard Worker STD_LP_shmem);
366*49cdfc7eSAndroid Build Coastguard Worker }
367*49cdfc7eSAndroid Build Coastguard Worker }
368*49cdfc7eSAndroid Build Coastguard Worker
369*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LD_SHMEM")) != NULL) {
370*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
371*49cdfc7eSAndroid Build Coastguard Worker STD_LD_shmem = k;
372*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
373*49cdfc7eSAndroid Build Coastguard Worker printf
374*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_LD_SHMEM, Set STD_LD_shmem to %d\n",
375*49cdfc7eSAndroid Build Coastguard Worker STD_LD_shmem);
376*49cdfc7eSAndroid Build Coastguard Worker }
377*49cdfc7eSAndroid Build Coastguard Worker }
378*49cdfc7eSAndroid Build Coastguard Worker
379*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_TP_SBRK")) != NULL) {
380*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
381*49cdfc7eSAndroid Build Coastguard Worker STD_TP_sbrk = k;
382*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
383*49cdfc7eSAndroid Build Coastguard Worker printf
384*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_TP_SBRK, Set STD_TP_sbrk to %d\n",
385*49cdfc7eSAndroid Build Coastguard Worker STD_TP_sbrk);
386*49cdfc7eSAndroid Build Coastguard Worker }
387*49cdfc7eSAndroid Build Coastguard Worker }
388*49cdfc7eSAndroid Build Coastguard Worker
389*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LP_SBRK")) != NULL) {
390*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
391*49cdfc7eSAndroid Build Coastguard Worker STD_LP_sbrk = k;
392*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
393*49cdfc7eSAndroid Build Coastguard Worker printf
394*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_LP_SBRK, Set STD_LP_sbrk to %d\n",
395*49cdfc7eSAndroid Build Coastguard Worker STD_LP_sbrk);
396*49cdfc7eSAndroid Build Coastguard Worker }
397*49cdfc7eSAndroid Build Coastguard Worker }
398*49cdfc7eSAndroid Build Coastguard Worker
399*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LP_RECFUN")) != NULL) {
400*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
401*49cdfc7eSAndroid Build Coastguard Worker STD_LP_recfun = k;
402*49cdfc7eSAndroid Build Coastguard Worker if (STD_bigstack != NULL)
403*49cdfc7eSAndroid Build Coastguard Worker STD_bigstack =
404*49cdfc7eSAndroid Build Coastguard Worker malloc(sizeof(struct usc_bigstack_t));
405*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
406*49cdfc7eSAndroid Build Coastguard Worker printf
407*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_LP_RECFUN, Set STD_LP_recfun to %d\n",
408*49cdfc7eSAndroid Build Coastguard Worker STD_LP_recfun);
409*49cdfc7eSAndroid Build Coastguard Worker }
410*49cdfc7eSAndroid Build Coastguard Worker }
411*49cdfc7eSAndroid Build Coastguard Worker
412*49cdfc7eSAndroid Build Coastguard Worker if ((ptr = getenv("USC_LD_RECFUN")) != NULL) {
413*49cdfc7eSAndroid Build Coastguard Worker if (sscanf(ptr, "%i", &k) == 1 && k >= 0) {
414*49cdfc7eSAndroid Build Coastguard Worker STD_LD_recfun = k;
415*49cdfc7eSAndroid Build Coastguard Worker if (STD_bigstack != NULL)
416*49cdfc7eSAndroid Build Coastguard Worker STD_bigstack =
417*49cdfc7eSAndroid Build Coastguard Worker malloc(sizeof(struct usc_bigstack_t));
418*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
419*49cdfc7eSAndroid Build Coastguard Worker printf
420*49cdfc7eSAndroid Build Coastguard Worker ("Using env USC_LD_RECFUN, Set STD_LD_recfun to %d\n",
421*49cdfc7eSAndroid Build Coastguard Worker STD_LD_recfun);
422*49cdfc7eSAndroid Build Coastguard Worker }
423*49cdfc7eSAndroid Build Coastguard Worker }
424*49cdfc7eSAndroid Build Coastguard Worker #if UNIT_TEST
425*49cdfc7eSAndroid Build Coastguard Worker printf("The following variables after option and env parsing:\n");
426*49cdfc7eSAndroid Build Coastguard Worker printf("STD_LOOP_DURATION = %f\n", STD_LOOP_DURATION);
427*49cdfc7eSAndroid Build Coastguard Worker printf("STD_LOOP_COUNT = %d\n", STD_LOOP_COUNT);
428*49cdfc7eSAndroid Build Coastguard Worker printf("STD_INFINITE = %d\n", STD_INFINITE);
429*49cdfc7eSAndroid Build Coastguard Worker #endif
430*49cdfc7eSAndroid Build Coastguard Worker
431*49cdfc7eSAndroid Build Coastguard Worker return NULL;
432*49cdfc7eSAndroid Build Coastguard Worker }
433*49cdfc7eSAndroid Build Coastguard Worker
434*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
435*49cdfc7eSAndroid Build Coastguard Worker * This function will do desired end of global setup test
436*49cdfc7eSAndroid Build Coastguard Worker * hooks.
437*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
usc_global_setup_hook(void)438*49cdfc7eSAndroid Build Coastguard Worker int usc_global_setup_hook(void)
439*49cdfc7eSAndroid Build Coastguard Worker {
440*49cdfc7eSAndroid Build Coastguard Worker if (STD_TP_sbrk || STD_LP_sbrk)
441*49cdfc7eSAndroid Build Coastguard Worker STD_start_break = sbrk(0); /* get original sbreak size */
442*49cdfc7eSAndroid Build Coastguard Worker
443*49cdfc7eSAndroid Build Coastguard Worker if (STD_TP_sbrk) {
444*49cdfc7eSAndroid Build Coastguard Worker sbrk(STD_TP_sbrk);
445*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
446*49cdfc7eSAndroid Build Coastguard Worker printf("after sbrk(%d)\n", STD_TP_sbrk);
447*49cdfc7eSAndroid Build Coastguard Worker }
448*49cdfc7eSAndroid Build Coastguard Worker return 0;
449*49cdfc7eSAndroid Build Coastguard Worker }
450*49cdfc7eSAndroid Build Coastguard Worker
451*49cdfc7eSAndroid Build Coastguard Worker #define USECS_PER_SEC 1000000 /* microseconds per second */
452*49cdfc7eSAndroid Build Coastguard Worker
get_current_time(void)453*49cdfc7eSAndroid Build Coastguard Worker static uint64_t get_current_time(void)
454*49cdfc7eSAndroid Build Coastguard Worker {
455*49cdfc7eSAndroid Build Coastguard Worker struct timespec ts;
456*49cdfc7eSAndroid Build Coastguard Worker
457*49cdfc7eSAndroid Build Coastguard Worker tst_clock_gettime(CLOCK_MONOTONIC, &ts);
458*49cdfc7eSAndroid Build Coastguard Worker
459*49cdfc7eSAndroid Build Coastguard Worker return (((uint64_t) ts.tv_sec) * USECS_PER_SEC) + ts.tv_nsec / 1000;
460*49cdfc7eSAndroid Build Coastguard Worker }
461*49cdfc7eSAndroid Build Coastguard Worker
462*49cdfc7eSAndroid Build Coastguard Worker /***********************************************************************
463*49cdfc7eSAndroid Build Coastguard Worker *
464*49cdfc7eSAndroid Build Coastguard Worker * This function will determine if test should continue iterating
465*49cdfc7eSAndroid Build Coastguard Worker * If the STD_INFINITE flag is set, return 1.
466*49cdfc7eSAndroid Build Coastguard Worker * If the STD_LOOP_COUNT variable is set, compare it against
467*49cdfc7eSAndroid Build Coastguard Worker * the counter.
468*49cdfc7eSAndroid Build Coastguard Worker * If the STD_LOOP_DURATION variable is set, compare current time against
469*49cdfc7eSAndroid Build Coastguard Worker * calculated stop_time.
470*49cdfc7eSAndroid Build Coastguard Worker * This function will return 1 until all desired looping methods
471*49cdfc7eSAndroid Build Coastguard Worker * have been met.
472*49cdfc7eSAndroid Build Coastguard Worker *
473*49cdfc7eSAndroid Build Coastguard Worker * counter integer is supplied by the user program.
474*49cdfc7eSAndroid Build Coastguard Worker ***********************************************************************/
usc_test_looping(int counter)475*49cdfc7eSAndroid Build Coastguard Worker int usc_test_looping(int counter)
476*49cdfc7eSAndroid Build Coastguard Worker {
477*49cdfc7eSAndroid Build Coastguard Worker static int first_time = 1;
478*49cdfc7eSAndroid Build Coastguard Worker static uint64_t stop_time = 0;
479*49cdfc7eSAndroid Build Coastguard Worker int keepgoing = 0;
480*49cdfc7eSAndroid Build Coastguard Worker
481*49cdfc7eSAndroid Build Coastguard Worker /*
482*49cdfc7eSAndroid Build Coastguard Worker * If this is the first iteration and we are looping for
483*49cdfc7eSAndroid Build Coastguard Worker * duration of STD_LOOP_DURATION seconds (fractional) or
484*49cdfc7eSAndroid Build Coastguard Worker * doing loop delays, get the clocks per second.
485*49cdfc7eSAndroid Build Coastguard Worker */
486*49cdfc7eSAndroid Build Coastguard Worker if (first_time) {
487*49cdfc7eSAndroid Build Coastguard Worker first_time = 0;
488*49cdfc7eSAndroid Build Coastguard Worker
489*49cdfc7eSAndroid Build Coastguard Worker /*
490*49cdfc7eSAndroid Build Coastguard Worker * If looping for duration, calculate stop time in
491*49cdfc7eSAndroid Build Coastguard Worker * clocks.
492*49cdfc7eSAndroid Build Coastguard Worker */
493*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_DURATION) {
494*49cdfc7eSAndroid Build Coastguard Worker stop_time =
495*49cdfc7eSAndroid Build Coastguard Worker (uint64_t) (USECS_PER_SEC * STD_LOOP_DURATION)
496*49cdfc7eSAndroid Build Coastguard Worker + get_current_time();
497*49cdfc7eSAndroid Build Coastguard Worker }
498*49cdfc7eSAndroid Build Coastguard Worker }
499*49cdfc7eSAndroid Build Coastguard Worker
500*49cdfc7eSAndroid Build Coastguard Worker if (STD_INFINITE)
501*49cdfc7eSAndroid Build Coastguard Worker keepgoing++;
502*49cdfc7eSAndroid Build Coastguard Worker
503*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_COUNT && counter < STD_LOOP_COUNT)
504*49cdfc7eSAndroid Build Coastguard Worker keepgoing++;
505*49cdfc7eSAndroid Build Coastguard Worker
506*49cdfc7eSAndroid Build Coastguard Worker if (STD_LOOP_DURATION != 0.0 && get_current_time() < stop_time)
507*49cdfc7eSAndroid Build Coastguard Worker keepgoing++;
508*49cdfc7eSAndroid Build Coastguard Worker
509*49cdfc7eSAndroid Build Coastguard Worker if (keepgoing == 0)
510*49cdfc7eSAndroid Build Coastguard Worker return 0;
511*49cdfc7eSAndroid Build Coastguard Worker
512*49cdfc7eSAndroid Build Coastguard Worker /*
513*49cdfc7eSAndroid Build Coastguard Worker * The following code allows special system testing hooks.
514*49cdfc7eSAndroid Build Coastguard Worker */
515*49cdfc7eSAndroid Build Coastguard Worker
516*49cdfc7eSAndroid Build Coastguard Worker if (STD_LP_recfun) {
517*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
518*49cdfc7eSAndroid Build Coastguard Worker printf
519*49cdfc7eSAndroid Build Coastguard Worker ("calling usc_recressive_func(0, %d, *STD_bigstack)\n",
520*49cdfc7eSAndroid Build Coastguard Worker STD_LP_recfun);
521*49cdfc7eSAndroid Build Coastguard Worker usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
522*49cdfc7eSAndroid Build Coastguard Worker }
523*49cdfc7eSAndroid Build Coastguard Worker
524*49cdfc7eSAndroid Build Coastguard Worker if (STD_LP_sbrk) {
525*49cdfc7eSAndroid Build Coastguard Worker if (Debug)
526*49cdfc7eSAndroid Build Coastguard Worker printf("about to do sbrk(%d)\n", STD_LP_sbrk);
527*49cdfc7eSAndroid Build Coastguard Worker sbrk(STD_LP_sbrk);
528*49cdfc7eSAndroid Build Coastguard Worker }
529*49cdfc7eSAndroid Build Coastguard Worker
530*49cdfc7eSAndroid Build Coastguard Worker if (keepgoing)
531*49cdfc7eSAndroid Build Coastguard Worker return 1;
532*49cdfc7eSAndroid Build Coastguard Worker else
533*49cdfc7eSAndroid Build Coastguard Worker return 0;
534*49cdfc7eSAndroid Build Coastguard Worker }
535*49cdfc7eSAndroid Build Coastguard Worker
536*49cdfc7eSAndroid Build Coastguard Worker /*
537*49cdfc7eSAndroid Build Coastguard Worker * This function recressively calls itself max times.
538*49cdfc7eSAndroid Build Coastguard Worker */
usc_recressive_func(int cnt,int max,struct usc_bigstack_t bstack)539*49cdfc7eSAndroid Build Coastguard Worker static void usc_recressive_func(int cnt, int max, struct usc_bigstack_t bstack)
540*49cdfc7eSAndroid Build Coastguard Worker {
541*49cdfc7eSAndroid Build Coastguard Worker if (cnt < max)
542*49cdfc7eSAndroid Build Coastguard Worker usc_recressive_func(cnt + 1, max, bstack);
543*49cdfc7eSAndroid Build Coastguard Worker
544*49cdfc7eSAndroid Build Coastguard Worker }
545*49cdfc7eSAndroid Build Coastguard Worker
546*49cdfc7eSAndroid Build Coastguard Worker #if UNIT_TEST
547*49cdfc7eSAndroid Build Coastguard Worker
548*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************
549*49cdfc7eSAndroid Build Coastguard Worker * UNIT TEST CODE
550*49cdfc7eSAndroid Build Coastguard Worker * UNIT TEST CODE
551*49cdfc7eSAndroid Build Coastguard Worker *
552*49cdfc7eSAndroid Build Coastguard Worker * this following code is provide so that unit testing can
553*49cdfc7eSAndroid Build Coastguard Worker * be done fairly easily.
554*49cdfc7eSAndroid Build Coastguard Worker ******************************************************************************/
555*49cdfc7eSAndroid Build Coastguard Worker
556*49cdfc7eSAndroid Build Coastguard Worker int Help = 0;
557*49cdfc7eSAndroid Build Coastguard Worker int Help2 = 0;
558*49cdfc7eSAndroid Build Coastguard Worker char *ptr;
559*49cdfc7eSAndroid Build Coastguard Worker
560*49cdfc7eSAndroid Build Coastguard Worker long TEST_RETURN;
561*49cdfc7eSAndroid Build Coastguard Worker int TEST_ERRNO;
562*49cdfc7eSAndroid Build Coastguard Worker
563*49cdfc7eSAndroid Build Coastguard Worker /* for test specific parse_opts options */
564*49cdfc7eSAndroid Build Coastguard Worker option_t Options[] = {
565*49cdfc7eSAndroid Build Coastguard Worker {"help", &Help2, NULL}, /* -help option */
566*49cdfc7eSAndroid Build Coastguard Worker {"h", &Help, NULL}, /* -h option */
567*49cdfc7eSAndroid Build Coastguard Worker
568*49cdfc7eSAndroid Build Coastguard Worker #if INVALID_TEST_CASES
569*49cdfc7eSAndroid Build Coastguard Worker {"missingflag", NULL, &ptr}, /* error */
570*49cdfc7eSAndroid Build Coastguard Worker {"missingarg:", &Help, NULL}, /* error */
571*49cdfc7eSAndroid Build Coastguard Worker #endif /* INVALID_TEST_CASES */
572*49cdfc7eSAndroid Build Coastguard Worker
573*49cdfc7eSAndroid Build Coastguard Worker {NULL, NULL, NULL}
574*49cdfc7eSAndroid Build Coastguard Worker };
575*49cdfc7eSAndroid Build Coastguard Worker
main(int argc,char ** argv)576*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char **argv)
577*49cdfc7eSAndroid Build Coastguard Worker {
578*49cdfc7eSAndroid Build Coastguard Worker int lc;
579*49cdfc7eSAndroid Build Coastguard Worker char *msg;
580*49cdfc7eSAndroid Build Coastguard Worker struct timeval t;
581*49cdfc7eSAndroid Build Coastguard Worker int cnt;
582*49cdfc7eSAndroid Build Coastguard Worker
583*49cdfc7eSAndroid Build Coastguard Worker if ((msg = parse_opts(argc, argv, Options, NULL)) != NULL) {
584*49cdfc7eSAndroid Build Coastguard Worker printf("ERROR: %s\n", msg);
585*49cdfc7eSAndroid Build Coastguard Worker exit(1);
586*49cdfc7eSAndroid Build Coastguard Worker }
587*49cdfc7eSAndroid Build Coastguard Worker
588*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
589*49cdfc7eSAndroid Build Coastguard Worker
590*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
591*49cdfc7eSAndroid Build Coastguard Worker
592*49cdfc7eSAndroid Build Coastguard Worker TEST(gettimeofday(&t, NULL));
593*49cdfc7eSAndroid Build Coastguard Worker printf("iter=%d: sec:%d, usec:%6.6d %s", lc + 1, t.tv_sec,
594*49cdfc7eSAndroid Build Coastguard Worker t.tv_usec, ctime(&t.tv_sec));
595*49cdfc7eSAndroid Build Coastguard Worker }
596*49cdfc7eSAndroid Build Coastguard Worker
597*49cdfc7eSAndroid Build Coastguard Worker TEST_CLEANUP;
598*49cdfc7eSAndroid Build Coastguard Worker
599*49cdfc7eSAndroid Build Coastguard Worker exit(0);
600*49cdfc7eSAndroid Build Coastguard Worker }
601*49cdfc7eSAndroid Build Coastguard Worker
602*49cdfc7eSAndroid Build Coastguard Worker #endif /* UNIT_TEST */
603