summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/dup.cc
diff options
context:
space:
mode:
authorJamie Liu <jamieliu@google.com>2019-01-29 08:00:33 -0800
committerShentubot <shentubot@google.com>2019-01-29 08:01:48 -0800
commit57c202ead2d937e40c5d10da409504ac474165d1 (patch)
tree1e0d3365e744b554570563c0f4c661377f475187 /test/syscalls/linux/dup.cc
parent24cb2c0a7256cdb515c2fc2cfc90d130e2a405ef (diff)
Refactor out NewEventFD to a test utility.
PiperOrigin-RevId: 231404512 Change-Id: I31efcc23a0c4a48ef6fbba3ca07415d79290f55c
Diffstat (limited to 'test/syscalls/linux/dup.cc')
-rw-r--r--test/syscalls/linux/dup.cc18
1 files changed, 6 insertions, 12 deletions
diff --git a/test/syscalls/linux/dup.cc b/test/syscalls/linux/dup.cc
index fc11844fb..e8de2f4c4 100644
--- a/test/syscalls/linux/dup.cc
+++ b/test/syscalls/linux/dup.cc
@@ -13,10 +13,10 @@
// limitations under the License.
#include <fcntl.h>
-#include <sys/eventfd.h>
#include <unistd.h>
#include "gtest/gtest.h"
+#include "test/util/eventfd_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
#include "test/util/temp_path.h"
@@ -63,20 +63,14 @@ TEST(DupTest, Dup) {
}
TEST(DupTest, DupClearsCloExec) {
- FileDescriptor nfd;
-
// Open an eventfd file descriptor with FD_CLOEXEC descriptor flag set.
- int event_fd = 0;
- ASSERT_THAT(event_fd = eventfd(0, EFD_CLOEXEC), SyscallSucceeds());
- FileDescriptor event_fd_closer(event_fd);
-
- EXPECT_THAT(fcntl(event_fd_closer.get(), F_GETFD),
- SyscallSucceedsWithValue(FD_CLOEXEC));
+ FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(NewEventFD(0, EFD_CLOEXEC));
+ EXPECT_THAT(fcntl(fd.get(), F_GETFD), SyscallSucceedsWithValue(FD_CLOEXEC));
// Duplicate the descriptor. Ensure that it doesn't have FD_CLOEXEC set.
- nfd = ASSERT_NO_ERRNO_AND_VALUE(event_fd_closer.Dup());
- ASSERT_NE(event_fd_closer.get(), nfd.get());
- CheckSameFile(event_fd_closer, nfd);
+ FileDescriptor nfd = ASSERT_NO_ERRNO_AND_VALUE(fd.Dup());
+ ASSERT_NE(fd.get(), nfd.get());
+ CheckSameFile(fd, nfd);
EXPECT_THAT(fcntl(nfd.get(), F_GETFD), SyscallSucceedsWithValue(0));
}