Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 1 | import os |
| 2 | import platform |
| 3 | import re |
| 4 | import subprocess |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 5 | import sys |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 6 | |
| 7 | import lit.formats |
| 8 | import lit.util |
| 9 | |
| 10 | from lit.llvm import llvm_config |
| 11 | from lit.llvm.subst import ToolSubst |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 12 | |
| 13 | # Configuration file for the 'lit' test runner. |
| 14 | |
| 15 | # name: The name of this test suite. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 16 | config.name = 'cross-project-tests' |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 17 | |
| 18 | # testFormat: The test format to use to interpret tests. |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 19 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
| 20 | |
| 21 | # suffixes: A list of file extensions to treat as test files. |
| 22 | config.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. |
| 27 | config.excludes = ['Inputs'] |
| 28 | |
| 29 | # test_source_root: The root path where tests are located. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 30 | config.test_source_root = config.cross_project_tests_src_root |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 31 | |
| 32 | # test_exec_root: The root path where tests should be run. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 33 | config.test_exec_root = config.cross_project_tests_obj_root |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 34 | |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 35 | llvm_config.use_default_substitutions() |
| 36 | |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 37 | tools = [ |
| 38 | ToolSubst('%test_debuginfo', command=os.path.join( |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 39 | config.cross_project_tests_src_root, 'debuginfo-tests', |
James Henderson | 1364750 | 2021-02-08 15:40:55 +0000 | [diff] [blame] | 40 | 'llgdb-tests', 'test_debuginfo.pl')), |
Christian Sigg | 60346bd | 2020-01-11 08:47:41 +0100 | [diff] [blame] | 41 | ToolSubst("%llvm_src_root", config.llvm_src_root), |
| 42 | ToolSubst("%llvm_tools_dir", config.llvm_tools_dir), |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 43 | ] |
| 44 | |
| 45 | def 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. |
| 56 | is_msvc = get_required_attr(config, "is_msvc") |
| 57 | if is_msvc: |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 58 | config.available_features.add('msvc') |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 59 | # 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 Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 63 | 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 Henderson | 4446a72 | 2021-02-09 14:57:03 +0000 | [diff] [blame] | 70 | # 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 Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 72 | if not hasattr(config, 'clang_src_dir'): |
| 73 | config.clang_src_dir = "" |
James Henderson | 3827600 | 2021-02-09 15:19:27 +0000 | [diff] [blame^] | 74 | llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects)) |
| 75 | |
James Henderson | 4446a72 | 2021-02-09 14:57:03 +0000 | [diff] [blame] | 76 | if not hasattr(config, 'lld_src_dir'): |
| 77 | config.lld_src_dir = "" |
| 78 | llvm_config.use_lld(required=('lld' in config.llvm_enabled_projects)) |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 79 | |
| 80 | if 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']) |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 84 | |
| 85 | def add_host_triple(clang): |
| 86 | return '{} --target={}'.format(clang, config.host_triple) |
| 87 | |
| 88 | # The set of arches we can build. |
| 89 | targets = set(config.targets_to_build) |
| 90 | # Add aliases to the target set. |
| 91 | if 'AArch64' in targets: |
| 92 | targets.add('arm64') |
| 93 | if 'ARM' in config.targets_to_build: |
| 94 | targets.add('thumbv7') |
| 95 | |
| 96 | def can_target_host(): |
| 97 | # Check if the targets set contains anything that looks like our host arch. |
| 98 | # The arch name in the triple and targets set may be spelled differently |
| 99 | # (e.g. x86 vs X86). |
| 100 | return any(config.host_triple.lower().startswith(x.lower()) |
| 101 | for x in targets) |
| 102 | |
| 103 | # Dexter tests run on the host machine. If the host arch is supported add |
| 104 | # 'dexter' as an available feature and force the dexter tests to use the host |
| 105 | # triple. |
| 106 | if can_target_host(): |
| 107 | config.available_features.add('dexter') |
| 108 | if config.host_triple != config.target_triple: |
| 109 | print('Forcing dexter tests to use host triple {}.'.format(config.host_triple)) |
| 110 | llvm_config.with_environment('PATHTOCLANG', |
| 111 | add_host_triple(llvm_config.config.clang)) |
| 112 | llvm_config.with_environment('PATHTOCLANGPP', |
| 113 | add_host_triple(llvm_config.use_llvm_tool('clang++'))) |
| 114 | llvm_config.with_environment('PATHTOCLANGCL', |
| 115 | add_host_triple(llvm_config.use_llvm_tool('clang-cl'))) |
| 116 | else: |
| 117 | print('Host triple {} not supported. Skipping dexter tests in the ' |
| 118 | 'debuginfo-tests project.'.format(config.host_triple)) |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 119 | |
| 120 | # Check which debuggers are available: |
James Henderson | 5c4a5da | 2021-05-18 10:57:32 +0100 | [diff] [blame] | 121 | lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB') |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 122 | |
| 123 | if lldb_path is not None: |
| 124 | config.available_features.add('lldb') |
| 125 | |
| 126 | # Produce dexter path, lldb path, and combine into the %dexter substitution |
Jeremy Morse | 7f738c8 | 2019-11-01 12:29:42 +0000 | [diff] [blame] | 127 | # for running a test. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 128 | dexter_path = os.path.join(config.cross_project_tests_src_root, |
James Henderson | 1364750 | 2021-02-08 15:40:55 +0000 | [diff] [blame] | 129 | 'debuginfo-tests', 'dexter', 'dexter.py') |
James Henderson | 6c330f0 | 2021-02-08 15:46:40 +0000 | [diff] [blame] | 130 | dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path) |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 131 | if lldb_path is not None: |
Jeremy Morse | 5ee4a03 | 2020-02-13 14:24:33 +0000 | [diff] [blame] | 132 | dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path) |
Jeremy Morse | 7f738c8 | 2019-11-01 12:29:42 +0000 | [diff] [blame] | 133 | tools.append(ToolSubst('%dexter', dexter_test_cmd)) |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 134 | |
Jeremy Morse | 7f738c8 | 2019-11-01 12:29:42 +0000 | [diff] [blame] | 135 | # For testing other bits of dexter that aren't under the "test" subcommand, |
| 136 | # have a %dexter_base substitution. |
James Henderson | 6c330f0 | 2021-02-08 15:46:40 +0000 | [diff] [blame] | 137 | dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path) |
Jeremy Morse | 7f738c8 | 2019-11-01 12:29:42 +0000 | [diff] [blame] | 138 | tools.append(ToolSubst('%dexter_base', dexter_base_cmd)) |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 139 | |
Tom Weaver | b6d2212 | 2020-03-31 10:18:12 +0100 | [diff] [blame] | 140 | # Set up commands for DexTer regression tests. |
| 141 | # Builder, debugger, optimisation level and several other flags differ |
| 142 | # depending on whether we're running a unix like or windows os. |
| 143 | if platform.system() == 'Windows': |
| 144 | dexter_regression_test_builder = '--builder clang-cl_vs2015' |
| 145 | dexter_regression_test_debugger = '--debugger dbgeng' |
| 146 | dexter_regression_test_cflags = '--cflags "/Zi /Od"' |
| 147 | dexter_regression_test_ldflags = '--ldflags "/Zi"' |
| 148 | else: |
| 149 | dexter_regression_test_builder = '--builder clang' |
| 150 | dexter_regression_test_debugger = "--debugger lldb" |
| 151 | dexter_regression_test_cflags = '--cflags "-O0 -glldb"' |
| 152 | dexter_regression_test_ldflags = '' |
| 153 | |
| 154 | # Typical command would take the form: |
| 155 | # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g' |
| 156 | dexter_regression_test_command = ' '.join( |
James Henderson | 6c330f0 | 2021-02-08 15:46:40 +0000 | [diff] [blame] | 157 | # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags |
| 158 | ['"{}"'.format(sys.executable), |
James Henderson | a31eae8 | 2021-02-10 15:14:32 +0000 | [diff] [blame] | 159 | '"{}"'.format(dexter_path), |
Tom Weaver | b6d2212 | 2020-03-31 10:18:12 +0100 | [diff] [blame] | 160 | 'test', |
| 161 | '--fail-lt 1.0 -w', |
| 162 | dexter_regression_test_builder, |
| 163 | dexter_regression_test_debugger, |
| 164 | dexter_regression_test_cflags, |
| 165 | dexter_regression_test_ldflags]) |
| 166 | |
| 167 | tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_command)) |
| 168 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 169 | tool_dirs = [config.llvm_tools_dir] |
| 170 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 171 | llvm_config.add_tool_substitutions(tools, tool_dirs) |
| 172 | |
| 173 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 174 | |
| 175 | if platform.system() == 'Darwin': |
Jonas Devlieghere | 635eb80 | 2019-06-25 15:58:32 +0000 | [diff] [blame] | 176 | xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8") |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 177 | match = re.search('lldb-(\d+)', xcode_lldb_vers) |
| 178 | if match: |
| 179 | apple_lldb_vers = int(match.group(1)) |
| 180 | if apple_lldb_vers < 1000: |
| 181 | config.available_features.add('apple-lldb-pre-1000') |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 182 | |
Christian Sigg | e9b3884 | 2020-09-29 15:19:54 +0200 | [diff] [blame] | 183 | llvm_config.feature_config( |
| 184 | [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})] |
| 185 | ) |