Exemple #1
0
/*===========================================================================*
 *				    main				     *
 *===========================================================================*/
int main(int argc, char **argv)
{
	endpoint_t ep_self, ep_requestor, ep_child;
	cp_grant_id_t gid;
	int i, r, pid;
	char *buf;
	int status;

	/* SEF local startup. */
	env_setargs(argc, argv);
	sef_local_startup();

	/* Prepare work. */
	buf = (char*) CLICK_CEIL(buf_buf);
	fid_send = open(FIFO_GRANTOR, O_WRONLY);
	fid_get = open(FIFO_REQUESTOR, O_RDONLY);
	if(fid_get < 0 || fid_send < 0) {
		printf("GRANTOR: can't open fifo files.\n");
		return 1;
	}

	/* Get the requestor's endpoint. */
	read(fid_get, &ep_requestor, sizeof(ep_requestor));
	dprint("GRANTOR: getting requestor's endpoint: %d\n", ep_requestor);

	/* Grant. */
	gid = cpf_grant_direct(ep_requestor, (long)buf, BUF_SIZE,
		CPF_READ | CPF_WRITE | CPF_MAP);
	ep_self = getprocnr();
	dprint("GRANTOR: sending my endpoint %d and gid %d\n", ep_self, gid);
	write(fid_send, &ep_self, sizeof(ep_self));
	write(fid_send, &gid, sizeof(gid));

	/* Test safemap. */
	buf[0] = 0;
	FIFO_NOTIFY(fid_send);
	FIFO_WAIT(fid_get);

	return 0;
}
Exemple #2
0
/*===========================================================================*
 *				    main				     *
 *===========================================================================*/
int main(int argc, char **argv)
{
	endpoint_t ep_self, ep_child;
	size_t size = BUF_SIZE;
	int i, r, pid;
	int status;
	u64_t start, end, diff;
	double micros;
	char nr_pages_str[10], is_map_str[2], is_write_str[2];
	int nr_pages, is_map, is_write;

	/* SEF local startup. */
	env_setargs(argc, argv);
	sef_local_startup();

	/* Parse the command line. */
	r = env_get_param("pages", nr_pages_str, sizeof(nr_pages_str));
	errno = 0;
	nr_pages = atoi(nr_pages_str);
	if (r != OK || errno || nr_pages <=0) {
		exit_usage();
	}
	if(nr_pages > TEST_PAGE_NUM) {
		printf("REQUESTOR: too many pages. Max allowed: %d\n",
			TEST_PAGE_NUM);
		exit_usage();
	}
	r = env_get_param("map", is_map_str, sizeof(is_map_str));
	errno = 0;
	is_map = atoi(is_map_str);
	if (r != OK || errno || (is_map!=0 && is_map!=1)) {
		exit_usage();
	}
	r = env_get_param("write", is_write_str, sizeof(is_write_str));
	errno = 0;
	is_write = atoi(is_write_str);
	if (r != OK || errno || (is_write!=0 && is_write!=1)) {
		exit_usage();
	}
	printf("REQUESTOR: Running tests with pages=%d map=%d write=%d...\n",
		nr_pages, is_map, is_write);

	/* Prepare work. */
	buf = (char*) CLICK_CEIL(buf_buf);
	fid_get = open(FIFO_GRANTOR, O_RDONLY);
	fid_send = open(FIFO_REQUESTOR, O_WRONLY);
	if(fid_get < 0 || fid_send < 0) {
		printf("REQUESTOR: can't open fifo files.\n");
		return 1;
	}

	/* Send the endpoint to the granter, in order to let him to
	 * create the grant.
	 */
	ep_self = getprocnr();
	write(fid_send, &ep_self, sizeof(ep_self));
	dprint("REQUESTOR: sending my endpoint: %d\n", ep_self);

	/* Get the granter's endpoint and gid. */
	read(fid_get, &ep_granter, sizeof(ep_granter));
	read(fid_get, &gid, sizeof(gid));
	dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n",
		ep_granter, gid);

	FIFO_WAIT(fid_get);
	diff = make64(0, 0);

	if(is_map) {
		/* Test safemap. */
		for(i=0;i<NR_TEST_ITERATIONS;i++) {
			read_tsc_64(&start);
			r = sys_safemap(ep_granter, gid, 0, (long)buf,
				nr_pages*CLICK_SIZE, D, 1);
			if(r != OK) {
				printf("REQUESTOR: safemap error: %d\n", r);
				return 1;
			}
			read_write_buff(buf, nr_pages*CLICK_SIZE, is_write);
			read_tsc_64(&end);
			diff = add64(diff, (sub64(end, start)));
			r = sys_safeunmap(D, (long)buf);
			if(r != OK) {
				printf("REQUESTOR: safeunmap error: %d\n", r);
				return 1;
			}
		}
		micros = ((double)tsc_64_to_micros(diff))
			/ (NR_TEST_ITERATIONS*nr_pages);
		REPORT_TEST("REQUESTOR", "SAFEMAP", micros);
	}
	else {
		/* Test safecopy. */
		for(i=0;i<NR_TEST_ITERATIONS;i++) {
			read_tsc_64(&start);
			r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf,
				nr_pages*CLICK_SIZE, D);
			if(r != OK) {
				printf("REQUESTOR: safecopy error: %d\n", r);
				return 1;
			}
			read_write_buff(buf, nr_pages*CLICK_SIZE, is_write);
			read_tsc_64(&end);
			diff = add64(diff, (sub64(end, start)));
		}
		micros = ((double)tsc_64_to_micros(diff))
			/ (NR_TEST_ITERATIONS*nr_pages);
		REPORT_TEST("REQUESTOR", "SAFECOPY", micros);
	}

	FIFO_NOTIFY(fid_send);

	return 0;
}
Exemple #3
0
/*===========================================================================*
 *				    main				     *
 *===========================================================================*/
int main(int argc, char **argv)
{
	endpoint_t ep_self, ep_child;
	size_t size = BUF_SIZE;
	int i, r, pid;
	int status;

	/* SEF local startup. */
	env_setargs(argc, argv);
	sef_local_startup();

	/* Prepare work. */
	buf = (char*) CLICK_CEIL(buf_buf);
	fid_get = open(FIFO_GRANTOR, O_RDONLY);
	fid_send = open(FIFO_REQUESTOR, O_WRONLY);
	if(fid_get < 0 || fid_send < 0) {
		printf("REQUESTOR: can't open fifo files.\n");
		return 1;
	}

	/* Send the endpoint to the granter, in order to let him to
	 * create the grant.
	 */
	ep_self = getprocnr();
	write(fid_send, &ep_self, sizeof(ep_self));
	dprint("REQUESTOR: sending my endpoint: %d\n", ep_self);

	/* Get the granter's endpoint and gid. */
	read(fid_get, &ep_granter, sizeof(ep_granter));
	read(fid_get, &gid, sizeof(gid));
	dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n",
		ep_granter, gid);

	/* Test MAP. */
	FIFO_WAIT(fid_get);
	r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safemap: %d\n", r);
		return 1;
	}
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "MAP");
	buf[0] = BUF_START_REQUESTOR;
	r = sys_safeunmap((long)buf);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safeunmap: %d\n", r);
		return 1;
	}
	FIFO_NOTIFY(fid_send);

	/* Test UNMAP. */
	FIFO_WAIT(fid_get);
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_REQUESTOR, "UNMAP");
	r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1);
	if(r != 0) {
		printf("REQUESTOR: error in sys_safemap: %d\n", r);
		return 1;
	}
	FIFO_NOTIFY(fid_send);

	/* Test REVOKE. */
	FIFO_WAIT(fid_get);
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "REVOKE");
	buf[0] = BUF_START_REQUESTOR;
	FIFO_NOTIFY(fid_send);

	/* Test SMAP_COW. */
	FIFO_WAIT(fid_get);
	r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safemap: %d\n", r);
		return 1;
	}
	buf[0] = BUF_START_REQUESTOR;
	pid = fork();
	if(pid < 0) {
		printf("REQUESTOR: error in fork\n");
		return 1;
	}
	if(pid == 0) {
		exit(buf[0] != BUF_START_REQUESTOR);
	}
	FIFO_NOTIFY(fid_send);
	FIFO_WAIT(fid_get);
	ep_child = getnprocnr(pid);
	if ((r = sys_privctl(ep_child, SYS_PRIV_SET_USER, NULL)) != OK) {
		printf("REQUESTOR: unable to set privileges: %d\n", r);
		return 1;
	}
	if ((r = sys_privctl(ep_child, SYS_PRIV_ALLOW, NULL)) != OK) {
		printf("REQUESTOR: child process can't run: %d\n", r);
		return 1;
	}
	wait(&status);
	FIFO_NOTIFY(fid_send);
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR, "SMAP_COW");
	CHECK_TEST("REQUESTOR", 1, WIFEXITED(status)
		&& (WEXITSTATUS(status) == 0), "SMAP_COW child");

	/* Test COW_SMAP. */
	FIFO_WAIT(fid_get);
	buf[0] = BUF_START_REQUESTOR;
	r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safemap: %d\n", r);
		return 1;
	}
	FIFO_NOTIFY(fid_send);
	FIFO_WAIT(fid_get);
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_GRANTOR+1, "COW_SMAP");

	/* Test COW_SMAP2 (with COW safecopy). */
	FIFO_WAIT(fid_get);
	buf[0] = BUF_START_REQUESTOR;
	r = sys_safecopyto(ep_granter, gid, 0, (long)buf, size);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safecopyto: %d\n", r);
		return 1;
	}
	r = sys_safemap(ep_granter, gid, 0, (long)buf, size, 1);
	if(r != OK) {
		printf("REQUESTOR: error in sys_safemap: %d\n", r);
		return 1;
	}
	FIFO_NOTIFY(fid_send);
	CHECK_TEST("REQUESTOR", buf[0], BUF_START_REQUESTOR, "COW_SMAP2");

	return 0;
}