2017-12-12 16:54:20 +00:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import re
|
|
|
|
import subprocess
|
2019-10-31 16:51:53 +00:00
|
|
|
import sys
|
2017-12-12 16:54:20 +00:00
|
|
|
|
|
|
|
import lit.formats
|
|
|
|
import lit.util
|
|
|
|
|
|
|
|
from lit.llvm import llvm_config
|
|
|
|
from lit.llvm.subst import ToolSubst
|
|
|
|
|
|
|
|
# Configuration file for the 'lit' test runner.
|
|
|
|
|
|
|
|
# name: The name of this test suite.
|
|
|
|
config.name = 'debuginfo-tests'
|
|
|
|
|
|
|
|
# testFormat: The test format to use to interpret tests.
|
|
|
|
#
|
|
|
|
# For now we require '&&' between commands, until they get globally killed and
|
|
|
|
# the test runner updated.
|
|
|
|
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
|
|
|
|
|
|
|
|
# suffixes: A list of file extensions to treat as test files.
|
|
|
|
config.suffixes = ['.c', '.cpp', '.m']
|
|
|
|
|
|
|
|
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
|
|
|
|
# subdirectories contain auxiliary inputs for various tests in their parent
|
|
|
|
# directories.
|
|
|
|
config.excludes = ['Inputs']
|
|
|
|
|
|
|
|
# test_source_root: The root path where tests are located.
|
2021-02-08 15:40:55 +00:00
|
|
|
config.test_source_root = config.debuginfo_tests_src_root
|
2017-12-12 16:54:20 +00:00
|
|
|
|
|
|
|
# test_exec_root: The root path where tests should be run.
|
|
|
|
config.test_exec_root = config.debuginfo_tests_obj_root
|
|
|
|
|
2019-10-31 16:51:53 +00:00
|
|
|
llvm_config.use_default_substitutions()
|
|
|
|
|
2019-05-28 23:03:33 +00:00
|
|
|
tools = [
|
|
|
|
ToolSubst('%test_debuginfo', command=os.path.join(
|
2021-02-08 15:40:55 +00:00
|
|
|
config.debuginfo_tests_src_root, 'debuginfo-tests',
|
|
|
|
'llgdb-tests', 'test_debuginfo.pl')),
|
2020-01-11 07:47:41 +00:00
|
|
|
ToolSubst("%llvm_src_root", config.llvm_src_root),
|
|
|
|
ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
|
2019-05-28 23:03:33 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
|
|
|
if attr_value == None:
|
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
|
|
|
"to lit.site.cfg " % attr_name)
|
|
|
|
return attr_value
|
|
|
|
|
|
|
|
# If this is an MSVC environment, the tests at the root of the tree are
|
|
|
|
# unsupported. The local win_cdb test suite, however, is supported.
|
|
|
|
is_msvc = get_required_attr(config, "is_msvc")
|
|
|
|
if is_msvc:
|
2019-10-31 16:51:53 +00:00
|
|
|
config.available_features.add('msvc')
|
2019-05-28 23:03:33 +00:00
|
|
|
# FIXME: We should add some llvm lit utility code to find the Windows SDK
|
|
|
|
# and set up the environment appopriately.
|
|
|
|
win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
|
|
|
|
arch = 'x64'
|
|
|
|
llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
|
|
|
|
# Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
|
|
|
|
# the network.
|
|
|
|
llvm_config.with_environment('_NT_SYMBOL_PATH', '')
|
|
|
|
tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
|
|
|
|
arch, 'cdb.exe')))
|
|
|
|
|
2017-12-12 16:54:20 +00:00
|
|
|
# clang_src_dir is not used by these tests, but is required by
|
|
|
|
# use_clang(), so set it to "".
|
|
|
|
if not hasattr(config, 'clang_src_dir'):
|
|
|
|
config.clang_src_dir = ""
|
|
|
|
llvm_config.use_clang()
|
|
|
|
|
|
|
|
if config.llvm_use_sanitizer:
|
|
|
|
# Propagate path to symbolizer for ASan/MSan.
|
|
|
|
llvm_config.with_system_environment(
|
|
|
|
['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
|
2021-02-24 11:09:18 +00:00
|
|
|
|
|
|
|
def add_host_triple(clang):
|
|
|
|
return '{} --target={}'.format(clang, config.host_triple)
|
|
|
|
|
|
|
|
# The set of arches we can build.
|
|
|
|
targets = set(config.targets_to_build)
|
|
|
|
# Add aliases to the target set.
|
|
|
|
if 'AArch64' in targets:
|
|
|
|
targets.add('arm64')
|
|
|
|
if 'ARM' in config.targets_to_build:
|
|
|
|
targets.add('thumbv7')
|
|
|
|
|
|
|
|
def can_target_host():
|
|
|
|
# Check if the targets set contains anything that looks like our host arch.
|
|
|
|
# The arch name in the triple and targets set may be spelled differently
|
|
|
|
# (e.g. x86 vs X86).
|
|
|
|
return any(config.host_triple.lower().startswith(x.lower())
|
|
|
|
for x in targets)
|
|
|
|
|
|
|
|
# Dexter tests run on the host machine. If the host arch is supported add
|
|
|
|
# 'dexter' as an available feature and force the dexter tests to use the host
|
|
|
|
# triple.
|
|
|
|
if can_target_host():
|
|
|
|
config.available_features.add('dexter')
|
|
|
|
if config.host_triple != config.target_triple:
|
|
|
|
print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
|
|
|
|
llvm_config.with_environment('PATHTOCLANG',
|
|
|
|
add_host_triple(llvm_config.config.clang))
|
|
|
|
llvm_config.with_environment('PATHTOCLANGPP',
|
|
|
|
add_host_triple(llvm_config.use_llvm_tool('clang++')))
|
|
|
|
llvm_config.with_environment('PATHTOCLANGCL',
|
|
|
|
add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
|
|
|
|
else:
|
|
|
|
print('Host triple {} not supported. Skipping dexter tests in the '
|
|
|
|
'debuginfo-tests project.'.format(config.host_triple))
|
2019-10-31 16:51:53 +00:00
|
|
|
|
|
|
|
# Check which debuggers are available:
|
2021-05-18 09:57:32 +00:00
|
|
|
lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
|
2019-10-31 16:51:53 +00:00
|
|
|
|
|
|
|
if lldb_path is not None:
|
|
|
|
config.available_features.add('lldb')
|
|
|
|
|
|
|
|
# Produce dexter path, lldb path, and combine into the %dexter substitution
|
2019-11-01 12:29:42 +00:00
|
|
|
# for running a test.
|
2019-10-31 16:51:53 +00:00
|
|
|
dexter_path = os.path.join(config.debuginfo_tests_src_root,
|
2021-02-08 15:40:55 +00:00
|
|
|
'debuginfo-tests', 'dexter', 'dexter.py')
|
2021-02-08 15:46:40 +00:00
|
|
|
dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
|
2019-10-31 16:51:53 +00:00
|
|
|
if lldb_path is not None:
|
2020-02-13 14:24:33 +00:00
|
|
|
dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
|
2019-11-01 12:29:42 +00:00
|
|
|
tools.append(ToolSubst('%dexter', dexter_test_cmd))
|
2019-10-31 16:51:53 +00:00
|
|
|
|
2019-11-01 12:29:42 +00:00
|
|
|
# For testing other bits of dexter that aren't under the "test" subcommand,
|
|
|
|
# have a %dexter_base substitution.
|
2021-02-08 15:46:40 +00:00
|
|
|
dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
|
2019-11-01 12:29:42 +00:00
|
|
|
tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
|
2017-12-12 16:54:20 +00:00
|
|
|
|
2020-03-31 09:18:12 +00:00
|
|
|
# Set up commands for DexTer regression tests.
|
|
|
|
# Builder, debugger, optimisation level and several other flags differ
|
|
|
|
# depending on whether we're running a unix like or windows os.
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
dexter_regression_test_builder = '--builder clang-cl_vs2015'
|
|
|
|
dexter_regression_test_debugger = '--debugger dbgeng'
|
|
|
|
dexter_regression_test_cflags = '--cflags "/Zi /Od"'
|
|
|
|
dexter_regression_test_ldflags = '--ldflags "/Zi"'
|
|
|
|
else:
|
|
|
|
dexter_regression_test_builder = '--builder clang'
|
|
|
|
dexter_regression_test_debugger = "--debugger lldb"
|
|
|
|
dexter_regression_test_cflags = '--cflags "-O0 -glldb"'
|
|
|
|
dexter_regression_test_ldflags = ''
|
|
|
|
|
|
|
|
# Typical command would take the form:
|
|
|
|
# ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
|
|
|
|
dexter_regression_test_command = ' '.join(
|
2021-02-08 15:46:40 +00:00
|
|
|
# "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
|
|
|
|
['"{}"'.format(sys.executable),
|
2021-02-10 15:14:32 +00:00
|
|
|
'"{}"'.format(dexter_path),
|
2020-03-31 09:18:12 +00:00
|
|
|
'test',
|
|
|
|
'--fail-lt 1.0 -w',
|
|
|
|
dexter_regression_test_builder,
|
|
|
|
dexter_regression_test_debugger,
|
|
|
|
dexter_regression_test_cflags,
|
|
|
|
dexter_regression_test_ldflags])
|
|
|
|
|
|
|
|
tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_command))
|
|
|
|
|
2017-12-12 16:54:20 +00:00
|
|
|
tool_dirs = [config.llvm_tools_dir]
|
|
|
|
|
|
|
|
llvm_config.add_tool_substitutions(tools, tool_dirs)
|
|
|
|
|
|
|
|
lit.util.usePlatformSdkOnDarwin(config, lit_config)
|
2018-08-04 00:02:48 +00:00
|
|
|
|
2019-10-31 16:51:53 +00:00
|
|
|
# available_features: REQUIRES/UNSUPPORTED lit commands look at this list.
|
2018-08-04 00:02:48 +00:00
|
|
|
if platform.system() == 'Darwin':
|
2019-06-25 15:58:32 +00:00
|
|
|
xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
|
2018-08-04 00:02:48 +00:00
|
|
|
match = re.search('lldb-(\d+)', xcode_lldb_vers)
|
|
|
|
if match:
|
|
|
|
apple_lldb_vers = int(match.group(1))
|
|
|
|
if apple_lldb_vers < 1000:
|
|
|
|
config.available_features.add('apple-lldb-pre-1000')
|
2019-10-31 16:51:53 +00:00
|
|
|
|
2020-09-29 13:19:54 +00:00
|
|
|
llvm_config.feature_config(
|
|
|
|
[('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
|
|
|
|
)
|