summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-05-30 14:08:51 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-05-30 14:08:51 +0000
commit64bff329e459bd3b1886447b25c5787f6eff93db (patch)
tree202a5c8e5d8f7ede0fedf4f2e4f1457731ecedee
parent2ff56e76c25aea0ee68c607fb8d7479caddb52ab (diff)
downloadcompiler-rt-64bff329e459bd3b1886447b25c5787f6eff93db.tar.gz
tsan: make positive tests more robust
Add a script that is used to deflake inherently flaky tsan tests. It is invoked from lit tests as: %deflake %run %t The script runs the target program up to 10 times, until it produces a tsan warning. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209898 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/tsan/atomic_free.cc2
-rw-r--r--test/tsan/atomic_free2.cc2
-rw-r--r--test/tsan/atomic_race.cc2
-rw-r--r--test/tsan/atomic_stack.cc2
-rw-r--r--test/tsan/cond_race.cc2
-rw-r--r--test/tsan/deadlock_detector_stress_test.cc10
-rw-r--r--test/tsan/deep_stack1.cc4
-rwxr-xr-xtest/tsan/deflake.bash17
-rw-r--r--test/tsan/fd_location.cc2
-rw-r--r--test/tsan/fd_pipe_race.cc2
-rw-r--r--test/tsan/fd_stdout_race.cc2
-rw-r--r--test/tsan/free_race.c2
-rw-r--r--test/tsan/free_race2.c2
-rw-r--r--test/tsan/global_race.cc22
-rw-r--r--test/tsan/global_race2.cc26
-rw-r--r--test/tsan/global_race3.cc30
-rw-r--r--test/tsan/halt_on_error.cc2
-rw-r--r--test/tsan/heap_race.cc2
-rw-r--r--test/tsan/ignore_lib0.cc2
-rw-r--r--test/tsan/ignore_lib1.cc2
-rw-r--r--test/tsan/ignore_lib2.cc2
-rw-r--r--test/tsan/ignore_lib3.cc2
-rw-r--r--test/tsan/ignore_sync.cc2
-rw-r--r--test/tsan/inlined_memcpy_race.cc21
-rw-r--r--test/tsan/inlined_memcpy_race2.cc38
-rw-r--r--test/tsan/java_lock_rec_race.cc2
-rw-r--r--test/tsan/java_race.cc2
-rw-r--r--test/tsan/java_race_move.cc2
-rw-r--r--test/tsan/lit.cfg2
-rw-r--r--test/tsan/load_shared_lib.cc2
-rw-r--r--test/tsan/longjmp3.cc2
-rw-r--r--test/tsan/longjmp4.cc2
-rw-r--r--test/tsan/malloc_hook.cc2
-rw-r--r--test/tsan/malloc_stack.cc2
-rw-r--r--test/tsan/memcpy_race.cc2
-rw-r--r--test/tsan/mop_with_offset.cc2
-rw-r--r--test/tsan/mop_with_offset2.cc2
-rw-r--r--test/tsan/mutex_bad_read_lock.cc2
-rw-r--r--test/tsan/mutex_bad_read_unlock.cc2
-rw-r--r--test/tsan/mutex_bad_unlock.cc2
-rw-r--r--test/tsan/mutex_destroy_locked.cc2
-rw-r--r--test/tsan/mutex_double_lock.cc2
-rw-r--r--test/tsan/mutex_robust2.cc2
-rw-r--r--test/tsan/mutexset1.cc2
-rw-r--r--test/tsan/mutexset2.cc2
-rw-r--r--test/tsan/mutexset3.cc2
-rw-r--r--test/tsan/mutexset4.cc2
-rw-r--r--test/tsan/mutexset5.cc2
-rw-r--r--test/tsan/mutexset6.cc2
-rw-r--r--test/tsan/mutexset7.cc2
-rw-r--r--test/tsan/mutexset8.cc2
-rw-r--r--test/tsan/pthread_atfork_deadlock.c2
-rw-r--r--test/tsan/race_on_barrier.c2
-rw-r--r--test/tsan/race_on_barrier2.c2
-rw-r--r--test/tsan/race_on_heap.cc4
-rw-r--r--test/tsan/race_on_mutex.c2
-rw-r--r--test/tsan/race_on_mutex2.c2
-rw-r--r--test/tsan/race_on_read.cc2
-rw-r--r--test/tsan/race_on_write.cc2
-rw-r--r--test/tsan/race_with_finished_thread.cc2
-rw-r--r--test/tsan/signal_errno.cc2
-rw-r--r--test/tsan/signal_malloc.cc2
-rw-r--r--test/tsan/sigsuspend.cc2
-rw-r--r--test/tsan/simple_race.c3
-rw-r--r--test/tsan/simple_race.cc2
-rw-r--r--test/tsan/simple_stack.c2
-rw-r--r--test/tsan/simple_stack2.cc2
-rw-r--r--test/tsan/sleep_sync.cc2
-rw-r--r--test/tsan/sleep_sync2.cc2
-rw-r--r--test/tsan/stack_race.cc2
-rw-r--r--test/tsan/stack_race2.cc2
-rw-r--r--test/tsan/static_init3.cc2
-rw-r--r--test/tsan/suppress_same_address.cc2
-rw-r--r--test/tsan/suppress_same_stacks.cc2
-rw-r--r--test/tsan/thread_end_with_ignore.cc2
-rw-r--r--test/tsan/thread_end_with_ignore2.cc2
-rw-r--r--test/tsan/thread_end_with_ignore3.cc2
-rw-r--r--test/tsan/thread_leak3.c2
-rw-r--r--test/tsan/thread_leak5.c2
-rw-r--r--test/tsan/thread_name.cc2
-rw-r--r--test/tsan/thread_name2.cc2
-rw-r--r--test/tsan/tiny_race.c2
-rw-r--r--test/tsan/tls_race.cc2
-rw-r--r--test/tsan/tls_race2.cc2
-rw-r--r--test/tsan/unaligned_race.cc2
-rw-r--r--test/tsan/vptr_harmful_race.cc2
-rw-r--r--test/tsan/vptr_harmful_race2.cc2
-rw-r--r--test/tsan/vptr_harmful_race3.cc2
-rw-r--r--test/tsan/write_in_reader_lock.cc2
89 files changed, 206 insertions, 127 deletions
diff --git a/test/tsan/atomic_free.cc b/test/tsan/atomic_free.cc
index c36b8fb36..1dcf887c4 100644
--- a/test/tsan/atomic_free.cc
+++ b/test/tsan/atomic_free.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/atomic_free2.cc b/test/tsan/atomic_free2.cc
index 11204ba77..c50be6bba 100644
--- a/test/tsan/atomic_free2.cc
+++ b/test/tsan/atomic_free2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/atomic_race.cc b/test/tsan/atomic_race.cc
index e64ef96ed..ca444b42b 100644
--- a/test/tsan/atomic_race.cc
+++ b/test/tsan/atomic_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
diff --git a/test/tsan/atomic_stack.cc b/test/tsan/atomic_stack.cc
index d28b5b962..7e3176f8e 100644
--- a/test/tsan/atomic_stack.cc
+++ b/test/tsan/atomic_stack.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/cond_race.cc b/test/tsan/cond_race.cc
index 375bd920a..fa42fafca 100644
--- a/test/tsan/cond_race.cc
+++ b/test/tsan/cond_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
// CHECK-NOT: unlock of unlocked mutex
// CHECK: ThreadSanitizer: data race
// CHECK: pthread_cond_signal
diff --git a/test/tsan/deadlock_detector_stress_test.cc b/test/tsan/deadlock_detector_stress_test.cc
index ac9fcbd5e..53624782e 100644
--- a/test/tsan/deadlock_detector_stress_test.cc
+++ b/test/tsan/deadlock_detector_stress_test.cc
@@ -1,12 +1,12 @@
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
-// TSAN_OPTIONS="detect_deadlocks=1 second_deadlock_stack=1" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
+// TSAN_OPTIONS="detect_deadlocks=1 second_deadlock_stack=1" %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadSpinLock
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRecursiveMutex
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
#include <pthread.h>
#undef NDEBUG
#include <assert.h>
diff --git a/test/tsan/deep_stack1.cc b/test/tsan/deep_stack1.cc
index 617f102b1..1d00a0e85 100644
--- a/test/tsan/deep_stack1.cc
+++ b/test/tsan/deep_stack1.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/deflake.bash b/test/tsan/deflake.bash
new file mode 100755
index 000000000..9731fa53e
--- /dev/null
+++ b/test/tsan/deflake.bash
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# This script is used to deflake inherently flaky tsan tests.
+# It is invoked from lit tests as:
+# %deflake mybinary
+# which is then substituted by lit to:
+# $(dirname %s)/deflake.bash mybinary
+# The script runs the target program up to 10 times,
+# until it fails (i.e. produces a race report).
+
+for i in $(seq 1 10); do
+ OUT=`$@ 2>&1`
+ if [[ $? != 0 ]]; then
+ echo "$OUT"
+ exit 0
+ fi
+done
+exit 1
diff --git a/test/tsan/fd_location.cc b/test/tsan/fd_location.cc
index ebe33be75..535329e06 100644
--- a/test/tsan/fd_location.cc
+++ b/test/tsan/fd_location.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/fd_pipe_race.cc b/test/tsan/fd_pipe_race.cc
index 384cafa19..88c4ed4aa 100644
--- a/test/tsan/fd_pipe_race.cc
+++ b/test/tsan/fd_pipe_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/fd_stdout_race.cc b/test/tsan/fd_stdout_race.cc
index 47f3c6f6c..d6a2c7c79 100644
--- a/test/tsan/fd_stdout_race.cc
+++ b/test/tsan/fd_stdout_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/free_race.c b/test/tsan/free_race.c
index 040f22334..663d7bcf2 100644
--- a/test/tsan/free_race.c
+++ b/test/tsan/free_race.c
@@ -1,5 +1,5 @@
// RUN: %clang_tsan -O1 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOZUPP
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOZUPP
// RUN: TSAN_OPTIONS="suppressions=%s.supp print_suppressions=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPP
#include <pthread.h>
diff --git a/test/tsan/free_race2.c b/test/tsan/free_race2.c
index 2b979f311..de6b2ae1f 100644
--- a/test/tsan/free_race2.c
+++ b/test/tsan/free_race2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <stdlib.h>
void __attribute__((noinline)) foo(int *mem) {
diff --git a/test/tsan/global_race.cc b/test/tsan/global_race.cc
index d28700cbc..224ab227e 100644
--- a/test/tsan/global_race.cc
+++ b/test/tsan/global_race.cc
@@ -1,44 +1,26 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
int GlobalData[10];
-int x;
-namespace XXX {
- struct YYY {
- static int ZZZ[10];
- };
- int YYY::ZZZ[10];
-}
void *Thread(void *a) {
sleep(1);
GlobalData[2] = 42;
- x = 1;
- XXX::YYY::ZZZ[0] = 1;
return 0;
}
int main() {
fprintf(stderr, "addr=%p\n", GlobalData);
- fprintf(stderr, "addr2=%p\n", &x);
- fprintf(stderr, "addr3=%p\n", XXX::YYY::ZZZ);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
GlobalData[2] = 43;
- x = 0;
- XXX::YYY::ZZZ[0] = 0;
pthread_join(t, 0);
}
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
-// CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]]
-// CHECK: addr3=[[ADDR3:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] ({{.*}}+0x{{[0-9,a-f]+}})
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'x' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}})
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'XXX::YYY::ZZZ' of size 40 at [[ADDR3]] ({{.*}}+0x{{[0-9,a-f]+}})
+
diff --git a/test/tsan/global_race2.cc b/test/tsan/global_race2.cc
new file mode 100644
index 000000000..b8352ba52
--- /dev/null
+++ b/test/tsan/global_race2.cc
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+
+int x;
+
+void *Thread(void *a) {
+ sleep(1);
+ x = 1;
+ return 0;
+}
+
+int main() {
+ fprintf(stderr, "addr2=%p\n", &x);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ x = 0;
+ pthread_join(t, 0);
+}
+
+// CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is global 'x' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}})
+
diff --git a/test/tsan/global_race3.cc b/test/tsan/global_race3.cc
new file mode 100644
index 000000000..e37bf78b7
--- /dev/null
+++ b/test/tsan/global_race3.cc
@@ -0,0 +1,30 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+
+namespace XXX {
+ struct YYY {
+ static int ZZZ[10];
+ };
+ int YYY::ZZZ[10];
+}
+
+void *Thread(void *a) {
+ sleep(1);
+ XXX::YYY::ZZZ[0] = 1;
+ return 0;
+}
+
+int main() {
+ fprintf(stderr, "addr3=%p\n", XXX::YYY::ZZZ);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ XXX::YYY::ZZZ[0] = 0;
+ pthread_join(t, 0);
+}
+
+// CHECK: addr3=[[ADDR3:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is global 'XXX::YYY::ZZZ' of size 40 at [[ADDR3]] ({{.*}}+0x{{[0-9,a-f]+}})
diff --git a/test/tsan/halt_on_error.cc b/test/tsan/halt_on_error.cc
index 457480178..3c55c60a4 100644
--- a/test/tsan/halt_on_error.cc
+++ b/test/tsan/halt_on_error.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/heap_race.cc b/test/tsan/heap_race.cc
index 63591e07b..c3da68f42 100644
--- a/test/tsan/heap_race.cc
+++ b/test/tsan/heap_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
diff --git a/test/tsan/ignore_lib0.cc b/test/tsan/ignore_lib0.cc
index d62aa99dc..fe1a35558 100644
--- a/test/tsan/ignore_lib0.cc
+++ b/test/tsan/ignore_lib0.cc
@@ -1,7 +1,7 @@
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib0.so
// RUN: %clangxx_tsan -O1 %s -L%T -lignore_lib0 -o %t
// RUN: echo running w/o suppressions:
-// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPP
+// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP
// RUN: echo running with suppressions:
// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
diff --git a/test/tsan/ignore_lib1.cc b/test/tsan/ignore_lib1.cc
index b848350d7..30a9994b9 100644
--- a/test/tsan/ignore_lib1.cc
+++ b/test/tsan/ignore_lib1.cc
@@ -1,7 +1,7 @@
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib1.so
// RUN: %clangxx_tsan -O1 %s -o %t
// RUN: echo running w/o suppressions:
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPP
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP
// RUN: echo running with suppressions:
// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
diff --git a/test/tsan/ignore_lib2.cc b/test/tsan/ignore_lib2.cc
index 7467ec0f2..23a0872fe 100644
--- a/test/tsan/ignore_lib2.cc
+++ b/test/tsan/ignore_lib2.cc
@@ -1,7 +1,7 @@
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_0.so
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_1.so
// RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %deflake %run %t | FileCheck %s
// Tests that called_from_lib suppression matched against 2 libraries
// causes program crash (this is not supported).
diff --git a/test/tsan/ignore_lib3.cc b/test/tsan/ignore_lib3.cc
index 6a5f5ccea..137109ea6 100644
--- a/test/tsan/ignore_lib3.cc
+++ b/test/tsan/ignore_lib3.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib3.so
// RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %deflake %run %t | FileCheck %s
// Tests that unloading of a library matched against called_from_lib suppression
// causes program crash (this is not supported).
diff --git a/test/tsan/ignore_sync.cc b/test/tsan/ignore_sync.cc
index ae6edaea0..ae24a8c49 100644
--- a/test/tsan/ignore_sync.cc
+++ b/test/tsan/ignore_sync.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
diff --git a/test/tsan/inlined_memcpy_race.cc b/test/tsan/inlined_memcpy_race.cc
index 12f82d264..a95576a83 100644
--- a/test/tsan/inlined_memcpy_race.cc
+++ b/test/tsan/inlined_memcpy_race.cc
@@ -1,22 +1,17 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-int x[4], y[4], z[4];
+int x[4], z[4];
void *MemCpyThread(void *a) {
memcpy((int*)a, z, 16);
return NULL;
}
-void *MemMoveThread(void *a) {
- memmove((int*)a, z, 16);
- return NULL;
-}
-
void *MemSetThread(void *a) {
sleep(1);
memset((int*)a, 0, 16);
@@ -30,12 +25,6 @@ int main() {
pthread_create(&t[1], NULL, MemSetThread, x);
pthread_join(t[0], NULL);
pthread_join(t[1], NULL);
- // Race on y between memmove and memset
- pthread_create(&t[0], NULL, MemMoveThread, y);
- pthread_create(&t[1], NULL, MemSetThread, y);
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
-
printf("PASS\n");
return 0;
}
@@ -47,9 +36,3 @@ int main() {
// CHECK: #0 memcpy
// CHECK: #1 MemCpyThread
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: #0 memset
-// CHECK: #1 MemSetThread
-// CHECK: Previous write
-// CHECK: #0 memmove
-// CHECK: #1 MemMoveThread
diff --git a/test/tsan/inlined_memcpy_race2.cc b/test/tsan/inlined_memcpy_race2.cc
new file mode 100644
index 000000000..63b560f02
--- /dev/null
+++ b/test/tsan/inlined_memcpy_race2.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int y[4], z[4];
+
+void *MemMoveThread(void *a) {
+ memmove((int*)a, z, 16);
+ return NULL;
+}
+
+void *MemSetThread(void *a) {
+ sleep(1);
+ memset((int*)a, 0, 16);
+ return NULL;
+}
+
+int main() {
+ pthread_t t[2];
+ // Race on y between memmove and memset
+ pthread_create(&t[0], NULL, MemMoveThread, y);
+ pthread_create(&t[1], NULL, MemSetThread, y);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+
+ printf("PASS\n");
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: #0 memset
+// CHECK: #1 MemSetThread
+// CHECK: Previous write
+// CHECK: #0 memmove
+// CHECK: #1 MemMoveThread
diff --git a/test/tsan/java_lock_rec_race.cc b/test/tsan/java_lock_rec_race.cc
index c802b9e77..af308d7b7 100644
--- a/test/tsan/java_lock_rec_race.cc
+++ b/test/tsan/java_lock_rec_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "java.h"
#include <unistd.h>
diff --git a/test/tsan/java_race.cc b/test/tsan/java_race.cc
index 27b5c7fb6..10aefdbaf 100644
--- a/test/tsan/java_race.cc
+++ b/test/tsan/java_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "java.h"
void *Thread(void *p) {
diff --git a/test/tsan/java_race_move.cc b/test/tsan/java_race_move.cc
index b7446665a..45876a034 100644
--- a/test/tsan/java_race_move.cc
+++ b/test/tsan/java_race_move.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "java.h"
jptr varaddr;
diff --git a/test/tsan/lit.cfg b/test/tsan/lit.cfg
index 7b7c2bb71..f7051b3b6 100644
--- a/test/tsan/lit.cfg
+++ b/test/tsan/lit.cfg
@@ -57,6 +57,8 @@ config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxf
# Define CHECK-%os to check for OS-dependent output.
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
+config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) )
+
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
diff --git a/test/tsan/load_shared_lib.cc b/test/tsan/load_shared_lib.cc
index 2b250e3e6..2747b2951 100644
--- a/test/tsan/load_shared_lib.cc
+++ b/test/tsan/load_shared_lib.cc
@@ -4,7 +4,7 @@
// RUN: %clangxx_tsan -O1 %p/SharedLibs/load_shared_lib-so.cc \
// RUN: -fPIC -shared -o %t-so.so
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <dlfcn.h>
#include <pthread.h>
diff --git a/test/tsan/longjmp3.cc b/test/tsan/longjmp3.cc
index afb4996d4..71d964dbb 100644
--- a/test/tsan/longjmp3.cc
+++ b/test/tsan/longjmp3.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/tsan/longjmp4.cc b/test/tsan/longjmp4.cc
index 1ec3b4b7e..15330f5d8 100644
--- a/test/tsan/longjmp4.cc
+++ b/test/tsan/longjmp4.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/tsan/malloc_hook.cc b/test/tsan/malloc_hook.cc
index 63e1c3cac..a2658b79a 100644
--- a/test/tsan/malloc_hook.cc
+++ b/test/tsan/malloc_hook.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
diff --git a/test/tsan/malloc_stack.cc b/test/tsan/malloc_stack.cc
index cea602018..602736075 100644
--- a/test/tsan/malloc_stack.cc
+++ b/test/tsan/malloc_stack.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/memcpy_race.cc b/test/tsan/memcpy_race.cc
index d7314d255..8ec8e0a3e 100644
--- a/test/tsan/memcpy_race.cc
+++ b/test/tsan/memcpy_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
diff --git a/test/tsan/mop_with_offset.cc b/test/tsan/mop_with_offset.cc
index e9342794d..e44c78b7d 100644
--- a/test/tsan/mop_with_offset.cc
+++ b/test/tsan/mop_with_offset.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
diff --git a/test/tsan/mop_with_offset2.cc b/test/tsan/mop_with_offset2.cc
index 31b4a406d..a465d5f09 100644
--- a/test/tsan/mop_with_offset2.cc
+++ b/test/tsan/mop_with_offset2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
diff --git a/test/tsan/mutex_bad_read_lock.cc b/test/tsan/mutex_bad_read_lock.cc
index c64bf8849..84a2976d5 100644
--- a/test/tsan/mutex_bad_read_lock.cc
+++ b/test/tsan/mutex_bad_read_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
int main() {
diff --git a/test/tsan/mutex_bad_read_unlock.cc b/test/tsan/mutex_bad_read_unlock.cc
index ab417f43c..dcee51599 100644
--- a/test/tsan/mutex_bad_read_unlock.cc
+++ b/test/tsan/mutex_bad_read_unlock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
diff --git a/test/tsan/mutex_bad_unlock.cc b/test/tsan/mutex_bad_unlock.cc
index 301903571..6b483cf17 100644
--- a/test/tsan/mutex_bad_unlock.cc
+++ b/test/tsan/mutex_bad_unlock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
int main() {
diff --git a/test/tsan/mutex_destroy_locked.cc b/test/tsan/mutex_destroy_locked.cc
index 6c5dcbf11..b81905ec6 100644
--- a/test/tsan/mutex_destroy_locked.cc
+++ b/test/tsan/mutex_destroy_locked.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/mutex_double_lock.cc b/test/tsan/mutex_double_lock.cc
index 551d911e6..c1bebf737 100644
--- a/test/tsan/mutex_double_lock.cc
+++ b/test/tsan/mutex_double_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/mutex_robust2.cc b/test/tsan/mutex_robust2.cc
index f3125c115..0914c1763 100644
--- a/test/tsan/mutex_robust2.cc
+++ b/test/tsan/mutex_robust2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/test/tsan/mutexset1.cc b/test/tsan/mutexset1.cc
index 49607d7a2..72964edfb 100644
--- a/test/tsan/mutexset1.cc
+++ b/test/tsan/mutexset1.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset2.cc b/test/tsan/mutexset2.cc
index 80b690df7..01a5f5df6 100644
--- a/test/tsan/mutexset2.cc
+++ b/test/tsan/mutexset2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset3.cc b/test/tsan/mutexset3.cc
index 17c27ea26..e14bb1111 100644
--- a/test/tsan/mutexset3.cc
+++ b/test/tsan/mutexset3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset4.cc b/test/tsan/mutexset4.cc
index f56d37a73..db860e005 100644
--- a/test/tsan/mutexset4.cc
+++ b/test/tsan/mutexset4.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset5.cc b/test/tsan/mutexset5.cc
index ea1255373..e1cc2fcac 100644
--- a/test/tsan/mutexset5.cc
+++ b/test/tsan/mutexset5.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset6.cc b/test/tsan/mutexset6.cc
index a42a74364..07dcc0a73 100644
--- a/test/tsan/mutexset6.cc
+++ b/test/tsan/mutexset6.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset7.cc b/test/tsan/mutexset7.cc
index b80eddb08..12174844c 100644
--- a/test/tsan/mutexset7.cc
+++ b/test/tsan/mutexset7.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/mutexset8.cc b/test/tsan/mutexset8.cc
index 23449ab0d..3e1ab8c5a 100644
--- a/test/tsan/mutexset8.cc
+++ b/test/tsan/mutexset8.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/pthread_atfork_deadlock.c b/test/tsan/pthread_atfork_deadlock.c
index 3e91f3ea5..965de05b4 100644
--- a/test/tsan/pthread_atfork_deadlock.c
+++ b/test/tsan/pthread_atfork_deadlock.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
// Regression test for
// https://code.google.com/p/thread-sanitizer/issues/detail?id=61
// When the data race was reported, pthread_atfork() handler used to be
diff --git a/test/tsan/race_on_barrier.c b/test/tsan/race_on_barrier.c
index e93995ade..99b18fe4d 100644
--- a/test/tsan/race_on_barrier.c
+++ b/test/tsan/race_on_barrier.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
diff --git a/test/tsan/race_on_barrier2.c b/test/tsan/race_on_barrier2.c
index 75f9b4a09..98c028e19 100644
--- a/test/tsan/race_on_barrier2.c
+++ b/test/tsan/race_on_barrier2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
diff --git a/test/tsan/race_on_heap.cc b/test/tsan/race_on_heap.cc
index 54c4a9b02..a66e0c4f9 100644
--- a/test/tsan/race_on_heap.cc
+++ b/test/tsan/race_on_heap.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
@@ -38,7 +38,7 @@ int main() {
// CHECK: WARNING: ThreadSanitizer: data race
// ...
// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
-// CHCEKL #0 malloc
+// CHCEK: #0 malloc
// CHECK: #{{1|2}} alloc
// CHECK: #{{2|3}} AllocThread
// ...
diff --git a/test/tsan/race_on_mutex.c b/test/tsan/race_on_mutex.c
index d3e621062..b4adeeb4d 100644
--- a/test/tsan/race_on_mutex.c
+++ b/test/tsan/race_on_mutex.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
diff --git a/test/tsan/race_on_mutex2.c b/test/tsan/race_on_mutex2.c
index c860fc6d8..1796d0c64 100644
--- a/test/tsan/race_on_mutex2.c
+++ b/test/tsan/race_on_mutex2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
diff --git a/test/tsan/race_on_read.cc b/test/tsan/race_on_read.cc
index 4dc976d00..1ec0522b9 100644
--- a/test/tsan/race_on_read.cc
+++ b/test/tsan/race_on_read.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/race_on_write.cc b/test/tsan/race_on_write.cc
index add22ce60..484bbb7ae 100644
--- a/test/tsan/race_on_write.cc
+++ b/test/tsan/race_on_write.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/race_with_finished_thread.cc b/test/tsan/race_with_finished_thread.cc
index b3f9b7066..d28760093 100644
--- a/test/tsan/race_with_finished_thread.cc
+++ b/test/tsan/race_with_finished_thread.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
diff --git a/test/tsan/signal_errno.cc b/test/tsan/signal_errno.cc
index 326953ea2..27d4ecd88 100644
--- a/test/tsan/signal_errno.cc
+++ b/test/tsan/signal_errno.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/tsan/signal_malloc.cc b/test/tsan/signal_malloc.cc
index f6fc3facb..db5e79b99 100644
--- a/test/tsan/signal_malloc.cc
+++ b/test/tsan/signal_malloc.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
diff --git a/test/tsan/sigsuspend.cc b/test/tsan/sigsuspend.cc
index dc9606637..f614c12ac 100644
--- a/test/tsan/sigsuspend.cc
+++ b/test/tsan/sigsuspend.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
// Always enable asserts.
#ifdef NDEBUG
diff --git a/test/tsan/simple_race.c b/test/tsan/simple_race.c
index 78f105fa1..7b60c5ec2 100644
--- a/test/tsan/simple_race.c
+++ b/test/tsan/simple_race.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
@@ -26,3 +26,4 @@ int main() {
}
// CHECK: WARNING: ThreadSanitizer: data race
+
diff --git a/test/tsan/simple_race.cc b/test/tsan/simple_race.cc
index 9010ed5f5..0236b9f9b 100644
--- a/test/tsan/simple_race.cc
+++ b/test/tsan/simple_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>
diff --git a/test/tsan/simple_stack.c b/test/tsan/simple_stack.c
index f2326eb09..899277f4e 100644
--- a/test/tsan/simple_stack.c
+++ b/test/tsan/simple_stack.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/simple_stack2.cc b/test/tsan/simple_stack2.cc
index 080387a87..ba0303c1e 100644
--- a/test/tsan/simple_stack2.cc
+++ b/test/tsan/simple_stack2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/sleep_sync.cc b/test/tsan/sleep_sync.cc
index 5047fdf04..c7614e16b 100644
--- a/test/tsan/sleep_sync.cc
+++ b/test/tsan/sleep_sync.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/sleep_sync2.cc b/test/tsan/sleep_sync2.cc
index 773940525..4e616992e 100644
--- a/test/tsan/sleep_sync2.cc
+++ b/test/tsan/sleep_sync2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/stack_race.cc b/test/tsan/stack_race.cc
index 90da2f8c8..2e02f46a2 100644
--- a/test/tsan/stack_race.cc
+++ b/test/tsan/stack_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/test/tsan/stack_race2.cc b/test/tsan/stack_race2.cc
index 83a67f49a..818db367b 100644
--- a/test/tsan/stack_race2.cc
+++ b/test/tsan/stack_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/test/tsan/static_init3.cc b/test/tsan/static_init3.cc
index 94934b4a9..3b9fe62ae 100644
--- a/test/tsan/static_init3.cc
+++ b/test/tsan/static_init3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/test/tsan/suppress_same_address.cc b/test/tsan/suppress_same_address.cc
index c1721409a..df19da1cc 100644
--- a/test/tsan/suppress_same_address.cc
+++ b/test/tsan/suppress_same_address.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/suppress_same_stacks.cc b/test/tsan/suppress_same_stacks.cc
index 23008b4bb..9305650ea 100644
--- a/test/tsan/suppress_same_stacks.cc
+++ b/test/tsan/suppress_same_stacks.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
volatile int N; // Prevent loop unrolling.
diff --git a/test/tsan/thread_end_with_ignore.cc b/test/tsan/thread_end_with_ignore.cc
index 438a738e2..79bb08d64 100644
--- a/test/tsan/thread_end_with_ignore.cc
+++ b/test/tsan/thread_end_with_ignore.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
diff --git a/test/tsan/thread_end_with_ignore2.cc b/test/tsan/thread_end_with_ignore2.cc
index ca9b5ca89..9387ea488 100644
--- a/test/tsan/thread_end_with_ignore2.cc
+++ b/test/tsan/thread_end_with_ignore2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
int main() {
diff --git a/test/tsan/thread_end_with_ignore3.cc b/test/tsan/thread_end_with_ignore3.cc
index f066f9e1d..55688b2a5 100644
--- a/test/tsan/thread_end_with_ignore3.cc
+++ b/test/tsan/thread_end_with_ignore3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
diff --git a/test/tsan/thread_leak3.c b/test/tsan/thread_leak3.c
index efc4dd024..f4db48421 100644
--- a/test/tsan/thread_leak3.c
+++ b/test/tsan/thread_leak3.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/thread_leak5.c b/test/tsan/thread_leak5.c
index 130858cfb..ca244a9f2 100644
--- a/test/tsan/thread_leak5.c
+++ b/test/tsan/thread_leak5.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/thread_name.cc b/test/tsan/thread_name.cc
index af29a2ee4..05b0a352a 100644
--- a/test/tsan/thread_name.cc
+++ b/test/tsan/thread_name.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/thread_name2.cc b/test/tsan/thread_name2.cc
index 0530c9888..b9a574623 100644
--- a/test/tsan/thread_name2.cc
+++ b/test/tsan/thread_name2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
diff --git a/test/tsan/tiny_race.c b/test/tsan/tiny_race.c
index 9d8422480..c10eab15c 100644
--- a/test/tsan/tiny_race.c
+++ b/test/tsan/tiny_race.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>
diff --git a/test/tsan/tls_race.cc b/test/tsan/tls_race.cc
index dbfc5531b..18589347e 100644
--- a/test/tsan/tls_race.cc
+++ b/test/tsan/tls_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/test/tsan/tls_race2.cc b/test/tsan/tls_race2.cc
index ed9f4d0fa..0ca629ada 100644
--- a/test/tsan/tls_race2.cc
+++ b/test/tsan/tls_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/test/tsan/unaligned_race.cc b/test/tsan/unaligned_race.cc
index a2b267514..6e9b5a33f 100644
--- a/test/tsan/unaligned_race.cc
+++ b/test/tsan/unaligned_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/tsan/vptr_harmful_race.cc b/test/tsan/vptr_harmful_race.cc
index c7d4b74df..68e12e8e7 100644
--- a/test/tsan/vptr_harmful_race.cc
+++ b/test/tsan/vptr_harmful_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
diff --git a/test/tsan/vptr_harmful_race2.cc b/test/tsan/vptr_harmful_race2.cc
index b018d5cb9..aa53bbb90 100644
--- a/test/tsan/vptr_harmful_race2.cc
+++ b/test/tsan/vptr_harmful_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
diff --git a/test/tsan/vptr_harmful_race3.cc b/test/tsan/vptr_harmful_race3.cc
index 01c94e284..ac6ea94e5 100644
--- a/test/tsan/vptr_harmful_race3.cc
+++ b/test/tsan/vptr_harmful_race3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
diff --git a/test/tsan/write_in_reader_lock.cc b/test/tsan/write_in_reader_lock.cc
index 77373bedc..55882139b 100644
--- a/test/tsan/write_in_reader_lock.cc
+++ b/test/tsan/write_in_reader_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <unistd.h>