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