1 # -*- Python -*- 2 3 import os 4 5 # Setup config name. 6 config.name = 'ThreadSanitizer' 7 8 # Setup source root. 9 config.test_source_root = os.path.dirname(__file__) 10 11 def DisplayNoConfigMessage(): 12 lit.fatal("No site specific configuration available! " + 13 "Try running your test from the build tree or running " + 14 "make check-tsan") 15 16 # Figure out LLVM source root. 17 llvm_src_root = getattr(config, 'llvm_src_root', None) 18 if llvm_src_root is None: 19 # We probably haven't loaded the site-specific configuration: the user 20 # is likely trying to run a test file directly, and the site configuration 21 # wasn't created by the build system. 22 tsan_site_cfg = lit.params.get('tsan_site_config', None) 23 if (tsan_site_cfg) and (os.path.exists(tsan_site_cfg)): 24 lit.load_config(config, tsan_site_cfg) 25 raise SystemExit 26 27 # Try to guess the location of site-specific configuration using llvm-config 28 # util that can point where the build tree is. 29 llvm_config = lit.util.which("llvm-config", config.environment["PATH"]) 30 if not llvm_config: 31 DisplayNoConfigMessage() 32 33 # Validate that llvm-config points to the same source tree. 34 llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip() 35 tsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt", 36 "lib", "tsan", "lit_tests") 37 if (os.path.realpath(tsan_test_src_root) != 38 os.path.realpath(config.test_source_root)): 39 DisplayNoConfigMessage() 40 41 # Find out the presumed location of generated site config. 42 llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip() 43 tsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", 44 "lib", "tsan", "lit_tests", "lit.site.cfg") 45 if (not tsan_site_cfg) or (not os.path.exists(tsan_site_cfg)): 46 DisplayNoConfigMessage() 47 48 lit.load_config(config, tsan_site_cfg) 49 raise SystemExit 50 51 # Setup attributes common for all compiler-rt projects. 52 compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt", 53 "lib", "lit.common.cfg") 54 if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)): 55 lit.fatal("Can't find common compiler-rt lit config at: %r" 56 % compiler_rt_lit_cfg) 57 lit.load_config(config, compiler_rt_lit_cfg) 58 59 # Setup environment variables for running ThreadSanitizer. 60 tsan_options = "atexit_sleep_ms=0" 61 # Get path to external LLVM symbolizer to run ThreadSanitizer output tests. 62 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 63 if llvm_tools_dir: 64 llvm_symbolizer_path = os.path.join(llvm_tools_dir, "llvm-symbolizer") 65 tsan_options += " " + "external_symbolizer_path=" + llvm_symbolizer_path 66 67 config.environment['TSAN_OPTIONS'] = tsan_options 68 69 # Setup default compiler flags used with -fsanitize=thread option. 70 # FIXME: Review the set of required flags and check if it can be reduced. 71 clang_tsan_cflags = ("-fsanitize=thread " 72 + "-fPIE " 73 + "-fno-builtin " 74 + "-g " 75 + "-Wall " 76 + "-pie " 77 + "-lpthread " 78 + "-ldl ") 79 clang_tsan_cxxflags = "-ccc-cxx " + clang_tsan_cflags 80 config.substitutions.append( ("%clangxx_tsan ", (" " + config.clang + " " + 81 clang_tsan_cxxflags + " ")) ) 82 config.substitutions.append( ("%clang_tsan ", (" " + config.clang + " " + 83 clang_tsan_cflags + " ")) ) 84 85 # Define CHECK-%os to check for OS-dependent output. 86 config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) 87 88 # Default test suffixes. 89 config.suffixes = ['.c', '.cc', '.cpp'] 90 91 # ThreadSanitizer tests are currently supported on Linux only. 92 if config.host_os not in ['Linux']: 93 config.unsupported = True 94