Daniel Dunbar | 3667b99 | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 3 | import os |
Daniel Dunbar | 79327b6 | 2009-09-22 10:08:03 +0000 | [diff] [blame] | 4 | import platform |
Chandler Carruth | 2837f66 | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 5 | import re |
| 6 | import subprocess |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 7 | import tempfile |
Chandler Carruth | 2837f66 | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 8 | |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Daniel Dunbar | be4253a | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 11 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 12 | from lit.llvm import llvm_config |
Zachary Turner | 96b04b6 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 13 | from lit.llvm.subst import ToolSubst |
| 14 | from lit.llvm.subst import FindTool |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 15 | |
Daniel Dunbar | 3667b99 | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 16 | # Configuration file for the 'lit' test runner. |
| 17 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 18 | # name: The name of this test suite. |
| 19 | config.name = 'Clang' |
Daniel Dunbar | be4253a | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 20 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 21 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 3667b99 | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 22 | # |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 23 | # For now we require '&&' between commands, until they get globally killed and |
| 24 | # the test runner updated. |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 25 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
Daniel Dunbar | f87be55 | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 26 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 27 | # suffixes: A list of file extensions to treat as test files. |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 28 | config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu', |
Puyan Lotfi | c382d03 | 2019-10-08 15:23:14 +0000 | [diff] [blame] | 29 | '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs'] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 30 | |
Alp Toker | 9c5ae47 | 2013-11-15 13:37:49 +0000 | [diff] [blame] | 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. |
Don Hinton | d15d76e | 2017-12-14 22:12:46 +0000 | [diff] [blame] | 34 | config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests'] |
Alp Toker | 9c5ae47 | 2013-11-15 13:37:49 +0000 | [diff] [blame] | 35 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 36 | # test_source_root: The root path where tests are located. |
| 37 | config.test_source_root = os.path.dirname(__file__) |
| 38 | |
| 39 | # test_exec_root: The root path where tests should be run. |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 40 | config.test_exec_root = os.path.join(config.clang_obj_root, 'test') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 41 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 42 | llvm_config.use_default_substitutions() |
Jordy Rose | 0e09fac | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 43 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 44 | llvm_config.use_clang() |
Daniel Dunbar | a87097a | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 45 | |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 46 | config.substitutions.append( |
| 47 | ('%src_include_dir', config.clang_src_dir + '/include')) |
| 48 | |
| 49 | |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 50 | # Propagate path to symbolizer for ASan/MSan. |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 51 | llvm_config.with_system_environment( |
| 52 | ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 53 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 54 | config.substitutions.append(('%PATH%', config.environment['PATH'])) |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 55 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 56 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 57 | # For each occurrence of a clang tool name, replace it with the full path to |
| 58 | # the build directory holding that tool. We explicitly specify the directories |
| 59 | # to search to ensure that we get the tools just built and not some random |
| 60 | # tools that might happen to be in the user's PATH. |
| 61 | tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 62 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 63 | tools = [ |
Puyan Lotfi | c382d03 | 2019-10-08 15:23:14 +0000 | [diff] [blame] | 64 | 'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs', |
Rafael Stahl | 8c48705 | 2019-01-10 17:44:04 +0000 | [diff] [blame] | 65 | ToolSubst('%clang_extdef_map', command=FindTool( |
| 66 | 'clang-extdef-mapping'), unresolved='ignore'), |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 67 | ] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 68 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 69 | if config.clang_examples: |
Zachary Turner | b719d1b | 2018-05-08 18:20:10 +0000 | [diff] [blame] | 70 | config.available_features.add('examples') |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 71 | tools.append('clang-interpreter') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 72 | |
Nico Weber | 55ef9a1 | 2019-05-02 19:47:05 +0000 | [diff] [blame] | 73 | if config.clang_staticanalyzer: |
| 74 | config.available_features.add('staticanalyzer') |
| 75 | tools.append('clang-check') |
| 76 | |
| 77 | if config.clang_staticanalyzer_z3 == '1': |
| 78 | config.available_features.add('z3') |
| 79 | |
| 80 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 81 | llvm_config.add_tool_substitutions(tools, tool_dirs) |
Chandler Carruth | c0b1b86 | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 82 | |
Benjamin Kramer | 9b10b69 | 2018-06-22 09:46:40 +0000 | [diff] [blame] | 83 | config.substitutions.append( |
Benjamin Kramer | 9508af3 | 2018-06-22 20:03:32 +0000 | [diff] [blame] | 84 | ('%hmaptool', "'%s' %s" % (config.python_executable, |
Michal Gorny | 624169f | 2018-08-01 20:38:22 +0000 | [diff] [blame] | 85 | os.path.join(config.clang_tools_dir, 'hmaptool')))) |
Benjamin Kramer | 9b10b69 | 2018-06-22 09:46:40 +0000 | [diff] [blame] | 86 | |
Alp Toker | 120dd1af | 2014-01-08 11:38:47 +0000 | [diff] [blame] | 87 | # Plugins (loadable modules) |
Petr Hosek | b7804ef | 2019-05-17 06:07:37 +0000 | [diff] [blame] | 88 | if config.has_plugins and config.llvm_plugin_ext: |
Alp Toker | 120dd1af | 2014-01-08 11:38:47 +0000 | [diff] [blame] | 89 | config.available_features.add('plugins') |
| 90 | |
Daniel Dunbar | b44eb0b | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 91 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 92 | # |
Jonas Hahnfeld | fdaaca8 | 2016-09-29 07:43:08 +0000 | [diff] [blame] | 93 | if config.clang_default_cxx_stdlib != '': |
| 94 | config.available_features.add('default-cxx-stdlib-set') |
| 95 | |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 96 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 97 | if platform.system() not in ['FreeBSD']: |
| 98 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | f5ea88b | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 99 | |
Leonard Chan | e6d2c8d | 2019-06-19 17:41:30 +0000 | [diff] [blame] | 100 | # Support for new pass manager. |
| 101 | if config.enable_experimental_new_pass_manager: |
| 102 | config.available_features.add('experimental-new-pass-manager') |
| 103 | |
NAKAMURA Takumi | 6bbc981 | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 104 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | b59973e | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 105 | if platform.system() not in ['Windows']: |
| 106 | config.available_features.add('ansi-escape-sequences') |
| 107 | |
NAKAMURA Takumi | 0c81c71 | 2014-02-06 07:15:59 +0000 | [diff] [blame] | 108 | # Capability to print utf8 to the terminal. |
| 109 | # Windows expects codepage, unless Wide API. |
| 110 | if platform.system() not in ['Windows']: |
| 111 | config.available_features.add('utf8-capable-terminal') |
| 112 | |
Michal Gorny | 7cfe480 | 2016-10-10 12:23:40 +0000 | [diff] [blame] | 113 | # Support for libgcc runtime. Used to rule out tests that require |
| 114 | # clang to run with -rtlib=libgcc. |
| 115 | if platform.system() not in ['Darwin', 'Fuchsia']: |
| 116 | config.available_features.add('libgcc') |
| 117 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 118 | # Case-insensitive file system |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 119 | |
| 120 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 121 | def is_filesystem_case_insensitive(): |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 122 | handle, path = tempfile.mkstemp( |
| 123 | prefix='case-test', dir=config.test_exec_root) |
NAKAMURA Takumi | 77fcfe7 | 2013-07-01 09:51:55 +0000 | [diff] [blame] | 124 | isInsensitive = os.path.exists( |
| 125 | os.path.join( |
| 126 | os.path.dirname(path), |
| 127 | os.path.basename(path).upper() |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 128 | )) |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 129 | os.close(handle) |
| 130 | os.remove(path) |
| 131 | return isInsensitive |
| 132 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 133 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 134 | if is_filesystem_case_insensitive(): |
| 135 | config.available_features.add('case-insensitive-filesystem') |
| 136 | |
Daniel Dunbar | 5238559 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 137 | # Tests that require the /dev/fd filesystem. |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 138 | if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']: |
Daniel Dunbar | 5238559 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 139 | config.available_features.add('dev-fd-fs') |
| 140 | |
Paul Robinson | 4b66e0f | 2019-05-10 13:40:17 +0000 | [diff] [blame] | 141 | # Set on native MS environment. |
| 142 | if re.match(r'.*-(windows-msvc)$', config.target_triple): |
| 143 | config.available_features.add('ms-sdk') |
Filipe Cabecinhas | 18a7261 | 2015-01-30 18:25:59 +0000 | [diff] [blame] | 144 | |
NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 145 | # [PR8833] LLP64-incompatible tests |
Petr Hosek | eb46c95 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 146 | if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple): |
NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 147 | config.available_features.add('LP64') |
| 148 | |
NAKAMURA Takumi | 556d713 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 149 | # [PR12920] "clang-driver" -- set if gcc driver is not used. |
NAKAMURA Takumi | 79e40ec | 2015-10-20 22:36:16 +0000 | [diff] [blame] | 150 | if not re.match(r'.*-(cygwin)$', config.target_triple): |
NAKAMURA Takumi | 556d713 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 151 | config.available_features.add('clang-driver') |
| 152 | |
NAKAMURA Takumi | 23c7671 | 2014-02-16 10:15:34 +0000 | [diff] [blame] | 153 | # [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 154 | # only if all handles were closed. |
| 155 | if platform.system() not in ['Windows']: |
| 156 | config.available_features.add('can-remove-opened-file') |
| 157 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 158 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 159 | def calculate_arch_features(arch_string): |
| 160 | features = [] |
| 161 | for arch in arch_string.split(): |
| 162 | features.append(arch.lower() + '-registered-target') |
| 163 | return features |
NAKAMURA Takumi | 67eade6 | 2013-12-04 03:40:56 +0000 | [diff] [blame] | 164 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 165 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 166 | llvm_config.feature_config( |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 167 | [('--assertion-mode', {'ON': 'asserts'}), |
| 168 | ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}), |
| 169 | ('--targets-built', calculate_arch_features) |
| 170 | ]) |
Dmitri Gribenko | 740c0fb | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 171 | |
| 172 | if lit.util.which('xmllint'): |
| 173 | config.available_features.add('xmllint') |
| 174 | |
Michal Gorny | 638ac70 | 2017-01-25 13:11:45 +0000 | [diff] [blame] | 175 | if config.enable_backtrace: |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 176 | config.available_features.add('backtrace') |
Pete Cooper | 7dc8af5 | 2015-02-10 19:53:38 +0000 | [diff] [blame] | 177 | |
Richard Smith | 26a92d5 | 2019-08-26 18:18:07 +0000 | [diff] [blame] | 178 | if config.enable_threads: |
| 179 | config.available_features.add('thread_support') |
| 180 | |
Yunzhong Gao | 7cbc78e | 2016-01-27 02:18:28 +0000 | [diff] [blame] | 181 | # Check if we should allow outputs to console. |
| 182 | run_console_tests = int(lit_config.params.get('enable_console', '0')) |
| 183 | if run_console_tests != 0: |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 184 | config.available_features.add('console') |
Yunzhong Gao | 7cbc78e | 2016-01-27 02:18:28 +0000 | [diff] [blame] | 185 | |
Alexander Potapenko | 14f8ac0 | 2014-06-10 14:22:00 +0000 | [diff] [blame] | 186 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Alex Lorenz | 01bf58d | 2017-06-02 11:26:35 +0000 | [diff] [blame] | 187 | macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) |
| 188 | if macOSSDKVersion is not None: |
Azharuddin Mohammed | 18b78bf | 2019-07-11 21:45:48 +0000 | [diff] [blame] | 189 | config.available_features.add('macos-sdk-' + str(macOSSDKVersion)) |
Michal Gorny | dae01c3 | 2018-12-23 15:07:26 +0000 | [diff] [blame] | 190 | |
| 191 | if os.path.exists('/etc/gentoo-release'): |
| 192 | config.available_features.add('gentoo') |
Don Hinton | 0a29028 | 2019-06-15 20:09:54 +0000 | [diff] [blame] | 193 | |
| 194 | if config.enable_shared: |
| 195 | config.available_features.add("enable_shared") |