public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Steve Muckle <smuckle.linux@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/2] syscalls/epoll_wait01: cleanup data structure usage
Date: Thu, 27 Jul 2017 12:06:47 -0700	[thread overview]
Message-ID: <20170727190647.116088-2-smuckle.linux@gmail.com> (raw)
In-Reply-To: <20170727190647.116088-1-smuckle.linux@gmail.com>

The fds2 data structure is not used during the test, remove it.
Ensure the event structure that epoll_wait() writes into is cleared
prior to invoking the call so that the returned data is confidently
known.

Signed-off-by: Steve Muckle <smuckle.linux@gmail.com>
---
 .../kernel/syscalls/epoll_wait/epoll_wait01.c      | 49 ++++++++++------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
index 10f8b6ca6..9afd2dae2 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
@@ -34,11 +34,10 @@
 char *TCID = "epoll_wait01";
 int TST_TOTAL = 3;
 
-static int write_size, epfd, fds[2], fds2[2];
-static struct epoll_event epevs[3] = {
+static int write_size, epfd, fds[2];
+static struct epoll_event epevs[2] = {
 	{.events = EPOLLIN},
 	{.events = EPOLLOUT},
-	{.events = EPOLLIN}
 };
 
 static void setup(void);
@@ -77,7 +76,6 @@ static void setup(void)
 	TEST_PAUSE;
 
 	SAFE_PIPE(NULL, fds);
-	SAFE_PIPE(cleanup, fds2);
 
 	write_size = get_writesize();
 
@@ -89,11 +87,9 @@ static void setup(void)
 
 	epevs[0].data.fd = fds[0];
 	epevs[1].data.fd = fds[1];
-	epevs[2].data.fd = fds2[0];
 
 	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &epevs[0]) ||
-	    epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[1]) ||
-	    epoll_ctl(epfd, EPOLL_CTL_ADD, fds2[0], &epevs[2])) {
+	    epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[1])) {
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "failed to register epoll target");
 	}
@@ -128,7 +124,9 @@ static int get_writesize(void)
 
 static void verify_epollout(void)
 {
-	TEST(epoll_wait(epfd, epevs, 3, -1));
+	struct epoll_event ret_evs = {.events = 0, .data.fd = 0};
+
+	TEST(epoll_wait(epfd, &ret_evs, 1, -1));
 
 	if (TEST_RETURN == -1) {
 		tst_resm(TFAIL | TTERRNO, "epoll_wait() epollout failed");
@@ -141,15 +139,15 @@ static void verify_epollout(void)
 		return;
 	}
 
-	if (epevs[0].data.fd != fds[1]) {
+	if (ret_evs.data.fd != fds[1]) {
 		tst_resm(TFAIL, "epoll.data.fd %i, expected %i",
-			 epevs[0].data.fd, fds[1]);
+			 ret_evs.data.fd, fds[1]);
 		return;
 	}
 
-	if (epevs[0].events != EPOLLOUT) {
+	if (ret_evs.events != EPOLLOUT) {
 		tst_resm(TFAIL, "epoll.events %x, expected EPOLLOUT %x",
-			 epevs[0].events, EPOLLOUT);
+			 ret_evs.events, EPOLLOUT);
 		return;
 	}
 
@@ -160,12 +158,13 @@ static void verify_epollin(void)
 {
 	char write_buf[write_size];
 	char read_buf[sizeof(write_buf)];
+	struct epoll_event ret_evs = {.events = 0, .data.fd = 0};
 
 	memset(write_buf, 'a', sizeof(write_buf));
 
 	SAFE_WRITE(cleanup, 1, fds[1], write_buf, sizeof(write_buf));
 
-	TEST(epoll_wait(epfd, epevs, 3, -1));
+	TEST(epoll_wait(epfd, &ret_evs, 1, -1));
 
 	if (TEST_RETURN == -1) {
 		tst_resm(TFAIL | TTERRNO, "epoll_wait() epollin failed");
@@ -178,15 +177,15 @@ static void verify_epollin(void)
 		goto end;
 	}
 
-	if (epevs[0].data.fd != fds[0]) {
+	if (ret_evs.data.fd != fds[0]) {
 		tst_resm(TFAIL, "epoll.data.fd %i, expected %i",
-			 epevs[0].data.fd, fds[0]);
+			 ret_evs.data.fd, fds[0]);
 		goto end;
 	}
 
-	if (epevs[0].events != EPOLLIN) {
+	if (ret_evs.events != EPOLLIN) {
 		tst_resm(TFAIL, "epoll.events %x, expected EPOLLIN %x",
-			 epevs[0].events, EPOLLIN);
+			 ret_evs.events, EPOLLIN);
 		goto end;
 	}
 
@@ -201,13 +200,15 @@ static void verify_epollio(void)
 	char write_buf[] = "Testing";
 	char read_buf[sizeof(write_buf)];
 	uint32_t events = EPOLLIN | EPOLLOUT;
+	struct epoll_event ret_evs[2];
 
 	SAFE_WRITE(cleanup, 1, fds[1], write_buf, sizeof(write_buf));
 
 	while (events) {
 		int events_matched = 0;
 
-		TEST(epoll_wait(epfd, epevs, 3, -1));
+		bzero(ret_evs, sizeof(ret_evs));
+		TEST(epoll_wait(epfd, ret_evs, 2, -1));
 
 		if (TEST_RETURN <= 0) {
 			tst_resm(TFAIL | TTERRNO, "epoll_wait() returned %i",
@@ -216,13 +217,13 @@ static void verify_epollio(void)
 		}
 
 		if ((events & EPOLLIN) &&
-		    has_event(epevs, 2, fds[0], EPOLLIN)) {
+		    has_event(ret_evs, 2, fds[0], EPOLLIN)) {
 			events_matched++;
 			events &= ~EPOLLIN;
 		}
 
 		if ((events & EPOLLOUT) &&
-		    has_event(epevs, 2, fds[1], EPOLLOUT)) {
+		    has_event(ret_evs, 2, fds[1], EPOLLOUT)) {
 			events_matched++;
 			events &= ~EPOLLOUT;
 		}
@@ -230,7 +231,7 @@ static void verify_epollio(void)
 		if (TEST_RETURN != events_matched) {
 			tst_resm(TFAIL,
 				 "epoll_wait() returned unexpected events");
-			dump_epevs(epevs, 2);
+			dump_epevs(ret_evs, 2);
 			goto end;
 		}
 	}
@@ -274,10 +275,4 @@ static void cleanup(void)
 
 	if (close(fds[1]))
 		tst_resm(TWARN | TERRNO, "failed to close fds[1]");
-
-	if (fds2[0] > 0 && close(fds2[0]))
-		tst_resm(TWARN | TERRNO, "failed to close fds2[0]");
-
-	if (fds2[1] > 0 && close(fds2[1]))
-		tst_resm(TWARN | TERRNO, "failed to close fds2[1]");
 }
-- 
2.14.0.rc0.400.g1c36432dff-goog


  reply	other threads:[~2017-07-27 19:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 19:06 [LTP] [PATCH v2 1/2] syscalls/epoll_*: allow for epoll_wait returning a subset of events Steve Muckle
2017-07-27 19:06 ` Steve Muckle [this message]
2017-07-28  9:59   ` [LTP] [PATCH v2 2/2] syscalls/epoll_wait01: cleanup data structure usage Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170727190647.116088-2-smuckle.linux@gmail.com \
    --to=smuckle.linux@gmail.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox