]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | # -*- Python -*- |
2 | ||
3 | import os | |
4 | ||
5 | def 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. | |
15 | config.name = 'ThreadSanitizer' | |
16 | ||
17 | # Setup source root. | |
18 | config.test_source_root = os.path.dirname(__file__) | |
19 | ||
20 | # Setup environment variables for running ThreadSanitizer. | |
21 | tsan_options = "atexit_sleep_ms=0" | |
22 | ||
92a42be0 SL |
23 | if config.host_os == 'Darwin': |
24 | # On Darwin, we default to `abort_on_error=1`, which would make tests run | |
25 | # much slower. Let's override this and run lit tests with 'abort_on_error=0'. | |
26 | tsan_options += ':abort_on_error=0' | |
27 | ||
1a4d82fc JJ |
28 | config.environment['TSAN_OPTIONS'] = tsan_options |
29 | ||
92a42be0 SL |
30 | # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread. |
31 | if config.compiler_id == 'GNU': | |
32 | extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"] | |
33 | else: | |
34 | extra_cflags = [] | |
35 | ||
1a4d82fc | 36 | # Setup default compiler flags used with -fsanitize=thread option. |
1a4d82fc | 37 | clang_tsan_cflags = ["-fsanitize=thread", |
1a4d82fc | 38 | "-Wall", |
92a42be0 | 39 | "-m64"] + config.debug_info_flags + extra_cflags |
1a4d82fc | 40 | clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags |
92a42be0 SL |
41 | # Add additional flags if we're using instrumented libc++. |
42 | # Instrumented libcxx currently not supported on Darwin. | |
43 | if config.has_libcxx and config.host_os != 'Darwin': | |
44 | # FIXME: Dehardcode this path somehow. | |
45 | libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib", | |
46 | "tsan", "libcxx_tsan") | |
47 | libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1") | |
48 | libcxx_libdir = os.path.join(libcxx_path, "lib") | |
49 | libcxx_so = os.path.join(libcxx_libdir, "libc++.so") | |
50 | clang_tsan_cxxflags += ["-std=c++11", | |
51 | "-I%s" % libcxx_incdir, | |
52 | libcxx_so, | |
53 | "-Wl,-rpath=%s" % libcxx_libdir] | |
1a4d82fc JJ |
54 | |
55 | def build_invocation(compile_flags): | |
56 | return " " + " ".join([config.clang] + compile_flags) + " " | |
57 | ||
58 | config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) ) | |
59 | config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) ) | |
60 | ||
61 | # Define CHECK-%os to check for OS-dependent output. | |
62 | config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) | |
63 | ||
92a42be0 SL |
64 | config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) ) |
65 | ||
1a4d82fc JJ |
66 | # Default test suffixes. |
67 | config.suffixes = ['.c', '.cc', '.cpp'] | |
68 | ||
92a42be0 SL |
69 | # ThreadSanitizer tests are currently supported on FreeBSD, Linux and Darwin. |
70 | if config.host_os not in ['FreeBSD', 'Linux', 'Darwin']: | |
1a4d82fc | 71 | config.unsupported = True |
92a42be0 SL |
72 | |
73 | # Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL | |
74 | # because the test hangs. | |
75 | if config.target_arch != 'aarch64': | |
76 | config.available_features.add('stable-runtime') |