3 # Configuration file for the 'lit' test runner.
14 # name: The name of this test suite.
17 # Tweak PATH for Win32 to decide to use bash.exe or not.
18 if sys.platform in ['win32']:
19 # Seek sane tools in directories and set to $PATH.
20 path = getattr(config, 'lit_tools_dir', None)
21 path = lit_config.getToolsPath(path,
22 config.environment['PATH'],
23 ['cmp.exe', 'grep.exe', 'sed.exe'])
25 path = os.path.pathsep.join((path,
26 config.environment['PATH']))
27 config.environment['PATH'] = path
29 # Choose between lit's internal shell pipeline runner and a real shell. If
30 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
31 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
33 # 0 is external, "" is default, and everything else is internal.
34 execute_external = (use_lit_shell == "0")
36 # Otherwise we default to internal on Windows and external elsewhere, as
37 # bash on Windows is usually very slow.
38 execute_external = (not sys.platform in ['win32'])
40 # testFormat: The test format to use to interpret tests.
41 config.test_format = lit.formats.ShTest(execute_external)
43 # suffixes: A list of file extensions to treat as test files. This is overriden
44 # by individual lit.local.cfg files in the test subdirectories.
45 config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s', '.mir']
47 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
48 # subdirectories contain auxiliary inputs for various tests in their parent
50 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
52 # test_source_root: The root path where tests are located.
53 config.test_source_root = os.path.dirname(__file__)
55 # test_exec_root: The root path where tests should be run.
56 config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
58 # Tweak the PATH to include the tools dir.
59 path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
60 config.environment['PATH'] = path
62 # Propagate 'HOME' through the environment.
63 if 'HOME' in os.environ:
64 config.environment['HOME'] = os.environ['HOME']
66 # Propagate 'INCLUDE' through the environment.
67 if 'INCLUDE' in os.environ:
68 config.environment['INCLUDE'] = os.environ['INCLUDE']
70 # Propagate 'LIB' through the environment.
71 if 'LIB' in os.environ:
72 config.environment['LIB'] = os.environ['LIB']
74 # Propagate the temp directory. Windows requires this because it uses \Windows\
75 # if none of these are present.
76 if 'TMP' in os.environ:
77 config.environment['TMP'] = os.environ['TMP']
78 if 'TEMP' in os.environ:
79 config.environment['TEMP'] = os.environ['TEMP']
81 # Propagate LLVM_SRC_ROOT into the environment.
82 config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
84 # Propagate PYTHON_EXECUTABLE into the environment
85 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
88 # Propagate path to symbolizer for ASan/MSan.
89 for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
90 if symbolizer in os.environ:
91 config.environment[symbolizer] = os.environ[symbolizer]
93 # Set up OCAMLPATH to include newly built OCaml libraries.
94 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
95 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
96 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
97 if 'OCAMLPATH' in os.environ:
98 ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
99 config.environment['OCAMLPATH'] = ocamlpath
101 if 'CAML_LD_LIBRARY_PATH' in os.environ:
102 caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
103 os.environ['CAML_LD_LIBRARY_PATH']))
104 config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
106 config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
108 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
109 config.environment['OCAMLRUNPARAM'] = 'b'
111 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
112 # available. This is darwin specific since it's currently only needed on darwin.
113 def get_asan_rtlib():
114 if not "Address" in config.llvm_use_sanitizer or \
115 not "Darwin" in config.host_os or \
116 not "x86" in config.host_triple:
121 print("glob module not found, skipping get_asan_rtlib() lookup")
123 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
124 # path from the host cc.
125 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
126 asan_dylib_dir_pattern = host_lib_dir + \
127 "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
128 found_dylibs = glob.glob(asan_dylib_dir_pattern)
129 if len(found_dylibs) != 1:
131 return found_dylibs[0]
134 # The target triple used by default by lli is the process target triple (some
135 # triple appropriate for generating code for the current process) but because
136 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
137 # Windows. FIXME: the process target triple should be used here, but this is
138 # difficult to obtain on Windows.
139 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
140 lli += ' -mtriple='+config.host_triple+'-elf'
141 config.substitutions.append( ('%lli', lli ) )
143 # Similarly, have a macro to use llc with DWARF even when the host is win32.
145 if re.search(r'win32', config.target_triple):
146 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
147 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
149 # Add site-specific substitutions.
150 config.substitutions.append( ('%gold', config.gold_executable) )
151 config.substitutions.append( ('%go', config.go_executable) )
152 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
153 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
154 config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
155 config.substitutions.append( ('%python', config.python_executable) )
156 config.substitutions.append( ('%host_cc', config.host_cc) )
158 # Provide the path to asan runtime lib if available. On darwin, this lib needs
159 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
160 # to be linked contain instrumented sanitizer code.
161 ld64_cmd = config.ld64_executable
162 asan_rtlib = get_asan_rtlib()
164 ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
165 config.substitutions.append( ('%ld64', ld64_cmd) )
167 # OCaml substitutions.
168 # Support tests for both native and bytecode builds.
169 config.substitutions.append( ('%ocamlc',
170 "%s ocamlc -cclib -L%s %s" %
171 (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)) )
172 if config.have_ocamlopt:
173 config.substitutions.append( ('%ocamlopt',
174 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
175 (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)) )
177 config.substitutions.append( ('%ocamlopt', "true" ) )
179 # For each occurrence of an llvm tool name as its own word, replace it
180 # with the full path to the build directory holding that tool. This
181 # ensures that we are testing the tools just built and not some random
182 # tools that might happen to be in the user's PATH. Thus this list
183 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
184 # (llvm_tools_dir in lit parlance).
186 # Avoid matching RUN line fragments that are actually part of
187 # path names or options or whatever.
188 # The regex is a pre-assertion to avoid matching a preceding
189 # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
190 # also have a post-assertion to not match a trailing hyphen (foo-).
191 NOJUNK = r"(?<!\.|-|\^|/|<)"
194 def find_tool_substitution(pattern):
195 # Extract the tool name from the pattern. This relies on the tool
196 # name being surrounded by \b word match operators. If the
197 # pattern starts with "| ", include it in the string to be
199 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
201 tool_pipe = tool_match.group(2)
202 tool_name = tool_match.group(4)
203 # Did the user specify the tool path + arguments? This allows things like
204 # llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs"
205 tool_path = lit_config.params.get(tool_name)
206 if tool_path is None:
207 tool_path = lit.util.which(tool_name, config.llvm_tools_dir)
208 if tool_path is None:
209 return tool_name, tool_path, tool_pipe
210 if (tool_name == "llc" and
211 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and
212 os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"):
213 tool_path += " -verify-machineinstrs"
214 if (tool_name == "llvm-go"):
215 tool_path += " go=" + config.go_executable
216 return tool_name, tool_path, tool_pipe
219 for pattern in [r"\bbugpoint\b(?!-)",
224 r"\bllvm-bcanalyzer\b",
231 r"\bllvm-dsymutil\b",
232 r"\bllvm-dwarfdump\b",
234 r"\bllvm-isel-fuzzer\b",
240 r"\bllvm-mcmarkup\b",
241 r"\bllvm-modextract\b",
246 r"\bllvm-profdata\b",
257 NOJUNK + r"\bllvm-symbolizer\b",
261 NOJUNK + r"\bsancov\b",
262 NOJUNK + r"\bsanstats\b",
265 r"\bverify-uselistorder\b",
266 # Handle these specially as they are strings searched
267 # for during testing.
270 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
272 # Warn, but still provide a substitution.
273 lit_config.note('Did not find ' + tool_name + ' in ' + config.llvm_tools_dir)
274 tool_path = config.llvm_tools_dir + '/' + tool_name
275 config.substitutions.append((pattern, tool_pipe + tool_path))
277 # For tools that are optional depending on the config, we won't warn
278 # if they're missing.
279 for pattern in [r"\bllvm-go\b",
281 r"\bKaleidoscope-Ch3\b",
282 r"\bKaleidoscope-Ch4\b",
283 r"\bKaleidoscope-Ch5\b",
284 r"\bKaleidoscope-Ch6\b",
285 r"\bKaleidoscope-Ch7\b",
286 r"\bKaleidoscope-Ch8\b"]:
287 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
289 # Provide a substitution anyway, for the sake of consistent errors.
290 tool_path = config.llvm_tools_dir + '/' + tool_name
291 config.substitutions.append((pattern, tool_pipe + tool_path))
296 config.targets = frozenset(config.targets_to_build.split())
298 for arch in config.targets_to_build.split():
299 config.available_features.add(arch.lower() + '-registered-target')
305 config.available_features.add('shell')
307 # Others/can-execute.txt
308 if sys.platform not in ['win32']:
309 config.available_features.add('can-execute')
310 config.available_features.add('not_COFF')
313 # FIXME: This should be supplied by Makefile or autoconf.
314 if sys.platform in ['win32', 'cygwin']:
315 loadable_module = (config.enable_shared == 1)
317 loadable_module = True
320 config.available_features.add('loadable_module')
322 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
323 if not config.build_shared_libs:
324 config.available_features.add("static-libs")
327 if 'Address' in config.llvm_use_sanitizer:
328 config.available_features.add("asan")
330 config.available_features.add("not_asan")
331 if 'Memory' in config.llvm_use_sanitizer:
332 config.available_features.add("msan")
334 config.available_features.add("not_msan")
335 if 'Undefined' in config.llvm_use_sanitizer:
336 config.available_features.add("ubsan")
338 config.available_features.add("not_ubsan")
340 # Check if we should run long running tests.
341 if lit_config.params.get("run_long_tests", None) == "true":
342 config.available_features.add("long_tests")
344 # Direct object generation
345 if not 'hexagon' in config.target_triple:
346 config.available_features.add("object-emission")
349 config.available_features.add("zlib")
351 config.available_features.add("nozlib")
353 # LLVM can be configured with an empty default triple
354 # Some tests are "generic" and require a valid default triple
355 if config.target_triple:
356 config.available_features.add("default_triple")
357 if re.match(r'^x86_64.*-linux', config.target_triple):
358 config.available_features.add("x86_64-linux")
360 # Native compilation: host arch == default triple arch
361 # FIXME: Consider cases that target can be executed
362 # even if host_triple were different from target_triple.
363 if config.host_triple == config.target_triple:
364 config.available_features.add("native")
368 def have_ld_plugin_support():
369 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
372 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
373 ld_out = ld_cmd.stdout.read().decode()
376 if not '-plugin' in ld_out:
379 # check that the used emulations are supported.
380 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
381 if len(emu_line) != 1:
383 emu_line = emu_line[0]
384 fields = emu_line.split(':')
387 emulations = fields[2].split()
388 if 'elf_x86_64' not in emulations:
390 if 'elf32ppc' in emulations:
391 config.available_features.add('ld_emu_elf32ppc')
393 ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'})
394 if not 'GNU gold' in ld_version.stdout.read().decode():
400 if have_ld_plugin_support():
401 config.available_features.add('ld_plugin')
403 def have_ld64_plugin_support():
404 if not config.llvm_tool_lto_build or config.ld64_executable == '':
407 ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
408 ld_out = ld_cmd.stderr.read().decode()
411 if 'ld64' not in ld_out or 'LTO' not in ld_out:
416 if have_ld64_plugin_support():
417 config.available_features.add('ld64_plugin')
419 # Ask llvm-config about assertion mode.
421 llvm_config_cmd = subprocess.Popen(
422 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
423 stdout = subprocess.PIPE,
424 env=config.environment)
426 print("Could not find llvm-config in " + config.llvm_tools_dir)
429 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
430 config.available_features.add('asserts')
431 llvm_config_cmd.wait()
433 if 'darwin' == sys.platform:
435 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
436 stdout = subprocess.PIPE)
438 print("Could not exec sysctl")
439 result = sysctl_cmd.stdout.read().decode('ascii')
440 if -1 != result.find("hw.optional.fma: 1"):
441 config.available_features.add('fma3')
444 if platform.system() in ['Windows']:
445 if re.match(r'.*-win32$', config.target_triple):
446 config.available_features.add('target-windows')
447 # For tests that require Windows to run.
448 config.available_features.add('system-windows')
450 # .debug_frame is not emitted for targeting Windows x64.
451 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
452 config.available_features.add('debug_frame')
454 # Check if we should use gmalloc.
455 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
456 if use_gmalloc_str is not None:
457 if use_gmalloc_str.lower() in ('1', 'true'):
459 elif use_gmalloc_str.lower() in ('', '0', 'false'):
462 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
464 # Default to not using gmalloc
467 # Allow use of an explicit path for gmalloc library.
468 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
469 gmalloc_path_str = lit_config.params.get('gmalloc_path',
470 '/usr/lib/libgmalloc.dylib')
473 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
475 # Ask llvm-config about global-isel.
477 llvm_config_cmd = subprocess.Popen(
478 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--has-global-isel'],
479 stdout = subprocess.PIPE,
480 env=config.environment)
482 print("Could not find llvm-config in " + config.llvm_tools_dir)
485 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
486 config.available_features.add('global-isel')
487 llvm_config_cmd.wait()
489 if config.have_libxar:
490 config.available_features.add('xar')
492 if config.enable_abi_breaking_checks == "1":
493 config.available_features.add('abi-breaking-checks')
495 if config.llvm_libxml2_enabled == "1":
496 config.available_features.add('libxml2')