blob: 0e436506a96bd8f17f25d3f2383474feba84475d [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 +00008import tempfile
9
10import lit.formats
11import lit.util
12
13from lit.llvm import llvm_config
14from lit.llvm.subst import ToolSubst
15from lit.llvm.subst import FindTool
16
17# Configuration file for the 'lit' test runner.
18
19# name: The name of this test suite.
20config.name = 'debuginfo-tests'
21
22# testFormat: The test format to use to interpret tests.
23#
24# For now we require '&&' between commands, until they get globally killed and
25# the test runner updated.
26config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
27
28# suffixes: A list of file extensions to treat as test files.
29config.suffixes = ['.c', '.cpp', '.m']
30
31# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
32# subdirectories contain auxiliary inputs for various tests in their parent
33# directories.
34config.excludes = ['Inputs']
35
36# test_source_root: The root path where tests are located.
37config.test_source_root = os.path.join(config.debuginfo_tests_src_root)
38
39# test_exec_root: The root path where tests should be run.
40config.test_exec_root = config.debuginfo_tests_obj_root
41
Jeremy Morse984fad22019-10-31 16:51:53 +000042llvm_config.use_default_substitutions()
43
Reid Kleckner75d38f12019-05-28 23:03:33 +000044tools = [
45 ToolSubst('%test_debuginfo', command=os.path.join(
Jeremy Morse984fad22019-10-31 16:51:53 +000046 config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 08:47:41 +010047 ToolSubst("%llvm_src_root", config.llvm_src_root),
48 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:33 +000049]
50
51def get_required_attr(config, attr_name):
52 attr_value = getattr(config, attr_name, None)
53 if attr_value == None:
54 lit_config.fatal(
55 "No attribute %r in test configuration! You may need to run "
56 "tests from your build directory or add this attribute "
57 "to lit.site.cfg " % attr_name)
58 return attr_value
59
60# If this is an MSVC environment, the tests at the root of the tree are
61# unsupported. The local win_cdb test suite, however, is supported.
62is_msvc = get_required_attr(config, "is_msvc")
63if is_msvc:
Jeremy Morse984fad22019-10-31 16:51:53 +000064 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:33 +000065 # FIXME: We should add some llvm lit utility code to find the Windows SDK
66 # and set up the environment appopriately.
67 win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
68 arch = 'x64'
Reid Kleckner75d38f12019-05-28 23:03:33 +000069 llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
70 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
71 # the network.
72 llvm_config.with_environment('_NT_SYMBOL_PATH', '')
73 tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
74 arch, 'cdb.exe')))
75
Don Hinton3a58f672017-12-12 16:54:20 +000076# clang_src_dir is not used by these tests, but is required by
77# use_clang(), so set it to "".
78if not hasattr(config, 'clang_src_dir'):
79 config.clang_src_dir = ""
80llvm_config.use_clang()
81
82if config.llvm_use_sanitizer:
83 # Propagate path to symbolizer for ASan/MSan.
84 llvm_config.with_system_environment(
85 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
Jeremy Morse984fad22019-10-31 16:51:53 +000086llvm_config.with_environment('PATHTOCLANG', llvm_config.config.clang)
87llvm_config.with_environment('PATHTOCLANGPP', llvm_config.use_llvm_tool('clang++'))
88llvm_config.with_environment('PATHTOCLANGCL', llvm_config.use_llvm_tool('clang-cl'))
89
90# Check which debuggers are available:
91built_lldb = llvm_config.use_llvm_tool('lldb', search_env='CLANG')
Reid Kleckner7ac4c312019-10-31 15:18:54 -070092lldb_path = None
Jeremy Morse984fad22019-10-31 16:51:53 +000093if built_lldb is not None:
94 lldb_path = built_lldb
95elif lit.util.which('lldb') is not None:
96 lldb_path = lit.util.which('lldb')
97
98if lldb_path is not None:
99 config.available_features.add('lldb')
100
101# Produce dexter path, lldb path, and combine into the %dexter substitution
Jeremy Morse7f738c82019-11-01 12:29:42 +0000102# for running a test.
Jeremy Morse984fad22019-10-31 16:51:53 +0000103dexter_path = os.path.join(config.debuginfo_tests_src_root,
104 'dexter', 'dexter.py')
Jeremy Morse7f738c82019-11-01 12:29:42 +0000105dexter_test_cmd = '"{}" "{}" test'.format(config.python3_executable, dexter_path)
Jeremy Morse984fad22019-10-31 16:51:53 +0000106if lldb_path is not None:
Jeremy Morse5ee4a032020-02-13 14:24:33 +0000107 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
Jeremy Morse7f738c82019-11-01 12:29:42 +0000108tools.append(ToolSubst('%dexter', dexter_test_cmd))
Jeremy Morse984fad22019-10-31 16:51:53 +0000109
Jeremy Morse7f738c82019-11-01 12:29:42 +0000110# For testing other bits of dexter that aren't under the "test" subcommand,
111# have a %dexter_base substitution.
112dexter_base_cmd = '"{}" "{}"'.format(config.python3_executable, dexter_path)
113tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
Don Hinton3a58f672017-12-12 16:54:20 +0000114
Tom Weaverb6d22122020-03-31 10:18:12 +0100115# Set up commands for DexTer regression tests.
116# Builder, debugger, optimisation level and several other flags differ
117# depending on whether we're running a unix like or windows os.
118if platform.system() == 'Windows':
119 dexter_regression_test_builder = '--builder clang-cl_vs2015'
120 dexter_regression_test_debugger = '--debugger dbgeng'
121 dexter_regression_test_cflags = '--cflags "/Zi /Od"'
122 dexter_regression_test_ldflags = '--ldflags "/Zi"'
123else:
124 dexter_regression_test_builder = '--builder clang'
125 dexter_regression_test_debugger = "--debugger lldb"
126 dexter_regression_test_cflags = '--cflags "-O0 -glldb"'
127 dexter_regression_test_ldflags = ''
128
129# Typical command would take the form:
130# ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
131dexter_regression_test_command = ' '.join(
132 # "python3", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
133 ["{}".format(config.python3_executable),
134 "{}".format(dexter_path),
135 'test',
136 '--fail-lt 1.0 -w',
137 dexter_regression_test_builder,
138 dexter_regression_test_debugger,
139 dexter_regression_test_cflags,
140 dexter_regression_test_ldflags])
141
142tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_command))
143
Don Hinton3a58f672017-12-12 16:54:20 +0000144tool_dirs = [config.llvm_tools_dir]
145
Don Hinton3a58f672017-12-12 16:54:20 +0000146llvm_config.add_tool_substitutions(tools, tool_dirs)
147
148lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000149
Jeremy Morse984fad22019-10-31 16:51:53 +0000150# available_features: REQUIRES/UNSUPPORTED lit commands look at this list.
Vedant Kumarefab30c2018-08-04 00:02:48 +0000151if platform.system() == 'Darwin':
Fangrui Song93deae22018-11-03 04:52:32 +0000152 import subprocess
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000153 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000154 match = re.search('lldb-(\d+)', xcode_lldb_vers)
155 if match:
156 apple_lldb_vers = int(match.group(1))
157 if apple_lldb_vers < 1000:
158 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000159
Christian Sigge9b38842020-09-29 15:19:54 +0200160llvm_config.feature_config(
161 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
162)