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