blob: 497058b58beae047ede37d49163d8b8c45596566 [file] [log] [blame]
Daniel Dunbar3667b992009-07-31 05:54:17 +00001# -*- Python -*-
2
Daniel Dunbarb5cbf772009-09-22 05:16:02 +00003import os
Daniel Dunbar79327b62009-09-22 10:08:03 +00004import platform
Chandler Carruth2837f662011-11-05 20:55:50 +00005import re
6import subprocess
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +00007import tempfile
Chandler Carruth2837f662011-11-05 20:55:50 +00008
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +00009import lit.formats
10import lit.util
Daniel Dunbarbe4253a2009-09-08 16:39:23 +000011
Daniel Dunbar3667b992009-07-31 05:54:17 +000012# Configuration file for the 'lit' test runner.
13
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000014# name: The name of this test suite.
15config.name = 'Clang'
Daniel Dunbarbe4253a2009-09-08 16:39:23 +000016
NAKAMURA Takumi1e8200d2011-02-09 04:19:57 +000017# Tweak PATH for Win32
18if platform.system() == 'Windows':
19 # Seek sane tools in directories and set to $PATH.
20 path = getattr(config, 'lit_tools_dir', None)
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000021 path = lit_config.getToolsPath(path,
22 config.environment['PATH'],
23 ['cmp.exe', 'grep.exe', 'sed.exe'])
NAKAMURA Takumi1e8200d2011-02-09 04:19:57 +000024 if path is not None:
25 path = os.path.pathsep.join((path,
26 config.environment['PATH']))
27 config.environment['PATH'] = path
28
Reid Kleckner0675f852013-04-11 13:34:18 +000029# Choose between lit's internal shell pipeline runner and a real shell. If
30# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
31use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
32if use_lit_shell:
33 # 0 is external, "" is default, and everything else is internal.
34 execute_external = (use_lit_shell == "0")
35else:
36 # Otherwise we default to internal on Windows and external elsewhere, as
37 # bash on Windows is usually very slow.
38 execute_external = (not sys.platform in ['win32'])
39
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000040# testFormat: The test format to use to interpret tests.
Daniel Dunbar3667b992009-07-31 05:54:17 +000041#
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000042# For now we require '&&' between commands, until they get globally killed and
43# the test runner updated.
Daniel Dunbard90e0a12009-11-08 01:47:35 +000044config.test_format = lit.formats.ShTest(execute_external)
Daniel Dunbarf87be552009-09-06 01:31:12 +000045
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000046# suffixes: A list of file extensions to treat as test files.
Richard Smithbbcc9f02016-08-26 00:14:38 +000047config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs']
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000048
Alp Toker9c5ae472013-11-15 13:37:49 +000049# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
50# subdirectories contain auxiliary inputs for various tests in their parent
51# directories.
52config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
53
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000054# test_source_root: The root path where tests are located.
55config.test_source_root = os.path.dirname(__file__)
56
57# test_exec_root: The root path where tests should be run.
58clang_obj_root = getattr(config, 'clang_obj_root', None)
59if clang_obj_root is not None:
60 config.test_exec_root = os.path.join(clang_obj_root, 'test')
61
62# Set llvm_{src,obj}_root for use by others.
63config.llvm_src_root = getattr(config, 'llvm_src_root', None)
64config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
65
Jordy Rose0e09fac2012-04-06 18:14:01 +000066# Clear some environment variables that might affect Clang.
67#
68# This first set of vars are read by Clang, but shouldn't affect tests
69# that aren't specifically looking for these features, or are required
70# simply to run the tests at all.
71#
72# FIXME: Should we have a tool that enforces this?
73
74# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
75# 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
Jordy Rose0e09fac2012-04-06 18:14:01 +000076# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
77# 'VC80COMNTOOLS')
NAKAMURA Takumic4d558a2012-04-07 01:02:53 +000078possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Jordy Rose0e09fac2012-04-06 18:14:01 +000079 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
80 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
81 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
82 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
83 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
84 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
85 'LIBCLANG_RESOURCE_USAGE',
NAKAMURA Takumic4d558a2012-04-07 01:02:53 +000086 'LIBCLANG_CODE_COMPLETION_LOGGING']
87# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
88if platform.system() != 'Windows':
89 possibly_dangerous_env_vars.append('INCLUDE')
Jordy Rose0e09fac2012-04-06 18:14:01 +000090for name in possibly_dangerous_env_vars:
91 if name in config.environment:
92 del config.environment[name]
93
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000094# Tweak the PATH to include the tools dir and the scripts dir.
95if clang_obj_root is not None:
NAKAMURA Takumi462ba802013-12-18 15:08:56 +000096 clang_tools_dir = getattr(config, 'clang_tools_dir', None)
97 if not clang_tools_dir:
98 lit_config.fatal('No Clang tools dir set!')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000099 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
100 if not llvm_tools_dir:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000101 lit_config.fatal('No LLVM tools dir set!')
NAKAMURA Takumi462ba802013-12-18 15:08:56 +0000102 path = os.path.pathsep.join((
103 clang_tools_dir, llvm_tools_dir, config.environment['PATH']))
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000104 config.environment['PATH'] = path
Daniel Dunbara87097a2009-09-26 07:36:09 +0000105 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
106 if not llvm_libs_dir:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000107 lit_config.fatal('No LLVM libs dir set!')
Daniel Dunbara87097a2009-09-26 07:36:09 +0000108 path = os.path.pathsep.join((llvm_libs_dir,
109 config.environment.get('LD_LIBRARY_PATH','')))
110 config.environment['LD_LIBRARY_PATH'] = path
111
Alexey Samsonovc01f4f02013-04-04 07:41:20 +0000112# Propagate path to symbolizer for ASan/MSan.
113for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
114 if symbolizer in os.environ:
115 config.environment[symbolizer] = os.environ[symbolizer]
116
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000117###
118
119# Check that the object root is known.
120if config.test_exec_root is None:
121 # Otherwise, we haven't loaded the site specific configuration (the user is
122 # probably trying to run on a test file directly, and either the site
123 # configuration hasn't been created by the build system, or we are in an
124 # out-of-tree build situation).
125
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000126 # Check for 'clang_site_config' user parameter, and use that if available.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000127 site_cfg = lit_config.params.get('clang_site_config', None)
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000128 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000129 lit_config.load_config(config, site_cfg)
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000130 raise SystemExit
131
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000132 # Try to detect the situation where we are using an out-of-tree build by
133 # looking for 'llvm-config'.
134 #
135 # FIXME: I debated (i.e., wrote and threw away) adding logic to
136 # automagically generate the lit.site.cfg if we are in some kind of fresh
Daniel Dunbar8466a0d2009-11-07 23:53:17 +0000137 # build situation. This means knowing how to invoke the build system though,
138 # and I decided it was too much magic. We should solve this by just having
139 # the .cfg files generated during the configuration step.
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000140
141 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
142 if not llvm_config:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000143 lit_config.fatal('No site specific configuration available!')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000144
145 # Get the source and object roots.
146 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
147 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
148 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
149 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
150
151 # Validate that we got a tree which points to here, using the standard
152 # tools/clang layout.
153 this_src_root = os.path.dirname(config.test_source_root)
154 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000155 lit_config.fatal('No site specific configuration available!')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000156
157 # Check that the site specific configuration exists.
158 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
159 if not os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000160 lit_config.fatal(
161 'No site specific configuration available! You may need to '
162 'run "make test" in your Clang build directory.')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000163
164 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000165 lit_config.note('using out-of-tree build at %r' % clang_obj_root)
166 lit_config.load_config(config, site_cfg)
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000167 raise SystemExit
168
169###
170
171# Discover the 'clang' and 'clangcc' to use.
172
173import os
174
175def inferClang(PATH):
176 # Determine which clang to use.
177 clang = os.getenv('CLANG')
178
179 # If the user set clang in the environment, definitely use that and don't
180 # try to validate.
181 if clang:
182 return clang
183
184 # Otherwise look in the path.
185 clang = lit.util.which('clang', PATH)
186
187 if not clang:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000188 lit_config.fatal("couldn't find 'clang' program, try setting "
189 "CLANG in your environment")
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000190
191 return clang
192
NAKAMURA Takumi70f5be62011-03-05 11:16:06 +0000193config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000194if not lit_config.quiet:
195 lit_config.note('using clang: %r' % config.clang)
Chandler Carruthc0b1b862011-11-05 10:15:27 +0000196
Alp Toker120dd1af2014-01-08 11:38:47 +0000197# Plugins (loadable modules)
198# TODO: This should be supplied by Makefile or autoconf.
NAKAMURA Takumiba7d0fe2016-02-11 16:43:08 +0000199if sys.platform in ['win32', 'cygwin']:
Alp Toker120dd1af2014-01-08 11:38:47 +0000200 has_plugins = (config.enable_shared == 1)
201else:
202 has_plugins = True
203
204if has_plugins and config.llvm_plugin_ext:
205 config.available_features.add('plugins')
206
207config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
208config.substitutions.append( ('%pluginext', config.llvm_plugin_ext) )
NAKAMURA Takumi430443b2015-10-15 13:51:13 +0000209config.substitutions.append( ('%PATH%', config.environment['PATH']) )
Alp Toker120dd1af2014-01-08 11:38:47 +0000210
211if config.clang_examples:
212 config.available_features.add('examples')
213
Chandler Carruthc0b1b862011-11-05 10:15:27 +0000214# Note that when substituting %clang_cc1 also fill in the include directory of
215# the builtin headers. Those are part of even a freestanding environment, but
216# Clang relies on the driver to locate them.
Chandler Carruth34146d82011-11-05 23:29:28 +0000217def getClangBuiltinIncludeDir(clang):
Chandler Carruth2837f662011-11-05 20:55:50 +0000218 # FIXME: Rather than just getting the version, we should have clang print
219 # out its resource dir here in an easy to scrape form.
Chandler Carruth34146d82011-11-05 23:29:28 +0000220 cmd = subprocess.Popen([clang, '-print-file-name=include'],
Scott Douglassdf914d52014-09-24 18:37:52 +0000221 stdout=subprocess.PIPE,
222 env=config.environment)
Chandler Carruth34146d82011-11-05 23:29:28 +0000223 if not cmd.stdout:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000224 lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
NAKAMURA Takumi8e85e6a2013-06-26 10:45:20 +0000225 dir = cmd.stdout.read().strip()
226 if sys.platform in ['win32'] and execute_external:
227 # Don't pass dosish path separator to msys bash.exe.
228 dir = dir.replace('\\', '/')
Daniel Dunbareff4a952013-08-14 16:32:20 +0000229 # Ensure the result is an ascii string, across Python2.5+ - Python3.
230 return str(dir.decode('ascii'))
Chandler Carruth2837f662011-11-05 20:55:50 +0000231
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000232def makeItaniumABITriple(triple):
233 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
234 if not m:
235 lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
236 if m.group(3).lower() != 'win32':
237 # All non-win32 triples use the Itanium ABI.
238 return triple
239 return m.group(1) + '-' + m.group(2) + '-mingw32'
240
241def makeMSABITriple(triple):
242 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
243 if not m:
244 lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
Hans Wennborg1e76cba2014-01-15 01:08:42 +0000245 isa = m.group(1).lower()
246 vendor = m.group(2).lower()
247 os = m.group(3).lower()
248 if os == 'win32':
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000249 # If the OS is win32, we're done.
250 return triple
Hans Wennborg1e76cba2014-01-15 01:08:42 +0000251 if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
252 # For x86 ISAs, adjust the OS.
253 return isa + '-' + vendor + '-win32'
254 # -win32 is not supported for non-x86 targets; use a default.
255 return 'i686-pc-win32'
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000256
Justin Bognerfa9df7a2014-10-03 22:18:49 +0000257config.substitutions.append( ('%clang_cc1',
258 '%s -cc1 -internal-isystem %s -nostdsysteminc'
Chandler Carruth34146d82011-11-05 23:29:28 +0000259 % (config.clang,
260 getClangBuiltinIncludeDir(config.clang))) )
Hans Wennborg70850d82013-07-18 20:29:38 +0000261config.substitutions.append( ('%clang_cpp', ' ' + config.clang +
262 ' --driver-mode=cpp '))
Hans Wennborge4b031c2013-07-19 20:33:20 +0000263config.substitutions.append( ('%clang_cl', ' ' + config.clang +
264 ' --driver-mode=cl '))
Daniel Dunbar8452ef02010-06-29 16:52:24 +0000265config.substitutions.append( ('%clangxx', ' ' + config.clang +
Hans Wennborg70850d82013-07-18 20:29:38 +0000266 ' --driver-mode=g++ '))
Daniel Dunbar5618e982009-12-15 22:01:24 +0000267config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Adrian Prantl8ae19f72014-01-27 22:50:20 +0000268config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000269config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) )
270config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) )
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +0000271
Filipe Cabecinhasaa363022014-10-18 23:36:12 +0000272# The host triple might not be set, at least if we're compiling clang from
273# an already installed llvm.
274if config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@':
275 config.substitutions.append( ('%target_itanium_abi_host_triple', '--target=%s' % makeItaniumABITriple(config.host_triple)) )
276else:
277 config.substitutions.append( ('%target_itanium_abi_host_triple', '') )
278
Daniel Dunbar5618e982009-12-15 22:01:24 +0000279# FIXME: Find nicer way to prohibit this.
280config.substitutions.append(
281 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
282config.substitutions.append(
David Greene7b293452011-01-03 17:28:52 +0000283 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar78c974f2010-02-17 20:31:01 +0000284config.substitutions.append(
Daniel Dunbar5618e982009-12-15 22:01:24 +0000285 (' clang-cc ',
286 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
287config.substitutions.append(
288 (' clang -cc1 ',
289 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar8452ef02010-06-29 16:52:24 +0000290config.substitutions.append(
291 (' %clang-cc1 ',
292 """*** invalid substitution, use '%clang_cc1'. ***""") )
Hans Wennborg70850d82013-07-18 20:29:38 +0000293config.substitutions.append(
294 (' %clang-cpp ',
295 """*** invalid substitution, use '%clang_cpp'. ***""") )
Hans Wennborge4b031c2013-07-19 20:33:20 +0000296config.substitutions.append(
297 (' %clang-cl ',
298 """*** invalid substitution, use '%clang_cl'. ***""") )
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +0000299
Paul Robinson5df175c2014-03-26 16:40:43 +0000300# For each occurrence of a clang tool name as its own word, replace it
301# with the full path to the build directory holding that tool. This
302# ensures that we are testing the tools just built and not some random
303# tools that might happen to be in the user's PATH.
304tool_dirs = os.path.pathsep.join((clang_tools_dir, llvm_tools_dir))
305
306# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
307# For example, don't match 'clang-check-' or '.clang-format'.
308NoPreHyphenDot = r"(?<!(-|\.))"
309NoPostHyphenDot = r"(?!(-|\.))"
Francisco Lopes da Silva37e8f2d2015-01-05 19:59:24 +0000310NoPostBar = r"(?!(/|\\))"
Paul Robinson5df175c2014-03-26 16:40:43 +0000311
Richard Barton1448fdc2015-10-07 11:14:25 +0000312tool_patterns = [r"\bFileCheck\b",
313 r"\bc-index-test\b",
314 NoPreHyphenDot + r"\bclang-check\b" + NoPostHyphenDot,
315 NoPreHyphenDot + r"\bclang-format\b" + NoPostHyphenDot,
316 # FIXME: Some clang test uses opt?
317 NoPreHyphenDot + r"\bopt\b" + NoPostBar + NoPostHyphenDot,
318 # Handle these specially as they are strings searched
319 # for during testing.
320 r"\| \bcount\b",
321 r"\| \bnot\b"]
322
323if config.clang_examples:
324 tool_patterns.append(NoPreHyphenDot + r"\bclang-interpreter\b" + NoPostHyphenDot)
325
326for pattern in tool_patterns:
Paul Robinson5df175c2014-03-26 16:40:43 +0000327 # Extract the tool name from the pattern. This relies on the tool
328 # name being surrounded by \b word match operators. If the
329 # pattern starts with "| ", include it in the string to be
330 # substituted.
331 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
332 pattern)
333 tool_pipe = tool_match.group(2)
334 tool_name = tool_match.group(4)
335 tool_path = lit.util.which(tool_name, tool_dirs)
336 if not tool_path:
337 # Warn, but still provide a substitution.
338 lit_config.note('Did not find ' + tool_name + ' in ' + tool_dirs)
339 tool_path = clang_tools_dir + '/' + tool_name
340 config.substitutions.append((pattern, tool_pipe + tool_path))
341
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +0000342###
343
344# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +0000345#
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +0000346# Enabled/disabled features
347if config.clang_staticanalyzer != 0:
348 config.available_features.add("staticanalyzer")
349
Andrew Trick3df28242011-08-26 22:46:31 +0000350# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
351if platform.system() not in ['FreeBSD']:
352 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000353
354# Shell execution
Reid Kleckner0675f852013-04-11 13:34:18 +0000355if execute_external:
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000356 config.available_features.add('shell')
Galina Kistanovab38fd262011-06-03 18:36:30 +0000357
Adrian Prantl4e2292e2014-02-20 17:53:17 +0000358# For tests that require Darwin to run.
Adrian Prantl0e79c002014-02-20 19:51:46 +0000359# This is used by debuginfo-tests/*block*.m and debuginfo-tests/foreach.m.
Adrian Prantl4e2292e2014-02-20 17:53:17 +0000360if platform.system() in ['Darwin']:
361 config.available_features.add('system-darwin')
Andrea Di Biagioe6538112014-04-29 20:19:13 +0000362elif platform.system() in ['Windows']:
363 # For tests that require Windows to run.
364 config.available_features.add('system-windows')
Adrian Prantl4e2292e2014-02-20 17:53:17 +0000365
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +0000366# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +0000367if platform.system() not in ['Windows']:
368 config.available_features.add('ansi-escape-sequences')
369
NAKAMURA Takumi0c81c712014-02-06 07:15:59 +0000370# Capability to print utf8 to the terminal.
371# Windows expects codepage, unless Wide API.
372if platform.system() not in ['Windows']:
373 config.available_features.add('utf8-capable-terminal')
374
Justin Bognera4fb7992014-03-11 04:34:17 +0000375# Native compilation: Check if triples match.
376# FIXME: Consider cases that target can be executed
377# even if host_triple were different from target_triple.
378if config.host_triple == config.target_triple:
Amaury de la Vieuville7681afd2013-09-13 11:02:31 +0000379 config.available_features.add("native")
380
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000381# Case-insensitive file system
382def is_filesystem_case_insensitive():
Argyrios Kyrtzidisd6bdafc2012-11-01 00:59:15 +0000383 handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000384 isInsensitive = os.path.exists(
385 os.path.join(
386 os.path.dirname(path),
387 os.path.basename(path).upper()
388 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000389 os.close(handle)
390 os.remove(path)
391 return isInsensitive
392
393if is_filesystem_case_insensitive():
394 config.available_features.add('case-insensitive-filesystem')
395
Daniel Dunbar52385592012-11-15 20:06:10 +0000396# Tests that require the /dev/fd filesystem.
NAKAMURA Takumieb360a02012-11-27 05:25:41 +0000397if os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000398 config.available_features.add('dev-fd-fs')
399
NAKAMURA Takumi08848872014-02-16 10:15:57 +0000400# Not set on native MS environment.
401if not re.match(r'.*-win32$', config.target_triple):
402 config.available_features.add('non-ms-sdk')
403
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000404# Not set on native PS4 environment.
Filipe Cabecinhas10ff1332015-02-02 23:17:54 +0000405if not re.match(r'.*-scei-ps4', config.target_triple):
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000406 config.available_features.add('non-ps4-sdk')
407
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000408# [PR8833] LLP64-incompatible tests
Yaron Kerenf6309712014-12-17 09:55:15 +0000409if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple):
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000410 config.available_features.add('LP64')
411
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000412# [PR12920] "clang-driver" -- set if gcc driver is not used.
NAKAMURA Takumi79e40ec2015-10-20 22:36:16 +0000413if not re.match(r'.*-(cygwin)$', config.target_triple):
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000414 config.available_features.add('clang-driver')
415
NAKAMURA Takumi23c76712014-02-16 10:15:34 +0000416# [PR18856] Depends to remove opened file. On win32, a file could be removed
417# only if all handles were closed.
418if platform.system() not in ['Windows']:
419 config.available_features.add('can-remove-opened-file')
420
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000421# Returns set of available features, registered-target(s) and asserts.
422def get_llvm_config_props():
423 set_of_features = set()
424
425 cmd = subprocess.Popen(
426 [
427 os.path.join(llvm_tools_dir, 'llvm-config'),
428 '--assertion-mode',
429 '--targets-built',
430 ],
Scott Douglassdf914d52014-09-24 18:37:52 +0000431 stdout=subprocess.PIPE,
432 env=config.environment
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000433 )
434 # 1st line corresponds to --assertion-mode, "ON" or "OFF".
435 line = cmd.stdout.readline().strip().decode('ascii')
436 if line == "ON":
437 set_of_features.add('asserts')
438
439 # 2nd line corresponds to --targets-built, like;
440 # AArch64 ARM CppBackend X86
441 for arch in cmd.stdout.readline().decode('ascii').split():
442 set_of_features.add(arch.lower() + '-registered-target')
443
444 return set_of_features
445
446config.available_features.update(get_llvm_config_props())
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000447
448if lit.util.which('xmllint'):
449 config.available_features.add('xmllint')
450
Alexey Samsonov55b688f2013-03-26 08:28:18 +0000451# Sanitizers.
Justin Bogner4c4628c2015-06-22 18:47:10 +0000452if 'Address' in config.llvm_use_sanitizer:
Alexey Samsonov55b688f2013-03-26 08:28:18 +0000453 config.available_features.add("asan")
Alexey Samsonovb80effd2014-01-28 06:59:32 +0000454else:
455 config.available_features.add("not_asan")
Justin Bogner4c4628c2015-06-22 18:47:10 +0000456if 'Memory' in config.llvm_use_sanitizer:
Alexey Samsonov55b688f2013-03-26 08:28:18 +0000457 config.available_features.add("msan")
Justin Bogner4c4628c2015-06-22 18:47:10 +0000458if 'Undefined' in config.llvm_use_sanitizer:
Alexey Samsonov3205b512014-09-03 19:46:32 +0000459 config.available_features.add("ubsan")
460else:
461 config.available_features.add("not_ubsan")
Michael Gottesman6ef6e142013-06-19 23:23:49 +0000462
Pete Cooper7dc8af52015-02-10 19:53:38 +0000463if config.enable_backtrace == "1":
464 config.available_features.add("backtrace")
465
Richard Smithaada85c2016-02-06 02:06:43 +0000466if config.have_zlib == "1":
467 config.available_features.add("zlib")
468else:
469 config.available_features.add("nozlib")
470
Michael Gottesman6ef6e142013-06-19 23:23:49 +0000471# Check if we should run long running tests.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000472if lit_config.params.get("run_long_tests", None) == "true":
Michael Gottesman6ef6e142013-06-19 23:23:49 +0000473 config.available_features.add("long_tests")
David Dean9b9c78a2013-07-11 23:37:50 +0000474
475# Check if we should use gmalloc.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000476use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
David Dean9b9c78a2013-07-11 23:37:50 +0000477if use_gmalloc_str is not None:
478 if use_gmalloc_str.lower() in ('1', 'true'):
479 use_gmalloc = True
480 elif use_gmalloc_str.lower() in ('', '0', 'false'):
481 use_gmalloc = False
482 else:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000483 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
David Dean9b9c78a2013-07-11 23:37:50 +0000484else:
485 # Default to not using gmalloc
486 use_gmalloc = False
487
488# Allow use of an explicit path for gmalloc library.
489# Will default to '/usr/lib/libgmalloc.dylib' if not set.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000490gmalloc_path_str = lit_config.params.get('gmalloc_path',
491 '/usr/lib/libgmalloc.dylib')
David Dean9b9c78a2013-07-11 23:37:50 +0000492if use_gmalloc:
493 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
Daniel Dunbar184687b2013-11-06 21:44:54 +0000494
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000495# Check if we should allow outputs to console.
496run_console_tests = int(lit_config.params.get('enable_console', '0'))
497if run_console_tests != 0:
498 config.available_features.add('console')
499
Alexander Potapenko14f8ac02014-06-10 14:22:00 +0000500lit.util.usePlatformSdkOnDarwin(config, lit_config)