aboutsummaryrefslogtreecommitdiff
path: root/third-party
diff options
context:
space:
mode:
authorMartin Braenne <mboehme@google.com>2023-06-13 07:05:15 +0000
committerMartin Braenne <mboehme@google.com>2023-06-15 04:29:00 +0000
commitdfbcee286b9b96751014ebc5ba5290e42796be37 (patch)
tree85576de202f4ffa817001df166dc209d14006894 /third-party
parent0e08374abb2c61a3ae5c24d5f60be3b548da9778 (diff)
downloadllvm-dfbcee286b9b96751014ebc5ba5290e42796be37.zip
llvm-dfbcee286b9b96751014ebc5ba5290e42796be37.tar.gz
llvm-dfbcee286b9b96751014ebc5ba5290e42796be37.tar.bz2
Prevent deadlocks in death tests.
We have recently started seeing deadlocks in death tests while running in an internal test environment. Per the documentation here, there are issues with death tests in the presence of threads: https://github.com/google/googletest/blob/main/docs/advanced.md#death-tests-and-threads To avoid the deadlocks, I first tried appending `DeathTest` to the relevant test suite names, which has the effect of running these test suites before all other tests. However, this did not prevent the deadlocks. This patch therefore uses the option of setting the `death_test_style` flag to `"threadsafe"` (see description in the page linked above under "Death Test Styles"), and this prevents the deadlocks. The documentation notes that the "threadsafe" death test style "trades increased test execution time (potentially dramatically so) for improved thread safety". This is because, to execute a death test, "threadsafe" does a "fork + exec", then re-executes the current test in the child process, whereas the default "fast" death test style does only a fork (on those platforms that support it). However, as we have relatively few death tests, the increased execution time does not make a big difference in total test execution time in my testing. Note that other projects, such as Chromium, also choose to set the "threadsafe" death test style globally: https://source.chromium.org/chromium/chromium/src/+/main:base/test/test_suite.cc;l=367 Reviewed By: hans Differential Revision: https://reviews.llvm.org/D152696
Diffstat (limited to 'third-party')
-rw-r--r--third-party/unittest/UnitTestMain/TestMain.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/third-party/unittest/UnitTestMain/TestMain.cpp b/third-party/unittest/UnitTestMain/TestMain.cpp
index 35ba72b..c1fb848 100644
--- a/third-party/unittest/UnitTestMain/TestMain.cpp
+++ b/third-party/unittest/UnitTestMain/TestMain.cpp
@@ -29,6 +29,10 @@ int main(int argc, char **argv) {
true /* Disable crash reporting */);
}
+ // Use the "threadsafe" test style for death tests -- the "fast" test style
+ // can cause deadlocks.
+ testing::GTEST_FLAG(death_test_style) = "threadsafe";
+
// Initialize both gmock and gtest.
testing::InitGoogleMock(&argc, argv);