diff options
author | Jamie Liu <jamieliu@google.com> | 2019-01-29 09:05:51 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-29 09:06:59 -0800 |
commit | 3c5f8dfd4b0a7157343bacb62620e4f11612c3b7 (patch) | |
tree | 7a150c0a9e015a900226da08a3ac407cde942aa2 | |
parent | 57c202ead2d937e40c5d10da409504ac474165d1 (diff) |
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
-rw-r--r-- | test/syscalls/linux/BUILD | 1 | ||||
-rw-r--r-- | test/syscalls/linux/poll.cc | 9 |
2 files changed, 7 insertions, 3 deletions
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<struct pollfd> fds(max_fds, {.fd = 1, .events = POLLOUT}); + std::vector<struct pollfd> 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)); |