blob: 66cec612a3f0f4c8e43479b327248a6c64c8ec95 [file] [log] [blame]
Daniel Dunbar1db467f2009-07-31 05:54:17 +00001# -*- Python -*-
2
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +00003import os
Daniel Dunbarb850ddd2009-09-22 10:08:03 +00004import platform
Chandler Carruthb40fd3f2011-11-05 20:55:50 +00005import re
6import subprocess
Argyrios Kyrtzidis4182ed62012-10-31 20:59:50 +00007import tempfile
Chandler Carruthb40fd3f2011-11-05 20:55:50 +00008
Daniel Dunbar4c87ca42013-08-09 14:43:04 +00009import lit.formats
10import lit.util
Daniel Dunbar724827f2009-09-08 16:39:23 +000011
Daniel Dunbar1db467f2009-07-31 05:54:17 +000012# Configuration file for the 'lit' test runner.
13
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000014# name: The name of this test suite.
15config.name = 'Clang'
Daniel Dunbar724827f2009-09-08 16:39:23 +000016
NAKAMURA Takumi98af1ac2011-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 Dunbar4c87ca42013-08-09 14:43:04 +000021 path = lit_config.getToolsPath(path,
22 config.environment['PATH'],
23 ['cmp.exe', 'grep.exe', 'sed.exe'])
NAKAMURA Takumi98af1ac2011-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 Klecknera53763f2013-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 Dunbar5e01e3c2009-09-22 05:16:02 +000040# testFormat: The test format to use to interpret tests.
Daniel Dunbar1db467f2009-07-31 05:54:17 +000041#
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000042# For now we require '&&' between commands, until they get globally killed and
43# the test runner updated.
Daniel Dunbarbc20ef32009-11-08 01:47:35 +000044config.test_format = lit.formats.ShTest(execute_external)
Daniel Dunbar6827f3f2009-09-06 01:31:12 +000045
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000046# suffixes: A list of file extensions to treat as test files.
Stephen Hines651f13c2014-04-23 16:59:28 -070047config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S']
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000048
Alp Toker6c6fd7e2013-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 Dunbar5e01e3c2009-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 Rose40f45ee2012-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',
76# 'IOS_SIMULATOR_DEPLOYMENT_TARGET',
77# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
78# 'VC80COMNTOOLS')
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000079possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Jordy Rose40f45ee2012-04-06 18:14:01 +000080 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
81 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
82 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
83 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
84 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
85 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
86 'LIBCLANG_RESOURCE_USAGE',
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000087 'LIBCLANG_CODE_COMPLETION_LOGGING']
88# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
89if platform.system() != 'Windows':
90 possibly_dangerous_env_vars.append('INCLUDE')
Jordy Rose40f45ee2012-04-06 18:14:01 +000091for name in possibly_dangerous_env_vars:
92 if name in config.environment:
93 del config.environment[name]
94
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000095# Tweak the PATH to include the tools dir and the scripts dir.
96if clang_obj_root is not None:
Stephen Hines651f13c2014-04-23 16:59:28 -070097 clang_tools_dir = getattr(config, 'clang_tools_dir', None)
98 if not clang_tools_dir:
99 lit_config.fatal('No Clang tools dir set!')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000100 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
101 if not llvm_tools_dir:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000102 lit_config.fatal('No LLVM tools dir set!')
Stephen Hines651f13c2014-04-23 16:59:28 -0700103 path = os.path.pathsep.join((
104 clang_tools_dir, llvm_tools_dir, config.environment['PATH']))
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000105 config.environment['PATH'] = path
Daniel Dunbar9e10cc72009-09-26 07:36:09 +0000106 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
107 if not llvm_libs_dir:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000108 lit_config.fatal('No LLVM libs dir set!')
Daniel Dunbar9e10cc72009-09-26 07:36:09 +0000109 path = os.path.pathsep.join((llvm_libs_dir,
110 config.environment.get('LD_LIBRARY_PATH','')))
111 config.environment['LD_LIBRARY_PATH'] = path
112
Alexey Samsonov32d2a652013-04-04 07:41:20 +0000113# Propagate path to symbolizer for ASan/MSan.
114for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
115 if symbolizer in os.environ:
116 config.environment[symbolizer] = os.environ[symbolizer]
117
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000118###
119
120# Check that the object root is known.
121if config.test_exec_root is None:
122 # Otherwise, we haven't loaded the site specific configuration (the user is
123 # probably trying to run on a test file directly, and either the site
124 # configuration hasn't been created by the build system, or we are in an
125 # out-of-tree build situation).
126
Daniel Dunbarb258d8f2009-11-05 16:36:19 +0000127 # Check for 'clang_site_config' user parameter, and use that if available.
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000128 site_cfg = lit_config.params.get('clang_site_config', None)
Daniel Dunbarb258d8f2009-11-05 16:36:19 +0000129 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000130 lit_config.load_config(config, site_cfg)
Daniel Dunbarb258d8f2009-11-05 16:36:19 +0000131 raise SystemExit
132
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000133 # Try to detect the situation where we are using an out-of-tree build by
134 # looking for 'llvm-config'.
135 #
136 # FIXME: I debated (i.e., wrote and threw away) adding logic to
137 # automagically generate the lit.site.cfg if we are in some kind of fresh
Daniel Dunbar23354212009-11-07 23:53:17 +0000138 # build situation. This means knowing how to invoke the build system though,
139 # and I decided it was too much magic. We should solve this by just having
140 # the .cfg files generated during the configuration step.
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000141
142 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
143 if not llvm_config:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000144 lit_config.fatal('No site specific configuration available!')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000145
146 # Get the source and object roots.
147 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
148 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
149 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
150 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
151
152 # Validate that we got a tree which points to here, using the standard
153 # tools/clang layout.
154 this_src_root = os.path.dirname(config.test_source_root)
155 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000156 lit_config.fatal('No site specific configuration available!')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000157
158 # Check that the site specific configuration exists.
159 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
160 if not os.path.exists(site_cfg):
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000161 lit_config.fatal(
162 'No site specific configuration available! You may need to '
163 'run "make test" in your Clang build directory.')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000164
165 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000166 lit_config.note('using out-of-tree build at %r' % clang_obj_root)
167 lit_config.load_config(config, site_cfg)
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000168 raise SystemExit
169
170###
171
172# Discover the 'clang' and 'clangcc' to use.
173
174import os
175
176def inferClang(PATH):
177 # Determine which clang to use.
178 clang = os.getenv('CLANG')
179
180 # If the user set clang in the environment, definitely use that and don't
181 # try to validate.
182 if clang:
183 return clang
184
185 # Otherwise look in the path.
186 clang = lit.util.which('clang', PATH)
187
188 if not clang:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000189 lit_config.fatal("couldn't find 'clang' program, try setting "
190 "CLANG in your environment")
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000191
192 return clang
193
NAKAMURA Takumi9085e6f2011-03-05 11:16:06 +0000194config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000195if not lit_config.quiet:
196 lit_config.note('using clang: %r' % config.clang)
Chandler Carruth044a790c2011-11-05 10:15:27 +0000197
Stephen Hines651f13c2014-04-23 16:59:28 -0700198# Plugins (loadable modules)
199# TODO: This should be supplied by Makefile or autoconf.
200if sys.platform in ['win32', 'cygwin']:
201 has_plugins = (config.enable_shared == 1)
202else:
203 has_plugins = True
204
205if has_plugins and config.llvm_plugin_ext:
206 config.available_features.add('plugins')
207
208config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
209config.substitutions.append( ('%pluginext', config.llvm_plugin_ext) )
210
211if config.clang_examples:
212 config.available_features.add('examples')
213
Chandler Carruth044a790c2011-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 Carruthdf0a4c32011-11-05 23:29:28 +0000217def getClangBuiltinIncludeDir(clang):
Chandler Carruthb40fd3f2011-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 Carruthdf0a4c32011-11-05 23:29:28 +0000220 cmd = subprocess.Popen([clang, '-print-file-name=include'],
221 stdout=subprocess.PIPE)
222 if not cmd.stdout:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000223 lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
NAKAMURA Takumi5407d4a2013-06-26 10:45:20 +0000224 dir = cmd.stdout.read().strip()
225 if sys.platform in ['win32'] and execute_external:
226 # Don't pass dosish path separator to msys bash.exe.
227 dir = dir.replace('\\', '/')
Daniel Dunbar03f443a2013-08-14 16:32:20 +0000228 # Ensure the result is an ascii string, across Python2.5+ - Python3.
229 return str(dir.decode('ascii'))
Chandler Carruthb40fd3f2011-11-05 20:55:50 +0000230
Stephen Hines651f13c2014-04-23 16:59:28 -0700231def makeItaniumABITriple(triple):
232 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
233 if not m:
234 lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
235 if m.group(3).lower() != 'win32':
236 # All non-win32 triples use the Itanium ABI.
237 return triple
238 return m.group(1) + '-' + m.group(2) + '-mingw32'
239
240def makeMSABITriple(triple):
241 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
242 if not m:
243 lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
244 isa = m.group(1).lower()
245 vendor = m.group(2).lower()
246 os = m.group(3).lower()
247 if os == 'win32':
248 # If the OS is win32, we're done.
249 return triple
250 if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
251 # For x86 ISAs, adjust the OS.
252 return isa + '-' + vendor + '-win32'
253 # -win32 is not supported for non-x86 targets; use a default.
254 return 'i686-pc-win32'
255
Chandler Carruth07643082011-11-07 09:17:31 +0000256config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s'
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000257 % (config.clang,
258 getClangBuiltinIncludeDir(config.clang))) )
Hans Wennborg76b86c22013-07-18 20:29:38 +0000259config.substitutions.append( ('%clang_cpp', ' ' + config.clang +
260 ' --driver-mode=cpp '))
Hans Wennborgc2f531a2013-07-19 20:33:20 +0000261config.substitutions.append( ('%clang_cl', ' ' + config.clang +
262 ' --driver-mode=cl '))
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000263config.substitutions.append( ('%clangxx', ' ' + config.clang +
Hans Wennborg76b86c22013-07-18 20:29:38 +0000264 ' --driver-mode=g++ '))
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000265config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Devang Patel8c6b9132010-09-13 20:46:23 +0000266config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Stephen Hines651f13c2014-04-23 16:59:28 -0700267config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) )
268config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) )
Daniel Dunbara5728872009-12-15 20:14:24 +0000269
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000270# FIXME: Find nicer way to prohibit this.
271config.substitutions.append(
272 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
273config.substitutions.append(
David Greene431feb52011-01-03 17:28:52 +0000274 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar679d6052010-02-17 20:31:01 +0000275config.substitutions.append(
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000276 (' clang-cc ',
277 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
278config.substitutions.append(
279 (' clang -cc1 ',
280 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000281config.substitutions.append(
282 (' %clang-cc1 ',
283 """*** invalid substitution, use '%clang_cc1'. ***""") )
Hans Wennborg76b86c22013-07-18 20:29:38 +0000284config.substitutions.append(
285 (' %clang-cpp ',
286 """*** invalid substitution, use '%clang_cpp'. ***""") )
Hans Wennborgc2f531a2013-07-19 20:33:20 +0000287config.substitutions.append(
288 (' %clang-cl ',
289 """*** invalid substitution, use '%clang_cl'. ***""") )
Daniel Dunbardb918642010-08-24 21:39:55 +0000290
Stephen Hines651f13c2014-04-23 16:59:28 -0700291# For each occurrence of a clang tool name as its own word, replace it
292# with the full path to the build directory holding that tool. This
293# ensures that we are testing the tools just built and not some random
294# tools that might happen to be in the user's PATH.
295tool_dirs = os.path.pathsep.join((clang_tools_dir, llvm_tools_dir))
296
297# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
298# For example, don't match 'clang-check-' or '.clang-format'.
299NoPreHyphenDot = r"(?<!(-|\.))"
300NoPostHyphenDot = r"(?!(-|\.))"
301
302for pattern in [r"\bFileCheck\b",
303 r"\bc-index-test\b",
304 NoPreHyphenDot + r"\bclang-check\b" + NoPostHyphenDot,
305 NoPreHyphenDot + r"\bclang-format\b" + NoPostHyphenDot,
306 # FIXME: Some clang test uses opt?
307 NoPreHyphenDot + r"\bopt\b" + NoPostHyphenDot,
308 # Handle these specially as they are strings searched
309 # for during testing.
310 r"\| \bcount\b",
311 r"\| \bnot\b"]:
312 # Extract the tool name from the pattern. This relies on the tool
313 # name being surrounded by \b word match operators. If the
314 # pattern starts with "| ", include it in the string to be
315 # substituted.
316 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
317 pattern)
318 tool_pipe = tool_match.group(2)
319 tool_name = tool_match.group(4)
320 tool_path = lit.util.which(tool_name, tool_dirs)
321 if not tool_path:
322 # Warn, but still provide a substitution.
323 lit_config.note('Did not find ' + tool_name + ' in ' + tool_dirs)
324 tool_path = clang_tools_dir + '/' + tool_name
325 config.substitutions.append((pattern, tool_pipe + tool_path))
326
Daniel Dunbardb918642010-08-24 21:39:55 +0000327###
328
329# Set available features we allow tests to conditionalize on.
Andrew Trick6da28e22011-08-26 22:46:31 +0000330#
331# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
332if platform.system() not in ['FreeBSD']:
333 config.available_features.add('crash-recovery')
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000334
335# Shell execution
Reid Klecknera53763f2013-04-11 13:34:18 +0000336if execute_external:
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000337 config.available_features.add('shell')
Galina Kistanovaee226972011-06-03 18:36:30 +0000338
NAKAMURA Takumi05a10ff2013-01-16 06:10:16 +0000339# Exclude MSYS due to transforming '/' to 'X:/mingwroot/'.
Hans Wennborgde56bb72013-08-05 20:14:43 +0000340if not platform.system() in ['Windows'] or not execute_external:
NAKAMURA Takumi05a10ff2013-01-16 06:10:16 +0000341 config.available_features.add('shell-preserves-root')
342
Stephen Hines651f13c2014-04-23 16:59:28 -0700343# For tests that require Darwin to run.
344# This is used by debuginfo-tests/*block*.m and debuginfo-tests/foreach.m.
345if platform.system() in ['Darwin']:
346 config.available_features.add('system-darwin')
347
NAKAMURA Takumi5e3d24c2012-09-12 10:38:03 +0000348# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumi0ca4be32012-07-11 11:44:00 +0000349if platform.system() not in ['Windows']:
350 config.available_features.add('ansi-escape-sequences')
351
Stephen Hines651f13c2014-04-23 16:59:28 -0700352# Capability to print utf8 to the terminal.
353# Windows expects codepage, unless Wide API.
354if platform.system() not in ['Windows']:
355 config.available_features.add('utf8-capable-terminal')
356
357# Native compilation: Check if triples match.
358# FIXME: Consider cases that target can be executed
359# even if host_triple were different from target_triple.
360if config.host_triple == config.target_triple:
Amaury de la Vieuville09098592013-09-13 11:02:31 +0000361 config.available_features.add("native")
362
Argyrios Kyrtzidis4182ed62012-10-31 20:59:50 +0000363# Case-insensitive file system
364def is_filesystem_case_insensitive():
Argyrios Kyrtzidisb2ed96a2012-11-01 00:59:15 +0000365 handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi80db6a72013-07-01 09:51:55 +0000366 isInsensitive = os.path.exists(
367 os.path.join(
368 os.path.dirname(path),
369 os.path.basename(path).upper()
370 ))
Argyrios Kyrtzidis4182ed62012-10-31 20:59:50 +0000371 os.close(handle)
372 os.remove(path)
373 return isInsensitive
374
375if is_filesystem_case_insensitive():
376 config.available_features.add('case-insensitive-filesystem')
377
Daniel Dunbar0b95bd02012-11-15 20:06:10 +0000378# Tests that require the /dev/fd filesystem.
NAKAMURA Takumi93308b92012-11-27 05:25:41 +0000379if os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']:
Daniel Dunbar0b95bd02012-11-15 20:06:10 +0000380 config.available_features.add('dev-fd-fs')
381
Stephen Hines651f13c2014-04-23 16:59:28 -0700382# DW2 Target
383if not re.match(r'.*-win32$', config.target_triple):
384 config.available_features.add('dw2')
385
386# Not set on native MS environment.
387if not re.match(r'.*-win32$', config.target_triple):
388 config.available_features.add('non-ms-sdk')
389
NAKAMURA Takumib774d732012-09-12 10:45:40 +0000390# [PR8833] LLP64-incompatible tests
391if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple):
392 config.available_features.add('LP64')
393
NAKAMURA Takumi5e4ccb42012-12-11 07:06:09 +0000394# [PR12920] "clang-driver" -- set if gcc driver is not used.
395if not re.match(r'.*-(cygwin|mingw32)$', config.target_triple):
396 config.available_features.add('clang-driver')
397
Stephen Hines651f13c2014-04-23 16:59:28 -0700398# [PR18856] Depends to remove opened file. On win32, a file could be removed
399# only if all handles were closed.
400if platform.system() not in ['Windows']:
401 config.available_features.add('can-remove-opened-file')
Galina Kistanovaee226972011-06-03 18:36:30 +0000402
Stephen Hines651f13c2014-04-23 16:59:28 -0700403# Returns set of available features, registered-target(s) and asserts.
404def get_llvm_config_props():
405 set_of_features = set()
Galina Kistanovaee226972011-06-03 18:36:30 +0000406
Stephen Hines651f13c2014-04-23 16:59:28 -0700407 cmd = subprocess.Popen(
408 [
409 os.path.join(llvm_tools_dir, 'llvm-config'),
410 '--assertion-mode',
411 '--targets-built',
412 ],
413 stdout=subprocess.PIPE
414 )
415 # 1st line corresponds to --assertion-mode, "ON" or "OFF".
416 line = cmd.stdout.readline().strip().decode('ascii')
417 if line == "ON":
418 set_of_features.add('asserts')
Galina Kistanovaee226972011-06-03 18:36:30 +0000419
Stephen Hines651f13c2014-04-23 16:59:28 -0700420 # 2nd line corresponds to --targets-built, like;
421 # AArch64 ARM CppBackend X86
422 for arch in cmd.stdout.readline().decode('ascii').split():
423 set_of_features.add(arch.lower() + '-registered-target')
Galina Kistanovaee226972011-06-03 18:36:30 +0000424
Stephen Hines651f13c2014-04-23 16:59:28 -0700425 return set_of_features
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000426
Stephen Hines651f13c2014-04-23 16:59:28 -0700427config.available_features.update(get_llvm_config_props())
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +0000428
429if lit.util.which('xmllint'):
430 config.available_features.add('xmllint')
431
Alexey Samsonov48c08342013-03-26 08:28:18 +0000432# Sanitizers.
433if config.llvm_use_sanitizer == "Address":
434 config.available_features.add("asan")
Stephen Hines651f13c2014-04-23 16:59:28 -0700435else:
436 config.available_features.add("not_asan")
Alexey Samsonov48c08342013-03-26 08:28:18 +0000437if (config.llvm_use_sanitizer == "Memory" or
438 config.llvm_use_sanitizer == "MemoryWithOrigins"):
439 config.available_features.add("msan")
Michael Gottesman63f40502013-06-19 23:23:49 +0000440
441# Check if we should run long running tests.
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000442if lit_config.params.get("run_long_tests", None) == "true":
Michael Gottesman63f40502013-06-19 23:23:49 +0000443 config.available_features.add("long_tests")
David Dean22d017d2013-07-11 23:37:50 +0000444
445# Check if we should use gmalloc.
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000446use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
David Dean22d017d2013-07-11 23:37:50 +0000447if use_gmalloc_str is not None:
448 if use_gmalloc_str.lower() in ('1', 'true'):
449 use_gmalloc = True
450 elif use_gmalloc_str.lower() in ('', '0', 'false'):
451 use_gmalloc = False
452 else:
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000453 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
David Dean22d017d2013-07-11 23:37:50 +0000454else:
455 # Default to not using gmalloc
456 use_gmalloc = False
457
458# Allow use of an explicit path for gmalloc library.
459# Will default to '/usr/lib/libgmalloc.dylib' if not set.
Daniel Dunbar4c87ca42013-08-09 14:43:04 +0000460gmalloc_path_str = lit_config.params.get('gmalloc_path',
461 '/usr/lib/libgmalloc.dylib')
David Dean22d017d2013-07-11 23:37:50 +0000462if use_gmalloc:
463 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
Daniel Dunbar8ad46b72013-11-06 21:44:54 +0000464
465# On Darwin, support relocatable SDKs by providing Clang with a
466# default system root path.
467if 'darwin' in config.target_triple:
Joerg Sonnenbergera6834042013-11-14 23:18:08 +0000468 try:
469 cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
470 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
471 out, err = cmd.communicate()
472 out = out.strip()
473 res = cmd.wait()
474 except OSError:
475 res = -1
Daniel Dunbar8ad46b72013-11-06 21:44:54 +0000476 if res == 0 and out:
477 sdk_path = out
478 lit_config.note('using SDKROOT: %r' % sdk_path)
479 config.environment['SDKROOT'] = sdk_path