1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
8 #include <lib/errtest.h>
14 /*---------------------------------------------------------------------------
16 Test program used to test the DMAPI function dm_set_eventlist(). The
19 test_eventlist [-v] [-s sid] [-t token] directory
23 is the path to a specific copy of ls, important only for its size
25 is the pathname to a DMAPI filesystem.
27 is the dm_sessid_t value to use.
29 is the dm_token_t value to use (DM_NO_TOKEN is the default).
30 ----------------------------------------------------------------------------*/
33 extern char *sys_errlist[];
41 int check_one_event (dm_sessid_t, void*, size_t, dm_token_t,
47 fprintf(stderr, "usage:\t%s [-v] [-s sid] [-t token]"
48 "ls_path directory \n", Progname);
49 /* fprintf(stderr, "possible events are:\n");
50 for (i = 0; i < ev_namecnt; i++) {
51 fprintf(stderr, "%s (%d)\n", ev_names[i].name,
64 dm_sessid_t sid = DM_NO_SESSION;
65 dm_token_t token = DM_NO_TOKEN;
79 dm_token_t test_token = DM_NO_TOKEN;
80 dm_eventset_t eventset;
84 Progname = strrchr(argv[0], '/');
91 /* Crack and validate the command line options. */
93 while ((opt = getopt(argc, argv, "s:t:uv")) != EOF) {
105 if (Vflag==0) Vflag=1;
112 if (optind + 2 != argc)
114 ls_path = argv[optind];
115 dir_name = argv[optind+1];
117 if (dm_init_service(&name) == -1) {
118 fprintf(stderr, "Can't initialize the DMAPI\n");
122 if (sid == DM_NO_SESSION)
123 find_test_session(&sid);
125 /* Get the directory handle */
126 if (dm_path_to_handle(dir_name, &hanp, &hlen)) {
127 fprintf(stderr, "can't get handle for %s\n", dir_name);
131 /***********************************************\
132 |* Test to run on a FILE... *|
133 \***********************************************/
135 printf("File test beginning...\n");
136 sprintf(object, "%s/VeryLongUnlikelyFilename.DMAPIFOO", dir_name);
137 sprintf(command, "cp %s %s \n", ls_path, object);
140 if (dm_path_to_handle(object, &hanp, &hlen)) {
141 fprintf(stderr, "can't get handle for %s\n; aborting test",
145 for (i = 0; i < ev_namecnt; i++) {
146 error = check_one_event(sid, hanp, hlen, token,
147 ev_names[i].value, Vflag);
148 switch (ev_names[i].value){
149 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
151 fprintf(stderr, "ERROR: %s failed on a file!\n",
157 fprintf(stderr, "ERROR: %s succeeded on a file!\n",
162 /*------------------------*\
163 |* ## Errno subtests ## *|
164 \*------------------------*/
165 printf("\t(errno subtests beginning...)\n");
167 DMEV_SET(DM_EVENT_ATTRIBUTE, eventset);
168 /*---------------------------------------------------------*/
169 EXCLTEST("set", hanp, hlen, test_token,
170 dm_set_eventlist(sid, hanp, hlen, test_token,
171 &eventset, DM_EVENT_MAX))
172 /*---------------------------------------------------------*/
173 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
175 "Cannot create a test handle (%s); skipping EBADF test\n",
179 /* Alter the handle copy to make it (presumably) invalid */
180 ((char *) test_vp)[hlen/2]++;
183 dm_set_eventlist(sid, test_vp, hlen, token,
184 &eventset, DM_EVENT_MAX))
185 dm_handle_free(test_vp, hlen);
187 /*---------------------------------------------------------*/
189 /* Veritas gets a segmentation fault if hanp is NULL or if the
190 &eventset is out of range.
192 fprintf(stderr, "\tERROR testing for EFAULT in set (bad hanp): "
193 "Veritas gets a segmentation fault.\n");
194 fprintf(stderr, "\tERROR testing for EFAULT in set (bad eventset): "
195 "Veritas gets a segmentation fault.\n");
199 dm_set_eventlist(sid, NULL, hlen, token,
200 &eventset, DM_EVENT_MAX))
203 dm_set_eventlist(sid, hanp, hlen, token,
204 (dm_eventset_t*)(-1000), DM_EVENT_MAX))
206 /*---------------------------------------------------------*/
209 dm_set_eventlist(-100, hanp, hlen, token,
210 &eventset, DM_EVENT_MAX))
211 /*---------------------------------------------------------*/
214 dm_set_eventlist(sid, hanp, hlen, 0,
215 &eventset, DM_EVENT_MAX))
216 /*---------------------------------------------------------*/
218 PROBLEM: too-small buffer does not produce E2BIG
220 dm_eventset_t *small_evsp = malloc(0);
221 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
223 "can't get filesystem handle from %s; aborting test\n",
227 check_one_event(sid, fshanp, fshlen, token,
228 DM_EVENT_CREATE, Vflag);
231 dm_get_eventlist(sid, fshanp, fshlen, token,
232 DM_EVENT_MAX, small_evsp, &nelemp))
233 check_one_event(sid, fshanp, fshlen, token,
234 DM_EVENT_INVALID, Vflag);
238 /*---------------------------------------------------------*/
239 SHAREDTEST("get", hanp, hlen, test_token,
240 dm_get_eventlist(sid, hanp, hlen, test_token,
241 DM_EVENT_MAX, &eventset, &nelemp))
242 /*---------------------------------------------------------*/
245 dm_get_eventlist(sid, test_vp, hlen, token, DM_EVENT_MAX,
247 /*---------------------------------------------------------*/
249 /* Veritas gets a segmentation fault if hanp is NULL. */
251 fprintf(stderr, "\tERROR testing for EFAULT in get (bad hanp): "
252 "Veritas gets a segmentation fault.\n");
256 dm_get_eventlist(sid, NULL, hlen, token, DM_EVENT_MAX,
257 &eventset, &nelemp ))
259 /*---------------------------------------------------------*/
262 dm_get_eventlist(-100, hanp, hlen, token, DM_EVENT_MAX,
264 /*---------------------------------------------------------*/
267 dm_get_eventlist(sid, hanp, hlen, 0, DM_EVENT_MAX,
269 /*---------------------------------------------------------*/
270 printf("\t(errno subtests complete)\n");
271 /*---------------------*\
272 |* End of errno tests *|
273 \*---------------------*/
275 /* Finally, use DM_EVENT_INVALID to delete events... */
276 check_one_event(sid, hanp, hlen, token, DM_EVENT_INVALID, Vflag);
278 sprintf(command, "rm %s \n", object);
280 printf("\tFile test complete.\n");
281 if (Vflag) printf("\n");
283 /***********************************************\
284 |* Test to run on a DIRECTORY... *|
285 \***********************************************/
287 printf("Directory test beginning...\n");
288 sprintf(object, "%s/VeryLongUnlikelyDirectoryName.DMAPIFOO",
290 sprintf(command, "mkdir %s \n", object);
293 if (opaque_to_handle(object, &hanp, &hlen)) {
294 fprintf(stderr, "can't get handle for %s\n; aborting test",
298 for (i = 0; i < ev_namecnt; i++) {
299 error = check_one_event(sid, hanp, hlen, token,
300 ev_names[i].value, Vflag);
301 switch (ev_names[i].value){
302 case DM_EVENT_CREATE: case DM_EVENT_POSTCREATE:
303 case DM_EVENT_REMOVE: case DM_EVENT_POSTREMOVE:
304 case DM_EVENT_RENAME: case DM_EVENT_POSTRENAME:
305 case DM_EVENT_LINK: case DM_EVENT_POSTLINK:
306 case DM_EVENT_SYMLINK: case DM_EVENT_POSTSYMLINK:
307 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
309 fprintf(stderr, "ERROR: %s failed on a directory!\n",
315 fprintf(stderr, "ERROR: %s succeeded on a directory!\n",
320 /* Use DM_EVENT_INVALID to delete events... */
321 check_one_event(sid, hanp, hlen, token, DM_EVENT_INVALID, Vflag);
323 sprintf(object, "%s/VeryLongUnlikelyDirectoryName.DMAPIFOO", dir_name);
324 sprintf(command, "rmdir %s\n", object);
326 printf("\tDirectory test complete.\n");
327 if (Vflag) printf("\n");
329 /***********************************************\
330 |* Test to run on a FILESYSTEM... *|
331 \***********************************************/
333 printf("Filesystem test beginning...\n");
335 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
337 "can't get filesystem handle from %s; aborting test\n",
341 for (i = 0; i < ev_namecnt; i++) {
342 error = check_one_event(sid, fshanp, fshlen, token,
343 ev_names[i].value, Vflag);
344 switch (ev_names[i].value){
345 case DM_EVENT_PREUNMOUNT: case DM_EVENT_UNMOUNT:
346 case DM_EVENT_NOSPACE: case DM_EVENT_DEBUT:
347 case DM_EVENT_CREATE: case DM_EVENT_POSTCREATE:
348 case DM_EVENT_REMOVE: case DM_EVENT_POSTREMOVE:
349 case DM_EVENT_RENAME: case DM_EVENT_POSTRENAME:
350 case DM_EVENT_LINK: case DM_EVENT_POSTLINK:
351 case DM_EVENT_SYMLINK: case DM_EVENT_POSTSYMLINK:
352 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
354 fprintf(stderr, "ERROR: %s failed on a filesystem!\n",
360 fprintf(stderr, "ERROR: %s succeeded on a filesystem!\n",
365 /* Use DM_EVENT_INVALID to delete events... */
366 check_one_event(sid, fshanp, fshlen, token, DM_EVENT_INVALID, Vflag);
368 printf("\tFilesystem test complete.\n");
370 /***********************************************\
372 \***********************************************/
374 dm_handle_free(fshanp, fshlen);
375 dm_handle_free(hanp, hlen);
379 /*-------------------------------------------------------------------
382 Using dm_set_eventlist, set a single event on the object
383 indicated by the handle.
385 Using dm_get_eventlist, check to see that the single event
387 -------------------------------------------------------------------*/
395 dm_eventtype_t event,
398 dm_eventset_t eventset;
399 dm_eventset_t check_eventset;
405 DMEV_ZERO(check_eventset);
407 if (event != DM_EVENT_INVALID) {
408 DMEV_SET(event, eventset);
411 if (dm_set_eventlist(sid, hanp, hlen, token,
412 &eventset, DM_EVENT_MAX)) {
414 fprintf(stdout, " note: %s could not be set (%s)\n",
415 ev_value_to_name(event), errno_names[errno]);
420 if (dm_get_eventlist(sid, hanp, hlen, token,
421 DM_EVENT_MAX, &check_eventset, &nelemp)) {
423 fprintf(stdout, "dm_get_eventlist failed, %s\n",
429 /* For each element, see that get_eventlist agrees
430 * with set_eventlist; if not, make noise.
432 for (i = 0; i < ev_namecnt; i++) {
433 int set = DMEV_ISSET(ev_names[i].value, eventset);
434 int found = DMEV_ISSET(ev_names[i].value, check_eventset);
436 fprintf(stderr, "ERROR: event %s was set but not found.\n",
440 else if (!set && found) {
441 fprintf(stderr, "ERROR: Found unexpected event %s \n",
445 else if ((Vflag == 2) && !set && !found) {
446 fprintf(stderr, "clear: %s\n",
449 else if (Vflag && set && found) {
450 fprintf(stderr, " SET: %s\n", ev_names[i].name);
454 if (Vflag && set_count == 0) {
455 fprintf(stderr, "\t(All events cleared)\n");