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', '.cpp', '.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)
101 llvm_lib_dir = os.path.join(getattr(config, 'llvm_obj_root', None), 'lib')
103 llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
104 if 'OCAMLPATH' in os.environ:
105 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
106 config.environment['OCAMLPATH'] = ocamlpath
108 config.environment['OCAMLPATH'] = llvm_ocaml_lib
110 if 'CAML_LD_LIBRARY_PATH' in os.environ:
111 caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
112 os.environ['CAML_LD_LIBRARY_PATH']))
113 config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
115 config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
117 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
118 config.environment['OCAMLRUNPARAM'] = 'b'
124 # Check that the object root is known.
125 if config.test_exec_root is None:
126 # Otherwise, we haven't loaded the site specific configuration (the user is
127 # probably trying to run on a test file directly, and either the site
128 # configuration hasn't been created by the build system, or we are in an
129 # out-of-tree build situation).
131 # Check for 'llvm_site_config' user parameter, and use that if available.
132 site_cfg = lit_config.params.get('llvm_site_config', None)
133 if site_cfg and os.path.exists(site_cfg):
134 lit_config.load_config(config, site_cfg)
137 # Try to detect the situation where we are using an out-of-tree build by
138 # looking for 'llvm-config'.
140 # FIXME: I debated (i.e., wrote and threw away) adding logic to
141 # automagically generate the lit.site.cfg if we are in some kind of fresh
142 # build situation. This means knowing how to invoke the build system
143 # though, and I decided it was too much magic.
145 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
147 lit_config.fatal('No site specific configuration available!')
149 # Get the source and object roots.
150 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
151 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
153 # Validate that we got a tree which points to here.
154 this_src_root = os.path.dirname(config.test_source_root)
155 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
156 lit_config.fatal('No site specific configuration available!')
158 # Check that the site specific configuration exists.
159 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
160 if not os.path.exists(site_cfg):
161 lit_config.fatal('No site specific configuration available!')
163 # Okay, that worked. Notify the user of the automagic, and reconfigure.
164 lit_config.note('using out-of-tree build at %r' % llvm_obj_root)
165 lit_config.load_config(config, site_cfg)
171 # The target triple used by default by lli is the process target triple (some
172 # triple appropriate for generating code for the current process) but because
173 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
174 # Windows. FIXME: the process target triple should be used here, but this is
175 # difficult to obtain on Windows.
176 if re.search(r'cygwin|mingw32|win32', config.host_triple):
177 lli += ' -mtriple='+config.host_triple+'-elf'
178 config.substitutions.append( ('%lli', lli ) )
180 # Similarly, have a macro to use llc with DWARF even when the host is win32.
182 if re.search(r'win32', config.target_triple):
183 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
184 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
186 # Add site-specific substitutions.
187 config.substitutions.append( ('%go', config.go_executable) )
188 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
189 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
190 config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
191 config.substitutions.append( ('%python', config.python_executable) )
193 # OCaml substitutions.
194 # Support tests for both native and bytecode builds.
195 config.substitutions.append( ('%ocamlc',
196 "%s ocamlc %s" % (config.ocamlfind_executable, config.ocaml_flags)) )
197 if config.have_ocamlopt in ('1', 'TRUE'):
198 config.substitutions.append( ('%ocamlopt',
199 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
200 (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
202 config.substitutions.append( ('%ocamlopt', "true" ) )
204 # For each occurrence of an llvm tool name as its own word, replace it
205 # with the full path to the build directory holding that tool. This
206 # ensures that we are testing the tools just built and not some random
207 # tools that might happen to be in the user's PATH. Thus this list
208 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
209 # (llvm_tools_dir in lit parlance).
211 # Avoid matching RUN line fragments that are actually part of
212 # path names or options or whatever.
213 # The regex is a pre-assertion to avoid matching a preceding
214 # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
215 # also have a post-assertion to not match a trailing hyphen (foo-).
216 NOJUNK = r"(?<!\.|-|\^|/)"
218 for pattern in [r"\bbugpoint\b(?!-)",
223 r"\bllvm-bcanalyzer\b",
228 r"\bllvm-dwarfdump\b",
234 r"\bllvm-mcmarkup\b",
237 r"\bllvm-profdata\b",
243 r"\bllvm-vtabledump\b",
250 r"\bverify-uselistorder\b",
251 # Handle these specially as they are strings searched
252 # for during testing.
255 # Extract the tool name from the pattern. This relies on the tool
256 # name being surrounded by \b word match operators. If the
257 # pattern starts with "| ", include it in the string to be
259 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
261 tool_pipe = tool_match.group(2)
262 tool_name = tool_match.group(4)
263 tool_path = lit.util.which(tool_name, llvm_tools_dir)
265 # Warn, but still provide a substitution.
266 lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
267 tool_path = llvm_tools_dir + '/' + tool_name
268 config.substitutions.append((pattern, tool_pipe + tool_path))
272 config.targets = frozenset(config.targets_to_build.split())
278 config.available_features.add('shell')
280 # Others/can-execute.txt
281 if sys.platform not in ['win32']:
282 config.available_features.add('can-execute')
285 # FIXME: This should be supplied by Makefile or autoconf.
286 if sys.platform in ['win32', 'cygwin']:
287 loadable_module = (config.enable_shared == 1)
289 loadable_module = True
292 config.available_features.add('loadable_module')
295 if config.llvm_use_sanitizer == "Address":
296 config.available_features.add("asan")
297 if (config.llvm_use_sanitizer == "Memory" or
298 config.llvm_use_sanitizer == "MemoryWithOrigins"):
299 config.available_features.add("msan")
300 if config.llvm_use_sanitizer == "Undefined":
301 config.available_features.add("ubsan")
303 config.available_features.add("not_ubsan")
305 # Direct object generation
306 # Suppress x86_64-mingw32 while investigating since r219108.
307 if not 'hexagon' in config.target_triple and not re.match(r'^x86_64.*-(mingw32|win32)', config.target_triple):
308 config.available_features.add("object-emission")
310 if config.have_zlib == "1":
311 config.available_features.add("zlib")
313 config.available_features.add("nozlib")
315 # Native compilation: host arch == target arch
316 # FIXME: Consider cases that target can be executed
317 # even if host_triple were different from target_triple.
318 if config.host_triple == config.target_triple:
319 config.available_features.add("native")
323 def have_ld_plugin_support():
324 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
327 ld_cmd = subprocess.Popen(['ld', '--help'], stdout = subprocess.PIPE)
328 if not '-plugin' in ld_cmd.stdout.read():
332 ld_version = subprocess.Popen(['ld', '--version'], stdout = subprocess.PIPE)
333 if not 'GNU gold' in ld_version.stdout.read():
339 if have_ld_plugin_support():
340 config.available_features.add('ld_plugin')
342 # Ask llvm-config about assertion mode.
344 llvm_config_cmd = subprocess.Popen(
345 [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
346 stdout = subprocess.PIPE,
347 env=config.environment)
349 print("Could not find llvm-config in " + llvm_tools_dir)
352 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
353 config.available_features.add('asserts')
354 llvm_config_cmd.wait()
356 if 'darwin' == sys.platform:
358 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
359 stdout = subprocess.PIPE)
361 print("Could not exec sysctl")
362 result = sysctl_cmd.stdout.read().decode('ascii')
363 if -1 != result.find("hw.optional.fma: 1"):
364 config.available_features.add('fma3')
367 # .debug_frame is not emitted for targeting Windows x64.
368 if not re.match(r'^x86_64.*-(mingw32|win32)', config.target_triple):
369 config.available_features.add('debug_frame')
371 # Check if we should use gmalloc.
372 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
373 if use_gmalloc_str is not None:
374 if use_gmalloc_str.lower() in ('1', 'true'):
376 elif use_gmalloc_str.lower() in ('', '0', 'false'):
379 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
381 # Default to not using gmalloc
384 # Allow use of an explicit path for gmalloc library.
385 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
386 gmalloc_path_str = lit_config.params.get('gmalloc_path',
387 '/usr/lib/libgmalloc.dylib')
390 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})