Esempio n. 1
0
void *Thread(void *parm)
{
	int rc;
	size_t dmMsgBufLen;
	dm_eventmsg_t *dmMsg;
	int bMounted = DM_FALSE;
	dm_eventtype_t type;
	dm_token_t token;
	dm_eventset_t events;
	dm_response_t response;

	do {
		/* Loop until message received (wait could be interrupted) */
		do {
			DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
			dmMsgBufLen = 0;

			rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf), dmMsgBuf, &dmMsgBufLen);
			DMLOG_PRINT(DMLVL_DEBUG, "... dm_get_events returned %d (errno %d)\n", rc, errno);
		} while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));

		if (rc) {
			DMLOG_PRINT(DMLVL_ERR, "dm_get_events failed with rc = %d, errno = %d\n", rc, errno);
			dm_destroy_session(sid);
			DM_EXIT();
		} else {
			dmMsg = (dm_eventmsg_t *)dmMsgBuf;
			token = dmMsg->ev_token;
			type = dmMsg->ev_type;

			DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
		}

		if (type == DM_EVENT_MOUNT) {
			/* SPECIAL CASE: need to set disposition, events and response */
			dm_mount_event_t *me = DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
			void *hanp = DM_GET_VALUE(me, me_handle1, void *);
			size_t hlen = DM_GET_LEN(me, me_handle1);

			DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
			DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n", me->me_mode);
			DMLOG_PRINT(DMLVL_DEBUG, "  File system handle: %p\n", hanp);
			DMLOG_PRINT(DMLVL_DEBUG, "  File system handle length: %d\n", hlen);
			DMLOG_PRINT(DMLVL_DEBUG, "  Mountpoint handle: %p\n", DM_GET_VALUE(me, me_handle2, void *));
			DMLOG_PRINT(DMLVL_DEBUG, "  Mountpoint handle length: %d\n", DM_GET_LEN(me, me_handle2));
			DMLOG_PRINT(DMLVL_DEBUG, "  Mountpoint path: %s\n", DM_GET_VALUE(me, me_name1, char *));
			DMLOG_PRINT(DMLVL_DEBUG, "  Media designator: %s\n", DM_GET_VALUE(me, me_name2, char *));
			DMLOG_PRINT(DMLVL_DEBUG, "  Root handle: %p\n", DM_GET_VALUE(me, me_roothandle, void *));
			DMLOG_PRINT(DMLVL_DEBUG, "  Root handle length: %d\n", DM_GET_LEN(me, me_roothandle));

			bMounted = dm_handle_is_valid(hanp, hlen);

			rc = dm_request_right(sid, hanp, hlen, token, DM_RR_WAIT, DM_RIGHT_EXCL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "dm_request_right failed! (rc = %d, errno = %d)\n", rc, errno);
				dm_destroy_session(sid);
				DM_EXIT();
			}

			DMEV_ZERO(events);
			DMEV_SET(DM_EVENT_PREUNMOUNT, events);
			DMEV_SET(DM_EVENT_UNMOUNT, events);
			rc = dm_set_disp(sid, hanp, hlen, token, &events, DM_EVENT_MAX);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
				dm_destroy_session(sid);
				DM_EXIT();
			}

			rc = dm_set_eventlist(sid, hanp, hlen, token, &events, DM_EVENT_MAX);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "dm_set_eventlist failed! (rc = %d, errno = %d)\n", rc, errno);
				dm_destroy_session(sid);
				DM_EXIT();
			}

			rc = dm_release_right(sid, hanp, hlen, token);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "dm_request_right failed! (rc = %d, errno = %d)\n", rc, errno);
				dm_destroy_session(sid);
				DM_EXIT();
			}

			me_len = me->me_roothandle.vd_offset + me->me_roothandle.vd_length;
			if ((me_ptr = malloc(me_len)) == NULL) {
				DMLOG_PRINT(DMLVL_ERR, "malloc failed! (errno = %d)\n", errno);
				dm_destroy_session(sid);
				DM_EXIT();
			}
			memcpy(me_ptr, me, me_len);

			response = DM_RESP_CONTINUE;
		} else if (type == DM_EVENT_UNMOUNT) {
			dm_namesp_event_t *nse = DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
			if (nse->ne_retcode == 0) {
				bMounted = DM_FALSE;
			}

			response = DM_RESP_CONTINUE;
		} else {
Esempio n. 2
0
int main(int argc, char **argv)
{

	char *szFuncName;
	char *varstr;
	int   rc;
	char *szSessionInfo = "dm_test session info";
	dm_eventset_t events;

	DMOPT_PARSE(argc, argv);
	DMLOG_START();

	DMEV_ZERO(events);
	DMEV_SET(DM_EVENT_MOUNT, events);

	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
	if ((rc = dm_init_service(&varstr)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else {
		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
		sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);

		remove(DummyFile);
		rmdir(DummySubdir);
	}

	DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI mount tests\n") ;

	szFuncName = "dm_set_dmattr";

	/*
	 * TEST    : dm_get_mountinfo - invalid sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 1)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName);
			rc = dm_get_mountinfo(INVALID_ADDR, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid hanp
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 2)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName);
			rc = dm_get_mountinfo(sid, (void *)INVALID_ADDR, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid hlen
	 * EXPECTED: rc = -1, errno = EBADF
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 3)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid token
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 4)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, INVALID_ADDR, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid buflen
	 * EXPECTED: rc = -1, errno = E2BIG
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 5)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, 0, buf, &rlen);
			if (rc == -1) {
				if (errno == E2BIG) {
					DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
					if (rlen == me_len) {
						DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d and expected errno = %d\n", szFuncName, -1, E2BIG);
						DMVAR_PASS();
					} else {
						DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n", szFuncName, -1, E2BIG, rlen, me_len);
						DMVAR_FAIL();
					}
				} else {
					DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, -1, errno);
					DMVAR_FAIL();
				}
			} else {
				DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc);
				DMVAR_FAIL();
			}

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid bufp
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 6)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), (void *)INVALID_ADDR, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - invalid rlenp
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 7)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, (size_t *)INVALID_ADDR);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - valid
	 * EXPECTED: rc = 0
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 8)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			if (rc == 0) {
				DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
				if (rlen == me_len) {
					if (memcmp(buf, me_ptr, rlen) == 0) {
						DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0);
						DMVAR_PASS();
					} else {
						DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but mount info not same\n", szFuncName, 0);
						DMVAR_FAIL();
					}
				} else {
					DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but mount info len not same (%d vs %d)\n", szFuncName, 0, rlen, me_len);
					DMVAR_FAIL();
				}
			} else {
				DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno);
				DMVAR_FAIL();
			}

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - DM_NO_SESSION sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 9)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName);
			rc = dm_get_mountinfo(DM_NO_SESSION, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - global handle
	 * EXPECTED: rc = -1, errno = EBADF
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 10)) {
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName);
		rc = dm_get_mountinfo(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);

		/* Variation clean up */
	}

	/*
	 * TEST    : dm_get_mountinfo - file handle
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 11)) {
		int fd;
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : dm_get_mountinfo - dir handle
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 12)) {
		void *hanp;
		size_t hlen;
		char buf[MOUNTEVENT_LEN];
		size_t rlen;

		/* Variation set up */
		if ((rc = mkdir(DummySubdir, O_RDWR | O_CREAT)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) {
			rmdir(DummySubdir);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", szFuncName);
			rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	if (me_ptr != NULL) {
		free(me_ptr);
	}

	rc = umount(mountPt);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	pthread_join(tid, NULL);

	rc = dm_destroy_session(sid);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	DMLOG_STOP();

	return 0;
}
Esempio n. 3
0
int
main(
	int	argc, 
	char	**argv)
{
	dm_sessid_t	sid = DM_NO_SESSION;
	dm_token_t	token = DM_NO_TOKEN;
	char		*object;
	dm_eventset_t	eventset;
	void		*hanp;
	size_t	 	hlen;
	int		Fflag = 0;
	u_int		maxevent = DM_EVENT_MAX;
	char		*name;
	int		opt;

	Progname = strrchr(argv[0], '/');
	if (Progname) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	/* Crack and validate the command line options. */

	while ((opt = getopt(argc, argv, "Fm:s:t:")) != EOF) {
		switch (opt) {
		case 'F':
			Fflag++;
			break;
		case 'm':
			maxevent = atol(optarg);
			break;
		case 's':
			sid = atol(optarg);
			break;
		case 't':
			token = atol(optarg);
			break;
		case '?':
			usage();
		}
	}
	if (optind + 1 > argc)
		usage();
	object = argv[optind++];

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't initialize the DMAPI\n");
		exit(1);
	}
	if (sid == DM_NO_SESSION)
		find_test_session(&sid);

	DMEV_ZERO(eventset);

	/* Get the file's handle or convert the external handle. */

	if (opaque_to_handle(object, &hanp, &hlen)) {
		fprintf(stderr, "can't get handle for %s\n", object);
		exit(1);
	}

	if (Fflag) {
		void	*fshanp;
		size_t	fshlen;

		if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
			fprintf(stderr, "can't get filesystem handle from %s\n",
				object);
			exit(1);
		}
		dm_handle_free(hanp, hlen);
		hanp = fshanp;
		hlen = fshlen;
	}

	for (; optind < argc; optind++) {
		dm_eventtype_t	event;

		event = ev_name_to_value(argv[optind]);
		if (event == DM_EVENT_INVALID) {
			fprintf(stderr, "invalid event %s\n", argv[optind]);
			usage();
		}
		if ((event == DM_EVENT_READ) || (event == DM_EVENT_WRITE) ||
		    (event == DM_EVENT_TRUNCATE)) {
			fprintf(stderr, "Use set_region to twiddle read/write/trunc events\n");
			exit(1);
		}

		DMEV_SET(event, eventset);
	}

	if (dm_set_eventlist(sid, hanp, hlen, token, &eventset, maxevent)) {
		fprintf(stderr, "dm_set_eventlist failed, %s\n",
			strerror(errno));
		exit(1);
	}

	dm_handle_free(hanp, hlen);
	exit(0);
}
Esempio n. 4
0
int main(int argc, char **argv)
{

	char *varstr;
	int   rc;
	char *szSessionInfo = "dm_test session info";
	dm_eventset_t events;

	DMOPT_PARSE(argc, argv);
	DMLOG_START();

	DMEV_ZERO(events);
	DMEV_SET(DM_EVENT_MOUNT, events);

	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
	if ((rc = dm_init_service(&varstr)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else {
		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
		sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);

		remove(DummyFile);
		rmdir(DummySubdir);
	}

	fd_f = open(DummyFile, O_RDWR | O_CREAT);
	if (fd_f == -1) {
		DMLOG_PRINT(DMLVL_ERR, "open failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	/* This is what kicks off the test case, variations done in thread */
	runTestOnCreate = 1;
	rc = mkdir(DummySubdir, O_RDWR | O_CREAT);
	runTestOnCreate = 0;
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "mkdir failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	rc = rmdir(DummySubdir);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "rmdir failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	rc = close(fd_f);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "close failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	rc = remove(DummyFile);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "remove failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	rc = umount(mountPt);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	pthread_join(tid, NULL);

	rc = dm_destroy_session(sid);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	DMLOG_STOP();

	return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{

	char *szFuncName;
	char *varstr;
	int   rc;
	int   varStatus;
	char *szSessionInfo = "dm_test session info";
	dm_eventset_t events;

	DMOPT_PARSE(argc, argv);
	DMLOG_START();

	DMEV_ZERO(events);
	DMEV_SET(DM_EVENT_MOUNT, events);
	
	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
	if ((rc = dm_init_service(&varstr)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else {
		rc = dm_get_config(fshanp, fshlen, DM_CONFIG_MAX_MESSAGE_DATA, &maxMsgDat);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_ERR, "dm_get_config failed! (rc = %d, errno = %d)\n", rc, errno);
			umount(mountPt);
			dm_destroy_session(sid);
			DM_EXIT();
		}
	}

	DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI user event tests\n") ;

	szFuncName = "dm_create_userevent";
	
	/*
	 * TEST    : dm_create_uservent - invalid sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 1)) {
		char buf[MSG_DATALEN];
		dm_token_t token;

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); 
		rc = dm_create_userevent(INVALID_ADDR, MSG_DATALEN, buf, &token);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_create_uservent - invalid msglen
	 * EXPECTED: rc = -1, errno = E2BIG
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 2)) {
		char buf[MSG_DATALEN];
		dm_token_t token;

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msglen)\n", szFuncName); 
		rc = dm_create_userevent(sid, maxMsgDat+1, buf, &token);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_create_uservent - invalid msgdatap
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 3)) {
		dm_token_t token;

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgdatap)\n", szFuncName); 
		rc = dm_create_userevent(sid, MSG_DATALEN, (void *)INVALID_ADDR, &token);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_create_uservent - invalid tokenp
	 * EXPECTED: rc = -1, errno = EFAULT
	 *
	 * This variation uncovered XFS BUG #11 (unused tevp left on queue)
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 4)) {
		char buf[MSG_DATALEN];

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid tokenp)\n", szFuncName); 
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, (dm_token_t *)INVALID_ADDR);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_create_uservent - valid
	 * EXPECTED: rc = 0
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 5)) {
		char buf[MSG_DATALEN];
		dm_token_t token;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName); 
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		DMVAR_ENDPASSEXP(szFuncName, 0, rc);

		/* Variation clean up */
		rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
		}
	}
	
	/*
	 * TEST    : dm_create_uservent - DM_NO_SESSION sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 6)) {
		char buf[MSG_DATALEN];
		dm_token_t token;

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); 
		rc = dm_create_userevent(DM_NO_SESSION, MSG_DATALEN, buf, &token);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

		/* Variation clean up */
	}
	
	szFuncName = "dm_send_msg";
	
	/*
	 * TEST    : dm_send_msg - invalid targetsid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 1)) {
		char buf[MSG_DATALEN];

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid targetsid)\n", szFuncName); 
		rc = dm_send_msg(INVALID_ADDR, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - invalid msgtype
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 2)) {
		char buf[MSG_DATALEN];

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgtype)\n", szFuncName); 
		rc = dm_send_msg(sid, INVALID_ADDR, MSG_DATALEN, buf);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - invalid buflen
	 * EXPECTED: rc = -1, errno = E2BIG
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 3)) {
		char buf[MSG_DATALEN];

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName); 
		rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, maxMsgDat+1, buf);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - invalid bufp
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 4)) {
		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName); 
		rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, (void *)INVALID_ADDR);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - DM_RESP_CONTINUE
	 * EXPECTED: rc = 0
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 5)) {
		char buf[MSG_DATALEN];

		/* Variation set up */
		eventExpected = DM_EVENT_USER;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		memcpy(buf, MSG_DATA, MSG_DATALEN);

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(continue response)\n", szFuncName); 
		rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
		if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
			if (tokenReceived == 0) {
				DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs non-zero)\n", tokenReceived);
				varStatus = DMSTAT_FAIL;
			}
			if (msgDataLenReceived != MSG_DATALEN) {
				DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN);
				varStatus = DMSTAT_FAIL;
			} else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - DM_RESP_ABORT
	 * EXPECTED: rc = -1, errno = ABORT_ERRNO
	 *
	 * This variation uncovered XFS BUG #39 (response reterror returned 
	 * instead of -1 and errno set to reterror)
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 6)) {
		char buf[MSG_DATALEN];

		/* Variation set up */
		eventExpected = DM_EVENT_USER;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_ABORT;
		memcpy(buf, MSG_DATA, MSG_DATALEN);

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(abort response)\n", szFuncName); 
		rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
		if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
			if (tokenReceived == 0) {
				DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs non-zero)\n", tokenReceived);
				varStatus = DMSTAT_FAIL;
			}
			if (msgDataLenReceived != MSG_DATALEN) {
				DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN);
				varStatus = DMSTAT_FAIL;
			} else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
	}

	/*
	 * TEST    : dm_send_msg - DM_MSGTYPE_ASYNC
	 * EXPECTED: rc = 0
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 7)) {
		char buf[MSG_DATALEN];

		/* Variation set up */
		eventExpected = DM_EVENT_USER;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		memcpy(buf, MSG_DATA, MSG_DATALEN);

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_MSGTYPE_ASYNC)\n", szFuncName); 
		rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, MSG_DATALEN, buf);
		EVENT_DELIVERY_DELAY;
		if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
			if (tokenReceived != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs %d)\n", tokenReceived, 0);
				varStatus = DMSTAT_FAIL;
			}
			if (msgDataLenReceived != MSG_DATALEN) {
				DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN);
				varStatus = DMSTAT_FAIL;
			} else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
	}
	
	/*
	 * TEST    : dm_send_msg - DM_NO_SESSION targetsid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(SEND_MSG_BASE + 8)) {
		char buf[MSG_DATALEN];

		/* Variation set up */

		/* Variation */
		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION targetsid)\n", szFuncName); 
		rc = dm_send_msg(DM_NO_SESSION, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

		/* Variation clean up */
	}
	
	szFuncName = "dm_find_eventmsg";
	
	/*
	 * TEST    : dm_find_eventmsg - invalid sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 1)) {
		dm_token_t token;
		char buf[MSG_DATALEN];
		size_t rlen;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); 
			rc = dm_find_eventmsg(INVALID_ADDR, token, MSG_DATALEN, buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	/*
	 * TEST    : dm_find_eventmsg - invalid token
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 2)) {
		dm_token_t token;
		char buf[MSG_DATALEN];
		size_t rlen;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); 
			rc = dm_find_eventmsg(sid, INVALID_ADDR, MSG_DATALEN, buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	/*
	 * TEST    : dm_find_eventmsg - invalid buflen
	 * EXPECTED: rc = -1, errno = E2BIG
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 3)) {
		dm_token_t token;
		char buf[MSG_DATALEN];
		size_t rlen;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName); 
			rc = dm_find_eventmsg(sid, token, MSG_DATALEN-1, buf, &rlen);
			if (rc == -1) {
				if (errno == E2BIG) {
					DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
					if (rlen == MSG_DATALEN+sizeof(dm_eventmsg_t)) {
						DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d, expected errno = %d, and expected rlen = %d\n", szFuncName, rc, errno, rlen);
						DMVAR_PASS();
					} else {
						DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n", szFuncName, rc, errno, rlen, MSG_DATALEN);
						DMVAR_FAIL();
					}
				} else {
					DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, rc, errno);
					DMVAR_FAIL();
				}
			} else {
	  			DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc);
				DMVAR_FAIL();
			}

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	/*
	 * TEST    : dm_find_eventmsg - invalid bufp
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 4)) {
		dm_token_t token;
		char buf[MSG_DATALEN];
		size_t rlen;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName); 
			rc = dm_find_eventmsg(sid, token, MSG_DATALEN, (void *)INVALID_ADDR, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	/*
	 * TEST    : dm_find_eventmsg - invalid rlenp
	 * EXPECTED: rc = -1, errno = EFAULT
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 5)) {
		dm_token_t token;
		char buf[MSG_DATALEN];

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", szFuncName); 
			rc = dm_find_eventmsg(sid, token, MSG_DATALEN, buf, (size_t *)INVALID_ADDR);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : dm_find_eventmsg - valid
	 * EXPECTED: rc = 0
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 6)) {
		dm_token_t token;
		char bufin[MSG_DATALEN], bufout[MSG_DATALEN+sizeof(dm_eventmsg_t)];
		size_t rlen;

		/* Variation set up */
		memcpy(bufin, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, bufin, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName); 
			rc = dm_find_eventmsg(sid, token, sizeof(bufout), bufout, &rlen);
			if (rc == 0) {
				DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
				if (rlen == MSG_DATALEN+sizeof(dm_eventmsg_t)) {
					if (memcmp(bufin, bufout+sizeof(dm_eventmsg_t), MSG_DATALEN) == 0) {
				  		DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d, expected rlen %d, and expected buffer %s\n", szFuncName, rc, rlen, bufout+sizeof(dm_eventmsg_t));
						DMVAR_PASS();
					} else {
				  		DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected rlen %d but expected buffer %s\n", szFuncName, rc, rlen, bufout);
						DMVAR_FAIL();
					}
				} else {
			  		DMLOG_PRINT(DMLVL_ERR, "%s passed with expected rc = %d but unexpected rlen %d\n", szFuncName, rc, rlen);
					DMVAR_FAIL();
				}
			} else {
				DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno);
				DMVAR_FAIL();
			}

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	/*
	 * TEST    : dm_find_eventmsg - DM_NO_SESSION sid
	 * EXPECTED: rc = -1, errno = EINVAL
	 */
	if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 7)) {
		dm_token_t token;
		char buf[MSG_DATALEN];
		size_t rlen;

		/* Variation set up */
		memcpy(buf, MSG_DATA, MSG_DATALEN);
		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); 
			rc = dm_find_eventmsg(DM_NO_SESSION, token, MSG_DATALEN, buf, &rlen);
			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);

			/* Variation clean up */
			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}
	
	rc = umount(mountPt);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	EVENT_DELIVERY_DELAY;
	pthread_join(tid, NULL);

	rc = dm_destroy_session(sid);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	DMLOG_STOP();
			
	return 0;
}
Esempio n. 6
0
int main(int argc, char **argv)
{

	char *varstr;
	int   rc;
	int   i;
	char *szSessionInfo = "dm_test session info";
	dm_eventset_t events;

	DMOPT_PARSE(argc, argv);
	DMLOG_START();

	DMEV_ZERO(events);
	DMEV_SET(DM_EVENT_MOUNT, events);
	
	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
	if ((rc = dm_init_service(&varstr)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else {
		int fd;

		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
		sprintf(DummyTmp, "%s/%s", mountPt, DUMMY_TMP);

		remove(DummyFile);

		EVENT_DELIVERY_DELAY;
		fd = open(DummyTmp, O_RDWR | O_CREAT);
		if (fd != -1) {
			for (i = 0; i < TMP_FILELEN/DUMMY_STRLEN; i++) {
				if (write(fd, DUMMY_STRING, DUMMY_STRLEN) != DUMMY_STRLEN) {
					rc = -1;
					break;
				}					
			}
		} else {
			rc = -1;
		}
		if (rc != -1) {
			rc = fsync(fd);
		}
		if (rc != -1) {
			rc = close(fd);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_ERR, "creating dummy file failed! (rc = %d, errno = %d)\n", rc, errno);
			dm_destroy_session(sid);
			DM_EXIT();
		}
	}

	DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI memory mapped file synchronous event data tests\n") ;
	
	/*
	 * TEST    : mmap - no regions
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 1)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if ((rc = close(fd)) == -1) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_REGION_WRITE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 2)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_REGION_TRUNCATE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 3)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_TRUNCATE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ, DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_READ
	 *
	 * This variation uncovered XFS BUG #33 (entire file returned instead 
	 * of mapped region only)
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 4)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_READ;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ, DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_READ
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 5)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_READ;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_ABORT;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 0);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 6)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/2;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 7)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/2;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ
	 * EXPECTED: DM_EVENT_READ
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 8)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_READ;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/4;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_READ
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_READ_BASE + 9)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = DUMMY_STRLEN;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - no regions
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 1)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if ((rc = close(fd)) == -1) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_REGION_READ
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 2)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_READ;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_REGION_TRUNCATE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 3)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = 0;
		size_t inlen = DUMMY_STRLEN;
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_INVALID;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_TRUNCATE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE, DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_WRITE
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 4)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_WRITE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE, DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_WRITE
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 5)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_WRITE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_ABORT;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 0);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 6)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(0);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/2;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 7)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/2;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE
	 * EXPECTED: DM_EVENT_WRITE
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 8)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int varStatus;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_WRITE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = TMP_FILELEN/4;
		Regions[0].rg_size = 0;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				if (inoff != offset) {
					DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset);
					varStatus = DMSTAT_FAIL;
				} else if (inlen != length) {
					DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	/*
	 * TEST    : mmap - one region, DM_EVENT_WRITE
	 * EXPECTED: no event
	 */
	if (DMVAR_EXEC(MMAP_WRITE_BASE + 9)) {
		int fd;
		void *hanp;
		size_t hlen;
		off_t inoff = PAGEALIGN(TMP_FILELEN/4);
		size_t inlen = PAGEALIGN(DUMMY_STRLEN);
		dm_boolean_t exactflag;
		int numRegions;
		dm_region_t Regions[1];

		/* Variation set up */
		eventExpected = DM_EVENT_INVALID;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		numRegions = 1;
		Regions[0].rg_offset = 0;
		Regions[0].rg_size = DUMMY_STRLEN;
		Regions[0].rg_flags = DM_REGION_WRITE;

		sprintf(command, "cp %s %s", DummyTmp, DummyFile);
		if ((rc = system(command)) == -1) {
			/* No clean up */
		} else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
			remove(DummyFile);
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
			remove(DummyFile);
		} else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) ||
			   ((rc = close(fd)) == -1)) {
			dm_handle_free(hanp, hlen);
			remove(DummyFile);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1);
			DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
			rc = system(command);
			EVENT_DELIVERY_DELAY;
			DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived));

			/* Variation clean up */
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}
	
	remove(DummyFile);
	remove(DummyTmp);
		
	rc = umount(mountPt);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	pthread_join(tid, NULL);

	rc = dm_destroy_session(sid);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	DMLOG_STOP();
			
	return 0;
}