X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FLockFileManagerTest.cpp;h=efe3c3088b33e1ea04e04ca247a734cc1682ae25;hb=e51b530b1255624a0a170395ce2d950b56d6c7f3;hp=6392739778c9653f14d315973231fb08be34e8da;hpb=2c8cd9a0baa99a66ebde72dc688ef3e9239890e0;p=oota-llvm.git diff --git a/unittests/Support/LockFileManagerTest.cpp b/unittests/Support/LockFileManagerTest.cpp index 6392739778c..efe3c3088b3 100644 --- a/unittests/Support/LockFileManagerTest.cpp +++ b/unittests/Support/LockFileManagerTest.cpp @@ -19,7 +19,7 @@ namespace { TEST(LockFileManagerTest, Basic) { SmallString<64> TmpDir; - error_code EC; + std::error_code EC; EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); ASSERT_FALSE(EC); @@ -46,7 +46,7 @@ TEST(LockFileManagerTest, Basic) { TEST(LockFileManagerTest, LinkLockExists) { SmallString<64> TmpDir; - error_code EC; + std::error_code EC; EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); ASSERT_FALSE(EC); @@ -59,9 +59,19 @@ TEST(LockFileManagerTest, LinkLockExists) { SmallString<64> TmpFileLock(TmpDir); sys::path::append(TmpFileLock, "file.lock-000"); + int FD; + EC = sys::fs::openFileForWrite(StringRef(TmpFileLock), FD, sys::fs::F_None); + ASSERT_FALSE(EC); + + int Ret = close(FD); + ASSERT_EQ(Ret, 0); + EC = sys::fs::create_link(TmpFileLock.str(), FileLocK.str()); ASSERT_FALSE(EC); + EC = sys::fs::remove(StringRef(TmpFileLock)); + ASSERT_FALSE(EC); + { // The lock file doesn't point to a real file, so we should successfully // acquire it. @@ -76,4 +86,42 @@ TEST(LockFileManagerTest, LinkLockExists) { ASSERT_FALSE(EC); } + +TEST(LockFileManagerTest, RelativePath) { + SmallString<64> TmpDir; + std::error_code EC; + EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); + ASSERT_FALSE(EC); + + char PathBuf[1024]; + const char *OrigPath = getcwd(PathBuf, 1024); + ASSERT_FALSE(chdir(TmpDir.c_str())); + + sys::fs::create_directory("inner"); + SmallString<64> LockedFile("inner"); + sys::path::append(LockedFile, "file"); + + SmallString<64> FileLock(LockedFile); + FileLock += ".lock"; + + { + // The lock file should not exist, so we should successfully acquire it. + LockFileManager Locked(LockedFile); + EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState()); + EXPECT_TRUE(sys::fs::exists(FileLock.str())); + } + + // Now that the lock is out of scope, the file should be gone. + EXPECT_FALSE(sys::fs::exists(LockedFile.str())); + EXPECT_FALSE(sys::fs::exists(FileLock.str())); + + EC = sys::fs::remove("inner"); + ASSERT_FALSE(EC); + + ASSERT_FALSE(chdir(OrigPath)); + + EC = sys::fs::remove(StringRef(TmpDir)); + ASSERT_FALSE(EC); +} + } // end anonymous namespace