Update copyright dates (again)
[xfstests-dev.git] / dmapi / src / suite2 / lib / errtest.h
1 /*
2  * Copyright (c) 2000-2001 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/SGIGPLNoticeExplan/
31  */
32 #ifndef __ERRTEST_SEEN
33 #define __ERRTEST_SEEN
34
35 #include <strings.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39
40 #define NUM_ERRS 100
41
42 void* handle_clone(void* src_hanp, u_int hlen );
43
44 char    *
45 errno_names[] = {
46         "ERROR_0",
47         "EPERM",
48         "ENOENT",
49         "ESRCH",
50         "EINTR",
51         "EIO",
52         "ENXIO",
53         "E2BIG",
54         "ENOEXEC",
55         "EBADF",
56         "ECHILD",
57         "EAGAIN",
58         "ENOMEM",
59         "EACCES",
60         "EFAULT",
61         "ENOTBLK",
62         "EBUSY",
63         "EEXIST",
64         "EXDEV",
65         "ENODEV",
66         "ENOTDIR",
67         "EISDIR",
68         "EINVAL",
69         "ENFILE",
70         "EMFILE",
71         "ENOTTY",
72         "ETXTBSY",
73         "EFBIG",
74         "ENOSPC",
75         "ESPIPE",
76         "EROFS",
77         "EMLINK",
78         "EPIPE",
79         "EDOM",
80         "ERANGE",
81         "ENOMSG",
82         "EIDRM",
83         "ECHRNG",
84         "EL2NSYNC",
85         "EL3HLT",
86         "EL3RST",
87         "ELNRNG",
88         "EUNATCH",
89         "ENOCSI",
90         "EL2HLT",
91         "EDEADLK",
92         "ENOLCK",
93         "ERROR_47",
94         "ERROR_48",
95         "ERROR_49",
96         "EBADE",
97         "EBADR",
98         "EXFULL",
99         "ENOANO",
100         "EBADRQC",
101         "EBADSLT",
102         "EDEADLOCK",
103         "EBFONT",
104         "ERROR_58",
105         "ERROR_59",
106         "ENOSTR",
107         "ENODATA",
108         "ETIME",
109         "ENOSR",
110         "ENONET",
111         "ENOPKG",
112         "EREMOTE",
113         "ENOLINK",
114         "EADV",
115         "ESRMNT",
116         "ECOMM",
117         "EPROTO",
118         "ERROR_72",
119         "ERROR_73",
120         "EMULTIHOP",
121         "ERROR_75",
122         "ERROR_76",
123         "EBADMSG",
124         "ENAMETOOLONG",
125         "EOVERFLOW",
126         "ENOTUNIQ",
127         "EBADFD",
128         "EREMCHG",
129         "ELIBACC",
130         "ELIBBAD",
131         "ELIBSCN",
132         "ELIBMAX",
133         "ELIBEXEC",
134         "EILSEQ",
135         "ENOSYS",
136         "ELOOP",
137         "ERESTART",
138         "ESTRPIPE",
139         "ENOTEMPTY",
140         "EUSERS",
141         "ENOTSOCK",
142         "EDESTADDRREQ",
143         "EMSGSIZE",
144         "EPROTOTYPE",
145         "ENOPROTOOPT" };
146
147 #define ERR_NAME                                                        \
148         ((errno<NUM_ERRS)?(errno_names[errno]):("an unknown errno"))
149
150 #define ERRTEST(EXPECTED, NAME, FUNCTION)                               \
151     if ((FUNCTION) < 0) {                                               \
152       if (errno == (EXPECTED)) {                                        \
153         if (Vflag)                                                      \
154           fprintf(stdout,"\treport on test for " #EXPECTED              \
155                           " in %s: test successful\n", (NAME));         \
156       }                                                                 \
157       else {                                                            \
158         fprintf(stdout, "\tERROR testing for " #EXPECTED                \
159                   " in %s: found %s.\n", (NAME), ERR_NAME);             \
160       }                                                                 \
161     }                                                                   \
162     else {                                                              \
163       fprintf(stdout, "\tERROR testing for " #EXPECTED                  \
164               " in %s: no error was produced!\n", (NAME));              \
165     }
166
167
168 #define EXCLTEST(NAME, HANP, HLEN, TOKEN, FUNCTION)                      \
169 if (dm_create_userevent(sid, 10, "DMAPI" NAME, &(TOKEN))) {             \
170   fprintf(stdout,                                                       \
171           "\tERROR: can't create token (%s); skipping EACCES test\n",   \
172           ERR_NAME);                                                    \
173 }                                                                       \
174 else {                                                                  \
175   ERRTEST(EACCES, "no-right " NAME, (FUNCTION))                         \
176                                                                         \
177   if (dm_request_right(sid, (HANP), (HLEN), (TOKEN), 0, DM_RIGHT_SHARED))       \
178     fprintf(stdout, "\t"NAME" ERROR: Couldn't upgrade to SHARED. %s\n", \
179             ERR_NAME);                                                  \
180   else ERRTEST(EACCES, "SHARED " NAME, (FUNCTION))                      \
181                                                                         \
182   if (dm_request_right(sid, (HANP), (HLEN), (TOKEN), 0, DM_RIGHT_EXCL)) \
183     fprintf(stdout, "\t"NAME" ERROR: Couldn't upgrade to EXCL: %s\n",   \
184             ERR_NAME);                                                  \
185   else if ((FUNCTION) < 0)                                              \
186     fprintf(stdout, "\t"NAME" ERROR: token with DM_RIGHT_EXCL was "     \
187             "denied access: %s\n", ERR_NAME);                           \
188   else if (Vflag)                                                       \
189     fprintf(stdout, "\treport on test for success in EXCL "NAME": "     \
190             "test successful.\n");                                      \
191                                                                         \
192   if (dm_respond_event(sid, (TOKEN), DM_RESP_CONTINUE, 0, 0, 0))        \
193     fprintf(stdout, "\tERROR in responding to token: %s\n", ERR_NAME);  \
194 }
195
196
197
198 #define SHAREDTEST(NAME, HANP, HLEN,  TOKEN, FUNCTION)                  \
199 if (dm_create_userevent(sid, 10, "DMAPI" NAME, &(TOKEN))) {             \
200      fprintf(stdout,                                                    \
201              "\tCannot create_userevent (%s); skipping EACCES test\n",  \
202              ERR_NAME);                                                 \
203 }                                                                       \
204 else {                                                                  \
205   ERRTEST(EACCES, "no-right " NAME, (FUNCTION))                         \
206                                                                         \
207   if (dm_request_right(sid, (HANP), (HLEN), (TOKEN),                    \
208                        0, DM_RIGHT_SHARED))                             \
209     fprintf(stdout, "\t"NAME" ERROR: Couldn't upgrade to EXCL. %s\n",   \
210             ERR_NAME);                                                  \
211   else if ((FUNCTION) < 0)                                              \
212     fprintf(stdout, "\t" NAME" ERROR: token with DM_RIGHT_SHARED "      \
213             "was denied access. %s\n", ERR_NAME);                       \
214   else if (Vflag)                                                       \
215     fprintf(stdout, "\treport on test for success in SHARED "NAME": "   \
216             "test successful.\n");                                      \
217                                                                         \
218   if (dm_request_right(sid, (HANP), (HLEN), (TOKEN), 0, DM_RIGHT_EXCL)) \
219     fprintf(stdout, "\t"NAME" ERROR: Couldn't upgrade to EXCL. %s\n",   \
220             ERR_NAME);                                                  \
221   else if ((FUNCTION) < 0)                                              \
222       fprintf(stdout, "\t" NAME" ERROR: token with DM_RIGHT_EXCL was "  \
223               "denied access. %s\n", ERR_NAME);                         \
224   else if (Vflag)                                                       \
225     fprintf(stdout, "\treport on test for success in EXCL "NAME": "     \
226             "test successful.\n");                                      \
227                                                                         \
228   if (dm_respond_event(sid, (TOKEN), DM_RESP_CONTINUE, 0, 0, 0))        \
229     fprintf(stderr, "\tERROR in responding to token: %s\n", ERR_NAME);  \
230 }
231
232
233
234 void* 
235 handle_clone(void* src_hanp, u_int hlen )
236 {
237   void* dest_hanp;
238
239   if ((dest_hanp = malloc(hlen)) == NULL) return(NULL);
240   bcopy(src_hanp, dest_hanp, hlen);
241   return(dest_hanp);
242 }
243
244 #endif
245