diff options
author | Jamie Liu <jamieliu@google.com> | 2019-01-29 08:00:33 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-29 08:01:48 -0800 |
commit | 57c202ead2d937e40c5d10da409504ac474165d1 (patch) | |
tree | 1e0d3365e744b554570563c0f4c661377f475187 /test/syscalls/linux/getdents.cc | |
parent | 24cb2c0a7256cdb515c2fc2cfc90d130e2a405ef (diff) |
Refactor out NewEventFD to a test utility.
PiperOrigin-RevId: 231404512
Change-Id: I31efcc23a0c4a48ef6fbba3ca07415d79290f55c
Diffstat (limited to 'test/syscalls/linux/getdents.cc')
-rw-r--r-- | test/syscalls/linux/getdents.cc | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/test/syscalls/linux/getdents.cc b/test/syscalls/linux/getdents.cc index 5db580aa0..526925599 100644 --- a/test/syscalls/linux/getdents.cc +++ b/test/syscalls/linux/getdents.cc @@ -19,13 +19,13 @@ #include <stdint.h> #include <stdio.h> #include <string.h> -#include <sys/eventfd.h> #include <sys/mman.h> #include <sys/types.h> #include <syscall.h> #include <unistd.h> #include <map> #include <string> +#include <unordered_map> #include <unordered_set> #include <utility> @@ -33,6 +33,7 @@ #include "gtest/gtest.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" +#include "test/util/eventfd_util.h" #include "test/util/file_descriptor.h" #include "test/util/fs_util.h" #include "test/util/posix_error.h" @@ -368,16 +369,11 @@ TYPED_TEST(GetdentsTest, PartialBuffer) { // getdents iterates correctly despite mutation of /proc/self/fd. TYPED_TEST(GetdentsTest, ProcSelfFd) { constexpr size_t kNfds = 10; - std::unordered_set<int> fds; - std::vector<FileDescriptor> fd_closers; - fd_closers.reserve(fds.size()); - for (int fd : fds) { - fd_closers.emplace_back(fd); - } + std::unordered_map<int, FileDescriptor> fds; + fds.reserve(kNfds); for (size_t i = 0; i < kNfds; i++) { - int fd; - ASSERT_THAT(fd = eventfd(0, 0), SyscallSucceeds()); - fds.insert(fd); + FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(NewEventFD()); + fds.emplace(fd.get(), std::move(fd)); } const FileDescriptor proc_self_fd = @@ -401,11 +397,7 @@ TYPED_TEST(GetdentsTest, ProcSelfFd) { if (!absl::SimpleAtoi(d->d_name, &dfd)) continue; EXPECT_TRUE(prev_fds.insert(dfd).second) << "Repeated observation of /proc/self/fd/" << dfd; - auto it = fds.find(dfd); - if (it != fds.end()) { - fds.erase(it); - EXPECT_THAT(close(dfd), SyscallSucceeds()); - } + fds.erase(dfd); } } |