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. 6 import os 7 import platform 8 import re 9 import subprocess 10 11 import lit.formats 12 import lit.util 13 14 # Setup test format. Use bash on Unix and the lit shell on Windows. 15 execute_external = (not sys.platform in ['win32']) 16 config.test_format = lit.formats.ShTest(execute_external) 17 if execute_external: 18 config.available_features.add('shell') 19 20 # Setup clang binary. 21 compiler_path = getattr(config, 'clang', None) 22 if (not compiler_path) or (not os.path.exists(compiler_path)): 23 lit_config.fatal("Can't find compiler on path %r" % compiler_path) 24 25 compiler_id = getattr(config, 'compiler_id', None) 26 if 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") 36 elif compiler_id == 'GNU': 37 config.cxx_mode_flags = ["-x c++"] 38 config.debug_info_flags = ["-g"] 39 else: 40 lit_config.fatal("Unsupported compiler id: %r" % compiler_id) 41 # Add compiler ID to the list of available features. 42 config.available_features.add(compiler_id) 43 44 # Clear some environment variables that might affect Clang. 45 possibly_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. 57 if platform.system() != 'Windows': 58 possibly_dangerous_env_vars.append('INCLUDE') 59 for 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. 64 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 65 if (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) 67 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) 68 config.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. 72 if 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. 77 config.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. 82 config.substitutions.append( ('%run', config.emulator) ) 83 84 # Define CHECK-%os to check for OS-dependent output. 85 config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) 86 87 if 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 ") ) 93 else: 94 config.substitutions.append( ("%expect_crash ", "not --crash ") ) 95 96 # Add supported compiler_rt architectures to a list of available features. 97 compiler_rt_arch = getattr(config, 'compiler_rt_arch', None) 98 if compiler_rt_arch: 99 for arch in compiler_rt_arch.split(";"): 100 config.available_features.add(arch + "-supported-target") 101 102 compiler_rt_debug = getattr(config, 'compiler_rt_debug', False) 103 if not compiler_rt_debug: 104 config.available_features.add('compiler-rt-optimized') 105 106 sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True) 107 if sanitizer_can_use_cxxabi: 108 config.available_features.add('cxxabi') 109 110 # Test lld if it is available. 111 if config.has_lld: 112 config.available_features.add('lld') 113 114 lit.util.usePlatformSdkOnDarwin(config, lit_config) 115 116 def is_darwin_lto_supported(): 117 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')) 118 119 def 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 132 def is_windows_lto_supported(): 133 return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe')) 134 135 if 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 = [] 139 elif 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"] 143 elif 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"] 147 else: 148 config.lto_supported = False 149 150 # Ask llvm-config about assertion mode. 151 try: 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) 156 except OSError: 157 print("Could not find llvm-config in " + llvm_tools_dir) 158 exit(42) 159 160 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')): 161 config.available_features.add('asserts') 162 llvm_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. 166 if platform.system() == 'Windows': 167 config.test_retry_attempts = 2 168