[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / test / lit.cfg.py
blob75a38b4c5dad587047471a9756bab941f0c80344
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'])
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('%llvm', FindTool('llvm'), unresolved='ignore'),
143 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
144 ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args),
145 ToolSubst('%go', config.go_executable, unresolved='ignore'),
146 ToolSubst('%gold', config.gold_executable, unresolved='ignore'),
147 ToolSubst('%ld64', ld64_cmd, unresolved='ignore'),
148 ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
149 ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
150 ToolSubst('%opt-viewer', opt_viewer_cmd),
151 ToolSubst('%llvm-objcopy', FindTool('llvm-objcopy')),
152 ToolSubst('%llvm-strip', FindTool('llvm-strip')),
153 ToolSubst('%llvm-install-name-tool', FindTool('llvm-install-name-tool')),
154 ToolSubst('%llvm-bitcode-strip', FindTool('llvm-bitcode-strip')),
155 ToolSubst('%split-file', FindTool('split-file')),
158 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
159 tools.extend([
160 'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as',
161 'llvm-addr2line', 'llvm-bcanalyzer', 'llvm-bitcode-strip', 'llvm-config',
162 'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', 'llvm-debuginfod-find', 'llvm-debuginfod',
163 'llvm-diff', 'llvm-dis', 'llvm-dwarfdump', 'llvm-dwarfutil', 'llvm-dlltool',
164 'llvm-exegesis', 'llvm-extract', 'llvm-isel-fuzzer', 'llvm-ifs',
165 'llvm-install-name-tool', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
166 'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mca',
167 'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump', 'llvm-otool',
168 'llvm-pdbutil', 'llvm-profdata', 'llvm-profgen', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
169 'llvm-readobj', 'llvm-remark-size-diff', 'llvm-rtdyld', 'llvm-sim',
170 'llvm-size', 'llvm-split', 'llvm-stress', 'llvm-strings', 'llvm-strip',
171 'llvm-tblgen', 'llvm-tapi-diff', 'llvm-undname', 'llvm-windres',
172 'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml',
173 'yaml-bench', 'verify-uselistorder', 'bugpoint', 'llc', 'llvm-symbolizer',
174 'opt', 'sancov', 'sanstats'])
176 # The following tools are optional
177 tools.extend([
178 ToolSubst('llvm-go', unresolved='ignore'),
179 ToolSubst('llvm-mt', unresolved='ignore'),
180 ToolSubst('Kaleidoscope-Ch3', unresolved='ignore'),
181 ToolSubst('Kaleidoscope-Ch4', unresolved='ignore'),
182 ToolSubst('Kaleidoscope-Ch5', unresolved='ignore'),
183 ToolSubst('Kaleidoscope-Ch6', unresolved='ignore'),
184 ToolSubst('Kaleidoscope-Ch7', unresolved='ignore'),
185 ToolSubst('Kaleidoscope-Ch8', unresolved='ignore'),
186 ToolSubst('LLJITWithThinLTOSummaries', unresolved='ignore'),
187 ToolSubst('LLJITWithRemoteDebugging', unresolved='ignore'),
188 ToolSubst('OrcV2CBindingsBasicUsage', unresolved='ignore'),
189 ToolSubst('OrcV2CBindingsAddObjectFile', unresolved='ignore'),
190 ToolSubst('OrcV2CBindingsRemovableCode', unresolved='ignore'),
191 ToolSubst('OrcV2CBindingsReflectProcessSymbols', unresolved='ignore'),
192 ToolSubst('OrcV2CBindingsLazy', unresolved='ignore'),
193 ToolSubst('OrcV2CBindingsVeryLazy', unresolved='ignore'),
194 ToolSubst('dxil-dis', unresolved='ignore')])
196 # Find (major, minor) version of ptxas
197 def ptxas_version(ptxas):
198 ptxas_cmd = subprocess.Popen([ptxas, '--version'], stdout=subprocess.PIPE)
199 ptxas_out = ptxas_cmd.stdout.read().decode('ascii')
200 ptxas_cmd.wait()
201 match = re.search('release (\d+)\.(\d+)', ptxas_out)
202 if match:
203 return (int(match.group(1)), int(match.group(2)))
204 print('couldn\'t determine ptxas version')
205 return None
207 def enable_ptxas(ptxas_executable):
208 version = ptxas_version(ptxas_executable)
209 if version:
210 # ptxas is supposed to be backward compatible with previous
211 # versions, so add a feature for every known version prior to
212 # the current one.
213 ptxas_known_versions = [
214 (9, 0), (9, 1), (9, 2),
215 (10, 0), (10, 1), (10, 2),
216 (11, 0), (11, 1), (11, 2), (11, 3), (11, 4), (11, 5), (11, 6),
219 # ignore ptxas if its version is below the minimum supported
220 # version
221 min_version = ptxas_known_versions[0]
222 if version[0] < min_version[0] or version[1] < min_version[1]:
223 print(
224 'Warning: ptxas version {}.{} is not supported'.format(
225 version[0], version[1]))
226 return
228 for known_major, known_minor in ptxas_known_versions:
229 if known_major <= version[0] and known_minor <= version[1]:
230 config.available_features.add(
231 'ptxas-{}.{}'.format(known_major, known_minor))
233 config.available_features.add('ptxas')
234 tools.extend([ToolSubst('%ptxas', ptxas_executable),
235 ToolSubst('%ptxas-verify', '{} -c -o /dev/null -'.format(
236 ptxas_executable))])
238 ptxas_executable = \
239 os.environ.get('LLVM_PTXAS_EXECUTABLE', None) or config.ptxas_executable
240 if ptxas_executable:
241 enable_ptxas(ptxas_executable)
243 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
245 # Targets
247 config.targets = frozenset(config.targets_to_build.split())
249 for arch in config.targets_to_build.split():
250 config.available_features.add(arch.lower() + '-registered-target')
252 # Features
253 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
254 if (config.host_ldflags.find("-m32") < 0
255 and any(config.llvm_host_triple.startswith(x) for x in known_arches)):
256 config.available_features.add("llvm-64-bits")
258 config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
260 if sys.platform in ['win32']:
261 # ExecutionEngine, no weak symbols in COFF.
262 config.available_features.add('uses_COFF')
263 else:
264 # Others/can-execute.txt
265 config.available_features.add('can-execute')
267 # Loadable module
268 if config.has_plugins:
269 config.available_features.add('plugins')
271 if config.build_examples:
272 config.available_features.add('examples')
274 if config.linked_bye_extension:
275 config.substitutions.append(('%llvmcheckext', 'CHECK-EXT'))
276 config.substitutions.append(('%loadbye', ''))
277 config.substitutions.append(('%loadnewpmbye', ''))
278 else:
279 config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT'))
280 config.substitutions.append(('%loadbye',
281 '-load={}/Bye{}'.format(config.llvm_shlib_dir,
282 config.llvm_shlib_ext)))
283 config.substitutions.append(('%loadnewpmbye',
284 '-load-pass-plugin={}/Bye{}'
285 .format(config.llvm_shlib_dir,
286 config.llvm_shlib_ext)))
289 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
290 if not config.build_shared_libs and not config.link_llvm_dylib:
291 config.available_features.add('static-libs')
293 if config.link_llvm_dylib:
294 config.available_features.add('llvm-dylib')
295 config.substitutions.append(
296 ('%llvmdylib',
297 '{}/libLLVM-{}{}'.format(config.llvm_shlib_dir,
298 config.llvm_dylib_version,
299 config.llvm_shlib_ext)))
301 if config.have_tf_aot:
302 config.available_features.add("have_tf_aot")
304 if config.have_tf_api:
305 config.available_features.add("have_tf_api")
307 if config.llvm_inliner_model_autogenerated:
308 config.available_features.add("llvm_inliner_model_autogenerated")
310 if config.llvm_raevict_model_autogenerated:
311 config.available_features.add("llvm_raevict_model_autogenerated")
313 def have_cxx_shared_library():
314 readobj_exe = lit.util.which('llvm-readobj', config.llvm_tools_dir)
315 if not readobj_exe:
316 print('llvm-readobj not found')
317 return False
319 try:
320 readobj_cmd = subprocess.Popen(
321 [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE)
322 except OSError:
323 print('could not exec llvm-readobj')
324 return False
326 readobj_out = readobj_cmd.stdout.read().decode('ascii')
327 readobj_cmd.wait()
329 regex = re.compile(r'(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)')
330 needed_libs = False
331 for line in readobj_out.splitlines():
332 if 'NeededLibraries [' in line:
333 needed_libs = True
334 if ']' in line:
335 needed_libs = False
336 if needed_libs and regex.search(line.lower()):
337 return True
338 return False
340 if have_cxx_shared_library():
341 config.available_features.add('cxx-shared-library')
343 if config.libcxx_used:
344 config.available_features.add('libcxx-used')
346 # LLVM can be configured with an empty default triple
347 # Some tests are "generic" and require a valid default triple
348 if config.target_triple:
349 config.available_features.add('default_triple')
350 # Direct object generation
351 if not config.target_triple.startswith(("nvptx", "xcore")):
352 config.available_features.add('object-emission')
354 if config.have_llvm_driver:
355 config.available_features.add('llvm-driver')
357 import subprocess
360 def have_ld_plugin_support():
361 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold' + config.llvm_shlib_ext)):
362 return False
364 ld_cmd = subprocess.Popen(
365 [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
366 ld_out = ld_cmd.stdout.read().decode()
367 ld_cmd.wait()
369 if not '-plugin' in ld_out:
370 return False
372 # check that the used emulations are supported.
373 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
374 if len(emu_line) != 1:
375 return False
376 emu_line = emu_line[0]
377 fields = emu_line.split(':')
378 if len(fields) != 3:
379 return False
380 emulations = fields[2].split()
381 if 'elf_x86_64' not in emulations:
382 return False
383 if 'elf32ppc' in emulations:
384 config.available_features.add('ld_emu_elf32ppc')
386 ld_version = subprocess.Popen(
387 [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
388 if not 'GNU gold' in ld_version.stdout.read().decode():
389 return False
390 ld_version.wait()
392 return True
395 if have_ld_plugin_support():
396 config.available_features.add('ld_plugin')
399 def have_ld64_plugin_support():
400 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO' + config.llvm_shlib_ext)):
401 return False
403 if config.ld64_executable == '':
404 return False
406 ld_cmd = subprocess.Popen(
407 [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
408 ld_out = ld_cmd.stderr.read().decode()
409 ld_cmd.wait()
411 if 'ld64' not in ld_out or 'LTO' not in ld_out:
412 return False
414 return True
417 if have_ld64_plugin_support():
418 config.available_features.add('ld64_plugin')
420 # Ask llvm-config about asserts
421 llvm_config.feature_config(
422 [('--assertion-mode', {'ON': 'asserts'}),
423 ('--build-mode', {'[Dd][Ee][Bb][Uu][Gg]': 'debug'})])
425 if 'darwin' == sys.platform:
426 cmd = ['sysctl', 'hw.optional.fma']
427 sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
429 # Non zero return, probably a permission issue
430 if sysctl_cmd.wait():
431 print(
432 "Warning: sysctl exists but calling \"{}\" failed, defaulting to no fma3.".format(
433 " ".join(cmd)))
434 else:
435 result = sysctl_cmd.stdout.read().decode('ascii')
436 if 'hw.optional.fma: 1' in result:
437 config.available_features.add('fma3')
439 # .debug_frame is not emitted for targeting Windows x64, arm64, or AIX.
440 if not re.match(r'^(x86_64|arm64|powerpc|powerpc64).*-(windows-gnu|windows-msvc|aix)', config.target_triple):
441 config.available_features.add('debug_frame')
443 if config.have_libxar:
444 config.available_features.add('xar')
446 if config.enable_threads:
447 config.available_features.add('thread_support')
449 if config.have_libxml2:
450 config.available_features.add('libxml2')
452 if config.have_curl:
453 config.available_features.add('curl')
455 if config.have_opt_viewer_modules:
456 config.available_features.add('have_opt_viewer_modules')
458 if config.expensive_checks:
459 config.available_features.add('expensive_checks')
461 if "MemoryWithOrigins" in config.llvm_use_sanitizer:
462 config.available_features.add('use_msan_with_origins')
464 def exclude_unsupported_files_for_aix(dirname):
465 for filename in os.listdir(dirname):
466 source_path = os.path.join( dirname, filename)
467 if os.path.isdir(source_path):
468 continue
469 f = open(source_path, 'r')
470 try:
471 data = f.read()
472 # 64-bit object files are not supported on AIX, so exclude the tests.
473 if ('-emit-obj' in data or '-filetype=obj' in data) and '64' in config.target_triple:
474 config.excludes += [ filename ]
475 finally:
476 f.close()
478 if 'aix' in config.target_triple:
479 for directory in ('/CodeGen/X86', '/DebugInfo', '/DebugInfo/X86', '/DebugInfo/Generic', '/LTO/X86', '/Linker'):
480 exclude_unsupported_files_for_aix(config.test_source_root + directory)
482 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
483 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
484 # environment variable specified, the default behaviour is to support 32-bit
485 # objects only. In order to not affect most test cases, which expect to support
486 # 32-bit and 64-bit objects by default, set the environment variable
487 # "OBJECT_MODE" to 'any' by default on AIX OS.
488 if 'system-aix' in config.available_features:
489 config.environment['OBJECT_MODE'] = 'any'