2012-09-18 15:23:54 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2013-05-27 17:35:24 +08:00
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
|
|
|
if not attr_value:
|
2013-08-10 06:14:01 +08:00
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
|
|
|
"to lit.site.cfg " % attr_name)
|
2013-05-27 17:35:24 +08:00
|
|
|
return attr_value
|
|
|
|
|
2012-09-18 15:23:54 +08:00
|
|
|
# Setup config name.
|
|
|
|
config.name = 'ThreadSanitizer'
|
|
|
|
|
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# Setup environment variables for running ThreadSanitizer.
|
2012-11-16 18:16:14 +08:00
|
|
|
tsan_options = "atexit_sleep_ms=0"
|
|
|
|
|
|
|
|
config.environment['TSAN_OPTIONS'] = tsan_options
|
2012-09-18 15:23:54 +08:00
|
|
|
|
2014-05-17 04:33:56 +08:00
|
|
|
# GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
|
|
|
|
if config.compiler_id == 'GNU':
|
2014-05-28 21:13:30 +08:00
|
|
|
extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
|
2014-05-17 04:33:56 +08:00
|
|
|
else:
|
|
|
|
extra_cflags = []
|
|
|
|
|
2012-11-06 10:31:42 +08:00
|
|
|
# Setup default compiler flags used with -fsanitize=thread option.
|
2014-02-17 21:08:10 +08:00
|
|
|
clang_tsan_cflags = ["-fsanitize=thread",
|
|
|
|
"-Wall",
|
2014-09-06 06:05:32 +08:00
|
|
|
"-m64"] + config.debug_info_flags + extra_cflags
|
2014-02-19 23:13:14 +08:00
|
|
|
clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags
|
2014-05-14 06:30:16 +08:00
|
|
|
# Add additional flags if we're using instrumented libc++.
|
|
|
|
if config.has_libcxx:
|
|
|
|
# FIXME: Dehardcode this path somehow.
|
|
|
|
libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
|
|
|
|
"tsan", "libcxx_tsan")
|
|
|
|
libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
|
|
|
|
libcxx_libdir = os.path.join(libcxx_path, "lib")
|
|
|
|
libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
|
|
|
|
clang_tsan_cxxflags += ["-std=c++11",
|
|
|
|
"-I%s" % libcxx_incdir,
|
|
|
|
libcxx_so,
|
|
|
|
"-Wl,-rpath=%s" % libcxx_libdir]
|
2014-02-17 21:08:10 +08:00
|
|
|
|
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
|
|
|
|
|
|
|
config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
|
2012-09-18 15:23:54 +08:00
|
|
|
|
|
|
|
# Define CHECK-%os to check for OS-dependent output.
|
|
|
|
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
|
|
|
|
|
2014-05-30 22:08:51 +08:00
|
|
|
config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) )
|
|
|
|
|
2012-09-18 15:23:54 +08:00
|
|
|
# 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
|