Recommit r310809 with a fix for the spill problem
[llvm-core.git] / test / lit.cfg.py
blob28e770d63089eb7cfe9c4728e104157ac532fda6
1 # -*- Python -*-
3 # Configuration file for the 'lit' test runner.
5 import os
6 import sys
7 import re
8 import platform
9 import subprocess
11 import lit.util
12 import lit.formats
13 from lit.llvm import llvm_config
14 from lit.llvm import ToolFilter
16 # name: The name of this test suite.
17 config.name = 'LLVM'
19 # testFormat: The test format to use to interpret tests.
20 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
22 # suffixes: A list of file extensions to treat as test files. This is overriden
23 # by individual lit.local.cfg files in the test subdirectories.
24 config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s', '.mir']
26 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
27 # subdirectories contain auxiliary inputs for various tests in their parent
28 # directories.
29 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
31 # test_source_root: The root path where tests are located.
32 config.test_source_root = os.path.dirname(__file__)
34 # test_exec_root: The root path where tests should be run.
35 config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
37 # Tweak the PATH to include the tools dir.
38 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
40 # Propagate some variables from the host environment.
41 llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
44 # Set up OCAMLPATH to include newly built OCaml libraries.
45 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
46 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
48 llvm_config.with_system_environment('OCAMLPATH')
49 llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
50 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
52 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
53 llvm_config.with_environment('CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
55 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
56 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
58 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
59 # available. This is darwin specific since it's currently only needed on darwin.
60 def get_asan_rtlib():
61 if not "Address" in config.llvm_use_sanitizer or \
62 not "Darwin" in config.host_os or \
63 not "x86" in config.host_triple:
64 return ""
65 try:
66 import glob
67 except:
68 print("glob module not found, skipping get_asan_rtlib() lookup")
69 return ""
70 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
71 # path from the host cc.
72 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
73 asan_dylib_dir_pattern = host_lib_dir + \
74 "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
75 found_dylibs = glob.glob(asan_dylib_dir_pattern)
76 if len(found_dylibs) != 1:
77 return ""
78 return found_dylibs[0]
80 lli = 'lli'
81 # The target triple used by default by lli is the process target triple (some
82 # triple appropriate for generating code for the current process) but because
83 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
84 # Windows. FIXME: the process target triple should be used here, but this is
85 # difficult to obtain on Windows.
86 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
87 lli += ' -mtriple='+config.host_triple+'-elf'
88 config.substitutions.append( ('%lli', lli ) )
90 # Similarly, have a macro to use llc with DWARF even when the host is win32.
91 llc_dwarf = 'llc'
92 if re.search(r'win32', config.target_triple):
93 llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
94 config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
96 # Add site-specific substitutions.
97 config.substitutions.append( ('%gold', config.gold_executable) )
98 config.substitutions.append( ('%go', config.go_executable) )
99 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
100 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
101 config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
102 config.substitutions.append( ('%python', config.python_executable) )
103 config.substitutions.append( ('%host_cc', config.host_cc) )
105 # Provide the path to asan runtime lib if available. On darwin, this lib needs
106 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
107 # to be linked contain instrumented sanitizer code.
108 ld64_cmd = config.ld64_executable
109 asan_rtlib = get_asan_rtlib()
110 if asan_rtlib:
111 ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
112 config.substitutions.append( ('%ld64', ld64_cmd) )
114 # OCaml substitutions.
115 # Support tests for both native and bytecode builds.
116 config.substitutions.append( ('%ocamlc',
117 "%s ocamlc -cclib -L%s %s" %
118 (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)) )
119 if config.have_ocamlopt:
120 config.substitutions.append( ('%ocamlopt',
121 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
122 (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)) )
123 else:
124 config.substitutions.append( ('%ocamlopt', "true" ) )
126 # For each occurrence of an llvm tool name as its own word, replace it
127 # with the full path to the build directory holding that tool. This
128 # ensures that we are testing the tools just built and not some random
129 # tools that might happen to be in the user's PATH. Thus this list
130 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
131 # (llvm_tools_dir in lit parlance).
133 # Avoid matching RUN line fragments that are actually part of
134 # path names or options or whatever.
135 # The regex is a pre-assertion to avoid matching a preceding
136 # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
137 # also have a post-assertion to not match a trailing hyphen (foo-).
138 JUNKCHARS = r".-^/<"
140 required_tools = [
141 'lli', 'llvm-ar', 'llvm-as', 'llvm-bcanalyzer', 'llvm-config', 'llvm-cov',
142 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis', 'llvm-dsymutil',
143 'llvm-dwarfdump', 'llvm-extract', 'llvm-isel-fuzzer', 'llvm-lib',
144 'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mcmarkup',
145 'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
146 'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-readobj',
147 'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings', 'llvm-tblgen',
148 'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml',
149 'FileCheck', 'yaml-bench', 'verify-uselistorder',
150 ToolFilter('bugpoint', post='-'),
151 ToolFilter('llc', pre=JUNKCHARS),
152 ToolFilter('llvm-symbolizer', pre=JUNKCHARS),
153 ToolFilter('opt', JUNKCHARS),
154 ToolFilter('sancov', pre=JUNKCHARS),
155 ToolFilter('sanstats', pre=JUNKCHARS),
156 # Handle these specially as they are strings searched for during testing.
157 ToolFilter(r'\| \bcount\b', verbatim=True),
158 ToolFilter(r'\| \bnot\b', verbatim=True)]
160 llvm_config.add_tool_substitutions(required_tools, config.llvm_tools_dir)
162 # For tools that are optional depending on the config, we won't warn
163 # if they're missing.
165 optional_tools = [
166 'llvm-go', 'llvm-mt', 'Kaleidoscope-Ch3', 'Kaleidoscope-Ch4',
167 'Kaleidoscope-Ch5', 'Kaleidoscope-Ch6', 'Kaleidoscope-Ch7',
168 'Kaleidoscope-Ch8']
169 llvm_config.add_tool_substitutions(optional_tools, config.llvm_tools_dir,
170 warn_missing=False)
172 ### Targets
174 config.targets = frozenset(config.targets_to_build.split())
176 for arch in config.targets_to_build.split():
177 config.available_features.add(arch.lower() + '-registered-target')
179 ### Features
181 # Others/can-execute.txt
182 if sys.platform not in ['win32']:
183 config.available_features.add('can-execute')
184 config.available_features.add('not_COFF')
186 # Loadable module
187 # FIXME: This should be supplied by Makefile or autoconf.
188 if sys.platform in ['win32', 'cygwin']:
189 loadable_module = (config.enable_shared == 1)
190 else:
191 loadable_module = True
193 if loadable_module:
194 config.available_features.add('loadable_module')
196 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
197 if not config.build_shared_libs:
198 config.available_features.add("static-libs")
200 # Direct object generation
201 if not 'hexagon' in config.target_triple:
202 config.available_features.add("object-emission")
204 # LLVM can be configured with an empty default triple
205 # Some tests are "generic" and require a valid default triple
206 if config.target_triple:
207 config.available_features.add("default_triple")
209 import subprocess
211 def have_ld_plugin_support():
212 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
213 return False
215 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
216 ld_out = ld_cmd.stdout.read().decode()
217 ld_cmd.wait()
219 if not '-plugin' in ld_out:
220 return False
222 # check that the used emulations are supported.
223 emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
224 if len(emu_line) != 1:
225 return False
226 emu_line = emu_line[0]
227 fields = emu_line.split(':')
228 if len(fields) != 3:
229 return False
230 emulations = fields[2].split()
231 if 'elf_x86_64' not in emulations:
232 return False
233 if 'elf32ppc' in emulations:
234 config.available_features.add('ld_emu_elf32ppc')
236 ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'})
237 if not 'GNU gold' in ld_version.stdout.read().decode():
238 return False
239 ld_version.wait()
241 return True
243 if have_ld_plugin_support():
244 config.available_features.add('ld_plugin')
246 def have_ld64_plugin_support():
247 if not config.llvm_tool_lto_build or config.ld64_executable == '':
248 return False
250 ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
251 ld_out = ld_cmd.stderr.read().decode()
252 ld_cmd.wait()
254 if 'ld64' not in ld_out or 'LTO' not in ld_out:
255 return False
257 return True
259 if have_ld64_plugin_support():
260 config.available_features.add('ld64_plugin')
262 # Ask llvm-config about asserts and global-isel.
263 llvm_config.feature_config(
264 [('--assertion-mode', {'ON' : 'asserts'}),
265 ('--has-global-isel', {'ON' : 'global-isel'})])
267 if 'darwin' == sys.platform:
268 try:
269 sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
270 stdout = subprocess.PIPE)
271 except OSError:
272 print("Could not exec sysctl")
273 result = sysctl_cmd.stdout.read().decode('ascii')
274 if -1 != result.find("hw.optional.fma: 1"):
275 config.available_features.add('fma3')
276 sysctl_cmd.wait()
278 # .debug_frame is not emitted for targeting Windows x64.
279 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
280 config.available_features.add('debug_frame')
282 if config.have_libxar:
283 config.available_features.add('xar')
285 if config.llvm_libxml2_enabled == "1":
286 config.available_features.add('libxml2')