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