summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/linux/tests/main.cc3
-rw-r--r--sandbox/linux/tests/unit_tests.cc29
2 files changed, 22 insertions, 10 deletions
diff --git a/sandbox/linux/tests/main.cc b/sandbox/linux/tests/main.cc
index 9ee384d..a736ea2 100644
--- a/sandbox/linux/tests/main.cc
+++ b/sandbox/linux/tests/main.cc
@@ -10,6 +10,9 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace sandbox {
+
+extern const bool kAllowForkWithThreads = false;
+
namespace {
// Check for leaks in our tests.
diff --git a/sandbox/linux/tests/unit_tests.cc b/sandbox/linux/tests/unit_tests.cc
index 81079b5..6f9c28a 100644
--- a/sandbox/linux/tests/unit_tests.cc
+++ b/sandbox/linux/tests/unit_tests.cc
@@ -42,6 +42,8 @@ int CountThreads() {
namespace sandbox {
+extern bool kAllowForkWithThreads;
+
bool IsAndroid() {
#if defined(OS_ANDROID)
return true;
@@ -126,18 +128,25 @@ void UnitTests::RunTestInProcess(UnitTests::Test test,
// appear as still running in /proc.
// We poll /proc, with an exponential back-off. At most, we'll sleep around
// 2^iterations nanoseconds in nanosleep().
- for (unsigned int iteration = 0; iteration < 30; iteration++) {
- struct timespec ts = {0, 1L << iteration /* nanoseconds */};
- PCHECK(0 == HANDLE_EINTR(nanosleep(&ts, &ts)));
- num_threads = CountThreads();
- if (kNumExpectedThreads == num_threads)
- break;
+ if (!kAllowForkWithThreads) {
+ for (unsigned int iteration = 0; iteration < 30; iteration++) {
+ struct timespec ts = {0, 1L << iteration /* nanoseconds */};
+ PCHECK(0 == HANDLE_EINTR(nanosleep(&ts, &ts)));
+ num_threads = CountThreads();
+ if (kNumExpectedThreads == num_threads)
+ break;
+ }
+ }
+
+ const std::string multiple_threads_error =
+ "Running sandbox tests with multiple threads "
+ "is not supported and will make the tests flaky.";
+ if (!kAllowForkWithThreads) {
+ ASSERT_EQ(kNumExpectedThreads, num_threads) << multiple_threads_error;
+ } else {
+ LOG(ERROR) << multiple_threads_error;
}
- ASSERT_EQ(kNumExpectedThreads, num_threads)
- << "Running sandbox tests with multiple threads "
- << "is not supported and will make the tests "
- << "flaky.\n";
int fds[2];
ASSERT_EQ(0, pipe(fds));
// Check that our pipe is not on one of the standard file descriptor.