]> git.proxmox.com Git - rustc.git/blame - src/llvm/test/lit.cfg
Imported Upstream version 1.0.0-alpha.2
[rustc.git] / src / llvm / test / lit.cfg
CommitLineData
223e47cc
LB
1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6import sys
7import re
970d7e83 8import platform
223e47cc 9
1a4d82fc
JJ
10import lit.util
11import lit.formats
12
223e47cc
LB
13# name: The name of this test suite.
14config.name = 'LLVM'
15
16# Tweak PATH for Win32 to decide to use bash.exe or not.
17if sys.platform in ['win32']:
18 # Seek sane tools in directories and set to $PATH.
19 path = getattr(config, 'lit_tools_dir', None)
1a4d82fc
JJ
20 path = lit_config.getToolsPath(path,
21 config.environment['PATH'],
22 ['cmp.exe', 'grep.exe', 'sed.exe'])
223e47cc
LB
23 if path is not None:
24 path = os.path.pathsep.join((path,
25 config.environment['PATH']))
26 config.environment['PATH'] = path
27
1a4d82fc
JJ
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.
30use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
31if use_lit_shell:
32 # 0 is external, "" is default, and everything else is internal.
33 execute_external = (use_lit_shell == "0")
34else:
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
223e47cc 39# testFormat: The test format to use to interpret tests.
223e47cc
LB
40config.test_format = lit.formats.ShTest(execute_external)
41
1a4d82fc
JJ
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.
44config.suffixes = ['.ll', '.c', '.cpp', '.test', '.txt', '.s']
223e47cc
LB
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.
1a4d82fc 49config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
223e47cc
LB
50
51# test_source_root: The root path where tests are located.
52config.test_source_root = os.path.dirname(__file__)
53
54# test_exec_root: The root path where tests should be run.
55llvm_obj_root = getattr(config, 'llvm_obj_root', None)
56if llvm_obj_root is not None:
57 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
58
1a4d82fc 59# Tweak the PATH to include the tools dir.
223e47cc 60if llvm_obj_root is not None:
223e47cc
LB
61 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
62 if not llvm_tools_dir:
1a4d82fc 63 lit_config.fatal('No LLVM tools dir set!')
223e47cc
LB
64 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
65 config.environment['PATH'] = path
66
67# Propagate 'HOME' through the environment.
68if 'HOME' in os.environ:
69 config.environment['HOME'] = os.environ['HOME']
70
71# Propagate 'INCLUDE' through the environment.
72if 'INCLUDE' in os.environ:
73 config.environment['INCLUDE'] = os.environ['INCLUDE']
74
75# Propagate 'LIB' through the environment.
76if '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.
81if 'TMP' in os.environ:
82 config.environment['TMP'] = os.environ['TMP']
83if 'TEMP' in os.environ:
84 config.environment['TEMP'] = os.environ['TEMP']
85
86# Propagate LLVM_SRC_ROOT into the environment.
87config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
88
89# Propagate PYTHON_EXECUTABLE into the environment
90config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
91 '')
92
1a4d82fc
JJ
93# Propagate path to symbolizer for ASan/MSan.
94for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
95 if symbolizer in os.environ:
96 config.environment[symbolizer] = os.environ[symbolizer]
97
85aaf69f
SL
98# Set up OCAMLPATH to include newly built OCaml libraries.
99llvm_lib_dir = getattr(config, 'llvm_lib_dir', None)
100if llvm_lib_dir is None:
101 if llvm_obj_root is not None:
102 llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
103
104if 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
110 else:
111 config.environment['OCAMLPATH'] = llvm_ocaml_lib
112
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
117 else:
118 config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
119
120# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
121config.environment['OCAMLRUNPARAM'] = 'b'
1a4d82fc 122
223e47cc
LB
123###
124
125import os
126
127# Check that the object root is known.
128if 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).
133
134 # Check for 'llvm_site_config' user parameter, and use that if available.
1a4d82fc 135 site_cfg = lit_config.params.get('llvm_site_config', None)
223e47cc 136 if site_cfg and os.path.exists(site_cfg):
1a4d82fc 137 lit_config.load_config(config, site_cfg)
223e47cc
LB
138 raise SystemExit
139
140 # Try to detect the situation where we are using an out-of-tree build by
141 # looking for 'llvm-config'.
142 #
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.
147
148 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
149 if not llvm_config:
1a4d82fc 150 lit_config.fatal('No site specific configuration available!')
223e47cc
LB
151
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()
155
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):
1a4d82fc 159 lit_config.fatal('No site specific configuration available!')
223e47cc
LB
160
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):
1a4d82fc 164 lit_config.fatal('No site specific configuration available!')
223e47cc
LB
165
166 # Okay, that worked. Notify the user of the automagic, and reconfigure.
1a4d82fc
JJ
167 lit_config.note('using out-of-tree build at %r' % llvm_obj_root)
168 lit_config.load_config(config, site_cfg)
223e47cc
LB
169 raise SystemExit
170
171###
172
1a4d82fc 173lli = 'lli'
970d7e83
LB
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.
85aaf69f 179if re.search(r'cygwin|mingw32|windows-gnu|win32', config.host_triple):
1a4d82fc
JJ
180 lli += ' -mtriple='+config.host_triple+'-elf'
181config.substitutions.append( ('%lli', lli ) )
182
183# Similarly, have a macro to use llc with DWARF even when the host is win32.
184llc_dwarf = 'llc'
185if re.search(r'win32', config.target_triple):
186 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
187config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
223e47cc
LB
188
189# Add site-specific substitutions.
85aaf69f 190config.substitutions.append( ('%go', config.go_executable) )
223e47cc
LB
191config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
192config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
1a4d82fc
JJ
193config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
194config.substitutions.append( ('%python', config.python_executable) )
223e47cc 195
85aaf69f
SL
196# OCaml substitutions.
197# Support tests for both native and bytecode builds.
198config.substitutions.append( ('%ocamlc',
199 "%s ocamlc -cclib -L%s %s" %
200 (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) )
201if config.have_ocamlopt in ('1', 'TRUE'):
202 config.substitutions.append( ('%ocamlopt',
203 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
204 (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
205else:
206 config.substitutions.append( ('%ocamlopt', "true" ) )
207
223e47cc
LB
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).
1a4d82fc
JJ
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-).
220NOJUNK = r"(?<!\.|-|\^|/)"
221
222for 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",
85aaf69f 232 r"\bllvm-dsymutil\b",
1a4d82fc
JJ
233 r"\bllvm-dwarfdump\b",
234 r"\bllvm-extract\b",
85aaf69f 235 r"\bllvm-go\b",
1a4d82fc
JJ
236 r"\bllvm-link\b",
237 r"\bllvm-lto\b",
238 r"\bllvm-mc\b",
239 r"\bllvm-mcmarkup\b",
240 r"\bllvm-nm\b",
241 r"\bllvm-objdump\b",
242 r"\bllvm-profdata\b",
243 r"\bllvm-ranlib\b",
244 r"\bllvm-readobj\b",
245 r"\bllvm-rtdyld\b",
223e47cc 246 r"\bllvm-size\b",
1a4d82fc
JJ
247 r"\bllvm-tblgen\b",
248 r"\bllvm-vtabledump\b",
249 r"\bllvm-c-test\b",
250 r"\bmacho-dump\b",
251 NOJUNK + r"\bopt\b",
252 r"\bFileCheck\b",
253 r"\bobj2yaml\b",
254 r"\byaml2obj\b",
255 r"\bverify-uselistorder\b",
223e47cc
LB
256 # Handle these specially as they are strings searched
257 # for during testing.
1a4d82fc
JJ
258 r"\| \bcount\b",
259 r"\| \bnot\b"]:
223e47cc
LB
260 # Extract the tool name from the pattern. This relies on the tool
261 # name being surrounded by \b word match operators. If the
262 # pattern starts with "| ", include it in the string to be
263 # substituted.
1a4d82fc 264 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
223e47cc 265 pattern)
1a4d82fc
JJ
266 tool_pipe = tool_match.group(2)
267 tool_name = tool_match.group(4)
268 tool_path = lit.util.which(tool_name, llvm_tools_dir)
269 if not tool_path:
270 # Warn, but still provide a substitution.
271 lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
272 tool_path = llvm_tools_dir + '/' + tool_name
273 config.substitutions.append((pattern, tool_pipe + tool_path))
274
275### Targets
276
277config.targets = frozenset(config.targets_to_build.split())
223e47cc
LB
278
279### Features
280
281# Shell execution
1a4d82fc 282if execute_external:
223e47cc
LB
283 config.available_features.add('shell')
284
1a4d82fc
JJ
285# Others/can-execute.txt
286if sys.platform not in ['win32']:
287 config.available_features.add('can-execute')
288
223e47cc
LB
289# Loadable module
290# FIXME: This should be supplied by Makefile or autoconf.
291if sys.platform in ['win32', 'cygwin']:
292 loadable_module = (config.enable_shared == 1)
293else:
294 loadable_module = True
295
296if loadable_module:
297 config.available_features.add('loadable_module')
298
1a4d82fc
JJ
299# Sanitizers.
300if config.llvm_use_sanitizer == "Address":
301 config.available_features.add("asan")
302if (config.llvm_use_sanitizer == "Memory" or
303 config.llvm_use_sanitizer == "MemoryWithOrigins"):
304 config.available_features.add("msan")
305if config.llvm_use_sanitizer == "Undefined":
306 config.available_features.add("ubsan")
307else:
308 config.available_features.add("not_ubsan")
309
310# Direct object generation
85aaf69f
SL
311# Suppress x86_64-mingw32 while investigating since r219108.
312if not 'hexagon' in config.target_triple and not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
1a4d82fc
JJ
313 config.available_features.add("object-emission")
314
315if config.have_zlib == "1":
316 config.available_features.add("zlib")
317else:
318 config.available_features.add("nozlib")
319
320# Native compilation: host arch == target arch
321# FIXME: Consider cases that target can be executed
322# even if host_triple were different from target_triple.
323if config.host_triple == config.target_triple:
324 config.available_features.add("native")
970d7e83 325
223e47cc 326import subprocess
1a4d82fc
JJ
327
328def have_ld_plugin_support():
329 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
330 return False
331
332 ld_cmd = subprocess.Popen(['ld', '--help'], stdout = subprocess.PIPE)
85aaf69f 333 ld_out = ld_cmd.stdout.read().decode()
1a4d82fc
JJ
334 ld_cmd.wait()
335
85aaf69f
SL
336 if not '-plugin' in ld_out:
337 return False
338
339 # check that the used emulations are supported.
340 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
341 if len(emu_line) != 1:
342 return False
343 emu_line = emu_line[0]
344 fields = emu_line.split(':')
345 if len(fields) != 3:
346 return False
347 emulations = fields[2].split()
348 if 'elf32ppc' not in emulations or 'elf_x86_64' not in emulations:
349 return False
350
1a4d82fc
JJ
351 ld_version = subprocess.Popen(['ld', '--version'], stdout = subprocess.PIPE)
352 if not 'GNU gold' in ld_version.stdout.read():
353 return False
354 ld_version.wait()
355
356 return True
357
358if have_ld_plugin_support():
359 config.available_features.add('ld_plugin')
360
361# Ask llvm-config about assertion mode.
223e47cc 362try:
1a4d82fc
JJ
363 llvm_config_cmd = subprocess.Popen(
364 [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
365 stdout = subprocess.PIPE,
366 env=config.environment)
367except OSError:
368 print("Could not find llvm-config in " + llvm_tools_dir)
223e47cc
LB
369 exit(42)
370
1a4d82fc 371if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
223e47cc 372 config.available_features.add('asserts')
1a4d82fc
JJ
373llvm_config_cmd.wait()
374
375if 'darwin' == sys.platform:
376 try:
377 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
378 stdout = subprocess.PIPE)
379 except OSError:
380 print("Could not exec sysctl")
381 result = sysctl_cmd.stdout.read().decode('ascii')
382 if -1 != result.find("hw.optional.fma: 1"):
383 config.available_features.add('fma3')
384 sysctl_cmd.wait()
385
386# .debug_frame is not emitted for targeting Windows x64.
85aaf69f 387if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
1a4d82fc
JJ
388 config.available_features.add('debug_frame')
389
390# Check if we should use gmalloc.
391use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
392if use_gmalloc_str is not None:
393 if use_gmalloc_str.lower() in ('1', 'true'):
394 use_gmalloc = True
395 elif use_gmalloc_str.lower() in ('', '0', 'false'):
396 use_gmalloc = False
397 else:
398 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
399else:
400 # Default to not using gmalloc
401 use_gmalloc = False
402
403# Allow use of an explicit path for gmalloc library.
404# Will default to '/usr/lib/libgmalloc.dylib' if not set.
405gmalloc_path_str = lit_config.params.get('gmalloc_path',
406 '/usr/lib/libgmalloc.dylib')
407
408if use_gmalloc:
409 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})