[PATCH] tsan: automatically deflake flaky tests
Dmitry Vyukov
dvyukov at google.com
Thu May 29 02:13:56 PDT 2014
introduce %deflake macro
http://reviews.llvm.org/D3913
Files:
test/tsan/deflake.bash
test/tsan/free_race.c
test/tsan/lit.cfg
test/tsan/simple_race.c
test/tsan/simple_race.cc
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 <pthread.h>
#include <stdio.h>
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 <pthread.h>
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 <pthread.h>
#include <stdio.h>
#include <unistd.h>
@@ -26,3 +26,4 @@
}
// CHECK: WARNING: ThreadSanitizer: data race
+
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/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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3913.9910.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140529/33f8a338/attachment.bin>
More information about the llvm-commits
mailing list