make vfs & filesystems use failable copying
[minix3.git] / test / ipc / lib / usctest.h
blob6358940658b4682ac9c888751f2105a8d9a69e76
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
26 * http://www.sgi.com
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33 /**********************************************************
35 * IRIX/Linux Feature Test and Evaluation - Silicon Graphics, Inc.
37 * FUNCTION NAME : usctest.h
39 * FUNCTION TITLE : System Call Test Macros
41 * SYNOPSIS:
42 * See DESCRIPTION below.
44 * AUTHOR : William Roske
46 * INITIAL RELEASE : UNICOS 7.0
48 * DESCRIPTION
49 * TEST(SCALL) - calls a system call
50 * TEST_VOID(SCALL) - same as TEST() but for syscalls with no return value.
51 * TEST_CLEANUP - print the log of errno return counts if STD_ERRNO_LOG
52 * is set.
53 * TEST_PAUSEF(HAND) - Pause for SIGUSR1 if the pause flag is set.
54 * Use "hand" as the interrupt handling function
55 * TEST_PAUSE - Pause for SIGUSR1 if the pause flag is set.
56 * Use internal function to do nothing on signal and go on.
57 * TEST_LOOPING(COUNTER) - Conditional to check if test should
58 * loop. Evaluates to TRUE (1) or FALSE (0).
59 * TEST_ERROR_LOG(eno) - log that this errno was received,
60 * if STD_ERRNO_LOG is set.
61 * TEST_EXP_ENOS(array) - set the bits in TEST_VALID_ENO array at
62 * positions specified in integer "array"
64 * RETURN VALUE
65 * TEST(SCALL) - Global Variables set:
66 * int TEST_RETURN=return code from SCALL
67 * int TEST_ERRNO=value of errno at return from SCALL
68 * TEST_VOID(SCALL) - Global Variables set:
69 * int TEST_ERRNO=value of errno at return from SCALL
70 * TEST_CLEANUP - None.
71 * TEST_PAUSEF(HAND) - None.
72 * TEST_PAUSE - None.
73 * TEST_LOOPING(COUNTER) - True if COUNTER < STD_LOOP_COUNT or
74 * STD_INFINITE is set.
75 * TEST_ERROR_LOG(eno) - None
76 * TEST_EXP_ENOS(array) - None
78 * KNOWN BUGS
79 * If you use the TEST_PAUSE or TEST_LOOPING macros, you must
80 * link in parse_opts.o, which contains the code for those functions.
82 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
84 #ifndef __USCTEST_H__
85 #define __USCTEST_H__ 1
87 #ifndef _SC_CLK_TCK
88 #include <unistd.h>
89 #endif
91 #include <sys/param.h>
93 /*
94 * Ensure that PATH_MAX is defined
96 #ifndef PATH_MAX
97 #ifdef MAXPATHLEN
98 #define PATH_MAX MAXPATHLEN
99 #else
100 #define PATH_MAX 1024
101 #endif
102 #endif
104 #ifndef CRAY
105 #ifndef BSIZE
106 #define BSIZE BBSIZE
107 #endif
108 #endif
110 /***********************************************************************
111 * Define option_t structure type.
112 * Entries in this struct are used by the parse_opts routine
113 * to indicate valid options and return option arguments
114 ***********************************************************************/
115 typedef struct {
116 char *option; /* Valid option string (one option only) like "a:" */
117 int *flag; /* pointer to location to set true if option given */
118 char **arg; /* pointer to location to place argument, if needed */
119 } option_t;
121 /***********************************************************************
122 * The following globals are defined in parse_opts.c but must be
123 * externed here because they are used in the macros defined below.
124 ***********************************************************************/
125 extern int STD_FUNCTIONAL_TEST, /* turned off by -f to not do functional test */
126 STD_TIMING_ON, /* turned on by -t to print timing stats */
127 STD_PAUSE, /* turned on by -p to pause before loop */
128 STD_INFINITE, /* turned on by -i0 to loop forever */
129 STD_LOOP_COUNT, /* changed by -in to set loop count to n */
130 STD_ERRNO_LOG, /* turned on by -e to log errnos returned */
131 STD_ERRNO_LIST[], /* counts of errnos returned. indexed by errno */
132 STD_COPIES,
133 STD_argind;
135 extern float STD_LOOP_DURATION, /* wall clock time to iterate */
136 STD_LOOP_DELAY; /* delay time after each iteration */
138 #define USC_MAX_ERRNO 2000
140 /**********************************************************************
141 * Prototype for parse_opts routine
142 **********************************************************************/
143 extern char *parse_opts(int ac, char **av, option_t *user_optarr, void (*uhf)(void));
147 * define a structure
149 struct usc_errno_t {
150 int flag;
153 /***********************************************************************
154 ****
155 ****
156 ****
157 **********************************************************************/
158 #ifdef _USC_LIB_
160 extern long TEST_RETURN;
161 extern long TEST_ERRNO;
162 extern struct usc_errno_t TEST_VALID_ENO[USC_MAX_ERRNO];
163 extern long btime, etime, tmptime;
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];
172 /***********************************************************************
173 * Globals for returning the return code and errno from the system call
174 * test macros.
175 ***********************************************************************/
176 long TEST_RETURN;
177 long TEST_ERRNO;
179 /***********************************************************************
180 * temporary variables for determining max and min times in TEST macro
181 ***********************************************************************/
182 long btime, etime, tmptime;
184 #endif /* _USC_LIB_ */
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;
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(int);
202 extern int (*_TMP_FUNC)(void);
203 extern void STD_opts_help(void);
206 /***********************************************************************
207 * TEST: calls a system call
209 * parameters:
210 * SCALL = system call and parameters to execute
212 ***********************************************************************/
213 #define TEST(SCALL) \
214 do { \
215 errno = 0; \
216 TEST_RETURN = SCALL; \
217 TEST_ERRNO = errno; \
218 } while (0)
220 /***********************************************************************
221 * TEST_VOID: calls a system call
223 * parameters:
224 * SCALL = system call and parameters to execute
226 * Note: This is IDENTICAL to the TEST() macro except that it is intended
227 * for use with syscalls returning no values (void syscall()). The
228 * Typecasting nothing (void) into an unsigned integer causes compilation
229 * errors.
231 ***********************************************************************/
232 #define TEST_VOID(SCALL) errno=0; SCALL; TEST_ERRNO=errno;
234 /***********************************************************************
235 * TEST_CLEANUP: print system call timing stats and errno log entries
236 * to stdout if STD_TIMING_ON and STD_ERRNO_LOG are set, respectively.
237 * Do NOT print ANY information if no system calls logged.
239 * parameters:
240 * none
242 ***********************************************************************/
243 #define TEST_CLEANUP \
244 if ( STD_ERRNO_LOG ) { \
245 for (tmptime=0; tmptime<USC_MAX_ERRNO; tmptime++) { \
246 if ( STD_ERRNO_LIST[tmptime] ) { \
247 if ( TEST_VALID_ENO[tmptime].flag ) \
248 tst_resm(TINFO, "ERRNO %d:\tReceived %d Times", \
249 tmptime, STD_ERRNO_LIST[tmptime]); \
250 else \
251 tst_resm(TINFO, \
252 "ERRNO %d:\tReceived %d Times ** UNEXPECTED **", \
253 tmptime, STD_ERRNO_LIST[tmptime]); \
258 /***********************************************************************
259 * TEST_PAUSEF: Pause for SIGUSR1 if the pause flag is set.
260 * Set the user specified function as the interrupt
261 * handler instead of "STD_go"
263 * parameters:
264 * none
266 ***********************************************************************/
267 #define TEST_PAUSEF(HANDLER) \
268 if ( STD_PAUSE ) { \
269 _TMP_FUNC = (int (*)(void))signal(SIGUSR1, HANDLER); \
270 pause(); \
271 signal(SIGUSR1, (void (*)(void))_TMP_FUNC); \
274 /***********************************************************************
275 * TEST_PAUSE: Pause for SIGUSR1 if the pause flag is set.
276 * Just continue when signal comes in.
278 * parameters:
279 * none
281 ***********************************************************************/
282 #define TEST_PAUSE usc_global_setup_hook();
283 int usc_global_setup_hook(void);
285 /***********************************************************************
286 * TEST_LOOPING now call the usc_test_looping function.
287 * The function will return 1 if the test should continue
288 * iterating.
290 ***********************************************************************/
291 #define TEST_LOOPING usc_test_looping
292 int usc_test_looping(int counter);
294 /***********************************************************************
295 * TEST_ERROR_LOG(eno): log this errno if STD_ERRNO_LOG flag set
297 * parameters:
298 * int eno: the errno location in STD_ERRNO_LIST to log.
300 ***********************************************************************/
301 #define TEST_ERROR_LOG(eno) \
302 if ( STD_ERRNO_LOG ) \
303 if ( eno < USC_MAX_ERRNO ) \
304 STD_ERRNO_LIST[eno]++; \
307 /***********************************************************************
308 * TEST_EXP_ENOS(array): set the bits associated with the nput errnos
309 * in the TEST_VALID_ENO array.
311 * parameters:
312 * int array[]: a zero terminated array of errnos expected.
314 ***********************************************************************/
315 #define TEST_EXP_ENOS(array) \
316 tmptime=0; \
317 while (array[tmptime] != 0) { \
318 if (array[tmptime] < USC_MAX_ERRNO) \
319 TEST_VALID_ENO[array[tmptime]].flag=1; \
320 tmptime++; \
324 #endif /* end of __USCTEST_H__ */