Fixed merge problems
[xfstests-dev.git] / include / usctest.h
1 /*
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
33 /* $Id: usctest.h,v 1.1 2003/07/07 06:36:46 nathans Exp $ */
34
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
112 /***********************************************************************
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  ***********************************************************************/
117 typedef 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  ***********************************************************************/
127 extern 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 */
130            STD_INFINITE,        /* turned on by -i0 to loop forever */
131            STD_LOOP_COUNT,      /* changed by -in to set loop count to n */
132            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
137 extern 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  **********************************************************************/
145 extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)());
146
147
148 /*
149  * define a structure 
150  */
151 struct usc_errno_t {
152     int flag;
153 };
154
155 /***********************************************************************
156  ****
157  **** 
158  ****
159  **********************************************************************/
160 #ifdef  _USC_LIB_
161
162 extern int TEST_RETURN;
163 extern int TEST_ERRNO;
164
165 #else
166 /***********************************************************************
167  * Global array of bit masks to indicate errnos that are expected.
168  * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro.
169  ***********************************************************************/
170 struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
171
172 /***********************************************************************
173  * Globals for returning the return code and errno from the system call
174  * test macros.
175  ***********************************************************************/
176 int TEST_RETURN;
177 int TEST_ERRNO;
178
179 /***********************************************************************
180  * temporary variables for determining max and min times in TEST macro
181  ***********************************************************************/
182 long btime, etime, tmptime;     
183
184 #endif  /* _USC_LIB_ */
185
186 /***********************************************************************
187  * structure for timing accumulator and counters 
188  ***********************************************************************/
189 struct tblock {
190     long tb_max;
191     long tb_min;
192     long tb_total;
193     long tb_count;
194 };
195
196 /***********************************************************************
197  * The following globals are externed here so that they are accessable
198  * in the macros that follow.
199  ***********************************************************************/
200 extern struct tblock tblock;
201 extern void STD_go();
202 extern int (*_TMP_FUNC)(void);
203 extern void STD_opts_help();
204
205
206 /***********************************************************************
207  * TEST: calls a system call 
208  * 
209  * parameters:
210  *      SCALL = system call and parameters to execute
211  *
212  ***********************************************************************/
213 #define TEST(SCALL) errno=0; TEST_RETURN = (unsigned) SCALL;  TEST_ERRNO=errno;
214
215 /***********************************************************************
216  * TEST_VOID: calls a system call
217  * 
218  * parameters:
219  *      SCALL = system call and parameters to execute
220  *
221  * Note: This is IDENTICAL to the TEST() macro except that it is intended
222  * for use with syscalls returning no values (void syscall()).  The 
223  * Typecasting nothing (void) into an unsigned integer causes compilation
224  * errors.
225  *
226  ***********************************************************************/
227 #define TEST_VOID(SCALL)  errno=0; SCALL; TEST_ERRNO=errno;
228
229 /***********************************************************************
230  * TEST_CLEANUP: print system call timing stats and errno log entries
231  * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively.
232  * Do NOT print ANY information if no system calls logged.
233  * 
234  * parameters:
235  *      none
236  *
237  ***********************************************************************/
238 #define TEST_CLEANUP    \
239 if ( STD_ERRNO_LOG ) {                                          \
240         for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) {             \
241              if ( STD_ERRNO_LIST[tmptime] )     {                       \
242                  if ( TEST_VALID_ENO[tmptime].flag )                    \
243                      tst_resm(TINFO, "ERRNO %d:\tReceived %d Times",    \
244                               tmptime, STD_ERRNO_LIST[tmptime]);        \
245                  else                                                   \
246                      tst_resm(TINFO,                                    \
247                               "ERRNO %d:\tReceived %d Times ** UNEXPECTED **",  \
248                               tmptime, STD_ERRNO_LIST[tmptime]);        \
249              }                                                          \
250         }                                                               \
251 }
252
253 /***********************************************************************
254  * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set.
255  *               Set the user specified function as the interrupt
256  *               handler instead of "STD_go"
257  * 
258  * parameters:
259  *      none
260  *
261  ***********************************************************************/
262 #define TEST_PAUSEF(HANDLER)                                    \
263 if ( STD_PAUSE ) {                                      \
264     _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER);    \
265     pause();                                            \
266     signal(SIGUSR1, (void (*)())_TMP_FUNC);             \
267 }
268
269 /***********************************************************************
270  * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
271  *             Just continue when signal comes in.
272  * 
273  * parameters:
274  *      none
275  *
276  ***********************************************************************/
277 #define TEST_PAUSE usc_global_setup_hook();
278 int usc_global_setup_hook();
279
280 /***********************************************************************
281  * TEST_LOOPING now call the usc_test_looping function.
282  * The function will return 1 if the test should continue
283  * iterating.
284  *
285  ***********************************************************************/
286 #define TEST_LOOPING usc_test_looping
287 int usc_test_looping(int counter);
288
289 /***********************************************************************
290  * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set
291  * 
292  * parameters:
293  *      int eno: the errno location in STD_ERRNO_LIST to log.
294  *
295  ***********************************************************************/
296 #define TEST_ERROR_LOG(eno)             \
297     if ( STD_ERRNO_LOG )                \
298         if ( eno < USC_MAX_ERRNO )              \
299             STD_ERRNO_LIST[eno]++;      \
300
301
302 /***********************************************************************
303  * TEST_EXP_ENOS(array): set the bits associated with the nput errnos
304  *      in the TEST_VALID_ENO array.
305  * 
306  * parameters:
307  *      int array[]: a zero terminated array of errnos expected.
308  *
309  ***********************************************************************/
310 #define TEST_EXP_ENOS(array)                            \
311     tmptime=0;                                          \
312     while (array[tmptime] != 0) {                       \
313         if (array[tmptime] < USC_MAX_ERRNO)             \
314             TEST_VALID_ENO[array[tmptime]].flag=1;      \
315         tmptime++;                                      \
316     }
317                                         
318
319 #endif  /* end of __USCTEST_H__ */