1*9880d681SAndroid Build Coastguard Worker# -*- Python -*- 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker# Configuration file for the 'lit' test runner. 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Workerimport os 6*9880d681SAndroid Build Coastguard Workerimport sys 7*9880d681SAndroid Build Coastguard Workerimport re 8*9880d681SAndroid Build Coastguard Workerimport platform 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Workerimport lit.util 11*9880d681SAndroid Build Coastguard Workerimport lit.formats 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Worker# name: The name of this test suite. 14*9880d681SAndroid Build Coastguard Workerconfig.name = 'LLVM' 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker# Tweak PATH for Win32 to decide to use bash.exe or not. 17*9880d681SAndroid Build Coastguard Workerif sys.platform in ['win32']: 18*9880d681SAndroid Build Coastguard Worker # Seek sane tools in directories and set to $PATH. 19*9880d681SAndroid Build Coastguard Worker path = getattr(config, 'lit_tools_dir', None) 20*9880d681SAndroid Build Coastguard Worker path = lit_config.getToolsPath(path, 21*9880d681SAndroid Build Coastguard Worker config.environment['PATH'], 22*9880d681SAndroid Build Coastguard Worker ['cmp.exe', 'grep.exe', 'sed.exe']) 23*9880d681SAndroid Build Coastguard Worker if path is not None: 24*9880d681SAndroid Build Coastguard Worker path = os.path.pathsep.join((path, 25*9880d681SAndroid Build Coastguard Worker config.environment['PATH'])) 26*9880d681SAndroid Build Coastguard Worker config.environment['PATH'] = path 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker# Choose between lit's internal shell pipeline runner and a real shell. If 29*9880d681SAndroid Build Coastguard Worker# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. 30*9880d681SAndroid Build Coastguard Workeruse_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") 31*9880d681SAndroid Build Coastguard Workerif use_lit_shell: 32*9880d681SAndroid Build Coastguard Worker # 0 is external, "" is default, and everything else is internal. 33*9880d681SAndroid Build Coastguard Worker execute_external = (use_lit_shell == "0") 34*9880d681SAndroid Build Coastguard Workerelse: 35*9880d681SAndroid Build Coastguard Worker # Otherwise we default to internal on Windows and external elsewhere, as 36*9880d681SAndroid Build Coastguard Worker # bash on Windows is usually very slow. 37*9880d681SAndroid Build Coastguard Worker execute_external = (not sys.platform in ['win32']) 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker# testFormat: The test format to use to interpret tests. 40*9880d681SAndroid Build Coastguard Workerconfig.test_format = lit.formats.ShTest(execute_external) 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker# suffixes: A list of file extensions to treat as test files. This is overriden 43*9880d681SAndroid Build Coastguard Worker# by individual lit.local.cfg files in the test subdirectories. 44*9880d681SAndroid Build Coastguard Workerconfig.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s', '.mir'] 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 47*9880d681SAndroid Build Coastguard Worker# subdirectories contain auxiliary inputs for various tests in their parent 48*9880d681SAndroid Build Coastguard Worker# directories. 49*9880d681SAndroid Build Coastguard Workerconfig.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker# test_source_root: The root path where tests are located. 52*9880d681SAndroid Build Coastguard Workerconfig.test_source_root = os.path.dirname(__file__) 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker# test_exec_root: The root path where tests should be run. 55*9880d681SAndroid Build Coastguard Workerllvm_obj_root = getattr(config, 'llvm_obj_root', None) 56*9880d681SAndroid Build Coastguard Workerif llvm_obj_root is not None: 57*9880d681SAndroid Build Coastguard Worker config.test_exec_root = os.path.join(llvm_obj_root, 'test') 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Worker# Tweak the PATH to include the tools dir. 60*9880d681SAndroid Build Coastguard Workerif llvm_obj_root is not None: 61*9880d681SAndroid Build Coastguard Worker llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 62*9880d681SAndroid Build Coastguard Worker if not llvm_tools_dir: 63*9880d681SAndroid Build Coastguard Worker lit_config.fatal('No LLVM tools dir set!') 64*9880d681SAndroid Build Coastguard Worker path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) 65*9880d681SAndroid Build Coastguard Worker config.environment['PATH'] = path 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker# Propagate 'HOME' through the environment. 68*9880d681SAndroid Build Coastguard Workerif 'HOME' in os.environ: 69*9880d681SAndroid Build Coastguard Worker config.environment['HOME'] = os.environ['HOME'] 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker# Propagate 'INCLUDE' through the environment. 72*9880d681SAndroid Build Coastguard Workerif 'INCLUDE' in os.environ: 73*9880d681SAndroid Build Coastguard Worker config.environment['INCLUDE'] = os.environ['INCLUDE'] 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker# Propagate 'LIB' through the environment. 76*9880d681SAndroid Build Coastguard Workerif 'LIB' in os.environ: 77*9880d681SAndroid Build Coastguard Worker config.environment['LIB'] = os.environ['LIB'] 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Worker# Propagate the temp directory. Windows requires this because it uses \Windows\ 80*9880d681SAndroid Build Coastguard Worker# if none of these are present. 81*9880d681SAndroid Build Coastguard Workerif 'TMP' in os.environ: 82*9880d681SAndroid Build Coastguard Worker config.environment['TMP'] = os.environ['TMP'] 83*9880d681SAndroid Build Coastguard Workerif 'TEMP' in os.environ: 84*9880d681SAndroid Build Coastguard Worker config.environment['TEMP'] = os.environ['TEMP'] 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker# Propagate LLVM_SRC_ROOT into the environment. 87*9880d681SAndroid Build Coastguard Workerconfig.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker# Propagate PYTHON_EXECUTABLE into the environment 90*9880d681SAndroid Build Coastguard Workerconfig.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', 91*9880d681SAndroid Build Coastguard Worker '') 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Worker# Propagate path to symbolizer for ASan/MSan. 94*9880d681SAndroid Build Coastguard Workerfor symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: 95*9880d681SAndroid Build Coastguard Worker if symbolizer in os.environ: 96*9880d681SAndroid Build Coastguard Worker config.environment[symbolizer] = os.environ[symbolizer] 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker# Set up OCAMLPATH to include newly built OCaml libraries. 99*9880d681SAndroid Build Coastguard Workerllvm_lib_dir = getattr(config, 'llvm_lib_dir', None) 100*9880d681SAndroid Build Coastguard Workerif llvm_lib_dir is None: 101*9880d681SAndroid Build Coastguard Worker if llvm_obj_root is not None: 102*9880d681SAndroid Build Coastguard Worker llvm_lib_dir = os.path.join(llvm_obj_root, 'lib') 103*9880d681SAndroid Build Coastguard Worker 104*9880d681SAndroid Build Coastguard Workerif llvm_lib_dir is not None: 105*9880d681SAndroid Build Coastguard Worker llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml') 106*9880d681SAndroid Build Coastguard Worker if llvm_ocaml_lib is not None: 107*9880d681SAndroid Build Coastguard Worker if 'OCAMLPATH' in os.environ: 108*9880d681SAndroid Build Coastguard Worker ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH'])) 109*9880d681SAndroid Build Coastguard Worker config.environment['OCAMLPATH'] = ocamlpath 110*9880d681SAndroid Build Coastguard Worker else: 111*9880d681SAndroid Build Coastguard Worker config.environment['OCAMLPATH'] = llvm_ocaml_lib 112*9880d681SAndroid Build Coastguard Worker 113*9880d681SAndroid Build Coastguard Worker if 'CAML_LD_LIBRARY_PATH' in os.environ: 114*9880d681SAndroid Build Coastguard Worker caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib, 115*9880d681SAndroid Build Coastguard Worker os.environ['CAML_LD_LIBRARY_PATH'])) 116*9880d681SAndroid Build Coastguard Worker config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path 117*9880d681SAndroid Build Coastguard Worker else: 118*9880d681SAndroid Build Coastguard Worker config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Worker# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests. 121*9880d681SAndroid Build Coastguard Workerconfig.environment['OCAMLRUNPARAM'] = 'b' 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Worker### 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Workerimport os 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker# Check that the object root is known. 128*9880d681SAndroid Build Coastguard Workerif config.test_exec_root is None: 129*9880d681SAndroid Build Coastguard Worker # Otherwise, we haven't loaded the site specific configuration (the user is 130*9880d681SAndroid Build Coastguard Worker # probably trying to run on a test file directly, and either the site 131*9880d681SAndroid Build Coastguard Worker # configuration hasn't been created by the build system, or we are in an 132*9880d681SAndroid Build Coastguard Worker # out-of-tree build situation). 133*9880d681SAndroid Build Coastguard Worker 134*9880d681SAndroid Build Coastguard Worker # Check for 'llvm_site_config' user parameter, and use that if available. 135*9880d681SAndroid Build Coastguard Worker site_cfg = lit_config.params.get('llvm_site_config', None) 136*9880d681SAndroid Build Coastguard Worker if site_cfg and os.path.exists(site_cfg): 137*9880d681SAndroid Build Coastguard Worker lit_config.load_config(config, site_cfg) 138*9880d681SAndroid Build Coastguard Worker raise SystemExit 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Worker # Try to detect the situation where we are using an out-of-tree build by 141*9880d681SAndroid Build Coastguard Worker # looking for 'llvm-config'. 142*9880d681SAndroid Build Coastguard Worker # 143*9880d681SAndroid Build Coastguard Worker # FIXME: I debated (i.e., wrote and threw away) adding logic to 144*9880d681SAndroid Build Coastguard Worker # automagically generate the lit.site.cfg if we are in some kind of fresh 145*9880d681SAndroid Build Coastguard Worker # build situation. This means knowing how to invoke the build system 146*9880d681SAndroid Build Coastguard Worker # though, and I decided it was too much magic. 147*9880d681SAndroid Build Coastguard Worker 148*9880d681SAndroid Build Coastguard Worker llvm_config = lit.util.which('llvm-config', config.environment['PATH']) 149*9880d681SAndroid Build Coastguard Worker if not llvm_config: 150*9880d681SAndroid Build Coastguard Worker lit_config.fatal('No site specific configuration available!') 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker # Get the source and object roots. 153*9880d681SAndroid Build Coastguard Worker llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() 154*9880d681SAndroid Build Coastguard Worker llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() 155*9880d681SAndroid Build Coastguard Worker 156*9880d681SAndroid Build Coastguard Worker # Validate that we got a tree which points to here. 157*9880d681SAndroid Build Coastguard Worker this_src_root = os.path.dirname(config.test_source_root) 158*9880d681SAndroid Build Coastguard Worker if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root): 159*9880d681SAndroid Build Coastguard Worker lit_config.fatal('No site specific configuration available!') 160*9880d681SAndroid Build Coastguard Worker 161*9880d681SAndroid Build Coastguard Worker # Check that the site specific configuration exists. 162*9880d681SAndroid Build Coastguard Worker site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg') 163*9880d681SAndroid Build Coastguard Worker if not os.path.exists(site_cfg): 164*9880d681SAndroid Build Coastguard Worker lit_config.fatal('No site specific configuration available!') 165*9880d681SAndroid Build Coastguard Worker 166*9880d681SAndroid Build Coastguard Worker # Okay, that worked. Notify the user of the automagic, and reconfigure. 167*9880d681SAndroid Build Coastguard Worker lit_config.note('using out-of-tree build at %r' % llvm_obj_root) 168*9880d681SAndroid Build Coastguard Worker lit_config.load_config(config, site_cfg) 169*9880d681SAndroid Build Coastguard Worker raise SystemExit 170*9880d681SAndroid Build Coastguard Worker 171*9880d681SAndroid Build Coastguard Worker### 172*9880d681SAndroid Build Coastguard Worker 173*9880d681SAndroid Build Coastguard Workerlli = 'lli' 174*9880d681SAndroid Build Coastguard Worker# The target triple used by default by lli is the process target triple (some 175*9880d681SAndroid Build Coastguard Worker# triple appropriate for generating code for the current process) but because 176*9880d681SAndroid Build Coastguard Worker# we don't support COFF in MCJIT well enough for the tests, force ELF format on 177*9880d681SAndroid Build Coastguard Worker# Windows. FIXME: the process target triple should be used here, but this is 178*9880d681SAndroid Build Coastguard Worker# difficult to obtain on Windows. 179*9880d681SAndroid Build Coastguard Workerif re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple): 180*9880d681SAndroid Build Coastguard Worker lli += ' -mtriple='+config.host_triple+'-elf' 181*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%lli', lli ) ) 182*9880d681SAndroid Build Coastguard Worker 183*9880d681SAndroid Build Coastguard Worker# Similarly, have a macro to use llc with DWARF even when the host is win32. 184*9880d681SAndroid Build Coastguard Workerllc_dwarf = 'llc' 185*9880d681SAndroid Build Coastguard Workerif re.search(r'win32', config.target_triple): 186*9880d681SAndroid Build Coastguard Worker llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32') 187*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%llc_dwarf', llc_dwarf) ) 188*9880d681SAndroid Build Coastguard Worker 189*9880d681SAndroid Build Coastguard Worker# Add site-specific substitutions. 190*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%gold', config.gold_executable) ) 191*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%ld64', config.ld64_executable) ) 192*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%go', config.go_executable) ) 193*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) 194*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%shlibext', config.llvm_shlib_ext) ) 195*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%exeext', config.llvm_exe_ext) ) 196*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%python', config.python_executable) ) 197*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%host_cc', config.host_cc) ) 198*9880d681SAndroid Build Coastguard Worker 199*9880d681SAndroid Build Coastguard Worker# OCaml substitutions. 200*9880d681SAndroid Build Coastguard Worker# Support tests for both native and bytecode builds. 201*9880d681SAndroid Build Coastguard Workerconfig.substitutions.append( ('%ocamlc', 202*9880d681SAndroid Build Coastguard Worker "%s ocamlc -cclib -L%s %s" % 203*9880d681SAndroid Build Coastguard Worker (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) ) 204*9880d681SAndroid Build Coastguard Workerif config.have_ocamlopt in ('1', 'TRUE'): 205*9880d681SAndroid Build Coastguard Worker config.substitutions.append( ('%ocamlopt', 206*9880d681SAndroid Build Coastguard Worker "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" % 207*9880d681SAndroid Build Coastguard Worker (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) ) 208*9880d681SAndroid Build Coastguard Workerelse: 209*9880d681SAndroid Build Coastguard Worker config.substitutions.append( ('%ocamlopt', "true" ) ) 210*9880d681SAndroid Build Coastguard Worker 211*9880d681SAndroid Build Coastguard Worker# For each occurrence of an llvm tool name as its own word, replace it 212*9880d681SAndroid Build Coastguard Worker# with the full path to the build directory holding that tool. This 213*9880d681SAndroid Build Coastguard Worker# ensures that we are testing the tools just built and not some random 214*9880d681SAndroid Build Coastguard Worker# tools that might happen to be in the user's PATH. Thus this list 215*9880d681SAndroid Build Coastguard Worker# includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin 216*9880d681SAndroid Build Coastguard Worker# (llvm_tools_dir in lit parlance). 217*9880d681SAndroid Build Coastguard Worker 218*9880d681SAndroid Build Coastguard Worker# Avoid matching RUN line fragments that are actually part of 219*9880d681SAndroid Build Coastguard Worker# path names or options or whatever. 220*9880d681SAndroid Build Coastguard Worker# The regex is a pre-assertion to avoid matching a preceding 221*9880d681SAndroid Build Coastguard Worker# dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns 222*9880d681SAndroid Build Coastguard Worker# also have a post-assertion to not match a trailing hyphen (foo-). 223*9880d681SAndroid Build Coastguard WorkerNOJUNK = r"(?<!\.|-|\^|/)" 224*9880d681SAndroid Build Coastguard Worker 225*9880d681SAndroid Build Coastguard Worker 226*9880d681SAndroid Build Coastguard Workerdef find_tool_substitution(pattern): 227*9880d681SAndroid Build Coastguard Worker # Extract the tool name from the pattern. This relies on the tool 228*9880d681SAndroid Build Coastguard Worker # name being surrounded by \b word match operators. If the 229*9880d681SAndroid Build Coastguard Worker # pattern starts with "| ", include it in the string to be 230*9880d681SAndroid Build Coastguard Worker # substituted. 231*9880d681SAndroid Build Coastguard Worker tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", 232*9880d681SAndroid Build Coastguard Worker pattern) 233*9880d681SAndroid Build Coastguard Worker tool_pipe = tool_match.group(2) 234*9880d681SAndroid Build Coastguard Worker tool_name = tool_match.group(4) 235*9880d681SAndroid Build Coastguard Worker # Did the user specify the tool path + arguments? This allows things like 236*9880d681SAndroid Build Coastguard Worker # llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs" 237*9880d681SAndroid Build Coastguard Worker tool_path = lit_config.params.get(tool_name) 238*9880d681SAndroid Build Coastguard Worker if tool_path is None: 239*9880d681SAndroid Build Coastguard Worker tool_path = lit.util.which(tool_name, llvm_tools_dir) 240*9880d681SAndroid Build Coastguard Worker if tool_path is None: 241*9880d681SAndroid Build Coastguard Worker return tool_name, tool_path, tool_pipe 242*9880d681SAndroid Build Coastguard Worker if (tool_name == "llc" and 243*9880d681SAndroid Build Coastguard Worker 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and 244*9880d681SAndroid Build Coastguard Worker os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"): 245*9880d681SAndroid Build Coastguard Worker tool_path += " -verify-machineinstrs" 246*9880d681SAndroid Build Coastguard Worker if (tool_name == "llvm-go"): 247*9880d681SAndroid Build Coastguard Worker tool_path += " go=" + config.go_executable 248*9880d681SAndroid Build Coastguard Worker return tool_name, tool_path, tool_pipe 249*9880d681SAndroid Build Coastguard Worker 250*9880d681SAndroid Build Coastguard Worker 251*9880d681SAndroid Build Coastguard Workerfor pattern in [r"\bbugpoint\b(?!-)", 252*9880d681SAndroid Build Coastguard Worker NOJUNK + r"\bllc\b", 253*9880d681SAndroid Build Coastguard Worker r"\blli\b", 254*9880d681SAndroid Build Coastguard Worker r"\bllvm-ar\b", 255*9880d681SAndroid Build Coastguard Worker r"\bllvm-as\b", 256*9880d681SAndroid Build Coastguard Worker r"\bllvm-bcanalyzer\b", 257*9880d681SAndroid Build Coastguard Worker r"\bllvm-config\b", 258*9880d681SAndroid Build Coastguard Worker r"\bllvm-cov\b", 259*9880d681SAndroid Build Coastguard Worker r"\bllvm-cxxdump\b", 260*9880d681SAndroid Build Coastguard Worker r"\bllvm-diff\b", 261*9880d681SAndroid Build Coastguard Worker r"\bllvm-dis\b", 262*9880d681SAndroid Build Coastguard Worker r"\bllvm-dsymutil\b", 263*9880d681SAndroid Build Coastguard Worker r"\bllvm-dwarfdump\b", 264*9880d681SAndroid Build Coastguard Worker r"\bllvm-extract\b", 265*9880d681SAndroid Build Coastguard Worker r"\bllvm-lib\b", 266*9880d681SAndroid Build Coastguard Worker r"\bllvm-link\b", 267*9880d681SAndroid Build Coastguard Worker r"\bllvm-lto\b", 268*9880d681SAndroid Build Coastguard Worker r"\bllvm-mc\b", 269*9880d681SAndroid Build Coastguard Worker r"\bllvm-mcmarkup\b", 270*9880d681SAndroid Build Coastguard Worker r"\bllvm-nm\b", 271*9880d681SAndroid Build Coastguard Worker r"\bllvm-objdump\b", 272*9880d681SAndroid Build Coastguard Worker r"\bllvm-pdbdump\b", 273*9880d681SAndroid Build Coastguard Worker r"\bllvm-profdata\b", 274*9880d681SAndroid Build Coastguard Worker r"\bllvm-ranlib\b", 275*9880d681SAndroid Build Coastguard Worker r"\bllvm-readobj\b", 276*9880d681SAndroid Build Coastguard Worker r"\bllvm-rtdyld\b", 277*9880d681SAndroid Build Coastguard Worker r"\bllvm-size\b", 278*9880d681SAndroid Build Coastguard Worker r"\bllvm-split\b", 279*9880d681SAndroid Build Coastguard Worker r"\bllvm-tblgen\b", 280*9880d681SAndroid Build Coastguard Worker r"\bllvm-c-test\b", 281*9880d681SAndroid Build Coastguard Worker NOJUNK + r"\bllvm-symbolizer\b", 282*9880d681SAndroid Build Coastguard Worker NOJUNK + r"\bopt\b", 283*9880d681SAndroid Build Coastguard Worker r"\bFileCheck\b", 284*9880d681SAndroid Build Coastguard Worker r"\bobj2yaml\b", 285*9880d681SAndroid Build Coastguard Worker NOJUNK + r"\bsancov\b", 286*9880d681SAndroid Build Coastguard Worker NOJUNK + r"\bsanstats\b", 287*9880d681SAndroid Build Coastguard Worker r"\byaml2obj\b", 288*9880d681SAndroid Build Coastguard Worker r"\byaml-bench\b", 289*9880d681SAndroid Build Coastguard Worker r"\bverify-uselistorder\b", 290*9880d681SAndroid Build Coastguard Worker # Handle these specially as they are strings searched 291*9880d681SAndroid Build Coastguard Worker # for during testing. 292*9880d681SAndroid Build Coastguard Worker r"\| \bcount\b", 293*9880d681SAndroid Build Coastguard Worker r"\| \bnot\b"]: 294*9880d681SAndroid Build Coastguard Worker tool_name, tool_path, tool_pipe = find_tool_substitution(pattern) 295*9880d681SAndroid Build Coastguard Worker if not tool_path: 296*9880d681SAndroid Build Coastguard Worker # Warn, but still provide a substitution. 297*9880d681SAndroid Build Coastguard Worker lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir) 298*9880d681SAndroid Build Coastguard Worker tool_path = llvm_tools_dir + '/' + tool_name 299*9880d681SAndroid Build Coastguard Worker config.substitutions.append((pattern, tool_pipe + tool_path)) 300*9880d681SAndroid Build Coastguard Worker 301*9880d681SAndroid Build Coastguard Worker# For tools that are optional depending on the config, we won't warn 302*9880d681SAndroid Build Coastguard Worker# if they're missing. 303*9880d681SAndroid Build Coastguard Workerfor pattern in [r"\bllvm-go\b", 304*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch3\b", 305*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch4\b", 306*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch5\b", 307*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch6\b", 308*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch7\b", 309*9880d681SAndroid Build Coastguard Worker r"\bKaleidoscope-Ch8\b"]: 310*9880d681SAndroid Build Coastguard Worker tool_name, tool_path, tool_pipe = find_tool_substitution(pattern) 311*9880d681SAndroid Build Coastguard Worker if not tool_path: 312*9880d681SAndroid Build Coastguard Worker # Provide a substitution anyway, for the sake of consistent errors. 313*9880d681SAndroid Build Coastguard Worker tool_path = llvm_tools_dir + '/' + tool_name 314*9880d681SAndroid Build Coastguard Worker config.substitutions.append((pattern, tool_pipe + tool_path)) 315*9880d681SAndroid Build Coastguard Worker 316*9880d681SAndroid Build Coastguard Worker 317*9880d681SAndroid Build Coastguard Worker### Targets 318*9880d681SAndroid Build Coastguard Worker 319*9880d681SAndroid Build Coastguard Workerconfig.targets = frozenset(config.targets_to_build.split()) 320*9880d681SAndroid Build Coastguard Worker 321*9880d681SAndroid Build Coastguard Worker### Features 322*9880d681SAndroid Build Coastguard Worker 323*9880d681SAndroid Build Coastguard Worker# Shell execution 324*9880d681SAndroid Build Coastguard Workerif execute_external: 325*9880d681SAndroid Build Coastguard Worker config.available_features.add('shell') 326*9880d681SAndroid Build Coastguard Worker 327*9880d681SAndroid Build Coastguard Worker# Others/can-execute.txt 328*9880d681SAndroid Build Coastguard Workerif sys.platform not in ['win32']: 329*9880d681SAndroid Build Coastguard Worker config.available_features.add('can-execute') 330*9880d681SAndroid Build Coastguard Worker 331*9880d681SAndroid Build Coastguard Worker# Loadable module 332*9880d681SAndroid Build Coastguard Worker# FIXME: This should be supplied by Makefile or autoconf. 333*9880d681SAndroid Build Coastguard Workerif sys.platform in ['win32', 'cygwin']: 334*9880d681SAndroid Build Coastguard Worker loadable_module = (config.enable_shared == 1) 335*9880d681SAndroid Build Coastguard Workerelse: 336*9880d681SAndroid Build Coastguard Worker loadable_module = True 337*9880d681SAndroid Build Coastguard Worker 338*9880d681SAndroid Build Coastguard Workerif loadable_module: 339*9880d681SAndroid Build Coastguard Worker config.available_features.add('loadable_module') 340*9880d681SAndroid Build Coastguard Worker 341*9880d681SAndroid Build Coastguard Worker# Sanitizers. 342*9880d681SAndroid Build Coastguard Workerif 'Address' in config.llvm_use_sanitizer: 343*9880d681SAndroid Build Coastguard Worker config.available_features.add("asan") 344*9880d681SAndroid Build Coastguard Workerelse: 345*9880d681SAndroid Build Coastguard Worker config.available_features.add("not_asan") 346*9880d681SAndroid Build Coastguard Workerif 'Memory' in config.llvm_use_sanitizer: 347*9880d681SAndroid Build Coastguard Worker config.available_features.add("msan") 348*9880d681SAndroid Build Coastguard Workerelse: 349*9880d681SAndroid Build Coastguard Worker config.available_features.add("not_msan") 350*9880d681SAndroid Build Coastguard Workerif 'Undefined' in config.llvm_use_sanitizer: 351*9880d681SAndroid Build Coastguard Worker config.available_features.add("ubsan") 352*9880d681SAndroid Build Coastguard Workerelse: 353*9880d681SAndroid Build Coastguard Worker config.available_features.add("not_ubsan") 354*9880d681SAndroid Build Coastguard Worker 355*9880d681SAndroid Build Coastguard Worker# Check if we should run long running tests. 356*9880d681SAndroid Build Coastguard Workerif lit_config.params.get("run_long_tests", None) == "true": 357*9880d681SAndroid Build Coastguard Worker config.available_features.add("long_tests") 358*9880d681SAndroid Build Coastguard Worker 359*9880d681SAndroid Build Coastguard Worker# Direct object generation 360*9880d681SAndroid Build Coastguard Workerif not 'hexagon' in config.target_triple: 361*9880d681SAndroid Build Coastguard Worker config.available_features.add("object-emission") 362*9880d681SAndroid Build Coastguard Worker 363*9880d681SAndroid Build Coastguard Workerif config.have_zlib == "1": 364*9880d681SAndroid Build Coastguard Worker config.available_features.add("zlib") 365*9880d681SAndroid Build Coastguard Workerelse: 366*9880d681SAndroid Build Coastguard Worker config.available_features.add("nozlib") 367*9880d681SAndroid Build Coastguard Worker 368*9880d681SAndroid Build Coastguard Worker# LLVM can be configured with an empty default triple 369*9880d681SAndroid Build Coastguard Worker# Some tests are "generic" and require a valid default triple 370*9880d681SAndroid Build Coastguard Workerif config.target_triple: 371*9880d681SAndroid Build Coastguard Worker config.available_features.add("default_triple") 372*9880d681SAndroid Build Coastguard Worker if re.match(r'^x86_64.*-linux', config.target_triple): 373*9880d681SAndroid Build Coastguard Worker config.available_features.add("x86_64-linux") 374*9880d681SAndroid Build Coastguard Worker 375*9880d681SAndroid Build Coastguard Worker# Native compilation: host arch == default triple arch 376*9880d681SAndroid Build Coastguard Worker# FIXME: Consider cases that target can be executed 377*9880d681SAndroid Build Coastguard Worker# even if host_triple were different from target_triple. 378*9880d681SAndroid Build Coastguard Workerif config.host_triple == config.target_triple: 379*9880d681SAndroid Build Coastguard Worker config.available_features.add("native") 380*9880d681SAndroid Build Coastguard Worker 381*9880d681SAndroid Build Coastguard Workerimport subprocess 382*9880d681SAndroid Build Coastguard Worker 383*9880d681SAndroid Build Coastguard Workerdef have_ld_plugin_support(): 384*9880d681SAndroid Build Coastguard Worker if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')): 385*9880d681SAndroid Build Coastguard Worker return False 386*9880d681SAndroid Build Coastguard Worker 387*9880d681SAndroid Build Coastguard Worker ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'}) 388*9880d681SAndroid Build Coastguard Worker ld_out = ld_cmd.stdout.read().decode() 389*9880d681SAndroid Build Coastguard Worker ld_cmd.wait() 390*9880d681SAndroid Build Coastguard Worker 391*9880d681SAndroid Build Coastguard Worker if not '-plugin' in ld_out: 392*9880d681SAndroid Build Coastguard Worker return False 393*9880d681SAndroid Build Coastguard Worker 394*9880d681SAndroid Build Coastguard Worker # check that the used emulations are supported. 395*9880d681SAndroid Build Coastguard Worker emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l] 396*9880d681SAndroid Build Coastguard Worker if len(emu_line) != 1: 397*9880d681SAndroid Build Coastguard Worker return False 398*9880d681SAndroid Build Coastguard Worker emu_line = emu_line[0] 399*9880d681SAndroid Build Coastguard Worker fields = emu_line.split(':') 400*9880d681SAndroid Build Coastguard Worker if len(fields) != 3: 401*9880d681SAndroid Build Coastguard Worker return False 402*9880d681SAndroid Build Coastguard Worker emulations = fields[2].split() 403*9880d681SAndroid Build Coastguard Worker if 'elf_x86_64' not in emulations: 404*9880d681SAndroid Build Coastguard Worker return False 405*9880d681SAndroid Build Coastguard Worker if 'elf32ppc' in emulations: 406*9880d681SAndroid Build Coastguard Worker config.available_features.add('ld_emu_elf32ppc') 407*9880d681SAndroid Build Coastguard Worker 408*9880d681SAndroid Build Coastguard Worker ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'}) 409*9880d681SAndroid Build Coastguard Worker if not 'GNU gold' in ld_version.stdout.read().decode(): 410*9880d681SAndroid Build Coastguard Worker return False 411*9880d681SAndroid Build Coastguard Worker ld_version.wait() 412*9880d681SAndroid Build Coastguard Worker 413*9880d681SAndroid Build Coastguard Worker return True 414*9880d681SAndroid Build Coastguard Worker 415*9880d681SAndroid Build Coastguard Workerif have_ld_plugin_support(): 416*9880d681SAndroid Build Coastguard Worker config.available_features.add('ld_plugin') 417*9880d681SAndroid Build Coastguard Worker 418*9880d681SAndroid Build Coastguard Workerdef have_ld64_plugin_support(): 419*9880d681SAndroid Build Coastguard Worker if config.ld64_executable == '': 420*9880d681SAndroid Build Coastguard Worker return False 421*9880d681SAndroid Build Coastguard Worker 422*9880d681SAndroid Build Coastguard Worker ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE) 423*9880d681SAndroid Build Coastguard Worker ld_out = ld_cmd.stderr.read().decode() 424*9880d681SAndroid Build Coastguard Worker ld_cmd.wait() 425*9880d681SAndroid Build Coastguard Worker 426*9880d681SAndroid Build Coastguard Worker if 'ld64' not in ld_out or 'LTO' not in ld_out: 427*9880d681SAndroid Build Coastguard Worker return False 428*9880d681SAndroid Build Coastguard Worker 429*9880d681SAndroid Build Coastguard Worker return True 430*9880d681SAndroid Build Coastguard Worker 431*9880d681SAndroid Build Coastguard Workerif have_ld64_plugin_support(): 432*9880d681SAndroid Build Coastguard Worker config.available_features.add('ld64_plugin') 433*9880d681SAndroid Build Coastguard Worker 434*9880d681SAndroid Build Coastguard Worker# Ask llvm-config about assertion mode. 435*9880d681SAndroid Build Coastguard Workertry: 436*9880d681SAndroid Build Coastguard Worker llvm_config_cmd = subprocess.Popen( 437*9880d681SAndroid Build Coastguard Worker [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'], 438*9880d681SAndroid Build Coastguard Worker stdout = subprocess.PIPE, 439*9880d681SAndroid Build Coastguard Worker env=config.environment) 440*9880d681SAndroid Build Coastguard Workerexcept OSError: 441*9880d681SAndroid Build Coastguard Worker print("Could not find llvm-config in " + llvm_tools_dir) 442*9880d681SAndroid Build Coastguard Worker exit(42) 443*9880d681SAndroid Build Coastguard Worker 444*9880d681SAndroid Build Coastguard Workerif re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')): 445*9880d681SAndroid Build Coastguard Worker config.available_features.add('asserts') 446*9880d681SAndroid Build Coastguard Workerllvm_config_cmd.wait() 447*9880d681SAndroid Build Coastguard Worker 448*9880d681SAndroid Build Coastguard Workerif 'darwin' == sys.platform: 449*9880d681SAndroid Build Coastguard Worker try: 450*9880d681SAndroid Build Coastguard Worker sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'], 451*9880d681SAndroid Build Coastguard Worker stdout = subprocess.PIPE) 452*9880d681SAndroid Build Coastguard Worker except OSError: 453*9880d681SAndroid Build Coastguard Worker print("Could not exec sysctl") 454*9880d681SAndroid Build Coastguard Worker result = sysctl_cmd.stdout.read().decode('ascii') 455*9880d681SAndroid Build Coastguard Worker if -1 != result.find("hw.optional.fma: 1"): 456*9880d681SAndroid Build Coastguard Worker config.available_features.add('fma3') 457*9880d681SAndroid Build Coastguard Worker sysctl_cmd.wait() 458*9880d681SAndroid Build Coastguard Worker 459*9880d681SAndroid Build Coastguard Workerif platform.system() in ['Windows'] and re.match(r'.*-win32$', config.target_triple): 460*9880d681SAndroid Build Coastguard Worker # For tests that require Windows to run. 461*9880d681SAndroid Build Coastguard Worker config.available_features.add('system-windows') 462*9880d681SAndroid Build Coastguard Worker 463*9880d681SAndroid Build Coastguard Worker# .debug_frame is not emitted for targeting Windows x64. 464*9880d681SAndroid Build Coastguard Workerif not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple): 465*9880d681SAndroid Build Coastguard Worker config.available_features.add('debug_frame') 466*9880d681SAndroid Build Coastguard Worker 467*9880d681SAndroid Build Coastguard Worker# Check if we should use gmalloc. 468*9880d681SAndroid Build Coastguard Workeruse_gmalloc_str = lit_config.params.get('use_gmalloc', None) 469*9880d681SAndroid Build Coastguard Workerif use_gmalloc_str is not None: 470*9880d681SAndroid Build Coastguard Worker if use_gmalloc_str.lower() in ('1', 'true'): 471*9880d681SAndroid Build Coastguard Worker use_gmalloc = True 472*9880d681SAndroid Build Coastguard Worker elif use_gmalloc_str.lower() in ('', '0', 'false'): 473*9880d681SAndroid Build Coastguard Worker use_gmalloc = False 474*9880d681SAndroid Build Coastguard Worker else: 475*9880d681SAndroid Build Coastguard Worker lit_config.fatal('user parameter use_gmalloc should be 0 or 1') 476*9880d681SAndroid Build Coastguard Workerelse: 477*9880d681SAndroid Build Coastguard Worker # Default to not using gmalloc 478*9880d681SAndroid Build Coastguard Worker use_gmalloc = False 479*9880d681SAndroid Build Coastguard Worker 480*9880d681SAndroid Build Coastguard Worker# Allow use of an explicit path for gmalloc library. 481*9880d681SAndroid Build Coastguard Worker# Will default to '/usr/lib/libgmalloc.dylib' if not set. 482*9880d681SAndroid Build Coastguard Workergmalloc_path_str = lit_config.params.get('gmalloc_path', 483*9880d681SAndroid Build Coastguard Worker '/usr/lib/libgmalloc.dylib') 484*9880d681SAndroid Build Coastguard Worker 485*9880d681SAndroid Build Coastguard Workerif use_gmalloc: 486*9880d681SAndroid Build Coastguard Worker config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str}) 487*9880d681SAndroid Build Coastguard Worker 488*9880d681SAndroid Build Coastguard Worker# Ask llvm-config about global-isel. 489*9880d681SAndroid Build Coastguard Workertry: 490*9880d681SAndroid Build Coastguard Worker llvm_config_cmd = subprocess.Popen( 491*9880d681SAndroid Build Coastguard Worker [os.path.join(llvm_tools_dir, 'llvm-config'), '--has-global-isel'], 492*9880d681SAndroid Build Coastguard Worker stdout = subprocess.PIPE, 493*9880d681SAndroid Build Coastguard Worker env=config.environment) 494*9880d681SAndroid Build Coastguard Workerexcept OSError: 495*9880d681SAndroid Build Coastguard Worker print("Could not find llvm-config in " + llvm_tools_dir) 496*9880d681SAndroid Build Coastguard Worker exit(42) 497*9880d681SAndroid Build Coastguard Worker 498*9880d681SAndroid Build Coastguard Workerif re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')): 499*9880d681SAndroid Build Coastguard Worker config.available_features.add('global-isel') 500*9880d681SAndroid Build Coastguard Workerllvm_config_cmd.wait() 501*9880d681SAndroid Build Coastguard Worker 502*9880d681SAndroid Build Coastguard Workerif config.have_libxar: 503*9880d681SAndroid Build Coastguard Worker config.available_features.add('xar') 504