Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 3 | import os |
Daniel Dunbar | b850ddd | 2009-09-22 10:08:03 +0000 | [diff] [blame] | 4 | import platform |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 5 | import re |
| 6 | import subprocess |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 7 | import tempfile |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 8 | |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 11 | |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 12 | # Configuration file for the 'lit' test runner. |
| 13 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 14 | # name: The name of this test suite. |
| 15 | config.name = 'Clang' |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 16 | |
NAKAMURA Takumi | 98af1ac | 2011-02-09 04:19:57 +0000 | [diff] [blame] | 17 | # Tweak PATH for Win32 |
| 18 | if platform.system() == 'Windows': |
| 19 | # Seek sane tools in directories and set to $PATH. |
| 20 | path = getattr(config, 'lit_tools_dir', None) |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 21 | path = lit_config.getToolsPath(path, |
| 22 | config.environment['PATH'], |
| 23 | ['cmp.exe', 'grep.exe', 'sed.exe']) |
NAKAMURA Takumi | 98af1ac | 2011-02-09 04:19:57 +0000 | [diff] [blame] | 24 | if path is not None: |
| 25 | path = os.path.pathsep.join((path, |
| 26 | config.environment['PATH'])) |
| 27 | config.environment['PATH'] = path |
| 28 | |
Reid Kleckner | a53763f | 2013-04-11 13:34:18 +0000 | [diff] [blame] | 29 | # Choose between lit's internal shell pipeline runner and a real shell. If |
| 30 | # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. |
| 31 | use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") |
| 32 | if use_lit_shell: |
| 33 | # 0 is external, "" is default, and everything else is internal. |
| 34 | execute_external = (use_lit_shell == "0") |
| 35 | else: |
| 36 | # Otherwise we default to internal on Windows and external elsewhere, as |
| 37 | # bash on Windows is usually very slow. |
| 38 | execute_external = (not sys.platform in ['win32']) |
| 39 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 40 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 41 | # |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 42 | # For now we require '&&' between commands, until they get globally killed and |
| 43 | # the test runner updated. |
Daniel Dunbar | bc20ef3 | 2009-11-08 01:47:35 +0000 | [diff] [blame] | 44 | config.test_format = lit.formats.ShTest(execute_external) |
Daniel Dunbar | 6827f3f | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 45 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 46 | # suffixes: A list of file extensions to treat as test files. |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 47 | config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap'] |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 48 | |
Alp Toker | 6c6fd7e | 2013-11-15 13:37:49 +0000 | [diff] [blame] | 49 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 50 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 51 | # directories. |
| 52 | config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] |
| 53 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 54 | # test_source_root: The root path where tests are located. |
| 55 | config.test_source_root = os.path.dirname(__file__) |
| 56 | |
| 57 | # test_exec_root: The root path where tests should be run. |
| 58 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 59 | if clang_obj_root is not None: |
| 60 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 61 | |
| 62 | # Set llvm_{src,obj}_root for use by others. |
| 63 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 64 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 65 | |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 66 | # Clear some environment variables that might affect Clang. |
| 67 | # |
| 68 | # This first set of vars are read by Clang, but shouldn't affect tests |
| 69 | # that aren't specifically looking for these features, or are required |
| 70 | # simply to run the tests at all. |
| 71 | # |
| 72 | # FIXME: Should we have a tool that enforces this? |
| 73 | |
| 74 | # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', |
| 75 | # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 76 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 77 | # 'VC80COMNTOOLS') |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 78 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 79 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 80 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 81 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 82 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 83 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 84 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 85 | 'LIBCLANG_RESOURCE_USAGE', |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 86 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 87 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 88 | if platform.system() != 'Windows': |
| 89 | possibly_dangerous_env_vars.append('INCLUDE') |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 90 | for name in possibly_dangerous_env_vars: |
| 91 | if name in config.environment: |
| 92 | del config.environment[name] |
| 93 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 94 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 95 | if clang_obj_root is not None: |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 96 | clang_tools_dir = getattr(config, 'clang_tools_dir', None) |
| 97 | if not clang_tools_dir: |
| 98 | lit_config.fatal('No Clang tools dir set!') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 99 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 100 | if not llvm_tools_dir: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 101 | lit_config.fatal('No LLVM tools dir set!') |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 102 | path = os.path.pathsep.join(( |
| 103 | clang_tools_dir, llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 104 | config.environment['PATH'] = path |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 105 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 106 | if not llvm_libs_dir: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 107 | lit_config.fatal('No LLVM libs dir set!') |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 108 | path = os.path.pathsep.join((llvm_libs_dir, |
| 109 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 110 | config.environment['LD_LIBRARY_PATH'] = path |
| 111 | |
Alexey Samsonov | 32d2a65 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 112 | # Propagate path to symbolizer for ASan/MSan. |
| 113 | for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: |
| 114 | if symbolizer in os.environ: |
| 115 | config.environment[symbolizer] = os.environ[symbolizer] |
| 116 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 117 | ### |
| 118 | |
| 119 | # Check that the object root is known. |
| 120 | if config.test_exec_root is None: |
| 121 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 122 | # probably trying to run on a test file directly, and either the site |
| 123 | # configuration hasn't been created by the build system, or we are in an |
| 124 | # out-of-tree build situation). |
| 125 | |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 126 | # Check for 'clang_site_config' user parameter, and use that if available. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 127 | site_cfg = lit_config.params.get('clang_site_config', None) |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 128 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 129 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 130 | raise SystemExit |
| 131 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 132 | # Try to detect the situation where we are using an out-of-tree build by |
| 133 | # looking for 'llvm-config'. |
| 134 | # |
| 135 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 136 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
Daniel Dunbar | 2335421 | 2009-11-07 23:53:17 +0000 | [diff] [blame] | 137 | # build situation. This means knowing how to invoke the build system though, |
| 138 | # and I decided it was too much magic. We should solve this by just having |
| 139 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 140 | |
| 141 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 142 | if not llvm_config: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 143 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 144 | |
| 145 | # Get the source and object roots. |
| 146 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 147 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 148 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 149 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 150 | |
| 151 | # Validate that we got a tree which points to here, using the standard |
| 152 | # tools/clang layout. |
| 153 | this_src_root = os.path.dirname(config.test_source_root) |
| 154 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 155 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 156 | |
| 157 | # Check that the site specific configuration exists. |
| 158 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 159 | if not os.path.exists(site_cfg): |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 160 | lit_config.fatal( |
| 161 | 'No site specific configuration available! You may need to ' |
| 162 | 'run "make test" in your Clang build directory.') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 163 | |
| 164 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 165 | lit_config.note('using out-of-tree build at %r' % clang_obj_root) |
| 166 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 167 | raise SystemExit |
| 168 | |
| 169 | ### |
| 170 | |
| 171 | # Discover the 'clang' and 'clangcc' to use. |
| 172 | |
| 173 | import os |
| 174 | |
| 175 | def inferClang(PATH): |
| 176 | # Determine which clang to use. |
| 177 | clang = os.getenv('CLANG') |
| 178 | |
| 179 | # If the user set clang in the environment, definitely use that and don't |
| 180 | # try to validate. |
| 181 | if clang: |
| 182 | return clang |
| 183 | |
| 184 | # Otherwise look in the path. |
| 185 | clang = lit.util.which('clang', PATH) |
| 186 | |
| 187 | if not clang: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 188 | lit_config.fatal("couldn't find 'clang' program, try setting " |
| 189 | "CLANG in your environment") |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 190 | |
| 191 | return clang |
| 192 | |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 193 | config.clang = inferClang(config.environment['PATH']).replace('\\', '/') |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 194 | if not lit_config.quiet: |
| 195 | lit_config.note('using clang: %r' % config.clang) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 196 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 197 | # Plugins (loadable modules) |
| 198 | # TODO: This should be supplied by Makefile or autoconf. |
| 199 | if sys.platform in ['win32', 'cygwin']: |
| 200 | has_plugins = (config.enable_shared == 1) |
| 201 | else: |
| 202 | has_plugins = True |
| 203 | |
| 204 | if has_plugins and config.llvm_plugin_ext: |
| 205 | config.available_features.add('plugins') |
| 206 | |
| 207 | config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) |
| 208 | config.substitutions.append( ('%pluginext', config.llvm_plugin_ext) ) |
| 209 | |
| 210 | if config.clang_examples: |
| 211 | config.available_features.add('examples') |
| 212 | |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 213 | # Note that when substituting %clang_cc1 also fill in the include directory of |
| 214 | # the builtin headers. Those are part of even a freestanding environment, but |
| 215 | # Clang relies on the driver to locate them. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 216 | def getClangBuiltinIncludeDir(clang): |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 217 | # FIXME: Rather than just getting the version, we should have clang print |
| 218 | # out its resource dir here in an easy to scrape form. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 219 | cmd = subprocess.Popen([clang, '-print-file-name=include'], |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 220 | stdout=subprocess.PIPE, |
| 221 | env=config.environment) |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 222 | if not cmd.stdout: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 223 | lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang) |
NAKAMURA Takumi | 5407d4a | 2013-06-26 10:45:20 +0000 | [diff] [blame] | 224 | dir = cmd.stdout.read().strip() |
| 225 | if sys.platform in ['win32'] and execute_external: |
| 226 | # Don't pass dosish path separator to msys bash.exe. |
| 227 | dir = dir.replace('\\', '/') |
Daniel Dunbar | 03f443a | 2013-08-14 16:32:20 +0000 | [diff] [blame] | 228 | # Ensure the result is an ascii string, across Python2.5+ - Python3. |
| 229 | return str(dir.decode('ascii')) |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 230 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 231 | def makeItaniumABITriple(triple): |
| 232 | m = re.match(r'(\w+)-(\w+)-(\w+)', triple) |
| 233 | if not m: |
| 234 | lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple) |
| 235 | if m.group(3).lower() != 'win32': |
| 236 | # All non-win32 triples use the Itanium ABI. |
| 237 | return triple |
| 238 | return m.group(1) + '-' + m.group(2) + '-mingw32' |
| 239 | |
| 240 | def makeMSABITriple(triple): |
| 241 | m = re.match(r'(\w+)-(\w+)-(\w+)', triple) |
| 242 | if not m: |
| 243 | lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple) |
| 244 | isa = m.group(1).lower() |
| 245 | vendor = m.group(2).lower() |
| 246 | os = m.group(3).lower() |
| 247 | if os == 'win32': |
| 248 | # If the OS is win32, we're done. |
| 249 | return triple |
| 250 | if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa): |
| 251 | # For x86 ISAs, adjust the OS. |
| 252 | return isa + '-' + vendor + '-win32' |
| 253 | # -win32 is not supported for non-x86 targets; use a default. |
| 254 | return 'i686-pc-win32' |
| 255 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 256 | config.substitutions.append( ('%clang_cc1', |
| 257 | '%s -cc1 -internal-isystem %s -nostdsysteminc' |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 258 | % (config.clang, |
| 259 | getClangBuiltinIncludeDir(config.clang))) ) |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 260 | config.substitutions.append( ('%clang_cpp', ' ' + config.clang + |
| 261 | ' --driver-mode=cpp ')) |
Hans Wennborg | c2f531a | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 262 | config.substitutions.append( ('%clang_cl', ' ' + config.clang + |
| 263 | ' --driver-mode=cl ')) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 264 | config.substitutions.append( ('%clangxx', ' ' + config.clang + |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 265 | ' --driver-mode=g++ ')) |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 266 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Devang Patel | 8c6b913 | 2010-09-13 20:46:23 +0000 | [diff] [blame] | 267 | config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') ) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 268 | config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) ) |
| 269 | config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) ) |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 270 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 271 | # The host triple might not be set, at least if we're compiling clang from |
| 272 | # an already installed llvm. |
| 273 | if config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@': |
| 274 | config.substitutions.append( ('%target_itanium_abi_host_triple', '--target=%s' % makeItaniumABITriple(config.host_triple)) ) |
| 275 | else: |
| 276 | config.substitutions.append( ('%target_itanium_abi_host_triple', '') ) |
| 277 | |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 278 | # FIXME: Find nicer way to prohibit this. |
| 279 | config.substitutions.append( |
| 280 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 281 | config.substitutions.append( |
David Greene | 431feb5 | 2011-01-03 17:28:52 +0000 | [diff] [blame] | 282 | (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
Daniel Dunbar | 679d605 | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 283 | config.substitutions.append( |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 284 | (' clang-cc ', |
| 285 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 286 | config.substitutions.append( |
| 287 | (' clang -cc1 ', |
| 288 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 289 | config.substitutions.append( |
| 290 | (' %clang-cc1 ', |
| 291 | """*** invalid substitution, use '%clang_cc1'. ***""") ) |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 292 | config.substitutions.append( |
| 293 | (' %clang-cpp ', |
| 294 | """*** invalid substitution, use '%clang_cpp'. ***""") ) |
Hans Wennborg | c2f531a | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 295 | config.substitutions.append( |
| 296 | (' %clang-cl ', |
| 297 | """*** invalid substitution, use '%clang_cl'. ***""") ) |
Daniel Dunbar | db91864 | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 298 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 299 | # For each occurrence of a clang tool name as its own word, replace it |
| 300 | # with the full path to the build directory holding that tool. This |
| 301 | # ensures that we are testing the tools just built and not some random |
| 302 | # tools that might happen to be in the user's PATH. |
| 303 | tool_dirs = os.path.pathsep.join((clang_tools_dir, llvm_tools_dir)) |
| 304 | |
| 305 | # Regex assertions to reject neighbor hyphens/dots (seen in some tests). |
| 306 | # For example, don't match 'clang-check-' or '.clang-format'. |
| 307 | NoPreHyphenDot = r"(?<!(-|\.))" |
| 308 | NoPostHyphenDot = r"(?!(-|\.))" |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 309 | NoPostBar = r"(?!(/|\\))" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 310 | |
| 311 | for pattern in [r"\bFileCheck\b", |
| 312 | r"\bc-index-test\b", |
| 313 | NoPreHyphenDot + r"\bclang-check\b" + NoPostHyphenDot, |
| 314 | NoPreHyphenDot + r"\bclang-format\b" + NoPostHyphenDot, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 315 | NoPreHyphenDot + r"\bclang-interpreter\b" + NoPostHyphenDot, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 316 | # FIXME: Some clang test uses opt? |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 317 | NoPreHyphenDot + r"\bopt\b" + NoPostBar + NoPostHyphenDot, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 318 | # Handle these specially as they are strings searched |
| 319 | # for during testing. |
| 320 | r"\| \bcount\b", |
| 321 | r"\| \bnot\b"]: |
| 322 | # Extract the tool name from the pattern. This relies on the tool |
| 323 | # name being surrounded by \b word match operators. If the |
| 324 | # pattern starts with "| ", include it in the string to be |
| 325 | # substituted. |
| 326 | tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
| 327 | pattern) |
| 328 | tool_pipe = tool_match.group(2) |
| 329 | tool_name = tool_match.group(4) |
| 330 | tool_path = lit.util.which(tool_name, tool_dirs) |
| 331 | if not tool_path: |
| 332 | # Warn, but still provide a substitution. |
| 333 | lit_config.note('Did not find ' + tool_name + ' in ' + tool_dirs) |
| 334 | tool_path = clang_tools_dir + '/' + tool_name |
| 335 | config.substitutions.append((pattern, tool_pipe + tool_path)) |
| 336 | |
Daniel Dunbar | db91864 | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 337 | ### |
| 338 | |
| 339 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 6da28e2 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 340 | # |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 341 | # Enabled/disabled features |
| 342 | if config.clang_staticanalyzer != 0: |
| 343 | config.available_features.add("staticanalyzer") |
| 344 | |
Andrew Trick | 6da28e2 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 345 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 346 | if platform.system() not in ['FreeBSD']: |
| 347 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 348 | |
| 349 | # Shell execution |
Reid Kleckner | a53763f | 2013-04-11 13:34:18 +0000 | [diff] [blame] | 350 | if execute_external: |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 351 | config.available_features.add('shell') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 352 | |
NAKAMURA Takumi | 05a10ff | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 353 | # Exclude MSYS due to transforming '/' to 'X:/mingwroot/'. |
Hans Wennborg | de56bb7 | 2013-08-05 20:14:43 +0000 | [diff] [blame] | 354 | if not platform.system() in ['Windows'] or not execute_external: |
NAKAMURA Takumi | 05a10ff | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 355 | config.available_features.add('shell-preserves-root') |
| 356 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 357 | # For tests that require Darwin to run. |
| 358 | # This is used by debuginfo-tests/*block*.m and debuginfo-tests/foreach.m. |
| 359 | if platform.system() in ['Darwin']: |
| 360 | config.available_features.add('system-darwin') |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 361 | elif platform.system() in ['Windows']: |
| 362 | # For tests that require Windows to run. |
| 363 | config.available_features.add('system-windows') |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 364 | |
NAKAMURA Takumi | 5e3d24c | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 365 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | 0ca4be3 | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 366 | if platform.system() not in ['Windows']: |
| 367 | config.available_features.add('ansi-escape-sequences') |
| 368 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 369 | # Capability to print utf8 to the terminal. |
| 370 | # Windows expects codepage, unless Wide API. |
| 371 | if platform.system() not in ['Windows']: |
| 372 | config.available_features.add('utf8-capable-terminal') |
| 373 | |
| 374 | # Native compilation: Check if triples match. |
| 375 | # FIXME: Consider cases that target can be executed |
| 376 | # even if host_triple were different from target_triple. |
| 377 | if config.host_triple == config.target_triple: |
Amaury de la Vieuville | 0909859 | 2013-09-13 11:02:31 +0000 | [diff] [blame] | 378 | config.available_features.add("native") |
| 379 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 380 | # Case-insensitive file system |
| 381 | def is_filesystem_case_insensitive(): |
Argyrios Kyrtzidis | b2ed96a | 2012-11-01 00:59:15 +0000 | [diff] [blame] | 382 | handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) |
NAKAMURA Takumi | 80db6a7 | 2013-07-01 09:51:55 +0000 | [diff] [blame] | 383 | isInsensitive = os.path.exists( |
| 384 | os.path.join( |
| 385 | os.path.dirname(path), |
| 386 | os.path.basename(path).upper() |
| 387 | )) |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 388 | os.close(handle) |
| 389 | os.remove(path) |
| 390 | return isInsensitive |
| 391 | |
| 392 | if is_filesystem_case_insensitive(): |
| 393 | config.available_features.add('case-insensitive-filesystem') |
| 394 | |
Daniel Dunbar | 0b95bd0 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 395 | # Tests that require the /dev/fd filesystem. |
NAKAMURA Takumi | 93308b9 | 2012-11-27 05:25:41 +0000 | [diff] [blame] | 396 | if os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']: |
Daniel Dunbar | 0b95bd0 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 397 | config.available_features.add('dev-fd-fs') |
| 398 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 399 | # DW2 Target |
| 400 | if not re.match(r'.*-win32$', config.target_triple): |
| 401 | config.available_features.add('dw2') |
| 402 | |
| 403 | # Not set on native MS environment. |
| 404 | if not re.match(r'.*-win32$', config.target_triple): |
| 405 | config.available_features.add('non-ms-sdk') |
| 406 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 407 | # Not set on native PS4 environment. |
| 408 | if not re.match(r'.*-scei-ps4', config.target_triple): |
| 409 | config.available_features.add('non-ps4-sdk') |
| 410 | |
NAKAMURA Takumi | b774d73 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 411 | # [PR8833] LLP64-incompatible tests |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 412 | if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple): |
NAKAMURA Takumi | b774d73 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 413 | config.available_features.add('LP64') |
| 414 | |
NAKAMURA Takumi | 5e4ccb4 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 415 | # [PR12920] "clang-driver" -- set if gcc driver is not used. |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 416 | if not re.match(r'.*-(cygwin|mingw32|windows-gnu)$', config.target_triple): |
NAKAMURA Takumi | 5e4ccb4 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 417 | config.available_features.add('clang-driver') |
| 418 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 419 | # [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 420 | # only if all handles were closed. |
| 421 | if platform.system() not in ['Windows']: |
| 422 | config.available_features.add('can-remove-opened-file') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 423 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 424 | # Returns set of available features, registered-target(s) and asserts. |
| 425 | def get_llvm_config_props(): |
| 426 | set_of_features = set() |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 427 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 428 | cmd = subprocess.Popen( |
| 429 | [ |
| 430 | os.path.join(llvm_tools_dir, 'llvm-config'), |
| 431 | '--assertion-mode', |
| 432 | '--targets-built', |
| 433 | ], |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 434 | stdout=subprocess.PIPE, |
| 435 | env=config.environment |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 436 | ) |
| 437 | # 1st line corresponds to --assertion-mode, "ON" or "OFF". |
| 438 | line = cmd.stdout.readline().strip().decode('ascii') |
| 439 | if line == "ON": |
| 440 | set_of_features.add('asserts') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 441 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 442 | # 2nd line corresponds to --targets-built, like; |
| 443 | # AArch64 ARM CppBackend X86 |
| 444 | for arch in cmd.stdout.readline().decode('ascii').split(): |
| 445 | set_of_features.add(arch.lower() + '-registered-target') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 446 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 447 | return set_of_features |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 448 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 449 | config.available_features.update(get_llvm_config_props()) |
Dmitri Gribenko | f303d4c | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 450 | |
| 451 | if lit.util.which('xmllint'): |
| 452 | config.available_features.add('xmllint') |
| 453 | |
Alexey Samsonov | 48c0834 | 2013-03-26 08:28:18 +0000 | [diff] [blame] | 454 | # Sanitizers. |
| 455 | if config.llvm_use_sanitizer == "Address": |
| 456 | config.available_features.add("asan") |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 457 | else: |
| 458 | config.available_features.add("not_asan") |
Alexey Samsonov | 48c0834 | 2013-03-26 08:28:18 +0000 | [diff] [blame] | 459 | if (config.llvm_use_sanitizer == "Memory" or |
| 460 | config.llvm_use_sanitizer == "MemoryWithOrigins"): |
| 461 | config.available_features.add("msan") |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 462 | if config.llvm_use_sanitizer == "Undefined": |
| 463 | config.available_features.add("ubsan") |
| 464 | else: |
| 465 | config.available_features.add("not_ubsan") |
Michael Gottesman | 63f4050 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 466 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 467 | if config.enable_backtrace == "1": |
| 468 | config.available_features.add("backtrace") |
| 469 | |
Michael Gottesman | 63f4050 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 470 | # Check if we should run long running tests. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 471 | if lit_config.params.get("run_long_tests", None) == "true": |
Michael Gottesman | 63f4050 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 472 | config.available_features.add("long_tests") |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 473 | |
| 474 | # Check if we should use gmalloc. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 475 | use_gmalloc_str = lit_config.params.get('use_gmalloc', None) |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 476 | if use_gmalloc_str is not None: |
| 477 | if use_gmalloc_str.lower() in ('1', 'true'): |
| 478 | use_gmalloc = True |
| 479 | elif use_gmalloc_str.lower() in ('', '0', 'false'): |
| 480 | use_gmalloc = False |
| 481 | else: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 482 | lit_config.fatal('user parameter use_gmalloc should be 0 or 1') |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 483 | else: |
| 484 | # Default to not using gmalloc |
| 485 | use_gmalloc = False |
| 486 | |
| 487 | # Allow use of an explicit path for gmalloc library. |
| 488 | # Will default to '/usr/lib/libgmalloc.dylib' if not set. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 489 | gmalloc_path_str = lit_config.params.get('gmalloc_path', |
| 490 | '/usr/lib/libgmalloc.dylib') |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 491 | if use_gmalloc: |
| 492 | config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str}) |
Daniel Dunbar | 8ad46b7 | 2013-11-06 21:44:54 +0000 | [diff] [blame] | 493 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 494 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |