From 3c5f8dfd4b0a7157343bacb62620e4f11612c3b7 Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Tue, 29 Jan 2019 09:05:51 -0800 Subject: Don't assume that stdout is always writable in PollTest.Nfds. stdout can be (and, in automated testing, often is) a host pipe or similar resource shared between multiple parallel tests, such that it can become transiently full during testing. PiperOrigin-RevId: 231413569 Change-Id: Id14991b5f71e53c894695899e65e1be4dd228cc6 --- test/syscalls/linux/BUILD | 1 + test/syscalls/linux/poll.cc | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD index 8cf83b311..e70742875 100644 --- a/test/syscalls/linux/BUILD +++ b/test/syscalls/linux/BUILD @@ -1246,6 +1246,7 @@ cc_binary( linkstatic = 1, deps = [ ":base_poll_test", + "//test/util:eventfd_util", "//test/util:file_descriptor", "//test/util:logging", "//test/util:test_main", diff --git a/test/syscalls/linux/poll.cc b/test/syscalls/linux/poll.cc index 897fd0bec..7a6a39444 100644 --- a/test/syscalls/linux/poll.cc +++ b/test/syscalls/linux/poll.cc @@ -23,6 +23,7 @@ #include "absl/time/clock.h" #include "absl/time/time.h" #include "test/syscalls/linux/base_poll_test.h" +#include "test/util/eventfd_util.h" #include "test/util/file_descriptor.h" #include "test/util/logging.h" #include "test/util/test_util.h" @@ -256,12 +257,14 @@ TEST_F(PollTest, Nfds) { TEST_PCHECK(getrlimit(RLIMIT_NOFILE, &rlim) == 0); rlim_t max_fds = rlim.rlim_cur; + // Create an eventfd. Since its value is initially zero, it is writable. + FileDescriptor efd = ASSERT_NO_ERRNO_AND_VALUE(NewEventFD()); + // Create the biggest possible pollfd array such that each element is valid. - // - // Each entry in the 'fds' array refers to stdout (fd=1) and polls for + // Each entry in the 'fds' array refers to the eventfd and polls for // "writable" events (events=POLLOUT). This essentially guarantees that the // poll() is a no-op and allows negative testing of the 'nfds' parameter. - std::vector fds(max_fds, {.fd = 1, .events = POLLOUT}); + std::vector fds(max_fds, {.fd = efd.get(), .events = POLLOUT}); // Verify that 'nfds' up to RLIMIT_NOFILE are allowed. EXPECT_THAT(RetryEINTR(poll)(fds.data(), 1, 1), SyscallSucceedsWithValue(1)); -- cgit v1.2.3