Update dmapi test suite, add Makefiles, remove Conscript files.
[xfstests-dev.git] / dmapi / src / suite2 / src / test_fileattr.c
1 /*
2  * Copyright (c) 2000 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 #ifdef linux
48 #include <string.h>
49 #endif
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, expected.dt_mode, 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, expected.dt_uid, 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, expected.dt_gid, 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             fs_num_files;
179         int             num_files=50;
180         dm_stat_t       *stat_arr;
181         dm_stat_t       dmstat;
182         dm_fileattr_t   fileattr;
183         char            *name;
184         int             opt;
185         int             oops=1;
186         int             i=0;
187         dm_attrloc_t    loc;
188         size_t          buflen = 16*sizeof(dm_stat_t);
189         size_t          rlen;
190         void            *bufp;
191         dm_stat_t       *statbuf;
192         int             loops=0;
193         int             all_file_count=0;
194         void            *fs_hanp;
195         size_t          fs_hlen;
196         void            *targhanp;
197         size_t          targhlen;
198         char            check_name[100];
199         char            *chk_name_p;
200         int             chk_num;
201
202         if (Progname = strrchr(argv[0], '/')) {
203                 Progname++;
204         } else {
205                 Progname = argv[0];
206         }
207
208         opterr = 0;
209         while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
210                 switch (opt) {
211                 case 'v':
212                          Vflag++;
213                          break;
214                 case 'n':
215                          num_files = atoi(optarg);
216                          break;
217                 case 's': 
218                          sid = atol(optarg);
219                          break;
220                 case '?':
221                          usage();
222                 }
223         }
224         if (optind + 2 != argc) {
225                 usage();
226         }
227         ls_path = argv[optind];
228         pathname = argv[optind+1];
229
230         /* Seed the random number generator */
231         srand((unsigned int)time(NULL)); 
232
233         if (dm_init_service(&name) == -1)  {
234                 fprintf(stderr, "Can't inititalize the DMAPI\n");
235                 exit(1);
236         }
237         if (sid == DM_NO_SESSION)
238                 find_test_session(&sid);
239         
240         /* Dynamically allocate stat_arr; */
241         stat_arr = 
242           (dm_stat_t *)malloc(num_files * sizeof(dm_stat_t));
243         
244         printf("Beginning file attribute tests...\n");
245
246         /* Fill in the dm_stat blocks with lots of junk...
247          */
248         for (i=0; i<num_files; i++) {
249           stat_arr[i].dt_atime=(time_t)(rand()+rand()*0x10000);
250           stat_arr[i].dt_mtime=(time_t)(rand()+rand()*0x10000);
251           stat_arr[i].dt_ctime=(time_t)(rand()+rand()*0x10000);
252           stat_arr[i].dt_dtime=(time_t)(rand()+rand()*0x10000);
253           stat_arr[i].dt_uid=(uid_t)(rand()+rand()*0x10000);
254           stat_arr[i].dt_gid=(gid_t)(rand()+rand()*0x10000);
255           stat_arr[i].dt_mode=(mode_t)((rand()%4096)+32768);
256           stat_arr[i].dt_size=(dm_off_t)(rand()+rand()*0x10000);
257         }       
258
259         /*-----------------------------------------------------*\
260         |* File creation and set_fileattr loop                 *|
261         \*-----------------------------------------------------*/
262         if (Vflag) fprintf(stderr, "\nCreating/setting up test files.\n");
263         for (i=0; i < num_files; i++) {
264           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
265                   pathname, i);
266           sprintf(command, "cp %s %s \n", ls_path, test_file); 
267           system(command);
268
269           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
270             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
271                     test_file, ERR_NAME);
272           }
273           else {
274             fileattr.fa_mode  = stat_arr[i].dt_mode;
275             fileattr.fa_uid   = stat_arr[i].dt_uid;
276             fileattr.fa_gid   = stat_arr[i].dt_gid;
277             fileattr.FA_ATIME = stat_arr[i].dt_atime;
278             fileattr.FA_MTIME = stat_arr[i].dt_mtime;
279             fileattr.FA_CTIME = stat_arr[i].dt_ctime;
280             fileattr.FA_DTIME = stat_arr[i].dt_dtime;
281             fileattr.fa_size  = stat_arr[i].dt_size;
282             if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
283                                 SET_MASK, &fileattr)) {
284               fprintf(stderr, "ERROR: set_fileattr failed on pass #%d; %s.\n",
285                       i, ERR_NAME);
286             }
287             else if (Vflag) {
288               fprintf(stderr, "report: set #%d was successful.\n", i);
289             }
290           }
291         }
292         
293         /*-----------------------------------------------------*\
294         |* Get_fileattr loop                                   *|
295         \*-----------------------------------------------------*/
296         if (Vflag) fprintf(stderr, "\nRunning get_fileattr test\n");
297         for (i=0; i < num_files; i++) {
298           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
299                   pathname, i);
300           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
301             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
302                     test_file, ERR_NAME);
303           }
304           if (dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
305                               GET_MASK, &dmstat)) {
306             fprintf(stderr,
307                     "ERROR: dm_get_fileattr failed on pass #%d, %s\n",
308                     i, ERR_NAME);
309           }
310           else {
311             comp_stat(stat_arr[i], dmstat, i); 
312           }
313         }
314           
315         /*-----------------------------------------------------*\
316         |* Get_dirattrs loop                                   *|
317         \*-----------------------------------------------------*/
318         if (Vflag) fprintf(stderr, "\nRunning get_dirattrs test\n");
319         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
320           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
321                   pathname, ERR_NAME);
322           goto abort_test;
323         }
324         if ((bufp = (void*)malloc(buflen)) == NULL) {
325           fprintf(stderr, "Can't allocate memory for buffer.\n");
326             goto abort_test;
327         }
328         if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
329           fprintf(stderr, 
330                   "ERROR: dm_init_attrloc failed with %s.\n",
331                   ERR_NAME);
332           goto abort_test;
333         }
334         i=0; 
335         loops=0;
336         do {
337           /* printf("About to call get_dirattrs;\tloops=%d\n", loops);
338            * fflush(stdout);
339            * sleep(1);
340            */
341           oops=dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
342                                GET_MASK, &loc, buflen,
343                                bufp, &rlen);
344           if (rlen==0) break;
345           for (statbuf = bufp; statbuf != NULL; 
346                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *)) {
347             chk_name_p = DM_GET_VALUE(statbuf, dt_compname, void *);
348             if (strncmp(chk_name_p, "DMAPI_fileattr_test.", 20)==0) {
349               sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
350               if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8) i++;
351             }
352           }
353           loops++;
354         } while (oops==1);
355         
356         if (oops==-1) {
357           fprintf(stderr, 
358                   "ERROR: dm_get_dirattrs failed with %s.\n",
359                   ERR_NAME);
360         }
361         if (i!=num_files) {
362           fprintf(stderr,
363                   "ERROR: get_dirattrs found %d matching file%s "
364                   "(expected %d).\n", i, (i==1)?"":"s", num_files);
365         }
366         else if (Vflag) {
367           fprintf(stderr, "report: get_dirattrs successfully "
368                   "found %d files in %d loops.\n", i, loops);
369         }
370
371         /*-----------------------------------------------------*\
372         |* Get_bulkattr loop                                   *|
373         \*-----------------------------------------------------*/
374         if (Vflag) fprintf(stderr, "\nRunning get_bulkattr test\n");
375         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
376           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
377                   pathname, ERR_NAME);
378           goto abort_test;
379         }
380         if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
381           fprintf(stderr, "ERROR: can't get filesystem handle for %s; %s\n",
382                   pathname, ERR_NAME);
383           goto abort_test;
384         }
385         
386         buflen = 16*sizeof(dm_stat_t); /* 100000000; */  
387         if ((bufp = (void*)malloc(buflen)) == NULL) {
388           fprintf(stderr, "Can't allocate memory for buffer.\n");
389           goto abort_test;
390         }
391         if (dm_init_attrloc(sid, fs_hanp, fs_hlen,
392                             DM_NO_TOKEN, &loc)){
393           fprintf(stderr, 
394                   "ERROR: dm_init_attrloc failed with %s.\n",
395                   ERR_NAME);
396           goto abort_test;
397         }
398         
399         i=0;
400         loops=0;
401         do {
402           oops=dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
403                                GET_MASK, &loc, buflen, bufp, &rlen); 
404           if (rlen==0) break;
405           for( statbuf = bufp; statbuf != NULL;  
406                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *) ) {
407             targhanp = DM_GET_VALUE(statbuf, dt_handle, void *);
408             targhlen = DM_GET_LEN(statbuf, dt_handle);
409             if (dm_handle_to_path(hanp, hlen, targhanp, targhlen,
410                                   (size_t)100, check_name, &rlen)){
411               fprintf(stderr, 
412                       "Warning: Couldn't get name from handle. (%s)\n",
413                           ERR_NAME);
414             }
415             else {
416               /* Put JUST name (not path) from check_name into chk_name_p */
417               if (chk_name_p = strrchr(check_name, '/')) chk_name_p++;
418               else chk_name_p = check_name;
419               /* Verify that check_name_p holds a testfile name */
420               if (strncmp(chk_name_p, "DMAPI_fileattr_test.",20)==0) {
421                 /* Get the test file's number and compare. */
422                 sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
423                 if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8)i++;
424               }
425             }            
426           }
427           loops++;
428         } while (oops==1);
429         
430         if (oops) {
431           fprintf(stderr, 
432                   "ERROR: dm_get_bulkattr failed with %s.\n",
433                   ERR_NAME);
434         }
435         /* printf("All_file_count: %d.  BUFLEN: %d\n",
436          * all_file_count, buflen);
437          */ 
438         if (i!=num_files) {
439           fprintf(stderr,
440                   "ERROR: get_bulkattr found %d matching file%s "
441                   "(expected %d) in %d loops.\n", i, (i==1)?"":"s",
442                   num_files, loops);
443         }
444         else if (Vflag) {
445           fprintf(stderr, "report: get_bulkattr successfully "
446                   "found %d files in %d loops.\n", i, loops);
447         }
448
449           /*------------------------*\
450           |*  ## Errno subtests ##  *|
451           \*------------------------*/
452           printf("\t(errno subtests beginning...)\n");
453           sprintf(test_file, "%s/DMAPI_fileattr_test.ERRNO", 
454                   pathname);
455           sprintf(command, "cp %s %s\n", ls_path, test_file); 
456           system(command);
457
458           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
459             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
460                     test_file, ERR_NAME);
461             goto abort_test;
462           }
463  
464           /*------------------------------------*\
465           |*  ## dm_set_fileattr() subtests ##  *|
466           \*------------------------------------*/
467           /*---------------------------------------------------------*/
468           EXCLTEST("set", hanp, hlen, test_token, 
469                    dm_set_fileattr(sid, hanp, hlen, test_token,
470                                    SET_MASK, &fileattr))
471           /*---------------------------------------------------------*/
472           { void *test_vp;
473           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
474             fprintf(stderr, 
475                     "Cannot create a test handle (%s); skipping EBADF test\n",
476                     ERR_NAME);
477           }
478           else {
479             ((char *) test_vp)[hlen/2]++;
480             ERRTEST(EBADF,
481                     "set",
482                     dm_set_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
483                                     SET_MASK, &fileattr))
484               dm_handle_free(test_vp, hlen);
485           }
486           }
487           /*---------------------------------------------------------*/
488           ERRTEST(EFAULT, 
489                   "set",
490                   dm_set_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
491                                   SET_MASK, &fileattr))
492           /*---------------------------------------------------------*/
493 #if 0
494           PROBLEM: 32 ones as a mask does not produce a "bad mask" 
495           EINVAL.  If it does not, I suspect nothing will.
496
497           ERRTEST(EINVAL, 
498                   "set (bad mask) [BROKEN]",
499                   dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
500                                   0xFFFFFFFF, &fileattr))
501 #endif
502           /*---------------------------------------------------------*/
503           ERRTEST(EINVAL, 
504                   "set (bad token)",
505                   dm_set_fileattr(sid, hanp, hlen, 0, 
506                                   SET_MASK, &fileattr))
507           /*---------------------------------------------------------*/
508           ERRTEST(EINVAL, 
509                   "set (bad session)",
510                   dm_set_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
511                                   SET_MASK, &fileattr))
512           /*---------------------------------------------------------*/
513
514
515           /*------------------------------------*\
516           |*  ## dm_get_fileattr() subtests ##  *|
517           \*------------------------------------*/
518           /*---------------------------------------------------------*/
519           SHAREDTEST("get", hanp, hlen, test_token,
520                      dm_get_fileattr(sid, hanp, hlen, test_token,
521                                      GET_MASK, &dmstat))
522           /*---------------------------------------------------------*/
523           { void *test_vp;
524           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
525             fprintf(stderr, 
526                     "Cannot create a test handle (%s); skipping EBADF test\n",
527                     ERR_NAME);
528           }
529           else {
530             ((char *) test_vp)[hlen/2]++;
531             ERRTEST(EBADF,
532                     "get",
533                     dm_get_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
534                                     GET_MASK, &dmstat))
535               dm_handle_free(test_vp, hlen);
536           }
537           }
538           /*---------------------------------------------------------*/
539           ERRTEST(EFAULT, 
540                   "get",
541                   dm_get_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
542                                   GET_MASK, &dmstat))
543           ERRTEST(EFAULT, 
544                   "get",
545                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
546                                   GET_MASK, (dm_stat_t *)(-1000)))
547           /*---------------------------------------------------------*/
548 #if 0
549           PROBLEM: 32 ones as a mask does not produce a "bad mask" 
550           EINVAL.  If it does not, I suspect nothing will.
551
552           ERRTEST(EINVAL, 
553                   "get (bad mask) [BROKEN]",
554                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
555                                   0xFFFFFFFF, &dmstat))
556 #endif
557           /*---------------------------------------------------------*/
558           ERRTEST(EINVAL, 
559                   "get (bad token)",
560                   dm_get_fileattr(sid, hanp, hlen, 0, 
561                                   GET_MASK, &dmstat))
562           /*---------------------------------------------------------*/
563           ERRTEST(EINVAL, 
564                   "get (bad session)",
565                   dm_get_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
566                                   GET_MASK, &dmstat))
567           /*---------------------------------------------------------*/
568             
569
570           dm_handle_free(hanp, hlen);
571
572           /*------------------------------------*\
573           |*  ## dm_get_dirattrs() subtests ##  *|
574           \*------------------------------------*/
575           if (dm_path_to_handle(pathname, &hanp, &hlen)) {
576             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
577                     pathname, ERR_NAME);
578           }
579           else if ((bufp = (void*)malloc(buflen)) == NULL) {
580             fprintf(stderr, "Can't allocate memory for buffer.\n");
581           }
582           else {
583             /*---------------------------------------------------------*/
584             if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
585               fprintf(stderr, 
586                       "ERROR: dm_init_attrloc failed with %s.\n",
587                       ERR_NAME);
588             } else {
589               SHAREDTEST("get_dir", hanp, hlen, test_token, 
590                          dm_get_dirattrs(sid, hanp, hlen, test_token,
591                                          GET_MASK, &loc, buflen, bufp, &rlen))
592             }
593             /*---------------------------------------------------------*/
594             { void* test_vp;
595               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
596                 fprintf(stderr,  "ERROR: dm_init_attrloc failed with %s.\n",
597                         ERR_NAME);
598               } 
599               else if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
600                 fprintf(stderr, "Cannot create a test handle (%s); "
601                         "skipping EBADF test\n", ERR_NAME);
602               }
603               else {
604                 ((char *) test_vp)[hlen/2]++;
605                 ERRTEST(EBADF,
606                         "get",
607                         dm_get_dirattrs(sid, test_vp, hlen, DM_NO_TOKEN,
608                                         GET_MASK, &loc, buflen, bufp, &rlen))
609                 dm_handle_free(test_vp, hlen);
610               }
611             }
612             /*---------------------------------------------------------*/
613             { void *p = (void *)(((char *)bufp)+1);
614               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
615                 fprintf(stderr, 
616                         "ERROR: dm_init_attrloc failed with %s.\n",
617                         ERR_NAME);
618               } 
619               else {
620                 /* PROBLEM:
621                    This would test alignment.  Right now, no error occurs
622                    when the buffer is "out of sync" with struct size.
623                    It makes it tough to read from the buffer, tho!
624                   ERRTEST(EFAULT,
625                         "get_dir (bad bufp)",
626                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
627                                         GET_MASK, &loc, buflen, p, &rlen))
628                 */
629                 ERRTEST(EFAULT,
630                         "get_dir (bad locp)",
631                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
632                                         GET_MASK, (dm_attrloc_t*)(-1000),
633                                         buflen, bufp, &rlen))
634                 ERRTEST(EFAULT,
635                         "get_dir (bad bufp)",
636                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
637                                         GET_MASK, &loc, buflen, 
638                                         (void*)(-1000), &rlen))
639                 ERRTEST(EFAULT,
640                         "get_dir (bad rlenp)",
641                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
642                                         GET_MASK, &loc, buflen, bufp,
643                                         (size_t*)(-1000)))
644               }
645             }
646             /*---------------------------------------------------------*/
647             /*---------------------------------------------------------*/
648           }
649             
650          /*------------------------------------*\
651          |*  ## dm_get_bulkattr() subtests ##  *|
652          \*------------------------------------*/
653          if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
654            fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
655                    pathname, ERR_NAME);
656          }
657          else if ((bufp = (void*)malloc(buflen)) == NULL) {
658            fprintf(stderr, "Can't allocate memory for buffer.\n");
659          }
660          else {
661            /*---------------------------------------------------------*/
662            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
663              fprintf(stderr, 
664                      "ERROR: dm_init_attrloc failed with %s.\n",
665                      ERR_NAME);
666            } 
667            else {
668              SHAREDTEST("get_bulk", fs_hanp, fs_hlen, test_token, 
669                         dm_get_bulkattr(sid, fs_hanp, fs_hlen, test_token,
670                                         GET_MASK, &loc, buflen, bufp, &rlen))
671            }
672            /*---------------------------------------------------------*/
673            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
674              fprintf(stderr, 
675                      "ERROR: dm_init_attrloc failed with %s.\n",
676                      ERR_NAME);
677            }
678            else {
679              void *p = (void *)(((char *)bufp)+1);
680              ERRTEST(EFAULT, "get_bulk (bad bufp)",
681                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
682                                      GET_MASK, &loc, buflen, 
683                                      (void *)(-1000), &rlen))
684              ERRTEST(EFAULT, "get_bulk (bad locp)",
685                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
686                                      GET_MASK, (dm_attrloc_t *)(-1000),
687                                      buflen, bufp, &rlen))
688              ERRTEST(EFAULT, "get_bulk (bad rlenp)", 
689                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
690                                      GET_MASK, &loc, buflen, bufp,
691                                      (u_int*)(-1000)))
692              ERRTEST(EFAULT, "get_bulk (bad bufp)",
693                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
694                                      GET_MASK, &loc, buflen, p, &rlen))
695            }
696            /*---------------------------------------------------------*/
697          }
698          
699           sprintf(command, "rm %s/DMAPI_fileattr_test.ERRNO\n", pathname); 
700           system(command);
701           printf("\t(errno subtests complete)\n");
702           /*---------------------*\
703           |* End of errno tests  *|
704           \*---------------------*/
705
706 abort_test:
707         /* File deletion loop */
708         if (Vflag) printf("(Deleting test files...)\n"); 
709         for (i=0; i < num_files; i++) {
710           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
711                   pathname, i);
712           sprintf(command, "rm %s\n", test_file); 
713           system(command);
714         }
715         printf("File attribute tests complete.\n");
716 }