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 |
| 7 | |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 8 | |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 9 | # Configuration file for the 'lit' test runner. |
| 10 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 11 | # name: The name of this test suite. |
| 12 | config.name = 'Clang' |
Daniel Dunbar | 724827f | 2009-09-08 16:39:23 +0000 | [diff] [blame] | 13 | |
NAKAMURA Takumi | 98af1ac | 2011-02-09 04:19:57 +0000 | [diff] [blame] | 14 | # Tweak PATH for Win32 |
| 15 | if platform.system() == 'Windows': |
| 16 | # Seek sane tools in directories and set to $PATH. |
| 17 | path = getattr(config, 'lit_tools_dir', None) |
| 18 | path = lit.getToolsPath(path, |
| 19 | config.environment['PATH'], |
| 20 | ['cmp.exe', 'grep.exe', 'sed.exe']) |
| 21 | if path is not None: |
| 22 | path = os.path.pathsep.join((path, |
| 23 | config.environment['PATH'])) |
| 24 | config.environment['PATH'] = path |
| 25 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 26 | # testFormat: The test format to use to interpret tests. |
Daniel Dunbar | 1db467f | 2009-07-31 05:54:17 +0000 | [diff] [blame] | 27 | # |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 28 | # For now we require '&&' between commands, until they get globally killed and |
| 29 | # the test runner updated. |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 30 | execute_external = (platform.system() != 'Windows' |
| 31 | or lit.getBashPath() not in [None, ""]) |
Daniel Dunbar | bc20ef3 | 2009-11-08 01:47:35 +0000 | [diff] [blame] | 32 | config.test_format = lit.formats.ShTest(execute_external) |
Daniel Dunbar | 6827f3f | 2009-09-06 01:31:12 +0000 | [diff] [blame] | 33 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 34 | # suffixes: A list of file extensions to treat as test files. |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 35 | config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl'] |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 36 | |
| 37 | # test_source_root: The root path where tests are located. |
| 38 | config.test_source_root = os.path.dirname(__file__) |
| 39 | |
| 40 | # test_exec_root: The root path where tests should be run. |
| 41 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 42 | if clang_obj_root is not None: |
| 43 | config.test_exec_root = os.path.join(clang_obj_root, 'test') |
| 44 | |
| 45 | # Set llvm_{src,obj}_root for use by others. |
| 46 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 47 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 48 | |
| 49 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 50 | if clang_obj_root is not None: |
| 51 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 52 | if not llvm_tools_dir: |
| 53 | lit.fatal('No LLVM tools dir set!') |
Daniel Dunbar | ee45d6d | 2009-09-24 06:31:08 +0000 | [diff] [blame] | 54 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 55 | config.environment['PATH'] = path |
| 56 | |
Daniel Dunbar | 9e10cc7 | 2009-09-26 07:36:09 +0000 | [diff] [blame] | 57 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 58 | if not llvm_libs_dir: |
| 59 | lit.fatal('No LLVM libs dir set!') |
| 60 | path = os.path.pathsep.join((llvm_libs_dir, |
| 61 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 62 | config.environment['LD_LIBRARY_PATH'] = path |
| 63 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 64 | ### |
| 65 | |
| 66 | # Check that the object root is known. |
| 67 | if config.test_exec_root is None: |
| 68 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 69 | # probably trying to run on a test file directly, and either the site |
| 70 | # configuration hasn't been created by the build system, or we are in an |
| 71 | # out-of-tree build situation). |
| 72 | |
Daniel Dunbar | b258d8f | 2009-11-05 16:36:19 +0000 | [diff] [blame] | 73 | # Check for 'clang_site_config' user parameter, and use that if available. |
| 74 | site_cfg = lit.params.get('clang_site_config', None) |
| 75 | if site_cfg and os.path.exists(site_cfg): |
| 76 | lit.load_config(config, site_cfg) |
| 77 | raise SystemExit |
| 78 | |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 79 | # Try to detect the situation where we are using an out-of-tree build by |
| 80 | # looking for 'llvm-config'. |
| 81 | # |
| 82 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 83 | # 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] | 84 | # build situation. This means knowing how to invoke the build system though, |
| 85 | # and I decided it was too much magic. We should solve this by just having |
| 86 | # the .cfg files generated during the configuration step. |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 87 | |
| 88 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 89 | if not llvm_config: |
| 90 | lit.fatal('No site specific configuration available!') |
| 91 | |
| 92 | # Get the source and object roots. |
| 93 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 94 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 95 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 96 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 97 | |
| 98 | # Validate that we got a tree which points to here, using the standard |
| 99 | # tools/clang layout. |
| 100 | this_src_root = os.path.dirname(config.test_source_root) |
| 101 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
| 102 | lit.fatal('No site specific configuration available!') |
| 103 | |
| 104 | # Check that the site specific configuration exists. |
| 105 | site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') |
| 106 | if not os.path.exists(site_cfg): |
Nico Weber | b4a88ef | 2010-09-27 20:40:32 +0000 | [diff] [blame] | 107 | lit.fatal('No site specific configuration available! You may need to ' |
| 108 | 'run "make test" in your Clang build directory.') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 109 | |
| 110 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 111 | lit.note('using out-of-tree build at %r' % clang_obj_root) |
| 112 | lit.load_config(config, site_cfg) |
| 113 | raise SystemExit |
| 114 | |
| 115 | ### |
| 116 | |
| 117 | # Discover the 'clang' and 'clangcc' to use. |
| 118 | |
| 119 | import os |
| 120 | |
| 121 | def inferClang(PATH): |
| 122 | # Determine which clang to use. |
| 123 | clang = os.getenv('CLANG') |
| 124 | |
| 125 | # If the user set clang in the environment, definitely use that and don't |
| 126 | # try to validate. |
| 127 | if clang: |
| 128 | return clang |
| 129 | |
| 130 | # Otherwise look in the path. |
| 131 | clang = lit.util.which('clang', PATH) |
| 132 | |
| 133 | if not clang: |
| 134 | lit.fatal("couldn't find 'clang' program, try setting " |
| 135 | "CLANG in your environment") |
| 136 | |
| 137 | return clang |
| 138 | |
Daniel Dunbar | e1fa096 | 2010-03-20 21:13:08 +0000 | [diff] [blame] | 139 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 140 | # can check it with XFAIL and XTARGET. |
| 141 | if lit.useValgrind: |
| 142 | config.target_triple += '-vg' |
| 143 | |
NAKAMURA Takumi | 9085e6f | 2011-03-05 11:16:06 +0000 | [diff] [blame] | 144 | config.clang = inferClang(config.environment['PATH']).replace('\\', '/') |
Daniel Dunbar | 5e01e3c | 2009-09-22 05:16:02 +0000 | [diff] [blame] | 145 | if not lit.quiet: |
| 146 | lit.note('using clang: %r' % config.clang) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 147 | |
| 148 | # Note that when substituting %clang_cc1 also fill in the include directory of |
| 149 | # the builtin headers. Those are part of even a freestanding environment, but |
| 150 | # Clang relies on the driver to locate them. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 151 | def getClangBuiltinIncludeDir(clang): |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 152 | # FIXME: Rather than just getting the version, we should have clang print |
| 153 | # out its resource dir here in an easy to scrape form. |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 154 | cmd = subprocess.Popen([clang, '-print-file-name=include'], |
| 155 | stdout=subprocess.PIPE) |
| 156 | if not cmd.stdout: |
| 157 | lit.fatal("Couldn't find the include dir for Clang ('%s')" % clang) |
| 158 | return cmd.stdout.read().strip() |
Chandler Carruth | b40fd3f | 2011-11-05 20:55:50 +0000 | [diff] [blame] | 159 | |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 160 | config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s' |
Chandler Carruth | df0a4c3 | 2011-11-05 23:29:28 +0000 | [diff] [blame] | 161 | % (config.clang, |
| 162 | getClangBuiltinIncludeDir(config.clang))) ) |
Chandler Carruth | 044a790c | 2011-11-05 10:15:27 +0000 | [diff] [blame] | 163 | |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 164 | config.substitutions.append( ('%clangxx', ' ' + config.clang + |
| 165 | ' -ccc-clang-cxx -ccc-cxx ')) |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 166 | config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) |
Devang Patel | 8c6b913 | 2010-09-13 20:46:23 +0000 | [diff] [blame] | 167 | 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] | 168 | |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 169 | # FIXME: Find nicer way to prohibit this. |
| 170 | config.substitutions.append( |
| 171 | (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) |
| 172 | config.substitutions.append( |
David Greene | 431feb5 | 2011-01-03 17:28:52 +0000 | [diff] [blame] | 173 | (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) |
Daniel Dunbar | 679d605 | 2010-02-17 20:31:01 +0000 | [diff] [blame] | 174 | config.substitutions.append( |
Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 175 | (' clang-cc ', |
| 176 | """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) |
| 177 | config.substitutions.append( |
| 178 | (' clang -cc1 ', |
| 179 | """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | 9fde9c4 | 2010-06-29 16:52:24 +0000 | [diff] [blame] | 180 | config.substitutions.append( |
| 181 | (' %clang-cc1 ', |
| 182 | """*** invalid substitution, use '%clang_cc1'. ***""") ) |
Daniel Dunbar | db91864 | 2010-08-24 21:39:55 +0000 | [diff] [blame] | 183 | |
| 184 | ### |
| 185 | |
| 186 | # Set available features we allow tests to conditionalize on. |
Andrew Trick | 6da28e2 | 2011-08-26 22:46:31 +0000 | [diff] [blame] | 187 | # |
| 188 | # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 189 | if platform.system() not in ['FreeBSD']: |
| 190 | config.available_features.add('crash-recovery') |
NAKAMURA Takumi | ef34d77 | 2011-02-28 09:41:07 +0000 | [diff] [blame] | 191 | |
| 192 | # Shell execution |
| 193 | if platform.system() not in ['Windows'] or lit.getBashPath() != '': |
| 194 | config.available_features.add('shell') |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 195 | |
| 196 | # Registered Targets |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 197 | def get_llc_props(tool): |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 198 | set_of_targets = set() |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 199 | enable_assertions = False |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 200 | |
| 201 | cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE) |
| 202 | |
| 203 | # Parse the stdout to get the list of registered targets. |
| 204 | parse_targets = False |
| 205 | for line in cmd.stdout: |
| 206 | if parse_targets: |
| 207 | m = re.match( r'(.*) - ', line) |
| 208 | if m is not None: |
| 209 | set_of_targets.add(m.group(1).strip() + '-registered-target') |
| 210 | else: |
| 211 | break |
| 212 | elif "Registered Targets:" in line: |
| 213 | parse_targets = True |
| 214 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 215 | if re.search(r'with assertions', line): |
| 216 | enable_assertions = True |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 217 | |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 218 | return {"set_of_targets": set_of_targets, |
| 219 | "enable_assertions": enable_assertions} |
| 220 | |
| 221 | llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc')) |
| 222 | if len(llc_props['set_of_targets']) > 0: |
| 223 | config.available_features.update(llc_props['set_of_targets']) |
Galina Kistanova | ee22697 | 2011-06-03 18:36:30 +0000 | [diff] [blame] | 224 | else: |
| 225 | lit.fatal('No Targets Registered with the LLVM Tools!') |
NAKAMURA Takumi | 6079676 | 2011-11-28 05:09:42 +0000 | [diff] [blame] | 226 | |
| 227 | if llc_props['enable_assertions']: |
| 228 | config.available_features.add('asserts') |