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