blob: bf8528b3f68a2984d662fd2df1621265aaf436a7 [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 Dunbar724827f2009-09-08 16:39:23 +00009
Daniel Dunbar1db467f2009-07-31 05:54:17 +000010# Configuration file for the 'lit' test runner.
11
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000012# name: The name of this test suite.
13config.name = 'Clang'
Daniel Dunbar724827f2009-09-08 16:39:23 +000014
NAKAMURA Takumi98af1ac2011-02-09 04:19:57 +000015# Tweak PATH for Win32
16if platform.system() == 'Windows':
17 # Seek sane tools in directories and set to $PATH.
18 path = getattr(config, 'lit_tools_dir', None)
19 path = lit.getToolsPath(path,
20 config.environment['PATH'],
21 ['cmp.exe', 'grep.exe', 'sed.exe'])
22 if path is not None:
23 path = os.path.pathsep.join((path,
24 config.environment['PATH']))
25 config.environment['PATH'] = path
26
Reid Klecknera53763f2013-04-11 13:34:18 +000027# Choose between lit's internal shell pipeline runner and a real shell. If
28# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
29use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
30if use_lit_shell:
31 # 0 is external, "" is default, and everything else is internal.
32 execute_external = (use_lit_shell == "0")
33else:
34 # Otherwise we default to internal on Windows and external elsewhere, as
35 # bash on Windows is usually very slow.
36 execute_external = (not sys.platform in ['win32'])
37
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000038# testFormat: The test format to use to interpret tests.
Daniel Dunbar1db467f2009-07-31 05:54:17 +000039#
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000040# For now we require '&&' between commands, until they get globally killed and
41# the test runner updated.
Daniel Dunbarbc20ef32009-11-08 01:47:35 +000042config.test_format = lit.formats.ShTest(execute_external)
Daniel Dunbar6827f3f2009-09-06 01:31:12 +000043
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000044# suffixes: A list of file extensions to treat as test files.
Jim Grosbachfc308292012-02-10 20:37:10 +000045config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s']
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000046
47# test_source_root: The root path where tests are located.
48config.test_source_root = os.path.dirname(__file__)
49
50# test_exec_root: The root path where tests should be run.
51clang_obj_root = getattr(config, 'clang_obj_root', None)
52if clang_obj_root is not None:
53 config.test_exec_root = os.path.join(clang_obj_root, 'test')
54
55# Set llvm_{src,obj}_root for use by others.
56config.llvm_src_root = getattr(config, 'llvm_src_root', None)
57config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
58
Jordy Rose40f45ee2012-04-06 18:14:01 +000059# Clear some environment variables that might affect Clang.
60#
61# This first set of vars are read by Clang, but shouldn't affect tests
62# that aren't specifically looking for these features, or are required
63# simply to run the tests at all.
64#
65# FIXME: Should we have a tool that enforces this?
66
67# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
68# 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
69# 'IOS_SIMULATOR_DEPLOYMENT_TARGET',
70# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
71# 'VC80COMNTOOLS')
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000072possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Jordy Rose40f45ee2012-04-06 18:14:01 +000073 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
74 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
75 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
76 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
77 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
78 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
79 'LIBCLANG_RESOURCE_USAGE',
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000080 'LIBCLANG_CODE_COMPLETION_LOGGING']
81# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
82if platform.system() != 'Windows':
83 possibly_dangerous_env_vars.append('INCLUDE')
Jordy Rose40f45ee2012-04-06 18:14:01 +000084for name in possibly_dangerous_env_vars:
85 if name in config.environment:
86 del config.environment[name]
87
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000088# Tweak the PATH to include the tools dir and the scripts dir.
89if clang_obj_root is not None:
90 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
91 if not llvm_tools_dir:
92 lit.fatal('No LLVM tools dir set!')
Daniel Dunbaree45d6d2009-09-24 06:31:08 +000093 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000094 config.environment['PATH'] = path
Daniel Dunbar9e10cc72009-09-26 07:36:09 +000095 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
96 if not llvm_libs_dir:
97 lit.fatal('No LLVM libs dir set!')
98 path = os.path.pathsep.join((llvm_libs_dir,
99 config.environment.get('LD_LIBRARY_PATH','')))
100 config.environment['LD_LIBRARY_PATH'] = path
101
Alexey Samsonov32d2a652013-04-04 07:41:20 +0000102# Propagate path to symbolizer for ASan/MSan.
103for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
104 if symbolizer in os.environ:
105 config.environment[symbolizer] = os.environ[symbolizer]
106
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000107###
108
109# Check that the object root is known.
110if config.test_exec_root is None:
111 # Otherwise, we haven't loaded the site specific configuration (the user is
112 # probably trying to run on a test file directly, and either the site
113 # configuration hasn't been created by the build system, or we are in an
114 # out-of-tree build situation).
115
Daniel Dunbarb258d8f2009-11-05 16:36:19 +0000116 # Check for 'clang_site_config' user parameter, and use that if available.
117 site_cfg = lit.params.get('clang_site_config', None)
118 if site_cfg and os.path.exists(site_cfg):
119 lit.load_config(config, site_cfg)
120 raise SystemExit
121
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000122 # Try to detect the situation where we are using an out-of-tree build by
123 # looking for 'llvm-config'.
124 #
125 # FIXME: I debated (i.e., wrote and threw away) adding logic to
126 # automagically generate the lit.site.cfg if we are in some kind of fresh
Daniel Dunbar23354212009-11-07 23:53:17 +0000127 # build situation. This means knowing how to invoke the build system though,
128 # and I decided it was too much magic. We should solve this by just having
129 # the .cfg files generated during the configuration step.
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000130
131 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
132 if not llvm_config:
133 lit.fatal('No site specific configuration available!')
134
135 # Get the source and object roots.
136 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
137 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
138 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
139 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
140
141 # Validate that we got a tree which points to here, using the standard
142 # tools/clang layout.
143 this_src_root = os.path.dirname(config.test_source_root)
144 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
145 lit.fatal('No site specific configuration available!')
146
147 # Check that the site specific configuration exists.
148 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
149 if not os.path.exists(site_cfg):
Nico Weberb4a88ef2010-09-27 20:40:32 +0000150 lit.fatal('No site specific configuration available! You may need to '
151 'run "make test" in your Clang build directory.')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000152
153 # Okay, that worked. Notify the user of the automagic, and reconfigure.
154 lit.note('using out-of-tree build at %r' % clang_obj_root)
155 lit.load_config(config, site_cfg)
156 raise SystemExit
157
158###
159
160# Discover the 'clang' and 'clangcc' to use.
161
162import os
163
164def inferClang(PATH):
165 # Determine which clang to use.
166 clang = os.getenv('CLANG')
167
168 # If the user set clang in the environment, definitely use that and don't
169 # try to validate.
170 if clang:
171 return clang
172
173 # Otherwise look in the path.
174 clang = lit.util.which('clang', PATH)
175
176 if not clang:
177 lit.fatal("couldn't find 'clang' program, try setting "
178 "CLANG in your environment")
179
180 return clang
181
NAKAMURA Takumi9085e6f2011-03-05 11:16:06 +0000182config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000183if not lit.quiet:
184 lit.note('using clang: %r' % config.clang)
Chandler Carruth044a790c2011-11-05 10:15:27 +0000185
186# Note that when substituting %clang_cc1 also fill in the include directory of
187# the builtin headers. Those are part of even a freestanding environment, but
188# Clang relies on the driver to locate them.
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000189def getClangBuiltinIncludeDir(clang):
Chandler Carruthb40fd3f2011-11-05 20:55:50 +0000190 # FIXME: Rather than just getting the version, we should have clang print
191 # out its resource dir here in an easy to scrape form.
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000192 cmd = subprocess.Popen([clang, '-print-file-name=include'],
193 stdout=subprocess.PIPE)
194 if not cmd.stdout:
195 lit.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
NAKAMURA Takumi5407d4a2013-06-26 10:45:20 +0000196 dir = cmd.stdout.read().strip()
197 if sys.platform in ['win32'] and execute_external:
198 # Don't pass dosish path separator to msys bash.exe.
199 dir = dir.replace('\\', '/')
200 return dir
Chandler Carruthb40fd3f2011-11-05 20:55:50 +0000201
Chandler Carruth07643082011-11-07 09:17:31 +0000202config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s'
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000203 % (config.clang,
204 getClangBuiltinIncludeDir(config.clang))) )
Chandler Carruth044a790c2011-11-05 10:15:27 +0000205
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000206config.substitutions.append( ('%clangxx', ' ' + config.clang +
Rafael Espindolad2d4d682012-10-30 00:13:16 +0000207 ' -ccc-cxx '))
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000208config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Devang Patel8c6b9132010-09-13 20:46:23 +0000209config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Daniel Dunbara5728872009-12-15 20:14:24 +0000210
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000211# FIXME: Find nicer way to prohibit this.
212config.substitutions.append(
213 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
214config.substitutions.append(
David Greene431feb52011-01-03 17:28:52 +0000215 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar679d6052010-02-17 20:31:01 +0000216config.substitutions.append(
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000217 (' clang-cc ',
218 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
219config.substitutions.append(
220 (' clang -cc1 ',
221 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000222config.substitutions.append(
223 (' %clang-cc1 ',
224 """*** invalid substitution, use '%clang_cc1'. ***""") )
Daniel Dunbardb918642010-08-24 21:39:55 +0000225
226###
227
228# Set available features we allow tests to conditionalize on.
Andrew Trick6da28e22011-08-26 22:46:31 +0000229#
230# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
231if platform.system() not in ['FreeBSD']:
232 config.available_features.add('crash-recovery')
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000233
234# Shell execution
Reid Klecknera53763f2013-04-11 13:34:18 +0000235if execute_external:
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000236 config.available_features.add('shell')
Galina Kistanovaee226972011-06-03 18:36:30 +0000237
NAKAMURA Takumi05a10ff2013-01-16 06:10:16 +0000238# Exclude MSYS due to transforming '/' to 'X:/mingwroot/'.
239if not platform.system() in ['Windows'] or lit.getBashPath() == '':
240 config.available_features.add('shell-preserves-root')
241
NAKAMURA Takumi5e3d24c2012-09-12 10:38:03 +0000242# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumi0ca4be32012-07-11 11:44:00 +0000243if platform.system() not in ['Windows']:
244 config.available_features.add('ansi-escape-sequences')
245
Argyrios Kyrtzidis4182ed62012-10-31 20:59:50 +0000246# Case-insensitive file system
247def is_filesystem_case_insensitive():
Argyrios Kyrtzidisb2ed96a2012-11-01 00:59:15 +0000248 handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi80db6a72013-07-01 09:51:55 +0000249 isInsensitive = os.path.exists(
250 os.path.join(
251 os.path.dirname(path),
252 os.path.basename(path).upper()
253 ))
Argyrios Kyrtzidis4182ed62012-10-31 20:59:50 +0000254 os.close(handle)
255 os.remove(path)
256 return isInsensitive
257
258if is_filesystem_case_insensitive():
259 config.available_features.add('case-insensitive-filesystem')
260
Daniel Dunbar0b95bd02012-11-15 20:06:10 +0000261# Tests that require the /dev/fd filesystem.
NAKAMURA Takumi93308b92012-11-27 05:25:41 +0000262if os.path.exists("/dev/fd/0") and sys.platform not in ['cygwin']:
Daniel Dunbar0b95bd02012-11-15 20:06:10 +0000263 config.available_features.add('dev-fd-fs')
264
NAKAMURA Takumib774d732012-09-12 10:45:40 +0000265# [PR8833] LLP64-incompatible tests
266if not re.match(r'^x86_64.*-(win32|mingw32)$', config.target_triple):
267 config.available_features.add('LP64')
268
NAKAMURA Takumi5e4ccb42012-12-11 07:06:09 +0000269# [PR12920] "clang-driver" -- set if gcc driver is not used.
270if not re.match(r'.*-(cygwin|mingw32)$', config.target_triple):
271 config.available_features.add('clang-driver')
272
Galina Kistanovaee226972011-06-03 18:36:30 +0000273# Registered Targets
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000274def get_llc_props(tool):
Galina Kistanovaee226972011-06-03 18:36:30 +0000275 set_of_targets = set()
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000276 enable_assertions = False
Galina Kistanovaee226972011-06-03 18:36:30 +0000277
278 cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE)
279
280 # Parse the stdout to get the list of registered targets.
281 parse_targets = False
282 for line in cmd.stdout:
283 if parse_targets:
284 m = re.match( r'(.*) - ', line)
285 if m is not None:
286 set_of_targets.add(m.group(1).strip() + '-registered-target')
287 else:
288 break
289 elif "Registered Targets:" in line:
290 parse_targets = True
291
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000292 if re.search(r'with assertions', line):
293 enable_assertions = True
Galina Kistanovaee226972011-06-03 18:36:30 +0000294
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000295 return {"set_of_targets": set_of_targets,
296 "enable_assertions": enable_assertions}
297
298llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc'))
299if len(llc_props['set_of_targets']) > 0:
300 config.available_features.update(llc_props['set_of_targets'])
Galina Kistanovaee226972011-06-03 18:36:30 +0000301else:
302 lit.fatal('No Targets Registered with the LLVM Tools!')
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000303
304if llc_props['enable_assertions']:
305 config.available_features.add('asserts')
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +0000306
307if lit.util.which('xmllint'):
308 config.available_features.add('xmllint')
309
Alexey Samsonov48c08342013-03-26 08:28:18 +0000310# Sanitizers.
311if config.llvm_use_sanitizer == "Address":
312 config.available_features.add("asan")
313if (config.llvm_use_sanitizer == "Memory" or
314 config.llvm_use_sanitizer == "MemoryWithOrigins"):
315 config.available_features.add("msan")
Michael Gottesman63f40502013-06-19 23:23:49 +0000316
317# Check if we should run long running tests.
318if lit.params.get("run_long_tests", None) == "true":
319 config.available_features.add("long_tests")