Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 May 2020 15:06:03 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r361552 - in stable/12/tests/sys: fifo kern/pipe
Message-ID:  <202005271506.04RF63b0036006@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Wed May 27 15:06:03 2020
New Revision: 361552
URL: https://svnweb.freebsd.org/changeset/base/361552

Log:
  MFC r361286:
  Avoid hard-coding pipe buffer sizes in the pipe and fifo kqueue tests.

Modified:
  stable/12/tests/sys/fifo/fifo_kqueue.c
  stable/12/tests/sys/kern/pipe/pipe_kqueue_test.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/tests/sys/fifo/fifo_kqueue.c
==============================================================================
--- stable/12/tests/sys/fifo/fifo_kqueue.c	Wed May 27 11:42:09 2020	(r361551)
+++ stable/12/tests/sys/fifo/fifo_kqueue.c	Wed May 27 15:06:03 2020	(r361552)
@@ -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: stable/12/tests/sys/kern/pipe/pipe_kqueue_test.c
==============================================================================
--- stable/12/tests/sys/kern/pipe/pipe_kqueue_test.c	Wed May 27 11:42:09 2020	(r361551)
+++ stable/12/tests/sys/kern/pipe/pipe_kqueue_test.c	Wed May 27 15:06:03 2020	(r361552)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005271506.04RF63b0036006>