27 lines · plain
1#!/usr/bin/env bash2# This script is used to deflake inherently flaky tsan tests.3# It is invoked from lit tests as:4# %deflake $THRESHOLD mybinary5# which is then substituted by lit to:6# $(dirname %s)/deflake.bash $THRESHOLD mybinary7# - 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).12 13THRESHOLD="${1}"14shift15 16# Early exit if $THRESHOLD is not a non-negative integer17[[ "${THRESHOLD}" =~ ^[0-9]+$ ]] || exit 118 19while (( THRESHOLD-- )); do20 OUT=`$@ 2>&1`21 if [[ $? != 0 ]]; then22 echo "$OUT"23 exit 024 fi25done26exit 127