Skip to contentSkip to conversation

selftests/epoll: add a regression test for pipe->poll_usage

PATCH Superseded Oleg Nesterov 1 participant 2 messages Jul 29 Kselftest

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/epoll: add a regression test for pipe->poll_usage

pipe->poll_usage was added to ensure that edge-triggered epoll consumers get a wakeup on every write, even if the pipe was already non-empty. However, none of the existing epoll_wakeup_test cases cover this; the test suite passes even with WRITE_ONCE(pipe->poll_usage, true) removed.

Add a test that writes twice to a pipe and verifies that epoll_wait with EPOLLET reports data each time. This covers the pipe-specific per-write wakeup behavior that edge-triggered consumers depend on.

---
 .../filesystems/epoll/epoll_wakeup_test.c     | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c +24 -0
index f6f1a7ff01b0..6ad7905ef95a 100644
@@ -3538,4 +3538,28 @@ TEST(epoll65)
 	close(ctx.efd[1]);
 }
 
+TEST(epoll66)
+{
+	struct epoll_event event;
+	int pfd[2], efd, err;
+
+	pipe(pfd);
+
+	efd = epoll_create1(0);
+	ASSERT_GE(efd, 0);
+
+	event.events = EPOLLIN | EPOLLET;
+	err = epoll_ctl(efd, EPOLL_CTL_ADD, pfd[0], &event);
+	ASSERT_EQ(err, 0);
+
+	for (int i = 0; i < 2; ++i) {
+		write(pfd[1], "", 1);
+		EXPECT_EQ(epoll_wait(efd, &event, 1, 0), 1);
+	}
+
+	close(pfd[0]);
+	close(pfd[1]);
+	close(efd);
+}
+
 TEST_HARNESS_MAIN
Signature · 1 line
2.52.0
#1 lore raw

Sashiko suggests to check the results of pipe() and write() as well:

https://sashiko.dev/#/patchset/amna1QtCtqll1LFj%40redhat.com

Not sure this makes sense, but I'll send V2 just in case.

Oleg.

Quoted 51 lines · Oleg Nesterov

pipe->poll_usage was added to ensure that edge-triggered epoll consumers get a wakeup on every write, even if the pipe was already non-empty. However, none of the existing epoll_wakeup_test cases cover this; the test suite passes even with WRITE_ONCE(pipe->poll_usage, true) removed.

Add a test that writes twice to a pipe and verifies that epoll_wait with EPOLLET reports data each time. This covers the pipe-specific per-write wakeup behavior that edge-triggered consumers depend on.

---
 .../filesystems/epoll/epoll_wakeup_test.c     | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c +24 -0
index f6f1a7ff01b0..6ad7905ef95a 100644
@@ -3538,4 +3538,28 @@ TEST(epoll65)
 	close(ctx.efd[1]);
 }
 
+TEST(epoll66)
+{
+	struct epoll_event event;
+	int pfd[2], efd, err;
+
+	pipe(pfd);
+
+	efd = epoll_create1(0);
+	ASSERT_GE(efd, 0);
+
+	event.events = EPOLLIN | EPOLLET;
+	err = epoll_ctl(efd, EPOLL_CTL_ADD, pfd[0], &event);
+	ASSERT_EQ(err, 0);
+
+	for (int i = 0; i < 2; ++i) {
+		write(pfd[1], "", 1);
+		EXPECT_EQ(epoll_wait(efd, &event, 1, 0), 1);
+	}
+
+	close(pfd[0]);
+	close(pfd[1]);
+	close(efd);
+}
+
 TEST_HARNESS_MAIN
Signature · 1 line
2.52.0