[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / tsan / lit.cfg.py
blob4295514f0a5e32386f38b6f0de0a4341594a41ac
1 # -*- Python -*-
3 import os
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.py " % attr_name)
12 return attr_value
14 # Setup config name.
15 config.name = 'ThreadSanitizer' + config.name_suffix
17 # Setup source root.
18 config.test_source_root = os.path.dirname(__file__)
20 # Setup environment variables for running ThreadSanitizer.
21 default_tsan_opts = "atexit_sleep_ms=0"
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 default_tsan_opts += ':abort_on_error=0'
27 # On Darwin, we default to ignore_noninstrumented_modules=1, which also
28 # suppresses some races the tests are supposed to find. Let's run without this
29 # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg.py).
30 default_tsan_opts += ':ignore_noninstrumented_modules=0'
31 default_tsan_opts += ':ignore_interceptors_accesses=0'
33 # Platform-specific default TSAN_OPTIONS for lit tests.
34 if default_tsan_opts:
35 config.environment['TSAN_OPTIONS'] = default_tsan_opts
36 default_tsan_opts += ':'
37 config.substitutions.append(('%env_tsan_opts=',
38 'env TSAN_OPTIONS=' + default_tsan_opts))
40 # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
41 if config.compiler_id == 'GNU':
42 extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lrt", "-pie"]
43 else:
44 extra_cflags = []
46 tsan_incdir = config.test_source_root + "/../"
47 # Setup default compiler flags used with -fsanitize=thread option.
48 clang_tsan_cflags = (["-fsanitize=thread",
49 "-Wall"] +
50 [config.target_cflags] +
51 config.debug_info_flags +
52 extra_cflags +
53 ["-I%s" % tsan_incdir])
54 clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags + ["-std=c++11"] + ["-I%s" % tsan_incdir]
55 # Add additional flags if we're using instrumented libc++.
56 # Instrumented libcxx currently not supported on Darwin.
57 if config.has_libcxx and config.host_os != 'Darwin':
58 # FIXME: Dehardcode this path somehow.
59 libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
60 "tsan", "libcxx_tsan_%s" % config.target_arch)
61 libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
62 libcxx_libdir = os.path.join(libcxx_path, "lib")
63 libcxx_a = os.path.join(libcxx_libdir, "libc++.a")
64 clang_tsan_cxxflags += ["-nostdinc++",
65 "-I%s" % libcxx_incdir]
66 config.substitutions.append( ("%link_libcxx_tsan", libcxx_a) )
67 else:
68 config.substitutions.append( ("%link_libcxx_tsan", "") )
70 def build_invocation(compile_flags):
71 return " " + " ".join([config.clang] + compile_flags) + " "
73 config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
74 config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
76 # Define CHECK-%os to check for OS-dependent output.
77 config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
79 config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash") + " " + config.deflake_threshold + " "))
81 # Default test suffixes.
82 config.suffixes = ['.c', '.cpp', '.m', '.mm']
84 if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']:
85 config.unsupported = True
87 if config.android:
88 config.unsupported = True
90 if not config.parallelism_group:
91 config.parallelism_group = 'shadow-memory'
93 if config.host_os == 'NetBSD':
94 config.substitutions.insert(0, ('%run', config.netbsd_noaslr_prefix))