• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) International Business Machines  Corp., 2004
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the 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 to the Free Software
16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * TEST CASE	: pmr_pre.c
21  *
22  * VARIATIONS	: 33
23  *
24  * API'S TESTED	: dm_set_region
25  *
26  * NOTES	: The last variation of this test case, when run before
27  * 		  rebooting and pmr_post, verifies that persistent managed
28  * 		  regions work
29  */
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <pthread.h>
35 #include <unistd.h>
36 #include <sys/mount.h>
37 #include <sys/stat.h>
38 #include <sys/xattr.h>
39 #include <sys/mman.h>
40 #include <fcntl.h>
41 #include "dm_test.h"
42 
43 #define ATTR_LISTLEN 1000
44 #define TMP_FILELEN 10000	/* must be > 2*PAGE_SIZE */
45 
46 pthread_t tid;
47 dm_sessid_t sid;
48 char dmMsgBuf[4096];
49 char command[4096];
50 char *mountPt;
51 char *deviceNm;
52 char DummyFile[FILENAME_MAX];
53 char DummySubdir[FILENAME_MAX];
54 char *PMR_AttrName = PMR_ATTRNAME;
55 
56 void *Thread(void *);
57 
main(int argc,char ** argv)58 int main(int argc, char **argv)
59 {
60 
61 	char *varstr;
62 	int i;
63 	int rc;
64 	char *szSessionInfo = "dm_test session info";
65 	char *szFuncName;
66 	dm_eventset_t events;
67 
68 	DMOPT_PARSE(argc, argv);
69 	DMLOG_START();
70 
71 	DMEV_ZERO(events);
72 	DMEV_SET(DM_EVENT_MOUNT, events);
73 
74 	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
75 	if ((rc = dm_init_service(&varstr)) != 0) {
76 		DMLOG_PRINT(DMLVL_ERR,
77 			    "dm_init_service failed! (rc = %d, errno = %d)\n",
78 			    rc, errno);
79 		DM_EXIT();
80 	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
81 		   == -1) {
82 		DMLOG_PRINT(DMLVL_ERR,
83 			    "dm_create_session failed! (rc = %d, errno = %d)\n",
84 			    rc, errno);
85 		DM_EXIT();
86 	} else
87 	    if ((rc =
88 		 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
89 			     &events, DM_EVENT_MAX)) == -1) {
90 		DMLOG_PRINT(DMLVL_ERR,
91 			    "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
92 			    errno);
93 		dm_destroy_session(sid);
94 		DM_EXIT();
95 	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
96 		DMLOG_PRINT(DMLVL_ERR,
97 			    "pthread_create failed! (rc = %d, errno = %d)\n",
98 			    rc, errno);
99 		dm_destroy_session(sid);
100 		DM_EXIT();
101 	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
102 		DMLOG_PRINT(DMLVL_ERR,
103 			    "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
104 			    errno);
105 		dm_destroy_session(sid);
106 		DM_EXIT();
107 	} else {
108 		int fd;
109 
110 		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
111 		sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);
112 
113 		remove(DummyFile);
114 		rmdir(DummySubdir);
115 
116 		EVENT_DELIVERY_DELAY;
117 		fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
118 		if (fd != -1) {
119 			for (i = 0; i < (TMP_FILELEN / DUMMY_STRLEN); i++) {
120 				if (write(fd, DUMMY_STRING, DUMMY_STRLEN) !=
121 				    DUMMY_STRLEN) {
122 					rc = -1;
123 					break;
124 				}
125 			}
126 		} else {
127 			rc = -1;
128 		}
129 		if (rc == 0) {
130 			rc = close(fd);
131 		}
132 		if (rc == -1) {
133 			DMLOG_PRINT(DMLVL_ERR,
134 				    "creating dummy file failed! (rc = %d, errno = %d)\n",
135 				    rc, errno);
136 			dm_destroy_session(sid);
137 			DM_EXIT();
138 		}
139 	}
140 
141 	DMLOG_PRINT(DMLVL_DEBUG,
142 		    "Starting DMAPI persistent managed regions test initialization\n");
143 
144 	szFuncName = "dm_set_region";
145 
146 	/*
147 	 * TEST    : dm_set_region - invalid sid
148 	 * EXPECTED: rc = -1, errno = EINVAL
149 	 */
150 	if (DMVAR_EXEC(SET_REGION_BASE + 1)) {
151 		int fd;
152 		void *hanp;
153 		size_t hlen;
154 		u_int nelem;
155 		dm_region_t regbuf;
156 		dm_boolean_t exactflag;
157 
158 		/* Variation set up */
159 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
160 		if ((rc = system(command)) == -1) {
161 			/* No clean up */
162 		} else
163 		    if ((fd =
164 			 open(DummyFile, O_RDWR | O_CREAT,
165 			      DUMMY_FILE_RW_MODE)) == -1) {
166 			remove(DummyFile);
167 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
168 			close(fd);
169 			remove(DummyFile);
170 		}
171 		if (rc == -1 || fd == -1) {
172 			DMLOG_PRINT(DMLVL_DEBUG,
173 				    "Unable to set up variation! (errno = %d)\n",
174 				    errno);
175 			DMVAR_SKIP();
176 		} else {
177 			/* Variation */
178 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
179 				    szFuncName);
180 			rc = dm_set_region(INVALID_ADDR, hanp, hlen,
181 					   DM_NO_TOKEN, nelem, &regbuf,
182 					   &exactflag);
183 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
184 
185 			/* Variation clean up */
186 			rc = close(fd);
187 			rc |= remove(DummyFile);
188 			if (rc == -1) {
189 				DMLOG_PRINT(DMLVL_DEBUG,
190 					    "Unable to clean up variation! (errno = %d)\n",
191 					    errno);
192 			}
193 			dm_handle_free(hanp, hlen);
194 		}
195 	}
196 
197 	/*
198 	 * TEST    : dm_set_region - invalid hanp
199 	 * EXPECTED: rc = -1, errno = EFAULT
200 	 */
201 	if (DMVAR_EXEC(SET_REGION_BASE + 2)) {
202 		int fd;
203 		void *hanp;
204 		size_t hlen;
205 		u_int nelem;
206 		dm_region_t regbuf;
207 		dm_boolean_t exactflag;
208 
209 		/* Variation set up */
210 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
211 		if ((rc = system(command)) == -1) {
212 			/* No clean up */
213 		} else
214 		    if ((fd =
215 			 open(DummyFile, O_RDWR | O_CREAT,
216 			      DUMMY_FILE_RW_MODE)) == -1) {
217 			remove(DummyFile);
218 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
219 			close(fd);
220 			remove(DummyFile);
221 		}
222 		if (rc == -1 || fd == -1) {
223 			DMLOG_PRINT(DMLVL_DEBUG,
224 				    "Unable to set up variation! (errno = %d)\n",
225 				    errno);
226 			DMVAR_SKIP();
227 		} else {
228 			/* Variation */
229 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp\n",
230 				    szFuncName);
231 			rc = dm_set_region(sid, (void *)INVALID_ADDR, hlen,
232 					   DM_NO_TOKEN, nelem, &regbuf,
233 					   &exactflag);
234 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
235 
236 			/* Variation clean up */
237 			rc = close(fd);
238 			rc |= remove(DummyFile);
239 			if (rc == -1) {
240 				DMLOG_PRINT(DMLVL_DEBUG,
241 					    "Unable to clean up variation! (errno = %d)\n",
242 					    errno);
243 			}
244 			dm_handle_free(hanp, hlen);
245 		}
246 	}
247 
248 	/*
249 	 * TEST    : dm_set_region - invalid hlen
250 	 * EXPECTED: rc = -1, errno = EBADF
251 	 */
252 	if (DMVAR_EXEC(SET_REGION_BASE + 3)) {
253 		int fd;
254 		void *hanp;
255 		size_t hlen;
256 		u_int nelem;
257 		dm_region_t regbuf;
258 		dm_boolean_t exactflag;
259 
260 		/* Variation set up */
261 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
262 		if ((rc = system(command)) == -1) {
263 			/* No clean up */
264 		} else
265 		    if ((fd =
266 			 open(DummyFile, O_RDWR | O_CREAT,
267 			      DUMMY_FILE_RW_MODE)) == -1) {
268 			remove(DummyFile);
269 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
270 			close(fd);
271 			remove(DummyFile);
272 		}
273 		if (rc == -1 || fd == -1) {
274 			DMLOG_PRINT(DMLVL_DEBUG,
275 				    "Unable to set up variation! (errno = %d)\n",
276 				    errno);
277 			DMVAR_SKIP();
278 		} else {
279 			/* Variation */
280 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen\n",
281 				    szFuncName);
282 			rc = dm_set_region(sid, hanp, INVALID_ADDR, DM_NO_TOKEN,
283 					   nelem, &regbuf, &exactflag);
284 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
285 
286 			/* Variation clean up */
287 			rc = close(fd);
288 			rc |= remove(DummyFile);
289 			if (rc == -1) {
290 				DMLOG_PRINT(DMLVL_DEBUG,
291 					    "Unable to clean up variation! (errno = %d)\n",
292 					    errno);
293 			}
294 			dm_handle_free(hanp, hlen);
295 		}
296 	}
297 
298 	/*
299 	 * TEST    : dm_set_region - invalid token
300 	 * EXPECTED: rc = -1, errno = EINVAL
301 	 */
302 	if (DMVAR_EXEC(SET_REGION_BASE + 4)) {
303 		int fd;
304 		void *hanp;
305 		size_t hlen;
306 		u_int nelem;
307 		dm_region_t regbuf;
308 		dm_boolean_t exactflag;
309 
310 		/* Variation set up */
311 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
312 		if ((rc = system(command)) == -1) {
313 			/* No clean up */
314 		} else
315 		    if ((fd =
316 			 open(DummyFile, O_RDWR | O_CREAT,
317 			      DUMMY_FILE_RW_MODE)) == -1) {
318 			remove(DummyFile);
319 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
320 			close(fd);
321 			remove(DummyFile);
322 		}
323 		if (rc == -1 || fd == -1) {
324 			DMLOG_PRINT(DMLVL_DEBUG,
325 				    "Unable to set up variation! (errno = %d)\n",
326 				    errno);
327 			DMVAR_SKIP();
328 		} else {
329 			/* Variation */
330 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
331 				    szFuncName);
332 			rc = dm_set_region(sid, hanp, hlen, INVALID_ADDR, nelem,
333 					   &regbuf, &exactflag);
334 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
335 
336 			/* Variation clean up */
337 			rc = close(fd);
338 			rc |= remove(DummyFile);
339 			if (rc == -1) {
340 				DMLOG_PRINT(DMLVL_DEBUG,
341 					    "Unable to clean up variation! (errno = %d)\n",
342 					    errno);
343 			}
344 			dm_handle_free(hanp, hlen);
345 		}
346 	}
347 
348 	/*
349 	 * TEST    : dm_set_region - invalid nelem
350 	 * EXPECTED: rc = -1, errno = E2BIG
351 	 */
352 	if (DMVAR_EXEC(SET_REGION_BASE + 5)) {
353 		int fd;
354 		void *hanp;
355 		size_t hlen;
356 		dm_region_t regbuf;
357 		dm_boolean_t exactflag;
358 		dm_size_t retval;
359 
360 		/* Variation set up */
361 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
362 		if ((rc = system(command)) == -1) {
363 			/* No clean up */
364 		} else
365 		    if ((fd =
366 			 open(DummyFile, O_RDWR | O_CREAT,
367 			      DUMMY_FILE_RW_MODE)) == -1) {
368 			remove(DummyFile);
369 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
370 			close(fd);
371 			remove(DummyFile);
372 		} else
373 		    if ((rc =
374 			 dm_get_config(hanp, hlen,
375 				       DM_CONFIG_MAX_MANAGED_REGIONS,
376 				       &retval)) == -1) {
377 			close(fd);
378 			remove(DummyFile);
379 			dm_handle_free(hanp, hlen);
380 		}
381 		if (rc == -1 || fd == -1) {
382 			DMLOG_PRINT(DMLVL_DEBUG,
383 				    "Unable to set up variation! (errno = %d)\n",
384 				    errno);
385 			DMVAR_SKIP();
386 		} else {
387 			/* Variation */
388 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid nelem)\n",
389 				    szFuncName);
390 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
391 					   retval + 1, &regbuf, &exactflag);
392 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);
393 
394 			/* Variation clean up */
395 			rc = close(fd);
396 			rc |= remove(DummyFile);
397 			if (rc == -1) {
398 				DMLOG_PRINT(DMLVL_DEBUG,
399 					    "Unable to clean up variation! (errno = %d)\n",
400 					    errno);
401 			}
402 			dm_handle_free(hanp, hlen);
403 		}
404 	}
405 
406 	/*
407 	 * TEST    : dm_set_region - invalid regbufp
408 	 * EXPECTED: rc = -1, errno = EFAULT
409 	 */
410 	if (DMVAR_EXEC(SET_REGION_BASE + 6)) {
411 		int fd;
412 		void *hanp;
413 		size_t hlen;
414 		u_int nelem;
415 		dm_boolean_t exactflag;
416 
417 		/* Variation set up */
418 		nelem = 1;
419 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
420 		if ((rc = system(command)) == -1) {
421 			/* No clean up */
422 		} else
423 		    if ((fd =
424 			 open(DummyFile, O_RDWR | O_CREAT,
425 			      DUMMY_FILE_RW_MODE)) == -1) {
426 			remove(DummyFile);
427 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
428 			close(fd);
429 			remove(DummyFile);
430 		}
431 		if (rc == -1 || fd == -1) {
432 			DMLOG_PRINT(DMLVL_DEBUG,
433 				    "Unable to set up variation! (errno = %d)\n",
434 				    errno);
435 			DMVAR_SKIP();
436 		} else {
437 			/* Variation */
438 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid regbufp)\n",
439 				    szFuncName);
440 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
441 					   (dm_region_t *) INVALID_ADDR,
442 					   &exactflag);
443 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
444 
445 			/* Variation clean up */
446 			rc = close(fd);
447 			rc |= remove(DummyFile);
448 			if (rc == -1) {
449 				DMLOG_PRINT(DMLVL_DEBUG,
450 					    "Unable to clean up variation! (errno = %d)\n",
451 					    errno);
452 			}
453 			dm_handle_free(hanp, hlen);
454 		}
455 	}
456 
457 	/*
458 	 * TEST    : dm_set_region - invalid exactflagp
459 	 * EXPECTED: rc = -1, errno = EFAULT
460 	 */
461 	if (DMVAR_EXEC(SET_REGION_BASE + 7)) {
462 		int fd;
463 		void *hanp;
464 		size_t hlen;
465 		u_int nelem;
466 		dm_region_t regbuf;
467 
468 		/* Variation set up */
469 		nelem = 1;
470 		memset(&regbuf, 0, sizeof(regbuf));
471 
472 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
473 		if ((rc = system(command)) == -1) {
474 			/* No clean up */
475 		} else
476 		    if ((fd =
477 			 open(DummyFile, O_RDWR | O_CREAT,
478 			      DUMMY_FILE_RW_MODE)) == -1) {
479 			remove(DummyFile);
480 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
481 			close(fd);
482 			remove(DummyFile);
483 		}
484 		if (rc == -1 || fd == -1) {
485 			DMLOG_PRINT(DMLVL_DEBUG,
486 				    "Unable to set up variation! (errno = %d)\n",
487 				    errno);
488 			DMVAR_SKIP();
489 		} else {
490 			/* Variation */
491 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid exactflagp)\n",
492 				    szFuncName);
493 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
494 					   &regbuf,
495 					   (dm_boolean_t *) INVALID_ADDR);
496 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
497 
498 			/* Variation clean up */
499 			rc = close(fd);
500 			rc |= remove(DummyFile);
501 			if (rc == -1) {
502 				DMLOG_PRINT(DMLVL_DEBUG,
503 					    "Unable to clean up variation! (errno = %d)\n",
504 					    errno);
505 			}
506 			dm_handle_free(hanp, hlen);
507 		}
508 	}
509 
510 	/*
511 	 * TEST    : dm_set_region - DM_NO_SESSION sid
512 	 * EXPECTED: rc = -1, errno = EINVAL
513 	 */
514 	if (DMVAR_EXEC(SET_REGION_BASE + 8)) {
515 		void *hanp;
516 		size_t hlen;
517 		u_int nelem;
518 		dm_region_t regbuf;
519 		dm_boolean_t exactflag;
520 
521 		/* Variation set up */
522 		nelem = 1;
523 		memset(&regbuf, 0, sizeof(regbuf));
524 
525 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
526 			/* No clean up */
527 		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
528 			   == -1) {
529 			rmdir(DummySubdir);
530 		}
531 		if (rc == -1) {
532 			DMLOG_PRINT(DMLVL_DEBUG,
533 				    "Unable to set up variation! (errno = %d)\n",
534 				    errno);
535 			DMVAR_SKIP();
536 		} else {
537 			/* Variation */
538 			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
539 				    szFuncName);
540 			rc = dm_set_region(DM_NO_SESSION, hanp, hlen,
541 					   DM_NO_TOKEN, nelem, &regbuf,
542 					   &exactflag);
543 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
544 
545 			/* Variation clean up */
546 			rc = rmdir(DummySubdir);
547 			if (rc == -1) {
548 				DMLOG_PRINT(DMLVL_DEBUG,
549 					    "Unable to clean up variation! (errno = %d)\n",
550 					    errno);
551 			}
552 			dm_handle_free(hanp, hlen);
553 		}
554 	}
555 
556 	/*
557 	 * TEST    : dm_set_region - global handle
558 	 * EXPECTED: rc = -1, errno = EBADF
559 	 */
560 	if (DMVAR_EXEC(SET_REGION_BASE + 9)) {
561 		void *hanp;
562 		size_t hlen;
563 		u_int nelem;
564 		dm_region_t regbuf;
565 		dm_boolean_t exactflag;
566 
567 		/* Variation set up */
568 		nelem = 1;
569 		memset(&regbuf, 0, sizeof(regbuf));
570 
571 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
572 			/* No clean up */
573 		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
574 			   == -1) {
575 			rmdir(DummySubdir);
576 		}
577 		if (rc == -1) {
578 			DMLOG_PRINT(DMLVL_DEBUG,
579 				    "Unable to set up variation! (errno = %d)\n",
580 				    errno);
581 			DMVAR_SKIP();
582 		} else {
583 			/* Variation */
584 			DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n",
585 				    szFuncName);
586 			rc = dm_set_region(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN,
587 					   DM_NO_TOKEN, nelem, &regbuf,
588 					   &exactflag);
589 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
590 
591 			/* Variation clean up */
592 			rc = rmdir(DummySubdir);
593 			if (rc == -1) {
594 				DMLOG_PRINT(DMLVL_DEBUG,
595 					    "Unable to clean up variation! (errno = %d)\n",
596 					    errno);
597 			}
598 			dm_handle_free(hanp, hlen);
599 		}
600 	}
601 
602 	/*
603 	 * TEST    : dm_set_region - directory handle
604 	 * EXPECTED: rc = -1, errno = EINVAL
605 	 */
606 	if (DMVAR_EXEC(SET_REGION_BASE + 10)) {
607 		void *hanp;
608 		size_t hlen;
609 		u_int nelem;
610 		dm_region_t regbuf;
611 		dm_boolean_t exactflag;
612 
613 		/* Variation set up */
614 		nelem = 1;
615 		memset(&regbuf, 0, sizeof(regbuf));
616 
617 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
618 			/* No clean up */
619 		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
620 			   == -1) {
621 			rmdir(DummySubdir);
622 		}
623 		if (rc == -1) {
624 			DMLOG_PRINT(DMLVL_DEBUG,
625 				    "Unable to set up variation! (errno = %d)\n",
626 				    errno);
627 			DMVAR_SKIP();
628 		} else {
629 			/* Variation */
630 			DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n",
631 				    szFuncName);
632 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
633 					   &regbuf, &exactflag);
634 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
635 
636 			/* Variation clean up */
637 			rc = rmdir(DummySubdir);
638 			if (rc == -1) {
639 				DMLOG_PRINT(DMLVL_DEBUG,
640 					    "Unable to clean up variation! (errno = %d)\n",
641 					    errno);
642 			}
643 			dm_handle_free(hanp, hlen);
644 		}
645 	}
646 
647 	/*
648 	 * TEST    : dm_set_region - fs handle
649 	 * EXPECTED: rc = -1, errno = EINVAL
650 	 */
651 	if (DMVAR_EXEC(SET_REGION_BASE + 11)) {
652 		int fd;
653 		void *hanp;
654 		size_t hlen;
655 		u_int nelem;
656 		dm_region_t regbuf;
657 		dm_boolean_t exactflag;
658 
659 		/* Variation set up */
660 		nelem = 1;
661 		memset(&regbuf, 0, sizeof(regbuf));
662 
663 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
664 		if ((rc = system(command)) == -1) {
665 			/* No clean up */
666 		} else
667 		    if ((fd =
668 			 open(DummyFile, O_RDWR | O_CREAT,
669 			      DUMMY_FILE_RW_MODE)) == -1) {
670 			remove(DummyFile);
671 		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
672 			   == -1) {
673 			close(fd);
674 			remove(DummyFile);
675 		}
676 		if (rc == -1 || fd == -1) {
677 			DMLOG_PRINT(DMLVL_DEBUG,
678 				    "Unable to set up variation! (errno = %d)\n",
679 				    errno);
680 			DMVAR_SKIP();
681 		} else {
682 			/* Variation */
683 			DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName);
684 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
685 					   &regbuf, &exactflag);
686 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
687 
688 			/* Variation clean up */
689 			rc = close(fd);
690 			rc |= remove(DummyFile);
691 			if (rc == -1) {
692 				DMLOG_PRINT(DMLVL_DEBUG,
693 					    "Unable to clean up variation! (errno = %d)\n",
694 					    errno);
695 			}
696 			dm_handle_free(hanp, hlen);
697 		}
698 	}
699 
700 	/*
701 	 * TEST    : dm_set_region - nelem 0
702 	 * EXPECTED: rc = 0
703 	 */
704 	if (DMVAR_EXEC(SET_REGION_BASE + 12)) {
705 		int fd;
706 		void *hanp;
707 		size_t hlen;
708 		u_int nelem;
709 		dm_boolean_t exactflag;
710 		char value[ATTR_LISTLEN];
711 
712 		/* Variation set up */
713 		nelem = 0;
714 
715 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
716 		if ((rc = system(command)) == -1) {
717 			/* No clean up */
718 		} else
719 		    if ((fd =
720 			 open(DummyFile, O_RDWR | O_CREAT,
721 			      DUMMY_FILE_RW_MODE)) == -1) {
722 			remove(DummyFile);
723 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
724 			close(fd);
725 			remove(DummyFile);
726 		}
727 		if (rc == -1 || fd == -1) {
728 			DMLOG_PRINT(DMLVL_DEBUG,
729 				    "Unable to set up variation! (errno = %d)\n",
730 				    errno);
731 			DMVAR_SKIP();
732 		} else {
733 			/* Variation */
734 			DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 0)\n", szFuncName);
735 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
736 					   NULL, &exactflag);
737 			if (rc == 0) {
738 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
739 					    exactflag);
740 				if (((rc =
741 				      getxattr(DummyFile, PMR_AttrName, value,
742 					       sizeof(value))) == -1)
743 				    && (errno == ENODATA)) {
744 					DMLOG_PRINT(DMLVL_DEBUG,
745 						    "%s passed with expected rc = 0\n",
746 						    szFuncName);
747 					DMVAR_PASS();
748 				} else {
749 					DMLOG_PRINT(DMLVL_ERR,
750 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
751 						    szFuncName, 0, PMR_AttrName,
752 						    rc, -1, errno);
753 					DMVAR_FAIL();
754 				}
755 			} else {
756 				DMLOG_PRINT(DMLVL_ERR,
757 					    "%s failed with unexpected rc = %d (errno = %d)\n",
758 					    szFuncName, rc, errno);
759 				DMVAR_FAIL();
760 			}
761 
762 			/* Variation clean up */
763 			rc = close(fd);
764 			rc |= remove(DummyFile);
765 			if (rc == -1) {
766 				DMLOG_PRINT(DMLVL_DEBUG,
767 					    "Unable to clean up variation! (errno = %d)\n",
768 					    errno);
769 			}
770 			dm_handle_free(hanp, hlen);
771 		}
772 	}
773 
774 	/*
775 	 * TEST    : dm_set_region - nelem 1
776 	 * EXPECTED: rc = 0
777 	 */
778 	if (DMVAR_EXEC(SET_REGION_BASE + 13)) {
779 		int fd;
780 		void *hanp;
781 		size_t hlen;
782 		u_int nelem;
783 		dm_region_t regbuf;
784 		dm_boolean_t exactflag;
785 		char value[ATTR_LISTLEN];
786 
787 		/* Variation set up */
788 		nelem = 1;
789 		memset(&regbuf, 0, sizeof(regbuf));
790 
791 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
792 		if ((rc = system(command)) == -1) {
793 			/* No clean up */
794 		} else
795 		    if ((fd =
796 			 open(DummyFile, O_RDWR | O_CREAT,
797 			      DUMMY_FILE_RW_MODE)) == -1) {
798 			remove(DummyFile);
799 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
800 			close(fd);
801 			remove(DummyFile);
802 		}
803 		if (rc == -1 || fd == -1) {
804 			DMLOG_PRINT(DMLVL_DEBUG,
805 				    "Unable to set up variation! (errno = %d)\n",
806 				    errno);
807 			DMVAR_SKIP();
808 		} else {
809 			/* Variation */
810 			DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 1)\n", szFuncName);
811 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
812 					   &regbuf, &exactflag);
813 			if (rc == 0) {
814 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
815 					    exactflag);
816 				if ((rc =
817 				     getxattr(DummyFile, PMR_AttrName, value,
818 					      sizeof(value))) >=
819 				    sizeof(dm_region_t)) {
820 					DMLOG_PRINT(DMLVL_DEBUG,
821 						    "%s passed with expected rc = 0\n",
822 						    szFuncName);
823 					DMVAR_PASS();
824 				} else {
825 					DMLOG_PRINT(DMLVL_ERR,
826 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
827 						    szFuncName, 0, PMR_AttrName,
828 						    rc, sizeof(dm_region_t),
829 						    errno);
830 					DMVAR_FAIL();
831 				}
832 			} else {
833 				DMLOG_PRINT(DMLVL_ERR,
834 					    "%s failed with unexpected rc = %d (errno = %d)\n",
835 					    szFuncName, rc, errno);
836 				DMVAR_FAIL();
837 			}
838 
839 			/* Variation clean up */
840 			rc = close(fd);
841 			rc |= remove(DummyFile);
842 			if (rc == -1) {
843 				DMLOG_PRINT(DMLVL_DEBUG,
844 					    "Unable to clean up variation! (errno = %d)\n",
845 					    errno);
846 			}
847 			dm_handle_free(hanp, hlen);
848 		}
849 	}
850 
851 	/*
852 	 * TEST    : dm_set_region - nelem 2
853 	 * EXPECTED: rc = 0
854 	 */
855 	if (DMVAR_EXEC(SET_REGION_BASE + 14)) {
856 #ifdef MULTIPLE_REGIONS
857 		int fd;
858 		void *hanp;
859 		size_t hlen;
860 		u_int nelem;
861 		dm_region_t regbuf[2];
862 		dm_boolean_t exactflag;
863 		char value[ATTR_LISTLEN];
864 
865 		/* Variation set up */
866 		nelem = 2;
867 		regbuf[0].rg_offset = 0;
868 		regbuf[0].rg_size = 1000;
869 		regbuf[0].rg_flags = DM_REGION_READ;
870 		regbuf[1].rg_offset = 2000;
871 		regbuf[1].rg_size = 1000;
872 		regbuf[1].rg_flags = DM_REGION_WRITE;
873 
874 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
875 		if ((rc = system(command)) == -1) {
876 			/* No clean up */
877 		} else
878 		    if ((fd =
879 			 open(DummyFile, O_RDWR | O_CREAT,
880 			      DUMMY_FILE_RW_MODE)) == -1) {
881 			remove(DummyFile);
882 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
883 			close(fd);
884 			remove(DummyFile);
885 		}
886 		if (rc == -1 || fd == -1) {
887 			DMLOG_PRINT(DMLVL_DEBUG,
888 				    "Unable to set up variation! (errno = %d)\n",
889 				    errno);
890 			DMVAR_SKIP();
891 		} else {
892 			/* Variation */
893 			DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 2)\n", szFuncName);
894 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
895 					   regbuf, &exactflag);
896 			if (rc == 0) {
897 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
898 					    exactflag);
899 				if ((rc =
900 				     getxattr(DummyFile, PMR_AttrName, value,
901 					      sizeof(value))) >=
902 				    (2 * sizeof(dm_region_t))) {
903 					DMLOG_PRINT(DMLVL_DEBUG,
904 						    "%s passed with expected rc = 0\n",
905 						    szFuncName);
906 					DMVAR_PASS();
907 				} else {
908 					DMLOG_PRINT(DMLVL_ERR,
909 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
910 						    szFuncName, 0, PMR_AttrName,
911 						    rc, 2 * sizeof(dm_region_t),
912 						    errno);
913 					DMVAR_FAIL();
914 				}
915 			} else {
916 				DMLOG_PRINT(DMLVL_ERR,
917 					    "%s failed with unexpected rc = %d (errno = %d)\n",
918 					    szFuncName, rc, errno);
919 				DMVAR_FAIL();
920 			}
921 
922 			/* Variation clean up */
923 			rc = close(fd);
924 			rc |= remove(DummyFile);
925 			if (rc == -1) {
926 				DMLOG_PRINT(DMLVL_DEBUG,
927 					    "Unable to clean up variation! (errno = %d)\n",
928 					    errno);
929 			}
930 			dm_handle_free(hanp, hlen);
931 		}
932 #else
933 		DMLOG_PRINT(DMLVL_WARN,
934 			    "Test case not built with MULTIPLE_REGIONS defined\n");
935 		DMVAR_SKIP();
936 #endif
937 	}
938 
939 	/*
940 	 * TEST    : dm_set_region - clear
941 	 * EXPECTED: rc = 0
942 	 */
943 	if (DMVAR_EXEC(SET_REGION_BASE + 15)) {
944 		int fd;
945 		void *hanp;
946 		size_t hlen;
947 		u_int nelem;
948 		dm_region_t regbuf[2];
949 		dm_boolean_t exactflag;
950 		char value[ATTR_LISTLEN];
951 
952 		/* Variation set up */
953 #ifdef MULTIPLE_REGIONS
954 		nelem = 2;
955 		regbuf[0].rg_offset = 0;
956 		regbuf[0].rg_size = 1000;
957 		regbuf[0].rg_flags = DM_REGION_READ;
958 		regbuf[1].rg_offset = 2000;
959 		regbuf[1].rg_size = 1000;
960 		regbuf[1].rg_flags = DM_REGION_WRITE;
961 #else
962 		nelem = 1;
963 		regbuf[0].rg_offset = 0;
964 		regbuf[0].rg_size = 1000;
965 		regbuf[0].rg_flags = DM_REGION_READ;
966 #endif
967 
968 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
969 		if ((rc = system(command)) == -1) {
970 			/* No clean up */
971 		} else
972 		    if ((fd =
973 			 open(DummyFile, O_RDWR | O_CREAT,
974 			      DUMMY_FILE_RW_MODE)) == -1) {
975 			remove(DummyFile);
976 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
977 			close(fd);
978 			remove(DummyFile);
979 		} else
980 		    if (((rc =
981 			  dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
982 					regbuf, &exactflag)) == -1)
983 			||
984 			((rc =
985 			  getxattr(DummyFile, PMR_AttrName, value,
986 				   sizeof(value))) <
987 			 (nelem * sizeof(dm_region_t)))) {
988 			close(fd);
989 			remove(DummyFile);
990 			dm_handle_free(hanp, hlen);
991 			rc = -1;	/* rc could be >= 0 from getxattr */
992 		}
993 		if (rc == -1 || fd == -1) {
994 			DMLOG_PRINT(DMLVL_DEBUG,
995 				    "Unable to set up variation! (errno = %d)\n",
996 				    errno);
997 			DMVAR_SKIP();
998 		} else {
999 			/* Variation */
1000 			DMLOG_PRINT(DMLVL_DEBUG, "%s(clear)\n", szFuncName);
1001 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, 0,
1002 					   NULL, &exactflag);
1003 			if (rc == 0) {
1004 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
1005 					    exactflag);
1006 				if (((rc =
1007 				      getxattr(DummyFile, PMR_AttrName, value,
1008 					       sizeof(value))) == -1)
1009 				    && (errno == ENODATA)) {
1010 					DMLOG_PRINT(DMLVL_DEBUG,
1011 						    "%s passed with expected rc = 0\n",
1012 						    szFuncName);
1013 					DMVAR_PASS();
1014 				} else {
1015 					DMLOG_PRINT(DMLVL_ERR,
1016 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
1017 						    szFuncName, 0, PMR_AttrName,
1018 						    rc, -1, errno);
1019 					DMVAR_FAIL();
1020 				}
1021 			} else {
1022 				DMLOG_PRINT(DMLVL_ERR,
1023 					    "%s failed with unexpected rc = %d (errno = %d)\n",
1024 					    szFuncName, rc, errno);
1025 				DMVAR_FAIL();
1026 			}
1027 
1028 			/* Variation clean up */
1029 			rc = close(fd);
1030 			rc |= remove(DummyFile);
1031 			if (rc == -1) {
1032 				DMLOG_PRINT(DMLVL_DEBUG,
1033 					    "Unable to clean up variation! (errno = %d)\n",
1034 					    errno);
1035 			}
1036 			dm_handle_free(hanp, hlen);
1037 		}
1038 	}
1039 
1040 	/*
1041 	 * TEST    : dm_set_region - replace
1042 	 * EXPECTED: rc = 0
1043 	 */
1044 	if (DMVAR_EXEC(SET_REGION_BASE + 16)) {
1045 		int fd;
1046 		void *hanp;
1047 		size_t hlen;
1048 		u_int nelem;
1049 		dm_region_t regbuf[2];
1050 		dm_boolean_t exactflag;
1051 		char value[ATTR_LISTLEN];
1052 		ssize_t xattrlen;
1053 
1054 		/* Variation set up */
1055 #ifdef MULTIPLE_REGIONS
1056 		nelem = 2;
1057 		regbuf[0].rg_offset = 0;
1058 		regbuf[0].rg_size = 1000;
1059 		regbuf[0].rg_flags = DM_REGION_WRITE;
1060 		regbuf[1].rg_offset = 2000;
1061 		regbuf[1].rg_size = 1000;
1062 		regbuf[1].rg_flags = DM_REGION_READ;
1063 #else
1064 		nelem = 1;
1065 		regbuf[0].rg_offset = 0;
1066 		regbuf[0].rg_size = 1000;
1067 		regbuf[0].rg_flags = DM_REGION_WRITE;
1068 #endif
1069 
1070 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1071 		if ((rc = system(command)) == -1) {
1072 			/* No clean up */
1073 		} else
1074 		    if ((fd =
1075 			 open(DummyFile, O_RDWR | O_CREAT,
1076 			      DUMMY_FILE_RW_MODE)) == -1) {
1077 			remove(DummyFile);
1078 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1079 			close(fd);
1080 			remove(DummyFile);
1081 		} else
1082 		    if (((rc =
1083 			  dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1084 					regbuf, &exactflag)) == -1)
1085 			||
1086 			((rc =
1087 			  getxattr(DummyFile, PMR_AttrName, value,
1088 				   sizeof(value))) <
1089 			 (nelem * sizeof(dm_region_t)))) {
1090 			close(fd);
1091 			remove(DummyFile);
1092 			dm_handle_free(hanp, hlen);
1093 			rc = -1;	/* rc could be >= 0 from getxattr */
1094 		}
1095 		if (rc == -1 || fd == -1) {
1096 			DMLOG_PRINT(DMLVL_DEBUG,
1097 				    "Unable to set up variation! (errno = %d)\n",
1098 				    errno);
1099 			DMVAR_SKIP();
1100 		} else {
1101 			/* Variation */
1102 			xattrlen = rc;
1103 
1104 			nelem = 1;
1105 			regbuf[0].rg_offset = 0;
1106 			regbuf[0].rg_size = 1000;
1107 			regbuf[0].rg_flags = DM_REGION_READ;
1108 
1109 			DMLOG_PRINT(DMLVL_DEBUG, "%s(replace)\n", szFuncName);
1110 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1111 					   regbuf, &exactflag);
1112 			if (rc == 0) {
1113 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
1114 					    exactflag);
1115 #ifdef MULTIPLE_REGIONS
1116 				if ((rc =
1117 				     getxattr(DummyFile, PMR_AttrName, value,
1118 					      sizeof(value))) < xattrlen) {
1119 #else
1120 				if ((rc =
1121 				     getxattr(DummyFile, PMR_AttrName, value,
1122 					      sizeof(value))) == xattrlen) {
1123 #endif
1124 					DMLOG_PRINT(DMLVL_DEBUG,
1125 						    "%s passed with expected rc = 0\n",
1126 						    szFuncName);
1127 					DMVAR_PASS();
1128 				} else {
1129 					DMLOG_PRINT(DMLVL_ERR,
1130 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
1131 						    szFuncName, 0, PMR_AttrName,
1132 						    rc, xattrlen, errno);
1133 					DMVAR_FAIL();
1134 				}
1135 			} else {
1136 				DMLOG_PRINT(DMLVL_ERR,
1137 					    "%s failed with unexpected rc = %d (errno = %d)\n",
1138 					    szFuncName, rc, errno);
1139 				DMVAR_FAIL();
1140 			}
1141 
1142 			/* Variation clean up */
1143 			rc = close(fd);
1144 			rc |= remove(DummyFile);
1145 			if (rc == -1) {
1146 				DMLOG_PRINT(DMLVL_DEBUG,
1147 					    "Unable to clean up variation! (errno = %d)\n",
1148 					    errno);
1149 			}
1150 			dm_handle_free(hanp, hlen);
1151 		}
1152 	}
1153 
1154 	/*
1155 	 * TEST    : dm_set_region - private read mmap overlapping region
1156 	 * EXPECTED: rc = -1, errno = EBUSY
1157 	 */
1158 	if (DMVAR_EXEC(SET_REGION_BASE + 17)) {
1159 		int fd;
1160 		void *hanp;
1161 		size_t hlen;
1162 		u_int nelem;
1163 		dm_region_t regbuf[2];
1164 		dm_boolean_t exactflag;
1165 		void *memmap;
1166 
1167 		/* Variation set up */
1168 #ifdef MULTIPLE_REGIONS
1169 		nelem = 2;
1170 		regbuf[0].rg_offset = 0;
1171 		regbuf[0].rg_size = PAGE_SIZE / 2;
1172 		regbuf[0].rg_flags = DM_REGION_READ;
1173 		regbuf[1].rg_offset = PAGE_SIZE;
1174 		regbuf[1].rg_size = PAGE_SIZE / 2;
1175 		regbuf[1].rg_flags = DM_REGION_WRITE;
1176 #else
1177 		nelem = 1;
1178 		regbuf[0].rg_offset = 0;
1179 		regbuf[0].rg_size = PAGE_SIZE / 2;
1180 		regbuf[0].rg_flags = DM_REGION_READ;
1181 #endif
1182 
1183 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1184 		if ((rc = system(command)) == -1) {
1185 			/* No clean up */
1186 		} else
1187 		    if ((fd =
1188 			 open(DummyFile, O_RDWR | O_CREAT,
1189 			      DUMMY_FILE_RW_MODE)) == -1) {
1190 			remove(DummyFile);
1191 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1192 			close(fd);
1193 			remove(DummyFile);
1194 		} else
1195 		    if ((memmap =
1196 			 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd,
1197 			      0)) == MAP_FAILED) {
1198 			close(fd);
1199 			remove(DummyFile);
1200 			dm_handle_free(hanp, hlen);
1201 		}
1202 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1203 			DMLOG_PRINT(DMLVL_DEBUG,
1204 				    "Unable to set up variation! (errno = %d)\n",
1205 				    errno);
1206 			DMVAR_SKIP();
1207 		} else {
1208 			/* Variation */
1209 			DMLOG_PRINT(DMLVL_DEBUG,
1210 				    "%s(private read mmap overlap region)\n",
1211 				    szFuncName);
1212 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1213 					   regbuf, &exactflag);
1214 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1215 
1216 			/* Variation clean up */
1217 			munmap(memmap, PAGE_SIZE);
1218 			rc = close(fd);
1219 			rc |= remove(DummyFile);
1220 			if (rc == -1) {
1221 				DMLOG_PRINT(DMLVL_DEBUG,
1222 					    "Unable to clean up variation! (errno = %d)\n",
1223 					    errno);
1224 			}
1225 			dm_handle_free(hanp, hlen);
1226 		}
1227 	}
1228 
1229 	/*
1230 	 * TEST    : dm_set_region - private write mmap overlapping region
1231 	 * EXPECTED: rc = -1, errno = EBUSY
1232 	 */
1233 	if (DMVAR_EXEC(SET_REGION_BASE + 18)) {
1234 		int fd;
1235 		void *hanp;
1236 		size_t hlen;
1237 		u_int nelem;
1238 		dm_region_t regbuf[2];
1239 		dm_boolean_t exactflag;
1240 		void *memmap;
1241 
1242 		/* Variation set up */
1243 #ifdef MULTIPLE_REGIONS
1244 		nelem = 2;
1245 		regbuf[0].rg_offset = 0;
1246 		regbuf[0].rg_size = PAGE_SIZE / 2;
1247 		regbuf[0].rg_flags = DM_REGION_READ;
1248 		regbuf[1].rg_offset = PAGE_SIZE;
1249 		regbuf[1].rg_size = PAGE_SIZE / 2;
1250 		regbuf[1].rg_flags = DM_REGION_WRITE;
1251 #else
1252 		nelem = 1;
1253 		regbuf[0].rg_offset = PAGE_SIZE;
1254 		regbuf[0].rg_size = PAGE_SIZE / 2;
1255 		regbuf[0].rg_flags = DM_REGION_WRITE;
1256 #endif
1257 
1258 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1259 		if ((rc = system(command)) == -1) {
1260 			/* No clean up */
1261 		} else
1262 		    if ((fd =
1263 			 open(DummyFile, O_RDWR | O_CREAT,
1264 			      DUMMY_FILE_RW_MODE)) == -1) {
1265 			remove(DummyFile);
1266 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1267 			close(fd);
1268 			remove(DummyFile);
1269 		} else
1270 		    if ((memmap =
1271 			 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE, fd,
1272 			      PAGE_SIZE)) == MAP_FAILED) {
1273 			close(fd);
1274 			remove(DummyFile);
1275 			dm_handle_free(hanp, hlen);
1276 		}
1277 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1278 			DMLOG_PRINT(DMLVL_DEBUG,
1279 				    "Unable to set up variation! (errno = %d)\n",
1280 				    errno);
1281 			DMVAR_SKIP();
1282 		} else {
1283 			/* Variation */
1284 			DMLOG_PRINT(DMLVL_DEBUG,
1285 				    "%s(private write mmap overlap region)\n",
1286 				    szFuncName);
1287 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1288 					   regbuf, &exactflag);
1289 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1290 
1291 			/* Variation clean up */
1292 			munmap(memmap, PAGE_SIZE);
1293 			rc = close(fd);
1294 			rc |= remove(DummyFile);
1295 			if (rc == -1) {
1296 				DMLOG_PRINT(DMLVL_DEBUG,
1297 					    "Unable to clean up variation! (errno = %d)\n",
1298 					    errno);
1299 			}
1300 			dm_handle_free(hanp, hlen);
1301 		}
1302 	}
1303 
1304 	/*
1305 	 * TEST    : dm_set_region - private exec mmap overlapping region
1306 	 * EXPECTED: rc = -1, errno = EBUSY
1307 	 */
1308 	if (DMVAR_EXEC(SET_REGION_BASE + 19)) {
1309 		int fd;
1310 		void *hanp;
1311 		size_t hlen;
1312 		u_int nelem;
1313 		dm_region_t regbuf[2];
1314 		dm_boolean_t exactflag;
1315 		void *memmap;
1316 
1317 		/* Variation set up */
1318 #ifdef MULTIPLE_REGIONS
1319 		nelem = 2;
1320 		regbuf[0].rg_offset = 0;
1321 		regbuf[0].rg_size = PAGE_SIZE / 2;
1322 		regbuf[0].rg_flags = DM_REGION_READ;
1323 		regbuf[1].rg_offset = PAGE_SIZE;
1324 		regbuf[1].rg_size = PAGE_SIZE / 2;
1325 		regbuf[1].rg_flags = DM_REGION_WRITE;
1326 #else
1327 		nelem = 1;
1328 		regbuf[0].rg_offset = PAGE_SIZE;
1329 		regbuf[0].rg_size = PAGE_SIZE / 2;
1330 		regbuf[0].rg_flags = DM_REGION_WRITE;
1331 #endif
1332 
1333 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1334 		if ((rc = system(command)) == -1) {
1335 			/* No clean up */
1336 		} else
1337 		    if ((fd =
1338 			 open(DummyFile, O_RDWR | O_CREAT,
1339 			      DUMMY_FILE_RW_MODE)) == -1) {
1340 			remove(DummyFile);
1341 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1342 			close(fd);
1343 			remove(DummyFile);
1344 		} else
1345 		    if ((memmap =
1346 			 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_PRIVATE, fd,
1347 			      PAGE_SIZE)) == MAP_FAILED) {
1348 			close(fd);
1349 			remove(DummyFile);
1350 			dm_handle_free(hanp, hlen);
1351 		}
1352 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1353 			DMLOG_PRINT(DMLVL_DEBUG,
1354 				    "Unable to set up variation! (errno = %d)\n",
1355 				    errno);
1356 			DMVAR_SKIP();
1357 		} else {
1358 			/* Variation */
1359 			DMLOG_PRINT(DMLVL_DEBUG,
1360 				    "%s(private exec mmap overlap region)\n",
1361 				    szFuncName);
1362 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1363 					   regbuf, &exactflag);
1364 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1365 
1366 			/* Variation clean up */
1367 			munmap(memmap, PAGE_SIZE);
1368 			rc = close(fd);
1369 			rc |= remove(DummyFile);
1370 			if (rc == -1) {
1371 				DMLOG_PRINT(DMLVL_DEBUG,
1372 					    "Unable to clean up variation! (errno = %d)\n",
1373 					    errno);
1374 			}
1375 			dm_handle_free(hanp, hlen);
1376 		}
1377 	}
1378 
1379 	/*
1380 	 * TEST    : dm_set_region - private read/write mmap overlapping region
1381 	 * EXPECTED: rc = -1, errno = EBUSY
1382 	 */
1383 	if (DMVAR_EXEC(SET_REGION_BASE + 20)) {
1384 		int fd;
1385 		void *hanp;
1386 		size_t hlen;
1387 		u_int nelem;
1388 		dm_region_t regbuf[2];
1389 		dm_boolean_t exactflag;
1390 		void *memmap;
1391 
1392 		/* Variation set up */
1393 #ifdef MULTIPLE_REGIONS
1394 		nelem = 2;
1395 		regbuf[0].rg_offset = 0;
1396 		regbuf[0].rg_size = PAGE_SIZE / 2;
1397 		regbuf[0].rg_flags = DM_REGION_READ;
1398 		regbuf[1].rg_offset = PAGE_SIZE;
1399 		regbuf[1].rg_size = PAGE_SIZE / 2;
1400 		regbuf[1].rg_flags = DM_REGION_WRITE;
1401 #else
1402 		nelem = 1;
1403 		regbuf[0].rg_offset = 0;
1404 		regbuf[0].rg_size = PAGE_SIZE / 2;
1405 		regbuf[0].rg_flags = DM_REGION_READ;
1406 #endif
1407 
1408 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1409 		if ((rc = system(command)) == -1) {
1410 			/* No clean up */
1411 		} else
1412 		    if ((fd =
1413 			 open(DummyFile, O_RDWR | O_CREAT,
1414 			      DUMMY_FILE_RW_MODE)) == -1) {
1415 			remove(DummyFile);
1416 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1417 			close(fd);
1418 			remove(DummyFile);
1419 		} else
1420 		    if ((memmap =
1421 			 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
1422 			      MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
1423 			close(fd);
1424 			remove(DummyFile);
1425 			dm_handle_free(hanp, hlen);
1426 		}
1427 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1428 			DMLOG_PRINT(DMLVL_DEBUG,
1429 				    "Unable to set up variation! (errno = %d)\n",
1430 				    errno);
1431 			DMVAR_SKIP();
1432 		} else {
1433 			/* Variation */
1434 			DMLOG_PRINT(DMLVL_DEBUG,
1435 				    "%s(private r/w mmap overlap region)\n",
1436 				    szFuncName);
1437 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1438 					   regbuf, &exactflag);
1439 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1440 
1441 			/* Variation clean up */
1442 			munmap(memmap, PAGE_SIZE);
1443 			rc = close(fd);
1444 			rc |= remove(DummyFile);
1445 			if (rc == -1) {
1446 				DMLOG_PRINT(DMLVL_DEBUG,
1447 					    "Unable to clean up variation! (errno = %d)\n",
1448 					    errno);
1449 			}
1450 			dm_handle_free(hanp, hlen);
1451 		}
1452 	}
1453 
1454 	/*
1455 	 * TEST    : dm_set_region - shared read mmap overlapping region
1456 	 * EXPECTED: rc = -1, errno = EBUSY
1457 	 */
1458 	if (DMVAR_EXEC(SET_REGION_BASE + 21)) {
1459 		int fd;
1460 		void *hanp;
1461 		size_t hlen;
1462 		u_int nelem;
1463 		dm_region_t regbuf[2];
1464 		dm_boolean_t exactflag;
1465 		void *memmap;
1466 
1467 		/* Variation set up */
1468 #ifdef MULTIPLE_REGIONS
1469 		nelem = 2;
1470 		regbuf[0].rg_offset = 0;
1471 		regbuf[0].rg_size = PAGE_SIZE / 2;
1472 		regbuf[0].rg_flags = DM_REGION_READ;
1473 		regbuf[1].rg_offset = PAGE_SIZE;
1474 		regbuf[1].rg_size = PAGE_SIZE / 2;
1475 		regbuf[1].rg_flags = DM_REGION_WRITE;
1476 #else
1477 		nelem = 1;
1478 		regbuf[0].rg_offset = 0;
1479 		regbuf[0].rg_size = PAGE_SIZE / 2;
1480 		regbuf[0].rg_flags = DM_REGION_READ;
1481 #endif
1482 
1483 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1484 		if ((rc = system(command)) == -1) {
1485 			/* No clean up */
1486 		} else
1487 		    if ((fd =
1488 			 open(DummyFile, O_RDWR | O_CREAT,
1489 			      DUMMY_FILE_RW_MODE)) == -1) {
1490 			remove(DummyFile);
1491 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1492 			close(fd);
1493 			remove(DummyFile);
1494 		} else
1495 		    if ((memmap =
1496 			 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd,
1497 			      0)) == MAP_FAILED) {
1498 			close(fd);
1499 			remove(DummyFile);
1500 			dm_handle_free(hanp, hlen);
1501 		}
1502 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1503 			DMLOG_PRINT(DMLVL_DEBUG,
1504 				    "Unable to set up variation! (errno = %d)\n",
1505 				    errno);
1506 			DMVAR_SKIP();
1507 		} else {
1508 			/* Variation */
1509 			DMLOG_PRINT(DMLVL_DEBUG,
1510 				    "%s(shared read mmap overlap region)\n",
1511 				    szFuncName);
1512 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1513 					   regbuf, &exactflag);
1514 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1515 
1516 			/* Variation clean up */
1517 			munmap(memmap, PAGE_SIZE);
1518 			rc = close(fd);
1519 			rc |= remove(DummyFile);
1520 			if (rc == -1) {
1521 				DMLOG_PRINT(DMLVL_DEBUG,
1522 					    "Unable to clean up variation! (errno = %d)\n",
1523 					    errno);
1524 			}
1525 			dm_handle_free(hanp, hlen);
1526 		}
1527 	}
1528 
1529 	/*
1530 	 * TEST    : dm_set_region - shared write mmap overlapping region
1531 	 * EXPECTED: rc = -1, errno = EBUSY
1532 	 */
1533 	if (DMVAR_EXEC(SET_REGION_BASE + 22)) {
1534 		int fd;
1535 		void *hanp;
1536 		size_t hlen;
1537 		u_int nelem;
1538 		dm_region_t regbuf[2];
1539 		dm_boolean_t exactflag;
1540 		void *memmap;
1541 
1542 		/* Variation set up */
1543 #ifdef MULTIPLE_REGIONS
1544 		nelem = 2;
1545 		regbuf[0].rg_offset = 0;
1546 		regbuf[0].rg_size = PAGE_SIZE / 2;
1547 		regbuf[0].rg_flags = DM_REGION_READ;
1548 		regbuf[1].rg_offset = PAGE_SIZE;
1549 		regbuf[1].rg_size = PAGE_SIZE / 2;
1550 		regbuf[1].rg_flags = DM_REGION_WRITE;
1551 #else
1552 		nelem = 1;
1553 		regbuf[0].rg_offset = PAGE_SIZE;
1554 		regbuf[0].rg_size = PAGE_SIZE / 2;
1555 		regbuf[0].rg_flags = DM_REGION_WRITE;
1556 #endif
1557 
1558 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1559 		if ((rc = system(command)) == -1) {
1560 			/* No clean up */
1561 		} else
1562 		    if ((fd =
1563 			 open(DummyFile, O_RDWR | O_CREAT,
1564 			      DUMMY_FILE_RW_MODE)) == -1) {
1565 			remove(DummyFile);
1566 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1567 			close(fd);
1568 			remove(DummyFile);
1569 		} else
1570 		    if ((memmap =
1571 			 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_SHARED, fd,
1572 			      PAGE_SIZE)) == MAP_FAILED) {
1573 			close(fd);
1574 			remove(DummyFile);
1575 			dm_handle_free(hanp, hlen);
1576 		}
1577 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1578 			DMLOG_PRINT(DMLVL_DEBUG,
1579 				    "Unable to set up variation! (errno = %d)\n",
1580 				    errno);
1581 			DMVAR_SKIP();
1582 		} else {
1583 			/* Variation */
1584 			DMLOG_PRINT(DMLVL_DEBUG,
1585 				    "%s(shared write mmap overlap region)\n",
1586 				    szFuncName);
1587 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1588 					   regbuf, &exactflag);
1589 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1590 
1591 			/* Variation clean up */
1592 			munmap(memmap, PAGE_SIZE);
1593 			rc = close(fd);
1594 			rc |= remove(DummyFile);
1595 			if (rc == -1) {
1596 				DMLOG_PRINT(DMLVL_DEBUG,
1597 					    "Unable to clean up variation! (errno = %d)\n",
1598 					    errno);
1599 			}
1600 			dm_handle_free(hanp, hlen);
1601 		}
1602 	}
1603 
1604 	/*
1605 	 * TEST    : dm_set_region - shared exec mmap overlapping region
1606 	 * EXPECTED: rc = -1, errno = EBUSY
1607 	 */
1608 	if (DMVAR_EXEC(SET_REGION_BASE + 23)) {
1609 		int fd;
1610 		void *hanp;
1611 		size_t hlen;
1612 		u_int nelem;
1613 		dm_region_t regbuf[2];
1614 		dm_boolean_t exactflag;
1615 		void *memmap;
1616 
1617 		/* Variation set up */
1618 #ifdef MULTIPLE_REGIONS
1619 		nelem = 2;
1620 		regbuf[0].rg_offset = 0;
1621 		regbuf[0].rg_size = PAGE_SIZE / 2;
1622 		regbuf[0].rg_flags = DM_REGION_READ;
1623 		regbuf[1].rg_offset = PAGE_SIZE;
1624 		regbuf[1].rg_size = PAGE_SIZE / 2;
1625 		regbuf[1].rg_flags = DM_REGION_WRITE;
1626 #else
1627 		nelem = 1;
1628 		regbuf[0].rg_offset = PAGE_SIZE;
1629 		regbuf[0].rg_size = PAGE_SIZE / 2;
1630 		regbuf[0].rg_flags = DM_REGION_WRITE;
1631 #endif
1632 
1633 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1634 		if ((rc = system(command)) == -1) {
1635 			/* No clean up */
1636 		} else
1637 		    if ((fd =
1638 			 open(DummyFile, O_RDWR | O_CREAT,
1639 			      DUMMY_FILE_RW_MODE)) == -1) {
1640 			remove(DummyFile);
1641 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1642 			close(fd);
1643 			remove(DummyFile);
1644 		} else
1645 		    if ((memmap =
1646 			 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd,
1647 			      PAGE_SIZE)) == MAP_FAILED) {
1648 			close(fd);
1649 			remove(DummyFile);
1650 			dm_handle_free(hanp, hlen);
1651 		}
1652 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1653 			DMLOG_PRINT(DMLVL_DEBUG,
1654 				    "Unable to set up variation! (errno = %d)\n",
1655 				    errno);
1656 			DMVAR_SKIP();
1657 		} else {
1658 			/* Variation */
1659 			DMLOG_PRINT(DMLVL_DEBUG,
1660 				    "%s(shared exec mmap overlap region)\n",
1661 				    szFuncName);
1662 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1663 					   regbuf, &exactflag);
1664 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1665 
1666 			/* Variation clean up */
1667 			munmap(memmap, PAGE_SIZE);
1668 			rc = close(fd);
1669 			rc |= remove(DummyFile);
1670 			if (rc == -1) {
1671 				DMLOG_PRINT(DMLVL_DEBUG,
1672 					    "Unable to clean up variation! (errno = %d)\n",
1673 					    errno);
1674 			}
1675 			dm_handle_free(hanp, hlen);
1676 		}
1677 	}
1678 
1679 	/*
1680 	 * TEST    : dm_set_region - shared read/write mmap overlapping region
1681 	 * EXPECTED: rc = -1, errno = EBUSY
1682 	 */
1683 	if (DMVAR_EXEC(SET_REGION_BASE + 24)) {
1684 		int fd;
1685 		void *hanp;
1686 		size_t hlen;
1687 		u_int nelem;
1688 		dm_region_t regbuf[2];
1689 		dm_boolean_t exactflag;
1690 		void *memmap;
1691 
1692 		/* Variation set up */
1693 #ifdef MULTIPLE_REGIONS
1694 		nelem = 2;
1695 		regbuf[0].rg_offset = 0;
1696 		regbuf[0].rg_size = PAGE_SIZE / 2;
1697 		regbuf[0].rg_flags = DM_REGION_READ;
1698 		regbuf[1].rg_offset = PAGE_SIZE;
1699 		regbuf[1].rg_size = PAGE_SIZE / 2;
1700 		regbuf[1].rg_flags = DM_REGION_WRITE;
1701 #else
1702 		nelem = 1;
1703 		regbuf[0].rg_offset = 0;
1704 		regbuf[0].rg_size = PAGE_SIZE / 2;
1705 		regbuf[0].rg_flags = DM_REGION_READ;
1706 #endif
1707 
1708 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1709 		if ((rc = system(command)) == -1) {
1710 			/* No clean up */
1711 		} else
1712 		    if ((fd =
1713 			 open(DummyFile, O_RDWR | O_CREAT,
1714 			      DUMMY_FILE_RW_MODE)) == -1) {
1715 			remove(DummyFile);
1716 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1717 			close(fd);
1718 			remove(DummyFile);
1719 		} else
1720 		    if ((memmap =
1721 			 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
1722 			      MAP_SHARED, fd, 0)) == MAP_FAILED) {
1723 			close(fd);
1724 			remove(DummyFile);
1725 			dm_handle_free(hanp, hlen);
1726 		}
1727 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1728 			DMLOG_PRINT(DMLVL_DEBUG,
1729 				    "Unable to set up variation! (errno = %d)\n",
1730 				    errno);
1731 			DMVAR_SKIP();
1732 		} else {
1733 			/* Variation */
1734 			DMLOG_PRINT(DMLVL_DEBUG,
1735 				    "%s(shared r/w mmap overlap region)\n",
1736 				    szFuncName);
1737 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1738 					   regbuf, &exactflag);
1739 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1740 
1741 			/* Variation clean up */
1742 			munmap(memmap, PAGE_SIZE);
1743 			rc = close(fd);
1744 			rc |= remove(DummyFile);
1745 			if (rc == -1) {
1746 				DMLOG_PRINT(DMLVL_DEBUG,
1747 					    "Unable to clean up variation! (errno = %d)\n",
1748 					    errno);
1749 			}
1750 			dm_handle_free(hanp, hlen);
1751 		}
1752 	}
1753 
1754 	/*
1755 	 * TEST    : dm_set_region - private read mmap not overlapping region
1756 	 * EXPECTED: rc = 0
1757 	 */
1758 	if (DMVAR_EXEC(SET_REGION_BASE + 25)) {
1759 		int fd;
1760 		void *hanp;
1761 		size_t hlen;
1762 		u_int nelem;
1763 		dm_region_t regbuf[2];
1764 		dm_boolean_t exactflag;
1765 		void *memmap;
1766 
1767 		/* Variation set up */
1768 #ifdef MULTIPLE_REGIONS
1769 		nelem = 2;
1770 		regbuf[0].rg_offset = 0;
1771 		regbuf[0].rg_size = PAGE_SIZE / 2;
1772 		regbuf[0].rg_flags = DM_REGION_READ;
1773 		regbuf[1].rg_offset = PAGE_SIZE;
1774 		regbuf[1].rg_size = PAGE_SIZE / 2;
1775 		regbuf[1].rg_flags = DM_REGION_WRITE;
1776 #else
1777 		nelem = 1;
1778 		regbuf[0].rg_offset = PAGE_SIZE;
1779 		regbuf[0].rg_size = PAGE_SIZE / 2;
1780 		regbuf[0].rg_flags = DM_REGION_WRITE;
1781 #endif
1782 
1783 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1784 		if ((rc = system(command)) == -1) {
1785 			/* No clean up */
1786 		} else
1787 		    if ((fd =
1788 			 open(DummyFile, O_RDWR | O_CREAT,
1789 			      DUMMY_FILE_RW_MODE)) == -1) {
1790 			remove(DummyFile);
1791 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1792 			close(fd);
1793 			remove(DummyFile);
1794 		} else
1795 		    if ((memmap =
1796 			 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd,
1797 			      PAGE_SIZE)) == MAP_FAILED) {
1798 			close(fd);
1799 			remove(DummyFile);
1800 			dm_handle_free(hanp, hlen);
1801 		}
1802 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1803 			DMLOG_PRINT(DMLVL_DEBUG,
1804 				    "Unable to set up variation! (errno = %d)\n",
1805 				    errno);
1806 			DMVAR_SKIP();
1807 		} else {
1808 			/* Variation */
1809 			DMLOG_PRINT(DMLVL_DEBUG,
1810 				    "%s(private read mmap not overlap region)\n",
1811 				    szFuncName);
1812 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1813 					   regbuf, &exactflag);
1814 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
1815 
1816 			/* Variation clean up */
1817 			munmap(memmap, PAGE_SIZE);
1818 			rc = close(fd);
1819 			rc |= remove(DummyFile);
1820 			if (rc == -1) {
1821 				DMLOG_PRINT(DMLVL_DEBUG,
1822 					    "Unable to clean up variation! (errno = %d)\n",
1823 					    errno);
1824 			}
1825 			dm_handle_free(hanp, hlen);
1826 		}
1827 	}
1828 
1829 	/*
1830 	 * TEST    : dm_set_region - private write mmap not overlapping region
1831 	 * EXPECTED: rc = 0
1832 	 */
1833 	if (DMVAR_EXEC(SET_REGION_BASE + 26)) {
1834 		int fd;
1835 		void *hanp;
1836 		size_t hlen;
1837 		u_int nelem;
1838 		dm_region_t regbuf[2];
1839 		dm_boolean_t exactflag;
1840 		void *memmap;
1841 
1842 		/* Variation set up */
1843 #ifdef MULTIPLE_REGIONS
1844 		nelem = 2;
1845 		regbuf[0].rg_offset = 0;
1846 		regbuf[0].rg_size = PAGE_SIZE / 2;
1847 		regbuf[0].rg_flags = DM_REGION_READ;
1848 		regbuf[1].rg_offset = PAGE_SIZE;
1849 		regbuf[1].rg_size = PAGE_SIZE / 2;
1850 		regbuf[1].rg_flags = DM_REGION_WRITE;
1851 #else
1852 		nelem = 1;
1853 		regbuf[0].rg_offset = 0;
1854 		regbuf[0].rg_size = PAGE_SIZE / 2;
1855 		regbuf[0].rg_flags = DM_REGION_READ;
1856 #endif
1857 
1858 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1859 		if ((rc = system(command)) == -1) {
1860 			/* No clean up */
1861 		} else
1862 		    if ((fd =
1863 			 open(DummyFile, O_RDWR | O_CREAT,
1864 			      DUMMY_FILE_RW_MODE)) == -1) {
1865 			remove(DummyFile);
1866 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1867 			close(fd);
1868 			remove(DummyFile);
1869 		} else
1870 		    if ((memmap =
1871 			 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE, fd,
1872 			      0)) == MAP_FAILED) {
1873 			close(fd);
1874 			remove(DummyFile);
1875 			dm_handle_free(hanp, hlen);
1876 		}
1877 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1878 			DMLOG_PRINT(DMLVL_DEBUG,
1879 				    "Unable to set up variation! (errno = %d)\n",
1880 				    errno);
1881 			DMVAR_SKIP();
1882 		} else {
1883 			/* Variation */
1884 			DMLOG_PRINT(DMLVL_DEBUG,
1885 				    "%s(private write mmap not overlap region)\n",
1886 				    szFuncName);
1887 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1888 					   regbuf, &exactflag);
1889 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
1890 
1891 			/* Variation clean up */
1892 			munmap(memmap, PAGE_SIZE);
1893 			rc = close(fd);
1894 			rc |= remove(DummyFile);
1895 			if (rc == -1) {
1896 				DMLOG_PRINT(DMLVL_DEBUG,
1897 					    "Unable to clean up variation! (errno = %d)\n",
1898 					    errno);
1899 			}
1900 			dm_handle_free(hanp, hlen);
1901 		}
1902 	}
1903 
1904 	/*
1905 	 * TEST    : dm_set_region - private exec mmap not overlapping region
1906 	 * EXPECTED: rc = 0
1907 	 */
1908 	if (DMVAR_EXEC(SET_REGION_BASE + 27)) {
1909 		int fd;
1910 		void *hanp;
1911 		size_t hlen;
1912 		u_int nelem;
1913 		dm_region_t regbuf[2];
1914 		dm_boolean_t exactflag;
1915 		void *memmap;
1916 
1917 		/* Variation set up */
1918 #ifdef MULTIPLE_REGIONS
1919 		nelem = 2;
1920 		regbuf[0].rg_offset = 0;
1921 		regbuf[0].rg_size = PAGE_SIZE / 2;
1922 		regbuf[0].rg_flags = DM_REGION_READ;
1923 		regbuf[1].rg_offset = PAGE_SIZE;
1924 		regbuf[1].rg_size = PAGE_SIZE / 2;
1925 		regbuf[1].rg_flags = DM_REGION_WRITE;
1926 #else
1927 		nelem = 1;
1928 		regbuf[0].rg_offset = 0;
1929 		regbuf[0].rg_size = PAGE_SIZE / 2;
1930 		regbuf[0].rg_flags = DM_REGION_READ;
1931 #endif
1932 
1933 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
1934 		if ((rc = system(command)) == -1) {
1935 			/* No clean up */
1936 		} else
1937 		    if ((fd =
1938 			 open(DummyFile, O_RDWR | O_CREAT,
1939 			      DUMMY_FILE_RW_MODE)) == -1) {
1940 			remove(DummyFile);
1941 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1942 			close(fd);
1943 			remove(DummyFile);
1944 		} else
1945 		    if ((memmap =
1946 			 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_PRIVATE, fd,
1947 			      0)) == MAP_FAILED) {
1948 			close(fd);
1949 			remove(DummyFile);
1950 			dm_handle_free(hanp, hlen);
1951 		}
1952 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
1953 			DMLOG_PRINT(DMLVL_DEBUG,
1954 				    "Unable to set up variation! (errno = %d)\n",
1955 				    errno);
1956 			DMVAR_SKIP();
1957 		} else {
1958 			/* Variation */
1959 			DMLOG_PRINT(DMLVL_DEBUG,
1960 				    "%s(private exec mmap not overlap region)\n",
1961 				    szFuncName);
1962 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
1963 					   regbuf, &exactflag);
1964 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
1965 
1966 			/* Variation clean up */
1967 			munmap(memmap, PAGE_SIZE);
1968 			rc = close(fd);
1969 			rc |= remove(DummyFile);
1970 			if (rc == -1) {
1971 				DMLOG_PRINT(DMLVL_DEBUG,
1972 					    "Unable to clean up variation! (errno = %d)\n",
1973 					    errno);
1974 			}
1975 			dm_handle_free(hanp, hlen);
1976 		}
1977 	}
1978 
1979 	/*
1980 	 * TEST    : dm_set_region - private r/w mmap not overlapping region
1981 	 * EXPECTED: rc = 0
1982 	 */
1983 	if (DMVAR_EXEC(SET_REGION_BASE + 28)) {
1984 		int fd;
1985 		void *hanp;
1986 		size_t hlen;
1987 		u_int nelem;
1988 		dm_region_t regbuf[2];
1989 		dm_boolean_t exactflag;
1990 		void *memmap;
1991 
1992 		/* Variation set up */
1993 #ifdef MULTIPLE_REGIONS
1994 		nelem = 2;
1995 		regbuf[0].rg_offset = 0;
1996 		regbuf[0].rg_size = PAGE_SIZE / 2;
1997 		regbuf[0].rg_flags = DM_REGION_READ;
1998 		regbuf[1].rg_offset = PAGE_SIZE;
1999 		regbuf[1].rg_size = PAGE_SIZE / 2;
2000 		regbuf[1].rg_flags = DM_REGION_WRITE;
2001 #else
2002 		nelem = 1;
2003 		regbuf[0].rg_offset = 0;
2004 		regbuf[0].rg_size = PAGE_SIZE / 2;
2005 		regbuf[0].rg_flags = DM_REGION_READ;
2006 #endif
2007 
2008 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2009 		if ((rc = system(command)) == -1) {
2010 			/* No clean up */
2011 		} else
2012 		    if ((fd =
2013 			 open(DummyFile, O_RDWR | O_CREAT,
2014 			      DUMMY_FILE_RW_MODE)) == -1) {
2015 			remove(DummyFile);
2016 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2017 			close(fd);
2018 			remove(DummyFile);
2019 		} else
2020 		    if ((memmap =
2021 			 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
2022 			      MAP_PRIVATE, fd, 2 * PAGE_SIZE)) == MAP_FAILED) {
2023 			close(fd);
2024 			remove(DummyFile);
2025 			dm_handle_free(hanp, hlen);
2026 		}
2027 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
2028 			DMLOG_PRINT(DMLVL_DEBUG,
2029 				    "Unable to set up variation! (errno = %d)\n",
2030 				    errno);
2031 			DMVAR_SKIP();
2032 		} else {
2033 			/* Variation */
2034 			DMLOG_PRINT(DMLVL_DEBUG,
2035 				    "%s(private r/w mmap not overlap region)\n",
2036 				    szFuncName);
2037 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2038 					   regbuf, &exactflag);
2039 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
2040 
2041 			/* Variation clean up */
2042 			munmap(memmap, PAGE_SIZE);
2043 			rc = close(fd);
2044 			rc |= remove(DummyFile);
2045 			if (rc == -1) {
2046 				DMLOG_PRINT(DMLVL_DEBUG,
2047 					    "Unable to clean up variation! (errno = %d)\n",
2048 					    errno);
2049 			}
2050 			dm_handle_free(hanp, hlen);
2051 		}
2052 	}
2053 
2054 	/*
2055 	 * TEST    : dm_set_region - shared read mmap not overlapping region
2056 	 * EXPECTED: rc = 0
2057 	 */
2058 	if (DMVAR_EXEC(SET_REGION_BASE + 29)) {
2059 		int fd;
2060 		void *hanp;
2061 		size_t hlen;
2062 		u_int nelem;
2063 		dm_region_t regbuf[2];
2064 		dm_boolean_t exactflag;
2065 		void *memmap;
2066 
2067 		/* Variation set up */
2068 #ifdef MULTIPLE_REGIONS
2069 		nelem = 2;
2070 		regbuf[0].rg_offset = 0;
2071 		regbuf[0].rg_size = PAGE_SIZE / 2;
2072 		regbuf[0].rg_flags = DM_REGION_READ;
2073 		regbuf[1].rg_offset = PAGE_SIZE;
2074 		regbuf[1].rg_size = PAGE_SIZE / 2;
2075 		regbuf[1].rg_flags = DM_REGION_WRITE;
2076 #else
2077 		nelem = 1;
2078 		regbuf[0].rg_offset = PAGE_SIZE;
2079 		regbuf[0].rg_size = PAGE_SIZE / 2;
2080 		regbuf[0].rg_flags = DM_REGION_WRITE;
2081 #endif
2082 
2083 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2084 		if ((rc = system(command)) == -1) {
2085 			/* No clean up */
2086 		} else
2087 		    if ((fd =
2088 			 open(DummyFile, O_RDWR | O_CREAT,
2089 			      DUMMY_FILE_RW_MODE)) == -1) {
2090 			remove(DummyFile);
2091 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2092 			close(fd);
2093 			remove(DummyFile);
2094 		} else
2095 		    if ((memmap =
2096 			 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd,
2097 			      PAGE_SIZE)) == MAP_FAILED) {
2098 			close(fd);
2099 			remove(DummyFile);
2100 			dm_handle_free(hanp, hlen);
2101 		}
2102 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
2103 			DMLOG_PRINT(DMLVL_DEBUG,
2104 				    "Unable to set up variation! (errno = %d)\n",
2105 				    errno);
2106 			DMVAR_SKIP();
2107 		} else {
2108 			/* Variation */
2109 			DMLOG_PRINT(DMLVL_DEBUG,
2110 				    "%s(shared read mmap not overlap region)\n",
2111 				    szFuncName);
2112 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2113 					   regbuf, &exactflag);
2114 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
2115 
2116 			/* Variation clean up */
2117 			munmap(memmap, PAGE_SIZE);
2118 			rc = close(fd);
2119 			rc |= remove(DummyFile);
2120 			if (rc == -1) {
2121 				DMLOG_PRINT(DMLVL_DEBUG,
2122 					    "Unable to clean up variation! (errno = %d)\n",
2123 					    errno);
2124 			}
2125 			dm_handle_free(hanp, hlen);
2126 		}
2127 	}
2128 
2129 	/*
2130 	 * TEST    : dm_set_region - shared write mmap not overlapping region
2131 	 * EXPECTED: rc = 0
2132 	 */
2133 	if (DMVAR_EXEC(SET_REGION_BASE + 30)) {
2134 		int fd;
2135 		void *hanp;
2136 		size_t hlen;
2137 		u_int nelem;
2138 		dm_region_t regbuf[2];
2139 		dm_boolean_t exactflag;
2140 		void *memmap;
2141 
2142 		/* Variation set up */
2143 #ifdef MULTIPLE_REGIONS
2144 		nelem = 2;
2145 		regbuf[0].rg_offset = 0;
2146 		regbuf[0].rg_size = PAGE_SIZE / 2;
2147 		regbuf[0].rg_flags = DM_REGION_READ;
2148 		regbuf[1].rg_offset = PAGE_SIZE;
2149 		regbuf[1].rg_size = PAGE_SIZE / 2;
2150 		regbuf[1].rg_flags = DM_REGION_WRITE;
2151 #else
2152 		nelem = 1;
2153 		regbuf[0].rg_offset = 0;
2154 		regbuf[0].rg_size = PAGE_SIZE / 2;
2155 		regbuf[0].rg_flags = DM_REGION_READ;
2156 #endif
2157 
2158 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2159 		if ((rc = system(command)) == -1) {
2160 			/* No clean up */
2161 		} else
2162 		    if ((fd =
2163 			 open(DummyFile, O_RDWR | O_CREAT,
2164 			      DUMMY_FILE_RW_MODE)) == -1) {
2165 			remove(DummyFile);
2166 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2167 			close(fd);
2168 			remove(DummyFile);
2169 		} else
2170 		    if ((memmap =
2171 			 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_SHARED, fd,
2172 			      0)) == MAP_FAILED) {
2173 			close(fd);
2174 			remove(DummyFile);
2175 			dm_handle_free(hanp, hlen);
2176 		}
2177 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
2178 			DMLOG_PRINT(DMLVL_DEBUG,
2179 				    "Unable to set up variation! (errno = %d)\n",
2180 				    errno);
2181 			DMVAR_SKIP();
2182 		} else {
2183 			/* Variation */
2184 			DMLOG_PRINT(DMLVL_DEBUG,
2185 				    "%s(shared write mmap not overlap region)\n",
2186 				    szFuncName);
2187 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2188 					   regbuf, &exactflag);
2189 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
2190 
2191 			/* Variation clean up */
2192 			munmap(memmap, PAGE_SIZE);
2193 			rc = close(fd);
2194 			rc |= remove(DummyFile);
2195 			if (rc == -1) {
2196 				DMLOG_PRINT(DMLVL_DEBUG,
2197 					    "Unable to clean up variation! (errno = %d)\n",
2198 					    errno);
2199 			}
2200 			dm_handle_free(hanp, hlen);
2201 		}
2202 	}
2203 
2204 	/*
2205 	 * TEST    : dm_set_region - shared exec mmap not overlapping region
2206 	 * EXPECTED: rc = 0
2207 	 */
2208 	if (DMVAR_EXEC(SET_REGION_BASE + 31)) {
2209 		int fd;
2210 		void *hanp;
2211 		size_t hlen;
2212 		u_int nelem;
2213 		dm_region_t regbuf[2];
2214 		dm_boolean_t exactflag;
2215 		void *memmap;
2216 
2217 		/* Variation set up */
2218 #ifdef MULTIPLE_REGIONS
2219 		nelem = 2;
2220 		regbuf[0].rg_offset = 0;
2221 		regbuf[0].rg_size = PAGE_SIZE / 2;
2222 		regbuf[0].rg_flags = DM_REGION_READ;
2223 		regbuf[1].rg_offset = PAGE_SIZE;
2224 		regbuf[1].rg_size = PAGE_SIZE / 2;
2225 		regbuf[1].rg_flags = DM_REGION_WRITE;
2226 #else
2227 		nelem = 1;
2228 		regbuf[0].rg_offset = 0;
2229 		regbuf[0].rg_size = PAGE_SIZE / 2;
2230 		regbuf[0].rg_flags = DM_REGION_READ;
2231 #endif
2232 
2233 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2234 		if ((rc = system(command)) == -1) {
2235 			/* No clean up */
2236 		} else
2237 		    if ((fd =
2238 			 open(DummyFile, O_RDWR | O_CREAT,
2239 			      DUMMY_FILE_RW_MODE)) == -1) {
2240 			remove(DummyFile);
2241 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2242 			close(fd);
2243 			remove(DummyFile);
2244 		} else
2245 		    if ((memmap =
2246 			 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd,
2247 			      0)) == MAP_FAILED) {
2248 			close(fd);
2249 			remove(DummyFile);
2250 			dm_handle_free(hanp, hlen);
2251 		}
2252 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
2253 			DMLOG_PRINT(DMLVL_DEBUG,
2254 				    "Unable to set up variation! (errno = %d)\n",
2255 				    errno);
2256 			DMVAR_SKIP();
2257 		} else {
2258 			/* Variation */
2259 			DMLOG_PRINT(DMLVL_DEBUG,
2260 				    "%s(shared exec mmap not overlap region)\n",
2261 				    szFuncName);
2262 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2263 					   regbuf, &exactflag);
2264 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY);
2265 
2266 			/* Variation clean up */
2267 			munmap(memmap, PAGE_SIZE);
2268 			rc = close(fd);
2269 			rc |= remove(DummyFile);
2270 			if (rc == -1) {
2271 				DMLOG_PRINT(DMLVL_DEBUG,
2272 					    "Unable to clean up variation! (errno = %d)\n",
2273 					    errno);
2274 			}
2275 			dm_handle_free(hanp, hlen);
2276 		}
2277 	}
2278 
2279 	/*
2280 	 * TEST    : dm_set_region - shared r/w mmap not overlapping region
2281 	 * EXPECTED: rc = 0
2282 	 */
2283 	if (DMVAR_EXEC(SET_REGION_BASE + 32)) {
2284 		int fd;
2285 		void *hanp;
2286 		size_t hlen;
2287 		u_int nelem;
2288 		dm_region_t regbuf[2];
2289 		dm_boolean_t exactflag;
2290 		void *memmap;
2291 
2292 		/* Variation set up */
2293 #ifdef MULTIPLE_REGIONS
2294 		nelem = 2;
2295 		regbuf[0].rg_offset = 0;
2296 		regbuf[0].rg_size = PAGE_SIZE / 2;
2297 		regbuf[0].rg_flags = DM_REGION_READ;
2298 		regbuf[1].rg_offset = PAGE_SIZE;
2299 		regbuf[1].rg_size = PAGE_SIZE / 2;
2300 		regbuf[1].rg_flags = DM_REGION_WRITE;
2301 #else
2302 		nelem = 1;
2303 		regbuf[0].rg_offset = 0;
2304 		regbuf[0].rg_size = PAGE_SIZE / 2;
2305 		regbuf[0].rg_flags = DM_REGION_READ;
2306 #endif
2307 
2308 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2309 		if ((rc = system(command)) == -1) {
2310 			/* No clean up */
2311 		} else
2312 		    if ((fd =
2313 			 open(DummyFile, O_RDWR | O_CREAT,
2314 			      DUMMY_FILE_RW_MODE)) == -1) {
2315 			remove(DummyFile);
2316 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2317 			close(fd);
2318 			remove(DummyFile);
2319 		} else
2320 		    if ((memmap =
2321 			 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
2322 			      MAP_SHARED, fd, 2 * PAGE_SIZE)) == MAP_FAILED) {
2323 			close(fd);
2324 			remove(DummyFile);
2325 			dm_handle_free(hanp, hlen);
2326 		}
2327 		if (rc == -1 || fd == -1 || memmap == MAP_FAILED) {
2328 			DMLOG_PRINT(DMLVL_DEBUG,
2329 				    "Unable to set up variation! (errno = %d)\n",
2330 				    errno);
2331 			DMVAR_SKIP();
2332 		} else {
2333 			/* Variation */
2334 			DMLOG_PRINT(DMLVL_DEBUG,
2335 				    "%s(shared r/w mmap not overlap region)\n",
2336 				    szFuncName);
2337 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2338 					   regbuf, &exactflag);
2339 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
2340 
2341 			/* Variation clean up */
2342 			munmap(memmap, PAGE_SIZE);
2343 			rc = close(fd);
2344 			rc |= remove(DummyFile);
2345 			if (rc == -1) {
2346 				DMLOG_PRINT(DMLVL_DEBUG,
2347 					    "Unable to clean up variation! (errno = %d)\n",
2348 					    errno);
2349 			}
2350 			dm_handle_free(hanp, hlen);
2351 		}
2352 	}
2353 
2354 	/*
2355 	 * TEST    : dm_set_region - persistent, Part I
2356 	 * EXPECTED: rc = 0
2357 	 */
2358 	if (DMVAR_EXEC(SET_REGION_BASE + 33)) {
2359 		int fd;
2360 		void *hanp;
2361 		size_t hlen;
2362 		u_int nelem;
2363 		dm_region_t regbuf[PMR_NUM_REGIONS];
2364 		dm_boolean_t exactflag;
2365 		char value[ATTR_LISTLEN];
2366 
2367 		/* Variation set up */
2368 		nelem = PMR_NUM_REGIONS;
2369 		memcpy(regbuf, dm_PMR_regbuf, nelem * sizeof(dm_region_t));
2370 		sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile);
2371 		if ((rc = system(command)) == -1) {
2372 			/* No clean up */
2373 		} else
2374 		    if ((fd =
2375 			 open(DummyFile, O_RDWR | O_CREAT,
2376 			      DUMMY_FILE_RW_MODE)) == -1) {
2377 			remove(DummyFile);
2378 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2379 			close(fd);
2380 			remove(DummyFile);
2381 		}
2382 		if (rc == -1 || fd == -1) {
2383 			DMLOG_PRINT(DMLVL_DEBUG,
2384 				    "Unable to set up variation! (errno = %d)\n",
2385 				    errno);
2386 			DMVAR_SKIP();
2387 		} else {
2388 			/* Variation */
2389 			DMLOG_PRINT(DMLVL_DEBUG, "%s(persistent, Part I)\n",
2390 				    szFuncName);
2391 			rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem,
2392 					   regbuf, &exactflag);
2393 			if (rc == 0) {
2394 				DMLOG_PRINT(DMLVL_DEBUG, "exactflag = %d\n",
2395 					    exactflag);
2396 				if ((rc =
2397 				     getxattr(DummyFile, PMR_AttrName, value,
2398 					      sizeof(value))) >=
2399 				    (PMR_NUM_REGIONS * sizeof(dm_region_t))) {
2400 					DMLOG_PRINT(DMLVL_DEBUG,
2401 						    "%s passed with expected rc = 0\n",
2402 						    szFuncName);
2403 					DMVAR_PASS();
2404 
2405 					printf
2406 					    ("********************************************************\n");
2407 					printf
2408 					    ("* PLEASE REBOOT AND RUN pmr_post TO COMPLETE VARIATION *\n");
2409 					printf
2410 					    ("********************************************************\n");
2411 
2412 				} else {
2413 					DMLOG_PRINT(DMLVL_ERR,
2414 						    "%s failed with expected rc = %d but unexpected getxattr(%s) rc (%d vs %d), errno %d\n",
2415 						    szFuncName, 0, PMR_AttrName,
2416 						    rc,
2417 						    PMR_NUM_REGIONS *
2418 						    sizeof(dm_region_t), errno);
2419 					DMVAR_FAIL();
2420 				}
2421 			} else {
2422 				DMLOG_PRINT(DMLVL_ERR,
2423 					    "%s failed with unexpected rc = %d (errno = %d)\n",
2424 					    szFuncName, rc, errno);
2425 				DMVAR_FAIL();
2426 			}
2427 
2428 			/* Variation clean up */
2429 			rc = close(fd);
2430 			/* DO NOT REMOVE DummyFile, IT IS NEEDED BY pmr_post */
2431 			/*rc |= remove(DummyFile); */
2432 			if (rc == -1) {
2433 				DMLOG_PRINT(DMLVL_DEBUG,
2434 					    "Unable to clean up variation! (errno = %d)\n",
2435 					    errno);
2436 			}
2437 			dm_handle_free(hanp, hlen);
2438 		}
2439 	}
2440 
2441 	rc = umount(mountPt);
2442 	if (rc == -1) {
2443 		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
2444 			    rc, errno);
2445 	}
2446 
2447 	pthread_join(tid, NULL);
2448 
2449 	rc = dm_destroy_session(sid);
2450 	if (rc == -1) {
2451 		DMLOG_PRINT(DMLVL_ERR,
2452 			    "dm_destroy_session failed! (rc = %d, errno = %d)\n",
2453 			    rc, errno);
2454 	}
2455 
2456 	remove(DUMMY_FILE);
2457 
2458 	DMLOG_STOP();
2459 
2460 	tst_exit();
2461 }
2462 
2463 void *Thread(void *parm)
2464 {
2465 	int rc;
2466 	size_t dmMsgBufLen;
2467 	dm_eventmsg_t *dmMsg;
2468 	int bMounted = DM_FALSE;
2469 	dm_eventtype_t type;
2470 	dm_token_t token;
2471 	dm_eventset_t events;
2472 	dm_response_t response;
2473 
2474 	do {
2475 		/* Loop until message received (wait could be interrupted) */
2476 		do {
2477 			DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
2478 			dmMsgBufLen = 0;
2479 
2480 			rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
2481 					   dmMsgBuf, &dmMsgBufLen);
2482 			DMLOG_PRINT(DMLVL_DEBUG,
2483 				    "... dm_get_events returned %d (errno %d)\n",
2484 				    rc, errno);
2485 		} while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
2486 
2487 		if (rc) {
2488 			DMLOG_PRINT(DMLVL_ERR,
2489 				    "dm_get_events failed with rc = %d, errno = %d\n",
2490 				    rc, errno);
2491 			dm_destroy_session(sid);
2492 			DM_EXIT();
2493 		} else {
2494 			dmMsg = (dm_eventmsg_t *) dmMsgBuf;
2495 			token = dmMsg->ev_token;
2496 			type = dmMsg->ev_type;
2497 
2498 			DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
2499 		}
2500 
2501 		if (type == DM_EVENT_MOUNT) {
2502 			/* SPECIAL CASE: need to set bMounted and response */
2503 			dm_mount_event_t *me =
2504 			    DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
2505 			void *lhanp = DM_GET_VALUE(me, me_handle1, void *);
2506 			size_t lhlen = DM_GET_LEN(me, me_handle1);
2507 
2508 			bMounted = dm_handle_is_valid(lhanp, lhlen);
2509 
2510 			rc = dm_request_right(sid, lhanp, lhlen, token,
2511 					      DM_RR_WAIT, DM_RIGHT_EXCL);
2512 			if (rc == -1) {
2513 				DMLOG_PRINT(DMLVL_ERR,
2514 					    "dm_request_right failed! (rc = %d, errno = %d)\n",
2515 					    rc, errno);
2516 				dm_destroy_session(sid);
2517 				DM_EXIT();
2518 			}
2519 
2520 			DMEV_ZERO(events);
2521 			DMEV_SET(DM_EVENT_UNMOUNT, events);
2522 			rc = dm_set_disp(sid, lhanp, lhlen, token, &events,
2523 					 DM_EVENT_MAX);
2524 			if (rc == -1) {
2525 				DMLOG_PRINT(DMLVL_ERR,
2526 					    "dm_set_disp failed! (rc = %d, errno = %d)\n",
2527 					    rc, errno);
2528 				dm_destroy_session(sid);
2529 				DM_EXIT();
2530 			}
2531 
2532 			rc = dm_set_eventlist(sid, lhanp, lhlen, token, &events,
2533 					      DM_EVENT_MAX);
2534 			if (rc == -1) {
2535 				DMLOG_PRINT(DMLVL_ERR,
2536 					    "dm_set_eventlist failed! (rc = %d, errno = %d)\n",
2537 					    rc, errno);
2538 				dm_destroy_session(sid);
2539 				DM_EXIT();
2540 			}
2541 
2542 			rc = dm_release_right(sid, lhanp, lhlen, token);
2543 			if (rc == -1) {
2544 				DMLOG_PRINT(DMLVL_ERR,
2545 					    "dm_request_right failed! (rc = %d, errno = %d)\n",
2546 					    rc, errno);
2547 				dm_destroy_session(sid);
2548 				DM_EXIT();
2549 			}
2550 
2551 			response = DM_RESP_CONTINUE;
2552 		} else if (type == DM_EVENT_UNMOUNT) {
2553 			/* SPECIAL CASE: need to set bMounted and response */
2554 			dm_namesp_event_t *nse =
2555 			    DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
2556 
2557 			if (nse->ne_retcode == 0) {
2558 				bMounted = DM_FALSE;
2559 			}
2560 
2561 			response = DM_RESP_CONTINUE;
2562 		} else {
2563 			DMLOG_PRINT(DMLVL_ERR, "Message is unexpected!\n");
2564 			response = DM_RESP_ABORT;
2565 		}
2566 
2567 		if (response != DM_RESP_INVALID) {
2568 			DMLOG_PRINT(DMLVL_DEBUG,
2569 				    "Responding to message %d with %d\n", type,
2570 				    response);
2571 			rc = dm_respond_event(sid, token, response,
2572 					      response ==
2573 					      DM_RESP_ABORT ? ABORT_ERRNO : 0,
2574 					      0, NULL);
2575 		}
2576 	} while (bMounted);
2577 
2578 	pthread_exit(0);
2579 }
2580