blob: 6b3284d10cecf6b479e1159d8b5b9f1cdd33d93f [file] [log] [blame]
Don Hinton3a58f672017-12-12 16:54:20 +00001import os
2import platform
3import re
4import subprocess
Jeremy Morse984fad22019-10-31 16:51:53 +00005import sys
Don Hinton3a58f672017-12-12 16:54:20 +00006
7import lit.formats
8import lit.util
9
10from lit.llvm import llvm_config
11from lit.llvm.subst import ToolSubst
Don Hinton3a58f672017-12-12 16:54:20 +000012
13# Configuration file for the 'lit' test runner.
14
15# name: The name of this test suite.
James Henderson24af0992021-02-11 15:41:32 +000016config.name = 'cross-project-tests'
Don Hinton3a58f672017-12-12 16:54:20 +000017
18# testFormat: The test format to use to interpret tests.
Don Hinton3a58f672017-12-12 16:54:20 +000019config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
20
21# suffixes: A list of file extensions to treat as test files.
22config.suffixes = ['.c', '.cpp', '.m']
23
24# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
25# subdirectories contain auxiliary inputs for various tests in their parent
26# directories.
27config.excludes = ['Inputs']
28
29# test_source_root: The root path where tests are located.
James Henderson24af0992021-02-11 15:41:32 +000030config.test_source_root = config.cross_project_tests_src_root
Don Hinton3a58f672017-12-12 16:54:20 +000031
32# test_exec_root: The root path where tests should be run.
James Henderson24af0992021-02-11 15:41:32 +000033config.test_exec_root = config.cross_project_tests_obj_root
Don Hinton3a58f672017-12-12 16:54:20 +000034
Jeremy Morse984fad22019-10-31 16:51:53 +000035llvm_config.use_default_substitutions()
36
Reid Kleckner75d38f12019-05-28 23:03:33 +000037tools = [
38 ToolSubst('%test_debuginfo', command=os.path.join(
James Henderson24af0992021-02-11 15:41:32 +000039 config.cross_project_tests_src_root, 'debuginfo-tests',
James Henderson13647502021-02-08 15:40:55 +000040 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 08:47:41 +010041 ToolSubst("%llvm_src_root", config.llvm_src_root),
42 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:33 +000043]
44
45def get_required_attr(config, attr_name):
46 attr_value = getattr(config, attr_name, None)
47 if attr_value == None:
48 lit_config.fatal(
49 "No attribute %r in test configuration! You may need to run "
50 "tests from your build directory or add this attribute "
51 "to lit.site.cfg " % attr_name)
52 return attr_value
53
54# If this is an MSVC environment, the tests at the root of the tree are
55# unsupported. The local win_cdb test suite, however, is supported.
56is_msvc = get_required_attr(config, "is_msvc")
57if is_msvc:
Jeremy Morse984fad22019-10-31 16:51:53 +000058 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:33 +000059 # FIXME: We should add some llvm lit utility code to find the Windows SDK
60 # and set up the environment appopriately.
61 win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
62 arch = 'x64'
Reid Kleckner75d38f12019-05-28 23:03:33 +000063 llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
64 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
65 # the network.
66 llvm_config.with_environment('_NT_SYMBOL_PATH', '')
67 tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
68 arch, 'cdb.exe')))
69
James Henderson4446a722021-02-09 14:57:03 +000070# clang_src_dir and lld_src_dir are not used by these tests, but are required by
71# use_clang() and use_lld() respectively, so set them to "", if needed.
Don Hinton3a58f672017-12-12 16:54:20 +000072if not hasattr(config, 'clang_src_dir'):
73 config.clang_src_dir = ""
James Henderson38276002021-02-09 15:19:27 +000074llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
75
James Henderson4446a722021-02-09 14:57:03 +000076if not hasattr(config, 'lld_src_dir'):
77 config.lld_src_dir = ""
78llvm_config.use_lld(required=('lld' in config.llvm_enabled_projects))
Don Hinton3a58f672017-12-12 16:54:20 +000079
80if config.llvm_use_sanitizer:
81 # Propagate path to symbolizer for ASan/MSan.
82 llvm_config.with_system_environment(
83 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:18 +000084
OCHyams18ee8982021-12-16 13:41:29 +000085# Check which debuggers are available:
86lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
87
88if lldb_path is not None:
89 config.available_features.add('lldb')
90
91def configure_dexter_substitutions():
92 """Configure substitutions for host platform and return list of dependencies
93 """
94 # Produce dexter path, lldb path, and combine into the %dexter substitution
95 # for running a test.
96 dexter_path = os.path.join(config.cross_project_tests_src_root,
97 'debuginfo-tests', 'dexter', 'dexter.py')
98 dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
99 if lldb_path is not None:
100 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
101 tools.append(ToolSubst('%dexter', dexter_test_cmd))
102
103 # For testing other bits of dexter that aren't under the "test" subcommand,
104 # have a %dexter_base substitution.
105 dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
106 tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
107
108 # Set up commands for DexTer regression tests.
109 # Builder, debugger, optimisation level and several other flags differ
110 # depending on whether we're running a unix like or windows os.
111 if platform.system() == 'Windows':
112 # The Windows builder script uses lld.
113 dependencies = ['clang', 'lld-link']
114 dexter_regression_test_builder = '--builder clang-cl_vs2015'
115 dexter_regression_test_debugger = '--debugger dbgeng'
116 dexter_regression_test_cflags = '--cflags "/Zi /Od"'
117 dexter_regression_test_ldflags = '--ldflags "/Zi"'
118 else:
119 # Use lldb as the debugger on non-Windows platforms.
120 dependencies = ['clang', 'lldb']
121 dexter_regression_test_builder = '--builder clang'
122 dexter_regression_test_debugger = "--debugger lldb"
123 dexter_regression_test_cflags = '--cflags "-O0 -glldb"'
124 dexter_regression_test_ldflags = ''
125
126 # Typical command would take the form:
127 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
128 # Exclude build flags for %dexter_regression_base.
129 dexter_regression_test_base = ' '.join(
130 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
131 ['"{}"'.format(sys.executable),
132 '"{}"'.format(dexter_path),
133 'test',
134 '--fail-lt 1.0 -w',
135 dexter_regression_test_debugger])
136 tools.append(ToolSubst('%dexter_regression_base', dexter_regression_test_base))
137
138 # Include build flags for %dexter_regression_test.
139 dexter_regression_test_build = ' '.join([
140 dexter_regression_test_base,
141 dexter_regression_test_builder,
142 dexter_regression_test_cflags,
143 dexter_regression_test_ldflags])
144 tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_build))
145 return dependencies
146
OCHyams52bc1c12021-02-24 11:09:18 +0000147def add_host_triple(clang):
148 return '{} --target={}'.format(clang, config.host_triple)
149
150# The set of arches we can build.
151targets = set(config.targets_to_build)
152# Add aliases to the target set.
153if 'AArch64' in targets:
154 targets.add('arm64')
155if 'ARM' in config.targets_to_build:
156 targets.add('thumbv7')
157
158def can_target_host():
159 # Check if the targets set contains anything that looks like our host arch.
160 # The arch name in the triple and targets set may be spelled differently
161 # (e.g. x86 vs X86).
162 return any(config.host_triple.lower().startswith(x.lower())
163 for x in targets)
164
165# Dexter tests run on the host machine. If the host arch is supported add
166# 'dexter' as an available feature and force the dexter tests to use the host
167# triple.
168if can_target_host():
OCHyams52bc1c12021-02-24 11:09:18 +0000169 if config.host_triple != config.target_triple:
170 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
OCHyams18ee8982021-12-16 13:41:29 +0000171 dependencies = configure_dexter_substitutions()
172 if all(d in config.available_features for d in dependencies):
173 config.available_features.add('dexter')
174 llvm_config.with_environment('PATHTOCLANG',
175 add_host_triple(llvm_config.config.clang))
176 llvm_config.with_environment('PATHTOCLANGPP',
177 add_host_triple(llvm_config.use_llvm_tool('clang++')))
178 llvm_config.with_environment('PATHTOCLANGCL',
179 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
OCHyams52bc1c12021-02-24 11:09:18 +0000180else:
181 print('Host triple {} not supported. Skipping dexter tests in the '
182 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53 +0000183
Don Hinton3a58f672017-12-12 16:54:20 +0000184tool_dirs = [config.llvm_tools_dir]
185
Don Hinton3a58f672017-12-12 16:54:20 +0000186llvm_config.add_tool_substitutions(tools, tool_dirs)
187
188lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000189
190if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000191 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000192 match = re.search('lldb-(\d+)', xcode_lldb_vers)
193 if match:
194 apple_lldb_vers = int(match.group(1))
195 if apple_lldb_vers < 1000:
196 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000197
Christian Sigge9b38842020-09-29 15:19:54 +0200198llvm_config.feature_config(
199 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
200)