<div dir="ltr">Excellent, thanks! </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 21, 2015 at 5:50 AM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dvyukov<br>
Date: Wed Jan 21 07:50:02 2015<br>
New Revision: 226659<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226659&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226659&view=rev</a><br>
Log:<br>
tsan: remove sleeps from tests<br>
<br>
Even sleep(1) lead to episodical flakes on some machines.<br>
Use an invisible by tsan barrier to enforce required execution order instead.<br>
This makes the tests deterministic and faster.<br>
<br>
<br>
Added:<br>
compiler-rt/trunk/test/tsan/test.h<br>
Removed:<br>
compiler-rt/trunk/test/tsan/process_sleep.h<br>
Modified:<br>
compiler-rt/trunk/test/tsan/atomic_free.cc<br>
compiler-rt/trunk/test/tsan/atomic_free2.cc<br>
compiler-rt/trunk/test/tsan/atomic_norace.cc<br>
compiler-rt/trunk/test/tsan/atomic_race.cc<br>
compiler-rt/trunk/test/tsan/atomic_stack.cc<br>
compiler-rt/trunk/test/tsan/benign_race.cc<br>
compiler-rt/trunk/test/tsan/blacklist2.cc<br>
compiler-rt/trunk/test/tsan/cond_cancel.c<br>
compiler-rt/trunk/test/tsan/cond_race.cc<br>
compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc<br>
compiler-rt/trunk/test/tsan/deep_stack1.cc<br>
compiler-rt/trunk/test/tsan/fd_close_norace.cc<br>
compiler-rt/trunk/test/tsan/fd_location.cc<br>
compiler-rt/trunk/test/tsan/fd_pipe_race.cc<br>
compiler-rt/trunk/test/tsan/fd_stdout_race.cc<br>
compiler-rt/trunk/test/tsan/fork_deadlock.cc<br>
compiler-rt/trunk/test/tsan/fork_multithreaded.cc<br>
compiler-rt/trunk/test/tsan/free_race.c<br>
compiler-rt/trunk/test/tsan/global_race.cc<br>
compiler-rt/trunk/test/tsan/global_race2.cc<br>
compiler-rt/trunk/test/tsan/global_race3.cc<br>
compiler-rt/trunk/test/tsan/halt_on_error.cc<br>
compiler-rt/trunk/test/tsan/ignore_free.cc<br>
compiler-rt/trunk/test/tsan/ignore_malloc.cc<br>
compiler-rt/trunk/test/tsan/ignore_race.cc<br>
compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc<br>
compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc<br>
compiler-rt/trunk/test/tsan/java.h<br>
compiler-rt/trunk/test/tsan/java_finalizer.cc<br>
compiler-rt/trunk/test/tsan/java_lock.cc<br>
compiler-rt/trunk/test/tsan/java_lock_move.cc<br>
compiler-rt/trunk/test/tsan/java_lock_rec.cc<br>
compiler-rt/trunk/test/tsan/java_lock_rec_race.cc<br>
compiler-rt/trunk/test/tsan/java_move_overlap.cc<br>
compiler-rt/trunk/test/tsan/java_move_overlap_race.cc<br>
compiler-rt/trunk/test/tsan/java_race_move.cc<br>
compiler-rt/trunk/test/tsan/java_rwlock.cc<br>
compiler-rt/trunk/test/tsan/java_volatile.cc<br>
compiler-rt/trunk/test/tsan/load_shared_lib.cc<br>
compiler-rt/trunk/test/tsan/malloc_stack.cc<br>
compiler-rt/trunk/test/tsan/map32bit.cc<br>
compiler-rt/trunk/test/tsan/memcpy_race.cc<br>
compiler-rt/trunk/test/tsan/mop_with_offset.cc<br>
compiler-rt/trunk/test/tsan/mop_with_offset2.cc<br>
compiler-rt/trunk/test/tsan/mutexset1.cc<br>
compiler-rt/trunk/test/tsan/mutexset2.cc<br>
compiler-rt/trunk/test/tsan/mutexset3.cc<br>
compiler-rt/trunk/test/tsan/mutexset4.cc<br>
compiler-rt/trunk/test/tsan/mutexset5.cc<br>
compiler-rt/trunk/test/tsan/mutexset6.cc<br>
compiler-rt/trunk/test/tsan/mutexset7.cc<br>
compiler-rt/trunk/test/tsan/mutexset8.cc<br>
compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c<br>
compiler-rt/trunk/test/tsan/race_on_barrier.c<br>
compiler-rt/trunk/test/tsan/race_on_mutex.c<br>
compiler-rt/trunk/test/tsan/race_on_mutex2.c<br>
compiler-rt/trunk/test/tsan/race_on_puts.cc<br>
compiler-rt/trunk/test/tsan/race_on_read.cc<br>
compiler-rt/trunk/test/tsan/race_on_speculative_load.cc<br>
compiler-rt/trunk/test/tsan/race_on_write.cc<br>
compiler-rt/trunk/test/tsan/race_with_finished_thread.cc<br>
compiler-rt/trunk/test/tsan/restore_stack.cc<br>
compiler-rt/trunk/test/tsan/signal_errno.cc<br>
compiler-rt/trunk/test/tsan/signal_malloc.cc<br>
compiler-rt/trunk/test/tsan/signal_recursive.cc<br>
compiler-rt/trunk/test/tsan/signal_sync.cc<br>
compiler-rt/trunk/test/tsan/signal_write.cc<br>
compiler-rt/trunk/test/tsan/simple_race.c<br>
compiler-rt/trunk/test/tsan/simple_race.cc<br>
compiler-rt/trunk/test/tsan/simple_stack.c<br>
compiler-rt/trunk/test/tsan/simple_stack2.cc<br>
compiler-rt/trunk/test/tsan/sleep_sync.cc<br>
compiler-rt/trunk/test/tsan/sleep_sync2.cc<br>
compiler-rt/trunk/test/tsan/stack_race.cc<br>
compiler-rt/trunk/test/tsan/stack_race2.cc<br>
compiler-rt/trunk/test/tsan/stack_sync_reuse.cc<br>
compiler-rt/trunk/test/tsan/suppress_same_address.cc<br>
compiler-rt/trunk/test/tsan/suppressions_race.cc<br>
compiler-rt/trunk/test/tsan/suppressions_race2.cc<br>
compiler-rt/trunk/test/tsan/thread_detach.c<br>
compiler-rt/trunk/test/tsan/thread_leak3.c<br>
compiler-rt/trunk/test/tsan/thread_leak4.c<br>
compiler-rt/trunk/test/tsan/thread_leak5.c<br>
compiler-rt/trunk/test/tsan/thread_name.cc<br>
compiler-rt/trunk/test/tsan/thread_name2.cc<br>
compiler-rt/trunk/test/tsan/tiny_race.c<br>
compiler-rt/trunk/test/tsan/tls_race.cc<br>
compiler-rt/trunk/test/tsan/tls_race2.cc<br>
compiler-rt/trunk/test/tsan/unaligned_race.cc<br>
compiler-rt/trunk/test/tsan/vptr_harmful_race.cc<br>
compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc<br>
compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc<br>
compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc<br>
compiler-rt/trunk/test/tsan/write_in_reader_lock.cc<br>
<br>
Modified: compiler-rt/trunk/test/tsan/atomic_free.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_free.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_free.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/atomic_free.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/atomic_free.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,17 +1,18 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *a) {<br>
__atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int *a = new int(0);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, a);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
delete a;<br>
pthread_join(t, 0);<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/atomic_free2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_free2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_free2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/atomic_free2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/atomic_free2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,18 +1,19 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int *a = new int(0);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, a);<br>
delete a;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/atomic_norace.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_norace.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_norace.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/atomic_norace.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/atomic_norace.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
const int kTestCount = 4;<br>
typedef long long T;<br>
@@ -36,7 +34,8 @@ void *Thread(void *p) {<br>
for (int i = 0; i < kTestCount; i++) {<br>
Test(i, &atomics[i], false);<br>
}<br>
- sleep(2);<br>
+ barrier_wait(&barrier);<br>
+ barrier_wait(&barrier);<br>
for (int i = 0; i < kTestCount; i++) {<br>
fprintf(stderr, "Test %d reverse\n", i);<br>
Test(i, &atomics[kTestCount + i], false);<br>
@@ -45,9 +44,10 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
for (int i = 0; i < kTestCount; i++) {<br>
fprintf(stderr, "Test %d\n", i);<br>
Test(i, &atomics[i], true);<br>
@@ -55,6 +55,7 @@ int main() {<br>
for (int i = 0; i < kTestCount; i++) {<br>
Test(i, &atomics[kTestCount + i], true);<br>
}<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/atomic_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/atomic_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/atomic_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
<br>
const int kTestCount = 4;<br>
typedef long long T;<br>
@@ -36,7 +34,8 @@ void *Thread(void *p) {<br>
for (int i = 0; i < kTestCount; i++) {<br>
Test(i, &atomics[i], false);<br>
}<br>
- sleep(4);<br>
+ barrier_wait(&barrier);<br>
+ barrier_wait(&barrier);<br>
for (int i = 0; i < kTestCount; i++) {<br>
fprintf(stderr, "Test %d reverse\n", i);<br>
Test(i, &atomics[kTestCount + i], false);<br>
@@ -45,9 +44,10 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
for (int i = 0; i < kTestCount; i++) {<br>
fprintf(stderr, "Test %d\n", i);<br>
Test(i, &atomics[i], true);<br>
@@ -55,6 +55,7 @@ int main() {<br>
for (int i = 0; i < kTestCount; i++) {<br>
Test(i, &atomics[kTestCount + i], true);<br>
}<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/atomic_stack.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_stack.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/atomic_stack.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/atomic_stack.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/atomic_stack.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,21 +1,22 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
Global++;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/benign_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/benign_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/benign_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/benign_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/benign_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
int WTFGlobal;<br>
@@ -18,10 +16,12 @@ void WTFAnnotateBenignRaceSized(const ch<br>
void *Thread(void *x) {<br>
Global = 42;<br>
WTFGlobal = 142;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
AnnotateBenignRaceSized(__FILE__, __LINE__,<br>
&Global, sizeof(Global), "Race on Global");<br>
WTFAnnotateBenignRaceSized(__FILE__, __LINE__,<br>
@@ -29,7 +29,7 @@ int main() {<br>
"Race on WTFGlobal");<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 43;<br>
WTFGlobal = 143;<br>
pthread_join(t, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/blacklist2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/blacklist2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/blacklist2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/blacklist2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/blacklist2.cc Wed Jan 21 07:50:02 2015<br>
@@ -5,14 +5,12 @@<br>
<br>
// RUN: %clangxx_tsan -O1 %s -fsanitize-blacklist=%t.blacklist -o %t<br>
// RUN: %deflake %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
// CHECK: ThreadSanitizer: data race<br>
// CHECK: Write of size 4<br>
// CHECK: #0 Thread1{{.*}}blacklist2.cc:[[@LINE+1]]<br>
@@ -35,10 +33,12 @@ void *Blacklisted_Thread2(void *x) {<br>
Global--;<br>
// CHECK: #2 Blacklisted_Thread2{{.*}}blacklist2.cc:[[@LINE+1]]<br>
CallTouchGlobal();<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Blacklisted_Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/cond_cancel.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cond_cancel.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cond_cancel.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/cond_cancel.c (original)<br>
+++ compiler-rt/trunk/test/tsan/cond_cancel.c Wed Jan 21 07:50:02 2015<br>
@@ -2,10 +2,7 @@<br>
// CHECK-NOT: WARNING<br>
// CHECK: OK<br>
<br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
pthread_mutex_t m;<br>
pthread_cond_t c;<br>
@@ -14,6 +11,7 @@ int x;<br>
void *thr1(void *p) {<br>
pthread_mutex_lock(&m);<br>
pthread_cleanup_push((void(*)(void *arg))pthread_mutex_unlock, &m);<br>
+ barrier_wait(&barrier);<br>
while (x == 0)<br>
pthread_cond_wait(&c, &m);<br>
pthread_cleanup_pop(1);<br>
@@ -21,12 +19,15 @@ void *thr1(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
+<br>
pthread_t th;<br>
<br>
pthread_mutex_init(&m, 0);<br>
pthread_cond_init(&c, 0);<br>
<br>
pthread_create(&th, 0, thr1, 0);<br>
+ barrier_wait(&barrier);<br>
sleep(1); // let it block on cond var<br>
pthread_cancel(th);<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/cond_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cond_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cond_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/cond_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/cond_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -3,10 +3,7 @@<br>
// CHECK: ThreadSanitizer: data race<br>
// CHECK: pthread_cond_signal<br>
<br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
struct Ctx {<br>
pthread_mutex_t m;<br>
@@ -20,10 +17,12 @@ void *thr(void *p) {<br>
c->done = true;<br>
pthread_mutex_unlock(&c->m);<br>
pthread_cond_signal(&c->c);<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
Ctx *c = new Ctx();<br>
pthread_mutex_init(&c->m, 0);<br>
pthread_cond_init(&c->c, 0);<br>
@@ -33,8 +32,8 @@ int main() {<br>
while (!c->done)<br>
pthread_cond_wait(&c->c, &c->m);<br>
pthread_mutex_unlock(&c->m);<br>
- // w/o this sleep, it can be reported as use-after-free<br>
- sleep(1);<br>
+ // otherwise it can be reported as use-after-free<br>
+ barrier_wait(&barrier);<br>
delete c;<br>
pthread_join(th, 0);<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/deadlock_detector_stress_test.cc Wed Jan 21 07:50:02 2015<br>
@@ -7,12 +7,9 @@<br>
// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD<br>
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRecursiveMutex<br>
// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC<br>
-#include <pthread.h><br>
+#include "test.h"<br>
#undef NDEBUG<br>
#include <assert.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
#include <new><br>
<br>
#ifndef LockType<br>
@@ -224,7 +221,7 @@ class LockTest {<br>
fprintf(stderr, "Starting Test5\n");<br>
// CHECK: Starting Test5<br>
Init(5);<br>
- RunThreads(&LockTest::Lock_0_1, &LockTest::Lock_1_0);<br>
+ RunThreads(&LockTest::Lock_0_1<true>, &LockTest::Lock_1_0<true>);<br>
// CHECK: WARNING: ThreadSanitizer: lock-order-inversion<br>
// CHECK: Cycle in lock order graph: [[M1:M[0-9]+]] ({{.*}}) => [[M2:M[0-9]+]] ({{.*}}) => [[M1]]<br>
// CHECK: Mutex [[M2]] acquired here while holding mutex [[M1]] in thread [[T1:T[0-9]+]]<br>
@@ -503,8 +500,21 @@ class LockTest {<br>
<br>
private:<br>
void Lock2(size_t l1, size_t l2) { L(l1); L(l2); U(l2); U(l1); }<br>
- void Lock_0_1() { Lock2(0, 1); }<br>
- void Lock_1_0() { sleep(1); Lock2(1, 0); }<br>
+<br>
+ template<bool wait = false><br>
+ void Lock_0_1() {<br>
+ Lock2(0, 1);<br>
+ if (wait)<br>
+ barrier_wait(&barrier);<br>
+ }<br>
+<br>
+ template<bool wait = false><br>
+ void Lock_1_0() {<br>
+ if (wait)<br>
+ barrier_wait(&barrier);<br>
+ Lock2(1, 0);<br>
+ }<br>
+<br>
void Lock1_Loop(size_t i, size_t n_iter) {<br>
for (size_t it = 0; it < n_iter; it++) {<br>
// if ((it & (it - 1)) == 0) fprintf(stderr, "%zd", i);<br>
@@ -569,6 +579,7 @@ class LockTest {<br>
};<br>
<br>
int main(int argc, char **argv) {<br>
+ barrier_init(&barrier, 2);<br>
if (argc > 1)<br>
test_number = atoi(argv[1]);<br>
if (argc > 2)<br>
<br>
Modified: compiler-rt/trunk/test/tsan/deep_stack1.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deep_stack1.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deep_stack1.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/deep_stack1.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/deep_stack1.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s<br>
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
volatile int X;<br>
volatile int N;<br>
@@ -17,13 +15,17 @@ static void foo() {<br>
<br>
void *Thread(void *p) {<br>
#ifdef ORDER1<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
#endif<br>
F();<br>
+#ifdef ORDER2<br>
+ barrier_wait(&barrier);<br>
+#endif<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
N = 50000;<br>
F = foo;<br>
pthread_t t;<br>
@@ -32,9 +34,13 @@ int main() {<br>
pthread_attr_setstacksize(&a, N * 256 + (1 << 20));<br>
pthread_create(&t, &a, Thread, 0);<br>
#ifdef ORDER2<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
#endif<br>
X = 43;<br>
+#ifdef ORDER1<br>
+ barrier_wait(&barrier);<br>
+#endif<br>
+<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fd_close_norace.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_close_norace.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_close_norace.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fd_close_norace.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fd_close_norace.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
#include <fcntl.h><br>
@@ -9,17 +7,19 @@<br>
void *Thread1(void *x) {<br>
int f = open("/dev/random", O_RDONLY);<br>
close(f);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
int f = open("/dev/random", O_RDONLY);<br>
close(f);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fd_location.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_location.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_location.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fd_location.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fd_location.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,23 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int fds[2];<br>
<br>
void *Thread1(void *x) {<br>
write(fds[1], "a", 1);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
close(fds[0]);<br>
close(fds[1]);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pipe(fds);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fd_pipe_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_pipe_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_pipe_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fd_pipe_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fd_pipe_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,23 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int fds[2];<br>
<br>
void *Thread1(void *x) {<br>
write(fds[1], "a", 1);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
close(fds[0]);<br>
close(fds[1]);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pipe(fds);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fd_stdout_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_stdout_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fd_stdout_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fd_stdout_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fd_stdout_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
#include <fcntl.h><br>
@@ -9,7 +7,7 @@<br>
int X;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
int f = open("/dev/random", O_RDONLY);<br>
char buf;<br>
read(f, &buf, 1);<br>
@@ -21,10 +19,12 @@ void *Thread1(void *x) {<br>
void *Thread2(void *x) {<br>
X = 43;<br>
write(STDOUT_FILENO, "a", 1);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fork_deadlock.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_deadlock.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_deadlock.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fork_deadlock.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fork_deadlock.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="atexit_sleep_ms=50" %run %t 2>&1 | FileCheck %s<br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
#include <errno.h><br>
-#include <pthread.h><br>
-#include <unistd.h><br>
#include <sys/types.h><br>
#include <sys/wait.h><br>
<br>
@@ -16,13 +13,14 @@ static void *incrementer(void *p) {<br>
}<br>
<br>
static void *watchdog(void *p) {<br>
- sleep(100);<br>
+ sleep(100); // is not intended to exit<br>
fprintf(stderr, "timed out after 100 seconds\n");<br>
exit(1);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t th1, th2;<br>
pthread_create(&th1, 0, incrementer, 0);<br>
pthread_create(&th2, 0, watchdog, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/fork_multithreaded.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_multithreaded.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/fork_multithreaded.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/fork_multithreaded.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/fork_multithreaded.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,19 +1,21 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE<br>
// RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="die_after_fork=0" %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE<br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
#include <errno.h><br>
-#include <pthread.h><br>
-#include <unistd.h><br>
#include <sys/types.h><br>
#include <sys/wait.h><br>
<br>
static void *sleeper(void *p) {<br>
- sleep(10);<br>
+ sleep(10); // not intended to exit during test<br>
+ return 0;<br>
+}<br>
+<br>
+static void *nop(void *p) {<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t th;<br>
pthread_create(&th, 0, sleeper, 0);<br>
switch (fork()) {<br>
@@ -23,7 +25,7 @@ int main() {<br>
case 0: // child<br>
{<br>
pthread_t th2;<br>
- pthread_create(&th2, 0, sleeper, 0);<br>
+ pthread_create(&th2, 0, nop, 0);<br>
exit(0);<br>
break;<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/free_race.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/free_race.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/free_race.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/free_race.c (original)<br>
+++ compiler-rt/trunk/test/tsan/free_race.c Wed Jan 21 07:50:02 2015<br>
@@ -2,11 +2,7 @@<br>
// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOZUPP<br>
// RUN: TSAN_OPTIONS="suppressions='%s.supp' print_suppressions=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPP<br>
<br>
-#include <pthread.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int *mem;<br>
pthread_mutex_t mtx;<br>
@@ -15,11 +11,12 @@ void *Thread1(void *x) {<br>
pthread_mutex_lock(&mtx);<br>
free(mem);<br>
pthread_mutex_unlock(&mtx);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&mtx);<br>
mem[0] = 42;<br>
pthread_mutex_unlock(&mtx);<br>
@@ -27,6 +24,7 @@ void *Thread2(void *x) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
mem = (int*)malloc(100);<br>
pthread_mutex_init(&mtx, 0);<br>
pthread_t t;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/global_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/global_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/global_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,24 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %T/global_race.cc.exe && %deflake %run %T/global_race.cc.exe | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int GlobalData[10];<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
GlobalData[2] = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// On FreeBSD, the %p conversion specifier works as 0x%x and thus does not<br>
// match to the format used in the diagnotic message.<br>
fprintf(stderr, "addr=0x%012lx\n", (unsigned long) GlobalData);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
GlobalData[2] = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/global_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/global_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/global_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,24 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int x;<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
x = 1;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// On FreeBSD, the %p conversion specifier works as 0x%x and thus does not<br>
// match to the format used in the diagnotic message.<br>
fprintf(stderr, "addr2=0x%012lx\n", (unsigned long) &x);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
x = 0;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/global_race3.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race3.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race3.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/global_race3.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/global_race3.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
namespace XXX {<br>
struct YYY {<br>
@@ -12,18 +9,20 @@ namespace XXX {<br>
}<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
XXX::YYY::ZZZ[0] = 1;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// On FreeBSD, the %p conversion specifier works as 0x%x and thus does not<br>
// match to the format used in the diagnotic message.<br>
fprintf(stderr, "addr3=0x%012lx\n", (unsigned long) XXX::YYY::ZZZ);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
XXX::YYY::ZZZ[0] = 0;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/halt_on_error.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/halt_on_error.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/halt_on_error.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/halt_on_error.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/halt_on_error.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,21 +1,21 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int X;<br>
<br>
void *Thread(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
X = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
fprintf(stderr, "BEFORE\n");<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
X = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
fprintf(stderr, "AFTER\n");<br>
return 0;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/ignore_free.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_free.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_free.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/ignore_free.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/ignore_free.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
extern "C" {<br>
void AnnotateIgnoreReadsBegin(const char *f, int l);<br>
@@ -13,14 +10,16 @@ void AnnotateIgnoreWritesEnd(const char<br>
<br>
void *Thread(void *p) {<br>
*(int*)p = 42;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int *p = new int(0);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, p);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
AnnotateIgnoreReadsBegin(__FILE__, __LINE__);<br>
AnnotateIgnoreWritesBegin(__FILE__, __LINE__);<br>
free(p);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/ignore_malloc.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_malloc.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_malloc.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/ignore_malloc.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/ignore_malloc.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
extern "C" {<br>
void AnnotateIgnoreReadsBegin(const char *f, int l);<br>
@@ -16,7 +13,7 @@ int *g;<br>
void *Thread(void *a) {<br>
int *p = 0;<br>
while ((p = __atomic_load_n(&g, __ATOMIC_RELAXED)) == 0)<br>
- usleep(100);<br>
+ usleep(100); // spin-wait<br>
*p = 42;<br>
return 0;<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/ignore_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/ignore_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/ignore_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
@@ -16,13 +14,15 @@ void *Thread(void *x) {<br>
Global = 42;<br>
AnnotateIgnoreReadsEnd(__FILE__, __LINE__);<br>
AnnotateIgnoreWritesEnd(__FILE__, __LINE__);<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 43;<br>
pthread_join(t, 0);<br>
printf("OK\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/inlined_memcpy_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,24 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
#include <string.h><br>
-#include <unistd.h><br>
<br>
int x[4], z[4];<br>
<br>
void *MemCpyThread(void *a) {<br>
memcpy((int*)a, z, 16);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *MemSetThread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
memset((int*)a, 0, 16);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
// Race on x between memcpy and memset<br>
pthread_create(&t[0], NULL, MemCpyThread, x);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/inlined_memcpy_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,24 +1,23 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
#include <string.h><br>
-#include <unistd.h><br>
<br>
int y[4], z[4];<br>
<br>
void *MemMoveThread(void *a) {<br>
memmove((int*)a, z, 16);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *MemSetThread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
memset((int*)a, 0, 16);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
// Race on y between memmove and memset<br>
pthread_create(&t[0], NULL, MemMoveThread, y);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java.h?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java.h?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java.h (original)<br>
+++ compiler-rt/trunk/test/tsan/java.h Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,4 @@<br>
-#include <pthread.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
extern "C" {<br>
typedef unsigned long jptr; // NOLINT<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_finalizer.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_finalizer.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_finalizer.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_finalizer.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_finalizer.cc Wed Jan 21 07:50:02 2015<br>
@@ -2,13 +2,14 @@<br>
#include "java.h"<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_finalize();<br>
*(int*)p = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -17,6 +18,7 @@ int main() {<br>
pthread_t th;<br>
pthread_create(&th, 0, Thread, (void*)jheap);<br>
*(int*)jheap = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(jheap, kBlockSize);<br>
fprintf(stderr, "DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_lock.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_lock.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_lock.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,12 +1,11 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
#include "java.h"<br>
-#include <unistd.h><br>
<br>
jptr varaddr;<br>
jptr lockaddr;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock(lockaddr);<br>
*(int*)varaddr = 42;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
@@ -14,6 +13,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -26,6 +26,7 @@ int main() {<br>
__tsan_java_mutex_lock(lockaddr);<br>
*(int*)varaddr = 43;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(jheap, kBlockSize);<br>
fprintf(stderr, "DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_lock_move.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_move.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_move.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_lock_move.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_lock_move.cc Wed Jan 21 07:50:02 2015<br>
@@ -7,7 +7,7 @@ jptr varaddr2;<br>
jptr lockaddr2;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock(lockaddr2);<br>
*(int*)varaddr2 = 42;<br>
__tsan_java_mutex_unlock(lockaddr2);<br>
@@ -15,6 +15,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -31,6 +32,7 @@ int main() {<br>
*(int*)varaddr = 43;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
__tsan_java_move(varaddr, varaddr2, kBlockSize);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(varaddr2, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_lock_rec.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_rec.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_rec.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_lock_rec.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_lock_rec.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,6 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
#include "java.h"<br>
-#include <unistd.h><br>
<br>
jptr varaddr;<br>
jptr lockaddr;<br>
@@ -14,7 +13,8 @@ void *Thread(void *p) {<br>
printf("FAILED 0 rec=%d\n", rec);<br>
exit(1);<br>
}<br>
- sleep(2);<br>
+ barrier_wait(&barrier);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock_rec(lockaddr, rec);<br>
if (*(int*)varaddr != 43) {<br>
printf("FAILED 3 var=%d\n", *(int*)varaddr);<br>
@@ -26,6 +26,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -36,7 +37,7 @@ int main() {<br>
lockaddr = jheap + 8;<br>
pthread_t th;<br>
pthread_create(&th, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock(lockaddr);<br>
if (*(int*)varaddr != 42) {<br>
printf("FAILED 1 var=%d\n", *(int*)varaddr);<br>
@@ -44,6 +45,7 @@ int main() {<br>
}<br>
*(int*)varaddr = 43;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(jheap, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_lock_rec_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_rec_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_lock_rec_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_lock_rec_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_lock_rec_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,6 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
#include "java.h"<br>
-#include <unistd.h><br>
<br>
jptr varaddr;<br>
jptr lockaddr;<br>
@@ -15,7 +14,8 @@ void *Thread(void *p) {<br>
exit(1);<br>
}<br>
*(int*)varaddr = 42;<br>
- sleep(2);<br>
+ barrier_wait(&barrier);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock_rec(lockaddr, rec);<br>
__tsan_java_mutex_unlock(lockaddr);<br>
__tsan_java_mutex_unlock(lockaddr);<br>
@@ -24,6 +24,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -34,10 +35,11 @@ int main() {<br>
lockaddr = jheap + 8;<br>
pthread_t th;<br>
pthread_create(&th, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock(lockaddr);<br>
*(int*)varaddr = 43;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(jheap, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_move_overlap.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_move_overlap.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_move_overlap.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_move_overlap.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_move_overlap.cc Wed Jan 21 07:50:02 2015<br>
@@ -13,7 +13,7 @@ jptr lockaddr1_new;<br>
jptr lockaddr2_new;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_lock(lockaddr1_new);<br>
*(char*)varaddr1_new = 43;<br>
__tsan_java_mutex_unlock(lockaddr1_new);<br>
@@ -24,6 +24,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
void *jheap = malloc(kHeapSize);<br>
jheap = (char*)jheap + 8;<br>
@@ -62,6 +63,7 @@ int main(int argc, char **argv) {<br>
__tsan_java_mutex_unlock(lockaddr2_old);<br>
<br>
__tsan_java_move(varaddr1_old, varaddr1_new, kBlockSize);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(varaddr1_new, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_move_overlap_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_move_overlap_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_move_overlap_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_move_overlap_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_move_overlap_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -9,13 +9,14 @@ jptr varaddr1_new;<br>
jptr varaddr2_new;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)varaddr1_new = 43;<br>
*(int*)varaddr2_new = 43;<br>
return 0;<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
void *jheap = malloc(kHeapSize);<br>
jheap = (char*)jheap + 8;<br>
@@ -42,6 +43,7 @@ int main(int argc, char **argv) {<br>
*(int*)varaddr2_old = 43;<br>
<br>
__tsan_java_move(varaddr1_old, varaddr1_new, kBlockSize);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(varaddr1_new, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_race_move.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_race_move.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_race_move.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_race_move.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_race_move.cc Wed Jan 21 07:50:02 2015<br>
@@ -5,12 +5,13 @@ jptr varaddr;<br>
jptr varaddr2;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)varaddr2 = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -23,6 +24,7 @@ int main() {<br>
pthread_create(&th, 0, Thread, 0);<br>
*(int*)varaddr = 43;<br>
__tsan_java_move(varaddr, varaddr2, kBlockSize);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(varaddr2, kBlockSize);<br>
fprintf(stderr, "DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_rwlock.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_rwlock.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_rwlock.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_rwlock.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_rwlock.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,12 +1,11 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
#include "java.h"<br>
-#include <unistd.h><br>
<br>
jptr varaddr;<br>
jptr lockaddr;<br>
<br>
void *Thread(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
__tsan_java_mutex_read_lock(lockaddr);<br>
*(int*)varaddr = 42;<br>
__tsan_java_mutex_read_unlock(lockaddr);<br>
@@ -14,6 +13,7 @@ void *Thread(void *p) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
@@ -26,6 +26,7 @@ int main() {<br>
__tsan_java_mutex_lock(lockaddr);<br>
*(int*)varaddr = 43;<br>
__tsan_java_mutex_unlock(lockaddr);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
__tsan_java_free(jheap, kBlockSize);<br>
printf("DONE\n");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/java_volatile.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_volatile.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_volatile.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/java_volatile.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/java_volatile.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,19 +1,19 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
#include "java.h"<br>
-#include <unistd.h><br>
<br>
jptr varaddr;<br>
jptr lockaddr;<br>
<br>
void *Thread(void *p) {<br>
while (__atomic_load_n((int*)lockaddr, __ATOMIC_RELAXED) == 0)<br>
- usleep(1000);<br>
+ usleep(1000); // spin-wait<br>
__tsan_java_acquire(lockaddr);<br>
*(int*)varaddr = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int const kHeapSize = 1024 * 1024;<br>
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;<br>
__tsan_java_init(jheap, kHeapSize);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/load_shared_lib.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/load_shared_lib.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/load_shared_lib.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/load_shared_lib.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/load_shared_lib.cc Wed Jan 21 07:50:02 2015<br>
@@ -7,35 +7,39 @@<br>
<br>
#ifdef BUILD_SO<br>
<br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int GLOB_SHARED = 0;<br>
<br>
extern "C"<br>
+void init_so() {<br>
+ barrier_init(&barrier, 2);<br>
+}<br>
+<br>
+extern "C"<br>
void *write_from_so(void *unused) {<br>
- if (unused)<br>
- sleep(1);<br>
+ if (unused == 0)<br>
+ barrier_wait(&barrier);<br>
GLOB_SHARED++;<br>
+ if (unused != 0)<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
#else // BUILD_SO<br>
<br>
+#include "test.h"<br>
#include <dlfcn.h><br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
-<br>
#include <string><br>
<br>
int GLOB = 0;<br>
<br>
void *write_glob(void *unused) {<br>
- if (unused)<br>
- sleep(1);<br>
+ if (unused == 0)<br>
+ barrier_wait(&barrier);<br>
GLOB++;<br>
+ if (unused != 0)<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
@@ -48,6 +52,7 @@ void race_two_threads(void *(*access_cal<br>
}<br>
<br>
int main(int argc, char *argv[]) {<br>
+ barrier_init(&barrier, 2);<br>
std::string path = std::string(argv[0]) + std::string("-so.so");<br>
race_two_threads(write_glob);<br>
// CHECK: write_glob<br>
@@ -56,6 +61,9 @@ int main(int argc, char *argv[]) {<br>
printf("error in dlopen(): %s\n", dlerror());<br>
return 1;<br>
}<br>
+ void (*init_so)();<br>
+ *(void **)&init_so = dlsym(lib, "init_so");<br>
+ init_so();<br>
void *(*write_from_so)(void *unused);<br>
*(void **)&write_from_so = dlsym(lib, "write_from_so");<br>
race_two_threads(write_from_so);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/malloc_stack.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/malloc_stack.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/malloc_stack.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/malloc_stack.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/malloc_stack.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,20 +1,21 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
_Atomic(int*) p;<br>
<br>
void *thr(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
int *pp = __c11_atomic_load(&p, __ATOMIC_RELAXED);<br>
*pp = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t th;<br>
pthread_create(&th, 0, thr, p);<br>
__c11_atomic_store(&p, new int, __ATOMIC_RELAXED);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/map32bit.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/map32bit.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/map32bit.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/map32bit.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/map32bit.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
+#include "test.h"<br>
#include <stdint.h><br>
-#include <unistd.h><br>
#include <errno.h><br>
#include <sys/mman.h><br>
<br>
@@ -12,10 +9,12 @@<br>
<br>
void *Thread(void *ptr) {<br>
*(int*)ptr = 42;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
void *ptr = mmap(0, 128 << 10, PROT_READ|PROT_WRITE,<br>
MAP_32BIT|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);<br>
fprintf(stderr, "ptr=%p\n", ptr);<br>
@@ -29,7 +28,7 @@ int main() {<br>
}<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, ptr);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)ptr = 42;<br>
pthread_join(t, 0);<br>
munmap(ptr, 128 << 10);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/memcpy_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/memcpy_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/memcpy_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/memcpy_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/memcpy_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
#include <string.h><br>
-#include <unistd.h><br>
<br>
char *data = new char[10];<br>
char *data1 = new char[10];<br>
@@ -12,17 +9,19 @@ char *data2 = new char[10];<br>
void *Thread1(void *x) {<br>
static volatile int size = 1;<br>
memcpy(data+5, data1, size);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
static volatile int size = 4;<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
memcpy(data+3, data2, size);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
fprintf(stderr, "addr=%p\n", &data[5]);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mop_with_offset.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mop_with_offset.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mop_with_offset.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mop_with_offset.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mop_with_offset.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,23 +1,22 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread1(void *x) {<br>
int *p = (int*)x;<br>
p[0] = 1;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
char *p = (char*)x;<br>
p[2] = 1;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int *data = new int(42);<br>
fprintf(stderr, "ptr1=%p\n", data);<br>
fprintf(stderr, "ptr2=%p\n", (char*)data + 2);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mop_with_offset2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mop_with_offset2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mop_with_offset2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mop_with_offset2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mop_with_offset2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,11 +1,8 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
int *p = (int*)x;<br>
p[0] = 1;<br>
return NULL;<br>
@@ -14,10 +11,12 @@ void *Thread1(void *x) {<br>
void *Thread2(void *x) {<br>
char *p = (char*)x;<br>
p[2] = 1;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int *data = new int(42);<br>
fprintf(stderr, "ptr1=%p\n", data);<br>
fprintf(stderr, "ptr2=%p\n", (char*)data + 2);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset1.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset1.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset1.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset1.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset1.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,13 +1,11 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&mtx);<br>
Global++;<br>
pthread_mutex_unlock(&mtx);<br>
@@ -16,10 +14,12 @@ void *Thread1(void *x) {<br>
<br>
void *Thread2(void *x) {<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1<br>
// CHECK: (mutexes: write [[M1:M[0-9]+]]):<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx;<br>
@@ -10,16 +8,18 @@ void *Thread1(void *x) {<br>
pthread_mutex_lock(&mtx);<br>
Global++;<br>
pthread_mutex_unlock(&mtx);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global--;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T2:<br>
// CHECK: Previous write of size 4 at {{.*}} by thread T1<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset3.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset3.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset3.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset3.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset3.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,14 +1,12 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx1;<br>
pthread_mutex_t mtx2;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&mtx1);<br>
pthread_mutex_lock(&mtx2);<br>
Global++;<br>
@@ -19,10 +17,12 @@ void *Thread1(void *x) {<br>
<br>
void *Thread2(void *x) {<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1<br>
// CHECK: (mutexes: write [[M1:M[0-9]+]], write [[M2:M[0-9]+]]):<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset4.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset4.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset4.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset4.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset4.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx1;<br>
@@ -13,16 +11,18 @@ void *Thread1(void *x) {<br>
Global++;<br>
pthread_mutex_unlock(&mtx2);<br>
pthread_mutex_unlock(&mtx1);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global--;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T2:<br>
// CHECK: Previous write of size 4 at {{.*}} by thread T1<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset5.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset5.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset5.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset5.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset5.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,14 +1,12 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx1;<br>
pthread_mutex_t mtx2;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&mtx1);<br>
Global++;<br>
pthread_mutex_unlock(&mtx1);<br>
@@ -19,10 +17,12 @@ void *Thread2(void *x) {<br>
pthread_mutex_lock(&mtx2);<br>
Global--;<br>
pthread_mutex_unlock(&mtx2);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1<br>
// CHECK: (mutexes: write [[M1:M[0-9]+]]):<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset6.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset6.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset6.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset6.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset6.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t mtx1;<br>
@@ -9,7 +7,7 @@ pthread_spinlock_t mtx2;<br>
pthread_rwlock_t mtx3;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&mtx1);<br>
Global++;<br>
pthread_mutex_unlock(&mtx1);<br>
@@ -24,10 +22,12 @@ void *Thread2(void *x) {<br>
Global--;<br>
pthread_spin_unlock(&mtx2);<br>
pthread_rwlock_unlock(&mtx3);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1<br>
// CHECK: (mutexes: write [[M1:M[0-9]+]]):<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset7.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset7.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset7.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset7.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset7.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,13 +1,11 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
__thread int huge[1024*1024];<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global++;<br>
return NULL;<br>
}<br>
@@ -20,10 +18,12 @@ void *Thread2(void *x) {<br>
pthread_mutex_unlock(mtx);<br>
pthread_mutex_destroy(mtx);<br>
delete mtx;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/mutexset8.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset8.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/mutexset8.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/mutexset8.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/mutexset8.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,13 +1,11 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
pthread_mutex_t *mtx;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(mtx);<br>
Global++;<br>
pthread_mutex_unlock(mtx);<br>
@@ -16,10 +14,12 @@ void *Thread1(void *x) {<br>
<br>
void *Thread2(void *x) {<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1<br>
// CHECK: (mutexes: write [[M1:M[0-9]+]]):<br>
<br>
Removed: compiler-rt/trunk/test/tsan/process_sleep.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/process_sleep.h?rev=226658&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/process_sleep.h?rev=226658&view=auto</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/process_sleep.h (original)<br>
+++ compiler-rt/trunk/test/tsan/process_sleep.h (removed)<br>
@@ -1,7 +0,0 @@<br>
-#include <time.h><br>
-<br>
-static void process_sleep(int sec) {<br>
- clock_t beg = clock();<br>
- while((clock() - beg) / CLOCKS_PER_SEC < sec)<br>
- usleep(100);<br>
-}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c (original)<br>
+++ compiler-rt/trunk/test/tsan/pthread_atfork_deadlock.c Wed Jan 21 07:50:02 2015<br>
@@ -4,14 +4,12 @@<br>
// When the data race was reported, pthread_atfork() handler used to be<br>
// executed which caused another race report in the same thread, which resulted<br>
// in a deadlock.<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int glob = 0;<br>
<br>
void *worker(void *unused) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
glob++;<br>
return NULL;<br>
}<br>
@@ -22,10 +20,12 @@ void atfork() {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_atfork(atfork, NULL, NULL);<br>
pthread_t t;<br>
pthread_create(&t, NULL, worker, NULL);<br>
glob++;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, NULL);<br>
// CHECK: ThreadSanitizer: data race<br>
// CHECK-NOT: ATFORK<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_barrier.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_barrier.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_barrier.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_barrier.c (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_barrier.c Wed Jan 21 07:50:02 2015<br>
@@ -1,25 +1,24 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
pthread_barrier_t B;<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
pthread_barrier_init(&B, 0, 2);<br>
+ barrier_wait(&barrier);<br>
pthread_barrier_wait(&B);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_barrier_wait(&B);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, NULL, Thread1, NULL);<br>
Thread2(0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_mutex.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_mutex.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_mutex.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_mutex.c (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_mutex.c Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
pthread_mutex_t Mtx;<br>
int Global;<br>
@@ -12,11 +9,12 @@ void *Thread1(void *x) {<br>
pthread_mutex_lock(&Mtx);<br>
Global = 42;<br>
pthread_mutex_unlock(&Mtx);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_lock(&Mtx);<br>
Global = 43;<br>
pthread_mutex_unlock(&Mtx);<br>
@@ -24,6 +22,7 @@ void *Thread2(void *x) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
@@ -36,7 +35,7 @@ int main() {<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK-NEXT: Atomic read of size 1 at {{.*}} by thread T2:<br>
// CHECK-NEXT: #0 pthread_mutex_lock<br>
-// CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:20{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:18{{(:3)?}} ({{.*}})<br>
// CHECK: Previous write of size 1 at {{.*}} by thread T1:<br>
// CHECK-NEXT: #0 pthread_mutex_init {{.*}} ({{.*}})<br>
-// CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:11{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:8{{(:3)?}} ({{.*}})<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_mutex2.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_mutex2.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_mutex2.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_mutex2.c (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_mutex2.c Wed Jan 21 07:50:02 2015<br>
@@ -1,21 +1,20 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *x) {<br>
pthread_mutex_lock((pthread_mutex_t*)x);<br>
pthread_mutex_unlock((pthread_mutex_t*)x);<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_mutex_t Mtx;<br>
pthread_mutex_init(&Mtx, 0);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, &Mtx);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_mutex_destroy(&Mtx);<br>
pthread_join(t, 0);<br>
return 0;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_puts.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_puts.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_puts.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_puts.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_puts.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,21 +1,22 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
char s[] = "abracadabra";<br>
<br>
void *Thread0(void *p) {<br>
puts(s);<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
void *Thread1(void *p) {<br>
+ barrier_wait(&barrier);<br>
s[3] = 'z';<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t th[2];<br>
pthread_create(&th[0], 0, Thread0, 0);<br>
pthread_create(&th[1], 0, Thread1, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_read.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_read.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_read.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_read.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_read.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,31 +1,35 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
#include <fcntl.h><br>
-#include <unistd.h><br>
#include <errno.h><br>
<br>
int fd;<br>
char buf;<br>
<br>
-void *Thread(void *x) {<br>
- sleep(1);<br>
+void *Thread1(void *x) {<br>
+ barrier_wait(&barrier);<br>
read(fd, &buf, 1);<br>
return NULL;<br>
}<br>
<br>
+void *Thread2(void *x) {<br>
+ read(fd, &buf, 1);<br>
+ barrier_wait(&barrier);<br>
+ return NULL;<br>
+}<br>
+<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
fd = open("/dev/random", O_RDONLY);<br>
if (fd < 0) {<br>
fprintf(stderr, "failed to open /dev/random (%d)\n", errno);<br>
return 1;<br>
}<br>
pthread_t t[2];<br>
- pthread_create(&t[0], NULL, Thread, NULL);<br>
- pthread_create(&t[1], NULL, Thread, NULL);<br>
+ pthread_create(&t[0], NULL, Thread1, NULL);<br>
+ pthread_create(&t[1], NULL, Thread2, NULL);<br>
pthread_join(t[0], NULL);<br>
pthread_join(t[1], NULL);<br>
close(fd);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_speculative_load.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_speculative_load.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_speculative_load.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_speculative_load.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_speculative_load.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,8 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t | FileCheck %s<br>
// Regtest for <a href="https://code.google.com/p/thread-sanitizer/issues/detail?id=40" target="_blank">https://code.google.com/p/thread-sanitizer/issues/detail?id=40</a><br>
// This is a correct program and tsan should not report a race.<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
+<br>
int g;<br>
__attribute__((noinline))<br>
int foo(int cond) {<br>
@@ -11,17 +10,21 @@ int foo(int cond) {<br>
return g;<br>
return 0;<br>
}<br>
+<br>
void *Thread1(void *p) {<br>
+ barrier_wait(&barrier);<br>
long res = foo((long)p);<br>
- sleep(1);<br>
return (void*) res;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread1, 0);<br>
g = 1;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
printf("PASS\n");<br>
+ // CHECK-NOT: ThreadSanitizer: data race<br>
// CHECK: PASS<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_on_write.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_write.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_on_write.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_on_write.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/race_on_write.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
#include <fcntl.h><br>
@@ -11,7 +9,7 @@ char buf;<br>
<br>
void *Thread1(void *x) {<br>
buf = 1;<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
@@ -21,11 +19,12 @@ void *Thread2(void *x) {<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
fd = open("/dev/null", O_WRONLY);<br>
if (fd < 0) return 1;<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
pthread_join(t[0], NULL);<br>
pthread_join(t[1], NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/race_with_finished_thread.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_with_finished_thread.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/race_with_finished_thread.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/race_with_finished_thread.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/race_with_finished_thread.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <stdio.h><br>
-#include <string.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
// Ensure that we can restore a stack of a finished thread.<br>
<br>
@@ -15,16 +11,19 @@ void __attribute__((noinline)) foobar(in<br>
<br>
void *Thread1(void *x) {<br>
foobar(&g_data);<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
+ sleep(1); // let the thread finish and exit<br>
g_data = 43;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/restore_stack.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/restore_stack.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/restore_stack.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/restore_stack.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/restore_stack.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
volatile int x;<br>
@@ -17,18 +15,21 @@ void *Thread(void *a) {<br>
__atomic_store_n(&x, 1, __ATOMIC_RELEASE);<br>
foo();<br>
data[0]++;<br>
+ if (a != 0)<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
for (int i = 0; i < 50; i++) {<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
pthread_join(t, 0);<br>
}<br>
pthread_t t;<br>
- pthread_create(&t, 0, Thread, 0);<br>
- sleep(5);<br>
+ pthread_create(&t, 0, Thread, (void*)1);<br>
+ barrier_wait(&barrier);<br>
for (int i = 0; i < kSize; i++)<br>
data[i]++;<br>
pthread_join(t, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/signal_errno.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_errno.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_errno.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/signal_errno.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/signal_errno.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,10 +1,7 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
+#include "test.h"<br>
#include <signal.h><br>
#include <sys/types.h><br>
-#include <unistd.h><br>
#include <errno.h><br>
<br>
pthread_t mainth;<br>
@@ -16,12 +13,13 @@ static void MyHandler(int, siginfo_t *s,<br>
}<br>
<br>
static void* sendsignal(void *p) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_kill(mainth, SIGPROF);<br>
return 0;<br>
}<br>
<br>
static __attribute__((noinline)) void loop() {<br>
+ barrier_wait(&barrier);<br>
while (done == 0) {<br>
volatile char *p = (char*)malloc(1);<br>
p[0] = 0;<br>
@@ -31,6 +29,7 @@ static __attribute__((noinline)) void lo<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
mainth = pthread_self();<br>
struct sigaction act = {};<br>
act.sa_sigaction = &MyHandler;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/signal_malloc.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_malloc.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_malloc.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/signal_malloc.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/signal_malloc.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,7 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
+#include "test.h"<br>
#include <signal.h><br>
#include <sys/types.h><br>
-#include <unistd.h><br>
<br>
static void handler(int, siginfo_t*, void*) {<br>
// CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal<br>
@@ -20,7 +18,7 @@ int main() {<br>
act.sa_sigaction = &handler;<br>
sigaction(SIGPROF, &act, 0);<br>
kill(getpid(), SIGPROF);<br>
- sleep(1);<br>
+ sleep(1); // let the signal handler run<br>
return 0;<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/signal_recursive.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_recursive.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_recursive.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/signal_recursive.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/signal_recursive.cc Wed Jan 21 07:50:02 2015<br>
@@ -3,19 +3,13 @@<br>
// Test case for recursive signal handlers, adopted from:<br>
// <a href="https://code.google.com/p/thread-sanitizer/issues/detail?id=71" target="_blank">https://code.google.com/p/thread-sanitizer/issues/detail?id=71</a><br>
<br>
-#include <pthread.h><br>
+#include "test.h"<br>
#include <semaphore.h><br>
#include <signal.h><br>
-#include <unistd.h><br>
#include <errno.h><br>
-#include <stdlib.h><br>
-#include <stdio.h><br>
-<br>
-#include "process_sleep.h"<br>
<br>
static const int kSigSuspend = SIGUSR1;<br>
static const int kSigRestart = SIGUSR2;<br>
-static sigset_t g_suspend_handler_mask;<br>
<br>
static sem_t g_thread_suspend_ack_sem;<br>
<br>
@@ -27,7 +21,7 @@ static void SaveRegistersInStack() {<br>
// Mono walks thread stacks to detect unreferenced objects.<br>
// If last object reference is kept in register the object will be collected<br>
// This is why threads can't be suspended with something like pthread_suspend<br>
-};<br>
+}<br>
<br>
static void fail(const char *what) {<br>
fprintf(stderr, "FAILED: %s (errno=%d)\n", what, errno);<br>
@@ -37,15 +31,19 @@ static void fail(const char *what) {<br>
static void SuspendHandler(int sig) {<br>
int old_errno = errno;<br>
SaveRegistersInStack();<br>
+<br>
+ // Enable kSigRestart handling, tsan disables signals around signal handlers.<br>
+ sigset_t sigset;<br>
+ sigemptyset(&sigset);<br>
+ pthread_sigmask(SIG_SETMASK, &sigset, 0);<br>
+<br>
// Acknowledge that thread is saved and suspended<br>
if (sem_post(&g_thread_suspend_ack_sem) != 0)<br>
fail("sem_post failed");<br>
<br>
- do {<br>
- g_busy_thread_received_restart = false;<br>
- if (sigsuspend(&g_suspend_handler_mask) != -1 || errno != EINTR)<br>
- fail("sigsuspend failed");<br>
- } while (!g_busy_thread_received_restart);<br>
+ // Wait for wakeup signal.<br>
+ while (!g_busy_thread_received_restart)<br>
+ usleep(100); // wait for kSigRestart signal<br>
<br>
// Acknowledge that thread restarted<br>
if (sem_post(&g_thread_suspend_ack_sem) != 0)<br>
@@ -83,21 +81,15 @@ static void StartWorld(pthread_t thread)<br>
static void CollectGarbage(pthread_t thread) {<br>
StopWorld(thread);<br>
// Walk stacks<br>
- process_sleep(1);<br>
StartWorld(thread);<br>
}<br>
<br>
static void Init() {<br>
- if (sigfillset(&g_suspend_handler_mask) != 0)<br>
- fail("sigfillset failed");<br>
- if (sigdelset(&g_suspend_handler_mask, kSigRestart) != 0)<br>
- fail("sigdelset failed");<br>
if (sem_init(&g_thread_suspend_ack_sem, 0, 0) != 0)<br>
fail("sem_init failed");<br>
<br>
struct sigaction act = {};<br>
act.sa_flags = SA_RESTART;<br>
- sigfillset(&act.sa_mask);<br>
act.sa_handler = &SuspendHandler;<br>
if (sigaction(kSigSuspend, &act, NULL) != 0)<br>
fail("sigaction failed");<br>
<br>
Modified: compiler-rt/trunk/test/tsan/signal_sync.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_sync.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_sync.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/signal_sync.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/signal_sync.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,11 +1,8 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
+#include "test.h"<br>
#include <signal.h><br>
#include <sys/types.h><br>
#include <sys/time.h><br>
-#include <unistd.h><br>
#include <errno.h><br>
<br>
volatile int X;<br>
@@ -18,7 +15,7 @@ static void handler(int sig) {<br>
<br>
static void* thr(void *p) {<br>
for (int i = 0; i != 1000; i++)<br>
- usleep(1000);<br>
+ usleep(1000); // process signals<br>
return 0;<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/signal_write.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_write.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_write.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/signal_write.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/signal_write.cc Wed Jan 21 07:50:02 2015<br>
@@ -16,7 +16,7 @@ int main() {<br>
act.sa_sigaction = &handler;<br>
sigaction(SIGPROF, &act, 0);<br>
kill(getpid(), SIGPROF);<br>
- sleep(1);<br>
+ sleep(1); // let the signal handler run, can't use barrier in sig handler<br>
fprintf(stderr, "DONE\n");<br>
return 0;<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/simple_race.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_race.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_race.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/simple_race.c (original)<br>
+++ compiler-rt/trunk/test/tsan/simple_race.c Wed Jan 21 07:50:02 2015<br>
@@ -1,22 +1,22 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 42;<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
Global = 43;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/simple_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/simple_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/simple_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,22 +1,22 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global++;<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/simple_stack.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_stack.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_stack.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/simple_stack.c (original)<br>
+++ compiler-rt/trunk/test/tsan/simple_stack.c Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
@@ -24,13 +22,14 @@ void __attribute__((noinline)) bar2() {<br>
}<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
bar1();<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
bar2();<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
@@ -39,6 +38,7 @@ void StartThread(pthread_t *t, void *(*f<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
StartThread(&t[0], Thread1);<br>
StartThread(&t[1], Thread2);<br>
@@ -49,18 +49,18 @@ int main() {<br>
<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:<br>
-// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:9{{(:3)?}} ({{.*}})<br>
-// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack.c:14{{(:3)?}} ({{.*}})<br>
-// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack.c:28{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:7{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack.c:12{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack.c:26{{(:3)?}} ({{.*}})<br>
// CHECK: Previous read of size 4 at {{.*}} by thread T2:<br>
-// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:18{{(:20)?}} ({{.*}})<br>
-// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:23{{(:3)?}} ({{.*}})<br>
-// CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:33{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:16{{(:20)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:21{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:31{{(:3)?}} ({{.*}})<br>
// CHECK: Thread T1 (tid={{.*}}, running) created by main thread at:<br>
// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})<br>
-// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})<br>
// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})<br>
// CHECK: Thread T2 ({{.*}}) created by main thread at:<br>
// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})<br>
-// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})<br>
+// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})<br>
// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:44{{(:3)?}} ({{.*}})<br>
<br>
Modified: compiler-rt/trunk/test/tsan/simple_stack2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_stack2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_stack2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/simple_stack2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/simple_stack2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %T/simple_stack2.cc.exe && %deflake %run %T/simple_stack2.cc.exe | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
@@ -30,24 +28,26 @@ void __attribute__((noinline)) bar2() {<br>
}<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
bar1();<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, NULL, Thread1, NULL);<br>
bar2();<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, NULL);<br>
}<br>
<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:<br>
-// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:9{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
-// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:16{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
-// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:7{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:14{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:32{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
// CHECK: Previous read of size 4 at {{.*}} by main thread:<br>
-// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:20{{(:22)?}} (simple_stack2.cc.exe+{{.*}})<br>
-// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:29{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
-// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:41{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:18{{(:22)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:27{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
+// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:40{{(:3)?}} (simple_stack2.cc.exe+{{.*}})<br>
<br>
Modified: compiler-rt/trunk/test/tsan/sleep_sync.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/sleep_sync.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/sleep_sync.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/sleep_sync.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/sleep_sync.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,23 +1,25 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int X = 0;<br>
<br>
void MySleep() {<br>
- sleep(1);<br>
+ sleep(1); // the sleep that must appear in the report<br>
}<br>
<br>
void *Thread(void *p) {<br>
+ barrier_wait(&barrier);<br>
MySleep(); // Assume the main thread has done the write.<br>
X = 42;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
X = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
return 0;<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/sleep_sync2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/sleep_sync2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/sleep_sync2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/sleep_sync2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/sleep_sync2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,18 +1,20 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int X = 0;<br>
<br>
void *Thread(void *p) {<br>
X = 42;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
- sleep(1);<br>
+ sleep(1); // must not appear in the report<br>
pthread_create(&t, 0, Thread, 0);<br>
+ barrier_wait(&barrier);<br>
X = 43;<br>
pthread_join(t, 0);<br>
return 0;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/stack_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/stack_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/stack_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,19 +1,19 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)a = 43;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
int Var = 42;<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, &Var);<br>
Var = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/stack_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/stack_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/stack_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,10 +1,8 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread2(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)a = 43;<br>
return 0;<br>
}<br>
@@ -14,11 +12,13 @@ void *Thread(void *a) {<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread2, &Var);<br>
Var = 42;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
pthread_join(t, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/stack_sync_reuse.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_sync_reuse.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/stack_sync_reuse.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/stack_sync_reuse.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/stack_sync_reuse.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,5 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
// Test case <a href="https://code.google.com/p/thread-sanitizer/issues/detail?id=87" target="_blank">https://code.google.com/p/thread-sanitizer/issues/detail?id=87</a><br>
// Tsan sees false HB edge on address pointed to by syncp variable.<br>
@@ -26,7 +23,7 @@ long sink;<br>
<br>
void *Thread(void *x) {<br>
while (__atomic_load_n(&syncp, __ATOMIC_ACQUIRE) == 0)<br>
- usleep(1000);<br>
+ usleep(1000); // spin wait<br>
global = 42;<br>
__atomic_store_n(syncp, 1, __ATOMIC_RELEASE);<br>
__atomic_store_n(&syncp, 0, __ATOMIC_RELAXED);<br>
@@ -39,7 +36,7 @@ void __attribute__((noinline)) foobar()<br>
__atomic_store_n(&s, 0, __ATOMIC_RELAXED);<br>
__atomic_store_n(&syncp, &s, __ATOMIC_RELEASE);<br>
while (__atomic_load_n(&syncp, __ATOMIC_RELAXED) != 0)<br>
- usleep(1000);<br>
+ usleep(1000); // spin wait<br>
}<br>
<br>
void __attribute__((noinline)) barfoo() {<br>
<br>
Modified: compiler-rt/trunk/test/tsan/suppress_same_address.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppress_same_address.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppress_same_address.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/suppress_same_address.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/suppress_same_address.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,11 +1,10 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
volatile int X;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
X = 42;<br>
X = 66;<br>
X = 78;<br>
@@ -16,10 +15,12 @@ void *Thread2(void *x) {<br>
X = 11;<br>
X = 99;<br>
X = 73;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread1, 0);<br>
Thread2(0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/suppressions_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/suppressions_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/suppressions_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,22 +1,22 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 42;<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
Global = 43;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/suppressions_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/suppressions_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/suppressions_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/suppressions_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,22 +1,22 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
Global = 42;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 43;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Added: compiler-rt/trunk/test/tsan/test.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/test.h?rev=226659&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/test.h?rev=226659&view=auto</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/test.h (added)<br>
+++ compiler-rt/trunk/test/tsan/test.h Wed Jan 21 07:50:02 2015<br>
@@ -0,0 +1,31 @@<br>
+#include <pthread.h><br>
+#include <stdlib.h><br>
+#include <stdio.h><br>
+#include <unistd.h><br>
+#include <dlfcn.h><br>
+#include <stddef.h><br>
+<br>
+// TSan-invisible barrier.<br>
+// Tests use it to establish necessary execution order in a way that does not<br>
+// interfere with tsan (does not establish synchronization between threads).<br>
+__typeof(pthread_barrier_wait) *barrier_wait;<br>
+<br>
+void barrier_init(pthread_barrier_t *barrier, unsigned count) {<br>
+ if (barrier_wait == 0) {<br>
+ void *h = dlopen("libpthread.so.0", RTLD_LAZY);<br>
+ if (h == 0) {<br>
+ fprintf(stderr, "failed to dlopen libpthread.so.0, exiting\n");<br>
+ exit(1);<br>
+ }<br>
+ barrier_wait = (__typeof(barrier_wait))dlsym(h, "pthread_barrier_wait");<br>
+ if (barrier_wait == 0) {<br>
+ fprintf(stderr, "failed to resolve pthread_barrier_wait, exiting\n");<br>
+ exit(1);<br>
+ }<br>
+ }<br>
+ pthread_barrier_init(barrier, 0, count);<br>
+}<br>
+<br>
+// Default instance of the barrier, but a test can declare more manually.<br>
+pthread_barrier_t barrier;<br>
+<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_detach.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_detach.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_detach.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_detach.c (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_detach.c Wed Jan 21 07:50:02 2015<br>
@@ -1,16 +1,16 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *x) {<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
pthread_detach(t);<br>
printf("PASS\n");<br>
return 0;<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_leak3.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak3.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak3.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_leak3.c (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_leak3.c Wed Jan 21 07:50:02 2015<br>
@@ -1,15 +1,17 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *x) {<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
+ sleep(1); // wait for the thread to finish and exit<br>
return 0;<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_leak4.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak4.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak4.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_leak4.c (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_leak4.c Wed Jan 21 07:50:02 2015<br>
@@ -1,18 +1,18 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
-#include <stdio.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *x) {<br>
- sleep(10);<br>
+ sleep(100); // leave the thread "running"<br>
return 0;<br>
}<br>
<br>
int main() {<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
- printf("OK\n");<br>
+ printf("DONE\n");<br>
return 0;<br>
}<br>
<br>
+// CHECK: DONE<br>
// CHECK-NOT: WARNING: ThreadSanitizer: thread leak<br>
+<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_leak5.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak5.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_leak5.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_leak5.c (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_leak5.c Wed Jan 21 07:50:02 2015<br>
@@ -1,18 +1,20 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *x) {<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
volatile int N = 5; // prevent loop unrolling<br>
+ barrier_init(&barrier, N + 1);<br>
for (int i = 0; i < N; i++) {<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
}<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
+ sleep(1); // wait for the threads to finish and exit<br>
return 0;<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_name.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_name.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_name.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
#if defined(__linux__)<br>
#define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12)<br>
@@ -18,7 +16,7 @@ extern "C" void AnnotateThreadName(const<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
AnnotateThreadName(__FILE__, __LINE__, "Thread1");<br>
Global++;<br>
return NULL;<br>
@@ -31,10 +29,12 @@ void *Thread2(void *x) {<br>
AnnotateThreadName(__FILE__, __LINE__, "Thread2");<br>
#endif<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/thread_name2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/thread_name2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/thread_name2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
#if defined(__FreeBSD__)<br>
#include <pthread_np.h><br>
@@ -11,7 +9,7 @@<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global++;<br>
return 0;<br>
}<br>
@@ -19,14 +17,17 @@ void *Thread1(void *x) {<br>
void *Thread2(void *x) {<br>
pthread_setname_np(pthread_self(), "foobar2");<br>
Global--;<br>
+ barrier_wait(&barrier);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 3);<br>
pthread_t t[2];<br>
pthread_create(&t[0], 0, Thread1, 0);<br>
pthread_create(&t[1], 0, Thread2, 0);<br>
pthread_setname_np(t[0], "foobar1");<br>
+ barrier_wait(&barrier);<br>
pthread_join(t[0], NULL);<br>
pthread_join(t[1], NULL);<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/tiny_race.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tiny_race.c?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tiny_race.c?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/tiny_race.c (original)<br>
+++ compiler-rt/trunk/test/tsan/tiny_race.c Wed Jan 21 07:50:02 2015<br>
@@ -1,19 +1,20 @@<br>
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
int Global;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Global = 42;<br>
return x;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread1, 0);<br>
Global = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
return Global;<br>
}<br>
<br>
Modified: compiler-rt/trunk/test/tsan/tls_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tls_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tls_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/tls_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/tls_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,19 +1,19 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)a = 43;<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
static __thread int Var = 42;<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, &Var);<br>
Var = 43;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/tls_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tls_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/tls_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/tls_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/tls_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,10 +1,8 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stddef.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
void *Thread2(void *a) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
*(int*)a = 43;<br>
return 0;<br>
}<br>
@@ -14,11 +12,13 @@ void *Thread(void *a) {<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread2, &Var);<br>
Var = 42;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, 0);<br>
pthread_join(t, 0);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/unaligned_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/unaligned_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/unaligned_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/unaligned_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/unaligned_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,9 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <stdlib.h><br>
+#include "test.h"<br>
#include <stdint.h><br>
-#include <unistd.h><br>
<br>
#define NOINLINE __attribute__((noinline))<br>
<br>
@@ -123,15 +120,17 @@ NOINLINE void Test(bool main) {<br>
<br>
void *Thread(void *p) {<br>
(void)p;<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
Test(false);<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t th;<br>
pthread_create(&th, 0, Thread, 0);<br>
Test(true);<br>
+ barrier_wait(&barrier);<br>
pthread_join(th, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/vptr_harmful_race.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/vptr_harmful_race.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/vptr_harmful_race.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
+#include "test.h"<br>
#include <semaphore.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
<br>
struct A {<br>
A() {<br>
@@ -31,16 +29,18 @@ static A *obj = new B;<br>
void *Thread1(void *x) {<br>
obj->F();<br>
obj->Done();<br>
+ barrier_wait(&barrier);<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
delete obj;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/vptr_harmful_race2.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
+#include "test.h"<br>
#include <semaphore.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
<br>
struct A {<br>
A() {<br>
@@ -29,18 +27,20 @@ struct B : A {<br>
static A *obj = new B;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
obj->F();<br>
+ barrier_wait(&barrier);<br>
obj->Done();<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
+ barrier_wait(&barrier);<br>
delete obj;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/vptr_harmful_race3.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,8 +1,6 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
+#include "test.h"<br>
#include <semaphore.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
<br>
struct A {<br>
A() {<br>
@@ -30,18 +28,20 @@ static A *obj = new B;<br>
static void (A::*fn)() = &A::F;<br>
<br>
void *Thread1(void *x) {<br>
- sleep(1);<br>
(obj->*fn)();<br>
+ barrier_wait(&barrier);<br>
obj->Done();<br>
return NULL;<br>
}<br>
<br>
void *Thread2(void *x) {<br>
+ barrier_wait(&barrier);<br>
delete obj;<br>
return NULL;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
pthread_t t[2];<br>
pthread_create(&t[0], NULL, Thread1, NULL);<br>
pthread_create(&t[1], NULL, Thread2, NULL);<br>
<br>
Modified: compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/vptr_harmful_race4.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,7 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <stdio.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
struct A {<br>
virtual void F() {<br>
@@ -17,16 +15,18 @@ struct B : A {<br>
};<br>
<br>
void *Thread(void *x) {<br>
- sleep(1);<br>
+ barrier_wait(&barrier);<br>
((A*)x)->F();<br>
return 0;<br>
}<br>
<br>
int main() {<br>
+ barrier_init(&barrier, 2);<br>
A *obj = new B;<br>
pthread_t t;<br>
pthread_create(&t, 0, Thread, obj);<br>
delete obj;<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
}<br>
<br>
<br>
Modified: compiler-rt/trunk/test/tsan/write_in_reader_lock.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/write_in_reader_lock.cc?rev=226659&r1=226658&r2=226659&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/write_in_reader_lock.cc?rev=226659&r1=226658&r2=226659&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/tsan/write_in_reader_lock.cc (original)<br>
+++ compiler-rt/trunk/test/tsan/write_in_reader_lock.cc Wed Jan 21 07:50:02 2015<br>
@@ -1,6 +1,5 @@<br>
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s<br>
-#include <pthread.h><br>
-#include <unistd.h><br>
+#include "test.h"<br>
<br>
pthread_rwlock_t rwlock;<br>
int GLOB;<br>
@@ -8,14 +7,15 @@ int GLOB;<br>
void *Thread1(void *p) {<br>
(void)p;<br>
pthread_rwlock_rdlock(&rwlock);<br>
+ barrier_wait(&barrier);<br>
// Write under reader lock.<br>
- sleep(1);<br>
GLOB++;<br>
pthread_rwlock_unlock(&rwlock);<br>
return 0;<br>
}<br>
<br>
int main(int argc, char *argv[]) {<br>
+ barrier_init(&barrier, 2);<br>
pthread_rwlock_init(&rwlock, NULL);<br>
pthread_rwlock_rdlock(&rwlock);<br>
pthread_t t;<br>
@@ -23,6 +23,7 @@ int main(int argc, char *argv[]) {<br>
volatile int x = GLOB;<br>
(void)x;<br>
pthread_rwlock_unlock(&rwlock);<br>
+ barrier_wait(&barrier);<br>
pthread_join(t, 0);<br>
pthread_rwlock_destroy(&rwlock);<br>
return 0;<br>
@@ -30,6 +31,6 @@ int main(int argc, char *argv[]) {<br>
<br>
// CHECK: WARNING: ThreadSanitizer: data race<br>
// CHECK: Write of size 4 at {{.*}} by thread T1{{.*}}:<br>
-// CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cc:13<br>
+// CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cc:12<br>
// CHECK: Previous read of size 4 at {{.*}} by main thread{{.*}}:<br>
// CHECK: #0 main {{.*}}write_in_reader_lock.cc:23<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>