From owner-svn-src-head@freebsd.org Wed May 20 17:48:19 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9C4CD2F002D; Wed, 20 May 2020 17:48:19 +0000 (UTC) (envelope-from markj@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49S0bR3lwTz4W5d; Wed, 20 May 2020 17:48:19 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7C3B12000F; Wed, 20 May 2020 17:48:19 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04KHmJ6U059491; Wed, 20 May 2020 17:48:19 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04KHmJ8d059489; Wed, 20 May 2020 17:48:19 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202005201748.04KHmJ8d059489@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Wed, 20 May 2020 17:48:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361286 - in head/tests/sys: fifo kern/pipe X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in head/tests/sys: fifo kern/pipe X-SVN-Commit-Revision: 361286 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 May 2020 17:48:19 -0000 Author: markj Date: Wed May 20 17:48:18 2020 New Revision: 361286 URL: https://svnweb.freebsd.org/changeset/base/361286 Log: Avoid hard-coding pipe buffer sizes in the pipe and fifo kqueue tests. Fix some style issues in the modified tests while here. Reported by: Jenkins via lwhsu MFC after: 1 week Sponsored by: The FreeBSD Foundation Modified: head/tests/sys/fifo/fifo_kqueue.c head/tests/sys/kern/pipe/pipe_kqueue_test.c Modified: head/tests/sys/fifo/fifo_kqueue.c ============================================================================== --- head/tests/sys/fifo/fifo_kqueue.c Wed May 20 17:33:11 2020 (r361285) +++ head/tests/sys/fifo/fifo_kqueue.c Wed May 20 17:48:18 2020 (r361286) @@ -219,10 +219,14 @@ ATF_TC_BODY(fifo_kqueue__connecting_reader, tc) ATF_REQUIRE(close(p[1]) == 0); } +/* Check that EVFILT_READ behaves sensibly on a FIFO reader. */ ATF_TC_WITHOUT_HEAD(fifo_kqueue__reads); ATF_TC_BODY(fifo_kqueue__reads, tc) { - int p[2] = { -1, -1 }; + struct kevent kev[32]; + ssize_t bytes, i, n; + int kq, p[2]; + char c; ATF_REQUIRE(mkfifo("testfifo", 0600) == 0); @@ -231,39 +235,38 @@ ATF_TC_BODY(fifo_kqueue__reads, tc) ATF_REQUIRE((p[1] = open("testfifo", O_WRONLY | O_CLOEXEC | O_NONBLOCK)) >= 0); - /* Check that EVFILT_READ behaves sensibly on a FIFO reader. */ - - char c = 0; - ssize_t r; - while ((r = write(p[1], &c, 1)) == 1) { - } - ATF_REQUIRE(r < 0); + bytes = 0; + c = 0; + while ((n = write(p[1], &c, 1)) == 1) + bytes++; + ATF_REQUIRE(n < 0); ATF_REQUIRE(errno == EAGAIN || errno == EWOULDBLOCK); + ATF_REQUIRE(bytes > 1); - for (int i = 0; i < PIPE_BUF + 1; ++i) { + for (i = 0; i < bytes / 2; i++) ATF_REQUIRE(read(p[0], &c, 1) == 1); - } + bytes -= i; - int kq = kqueue(); + kq = kqueue(); ATF_REQUIRE(kq >= 0); - struct kevent kev[32]; EV_SET(&kev[0], p[0], EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, 0); ATF_REQUIRE(kevent(kq, kev, 1, NULL, 0, NULL) == 0); ATF_REQUIRE(kevent(kq, NULL, 0, kev, nitems(kev), - &(struct timespec) { 0, 0 }) == 1); + &(struct timespec){ 0, 0 }) == 1); ATF_REQUIRE(kev[0].ident == (uintptr_t)p[0]); ATF_REQUIRE(kev[0].filter == EVFILT_READ); ATF_REQUIRE(kev[0].flags == EV_CLEAR); ATF_REQUIRE(kev[0].fflags == 0); - ATF_REQUIRE(kev[0].data == 65023); + ATF_REQUIRE(kev[0].data == bytes); ATF_REQUIRE(kev[0].udata == 0); - while ((r = read(p[0], &c, 1)) == 1) { - } - ATF_REQUIRE(r < 0); + while (bytes-- > 0) + ATF_REQUIRE(read(p[0], &c, 1) == 1); + n = read(p[0], &c, 1); + ATF_REQUIRE(n < 0); ATF_REQUIRE(errno == EAGAIN || errno == EWOULDBLOCK); ATF_REQUIRE(kevent(kq, NULL, 0, kev, nitems(kev), Modified: head/tests/sys/kern/pipe/pipe_kqueue_test.c ============================================================================== --- head/tests/sys/kern/pipe/pipe_kqueue_test.c Wed May 20 17:33:11 2020 (r361285) +++ head/tests/sys/kern/pipe/pipe_kqueue_test.c Wed May 20 17:48:18 2020 (r361286) @@ -243,28 +243,30 @@ ATF_TC_BODY(pipe_kqueue__closed_read_end_register_befo ATF_TC_WITHOUT_HEAD(pipe_kqueue__closed_write_end); ATF_TC_BODY(pipe_kqueue__closed_write_end, tc) { - int p[2] = { -1, -1 }; + struct kevent kev[32]; + ssize_t bytes, n; + int kq, p[2]; + char c; ATF_REQUIRE(pipe2(p, O_CLOEXEC | O_NONBLOCK) == 0); ATF_REQUIRE(p[0] >= 0); ATF_REQUIRE(p[1] >= 0); - char c = 0; - ssize_t r; - while ((r = write(p[1], &c, 1)) == 1) { - } - ATF_REQUIRE(r < 0); + bytes = 0; + c = 0; + while ((n = write(p[1], &c, 1)) == 1) + bytes++; + ATF_REQUIRE(n < 0); ATF_REQUIRE(errno == EAGAIN || errno == EWOULDBLOCK); ATF_REQUIRE(close(p[1]) == 0); - int kq = kqueue(); + kq = kqueue(); ATF_REQUIRE(kq >= 0); - struct kevent kev[32]; - EV_SET(&kev[0], p[0], EVFILT_READ, EV_ADD | EV_CLEAR | EV_RECEIPT, /**/ + EV_SET(&kev[0], p[0], EVFILT_READ, EV_ADD | EV_CLEAR | EV_RECEIPT, 0, 0, 0); - EV_SET(&kev[1], p[0], EVFILT_WRITE, EV_ADD | EV_CLEAR | EV_RECEIPT, /**/ + EV_SET(&kev[1], p[0], EVFILT_WRITE, EV_ADD | EV_CLEAR | EV_RECEIPT, 0, 0, 0); /* @@ -284,7 +286,7 @@ ATF_TC_BODY(pipe_kqueue__closed_write_end, tc) ATF_REQUIRE(kev[0].filter == EVFILT_READ); ATF_REQUIRE(kev[0].flags == (EV_EOF | EV_CLEAR | EV_RECEIPT)); ATF_REQUIRE(kev[0].fflags == 0); - ATF_REQUIRE(kev[0].data == 65536); + ATF_REQUIRE(kev[0].data == bytes); ATF_REQUIRE(kev[0].udata == 0); ATF_REQUIRE(close(kq) == 0); @@ -294,19 +296,21 @@ ATF_TC_BODY(pipe_kqueue__closed_write_end, tc) ATF_TC_WITHOUT_HEAD(pipe_kqueue__closed_write_end_register_before_close); ATF_TC_BODY(pipe_kqueue__closed_write_end_register_before_close, tc) { - int p[2] = { -1, -1 }; + struct kevent kev[32]; + ssize_t bytes, n; + int kq, p[2]; + char c; ATF_REQUIRE(pipe2(p, O_CLOEXEC | O_NONBLOCK) == 0); ATF_REQUIRE(p[0] >= 0); ATF_REQUIRE(p[1] >= 0); - int kq = kqueue(); + kq = kqueue(); ATF_REQUIRE(kq >= 0); - struct kevent kev[32]; - EV_SET(&kev[0], p[0], EVFILT_READ, EV_ADD | EV_CLEAR | EV_RECEIPT, /**/ + EV_SET(&kev[0], p[0], EVFILT_READ, EV_ADD | EV_CLEAR | EV_RECEIPT, 0, 0, 0); - EV_SET(&kev[1], p[0], EVFILT_WRITE, EV_ADD | EV_CLEAR | EV_RECEIPT, /**/ + EV_SET(&kev[1], p[0], EVFILT_WRITE, EV_ADD | EV_CLEAR | EV_RECEIPT, 0, 0, 0); /* @@ -320,35 +324,32 @@ ATF_TC_BODY(pipe_kqueue__closed_write_end_register_bef ATF_REQUIRE((kev[1].flags & EV_ERROR) != 0); ATF_REQUIRE(kev[1].data == 0); - char c = 0; - ssize_t r; - while ((r = write(p[1], &c, 1)) == 1) { - } - ATF_REQUIRE(r < 0); + bytes = 0; + c = 0; + while ((n = write(p[1], &c, 1)) == 1) + bytes++; + ATF_REQUIRE(n < 0); ATF_REQUIRE(errno == EAGAIN || errno == EWOULDBLOCK); ATF_REQUIRE(close(p[1]) == 0); ATF_REQUIRE(kevent(kq, NULL, 0, kev, nitems(kev), - &(struct timespec) { 0, 0 }) == 2); - { - ATF_REQUIRE(kev[0].ident == (uintptr_t)p[0]); - ATF_REQUIRE(kev[0].filter == EVFILT_WRITE); - ATF_REQUIRE(kev[0].flags == - (EV_EOF | EV_CLEAR | EV_ONESHOT | EV_RECEIPT)); - ATF_REQUIRE(kev[0].fflags == 0); - ATF_REQUIRE(kev[0].data == 4096 || - kev[0].data == 512 /* on FreeBSD 11.3 */); - ATF_REQUIRE(kev[0].udata == 0); - } - { - ATF_REQUIRE(kev[1].ident == (uintptr_t)p[0]); - ATF_REQUIRE(kev[1].filter == EVFILT_READ); - ATF_REQUIRE(kev[1].flags == (EV_EOF | EV_CLEAR | EV_RECEIPT)); - ATF_REQUIRE(kev[1].fflags == 0); - ATF_REQUIRE(kev[1].data == 65536); - ATF_REQUIRE(kev[1].udata == 0); - } + &(struct timespec){ 0, 0 }) == 2); + + ATF_REQUIRE(kev[0].ident == (uintptr_t)p[0]); + ATF_REQUIRE(kev[0].filter == EVFILT_WRITE); + ATF_REQUIRE(kev[0].flags == + (EV_EOF | EV_CLEAR | EV_ONESHOT | EV_RECEIPT)); + ATF_REQUIRE(kev[0].fflags == 0); + ATF_REQUIRE(kev[0].data > 0); + ATF_REQUIRE(kev[0].udata == 0); + + ATF_REQUIRE(kev[1].ident == (uintptr_t)p[0]); + ATF_REQUIRE(kev[1].filter == EVFILT_READ); + ATF_REQUIRE(kev[1].flags == (EV_EOF | EV_CLEAR | EV_RECEIPT)); + ATF_REQUIRE(kev[1].fflags == 0); + ATF_REQUIRE(kev[1].data == bytes); + ATF_REQUIRE(kev[1].udata == 0); ATF_REQUIRE(close(kq) == 0); ATF_REQUIRE(close(p[0]) == 0);