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: +# $(dirname %s)/deflake.bash %run %t %s [FileCheck args] +# The script runs the target program up to 10 times, +# until it produces the necessary output. + +BIN=$1 +SRC=$2 +shift +shift + +for i in $(seq 1 10); do + echo TRY $i + not $BIN 2>&1 | FileCheck $SRC $@ && exit 0 +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: $(dirname %s)/deflake.bash %run %t %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/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 && $(dirname %s)/deflake.bash %run %t %s #include #include #include