blob: 7bc9620926fae35e20072e4cfda4946922de104f [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
7
Daniel Dunbar724827f2009-09-08 16:39:23 +00008
Daniel Dunbar1db467f2009-07-31 05:54:17 +00009# Configuration file for the 'lit' test runner.
10
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000011# name: The name of this test suite.
12config.name = 'Clang'
Daniel Dunbar724827f2009-09-08 16:39:23 +000013
NAKAMURA Takumi98af1ac2011-02-09 04:19:57 +000014# Tweak PATH for Win32
15if platform.system() == 'Windows':
16 # Seek sane tools in directories and set to $PATH.
17 path = getattr(config, 'lit_tools_dir', None)
18 path = lit.getToolsPath(path,
19 config.environment['PATH'],
20 ['cmp.exe', 'grep.exe', 'sed.exe'])
21 if path is not None:
22 path = os.path.pathsep.join((path,
23 config.environment['PATH']))
24 config.environment['PATH'] = path
25
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000026# testFormat: The test format to use to interpret tests.
Daniel Dunbar1db467f2009-07-31 05:54:17 +000027#
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000028# For now we require '&&' between commands, until they get globally killed and
29# the test runner updated.
NAKAMURA Takumi9085e6f2011-03-05 11:16:06 +000030execute_external = (platform.system() != 'Windows'
31 or lit.getBashPath() not in [None, ""])
Daniel Dunbarbc20ef32009-11-08 01:47:35 +000032config.test_format = lit.formats.ShTest(execute_external)
Daniel Dunbar6827f3f2009-09-06 01:31:12 +000033
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000034# suffixes: A list of file extensions to treat as test files.
Jim Grosbachfc308292012-02-10 20:37:10 +000035config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s']
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000036
37# test_source_root: The root path where tests are located.
38config.test_source_root = os.path.dirname(__file__)
39
40# test_exec_root: The root path where tests should be run.
41clang_obj_root = getattr(config, 'clang_obj_root', None)
42if clang_obj_root is not None:
43 config.test_exec_root = os.path.join(clang_obj_root, 'test')
44
45# Set llvm_{src,obj}_root for use by others.
46config.llvm_src_root = getattr(config, 'llvm_src_root', None)
47config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
48
Jordy Rose40f45ee2012-04-06 18:14:01 +000049# Clear some environment variables that might affect Clang.
50#
51# This first set of vars are read by Clang, but shouldn't affect tests
52# that aren't specifically looking for these features, or are required
53# simply to run the tests at all.
54#
55# FIXME: Should we have a tool that enforces this?
56
57# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
58# 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
59# 'IOS_SIMULATOR_DEPLOYMENT_TARGET',
60# 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
61# 'VC80COMNTOOLS')
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000062possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Jordy Rose40f45ee2012-04-06 18:14:01 +000063 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
64 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
65 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
66 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
67 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
68 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
69 'LIBCLANG_RESOURCE_USAGE',
NAKAMURA Takumi79c5f952012-04-07 01:02:53 +000070 'LIBCLANG_CODE_COMPLETION_LOGGING']
71# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
72if platform.system() != 'Windows':
73 possibly_dangerous_env_vars.append('INCLUDE')
Jordy Rose40f45ee2012-04-06 18:14:01 +000074for name in possibly_dangerous_env_vars:
75 if name in config.environment:
76 del config.environment[name]
77
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000078# Tweak the PATH to include the tools dir and the scripts dir.
79if clang_obj_root is not None:
80 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
81 if not llvm_tools_dir:
82 lit.fatal('No LLVM tools dir set!')
Daniel Dunbaree45d6d2009-09-24 06:31:08 +000083 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000084 config.environment['PATH'] = path
85
Daniel Dunbar9e10cc72009-09-26 07:36:09 +000086 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
87 if not llvm_libs_dir:
88 lit.fatal('No LLVM libs dir set!')
89 path = os.path.pathsep.join((llvm_libs_dir,
90 config.environment.get('LD_LIBRARY_PATH','')))
91 config.environment['LD_LIBRARY_PATH'] = path
92
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000093###
94
95# Check that the object root is known.
96if config.test_exec_root is None:
97 # Otherwise, we haven't loaded the site specific configuration (the user is
98 # probably trying to run on a test file directly, and either the site
99 # configuration hasn't been created by the build system, or we are in an
100 # out-of-tree build situation).
101
Daniel Dunbarb258d8f2009-11-05 16:36:19 +0000102 # Check for 'clang_site_config' user parameter, and use that if available.
103 site_cfg = lit.params.get('clang_site_config', None)
104 if site_cfg and os.path.exists(site_cfg):
105 lit.load_config(config, site_cfg)
106 raise SystemExit
107
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000108 # Try to detect the situation where we are using an out-of-tree build by
109 # looking for 'llvm-config'.
110 #
111 # FIXME: I debated (i.e., wrote and threw away) adding logic to
112 # automagically generate the lit.site.cfg if we are in some kind of fresh
Daniel Dunbar23354212009-11-07 23:53:17 +0000113 # build situation. This means knowing how to invoke the build system though,
114 # and I decided it was too much magic. We should solve this by just having
115 # the .cfg files generated during the configuration step.
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000116
117 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
118 if not llvm_config:
119 lit.fatal('No site specific configuration available!')
120
121 # Get the source and object roots.
122 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
123 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
124 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
125 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
126
127 # Validate that we got a tree which points to here, using the standard
128 # tools/clang layout.
129 this_src_root = os.path.dirname(config.test_source_root)
130 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
131 lit.fatal('No site specific configuration available!')
132
133 # Check that the site specific configuration exists.
134 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
135 if not os.path.exists(site_cfg):
Nico Weberb4a88ef2010-09-27 20:40:32 +0000136 lit.fatal('No site specific configuration available! You may need to '
137 'run "make test" in your Clang build directory.')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000138
139 # Okay, that worked. Notify the user of the automagic, and reconfigure.
140 lit.note('using out-of-tree build at %r' % clang_obj_root)
141 lit.load_config(config, site_cfg)
142 raise SystemExit
143
144###
145
146# Discover the 'clang' and 'clangcc' to use.
147
148import os
149
150def inferClang(PATH):
151 # Determine which clang to use.
152 clang = os.getenv('CLANG')
153
154 # If the user set clang in the environment, definitely use that and don't
155 # try to validate.
156 if clang:
157 return clang
158
159 # Otherwise look in the path.
160 clang = lit.util.which('clang', PATH)
161
162 if not clang:
163 lit.fatal("couldn't find 'clang' program, try setting "
164 "CLANG in your environment")
165
166 return clang
167
Daniel Dunbare1fa0962010-03-20 21:13:08 +0000168# When running under valgrind, we mangle '-vg' onto the end of the triple so we
169# can check it with XFAIL and XTARGET.
170if lit.useValgrind:
171 config.target_triple += '-vg'
172
NAKAMURA Takumi9085e6f2011-03-05 11:16:06 +0000173config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000174if not lit.quiet:
175 lit.note('using clang: %r' % config.clang)
Chandler Carruth044a790c2011-11-05 10:15:27 +0000176
177# Note that when substituting %clang_cc1 also fill in the include directory of
178# the builtin headers. Those are part of even a freestanding environment, but
179# Clang relies on the driver to locate them.
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000180def getClangBuiltinIncludeDir(clang):
Chandler Carruthb40fd3f2011-11-05 20:55:50 +0000181 # FIXME: Rather than just getting the version, we should have clang print
182 # out its resource dir here in an easy to scrape form.
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000183 cmd = subprocess.Popen([clang, '-print-file-name=include'],
184 stdout=subprocess.PIPE)
185 if not cmd.stdout:
186 lit.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
187 return cmd.stdout.read().strip()
Chandler Carruthb40fd3f2011-11-05 20:55:50 +0000188
Chandler Carruth07643082011-11-07 09:17:31 +0000189config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s'
Chandler Carruthdf0a4c32011-11-05 23:29:28 +0000190 % (config.clang,
191 getClangBuiltinIncludeDir(config.clang))) )
Chandler Carruth044a790c2011-11-05 10:15:27 +0000192
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000193config.substitutions.append( ('%clangxx', ' ' + config.clang +
194 ' -ccc-clang-cxx -ccc-cxx '))
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000195config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Devang Patel8c6b9132010-09-13 20:46:23 +0000196config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Daniel Dunbara5728872009-12-15 20:14:24 +0000197
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000198# FIXME: Find nicer way to prohibit this.
199config.substitutions.append(
200 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
201config.substitutions.append(
David Greene431feb52011-01-03 17:28:52 +0000202 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar679d6052010-02-17 20:31:01 +0000203config.substitutions.append(
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000204 (' clang-cc ',
205 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
206config.substitutions.append(
207 (' clang -cc1 ',
208 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000209config.substitutions.append(
210 (' %clang-cc1 ',
211 """*** invalid substitution, use '%clang_cc1'. ***""") )
Daniel Dunbardb918642010-08-24 21:39:55 +0000212
213###
214
215# Set available features we allow tests to conditionalize on.
Andrew Trick6da28e22011-08-26 22:46:31 +0000216#
217# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
218if platform.system() not in ['FreeBSD']:
219 config.available_features.add('crash-recovery')
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000220
221# Shell execution
222if platform.system() not in ['Windows'] or lit.getBashPath() != '':
223 config.available_features.add('shell')
Galina Kistanovaee226972011-06-03 18:36:30 +0000224
NAKAMURA Takumi0ca4be32012-07-11 11:44:00 +0000225# ANSI escape sequences in non-dump terminal
226if platform.system() not in ['Windows']:
227 config.available_features.add('ansi-escape-sequences')
228
Galina Kistanovaee226972011-06-03 18:36:30 +0000229# Registered Targets
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000230def get_llc_props(tool):
Galina Kistanovaee226972011-06-03 18:36:30 +0000231 set_of_targets = set()
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000232 enable_assertions = False
Galina Kistanovaee226972011-06-03 18:36:30 +0000233
234 cmd = subprocess.Popen([tool, '-version'], stdout=subprocess.PIPE)
235
236 # Parse the stdout to get the list of registered targets.
237 parse_targets = False
238 for line in cmd.stdout:
239 if parse_targets:
240 m = re.match( r'(.*) - ', line)
241 if m is not None:
242 set_of_targets.add(m.group(1).strip() + '-registered-target')
243 else:
244 break
245 elif "Registered Targets:" in line:
246 parse_targets = True
247
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000248 if re.search(r'with assertions', line):
249 enable_assertions = True
Galina Kistanovaee226972011-06-03 18:36:30 +0000250
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000251 return {"set_of_targets": set_of_targets,
252 "enable_assertions": enable_assertions}
253
254llc_props = get_llc_props(os.path.join(llvm_tools_dir, 'llc'))
255if len(llc_props['set_of_targets']) > 0:
256 config.available_features.update(llc_props['set_of_targets'])
Galina Kistanovaee226972011-06-03 18:36:30 +0000257else:
258 lit.fatal('No Targets Registered with the LLVM Tools!')
NAKAMURA Takumi60796762011-11-28 05:09:42 +0000259
260if llc_props['enable_assertions']:
261 config.available_features.add('asserts')
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +0000262
263if lit.util.which('xmllint'):
264 config.available_features.add('xmllint')
265