]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/test/lit.common.cfg
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / lit.common.cfg
CommitLineData
1a4d82fc
JJ
1# -*- Python -*-
2
3# Configuration file for 'lit' test runner.
4# This file contains common rules for various compiler-rt testsuites.
5# It is mostly copied from lit.cfg used by Clang.
6import os
7import platform
92a42be0
SL
8import re
9import subprocess
1a4d82fc
JJ
10
11import lit.formats
92a42be0 12import lit.util
1a4d82fc 13
2c00a5a8
XL
14# Choose between lit's internal shell pipeline runner and a real shell. If
15# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
16use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
17if use_lit_shell:
18 # 0 is external, "" is default, and everything else is internal.
19 execute_external = (use_lit_shell == "0")
20else:
21 # Otherwise we default to internal on Windows and external elsewhere, as
22 # bash on Windows is usually very slow.
23 execute_external = (not sys.platform in ['win32'])
24
25# Setup test format.
1a4d82fc 26config.test_format = lit.formats.ShTest(execute_external)
92a42be0
SL
27if execute_external:
28 config.available_features.add('shell')
1a4d82fc 29
1a4d82fc
JJ
30compiler_id = getattr(config, 'compiler_id', None)
31if compiler_id == "Clang":
92a42be0
SL
32 if platform.system() != 'Windows':
33 config.cxx_mode_flags = ["--driver-mode=g++"]
34 else:
35 config.cxx_mode_flags = []
36 # We assume that sanitizers should provide good enough error
37 # reports and stack traces even with minimal debug info.
38 config.debug_info_flags = ["-gline-tables-only"]
39 if platform.system() == 'Windows':
40 config.debug_info_flags.append("-gcodeview")
1a4d82fc
JJ
41elif compiler_id == 'GNU':
42 config.cxx_mode_flags = ["-x c++"]
92a42be0 43 config.debug_info_flags = ["-g"]
1a4d82fc
JJ
44else:
45 lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
92a42be0
SL
46# Add compiler ID to the list of available features.
47config.available_features.add(compiler_id)
1a4d82fc 48
2c00a5a8
XL
49# If needed, add cflag for shadow scale.
50if config.asan_shadow_scale != '':
51 config.target_cflags += " -mllvm -asan-mapping-scale=" + config.asan_shadow_scale
52
53# BFD linker in 64-bit android toolchains fails to find libm.so, which is a
54# transitive shared library dependency (via asan runtime).
55if config.android:
56 config.target_cflags += " -pie -fuse-ld=gold -Wl,--enable-new-dtags"
57
1a4d82fc 58# Clear some environment variables that might affect Clang.
92a42be0
SL
59possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
60 'MSAN_OPTIONS', 'UBSAN_OPTIONS',
61 'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
1a4d82fc
JJ
62 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
63 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
64 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
65 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
66 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
67 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
68 'LIBCLANG_RESOURCE_USAGE',
7cac9316
XL
69 'LIBCLANG_CODE_COMPLETION_LOGGING',
70 'XRAY_OPTIONS']
1a4d82fc
JJ
71# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
72if platform.system() != 'Windows':
73 possibly_dangerous_env_vars.append('INCLUDE')
74for name in possibly_dangerous_env_vars:
75 if name in config.environment:
76 del config.environment[name]
77
78# Tweak PATH to include llvm tools dir.
2c00a5a8
XL
79if (not config.llvm_tools_dir) or (not os.path.exists(config.llvm_tools_dir)):
80 lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % config.llvm_tools_dir)
81path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
1a4d82fc
JJ
82config.environment['PATH'] = path
83
92a42be0
SL
84# Help MSVS link.exe find the standard libraries.
85# Make sure we only try to use it when targetting Windows.
86if platform.system() == 'Windows' and '-win' in config.target_triple:
87 config.environment['LIB'] = os.environ['LIB']
88
5bcae85e
SL
89if re.match(r'^x86_64.*-linux', config.target_triple):
90 config.available_features.add("x86_64-linux")
91
1a4d82fc
JJ
92# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
93# in RUN lines.
94config.substitutions.append(
95 (' clang', """\n\n*** Do not use 'clangXXX' in tests,
96 instead define '%clangXXX' substitution in lit config. ***\n\n""") )
97
98# Allow tests to be executed on a simulator or remotely.
2c00a5a8
XL
99if config.emulator:
100 config.substitutions.append( ('%run', config.emulator) )
101 config.substitutions.append( ('%env ', "env ") )
102 config.compile_wrapper = ""
103elif config.ios:
104 config.available_features.add('ios')
105 device_id_env = "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" if config.iossim else "SANITIZER_IOS_TEST_DEVICE_IDENTIFIER"
106 if device_id_env in os.environ: config.environment[device_id_env] = os.environ[device_id_env]
107 ios_commands_dir = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands")
108 run_wrapper = os.path.join(ios_commands_dir, "iossim_run.py" if config.iossim else "ios_run.py")
109 config.substitutions.append(('%run', run_wrapper))
110 env_wrapper = os.path.join(ios_commands_dir, "iossim_env.py" if config.iossim else "ios_env.py")
111 config.substitutions.append(('%env ', env_wrapper + " "))
112 compile_wrapper = os.path.join(ios_commands_dir, "iossim_compile.py" if config.iossim else "ios_compile.py")
113 config.compile_wrapper = compile_wrapper
114elif config.android:
115 config.available_features.add('android')
116 compile_wrapper = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "android_commands", "android_compile.py") + " "
117 config.compile_wrapper = compile_wrapper
118 config.substitutions.append( ('%run', "") )
119 config.substitutions.append( ('%env ', "env ") )
120else:
121 config.substitutions.append( ('%run', "") )
122 config.substitutions.append( ('%env ', "env ") )
123 config.compile_wrapper = ""
1a4d82fc 124
92a42be0
SL
125# Define CHECK-%os to check for OS-dependent output.
126config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
127
7cac9316
XL
128# Define %arch to check for architecture-dependent output.
129config.substitutions.append( ('%arch', (config.host_arch)))
130
92a42be0
SL
131if config.host_os == 'Windows':
132 # FIXME: This isn't quite right. Specifically, it will succeed if the program
133 # does not crash but exits with a non-zero exit code. We ought to merge
134 # KillTheDoctor and not --crash to make the latter more useful and remove the
135 # need for this substitution.
5bcae85e 136 config.expect_crash = "not KillTheDoctor "
92a42be0 137else:
5bcae85e
SL
138 config.expect_crash = "not --crash "
139
140config.substitutions.append( ("%expect_crash ", config.expect_crash) )
92a42be0 141
5bcae85e
SL
142target_arch = getattr(config, 'target_arch', None)
143if target_arch:
144 config.available_features.add(target_arch + '-target-arch')
2c00a5a8 145 if target_arch in ['x86_64', 'i386']:
5bcae85e 146 config.available_features.add('x86-target-arch')
7cac9316 147 config.available_features.add(target_arch + '-' + config.host_os.lower())
1a4d82fc
JJ
148
149compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
150if not compiler_rt_debug:
151 config.available_features.add('compiler-rt-optimized')
92a42be0
SL
152
153sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
154if sanitizer_can_use_cxxabi:
155 config.available_features.add('cxxabi')
156
92a42be0 157if config.has_lld:
2c00a5a8
XL
158 config.available_features.add('lld-available')
159
160if config.use_lld:
92a42be0
SL
161 config.available_features.add('lld')
162
5bcae85e
SL
163if config.can_symbolize:
164 config.available_features.add('can-symbolize')
165
92a42be0
SL
166lit.util.usePlatformSdkOnDarwin(config, lit_config)
167
5bcae85e 168if config.host_os == 'Darwin':
2c00a5a8 169 osx_version = (10, 0, 0)
5bcae85e
SL
170 try:
171 osx_version = subprocess.check_output(["sw_vers", "-productVersion"])
172 osx_version = tuple(int(x) for x in osx_version.split('.'))
2c00a5a8 173 if len(osx_version) == 2: osx_version = (osx_version[0], osx_version[1], 0)
5bcae85e
SL
174 if osx_version >= (10, 11):
175 config.available_features.add('osx-autointerception')
176 config.available_features.add('osx-ld64-live_support')
177 else:
178 # The ASAN initialization-bug.cc test should XFAIL on OS X systems
179 # older than El Capitan. By marking the test as being unsupported with
180 # this "feature", we can pass the test on newer OS X versions and other
181 # platforms.
182 config.available_features.add('osx-no-ld64-live_support')
183 except:
184 pass
185
2c00a5a8
XL
186 config.darwin_osx_version = osx_version
187
7cac9316
XL
188 # Detect x86_64h
189 try:
190 output = subprocess.check_output(["sysctl", "hw.cpusubtype"])
191 output_re = re.match("^hw.cpusubtype: ([0-9]+)$", output)
192 if output_re:
193 cpu_subtype = int(output_re.group(1))
194 if cpu_subtype == 8: # x86_64h
195 config.available_features.add('x86_64h')
196 except:
197 pass
198
199 config.substitutions.append( ("%macos_min_target_10_11", "-mmacosx-version-min=10.11") )
200else:
201 config.substitutions.append( ("%macos_min_target_10_11", "") )
202
2c00a5a8
XL
203if config.android:
204 adb = os.environ.get('ADB', 'adb')
205 try:
206 android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"]).rstrip()
207 except (subprocess.CalledProcessError, OSError):
208 lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb)" % adb)
209 try:
210 android_api_level = int(android_api_level_str)
211 except ValueError:
212 lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb): got '%s'" % (adb, android_api_level_str))
213 if android_api_level >= 26:
214 config.available_features.add('android-26')
215
216sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
5bcae85e
SL
217if os.path.exists(sancovcc_path):
218 config.available_features.add("has_sancovcc")
219 config.substitutions.append( ("%sancovcc ", sancovcc_path) )
220
92a42be0
SL
221def is_darwin_lto_supported():
222 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
223
224def is_linux_lto_supported():
2c00a5a8
XL
225 if config.use_lld:
226 return True
227
92a42be0
SL
228 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
229 return False
230
7cac9316 231 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
92a42be0
SL
232 ld_out = ld_cmd.stdout.read().decode()
233 ld_cmd.wait()
234
235 if not '-plugin' in ld_out:
236 return False
237
238 return True
239
240def is_windows_lto_supported():
241 return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe'))
242
243if config.host_os == 'Darwin' and is_darwin_lto_supported():
244 config.lto_supported = True
245 config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
246 config.lto_flags = []
247elif config.host_os == 'Linux' and is_linux_lto_supported():
248 config.lto_supported = True
249 config.lto_launch = []
2c00a5a8
XL
250 if config.use_lld:
251 config.lto_flags = ["-fuse-ld=lld"]
252 else:
253 config.lto_flags = ["-fuse-ld=gold"]
92a42be0
SL
254elif config.host_os == 'Windows' and is_windows_lto_supported():
255 config.lto_supported = True
256 config.lto_launch = []
257 config.lto_flags = ["-fuse-ld=lld"]
258else:
259 config.lto_supported = False
260
7cac9316
XL
261if config.lto_supported:
262 config.available_features.add('lto')
2c00a5a8
XL
263 if config.use_thinlto:
264 config.available_features.add('thinlto')
265 config.lto_flags += ["-flto=thin"]
266 else:
267 config.lto_flags += ["-flto"]
7cac9316 268
92a42be0
SL
269# Ask llvm-config about assertion mode.
270try:
271 llvm_config_cmd = subprocess.Popen(
272 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
273 stdout = subprocess.PIPE,
274 env=config.environment)
275except OSError:
2c00a5a8 276 print("Could not find llvm-config in " + config.llvm_tools_dir)
92a42be0
SL
277 exit(42)
278
279if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
280 config.available_features.add('asserts')
281llvm_config_cmd.wait()
282
283# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
284# retries. We don't do this on otther platforms because it's slower.
285if platform.system() == 'Windows':
286 config.test_retry_attempts = 2
2c00a5a8
XL
287
288# Only run up to 3 64-bit sanitized processes simultaneously on Darwin.
289# Using more scales badly and hogs the system due to inefficient handling
290# of large mmap'd regions (terabytes) by the kernel.
291if platform.system() == 'Darwin':
292 lit_config.parallelism_groups["darwin-64bit-sanitizer"] = 3
293
294if config.host_os == 'Darwin':
295 config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath,@executable_path/ %dynamiclib') )
296 config.substitutions.append( ("%ld_flags_rpath_so", '-install_name @rpath/`basename %dynamiclib`') )
297elif config.host_os == 'FreeBSD':
298 config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
299 config.substitutions.append( ("%ld_flags_rpath_so", '') )
300elif config.host_os == 'Linux':
301 config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
302 config.substitutions.append( ("%ld_flags_rpath_so", '') )
303
304# Must be defined after the substitutions that use %dynamiclib.
305config.substitutions.append( ("%dynamiclib", '%T/%xdynamiclib_filename') )
306config.substitutions.append( ("%xdynamiclib_filename", 'lib%xdynamiclib_namespec.so') )
307config.substitutions.append( ("%xdynamiclib_namespec", '%basename_t.dynamic') )
308
309config.default_sanitizer_opts = []
310if config.host_os == 'Darwin':
311 # On Darwin, we default to `abort_on_error=1`, which would make tests run
312 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
313 config.default_sanitizer_opts += ['abort_on_error=0']
314 config.default_sanitizer_opts += ['log_to_syslog=0']
315elif config.android:
316 config.default_sanitizer_opts += ['abort_on_error=0']
317
318# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
319# because the test hangs or fails on one configuration and not the other.
320if config.android or (config.target_arch not in ['arm', 'armhf', 'aarch64']):
321 config.available_features.add('stable-runtime')
322
323if config.asan_shadow_scale:
324 config.available_features.add("shadow-scale-%s" % config.asan_shadow_scale)
325else:
326 config.available_features.add("shadow-scale-3")
327
328# Propagate the LLD/LTO into the clang config option, so nothing else is needed.
329run_wrapper = []
330target_cflags = [getattr(config, 'target_cflags', None)]
331extra_cflags = []
332
333if config.use_lto and config.lto_supported:
334 run_wrapper += config.lto_launch
335 extra_cflags += config.lto_flags
336elif config.use_lto and (not config.lto_supported):
337 config.unsupported = True
338
339if config.use_lld and config.has_lld and not config.use_lto:
340 extra_cflags += ["-fuse-ld=lld"]
341elif config.use_lld and (not config.has_lld):
342 config.unsupported = True
343
344config.clang = " " + " ".join(run_wrapper + [config.compile_wrapper, config.clang]) + " "
345config.target_cflags = " " + " ".join(target_cflags + extra_cflags) + " "