2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include <lib/errtest.h>
40 /*---------------------------------------------------------------------------
42 Test program used to test the DMAPI function dm_set_eventlist(). The
45 test_eventlist [-v] [-s sid] [-t token] directory
49 is the path to a specific copy of ls, important only for its size
51 is the pathname to a DMAPI filesystem.
53 is the dm_sessid_t value to use.
55 is the dm_token_t value to use (DM_NO_TOKEN is the default).
56 ----------------------------------------------------------------------------*/
59 extern char *sys_errlist[];
67 int check_one_event (dm_sessid_t, void*, size_t, dm_token_t,
73 fprintf(stderr, "usage:\t%s [-v] [-s sid] [-t token]"
74 "ls_path directory \n", Progname);
75 /* fprintf(stderr, "possible events are:\n");
76 for (i = 0; i < ev_namecnt; i++) {
77 fprintf(stderr, "%s (%d)\n", ev_names[i].name,
90 dm_sessid_t sid = DM_NO_SESSION;
91 dm_token_t token = DM_NO_TOKEN;
105 dm_token_t test_token = DM_NO_TOKEN;
106 dm_eventset_t eventset;
110 if (Progname = strrchr(argv[0], '/')) {
116 /* Crack and validate the command line options. */
118 while ((opt = getopt(argc, argv, "s:t:uv")) != EOF) {
124 token = atol(optarg);
130 if (Vflag==0) Vflag=1;
137 if (optind + 2 != argc)
139 ls_path = argv[optind];
140 dir_name = argv[optind+1];
142 if (dm_init_service(&name) == -1) {
143 fprintf(stderr, "Can't initialize the DMAPI\n");
147 if (sid == DM_NO_SESSION)
148 find_test_session(&sid);
150 /* Get the directory handle */
151 if (dm_path_to_handle(dir_name, &hanp, &hlen)) {
152 fprintf(stderr, "can't get handle for %s\n", dir_name);
156 /***********************************************\
157 |* Test to run on a FILE... *|
158 \***********************************************/
160 printf("File test beginning...\n");
161 sprintf(object, "%s/VeryLongUnlikelyFilename.DMAPIFOO", dir_name);
162 sprintf(command, "cp %s %s \n", ls_path, object);
165 if (dm_path_to_handle(object, &hanp, &hlen)) {
166 fprintf(stderr, "can't get handle for %s\n; aborting test",
170 for (i = 0; i < ev_namecnt; i++) {
171 error = check_one_event(sid, hanp, hlen, token,
172 ev_names[i].value, Vflag);
173 switch (ev_names[i].value){
174 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
176 fprintf(stderr, "ERROR: %s failed on a file!\n",
182 fprintf(stderr, "ERROR: %s succeeded on a file!\n",
187 /*------------------------*\
188 |* ## Errno subtests ## *|
189 \*------------------------*/
190 printf("\t(errno subtests beginning...)\n");
192 DMEV_SET(DM_EVENT_ATTRIBUTE, eventset);
193 /*---------------------------------------------------------*/
194 EXCLTEST("set", hanp, hlen, test_token,
195 dm_set_eventlist(sid, hanp, hlen, test_token,
196 &eventset, DM_EVENT_MAX))
197 /*---------------------------------------------------------*/
198 if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
200 "Cannot create a test handle (%s); skipping EBADF test\n",
204 /* Alter the handle copy to make it (presumably) invalid */
205 ((char *) test_vp)[hlen/2]++;
208 dm_set_eventlist(sid, test_vp, hlen, token,
209 &eventset, DM_EVENT_MAX))
210 dm_handle_free(test_vp, hlen);
212 /*---------------------------------------------------------*/
214 /* Veritas gets a segmentation fault if hanp is NULL or if the
215 &eventset is out of range.
217 fprintf(stderr, "\tERROR testing for EFAULT in set (bad hanp): "
218 "Veritas gets a segmentation fault.\n");
219 fprintf(stderr, "\tERROR testing for EFAULT in set (bad eventset): "
220 "Veritas gets a segmentation fault.\n");
224 dm_set_eventlist(sid, NULL, hlen, token,
225 &eventset, DM_EVENT_MAX))
228 dm_set_eventlist(sid, hanp, hlen, token,
229 (dm_eventset_t*)(-1000), DM_EVENT_MAX))
231 /*---------------------------------------------------------*/
234 dm_set_eventlist(-100, hanp, hlen, token,
235 &eventset, DM_EVENT_MAX))
236 /*---------------------------------------------------------*/
239 dm_set_eventlist(sid, hanp, hlen, 0,
240 &eventset, DM_EVENT_MAX))
241 /*---------------------------------------------------------*/
243 PROBLEM: too-small buffer does not produce E2BIG
245 dm_eventset_t *small_evsp = malloc(0);
246 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
248 "can't get filesystem handle from %s; aborting test\n",
252 check_one_event(sid, fshanp, fshlen, token,
253 DM_EVENT_CREATE, Vflag);
256 dm_get_eventlist(sid, fshanp, fshlen, token,
257 DM_EVENT_MAX, small_evsp, &nelemp))
258 check_one_event(sid, fshanp, fshlen, token,
259 DM_EVENT_INVALID, Vflag);
263 /*---------------------------------------------------------*/
264 SHAREDTEST("get", hanp, hlen, test_token,
265 dm_get_eventlist(sid, hanp, hlen, test_token,
266 DM_EVENT_MAX, &eventset, &nelemp))
267 /*---------------------------------------------------------*/
270 dm_get_eventlist(sid, test_vp, hlen, token, DM_EVENT_MAX,
272 /*---------------------------------------------------------*/
274 /* Veritas gets a segmentation fault if hanp is NULL. */
276 fprintf(stderr, "\tERROR testing for EFAULT in get (bad hanp): "
277 "Veritas gets a segmentation fault.\n");
281 dm_get_eventlist(sid, NULL, hlen, token, DM_EVENT_MAX,
282 &eventset, &nelemp ))
284 /*---------------------------------------------------------*/
287 dm_get_eventlist(-100, hanp, hlen, token, DM_EVENT_MAX,
289 /*---------------------------------------------------------*/
292 dm_get_eventlist(sid, hanp, hlen, 0, DM_EVENT_MAX,
294 /*---------------------------------------------------------*/
295 printf("\t(errno subtests complete)\n");
296 /*---------------------*\
297 |* End of errno tests *|
298 \*---------------------*/
300 /* Finally, use DM_EVENT_INVALID to delete events... */
301 check_one_event(sid, hanp, hlen, token, DM_EVENT_INVALID, Vflag);
303 sprintf(command, "rm %s \n", object);
305 printf("\tFile test complete.\n");
306 if (Vflag) printf("\n");
308 /***********************************************\
309 |* Test to run on a DIRECTORY... *|
310 \***********************************************/
312 printf("Directory test beginning...\n");
313 sprintf(object, "%s/VeryLongUnlikelyDirectoryName.DMAPIFOO",
315 sprintf(command, "mkdir %s \n", object);
318 if (opaque_to_handle(object, &hanp, &hlen)) {
319 fprintf(stderr, "can't get handle for %s\n; aborting test",
323 for (i = 0; i < ev_namecnt; i++) {
324 error = check_one_event(sid, hanp, hlen, token,
325 ev_names[i].value, Vflag);
326 switch (ev_names[i].value){
327 case DM_EVENT_CREATE: case DM_EVENT_POSTCREATE:
328 case DM_EVENT_REMOVE: case DM_EVENT_POSTREMOVE:
329 case DM_EVENT_RENAME: case DM_EVENT_POSTRENAME:
330 case DM_EVENT_LINK: case DM_EVENT_POSTLINK:
331 case DM_EVENT_SYMLINK: case DM_EVENT_POSTSYMLINK:
332 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
334 fprintf(stderr, "ERROR: %s failed on a directory!\n",
340 fprintf(stderr, "ERROR: %s succeeded on a directory!\n",
345 /* Use DM_EVENT_INVALID to delete events... */
346 check_one_event(sid, hanp, hlen, token, DM_EVENT_INVALID, Vflag);
348 sprintf(object, "%s/VeryLongUnlikelyDirectoryName.DMAPIFOO", dir_name);
349 sprintf(command, "rmdir %s\n", object);
351 printf("\tDirectory test complete.\n");
352 if (Vflag) printf("\n");
354 /***********************************************\
355 |* Test to run on a FILESYSTEM... *|
356 \***********************************************/
358 printf("Filesystem test beginning...\n");
360 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
362 "can't get filesystem handle from %s; aborting test\n",
366 for (i = 0; i < ev_namecnt; i++) {
367 error = check_one_event(sid, fshanp, fshlen, token,
368 ev_names[i].value, Vflag);
369 switch (ev_names[i].value){
370 case DM_EVENT_PREUNMOUNT: case DM_EVENT_UNMOUNT:
371 case DM_EVENT_NOSPACE: case DM_EVENT_DEBUT:
372 case DM_EVENT_CREATE: case DM_EVENT_POSTCREATE:
373 case DM_EVENT_REMOVE: case DM_EVENT_POSTREMOVE:
374 case DM_EVENT_RENAME: case DM_EVENT_POSTRENAME:
375 case DM_EVENT_LINK: case DM_EVENT_POSTLINK:
376 case DM_EVENT_SYMLINK: case DM_EVENT_POSTSYMLINK:
377 case DM_EVENT_ATTRIBUTE: case DM_EVENT_DESTROY:
379 fprintf(stderr, "ERROR: %s failed on a filesystem!\n",
385 fprintf(stderr, "ERROR: %s succeeded on a filesystem!\n",
390 /* Use DM_EVENT_INVALID to delete events... */
391 check_one_event(sid, fshanp, fshlen, token, DM_EVENT_INVALID, Vflag);
393 printf("\tFilesystem test complete.\n");
395 /***********************************************\
397 \***********************************************/
399 dm_handle_free(fshanp, fshlen);
400 dm_handle_free(hanp, hlen);
404 /*-------------------------------------------------------------------
407 Using dm_set_eventlist, set a single event on the object
408 indicated by the handle.
410 Using dm_get_eventlist, check to see that the single event
412 -------------------------------------------------------------------*/
420 dm_eventtype_t event,
423 dm_eventset_t eventset;
424 dm_eventset_t check_eventset;
430 DMEV_ZERO(check_eventset);
432 if (event != DM_EVENT_INVALID) {
433 DMEV_SET(event, eventset);
436 if (dm_set_eventlist(sid, hanp, hlen, token,
437 &eventset, DM_EVENT_MAX)) {
439 fprintf(stdout, " note: %s could not be set (%s)\n",
440 ev_value_to_name(event), errno_names[errno]);
445 if (dm_get_eventlist(sid, hanp, hlen, token,
446 DM_EVENT_MAX, &check_eventset, &nelemp)) {
448 fprintf(stdout, "dm_get_eventlist failed, %s\n",
454 /* For each element, see that get_eventlist agrees
455 * with set_eventlist; if not, make noise.
457 for (i = 0; i < ev_namecnt; i++) {
458 int set = DMEV_ISSET(ev_names[i].value, eventset);
459 int found = DMEV_ISSET(ev_names[i].value, check_eventset);
461 fprintf(stderr, "ERROR: event %s was set but not found.\n",
465 else if (!set && found) {
466 fprintf(stderr, "ERROR: Found unexpected event %s \n",
470 else if ((Vflag == 2) && !set && !found) {
471 fprintf(stderr, "clear: %s\n",
474 else if (Vflag && set && found) {
475 fprintf(stderr, " SET: %s\n", ev_names[i].name);
479 if (Vflag && set_count == 0) {
480 fprintf(stderr, "\t(All events cleared)\n");