[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / test / lit.cfg.py
blob6378cfcd3c18b03c4bf847926fcedfd0699ee84a
1 # -*- Python -*-
3 # Configuration file for the 'lit' test runner.
5 import os
6 import sys
7 import re
8 import platform
9 import subprocess
11 import lit.util
12 import lit.formats
13 from lit.llvm import llvm_config
14 from lit.llvm.subst import FindTool
15 from lit.llvm.subst import ToolSubst
17 # name: The name of this test suite.
18 config.name = 'LLVM'
20 # testFormat: The test format to use to interpret tests.
21 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
23 # suffixes: A list of file extensions to treat as test files. This is overriden
24 # by individual lit.local.cfg files in the test subdirectories.
25 config.suffixes = ['.ll', '.c', '.test', '.txt', '.s', '.mir', '.yaml']
27 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28 # subdirectories contain auxiliary inputs for various tests in their parent
29 # directories.
30 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
32 # test_source_root: The root path where tests are located.
33 config.test_source_root = os.path.dirname(__file__)
35 # test_exec_root: The root path where tests should be run.
36 config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
38 # Tweak the PATH to include the tools dir.
39 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
41 # Propagate some variables from the host environment.
42 llvm_config.with_system_environment(
43 ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
46 # Set up OCAMLPATH to include newly built OCaml libraries.
47 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
48 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
50 llvm_config.with_system_environment('OCAMLPATH')
51 llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
52 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
54 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
55 llvm_config.with_environment(
56 'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
58 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
59 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
61 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
62 # available. This is darwin specific since it's currently only needed on darwin.
65 def get_asan_rtlib():
66 if not 'Address' in config.llvm_use_sanitizer or \
67 not 'Darwin' in config.host_os or \
68 not 'x86' in config.host_triple:
69 return ''
70 try:
71 import glob
72 except:
73 print('glob module not found, skipping get_asan_rtlib() lookup')
74 return ''
75 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
76 # path from the host cc.
77 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib')
78 asan_dylib_dir_pattern = host_lib_dir + \
79 '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib'
80 found_dylibs = glob.glob(asan_dylib_dir_pattern)
81 if len(found_dylibs) != 1:
82 return ''
83 return found_dylibs[0]
86 llvm_config.use_default_substitutions()
88 # Add site-specific substitutions.
89 config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
90 config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
91 config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
92 config.substitutions.append(('%exeext', config.llvm_exe_ext))
95 lli_args = []
96 # The target triple used by default by lli is the process target triple (some
97 # triple appropriate for generating code for the current process) but because
98 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
99 # Windows. FIXME: the process target triple should be used here, but this is
100 # difficult to obtain on Windows.
101 if re.search(r'cygwin|windows-gnu|windows-msvc', config.host_triple):
102 lli_args = ['-mtriple=' + config.host_triple + '-elf']
104 llc_args = []
106 # Similarly, have a macro to use llc with DWARF even when the host is Windows
107 if re.search(r'windows-msvc', config.target_triple):
108 llc_args = [' -mtriple=' +
109 config.target_triple.replace('-msvc', '-gnu')]
111 # Provide the path to asan runtime lib if available. On darwin, this lib needs
112 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
113 # to be linked contain instrumented sanitizer code.
114 ld64_cmd = config.ld64_executable
115 asan_rtlib = get_asan_rtlib()
116 if asan_rtlib:
117 ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd)
118 if config.osx_sysroot:
119 ld64_cmd = '{} -syslibroot {}'.format(ld64_cmd, config.osx_sysroot)
121 ocamlc_command = '%s ocamlc -cclib -L%s %s' % (
122 config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)
123 ocamlopt_command = 'true'
124 if config.have_ocamlopt:
125 ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % (
126 config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)
128 opt_viewer_cmd = '%s %s/tools/opt-viewer/opt-viewer.py' % (sys.executable, config.llvm_src_root)
130 llvm_original_di_preservation_cmd = os.path.join(
131 config.llvm_src_root,'utils', 'llvm-original-di-preservation.py')
132 config.substitutions.append(
133 ('%llvm-original-di-preservation', "'%s' %s" % (
134 config.python_executable, llvm_original_di_preservation_cmd)))
136 llvm_locstats_tool = os.path.join(config.llvm_tools_dir, 'llvm-locstats')
137 config.substitutions.append(
138 ('%llvm-locstats', "'%s' %s" % (config.python_executable, llvm_locstats_tool)))
139 config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)
141 tools = [
142 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
143 ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args),
144 ToolSubst('%go', config.go_executable, unresolved='ignore'),
145 ToolSubst('%gold', config.gold_executable, unresolved='ignore'),
146 ToolSubst('%ld64', ld64_cmd, unresolved='ignore'),
147 ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
148 ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
149 ToolSubst('%opt-viewer', opt_viewer_cmd),
150 ToolSubst('%llvm-objcopy', FindTool('llvm-objcopy')),
151 ToolSubst('%llvm-strip', FindTool('llvm-strip')),
152 ToolSubst('%llvm-install-name-tool', FindTool('llvm-install-name-tool')),
153 ToolSubst('%llvm-bitcode-strip', FindTool('llvm-bitcode-strip')),
154 ToolSubst('%split-file', FindTool('split-file')),
157 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
158 tools.extend([
159 'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as',
160 'llvm-addr2line', 'llvm-bcanalyzer', 'llvm-bitcode-strip', 'llvm-config',
161 'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis',
162 'llvm-dwarfdump', 'llvm-dlltool', 'llvm-exegesis', 'llvm-extract',
163 'llvm-isel-fuzzer', 'llvm-ifs',
164 'llvm-install-name-tool', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
165 'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mca',
166 'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump', 'llvm-otool',
167 'llvm-pdbutil', 'llvm-profdata', 'llvm-profgen', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
168 'llvm-readobj', 'llvm-rtdyld', 'llvm-sim', 'llvm-size', 'llvm-split',
169 'llvm-stress', 'llvm-strings', 'llvm-strip', 'llvm-tblgen', 'llvm-tapi-diff',
170 'llvm-undname', 'llvm-windres', 'llvm-c-test', 'llvm-cxxfilt',
171 'llvm-xray', 'yaml2obj', 'obj2yaml', 'yaml-bench', 'verify-uselistorder',
172 'bugpoint', 'llc', 'llvm-symbolizer', 'opt', 'sancov', 'sanstats'])
174 # The following tools are optional
175 tools.extend([
176 ToolSubst('llvm-go', unresolved='ignore'),
177 ToolSubst('llvm-mt', unresolved='ignore'),
178 ToolSubst('Kaleidoscope-Ch3', unresolved='ignore'),
179 ToolSubst('Kaleidoscope-Ch4', unresolved='ignore'),
180 ToolSubst('Kaleidoscope-Ch5', unresolved='ignore'),
181 ToolSubst('Kaleidoscope-Ch6', unresolved='ignore'),
182 ToolSubst('Kaleidoscope-Ch7', unresolved='ignore'),
183 ToolSubst('Kaleidoscope-Ch8', unresolved='ignore'),
184 ToolSubst('LLJITWithThinLTOSummaries', unresolved='ignore'),
185 ToolSubst('LLJITWithRemoteDebugging', unresolved='ignore'),
186 ToolSubst('OrcV2CBindingsBasicUsage', unresolved='ignore'),
187 ToolSubst('OrcV2CBindingsAddObjectFile', unresolved='ignore'),
188 ToolSubst('OrcV2CBindingsRemovableCode', unresolved='ignore'),
189 ToolSubst('OrcV2CBindingsReflectProcessSymbols', unresolved='ignore'),
190 ToolSubst('OrcV2CBindingsLazy', unresolved='ignore'),
191 ToolSubst('OrcV2CBindingsVeryLazy', unresolved='ignore')])
193 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
195 # Targets
197 config.targets = frozenset(config.targets_to_build.split())
199 for arch in config.targets_to_build.split():
200 config.available_features.add(arch.lower() + '-registered-target')
202 # Features
203 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
204 if (config.host_ldflags.find("-m32") < 0
205 and any(config.llvm_host_triple.startswith(x) for x in known_arches)):
206 config.available_features.add("llvm-64-bits")
208 config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
210 if sys.platform in ['win32']:
211 # ExecutionEngine, no weak symbols in COFF.
212 config.available_features.add('uses_COFF')
213 else:
214 # Others/can-execute.txt
215 config.available_features.add('can-execute')
217 # Loadable module
218 if config.has_plugins:
219 config.available_features.add('plugins')
221 if config.build_examples:
222 config.available_features.add('examples')
224 if config.linked_bye_extension:
225 config.substitutions.append(('%llvmcheckext', 'CHECK-EXT'))
226 config.substitutions.append(('%loadbye', ''))
227 config.substitutions.append(('%loadnewpmbye', ''))
228 else:
229 config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT'))
230 config.substitutions.append(('%loadbye',
231 '-load={}/Bye{}'.format(config.llvm_shlib_dir,
232 config.llvm_shlib_ext)))
233 config.substitutions.append(('%loadnewpmbye',
234 '-load-pass-plugin={}/Bye{}'
235 .format(config.llvm_shlib_dir,
236 config.llvm_shlib_ext)))
239 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
240 if not config.build_shared_libs and not config.link_llvm_dylib:
241 config.available_features.add('static-libs')
243 if config.have_tf_aot:
244 config.available_features.add("have_tf_aot")
246 if config.have_tf_api:
247 config.available_features.add("have_tf_api")
249 def have_cxx_shared_library():
250 readobj_exe = lit.util.which('llvm-readobj', config.llvm_tools_dir)
251 if not readobj_exe:
252 print('llvm-readobj not found')
253 return False
255 try:
256 readobj_cmd = subprocess.Popen(
257 [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE)
258 except OSError:
259 print('could not exec llvm-readobj')
260 return False
262 readobj_out = readobj_cmd.stdout.read().decode('ascii')
263 readobj_cmd.wait()
265 regex = re.compile(r'(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)')
266 needed_libs = False
267 for line in readobj_out.splitlines():
268 if 'NeededLibraries [' in line:
269 needed_libs = True
270 if ']' in line:
271 needed_libs = False
272 if needed_libs and regex.search(line.lower()):
273 return True
274 return False
276 if have_cxx_shared_library():
277 config.available_features.add('cxx-shared-library')
279 if config.libcxx_used:
280 config.available_features.add('libcxx-used')
282 # Direct object generation
283 if not 'xcore' in config.target_triple:
284 config.available_features.add('object-emission')
286 # LLVM can be configured with an empty default triple
287 # Some tests are "generic" and require a valid default triple
288 if config.target_triple:
289 config.available_features.add('default_triple')
291 import subprocess
294 def have_ld_plugin_support():
295 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold' + config.llvm_shlib_ext)):
296 return False
298 ld_cmd = subprocess.Popen(
299 [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
300 ld_out = ld_cmd.stdout.read().decode()
301 ld_cmd.wait()
303 if not '-plugin' in ld_out:
304 return False
306 # check that the used emulations are supported.
307 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
308 if len(emu_line) != 1:
309 return False
310 emu_line = emu_line[0]
311 fields = emu_line.split(':')
312 if len(fields) != 3:
313 return False
314 emulations = fields[2].split()
315 if 'elf_x86_64' not in emulations:
316 return False
317 if 'elf32ppc' in emulations:
318 config.available_features.add('ld_emu_elf32ppc')
320 ld_version = subprocess.Popen(
321 [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
322 if not 'GNU gold' in ld_version.stdout.read().decode():
323 return False
324 ld_version.wait()
326 return True
329 if have_ld_plugin_support():
330 config.available_features.add('ld_plugin')
333 def have_ld64_plugin_support():
334 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO' + config.llvm_shlib_ext)):
335 return False
337 if config.ld64_executable == '':
338 return False
340 ld_cmd = subprocess.Popen(
341 [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
342 ld_out = ld_cmd.stderr.read().decode()
343 ld_cmd.wait()
345 if 'ld64' not in ld_out or 'LTO' not in ld_out:
346 return False
348 return True
351 if have_ld64_plugin_support():
352 config.available_features.add('ld64_plugin')
354 # Ask llvm-config about asserts
355 llvm_config.feature_config(
356 [('--assertion-mode', {'ON': 'asserts'}),
357 ('--build-mode', {'[Dd][Ee][Bb][Uu][Gg]': 'debug'})])
359 if 'darwin' == sys.platform:
360 cmd = ['sysctl', 'hw.optional.fma']
361 sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
363 # Non zero return, probably a permission issue
364 if sysctl_cmd.wait():
365 print(
366 "Warning: sysctl exists but calling \"{}\" failed, defaulting to no fma3.".format(
367 " ".join(cmd)))
368 else:
369 result = sysctl_cmd.stdout.read().decode('ascii')
370 if 'hw.optional.fma: 1' in result:
371 config.available_features.add('fma3')
373 # .debug_frame is not emitted for targeting Windows x64 or arm64.
374 if not re.match(r'^(x86_64|arm64).*-(windows-gnu|windows-msvc)', config.target_triple):
375 config.available_features.add('debug_frame')
377 if config.have_libxar:
378 config.available_features.add('xar')
380 if config.enable_threads:
381 config.available_features.add('thread_support')
383 if config.have_libxml2:
384 config.available_features.add('libxml2')
386 if config.have_opt_viewer_modules:
387 config.available_features.add('have_opt_viewer_modules')
389 if config.expensive_checks:
390 config.available_features.add('expensive_checks')