diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-01-17 11:05:40 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-17 11:06:59 -0800 |
commit | 12bc7834dccdcd21353fc476dc76a5c9bc0d47bb (patch) | |
tree | 7679547af34bd09bf9536bb48d821e6e4dcb5db4 /test/syscalls | |
parent | e4d3ca7263291b43cdc49c7553c62608be062cd9 (diff) |
Allow fsync on a directory.
PiperOrigin-RevId: 229781337
Change-Id: I1f946cff2771714fb1abd83a83ed454e9febda0a
Diffstat (limited to 'test/syscalls')
-rw-r--r-- | test/syscalls/linux/BUILD | 1 | ||||
-rw-r--r-- | test/syscalls/linux/fsync.cc | 23 |
2 files changed, 14 insertions, 10 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD index 41d476481..19884d55e 100644 --- a/test/syscalls/linux/BUILD +++ b/test/syscalls/linux/BUILD @@ -783,6 +783,7 @@ cc_binary( srcs = ["fsync.cc"], linkstatic = 1, deps = [ + "//test/util:file_descriptor", "//test/util:temp_path", "//test/util:test_main", "//test/util:test_util", diff --git a/test/syscalls/linux/fsync.cc b/test/syscalls/linux/fsync.cc index 536a73bf1..b34229248 100644 --- a/test/syscalls/linux/fsync.cc +++ b/test/syscalls/linux/fsync.cc @@ -19,6 +19,7 @@ #include <string> #include "gtest/gtest.h" +#include "test/util/file_descriptor.h" #include "test/util/temp_path.h" #include "test/util/test_util.h" @@ -28,22 +29,24 @@ namespace testing { namespace { TEST(FsyncTest, TempFileSucceeds) { - std::string path = NewTempAbsPath(); - int fd; - EXPECT_THAT(fd = open(path.c_str(), O_RDWR | O_CREAT, 0666), - SyscallSucceeds()); + auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); + auto fd = ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_RDWR, 0666)); const std::string data = "some data to sync"; - EXPECT_THAT(write(fd, data.c_str(), data.size()), + EXPECT_THAT(write(fd.get(), data.c_str(), data.size()), SyscallSucceedsWithValue(data.size())); - EXPECT_THAT(fsync(fd), SyscallSucceeds()); - ASSERT_THAT(close(fd), SyscallSucceeds()); - ASSERT_THAT(unlink(path.c_str()), SyscallSucceeds()); + EXPECT_THAT(fsync(fd.get()), SyscallSucceeds()); +} + +TEST(FsyncTest, TempDirSucceeds) { + auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + auto fd = ASSERT_NO_ERRNO_AND_VALUE(Open(dir.path(), O_RDONLY | O_DIRECTORY)); + EXPECT_THAT(fsync(fd.get()), SyscallSucceeds()); } TEST(FsyncTest, CannotFsyncOnUnopenedFd) { + auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); int fd; - auto f = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); - ASSERT_THAT(fd = open(f.path().c_str(), O_RDONLY), SyscallSucceeds()); + ASSERT_THAT(fd = open(file.path().c_str(), O_RDONLY), SyscallSucceeds()); ASSERT_THAT(close(fd), SyscallSucceeds()); // fd is now invalid. |