From nobody Sun Jul 24 15:29:07 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LrRsv4KQ3z4WqJC; Sun, 24 Jul 2022 15:29:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LrRsv3q7Kz45SC; Sun, 24 Jul 2022 15:29:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658676547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xSnbujw4XHQ5/doWMeWjlu6FZLqFbaGAu+yT31KwZbA=; b=gu6aAfikri7qjrKRJlFWm5G2ZVeiFPLI9TVoeR7QHQZ+4bFRaRcfvt7IzMM5XDA+If4T+V 6sTY0as4nG8n0FJ8IsA+BR1bzTCm1qPPiq1UqFwr+p0iYu7Ych/C2jEPi025wee4p/CN8b wPw0W34NLEWBEcPmK77WP1hVr17/9PhYcFcjjgLWY2d34GwYqQ3Bb7D9zqMD+kSLWUzE0q X54oUzWau5HiWObNtb5y/IXc1CDzCRBF69VuldGd983iGxPV07ahEFPg6w6QFcEUvoEKy6 fHwdZ8BzW7IjAPWz0cEWlrlikNYvjv72im0+xt9UinxL5uZBh6lwJOQeZk5FeQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LrRsv2krKzNPB; Sun, 24 Jul 2022 15:29:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26OFT7ZW093457; Sun, 24 Jul 2022 15:29:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26OFT7ID093456; Sun, 24 Jul 2022 15:29:07 GMT (envelope-from git) Date: Sun, 24 Jul 2022 15:29:07 GMT Message-Id: <202207241529.26OFT7ID093456@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 57082ce8c43b - main - Add more aio tests List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 57082ce8c43bd555439311984fdcf738ac31dad1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658676547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xSnbujw4XHQ5/doWMeWjlu6FZLqFbaGAu+yT31KwZbA=; b=hsw+1mUUnyG3E19d6Y/uYmOAucdOlJsRz7WO26lC75zOLeo5J3R5LpavvTc52Z0mKLmsQw fxCy4vUTpU5z32EzERohul5JTCtx2S7YqLt2vL4WkeTdIri5QzaqaAFYvy6wO7FM+A6SrV p3D93913pFPzWYM/MhnxCRFsmNjDigRDei5bxNEa8XLSKIv7PkncYas7m7weIDr+wHoJKm 1cageGsrIYmB/Bmq07BAsIdHaCV3WMemq0tC0zWSK7Ng1vS7vQAlktR6lc4MVoKx5iiKKh JB74S53gGqDKBuNAMqTvPivarojqnZ/Wk5Z/OmzTxifHuTNT4kHt2GQMnDCt+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658676547; a=rsa-sha256; cv=none; b=iiP14ZDupZIwrhhOjR6PND6mFPcu2PwudUAvtWUQaIg5GCQlnAs60xm+/kCF1Wwy78KiOd gNYivUnAWVsGt8YJOl0AX3+8D0BIsUMHeZOPuIzWwfJClT6FNdroej5A1VPi+9YLQvEdly 7YjRCkaqjPcEDvmJs3hv4/LxDdcFd2FbjJms2nTjRVbYwpIz+XIyD343Ecc2nGCTxMGDmO p7sf5IWQ0N/8ZOpQx/fg0MyKiI92Ln2hZHRzyGN56j3HSXHoI5B85cwMV4RdmzCt2744iW eAnDxEj7/z4gF0VImzRJqban4D+c6C/IKgf9uDJMSuEj9XPcPgnP0RkVPSTs/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=57082ce8c43bd555439311984fdcf738ac31dad1 commit 57082ce8c43bd555439311984fdcf738ac31dad1 Author: Alan Somers AuthorDate: 2022-05-31 02:20:55 +0000 Commit: Alan Somers CommitDate: 2022-07-24 15:27:19 +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. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35359 --- tests/sys/aio/aio_test.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 3 deletions(-) diff --git a/tests/sys/aio/aio_test.c b/tests/sys/aio/aio_test.c index 44bf85a10241..5d244af7c5ac 100644 --- a/tests/sys/aio/aio_test.c +++ b/tests/sys/aio/aio_test.c @@ -40,6 +40,7 @@ */ #include +#include #include #include #include @@ -93,7 +94,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. @@ -254,6 +254,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. @@ -430,6 +471,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) { @@ -499,6 +546,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) { @@ -561,6 +614,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) { @@ -632,6 +691,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) { @@ -683,6 +748,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) { @@ -808,6 +879,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) { @@ -1525,7 +1611,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"); @@ -1534,7 +1620,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)); @@ -1680,6 +1765,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); @@ -1917,36 +2055,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); @@ -1963,6 +2110,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);