Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 21 | default_tsan_opts = "atexit_sleep_ms=0" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 22 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 | |
| 28 | # Platform-specific default TSAN_OPTIONS for lit tests. |
| 29 | if default_tsan_opts: |
| 30 | config.environment['TSAN_OPTIONS'] = default_tsan_opts |
| 31 | default_tsan_opts += ':' |
| 32 | config.substitutions.append(('%env_tsan_opts=', |
| 33 | 'env TSAN_OPTIONS=' + default_tsan_opts)) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 34 | |
| 35 | # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread. |
| 36 | if config.compiler_id == 'GNU': |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 37 | extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 38 | else: |
| 39 | extra_cflags = [] |
| 40 | |
| 41 | # Setup default compiler flags used with -fsanitize=thread option. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 42 | clang_tsan_cflags = ["-fsanitize=thread", |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 43 | "-Wall", |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 44 | "-m64"] + config.debug_info_flags + extra_cflags |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 45 | clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags |
| 46 | # Add additional flags if we're using instrumented libc++. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 47 | # Instrumented libcxx currently not supported on Darwin. |
| 48 | if config.has_libcxx and config.host_os != 'Darwin': |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 49 | # FIXME: Dehardcode this path somehow. |
| 50 | libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib", |
| 51 | "tsan", "libcxx_tsan") |
| 52 | libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1") |
| 53 | libcxx_libdir = os.path.join(libcxx_path, "lib") |
| 54 | libcxx_so = os.path.join(libcxx_libdir, "libc++.so") |
| 55 | clang_tsan_cxxflags += ["-std=c++11", |
| 56 | "-I%s" % libcxx_incdir, |
| 57 | libcxx_so, |
| 58 | "-Wl,-rpath=%s" % libcxx_libdir] |
| 59 | |
| 60 | def build_invocation(compile_flags): |
| 61 | return " " + " ".join([config.clang] + compile_flags) + " " |
| 62 | |
| 63 | config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) ) |
| 64 | config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) ) |
| 65 | |
| 66 | # Define CHECK-%os to check for OS-dependent output. |
| 67 | config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) |
| 68 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 69 | config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) ) |
| 70 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 71 | # Default test suffixes. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 72 | config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm'] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 73 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 74 | # ThreadSanitizer tests are currently supported on FreeBSD, Linux and Darwin. |
| 75 | if config.host_os not in ['FreeBSD', 'Linux', 'Darwin']: |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 76 | config.unsupported = True |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 77 | |
| 78 | # Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL |
| 79 | # because the test hangs. |
| 80 | if config.target_arch != 'aarch64': |
| 81 | config.available_features.add('stable-runtime') |