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