1# -*- Python -*- 2 3import os 4 5def get_required_attr(config, attr_name): 6 attr_value = getattr(config, attr_name, None) 7 if not attr_value: 8 lit.fatal("No attribute %r in test configuration! You may need to run " 9 "tests from your build directory or add this attribute " 10 "to lit.site.cfg " % attr_name) 11 return attr_value 12 13# Setup config name. 14config.name = 'ThreadSanitizer' 15 16# Setup source root. 17config.test_source_root = os.path.dirname(__file__) 18 19def DisplayNoConfigMessage(): 20 lit.fatal("No site specific configuration available! " + 21 "Try running your test from the build tree or running " + 22 "make check-tsan") 23 24# Figure out LLVM source root. 25llvm_src_root = getattr(config, 'llvm_src_root', None) 26if llvm_src_root is None: 27 # We probably haven't loaded the site-specific configuration: the user 28 # is likely trying to run a test file directly, and the site configuration 29 # wasn't created by the build system. 30 tsan_site_cfg = lit.params.get('tsan_site_config', None) 31 if (tsan_site_cfg) and (os.path.exists(tsan_site_cfg)): 32 lit.load_config(config, tsan_site_cfg) 33 raise SystemExit 34 35 # Try to guess the location of site-specific configuration using llvm-config 36 # util that can point where the build tree is. 37 llvm_config = lit.util.which("llvm-config", config.environment["PATH"]) 38 if not llvm_config: 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 environment variables for running ThreadSanitizer. 52tsan_options = "atexit_sleep_ms=0" 53# Set path to external LLVM symbolizer to run ThreadSanitizer output tests. 54tsan_options += " " + "external_symbolizer_path=" + config.llvm_symbolizer_path 55 56config.environment['TSAN_OPTIONS'] = tsan_options 57 58# Setup default compiler flags used with -fsanitize=thread option. 59# FIXME: Review the set of required flags and check if it can be reduced. 60clang_tsan_cflags = ("-fsanitize=thread " 61 + "-g " 62 + "-Wall " 63 + "-lpthread " 64 + "-ldl ") 65clang_tsan_cxxflags = "--driver-mode=g++ " + clang_tsan_cflags 66config.substitutions.append( ("%clangxx_tsan ", (" " + config.clang + " " + 67 clang_tsan_cxxflags + " ")) ) 68config.substitutions.append( ("%clang_tsan ", (" " + config.clang + " " + 69 clang_tsan_cflags + " ")) ) 70 71# Define CHECK-%os to check for OS-dependent output. 72config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) 73 74# Default test suffixes. 75config.suffixes = ['.c', '.cc', '.cpp'] 76 77# ThreadSanitizer tests are currently supported on Linux only. 78if config.host_os not in ['Linux']: 79 config.unsupported = True 80