blob: d23a40c79b7044c0b3285f886fc48daaa0674952 [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.
Jim Grosbach576452b2012-02-10 20:37:10 +000047config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s']
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000048
49# test_source_root: The root path where tests are located.
50config.test_source_root = os.path.dirname(__file__)
51
52# test_exec_root: The root path where tests should be run.
53clang_obj_root = getattr(config, 'clang_obj_root', None)
54if clang_obj_root is not None:
55 config.test_exec_root = os.path.join(clang_obj_root, 'test')
56
57# Set llvm_{src,obj}_root for use by others.
58config.llvm_src_root = getattr(config, 'llvm_src_root', None)
59config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
60
Jordy Rose0e09fac2012-04-06 18:14:01 +000061# Clear some environment variables that might affect Clang.
62#
63# This first set of vars are read by Clang, but shouldn't affect tests
64# that aren't specifically looking for these features, or are required
65# simply to run the tests at all.
66#
67# FIXME: Should we have a tool that enforces this?
68
69# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
70# 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
71# 'IOS_SIMULATOR_DEPLOYMENT_TARGET',
72# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
73# 'VC80COMNTOOLS')
NAKAMURA Takumic4d558a2012-04-07 01:02:53 +000074possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Jordy Rose0e09fac2012-04-06 18:14:01 +000075 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
76 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
77 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
78 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
79 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
80 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
81 'LIBCLANG_RESOURCE_USAGE',
NAKAMURA Takumic4d558a2012-04-07 01:02:53 +000082 'LIBCLANG_CODE_COMPLETION_LOGGING']
83# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
84if platform.system() != 'Windows':
85 possibly_dangerous_env_vars.append('INCLUDE')
Jordy Rose0e09fac2012-04-06 18:14:01 +000086for name in possibly_dangerous_env_vars:
87 if name in config.environment:
88 del config.environment[name]
89
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000090# Tweak the PATH to include the tools dir and the scripts dir.
91if clang_obj_root is not None:
92 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
93 if not llvm_tools_dir:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000094 lit_config.fatal('No LLVM tools dir set!')
Daniel Dunbarc437eb82009-09-24 06:31:08 +000095 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000096 config.environment['PATH'] = path
Daniel Dunbara87097a2009-09-26 07:36:09 +000097 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
98 if not llvm_libs_dir:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000099 lit_config.fatal('No LLVM libs dir set!')
Daniel Dunbara87097a2009-09-26 07:36:09 +0000100 path = os.path.pathsep.join((llvm_libs_dir,
101 config.environment.get('LD_LIBRARY_PATH','')))
102 config.environment['LD_LIBRARY_PATH'] = path
103
Alexey Samsonovc01f4f02013-04-04 07:41:20 +0000104# Propagate path to symbolizer for ASan/MSan.
105for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
106 if symbolizer in os.environ:
107 config.environment[symbolizer] = os.environ[symbolizer]
108
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000109###
110
111# Check that the object root is known.
112if config.test_exec_root is None:
113 # Otherwise, we haven't loaded the site specific configuration (the user is
114 # probably trying to run on a test file directly, and either the site
115 # configuration hasn't been created by the build system, or we are in an
116 # out-of-tree build situation).
117
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000118 # Check for 'clang_site_config' user parameter, and use that if available.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000119 site_cfg = lit_config.params.get('clang_site_config', None)
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000120 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000121 lit_config.load_config(config, site_cfg)
Daniel Dunbard3f630f2009-11-05 16:36:19 +0000122 raise SystemExit
123
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000124 # Try to detect the situation where we are using an out-of-tree build by
125 # looking for 'llvm-config'.
126 #
127 # FIXME: I debated (i.e., wrote and threw away) adding logic to
128 # automagically generate the lit.site.cfg if we are in some kind of fresh
Daniel Dunbar8466a0d2009-11-07 23:53:17 +0000129 # build situation. This means knowing how to invoke the build system though,
130 # and I decided it was too much magic. We should solve this by just having
131 # the .cfg files generated during the configuration step.
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000132
133 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
134 if not llvm_config:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000135 lit_config.fatal('No site specific configuration available!')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000136
137 # Get the source and object roots.
138 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
139 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
140 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
141 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
142
143 # Validate that we got a tree which points to here, using the standard
144 # tools/clang layout.
145 this_src_root = os.path.dirname(config.test_source_root)
146 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000147 lit_config.fatal('No site specific configuration available!')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000148
149 # Check that the site specific configuration exists.
150 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
151 if not os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000152 lit_config.fatal(
153 'No site specific configuration available! You may need to '
154 'run "make test" in your Clang build directory.')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000155
156 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000157 lit_config.note('using out-of-tree build at %r' % clang_obj_root)
158 lit_config.load_config(config, site_cfg)
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000159 raise SystemExit
160
161###
162
163# Discover the 'clang' and 'clangcc' to use.
164
165import os
166
167def inferClang(PATH):
168 # Determine which clang to use.
169 clang = os.getenv('CLANG')
170
171 # If the user set clang in the environment, definitely use that and don't
172 # try to validate.
173 if clang:
174 return clang
175
176 # Otherwise look in the path.
177 clang = lit.util.which('clang', PATH)
178
179 if not clang:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000180 lit_config.fatal("couldn't find 'clang' program, try setting "
181 "CLANG in your environment")
Daniel Dunbarb5cbf772009-09-22 05:16:02 +0000182
183 return clang
184
NAKAMURA Takumi70f5be62011-03-05 11:16:06 +0000185config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000186if not lit_config.quiet:
187 lit_config.note('using clang: %r' % config.clang)
Chandler Carruthc0b1b862011-11-05 10:15:27 +0000188
189# Note that when substituting %clang_cc1 also fill in the include directory of
190# the builtin headers. Those are part of even a freestanding environment, but
191# Clang relies on the driver to locate them.
Chandler Carruth34146d82011-11-05 23:29:28 +0000192def getClangBuiltinIncludeDir(clang):
Chandler Carruth2837f662011-11-05 20:55:50 +0000193 # FIXME: Rather than just getting the version, we should have clang print
194 # out its resource dir here in an easy to scrape form.
Chandler Carruth34146d82011-11-05 23:29:28 +0000195 cmd = subprocess.Popen([clang, '-print-file-name=include'],
196 stdout=subprocess.PIPE)
197 if not cmd.stdout:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000198 lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
NAKAMURA Takumi8e85e6a2013-06-26 10:45:20 +0000199 dir = cmd.stdout.read().strip()
200 if sys.platform in ['win32'] and execute_external:
201 # Don't pass dosish path separator to msys bash.exe.
202 dir = dir.replace('\\', '/')
Daniel Dunbareff4a952013-08-14 16:32:20 +0000203 # Ensure the result is an ascii string, across Python2.5+ - Python3.
204 return str(dir.decode('ascii'))
Chandler Carruth2837f662011-11-05 20:55:50 +0000205
Chandler Carrutha62ba812011-11-07 09:17:31 +0000206config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s'
Chandler Carruth34146d82011-11-05 23:29:28 +0000207 % (config.clang,
208 getClangBuiltinIncludeDir(config.clang))) )
Hans Wennborg70850d82013-07-18 20:29:38 +0000209config.substitutions.append( ('%clang_cpp', ' ' + config.clang +
210 ' --driver-mode=cpp '))
Hans Wennborge4b031c2013-07-19 20:33:20 +0000211config.substitutions.append( ('%clang_cl', ' ' + config.clang +
212 ' --driver-mode=cl '))
Daniel Dunbar8452ef02010-06-29 16:52:24 +0000213config.substitutions.append( ('%clangxx', ' ' + config.clang +
Hans Wennborg70850d82013-07-18 20:29:38 +0000214 ' --driver-mode=g++ '))
Daniel Dunbar5618e982009-12-15 22:01:24 +0000215config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Devang Patel068b5b32010-09-13 20:46:23 +0000216config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +0000217
Daniel Dunbar5618e982009-12-15 22:01:24 +0000218# FIXME: Find nicer way to prohibit this.
219config.substitutions.append(
220 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
221config.substitutions.append(
David Greene7b293452011-01-03 17:28:52 +0000222 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar78c974f2010-02-17 20:31:01 +0000223config.substitutions.append(
Daniel Dunbar5618e982009-12-15 22:01:24 +0000224 (' clang-cc ',
225 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
226config.substitutions.append(
227 (' clang -cc1 ',
228 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar8452ef02010-06-29 16:52:24 +0000229config.substitutions.append(
230 (' %clang-cc1 ',
231 """*** invalid substitution, use '%clang_cc1'. ***""") )
Hans Wennborg70850d82013-07-18 20:29:38 +0000232config.substitutions.append(
233 (' %clang-cpp ',
234 """*** invalid substitution, use '%clang_cpp'. ***""") )
Hans Wennborge4b031c2013-07-19 20:33:20 +0000235config.substitutions.append(
236 (' %clang-cl ',
237 """*** invalid substitution, use '%clang_cl'. ***""") )
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +0000238
239###
240
241# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +0000242#
243# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
244if platform.system() not in ['FreeBSD']:
245 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000246
247# Shell execution
Reid Kleckner0675f852013-04-11 13:34:18 +0000248if execute_external:
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000249 config.available_features.add('shell')
Galina Kistanovab38fd262011-06-03 18:36:30 +0000250
NAKAMURA Takumi6c8127c2013-01-16 06:10:16 +0000251# Exclude MSYS due to transforming '/' to 'X:/mingwroot/'.
Hans Wennborgdffe5992013-08-05 20:14:43 +0000252if not platform.system() in ['Windows'] or not execute_external:
NAKAMURA Takumi6c8127c2013-01-16 06:10:16 +0000253 config.available_features.add('shell-preserves-root')
254
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +0000255# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +0000256if platform.system() not in ['Windows']:
257 config.available_features.add('ansi-escape-sequences')
258
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000259# Case-insensitive file system
260def is_filesystem_case_insensitive():
Argyrios Kyrtzidisd6bdafc2012-11-01 00:59:15 +0000261 handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000262 isInsensitive = os.path.exists(
263 os.path.join(
264 os.path.dirname(path),
265 os.path.basename(path).upper()
266 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000267 os.close(handle)
268 os.remove(path)
269 return isInsensitive
270
271if is_filesystem_case_insensitive():
272 config.available_features.add('case-insensitive-filesystem')
273
Daniel Dunbar52385592012-11-15 20:06:10 +0000274# Tests that require the /dev/fd filesystem.
NAKAMURA Takumieb360a02012-11-27 05:25:41 +0000275if os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000276 config.available_features.add('dev-fd-fs')
277
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000278# [PR8833] LLP64-incompatible tests
279if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple):
280 config.available_features.add('LP64')
281
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000282# [PR12920] "clang-driver" -- set if gcc driver is not used.
283if not re.match(r'.*-(cygwin|mingw32)$', config.target_triple):
284 config.available_features.add('clang-driver')
285
Galina Kistanovab38fd262011-06-03 18:36:30 +0000286# Registered Targets
NAKAMURA Takumicd9c3d62011-11-28 05:09:42 +0000287def get_llc_props(tool):
Galina Kistanovab38fd262011-06-03 18:36:30 +0000288 set_of_targets = set()
NAKAMURA Takumicd9c3d62011-11-28 05:09:42 +0000289 enable_assertions = False
Galina Kistanovab38fd262011-06-03 18:36:30 +0000290
291 cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE)
292
293 # Parse the stdout to get the list of registered targets.
294 parse_targets = False
295 for line in cmd.stdout:
Daniel Dunbar368baed2013-08-09 00:45:18 +0000296 line = line.decode('ascii')
Galina Kistanovab38fd262011-06-03 18:36:30 +0000297 if parse_targets:
298 m = re.match( r'(.*) - ', line)
299 if m is not None:
300 set_of_targets.add(m.group(1).strip() + '-registered-target')
301 else:
302 break
303 elif "Registered Targets:" in line:
304 parse_targets = True
305
NAKAMURA Takumicd9c3d62011-11-28 05:09:42 +0000306 if re.search(r'with assertions', line):
307 enable_assertions = True
Galina Kistanovab38fd262011-06-03 18:36:30 +0000308
NAKAMURA Takumicd9c3d62011-11-28 05:09:42 +0000309 return {"set_of_targets": set_of_targets,
310 "enable_assertions": enable_assertions}
311
312llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc'))
313if len(llc_props['set_of_targets']) > 0:
314 config.available_features.update(llc_props['set_of_targets'])
Galina Kistanovab38fd262011-06-03 18:36:30 +0000315else:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000316 lit_config.fatal('No Targets Registered with the LLVM Tools!')
NAKAMURA Takumicd9c3d62011-11-28 05:09:42 +0000317
318if llc_props['enable_assertions']:
319 config.available_features.add('asserts')
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000320
321if lit.util.which('xmllint'):
322 config.available_features.add('xmllint')
323
Alexey Samsonov55b688f2013-03-26 08:28:18 +0000324# Sanitizers.
325if config.llvm_use_sanitizer == "Address":
326 config.available_features.add("asan")
327if (config.llvm_use_sanitizer == "Memory" or
328 config.llvm_use_sanitizer == "MemoryWithOrigins"):
329 config.available_features.add("msan")
Michael Gottesman6ef6e142013-06-19 23:23:49 +0000330
331# Check if we should run long running tests.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000332if lit_config.params.get("run_long_tests", None) == "true":
Michael Gottesman6ef6e142013-06-19 23:23:49 +0000333 config.available_features.add("long_tests")
David Dean9b9c78a2013-07-11 23:37:50 +0000334
335# Check if we should use gmalloc.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000336use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
David Dean9b9c78a2013-07-11 23:37:50 +0000337if use_gmalloc_str is not None:
338 if use_gmalloc_str.lower() in ('1', 'true'):
339 use_gmalloc = True
340 elif use_gmalloc_str.lower() in ('', '0', 'false'):
341 use_gmalloc = False
342 else:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000343 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
David Dean9b9c78a2013-07-11 23:37:50 +0000344else:
345 # Default to not using gmalloc
346 use_gmalloc = False
347
348# Allow use of an explicit path for gmalloc library.
349# Will default to '/usr/lib/libgmalloc.dylib' if not set.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +0000350gmalloc_path_str = lit_config.params.get('gmalloc_path',
351 '/usr/lib/libgmalloc.dylib')
David Dean9b9c78a2013-07-11 23:37:50 +0000352
353if use_gmalloc:
354 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})