Example #1
0
static int
aio_file_test(void)
{
	char pathname[PATH_MAX];
	struct aio_file_arg arg;
	struct aio_context ac;
	int fd;

	strcpy(pathname, PATH_TEMPLATE);
	fd = mkstemp(pathname);
	if (fd == -1)
		errx(-1, "FAIL: aio_file_test: mkstemp: %s",
		    strerror(errno));

	arg.afa_fd = fd;
	arg.afa_pathname = pathname;

	aio_context_init(&ac, "aio_file_test", fd, fd, FILE_LEN,
	    FILE_TIMEOUT, aio_file_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_file_cleanup(&arg);
	
	fprintf(stderr, "PASS: aio_file_test\n");
}
Example #2
0
static int
aio_md_test(void)
{
	int error, fd, i, mdctl_fd, unit;
	char pathname[PATH_MAX];
	struct aio_md_arg arg;
	struct aio_context ac;
	struct md_ioctl mdio;

	mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
	if (mdctl_fd < 0)
		errx(-1, "FAIL: aio_md_test: open(/dev/%s): %s", MDCTL_NAME,
		    strerror(errno));

	bzero(&mdio, sizeof(mdio));
	mdio.md_version = MDIOVERSION;
	mdio.md_type = MD_MALLOC;
	mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
	mdio.md_mediasize = GLOBAL_MAX;
	mdio.md_sectorsize = 512;

	arg.ama_mdctl_fd = mdctl_fd;
	arg.ama_unit = -1;
	arg.ama_fd = -1;
	if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
		error = errno;
		aio_md_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_md_test: MDIOCATTACH: %s",
		    strerror(errno));
	}

	arg.ama_unit = unit = mdio.md_unit;
	snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
	fd = open(pathname, O_RDWR);
	if (fd < 0) {
		error = errno;
		aio_md_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_md_test: open(%s): %s", pathname,
		    strerror(errno));
	}
	arg.ama_fd = fd;

	aio_context_init(&ac, "aio_md_test", fd, fd, MD_LEN, MD_TIMEOUT,
	    aio_md_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_md_cleanup(&arg);

	fprintf(stderr, "PASS: aio_md_test\n");
}
Example #3
0
ATF_TC_BODY(aio_fifo_test, tc)
{
	int error, read_fd = -1, write_fd = -1;
	struct aio_fifo_arg arg;
	char pathname[PATH_MAX];
	struct aio_context ac;

	ATF_REQUIRE_KERNEL_MODULE("aio");
	ATF_REQUIRE_UNSAFE_AIO();

	/*
	 * In theory, mkstemp() can return a name that is then collided with.
	 * Because this is a regression test, we treat that as a test failure
	 * rather than retrying.
	 */
	strcpy(pathname, PATH_TEMPLATE);
	ATF_REQUIRE_MSG(mkstemp(pathname) != -1,
	    "mkstemp failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(unlink(pathname) == 0,
	    "unlink failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(mkfifo(pathname, 0600) != -1,
	    "mkfifo failed: %s", strerror(errno));
	arg.afa_pathname = pathname;
	arg.afa_read_fd = -1;
	arg.afa_write_fd = -1;

	read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
	if (read_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("read_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_read_fd = read_fd;

	write_fd = open(pathname, O_WRONLY);
	if (write_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("write_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_write_fd = write_fd;

	aio_context_init(&ac, read_fd, write_fd, FIFO_LEN,
	    FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_fifo_cleanup(&arg);
}
Example #4
0
static int
aio_fifo_test(void)
{
	int error, read_fd = -1, write_fd = -1;
	struct aio_fifo_arg arg;
	char pathname[PATH_MAX];
	struct aio_context ac;

	/*
	 * In theory, mktemp() can return a name that is then collided with.
	 * Because this is a regression test, we treat that as a test failure
	 * rather than retrying.
	 */
	strcpy(pathname, PATH_TEMPLATE);
	mktemp(pathname);
	if (mkfifo(pathname, 0600) == -1)
		errx(-1, "FAIL: aio_fifo_test: mkfifo: %s", strerror(errno));
	arg.afa_pathname = pathname;
	arg.afa_read_fd = -1;
	arg.afa_write_fd = -1;

	read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
	if (read_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_fifo_test: read_fd open: %s",
		    strerror(errno));
	}
	arg.afa_read_fd = read_fd;

	write_fd = open(pathname, O_WRONLY);
	if (write_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_fifo_test: write_fd open: %s",
		    strerror(errno));
	}
	arg.afa_write_fd = write_fd;

	aio_context_init(&ac, "aio_fifo_test", read_fd, write_fd, FIFO_LEN,
	    FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_fifo_cleanup(&arg);

	fprintf(stderr, "PASS: aio_fifo_test\n");
}
Example #5
0
ATF_TC_BODY(aio_pipe_test, tc)
{
	struct aio_context ac;
	int pipes[2];

	ATF_REQUIRE_KERNEL_MODULE("aio");

	ATF_REQUIRE_MSG(pipe(pipes) != -1,
	    "pipe failed: %s", strerror(errno));

	aio_context_init(&ac, pipes[0], pipes[1], PIPE_LEN,
	    PIPE_TIMEOUT, aio_pipe_cleanup, pipes);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_pipe_cleanup(pipes);
}
Example #6
0
ATF_TC_BODY(aio_md_test, tc)
{
	int error, fd, mdctl_fd, unit;
	char pathname[PATH_MAX];
	struct aio_md_arg arg;
	struct aio_context ac;
	struct md_ioctl mdio;

	ATF_REQUIRE_KERNEL_MODULE("aio");

	mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
	ATF_REQUIRE_MSG(mdctl_fd != -1,
	    "opening /dev/%s failed: %s", MDCTL_NAME, strerror(errno));

	bzero(&mdio, sizeof(mdio));
	mdio.md_version = MDIOVERSION;
	mdio.md_type = MD_MALLOC;
	mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
	mdio.md_mediasize = GLOBAL_MAX;
	mdio.md_sectorsize = 512;

	arg.ama_mdctl_fd = mdctl_fd;
	arg.ama_unit = -1;
	arg.ama_fd = -1;
	if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
		error = errno;
		aio_md_cleanup(&arg);
		errno = error;
		atf_tc_fail("ioctl MDIOCATTACH failed: %s", strerror(errno));
	}

	arg.ama_unit = unit = mdio.md_unit;
	snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
	fd = open(pathname, O_RDWR);
	ATF_REQUIRE_MSG(fd != -1,
	    "opening %s failed: %s", pathname, strerror(errno));
	arg.ama_fd = fd;

	aio_context_init(&ac, fd, fd, MD_LEN, MD_TIMEOUT,
	    aio_md_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_md_cleanup(&arg);
}
Example #7
0
static int
aio_pipe_test(void)
{	
	struct aio_context ac;
	int pipes[2];

	if (pipe(pipes) < 0)
		errx(-1, "FAIL: aio_pipe_test: pipe: %s", strerror(errno));

	aio_context_init(&ac, "aio_file_test", pipes[0], pipes[1], PIPE_LEN,
	    PIPE_TIMEOUT, aio_pipe_cleanup, pipes);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_pipe_cleanup(pipes);

	fprintf(stderr, "PASS: aio_pipe_test\n");
}
Example #8
0
ATF_TC_BODY(aio_unix_socketpair_test, tc)
{
	struct aio_unix_socketpair_arg arg;
	struct aio_context ac;
	int sockets[2];

	ATF_REQUIRE_KERNEL_MODULE("aio");

	ATF_REQUIRE_MSG(socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) != -1,
	    "socketpair failed: %s", strerror(errno));

	arg.asa_sockets[0] = sockets[0];
	arg.asa_sockets[1] = sockets[1];
	aio_context_init(&ac, sockets[0],
	    sockets[1], UNIX_SOCKETPAIR_LEN, UNIX_SOCKETPAIR_TIMEOUT,
	    aio_unix_socketpair_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_unix_socketpair_cleanup(&arg);
}
Example #9
0
static int
aio_pty_test(void)
{
	struct aio_pty_arg arg;
	struct aio_context ac;
	int read_fd, write_fd;
	struct termios ts;
	int error;

	if (openpty(&read_fd, &write_fd, NULL, NULL, NULL) < 0)
		errx(-1, "FAIL: aio_pty_test: openpty: %s", strerror(errno));

	arg.apa_read_fd = read_fd;
	arg.apa_write_fd = write_fd;

	if (tcgetattr(write_fd, &ts) < 0) {
		error = errno;
		aio_pty_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_pty_test: tcgetattr: %s",
		    strerror(errno));
	}
	cfmakeraw(&ts);
	if (tcsetattr(write_fd, TCSANOW, &ts) < 0) {
		error = errno;
		aio_pty_cleanup(&arg);
		errno = error;
		errx(-1, "FAIL: aio_pty_test: tcsetattr: %s",
		    strerror(errno));
	}

	aio_context_init(&ac, "aio_pty_test", read_fd, write_fd, PTY_LEN,
	    PTY_TIMEOUT, aio_pty_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_pty_cleanup(&arg);

	fprintf(stderr, "PASS: aio_pty_test\n");
}
Example #10
0
ATF_TC_BODY(aio_pty_test, tc)
{
	struct aio_pty_arg arg;
	struct aio_context ac;
	int read_fd, write_fd;
	struct termios ts;
	int error;

	ATF_REQUIRE_KERNEL_MODULE("aio");
	ATF_REQUIRE_UNSAFE_AIO();

	ATF_REQUIRE_MSG(openpty(&read_fd, &write_fd, NULL, NULL, NULL) == 0,
	    "openpty failed: %s", strerror(errno));

	arg.apa_read_fd = read_fd;
	arg.apa_write_fd = write_fd;

	if (tcgetattr(write_fd, &ts) < 0) {
		error = errno;
		aio_pty_cleanup(&arg);
		errno = error;
		atf_tc_fail("tcgetattr failed: %s", strerror(errno));
	}
	cfmakeraw(&ts);
	if (tcsetattr(write_fd, TCSANOW, &ts) < 0) {
		error = errno;
		aio_pty_cleanup(&arg);
		errno = error;
		atf_tc_fail("tcsetattr failed: %s", strerror(errno));
	}
	aio_context_init(&ac, read_fd, write_fd, PTY_LEN,
	    PTY_TIMEOUT, aio_pty_cleanup, &arg);

	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_pty_cleanup(&arg);
}
Example #11
0
static int
aio_unix_socketpair_test(void)
{
	struct aio_unix_socketpair_arg arg;
	struct aio_context ac;
	int sockets[2];

	if (socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) < 0)
		errx(-1, "FAIL: aio_socketpair_test: socketpair: %s",
		    strerror(errno));

	arg.asa_sockets[0] = sockets[0];
	arg.asa_sockets[1] = sockets[1];
	aio_context_init(&ac, "aio_unix_socketpair_test", sockets[0],
	    sockets[1], UNIX_SOCKETPAIR_LEN, UNIX_SOCKETPAIR_TIMEOUT,
	    aio_unix_socketpair_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_unix_socketpair_cleanup(&arg);

	fprintf(stderr, "PASS: aio_unix_socketpair_test\n");
}
Example #12
0
ATF_TC_BODY(aio_file_test, tc)
{
	char pathname[PATH_MAX];
	struct aio_file_arg arg;
	struct aio_context ac;
	int fd;

	ATF_REQUIRE_KERNEL_MODULE("aio");

	strcpy(pathname, PATH_TEMPLATE);
	fd = mkstemp(pathname);
	ATF_REQUIRE_MSG(fd != -1, "mkstemp failed: %s", strerror(errno));

	arg.afa_fd = fd;
	arg.afa_pathname = pathname;

	aio_context_init(&ac, fd, fd, FILE_LEN,
	    FILE_TIMEOUT, aio_file_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_file_cleanup(&arg);
}