/* * Perform a simple write test of our initialized data buffer to the provided * file descriptor. */ static void aio_write_test(struct aio_context *ac) { struct aiocb aio, *aiop; ssize_t len; int error; bzero(&aio, sizeof(aio)); aio.aio_buf = ac->ac_buffer; aio.aio_nbytes = ac->ac_buflen; aio.aio_fildes = ac->ac_write_fd; aio.aio_offset = 0; aio_timeout_start(ac->ac_test, "aio_write_test", ac->ac_seconds); if (aio_write(&aio) < 0) { if (errno == EINTR) { if (aio_notpresent) errno = EOPNOTSUPP; if (aio_timedout) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_write_test: " "aio_write: timed out", ac->ac_test); } } aio_cleanup(ac); errx(-1, "FAIL: %s: aio_write_test: aio_write: %s", ac->ac_test, strerror(errno)); } len = aio_waitcomplete(&aiop, NULL); if (len < 0) { if (errno == EINTR) { if (aio_notpresent) errno = EOPNOTSUPP; if (aio_timedout) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_write_test: " "aio_waitcomplete: timed out", ac->ac_test); } } aio_cleanup(ac); errx(-1, "FAIL: %s: aio_write_test: aio_waitcomplete: %s", ac->ac_test, strerror(errno)); } aio_timeout_stop(ac->ac_test, "aio_write_test"); if (len != ac->ac_buflen) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_write_test: aio_waitcomplete: short " "write (%d)", ac->ac_test, len); } }
/* * Perform a simple read test of our initialized data buffer from the * provided file descriptor. */ static void aio_read_test(struct aio_context *ac) { struct aiocb aio, *aiop; ssize_t len; ATF_REQUIRE_KERNEL_MODULE("aio"); bzero(ac->ac_buffer, ac->ac_buflen); bzero(&aio, sizeof(aio)); aio.aio_buf = ac->ac_buffer; aio.aio_nbytes = ac->ac_buflen; aio.aio_fildes = ac->ac_read_fd; aio.aio_offset = 0; aio_timeout_start(ac->ac_seconds); if (aio_read(&aio) < 0) { if (errno == EINTR) { if (aio_timedout) { aio_cleanup(ac); atf_tc_fail("aio_write timed out"); } } aio_cleanup(ac); atf_tc_fail("aio_read failed: %s", strerror(errno)); } len = aio_waitcomplete(&aiop, NULL); if (len < 0) { if (errno == EINTR) { if (aio_timedout) { aio_cleanup(ac); atf_tc_fail("aio_waitcomplete timed out"); } } aio_cleanup(ac); atf_tc_fail("aio_waitcomplete failed: %s", strerror(errno)); } aio_timeout_stop(); if (len != ac->ac_buflen) { aio_cleanup(ac); atf_tc_fail("aio_waitcomplete short read (%jd)", (intmax_t)len); } if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0) { aio_cleanup(ac); atf_tc_fail("buffer mismatched"); } }