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.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. 14 config.name = 'MemorySanitizer' 15 16 # Setup source root. 17 config.test_source_root = os.path.dirname(__file__) 18 19 def DisplayNoConfigMessage(): 20 lit.fatal("No site specific configuration available! " + 21 "Try running your test from the build tree or running " + 22 "make check-msan") 23 24 # Figure out LLVM source root. 25 llvm_src_root = getattr(config, 'llvm_src_root', None) 26 if 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 msan_site_cfg = lit.params.get('msan_site_config', None) 31 if (msan_site_cfg) and (os.path.exists(msan_site_cfg)): 32 lit.load_config(config, msan_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 msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", 44 "lib", "msan", "lit_tests", "lit.site.cfg") 45 if (not msan_site_cfg) or (not os.path.exists(msan_site_cfg)): 46 DisplayNoConfigMessage() 47 48 lit.load_config(config, msan_site_cfg) 49 raise SystemExit 50 51 # Setup default compiler flags used with -fsanitize=memory option. 52 clang_msan_cflags = ["-fsanitize=memory", 53 "-mno-omit-leaf-frame-pointer", 54 "-fno-omit-frame-pointer", 55 "-fno-optimize-sibling-calls", 56 "-g"] 57 clang_msan_cxxflags = ["--driver-mode=g++ "] + clang_msan_cflags 58 config.substitutions.append( ("%clang_msan ", 59 " ".join([config.clang] + clang_msan_cflags) + 60 " ") ) 61 config.substitutions.append( ("%clangxx_msan ", 62 " ".join([config.clang] + clang_msan_cxxflags) + 63 " ") ) 64 65 # Setup path to external LLVM symbolizer to run MemorySanitizer output tests. 66 config.environment['MSAN_SYMBOLIZER_PATH'] = config.llvm_symbolizer_path 67 68 # Default test suffixes. 69 config.suffixes = ['.c', '.cc', '.cpp'] 70 71 # MemorySanitizer tests are currently supported on Linux only. 72 if config.host_os not in ['Linux']: 73 config.unsupported = True 74