Index: test/tsan/deflake.bash =================================================================== --- test/tsan/deflake.bash +++ 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 Index: test/tsan/free_race.c =================================================================== --- test/tsan/free_race.c +++ 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 Index: test/tsan/lit.cfg =================================================================== --- test/tsan/lit.cfg +++ test/tsan/lit.cfg @@ -57,6 +57,8 @@ # Define CHECK-%os to check for OS-dependent output. config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) +config.substitutions.append( ("%deflake ", "$(dirname %s)/deflake.bash ") ) + # Default test suffixes. config.suffixes = ['.c', '.cc', '.cpp'] Index: test/tsan/simple_race.c =================================================================== --- test/tsan/simple_race.c +++ 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 #include #include @@ -26,3 +26,4 @@ } // CHECK: WARNING: ThreadSanitizer: data race + Index: test/tsan/simple_race.cc =================================================================== --- test/tsan/simple_race.cc +++ 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 #include