67c9bbae744e59a69d1c699d3932c07234f86dde
[oota-llvm.git] / test / lit.cfg
1 # -*- Python -*-
2
3 # Configuration file for the 'lit' test runner.
4
5 import os
6 import sys
7 import re
8 import platform
9
10 import lit.util
11 import lit.formats
12
13 # name: The name of this test suite.
14 config.name = 'LLVM'
15
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'])
23     if path is not None:
24         path = os.path.pathsep.join((path,
25                                      config.environment['PATH']))
26         config.environment['PATH'] = path
27
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")
31 if use_lit_shell:
32     # 0 is external, "" is default, and everything else is internal.
33     execute_external = (use_lit_shell == "0")
34 else:
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'])
38
39 # testFormat: The test format to use to interpret tests.
40 config.test_format = lit.formats.ShTest(execute_external)
41
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']
45
46 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
47 # subdirectories contain auxiliary inputs for various tests in their parent
48 # directories.
49 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
50
51 # test_source_root: The root path where tests are located.
52 config.test_source_root = os.path.dirname(__file__)
53
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')
58
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
66
67 # Propagate 'HOME' through the environment.
68 if 'HOME' in os.environ:
69     config.environment['HOME'] = os.environ['HOME']
70
71 # Propagate 'INCLUDE' through the environment.
72 if 'INCLUDE' in os.environ:
73     config.environment['INCLUDE'] = os.environ['INCLUDE']
74
75 # Propagate 'LIB' through the environment.
76 if 'LIB' in os.environ:
77     config.environment['LIB'] = os.environ['LIB']
78
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']
85
86 # Propagate LLVM_SRC_ROOT into the environment.
87 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
88
89 # Propagate PYTHON_EXECUTABLE into the environment
90 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
91                                                   '')
92
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]
97
98 # Propagate options for sanitizers.
99 for options in ['ASAN_OPTIONS', 'UBSAN_OPTIONS']:
100     if options in os.environ:
101         config.environment[options] = os.environ[options]
102
103 # Set up OCAMLPATH to include newly built OCaml libraries.
104 llvm_lib_dir = getattr(config, 'llvm_lib_dir', None)
105 if not llvm_lib_dir:
106     llvm_lib_dir = os.path.join(getattr(config, 'llvm_obj_root', None), 'lib')
107
108 llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
109 if 'OCAMLPATH' in os.environ:
110     ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
111     config.environment['OCAMLPATH'] = ocamlpath
112 else:
113     config.environment['OCAMLPATH'] = llvm_ocaml_lib
114
115 if 'CAML_LD_LIBRARY_PATH' in os.environ:
116     caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
117                                 os.environ['CAML_LD_LIBRARY_PATH']))
118     config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
119 else:
120     config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
121
122 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
123 config.environment['OCAMLRUNPARAM'] = 'b'
124
125 ###
126
127 import os
128
129 # Check that the object root is known.
130 if config.test_exec_root is None:
131     # Otherwise, we haven't loaded the site specific configuration (the user is
132     # probably trying to run on a test file directly, and either the site
133     # configuration hasn't been created by the build system, or we are in an
134     # out-of-tree build situation).
135
136     # Check for 'llvm_site_config' user parameter, and use that if available.
137     site_cfg = lit_config.params.get('llvm_site_config', None)
138     if site_cfg and os.path.exists(site_cfg):
139         lit_config.load_config(config, site_cfg)
140         raise SystemExit
141
142     # Try to detect the situation where we are using an out-of-tree build by
143     # looking for 'llvm-config'.
144     #
145     # FIXME: I debated (i.e., wrote and threw away) adding logic to
146     # automagically generate the lit.site.cfg if we are in some kind of fresh
147     # build situation. This means knowing how to invoke the build system
148     # though, and I decided it was too much magic.
149
150     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
151     if not llvm_config:
152         lit_config.fatal('No site specific configuration available!')
153
154     # Get the source and object roots.
155     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
156     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
157
158     # Validate that we got a tree which points to here.
159     this_src_root = os.path.dirname(config.test_source_root)
160     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
161         lit_config.fatal('No site specific configuration available!')
162
163     # Check that the site specific configuration exists.
164     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
165     if not os.path.exists(site_cfg):
166         lit_config.fatal('No site specific configuration available!')
167
168     # Okay, that worked. Notify the user of the automagic, and reconfigure.
169     lit_config.note('using out-of-tree build at %r' % llvm_obj_root)
170     lit_config.load_config(config, site_cfg)
171     raise SystemExit
172
173 ###
174
175 lli = 'lli'
176 # The target triple used by default by lli is the process target triple (some
177 # triple appropriate for generating code for the current process) but because
178 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
179 # Windows.  FIXME: the process target triple should be used here, but this is
180 # difficult to obtain on Windows.
181 if re.search(r'cygwin|mingw32|win32', config.host_triple):
182   lli += ' -mtriple='+config.host_triple+'-elf'
183 config.substitutions.append( ('%lli', lli ) )
184
185 # Similarly, have a macro to use llc with DWARF even when the host is win32.
186 llc_dwarf = 'llc'
187 if re.search(r'win32', config.target_triple):
188   llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
189 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
190
191 # Add site-specific substitutions.
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) )
197
198 # OCaml substitutions.
199 # Support tests for both native and bytecode builds.
200 config.substitutions.append( ('%ocamlc',
201     "%s ocamlc %s" % (config.ocamlfind_executable, config.ocaml_flags)) )
202 if config.have_ocamlopt in ('1', 'TRUE'):
203     config.substitutions.append( ('%ocamlopt',
204         "%s ocamlopt %s" % (config.ocamlfind_executable, config.ocaml_flags)) )
205 else:
206     config.substitutions.append( ('%ocamlopt', "true" ) )
207
208 # For each occurrence of an llvm tool name as its own word, replace it
209 # with the full path to the build directory holding that tool.  This
210 # ensures that we are testing the tools just built and not some random
211 # tools that might happen to be in the user's PATH.  Thus this list
212 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
213 # (llvm_tools_dir in lit parlance).
214
215 # Avoid matching RUN line fragments that are actually part of
216 # path names or options or whatever.
217 # The regex is a pre-assertion to avoid matching a preceding
218 # dot, hyphen, carat, or slash (.foo, -foo, etc.).  Some patterns
219 # also have a post-assertion to not match a trailing hyphen (foo-).
220 NOJUNK = r"(?<!\.|-|\^|/)"
221
222 for pattern in [r"\bbugpoint\b(?!-)",
223                 NOJUNK + r"\bllc\b",
224                 r"\blli\b",
225                 r"\bllvm-ar\b",
226                 r"\bllvm-as\b",
227                 r"\bllvm-bcanalyzer\b",
228                 r"\bllvm-config\b",
229                 r"\bllvm-cov\b",
230                 r"\bllvm-diff\b",
231                 r"\bllvm-dis\b",
232                 r"\bllvm-dwarfdump\b",
233                 r"\bllvm-extract\b",
234                 r"\bllvm-go\b",
235                 r"\bllvm-link\b",
236                 r"\bllvm-lto\b",
237                 r"\bllvm-mc\b",
238                 r"\bllvm-mcmarkup\b",
239                 r"\bllvm-nm\b",
240                 r"\bllvm-objdump\b",
241                 r"\bllvm-profdata\b",
242                 r"\bllvm-ranlib\b",
243                 r"\bllvm-readobj\b",
244                 r"\bllvm-rtdyld\b",
245                 r"\bllvm-size\b",
246                 r"\bllvm-tblgen\b",
247                 r"\bllvm-vtabledump\b",
248                 r"\bllvm-c-test\b",
249                 r"\bmacho-dump\b",
250                 NOJUNK + r"\bopt\b",
251                 r"\bFileCheck\b",
252                 r"\bobj2yaml\b",
253                 r"\byaml2obj\b",
254                 r"\bverify-uselistorder\b",
255                 # Handle these specially as they are strings searched
256                 # for during testing.
257                 r"\| \bcount\b",
258                 r"\| \bnot\b"]:
259     # Extract the tool name from the pattern.  This relies on the tool
260     # name being surrounded by \b word match operators.  If the
261     # pattern starts with "| ", include it in the string to be
262     # substituted.
263     tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
264                           pattern)
265     tool_pipe = tool_match.group(2)
266     tool_name = tool_match.group(4)
267     tool_path = lit.util.which(tool_name, llvm_tools_dir)
268     if not tool_path:
269         # Warn, but still provide a substitution.
270         lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
271         tool_path = llvm_tools_dir + '/' + tool_name
272     config.substitutions.append((pattern, tool_pipe + tool_path))
273
274 ### Targets
275
276 config.targets = frozenset(config.targets_to_build.split())
277
278 ### Features
279
280 # Shell execution
281 if execute_external:
282     config.available_features.add('shell')
283
284 # Others/can-execute.txt
285 if sys.platform not in ['win32']:
286     config.available_features.add('can-execute')
287
288 # Loadable module
289 # FIXME: This should be supplied by Makefile or autoconf.
290 if sys.platform in ['win32', 'cygwin']:
291     loadable_module = (config.enable_shared == 1)
292 else:
293     loadable_module = True
294
295 if loadable_module:
296     config.available_features.add('loadable_module')
297
298 # Sanitizers.
299 if config.llvm_use_sanitizer == "Address":
300     config.available_features.add("asan")
301 if (config.llvm_use_sanitizer == "Memory" or
302         config.llvm_use_sanitizer == "MemoryWithOrigins"):
303     config.available_features.add("msan")
304 if config.llvm_use_sanitizer == "Undefined":
305     config.available_features.add("ubsan")
306 else:
307     config.available_features.add("not_ubsan")
308
309 # Direct object generation
310 # Suppress x86_64-mingw32 while investigating since r219108.
311 if not 'hexagon' in config.target_triple and not re.match(r'^x86_64.*-(mingw32|win32)', config.target_triple):
312     config.available_features.add("object-emission")
313
314 if config.have_zlib == "1":
315     config.available_features.add("zlib")
316 else:
317     config.available_features.add("nozlib")
318
319 # Native compilation: host arch == target arch
320 # FIXME: Consider cases that target can be executed
321 # even if host_triple were different from target_triple.
322 if config.host_triple == config.target_triple:
323     config.available_features.add("native")
324
325 import subprocess
326
327 def have_ld_plugin_support():
328     if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
329         return False
330
331     ld_cmd = subprocess.Popen(['ld', '--help'], stdout = subprocess.PIPE)
332     if not '-plugin' in ld_cmd.stdout.read():
333         return False
334     ld_cmd.wait()
335
336     ld_version = subprocess.Popen(['ld', '--version'], stdout = subprocess.PIPE)
337     if not 'GNU gold' in ld_version.stdout.read():
338         return False
339     ld_version.wait()
340
341     return True
342
343 if have_ld_plugin_support():
344     config.available_features.add('ld_plugin')
345
346 # Ask llvm-config about assertion mode.
347 try:
348     llvm_config_cmd = subprocess.Popen(
349         [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
350         stdout = subprocess.PIPE,
351         env=config.environment)
352 except OSError:
353     print("Could not find llvm-config in " + llvm_tools_dir)
354     exit(42)
355
356 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
357     config.available_features.add('asserts')
358 llvm_config_cmd.wait()
359
360 if 'darwin' == sys.platform:
361     try:
362         sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
363                                     stdout = subprocess.PIPE)
364     except OSError:
365         print("Could not exec sysctl")
366     result = sysctl_cmd.stdout.read().decode('ascii')
367     if -1 != result.find("hw.optional.fma: 1"):
368         config.available_features.add('fma3')
369     sysctl_cmd.wait()
370
371 # .debug_frame is not emitted for targeting Windows x64.
372 if not re.match(r'^x86_64.*-(mingw32|win32)', config.target_triple):
373     config.available_features.add('debug_frame')
374
375 # Check if we should use gmalloc.
376 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
377 if use_gmalloc_str is not None:
378     if use_gmalloc_str.lower() in ('1', 'true'):
379         use_gmalloc = True
380     elif use_gmalloc_str.lower() in ('', '0', 'false'):
381         use_gmalloc = False
382     else:
383         lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
384 else:
385     # Default to not using gmalloc
386     use_gmalloc = False
387
388 # Allow use of an explicit path for gmalloc library.
389 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
390 gmalloc_path_str = lit_config.params.get('gmalloc_path',
391                                          '/usr/lib/libgmalloc.dylib')
392
393 if use_gmalloc:
394      config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})