blob: 9cab3fc6a14c4c64c6c29b964b4cb228c63d42d5 [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
Don Hinton3a58f672017-12-12 16:54:20 +000070# clang_src_dir is not used by these tests, but is required by
71# use_clang(), so set it to "".
72if not hasattr(config, 'clang_src_dir'):
73 config.clang_src_dir = ""
74llvm_config.use_clang()
75
76if config.llvm_use_sanitizer:
77 # Propagate path to symbolizer for ASan/MSan.
78 llvm_config.with_system_environment(
79 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:18 +000080
81def add_host_triple(clang):
82 return '{} --target={}'.format(clang, config.host_triple)
83
84# The set of arches we can build.
85targets = set(config.targets_to_build)
86# Add aliases to the target set.
87if 'AArch64' in targets:
88 targets.add('arm64')
89if 'ARM' in config.targets_to_build:
90 targets.add('thumbv7')
91
92def can_target_host():
93 # Check if the targets set contains anything that looks like our host arch.
94 # The arch name in the triple and targets set may be spelled differently
95 # (e.g. x86 vs X86).
96 return any(config.host_triple.lower().startswith(x.lower())
97 for x in targets)
98
99# Dexter tests run on the host machine. If the host arch is supported add
100# 'dexter' as an available feature and force the dexter tests to use the host
101# triple.
102if can_target_host():
103 config.available_features.add('dexter')
104 if config.host_triple != config.target_triple:
105 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
106 llvm_config.with_environment('PATHTOCLANG',
107 add_host_triple(llvm_config.config.clang))
108 llvm_config.with_environment('PATHTOCLANGPP',
109 add_host_triple(llvm_config.use_llvm_tool('clang++')))
110 llvm_config.with_environment('PATHTOCLANGCL',
111 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
112else:
113 print('Host triple {} not supported. Skipping dexter tests in the '
114 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53 +0000115
116# Check which debuggers are available:
James Henderson5c4a5da2021-05-18 10:57:32 +0100117lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
Jeremy Morse984fad22019-10-31 16:51:53 +0000118
119if lldb_path is not None:
120 config.available_features.add('lldb')
121
122# Produce dexter path, lldb path, and combine into the %dexter substitution
Jeremy Morse7f738c82019-11-01 12:29:42 +0000123# for running a test.
James Henderson24af0992021-02-11 15:41:32 +0000124dexter_path = os.path.join(config.cross_project_tests_src_root,
James Henderson13647502021-02-08 15:40:55 +0000125 'debuginfo-tests', 'dexter', 'dexter.py')
James Henderson6c330f02021-02-08 15:46:40 +0000126dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
Jeremy Morse984fad22019-10-31 16:51:53 +0000127if lldb_path is not None:
Jeremy Morse5ee4a032020-02-13 14:24:33 +0000128 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
Jeremy Morse7f738c82019-11-01 12:29:42 +0000129tools.append(ToolSubst('%dexter', dexter_test_cmd))
Jeremy Morse984fad22019-10-31 16:51:53 +0000130
Jeremy Morse7f738c82019-11-01 12:29:42 +0000131# For testing other bits of dexter that aren't under the "test" subcommand,
132# have a %dexter_base substitution.
James Henderson6c330f02021-02-08 15:46:40 +0000133dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
Jeremy Morse7f738c82019-11-01 12:29:42 +0000134tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
Don Hinton3a58f672017-12-12 16:54:20 +0000135
Tom Weaverb6d22122020-03-31 10:18:12 +0100136# Set up commands for DexTer regression tests.
137# Builder, debugger, optimisation level and several other flags differ
138# depending on whether we're running a unix like or windows os.
139if platform.system() == 'Windows':
140 dexter_regression_test_builder = '--builder clang-cl_vs2015'
141 dexter_regression_test_debugger = '--debugger dbgeng'
142 dexter_regression_test_cflags = '--cflags "/Zi /Od"'
143 dexter_regression_test_ldflags = '--ldflags "/Zi"'
144else:
145 dexter_regression_test_builder = '--builder clang'
146 dexter_regression_test_debugger = "--debugger lldb"
147 dexter_regression_test_cflags = '--cflags "-O0 -glldb"'
148 dexter_regression_test_ldflags = ''
149
150# Typical command would take the form:
151# ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
152dexter_regression_test_command = ' '.join(
James Henderson6c330f02021-02-08 15:46:40 +0000153 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
154 ['"{}"'.format(sys.executable),
James Hendersona31eae82021-02-10 15:14:32 +0000155 '"{}"'.format(dexter_path),
Tom Weaverb6d22122020-03-31 10:18:12 +0100156 'test',
157 '--fail-lt 1.0 -w',
158 dexter_regression_test_builder,
159 dexter_regression_test_debugger,
160 dexter_regression_test_cflags,
161 dexter_regression_test_ldflags])
162
163tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_command))
164
Don Hinton3a58f672017-12-12 16:54:20 +0000165tool_dirs = [config.llvm_tools_dir]
166
Don Hinton3a58f672017-12-12 16:54:20 +0000167llvm_config.add_tool_substitutions(tools, tool_dirs)
168
169lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000170
171if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000172 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000173 match = re.search('lldb-(\d+)', xcode_lldb_vers)
174 if match:
175 apple_lldb_vers = int(match.group(1))
176 if apple_lldb_vers < 1000:
177 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000178
Christian Sigge9b38842020-09-29 15:19:54 +0200179llvm_config.feature_config(
180 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
181)