OSDN Git Service

Resubmit "[lit] Force site configs to run before source-tree configs"
[android-x86/external-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 import subprocess
10
11 import lit.util
12 import lit.formats
13
14 # name: The name of this test suite.
15 config.name = 'LLVM'
16
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'])
24     if path is not None:
25         path = os.path.pathsep.join((path,
26                                      config.environment['PATH']))
27         config.environment['PATH'] = path
28
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")
32 if use_lit_shell:
33     # 0 is external, "" is default, and everything else is internal.
34     execute_external = (use_lit_shell == "0")
35 else:
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'])
39
40 # testFormat: The test format to use to interpret tests.
41 config.test_format = lit.formats.ShTest(execute_external)
42
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']
46
47 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
48 # subdirectories contain auxiliary inputs for various tests in their parent
49 # directories.
50 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
51
52 # test_source_root: The root path where tests are located.
53 config.test_source_root = os.path.dirname(__file__)
54
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')
57
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
61
62 # Propagate 'HOME' through the environment.
63 if 'HOME' in os.environ:
64     config.environment['HOME'] = os.environ['HOME']
65
66 # Propagate 'INCLUDE' through the environment.
67 if 'INCLUDE' in os.environ:
68     config.environment['INCLUDE'] = os.environ['INCLUDE']
69
70 # Propagate 'LIB' through the environment.
71 if 'LIB' in os.environ:
72     config.environment['LIB'] = os.environ['LIB']
73
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']
80
81 # Propagate LLVM_SRC_ROOT into the environment.
82 config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
83
84 # Propagate PYTHON_EXECUTABLE into the environment
85 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
86                                                   '')
87
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]
92
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
100
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
105 else:
106     config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
107
108 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
109 config.environment['OCAMLRUNPARAM'] = 'b'
110
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:
117         return ""
118     try:
119         import glob
120     except:
121         print("glob module not found, skipping get_asan_rtlib() lookup")
122         return ""
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:
130         return ""
131     return found_dylibs[0]
132
133 lli = 'lli'
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 ) )
142
143 # Similarly, have a macro to use llc with DWARF even when the host is win32.
144 llc_dwarf = 'llc'
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) )
148
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) )
157
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()
163 if asan_rtlib:
164   ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
165 config.substitutions.append( ('%ld64', ld64_cmd) )
166
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)) )
176 else:
177     config.substitutions.append( ('%ocamlopt', "true" ) )
178
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).
185
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"(?<!\.|-|\^|/|<)"
192
193
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
198     # substituted.
199     tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
200                           pattern)
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
217
218
219 for pattern in [r"\bbugpoint\b(?!-)",
220                 NOJUNK + r"\bllc\b",
221                 r"\blli\b",
222                 r"\bllvm-ar\b",
223                 r"\bllvm-as\b",
224                 r"\bllvm-bcanalyzer\b",
225                 r"\bllvm-config\b",
226                 r"\bllvm-cov\b",
227                 r"\bllvm-cxxdump\b",
228                 r"\bllvm-cvtres\b",
229                 r"\bllvm-diff\b",
230                 r"\bllvm-dis\b",
231                 r"\bllvm-dsymutil\b",
232                 r"\bllvm-dwarfdump\b",
233                 r"\bllvm-extract\b",
234                 r"\bllvm-isel-fuzzer\b",
235                 r"\bllvm-lib\b",
236                 r"\bllvm-link\b",
237                 r"\bllvm-lto\b",
238                 r"\bllvm-lto2\b",
239                 r"\bllvm-mc\b",
240                 r"\bllvm-mcmarkup\b",
241                 r"\bllvm-modextract\b",
242                 r"\bllvm-nm\b",
243                 r"\bllvm-objcopy\b",
244                 r"\bllvm-objdump\b",
245                 r"\bllvm-pdbutil\b",
246                 r"\bllvm-profdata\b",
247                 r"\bllvm-ranlib\b",
248                 r"\bllvm-readobj\b",
249                 r"\bllvm-rtdyld\b",
250                 r"\bllvm-size\b",
251                 r"\bllvm-split\b",
252                 r"\bllvm-strings\b",
253                 r"\bllvm-tblgen\b",
254                 r"\bllvm-c-test\b",
255                 r"\bllvm-cxxfilt\b",
256                 r"\bllvm-xray\b",
257                 NOJUNK + r"\bllvm-symbolizer\b",
258                 NOJUNK + r"\bopt\b",
259                 r"\bFileCheck\b",
260                 r"\bobj2yaml\b",
261                 NOJUNK + r"\bsancov\b",
262                 NOJUNK + r"\bsanstats\b",
263                 r"\byaml2obj\b",
264                 r"\byaml-bench\b",
265                 r"\bverify-uselistorder\b",
266                 # Handle these specially as they are strings searched
267                 # for during testing.
268                 r"\| \bcount\b",
269                 r"\| \bnot\b"]:
270     tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
271     if not tool_path:
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))
276
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",
280                 r"\bllvm-mt\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)
288     if not tool_path:
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))
292
293
294 ### Targets
295
296 config.targets = frozenset(config.targets_to_build.split())
297
298 for arch in config.targets_to_build.split():
299     config.available_features.add(arch.lower() + '-registered-target')
300
301 ### Features
302
303 # Shell execution
304 if execute_external:
305     config.available_features.add('shell')
306
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')
311
312 # Loadable module
313 # FIXME: This should be supplied by Makefile or autoconf.
314 if sys.platform in ['win32', 'cygwin']:
315     loadable_module = (config.enable_shared == 1)
316 else:
317     loadable_module = True
318
319 if loadable_module:
320     config.available_features.add('loadable_module')
321
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")
325
326 # Sanitizers.
327 if 'Address' in config.llvm_use_sanitizer:
328     config.available_features.add("asan")
329 else:
330     config.available_features.add("not_asan")
331 if 'Memory' in config.llvm_use_sanitizer:
332     config.available_features.add("msan")
333 else:
334     config.available_features.add("not_msan")
335 if 'Undefined' in config.llvm_use_sanitizer:
336     config.available_features.add("ubsan")
337 else:
338     config.available_features.add("not_ubsan")
339
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")
343
344 # Direct object generation
345 if not 'hexagon' in config.target_triple:
346     config.available_features.add("object-emission")
347
348 if config.have_zlib:
349     config.available_features.add("zlib")
350 else:
351     config.available_features.add("nozlib")
352
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")
359
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")
365
366 import subprocess
367
368 def have_ld_plugin_support():
369     if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
370         return False
371
372     ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
373     ld_out = ld_cmd.stdout.read().decode()
374     ld_cmd.wait()
375
376     if not '-plugin' in ld_out:
377         return False
378
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:
382         return False
383     emu_line = emu_line[0]
384     fields = emu_line.split(':')
385     if len(fields) != 3:
386         return False
387     emulations = fields[2].split()
388     if 'elf_x86_64' not in emulations:
389         return False
390     if 'elf32ppc' in emulations:
391         config.available_features.add('ld_emu_elf32ppc')
392
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():
395         return False
396     ld_version.wait()
397
398     return True
399
400 if have_ld_plugin_support():
401     config.available_features.add('ld_plugin')
402
403 def have_ld64_plugin_support():
404     if not config.llvm_tool_lto_build or config.ld64_executable == '':
405         return False
406
407     ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
408     ld_out = ld_cmd.stderr.read().decode()
409     ld_cmd.wait()
410
411     if 'ld64' not in ld_out or 'LTO' not in ld_out:
412         return False
413
414     return True
415
416 if have_ld64_plugin_support():
417     config.available_features.add('ld64_plugin')
418
419 # Ask llvm-config about assertion mode.
420 try:
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)
425 except OSError:
426     print("Could not find llvm-config in " + config.llvm_tools_dir)
427     exit(42)
428
429 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
430     config.available_features.add('asserts')
431 llvm_config_cmd.wait()
432
433 if 'darwin' == sys.platform:
434     try:
435         sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
436                                     stdout = subprocess.PIPE)
437     except OSError:
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')
442     sysctl_cmd.wait()
443
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')
449
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')
453
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'):
458         use_gmalloc = True
459     elif use_gmalloc_str.lower() in ('', '0', 'false'):
460         use_gmalloc = False
461     else:
462         lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
463 else:
464     # Default to not using gmalloc
465     use_gmalloc = False
466
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')
471
472 if use_gmalloc:
473      config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
474
475 # Ask llvm-config about global-isel.
476 try:
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)
481 except OSError:
482     print("Could not find llvm-config in " + config.llvm_tools_dir)
483     exit(42)
484
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()
488
489 if config.have_libxar:
490     config.available_features.add('xar')
491
492 if config.enable_abi_breaking_checks == "1":
493     config.available_features.add('abi-breaking-checks')
494
495 if config.llvm_libxml2_enabled == "1":
496     config.available_features.add('libxml2')