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"); }
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); }