diff options
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r-- | test/syscalls/linux/poll.cc | 79 | ||||
-rw-r--r-- | test/syscalls/linux/tcp_socket.cc | 25 |
2 files changed, 87 insertions, 17 deletions
diff --git a/test/syscalls/linux/poll.cc b/test/syscalls/linux/poll.cc index 7a316427d..6f9a9498c 100644 --- a/test/syscalls/linux/poll.cc +++ b/test/syscalls/linux/poll.cc @@ -64,7 +64,7 @@ TEST_F(PollTest, NegativeTimeout_NoRandomSave) { EXPECT_TRUE(TimerFired()); } -TEST_F(PollTest, NonBlockingEventPOLLIN) { +void NonBlockingReadableTest(int16_t mask) { // Create a pipe. int fds[2]; ASSERT_THAT(pipe(fds), SyscallSucceeds()); @@ -77,14 +77,24 @@ TEST_F(PollTest, NonBlockingEventPOLLIN) { ASSERT_THAT(WriteFd(fd1.get(), s, strlen(s) + 1), SyscallSucceeds()); // Poll on the reader fd with POLLIN event. - struct pollfd poll_fd = {fd0.get(), POLLIN, 0}; + struct pollfd poll_fd = {fd0.get(), mask, 0}; EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, 0), SyscallSucceedsWithValue(1)); // Should trigger POLLIN event. - EXPECT_EQ(poll_fd.revents & POLLIN, POLLIN); + EXPECT_EQ(poll_fd.revents & mask, mask); } -TEST_F(PollTest, BlockingEventPOLLIN) { +TEST_F(PollTest, NonBlockingEventPOLLIN) { NonBlockingReadableTest(POLLIN); } + +TEST_F(PollTest, NonBlockingEventPOLLRDNORM) { + NonBlockingReadableTest(POLLRDNORM); +} + +TEST_F(PollTest, NonBlockingEventPOLLRDNORM_POLLIN) { + NonBlockingReadableTest(POLLRDNORM | POLLIN); +} + +void BlockingReadableTest(int16_t mask) { // Create a pipe. int fds[2]; ASSERT_THAT(pipe(fds), SyscallSucceeds()); @@ -94,15 +104,15 @@ TEST_F(PollTest, BlockingEventPOLLIN) { // Start a blocking poll on the read fd. absl::Notification notify; - ScopedThread t([&fd0, ¬ify]() { + ScopedThread t([&fd0, ¬ify, &mask]() { notify.Notify(); - // Poll on the reader fd with POLLIN event. - struct pollfd poll_fd = {fd0.get(), POLLIN, 0}; + // Poll on the reader fd with readable event. + struct pollfd poll_fd = {fd0.get(), mask, 0}; EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, -1), SyscallSucceedsWithValue(1)); - // Should trigger POLLIN event. - EXPECT_EQ(poll_fd.revents & POLLIN, POLLIN); + // Should trigger readable event. + EXPECT_EQ(poll_fd.revents & mask, mask); }); notify.WaitForNotification(); @@ -113,6 +123,57 @@ TEST_F(PollTest, BlockingEventPOLLIN) { ASSERT_THAT(WriteFd(fd1.get(), s, strlen(s) + 1), SyscallSucceeds()); } +TEST_F(PollTest, BlockingEventPOLLIN) { BlockingReadableTest(POLLIN); } + +TEST_F(PollTest, BlockingEventPOLLRDNORM) { BlockingReadableTest(POLLRDNORM); } + +TEST_F(PollTest, BlockingEventPOLLRDNORM_POLLIN) { + BlockingReadableTest(POLLRDNORM | POLLIN); +} + +void WritableTest(int16_t mask, int timeout) { + // Create a pipe. + int fds[2]; + ASSERT_THAT(pipe(fds), SyscallSucceeds()); + + FileDescriptor fd0(fds[0]); + FileDescriptor fd1(fds[1]); + + // In a newly created pipe 2nd fd should be writable. + + // Poll on second fd for a writable event. + struct pollfd poll_fd = {fd1.get(), mask, 0}; + EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, timeout), + SyscallSucceedsWithValue(1)); + + // Should trigger a writable event. + EXPECT_EQ(poll_fd.revents & mask, mask); +} + +TEST_F(PollTest, NonBlockingEventPOLLOUT) { + WritableTest(POLLOUT, /*timeout=*/0); +} + +TEST_F(PollTest, NonBlockingEventPOLLWRNORM) { + WritableTest(POLLWRNORM, /*timeout=*/0); +} + +TEST_F(PollTest, NonBlockingEventPOLLWRNORM_POLLOUT) { + WritableTest(POLLWRNORM | POLLOUT, /*timeout=*/0); +} + +TEST_F(PollTest, BlockingEventPOLLOUT) { + WritableTest(POLLOUT, /*timeout=*/-1); +} + +TEST_F(PollTest, BlockingEventPOLLWRNORM) { + WritableTest(POLLWRNORM, /*timeout=*/-1); +} + +TEST_F(PollTest, BlockingEventPOLLWRNORM_POLLOUT) { + WritableTest(POLLWRNORM | POLLOUT, /*timeout=*/-1); +} + TEST_F(PollTest, NonBlockingEventPOLLHUP) { // Create a pipe. int fds[2]; diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc index f56c50e61..7341cf1a6 100644 --- a/test/syscalls/linux/tcp_socket.cc +++ b/test/syscalls/linux/tcp_socket.cc @@ -1204,13 +1204,12 @@ TEST_P(SimpleTcpSocketTest, SelfConnectSend_NoRandomSave) { EXPECT_THAT(shutdown(s.get(), SHUT_WR), SyscallSucceedsWithValue(0)); } -TEST_P(SimpleTcpSocketTest, NonBlockingConnect) { +void NonBlockingConnect(int family, int16_t pollMask) { const FileDescriptor listener = - ASSERT_NO_ERRNO_AND_VALUE(Socket(GetParam(), SOCK_STREAM, IPPROTO_TCP)); + ASSERT_NO_ERRNO_AND_VALUE(Socket(family, SOCK_STREAM, IPPROTO_TCP)); // Initialize address to the loopback one. - sockaddr_storage addr = - ASSERT_NO_ERRNO_AND_VALUE(InetLoopbackAddr(GetParam())); + sockaddr_storage addr = ASSERT_NO_ERRNO_AND_VALUE(InetLoopbackAddr(family)); socklen_t addrlen = sizeof(addr); // Bind to some port then start listening. @@ -1221,7 +1220,7 @@ TEST_P(SimpleTcpSocketTest, NonBlockingConnect) { ASSERT_THAT(listen(listener.get(), SOMAXCONN), SyscallSucceeds()); FileDescriptor s = - ASSERT_NO_ERRNO_AND_VALUE(Socket(GetParam(), SOCK_STREAM, IPPROTO_TCP)); + ASSERT_NO_ERRNO_AND_VALUE(Socket(family, SOCK_STREAM, IPPROTO_TCP)); // Set the FD to O_NONBLOCK. int opts; @@ -1241,9 +1240,7 @@ TEST_P(SimpleTcpSocketTest, NonBlockingConnect) { ASSERT_THAT(t = RetryEINTR(accept)(listener.get(), nullptr, nullptr), SyscallSucceeds()); - // Now polling on the FD with a timeout should return 0 corresponding to no - // FDs ready. - struct pollfd poll_fd = {s.get(), POLLOUT, 0}; + struct pollfd poll_fd = {s.get(), pollMask, 0}; EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, 10000), SyscallSucceedsWithValue(1)); @@ -1257,6 +1254,18 @@ TEST_P(SimpleTcpSocketTest, NonBlockingConnect) { EXPECT_THAT(close(t), SyscallSucceeds()); } +TEST_P(SimpleTcpSocketTest, NonBlockingConnect_PollOut) { + NonBlockingConnect(GetParam(), POLLOUT); +} + +TEST_P(SimpleTcpSocketTest, NonBlockingConnect_PollWrNorm) { + NonBlockingConnect(GetParam(), POLLWRNORM); +} + +TEST_P(SimpleTcpSocketTest, NonBlockingConnect_PollWrNorm_PollOut) { + NonBlockingConnect(GetParam(), POLLWRNORM | POLLOUT); +} + TEST_P(SimpleTcpSocketTest, NonBlockingConnectRemoteClose) { const FileDescriptor listener = ASSERT_NO_ERRNO_AND_VALUE(Socket(GetParam(), SOCK_STREAM, IPPROTO_TCP)); |