xref: /aosp_15_r20/external/compiler-rt/test/tsan/lit.cfg (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot# -*- Python -*-
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger Robotimport os
4*7c3d14c8STreehugger Robot
5*7c3d14c8STreehugger Robotdef get_required_attr(config, attr_name):
6*7c3d14c8STreehugger Robot  attr_value = getattr(config, attr_name, None)
7*7c3d14c8STreehugger Robot  if not attr_value:
8*7c3d14c8STreehugger Robot    lit_config.fatal(
9*7c3d14c8STreehugger Robot      "No attribute %r in test configuration! You may need to run "
10*7c3d14c8STreehugger Robot      "tests from your build directory or add this attribute "
11*7c3d14c8STreehugger Robot      "to lit.site.cfg " % attr_name)
12*7c3d14c8STreehugger Robot  return attr_value
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot# Setup config name.
15*7c3d14c8STreehugger Robotconfig.name = 'ThreadSanitizer' + config.name_suffix
16*7c3d14c8STreehugger Robot
17*7c3d14c8STreehugger Robot# Setup source root.
18*7c3d14c8STreehugger Robotconfig.test_source_root = os.path.dirname(__file__)
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot# Setup environment variables for running ThreadSanitizer.
21*7c3d14c8STreehugger Robotdefault_tsan_opts = "atexit_sleep_ms=0"
22*7c3d14c8STreehugger Robot
23*7c3d14c8STreehugger Robotif config.host_os == 'Darwin':
24*7c3d14c8STreehugger Robot  # On Darwin, we default to `abort_on_error=1`, which would make tests run
25*7c3d14c8STreehugger Robot  # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
26*7c3d14c8STreehugger Robot  default_tsan_opts += ':abort_on_error=0'
27*7c3d14c8STreehugger Robot
28*7c3d14c8STreehugger Robot# Platform-specific default TSAN_OPTIONS for lit tests.
29*7c3d14c8STreehugger Robotif default_tsan_opts:
30*7c3d14c8STreehugger Robot  config.environment['TSAN_OPTIONS'] = default_tsan_opts
31*7c3d14c8STreehugger Robot  default_tsan_opts += ':'
32*7c3d14c8STreehugger Robotconfig.substitutions.append(('%env_tsan_opts=',
33*7c3d14c8STreehugger Robot                             'env TSAN_OPTIONS=' + default_tsan_opts))
34*7c3d14c8STreehugger Robot
35*7c3d14c8STreehugger Robot# GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
36*7c3d14c8STreehugger Robotif config.compiler_id == 'GNU':
37*7c3d14c8STreehugger Robot  extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
38*7c3d14c8STreehugger Robotelse:
39*7c3d14c8STreehugger Robot  extra_cflags = []
40*7c3d14c8STreehugger Robot
41*7c3d14c8STreehugger Robot# Setup default compiler flags used with -fsanitize=thread option.
42*7c3d14c8STreehugger Robotclang_tsan_cflags = (["-fsanitize=thread",
43*7c3d14c8STreehugger Robot                      "-Wall"] +
44*7c3d14c8STreehugger Robot                      [config.target_cflags] +
45*7c3d14c8STreehugger Robot                      config.debug_info_flags +
46*7c3d14c8STreehugger Robot                      extra_cflags)
47*7c3d14c8STreehugger Robotclang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags
48*7c3d14c8STreehugger Robot# Add additional flags if we're using instrumented libc++.
49*7c3d14c8STreehugger Robot# Instrumented libcxx currently not supported on Darwin.
50*7c3d14c8STreehugger Robotif config.has_libcxx and config.host_os != 'Darwin':
51*7c3d14c8STreehugger Robot  # FIXME: Dehardcode this path somehow.
52*7c3d14c8STreehugger Robot  libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib",
53*7c3d14c8STreehugger Robot                             "tsan", "libcxx_tsan_" + config.target_arch)
54*7c3d14c8STreehugger Robot  libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
55*7c3d14c8STreehugger Robot  libcxx_libdir = os.path.join(libcxx_path, "lib")
56*7c3d14c8STreehugger Robot  libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
57*7c3d14c8STreehugger Robot  clang_tsan_cxxflags += ["-std=c++11",
58*7c3d14c8STreehugger Robot                          "-nostdinc++",
59*7c3d14c8STreehugger Robot                          "-I%s" % libcxx_incdir,
60*7c3d14c8STreehugger Robot                          libcxx_so,
61*7c3d14c8STreehugger Robot                          "-Wl,-rpath=%s" % libcxx_libdir]
62*7c3d14c8STreehugger Robot
63*7c3d14c8STreehugger Robotdef build_invocation(compile_flags):
64*7c3d14c8STreehugger Robot  return " " + " ".join([config.clang] + compile_flags) + " "
65*7c3d14c8STreehugger Robot
66*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
67*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )
68*7c3d14c8STreehugger Robot
69*7c3d14c8STreehugger Robot# Define CHECK-%os to check for OS-dependent output.
70*7c3d14c8STreehugger Robotconfig.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
71*7c3d14c8STreehugger Robot
72*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) )
73*7c3d14c8STreehugger Robot
74*7c3d14c8STreehugger Robot# Default test suffixes.
75*7c3d14c8STreehugger Robotconfig.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm']
76*7c3d14c8STreehugger Robot
77*7c3d14c8STreehugger Robot# ThreadSanitizer tests are currently supported on FreeBSD, Linux and Darwin.
78*7c3d14c8STreehugger Robotif config.host_os not in ['FreeBSD', 'Linux', 'Darwin']:
79*7c3d14c8STreehugger Robot  config.unsupported = True
80*7c3d14c8STreehugger Robot
81*7c3d14c8STreehugger Robot# Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
82*7c3d14c8STreehugger Robot# because the test hangs.
83*7c3d14c8STreehugger Robotif config.target_arch != 'aarch64':
84*7c3d14c8STreehugger Robot  config.available_features.add('stable-runtime')
85