[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
This commit is contained in:
Alexey Samsonov 2012-09-18 07:23:54 +00:00
parent 7ecfa6d960
commit 341e5bcb45
37 changed files with 193 additions and 37 deletions

View File

@ -53,7 +53,7 @@ test: libtsan tsan_test
run: all
(ulimit -s 8192; ./tsan_test)
./output_tests/test_output.sh
./lit_tests/test_output.sh
presubmit:
# Debug build with clang.

View File

@ -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)

View File

@ -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 @@ int main() {
// CHECK: Previous write of size 8 at {{.*}} by thread 1:
// CHECK: #0 free
// CHECK: #1 Thread1

View File

@ -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 @@ int main() {
// CHECK: #0 free
// CHECK: #1 foo
// CHECK: #2 main

View File

@ -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>

View File

@ -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

View File

@ -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")

View File

@ -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 @@ int main() {
// CHECK: Previous write of size 1 at [[ADDR]] by thread 1:
// CHECK: #0 memcpy
// CHECK: #1 Thread1

View File

@ -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 @@ int main() {
// 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:

View File

@ -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 @@ int main() {
// 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:

View File

@ -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 @@ int main() {
// CHECK: Mutex {{.*}} created at:
// CHECK: #0 pthread_mutex_init
// CHECK: #1 main

View File

@ -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 @@ int main() {
}
// CHECK: WARNING: ThreadSanitizer: data race

View File

@ -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>

View File

@ -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>

View File

@ -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 @@ int main() {
// 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)?}} ({{.*}})

View File

@ -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 @@ int main() {
// CHECK: Thread 1 (finished) created at:
// CHECK: #0 pthread_create
// CHECK: #1 main

View File

@ -1,3 +1,4 @@
// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>

View File

@ -1,3 +1,4 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>

View File

@ -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 @@ int main() {
// 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)?}} ({{.*}})

View File

@ -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 @@ int main() {
// 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)?}} ({{.*}})

View File

@ -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 @@ int main() {
// CHECK-NEXT: #0 usleep
// CHECK-NEXT: #1 MySleep
// CHECK-NEXT: #2 main

View File

@ -1,3 +1,4 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <unistd.h>

View File

@ -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 @@ int main() {
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

View File

@ -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 @@ int main() {
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

View File

@ -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>

View File

@ -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 @@ int main() {
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

View File

@ -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 @@ int main() {
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

View File

@ -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 @@ int main() {
}
// CHECK: ThreadSanitizer: reported 1 warnings

View File

@ -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 @@ int main() {
}
// CHECK: ThreadSanitizer: reported 1 warnings

View File

@ -32,7 +32,7 @@ test_file() {
}
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 @@ if [ "$1" == "" ]; then
done
wait
else
test_file $ROOTDIR/output_tests/$1 $CXX "DUMP"
test_file $ROOTDIR/lit_tests/$1 $CXX "DUMP"
fi

View File

@ -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 @@ int main() {
pthread_t t;
pthread_create(&t, 0, Thread, 0);
pthread_join(t, 0);
printf("PASS\n");
return 0;
}
// CHECK-NOT: WARNING: ThreadSanitizer: thread leak

View File

@ -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 @@ int main() {
pthread_t t;
pthread_create(&t, 0, Thread, 0);
pthread_detach(t);
printf("PASS\n");
return 0;
}
// CHECK-NOT: WARNING: ThreadSanitizer: thread leak

View File

@ -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 @@ int main() {
}
// CHECK: WARNING: ThreadSanitizer: thread leak

View File

@ -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) {

View File

@ -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

View File

@ -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>

View File

@ -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>