[llvm] [FileSystem] Allow exclusive file lock (PR #114098)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 09:46:56 PDT 2025


================
@@ -583,10 +583,14 @@ TEST_F(ProgramEnvTest, TestLockFileExclusive) {
     int FD2;
     ASSERT_NO_ERROR(fs::openFileForReadWrite(LockedFile, FD2,
                                              fs::CD_OpenExisting, fs::OF_None));
+    // File should be non-exclusive locked. Try acquire exclusive lock will fail
+    // but non-exclusive will succeed.
+    EXPECT_TRUE(
+        fs::tryLockFile(FD2, std::chrono::seconds(0), /*Exclusive=*/true));
+
+    EXPECT_FALSE(
+        fs::tryLockFile(FD2, std::chrono::seconds(0), /*Exclusive=*/false));
----------------
dwblaikie wrote:

I wonder how other unit tests test this sort of case (an expected success llvm::Error) - specifically, if this /is/ a failure, then the EXPECT will fail, but the llvm::Error will crash during its dtor because the error information won't have been insepcted. In that crash/fault it'll print out the error information - so it'll be useful for a developer, they'll see what Error did occur. But the test case will have crashed, rather than failing/reporting a failure elegantly. I wonder if there's a cliche/pattern we have for failing informatively, but tidily as well?

https://github.com/llvm/llvm-project/pull/114098


More information about the llvm-commits mailing list