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