12 from lit
.llvm
import llvm_config
13 from lit
.llvm
.subst
import ToolSubst
14 from lit
.llvm
.subst
import FindTool
16 # Configuration file for the 'lit' test runner.
18 # name: The name of this test suite.
21 # testFormat: The test format to use to interpret tests.
23 # For now we require '&&' between commands, until they get globally killed and
24 # the test runner updated.
25 config
.test_format
= lit
.formats
.ShTest(not llvm_config
.use_lit_shell
)
27 # suffixes: A list of file extensions to treat as test files.
28 config
.suffixes
= ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip', '.hlsl',
29 '.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.rc']
31 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
32 # subdirectories contain auxiliary inputs for various tests in their parent
34 config
.excludes
= ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests']
36 # test_source_root: The root path where tests are located.
37 config
.test_source_root
= os
.path
.dirname(__file__
)
39 # test_exec_root: The root path where tests should be run.
40 config
.test_exec_root
= os
.path
.join(config
.clang_obj_root
, 'test')
42 llvm_config
.use_default_substitutions()
44 llvm_config
.use_clang()
46 config
.substitutions
.append(
47 ('%src_include_dir', config
.clang_src_dir
+ '/include'))
49 config
.substitutions
.append(
50 ('%target_triple', config
.target_triple
))
52 config
.substitutions
.append(('%PATH%', config
.environment
['PATH']))
55 # For each occurrence of a clang tool name, replace it with the full path to
56 # the build directory holding that tool. We explicitly specify the directories
57 # to search to ensure that we get the tools just built and not some random
58 # tools that might happen to be in the user's PATH.
59 tool_dirs
= [config
.clang_tools_dir
, config
.llvm_tools_dir
]
62 'apinotes-test', 'c-index-test', 'clang-diff', 'clang-format', 'clang-repl', 'clang-offload-packager',
63 'clang-tblgen', 'clang-scan-deps', 'opt', 'llvm-ifs', 'yaml2obj', 'clang-linker-wrapper',
64 ToolSubst('%clang_extdef_map', command
=FindTool(
65 'clang-extdef-mapping'), unresolved
='ignore'),
68 if config
.clang_examples
:
69 config
.available_features
.add('examples')
71 def have_host_jit_feature_support(feature_name
):
72 clang_repl_exe
= lit
.util
.which('clang-repl', config
.clang_tools_dir
)
74 if not clang_repl_exe
:
78 clang_repl_cmd
= subprocess
.Popen(
79 [clang_repl_exe
, '--host-supports-' + feature_name
], stdout
=subprocess
.PIPE
)
81 print('could not exec clang-repl')
84 clang_repl_out
= clang_repl_cmd
.stdout
.read().decode('ascii')
87 return 'true' in clang_repl_out
89 if have_host_jit_feature_support('jit'):
90 config
.available_features
.add('host-supports-jit')
92 if config
.clang_staticanalyzer
:
93 config
.available_features
.add('staticanalyzer')
94 tools
.append('clang-check')
96 if config
.clang_staticanalyzer_z3
:
97 config
.available_features
.add('z3')
99 config
.available_features
.add('no-z3')
101 check_analyzer_fixit_path
= os
.path
.join(
102 config
.test_source_root
, "Analysis", "check-analyzer-fixit.py")
103 config
.substitutions
.append(
104 ('%check_analyzer_fixit',
105 '"%s" %s' % (config
.python_executable
, check_analyzer_fixit_path
)))
107 llvm_config
.add_tool_substitutions(tools
, tool_dirs
)
109 config
.substitutions
.append(
110 ('%hmaptool', "'%s' %s" % (config
.python_executable
,
111 os
.path
.join(config
.clang_src_dir
, 'utils', 'hmaptool', 'hmaptool'))))
113 config
.substitutions
.append(
115 '"%s" %s' % (config
.python_executable
, os
.path
.join(config
.clang_src_dir
, 'utils',
116 'module-deps-to-rsp.py'))))
118 config
.substitutions
.append(('%host_cc', config
.host_cc
))
119 config
.substitutions
.append(('%host_cxx', config
.host_cxx
))
122 # Plugins (loadable modules)
123 if config
.has_plugins
and config
.llvm_plugin_ext
:
124 config
.available_features
.add('plugins')
126 if config
.clang_default_pie_on_linux
:
127 config
.available_features
.add('default-pie-on-linux')
129 # Set available features we allow tests to conditionalize on.
131 if config
.clang_default_cxx_stdlib
!= '':
132 config
.available_features
.add('default-cxx-stdlib={}'.format(config
.clang_default_cxx_stdlib
))
134 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
135 if platform
.system() not in ['FreeBSD']:
136 config
.available_features
.add('crash-recovery')
138 # ANSI escape sequences in non-dumb terminal
139 if platform
.system() not in ['Windows']:
140 config
.available_features
.add('ansi-escape-sequences')
142 # Capability to print utf8 to the terminal.
143 # Windows expects codepage, unless Wide API.
144 if platform
.system() not in ['Windows']:
145 config
.available_features
.add('utf8-capable-terminal')
147 # Support for libgcc runtime. Used to rule out tests that require
148 # clang to run with -rtlib=libgcc.
149 if platform
.system() not in ['Darwin', 'Fuchsia']:
150 config
.available_features
.add('libgcc')
152 # Case-insensitive file system
155 def is_filesystem_case_insensitive():
156 handle
, path
= tempfile
.mkstemp(
157 prefix
='case-test', dir=config
.test_exec_root
)
158 isInsensitive
= os
.path
.exists(
160 os
.path
.dirname(path
),
161 os
.path
.basename(path
).upper()
168 if is_filesystem_case_insensitive():
169 config
.available_features
.add('case-insensitive-filesystem')
171 # Tests that require the /dev/fd filesystem.
172 if os
.path
.exists('/dev/fd/0') and sys
.platform
not in ['cygwin']:
173 config
.available_features
.add('dev-fd-fs')
175 # Set on native MS environment.
176 if re
.match(r
'.*-(windows-msvc)$', config
.target_triple
):
177 config
.available_features
.add('ms-sdk')
179 # [PR8833] LLP64-incompatible tests
180 if not re
.match(r
'^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$', config
.target_triple
):
181 config
.available_features
.add('LP64')
183 # Tests that are specific to the Apple Silicon macOS.
184 if re
.match(r
'^arm64(e)?-apple-(macos|darwin)', config
.target_triple
):
185 config
.available_features
.add('apple-silicon-mac')
187 # [PR18856] Depends to remove opened file. On win32, a file could be removed
188 # only if all handles were closed.
189 if platform
.system() not in ['Windows']:
190 config
.available_features
.add('can-remove-opened-file')
193 known_arches
= ["x86_64", "mips64", "ppc64", "aarch64"]
194 if (any(config
.target_triple
.startswith(x
) for x
in known_arches
)):
195 config
.available_features
.add("clang-target-64-bits")
199 def calculate_arch_features(arch_string
):
201 for arch
in arch_string
.split():
202 features
.append(arch
.lower() + '-registered-target')
206 llvm_config
.feature_config(
207 [('--assertion-mode', {'ON': 'asserts'}),
208 ('--cxxflags', {r
'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
209 ('--targets-built', calculate_arch_features
),
212 if lit
.util
.which('xmllint'):
213 config
.available_features
.add('xmllint')
215 if config
.enable_backtrace
:
216 config
.available_features
.add('backtrace')
218 if config
.enable_threads
:
219 config
.available_features
.add('thread_support')
221 # Check if we should allow outputs to console.
222 run_console_tests
= int(lit_config
.params
.get('enable_console', '0'))
223 if run_console_tests
!= 0:
224 config
.available_features
.add('console')
226 lit
.util
.usePlatformSdkOnDarwin(config
, lit_config
)
227 macOSSDKVersion
= lit
.util
.findPlatformSdkVersionOnMacOS(config
, lit_config
)
228 if macOSSDKVersion
is not None:
229 config
.available_features
.add('macos-sdk-' + str(macOSSDKVersion
))
231 if os
.path
.exists('/etc/gentoo-release'):
232 config
.available_features
.add('gentoo')
234 if config
.enable_shared
:
235 config
.available_features
.add("enable_shared")
237 # Add a vendor-specific feature.
238 if config
.clang_vendor_uti
:
239 config
.available_features
.add('clang-vendor=' + config
.clang_vendor_uti
)
241 if config
.have_llvm_driver
:
242 config
.available_features
.add('llvm-driver')
244 def exclude_unsupported_files_for_aix(dirname
):
245 for filename
in os
.listdir(dirname
):
246 source_path
= os
.path
.join( dirname
, filename
)
247 if os
.path
.isdir(source_path
):
249 f
= open(source_path
, 'r', encoding
='ISO-8859-1')
252 # 64-bit object files are not supported on AIX, so exclude the tests.
253 if (any(option
in data
for option
in ('-emit-obj', '-fmodule-format=obj', '-fintegrated-as')) and
254 '64' in config
.target_triple
):
255 config
.excludes
+= [ filename
]
259 if 'aix' in config
.target_triple
:
260 for directory
in ('/CodeGenCXX', '/Misc', '/Modules', '/PCH', '/Driver',
261 '/ASTMerge/anonymous-fields', '/ASTMerge/injected-class-name-decl'):
262 exclude_unsupported_files_for_aix(config
.test_source_root
+ directory
)
264 # Some tests perform deep recursion, which requires a larger pthread stack size
265 # than the relatively low default of 192 KiB for 64-bit processes on AIX. The
266 # `AIXTHREAD_STK` environment variable provides a non-intrusive way to request
267 # a larger pthread stack size for the tests. Various applications and runtime
268 # libraries on AIX use a default pthread stack size of 4 MiB, so we will use
269 # that as a default value here.
270 if 'AIXTHREAD_STK' in os
.environ
:
271 config
.environment
['AIXTHREAD_STK'] = os
.environ
['AIXTHREAD_STK']
272 elif platform
.system() == 'AIX':
273 config
.environment
['AIXTHREAD_STK'] = '4194304'
275 # The llvm-nm tool supports an environment variable "OBJECT_MODE" on AIX OS, which
276 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
277 # environment variable specified, the default behaviour is to support 32-bit
278 # objects only. In order to not affect most test cases, which expect to support
279 # 32-bit and 64-bit objects by default, set the environment variable
280 # "OBJECT_MODE" to 'any' for llvm-nm on AIX OS.
282 if 'system-aix' in config
.available_features
:
283 config
.substitutions
.append(('llvm-nm', 'env OBJECT_MODE=any llvm-nm'))
285 # It is not realistically possible to account for all options that could
286 # possibly be present in system and user configuration files, so disable
287 # default configs for the test runs.
288 config
.environment
["CLANG_NO_DEFAULT_CONFIG"] = "1"