git: 5f46ec779fe7 - stable/13 - Add more aio tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 20 Aug 2022 03:07:40 UTC
The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=5f46ec779fe7a8c01f7ce57948bdcef0186dade8 commit 5f46ec779fe7a8c01f7ce57948bdcef0186dade8 Author: Alan Somers <asomers@FreeBSD.org> AuthorDate: 2022-05-31 02:20:55 +0000 Commit: Alan Somers <asomers@FreeBSD.org> CommitDate: 2022-08-20 03:04:33 +0000 Add more aio tests * Add tests for kqueue completion with all file types. * Add a test for kqueue completion with EV_ONESHOT. * Cleanup an unused variable. Differential Revision: https://reviews.freebsd.org/D35359 (cherry picked from commit 57082ce8c43bd555439311984fdcf738ac31dad1) Reap dead code in lio_kqueue_test and aio_kqueue_test Differential Revision: https://reviews.freebsd.org/D35358 (cherry picked from commit f10dd8af4b4fb17173321fac13b3221bf096555a) --- tests/sys/aio/aio_kqueue_test.c | 5 +- tests/sys/aio/aio_test.c | 154 +++++++++++++++++++++++++++++++++++++++- tests/sys/aio/lio_kqueue_test.c | 7 +- 3 files changed, 155 insertions(+), 11 deletions(-) diff --git a/tests/sys/aio/aio_kqueue_test.c b/tests/sys/aio/aio_kqueue_test.c index f3e63376eb1b..ac246310f8bc 100644 --- a/tests/sys/aio/aio_kqueue_test.c +++ b/tests/sys/aio/aio_kqueue_test.c @@ -59,7 +59,7 @@ main (int argc, char *argv[]) { struct aiocb **iocb, *kq_iocb; char *file, pathname[sizeof(PATH_TEMPLATE)+1]; - struct kevent ke, kq_returned; + struct kevent kq_returned; struct timespec ts; char buffer[32768]; int max_queue_per_proc; @@ -156,8 +156,7 @@ main (int argc, char *argv[]) for (;;) { - bzero(&ke, sizeof(ke)); - bzero(&kq_returned, sizeof(ke)); + bzero(&kq_returned, sizeof(kq_returned)); ts.tv_sec = 0; ts.tv_nsec = 1; result = kevent(kq, NULL, 0, diff --git a/tests/sys/aio/aio_test.c b/tests/sys/aio/aio_test.c index d6fb3d2f58d9..0c919da739e9 100644 --- a/tests/sys/aio/aio_test.c +++ b/tests/sys/aio/aio_test.c @@ -40,6 +40,7 @@ */ #include <sys/param.h> +#include <sys/event.h> #include <sys/module.h> #include <sys/resource.h> #include <sys/socket.h> @@ -91,7 +92,6 @@ struct aio_context { static sem_t completions; - /* * Fill a buffer given a seed that can be fed into srandom() to initialize * the PRNG in a repeatable manner. @@ -252,6 +252,47 @@ waitcomplete(struct aiocb *aio) return (ret); } +/* + * Setup an iocb for kqueue notification. This isn't thread + * safe, but it's ok because ATF runs every test case in a separate process. + */ +static struct sigevent* +setup_kqueue(void) +{ + static struct sigevent sev; + static int kq; + + kq = kqueue(); + ATF_REQUIRE(kq >= 0); + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify_kqueue = kq; + sev.sigev_value.sival_ptr = (void*)0xdeadbeef; + sev.sigev_notify = SIGEV_KEVENT; + + return (&sev); +} + +static ssize_t +poll_kqueue(struct aiocb *aio) +{ + int kq, nevents; + struct kevent events[1]; + + kq = aio->aio_sigevent.sigev_notify_kqueue; + + nevents = kevent(kq, NULL, 0, events, 1, NULL); + ATF_CHECK_EQ(1, nevents); + ATF_CHECK_EQ(events[0].ident, (uintptr_t) aio); + ATF_CHECK_EQ(events[0].filter, EVFILT_AIO); + ATF_CHECK_EQ(events[0].flags, EV_EOF); + ATF_CHECK_EQ(events[0].fflags, 0); + ATF_CHECK_EQ(events[0].data, 0); + ATF_CHECK_EQ((uintptr_t)events[0].udata, 0xdeadbeef); + + return (aio_return(aio)); +} + /* * Perform a simple write test of our initialized data buffer to the provided * file descriptor. @@ -428,6 +469,12 @@ aio_file_test(completion comp, struct sigevent *sev, bool vectored) close(fd); } +ATF_TC_WITHOUT_HEAD(file_kq); +ATF_TC_BODY(file_kq, tc) +{ + aio_file_test(poll_kqueue, setup_kqueue(), false); +} + ATF_TC_WITHOUT_HEAD(file_poll); ATF_TC_BODY(file_poll, tc) { @@ -497,6 +544,12 @@ aio_fifo_test(completion comp, struct sigevent *sev) close(write_fd); } +ATF_TC_WITHOUT_HEAD(fifo_kq); +ATF_TC_BODY(fifo_kq, tc) +{ + aio_fifo_test(poll_kqueue, setup_kqueue()); +} + ATF_TC_WITHOUT_HEAD(fifo_poll); ATF_TC_BODY(fifo_poll, tc) { @@ -559,6 +612,12 @@ aio_unix_socketpair_test(completion comp, struct sigevent *sev, bool vectored) close(sockets[1]); } +ATF_TC_WITHOUT_HEAD(socket_kq); +ATF_TC_BODY(socket_kq, tc) +{ + aio_unix_socketpair_test(poll_kqueue, setup_kqueue(), false); +} + ATF_TC_WITHOUT_HEAD(socket_poll); ATF_TC_BODY(socket_poll, tc) { @@ -630,6 +689,12 @@ aio_pty_test(completion comp, struct sigevent *sev) close(write_fd); } +ATF_TC_WITHOUT_HEAD(pty_kq); +ATF_TC_BODY(pty_kq, tc) +{ + aio_pty_test(poll_kqueue, setup_kqueue()); +} + ATF_TC_WITHOUT_HEAD(pty_poll); ATF_TC_BODY(pty_poll, tc) { @@ -681,6 +746,12 @@ aio_pipe_test(completion comp, struct sigevent *sev) close(pipes[1]); } +ATF_TC_WITHOUT_HEAD(pipe_kq); +ATF_TC_BODY(pipe_kq, tc) +{ + aio_pipe_test(poll_kqueue, setup_kqueue()); +} + ATF_TC_WITHOUT_HEAD(pipe_poll); ATF_TC_BODY(pipe_poll, tc) { @@ -806,6 +877,21 @@ aio_md_test(completion comp, struct sigevent *sev, bool vectored) close(fd); } +ATF_TC_WITH_CLEANUP(md_kq); +ATF_TC_HEAD(md_kq, tc) +{ + + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(md_kq, tc) +{ + aio_md_test(poll_kqueue, setup_kqueue(), false); +} +ATF_TC_CLEANUP(md_kq, tc) +{ + aio_md_cleanup(); +} + ATF_TC_WITH_CLEANUP(md_poll); ATF_TC_HEAD(md_poll, tc) { @@ -1384,7 +1470,7 @@ ATF_TC_BODY(aio_writev_dos_iov_len, tc) const struct aiocb *const iocbs[] = {&aio}; const char *wbuf = "Hello, world!"; struct iovec iov[1]; - ssize_t len, r; + ssize_t r; int fd; ATF_REQUIRE_KERNEL_MODULE("aio"); @@ -1393,7 +1479,6 @@ ATF_TC_BODY(aio_writev_dos_iov_len, tc) fd = open("testfile", O_RDWR | O_CREAT, 0600); ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno)); - len = strlen(wbuf); iov[0].iov_base = __DECONST(void*, wbuf); iov[0].iov_len = 1 << 30; bzero(&aio, sizeof(aio)); @@ -1539,6 +1624,59 @@ ATF_TC_BODY(aio_writev_empty_file_signal, tc) close(fd); } +/* + * Use an aiocb with kqueue and EV_ONESHOT. kqueue should deliver the event + * only once, even if the user doesn't promptly call aio_return. + */ +ATF_TC_WITHOUT_HEAD(ev_oneshot); +ATF_TC_BODY(ev_oneshot, tc) +{ + int fd, kq, nevents; + struct aiocb iocb; + struct kevent events[1]; + struct timespec timeout; + + ATF_REQUIRE_KERNEL_MODULE("aio"); + + kq = kqueue(); + ATF_REQUIRE(kq >= 0); + + fd = open(FILE_PATHNAME, O_RDWR | O_CREAT, 0600); + ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno)); + + memset(&iocb, 0, sizeof(iocb)); + iocb.aio_fildes = fd; + iocb.aio_sigevent.sigev_notify_kqueue = kq; + iocb.aio_sigevent.sigev_value.sival_ptr = (void*)0xdeadbeef; + iocb.aio_sigevent.sigev_notify_kevent_flags = EV_ONESHOT; + iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; + + ATF_CHECK_EQ(0, aio_fsync(O_SYNC, &iocb)); + + nevents = kevent(kq, NULL, 0, events, 1, NULL); + ATF_CHECK_EQ(1, nevents); + ATF_CHECK_EQ(events[0].ident, (uintptr_t) &iocb); + ATF_CHECK_EQ(events[0].filter, EVFILT_AIO); + ATF_CHECK_EQ(events[0].flags, EV_EOF | EV_ONESHOT); + ATF_CHECK_EQ(events[0].fflags, 0); + ATF_CHECK_EQ(events[0].data, 0); + ATF_CHECK_EQ((uintptr_t)events[0].udata, 0xdeadbeef); + + /* + * Even though we haven't called aio_return, kevent will not return the + * event again due to EV_ONESHOT. + */ + timeout.tv_sec = 0; + timeout.tv_nsec = 100000000; + nevents = kevent(kq, NULL, 0, events, 1, &timeout); + ATF_CHECK_EQ(0, nevents); + + ATF_CHECK_EQ(0, aio_return(&iocb)); + close(fd); + close(kq); +} + + // aio_writev and aio_readv should still work even if the iovcnt is greater // than the number of buffered AIO operations permitted per process. ATF_TC_WITH_CLEANUP(vectored_big_iovcnt); @@ -1770,36 +1908,45 @@ ATF_TC_CLEANUP(vectored_zvol_poll, tc) ATF_TP_ADD_TCS(tp) { + /* Test every file type with every completion method */ + ATF_TP_ADD_TC(tp, file_kq); ATF_TP_ADD_TC(tp, file_poll); ATF_TP_ADD_TC(tp, file_signal); ATF_TP_ADD_TC(tp, file_suspend); ATF_TP_ADD_TC(tp, file_thread); ATF_TP_ADD_TC(tp, file_waitcomplete); + ATF_TP_ADD_TC(tp, fifo_kq); ATF_TP_ADD_TC(tp, fifo_poll); ATF_TP_ADD_TC(tp, fifo_signal); ATF_TP_ADD_TC(tp, fifo_suspend); ATF_TP_ADD_TC(tp, fifo_thread); ATF_TP_ADD_TC(tp, fifo_waitcomplete); + ATF_TP_ADD_TC(tp, socket_kq); ATF_TP_ADD_TC(tp, socket_poll); ATF_TP_ADD_TC(tp, socket_signal); ATF_TP_ADD_TC(tp, socket_suspend); ATF_TP_ADD_TC(tp, socket_thread); ATF_TP_ADD_TC(tp, socket_waitcomplete); + ATF_TP_ADD_TC(tp, pty_kq); ATF_TP_ADD_TC(tp, pty_poll); ATF_TP_ADD_TC(tp, pty_signal); ATF_TP_ADD_TC(tp, pty_suspend); ATF_TP_ADD_TC(tp, pty_thread); ATF_TP_ADD_TC(tp, pty_waitcomplete); + ATF_TP_ADD_TC(tp, pipe_kq); ATF_TP_ADD_TC(tp, pipe_poll); ATF_TP_ADD_TC(tp, pipe_signal); ATF_TP_ADD_TC(tp, pipe_suspend); ATF_TP_ADD_TC(tp, pipe_thread); ATF_TP_ADD_TC(tp, pipe_waitcomplete); + ATF_TP_ADD_TC(tp, md_kq); ATF_TP_ADD_TC(tp, md_poll); ATF_TP_ADD_TC(tp, md_signal); ATF_TP_ADD_TC(tp, md_suspend); ATF_TP_ADD_TC(tp, md_thread); ATF_TP_ADD_TC(tp, md_waitcomplete); + + /* Various special cases */ ATF_TP_ADD_TC(tp, aio_fsync_errors); ATF_TP_ADD_TC(tp, aio_fsync_sync_test); ATF_TP_ADD_TC(tp, aio_fsync_dsync_test); @@ -1813,6 +1960,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, aio_writev_efault); ATF_TP_ADD_TC(tp, aio_writev_empty_file_poll); ATF_TP_ADD_TC(tp, aio_writev_empty_file_signal); + ATF_TP_ADD_TC(tp, ev_oneshot); ATF_TP_ADD_TC(tp, vectored_big_iovcnt); ATF_TP_ADD_TC(tp, vectored_file_poll); ATF_TP_ADD_TC(tp, vectored_md_poll); diff --git a/tests/sys/aio/lio_kqueue_test.c b/tests/sys/aio/lio_kqueue_test.c index 3226573721c6..b85e3630b9b8 100644 --- a/tests/sys/aio/lio_kqueue_test.c +++ b/tests/sys/aio/lio_kqueue_test.c @@ -63,7 +63,7 @@ main(int argc, char *argv[]) size_t max_queue_per_proc_size; char buffer[32768]; int kq; - struct kevent ke, kq_returned; + struct kevent kq_returned; struct timespec ts; struct sigevent sig; time_t time1, time2; @@ -153,15 +153,12 @@ main(int argc, char *argv[]) } for (;;) { - bzero(&ke, sizeof(ke)); - bzero(&kq_returned, sizeof(ke)); + bzero(&kq_returned, sizeof(kq_returned)); ts.tv_sec = 0; ts.tv_nsec = 1; #ifdef DEBUG printf("FOO lio %d -> %p\n", j, lio[j]); #endif - EV_SET(&ke, (uintptr_t)lio[j], - EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]); result = kevent(kq, NULL, 0, &kq_returned, 1, &ts); error = errno;