blob: aa3fd03add5a9be8b53eb6aef6a97c4758690697 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001# -*- 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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08008import re
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07009import subprocess
Stephen Hines2d1fdb22014-05-28 23:58:16 -070010
11import lit.formats
Stephen Hines6a211c52014-07-21 00:49:56 -070012import lit.util
Stephen Hines2d1fdb22014-05-28 23:58:16 -070013
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080014# Setup test format. Use bash on Unix and the lit shell on Windows.
15execute_external = (not sys.platform in ['win32'])
Stephen Hines2d1fdb22014-05-28 23:58:16 -070016config.test_format = lit.formats.ShTest(execute_external)
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080017if execute_external:
18 config.available_features.add('shell')
Stephen Hines2d1fdb22014-05-28 23:58:16 -070019
20# Setup clang binary.
21compiler_path = getattr(config, 'clang', None)
22if (not compiler_path) or (not os.path.exists(compiler_path)):
23 lit_config.fatal("Can't find compiler on path %r" % compiler_path)
24
25compiler_id = getattr(config, 'compiler_id', None)
26if compiler_id == "Clang":
27 if platform.system() != 'Windows':
28 config.cxx_mode_flags = ["--driver-mode=g++"]
29 else:
30 config.cxx_mode_flags = []
Stephen Hines6d186232014-11-26 17:56:19 -080031 # We assume that sanitizers should provide good enough error
32 # reports and stack traces even with minimal debug info.
33 config.debug_info_flags = ["-gline-tables-only"]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080034 if platform.system() == 'Windows':
35 config.debug_info_flags.append("-gcodeview")
Stephen Hines2d1fdb22014-05-28 23:58:16 -070036elif compiler_id == 'GNU':
37 config.cxx_mode_flags = ["-x c++"]
Stephen Hines6d186232014-11-26 17:56:19 -080038 config.debug_info_flags = ["-g"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070039else:
40 lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
41# Add compiler ID to the list of available features.
42config.available_features.add(compiler_id)
43
44# Clear some environment variables that might affect Clang.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070045possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
46 'MSAN_OPTIONS', 'UBSAN_OPTIONS',
47 'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Stephen Hines2d1fdb22014-05-28 23:58:16 -070048 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
49 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
50 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
51 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
52 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
53 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
54 'LIBCLANG_RESOURCE_USAGE',
55 'LIBCLANG_CODE_COMPLETION_LOGGING']
56# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
57if platform.system() != 'Windows':
58 possibly_dangerous_env_vars.append('INCLUDE')
59for name in possibly_dangerous_env_vars:
60 if name in config.environment:
61 del config.environment[name]
62
63# Tweak PATH to include llvm tools dir.
64llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
65if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
66 lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
67path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
68config.environment['PATH'] = path
69
70# Help MSVS link.exe find the standard libraries.
Stephen Hines86277eb2015-03-23 12:06:32 -070071# Make sure we only try to use it when targetting Windows.
72if platform.system() == 'Windows' and '-win' in config.target_triple:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070073 config.environment['LIB'] = os.environ['LIB']
74
75# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
76# in RUN lines.
77config.substitutions.append(
78 (' clang', """\n\n*** Do not use 'clangXXX' in tests,
79 instead define '%clangXXX' substitution in lit config. ***\n\n""") )
80
81# Allow tests to be executed on a simulator or remotely.
82config.substitutions.append( ('%run', config.emulator) )
83
Stephen Hines6d186232014-11-26 17:56:19 -080084# Define CHECK-%os to check for OS-dependent output.
85config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
86
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080087if config.host_os == 'Windows':
88 # FIXME: This isn't quite right. Specifically, it will succeed if the program
89 # does not crash but exits with a non-zero exit code. We ought to merge
90 # KillTheDoctor and not --crash to make the latter more useful and remove the
91 # need for this substitution.
92 config.substitutions.append( ("%expect_crash ", "not KillTheDoctor ") )
93else:
94 config.substitutions.append( ("%expect_crash ", "not --crash ") )
95
Stephen Hines2d1fdb22014-05-28 23:58:16 -070096# Add supported compiler_rt architectures to a list of available features.
97compiler_rt_arch = getattr(config, 'compiler_rt_arch', None)
98if compiler_rt_arch:
99 for arch in compiler_rt_arch.split(";"):
100 config.available_features.add(arch + "-supported-target")
101
102compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
103if not compiler_rt_debug:
104 config.available_features.add('compiler-rt-optimized')
Stephen Hines6a211c52014-07-21 00:49:56 -0700105
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -0800106sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
107if sanitizer_can_use_cxxabi:
108 config.available_features.add('cxxabi')
109
110# Test lld if it is available.
111if config.has_lld:
112 config.available_features.add('lld')
113
Stephen Hines6a211c52014-07-21 00:49:56 -0700114lit.util.usePlatformSdkOnDarwin(config, lit_config)
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -0700115
116def is_darwin_lto_supported():
117 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
118
119def is_linux_lto_supported():
120 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
121 return False
122
123 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE)
124 ld_out = ld_cmd.stdout.read().decode()
125 ld_cmd.wait()
126
127 if not '-plugin' in ld_out:
128 return False
129
130 return True
131
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -0800132def is_windows_lto_supported():
133 return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe'))
134
135if config.host_os == 'Darwin' and is_darwin_lto_supported():
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -0700136 config.lto_supported = True
137 config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
138 config.lto_flags = []
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -0800139elif config.host_os == 'Linux' and is_linux_lto_supported():
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -0700140 config.lto_supported = True
141 config.lto_launch = []
142 config.lto_flags = ["-fuse-ld=gold"]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -0800143elif config.host_os == 'Windows' and is_windows_lto_supported():
144 config.lto_supported = True
145 config.lto_launch = []
146 config.lto_flags = ["-fuse-ld=lld"]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -0700147else:
148 config.lto_supported = False
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -0800149
150# Ask llvm-config about assertion mode.
151try:
152 llvm_config_cmd = subprocess.Popen(
153 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
154 stdout = subprocess.PIPE,
155 env=config.environment)
156except OSError:
157 print("Could not find llvm-config in " + llvm_tools_dir)
158 exit(42)
159
160if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
161 config.available_features.add('asserts')
162llvm_config_cmd.wait()
163
164# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
165# retries. We don't do this on otther platforms because it's slower.
166if platform.system() == 'Windows':
167 config.test_retry_attempts = 2