/* * 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"); } }
/* * Initialize a testing context given the file descriptors provided by the * test setup. */ static void aio_context_init(struct aio_context *ac, int read_fd, int write_fd, int buflen, int seconds, void (*cleanup)(void *), void *cleanup_arg) { ATF_REQUIRE_MSG(buflen <= BUFFER_MAX, "aio_context_init: buffer too large (%d > %d)", buflen, BUFFER_MAX); bzero(ac, sizeof(*ac)); ac->ac_read_fd = read_fd; ac->ac_write_fd = write_fd; ac->ac_buflen = buflen; srandomdev(); ac->ac_seed = random(); aio_fill_buffer(ac->ac_buffer, buflen, ac->ac_seed); ATF_REQUIRE_MSG(aio_test_buffer(ac->ac_buffer, buflen, ac->ac_seed) != 0, "aio_test_buffer: internal error"); ac->ac_seconds = seconds; ac->ac_cleanup = cleanup; ac->ac_cleanup_arg = cleanup_arg; }
/* * Initialize a testing context given the file descriptors provided by the * test setup. */ static void aio_context_init(struct aio_context *ac, const char *test, int read_fd, int write_fd, int buflen, int seconds, void (*cleanup)(void *), void *cleanup_arg) { if (buflen > BUFFER_MAX) errx(-1, "FAIL: %s: aio_context_init: buffer too large", test); bzero(ac, sizeof(*ac)); ac->ac_test = test; ac->ac_read_fd = read_fd; ac->ac_write_fd = write_fd; ac->ac_buflen = buflen; srandomdev(); ac->ac_seed = random(); aio_fill_buffer(ac->ac_buffer, buflen, ac->ac_seed); if (aio_test_buffer(ac->ac_buffer, buflen, ac->ac_seed) == 0) errx(-1, "%s: aio_context_init: aio_test_buffer: internal " "error", test); ac->ac_seconds = seconds; ac->ac_cleanup = cleanup; ac->ac_cleanup_arg = cleanup_arg; }
/* * 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; 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_test, "aio_read_test", ac->ac_seconds); if (aio_read(&aio) < 0) { if (errno == EINTR) { if (aio_notpresent) errno = EOPNOTSUPP; if (aio_timedout) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_read_test: " "aio_read: timed out", ac->ac_test); } } aio_cleanup(ac); errx(-1, "FAIL: %s: aio_read_test: aio_read %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_read_test: " "aio_waitcomplete: timed out", ac->ac_test); } } aio_cleanup(ac); errx(-1, "FAIL: %s: aio_read_test: aio_waitcomplete: %s", ac->ac_test, strerror(errno)); } aio_timeout_stop(ac->ac_test, "aio_read_test"); if (len != ac->ac_buflen) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_read_test: aio_waitcomplete: short " "read (%d)", ac->ac_test, len); } if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0) { aio_cleanup(ac); errx(-1, "FAIL: %s: aio_read_test: buffer mismatch", ac->ac_test); } }