blob: 6c93266603d43eec129e88d4031ad2cc8b778bf3 [file] [log] [blame]
alaffincc2e5552000-07-27 17:13:18 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
32
vapierb3691d72006-05-26 06:06:06 +000033/* $Id: usctest.h,v 1.10 2006/05/26 06:06:06 vapier Exp $ */
alaffincc2e5552000-07-27 17:13:18 +000034
35/**********************************************************
36 *
37 * IRIX/Linux Feature Test and Evaluation - Silicon Graphics, Inc.
38 *
39 * FUNCTION NAME : usctest.h
40 *
41 * FUNCTION TITLE : System Call Test Macros
42 *
43 * SYNOPSIS:
44 * See DESCRIPTION below.
45 *
46 * AUTHOR : William Roske
47 *
48 * INITIAL RELEASE : UNICOS 7.0
49 *
50 * DESCRIPTION
51 * TEST(SCALL) - calls a system call
52 * TEST_VOID(SCALL) - same as TEST() but for syscalls with no return value.
53 * TEST_CLEANUP - print the log of errno return counts if STD_ERRNO_LOG
54 * is set.
55 * TEST_PAUSEF(HAND) - Pause for SIGUSR1 if the pause flag is set.
56 * Use "hand" as the interrupt handling function
57 * TEST_PAUSE - Pause for SIGUSR1 if the pause flag is set.
58 * Use internal function to do nothing on signal and go on.
59 * TEST_LOOPING(COUNTER) - Conditional to check if test should
60 * loop. Evaluates to TRUE (1) or FALSE (0).
61 * TEST_ERROR_LOG(eno) - log that this errno was received,
62 * if STD_ERRNO_LOG is set.
63 * TEST_EXP_ENOS(array) - set the bits in TEST_VALID_ENO array at
64 * positions specified in integer "array"
65 *
66 * RETURN VALUE
67 * TEST(SCALL) - Global Variables set:
68 * int TEST_RETURN=return code from SCALL
69 * int TEST_ERRNO=value of errno at return from SCALL
70 * TEST_VOID(SCALL) - Global Variables set:
71 * int TEST_ERRNO=value of errno at return from SCALL
72 * TEST_CLEANUP - None.
73 * TEST_PAUSEF(HAND) - None.
74 * TEST_PAUSE - None.
75 * TEST_LOOPING(COUNTER) - True if COUNTER < STD_LOOP_COUNT or
76 * STD_INFINITE is set.
77 * TEST_ERROR_LOG(eno) - None
78 * TEST_EXP_ENOS(array) - None
79 *
80 * KNOWN BUGS
81 * If you use the TEST_PAUSE or TEST_LOOPING macros, you must
82 * link in parse_opts.o, which contains the code for those functions.
83 *
84 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
85
86#ifndef __USCTEST_H__
87#define __USCTEST_H__ 1
88
89#ifndef _SC_CLK_TCK
90#include <unistd.h>
91#endif
92
93#include <sys/param.h>
94
95/*
96 * Ensure that PATH_MAX is defined
97 */
98#ifndef PATH_MAX
99#ifdef MAXPATHLEN
100#define PATH_MAX MAXPATHLEN
101#else
102#define PATH_MAX 1024
103#endif
104#endif
105
106#ifndef CRAY
107#ifndef BSIZE
108#define BSIZE BBSIZE
109#endif
110#endif
111
alaffincc2e5552000-07-27 17:13:18 +0000112/***********************************************************************
113 * Define option_t structure type.
114 * Entries in this struct are used by the parse_opts routine
115 * to indicate valid options and return option arguments
116 ***********************************************************************/
117typedef struct {
118 char *option; /* Valid option string (one option only) like "a:" */
119 int *flag; /* pointer to location to set true if option given */
120 char **arg; /* pointer to location to place argument, if needed */
121} option_t;
122
123/***********************************************************************
124 * The following globals are defined in parse_opts.c but must be
125 * externed here because they are used in the macros defined below.
126 ***********************************************************************/
127extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */
128 STD_TIMING_ON, /* turned on by -t to print timing stats */
129 STD_PAUSE, /* turned on by -p to pause before loop */
nstraz829b40a2000-09-06 14:33:29 +0000130 STD_INFINITE, /* turned on by -i0 to loop forever */
131 STD_LOOP_COUNT, /* changed by -in to set loop count to n */
alaffincc2e5552000-07-27 17:13:18 +0000132 STD_ERRNO_LOG, /* turned on by -e to log errnos returned */
133 STD_ERRNO_LIST[], /* counts of errnos returned. indexed by errno */
134 STD_COPIES,
135 STD_argind;
136
137extern float STD_LOOP_DURATION, /* wall clock time to iterate */
138 STD_LOOP_DELAY; /* delay time after each iteration */
139
140#define USC_MAX_ERRNO 2000
141
142/**********************************************************************
143 * Prototype for parse_opts routine
144 **********************************************************************/
nstraz6a918812000-08-31 19:20:35 +0000145extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)());
146
alaffincc2e5552000-07-27 17:13:18 +0000147
148/*
149 * define a structure
150 */
151struct usc_errno_t {
152 int flag;
153};
154
155/***********************************************************************
156 ****
157 ****
158 ****
159 **********************************************************************/
160#ifdef _USC_LIB_
161
robbiew2e6837d2005-07-11 18:56:53 +0000162extern long TEST_RETURN;
163extern long TEST_ERRNO;
robbiew6eaecb22005-12-22 20:18:22 +0000164extern struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
165extern long btime, etime, tmptime;
alaffincc2e5552000-07-27 17:13:18 +0000166
167#else
168/***********************************************************************
169 * Global array of bit masks to indicate errnos that are expected.
170 * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro.
171 ***********************************************************************/
172struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
173
174/***********************************************************************
175 * Globals for returning the return code and errno from the system call
176 * test macros.
177 ***********************************************************************/
robbiew2e6837d2005-07-11 18:56:53 +0000178long TEST_RETURN;
179long TEST_ERRNO;
alaffincc2e5552000-07-27 17:13:18 +0000180
181/***********************************************************************
182 * temporary variables for determining max and min times in TEST macro
183 ***********************************************************************/
184long btime, etime, tmptime;
185
186#endif /* _USC_LIB_ */
187
188/***********************************************************************
189 * structure for timing accumulator and counters
190 ***********************************************************************/
191struct tblock {
192 long tb_max;
193 long tb_min;
194 long tb_total;
195 long tb_count;
196};
197
198/***********************************************************************
199 * The following globals are externed here so that they are accessable
200 * in the macros that follow.
201 ***********************************************************************/
202extern struct tblock tblock;
203extern void STD_go();
204extern int (*_TMP_FUNC)(void);
nstraz94181082000-08-30 18:43:38 +0000205extern void STD_opts_help();
alaffincc2e5552000-07-27 17:13:18 +0000206
207
208/***********************************************************************
209 * TEST: calls a system call
210 *
211 * parameters:
212 * SCALL = system call and parameters to execute
213 *
214 ***********************************************************************/
vapierb3691d72006-05-26 06:06:06 +0000215#define TEST(SCALL) \
216 do { \
217 errno = 0; \
218 TEST_RETURN = SCALL; \
219 TEST_ERRNO = errno; \
220 } while (0)
alaffincc2e5552000-07-27 17:13:18 +0000221
222/***********************************************************************
223 * TEST_VOID: calls a system call
224 *
225 * parameters:
226 * SCALL = system call and parameters to execute
227 *
228 * Note: This is IDENTICAL to the TEST() macro except that it is intended
229 * for use with syscalls returning no values (void syscall()). The
230 * Typecasting nothing (void) into an unsigned integer causes compilation
231 * errors.
232 *
233 ***********************************************************************/
plars90b16982002-04-11 15:03:03 +0000234#define TEST_VOID(SCALL) errno=0; SCALL; TEST_ERRNO=errno;
alaffincc2e5552000-07-27 17:13:18 +0000235
236/***********************************************************************
237 * TEST_CLEANUP: print system call timing stats and errno log entries
238 * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively.
239 * Do NOT print ANY information if no system calls logged.
240 *
241 * parameters:
242 * none
243 *
244 ***********************************************************************/
245#define TEST_CLEANUP \
246if ( STD_ERRNO_LOG ) { \
247 for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) { \
248 if ( STD_ERRNO_LIST[tmptime] ) { \
249 if ( TEST_VALID_ENO[tmptime].flag ) \
250 tst_resm(TINFO, "ERRNO %d:\tReceived %d Times", \
251 tmptime, STD_ERRNO_LIST[tmptime]); \
252 else \
253 tst_resm(TINFO, \
254 "ERRNO %d:\tReceived %d Times ** UNEXPECTED **", \
255 tmptime, STD_ERRNO_LIST[tmptime]); \
256 } \
257 } \
258}
259
260/***********************************************************************
261 * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set.
262 * Set the user specified function as the interrupt
263 * handler instead of "STD_go"
264 *
265 * parameters:
266 * none
267 *
268 ***********************************************************************/
269#define TEST_PAUSEF(HANDLER) \
270if ( STD_PAUSE ) { \
271 _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER); \
272 pause(); \
273 signal(SIGUSR1, (void (*)())_TMP_FUNC); \
274}
275
276/***********************************************************************
277 * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
278 * Just continue when signal comes in.
279 *
280 * parameters:
281 * none
282 *
283 ***********************************************************************/
284#define TEST_PAUSE usc_global_setup_hook();
nstraz94181082000-08-30 18:43:38 +0000285int usc_global_setup_hook();
alaffincc2e5552000-07-27 17:13:18 +0000286
287/***********************************************************************
288 * TEST_LOOPING now call the usc_test_looping function.
289 * The function will return 1 if the test should continue
290 * iterating.
291 *
292 ***********************************************************************/
293#define TEST_LOOPING usc_test_looping
nstraz94181082000-08-30 18:43:38 +0000294int usc_test_looping(int counter);
alaffincc2e5552000-07-27 17:13:18 +0000295
296/***********************************************************************
297 * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set
298 *
299 * parameters:
300 * int eno: the errno location in STD_ERRNO_LIST to log.
301 *
302 ***********************************************************************/
303#define TEST_ERROR_LOG(eno) \
304 if ( STD_ERRNO_LOG ) \
305 if ( eno < USC_MAX_ERRNO ) \
306 STD_ERRNO_LIST[eno]++; \
307
308
309/***********************************************************************
310 * TEST_EXP_ENOS(array): set the bits associated with the nput errnos
311 * in the TEST_VALID_ENO array.
312 *
313 * parameters:
314 * int array[]: a zero terminated array of errnos expected.
315 *
316 ***********************************************************************/
317#define TEST_EXP_ENOS(array) \
318 tmptime=0; \
319 while (array[tmptime] != 0) { \
320 if (array[tmptime] < USC_MAX_ERRNO) \
321 TEST_VALID_ENO[array[tmptime]].flag=1; \
322 tmptime++; \
323 }
324
325
326#endif /* end of __USCTEST_H__ */