From ca7e83b67939809d5df619119fb3d5f958d67c86 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 22 Mar 2023 11:02:27 -0700 Subject: [PATCH] Internal change. PiperOrigin-RevId: 518617649 --- test/syscalls/linux/poll.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/syscalls/linux/poll.cc b/test/syscalls/linux/poll.cc index ccd084244..a80192599 100644 --- a/test/syscalls/linux/poll.cc +++ b/test/syscalls/linux/poll.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include @@ -350,6 +351,15 @@ TEST_F(PollTest, Nfds) { EXPECT_THAT(poll(fds.data(), max_fds + 1, 1), SyscallFailsWithErrno(EINVAL)); } +// Polling on a file that doesn't support blocking, like a directory, should +// immediately return. +TEST_F(PollTest, UnpollableFile) { + FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open("/", O_RDONLY)); + struct pollfd poll_fd = {fd.get(), POLLIN | POLLOUT, 0}; + EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, -1), SyscallSucceedsWithValue(1)); + EXPECT_EQ(poll_fd.revents, POLLIN | POLLOUT); +} + } // namespace } // namespace testing } // namespace gvisor