1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
10 #include <lib/errtest.h>
16 /*---------------------------------------------------------------------------
18 Automated test of the DMAPI functions dm_set_region() and dm_get_region().
22 test_region [-s sid] ls_path directory
28 is the path to a specific copy of ls, important only for its size
30 is the session ID whose events you you are interested in.
31 ----------------------------------------------------------------------------*/
36 extern char *sys_errlist[];
45 u_int reg_flags[8] = {DM_REGION_NOEVENT,
49 DM_REGION_READ | DM_REGION_WRITE,
50 DM_REGION_READ | DM_REGION_TRUNCATE,
51 DM_REGION_WRITE | DM_REGION_TRUNCATE,
52 DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE};
59 fprintf(stderr, "usage:\t%s [-s sid] ls_path pathname\n", Progname);
69 dm_region_t region = { 0, 0, 0 };
70 dm_region_t checkregion = { 0, 0, 0 };
71 dm_sessid_t sid = DM_NO_SESSION;
72 char *dir_name = NULL;
84 dm_token_t test_token = DM_NO_TOKEN;
86 Progname = strrchr(argv[0], '/');
93 /* Crack and validate the command line options. */
95 while ((opt = getopt(argc, argv, "vo:l:s:")) != EOF) {
101 region.rg_offset = atol(optarg);
104 region.rg_size = atol(optarg);
113 if (optind + 2 > argc)
115 ls_path = argv[optind];
116 dir_name = argv[optind+1];
118 if (dm_init_service(&name) == -1) {
119 fprintf(stderr, "Can't initialize the DMAPI\n");
122 if (sid == DM_NO_SESSION)
123 find_test_session(&sid);
125 /***********************************************\
126 |* Beginning the testing of set/get_region... *|
127 \***********************************************/
129 printf("Region test beginning...\n");
130 sprintf(object, "%s/VeryLongUnlikelyFilename.REGIONTEST", dir_name);
131 sprintf(command, "cp %s %s \n", ls_path, object);
134 /* Get the test file's handle. */
135 if (dm_path_to_handle(object, &hanp, &hlen)) {
136 fprintf(stderr, "can't get handle for file %s\n", object);
139 /* Loop over all possible region flag combinations,
140 * setting and getting. See what works!
142 for (i = 0; i < 8; i++) {
143 region.rg_flags = reg_flags[i];
144 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
145 ®ion, &exactflag)) {
146 fprintf(stderr, "dm_set_region failed, %s\n",
150 if (exactflag != DM_TRUE){
151 fprintf(stdout, "oops...exactflag was false!\n");
153 if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM,
154 &checkregion, &nelem_read)) {
155 fprintf(stderr, "dm_get_region failed, %s\n",
159 if (region.rg_flags != checkregion.rg_flags) {
160 fprintf(stdout, "set region flags %d, but found %d\n",
161 region.rg_flags, checkregion.rg_flags);
164 fprintf(stdout, "Test #%d okay\n", i);
168 /*************************************\
169 |* Correct-input testing complete. *|
170 |* Beginning improper-input testing. *|
171 \*************************************/
172 printf("\t(errno subtests beginning...)\n");
175 /**** SET tests ****/
176 /*---------------------------------------------------------*/
179 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
180 2, ®ion, &exactflag))
183 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
184 -1, ®ion, &exactflag))
185 /*---------------------------------------------------------*/
186 EXCLTEST("set", hanp, hlen, test_token,
187 dm_set_region(sid, hanp, hlen, test_token,
188 NELEM, ®ion, &exactflag))
189 /*---------------------------------------------------------*/
192 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
193 NELEM, (dm_region_t*)(-1000), &exactflag))
196 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
197 NELEM, ®ion, (dm_boolean_t*)(-1000)))
198 /*---------------------------------------------------------*/
200 "set (bad session id)",
201 dm_set_region(-100, hanp, hlen, DM_NO_TOKEN,
202 NELEM, ®ion, &exactflag))
203 /*---------------------------------------------------------*/
205 /**** GET tests ****/
206 /*---------------------------------------------------------*/
209 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
210 0, &checkregion, &nelem_read))
211 /*---------------------------------------------------------*/
214 dm_get_region(sid, NULL, hlen, DM_NO_TOKEN,
215 NELEM, &checkregion, &nelem_read))
216 /*---------------------------------------------------------*/
219 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
220 NELEM, (dm_region_t *)(-1000), &nelem_read))
221 /*---------------------------------------------------------*/
224 dm_get_region(sid, hanp, hlen, DM_NO_TOKEN,
225 NELEM, &checkregion, (u_int *)(-1000)))
226 /*---------------------------------------------------------*/
227 SHAREDTEST("get", hanp, hlen, test_token,
228 dm_get_region(sid, hanp, hlen, test_token,
229 NELEM, &checkregion, &nelem_read))
230 /*---------------------------------------------------------*/
233 dm_get_region(-100, hanp, hlen, DM_NO_TOKEN,
234 NELEM, &checkregion, &nelem_read))
235 /*---------------------------------------------------------*/
236 printf("\t(errno subtests complete)\n");
237 /**********************************\
238 |* End of improper-input testing. *|
239 \**********************************/
241 sprintf(command, "rm %s \n", object);
243 printf("Region test complete.\n");
245 /***********************************\
246 |* End of set/get_region testing. *|
247 \***********************************/
249 dm_handle_free(hanp, hlen);