2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
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.
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.
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
19 #include <sys/types.h>
22 #include <lib/errtest.h>
28 /*---------------------------------------------------------------------------
30 Automated test of the DMAPI functions dm_set_region() and dm_get_region().
34 test_region [-s sid] ls_path directory
40 is the path to a specific copy of ls, important only for its size
42 is the session ID whose events you you are interested in.
43 ----------------------------------------------------------------------------*/
48 extern char *sys_errlist[];
57 u_int reg_flags[8] = {DM_REGION_NOEVENT,
61 DM_REGION_READ | DM_REGION_WRITE,
62 DM_REGION_READ | DM_REGION_TRUNCATE,
63 DM_REGION_WRITE | DM_REGION_TRUNCATE,
64 DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE};
71 fprintf(stderr, "usage:\t%s [-s sid] ls_path pathname\n", Progname);
81 dm_region_t region = { 0, 0, 0 };
82 dm_region_t checkregion = { 0, 0, 0 };
83 dm_sessid_t sid = DM_NO_SESSION;
84 char *dir_name = NULL;
96 dm_token_t test_token = DM_NO_TOKEN;
98 Progname = strrchr(argv[0], '/');
105 /* Crack and validate the command line options. */
107 while ((opt = getopt(argc, argv, "vo:l:s:")) != EOF) {
113 region.rg_offset = atol(optarg);
116 region.rg_size = atol(optarg);
125 if (optind + 2 > argc)
127 ls_path = argv[optind];
128 dir_name = argv[optind+1];
130 if (dm_init_service(&name) == -1) {
131 fprintf(stderr, "Can't initialize the DMAPI\n");
134 if (sid == DM_NO_SESSION)
135 find_test_session(&sid);
137 /***********************************************\
138 |* Beginning the testing of set/get_region... *|
139 \***********************************************/
141 printf("Region test beginning...\n");
142 sprintf(object, "%s/VeryLongUnlikelyFilename.REGIONTEST", dir_name);
143 sprintf(command, "cp %s %s \n", ls_path, object);
146 /* Get the test file's handle. */
147 if (dm_path_to_handle(object, &hanp, &hlen)) {
148 fprintf(stderr, "can't get handle for file %s\n", object);
151 /* Loop over all possible region flag combinations,
152 * setting and getting. See what works!
154 for (i = 0; i < 8; i++) {
155 region.rg_flags = reg_flags[i];
156 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
157 ®ion, &exactflag)) {
158 fprintf(stderr, "dm_set_region failed, %s\n",
162 if (exactflag != DM_TRUE){
163 fprintf(stdout, "oops...exactflag was false!\n");
165 if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
166 &checkregion, &nelem_read)) {
167 fprintf(stderr, "dm_get_region failed, %s\n",
171 if (region.rg_flags != checkregion.rg_flags) {
172 fprintf(stdout, "set region flags %d, but found %d\n",
173 region.rg_flags, checkregion.rg_flags);
176 fprintf(stdout, "Test #%d okay\n", i);
180 /*************************************\
181 |* Correct-input testing complete. *|
182 |* Beginning improper-input testing. *|
183 \*************************************/
184 printf("\t(errno subtests beginning...)\n");
187 /**** SET tests ****/
188 /*---------------------------------------------------------*/
191 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
192 2, ®ion, &exactflag))
195 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
196 -1, ®ion, &exactflag))
197 /*---------------------------------------------------------*/
198 EXCLTEST("set", hanp, hlen, test_token,
199 dm_set_region(sid, hanp, hlen, test_token,
200 NELEM, ®ion, &exactflag))
201 /*---------------------------------------------------------*/
204 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
205 NELEM, (dm_region_t*)(-1000), &exactflag))
208 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
209 NELEM, ®ion, (dm_boolean_t*)(-1000)))
210 /*---------------------------------------------------------*/
212 "set (bad session id)",
213 dm_set_region(-100, hanp, hlen, DM_NO_TOKEN,
214 NELEM, ®ion, &exactflag))
215 /*---------------------------------------------------------*/
217 /**** GET tests ****/
218 /*---------------------------------------------------------*/
221 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
222 0, &checkregion, &nelem_read))
223 /*---------------------------------------------------------*/
226 dm_get_region(sid, NULL, hlen, DM_NO_TOKEN,
227 NELEM, &checkregion, &nelem_read))
228 /*---------------------------------------------------------*/
231 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
232 NELEM, (dm_region_t *)(-1000), &nelem_read))
233 /*---------------------------------------------------------*/
236 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
237 NELEM, &checkregion, (u_int *)(-1000)))
238 /*---------------------------------------------------------*/
239 SHAREDTEST("get", hanp, hlen, test_token,
240 dm_get_region(sid, hanp, hlen, test_token,
241 NELEM, &checkregion, &nelem_read))
242 /*---------------------------------------------------------*/
245 dm_get_region(-100, hanp, hlen, DM_NO_TOKEN,
246 NELEM, &checkregion, &nelem_read))
247 /*---------------------------------------------------------*/
248 printf("\t(errno subtests complete)\n");
249 /**********************************\
250 |* End of improper-input testing. *|
251 \**********************************/
253 sprintf(command, "rm %s \n", object);
255 printf("Region test complete.\n");
257 /***********************************\
258 |* End of set/get_region testing. *|
259 \***********************************/
261 dm_handle_free(hanp, hlen);