Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
| 6 | import subprocess |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 7 | import sys |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 8 | import tempfile |
| 9 | |
| 10 | import lit.formats |
| 11 | import lit.util |
| 12 | |
| 13 | from lit.llvm import llvm_config |
| 14 | from lit.llvm.subst import ToolSubst |
| 15 | from lit.llvm.subst import FindTool |
| 16 | |
| 17 | # Configuration file for the 'lit' test runner. |
| 18 | |
| 19 | # name: The name of this test suite. |
| 20 | config.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. |
| 26 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
| 27 | |
| 28 | # suffixes: A list of file extensions to treat as test files. |
| 29 | config.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. |
| 34 | config.excludes = ['Inputs'] |
| 35 | |
| 36 | # test_source_root: The root path where tests are located. |
| 37 | config.test_source_root = os.path.join(config.debuginfo_tests_src_root) |
| 38 | |
| 39 | # test_exec_root: The root path where tests should be run. |
| 40 | config.test_exec_root = config.debuginfo_tests_obj_root |
| 41 | |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 42 | llvm_config.use_default_substitutions() |
| 43 | |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 44 | tools = [ |
| 45 | ToolSubst('%test_debuginfo', command=os.path.join( |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 46 | config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')), |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 47 | ] |
| 48 | |
| 49 | def get_required_attr(config, attr_name): |
| 50 | attr_value = getattr(config, attr_name, None) |
| 51 | if attr_value == None: |
| 52 | lit_config.fatal( |
| 53 | "No attribute %r in test configuration! You may need to run " |
| 54 | "tests from your build directory or add this attribute " |
| 55 | "to lit.site.cfg " % attr_name) |
| 56 | return attr_value |
| 57 | |
| 58 | # If this is an MSVC environment, the tests at the root of the tree are |
| 59 | # unsupported. The local win_cdb test suite, however, is supported. |
| 60 | is_msvc = get_required_attr(config, "is_msvc") |
| 61 | if is_msvc: |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 62 | config.available_features.add('msvc') |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 63 | # FIXME: We should add some llvm lit utility code to find the Windows SDK |
| 64 | # and set up the environment appopriately. |
| 65 | win_sdk = 'C:/Program Files (x86)/Windows Kits/10/' |
| 66 | arch = 'x64' |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 67 | llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE']) |
| 68 | # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from |
| 69 | # the network. |
| 70 | llvm_config.with_environment('_NT_SYMBOL_PATH', '') |
| 71 | tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers', |
| 72 | arch, 'cdb.exe'))) |
| 73 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 74 | # clang_src_dir is not used by these tests, but is required by |
| 75 | # use_clang(), so set it to "". |
| 76 | if not hasattr(config, 'clang_src_dir'): |
| 77 | config.clang_src_dir = "" |
| 78 | llvm_config.use_clang() |
| 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']) |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 84 | llvm_config.with_environment('PATHTOCLANG', llvm_config.config.clang) |
| 85 | llvm_config.with_environment('PATHTOCLANGPP', llvm_config.use_llvm_tool('clang++')) |
| 86 | llvm_config.with_environment('PATHTOCLANGCL', llvm_config.use_llvm_tool('clang-cl')) |
| 87 | |
| 88 | # Check which debuggers are available: |
| 89 | built_lldb = llvm_config.use_llvm_tool('lldb', search_env='CLANG') |
| 90 | if built_lldb is not None: |
| 91 | lldb_path = built_lldb |
| 92 | elif lit.util.which('lldb') is not None: |
| 93 | lldb_path = lit.util.which('lldb') |
| 94 | |
| 95 | if lldb_path is not None: |
| 96 | config.available_features.add('lldb') |
| 97 | |
| 98 | # Produce dexter path, lldb path, and combine into the %dexter substitution |
| 99 | dexter_path = os.path.join(config.debuginfo_tests_src_root, |
| 100 | 'dexter', 'dexter.py') |
| 101 | dexter_cmd = '{} {} test'.format(config.python3_executable, dexter_path) |
| 102 | if lldb_path is not None: |
| 103 | dexter_cmd += ' --lldb-executable {}'.format(lldb_path) |
| 104 | |
| 105 | tools.append(ToolSubst('%dexter', dexter_cmd)) |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 106 | |
| 107 | tool_dirs = [config.llvm_tools_dir] |
| 108 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 109 | llvm_config.add_tool_substitutions(tools, tool_dirs) |
| 110 | |
| 111 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 112 | |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 113 | # available_features: REQUIRES/UNSUPPORTED lit commands look at this list. |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 114 | if platform.system() == 'Darwin': |
Fangrui Song | 93deae2 | 2018-11-03 04:52:32 +0000 | [diff] [blame] | 115 | import subprocess |
Jonas Devlieghere | 635eb80 | 2019-06-25 15:58:32 +0000 | [diff] [blame] | 116 | xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8") |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 117 | match = re.search('lldb-(\d+)', xcode_lldb_vers) |
| 118 | if match: |
| 119 | apple_lldb_vers = int(match.group(1)) |
| 120 | if apple_lldb_vers < 1000: |
| 121 | config.available_features.add('apple-lldb-pre-1000') |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 122 | |