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