set(TSAN_TESTSUITES)
+if (NOT DEFINED TSAN_TEST_DEFLAKE_THRESHOLD)
+ set(TSAN_TEST_DEFLAKE_THRESHOLD "10")
+endif()
+
set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH)
#!/usr/bin/env bash
# This script is used to deflake inherently flaky tsan tests.
# It is invoked from lit tests as:
-# %deflake mybinary
+# %deflake $THRESHOLD mybinary
# which is then substituted by lit to:
-# $(dirname %s)/deflake.bash mybinary
-# The script runs the target program up to 10 times,
+# $(dirname %s)/deflake.bash $THRESHOLD mybinary
+# - When TSAN_TEST_DEFLAKE_THRESHOLD is defined to a positive integer value,
+# THRESHOLD will be the defined value.
+# - When TSAN_TEST_DEFLAKE_THRESHOLD is not defined, THRESHOLD will be 10.
+# The script runs the target program up to $THRESHOLD times,
# until it fails (i.e. produces a race report).
-for i in $(seq 1 10); do
+THRESHOLD="${1}"
+shift
+
+# Early exit if $THRESHOLD is not a non-negative integer
+[[ "${THRESHOLD}" =~ ^[0-9]+$ ]] || exit 1
+
+while (( THRESHOLD-- )); do
OUT=`$@ 2>&1`
if [[ $? != 0 ]]; then
echo "$OUT"
# 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") + " "))
+config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash") + " " + config.deflake_threshold))
# Default test suffixes.
config.suffixes = ['.c', '.cpp', '.m', '.mm']
config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.deflake_threshold = "@TSAN_TEST_DEFLAKE_THRESHOLD@"
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")