summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/LockFileManagerTest.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp
index 1f949a369e4..6392739778c 100644
--- a/llvm/unittests/Support/LockFileManagerTest.cpp
+++ b/llvm/unittests/Support/LockFileManagerTest.cpp
@@ -44,4 +44,36 @@ TEST(LockFileManagerTest, Basic) {
ASSERT_FALSE(EC);
}
+TEST(LockFileManagerTest, LinkLockExists) {
+ SmallString<64> TmpDir;
+ error_code EC;
+ EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
+ ASSERT_FALSE(EC);
+
+ SmallString<64> LockedFile(TmpDir);
+ sys::path::append(LockedFile, "file");
+
+ SmallString<64> FileLocK(TmpDir);
+ sys::path::append(FileLocK, "file.lock");
+
+ SmallString<64> TmpFileLock(TmpDir);
+ sys::path::append(TmpFileLock, "file.lock-000");
+
+ EC = sys::fs::create_link(TmpFileLock.str(), FileLocK.str());
+ ASSERT_FALSE(EC);
+
+ {
+ // The lock file doesn't point to a real file, so we should successfully
+ // acquire it.
+ LockFileManager Locked(LockedFile);
+ EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
+ }
+
+ // Now that the lock is out of scope, the file should be gone.
+ EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
+
+ EC = sys::fs::remove(StringRef(TmpDir));
+ ASSERT_FALSE(EC);
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud