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