2 # This script is used to deflake inherently flaky tsan tests.
3 # It is invoked from lit tests as:
4 # %deflake $THRESHOLD mybinary
5 # which is then substituted by lit to:
6 # $(dirname %s)/deflake.bash $THRESHOLD mybinary
7 # - When TSAN_TEST_DEFLAKE_THRESHOLD is defined to a positive integer value,
8 # THRESHOLD will be the defined value.
9 # - When TSAN_TEST_DEFLAKE_THRESHOLD is not defined, THRESHOLD will be 10.
10 # The script runs the target program up to $THRESHOLD times,
11 # until it fails (i.e. produces a race report).
16 # Early exit if $THRESHOLD is not a non-negative integer
17 [[ "${THRESHOLD}" =~ ^
[0-9]+$
]] ||
exit 1
19 while (( THRESHOLD--
)); do
21 if [[ $?
!= 0 ]]; then