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. |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 47 | config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s'] |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 48 | |
| 49 | # test_source_root: The root path where tests are located. |
| 50 | config.test_source_root = os.path.dirname(__file__) |
| 51 | |
| 52 | # test_exec_root: The root path where tests should be run. |
| 53 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 54 | if clang_obj_root is not None: |
| 55 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 56 | |
| 57 | # Set llvm_{src,obj}_root for use by others. |
| 58 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 59 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 60 | |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 61 | # Clear some environment variables that might affect Clang. |
| 62 | # |
| 63 | # This first set of vars are read by Clang, but shouldn't affect tests |
| 64 | # that aren't specifically looking for these features, or are required |
| 65 | # simply to run the tests at all. |
| 66 | # |
| 67 | # FIXME: Should we have a tool that enforces this? |
| 68 | |
| 69 | # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', |
| 70 | # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', |
| 71 | # 'IOS_SIMULATOR_DEPLOYMENT_TARGET', |
| 72 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 73 | # 'VC80COMNTOOLS') |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 74 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 75 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 76 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 77 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 78 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 79 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 80 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 81 | 'LIBCLANG_RESOURCE_USAGE', |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 82 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 83 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 84 | if platform.system() != 'Windows': |
| 85 | possibly_dangerous_env_vars.append('INCLUDE') |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 86 | for name in possibly_dangerous_env_vars: |
| 87 | if name in config.environment: |
| 88 | del config.environment[name] |
| 89 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 90 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 91 | if clang_obj_root is not None: |
| 92 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 93 | if not llvm_tools_dir: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 94 | lit_config.fatal('No LLVM tools dir set!') |
Daniel Dunbar | ee45d6d | 2009-09-24 06:31:08 +0000 | [diff] [blame] | 95 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 96 | config.environment['PATH'] = path |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 97 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 98 | if not llvm_libs_dir: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 99 | lit_config.fatal('No LLVM libs dir set!') |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 100 | path = os.path.pathsep.join((llvm_libs_dir, |
| 101 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 102 | config.environment['LD_LIBRARY_PATH'] = path |
| 103 | |
Alexey Samsonov | 32d2a65 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 104 | # Propagate path to symbolizer for ASan/MSan. |
| 105 | for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: |
| 106 | if symbolizer in os.environ: |
| 107 | config.environment[symbolizer] = os.environ[symbolizer] |
| 108 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 109 | ### |
| 110 | |
| 111 | # Check that the object root is known. |
| 112 | if config.test_exec_root is None: |
| 113 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 114 | # probably trying to run on a test file directly, and either the site |
| 115 | # configuration hasn't been created by the build system, or we are in an |
| 116 | # out-of-tree build situation). |
| 117 | |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 118 | # Check for 'clang_site_config' user parameter, and use that if available. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 119 | site_cfg = lit_config.params.get('clang_site_config', None) |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 120 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 121 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 122 | raise SystemExit |
| 123 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 124 | # Try to detect the situation where we are using an out-of-tree build by |
| 125 | # looking for 'llvm-config'. |
| 126 | # |
| 127 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 128 | # 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] | 129 | # build situation. This means knowing how to invoke the build system though, |
| 130 | # and I decided it was too much magic. We should solve this by just having |
| 131 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 132 | |
| 133 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 134 | if not llvm_config: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 135 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 136 | |
| 137 | # Get the source and object roots. |
| 138 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 139 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 140 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 141 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 142 | |
| 143 | # Validate that we got a tree which points to here, using the standard |
| 144 | # tools/clang layout. |
| 145 | this_src_root = os.path.dirname(config.test_source_root) |
| 146 | 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] | 147 | lit_config.fatal('No site specific configuration available!') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 148 | |
| 149 | # Check that the site specific configuration exists. |
| 150 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 151 | if not os.path.exists(site_cfg): |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 152 | lit_config.fatal( |
| 153 | 'No site specific configuration available! You may need to ' |
| 154 | 'run "make test" in your Clang build directory.') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 155 | |
| 156 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 157 | lit_config.note('using out-of-tree build at %r' % clang_obj_root) |
| 158 | lit_config.load_config(config, site_cfg) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 159 | raise SystemExit |
| 160 | |
| 161 | ### |
| 162 | |
| 163 | # Discover the 'clang' and 'clangcc' to use. |
| 164 | |
| 165 | import os |
| 166 | |
| 167 | def inferClang(PATH): |
| 168 | # Determine which clang to use. |
| 169 | clang = os.getenv('CLANG') |
| 170 | |
| 171 | # If the user set clang in the environment, definitely use that and don't |
| 172 | # try to validate. |
| 173 | if clang: |
| 174 | return clang |
| 175 | |
| 176 | # Otherwise look in the path. |
| 177 | clang = lit.util.which('clang', PATH) |
| 178 | |
| 179 | if not clang: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 180 | lit_config.fatal("couldn't find 'clang' program, try setting " |
| 181 | "CLANG in your environment") |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 182 | |
| 183 | return clang |
| 184 | |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 185 | config.clang = inferClang(config.environment['PATH']).replace('\\', '/') |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 186 | if not lit_config.quiet: |
| 187 | lit_config.note('using clang: %r' % config.clang) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 188 | |
| 189 | # Note that when substituting %clang_cc1 also fill in the include directory of |
| 190 | # the builtin headers. Those are part of even a freestanding environment, but |
| 191 | # Clang relies on the driver to locate them. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 192 | def getClangBuiltinIncludeDir(clang): |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 193 | # FIXME: Rather than just getting the version, we should have clang print |
| 194 | # out its resource dir here in an easy to scrape form. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 195 | cmd = subprocess.Popen([clang, '-print-file-name=include'], |
| 196 | stdout=subprocess.PIPE) |
| 197 | if not cmd.stdout: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 198 | 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] | 199 | dir = cmd.stdout.read().strip() |
| 200 | if sys.platform in ['win32'] and execute_external: |
| 201 | # Don't pass dosish path separator to msys bash.exe. |
| 202 | dir = dir.replace('\\', '/') |
Daniel Dunbar | 03f443a | 2013-08-14 16:32:20 +0000 | [diff] [blame] | 203 | # Ensure the result is an ascii string, across Python2.5+ - Python3. |
| 204 | return str(dir.decode('ascii')) |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 205 | |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 206 | config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s' |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 207 | % (config.clang, |
| 208 | getClangBuiltinIncludeDir(config.clang))) ) |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 209 | config.substitutions.append( ('%clang_cpp', ' ' + config.clang + |
| 210 | ' --driver-mode=cpp ')) |
Hans Wennborg | c2f531a | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 211 | config.substitutions.append( ('%clang_cl', ' ' + config.clang + |
| 212 | ' --driver-mode=cl ')) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 213 | config.substitutions.append( ('%clangxx', ' ' + config.clang + |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 214 | ' --driver-mode=g++ ')) |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 215 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Devang Patel | 8c6b913 | 2010-09-13 20:46:23 +0000 | [diff] [blame] | 216 | config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') ) |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 218 | # FIXME: Find nicer way to prohibit this. |
| 219 | config.substitutions.append( |
| 220 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 221 | config.substitutions.append( |
David Greene | 431feb5 | 2011-01-03 17:28:52 +0000 | [diff] [blame] | 222 | (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
Daniel Dunbar | 679d605 | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 223 | config.substitutions.append( |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 224 | (' clang-cc ', |
| 225 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 226 | config.substitutions.append( |
| 227 | (' clang -cc1 ', |
| 228 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 229 | config.substitutions.append( |
| 230 | (' %clang-cc1 ', |
| 231 | """*** invalid substitution, use '%clang_cc1'. ***""") ) |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 232 | config.substitutions.append( |
| 233 | (' %clang-cpp ', |
| 234 | """*** invalid substitution, use '%clang_cpp'. ***""") ) |
Hans Wennborg | c2f531a | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 235 | config.substitutions.append( |
| 236 | (' %clang-cl ', |
| 237 | """*** invalid substitution, use '%clang_cl'. ***""") ) |
Daniel Dunbar | db91864 | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 238 | |
| 239 | ### |
| 240 | |
| 241 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 6da28e2 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 242 | # |
| 243 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 244 | if platform.system() not in ['FreeBSD']: |
| 245 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 246 | |
| 247 | # Shell execution |
Reid Kleckner | a53763f | 2013-04-11 13:34:18 +0000 | [diff] [blame] | 248 | if execute_external: |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 249 | config.available_features.add('shell') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 250 | |
NAKAMURA Takumi | 05a10ff | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 251 | # Exclude MSYS due to transforming '/' to 'X:/mingwroot/'. |
Hans Wennborg | de56bb7 | 2013-08-05 20:14:43 +0000 | [diff] [blame] | 252 | if not platform.system() in ['Windows'] or not execute_external: |
NAKAMURA Takumi | 05a10ff | 2013-01-16 06:10:16 +0000 | [diff] [blame] | 253 | config.available_features.add('shell-preserves-root') |
| 254 | |
NAKAMURA Takumi | 5e3d24c | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 255 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | 0ca4be3 | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 256 | if platform.system() not in ['Windows']: |
| 257 | config.available_features.add('ansi-escape-sequences') |
| 258 | |
Amaury de la Vieuville | 0909859 | 2013-09-13 11:02:31 +0000 | [diff] [blame] | 259 | # Native compilation: host arch == target arch |
| 260 | if config.host_arch in config.target_triple: |
| 261 | config.available_features.add("native") |
| 262 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 263 | # Case-insensitive file system |
| 264 | def is_filesystem_case_insensitive(): |
Argyrios Kyrtzidis | b2ed96a | 2012-11-01 00:59:15 +0000 | [diff] [blame] | 265 | handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) |
NAKAMURA Takumi | 80db6a7 | 2013-07-01 09:51:55 +0000 | [diff] [blame] | 266 | isInsensitive = os.path.exists( |
| 267 | os.path.join( |
| 268 | os.path.dirname(path), |
| 269 | os.path.basename(path).upper() |
| 270 | )) |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 271 | os.close(handle) |
| 272 | os.remove(path) |
| 273 | return isInsensitive |
| 274 | |
| 275 | if is_filesystem_case_insensitive(): |
| 276 | config.available_features.add('case-insensitive-filesystem') |
| 277 | |
Daniel Dunbar | 0b95bd0 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 278 | # Tests that require the /dev/fd filesystem. |
NAKAMURA Takumi | 93308b9 | 2012-11-27 05:25:41 +0000 | [diff] [blame] | 279 | 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] | 280 | config.available_features.add('dev-fd-fs') |
| 281 | |
NAKAMURA Takumi | b774d73 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 282 | # [PR8833] LLP64-incompatible tests |
| 283 | if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple): |
| 284 | config.available_features.add('LP64') |
| 285 | |
NAKAMURA Takumi | 5e4ccb4 | 2012-12-11 07:06:09 +0000 | [diff] [blame] | 286 | # [PR12920] "clang-driver" -- set if gcc driver is not used. |
| 287 | if not re.match(r'.*-(cygwin|mingw32)$', config.target_triple): |
| 288 | config.available_features.add('clang-driver') |
| 289 | |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 290 | # Registered Targets |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 291 | def get_llc_props(tool): |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 292 | set_of_targets = set() |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 293 | enable_assertions = False |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 294 | |
| 295 | cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE) |
| 296 | |
| 297 | # Parse the stdout to get the list of registered targets. |
| 298 | parse_targets = False |
| 299 | for line in cmd.stdout: |
Daniel Dunbar | 0cf153b | 2013-08-09 00:45:18 +0000 | [diff] [blame] | 300 | line = line.decode('ascii') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 301 | if parse_targets: |
| 302 | m = re.match( r'(.*) - ', line) |
| 303 | if m is not None: |
| 304 | set_of_targets.add(m.group(1).strip() + '-registered-target') |
| 305 | else: |
| 306 | break |
| 307 | elif "Registered Targets:" in line: |
| 308 | parse_targets = True |
| 309 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 310 | if re.search(r'with assertions', line): |
| 311 | enable_assertions = True |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 312 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 313 | return {"set_of_targets": set_of_targets, |
| 314 | "enable_assertions": enable_assertions} |
| 315 | |
| 316 | llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc')) |
| 317 | if len(llc_props['set_of_targets']) > 0: |
| 318 | config.available_features.update(llc_props['set_of_targets']) |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 319 | else: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 320 | lit_config.fatal('No Targets Registered with the LLVM Tools!') |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 321 | |
| 322 | if llc_props['enable_assertions']: |
| 323 | config.available_features.add('asserts') |
Dmitri Gribenko | f303d4c | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 324 | |
| 325 | if lit.util.which('xmllint'): |
| 326 | config.available_features.add('xmllint') |
| 327 | |
Alexey Samsonov | 48c0834 | 2013-03-26 08:28:18 +0000 | [diff] [blame] | 328 | # Sanitizers. |
| 329 | if config.llvm_use_sanitizer == "Address": |
| 330 | config.available_features.add("asan") |
| 331 | if (config.llvm_use_sanitizer == "Memory" or |
| 332 | config.llvm_use_sanitizer == "MemoryWithOrigins"): |
| 333 | config.available_features.add("msan") |
Michael Gottesman | 63f4050 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 334 | |
| 335 | # Check if we should run long running tests. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 336 | if lit_config.params.get("run_long_tests", None) == "true": |
Michael Gottesman | 63f4050 | 2013-06-19 23:23:49 +0000 | [diff] [blame] | 337 | config.available_features.add("long_tests") |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 338 | |
| 339 | # Check if we should use gmalloc. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 340 | use_gmalloc_str = lit_config.params.get('use_gmalloc', None) |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 341 | if use_gmalloc_str is not None: |
| 342 | if use_gmalloc_str.lower() in ('1', 'true'): |
| 343 | use_gmalloc = True |
| 344 | elif use_gmalloc_str.lower() in ('', '0', 'false'): |
| 345 | use_gmalloc = False |
| 346 | else: |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 347 | lit_config.fatal('user parameter use_gmalloc should be 0 or 1') |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 348 | else: |
| 349 | # Default to not using gmalloc |
| 350 | use_gmalloc = False |
| 351 | |
| 352 | # Allow use of an explicit path for gmalloc library. |
| 353 | # Will default to '/usr/lib/libgmalloc.dylib' if not set. |
Daniel Dunbar | 4c87ca4 | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 354 | gmalloc_path_str = lit_config.params.get('gmalloc_path', |
| 355 | '/usr/lib/libgmalloc.dylib') |
David Dean | 22d017d | 2013-07-11 23:37:50 +0000 | [diff] [blame] | 356 | |
| 357 | if use_gmalloc: |
| 358 | config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str}) |