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 | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 9 | |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 10 | # Configuration file for the 'lit' test runner. |
| 11 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 12 | # name: The name of this test suite. |
| 13 | config.name = 'Clang' |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 14 | |
NAKAMURA Takumi | 98af1ac | 2011-02-09 04:19:57 +0000 | [diff] [blame] | 15 | # Tweak PATH for Win32 |
| 16 | if platform.system() == 'Windows': |
| 17 | # Seek sane tools in directories and set to $PATH. |
| 18 | path = getattr(config, 'lit_tools_dir', None) |
| 19 | path = lit.getToolsPath(path, |
| 20 | config.environment['PATH'], |
| 21 | ['cmp.exe', 'grep.exe', 'sed.exe']) |
| 22 | if path is not None: |
| 23 | path = os.path.pathsep.join((path, |
| 24 | config.environment['PATH'])) |
| 25 | config.environment['PATH'] = path |
| 26 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 27 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 28 | # |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 29 | # For now we require '&&' between commands, until they get globally killed and |
| 30 | # the test runner updated. |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 31 | execute_external = (platform.system() != 'Windows' |
| 32 | or lit.getBashPath() not in [None, ""]) |
Daniel Dunbar | bc20ef3 | 2009-11-08 01:47:35 +0000 | [diff] [blame] | 33 | config.test_format = lit.formats.ShTest(execute_external) |
Daniel Dunbar | 6827f3f | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 34 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 35 | # suffixes: A list of file extensions to treat as test files. |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 36 | config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s'] |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 37 | |
| 38 | # test_source_root: The root path where tests are located. |
| 39 | config.test_source_root = os.path.dirname(__file__) |
| 40 | |
| 41 | # test_exec_root: The root path where tests should be run. |
| 42 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 43 | if clang_obj_root is not None: |
| 44 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 45 | |
| 46 | # Set llvm_{src,obj}_root for use by others. |
| 47 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 48 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 49 | |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 50 | # Clear some environment variables that might affect Clang. |
| 51 | # |
| 52 | # This first set of vars are read by Clang, but shouldn't affect tests |
| 53 | # that aren't specifically looking for these features, or are required |
| 54 | # simply to run the tests at all. |
| 55 | # |
| 56 | # FIXME: Should we have a tool that enforces this? |
| 57 | |
| 58 | # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', |
| 59 | # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', |
| 60 | # 'IOS_SIMULATOR_DEPLOYMENT_TARGET', |
| 61 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 62 | # 'VC80COMNTOOLS') |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 63 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 64 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 65 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 66 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 67 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 68 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 69 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 70 | 'LIBCLANG_RESOURCE_USAGE', |
NAKAMURA Takumi | 79c5f95 | 2012-04-07 01:02:53 +0000 | [diff] [blame] | 71 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 72 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 73 | if platform.system() != 'Windows': |
| 74 | possibly_dangerous_env_vars.append('INCLUDE') |
Jordy Rose | 40f45ee | 2012-04-06 18:14:01 +0000 | [diff] [blame] | 75 | for name in possibly_dangerous_env_vars: |
| 76 | if name in config.environment: |
| 77 | del config.environment[name] |
| 78 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 79 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 80 | if clang_obj_root is not None: |
| 81 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 82 | if not llvm_tools_dir: |
| 83 | lit.fatal('No LLVM tools dir set!') |
Daniel Dunbar | ee45d6d | 2009-09-24 06:31:08 +0000 | [diff] [blame] | 84 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 85 | config.environment['PATH'] = path |
| 86 | |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 87 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 88 | if not llvm_libs_dir: |
| 89 | lit.fatal('No LLVM libs dir set!') |
| 90 | path = os.path.pathsep.join((llvm_libs_dir, |
| 91 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 92 | config.environment['LD_LIBRARY_PATH'] = path |
| 93 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 94 | ### |
| 95 | |
| 96 | # Check that the object root is known. |
| 97 | if config.test_exec_root is None: |
| 98 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 99 | # probably trying to run on a test file directly, and either the site |
| 100 | # configuration hasn't been created by the build system, or we are in an |
| 101 | # out-of-tree build situation). |
| 102 | |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 103 | # Check for 'clang_site_config' user parameter, and use that if available. |
| 104 | site_cfg = lit.params.get('clang_site_config', None) |
| 105 | if site_cfg and os.path.exists(site_cfg): |
| 106 | lit.load_config(config, site_cfg) |
| 107 | raise SystemExit |
| 108 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 109 | # Try to detect the situation where we are using an out-of-tree build by |
| 110 | # looking for 'llvm-config'. |
| 111 | # |
| 112 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 113 | # 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] | 114 | # build situation. This means knowing how to invoke the build system though, |
| 115 | # and I decided it was too much magic. We should solve this by just having |
| 116 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 117 | |
| 118 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 119 | if not llvm_config: |
| 120 | lit.fatal('No site specific configuration available!') |
| 121 | |
| 122 | # Get the source and object roots. |
| 123 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 124 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 125 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 126 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 127 | |
| 128 | # Validate that we got a tree which points to here, using the standard |
| 129 | # tools/clang layout. |
| 130 | this_src_root = os.path.dirname(config.test_source_root) |
| 131 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
| 132 | lit.fatal('No site specific configuration available!') |
| 133 | |
| 134 | # Check that the site specific configuration exists. |
| 135 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 136 | if not os.path.exists(site_cfg): |
Nico Weber | b4a88ef | 2010-09-27 20:40:32 +0000 | [diff] [blame] | 137 | lit.fatal('No site specific configuration available! You may need to ' |
| 138 | 'run "make test" in your Clang build directory.') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 139 | |
| 140 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 141 | lit.note('using out-of-tree build at %r' % clang_obj_root) |
| 142 | lit.load_config(config, site_cfg) |
| 143 | raise SystemExit |
| 144 | |
| 145 | ### |
| 146 | |
| 147 | # Discover the 'clang' and 'clangcc' to use. |
| 148 | |
| 149 | import os |
| 150 | |
| 151 | def inferClang(PATH): |
| 152 | # Determine which clang to use. |
| 153 | clang = os.getenv('CLANG') |
| 154 | |
| 155 | # If the user set clang in the environment, definitely use that and don't |
| 156 | # try to validate. |
| 157 | if clang: |
| 158 | return clang |
| 159 | |
| 160 | # Otherwise look in the path. |
| 161 | clang = lit.util.which('clang', PATH) |
| 162 | |
| 163 | if not clang: |
| 164 | lit.fatal("couldn't find 'clang' program, try setting " |
| 165 | "CLANG in your environment") |
| 166 | |
| 167 | return clang |
| 168 | |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 169 | config.clang = inferClang(config.environment['PATH']).replace('\\', '/') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 170 | if not lit.quiet: |
| 171 | lit.note('using clang: %r' % config.clang) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 172 | |
| 173 | # Note that when substituting %clang_cc1 also fill in the include directory of |
| 174 | # the builtin headers. Those are part of even a freestanding environment, but |
| 175 | # Clang relies on the driver to locate them. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 176 | def getClangBuiltinIncludeDir(clang): |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 177 | # FIXME: Rather than just getting the version, we should have clang print |
| 178 | # out its resource dir here in an easy to scrape form. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 179 | cmd = subprocess.Popen([clang, '-print-file-name=include'], |
| 180 | stdout=subprocess.PIPE) |
| 181 | if not cmd.stdout: |
| 182 | lit.fatal("Couldn't find the include dir for Clang ('%s')" % clang) |
| 183 | return cmd.stdout.read().strip() |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 184 | |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 185 | config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s' |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 186 | % (config.clang, |
| 187 | getClangBuiltinIncludeDir(config.clang))) ) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 188 | |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 189 | config.substitutions.append( ('%clangxx', ' ' + config.clang + |
Rafael Espindola | d2d4d68 | 2012-10-30 00:13:16 +0000 | [diff] [blame] | 190 | ' -ccc-cxx ')) |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 191 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Devang Patel | 8c6b913 | 2010-09-13 20:46:23 +0000 | [diff] [blame] | 192 | 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] | 193 | |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 194 | # FIXME: Find nicer way to prohibit this. |
| 195 | config.substitutions.append( |
| 196 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 197 | config.substitutions.append( |
David Greene | 431feb5 | 2011-01-03 17:28:52 +0000 | [diff] [blame] | 198 | (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
Daniel Dunbar | 679d605 | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 199 | config.substitutions.append( |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 200 | (' clang-cc ', |
| 201 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 202 | config.substitutions.append( |
| 203 | (' clang -cc1 ', |
| 204 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 205 | config.substitutions.append( |
| 206 | (' %clang-cc1 ', |
| 207 | """*** invalid substitution, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | db91864 | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 208 | |
| 209 | ### |
| 210 | |
| 211 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 6da28e2 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 212 | # |
| 213 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 214 | if platform.system() not in ['FreeBSD']: |
| 215 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 216 | |
| 217 | # Shell execution |
| 218 | if platform.system() not in ['Windows'] or lit.getBashPath() != '': |
| 219 | config.available_features.add('shell') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 220 | |
Alexander Potapenko | 087c65f | 2012-09-20 10:10:01 +0000 | [diff] [blame] | 221 | # For tests that require Darwin to run. |
| 222 | if platform.system() in ['Darwin']: |
| 223 | config.available_features.add('system-darwin') |
| 224 | |
NAKAMURA Takumi | 5e3d24c | 2012-09-12 10:38:03 +0000 | [diff] [blame] | 225 | # ANSI escape sequences in non-dumb terminal |
NAKAMURA Takumi | 0ca4be3 | 2012-07-11 11:44:00 +0000 | [diff] [blame] | 226 | if platform.system() not in ['Windows']: |
| 227 | config.available_features.add('ansi-escape-sequences') |
| 228 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 229 | # Case-insensitive file system |
| 230 | def is_filesystem_case_insensitive(): |
Argyrios Kyrtzidis | b2ed96a | 2012-11-01 00:59:15 +0000 | [diff] [blame] | 231 | handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 232 | isInsensitive = os.path.exists(path.upper()) |
| 233 | os.close(handle) |
| 234 | os.remove(path) |
| 235 | return isInsensitive |
| 236 | |
| 237 | if is_filesystem_case_insensitive(): |
| 238 | config.available_features.add('case-insensitive-filesystem') |
| 239 | |
Daniel Dunbar | 0b95bd0 | 2012-11-15 20:06:10 +0000 | [diff] [blame] | 240 | # Tests that require the /dev/fd filesystem. |
NAKAMURA Takumi | 93308b9 | 2012-11-27 05:25:41 +0000 | [diff] [blame] | 241 | 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] | 242 | config.available_features.add('dev-fd-fs') |
| 243 | |
NAKAMURA Takumi | b774d73 | 2012-09-12 10:45:40 +0000 | [diff] [blame] | 244 | # [PR8833] LLP64-incompatible tests |
| 245 | if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple): |
| 246 | config.available_features.add('LP64') |
| 247 | |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 248 | # Registered Targets |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 249 | def get_llc_props(tool): |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 250 | set_of_targets = set() |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 251 | enable_assertions = False |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 252 | |
| 253 | cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE) |
| 254 | |
| 255 | # Parse the stdout to get the list of registered targets. |
| 256 | parse_targets = False |
| 257 | for line in cmd.stdout: |
| 258 | if parse_targets: |
| 259 | m = re.match( r'(.*) - ', line) |
| 260 | if m is not None: |
| 261 | set_of_targets.add(m.group(1).strip() + '-registered-target') |
| 262 | else: |
| 263 | break |
| 264 | elif "Registered Targets:" in line: |
| 265 | parse_targets = True |
| 266 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 267 | if re.search(r'with assertions', line): |
| 268 | enable_assertions = True |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 269 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 270 | return {"set_of_targets": set_of_targets, |
| 271 | "enable_assertions": enable_assertions} |
| 272 | |
| 273 | llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc')) |
| 274 | if len(llc_props['set_of_targets']) > 0: |
| 275 | config.available_features.update(llc_props['set_of_targets']) |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 276 | else: |
| 277 | lit.fatal('No Targets Registered with the LLVM Tools!') |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 278 | |
| 279 | if llc_props['enable_assertions']: |
| 280 | config.available_features.add('asserts') |
Dmitri Gribenko | f303d4c | 2012-08-07 17:54:38 +0000 | [diff] [blame] | 281 | |
| 282 | if lit.util.which('xmllint'): |
| 283 | config.available_features.add('xmllint') |
| 284 | |