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', 29 '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs'] 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', 67 'clang-tblgen', 'opt', 'llvm-ifs', 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 76if config.clang_staticanalyzer: 77 config.available_features.add('staticanalyzer') 78 tools.append('clang-check') 79 80 if config.clang_staticanalyzer_z3 == '1': 81 config.available_features.add('z3') 82 83 check_analyzer_fixit_path = os.path.join( 84 config.test_source_root, "Analysis", "check-analyzer-fixit.py") 85 config.substitutions.append( 86 ('%check_analyzer_fixit', 87 '"%s" %s' % (config.python_executable, check_analyzer_fixit_path))) 88 89llvm_config.add_tool_substitutions(tools, tool_dirs) 90 91config.substitutions.append( 92 ('%hmaptool', "'%s' %s" % (config.python_executable, 93 os.path.join(config.clang_tools_dir, 'hmaptool')))) 94 95 96# Plugins (loadable modules) 97if config.has_plugins and config.llvm_plugin_ext: 98 config.available_features.add('plugins') 99 100# Set available features we allow tests to conditionalize on. 101# 102if config.clang_default_cxx_stdlib != '': 103 config.available_features.add('default-cxx-stdlib-set') 104 105# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. 106if platform.system() not in ['FreeBSD']: 107 config.available_features.add('crash-recovery') 108 109# Support for new pass manager. 110if config.enable_experimental_new_pass_manager: 111 config.available_features.add('experimental-new-pass-manager') 112 113# ANSI escape sequences in non-dumb terminal 114if platform.system() not in ['Windows']: 115 config.available_features.add('ansi-escape-sequences') 116 117# Capability to print utf8 to the terminal. 118# Windows expects codepage, unless Wide API. 119if platform.system() not in ['Windows']: 120 config.available_features.add('utf8-capable-terminal') 121 122# Support for libgcc runtime. Used to rule out tests that require 123# clang to run with -rtlib=libgcc. 124if platform.system() not in ['Darwin', 'Fuchsia']: 125 config.available_features.add('libgcc') 126 127# Case-insensitive file system 128 129 130def is_filesystem_case_insensitive(): 131 handle, path = tempfile.mkstemp( 132 prefix='case-test', dir=config.test_exec_root) 133 isInsensitive = os.path.exists( 134 os.path.join( 135 os.path.dirname(path), 136 os.path.basename(path).upper() 137 )) 138 os.close(handle) 139 os.remove(path) 140 return isInsensitive 141 142 143if is_filesystem_case_insensitive(): 144 config.available_features.add('case-insensitive-filesystem') 145 146# Tests that require the /dev/fd filesystem. 147if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']: 148 config.available_features.add('dev-fd-fs') 149 150# Set on native MS environment. 151if re.match(r'.*-(windows-msvc)$', config.target_triple): 152 config.available_features.add('ms-sdk') 153 154# [PR8833] LLP64-incompatible tests 155if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple): 156 config.available_features.add('LP64') 157 158# [PR12920] "clang-driver" -- set if gcc driver is not used. 159if not re.match(r'.*-(cygwin)$', config.target_triple): 160 config.available_features.add('clang-driver') 161 162# Tests that are specific to the Apple Silicon macOS. 163if re.match(r'^arm64(e)?-apple-(macos|darwin)', config.target_triple): 164 config.available_features.add('apple-silicon-mac') 165 166# [PR18856] Depends to remove opened file. On win32, a file could be removed 167# only if all handles were closed. 168if platform.system() not in ['Windows']: 169 config.available_features.add('can-remove-opened-file') 170 171# Features 172known_arches = ["x86_64", "mips64", "ppc64", "aarch64"] 173if (any(config.target_triple.startswith(x) for x in known_arches)): 174 config.available_features.add("clang-target-64-bits") 175 176 177 178def calculate_arch_features(arch_string): 179 features = [] 180 for arch in arch_string.split(): 181 features.append(arch.lower() + '-registered-target') 182 return features 183 184 185llvm_config.feature_config( 186 [('--assertion-mode', {'ON': 'asserts'}), 187 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}), 188 ('--targets-built', calculate_arch_features), 189 ]) 190 191if lit.util.which('xmllint'): 192 config.available_features.add('xmllint') 193 194if config.enable_backtrace: 195 config.available_features.add('backtrace') 196 197if config.enable_threads: 198 config.available_features.add('thread_support') 199 200# Check if we should allow outputs to console. 201run_console_tests = int(lit_config.params.get('enable_console', '0')) 202if run_console_tests != 0: 203 config.available_features.add('console') 204 205lit.util.usePlatformSdkOnDarwin(config, lit_config) 206macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) 207if macOSSDKVersion is not None: 208 config.available_features.add('macos-sdk-' + str(macOSSDKVersion)) 209 210if os.path.exists('/etc/gentoo-release'): 211 config.available_features.add('gentoo') 212 213if config.enable_shared: 214 config.available_features.add("enable_shared") 215 216# Add a vendor-specific feature. 217if config.clang_vendor_uti: 218 config.available_features.add('clang-vendor=' + config.clang_vendor_uti) 219