xref: /aosp_15_r20/external/compiler-rt/test/lit.common.cfg (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot# -*- Python -*-
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger Robot# Configuration file for 'lit' test runner.
4*7c3d14c8STreehugger Robot# This file contains common rules for various compiler-rt testsuites.
5*7c3d14c8STreehugger Robot# It is mostly copied from lit.cfg used by Clang.
6*7c3d14c8STreehugger Robotimport os
7*7c3d14c8STreehugger Robotimport platform
8*7c3d14c8STreehugger Robotimport re
9*7c3d14c8STreehugger Robotimport subprocess
10*7c3d14c8STreehugger Robot
11*7c3d14c8STreehugger Robotimport lit.formats
12*7c3d14c8STreehugger Robotimport lit.util
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot# Setup test format. Use bash on Unix and the lit shell on Windows.
15*7c3d14c8STreehugger Robotexecute_external = (not sys.platform in ['win32'])
16*7c3d14c8STreehugger Robotconfig.test_format = lit.formats.ShTest(execute_external)
17*7c3d14c8STreehugger Robotif execute_external:
18*7c3d14c8STreehugger Robot  config.available_features.add('shell')
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot# Setup clang binary.
21*7c3d14c8STreehugger Robotcompiler_path = getattr(config, 'clang', None)
22*7c3d14c8STreehugger Robotif (not compiler_path) or (not os.path.exists(compiler_path)):
23*7c3d14c8STreehugger Robot  lit_config.fatal("Can't find compiler on path %r" % compiler_path)
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robotcompiler_id = getattr(config, 'compiler_id', None)
26*7c3d14c8STreehugger Robotif compiler_id == "Clang":
27*7c3d14c8STreehugger Robot  if platform.system() != 'Windows':
28*7c3d14c8STreehugger Robot    config.cxx_mode_flags = ["--driver-mode=g++"]
29*7c3d14c8STreehugger Robot  else:
30*7c3d14c8STreehugger Robot    config.cxx_mode_flags = []
31*7c3d14c8STreehugger Robot  # We assume that sanitizers should provide good enough error
32*7c3d14c8STreehugger Robot  # reports and stack traces even with minimal debug info.
33*7c3d14c8STreehugger Robot  config.debug_info_flags = ["-gline-tables-only"]
34*7c3d14c8STreehugger Robot  if platform.system() == 'Windows':
35*7c3d14c8STreehugger Robot    config.debug_info_flags.append("-gcodeview")
36*7c3d14c8STreehugger Robotelif compiler_id == 'GNU':
37*7c3d14c8STreehugger Robot  config.cxx_mode_flags = ["-x c++"]
38*7c3d14c8STreehugger Robot  config.debug_info_flags = ["-g"]
39*7c3d14c8STreehugger Robotelse:
40*7c3d14c8STreehugger Robot  lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
41*7c3d14c8STreehugger Robot# Add compiler ID to the list of available features.
42*7c3d14c8STreehugger Robotconfig.available_features.add(compiler_id)
43*7c3d14c8STreehugger Robot
44*7c3d14c8STreehugger Robot# Clear some environment variables that might affect Clang.
45*7c3d14c8STreehugger Robotpossibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
46*7c3d14c8STreehugger Robot                               'MSAN_OPTIONS', 'UBSAN_OPTIONS',
47*7c3d14c8STreehugger Robot                               'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
48*7c3d14c8STreehugger Robot                               'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
49*7c3d14c8STreehugger Robot                               'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
50*7c3d14c8STreehugger Robot                               'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
51*7c3d14c8STreehugger Robot                               'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
52*7c3d14c8STreehugger Robot                               'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
53*7c3d14c8STreehugger Robot                               'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
54*7c3d14c8STreehugger Robot                               'LIBCLANG_RESOURCE_USAGE',
55*7c3d14c8STreehugger Robot                               'LIBCLANG_CODE_COMPLETION_LOGGING']
56*7c3d14c8STreehugger Robot# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
57*7c3d14c8STreehugger Robotif platform.system() != 'Windows':
58*7c3d14c8STreehugger Robot    possibly_dangerous_env_vars.append('INCLUDE')
59*7c3d14c8STreehugger Robotfor name in possibly_dangerous_env_vars:
60*7c3d14c8STreehugger Robot  if name in config.environment:
61*7c3d14c8STreehugger Robot    del config.environment[name]
62*7c3d14c8STreehugger Robot
63*7c3d14c8STreehugger Robot# Tweak PATH to include llvm tools dir.
64*7c3d14c8STreehugger Robotllvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
65*7c3d14c8STreehugger Robotif (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
66*7c3d14c8STreehugger Robot  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
67*7c3d14c8STreehugger Robotpath = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
68*7c3d14c8STreehugger Robotconfig.environment['PATH'] = path
69*7c3d14c8STreehugger Robot
70*7c3d14c8STreehugger Robot# Help MSVS link.exe find the standard libraries.
71*7c3d14c8STreehugger Robot# Make sure we only try to use it when targetting Windows.
72*7c3d14c8STreehugger Robotif platform.system() == 'Windows' and '-win' in config.target_triple:
73*7c3d14c8STreehugger Robot  config.environment['LIB'] = os.environ['LIB']
74*7c3d14c8STreehugger Robot
75*7c3d14c8STreehugger Robotif re.match(r'^x86_64.*-linux', config.target_triple):
76*7c3d14c8STreehugger Robot      config.available_features.add("x86_64-linux")
77*7c3d14c8STreehugger Robot
78*7c3d14c8STreehugger Robot# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
79*7c3d14c8STreehugger Robot# in RUN lines.
80*7c3d14c8STreehugger Robotconfig.substitutions.append(
81*7c3d14c8STreehugger Robot    (' clang', """\n\n*** Do not use 'clangXXX' in tests,
82*7c3d14c8STreehugger Robot     instead define '%clangXXX' substitution in lit config. ***\n\n""") )
83*7c3d14c8STreehugger Robot
84*7c3d14c8STreehugger Robot# Allow tests to be executed on a simulator or remotely.
85*7c3d14c8STreehugger Robotconfig.substitutions.append( ('%run', config.emulator) )
86*7c3d14c8STreehugger Robot
87*7c3d14c8STreehugger Robot# Define CHECK-%os to check for OS-dependent output.
88*7c3d14c8STreehugger Robotconfig.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
89*7c3d14c8STreehugger Robot
90*7c3d14c8STreehugger Robotif config.host_os == 'Windows':
91*7c3d14c8STreehugger Robot  # FIXME: This isn't quite right. Specifically, it will succeed if the program
92*7c3d14c8STreehugger Robot  # does not crash but exits with a non-zero exit code. We ought to merge
93*7c3d14c8STreehugger Robot  # KillTheDoctor and not --crash to make the latter more useful and remove the
94*7c3d14c8STreehugger Robot  # need for this substitution.
95*7c3d14c8STreehugger Robot  config.expect_crash = "not KillTheDoctor "
96*7c3d14c8STreehugger Robotelse:
97*7c3d14c8STreehugger Robot  config.expect_crash = "not --crash "
98*7c3d14c8STreehugger Robot
99*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%expect_crash ", config.expect_crash) )
100*7c3d14c8STreehugger Robot
101*7c3d14c8STreehugger Robottarget_arch = getattr(config, 'target_arch', None)
102*7c3d14c8STreehugger Robotif target_arch:
103*7c3d14c8STreehugger Robot  config.available_features.add(target_arch + '-target-arch')
104*7c3d14c8STreehugger Robot  if target_arch in ['x86_64', 'i386', 'i686']:
105*7c3d14c8STreehugger Robot    config.available_features.add('x86-target-arch')
106*7c3d14c8STreehugger Robot
107*7c3d14c8STreehugger Robotcompiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
108*7c3d14c8STreehugger Robotif not compiler_rt_debug:
109*7c3d14c8STreehugger Robot  config.available_features.add('compiler-rt-optimized')
110*7c3d14c8STreehugger Robot
111*7c3d14c8STreehugger Robotsanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
112*7c3d14c8STreehugger Robotif sanitizer_can_use_cxxabi:
113*7c3d14c8STreehugger Robot  config.available_features.add('cxxabi')
114*7c3d14c8STreehugger Robot
115*7c3d14c8STreehugger Robotif config.has_lld:
116*7c3d14c8STreehugger Robot  config.available_features.add('lld')
117*7c3d14c8STreehugger Robot
118*7c3d14c8STreehugger Robotif config.can_symbolize:
119*7c3d14c8STreehugger Robot  config.available_features.add('can-symbolize')
120*7c3d14c8STreehugger Robot
121*7c3d14c8STreehugger Robotlit.util.usePlatformSdkOnDarwin(config, lit_config)
122*7c3d14c8STreehugger Robot
123*7c3d14c8STreehugger Robotif config.host_os == 'Darwin':
124*7c3d14c8STreehugger Robot  try:
125*7c3d14c8STreehugger Robot    osx_version = subprocess.check_output(["sw_vers", "-productVersion"])
126*7c3d14c8STreehugger Robot    osx_version = tuple(int(x) for x in osx_version.split('.'))
127*7c3d14c8STreehugger Robot    if osx_version >= (10, 11):
128*7c3d14c8STreehugger Robot      config.available_features.add('osx-autointerception')
129*7c3d14c8STreehugger Robot      config.available_features.add('osx-ld64-live_support')
130*7c3d14c8STreehugger Robot    else:
131*7c3d14c8STreehugger Robot      # The ASAN initialization-bug.cc test should XFAIL on OS X systems
132*7c3d14c8STreehugger Robot      # older than El Capitan. By marking the test as being unsupported with
133*7c3d14c8STreehugger Robot      # this "feature", we can pass the test on newer OS X versions and other
134*7c3d14c8STreehugger Robot      # platforms.
135*7c3d14c8STreehugger Robot      config.available_features.add('osx-no-ld64-live_support')
136*7c3d14c8STreehugger Robot  except:
137*7c3d14c8STreehugger Robot    pass
138*7c3d14c8STreehugger Robot
139*7c3d14c8STreehugger Robotsancovcc_path = os.path.join(llvm_tools_dir, "sancov")
140*7c3d14c8STreehugger Robotif os.path.exists(sancovcc_path):
141*7c3d14c8STreehugger Robot  config.available_features.add("has_sancovcc")
142*7c3d14c8STreehugger Robot  config.substitutions.append( ("%sancovcc ", sancovcc_path) )
143*7c3d14c8STreehugger Robot
144*7c3d14c8STreehugger Robotdef is_darwin_lto_supported():
145*7c3d14c8STreehugger Robot  return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
146*7c3d14c8STreehugger Robot
147*7c3d14c8STreehugger Robotdef is_linux_lto_supported():
148*7c3d14c8STreehugger Robot  if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
149*7c3d14c8STreehugger Robot    return False
150*7c3d14c8STreehugger Robot
151*7c3d14c8STreehugger Robot  ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE)
152*7c3d14c8STreehugger Robot  ld_out = ld_cmd.stdout.read().decode()
153*7c3d14c8STreehugger Robot  ld_cmd.wait()
154*7c3d14c8STreehugger Robot
155*7c3d14c8STreehugger Robot  if not '-plugin' in ld_out:
156*7c3d14c8STreehugger Robot    return False
157*7c3d14c8STreehugger Robot
158*7c3d14c8STreehugger Robot  return True
159*7c3d14c8STreehugger Robot
160*7c3d14c8STreehugger Robotdef is_windows_lto_supported():
161*7c3d14c8STreehugger Robot  return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe'))
162*7c3d14c8STreehugger Robot
163*7c3d14c8STreehugger Robotif config.host_os == 'Darwin' and is_darwin_lto_supported():
164*7c3d14c8STreehugger Robot  config.lto_supported = True
165*7c3d14c8STreehugger Robot  config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
166*7c3d14c8STreehugger Robot  config.lto_flags = []
167*7c3d14c8STreehugger Robotelif config.host_os == 'Linux' and is_linux_lto_supported():
168*7c3d14c8STreehugger Robot  config.lto_supported = True
169*7c3d14c8STreehugger Robot  config.lto_launch = []
170*7c3d14c8STreehugger Robot  config.lto_flags = ["-fuse-ld=gold"]
171*7c3d14c8STreehugger Robotelif config.host_os == 'Windows' and is_windows_lto_supported():
172*7c3d14c8STreehugger Robot  config.lto_supported = True
173*7c3d14c8STreehugger Robot  config.lto_launch = []
174*7c3d14c8STreehugger Robot  config.lto_flags = ["-fuse-ld=lld"]
175*7c3d14c8STreehugger Robotelse:
176*7c3d14c8STreehugger Robot  config.lto_supported = False
177*7c3d14c8STreehugger Robot
178*7c3d14c8STreehugger Robot# Ask llvm-config about assertion mode.
179*7c3d14c8STreehugger Robottry:
180*7c3d14c8STreehugger Robot  llvm_config_cmd = subprocess.Popen(
181*7c3d14c8STreehugger Robot      [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
182*7c3d14c8STreehugger Robot      stdout = subprocess.PIPE,
183*7c3d14c8STreehugger Robot      env=config.environment)
184*7c3d14c8STreehugger Robotexcept OSError:
185*7c3d14c8STreehugger Robot  print("Could not find llvm-config in " + llvm_tools_dir)
186*7c3d14c8STreehugger Robot  exit(42)
187*7c3d14c8STreehugger Robot
188*7c3d14c8STreehugger Robotif re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
189*7c3d14c8STreehugger Robot  config.available_features.add('asserts')
190*7c3d14c8STreehugger Robotllvm_config_cmd.wait()
191*7c3d14c8STreehugger Robot
192*7c3d14c8STreehugger Robot# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
193*7c3d14c8STreehugger Robot# retries. We don't do this on otther platforms because it's slower.
194*7c3d14c8STreehugger Robotif platform.system() == 'Windows':
195*7c3d14c8STreehugger Robot  config.test_retry_attempts = 2
196