2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <sys/types.h>
36 #include <lib/errtest.h>
42 /*---------------------------------------------------------------------------
44 Automated test of the DMAPI functions dm_set_region() and dm_get_region().
48 test_region [-s sid] ls_path directory
54 is the path to a specific copy of ls, important only for its size
56 is the session ID whose events you you are interested in.
57 ----------------------------------------------------------------------------*/
62 extern char *sys_errlist[];
74 { "DM_REGION_READ", DM_REGION_READ },
75 { "DM_REGION_WRITE", DM_REGION_WRITE },
76 { "DM_REGION_TRUNCATE", DM_REGION_TRUNCATE }
79 u_int reg_flags[8] = {DM_REGION_NOEVENT,
83 DM_REGION_READ | DM_REGION_WRITE,
84 DM_REGION_READ | DM_REGION_TRUNCATE,
85 DM_REGION_WRITE | DM_REGION_TRUNCATE,
86 DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE};
89 static int nevents = sizeof(rg_events)/sizeof(rg_events[0]);
97 fprintf(stderr, "usage:\t%s [-s sid] ls_path pathname\n", Progname);
107 dm_region_t region = { 0, 0, 0 };
108 dm_region_t checkregion = { 0, 0, 0 };
109 dm_sessid_t sid = DM_NO_SESSION;
110 char *dir_name = NULL;
111 char *ls_path = NULL;
115 u_int nelem_read = 0;
122 dm_token_t test_token = DM_NO_TOKEN;
124 if (Progname = strrchr(argv[0], '/')) {
130 /* Crack and validate the command line options. */
132 while ((opt = getopt(argc, argv, "vo:l:s:")) != EOF) {
138 region.rg_offset = atol(optarg);
141 region.rg_size = atol(optarg);
150 if (optind + 2 > argc)
152 ls_path = argv[optind];
153 dir_name = argv[optind+1];
155 if (dm_init_service(&name) == -1) {
156 fprintf(stderr, "Can't inititalize the DMAPI\n");
159 if (sid == DM_NO_SESSION)
160 find_test_session(&sid);
162 /***********************************************\
163 |* Beginning the testing of set/get_region... *|
164 \***********************************************/
166 printf("Region test beginning...\n");
167 sprintf(object, "%s/VeryLongUnlikelyFilename.REGIONTEST", dir_name);
168 sprintf(command, "cp %s %s \n", ls_path, object);
171 /* Get the test file's handle. */
172 if (dm_path_to_handle(object, &hanp, &hlen)) {
173 fprintf(stderr, "can't get handle for file %s\n", object);
176 /* Loop over all possible region flag combinations,
177 * setting and getting. See what works!
179 for (i = 0; i < 8; i++) {
180 region.rg_flags = reg_flags[i];
181 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
182 ®ion, &exactflag)) {
183 fprintf(stderr, "dm_set_region failed, %s\n",
187 if (exactflag != DM_TRUE){
188 fprintf(stdout, "oops...exactflag was false!\n");
190 if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
191 &checkregion, &nelem_read)) {
192 fprintf(stderr, "dm_get_region failed, %s\n",
196 if (region.rg_flags != checkregion.rg_flags) {
197 fprintf(stdout, "set region flags %d, but found %d\n",
198 region.rg_flags, checkregion.rg_flags);
201 fprintf(stdout, "Test #%d okay\n", i);
205 /*************************************\
206 |* Correct-input testing complete. *|
207 |* Beginning improper-input testing. *|
208 \*************************************/
209 printf("\t(errno subtests beginning...)\n");
212 /**** SET tests ****/
213 /*---------------------------------------------------------*/
216 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
217 2, ®ion, &exactflag))
220 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
221 -1, ®ion, &exactflag))
222 /*---------------------------------------------------------*/
223 EXCLTEST("set", hanp, hlen, test_token,
224 dm_set_region(sid, hanp, hlen, test_token,
225 NELEM, ®ion, &exactflag))
226 /*---------------------------------------------------------*/
229 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
230 NELEM, (dm_region_t*)(-1000), &exactflag))
233 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
234 NELEM, ®ion, (dm_boolean_t*)(-1000)))
235 /*---------------------------------------------------------*/
237 "set (bad session id)",
238 dm_set_region(-100, hanp, hlen, DM_NO_TOKEN,
239 NELEM, ®ion, &exactflag))
240 /*---------------------------------------------------------*/
242 /**** GET tests ****/
243 /*---------------------------------------------------------*/
246 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
247 0, &checkregion, &nelem_read))
248 /*---------------------------------------------------------*/
251 dm_get_region(sid, NULL, hlen, DM_NO_TOKEN,
252 NELEM, &checkregion, &nelem_read))
253 /*---------------------------------------------------------*/
256 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
257 NELEM, (dm_region_t *)(-1000), &nelem_read))
258 /*---------------------------------------------------------*/
261 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
262 NELEM, &checkregion, (u_int *)(-1000)))
263 /*---------------------------------------------------------*/
264 SHAREDTEST("get", hanp, hlen, test_token,
265 dm_get_region(sid, hanp, hlen, test_token,
266 NELEM, &checkregion, &nelem_read))
267 /*---------------------------------------------------------*/
270 dm_get_region(-100, hanp, hlen, DM_NO_TOKEN,
271 NELEM, &checkregion, &nelem_read))
272 /*---------------------------------------------------------*/
273 printf("\t(errno subtests complete)\n");
274 /**********************************\
275 |* End of improper-input testing. *|
276 \**********************************/
278 sprintf(command, "rm %s \n", object);
280 printf("Region test complete.\n");
282 /***********************************\
283 |* End of set/get_region testing. *|
284 \***********************************/
286 dm_handle_free(hanp, hlen);