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 | |
Daniel Dunbar | 3667b99 | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 12 | # Configuration file for the 'lit' test runner. |
| 13 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 14 | # name: The name of this test suite. |
| 15 | config.name = 'Clang' |
Daniel Dunbar | be4253a | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 16 | |
NAKAMURA Takumi | 1e8200d | 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 | 94ec6cc | 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 | 1e8200d | 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 | 0675f85 | 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 | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 40 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 3667b99 | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 41 | # |
Daniel Dunbar | b5cbf77 | 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 | d90e0a1 | 2009-11-08 01:47:35 +0000 | [diff] [blame] | 44 | config.test_format = lit.formats.ShTest(execute_external) |
Daniel Dunbar | f87be55 | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 45 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 46 | # suffixes: A list of file extensions to treat as test files. |
Daniel Jasper | 5c77e39 | 2014-03-14 14:53:17 +0000 | [diff] [blame] | 47 | config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S'] |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 48 | |
Alp Toker | 9c5ae47 | 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 | b5cbf77 | 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 | 0e09fac | 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', |
| 76 | # 'IOS_SIMULATOR_DEPLOYMENT_TARGET', |
| 77 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 78 | # 'VC80COMNTOOLS') |
NAKAMURA Takumi | c4d558a | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 79 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
Jordy Rose | 0e09fac | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 80 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 81 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 82 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 83 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 84 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 85 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 86 | 'LIBCLANG_RESOURCE_USAGE', |
NAKAMURA Takumi | c4d558a | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 87 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 88 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 89 | if platform.system() != 'Windows': |
| 90 | possibly_dangerous_env_vars.append('INCLUDE') |
Jordy Rose | 0e09fac | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 91 | for name in possibly_dangerous_env_vars: |
| 92 | if name in config.environment: |
| 93 | del config.environment[name] |
| 94 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 95 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 96 | if clang_obj_root is not None: |
NAKAMURA Takumi | 462ba80 | 2013-12-18 15:08:56 +0000 | [diff] [blame] | 97 | clang_tools_dir = getattr(config, 'clang_tools_dir', None) |
| 98 | if not clang_tools_dir: |
| 99 | lit_config.fatal('No Clang tools dir set!') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 100 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 101 | if not llvm_tools_dir: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 102 | lit_config.fatal('No LLVM tools dir set!') |
NAKAMURA Takumi | 462ba80 | 2013-12-18 15:08:56 +0000 | [diff] [blame] | 103 | path = os.path.pathsep.join(( |
| 104 | clang_tools_dir, llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 105 | config.environment['PATH'] = path |
Daniel Dunbar | a87097a | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 106 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 107 | if not llvm_libs_dir: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 108 | lit_config.fatal('No LLVM libs dir set!') |
Daniel Dunbar | a87097a | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 109 | path = os.path.pathsep.join((llvm_libs_dir, |
| 110 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 111 | config.environment['LD_LIBRARY_PATH'] = path |
| 112 | |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 113 | # Propagate path to symbolizer for ASan/MSan. |
| 114 | for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: |
| 115 | if symbolizer in os.environ: |
| 116 | config.environment[symbolizer] = os.environ[symbolizer] |
| 117 | |
Chandler Carruth | 0702f8e | 2014-05-02 21:46:39 +0000 | [diff] [blame] | 118 | # Propagate options for sanitizers. |
Alexey Samsonov | 4ee2675 | 2014-08-29 00:50:36 +0000 | [diff] [blame] | 119 | for options in ['ASAN_OPTIONS', 'UBSAN_OPTIONS']: |
Chandler Carruth | 0702f8e | 2014-05-02 21:46:39 +0000 | [diff] [blame] | 120 | if options in os.environ: |
| 121 | config.environment[options] = os.environ[options] |
| 122 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 123 | ### |
| 124 | |
| 125 | # Check that the object root is known. |
| 126 | if config.test_exec_root is None: |
| 127 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 128 | # probably trying to run on a test file directly, and either the site |
| 129 | # configuration hasn't been created by the build system, or we are in an |
| 130 | # out-of-tree build situation). |
| 131 | |
Daniel Dunbar | d3f630f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 132 | # Check for 'clang_site_config' user parameter, and use that if available. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 133 | site_cfg = lit_config.params.get('clang_site_config', None) |
Daniel Dunbar | d3f630f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 134 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 135 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | d3f630f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 136 | raise SystemExit |
| 137 | |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 138 | # Try to detect the situation where we are using an out-of-tree build by |
| 139 | # looking for 'llvm-config'. |
| 140 | # |
| 141 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 142 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
Daniel Dunbar | 8466a0d | 2009-11-07 23:53:17 +0000 | [diff] [blame] | 143 | # build situation. This means knowing how to invoke the build system though, |
| 144 | # and I decided it was too much magic. We should solve this by just having |
| 145 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 146 | |
| 147 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 148 | if not llvm_config: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 149 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 150 | |
| 151 | # Get the source and object roots. |
| 152 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 153 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 154 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 155 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 156 | |
| 157 | # Validate that we got a tree which points to here, using the standard |
| 158 | # tools/clang layout. |
| 159 | this_src_root = os.path.dirname(config.test_source_root) |
| 160 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 161 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 162 | |
| 163 | # Check that the site specific configuration exists. |
| 164 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 165 | if not os.path.exists(site_cfg): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 166 | lit_config.fatal( |
| 167 | 'No site specific configuration available! You may need to ' |
| 168 | 'run "make test" in your Clang build directory.') |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 169 | |
| 170 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 171 | lit_config.note('using out-of-tree build at %r' % clang_obj_root) |
| 172 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 173 | raise SystemExit |
| 174 | |
| 175 | ### |
| 176 | |
| 177 | # Discover the 'clang' and 'clangcc' to use. |
| 178 | |
| 179 | import os |
| 180 | |
| 181 | def inferClang(PATH): |
| 182 | # Determine which clang to use. |
| 183 | clang = os.getenv('CLANG') |
| 184 | |
| 185 | # If the user set clang in the environment, definitely use that and don't |
| 186 | # try to validate. |
| 187 | if clang: |
| 188 | return clang |
| 189 | |
| 190 | # Otherwise look in the path. |
| 191 | clang = lit.util.which('clang', PATH) |
| 192 | |
| 193 | if not clang: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 194 | lit_config.fatal("couldn't find 'clang' program, try setting " |
| 195 | "CLANG in your environment") |
Daniel Dunbar | b5cbf77 | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 196 | |
| 197 | return clang |
| 198 | |
NAKAMURA Takumi | 70f5be6 | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 199 | config.clang = inferClang(config.environment['PATH']).replace('\\', '/') |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 200 | if not lit_config.quiet: |
| 201 | lit_config.note('using clang: %r' % config.clang) |
Chandler Carruth | c0b1b86 | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 202 | |
Alp Toker | 120dd1af | 2014-01-08 11:38:47 +0000 | [diff] [blame] | 203 | # Plugins (loadable modules) |
| 204 | # TODO: This should be supplied by Makefile or autoconf. |
| 205 | if sys.platform in ['win32', 'cygwin']: |
| 206 | has_plugins = (config.enable_shared == 1) |
| 207 | else: |
| 208 | has_plugins = True |
| 209 | |
| 210 | if has_plugins and config.llvm_plugin_ext: |
| 211 | config.available_features.add('plugins') |
| 212 | |
| 213 | config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) |
| 214 | config.substitutions.append( ('%pluginext', config.llvm_plugin_ext) ) |
| 215 | |
| 216 | if config.clang_examples: |
| 217 | config.available_features.add('examples') |
| 218 | |
Chandler Carruth | c0b1b86 | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 219 | # Note that when substituting %clang_cc1 also fill in the include directory of |
| 220 | # the builtin headers. Those are part of even a freestanding environment, but |
| 221 | # Clang relies on the driver to locate them. |
Chandler Carruth | 34146d8 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 222 | def getClangBuiltinIncludeDir(clang): |
Chandler Carruth | 2837f66 | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 223 | # FIXME: Rather than just getting the version, we should have clang print |
| 224 | # out its resource dir here in an easy to scrape form. |
Chandler Carruth | 34146d8 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 225 | cmd = subprocess.Popen([clang, '-print-file-name=include'], |
Scott Douglass | df914d5 | 2014-09-24 18:37:52 +0000 | [diff] [blame^] | 226 | stdout=subprocess.PIPE, |
| 227 | env=config.environment) |
Chandler Carruth | 34146d8 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 228 | if not cmd.stdout: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 229 | lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang) |
NAKAMURA Takumi | 8e85e6a | 2013-06-26 10:45:20 +0000 | [diff] [blame] | 230 | dir = cmd.stdout.read().strip() |
| 231 | if sys.platform in ['win32'] and execute_external: |
| 232 | # Don't pass dosish path separator to msys bash.exe. |
| 233 | dir = dir.replace('\\', '/') |
Daniel Dunbar | eff4a95 | 2013-08-14 16:32:20 +0000 | [diff] [blame] | 234 | # Ensure the result is an ascii string, across Python2.5+ - Python3. |
| 235 | return str(dir.decode('ascii')) |
Chandler Carruth | 2837f66 | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 236 | |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 237 | def makeItaniumABITriple(triple): |
| 238 | m = re.match(r'(\w+)-(\w+)-(\w+)', triple) |
| 239 | if not m: |
| 240 | lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple) |
| 241 | if m.group(3).lower() != 'win32': |
| 242 | # All non-win32 triples use the Itanium ABI. |
| 243 | return triple |
| 244 | return m.group(1) + '-' + m.group(2) + '-mingw32' |
| 245 | |
| 246 | def makeMSABITriple(triple): |
| 247 | m = re.match(r'(\w+)-(\w+)-(\w+)', triple) |
| 248 | if not m: |
| 249 | lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple) |
Hans Wennborg | 1e76cba | 2014-01-15 01:08:42 +0000 | [diff] [blame] | 250 | isa = m.group(1).lower() |
| 251 | vendor = m.group(2).lower() |
| 252 | os = m.group(3).lower() |
| 253 | if os == 'win32': |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 254 | # If the OS is win32, we're done. |
| 255 | return triple |
Hans Wennborg | 1e76cba | 2014-01-15 01:08:42 +0000 | [diff] [blame] | 256 | if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa): |
| 257 | # For x86 ISAs, adjust the OS. |
| 258 | return isa + '-' + vendor + '-win32' |
| 259 | # -win32 is not supported for non-x86 targets; use a default. |
| 260 | return 'i686-pc-win32' |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 261 | |
Chandler Carruth | a62ba81 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 262 | config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s' |
Chandler Carruth | 34146d8 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 263 | % (config.clang, |
| 264 | getClangBuiltinIncludeDir(config.clang))) ) |
Hans Wennborg | 70850d8 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 265 | config.substitutions.append( ('%clang_cpp', ' ' + config.clang + |
| 266 | ' --driver-mode=cpp ')) |
Hans Wennborg | e4b031c | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 267 | config.substitutions.append( ('%clang_cl', ' ' + config.clang + |
| 268 | ' --driver-mode=cl ')) |
Daniel Dunbar | 8452ef0 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 269 | config.substitutions.append( ('%clangxx', ' ' + config.clang + |
Hans Wennborg | 70850d8 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 270 | ' --driver-mode=g++ ')) |
Daniel Dunbar | 5618e98 | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 271 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Adrian Prantl | 8ae19f7 | 2014-01-27 22:50:20 +0000 | [diff] [blame] | 272 | config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') ) |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 273 | config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) ) |
| 274 | config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) ) |
Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 275 | |
Daniel Dunbar | 5618e98 | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 276 | # FIXME: Find nicer way to prohibit this. |
| 277 | config.substitutions.append( |
| 278 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 279 | config.substitutions.append( |
David Greene | 7b29345 | 2011-01-03 17:28:52 +0000 | [diff] [blame] | 280 | (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
Daniel Dunbar | 78c974f | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 281 | config.substitutions.append( |
Daniel Dunbar | 5618e98 | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 282 | (' clang-cc ', |
| 283 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 284 | config.substitutions.append( |
| 285 | (' clang -cc1 ', |
| 286 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | 8452ef0 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 287 | config.substitutions.append( |
| 288 | (' %clang-cc1 ', |
| 289 | """*** invalid substitution, use '%clang_cc1'. ***""") ) |
Hans Wennborg | 70850d8 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 290 | config.substitutions.append( |
| 291 | (' %clang-cpp ', |
| 292 | """*** invalid substitution, use '%clang_cpp'. ***""") ) |
Hans Wennborg | e4b031c | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 293 | config.substitutions.append( |
| 294 | (' %clang-cl ', |
| 295 | """*** invalid substitution, use '%clang_cl'. ***""") ) |
Daniel Dunbar | b44eb0b | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 296 | |
Paul Robinson | 5df175c | 2014-03-26 16:40:43 +0000 | [diff] [blame] | 297 | # For each occurrence of a clang tool name as its own word, replace it |
| 298 | # with the full path to the build directory holding that tool. This |
| 299 | # ensures that we are testing the tools just built and not some random |
| 300 | # tools that might happen to be in the user's PATH. |
| 301 | tool_dirs = os.path.pathsep.join((clang_tools_dir, llvm_tools_dir)) |
| 302 | |
| 303 | # Regex assertions to reject neighbor hyphens/dots (seen in some tests). |
| 304 | # For example, don't match 'clang-check-' or '.clang-format'. |
| 305 | NoPreHyphenDot = r"(?<!(-|\.))" |
| 306 | NoPostHyphenDot = r"(?!(-|\.))" |
| 307 | |
| 308 | for pattern in [r"\bFileCheck\b", |
| 309 | r"\bc-index-test\b", |
| 310 | NoPreHyphenDot + r"\bclang-check\b" + NoPostHyphenDot, |
| 311 | NoPreHyphenDot + r"\bclang-format\b" + NoPostHyphenDot, |
Alp Toker | ee77934 | 2014-05-05 06:42:07 +0000 | [diff] [blame] | 312 | NoPreHyphenDot + r"\bclang-interpreter\b" + NoPostHyphenDot, |
Paul Robinson | 5df175c | 2014-03-26 16:40:43 +0000 | [diff] [blame] | 313 | # FIXME: Some clang test uses opt? |
| 314 | NoPreHyphenDot + r"\bopt\b" + NoPostHyphenDot, |
| 315 | # Handle these specially as they are strings searched |
| 316 | # for during testing. |
| 317 | r"\| \bcount\b", |
| 318 | r"\| \bnot\b"]: |
| 319 | # Extract the tool name from the pattern. This relies on the tool |
| 320 | # name being surrounded by \b word match operators. If the |
| 321 | # pattern starts with "| ", include it in the string to be |
| 322 | # substituted. |
| 323 | tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
| 324 | pattern) |
| 325 | tool_pipe = tool_match.group(2) |
| 326 | tool_name = tool_match.group(4) |
| 327 | tool_path = lit.util.which(tool_name, tool_dirs) |
| 328 | if not tool_path: |
| 329 | # Warn, but still provide a substitution. |
| 330 | lit_config.note('Did not find ' + tool_name + ' in ' + tool_dirs) |
| 331 | tool_path = clang_tools_dir + '/' + tool_name |
| 332 | config.substitutions.append((pattern, tool_pipe + tool_path)) |
| 333 | |
Daniel Dunbar | b44eb0b | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 334 | ### |
| 335 | |
| 336 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 337 | # |
NAKAMURA Takumi | 1fb02cb | 2014-07-16 12:05:45 +0000 | [diff] [blame] | 338 | # Enabled/disabled features |
| 339 | if config.clang_staticanalyzer != 0: |
| 340 | config.available_features.add("staticanalyzer") |
| 341 | |
Andrew Trick | 3df2824 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 342 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 343 | if platform.system() not in ['FreeBSD']: |
| 344 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | f5ea88b | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 345 | |
| 346 | # Shell execution |
Reid Kleckner | 0675f85 | 2013-04-11 13:34:18 +0000 | [diff] [blame] | 347 | if execute_external: |
NAKAMURA Takumi | f5ea88b | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 348 | config.available_features.add('shell') |
Galina Kistanova | b38fd26 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 349 | |
NAKAMURA Takumi | 6c8127c | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 350 | # Exclude MSYS due to transforming '/' to 'X:/mingwroot/'. |
Hans Wennborg | dffe599 | 2013-08-05 20:14:43 +0000 | [diff] [blame] | 351 | if not platform.system() in ['Windows'] or not execute_external: |
NAKAMURA Takumi | 6c8127c | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 352 | config.available_features.add('shell-preserves-root') |
| 353 | |
Adrian Prantl | 4e2292e | 2014-02-20 17:53:17 +0000 | [diff] [blame] | 354 | # For tests that require Darwin to run. |
Adrian Prantl | 0e79c00 | 2014-02-20 19:51:46 +0000 | [diff] [blame] | 355 | # This is used by debuginfo-tests/*block*.m and debuginfo-tests/foreach.m. |
Adrian Prantl | 4e2292e | 2014-02-20 17:53:17 +0000 | [diff] [blame] | 356 | if platform.system() in ['Darwin']: |
| 357 | config.available_features.add('system-darwin') |
Andrea Di Biagio | e653811 | 2014-04-29 20:19:13 +0000 | [diff] [blame] | 358 | elif platform.system() in ['Windows']: |
| 359 | # For tests that require Windows to run. |
| 360 | config.available_features.add('system-windows') |
Adrian Prantl | 4e2292e | 2014-02-20 17:53:17 +0000 | [diff] [blame] | 361 | |
NAKAMURA Takumi | 6bbc981 | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 362 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | b59973e | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 363 | if platform.system() not in ['Windows']: |
| 364 | config.available_features.add('ansi-escape-sequences') |
| 365 | |
NAKAMURA Takumi | 0c81c71 | 2014-02-06 07:15:59 +0000 | [diff] [blame] | 366 | # Capability to print utf8 to the terminal. |
| 367 | # Windows expects codepage, unless Wide API. |
| 368 | if platform.system() not in ['Windows']: |
| 369 | config.available_features.add('utf8-capable-terminal') |
| 370 | |
Justin Bogner | a4fb799 | 2014-03-11 04:34:17 +0000 | [diff] [blame] | 371 | # Native compilation: Check if triples match. |
| 372 | # FIXME: Consider cases that target can be executed |
| 373 | # even if host_triple were different from target_triple. |
| 374 | if config.host_triple == config.target_triple: |
Amaury de la Vieuville | 7681afd | 2013-09-13 11:02:31 +0000 | [diff] [blame] | 375 | config.available_features.add("native") |
| 376 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 377 | # Case-insensitive file system |
| 378 | def is_filesystem_case_insensitive(): |
Argyrios Kyrtzidis | d6bdafc | 2012-11-01 00:59:15 +0000 | [diff] [blame] | 379 | handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) |
NAKAMURA Takumi | 77fcfe7 | 2013-07-01 09:51:55 +0000 | [diff] [blame] | 380 | isInsensitive = os.path.exists( |
| 381 | os.path.join( |
| 382 | os.path.dirname(path), |
| 383 | os.path.basename(path).upper() |
| 384 | )) |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 385 | os.close(handle) |
| 386 | os.remove(path) |
| 387 | return isInsensitive |
| 388 | |
| 389 | if is_filesystem_case_insensitive(): |
| 390 | config.available_features.add('case-insensitive-filesystem') |
| 391 | |
Daniel Dunbar | 5238559 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 392 | # Tests that require the /dev/fd filesystem. |
NAKAMURA Takumi | eb360a0 | 2012-11-27 05:25:41 +0000 | [diff] [blame] | 393 | 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] | 394 | config.available_features.add('dev-fd-fs') |
| 395 | |
NAKAMURA Takumi | d7a6004 | 2014-02-16 10:15:46 +0000 | [diff] [blame] | 396 | # DW2 Target |
| 397 | if not re.match(r'.*-win32$', config.target_triple): |
| 398 | config.available_features.add('dw2') |
| 399 | |
NAKAMURA Takumi | 0884887 | 2014-02-16 10:15:57 +0000 | [diff] [blame] | 400 | # Not set on native MS environment. |
| 401 | if not re.match(r'.*-win32$', config.target_triple): |
| 402 | config.available_features.add('non-ms-sdk') |
| 403 | |
NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 404 | # [PR8833] LLP64-incompatible tests |
| 405 | if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple): |
| 406 | config.available_features.add('LP64') |
| 407 | |
NAKAMURA Takumi | 556d713 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 408 | # [PR12920] "clang-driver" -- set if gcc driver is not used. |
| 409 | if not re.match(r'.*-(cygwin|mingw32)$', config.target_triple): |
| 410 | config.available_features.add('clang-driver') |
| 411 | |
NAKAMURA Takumi | 23c7671 | 2014-02-16 10:15:34 +0000 | [diff] [blame] | 412 | # [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 413 | # only if all handles were closed. |
| 414 | if platform.system() not in ['Windows']: |
| 415 | config.available_features.add('can-remove-opened-file') |
| 416 | |
NAKAMURA Takumi | 67eade6 | 2013-12-04 03:40:56 +0000 | [diff] [blame] | 417 | # Returns set of available features, registered-target(s) and asserts. |
| 418 | def get_llvm_config_props(): |
| 419 | set_of_features = set() |
| 420 | |
| 421 | cmd = subprocess.Popen( |
| 422 | [ |
| 423 | os.path.join(llvm_tools_dir, 'llvm-config'), |
| 424 | '--assertion-mode', |
| 425 | '--targets-built', |
| 426 | ], |
Scott Douglass | df914d5 | 2014-09-24 18:37:52 +0000 | [diff] [blame^] | 427 | stdout=subprocess.PIPE, |
| 428 | env=config.environment |
NAKAMURA Takumi | 67eade6 | 2013-12-04 03:40:56 +0000 | [diff] [blame] | 429 | ) |
| 430 | # 1st line corresponds to --assertion-mode, "ON" or "OFF". |
| 431 | line = cmd.stdout.readline().strip().decode('ascii') |
| 432 | if line == "ON": |
| 433 | set_of_features.add('asserts') |
| 434 | |
| 435 | # 2nd line corresponds to --targets-built, like; |
| 436 | # AArch64 ARM CppBackend X86 |
| 437 | for arch in cmd.stdout.readline().decode('ascii').split(): |
| 438 | set_of_features.add(arch.lower() + '-registered-target') |
| 439 | |
| 440 | return set_of_features |
| 441 | |
| 442 | config.available_features.update(get_llvm_config_props()) |
Dmitri Gribenko | 740c0fb | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 443 | |
| 444 | if lit.util.which('xmllint'): |
| 445 | config.available_features.add('xmllint') |
| 446 | |
Alexey Samsonov | 55b688f | 2013-03-26 08:28:18 +0000 | [diff] [blame] | 447 | # Sanitizers. |
| 448 | if config.llvm_use_sanitizer == "Address": |
| 449 | config.available_features.add("asan") |
Alexey Samsonov | b80effd | 2014-01-28 06:59:32 +0000 | [diff] [blame] | 450 | else: |
| 451 | config.available_features.add("not_asan") |
Alexey Samsonov | 55b688f | 2013-03-26 08:28:18 +0000 | [diff] [blame] | 452 | if (config.llvm_use_sanitizer == "Memory" or |
| 453 | config.llvm_use_sanitizer == "MemoryWithOrigins"): |
| 454 | config.available_features.add("msan") |
Alexey Samsonov | 3205b51 | 2014-09-03 19:46:32 +0000 | [diff] [blame] | 455 | if config.llvm_use_sanitizer == "Undefined": |
| 456 | config.available_features.add("ubsan") |
| 457 | else: |
| 458 | config.available_features.add("not_ubsan") |
Michael Gottesman | 6ef6e14 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 459 | |
| 460 | # Check if we should run long running tests. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 461 | if lit_config.params.get("run_long_tests", None) == "true": |
Michael Gottesman | 6ef6e14 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 462 | config.available_features.add("long_tests") |
David Dean | 9b9c78a | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 463 | |
| 464 | # Check if we should use gmalloc. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 465 | use_gmalloc_str = lit_config.params.get('use_gmalloc', None) |
David Dean | 9b9c78a | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 466 | if use_gmalloc_str is not None: |
| 467 | if use_gmalloc_str.lower() in ('1', 'true'): |
| 468 | use_gmalloc = True |
| 469 | elif use_gmalloc_str.lower() in ('', '0', 'false'): |
| 470 | use_gmalloc = False |
| 471 | else: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 472 | lit_config.fatal('user parameter use_gmalloc should be 0 or 1') |
David Dean | 9b9c78a | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 473 | else: |
| 474 | # Default to not using gmalloc |
| 475 | use_gmalloc = False |
| 476 | |
| 477 | # Allow use of an explicit path for gmalloc library. |
| 478 | # Will default to '/usr/lib/libgmalloc.dylib' if not set. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 479 | gmalloc_path_str = lit_config.params.get('gmalloc_path', |
| 480 | '/usr/lib/libgmalloc.dylib') |
David Dean | 9b9c78a | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 481 | if use_gmalloc: |
| 482 | config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str}) |
Daniel Dunbar | 184687b | 2013-11-06 21:44:54 +0000 | [diff] [blame] | 483 | |
Alexander Potapenko | 14f8ac0 | 2014-06-10 14:22:00 +0000 | [diff] [blame] | 484 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |