diff options
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 355aa6b..888729b 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -1471,6 +1471,43 @@ TEST_F(FileSystemTest, FileMapping) { ASSERT_NO_ERROR(fs::remove(TempPath)); } +TEST_F(FileSystemTest, FileMappingSync) { + // Create a temp file. + SmallString<0> TempPath(TestDirectory); + sys::path::append(TempPath, "test-%%%%"); + auto TempFileOrError = fs::TempFile::create(TempPath); + ASSERT_TRUE((bool)TempFileOrError); + fs::TempFile File = std::move(*TempFileOrError); + StringRef Content("hello there"); + std::string FileName = File.TmpName; + ASSERT_NO_ERROR( + fs::resize_file_before_mapping_readwrite(File.FD, Content.size())); + { + // Map in the file and write some content. + std::error_code EC; + fs::mapped_file_region MFR(fs::convertFDToNativeFile(File.FD), + fs::mapped_file_region::readwrite, + Content.size(), 0, EC); + + // Keep the file so it can be read. + ASSERT_FALSE((bool)File.keep()); + + // Write content through mapped memory. + ASSERT_NO_ERROR(EC); + std::copy(Content.begin(), Content.end(), MFR.data()); + + // Synchronize to file system. + ASSERT_FALSE((bool)MFR.sync()); + + // Check the file content using file IO APIs. + auto Buffer = MemoryBuffer::getFile(FileName); + ASSERT_TRUE((bool)Buffer); + ASSERT_EQ(Content, Buffer->get()->getBuffer()); + } + // Manually remove the test file. + ASSERT_FALSE((bool)fs::remove(FileName)); +} + TEST(Support, NormalizePath) { // Input, Expected Win, Expected Posix using TestTuple = std::tuple<const char *, const char *, const char *>; |