1 # -*- Python -*- 2 3 # Configuration file for the 'lit' test runner. 4 5 import os 6 import sys 7 import re 8 9 # name: The name of this test suite. 10 config.name = 'LLVM' 11 12 # Tweak PATH for Win32 to decide to use bash.exe or not. 13 if sys.platform in ['win32']: 14 # Seek sane tools in directories and set to $PATH. 15 path = getattr(config, 'lit_tools_dir', None) 16 path = lit.getToolsPath(path, 17 config.environment['PATH'], 18 ['cmp.exe', 'grep.exe', 'sed.exe']) 19 if path is not None: 20 path = os.path.pathsep.join((path, 21 config.environment['PATH'])) 22 config.environment['PATH'] = path 23 24 # testFormat: The test format to use to interpret tests. 25 execute_external = (not sys.platform in ['win32'] 26 or lit.getBashPath() not in [None, ""]) 27 config.test_format = lit.formats.ShTest(execute_external) 28 29 # To ignore test output on stderr so it doesn't trigger failures uncomment this: 30 #config.test_format = lit.formats.TclTest(ignoreStdErr=True) 31 32 # suffixes: A list of file extensions to treat as test files, this is actually 33 # set by on_clone(). 34 config.suffixes = [] 35 36 # excludes: A list of directories to exclude from the testsuite. The 'Inputs' 37 # subdirectories contain auxiliary inputs for various tests in their parent 38 # directories. 39 config.excludes = ['Inputs'] 40 41 # test_source_root: The root path where tests are located. 42 config.test_source_root = os.path.dirname(__file__) 43 44 # test_exec_root: The root path where tests should be run. 45 llvm_obj_root = getattr(config, 'llvm_obj_root', None) 46 if llvm_obj_root is not None: 47 config.test_exec_root = os.path.join(llvm_obj_root, 'test') 48 49 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin 50 # dir (if available). 51 if llvm_obj_root is not None: 52 llvm_src_root = getattr(config, 'llvm_src_root', None) 53 if not llvm_src_root: 54 lit.fatal('No LLVM source root set!') 55 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test', 56 'Scripts'), 57 config.environment['PATH'])) 58 config.environment['PATH'] = path 59 60 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 61 if not llvm_tools_dir: 62 lit.fatal('No LLVM tools dir set!') 63 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) 64 config.environment['PATH'] = path 65 66 # Propagate 'HOME' through the environment. 67 if 'HOME' in os.environ: 68 config.environment['HOME'] = os.environ['HOME'] 69 70 # Propagate 'INCLUDE' through the environment. 71 if 'INCLUDE' in os.environ: 72 config.environment['INCLUDE'] = os.environ['INCLUDE'] 73 74 # Propagate 'LIB' through the environment. 75 if 'LIB' in os.environ: 76 config.environment['LIB'] = os.environ['LIB'] 77 78 # Propagate the temp directory. Windows requires this because it uses \Windows\ 79 # if none of these are present. 80 if 'TMP' in os.environ: 81 config.environment['TMP'] = os.environ['TMP'] 82 if 'TEMP' in os.environ: 83 config.environment['TEMP'] = os.environ['TEMP'] 84 85 # Propagate LLVM_SRC_ROOT into the environment. 86 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') 87 88 # Propagate PYTHON_EXECUTABLE into the environment 89 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', 90 '') 91 92 ### 93 94 import os 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 103 # Check for 'llvm_site_config' user parameter, and use that if available. 104 site_cfg = lit.params.get('llvm_site_config', None) 105 if site_cfg and os.path.exists(site_cfg): 106 lit.load_config(config, site_cfg) 107 raise SystemExit 108 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 114 # build situation. This means knowing how to invoke the build system 115 # though, and I decided it was too much magic. 116 117 llvm_config = lit.util.which('llvm-config', config.environment['PATH']) 118 if not llvm_config: 119 lit.fatal('No site specific configuration available!') 120 121 # Get the source and object roots. 122 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() 123 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() 124 125 # Validate that we got a tree which points to here. 126 this_src_root = os.path.dirname(config.test_source_root) 127 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root): 128 lit.fatal('No site specific configuration available!') 129 130 # Check that the site specific configuration exists. 131 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg') 132 if not os.path.exists(site_cfg): 133 lit.fatal('No site specific configuration available!') 134 135 # Okay, that worked. Notify the user of the automagic, and reconfigure. 136 lit.note('using out-of-tree build at %r' % llvm_obj_root) 137 lit.load_config(config, site_cfg) 138 raise SystemExit 139 140 ### 141 142 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the 143 # triple so we can check it with XFAIL and XTARGET. 144 config.target_triple += lit.valgrindTriple 145 146 # Process jit implementation option 147 jit_impl_cfg = lit.params.get('jit_impl', None) 148 if jit_impl_cfg == 'mcjit': 149 # When running with mcjit, mangle -mcjit into target triple 150 # and add -use-mcjit flag to lli invocation 151 if 'i686' in config.target_triple: 152 config.target_triple += jit_impl_cfg + '-ia32' 153 elif 'x86_64' in config.target_triple: 154 config.target_triple += jit_impl_cfg + '-ia64' 155 else: 156 config.target_triple += jit_impl_cfg 157 158 config.substitutions.append( ('%lli', 'lli -use-mcjit') ) 159 else: 160 config.substitutions.append( ('%lli', 'lli') ) 161 162 # Add site-specific substitutions. 163 config.substitutions.append( ('%ocamlopt', config.ocamlopt_executable) ) 164 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) 165 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) ) 166 167 # For each occurrence of an llvm tool name as its own word, replace it 168 # with the full path to the build directory holding that tool. This 169 # ensures that we are testing the tools just built and not some random 170 # tools that might happen to be in the user's PATH. Thus this list 171 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin 172 # (llvm_tools_dir in lit parlance). 173 # Don't match 'bugpoint-' or 'clang-'. 174 # Don't match '/clang' or '-clang'. 175 if os.pathsep == ';': 176 pathext = os.environ.get('PATHEXT', '').split(';') 177 else: 178 pathext = [''] 179 for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/|-)\bclang\b(?!-)", 180 r"\bgold\b", 181 r"\bllc\b", r"\blli\b", 182 r"\bllvm-ar\b", r"\bllvm-as\b", 183 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b", 184 r"\bllvm-cov\b", r"\bllvm-diff\b", 185 r"\bllvm-dis\b", r"\bllvm-dwarfdump\b", 186 r"\bllvm-extract\b", 187 r"\bllvm-link\b", r"\bllvm-mc\b", 188 r"\bllvm-nm\b", r"\bllvm-objdump\b", 189 r"\bllvm-prof\b", r"\bllvm-ranlib\b", 190 r"\bllvm-rtdyld\b", r"\bllvm-shlib\b", 191 r"\bllvm-size\b", 192 # Don't match '-llvmc'. 193 r"(?<!-)\bllvmc\b", r"\blto\b", 194 # Don't match '.opt', '-opt', 195 # '^opt' or '/opt'. 196 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b", 197 r"\bllvm-tblgen\b", r"\bFileCheck\b", 198 r"\bFileUpdate\b", r"\bc-index-test\b", 199 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b", 200 # Handle these specially as they are strings searched 201 # for during testing. 202 r"\| \bcount\b", r"\| \bnot\b"]: 203 # Extract the tool name from the pattern. This relies on the tool 204 # name being surrounded by \b word match operators. If the 205 # pattern starts with "| ", include it in the string to be 206 # substituted. 207 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", 208 r"\2" + llvm_tools_dir + "/" + r"\4", 209 pattern) 210 for ext in pathext: 211 substitution_ext = substitution + ext 212 if os.path.exists(substitution_ext): 213 substitution = substitution_ext 214 break 215 config.substitutions.append((pattern, substitution)) 216 217 ### Features 218 219 # Shell execution 220 if sys.platform not in ['win32'] or lit.getBashPath() != '': 221 config.available_features.add('shell') 222 223 # Loadable module 224 # FIXME: This should be supplied by Makefile or autoconf. 225 if sys.platform in ['win32', 'cygwin']: 226 loadable_module = (config.enable_shared == 1) 227 else: 228 loadable_module = True 229 230 if loadable_module: 231 config.available_features.add('loadable_module') 232 233 # llc knows whether he is compiled with -DNDEBUG. 234 import subprocess 235 try: 236 llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'], 237 stdout = subprocess.PIPE) 238 except OSError, why: 239 print "Could not find llc in " + llvm_tools_dir 240 exit(42) 241 242 if re.search(r'with assertions', llc_cmd.stdout.read()): 243 config.available_features.add('asserts') 244 llc_cmd.wait() 245