check: allow '-e testid' to exclude a single test
[xfstests-dev.git] / dmapi / src / suite2 / src / test_fileattr.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <sys/types.h>
8 #include <sys/stat.h>
9
10 #include <errno.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <strings.h>
14
15 #include <lib/dmport.h>
16 #include <lib/hsm.h>
17 #include <lib/errtest.h>
18
19 #include <unistd.h>
20
21 #include <time.h>
22 #include <string.h>
23
24
25 /*---------------------------------------------------------------------------
26 Automated test of the DMAPI functions:
27    dm_set_fileattr()
28    dm_get_fileattr()
29    dm_get_bulkattr()
30    dm_get_dirattrs()
31
32 The command line is:
33    test_fileattr [-s sid] [-n num_files] [-v] ls_path pathname
34
35 where:
36    sid
37       is the session ID whose events you you are interested in.
38    num_files
39       is the number of test files to create.
40    ls_path
41       is the path to a copy of ls, which will be copied as a test file.
42    pathname
43       is the filesystem to use for the test.
44 ----------------------------------------------------------------------------*/
45
46 #define SET_MASK  DM_AT_ATIME|DM_AT_MTIME|DM_AT_CTIME|DM_AT_DTIME|\
47                   DM_AT_UID|DM_AT_GID|DM_AT_MODE|DM_AT_SIZE 
48
49 #define GET_MASK DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|\
50                   DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT
51
52 extern  int     optind;
53 extern  int     opterr;
54 extern  char    *optarg;
55
56 char    *Progname;
57 int     Vflag=0;
58
59
60 int
61 comp_stat ( dm_stat_t expected,
62             dm_stat_t found,
63             int       i)
64 {
65    int good=0;
66    if (found.dt_mode != expected.dt_mode) {
67      fprintf(stderr, 
68              "ERROR: get #%d, expected mode %ld, but found %ld\n",
69              i, (long)expected.dt_mode, (long)found.dt_mode);
70    }
71    else good++;
72    if (found.dt_uid != expected.dt_uid) {
73      fprintf(stderr, 
74              "ERROR: get #%d, expected uid %ld, but found %ld\n",
75              i, (long)expected.dt_uid, (long)found.dt_uid);
76    }
77    else good++;
78    if (found.dt_gid != expected.dt_gid) {
79      fprintf(stderr, 
80              "ERROR: get #%d, expected gid %ld, but found %ld\n",
81              i, (long)expected.dt_gid, (long)found.dt_gid);
82    }
83    else good++;
84    if (found.dt_atime != expected.dt_atime) {
85      fprintf(stderr, 
86              "ERROR: get #%d, expected atime %ld, but found %ld\n",
87              i, expected.dt_atime, found.dt_atime);
88    }
89    else good++;
90    if (found.dt_mtime != expected.dt_mtime) {
91      fprintf(stderr, 
92              "ERROR: get #%d, expected mtime %ld, but found %ld\n",
93              i, expected.dt_mtime, found.dt_mtime);
94    }
95    else good++;
96    if (found.dt_ctime != expected.dt_ctime) {
97      fprintf(stderr, 
98              "ERROR: get #%d, expected ctime %ld, but found %ld\n",
99              i, expected.dt_ctime, found.dt_ctime);
100    }
101    else good++;
102    
103    /* NOTE: dtime gets set to ctime */
104    
105    if (found.dt_dtime != expected.dt_ctime) {
106      fprintf(stderr, 
107              "ERROR: get #%d, expected dtime %ld, but found %ld\n",
108              i, expected.dt_ctime, found.dt_dtime);
109    }
110    else good++;
111    if (found.dt_size != expected.dt_size) {
112      fprintf(stderr, 
113              "ERROR: get #%d, expected size %lld, but found %lld\n",
114              i, (long long) expected.dt_size, (long long) found.dt_size);
115    }
116    else good++;
117    if (Vflag){
118      if (good==8) {
119        fprintf(stderr, "report: get #%d had no errors.\n",i);
120      } else {
121        fprintf(stderr, "report: %d tests correct for get #%d.\n", 
122                good, i);
123      }
124    }
125    return(good);
126 }
127
128
129 static void
130 usage(void)
131 {
132         fprintf(stderr, 
133                 "Usage: %s [-v] [-s sid] [-n num_files] ls_path pathname\n",
134                 Progname);
135         exit(1);
136 }
137
138
139 int
140 main(
141         int     argc,
142         char    **argv)
143 {
144         dm_sessid_t     sid = DM_NO_SESSION;
145         dm_token_t      test_token = DM_NO_TOKEN;
146         void            *hanp;
147         size_t          hlen;
148         char            *ls_path;
149         char            *pathname;
150         char            test_file[100];
151         char            command[200];
152         int             num_files=50;
153         dm_stat_t       *stat_arr;
154         dm_stat_t       dmstat;
155         dm_fileattr_t   fileattr;
156         char            *name;
157         int             opt;
158         int             oops=1;
159         int             i=0;
160         dm_attrloc_t    loc;
161         size_t          buflen = 16*sizeof(dm_stat_t);
162         size_t          rlen;
163         void            *bufp;
164         dm_stat_t       *statbuf;
165         int             loops=0;
166         void            *fs_hanp;
167         size_t          fs_hlen;
168         void            *targhanp;
169         size_t          targhlen;
170         char            check_name[100];
171         char            *chk_name_p;
172         int             chk_num;
173
174         Progname = strrchr(argv[0], '/');
175         if (Progname) {
176                 Progname++;
177         } else {
178                 Progname = argv[0];
179         }
180
181         opterr = 0;
182         while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
183                 switch (opt) {
184                 case 'v':
185                          Vflag++;
186                          break;
187                 case 'n':
188                          num_files = atoi(optarg);
189                          break;
190                 case 's': 
191                          sid = atol(optarg);
192                          break;
193                 case '?':
194                          usage();
195                 }
196         }
197         if (optind + 2 != argc) {
198                 usage();
199         }
200         ls_path = argv[optind];
201         pathname = argv[optind+1];
202
203         /* Seed the random number generator */
204         srand((unsigned int)time(NULL)); 
205
206         if (dm_init_service(&name) == -1)  {
207                 fprintf(stderr, "Can't initialize the DMAPI\n");
208                 exit(1);
209         }
210         if (sid == DM_NO_SESSION)
211                 find_test_session(&sid);
212         
213         /* Dynamically allocate stat_arr; */
214         stat_arr = 
215           (dm_stat_t *)malloc(num_files * sizeof(dm_stat_t));
216         
217         printf("Beginning file attribute tests...\n");
218
219         /* Fill in the dm_stat blocks with lots of junk...
220          */
221         for (i=0; i<num_files; i++) {
222           /*
223            * XFS inode timestamp t_sec is a 32 bit signed value. rand() only
224            * returns 15 bits of random number, and so the rand()*0x10000 is
225            * really a rand() << 16 to populate the upper 16 bits of
226            * the timestamp.IOWs, linux does not need this but irix does.
227            */
228           stat_arr[i].dt_atime=((time_t)(rand()+rand()*0x10000) & 0x7FFFFFFF);
229           stat_arr[i].dt_mtime=((time_t)(rand()+rand()*0x10000) & 0x7FFFFFFF);
230           stat_arr[i].dt_ctime=((time_t)(rand()+rand()*0x10000) & 0x7FFFFFFF);
231           stat_arr[i].dt_dtime=((time_t)(rand()+rand()*0x10000) & 0x7FFFFFFF);
232
233           stat_arr[i].dt_uid=(uid_t)(rand()+rand()*0x10000);
234           stat_arr[i].dt_gid=(gid_t)(rand()+rand()*0x10000);
235           stat_arr[i].dt_mode=(mode_t)((rand()%4096)+32768);
236           stat_arr[i].dt_size=((dm_off_t)(rand()+rand()*0x10000)) & 0x1FFFFFFFFFFULL; /* 1 TB max */
237         }       
238
239         /*-----------------------------------------------------*\
240         |* File creation and set_fileattr loop                 *|
241         \*-----------------------------------------------------*/
242         if (Vflag) fprintf(stderr, "\nCreating/setting up test files.\n");
243         for (i=0; i < num_files; i++) {
244           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
245                   pathname, i);
246           sprintf(command, "cp %s %s \n", ls_path, test_file); 
247           system(command);
248
249           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
250             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
251                     test_file, ERR_NAME);
252           }
253           else {
254             fileattr.fa_mode  = stat_arr[i].dt_mode;
255             fileattr.fa_uid   = stat_arr[i].dt_uid;
256             fileattr.fa_gid   = stat_arr[i].dt_gid;
257             fileattr.FA_ATIME = stat_arr[i].dt_atime;
258             fileattr.FA_MTIME = stat_arr[i].dt_mtime;
259             fileattr.FA_CTIME = stat_arr[i].dt_ctime;
260             fileattr.FA_DTIME = stat_arr[i].dt_dtime;
261             fileattr.fa_size  = stat_arr[i].dt_size;
262             if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
263                                 SET_MASK, &fileattr)) {
264               fprintf(stderr, "ERROR: set_fileattr failed on pass #%d; %s.\n",
265                       i, ERR_NAME);
266             }
267             else if (Vflag) {
268               fprintf(stderr, "report: set #%d was successful.\n", i);
269             }
270           }
271         }
272         sync();
273         /*-----------------------------------------------------*\
274         |* Get_fileattr loop                                   *|
275         \*-----------------------------------------------------*/
276         if (Vflag) fprintf(stderr, "\nRunning get_fileattr test\n");
277         for (i=0; i < num_files; i++) {
278           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
279                   pathname, i);
280           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
281             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
282                     test_file, ERR_NAME);
283           }
284           if (dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
285                               GET_MASK, &dmstat)) {
286             fprintf(stderr,
287                     "ERROR: dm_get_fileattr failed on pass #%d, %s\n",
288                     i, ERR_NAME);
289           }
290           else {
291             comp_stat(stat_arr[i], dmstat, i); 
292           }
293         }
294           
295         /*-----------------------------------------------------*\
296         |* Get_dirattrs loop                                   *|
297         \*-----------------------------------------------------*/
298         if (Vflag) fprintf(stderr, "\nRunning get_dirattrs test\n");
299         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
300           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
301                   pathname, ERR_NAME);
302           goto abort_test;
303         }
304         if ((bufp = (void*)malloc(buflen)) == NULL) {
305           fprintf(stderr, "Can't allocate memory for buffer.\n");
306             goto abort_test;
307         }
308         if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
309           fprintf(stderr, 
310                   "ERROR: dm_init_attrloc failed with %s.\n",
311                   ERR_NAME);
312           goto abort_test;
313         }
314         i=0; 
315         loops=0;
316         do {
317           /* printf("About to call get_dirattrs;\tloops=%d\n", loops);
318            * fflush(stdout);
319            * sleep(1);
320            */
321           oops=dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
322                                GET_MASK, &loc, buflen,
323                                bufp, &rlen);
324           if (rlen==0) break;
325           for (statbuf = bufp; statbuf != NULL; 
326                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *)) {
327             chk_name_p = DM_GET_VALUE(statbuf, dt_compname, void *);
328             if (strncmp(chk_name_p, "DMAPI_fileattr_test.", 20)==0) {
329               sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
330               if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8) i++;
331             }
332           }
333           loops++;
334         } while (oops==1);
335         
336         if (oops==-1) {
337           fprintf(stderr, 
338                   "ERROR: dm_get_dirattrs failed with %s.\n",
339                   ERR_NAME);
340         }
341         if (i!=num_files) {
342           fprintf(stderr,
343                   "ERROR: get_dirattrs found %d matching file%s "
344                   "(expected %d).\n", i, (i==1)?"":"s", num_files);
345         }
346         else if (Vflag) {
347           fprintf(stderr, "report: get_dirattrs successfully "
348                   "found %d files in %d loops.\n", i, loops);
349         }
350
351         /*-----------------------------------------------------*\
352         |* Get_bulkattr loop                                   *|
353         \*-----------------------------------------------------*/
354         if (Vflag) fprintf(stderr, "\nRunning get_bulkattr test\n");
355         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
356           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
357                   pathname, ERR_NAME);
358           goto abort_test;
359         }
360         if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
361           fprintf(stderr, "ERROR: can't get filesystem handle for %s; %s\n",
362                   pathname, ERR_NAME);
363           goto abort_test;
364         }
365         
366         buflen = 16*sizeof(dm_stat_t); /* 100000000; */  
367         if ((bufp = (void*)malloc(buflen)) == NULL) {
368           fprintf(stderr, "Can't allocate memory for buffer.\n");
369           goto abort_test;
370         }
371         if (dm_init_attrloc(sid, fs_hanp, fs_hlen,
372                             DM_NO_TOKEN, &loc)){
373           fprintf(stderr, 
374                   "ERROR: dm_init_attrloc failed with %s.\n",
375                   ERR_NAME);
376           goto abort_test;
377         }
378         
379         i=0;
380         loops=0;
381         do {
382           oops=dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
383                                GET_MASK, &loc, buflen, bufp, &rlen); 
384           if (rlen==0) break;
385           for( statbuf = bufp; statbuf != NULL;  
386                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *) ) {
387             targhanp = DM_GET_VALUE(statbuf, dt_handle, void *);
388             targhlen = DM_GET_LEN(statbuf, dt_handle);
389             if (dm_handle_to_path(hanp, hlen, targhanp, targhlen,
390                                   (size_t)100, check_name, &rlen)){
391               fprintf(stderr, 
392                       "Warning: Couldn't get name from handle. (%s)\n",
393                           ERR_NAME);
394             }
395             else {
396               /* Put JUST name (not path) from check_name into chk_name_p */
397               chk_name_p = strrchr(check_name, '/');
398               if (chk_name_p) chk_name_p++;
399               else chk_name_p = check_name;
400               /* Verify that check_name_p holds a testfile name */
401               if (strncmp(chk_name_p, "DMAPI_fileattr_test.",20)==0) {
402                 /* Get the test file's number and compare. */
403                 sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
404                 if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8)i++;
405               }
406             }            
407           }
408           loops++;
409         } while (oops==1);
410         
411         if (oops) {
412           fprintf(stderr, 
413                   "ERROR: dm_get_bulkattr failed with %s.\n",
414                   ERR_NAME);
415         }
416         /* printf("All_file_count: %d.  BUFLEN: %d\n",
417          * all_file_count, buflen);
418          */ 
419         if (i!=num_files) {
420           fprintf(stderr,
421                   "ERROR: get_bulkattr found %d matching file%s "
422                   "(expected %d) in %d loops.\n", i, (i==1)?"":"s",
423                   num_files, loops);
424         }
425         else if (Vflag) {
426           fprintf(stderr, "report: get_bulkattr successfully "
427                   "found %d files in %d loops.\n", i, loops);
428         }
429
430           /*------------------------*\
431           |*  ## Errno subtests ##  *|
432           \*------------------------*/
433           printf("\t(errno subtests beginning...)\n");
434           sprintf(test_file, "%s/DMAPI_fileattr_test.ERRNO", 
435                   pathname);
436           sprintf(command, "cp %s %s\n", ls_path, test_file); 
437           system(command);
438
439           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
440             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
441                     test_file, ERR_NAME);
442             goto abort_test;
443           }
444  
445           /*------------------------------------*\
446           |*  ## dm_set_fileattr() subtests ##  *|
447           \*------------------------------------*/
448           /*---------------------------------------------------------*/
449           EXCLTEST("set", hanp, hlen, test_token, 
450                    dm_set_fileattr(sid, hanp, hlen, test_token,
451                                    SET_MASK, &fileattr))
452           /*---------------------------------------------------------*/
453           { void *test_vp;
454           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
455             fprintf(stderr, 
456                     "Cannot create a test handle (%s); skipping EBADF test\n",
457                     ERR_NAME);
458           }
459           else {
460             ((char *) test_vp)[hlen/2]++;
461             ERRTEST(EBADF,
462                     "set",
463                     dm_set_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
464                                     SET_MASK, &fileattr))
465               dm_handle_free(test_vp, hlen);
466           }
467           }
468           /*---------------------------------------------------------*/
469           ERRTEST(EFAULT, 
470                   "set",
471                   dm_set_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
472                                   SET_MASK, &fileattr))
473           /*---------------------------------------------------------*/
474 #if 0
475           PROBLEM: 32 ones as a mask does not produce a "bad mask" 
476           EINVAL.  If it does not, I suspect nothing will.
477
478           ERRTEST(EINVAL, 
479                   "set (bad mask) [BROKEN]",
480                   dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
481                                   0xFFFFFFFF, &fileattr))
482 #endif
483           /*---------------------------------------------------------*/
484           ERRTEST(EINVAL, 
485                   "set (bad token)",
486                   dm_set_fileattr(sid, hanp, hlen, 0, 
487                                   SET_MASK, &fileattr))
488           /*---------------------------------------------------------*/
489           ERRTEST(EINVAL, 
490                   "set (bad session)",
491                   dm_set_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
492                                   SET_MASK, &fileattr))
493           /*---------------------------------------------------------*/
494
495
496           /*------------------------------------*\
497           |*  ## dm_get_fileattr() subtests ##  *|
498           \*------------------------------------*/
499           /*---------------------------------------------------------*/
500           SHAREDTEST("get", hanp, hlen, test_token,
501                      dm_get_fileattr(sid, hanp, hlen, test_token,
502                                      GET_MASK, &dmstat))
503           /*---------------------------------------------------------*/
504           { void *test_vp;
505           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
506             fprintf(stderr, 
507                     "Cannot create a test handle (%s); skipping EBADF test\n",
508                     ERR_NAME);
509           }
510           else {
511             ((char *) test_vp)[hlen/2]++;
512             ERRTEST(EBADF,
513                     "get",
514                     dm_get_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
515                                     GET_MASK, &dmstat))
516               dm_handle_free(test_vp, hlen);
517           }
518           }
519           /*---------------------------------------------------------*/
520           ERRTEST(EFAULT, 
521                   "get",
522                   dm_get_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
523                                   GET_MASK, &dmstat))
524           ERRTEST(EFAULT, 
525                   "get",
526                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
527                                   GET_MASK, (dm_stat_t *)(-1000)))
528           /*---------------------------------------------------------*/
529 #if 0
530           PROBLEM: 32 ones as a mask does not produce a "bad mask" 
531           EINVAL.  If it does not, I suspect nothing will.
532
533           ERRTEST(EINVAL, 
534                   "get (bad mask) [BROKEN]",
535                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
536                                   0xFFFFFFFF, &dmstat))
537 #endif
538           /*---------------------------------------------------------*/
539           ERRTEST(EINVAL, 
540                   "get (bad token)",
541                   dm_get_fileattr(sid, hanp, hlen, 0, 
542                                   GET_MASK, &dmstat))
543           /*---------------------------------------------------------*/
544           ERRTEST(EINVAL, 
545                   "get (bad session)",
546                   dm_get_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
547                                   GET_MASK, &dmstat))
548           /*---------------------------------------------------------*/
549             
550
551           dm_handle_free(hanp, hlen);
552
553           /*------------------------------------*\
554           |*  ## dm_get_dirattrs() subtests ##  *|
555           \*------------------------------------*/
556           if (dm_path_to_handle(pathname, &hanp, &hlen)) {
557             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
558                     pathname, ERR_NAME);
559           }
560           else if ((bufp = (void*)malloc(buflen)) == NULL) {
561             fprintf(stderr, "Can't allocate memory for buffer.\n");
562           }
563           else {
564             /*---------------------------------------------------------*/
565             if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
566               fprintf(stderr, 
567                       "ERROR: dm_init_attrloc failed with %s.\n",
568                       ERR_NAME);
569             } else {
570               SHAREDTEST("get_dir", hanp, hlen, test_token, 
571                          dm_get_dirattrs(sid, hanp, hlen, test_token,
572                                          GET_MASK, &loc, buflen, bufp, &rlen))
573             }
574             /*---------------------------------------------------------*/
575             { void* test_vp;
576               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
577                 fprintf(stderr,  "ERROR: dm_init_attrloc failed with %s.\n",
578                         ERR_NAME);
579               } 
580               else if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
581                 fprintf(stderr, "Cannot create a test handle (%s); "
582                         "skipping EBADF test\n", ERR_NAME);
583               }
584               else {
585                 ((char *) test_vp)[hlen/2]++;
586                 ERRTEST(EBADF,
587                         "get",
588                         dm_get_dirattrs(sid, test_vp, hlen, DM_NO_TOKEN,
589                                         GET_MASK, &loc, buflen, bufp, &rlen))
590                 dm_handle_free(test_vp, hlen);
591               }
592             }
593             /*---------------------------------------------------------*/
594             { 
595               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
596                 fprintf(stderr, 
597                         "ERROR: dm_init_attrloc failed with %s.\n",
598                         ERR_NAME);
599               } 
600               else {
601                 /* PROBLEM:
602                    This would test alignment.  Right now, no error occurs
603                    when the buffer is "out of sync" with struct size.
604                    It makes it tough to read from the buffer, tho!
605                   ERRTEST(EFAULT,
606                         "get_dir (bad bufp)",
607                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
608                                         GET_MASK, &loc, buflen, p, &rlen))
609                 */
610                 ERRTEST(EFAULT,
611                         "get_dir (bad locp)",
612                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
613                                         GET_MASK, (dm_attrloc_t*)(-1000),
614                                         buflen, bufp, &rlen))
615                 ERRTEST(EFAULT,
616                         "get_dir (bad bufp)",
617                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
618                                         GET_MASK, &loc, buflen, 
619                                         (void*)(-1000), &rlen))
620                 ERRTEST(EFAULT,
621                         "get_dir (bad rlenp)",
622                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
623                                         GET_MASK, &loc, buflen, bufp,
624                                         (size_t*)(-1000)))
625               }
626             }
627             /*---------------------------------------------------------*/
628             /*---------------------------------------------------------*/
629           }
630             
631          /*------------------------------------*\
632          |*  ## dm_get_bulkattr() subtests ##  *|
633          \*------------------------------------*/
634          if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
635            fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
636                    pathname, ERR_NAME);
637          }
638          else if ((bufp = (void*)malloc(buflen)) == NULL) {
639            fprintf(stderr, "Can't allocate memory for buffer.\n");
640          }
641          else {
642            /*---------------------------------------------------------*/
643            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
644              fprintf(stderr, 
645                      "ERROR: dm_init_attrloc failed with %s.\n",
646                      ERR_NAME);
647            } 
648            else {
649              SHAREDTEST("get_bulk", fs_hanp, fs_hlen, test_token, 
650                         dm_get_bulkattr(sid, fs_hanp, fs_hlen, test_token,
651                                         GET_MASK, &loc, buflen, bufp, &rlen))
652            }
653            /*---------------------------------------------------------*/
654            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
655              fprintf(stderr, 
656                      "ERROR: dm_init_attrloc failed with %s.\n",
657                      ERR_NAME);
658            }
659            else {
660              void *p = (void *)(((char *)bufp)+1);
661              ERRTEST(EFAULT, "get_bulk (bad bufp)",
662                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
663                                      GET_MASK, &loc, buflen, 
664                                      (void *)(-1000), &rlen))
665              ERRTEST(EFAULT, "get_bulk (bad locp)",
666                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
667                                      GET_MASK, (dm_attrloc_t *)(-1000),
668                                      buflen, bufp, &rlen))
669              ERRTEST(EFAULT, "get_bulk (bad rlenp)", 
670                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
671                                      GET_MASK, &loc, buflen, bufp,
672                                      (size_t *) (-1000)))
673              ERRTEST(EFAULT, "get_bulk (bad bufp)",
674                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
675                                      GET_MASK, &loc, buflen, p, &rlen))
676            }
677            /*---------------------------------------------------------*/
678          }
679          
680           sprintf(command, "rm %s/DMAPI_fileattr_test.ERRNO\n", pathname); 
681           system(command);
682           printf("\t(errno subtests complete)\n");
683           /*---------------------*\
684           |* End of errno tests  *|
685           \*---------------------*/
686
687 abort_test:
688         /* File deletion loop */
689         if (Vflag) printf("(Deleting test files...)\n"); 
690         for (i=0; i < num_files; i++) {
691           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
692                   pathname, i);
693           sprintf(command, "rm %s\n", test_file); 
694           system(command);
695         }
696         printf("File attribute tests complete.\n");
697         exit(0);
698 }