merge irix dmapi test changes
[xfstests-dev.git] / dmapi / src / suite2 / src / test_efault.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 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include <errno.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <strings.h>
39
40 #include <lib/dmport.h>
41 #include <lib/hsm.h>
42 #include <lib/errtest.h>
43
44 #include <getopt.h>
45 #include <string.h>
46
47
48 /*---------------------------------------------------------------------------
49 Automated search for EFAULT in the following DMAPI commands:
50    dm_get_allocinfo
51    dm_get_config
52    dm_get_config_events
53    dm_getall_dmattr
54    dm_init_attrloc
55
56 There are other EFAULT tests, in the programs that test individual 
57 DMAPI functions.  Those other tests are referenced in comments in this source.
58
59 The command line is:
60    test_efault [-s sid] [-v] ls_path pathname
61
62 where:
63    sid
64       is the session ID whose events you you are interested in.
65    ls_path
66       is the path to a copy of ls, which will be copied as a test file.
67    pathname
68       is the filesystem to use for the test.
69 ----------------------------------------------------------------------------*/
70
71 extern  int     optind;
72 extern  int     opterr;
73 extern  char    *optarg;
74
75 char    *Progname;
76 int     Vflag=0;
77
78 static void
79 usage(void)
80 {
81         fprintf(stderr, 
82                 "Usage: %s [-v] [-s sid] ls_path pathname\n",
83                 Progname);
84         exit(1);
85 }
86
87
88 int
89 main(int argc, char **argv) {
90      
91         dm_sessid_t     sid = DM_NO_SESSION;
92         void            *hanp;
93         size_t          hlen;
94         char            *name;
95         char            *ls_path;
96         char            *pathname;
97         char            test_file[100];
98         char            command[100];
99         int             opt;
100
101         if (Progname = strrchr(argv[0], '/')) {
102                 Progname++;
103         } else {
104                 Progname = argv[0];
105         }
106
107         opterr = 0;
108         while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
109                 switch (opt) {
110                 case 'v':
111                          Vflag++;
112                          break;
113                 case 's': 
114                          sid = atol(optarg);
115                          break;
116                 case '?':
117                          usage();
118                 }
119         }
120         if (optind + 2 != argc) {
121                 usage();
122         }
123         ls_path = argv[optind];
124         pathname = argv[optind+1];
125
126         if (dm_init_service(&name) == -1)  {
127                 fprintf(stderr, "Can't inititalize the DMAPI\n");
128                 exit(1);
129         }
130         if (sid == DM_NO_SESSION)
131                 find_test_session(&sid);
132         
133         printf("Beginning EFAULT testing...\n");
134
135         /*----------------------------------*\
136         |*  ## Traditional errno tests  ##  *|
137         \*----------------------------------*/
138         sprintf(test_file, "%s/DMAPI_EFAULT_test_file", pathname);
139         sprintf(command, "cp %s %s\n", ls_path, test_file); 
140         system(command);
141         
142         if (dm_path_to_handle(test_file, &hanp, &hlen)) {
143           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
144                   test_file, ERR_NAME);
145           goto abort_test;
146         }
147
148
149         /*---------------------------------------------------------
150          * get_allocinfo
151          *---------------------------------------------------------
152          */
153         { dm_off_t     off=0;
154           u_int        nelem=1;
155           dm_extent_t  extent;
156           u_int        nelem_ret;
157           
158           ERRTEST(EFAULT, "get_allocinfo (bad offp)",
159                   dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN,
160                                    (dm_off_t*)(-1000), 
161                                    nelem, &extent, &nelem_ret))
162           ERRTEST(EFAULT, "get_allocinfo (bad extentp)",
163                   dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN,
164                                    &off, nelem, (dm_extent_t*)(-1000),
165                                    &nelem_ret))
166           ERRTEST(EFAULT, "get_allocinfo (bad nelemp)",
167                   dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN,
168                                    &off, nelem, &extent,
169                                    (u_int*)(-1000)))
170         }
171    
172         /*------------------------------------------------------
173          * get_bulkattr: see test_fileattr.c
174          *------------------------------------------------------
175          * get_config
176          *------------------------------------------------------
177          */
178           ERRTEST(EFAULT, "get_config", 
179                   dm_get_config(hanp, hlen, DM_CONFIG_BULKALL,
180                                 (dm_size_t*)(-1000)))
181         /*---------------------------------------------------------
182          * get_config_events
183          *---------------------------------------------------------
184          */
185         { 
186           u_int         nelem=5;
187           u_int         *nelemp;
188           dm_eventset_t *eventsetp;
189           eventsetp = (dm_eventset_t *)malloc(nelem*sizeof(dm_eventset_t));
190           if (eventsetp == NULL) {
191             printf("Couldn't malloc for config_events tests: %s\n", ERR_NAME);
192           }
193           else {
194           ERRTEST(EFAULT, "get_config_events (bad eventsetp)",
195                 dm_get_config_events(hanp, hlen, nelem, 
196                                      (dm_eventset_t*)(-1000), nelemp))
197           ERRTEST(EFAULT, "get_config_events (bad nelemp)",
198                   dm_get_config_events(hanp, hlen, nelem, eventsetp, 
199                                        (u_int*)(-1000)))
200           }
201         }
202         /*---------------------------------------------------------
203          * get_dirattrs: see test_fileattr.c
204          *---------------------------------------------------------
205          * get_fileattr: see test_fileattr.c
206          *---------------------------------------------------------
207          * get_region: see test_region.c
208          *---------------------------------------------------------
209          * getall_dmattr
210          *---------------------------------------------------------
211          */
212         { 
213           size_t buflen = 5;
214           void   *bufp  = (void *)malloc(buflen*sizeof(dm_attrlist_t));
215           size_t *rlenp;
216           ERRTEST(EFAULT, "getall_dmattr (NULL handle)", 
217                   dm_getall_dmattr(sid, NULL, hlen, DM_NO_TOKEN,
218                                    buflen, bufp, rlenp))
219           ERRTEST(EFAULT, "getall_dmattr (incremented  bufp)", 
220                   dm_getall_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
221                                    buflen, (void*)((char*)(bufp)+1), rlenp))
222           ERRTEST(EFAULT, "getall_dmattr (bad bufp)", 
223                   dm_getall_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
224                                    buflen, (void*)(-1000), rlenp))
225           ERRTEST(EFAULT, "getall_dmattr (bad rlenp)", 
226                   dm_getall_dmattr(sid, hanp, hlen, DM_NO_TOKEN,
227                                    buflen, bufp, (size_t*)(-1000)))
228         }
229         /*---------------------------------------------------------
230          * init_attrloc
231          *---------------------------------------------------------
232          */
233         ERRTEST(ENOTSUP, "init_attrloc", 
234                 dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN,
235                                 (dm_attrloc_t*)(-1000)))
236         /*---------------------------------------------------------
237          * probe_hole: see test_hole.c
238          *---------------------------------------------------------
239          * remove_dmattr: see test_dmattr.c
240          *---------------------------------------------------------
241          * set_dmattr: see test_dmattr.c
242          *---------------------------------------------------------
243          * set_eventlist: see test_eventlist.c
244          *---------------------------------------------------------
245          * set_region: see test_region.c
246          *---------------------------------------------------------
247          */
248
249 abort_test:
250         sprintf(command, "rm %s\n", test_file); 
251         system(command);
252
253         printf("EFAULT testing complete.\n");
254
255         exit(0);
256 }
257