Re-sort all of the includes with ./utils/sort_includes.py so that
[oota-llvm.git] / unittests / Support / LockFileManagerTest.cpp
1 //===- unittests/LockFileManagerTest.cpp - LockFileManager tests ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Support/LockFileManager.h"
11 #include "llvm/Support/FileSystem.h"
12 #include "llvm/Support/Path.h"
13 #include "gtest/gtest.h"
14 #include <memory>
15
16 using namespace llvm;
17
18 namespace {
19
20 TEST(LockFileManagerTest, Basic) {
21   SmallString<64> TmpDir;
22   error_code EC;
23   EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
24   ASSERT_FALSE(EC);
25
26   SmallString<64> LockedFile(TmpDir);
27   sys::path::append(LockedFile, "file.lock");
28
29   {
30     // The lock file should not exist, so we should successfully acquire it.
31     LockFileManager Locked1(LockedFile);
32     EXPECT_EQ(LockFileManager::LFS_Owned, Locked1.getState());
33
34     // Attempting to reacquire the lock should fail.  Waiting on it would cause
35     // deadlock, so don't try that.
36     LockFileManager Locked2(LockedFile);
37     EXPECT_NE(LockFileManager::LFS_Owned, Locked2.getState());
38   }
39
40   // Now that the lock is out of scope, the file should be gone.
41   EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
42
43   sys::fs::remove_all(StringRef(TmpDir));
44 }
45
46 } // end anonymous namespace