6 def get_required_attr(config
, attr_name
):
7 attr_value
= getattr(config
, attr_name
, None)
10 "No attribute %r in test configuration! You may need to run "
11 "tests from your build directory or add this attribute "
12 "to lit.site.cfg.py " % attr_name
18 config
.name
= "ThreadSanitizer" + config
.name_suffix
21 config
.test_source_root
= os
.path
.dirname(__file__
)
23 # Setup environment variables for running ThreadSanitizer.
24 default_tsan_opts
= "atexit_sleep_ms=0"
26 if config
.host_os
== "Darwin":
27 # On Darwin, we default to `abort_on_error=1`, which would make tests run
28 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
29 default_tsan_opts
+= ":abort_on_error=0"
30 # On Darwin, we default to ignore_noninstrumented_modules=1, which also
31 # suppresses some races the tests are supposed to find. Let's run without this
32 # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg.py).
33 default_tsan_opts
+= ":ignore_noninstrumented_modules=0"
34 default_tsan_opts
+= ":ignore_interceptors_accesses=0"
36 # Platform-specific default TSAN_OPTIONS for lit tests.
38 config
.environment
["TSAN_OPTIONS"] = default_tsan_opts
39 default_tsan_opts
+= ":"
40 config
.substitutions
.append(
41 ("%env_tsan_opts=", "env TSAN_OPTIONS=" + default_tsan_opts
)
44 # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
45 if config
.compiler_id
== "GNU":
46 extra_cflags
= ["-fPIE", "-pthread", "-ldl", "-lrt", "-pie"]
50 tsan_incdir
= config
.test_source_root
+ "/../"
51 # Setup default compiler flags used with -fsanitize=thread option.
53 ["-fsanitize=thread", "-Wall"]
54 + [config
.target_cflags
]
55 + config
.debug_info_flags
57 + ["-I%s" % tsan_incdir
]
59 clang_tsan_cxxflags
= (
60 config
.cxx_mode_flags
+ clang_tsan_cflags
+ ["-std=c++11"] + ["-I%s" % tsan_incdir
]
62 # Add additional flags if we're using instrumented libc++.
63 # Instrumented libcxx currently not supported on Darwin.
64 if config
.has_libcxx
and config
.host_os
!= "Darwin":
65 # FIXME: Dehardcode this path somehow.
66 libcxx_path
= os
.path
.join(
67 config
.compiler_rt_obj_root
,
70 "libcxx_tsan_%s" % config
.target_arch
,
72 libcxx_incdir
= os
.path
.join(libcxx_path
, "include", "c++", "v1")
73 libcxx_libdir
= os
.path
.join(libcxx_path
, "lib")
74 libcxx_a
= os
.path
.join(libcxx_libdir
, "libc++.a")
75 clang_tsan_cxxflags
+= ["-nostdinc++", "-I%s" % libcxx_incdir
]
76 config
.substitutions
.append(("%link_libcxx_tsan", libcxx_a
))
78 config
.substitutions
.append(("%link_libcxx_tsan", ""))
81 def build_invocation(compile_flags
):
82 return " " + " ".join([config
.clang
] + compile_flags
) + " "
85 config
.substitutions
.append(("%clang_tsan ", build_invocation(clang_tsan_cflags
)))
86 config
.substitutions
.append(("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags
)))
88 # Define CHECK-%os to check for OS-dependent output.
89 config
.substitutions
.append(("CHECK-%os", ("CHECK-" + config
.host_os
)))
91 config
.substitutions
.append(
94 os
.path
.join(os
.path
.dirname(__file__
), "deflake.bash")
96 + config
.deflake_threshold
101 # Default test suffixes.
102 config
.suffixes
= [".c", ".cpp", ".m", ".mm"]
104 if config
.host_os
not in ["FreeBSD", "Linux", "Darwin", "NetBSD"]:
105 config
.unsupported
= True
108 config
.unsupported
= True
110 if not config
.parallelism_group
:
111 config
.parallelism_group
= "shadow-memory"
113 if config
.host_os
== "NetBSD":
114 config
.substitutions
.insert(0, ("%run", config
.netbsd_noaslr_prefix
))