[TSan] port all output tests to lit and move them to lit_tests directory. This makes 'make check-tsan' command test both unit and output TSan tests. Old custom makefiles for running TSan tests are still functional as well.

llvm-svn: 164110
diff --git a/compiler-rt/lib/tsan/Makefile.old b/compiler-rt/lib/tsan/Makefile.old
index 9532273..1273a78 100644
--- a/compiler-rt/lib/tsan/Makefile.old
+++ b/compiler-rt/lib/tsan/Makefile.old
@@ -53,7 +53,7 @@
 
 run: all
 	(ulimit -s 8192; ./tsan_test)
-	./output_tests/test_output.sh
+	./lit_tests/test_output.sh
 
 presubmit:
 	# Debug build with clang.
diff --git a/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt b/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt
index 62cad78..4e3273b 100644
--- a/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt
+++ b/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt
@@ -1,10 +1,34 @@
 configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
   )
 
-# Run TSan unit tests.
-if(LLVM_INCLUDE_TESTS)
+if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}")
+  # Run TSan output tests only if we're not cross-compiling,
+  # and can be sure that clang would produce working binaries.
+  set(TSAN_TEST_DEPS
+    clang clang-headers FileCheck count not
+    ${TSAN_RUNTIME_LIBRARIES}
+    )
+  set(TSAN_TEST_PARAMS
+    tsan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+    )
+  if(LLVM_INCLUDE_TESTS)
+    list(APPEND ASAN_TEST_DEPS TsanUnitTests)
+  endif()
+  add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"
+    ${CMAKE_CURRENT_BINARY_DIR}
+    PARAMS ${TSAN_TEST_PARAMS}
+    DEPENDS ${TSAN_TEST_DEPS}
+    )
+  set_target_properties(check-tsan PROPERTIES FOLDER "TSan unittests")
+elseif(LLVM_INCLUDE_TESTS)
+  # Otherwise run only TSan unit tests.
   add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"
     ${CMAKE_CURRENT_BINARY_DIR}/Unit
     DEPENDS TsanUnitTests)
diff --git a/compiler-rt/lib/tsan/output_tests/free_race.c b/compiler-rt/lib/tsan/lit_tests/free_race.c
similarity index 93%
rename from compiler-rt/lib/tsan/output_tests/free_race.c
rename to compiler-rt/lib/tsan/lit_tests/free_race.c
index fb7fbac..9200c3b 100644
--- a/compiler-rt/lib/tsan/output_tests/free_race.c
+++ b/compiler-rt/lib/tsan/lit_tests/free_race.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -40,4 +41,3 @@
 // CHECK:   Previous write of size 8 at {{.*}} by thread 1:
 // CHECK:     #0 free
 // CHECK:     #1 Thread1
-
diff --git a/compiler-rt/lib/tsan/output_tests/free_race2.c b/compiler-rt/lib/tsan/lit_tests/free_race2.c
similarity index 89%
rename from compiler-rt/lib/tsan/output_tests/free_race2.c
rename to compiler-rt/lib/tsan/lit_tests/free_race2.c
index 7b2bdec..095f82e 100644
--- a/compiler-rt/lib/tsan/output_tests/free_race2.c
+++ b/compiler-rt/lib/tsan/lit_tests/free_race2.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <stdlib.h>
 
 void __attribute__((noinline)) foo(int *mem) {
@@ -23,4 +24,3 @@
 // CHECK:     #0 free
 // CHECK:     #1 foo
 // CHECK:     #2 main
-
diff --git a/compiler-rt/lib/tsan/output_tests/heap_race.cc b/compiler-rt/lib/tsan/lit_tests/heap_race.cc
similarity index 83%
rename from compiler-rt/lib/tsan/output_tests/heap_race.cc
rename to compiler-rt/lib/tsan/lit_tests/heap_race.cc
index e92bb37..297f8db 100644
--- a/compiler-rt/lib/tsan/output_tests/heap_race.cc
+++ b/compiler-rt/lib/tsan/lit_tests/heap_race.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/compiler-rt/lib/tsan/lit_tests/lit.cfg b/compiler-rt/lib/tsan/lit_tests/lit.cfg
new file mode 100644
index 0000000..f5e5230
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/lit.cfg
@@ -0,0 +1,86 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'ThreadSanitizer'
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+def DisplayNoConfigMessage():
+  lit.fatal("No site specific configuration available! " +
+            "Try running your test from the build tree or running " +
+            "make check-tsan")
+
+# Figure out LLVM source root.
+llvm_src_root = getattr(config, 'llvm_src_root', None)
+if llvm_src_root is None:
+  # We probably haven't loaded the site-specific configuration: the user
+  # is likely trying to run a test file directly, and the site configuration
+  # wasn't created by the build system.
+  tsan_site_cfg = lit.params.get('tsan_site_config', None)
+  if (tsan_site_cfg) and (os.path.exists(tsan_site_cfg)):
+    lit.load_config(config, tsan_site_cfg)
+    raise SystemExit
+
+  # Try to guess the location of site-specific configuration using llvm-config
+  # util that can point where the build tree is.
+  llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
+  if not llvm_config:
+    DisplayNoConfigMessage()
+
+  # Validate that llvm-config points to the same source tree.
+  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
+  tsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
+                                    "lib", "tsan", "lit_tests")
+  if (os.path.realpath(tsan_test_src_root) !=
+      os.path.realpath(config.test_source_root)):
+    DisplayNoConfigMessage()
+
+  # Find out the presumed location of generated site config.
+  llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
+  tsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
+                               "lib", "tsan", "lit_tests", "lit.site.cfg")
+  if (not tsan_site_cfg) or (not os.path.exists(tsan_site_cfg)):
+    DisplayNoConfigMessage()
+
+  lit.load_config(config, tsan_site_cfg)
+  raise SystemExit
+
+# Setup attributes common for all compiler-rt projects.
+compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
+                                   "lib", "lit.common.cfg")
+if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
+  lit.fatal("Can't find common compiler-rt lit config at: %r"
+            % compiler_rt_lit_cfg)
+lit.load_config(config, compiler_rt_lit_cfg)
+
+# Setup environment variables for running ThreadSanitizer.
+config.environment['TSAN_OPTIONS'] = "atexit_sleep_ms=0"
+
+# Setup default compiler flags used with -faddress-sanitizer option.
+# FIXME: Review the set of required flags and check if it can be reduced.
+clang_tsan_cflags = ("-fthread-sanitizer "
+                      + "-fPIE "
+                      + "-fno-builtin "
+                      + "-g "
+                      + "-Wall "
+                      + "-pie "
+                      + "-lpthread "
+                      + "-ldl ")
+clang_tsan_cxxflags = "-ccc-clang-cxx -ccc-cxx " + clang_tsan_cflags
+config.substitutions.append( ("%clangxx_tsan ", (" " + config.clang + " " +
+                                                clang_tsan_cxxflags + " ")) )
+config.substitutions.append( ("%clang_tsan ", (" " + config.clang + " " +
+                                              clang_tsan_cflags + " ")) )
+
+# Define CHECK-%os to check for OS-dependent output.
+config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
+
+# Default test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp']
+
+# ThreadSanitizer tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+  config.unsupported = True
diff --git a/compiler-rt/lib/tsan/lit_tests/lit.site.cfg.in b/compiler-rt/lib/tsan/lit_tests/lit.site.cfg.in
new file mode 100644
index 0000000..b1c6ccf
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/lit.site.cfg.in
@@ -0,0 +1,19 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+
+config.clang = "@LLVM_BINARY_DIR@/bin/clang"
+config.host_os = "@HOST_OS@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
+config.target_triple = "@TARGET_TRIPLE@"
+
+# LLVM tools dir can be passed in lit parameters, so try to
+# apply substitution.
+try:
+  config.llvm_tools_dir = config.llvm_tools_dir % lit.params
+except KeyError,e:
+  key, = e.args
+  lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))
+
+# Let the main config do the real work.
+lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
diff --git a/compiler-rt/lib/tsan/output_tests/memcpy_race.cc b/compiler-rt/lib/tsan/lit_tests/memcpy_race.cc
similarity index 93%
rename from compiler-rt/lib/tsan/output_tests/memcpy_race.cc
rename to compiler-rt/lib/tsan/lit_tests/memcpy_race.cc
index c6b79a7..c87bc9c 100644
--- a/compiler-rt/lib/tsan/output_tests/memcpy_race.cc
+++ b/compiler-rt/lib/tsan/lit_tests/memcpy_race.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -37,4 +38,3 @@
 // CHECK:   Previous write of size 1 at [[ADDR]] by thread 1:
 // CHECK:     #0 memcpy
 // CHECK:     #1 Thread1
-
diff --git a/compiler-rt/lib/tsan/output_tests/mop_with_offset.cc b/compiler-rt/lib/tsan/lit_tests/mop_with_offset.cc
similarity index 92%
rename from compiler-rt/lib/tsan/output_tests/mop_with_offset.cc
rename to compiler-rt/lib/tsan/lit_tests/mop_with_offset.cc
index fc497bf..14ece1a 100644
--- a/compiler-rt/lib/tsan/output_tests/mop_with_offset.cc
+++ b/compiler-rt/lib/tsan/lit_tests/mop_with_offset.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -33,4 +34,3 @@
 // CHECK: WARNING: ThreadSanitizer: data race
 // CHECK:   Write of size 1 at [[PTR2]] by thread 2:
 // CHECK:   Previous write of size 4 at [[PTR1]] by thread 1:
-
diff --git a/compiler-rt/lib/tsan/output_tests/mop_with_offset2.cc b/compiler-rt/lib/tsan/lit_tests/mop_with_offset2.cc
similarity index 92%
rename from compiler-rt/lib/tsan/output_tests/mop_with_offset2.cc
rename to compiler-rt/lib/tsan/lit_tests/mop_with_offset2.cc
index bbeda55..2a6fde7 100644
--- a/compiler-rt/lib/tsan/output_tests/mop_with_offset2.cc
+++ b/compiler-rt/lib/tsan/lit_tests/mop_with_offset2.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -33,4 +34,3 @@
 // CHECK: WARNING: ThreadSanitizer: data race
 // CHECK:   Write of size 4 at [[PTR1]] by thread 1:
 // CHECK:   Previous write of size 1 at [[PTR2]] by thread 2:
-
diff --git a/compiler-rt/lib/tsan/output_tests/mutex_destroy_locked.cc b/compiler-rt/lib/tsan/lit_tests/mutex_destroy_locked.cc
similarity index 90%
rename from compiler-rt/lib/tsan/output_tests/mutex_destroy_locked.cc
rename to compiler-rt/lib/tsan/lit_tests/mutex_destroy_locked.cc
index f6ab874..427c643 100644
--- a/compiler-rt/lib/tsan/output_tests/mutex_destroy_locked.cc
+++ b/compiler-rt/lib/tsan/lit_tests/mutex_destroy_locked.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
@@ -26,4 +27,3 @@
 // CHECK:   Mutex {{.*}} created at:
 // CHECK:     #0 pthread_mutex_init
 // CHECK:     #1 main
-
diff --git a/compiler-rt/lib/tsan/output_tests/race_on_barrier.c b/compiler-rt/lib/tsan/lit_tests/race_on_barrier.c
similarity index 89%
rename from compiler-rt/lib/tsan/output_tests/race_on_barrier.c
rename to compiler-rt/lib/tsan/lit_tests/race_on_barrier.c
index 98d7a1d..491201f 100644
--- a/compiler-rt/lib/tsan/output_tests/race_on_barrier.c
+++ b/compiler-rt/lib/tsan/lit_tests/race_on_barrier.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -28,4 +29,3 @@
 }
 
 // CHECK:      WARNING: ThreadSanitizer: data race
-
diff --git a/compiler-rt/lib/tsan/output_tests/race_on_barrier2.c b/compiler-rt/lib/tsan/lit_tests/race_on_barrier2.c
similarity index 90%
rename from compiler-rt/lib/tsan/output_tests/race_on_barrier2.c
rename to compiler-rt/lib/tsan/lit_tests/race_on_barrier2.c
index dbdb6b5..46a4f50 100644
--- a/compiler-rt/lib/tsan/output_tests/race_on_barrier2.c
+++ b/compiler-rt/lib/tsan/lit_tests/race_on_barrier2.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/compiler-rt/lib/tsan/output_tests/race_on_heap.cc b/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc
similarity index 93%
rename from compiler-rt/lib/tsan/output_tests/race_on_heap.cc
rename to compiler-rt/lib/tsan/lit_tests/race_on_heap.cc
index 09a461c..1fdf54d 100644
--- a/compiler-rt/lib/tsan/output_tests/race_on_heap.cc
+++ b/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/compiler-rt/lib/tsan/output_tests/race_on_mutex.c b/compiler-rt/lib/tsan/lit_tests/race_on_mutex.c
similarity index 82%
rename from compiler-rt/lib/tsan/output_tests/race_on_mutex.c
rename to compiler-rt/lib/tsan/lit_tests/race_on_mutex.c
index 3ee9494..6c6697d 100644
--- a/compiler-rt/lib/tsan/output_tests/race_on_mutex.c
+++ b/compiler-rt/lib/tsan/lit_tests/race_on_mutex.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -35,7 +36,7 @@
 // CHECK:      WARNING: ThreadSanitizer: data race
 // CHECK-NEXT:   Read of size 1 at {{.*}} by thread 2:
 // CHECK-NEXT:     #0 pthread_mutex_lock
-// CHECK-NEXT:     #1 Thread2{{.*}} {{.*}}race_on_mutex.c:19{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 Thread2{{.*}} {{.*}}race_on_mutex.c:20{{(:3)?}} ({{.*}})
 // CHECK:        Previous write of size 1 at {{.*}} by thread 1:
 // CHECK-NEXT:     #0 pthread_mutex_init {{.*}} ({{.*}})
-// CHECK-NEXT:     #1 Thread1{{.*}} {{.*}}race_on_mutex.c:10{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 Thread1{{.*}} {{.*}}race_on_mutex.c:11{{(:3)?}} ({{.*}})
diff --git a/compiler-rt/lib/tsan/output_tests/race_with_finished_thread.cc b/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc
similarity index 93%
rename from compiler-rt/lib/tsan/output_tests/race_with_finished_thread.cc
rename to compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc
index 1f60f4b..e50c22b 100644
--- a/compiler-rt/lib/tsan/output_tests/race_with_finished_thread.cc
+++ b/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -40,4 +41,3 @@
 // CHECK:   Thread 1 (finished) created at:
 // CHECK:     #0 pthread_create
 // CHECK:     #1 main
-
diff --git a/compiler-rt/lib/tsan/output_tests/simple_race.c b/compiler-rt/lib/tsan/lit_tests/simple_race.c
similarity index 87%
rename from compiler-rt/lib/tsan/output_tests/simple_race.c
rename to compiler-rt/lib/tsan/lit_tests/simple_race.c
index ed831fd..44aff89 100644
--- a/compiler-rt/lib/tsan/output_tests/simple_race.c
+++ b/compiler-rt/lib/tsan/lit_tests/simple_race.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 
diff --git a/compiler-rt/lib/tsan/output_tests/simple_race.cc b/compiler-rt/lib/tsan/lit_tests/simple_race.cc
similarity index 86%
rename from compiler-rt/lib/tsan/output_tests/simple_race.cc
rename to compiler-rt/lib/tsan/lit_tests/simple_race.cc
index 8d2cabf..ec29c92 100644
--- a/compiler-rt/lib/tsan/output_tests/simple_race.cc
+++ b/compiler-rt/lib/tsan/lit_tests/simple_race.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 
diff --git a/compiler-rt/lib/tsan/output_tests/simple_stack.c b/compiler-rt/lib/tsan/lit_tests/simple_stack.c
similarity index 67%
rename from compiler-rt/lib/tsan/output_tests/simple_stack.c
rename to compiler-rt/lib/tsan/lit_tests/simple_stack.c
index 12c5f5e..08f5f65 100644
--- a/compiler-rt/lib/tsan/output_tests/simple_stack.c
+++ b/compiler-rt/lib/tsan/lit_tests/simple_stack.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -48,18 +49,18 @@
 
 // CHECK:      WARNING: ThreadSanitizer: data race
 // CHECK-NEXT:   Write of size 4 at {{.*}} by thread 1:
-// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack.c:8{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack.c:13{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack.c:27{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack.c:9{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack.c:14{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack.c:28{{(:3)?}} ({{.*}})
 // CHECK:        Previous read of size 4 at {{.*}} by thread 2:
-// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack.c:17{{(:26)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack.c:22{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 Thread2{{.*}} {{.*}}simple_stack.c:32{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack.c:18{{(:26)?}} ({{.*}})
+// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack.c:23{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 Thread2{{.*}} {{.*}}simple_stack.c:33{{(:3)?}} ({{.*}})
 // CHECK:        Thread 1 (running) created at:
 // CHECK-NEXT:     #0 pthread_create {{.*}} ({{.*}})
-// CHECK-NEXT:     #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack.c:42{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})
 // CHECK:        Thread 2 ({{.*}}) created at:
 // CHECK-NEXT:     #0 pthread_create {{.*}} ({{.*}})
-// CHECK-NEXT:     #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack.c:44{{(:3)?}} ({{.*}})
diff --git a/compiler-rt/lib/tsan/output_tests/simple_stack2.cc b/compiler-rt/lib/tsan/lit_tests/simple_stack2.cc
similarity index 66%
rename from compiler-rt/lib/tsan/output_tests/simple_stack2.cc
rename to compiler-rt/lib/tsan/lit_tests/simple_stack2.cc
index 5605415..ed95c68 100644
--- a/compiler-rt/lib/tsan/output_tests/simple_stack2.cc
+++ b/compiler-rt/lib/tsan/lit_tests/simple_stack2.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -43,10 +44,10 @@
 
 // CHECK:      WARNING: ThreadSanitizer: data race
 // CHECK-NEXT:   Write of size 4 at {{.*}} by thread 1:
-// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack2.cc:8{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack2.cc:15{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack2.cc:33{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack2.cc:9{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack2.cc:16{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}} ({{.*}})
 // CHECK:        Previous read of size 4 at {{.*}} by main thread:
-// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack2.cc:19{{(:28)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack2.cc:28{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack2.cc:40{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack2.cc:20{{(:28)?}} ({{.*}})
+// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack2.cc:29{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack2.cc:41{{(:3)?}} ({{.*}})
diff --git a/compiler-rt/lib/tsan/output_tests/sleep_sync.cc b/compiler-rt/lib/tsan/lit_tests/sleep_sync.cc
similarity index 88%
rename from compiler-rt/lib/tsan/output_tests/sleep_sync.cc
rename to compiler-rt/lib/tsan/lit_tests/sleep_sync.cc
index a130f15..566d04b 100644
--- a/compiler-rt/lib/tsan/output_tests/sleep_sync.cc
+++ b/compiler-rt/lib/tsan/lit_tests/sleep_sync.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
@@ -27,4 +28,3 @@
 // CHECK-NEXT:     #0 usleep
 // CHECK-NEXT:     #1 MySleep
 // CHECK-NEXT:     #2 main
-
diff --git a/compiler-rt/lib/tsan/output_tests/sleep_sync2.cc b/compiler-rt/lib/tsan/lit_tests/sleep_sync2.cc
similarity index 83%
rename from compiler-rt/lib/tsan/output_tests/sleep_sync2.cc
rename to compiler-rt/lib/tsan/lit_tests/sleep_sync2.cc
index 017b9ba..9a51826 100644
--- a/compiler-rt/lib/tsan/output_tests/sleep_sync2.cc
+++ b/compiler-rt/lib/tsan/lit_tests/sleep_sync2.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/compiler-rt/lib/tsan/output_tests/static_init1.cc b/compiler-rt/lib/tsan/lit_tests/static_init1.cc
similarity index 84%
rename from compiler-rt/lib/tsan/output_tests/static_init1.cc
rename to compiler-rt/lib/tsan/lit_tests/static_init1.cc
index 75d2819..4faf5bc 100644
--- a/compiler-rt/lib/tsan/output_tests/static_init1.cc
+++ b/compiler-rt/lib/tsan/lit_tests/static_init1.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -20,6 +21,7 @@
   pthread_create(&t[1], 0, Thread, 0);
   pthread_join(t[0], 0);
   pthread_join(t[1], 0);
+  printf("PASS\n");
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/lib/tsan/output_tests/static_init2.cc b/compiler-rt/lib/tsan/lit_tests/static_init2.cc
similarity index 86%
rename from compiler-rt/lib/tsan/output_tests/static_init2.cc
rename to compiler-rt/lib/tsan/lit_tests/static_init2.cc
index 8d41061..96ef821 100644
--- a/compiler-rt/lib/tsan/output_tests/static_init2.cc
+++ b/compiler-rt/lib/tsan/lit_tests/static_init2.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -26,6 +27,7 @@
   pthread_create(&t[1], 0, Thread, 0);
   pthread_join(t[0], 0);
   pthread_join(t[1], 0);
+  printf("PASS\n");
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/lib/tsan/output_tests/static_init3.cc b/compiler-rt/lib/tsan/lit_tests/static_init3.cc
similarity index 92%
rename from compiler-rt/lib/tsan/output_tests/static_init3.cc
rename to compiler-rt/lib/tsan/lit_tests/static_init3.cc
index 718f811..40fd4b9 100644
--- a/compiler-rt/lib/tsan/output_tests/static_init3.cc
+++ b/compiler-rt/lib/tsan/lit_tests/static_init3.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/compiler-rt/lib/tsan/output_tests/static_init4.cc b/compiler-rt/lib/tsan/lit_tests/static_init4.cc
similarity index 87%
rename from compiler-rt/lib/tsan/output_tests/static_init4.cc
rename to compiler-rt/lib/tsan/lit_tests/static_init4.cc
index 175d464..5ecc399 100644
--- a/compiler-rt/lib/tsan/output_tests/static_init4.cc
+++ b/compiler-rt/lib/tsan/lit_tests/static_init4.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -30,6 +31,7 @@
   pthread_create(&t[1], 0, Thread1, 0);
   pthread_join(t[0], 0);
   pthread_join(t[1], 0);
+  printf("PASS\n");
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/lib/tsan/output_tests/static_init5.cc b/compiler-rt/lib/tsan/lit_tests/static_init5.cc
similarity index 89%
rename from compiler-rt/lib/tsan/output_tests/static_init5.cc
rename to compiler-rt/lib/tsan/lit_tests/static_init5.cc
index 89c1137..9d44eb2 100644
--- a/compiler-rt/lib/tsan/output_tests/static_init5.cc
+++ b/compiler-rt/lib/tsan/lit_tests/static_init5.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -35,6 +36,7 @@
   pthread_create(&t[1], 0, Thread1, 0);
   pthread_join(t[0], 0);
   pthread_join(t[1], 0);
+  printf("PASS\n");
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/lib/tsan/output_tests/suppress_same_address.cc b/compiler-rt/lib/tsan/lit_tests/suppress_same_address.cc
similarity index 83%
rename from compiler-rt/lib/tsan/output_tests/suppress_same_address.cc
rename to compiler-rt/lib/tsan/lit_tests/suppress_same_address.cc
index 6e98970..174d1cc 100644
--- a/compiler-rt/lib/tsan/output_tests/suppress_same_address.cc
+++ b/compiler-rt/lib/tsan/lit_tests/suppress_same_address.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 
 int X;
@@ -24,4 +25,3 @@
 }
 
 // CHECK: ThreadSanitizer: reported 1 warnings
-
diff --git a/compiler-rt/lib/tsan/output_tests/suppress_same_stacks.cc b/compiler-rt/lib/tsan/lit_tests/suppress_same_stacks.cc
similarity index 88%
rename from compiler-rt/lib/tsan/output_tests/suppress_same_stacks.cc
rename to compiler-rt/lib/tsan/lit_tests/suppress_same_stacks.cc
index 6046a4e..32bff9d 100644
--- a/compiler-rt/lib/tsan/output_tests/suppress_same_stacks.cc
+++ b/compiler-rt/lib/tsan/lit_tests/suppress_same_stacks.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 
 volatile int N;  // Prevent loop unrolling.
@@ -24,4 +25,3 @@
 }
 
 // CHECK: ThreadSanitizer: reported 1 warnings
-
diff --git a/compiler-rt/lib/tsan/output_tests/test_output.sh b/compiler-rt/lib/tsan/lit_tests/test_output.sh
similarity index 90%
rename from compiler-rt/lib/tsan/output_tests/test_output.sh
rename to compiler-rt/lib/tsan/lit_tests/test_output.sh
index bd9cd91..e4c2a4c 100755
--- a/compiler-rt/lib/tsan/output_tests/test_output.sh
+++ b/compiler-rt/lib/tsan/lit_tests/test_output.sh
@@ -32,7 +32,7 @@
 }
 
 if [ "$1" == "" ]; then
-  for c in $ROOTDIR/output_tests/*.{c,cc}; do
+  for c in $ROOTDIR/lit_tests/*.{c,cc}; do
     if [[ $c == */failing_* ]]; then
       echo SKIPPING FAILING TEST $c
       continue
@@ -45,5 +45,5 @@
   done
   wait
 else
-  test_file $ROOTDIR/output_tests/$1 $CXX "DUMP"
+  test_file $ROOTDIR/lit_tests/$1 $CXX "DUMP"
 fi
diff --git a/compiler-rt/lib/tsan/output_tests/thread_leak.c b/compiler-rt/lib/tsan/lit_tests/thread_leak.c
similarity index 68%
rename from compiler-rt/lib/tsan/output_tests/thread_leak.c
rename to compiler-rt/lib/tsan/lit_tests/thread_leak.c
index 88a11be..c5e669e 100644
--- a/compiler-rt/lib/tsan/output_tests/thread_leak.c
+++ b/compiler-rt/lib/tsan/lit_tests/thread_leak.c
@@ -1,4 +1,6 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
+#include <stdio.h>
 
 void *Thread(void *x) {
   return 0;
@@ -8,8 +10,8 @@
   pthread_t t;
   pthread_create(&t, 0, Thread, 0);
   pthread_join(t, 0);
+  printf("PASS\n");
   return 0;
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: thread leak
-
diff --git a/compiler-rt/lib/tsan/output_tests/thread_leak2.c b/compiler-rt/lib/tsan/lit_tests/thread_leak2.c
similarity index 68%
rename from compiler-rt/lib/tsan/output_tests/thread_leak2.c
rename to compiler-rt/lib/tsan/lit_tests/thread_leak2.c
index 71e9c50..39f6b5e 100644
--- a/compiler-rt/lib/tsan/output_tests/thread_leak2.c
+++ b/compiler-rt/lib/tsan/lit_tests/thread_leak2.c
@@ -1,4 +1,6 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
+#include <stdio.h>
 
 void *Thread(void *x) {
   return 0;
@@ -8,8 +10,8 @@
   pthread_t t;
   pthread_create(&t, 0, Thread, 0);
   pthread_detach(t);
+  printf("PASS\n");
   return 0;
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: thread leak
-
diff --git a/compiler-rt/lib/tsan/output_tests/thread_leak3.c b/compiler-rt/lib/tsan/lit_tests/thread_leak3.c
similarity index 76%
rename from compiler-rt/lib/tsan/output_tests/thread_leak3.c
rename to compiler-rt/lib/tsan/lit_tests/thread_leak3.c
index 058b6e5..c48219f 100644
--- a/compiler-rt/lib/tsan/output_tests/thread_leak3.c
+++ b/compiler-rt/lib/tsan/lit_tests/thread_leak3.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 
 void *Thread(void *x) {
@@ -11,4 +12,3 @@
 }
 
 // CHECK: WARNING: ThreadSanitizer: thread leak
-
diff --git a/compiler-rt/lib/tsan/output_tests/tiny_race.c b/compiler-rt/lib/tsan/lit_tests/tiny_race.c
similarity index 81%
rename from compiler-rt/lib/tsan/output_tests/tiny_race.c
rename to compiler-rt/lib/tsan/lit_tests/tiny_race.c
index 3a8d192..44cc133 100644
--- a/compiler-rt/lib/tsan/output_tests/tiny_race.c
+++ b/compiler-rt/lib/tsan/lit_tests/tiny_race.c
@@ -1,3 +1,4 @@
+// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 int Global;
 void *Thread1(void *x) {
diff --git a/compiler-rt/lib/tsan/output_tests/virtual_inheritance_compile_bug.cc b/compiler-rt/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc
similarity index 87%
rename from compiler-rt/lib/tsan/output_tests/virtual_inheritance_compile_bug.cc
rename to compiler-rt/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc
index 6198e8a..2275b8b 100644
--- a/compiler-rt/lib/tsan/output_tests/virtual_inheritance_compile_bug.cc
+++ b/compiler-rt/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc
@@ -1,5 +1,7 @@
 // Regression test for http://code.google.com/p/thread-sanitizer/issues/detail?id=3.
 // The C++ variant is much more compact that the LLVM IR equivalent.
+
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <stdio.h>
 struct AAA              {  virtual long aaa () { return 0; } };  // NOLINT
 struct BBB: virtual AAA { unsigned long bbb; };  // NOLINT
diff --git a/compiler-rt/lib/tsan/output_tests/vptr_benign_race.cc b/compiler-rt/lib/tsan/lit_tests/vptr_benign_race.cc
similarity index 92%
rename from compiler-rt/lib/tsan/output_tests/vptr_benign_race.cc
rename to compiler-rt/lib/tsan/lit_tests/vptr_benign_race.cc
index fec4ffb..8c9fc59 100644
--- a/compiler-rt/lib/tsan/output_tests/vptr_benign_race.cc
+++ b/compiler-rt/lib/tsan/lit_tests/vptr_benign_race.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>
diff --git a/compiler-rt/lib/tsan/output_tests/vptr_harmful_race.cc b/compiler-rt/lib/tsan/lit_tests/vptr_harmful_race.cc
similarity index 91%
rename from compiler-rt/lib/tsan/output_tests/vptr_harmful_race.cc
rename to compiler-rt/lib/tsan/lit_tests/vptr_harmful_race.cc
index a19e6ab..f51ba7e 100644
--- a/compiler-rt/lib/tsan/output_tests/vptr_harmful_race.cc
+++ b/compiler-rt/lib/tsan/lit_tests/vptr_harmful_race.cc
@@ -1,3 +1,4 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>