src/open_by_handle: program to exercise open_by_handle_at() syscall
[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 BSIZE 
93 #define BSIZE BBSIZE
94 #endif
95
96 /***********************************************************************
97  * Define option_t structure type.
98  * Entries in this struct are used by the parse_opts routine
99  * to indicate valid options and return option arguments
100  ***********************************************************************/
101 typedef struct {                
102   char *option;         /* Valid option string (one option only) like "a:" */
103   int  *flag;           /* pointer to location to set true if option given */
104   char **arg;           /* pointer to location to place argument, if needed */
105 } option_t;
106
107 /***********************************************************************
108  * The following globals are defined in parse_opts.c but must be 
109  * externed here because they are used in the macros defined below.
110  ***********************************************************************/
111 extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */
112            STD_TIMING_ON,       /* turned on by -t to print timing stats */
113            STD_PAUSE,           /* turned on by -p to pause before loop */
114            STD_INFINITE,        /* turned on by -i0 to loop forever */
115            STD_LOOP_COUNT,      /* changed by -in to set loop count to n */
116            STD_ERRNO_LOG,       /* turned on by -e to log errnos returned */
117            STD_ERRNO_LIST[],    /* counts of errnos returned.  indexed by errno */
118            STD_COPIES,
119            STD_argind;
120
121 extern float STD_LOOP_DURATION, /* wall clock time to iterate */
122              STD_LOOP_DELAY;    /* delay time after each iteration */
123
124 #define USC_MAX_ERRNO   2000
125     
126 /**********************************************************************
127  * Prototype for parse_opts routine
128  **********************************************************************/
129 extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)());
130
131
132 /*
133  * define a structure 
134  */
135 struct usc_errno_t {
136     int flag;
137 };
138
139 /***********************************************************************
140  ****
141  **** 
142  ****
143  **********************************************************************/
144 #ifdef  _USC_LIB_
145
146 extern int TEST_RETURN;
147 extern int TEST_ERRNO;
148
149 #else
150 /***********************************************************************
151  * Global array of bit masks to indicate errnos that are expected.
152  * Bits set by TEST_EXP_ENOS() macro and used by TEST_CLEANUP() macro.
153  ***********************************************************************/
154 struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
155
156 /***********************************************************************
157  * Globals for returning the return code and errno from the system call
158  * test macros.
159  ***********************************************************************/
160 int TEST_RETURN;
161 int TEST_ERRNO;
162
163 /***********************************************************************
164  * temporary variables for determining max and min times in TEST macro
165  ***********************************************************************/
166 long btime, etime, tmptime;     
167
168 #endif  /* _USC_LIB_ */
169
170 /***********************************************************************
171  * structure for timing accumulator and counters 
172  ***********************************************************************/
173 struct tblock {
174     long tb_max;
175     long tb_min;
176     long tb_total;
177     long tb_count;
178 };
179
180 /***********************************************************************
181  * The following globals are externed here so that they are accessable
182  * in the macros that follow.
183  ***********************************************************************/
184 extern struct tblock tblock;
185 extern void STD_go();
186 extern int (*_TMP_FUNC)(void);
187 extern void STD_opts_help();
188
189
190 /***********************************************************************
191  * TEST: calls a system call 
192  * 
193  * parameters:
194  *      SCALL = system call and parameters to execute
195  *
196  ***********************************************************************/
197 #define TEST(SCALL) errno=0; TEST_RETURN = (unsigned) SCALL;  TEST_ERRNO=errno;
198
199 /***********************************************************************
200  * TEST_VOID: calls a system call
201  * 
202  * parameters:
203  *      SCALL = system call and parameters to execute
204  *
205  * Note: This is IDENTICAL to the TEST() macro except that it is intended
206  * for use with syscalls returning no values (void syscall()).  The 
207  * Typecasting nothing (void) into an unsigned integer causes compilation
208  * errors.
209  *
210  ***********************************************************************/
211 #define TEST_VOID(SCALL)  errno=0; SCALL; TEST_ERRNO=errno;
212
213 /***********************************************************************
214  * TEST_CLEANUP: print system call timing stats and errno log entries
215  * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively.
216  * Do NOT print ANY information if no system calls logged.
217  * 
218  * parameters:
219  *      none
220  *
221  ***********************************************************************/
222 #define TEST_CLEANUP    \
223 if ( STD_ERRNO_LOG ) {                                          \
224         for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) {             \
225              if ( STD_ERRNO_LIST[tmptime] )     {                       \
226                  if ( TEST_VALID_ENO[tmptime].flag )                    \
227                      tst_resm(TINFO, "ERRNO %d:\tReceived %d Times",    \
228                               tmptime, STD_ERRNO_LIST[tmptime]);        \
229                  else                                                   \
230                      tst_resm(TINFO,                                    \
231                               "ERRNO %d:\tReceived %d Times ** UNEXPECTED **",  \
232                               tmptime, STD_ERRNO_LIST[tmptime]);        \
233              }                                                          \
234         }                                                               \
235 }
236
237 /***********************************************************************
238  * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set.
239  *               Set the user specified function as the interrupt
240  *               handler instead of "STD_go"
241  * 
242  * parameters:
243  *      none
244  *
245  ***********************************************************************/
246 #define TEST_PAUSEF(HANDLER)                                    \
247 if ( STD_PAUSE ) {                                      \
248     _TMP_FUNC = (int (*)())signal(SIGUSR1, HANDLER);    \
249     pause();                                            \
250     signal(SIGUSR1, (void (*)())_TMP_FUNC);             \
251 }
252
253 /***********************************************************************
254  * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
255  *             Just continue when signal comes in.
256  * 
257  * parameters:
258  *      none
259  *
260  ***********************************************************************/
261 #define TEST_PAUSE usc_global_setup_hook();
262 int usc_global_setup_hook();
263
264 /***********************************************************************
265  * TEST_LOOPING now call the usc_test_looping function.
266  * The function will return 1 if the test should continue
267  * iterating.
268  *
269  ***********************************************************************/
270 #define TEST_LOOPING usc_test_looping
271 int usc_test_looping(int counter);
272
273 /***********************************************************************
274  * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set
275  * 
276  * parameters:
277  *      int eno: the errno location in STD_ERRNO_LIST to log.
278  *
279  ***********************************************************************/
280 #define TEST_ERROR_LOG(eno)             \
281     if ( STD_ERRNO_LOG )                \
282         if ( eno < USC_MAX_ERRNO )              \
283             STD_ERRNO_LIST[eno]++;      \
284
285
286 /***********************************************************************
287  * TEST_EXP_ENOS(array): set the bits associated with the nput errnos
288  *      in the TEST_VALID_ENO array.
289  * 
290  * parameters:
291  *      int array[]: a zero terminated array of errnos expected.
292  *
293  ***********************************************************************/
294 #define TEST_EXP_ENOS(array)                            \
295     tmptime=0;                                          \
296     while (array[tmptime] != 0) {                       \
297         if (array[tmptime] < USC_MAX_ERRNO)             \
298             TEST_VALID_ENO[array[tmptime]].flag=1;      \
299         tmptime++;                                      \
300     }
301                                         
302
303 #endif  /* end of __USCTEST_H__ */