blob: d27500f8e3ea6c03f3ec168c06a0e8a790f0fe46 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001# -*- Python -*-
2
3import os
4
5def get_required_attr(config, attr_name):
6 attr_value = getattr(config, attr_name, None)
7 if not attr_value:
8 lit_config.fatal(
9 "No attribute %r in test configuration! You may need to run "
10 "tests from your build directory or add this attribute "
11 "to lit.site.cfg " % attr_name)
12 return attr_value
13
14# Setup config name.
15config.name = 'ThreadSanitizer'
16
17# Setup source root.
18config.test_source_root = os.path.dirname(__file__)
19
20# Setup environment variables for running ThreadSanitizer.
21tsan_options = "atexit_sleep_ms=0"
22
23config.environment['TSAN_OPTIONS'] = tsan_options
24
25# GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
26if config.compiler_id == 'GNU':
Stephen Hines6a211c52014-07-21 00:49:56 -070027 extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070028else:
29 extra_cflags = []
30
31# Setup default compiler flags used with -fsanitize=thread option.
Stephen Hines2d1fdb22014-05-28 23:58:16 -070032clang_tsan_cflags = ["-fsanitize=thread",
Stephen Hines2d1fdb22014-05-28 23:58:16 -070033 "-Wall",
Stephen Hines6d186232014-11-26 17:56:19 -080034 "-m64"] + config.debug_info_flags + extra_cflags
Stephen Hines2d1fdb22014-05-28 23:58:16 -070035clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags
36# Add additional flags if we're using instrumented libc++.
37if config.has_libcxx:
38 # FIXME: Dehardcode this path somehow.
39 libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
40 "tsan", "libcxx_tsan")
41 libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
42 libcxx_libdir = os.path.join(libcxx_path, "lib")
43 libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
44 clang_tsan_cxxflags += ["-std=c++11",
45 "-I%s" % libcxx_incdir,
46 libcxx_so,
47 "-Wl,-rpath=%s" % libcxx_libdir]
48
49def build_invocation(compile_flags):
50 return " " + " ".join([config.clang] + compile_flags) + " "
51
52config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
53config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
54
55# Define CHECK-%os to check for OS-dependent output.
56config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
57
Stephen Hines6a211c52014-07-21 00:49:56 -070058config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) )
59
Stephen Hines2d1fdb22014-05-28 23:58:16 -070060# Default test suffixes.
61config.suffixes = ['.c', '.cc', '.cpp']
62
Stephen Hines6d186232014-11-26 17:56:19 -080063# ThreadSanitizer tests are currently supported on FreeBSD and Linux only.
64if config.host_os not in ['FreeBSD', 'Linux']:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070065 config.unsupported = True