blob: aefe0303b764a0750ae8de4c3d62be31bdc3fed2 [file] [log] [blame]
Don Hinton3a58f672017-12-12 16:54:20 +00001# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
Jeremy Morse984fad22019-10-31 16:51:53 +00007import sys
Don Hinton3a58f672017-12-12 16:54:20 +00008
9import lit.formats
10import lit.util
11
12from lit.llvm import llvm_config
13from lit.llvm.subst import ToolSubst
Don Hinton3a58f672017-12-12 16:54:20 +000014
15# Configuration file for the 'lit' test runner.
16
17# name: The name of this test suite.
18config.name = 'debuginfo-tests'
19
20# testFormat: The test format to use to interpret tests.
21#
22# For now we require '&&' between commands, until they get globally killed and
23# the test runner updated.
24config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
25
26# suffixes: A list of file extensions to treat as test files.
27config.suffixes = ['.c', '.cpp', '.m']
28
29# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
30# subdirectories contain auxiliary inputs for various tests in their parent
31# directories.
32config.excludes = ['Inputs']
33
34# test_source_root: The root path where tests are located.
James Henderson13647502021-02-08 15:40:55 +000035config.test_source_root = config.debuginfo_tests_src_root
Don Hinton3a58f672017-12-12 16:54:20 +000036
37# test_exec_root: The root path where tests should be run.
38config.test_exec_root = config.debuginfo_tests_obj_root
39
Jeremy Morse984fad22019-10-31 16:51:53 +000040llvm_config.use_default_substitutions()
41
Reid Kleckner75d38f12019-05-28 23:03:33 +000042tools = [
43 ToolSubst('%test_debuginfo', command=os.path.join(
James Henderson13647502021-02-08 15:40:55 +000044 config.debuginfo_tests_src_root, 'debuginfo-tests',
45 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 08:47:41 +010046 ToolSubst("%llvm_src_root", config.llvm_src_root),
47 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:33 +000048]
49
50def get_required_attr(config, attr_name):
51 attr_value = getattr(config, attr_name, None)
52 if attr_value == None:
53 lit_config.fatal(
54 "No attribute %r in test configuration! You may need to run "
55 "tests from your build directory or add this attribute "
56 "to lit.site.cfg " % attr_name)
57 return attr_value
58
59# If this is an MSVC environment, the tests at the root of the tree are
60# unsupported. The local win_cdb test suite, however, is supported.
61is_msvc = get_required_attr(config, "is_msvc")
62if is_msvc:
Jeremy Morse984fad22019-10-31 16:51:53 +000063 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:33 +000064 # FIXME: We should add some llvm lit utility code to find the Windows SDK
65 # and set up the environment appopriately.
66 win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
67 arch = 'x64'
Reid Kleckner75d38f12019-05-28 23:03:33 +000068 llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
69 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
70 # the network.
71 llvm_config.with_environment('_NT_SYMBOL_PATH', '')
72 tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
73 arch, 'cdb.exe')))
74
Don Hinton3a58f672017-12-12 16:54:20 +000075# clang_src_dir is not used by these tests, but is required by
76# use_clang(), so set it to "".
77if not hasattr(config, 'clang_src_dir'):
78 config.clang_src_dir = ""
79llvm_config.use_clang()
80
81if config.llvm_use_sanitizer:
82 # Propagate path to symbolizer for ASan/MSan.
83 llvm_config.with_system_environment(
84 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:18 +000085
86def add_host_triple(clang):
87 return '{} --target={}'.format(clang, config.host_triple)
88
89# The set of arches we can build.
90targets = set(config.targets_to_build)
91# Add aliases to the target set.
92if 'AArch64' in targets:
93 targets.add('arm64')
94if 'ARM' in config.targets_to_build:
95 targets.add('thumbv7')
96
97def can_target_host():
98 # Check if the targets set contains anything that looks like our host arch.
99 # The arch name in the triple and targets set may be spelled differently
100 # (e.g. x86 vs X86).
101 return any(config.host_triple.lower().startswith(x.lower())
102 for x in targets)
103
104# Dexter tests run on the host machine. If the host arch is supported add
105# 'dexter' as an available feature and force the dexter tests to use the host
106# triple.
107if can_target_host():
108 config.available_features.add('dexter')
109 if config.host_triple != config.target_triple:
110 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
111 llvm_config.with_environment('PATHTOCLANG',
112 add_host_triple(llvm_config.config.clang))
113 llvm_config.with_environment('PATHTOCLANGPP',
114 add_host_triple(llvm_config.use_llvm_tool('clang++')))
115 llvm_config.with_environment('PATHTOCLANGCL',
116 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
117else:
118 print('Host triple {} not supported. Skipping dexter tests in the '
119 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53 +0000120
121# Check which debuggers are available:
James Henderson5c4a5da2021-05-18 10:57:32 +0100122lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
Jeremy Morse984fad22019-10-31 16:51:53 +0000123
124if lldb_path is not None:
125 config.available_features.add('lldb')
126
127# Produce dexter path, lldb path, and combine into the %dexter substitution
Jeremy Morse7f738c82019-11-01 12:29:42 +0000128# for running a test.
Jeremy Morse984fad22019-10-31 16:51:53 +0000129dexter_path = os.path.join(config.debuginfo_tests_src_root,
James Henderson13647502021-02-08 15:40:55 +0000130 'debuginfo-tests', 'dexter', 'dexter.py')
James Henderson6c330f02021-02-08 15:46:40 +0000131dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
Jeremy Morse984fad22019-10-31 16:51:53 +0000132if lldb_path is not None:
Jeremy Morse5ee4a032020-02-13 14:24:33 +0000133 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
Jeremy Morse7f738c82019-11-01 12:29:42 +0000134tools.append(ToolSubst('%dexter', dexter_test_cmd))
Jeremy Morse984fad22019-10-31 16:51:53 +0000135
Jeremy Morse7f738c82019-11-01 12:29:42 +0000136# For testing other bits of dexter that aren't under the "test" subcommand,
137# have a %dexter_base substitution.
James Henderson6c330f02021-02-08 15:46:40 +0000138dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
Jeremy Morse7f738c82019-11-01 12:29:42 +0000139tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
Don Hinton3a58f672017-12-12 16:54:20 +0000140
Tom Weaverb6d22122020-03-31 10:18:12 +0100141# Set up commands for DexTer regression tests.
142# Builder, debugger, optimisation level and several other flags differ
143# depending on whether we're running a unix like or windows os.
144if platform.system() == 'Windows':
145 dexter_regression_test_builder = '--builder clang-cl_vs2015'
146 dexter_regression_test_debugger = '--debugger dbgeng'
147 dexter_regression_test_cflags = '--cflags "/Zi /Od"'
148 dexter_regression_test_ldflags = '--ldflags "/Zi"'
149else:
150 dexter_regression_test_builder = '--builder clang'
151 dexter_regression_test_debugger = "--debugger lldb"
152 dexter_regression_test_cflags = '--cflags "-O0 -glldb"'
153 dexter_regression_test_ldflags = ''
154
155# Typical command would take the form:
156# ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
157dexter_regression_test_command = ' '.join(
James Henderson6c330f02021-02-08 15:46:40 +0000158 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
159 ['"{}"'.format(sys.executable),
James Hendersona31eae82021-02-10 15:14:32 +0000160 '"{}"'.format(dexter_path),
Tom Weaverb6d22122020-03-31 10:18:12 +0100161 'test',
162 '--fail-lt 1.0 -w',
163 dexter_regression_test_builder,
164 dexter_regression_test_debugger,
165 dexter_regression_test_cflags,
166 dexter_regression_test_ldflags])
167
168tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_command))
169
Don Hinton3a58f672017-12-12 16:54:20 +0000170tool_dirs = [config.llvm_tools_dir]
171
Don Hinton3a58f672017-12-12 16:54:20 +0000172llvm_config.add_tool_substitutions(tools, tool_dirs)
173
174lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000175
Jeremy Morse984fad22019-10-31 16:51:53 +0000176# available_features: REQUIRES/UNSUPPORTED lit commands look at this list.
Vedant Kumarefab30c2018-08-04 00:02:48 +0000177if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000178 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000179 match = re.search('lldb-(\d+)', xcode_lldb_vers)
180 if match:
181 apple_lldb_vers = int(match.group(1))
182 if apple_lldb_vers < 1000:
183 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000184
Christian Sigge9b38842020-09-29 15:19:54 +0200185llvm_config.feature_config(
186 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
187)