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', |
| 29 | '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs'] |
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 | |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 46 | # Propagate path to symbolizer for ASan/MSan. |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 47 | llvm_config.with_system_environment( |
| 48 | ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 49 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 50 | config.substitutions.append(('%PATH%', config.environment['PATH'])) |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 51 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 52 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 53 | # For each occurrence of a clang tool name, replace it with the full path to |
| 54 | # the build directory holding that tool. We explicitly specify the directories |
| 55 | # to search to ensure that we get the tools just built and not some random |
| 56 | # tools that might happen to be in the user's PATH. |
| 57 | tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 58 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 59 | tools = [ |
| 60 | 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt', |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 61 | ToolSubst('%clang_func_map', command=FindTool( |
| 62 | 'clang-func-mapping'), unresolved='ignore'), |
| 63 | ] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 64 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 65 | if config.clang_examples: |
| 66 | tools.append('clang-interpreter') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 67 | |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 68 | llvm_config.add_tool_substitutions(tools, tool_dirs) |
Chandler Carruth | c0b1b86 | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 69 | |
Alp Toker | 120dd1af | 2014-01-08 11:38:47 +0000 | [diff] [blame] | 70 | # Plugins (loadable modules) |
| 71 | # TODO: This should be supplied by Makefile or autoconf. |
NAKAMURA Takumi | ba7d0fe | 2016-02-11 16:43:08 +0000 | [diff] [blame] | 72 | if sys.platform in ['win32', 'cygwin']: |
Michal Gorny | 638ac70 | 2017-01-25 13:11:45 +0000 | [diff] [blame] | 73 | has_plugins = config.enable_shared |
Alp Toker | 120dd1af | 2014-01-08 11:38:47 +0000 | [diff] [blame] | 74 | else: |
| 75 | has_plugins = True |
| 76 | |
| 77 | if has_plugins and config.llvm_plugin_ext: |
| 78 | config.available_features.add('plugins') |
| 79 | |
Daniel Dunbar | b44eb0b | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 80 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 81 | # |
Jonas Hahnfeld | fdaaca8 | 2016-09-29 07:43:08 +0000 | [diff] [blame] | 82 | if config.clang_default_cxx_stdlib != '': |
| 83 | config.available_features.add('default-cxx-stdlib-set') |
| 84 | |
NAKAMURA Takumi | 1fb02cb | 2014-07-16 12:05:45 +0000 | [diff] [blame] | 85 | # Enabled/disabled features |
Michal Gorny | 638ac70 | 2017-01-25 13:11:45 +0000 | [diff] [blame] | 86 | if config.clang_staticanalyzer: |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 87 | config.available_features.add('staticanalyzer') |
NAKAMURA Takumi | 1fb02cb | 2014-07-16 12:05:45 +0000 | [diff] [blame] | 88 | |
Dominic Chen | 08f943c | 2017-04-04 19:52:25 +0000 | [diff] [blame] | 89 | if config.clang_staticanalyzer_z3 == '1': |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 90 | config.available_features.add('z3') |
Dominic Chen | 08f943c | 2017-04-04 19:52:25 +0000 | [diff] [blame] | 91 | |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 92 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 93 | if platform.system() not in ['FreeBSD']: |
| 94 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | f5ea88b | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 95 | |
NAKAMURA Takumi | 6bbc981 | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 96 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | b59973e | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 97 | if platform.system() not in ['Windows']: |
| 98 | config.available_features.add('ansi-escape-sequences') |
| 99 | |
NAKAMURA Takumi | 0c81c71 | 2014-02-06 07:15:59 +0000 | [diff] [blame] | 100 | # Capability to print utf8 to the terminal. |
| 101 | # Windows expects codepage, unless Wide API. |
| 102 | if platform.system() not in ['Windows']: |
| 103 | config.available_features.add('utf8-capable-terminal') |
| 104 | |
Michal Gorny | 7cfe480 | 2016-10-10 12:23:40 +0000 | [diff] [blame] | 105 | # Support for libgcc runtime. Used to rule out tests that require |
| 106 | # clang to run with -rtlib=libgcc. |
| 107 | if platform.system() not in ['Darwin', 'Fuchsia']: |
| 108 | config.available_features.add('libgcc') |
| 109 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 110 | # Case-insensitive file system |
Zachary Turner | 8eb7005 | 2017-10-17 23:43:36 +0000 | [diff] [blame] | 111 | |
| 112 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 113 | def is_filesystem_case_insensitive(): |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 114 | handle, path = tempfile.mkstemp( |
| 115 | prefix='case-test', dir=config.test_exec_root) |
NAKAMURA Takumi | 77fcfe7 | 2013-07-01 09:51:55 +0000 | [diff] [blame] | 116 | isInsensitive = os.path.exists( |
| 117 | os.path.join( |
| 118 | os.path.dirname(path), |
| 119 | os.path.basename(path).upper() |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 120 | )) |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 121 | os.close(handle) |
| 122 | os.remove(path) |
| 123 | return isInsensitive |
| 124 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 125 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 126 | if is_filesystem_case_insensitive(): |
| 127 | config.available_features.add('case-insensitive-filesystem') |
| 128 | |
Daniel Dunbar | 5238559 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 129 | # Tests that require the /dev/fd filesystem. |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 130 | 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] | 131 | config.available_features.add('dev-fd-fs') |
| 132 | |
NAKAMURA Takumi | 0884887 | 2014-02-16 10:15:57 +0000 | [diff] [blame] | 133 | # Not set on native MS environment. |
| 134 | if not re.match(r'.*-win32$', config.target_triple): |
| 135 | config.available_features.add('non-ms-sdk') |
| 136 | |
Filipe Cabecinhas | 18a7261 | 2015-01-30 18:25:59 +0000 | [diff] [blame] | 137 | # Not set on native PS4 environment. |
Filipe Cabecinhas | 10ff133 | 2015-02-02 23:17:54 +0000 | [diff] [blame] | 138 | if not re.match(r'.*-scei-ps4', config.target_triple): |
Filipe Cabecinhas | 18a7261 | 2015-01-30 18:25:59 +0000 | [diff] [blame] | 139 | config.available_features.add('non-ps4-sdk') |
| 140 | |
NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 141 | # [PR8833] LLP64-incompatible tests |
Yaron Keren | f630971 | 2014-12-17 09:55:15 +0000 | [diff] [blame] | 142 | if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple): |
NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 143 | config.available_features.add('LP64') |
| 144 | |
NAKAMURA Takumi | 556d713 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 145 | # [PR12920] "clang-driver" -- set if gcc driver is not used. |
NAKAMURA Takumi | 79e40ec | 2015-10-20 22:36:16 +0000 | [diff] [blame] | 146 | if not re.match(r'.*-(cygwin)$', config.target_triple): |
NAKAMURA Takumi | 556d713 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 147 | config.available_features.add('clang-driver') |
| 148 | |
NAKAMURA Takumi | 23c7671 | 2014-02-16 10:15:34 +0000 | [diff] [blame] | 149 | # [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 150 | # only if all handles were closed. |
| 151 | if platform.system() not in ['Windows']: |
| 152 | config.available_features.add('can-remove-opened-file') |
| 153 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 154 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 155 | def calculate_arch_features(arch_string): |
| 156 | features = [] |
| 157 | for arch in arch_string.split(): |
| 158 | features.append(arch.lower() + '-registered-target') |
| 159 | return features |
NAKAMURA Takumi | 67eade6 | 2013-12-04 03:40:56 +0000 | [diff] [blame] | 160 | |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 161 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 162 | llvm_config.feature_config( |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 163 | [('--assertion-mode', {'ON': 'asserts'}), |
| 164 | ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}), |
| 165 | ('--targets-built', calculate_arch_features) |
| 166 | ]) |
Dmitri Gribenko | 740c0fb | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 167 | |
| 168 | if lit.util.which('xmllint'): |
| 169 | config.available_features.add('xmllint') |
| 170 | |
Michal Gorny | 638ac70 | 2017-01-25 13:11:45 +0000 | [diff] [blame] | 171 | if config.enable_backtrace: |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 172 | config.available_features.add('backtrace') |
Pete Cooper | 7dc8af5 | 2015-02-10 19:53:38 +0000 | [diff] [blame] | 173 | |
Yunzhong Gao | 7cbc78e | 2016-01-27 02:18:28 +0000 | [diff] [blame] | 174 | # Check if we should allow outputs to console. |
| 175 | run_console_tests = int(lit_config.params.get('enable_console', '0')) |
| 176 | if run_console_tests != 0: |
Zachary Turner | c981448 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 177 | config.available_features.add('console') |
Yunzhong Gao | 7cbc78e | 2016-01-27 02:18:28 +0000 | [diff] [blame] | 178 | |
Alexander Potapenko | 14f8ac0 | 2014-06-10 14:22:00 +0000 | [diff] [blame] | 179 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Alex Lorenz | 01bf58d | 2017-06-02 11:26:35 +0000 | [diff] [blame] | 180 | macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) |
| 181 | if macOSSDKVersion is not None: |
| 182 | config.available_features.add('macos-sdk-' + macOSSDKVersion) |