1# -*- Python -*- 2 3import os 4import platform 5import re 6import subprocess 7import tempfile 8 9import lit.formats 10import lit.util 11 12from lit.llvm import llvm_config 13from lit.llvm.subst import ToolSubst 14from lit.llvm.subst import FindTool 15 16# Configuration file for the 'lit' test runner. 17 18# name: The name of this test suite. 19config.name = 'Clang' 20 21# testFormat: The test format to use to interpret tests. 22# 23# For now we require '&&' between commands, until they get globally killed and 24# the test runner updated. 25config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 26 27# suffixes: A list of file extensions to treat as test files. 28config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip', 29 '.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.rc'] 30 31# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 32# subdirectories contain auxiliary inputs for various tests in their parent 33# directories. 34config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests'] 35 36# test_source_root: The root path where tests are located. 37config.test_source_root = os.path.dirname(__file__) 38 39# test_exec_root: The root path where tests should be run. 40config.test_exec_root = os.path.join(config.clang_obj_root, 'test') 41 42llvm_config.use_default_substitutions() 43 44llvm_config.use_clang() 45 46config.substitutions.append( 47 ('%src_include_dir', config.clang_src_dir + '/include')) 48 49config.substitutions.append( 50 ('%target_triple', config.target_triple)) 51 52# Propagate path to symbolizer for ASan/MSan. 53llvm_config.with_system_environment( 54 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) 55 56config.substitutions.append(('%PATH%', config.environment['PATH'])) 57 58 59# For each occurrence of a clang tool name, replace it with the full path to 60# the build directory holding that tool. We explicitly specify the directories 61# to search to ensure that we get the tools just built and not some random 62# tools that might happen to be in the user's PATH. 63tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] 64 65tools = [ 66 'apinotes-test', 'c-index-test', 'clang-diff', 'clang-format', 'clang-repl', 67 'clang-tblgen', 'opt', 'llvm-ifs', 'yaml2obj', 68 ToolSubst('%clang_extdef_map', command=FindTool( 69 'clang-extdef-mapping'), unresolved='ignore'), 70] 71 72if config.clang_examples: 73 config.available_features.add('examples') 74 tools.append('clang-interpreter') 75 76def have_host_jit_support(): 77 clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir) 78 79 if not clang_repl_exe: 80 print('clang-repl not found') 81 return False 82 83 try: 84 clang_repl_cmd = subprocess.Popen( 85 [clang_repl_exe, '--host-supports-jit'], stdout=subprocess.PIPE) 86 except OSError: 87 print('could not exec clang-repl') 88 return False 89 90 clang_repl_out = clang_repl_cmd.stdout.read().decode('ascii') 91 clang_repl_cmd.wait() 92 93 return 'true' in clang_repl_out 94 95if have_host_jit_support(): 96 config.available_features.add('host-supports-jit') 97 98if config.clang_staticanalyzer: 99 config.available_features.add('staticanalyzer') 100 tools.append('clang-check') 101 102 if config.clang_staticanalyzer_z3 == '1': 103 config.available_features.add('z3') 104 105 check_analyzer_fixit_path = os.path.join( 106 config.test_source_root, "Analysis", "check-analyzer-fixit.py") 107 config.substitutions.append( 108 ('%check_analyzer_fixit', 109 '"%s" %s' % (config.python_executable, check_analyzer_fixit_path))) 110 111llvm_config.add_tool_substitutions(tools, tool_dirs) 112 113config.substitutions.append( 114 ('%hmaptool', "'%s' %s" % (config.python_executable, 115 os.path.join(config.clang_tools_dir, 'hmaptool')))) 116 117config.substitutions.append(('%host_cc', config.host_cc)) 118config.substitutions.append(('%host_cxx', config.host_cxx)) 119 120 121# Plugins (loadable modules) 122if config.has_plugins and config.llvm_plugin_ext: 123 config.available_features.add('plugins') 124 125# Set available features we allow tests to conditionalize on. 126# 127if config.clang_default_cxx_stdlib != '': 128 config.available_features.add('default-cxx-stdlib-set') 129 130# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. 131if platform.system() not in ['FreeBSD']: 132 config.available_features.add('crash-recovery') 133 134# Support for new pass manager. 135if config.enable_experimental_new_pass_manager: 136 config.available_features.add('experimental-new-pass-manager') 137 138# ANSI escape sequences in non-dumb terminal 139if platform.system() not in ['Windows']: 140 config.available_features.add('ansi-escape-sequences') 141 142# Capability to print utf8 to the terminal. 143# Windows expects codepage, unless Wide API. 144if platform.system() not in ['Windows']: 145 config.available_features.add('utf8-capable-terminal') 146 147# Support for libgcc runtime. Used to rule out tests that require 148# clang to run with -rtlib=libgcc. 149if platform.system() not in ['Darwin', 'Fuchsia']: 150 config.available_features.add('libgcc') 151 152# Case-insensitive file system 153 154 155def is_filesystem_case_insensitive(): 156 handle, path = tempfile.mkstemp( 157 prefix='case-test', dir=config.test_exec_root) 158 isInsensitive = os.path.exists( 159 os.path.join( 160 os.path.dirname(path), 161 os.path.basename(path).upper() 162 )) 163 os.close(handle) 164 os.remove(path) 165 return isInsensitive 166 167 168if is_filesystem_case_insensitive(): 169 config.available_features.add('case-insensitive-filesystem') 170 171# Tests that require the /dev/fd filesystem. 172if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']: 173 config.available_features.add('dev-fd-fs') 174 175# Set on native MS environment. 176if re.match(r'.*-(windows-msvc)$', config.target_triple): 177 config.available_features.add('ms-sdk') 178 179# [PR8833] LLP64-incompatible tests 180if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple): 181 config.available_features.add('LP64') 182 183# [PR12920] "clang-driver" -- set if gcc driver is not used. 184if not re.match(r'.*-(cygwin)$', config.target_triple): 185 config.available_features.add('clang-driver') 186 187# Tests that are specific to the Apple Silicon macOS. 188if re.match(r'^arm64(e)?-apple-(macos|darwin)', config.target_triple): 189 config.available_features.add('apple-silicon-mac') 190 191# [PR18856] Depends to remove opened file. On win32, a file could be removed 192# only if all handles were closed. 193if platform.system() not in ['Windows']: 194 config.available_features.add('can-remove-opened-file') 195 196# Features 197known_arches = ["x86_64", "mips64", "ppc64", "aarch64"] 198if (any(config.target_triple.startswith(x) for x in known_arches)): 199 config.available_features.add("clang-target-64-bits") 200 201 202 203def calculate_arch_features(arch_string): 204 features = [] 205 for arch in arch_string.split(): 206 features.append(arch.lower() + '-registered-target') 207 return features 208 209 210llvm_config.feature_config( 211 [('--assertion-mode', {'ON': 'asserts'}), 212 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}), 213 ('--targets-built', calculate_arch_features), 214 ]) 215 216if lit.util.which('xmllint'): 217 config.available_features.add('xmllint') 218 219if config.enable_backtrace: 220 config.available_features.add('backtrace') 221 222if config.enable_threads: 223 config.available_features.add('thread_support') 224 225# Check if we should allow outputs to console. 226run_console_tests = int(lit_config.params.get('enable_console', '0')) 227if run_console_tests != 0: 228 config.available_features.add('console') 229 230lit.util.usePlatformSdkOnDarwin(config, lit_config) 231macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) 232if macOSSDKVersion is not None: 233 config.available_features.add('macos-sdk-' + str(macOSSDKVersion)) 234 235if os.path.exists('/etc/gentoo-release'): 236 config.available_features.add('gentoo') 237 238if config.enable_shared: 239 config.available_features.add("enable_shared") 240 241# Add a vendor-specific feature. 242if config.clang_vendor_uti: 243 config.available_features.add('clang-vendor=' + config.clang_vendor_uti) 244