3 # Configuration file for the 'lit' test runner.
13 # name: The name of this test suite.
16 # Tweak PATH for Win32 to decide to use bash.exe or not.
17 if sys.platform in ['win32']:
18 # Seek sane tools in directories and set to $PATH.
19 path = getattr(config, 'lit_tools_dir', None)
20 path = lit_config.getToolsPath(path,
21 config.environment['PATH'],
22 ['cmp.exe', 'grep.exe', 'sed.exe'])
24 path = os.path.pathsep.join((path,
25 config.environment['PATH']))
26 config.environment['PATH'] = path
28 # Choose between lit's internal shell pipeline runner and a real shell. If
29 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
30 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
32 # 0 is external, "" is default, and everything else is internal.
33 execute_external = (use_lit_shell == "0")
35 # Otherwise we default to internal on Windows and external elsewhere, as
36 # bash on Windows is usually very slow.
37 execute_external = (not sys.platform in ['win32'])
39 # testFormat: The test format to use to interpret tests.
40 config.test_format = lit.formats.ShTest(execute_external)
42 # suffixes: A list of file extensions to treat as test files. This is overriden
43 # by individual lit.local.cfg files in the test subdirectories.
44 config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s']
46 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
47 # subdirectories contain auxiliary inputs for various tests in their parent
49 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
51 # test_source_root: The root path where tests are located.
52 config.test_source_root = os.path.dirname(__file__)
54 # test_exec_root: The root path where tests should be run.
55 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
56 if llvm_obj_root is not None:
57 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
59 # Tweak the PATH to include the tools dir.
60 if llvm_obj_root is not None:
61 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
62 if not llvm_tools_dir:
63 lit_config.fatal('No LLVM tools dir set!')
64 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
65 config.environment['PATH'] = path
67 # Propagate 'HOME' through the environment.
68 if 'HOME' in os.environ:
69 config.environment['HOME'] = os.environ['HOME']
71 # Propagate 'INCLUDE' through the environment.
72 if 'INCLUDE' in os.environ:
73 config.environment['INCLUDE'] = os.environ['INCLUDE']
75 # Propagate 'LIB' through the environment.
76 if 'LIB' in os.environ:
77 config.environment['LIB'] = os.environ['LIB']
79 # Propagate the temp directory. Windows requires this because it uses \Windows\
80 # if none of these are present.
81 if 'TMP' in os.environ:
82 config.environment['TMP'] = os.environ['TMP']
83 if 'TEMP' in os.environ:
84 config.environment['TEMP'] = os.environ['TEMP']
86 # Propagate LLVM_SRC_ROOT into the environment.
87 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
89 # Propagate PYTHON_EXECUTABLE into the environment
90 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
93 # Propagate path to symbolizer for ASan/MSan.
94 for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
95 if symbolizer in os.environ:
96 config.environment[symbolizer] = os.environ[symbolizer]
98 # Set up OCAMLPATH to include newly built OCaml libraries.
99 llvm_lib_dir = getattr(config, 'llvm_lib_dir', None)
100 if llvm_lib_dir is None:
101 if llvm_obj_root is not None:
102 llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
104 if llvm_lib_dir is not None:
105 llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
106 if llvm_ocaml_lib is not None:
107 if 'OCAMLPATH' in os.environ:
108 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
109 config.environment['OCAMLPATH'] = ocamlpath
111 config.environment['OCAMLPATH'] = llvm_ocaml_lib
113 if 'CAML_LD_LIBRARY_PATH' in os.environ:
114 caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
115 os.environ['CAML_LD_LIBRARY_PATH']))
116 config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
118 config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
120 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
121 config.environment['OCAMLRUNPARAM'] = 'b'
127 # Check that the object root is known.
128 if config.test_exec_root is None:
129 # Otherwise, we haven't loaded the site specific configuration (the user is
130 # probably trying to run on a test file directly, and either the site
131 # configuration hasn't been created by the build system, or we are in an
132 # out-of-tree build situation).
134 # Check for 'llvm_site_config' user parameter, and use that if available.
135 site_cfg = lit_config.params.get('llvm_site_config', None)
136 if site_cfg and os.path.exists(site_cfg):
137 lit_config.load_config(config, site_cfg)
140 # Try to detect the situation where we are using an out-of-tree build by
141 # looking for 'llvm-config'.
143 # FIXME: I debated (i.e., wrote and threw away) adding logic to
144 # automagically generate the lit.site.cfg if we are in some kind of fresh
145 # build situation. This means knowing how to invoke the build system
146 # though, and I decided it was too much magic.
148 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
150 lit_config.fatal('No site specific configuration available!')
152 # Get the source and object roots.
153 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
154 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
156 # Validate that we got a tree which points to here.
157 this_src_root = os.path.dirname(config.test_source_root)
158 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
159 lit_config.fatal('No site specific configuration available!')
161 # Check that the site specific configuration exists.
162 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
163 if not os.path.exists(site_cfg):
164 lit_config.fatal('No site specific configuration available!')
166 # Okay, that worked. Notify the user of the automagic, and reconfigure.
167 lit_config.note('using out-of-tree build at %r' % llvm_obj_root)
168 lit_config.load_config(config, site_cfg)
174 # The target triple used by default by lli is the process target triple (some
175 # triple appropriate for generating code for the current process) but because
176 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
177 # Windows. FIXME: the process target triple should be used here, but this is
178 # difficult to obtain on Windows.
179 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
180 lli += ' -mtriple='+config.host_triple+'-elf'
181 config.substitutions.append( ('%lli', lli ) )
183 # Similarly, have a macro to use llc with DWARF even when the host is win32.
185 if re.search(r'win32', config.target_triple):
186 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
187 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
189 # Add site-specific substitutions.
190 config.substitutions.append( ('%gold', config.gold_executable) )
191 config.substitutions.append( ('%ld64', config.ld64_executable) )
192 config.substitutions.append( ('%go', config.go_executable) )
193 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
194 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
195 config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
196 config.substitutions.append( ('%python', config.python_executable) )
198 # OCaml substitutions.
199 # Support tests for both native and bytecode builds.
200 config.substitutions.append( ('%ocamlc',
201 "%s ocamlc -cclib -L%s %s" %
202 (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) )
203 if config.have_ocamlopt in ('1', 'TRUE'):
204 config.substitutions.append( ('%ocamlopt',
205 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
206 (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
208 config.substitutions.append( ('%ocamlopt', "true" ) )
210 # For each occurrence of an llvm tool name as its own word, replace it
211 # with the full path to the build directory holding that tool. This
212 # ensures that we are testing the tools just built and not some random
213 # tools that might happen to be in the user's PATH. Thus this list
214 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
215 # (llvm_tools_dir in lit parlance).
217 # Avoid matching RUN line fragments that are actually part of
218 # path names or options or whatever.
219 # The regex is a pre-assertion to avoid matching a preceding
220 # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
221 # also have a post-assertion to not match a trailing hyphen (foo-).
222 NOJUNK = r"(?<!\.|-|\^|/)"
225 def find_tool_substitution(pattern):
226 # Extract the tool name from the pattern. This relies on the tool
227 # name being surrounded by \b word match operators. If the
228 # pattern starts with "| ", include it in the string to be
230 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
232 tool_pipe = tool_match.group(2)
233 tool_name = tool_match.group(4)
234 # Did the user specify the tool path + arguments? This allows things like
235 # llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs"
236 tool_path = lit_config.params.get(tool_name)
237 if tool_path is None:
238 tool_path = lit.util.which(tool_name, llvm_tools_dir)
239 if (tool_name == "llc" and
240 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and
241 os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"):
242 tool_path += " -verify-machineinstrs"
243 return tool_name, tool_path, tool_pipe
246 for pattern in [r"\bbugpoint\b(?!-)",
251 r"\bllvm-bcanalyzer\b",
257 r"\bllvm-dsymutil\b",
258 r"\bllvm-dwarfdump\b",
264 r"\bllvm-mcmarkup\b",
267 r"\bllvm-profdata\b",
281 r"\bverify-uselistorder\b",
282 # Handle these specially as they are strings searched
283 # for during testing.
286 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
288 # Warn, but still provide a substitution.
289 lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
290 tool_path = llvm_tools_dir + '/' + tool_name
291 config.substitutions.append((pattern, tool_pipe + tool_path))
293 # For tools that are optional depending on the config, we won't warn
294 # if they're missing.
295 for pattern in [r"\bllvm-go\b",
296 r"\bKaleidoscope-Ch3\b",
297 r"\bKaleidoscope-Ch4\b",
298 r"\bKaleidoscope-Ch5\b",
299 r"\bKaleidoscope-Ch6\b",
300 r"\bKaleidoscope-Ch7\b",
301 r"\bKaleidoscope-Ch8\b"]:
302 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
304 # Provide a substitution anyway, for the sake of consistent errors.
305 tool_path = llvm_tools_dir + '/' + tool_name
306 config.substitutions.append((pattern, tool_pipe + tool_path))
311 config.targets = frozenset(config.targets_to_build.split())
317 config.available_features.add('shell')
319 # Others/can-execute.txt
320 if sys.platform not in ['win32']:
321 config.available_features.add('can-execute')
324 # FIXME: This should be supplied by Makefile or autoconf.
325 if sys.platform in ['win32', 'cygwin']:
326 loadable_module = (config.enable_shared == 1)
328 loadable_module = True
331 config.available_features.add('loadable_module')
334 if config.llvm_use_sanitizer == "Address":
335 config.available_features.add("asan")
336 if (config.llvm_use_sanitizer == "Memory" or
337 config.llvm_use_sanitizer == "MemoryWithOrigins"):
338 config.available_features.add("msan")
339 if config.llvm_use_sanitizer == "Undefined":
340 config.available_features.add("ubsan")
342 config.available_features.add("not_ubsan")
344 # Check if we should run long running tests.
345 if lit_config.params.get("run_long_tests", None) == "true":
346 config.available_features.add("long_tests")
348 # Direct object generation
349 # Suppress x86_64-mingw32 while investigating since r219108.
350 if not 'hexagon' in config.target_triple and not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
351 config.available_features.add("object-emission")
353 if config.have_zlib == "1":
354 config.available_features.add("zlib")
356 config.available_features.add("nozlib")
358 # Native compilation: host arch == target arch and native backend built-in
359 # FIXME: Consider cases that target can be executed
360 # even if host_triple were different from target_triple.
361 if (config.host_triple == config.target_triple and
362 config.native_target in config.targets_to_build):
363 config.available_features.add("native")
367 def have_ld_plugin_support():
368 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
371 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
372 ld_out = ld_cmd.stdout.read().decode()
375 if not '-plugin' in ld_out:
378 # check that the used emulations are supported.
379 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
380 if len(emu_line) != 1:
382 emu_line = emu_line[0]
383 fields = emu_line.split(':')
386 emulations = fields[2].split()
387 if 'elf_x86_64' not in emulations:
389 if 'elf32ppc' in emulations:
390 config.available_features.add('ld_emu_elf32ppc')
392 ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'})
393 if not 'GNU gold' in ld_version.stdout.read().decode():
399 if have_ld_plugin_support():
400 config.available_features.add('ld_plugin')
402 def have_ld64_plugin_support():
403 if config.ld64_executable == '':
406 ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
407 ld_out = ld_cmd.stderr.read().decode()
410 if 'ld64' not in ld_out or 'LTO' not in ld_out:
415 if have_ld64_plugin_support():
416 config.available_features.add('ld64_plugin')
418 # Ask llvm-config about assertion mode.
420 llvm_config_cmd = subprocess.Popen(
421 [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
422 stdout = subprocess.PIPE,
423 env=config.environment)
425 print("Could not find llvm-config in " + llvm_tools_dir)
428 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
429 config.available_features.add('asserts')
430 llvm_config_cmd.wait()
432 if 'darwin' == sys.platform:
434 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
435 stdout = subprocess.PIPE)
437 print("Could not exec sysctl")
438 result = sysctl_cmd.stdout.read().decode('ascii')
439 if -1 != result.find("hw.optional.fma: 1"):
440 config.available_features.add('fma3')
443 # .debug_frame is not emitted for targeting Windows x64.
444 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
445 config.available_features.add('debug_frame')
447 # Check if we should use gmalloc.
448 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
449 if use_gmalloc_str is not None:
450 if use_gmalloc_str.lower() in ('1', 'true'):
452 elif use_gmalloc_str.lower() in ('', '0', 'false'):
455 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
457 # Default to not using gmalloc
460 # Allow use of an explicit path for gmalloc library.
461 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
462 gmalloc_path_str = lit_config.params.get('gmalloc_path',
463 '/usr/lib/libgmalloc.dylib')
466 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})