OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <fcntl.h> | 5 #include <fcntl.h> |
6 #include <poll.h> | 6 #include <poll.h> |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
10 #include <sys/time.h> | 10 #include <sys/time.h> |
(...skipping 24 matching lines...) Expand all Loading... | |
35 if (task_d != 0 || task_stat.st_nlink < 3) | 35 if (task_d != 0 || task_stat.st_nlink < 3) |
36 return -1; | 36 return -1; |
37 const int num_threads = task_stat.st_nlink - 2; | 37 const int num_threads = task_stat.st_nlink - 2; |
38 return num_threads; | 38 return num_threads; |
39 } | 39 } |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 namespace sandbox { | 43 namespace sandbox { |
44 | 44 |
45 extern bool kAllowForkWithThreads; | |
46 | |
47 bool IsAndroid() { | 45 bool IsAndroid() { |
48 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
49 return true; | 47 return true; |
50 #else | 48 #else |
51 return false; | 49 return false; |
52 #endif | 50 #endif |
53 } | 51 } |
54 | 52 |
55 bool IsArchitectureArm() { | 53 bool IsArchitectureArm() { |
56 #if defined(ARCH_CPU_ARM_FAMILY) | 54 #if defined(ARCH_CPU_ARM_FAMILY) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 const int kNumExpectedThreads = 1; | 114 const int kNumExpectedThreads = 1; |
117 #else | 115 #else |
118 // Under TSAN, there is a special helper thread. It should be completely | 116 // Under TSAN, there is a special helper thread. It should be completely |
119 // invisible to our testing, so we ignore it. It should be ok to fork() | 117 // invisible to our testing, so we ignore it. It should be ok to fork() |
120 // with this thread. It's currently buggy, but it's the best we can do until | 118 // with this thread. It's currently buggy, but it's the best we can do until |
121 // there is a way to delay the start of the thread | 119 // there is a way to delay the start of the thread |
122 // (https://code.google.com/p/thread-sanitizer/issues/detail?id=19). | 120 // (https://code.google.com/p/thread-sanitizer/issues/detail?id=19). |
123 const int kNumExpectedThreads = 2; | 121 const int kNumExpectedThreads = 2; |
124 #endif | 122 #endif |
125 | 123 |
126 // The kernel is at liberty to wake a thread id futex before updating /proc. | 124 // The kernel is at liberty to wake a thread id futex before updating /proc. |
hamaji
2014/05/07 06:52:51
I guess we want to keep this?
jln (very slow on Chromium)
2014/05/08 00:36:37
Ohh yeah absolutely. If a test starts and stops a
| |
127 // If another test running in the same process has stopped a thread, it may | 125 // If another test running in the same process has stopped a thread, it may |
128 // appear as still running in /proc. | 126 // appear as still running in /proc. |
129 // We poll /proc, with an exponential back-off. At most, we'll sleep around | 127 // We poll /proc, with an exponential back-off. At most, we'll sleep around |
130 // 2^iterations nanoseconds in nanosleep(). | 128 // 2^iterations nanoseconds in nanosleep(). |
131 if (!kAllowForkWithThreads) { | 129 for (unsigned int iteration = 0; iteration < 30; iteration++) { |
132 for (unsigned int iteration = 0; iteration < 30; iteration++) { | 130 struct timespec ts = {0, 1L << iteration /* nanoseconds */}; |
133 struct timespec ts = {0, 1L << iteration /* nanoseconds */}; | 131 PCHECK(0 == HANDLE_EINTR(nanosleep(&ts, &ts))); |
134 PCHECK(0 == HANDLE_EINTR(nanosleep(&ts, &ts))); | 132 num_threads = CountThreads(); |
135 num_threads = CountThreads(); | 133 if (kNumExpectedThreads == num_threads) |
136 if (kNumExpectedThreads == num_threads) | 134 break; |
137 break; | |
138 } | |
139 } | 135 } |
140 | 136 |
141 const std::string multiple_threads_error = | 137 ASSERT_EQ(kNumExpectedThreads, num_threads) |
142 "Running sandbox tests with multiple threads " | 138 << "Running sandbox tests with multiple threads " |
143 "is not supported and will make the tests flaky."; | 139 << "is not supported and will make the tests " |
144 if (!kAllowForkWithThreads) { | 140 << "flaky.\n"; |
Mark Seaborn
2014/05/08 15:29:39
Nit: Isn't '\n' unnecessary for ASSERT_EQ? Also f
jln (DO NOT USE THIS)
2014/05/08 16:30:02
Ohh good catch!
hamaji
2014/05/10 08:06:24
Done. After I reverted https://codereview.chromium
| |
145 ASSERT_EQ(kNumExpectedThreads, num_threads) << multiple_threads_error; | |
146 } else { | |
147 if (kNumExpectedThreads != num_threads) | |
148 LOG(ERROR) << multiple_threads_error; | |
149 } | |
150 | |
151 int fds[2]; | 141 int fds[2]; |
152 ASSERT_EQ(0, pipe(fds)); | 142 ASSERT_EQ(0, pipe(fds)); |
153 // Check that our pipe is not on one of the standard file descriptor. | 143 // Check that our pipe is not on one of the standard file descriptor. |
154 SANDBOX_ASSERT(fds[0] > 2 && fds[1] > 2); | 144 SANDBOX_ASSERT(fds[0] > 2 && fds[1] > 2); |
155 | 145 |
156 pid_t pid; | 146 pid_t pid; |
157 ASSERT_LE(0, (pid = fork())); | 147 ASSERT_LE(0, (pid = fork())); |
158 if (!pid) { | 148 if (!pid) { |
159 // In child process | 149 // In child process |
160 // Redirect stderr to our pipe. This way, we can capture all error | 150 // Redirect stderr to our pipe. This way, we can capture all error |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 fflush(stderr); | 281 fflush(stderr); |
292 _exit(kExitWithAssertionFailure); | 282 _exit(kExitWithAssertionFailure); |
293 } | 283 } |
294 | 284 |
295 void UnitTests::IgnoreThisTest() { | 285 void UnitTests::IgnoreThisTest() { |
296 fflush(stderr); | 286 fflush(stderr); |
297 _exit(kIgnoreThisTest); | 287 _exit(kIgnoreThisTest); |
298 } | 288 } |
299 | 289 |
300 } // namespace | 290 } // namespace |
OLD | NEW |