1 # -*- Python -*- 2 3 import os 4 5 # Setup config name. 6 config.name = 'UndefinedBehaviorSanitizer' 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-ubsan") 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 or we're performing an out-of-tree build. 22 ubsan_site_cfg = lit.params.get('ubsan_site_config', None) 23 if ubsan_site_cfg and os.path.exists(ubsan_site_cfg): 24 lit.load_config(config, ubsan_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 ubsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt", 36 "lib", "ubsan", "lit_tests") 37 if (os.path.realpath(ubsan_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 ubsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", 44 "lib", "ubsan", "lit_tests", "lit.site.cfg") 45 if not ubsan_site_cfg or not os.path.exists(ubsan_site_cfg): 46 DisplayNoConfigMessage() 47 48 lit.load_config(config, ubsan_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 # Default test suffixes. 60 config.suffixes = ['.c', '.cc', '.cpp'] 61 62 # UndefinedBehaviorSanitizer tests are currently supported on 63 # Linux and Darwin only. 64 if config.host_os not in ['Linux', 'Darwin']: 65 config.unsupported = True 66