1*67e74705SXin Li# -*- Python -*- 2*67e74705SXin Li 3*67e74705SXin Liimport os 4*67e74705SXin Liimport platform 5*67e74705SXin Liimport re 6*67e74705SXin Liimport subprocess 7*67e74705SXin Liimport tempfile 8*67e74705SXin Li 9*67e74705SXin Liimport lit.formats 10*67e74705SXin Liimport lit.util 11*67e74705SXin Li 12*67e74705SXin Li# Configuration file for the 'lit' test runner. 13*67e74705SXin Li 14*67e74705SXin Li# name: The name of this test suite. 15*67e74705SXin Liconfig.name = 'Clang' 16*67e74705SXin Li 17*67e74705SXin Li# Tweak PATH for Win32 18*67e74705SXin Liif platform.system() == 'Windows': 19*67e74705SXin Li # Seek sane tools in directories and set to $PATH. 20*67e74705SXin Li path = getattr(config, 'lit_tools_dir', None) 21*67e74705SXin Li path = lit_config.getToolsPath(path, 22*67e74705SXin Li config.environment['PATH'], 23*67e74705SXin Li ['cmp.exe', 'grep.exe', 'sed.exe']) 24*67e74705SXin Li if path is not None: 25*67e74705SXin Li path = os.path.pathsep.join((path, 26*67e74705SXin Li config.environment['PATH'])) 27*67e74705SXin Li config.environment['PATH'] = path 28*67e74705SXin Li 29*67e74705SXin Li# Choose between lit's internal shell pipeline runner and a real shell. If 30*67e74705SXin Li# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. 31*67e74705SXin Liuse_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") 32*67e74705SXin Liif use_lit_shell: 33*67e74705SXin Li # 0 is external, "" is default, and everything else is internal. 34*67e74705SXin Li execute_external = (use_lit_shell == "0") 35*67e74705SXin Lielse: 36*67e74705SXin Li # Otherwise we default to internal on Windows and external elsewhere, as 37*67e74705SXin Li # bash on Windows is usually very slow. 38*67e74705SXin Li execute_external = (not sys.platform in ['win32']) 39*67e74705SXin Li 40*67e74705SXin Li# testFormat: The test format to use to interpret tests. 41*67e74705SXin Li# 42*67e74705SXin Li# For now we require '&&' between commands, until they get globally killed and 43*67e74705SXin Li# the test runner updated. 44*67e74705SXin Liconfig.test_format = lit.formats.ShTest(execute_external) 45*67e74705SXin Li 46*67e74705SXin Li# suffixes: A list of file extensions to treat as test files. 47*67e74705SXin Liconfig.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs'] 48*67e74705SXin Li 49*67e74705SXin Li# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 50*67e74705SXin Li# subdirectories contain auxiliary inputs for various tests in their parent 51*67e74705SXin Li# directories. 52*67e74705SXin Liconfig.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] 53*67e74705SXin Li 54*67e74705SXin Li# test_source_root: The root path where tests are located. 55*67e74705SXin Liconfig.test_source_root = os.path.dirname(__file__) 56*67e74705SXin Li 57*67e74705SXin Li# test_exec_root: The root path where tests should be run. 58*67e74705SXin Liclang_obj_root = getattr(config, 'clang_obj_root', None) 59*67e74705SXin Liif clang_obj_root is not None: 60*67e74705SXin Li config.test_exec_root = os.path.join(clang_obj_root, 'test') 61*67e74705SXin Li 62*67e74705SXin Li# Set llvm_{src,obj}_root for use by others. 63*67e74705SXin Liconfig.llvm_src_root = getattr(config, 'llvm_src_root', None) 64*67e74705SXin Liconfig.llvm_obj_root = getattr(config, 'llvm_obj_root', None) 65*67e74705SXin Li 66*67e74705SXin Li# Clear some environment variables that might affect Clang. 67*67e74705SXin Li# 68*67e74705SXin Li# This first set of vars are read by Clang, but shouldn't affect tests 69*67e74705SXin Li# that aren't specifically looking for these features, or are required 70*67e74705SXin Li# simply to run the tests at all. 71*67e74705SXin Li# 72*67e74705SXin Li# FIXME: Should we have a tool that enforces this? 73*67e74705SXin Li 74*67e74705SXin Li# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', 75*67e74705SXin Li# 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', 76*67e74705SXin Li# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', 77*67e74705SXin Li# 'VC80COMNTOOLS') 78*67e74705SXin Lipossibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', 79*67e74705SXin Li 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', 80*67e74705SXin Li 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 81*67e74705SXin Li 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', 82*67e74705SXin Li 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', 83*67e74705SXin Li 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', 84*67e74705SXin Li 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', 85*67e74705SXin Li 'LIBCLANG_RESOURCE_USAGE', 86*67e74705SXin Li 'LIBCLANG_CODE_COMPLETION_LOGGING'] 87*67e74705SXin Li# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. 88*67e74705SXin Liif platform.system() != 'Windows': 89*67e74705SXin Li possibly_dangerous_env_vars.append('INCLUDE') 90*67e74705SXin Lifor name in possibly_dangerous_env_vars: 91*67e74705SXin Li if name in config.environment: 92*67e74705SXin Li del config.environment[name] 93*67e74705SXin Li 94*67e74705SXin Li# Tweak the PATH to include the tools dir and the scripts dir. 95*67e74705SXin Liif clang_obj_root is not None: 96*67e74705SXin Li clang_tools_dir = getattr(config, 'clang_tools_dir', None) 97*67e74705SXin Li if not clang_tools_dir: 98*67e74705SXin Li lit_config.fatal('No Clang tools dir set!') 99*67e74705SXin Li llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 100*67e74705SXin Li if not llvm_tools_dir: 101*67e74705SXin Li lit_config.fatal('No LLVM tools dir set!') 102*67e74705SXin Li path = os.path.pathsep.join(( 103*67e74705SXin Li clang_tools_dir, llvm_tools_dir, config.environment['PATH'])) 104*67e74705SXin Li config.environment['PATH'] = path 105*67e74705SXin Li llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) 106*67e74705SXin Li if not llvm_libs_dir: 107*67e74705SXin Li lit_config.fatal('No LLVM libs dir set!') 108*67e74705SXin Li path = os.path.pathsep.join((llvm_libs_dir, 109*67e74705SXin Li config.environment.get('LD_LIBRARY_PATH',''))) 110*67e74705SXin Li config.environment['LD_LIBRARY_PATH'] = path 111*67e74705SXin Li 112*67e74705SXin Li# Propagate path to symbolizer for ASan/MSan. 113*67e74705SXin Lifor symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: 114*67e74705SXin Li if symbolizer in os.environ: 115*67e74705SXin Li config.environment[symbolizer] = os.environ[symbolizer] 116*67e74705SXin Li 117*67e74705SXin Li### 118*67e74705SXin Li 119*67e74705SXin Li# Check that the object root is known. 120*67e74705SXin Liif config.test_exec_root is None: 121*67e74705SXin Li # Otherwise, we haven't loaded the site specific configuration (the user is 122*67e74705SXin Li # probably trying to run on a test file directly, and either the site 123*67e74705SXin Li # configuration hasn't been created by the build system, or we are in an 124*67e74705SXin Li # out-of-tree build situation). 125*67e74705SXin Li 126*67e74705SXin Li # Check for 'clang_site_config' user parameter, and use that if available. 127*67e74705SXin Li site_cfg = lit_config.params.get('clang_site_config', None) 128*67e74705SXin Li if site_cfg and os.path.exists(site_cfg): 129*67e74705SXin Li lit_config.load_config(config, site_cfg) 130*67e74705SXin Li raise SystemExit 131*67e74705SXin Li 132*67e74705SXin Li # Try to detect the situation where we are using an out-of-tree build by 133*67e74705SXin Li # looking for 'llvm-config'. 134*67e74705SXin Li # 135*67e74705SXin Li # FIXME: I debated (i.e., wrote and threw away) adding logic to 136*67e74705SXin Li # automagically generate the lit.site.cfg if we are in some kind of fresh 137*67e74705SXin Li # build situation. This means knowing how to invoke the build system though, 138*67e74705SXin Li # and I decided it was too much magic. We should solve this by just having 139*67e74705SXin Li # the .cfg files generated during the configuration step. 140*67e74705SXin Li 141*67e74705SXin Li llvm_config = lit.util.which('llvm-config', config.environment['PATH']) 142*67e74705SXin Li if not llvm_config: 143*67e74705SXin Li lit_config.fatal('No site specific configuration available!') 144*67e74705SXin Li 145*67e74705SXin Li # Get the source and object roots. 146*67e74705SXin Li llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() 147*67e74705SXin Li llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() 148*67e74705SXin Li clang_src_root = os.path.join(llvm_src_root, "tools", "clang") 149*67e74705SXin Li clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") 150*67e74705SXin Li 151*67e74705SXin Li # Validate that we got a tree which points to here, using the standard 152*67e74705SXin Li # tools/clang layout. 153*67e74705SXin Li this_src_root = os.path.dirname(config.test_source_root) 154*67e74705SXin Li if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): 155*67e74705SXin Li lit_config.fatal('No site specific configuration available!') 156*67e74705SXin Li 157*67e74705SXin Li # Check that the site specific configuration exists. 158*67e74705SXin Li site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg') 159*67e74705SXin Li if not os.path.exists(site_cfg): 160*67e74705SXin Li lit_config.fatal( 161*67e74705SXin Li 'No site specific configuration available! You may need to ' 162*67e74705SXin Li 'run "make test" in your Clang build directory.') 163*67e74705SXin Li 164*67e74705SXin Li # Okay, that worked. Notify the user of the automagic, and reconfigure. 165*67e74705SXin Li lit_config.note('using out-of-tree build at %r' % clang_obj_root) 166*67e74705SXin Li lit_config.load_config(config, site_cfg) 167*67e74705SXin Li raise SystemExit 168*67e74705SXin Li 169*67e74705SXin Li### 170*67e74705SXin Li 171*67e74705SXin Li# Discover the 'clang' and 'clangcc' to use. 172*67e74705SXin Li 173*67e74705SXin Liimport os 174*67e74705SXin Li 175*67e74705SXin Lidef inferClang(PATH): 176*67e74705SXin Li # Determine which clang to use. 177*67e74705SXin Li clang = os.getenv('CLANG') 178*67e74705SXin Li 179*67e74705SXin Li # If the user set clang in the environment, definitely use that and don't 180*67e74705SXin Li # try to validate. 181*67e74705SXin Li if clang: 182*67e74705SXin Li return clang 183*67e74705SXin Li 184*67e74705SXin Li # Otherwise look in the path. 185*67e74705SXin Li clang = lit.util.which('clang', PATH) 186*67e74705SXin Li 187*67e74705SXin Li if not clang: 188*67e74705SXin Li lit_config.fatal("couldn't find 'clang' program, try setting " 189*67e74705SXin Li "CLANG in your environment") 190*67e74705SXin Li 191*67e74705SXin Li return clang 192*67e74705SXin Li 193*67e74705SXin Liconfig.clang = inferClang(config.environment['PATH']).replace('\\', '/') 194*67e74705SXin Liif not lit_config.quiet: 195*67e74705SXin Li lit_config.note('using clang: %r' % config.clang) 196*67e74705SXin Li 197*67e74705SXin Li# Plugins (loadable modules) 198*67e74705SXin Li# TODO: This should be supplied by Makefile or autoconf. 199*67e74705SXin Liif sys.platform in ['win32', 'cygwin']: 200*67e74705SXin Li has_plugins = (config.enable_shared == 1) 201*67e74705SXin Lielse: 202*67e74705SXin Li has_plugins = True 203*67e74705SXin Li 204*67e74705SXin Liif has_plugins and config.llvm_plugin_ext: 205*67e74705SXin Li config.available_features.add('plugins') 206*67e74705SXin Li 207*67e74705SXin Liconfig.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) ) 208*67e74705SXin Liconfig.substitutions.append( ('%pluginext', config.llvm_plugin_ext) ) 209*67e74705SXin Liconfig.substitutions.append( ('%PATH%', config.environment['PATH']) ) 210*67e74705SXin Li 211*67e74705SXin Liif config.clang_examples: 212*67e74705SXin Li config.available_features.add('examples') 213*67e74705SXin Li 214*67e74705SXin Li# Note that when substituting %clang_cc1 also fill in the include directory of 215*67e74705SXin Li# the builtin headers. Those are part of even a freestanding environment, but 216*67e74705SXin Li# Clang relies on the driver to locate them. 217*67e74705SXin Lidef getClangBuiltinIncludeDir(clang): 218*67e74705SXin Li # FIXME: Rather than just getting the version, we should have clang print 219*67e74705SXin Li # out its resource dir here in an easy to scrape form. 220*67e74705SXin Li cmd = subprocess.Popen([clang, '-print-file-name=include'], 221*67e74705SXin Li stdout=subprocess.PIPE, 222*67e74705SXin Li env=config.environment) 223*67e74705SXin Li if not cmd.stdout: 224*67e74705SXin Li lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang) 225*67e74705SXin Li dir = cmd.stdout.read().strip() 226*67e74705SXin Li if sys.platform in ['win32'] and execute_external: 227*67e74705SXin Li # Don't pass dosish path separator to msys bash.exe. 228*67e74705SXin Li dir = dir.replace('\\', '/') 229*67e74705SXin Li # Ensure the result is an ascii string, across Python2.5+ - Python3. 230*67e74705SXin Li return str(dir.decode('ascii')) 231*67e74705SXin Li 232*67e74705SXin Lidef makeItaniumABITriple(triple): 233*67e74705SXin Li m = re.match(r'(\w+)-(\w+)-(\w+)', triple) 234*67e74705SXin Li if not m: 235*67e74705SXin Li lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple) 236*67e74705SXin Li if m.group(3).lower() != 'win32': 237*67e74705SXin Li # All non-win32 triples use the Itanium ABI. 238*67e74705SXin Li return triple 239*67e74705SXin Li return m.group(1) + '-' + m.group(2) + '-mingw32' 240*67e74705SXin Li 241*67e74705SXin Lidef makeMSABITriple(triple): 242*67e74705SXin Li m = re.match(r'(\w+)-(\w+)-(\w+)', triple) 243*67e74705SXin Li if not m: 244*67e74705SXin Li lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple) 245*67e74705SXin Li isa = m.group(1).lower() 246*67e74705SXin Li vendor = m.group(2).lower() 247*67e74705SXin Li os = m.group(3).lower() 248*67e74705SXin Li if os == 'win32': 249*67e74705SXin Li # If the OS is win32, we're done. 250*67e74705SXin Li return triple 251*67e74705SXin Li if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa): 252*67e74705SXin Li # For x86 ISAs, adjust the OS. 253*67e74705SXin Li return isa + '-' + vendor + '-win32' 254*67e74705SXin Li # -win32 is not supported for non-x86 targets; use a default. 255*67e74705SXin Li return 'i686-pc-win32' 256*67e74705SXin Li 257*67e74705SXin Liconfig.substitutions.append( ('%clang_cc1', 258*67e74705SXin Li '%s -cc1 -internal-isystem %s -nostdsysteminc' 259*67e74705SXin Li % (config.clang, 260*67e74705SXin Li getClangBuiltinIncludeDir(config.clang))) ) 261*67e74705SXin Liconfig.substitutions.append( ('%clang_cpp', ' ' + config.clang + 262*67e74705SXin Li ' --driver-mode=cpp ')) 263*67e74705SXin Liconfig.substitutions.append( ('%clang_cl', ' ' + config.clang + 264*67e74705SXin Li ' --driver-mode=cl ')) 265*67e74705SXin Liconfig.substitutions.append( ('%clangxx', ' ' + config.clang + 266*67e74705SXin Li ' --driver-mode=g++ ')) 267*67e74705SXin Liconfig.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) 268*67e74705SXin Liconfig.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') ) 269*67e74705SXin Liconfig.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) ) 270*67e74705SXin Liconfig.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) ) 271*67e74705SXin Li 272*67e74705SXin Li# The host triple might not be set, at least if we're compiling clang from 273*67e74705SXin Li# an already installed llvm. 274*67e74705SXin Liif config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@': 275*67e74705SXin Li config.substitutions.append( ('%target_itanium_abi_host_triple', '--target=%s' % makeItaniumABITriple(config.host_triple)) ) 276*67e74705SXin Lielse: 277*67e74705SXin Li config.substitutions.append( ('%target_itanium_abi_host_triple', '') ) 278*67e74705SXin Li 279*67e74705SXin Li# FIXME: Find nicer way to prohibit this. 280*67e74705SXin Liconfig.substitutions.append( 281*67e74705SXin Li (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") ) 282*67e74705SXin Liconfig.substitutions.append( 283*67e74705SXin Li (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***""")) 284*67e74705SXin Liconfig.substitutions.append( 285*67e74705SXin Li (' clang-cc ', 286*67e74705SXin Li """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") ) 287*67e74705SXin Liconfig.substitutions.append( 288*67e74705SXin Li (' clang -cc1 ', 289*67e74705SXin Li """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) 290*67e74705SXin Liconfig.substitutions.append( 291*67e74705SXin Li (' %clang-cc1 ', 292*67e74705SXin Li """*** invalid substitution, use '%clang_cc1'. ***""") ) 293*67e74705SXin Liconfig.substitutions.append( 294*67e74705SXin Li (' %clang-cpp ', 295*67e74705SXin Li """*** invalid substitution, use '%clang_cpp'. ***""") ) 296*67e74705SXin Liconfig.substitutions.append( 297*67e74705SXin Li (' %clang-cl ', 298*67e74705SXin Li """*** invalid substitution, use '%clang_cl'. ***""") ) 299*67e74705SXin Li 300*67e74705SXin Li# For each occurrence of a clang tool name as its own word, replace it 301*67e74705SXin Li# with the full path to the build directory holding that tool. This 302*67e74705SXin Li# ensures that we are testing the tools just built and not some random 303*67e74705SXin Li# tools that might happen to be in the user's PATH. 304*67e74705SXin Litool_dirs = os.path.pathsep.join((clang_tools_dir, llvm_tools_dir)) 305*67e74705SXin Li 306*67e74705SXin Li# Regex assertions to reject neighbor hyphens/dots (seen in some tests). 307*67e74705SXin Li# For example, don't match 'clang-check-' or '.clang-format'. 308*67e74705SXin LiNoPreHyphenDot = r"(?<!(-|\.))" 309*67e74705SXin LiNoPostHyphenDot = r"(?!(-|\.))" 310*67e74705SXin LiNoPostBar = r"(?!(/|\\))" 311*67e74705SXin Li 312*67e74705SXin Litool_patterns = [r"\bFileCheck\b", 313*67e74705SXin Li r"\bc-index-test\b", 314*67e74705SXin Li NoPreHyphenDot + r"\bclang-check\b" + NoPostHyphenDot, 315*67e74705SXin Li NoPreHyphenDot + r"\bclang-format\b" + NoPostHyphenDot, 316*67e74705SXin Li # FIXME: Some clang test uses opt? 317*67e74705SXin Li NoPreHyphenDot + r"\bopt\b" + NoPostBar + NoPostHyphenDot, 318*67e74705SXin Li # Handle these specially as they are strings searched 319*67e74705SXin Li # for during testing. 320*67e74705SXin Li r"\| \bcount\b", 321*67e74705SXin Li r"\| \bnot\b"] 322*67e74705SXin Li 323*67e74705SXin Liif config.clang_examples: 324*67e74705SXin Li tool_patterns.append(NoPreHyphenDot + r"\bclang-interpreter\b" + NoPostHyphenDot) 325*67e74705SXin Li 326*67e74705SXin Lifor pattern in tool_patterns: 327*67e74705SXin Li # Extract the tool name from the pattern. This relies on the tool 328*67e74705SXin Li # name being surrounded by \b word match operators. If the 329*67e74705SXin Li # pattern starts with "| ", include it in the string to be 330*67e74705SXin Li # substituted. 331*67e74705SXin Li tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", 332*67e74705SXin Li pattern) 333*67e74705SXin Li tool_pipe = tool_match.group(2) 334*67e74705SXin Li tool_name = tool_match.group(4) 335*67e74705SXin Li tool_path = lit.util.which(tool_name, tool_dirs) 336*67e74705SXin Li if not tool_path: 337*67e74705SXin Li # Warn, but still provide a substitution. 338*67e74705SXin Li lit_config.note('Did not find ' + tool_name + ' in ' + tool_dirs) 339*67e74705SXin Li tool_path = clang_tools_dir + '/' + tool_name 340*67e74705SXin Li config.substitutions.append((pattern, tool_pipe + tool_path)) 341*67e74705SXin Li 342*67e74705SXin Li### 343*67e74705SXin Li 344*67e74705SXin Li# Set available features we allow tests to conditionalize on. 345*67e74705SXin Li# 346*67e74705SXin Li# Enabled/disabled features 347*67e74705SXin Liif config.clang_staticanalyzer != 0: 348*67e74705SXin Li config.available_features.add("staticanalyzer") 349*67e74705SXin Li 350*67e74705SXin Li# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. 351*67e74705SXin Liif platform.system() not in ['FreeBSD']: 352*67e74705SXin Li config.available_features.add('crash-recovery') 353*67e74705SXin Li 354*67e74705SXin Li# Shell execution 355*67e74705SXin Liif execute_external: 356*67e74705SXin Li config.available_features.add('shell') 357*67e74705SXin Li 358*67e74705SXin Li# For tests that require Darwin to run. 359*67e74705SXin Li# This is used by debuginfo-tests/*block*.m and debuginfo-tests/foreach.m. 360*67e74705SXin Liif platform.system() in ['Darwin']: 361*67e74705SXin Li config.available_features.add('system-darwin') 362*67e74705SXin Lielif platform.system() in ['Windows']: 363*67e74705SXin Li # For tests that require Windows to run. 364*67e74705SXin Li config.available_features.add('system-windows') 365*67e74705SXin Li 366*67e74705SXin Li# ANSI escape sequences in non-dumb terminal 367*67e74705SXin Liif platform.system() not in ['Windows']: 368*67e74705SXin Li config.available_features.add('ansi-escape-sequences') 369*67e74705SXin Li 370*67e74705SXin Li# Capability to print utf8 to the terminal. 371*67e74705SXin Li# Windows expects codepage, unless Wide API. 372*67e74705SXin Liif platform.system() not in ['Windows']: 373*67e74705SXin Li config.available_features.add('utf8-capable-terminal') 374*67e74705SXin Li 375*67e74705SXin Li# Native compilation: Check if triples match. 376*67e74705SXin Li# FIXME: Consider cases that target can be executed 377*67e74705SXin Li# even if host_triple were different from target_triple. 378*67e74705SXin Liif config.host_triple == config.target_triple: 379*67e74705SXin Li config.available_features.add("native") 380*67e74705SXin Li 381*67e74705SXin Li# Case-insensitive file system 382*67e74705SXin Lidef is_filesystem_case_insensitive(): 383*67e74705SXin Li handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) 384*67e74705SXin Li isInsensitive = os.path.exists( 385*67e74705SXin Li os.path.join( 386*67e74705SXin Li os.path.dirname(path), 387*67e74705SXin Li os.path.basename(path).upper() 388*67e74705SXin Li )) 389*67e74705SXin Li os.close(handle) 390*67e74705SXin Li os.remove(path) 391*67e74705SXin Li return isInsensitive 392*67e74705SXin Li 393*67e74705SXin Liif is_filesystem_case_insensitive(): 394*67e74705SXin Li config.available_features.add('case-insensitive-filesystem') 395*67e74705SXin Li 396*67e74705SXin Li# Tests that require the /dev/fd filesystem. 397*67e74705SXin Liif os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']: 398*67e74705SXin Li config.available_features.add('dev-fd-fs') 399*67e74705SXin Li 400*67e74705SXin Li# Not set on native MS environment. 401*67e74705SXin Liif not re.match(r'.*-win32$', config.target_triple): 402*67e74705SXin Li config.available_features.add('non-ms-sdk') 403*67e74705SXin Li 404*67e74705SXin Li# Not set on native PS4 environment. 405*67e74705SXin Liif not re.match(r'.*-scei-ps4', config.target_triple): 406*67e74705SXin Li config.available_features.add('non-ps4-sdk') 407*67e74705SXin Li 408*67e74705SXin Li# [PR8833] LLP64-incompatible tests 409*67e74705SXin Liif not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple): 410*67e74705SXin Li config.available_features.add('LP64') 411*67e74705SXin Li 412*67e74705SXin Li# [PR12920] "clang-driver" -- set if gcc driver is not used. 413*67e74705SXin Liif not re.match(r'.*-(cygwin)$', config.target_triple): 414*67e74705SXin Li config.available_features.add('clang-driver') 415*67e74705SXin Li 416*67e74705SXin Li# [PR18856] Depends to remove opened file. On win32, a file could be removed 417*67e74705SXin Li# only if all handles were closed. 418*67e74705SXin Liif platform.system() not in ['Windows']: 419*67e74705SXin Li config.available_features.add('can-remove-opened-file') 420*67e74705SXin Li 421*67e74705SXin Li# Returns set of available features, registered-target(s) and asserts. 422*67e74705SXin Lidef get_llvm_config_props(): 423*67e74705SXin Li set_of_features = set() 424*67e74705SXin Li 425*67e74705SXin Li cmd = subprocess.Popen( 426*67e74705SXin Li [ 427*67e74705SXin Li os.path.join(llvm_tools_dir, 'llvm-config'), 428*67e74705SXin Li '--assertion-mode', 429*67e74705SXin Li '--targets-built', 430*67e74705SXin Li ], 431*67e74705SXin Li stdout=subprocess.PIPE, 432*67e74705SXin Li env=config.environment 433*67e74705SXin Li ) 434*67e74705SXin Li # 1st line corresponds to --assertion-mode, "ON" or "OFF". 435*67e74705SXin Li line = cmd.stdout.readline().strip().decode('ascii') 436*67e74705SXin Li if line == "ON": 437*67e74705SXin Li set_of_features.add('asserts') 438*67e74705SXin Li 439*67e74705SXin Li # 2nd line corresponds to --targets-built, like; 440*67e74705SXin Li # AArch64 ARM CppBackend X86 441*67e74705SXin Li for arch in cmd.stdout.readline().decode('ascii').split(): 442*67e74705SXin Li set_of_features.add(arch.lower() + '-registered-target') 443*67e74705SXin Li 444*67e74705SXin Li return set_of_features 445*67e74705SXin Li 446*67e74705SXin Liconfig.available_features.update(get_llvm_config_props()) 447*67e74705SXin Li 448*67e74705SXin Liif lit.util.which('xmllint'): 449*67e74705SXin Li config.available_features.add('xmllint') 450*67e74705SXin Li 451*67e74705SXin Li# Sanitizers. 452*67e74705SXin Liif 'Address' in config.llvm_use_sanitizer: 453*67e74705SXin Li config.available_features.add("asan") 454*67e74705SXin Lielse: 455*67e74705SXin Li config.available_features.add("not_asan") 456*67e74705SXin Liif 'Memory' in config.llvm_use_sanitizer: 457*67e74705SXin Li config.available_features.add("msan") 458*67e74705SXin Liif 'Undefined' in config.llvm_use_sanitizer: 459*67e74705SXin Li config.available_features.add("ubsan") 460*67e74705SXin Lielse: 461*67e74705SXin Li config.available_features.add("not_ubsan") 462*67e74705SXin Li 463*67e74705SXin Liif config.enable_backtrace == "1": 464*67e74705SXin Li config.available_features.add("backtrace") 465*67e74705SXin Li 466*67e74705SXin Liif config.have_zlib == "1": 467*67e74705SXin Li config.available_features.add("zlib") 468*67e74705SXin Lielse: 469*67e74705SXin Li config.available_features.add("nozlib") 470*67e74705SXin Li 471*67e74705SXin Li# Check if we should run long running tests. 472*67e74705SXin Liif lit_config.params.get("run_long_tests", None) == "true": 473*67e74705SXin Li config.available_features.add("long_tests") 474*67e74705SXin Li 475*67e74705SXin Li# Check if we should use gmalloc. 476*67e74705SXin Liuse_gmalloc_str = lit_config.params.get('use_gmalloc', None) 477*67e74705SXin Liif use_gmalloc_str is not None: 478*67e74705SXin Li if use_gmalloc_str.lower() in ('1', 'true'): 479*67e74705SXin Li use_gmalloc = True 480*67e74705SXin Li elif use_gmalloc_str.lower() in ('', '0', 'false'): 481*67e74705SXin Li use_gmalloc = False 482*67e74705SXin Li else: 483*67e74705SXin Li lit_config.fatal('user parameter use_gmalloc should be 0 or 1') 484*67e74705SXin Lielse: 485*67e74705SXin Li # Default to not using gmalloc 486*67e74705SXin Li use_gmalloc = False 487*67e74705SXin Li 488*67e74705SXin Li# Allow use of an explicit path for gmalloc library. 489*67e74705SXin Li# Will default to '/usr/lib/libgmalloc.dylib' if not set. 490*67e74705SXin Ligmalloc_path_str = lit_config.params.get('gmalloc_path', 491*67e74705SXin Li '/usr/lib/libgmalloc.dylib') 492*67e74705SXin Liif use_gmalloc: 493*67e74705SXin Li config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str}) 494*67e74705SXin Li 495*67e74705SXin Li# Check if we should allow outputs to console. 496*67e74705SXin Lirun_console_tests = int(lit_config.params.get('enable_console', '0')) 497*67e74705SXin Liif run_console_tests != 0: 498*67e74705SXin Li config.available_features.add('console') 499*67e74705SXin Li 500*67e74705SXin Lilit.util.usePlatformSdkOnDarwin(config, lit_config) 501