• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8import re
9import subprocess
10
11import lit.formats
12import lit.util
13
14# Setup test format. Use bash on Unix and the lit shell on Windows.
15execute_external = (not sys.platform in ['win32'])
16config.test_format = lit.formats.ShTest(execute_external)
17if execute_external:
18  config.available_features.add('shell')
19
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 = []
31  # 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"]
34  if platform.system() == 'Windows':
35    config.debug_info_flags.append("-gcodeview")
36elif compiler_id == 'GNU':
37  config.cxx_mode_flags = ["-x c++"]
38  config.debug_info_flags = ["-g"]
39else:
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.
45possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
46                               'MSAN_OPTIONS', 'UBSAN_OPTIONS',
47                               'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
48                               '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.
71# Make sure we only try to use it when targetting Windows.
72if platform.system() == 'Windows' and '-win' in config.target_triple:
73  config.environment['LIB'] = os.environ['LIB']
74
75if re.match(r'^x86_64.*-linux', config.target_triple):
76      config.available_features.add("x86_64-linux")
77
78# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
79# in RUN lines.
80config.substitutions.append(
81    (' clang', """\n\n*** Do not use 'clangXXX' in tests,
82     instead define '%clangXXX' substitution in lit config. ***\n\n""") )
83
84# Allow tests to be executed on a simulator or remotely.
85config.substitutions.append( ('%run', config.emulator) )
86
87# Define CHECK-%os to check for OS-dependent output.
88config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
89
90if config.host_os == 'Windows':
91  # FIXME: This isn't quite right. Specifically, it will succeed if the program
92  # does not crash but exits with a non-zero exit code. We ought to merge
93  # KillTheDoctor and not --crash to make the latter more useful and remove the
94  # need for this substitution.
95  config.expect_crash = "not KillTheDoctor "
96else:
97  config.expect_crash = "not --crash "
98
99config.substitutions.append( ("%expect_crash ", config.expect_crash) )
100
101target_arch = getattr(config, 'target_arch', None)
102if target_arch:
103  config.available_features.add(target_arch + '-target-arch')
104  if target_arch in ['x86_64', 'i386', 'i686']:
105    config.available_features.add('x86-target-arch')
106
107compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
108if not compiler_rt_debug:
109  config.available_features.add('compiler-rt-optimized')
110
111sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
112if sanitizer_can_use_cxxabi:
113  config.available_features.add('cxxabi')
114
115if config.has_lld:
116  config.available_features.add('lld')
117
118if config.can_symbolize:
119  config.available_features.add('can-symbolize')
120
121lit.util.usePlatformSdkOnDarwin(config, lit_config)
122
123if config.host_os == 'Darwin':
124  try:
125    osx_version = subprocess.check_output(["sw_vers", "-productVersion"])
126    osx_version = tuple(int(x) for x in osx_version.split('.'))
127    if osx_version >= (10, 11):
128      config.available_features.add('osx-autointerception')
129      config.available_features.add('osx-ld64-live_support')
130    else:
131      # The ASAN initialization-bug.cc test should XFAIL on OS X systems
132      # older than El Capitan. By marking the test as being unsupported with
133      # this "feature", we can pass the test on newer OS X versions and other
134      # platforms.
135      config.available_features.add('osx-no-ld64-live_support')
136  except:
137    pass
138
139sancovcc_path = os.path.join(llvm_tools_dir, "sancov")
140if os.path.exists(sancovcc_path):
141  config.available_features.add("has_sancovcc")
142  config.substitutions.append( ("%sancovcc ", sancovcc_path) )
143
144def is_darwin_lto_supported():
145  return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
146
147def is_linux_lto_supported():
148  if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
149    return False
150
151  ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE)
152  ld_out = ld_cmd.stdout.read().decode()
153  ld_cmd.wait()
154
155  if not '-plugin' in ld_out:
156    return False
157
158  return True
159
160def is_windows_lto_supported():
161  return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe'))
162
163if config.host_os == 'Darwin' and is_darwin_lto_supported():
164  config.lto_supported = True
165  config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
166  config.lto_flags = []
167elif config.host_os == 'Linux' and is_linux_lto_supported():
168  config.lto_supported = True
169  config.lto_launch = []
170  config.lto_flags = ["-fuse-ld=gold"]
171elif config.host_os == 'Windows' and is_windows_lto_supported():
172  config.lto_supported = True
173  config.lto_launch = []
174  config.lto_flags = ["-fuse-ld=lld"]
175else:
176  config.lto_supported = False
177
178# Ask llvm-config about assertion mode.
179try:
180  llvm_config_cmd = subprocess.Popen(
181      [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
182      stdout = subprocess.PIPE,
183      env=config.environment)
184except OSError:
185  print("Could not find llvm-config in " + llvm_tools_dir)
186  exit(42)
187
188if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
189  config.available_features.add('asserts')
190llvm_config_cmd.wait()
191
192# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
193# retries. We don't do this on otther platforms because it's slower.
194if platform.system() == 'Windows':
195  config.test_retry_attempts = 2
196