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', '.cppm', '.m', '.mm', '.cu', 29 '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs'] 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 46# Propagate path to symbolizer for ASan/MSan. 47llvm_config.with_system_environment( 48 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) 49 50config.substitutions.append(('%PATH%', config.environment['PATH'])) 51 52 53# For each occurrence of a clang tool name, replace it with the full path to 54# the build directory holding that tool. We explicitly specify the directories 55# to search to ensure that we get the tools just built and not some random 56# tools that might happen to be in the user's PATH. 57tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] 58 59tools = [ 60 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen', 61 'opt', 62 ToolSubst('%clang_func_map', command=FindTool( 63 'clang-func-mapping'), unresolved='ignore'), 64] 65 66if config.clang_examples: 67 config.available_features.add('examples') 68 tools.append('clang-interpreter') 69 70llvm_config.add_tool_substitutions(tools, tool_dirs) 71 72config.substitutions.append( 73 ('%hmaptool', "'%s' %s" % (config.python_executable, 74 os.path.join(config.clang_tools_dir, 'hmaptool')))) 75 76# Plugins (loadable modules) 77# TODO: This should be supplied by Makefile or autoconf. 78if sys.platform in ['win32', 'cygwin']: 79 has_plugins = config.enable_shared 80else: 81 has_plugins = True 82 83if has_plugins and config.llvm_plugin_ext: 84 config.available_features.add('plugins') 85 86# Set available features we allow tests to conditionalize on. 87# 88if config.clang_default_cxx_stdlib != '': 89 config.available_features.add('default-cxx-stdlib-set') 90 91# Enabled/disabled features 92if config.clang_staticanalyzer: 93 config.available_features.add('staticanalyzer') 94 95 if config.clang_staticanalyzer_z3 == '1': 96 config.available_features.add('z3') 97 98# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. 99if platform.system() not in ['FreeBSD']: 100 config.available_features.add('crash-recovery') 101 102# ANSI escape sequences in non-dumb terminal 103if platform.system() not in ['Windows']: 104 config.available_features.add('ansi-escape-sequences') 105 106# Capability to print utf8 to the terminal. 107# Windows expects codepage, unless Wide API. 108if platform.system() not in ['Windows']: 109 config.available_features.add('utf8-capable-terminal') 110 111# Support for libgcc runtime. Used to rule out tests that require 112# clang to run with -rtlib=libgcc. 113if platform.system() not in ['Darwin', 'Fuchsia']: 114 config.available_features.add('libgcc') 115 116# Case-insensitive file system 117 118 119def is_filesystem_case_insensitive(): 120 handle, path = tempfile.mkstemp( 121 prefix='case-test', dir=config.test_exec_root) 122 isInsensitive = os.path.exists( 123 os.path.join( 124 os.path.dirname(path), 125 os.path.basename(path).upper() 126 )) 127 os.close(handle) 128 os.remove(path) 129 return isInsensitive 130 131 132if is_filesystem_case_insensitive(): 133 config.available_features.add('case-insensitive-filesystem') 134 135# Tests that require the /dev/fd filesystem. 136if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']: 137 config.available_features.add('dev-fd-fs') 138 139# Not set on native MS environment. 140if not re.match(r'.*-win32$', config.target_triple): 141 config.available_features.add('non-ms-sdk') 142 143# Not set on native PS4 environment. 144if not re.match(r'.*-scei-ps4', config.target_triple): 145 config.available_features.add('non-ps4-sdk') 146 147# [PR8833] LLP64-incompatible tests 148if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple): 149 config.available_features.add('LP64') 150 151# [PR12920] "clang-driver" -- set if gcc driver is not used. 152if not re.match(r'.*-(cygwin)$', config.target_triple): 153 config.available_features.add('clang-driver') 154 155# [PR18856] Depends to remove opened file. On win32, a file could be removed 156# only if all handles were closed. 157if platform.system() not in ['Windows']: 158 config.available_features.add('can-remove-opened-file') 159 160 161def calculate_arch_features(arch_string): 162 features = [] 163 for arch in arch_string.split(): 164 features.append(arch.lower() + '-registered-target') 165 return features 166 167 168llvm_config.feature_config( 169 [('--assertion-mode', {'ON': 'asserts'}), 170 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}), 171 ('--targets-built', calculate_arch_features) 172 ]) 173 174if lit.util.which('xmllint'): 175 config.available_features.add('xmllint') 176 177if config.enable_backtrace: 178 config.available_features.add('backtrace') 179 180# Check if we should allow outputs to console. 181run_console_tests = int(lit_config.params.get('enable_console', '0')) 182if run_console_tests != 0: 183 config.available_features.add('console') 184 185lit.util.usePlatformSdkOnDarwin(config, lit_config) 186macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) 187if macOSSDKVersion is not None: 188 config.available_features.add('macos-sdk-' + macOSSDKVersion) 189