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[];
71 u_int reg_flags[8] = {DM_REGION_NOEVENT,
75 DM_REGION_READ | DM_REGION_WRITE,
76 DM_REGION_READ | DM_REGION_TRUNCATE,
77 DM_REGION_WRITE | DM_REGION_TRUNCATE,
78 DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE};
85 fprintf(stderr, "usage:\t%s [-s sid] ls_path pathname\n", Progname);
95 dm_region_t region = { 0, 0, 0 };
96 dm_region_t checkregion = { 0, 0, 0 };
97 dm_sessid_t sid = DM_NO_SESSION;
98 char *dir_name = NULL;
103 u_int nelem_read = 0;
110 dm_token_t test_token = DM_NO_TOKEN;
112 if (Progname = strrchr(argv[0], '/')) {
118 /* Crack and validate the command line options. */
120 while ((opt = getopt(argc, argv, "vo:l:s:")) != EOF) {
126 region.rg_offset = atol(optarg);
129 region.rg_size = atol(optarg);
138 if (optind + 2 > argc)
140 ls_path = argv[optind];
141 dir_name = argv[optind+1];
143 if (dm_init_service(&name) == -1) {
144 fprintf(stderr, "Can't initialize the DMAPI\n");
147 if (sid == DM_NO_SESSION)
148 find_test_session(&sid);
150 /***********************************************\
151 |* Beginning the testing of set/get_region... *|
152 \***********************************************/
154 printf("Region test beginning...\n");
155 sprintf(object, "%s/VeryLongUnlikelyFilename.REGIONTEST", dir_name);
156 sprintf(command, "cp %s %s \n", ls_path, object);
159 /* Get the test file's handle. */
160 if (dm_path_to_handle(object, &hanp, &hlen)) {
161 fprintf(stderr, "can't get handle for file %s\n", object);
164 /* Loop over all possible region flag combinations,
165 * setting and getting. See what works!
167 for (i = 0; i < 8; i++) {
168 region.rg_flags = reg_flags[i];
169 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
170 ®ion, &exactflag)) {
171 fprintf(stderr, "dm_set_region failed, %s\n",
175 if (exactflag != DM_TRUE){
176 fprintf(stdout, "oops...exactflag was false!\n");
178 if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
179 &checkregion, &nelem_read)) {
180 fprintf(stderr, "dm_get_region failed, %s\n",
184 if (region.rg_flags != checkregion.rg_flags) {
185 fprintf(stdout, "set region flags %d, but found %d\n",
186 region.rg_flags, checkregion.rg_flags);
189 fprintf(stdout, "Test #%d okay\n", i);
193 /*************************************\
194 |* Correct-input testing complete. *|
195 |* Beginning improper-input testing. *|
196 \*************************************/
197 printf("\t(errno subtests beginning...)\n");
200 /**** SET tests ****/
201 /*---------------------------------------------------------*/
204 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
205 2, ®ion, &exactflag))
208 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
209 -1, ®ion, &exactflag))
210 /*---------------------------------------------------------*/
211 EXCLTEST("set", hanp, hlen, test_token,
212 dm_set_region(sid, hanp, hlen, test_token,
213 NELEM, ®ion, &exactflag))
214 /*---------------------------------------------------------*/
217 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
218 NELEM, (dm_region_t*)(-1000), &exactflag))
221 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
222 NELEM, ®ion, (dm_boolean_t*)(-1000)))
223 /*---------------------------------------------------------*/
225 "set (bad session id)",
226 dm_set_region(-100, hanp, hlen, DM_NO_TOKEN,
227 NELEM, ®ion, &exactflag))
228 /*---------------------------------------------------------*/
230 /**** GET tests ****/
231 /*---------------------------------------------------------*/
234 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
235 0, &checkregion, &nelem_read))
236 /*---------------------------------------------------------*/
239 dm_get_region(sid, NULL, hlen, DM_NO_TOKEN,
240 NELEM, &checkregion, &nelem_read))
241 /*---------------------------------------------------------*/
244 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
245 NELEM, (dm_region_t *)(-1000), &nelem_read))
246 /*---------------------------------------------------------*/
249 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
250 NELEM, &checkregion, (u_int *)(-1000)))
251 /*---------------------------------------------------------*/
252 SHAREDTEST("get", hanp, hlen, test_token,
253 dm_get_region(sid, hanp, hlen, test_token,
254 NELEM, &checkregion, &nelem_read))
255 /*---------------------------------------------------------*/
258 dm_get_region(-100, hanp, hlen, DM_NO_TOKEN,
259 NELEM, &checkregion, &nelem_read))
260 /*---------------------------------------------------------*/
261 printf("\t(errno subtests complete)\n");
262 /**********************************\
263 |* End of improper-input testing. *|
264 \**********************************/
266 sprintf(command, "rm %s \n", object);
268 printf("Region test complete.\n");
270 /***********************************\
271 |* End of set/get_region testing. *|
272 \***********************************/
274 dm_handle_free(hanp, hlen);