summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorAndrew Ng <anng.sw@gmail.com>2018-07-04 14:17:10 +0000
committerAndrew Ng <anng.sw@gmail.com>2018-07-04 14:17:10 +0000
commit089303d8ffeda0426de8c134fc40f0c2bd772abe (patch)
tree52cea07ddf68eb151714396f2847111f9341e1e5 /llvm/unittests/Support
parent67676e9c9913e30690f8f01eba1c9bb2b354c860 (diff)
downloadbcm5719-llvm-089303d8ffeda0426de8c134fc40f0c2bd772abe.tar.gz
bcm5719-llvm-089303d8ffeda0426de8c134fc40f0c2bd772abe.zip
[ThinLTO] Update ThinLTO cache file atimes when on Windows
ThinLTO cache file access times are used for expiration based pruning and since Vista, file access times are not updated by Windows by default: https://blogs.technet.microsoft.com/filecab/2006/11/07/disabling-last-access-time-in-windows-vista-to-improve-ntfs-performance This means on Windows, cache files are currently being pruned from creation time. This change manually updates cache files that are accessed by ThinLTO, when on Windows. Patch by Owen Reynolds. Differential Revision: https://reviews.llvm.org/D47266 llvm-svn: 336276
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/Path.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index ff301dc7d89..dcbe94c6715 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -26,6 +26,7 @@
#ifdef _WIN32
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Chrono.h"
#include <windows.h>
#include <winerror.h>
#endif
@@ -1251,8 +1252,39 @@ TEST_F(FileSystemTest, OpenFileForRead) {
ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2));
ASSERT_EQ(D1, D2);
}
+ ::close(FileDescriptor);
+ ::close(FileDescriptor2);
+
+#ifdef _WIN32
+ // Since Windows Vista, file access time is not updated by default.
+ // This is instead updated manually by openFileForRead.
+ // https://blogs.technet.microsoft.com/filecab/2006/11/07/disabling-last-access-time-in-windows-vista-to-improve-ntfs-performance/
+ // This part of the unit test is Windows specific as the updating of
+ // access times can be disabled on Linux using /etc/fstab.
+
+ // Set access time to UNIX epoch.
+ ASSERT_NO_ERROR(sys::fs::openFileForWrite(Twine(TempPath), FileDescriptor,
+ fs::CD_OpenExisting));
+ TimePoint<> Epoch(std::chrono::milliseconds(0));
+ ASSERT_NO_ERROR(fs::setLastModificationAndAccessTime(FileDescriptor, Epoch));
+ ::close(FileDescriptor);
+ // Open the file and ensure access time is updated, when forced.
+ bool ForceATime = true;
+ ASSERT_NO_ERROR(fs::openFileForRead(Twine(TempPath), FileDescriptor,
+ fs::OF_UpdateAtime, &ResultPath));
+
+ sys::fs::file_status Status;
+ ASSERT_NO_ERROR(sys::fs::status(FileDescriptor, Status));
+ auto FileAccessTime = Status.getLastAccessedTime();
+
+ ASSERT_NE(Epoch, FileAccessTime);
::close(FileDescriptor);
+
+ // Ideally this test would include a case when ATime is not forced to update,
+ // however the expected behaviour will differ depending on the configuration
+ // of the Windows file system.
+#endif
}
static void createFileWithData(const Twine &Path, bool ShouldExistBefore,
OpenPOWER on IntegriCloud