OSDN Git Service

[llvm-opt-fuzzer] NFC. Add sanity tests.
[android-x86/external-llvm.git] / test / lit.cfg.py
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 from lit.llvm import llvm_config
14 from lit.llvm.subst import FindTool
15 from lit.llvm.subst import ToolSubst
16
17 # name: The name of this test suite.
18 config.name = 'LLVM'
19
20 # testFormat: The test format to use to interpret tests.
21 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
22
23 # suffixes: A list of file extensions to treat as test files. This is overriden
24 # by individual lit.local.cfg files in the test subdirectories.
25 config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s', '.mir']
26
27 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28 # subdirectories contain auxiliary inputs for various tests in their parent
29 # directories.
30 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
31
32 # test_source_root: The root path where tests are located.
33 config.test_source_root = os.path.dirname(__file__)
34
35 # test_exec_root: The root path where tests should be run.
36 config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
37
38 # Tweak the PATH to include the tools dir.
39 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
40
41 # Propagate some variables from the host environment.
42 llvm_config.with_system_environment(
43     ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
44
45
46 # Set up OCAMLPATH to include newly built OCaml libraries.
47 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
48 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
49
50 llvm_config.with_system_environment('OCAMLPATH')
51 llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
52 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
53
54 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
55 llvm_config.with_environment(
56     'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
57
58 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
59 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
60
61 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
62 # available. This is darwin specific since it's currently only needed on darwin.
63
64
65 def get_asan_rtlib():
66     if not 'Address' in config.llvm_use_sanitizer or \
67        not 'Darwin' in config.host_os or \
68        not 'x86' in config.host_triple:
69         return ''
70     try:
71         import glob
72     except:
73         print('glob module not found, skipping get_asan_rtlib() lookup')
74         return ''
75     # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
76     # path from the host cc.
77     host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib')
78     asan_dylib_dir_pattern = host_lib_dir + \
79         '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib'
80     found_dylibs = glob.glob(asan_dylib_dir_pattern)
81     if len(found_dylibs) != 1:
82         return ''
83     return found_dylibs[0]
84
85
86 llvm_config.use_default_substitutions()
87
88 # Add site-specific substitutions.
89 config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
90 config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
91 config.substitutions.append(('%exeext', config.llvm_exe_ext))
92 config.substitutions.append(('%host_cc', config.host_cc))
93
94
95 lli_args = []
96 # The target triple used by default by lli is the process target triple (some
97 # triple appropriate for generating code for the current process) but because
98 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
99 # Windows.  FIXME: the process target triple should be used here, but this is
100 # difficult to obtain on Windows.
101 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
102     lli_args = ['-mtriple=' + config.host_triple + '-elf']
103
104 llc_args = []
105
106 # Similarly, have a macro to use llc with DWARF even when the host is win32.
107 if re.search(r'win32', config.target_triple):
108     llc_args = [' -mtriple=' +
109                 config.target_triple.replace('-win32', '-mingw32')]
110
111 # Provide the path to asan runtime lib if available. On darwin, this lib needs
112 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
113 # to be linked contain instrumented sanitizer code.
114 ld64_cmd = config.ld64_executable
115 asan_rtlib = get_asan_rtlib()
116 if asan_rtlib:
117     ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd)
118
119 ocamlc_command = '%s ocamlc -cclib -L%s %s' % (
120     config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)
121 ocamlopt_command = 'true'
122 if config.have_ocamlopt:
123     ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % (
124         config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)
125
126
127 tools = [
128     ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
129     ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args),
130     ToolSubst('%go', config.go_executable, unresolved='ignore'),
131     ToolSubst('%gold', config.gold_executable, unresolved='ignore'),
132     ToolSubst('%ld64', ld64_cmd, unresolved='ignore'),
133     ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
134     ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
135 ]
136
137 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
138 tools.extend([
139     'lli', 'lli-child-target', 'llvm-ar', 'llvm-as', 'llvm-bcanalyzer', 'llvm-config', 'llvm-cov',
140     'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis', 'llvm-dsymutil',
141     'llvm-dwarfdump', 'llvm-extract', 'llvm-isel-fuzzer', 'llvm-opt-fuzzer', 'llvm-lib',
142     'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mcmarkup',
143     'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
144     'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-readobj',
145     'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings', 'llvm-tblgen',
146     'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml',
147     'yaml-bench', 'verify-uselistorder',
148     'bugpoint', 'llc', 'llvm-symbolizer', 'opt', 'sancov', 'sanstats'])
149
150 # The following tools are optional
151 tools.extend([
152     ToolSubst('llvm-go', unresolved='ignore'),
153     ToolSubst('llvm-mt', unresolved='ignore'),
154     ToolSubst('Kaleidoscope-Ch3', unresolved='ignore'),
155     ToolSubst('Kaleidoscope-Ch4', unresolved='ignore'),
156     ToolSubst('Kaleidoscope-Ch5', unresolved='ignore'),
157     ToolSubst('Kaleidoscope-Ch6', unresolved='ignore'),
158     ToolSubst('Kaleidoscope-Ch7', unresolved='ignore'),
159     ToolSubst('Kaleidoscope-Ch8', unresolved='ignore')])
160
161 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
162
163 # Targets
164
165 config.targets = frozenset(config.targets_to_build.split())
166
167 for arch in config.targets_to_build.split():
168     config.available_features.add(arch.lower() + '-registered-target')
169
170 # Features
171 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
172 if (config.host_ldflags.find("-m32") < 0
173     and any(config.llvm_host_triple.startswith(x) for x in known_arches)):
174   config.available_features.add("llvm-64-bits")
175
176 # Others/can-execute.txt
177 if sys.platform not in ['win32']:
178     config.available_features.add('can-execute')
179     config.available_features.add('not_COFF')
180
181 # Loadable module
182 # FIXME: This should be supplied by Makefile or autoconf.
183 if sys.platform in ['win32', 'cygwin']:
184     loadable_module = (config.enable_shared == 1)
185 else:
186     loadable_module = True
187
188 if loadable_module:
189     config.available_features.add('loadable_module')
190
191 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
192 if not config.build_shared_libs and not config.link_llvm_dylib:
193     config.available_features.add('static-libs')
194
195 # Direct object generation
196 if not 'hexagon' in config.target_triple:
197     config.available_features.add('object-emission')
198
199 # LLVM can be configured with an empty default triple
200 # Some tests are "generic" and require a valid default triple
201 if config.target_triple:
202     config.available_features.add('default_triple')
203
204 import subprocess
205
206
207 def have_ld_plugin_support():
208     if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
209         return False
210
211     ld_cmd = subprocess.Popen(
212         [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
213     ld_out = ld_cmd.stdout.read().decode()
214     ld_cmd.wait()
215
216     if not '-plugin' in ld_out:
217         return False
218
219     # check that the used emulations are supported.
220     emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
221     if len(emu_line) != 1:
222         return False
223     emu_line = emu_line[0]
224     fields = emu_line.split(':')
225     if len(fields) != 3:
226         return False
227     emulations = fields[2].split()
228     if 'elf_x86_64' not in emulations:
229         return False
230     if 'elf32ppc' in emulations:
231         config.available_features.add('ld_emu_elf32ppc')
232
233     ld_version = subprocess.Popen(
234         [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
235     if not 'GNU gold' in ld_version.stdout.read().decode():
236         return False
237     ld_version.wait()
238
239     return True
240
241
242 if have_ld_plugin_support():
243     config.available_features.add('ld_plugin')
244
245
246 def have_ld64_plugin_support():
247     if not config.llvm_tool_lto_build or config.ld64_executable == '':
248         return False
249
250     ld_cmd = subprocess.Popen(
251         [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
252     ld_out = ld_cmd.stderr.read().decode()
253     ld_cmd.wait()
254
255     if 'ld64' not in ld_out or 'LTO' not in ld_out:
256         return False
257
258     return True
259
260
261 if have_ld64_plugin_support():
262     config.available_features.add('ld64_plugin')
263
264 # Ask llvm-config about asserts and global-isel.
265 llvm_config.feature_config(
266     [('--assertion-mode', {'ON': 'asserts'}),
267      ('--has-global-isel', {'ON': 'global-isel'})])
268
269 if 'darwin' == sys.platform:
270     try:
271         sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
272                                       stdout=subprocess.PIPE)
273     except OSError:
274         print('Could not exec sysctl')
275     result = sysctl_cmd.stdout.read().decode('ascii')
276     if -1 != result.find('hw.optional.fma: 1'):
277         config.available_features.add('fma3')
278     sysctl_cmd.wait()
279
280 # .debug_frame is not emitted for targeting Windows x64.
281 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
282     config.available_features.add('debug_frame')
283
284 if config.have_libxar:
285     config.available_features.add('xar')
286
287 if config.llvm_libxml2_enabled == '1':
288     config.available_features.add('libxml2')