1# -*- Python -*- 2 3# Configuration file for 'lit' test runner. 4# This file contains common rules for various compiler-rt testsuites. 5# It is mostly copied from lit.cfg used by Clang. 6import os 7import platform 8import re 9import subprocess 10 11import lit.formats 12import lit.util 13 14# Setup test format. Use bash on Unix and the lit shell on Windows. 15execute_external = (not sys.platform in ['win32']) 16config.test_format = lit.formats.ShTest(execute_external) 17if execute_external: 18 config.available_features.add('shell') 19 20# Setup clang binary. 21compiler_path = getattr(config, 'clang', None) 22if (not compiler_path) or (not os.path.exists(compiler_path)): 23 lit_config.fatal("Can't find compiler on path %r" % compiler_path) 24 25compiler_id = getattr(config, 'compiler_id', None) 26if compiler_id == "Clang": 27 if platform.system() != 'Windows': 28 config.cxx_mode_flags = ["--driver-mode=g++"] 29 else: 30 config.cxx_mode_flags = [] 31 # We assume that sanitizers should provide good enough error 32 # reports and stack traces even with minimal debug info. 33 config.debug_info_flags = ["-gline-tables-only"] 34 if platform.system() == 'Windows': 35 config.debug_info_flags.append("-gcodeview") 36elif compiler_id == 'GNU': 37 config.cxx_mode_flags = ["-x c++"] 38 config.debug_info_flags = ["-g"] 39else: 40 lit_config.fatal("Unsupported compiler id: %r" % compiler_id) 41# Add compiler ID to the list of available features. 42config.available_features.add(compiler_id) 43 44# Clear some environment variables that might affect Clang. 45possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', 46 'MSAN_OPTIONS', 'UBSAN_OPTIONS', 47 'COMPILER_PATH', 'RC_DEBUG_OPTIONS', 48 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', 49 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 50 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', 51 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', 52 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', 53 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', 54 'LIBCLANG_RESOURCE_USAGE', 55 'LIBCLANG_CODE_COMPLETION_LOGGING'] 56# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. 57if platform.system() != 'Windows': 58 possibly_dangerous_env_vars.append('INCLUDE') 59for name in possibly_dangerous_env_vars: 60 if name in config.environment: 61 del config.environment[name] 62 63# Tweak PATH to include llvm tools dir. 64llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 65if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)): 66 lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir) 67path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) 68config.environment['PATH'] = path 69 70# Help MSVS link.exe find the standard libraries. 71# Make sure we only try to use it when targetting Windows. 72if platform.system() == 'Windows' and '-win' in config.target_triple: 73 config.environment['LIB'] = os.environ['LIB'] 74 75# Use ugly construction to explicitly prohibit "clang", "clang++" etc. 76# in RUN lines. 77config.substitutions.append( 78 (' clang', """\n\n*** Do not use 'clangXXX' in tests, 79 instead define '%clangXXX' substitution in lit config. ***\n\n""") ) 80 81# Allow tests to be executed on a simulator or remotely. 82config.substitutions.append( ('%run', config.emulator) ) 83 84# Define CHECK-%os to check for OS-dependent output. 85config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) 86 87if config.host_os == 'Windows': 88 # FIXME: This isn't quite right. Specifically, it will succeed if the program 89 # does not crash but exits with a non-zero exit code. We ought to merge 90 # KillTheDoctor and not --crash to make the latter more useful and remove the 91 # need for this substitution. 92 config.substitutions.append( ("%expect_crash ", "not KillTheDoctor ") ) 93else: 94 config.substitutions.append( ("%expect_crash ", "not --crash ") ) 95 96# Add supported compiler_rt architectures to a list of available features. 97compiler_rt_arch = getattr(config, 'compiler_rt_arch', None) 98if compiler_rt_arch: 99 for arch in compiler_rt_arch.split(";"): 100 config.available_features.add(arch + "-supported-target") 101 102compiler_rt_debug = getattr(config, 'compiler_rt_debug', False) 103if not compiler_rt_debug: 104 config.available_features.add('compiler-rt-optimized') 105 106sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True) 107if sanitizer_can_use_cxxabi: 108 config.available_features.add('cxxabi') 109 110# Test lld if it is available. 111if config.has_lld: 112 config.available_features.add('lld') 113 114lit.util.usePlatformSdkOnDarwin(config, lit_config) 115 116def is_darwin_lto_supported(): 117 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')) 118 119def is_linux_lto_supported(): 120 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')): 121 return False 122 123 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE) 124 ld_out = ld_cmd.stdout.read().decode() 125 ld_cmd.wait() 126 127 if not '-plugin' in ld_out: 128 return False 129 130 return True 131 132def is_windows_lto_supported(): 133 return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe')) 134 135if config.host_os == 'Darwin' and is_darwin_lto_supported(): 136 config.lto_supported = True 137 config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir] 138 config.lto_flags = [] 139elif config.host_os == 'Linux' and is_linux_lto_supported(): 140 config.lto_supported = True 141 config.lto_launch = [] 142 config.lto_flags = ["-fuse-ld=gold"] 143elif config.host_os == 'Windows' and is_windows_lto_supported(): 144 config.lto_supported = True 145 config.lto_launch = [] 146 config.lto_flags = ["-fuse-ld=lld"] 147else: 148 config.lto_supported = False 149 150# Ask llvm-config about assertion mode. 151try: 152 llvm_config_cmd = subprocess.Popen( 153 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'], 154 stdout = subprocess.PIPE, 155 env=config.environment) 156except OSError: 157 print("Could not find llvm-config in " + llvm_tools_dir) 158 exit(42) 159 160if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')): 161 config.available_features.add('asserts') 162llvm_config_cmd.wait() 163 164# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some 165# retries. We don't do this on otther platforms because it's slower. 166if platform.system() == 'Windows': 167 config.test_retry_attempts = 2 168