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