1 //===- unittests/LockFileManagerTest.cpp - LockFileManager tests ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/LockFileManager.h"
11 #include "llvm/Support/FileSystem.h"
12 #include "llvm/Support/Path.h"
14 #include "gtest/gtest.h"
22 TEST(LockFileManagerTest, Basic) {
23 SmallString<64> TmpDir;
25 EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
28 SmallString<64> LockedFile(TmpDir);
29 sys::path::append(LockedFile, "file.lock");
32 // The lock file should not exist, so we should successfully acquire it.
33 LockFileManager Locked1(LockedFile);
34 EXPECT_EQ(LockFileManager::LFS_Owned, Locked1.getState());
36 // Attempting to reacquire the lock should fail. Waiting on it would cause
37 // deadlock, so don't try that.
38 LockFileManager Locked2(LockedFile);
39 EXPECT_NE(LockFileManager::LFS_Owned, Locked2.getState());
42 // Now that the lock is out of scope, the file should be gone.
43 EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
45 sys::fs::remove_all(StringRef(TmpDir));
48 } // end anonymous namespace