summaryrefslogtreecommitdiffstats
path: root/clang/unittests/DirectoryWatcher
diff options
context:
space:
mode:
authorPuyan Lotfi <puyan@puyan.org>2019-08-06 05:12:23 +0000
committerPuyan Lotfi <puyan@puyan.org>2019-08-06 05:12:23 +0000
commitef74924fc75b32511057b06bc28c08f6419b71ba (patch)
tree5f659e8ad2848fdc9b7c385c50b221cf5245e965 /clang/unittests/DirectoryWatcher
parentd099c893919ccb191af8e39351b4dc8979a25f94 (diff)
downloadbcm5719-llvm-ef74924fc75b32511057b06bc28c08f6419b71ba.tar.gz
bcm5719-llvm-ef74924fc75b32511057b06bc28c08f6419b71ba.zip
[clang][DirectoryWatcher] Adding llvm::Expected error handling to create.
Prior to this patch Unix style errno error reporting from the inotify layer was used by DirectoryWatcher::create to simply return a nullptr on error. This would generally be ok, except that in LLVM we have much more robust error reporting through the facilities of llvm::Expected. The other critical thing I stumbled across was that the unit tests for DirectoryWatcher were not failing abruptly when inotify_init() was reporting an error, but would continue with the testing and eventually hit a deadlock in a pathological machine state (ie in the unit test, the return nullptr on ::create was ignored). Generally this pathological state never happens on any build bot, so it is totally understandable that it was overlooked, but on a Linux desktop running a dubious desktop environment (which I will not name) there is a chance that said desktop environment could use up enough inotify instances to exceed the user's limit. These are the conditions that led me to hit the deadlock I am addressing in this patch with more robust error handling. With the new llvm::Expected error handling when your system runs out of inotify instances for your user, the unit test will be forced to handle the error or crash and report the issue to the user instead of weirdly deadlocking on a condition variable wait. Differential Revision: https://reviews.llvm.org/D65704 llvm-svn: 367979
Diffstat (limited to 'clang/unittests/DirectoryWatcher')
-rw-r--r--clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
index 52a69616057..14ef3460327 100644
--- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -284,6 +284,7 @@ TEST(DirectoryWatcherTest, InitialScanSync) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
checkEventualResultWithTimeout(TestConsumer);
}
@@ -315,6 +316,7 @@ TEST(DirectoryWatcherTest, InitialScanAsync) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/false);
+ if (!DW) return;
checkEventualResultWithTimeout(TestConsumer);
}
@@ -335,6 +337,7 @@ TEST(DirectoryWatcherTest, AddFiles) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
fixture.addFile("a");
fixture.addFile("b");
@@ -360,6 +363,7 @@ TEST(DirectoryWatcherTest, ModifyFile) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
// modify the file
{
@@ -390,6 +394,7 @@ TEST(DirectoryWatcherTest, DeleteFile) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
fixture.deleteFile("a");
@@ -411,6 +416,7 @@ TEST(DirectoryWatcherTest, DeleteWatchedDir) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
remove_directories(fixture.TestWatchedDir);
@@ -431,6 +437,7 @@ TEST(DirectoryWatcherTest, InvalidatedWatcher) {
TestConsumer.consume(Events, IsInitial);
},
/*waitForInitialSync=*/true);
+ if (!DW) return;
} // DW is destructed here.
checkEventualResultWithTimeout(TestConsumer);
OpenPOWER on IntegriCloud