Introduce llvm::sys::getProcessTriple() function.
[oota-llvm.git] / test / lit.cfg
1 # -*- Python -*-
2
3 # Configuration file for the 'lit' test runner.
4
5 import os
6 import sys
7 import re
8 import platform
9
10 # name: The name of this test suite.
11 config.name = 'LLVM'
12
13 # Tweak PATH for Win32 to decide to use bash.exe or not.
14 if sys.platform in ['win32']:
15     # Seek sane tools in directories and set to $PATH.
16     path = getattr(config, 'lit_tools_dir', None)
17     path = lit.getToolsPath(path,
18                             config.environment['PATH'],
19                             ['cmp.exe', 'grep.exe', 'sed.exe'])
20     if path is not None:
21         path = os.path.pathsep.join((path,
22                                      config.environment['PATH']))
23         config.environment['PATH'] = path
24
25 # testFormat: The test format to use to interpret tests.
26 execute_external = (not sys.platform in ['win32']
27                     or lit.getBashPath() not in [None, ""])
28 config.test_format = lit.formats.ShTest(execute_external)
29
30 # To ignore test output on stderr so it doesn't trigger failures uncomment this:
31 #config.test_format = lit.formats.TclTest(ignoreStdErr=True)
32
33 # suffixes: A list of file extensions to treat as test files, this is actually
34 # set by on_clone().
35 config.suffixes = []
36
37 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
38 # subdirectories contain auxiliary inputs for various tests in their parent
39 # directories.
40 config.excludes = ['Inputs']
41
42 # test_source_root: The root path where tests are located.
43 config.test_source_root = os.path.dirname(__file__)
44
45 # test_exec_root: The root path where tests should be run.
46 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
47 if llvm_obj_root is not None:
48     config.test_exec_root = os.path.join(llvm_obj_root, 'test')
49
50 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
51 # dir (if available).
52 if llvm_obj_root is not None:
53     llvm_src_root = getattr(config, 'llvm_src_root', None)
54     if not llvm_src_root:
55         lit.fatal('No LLVM source root set!')
56     path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
57                                               'Scripts'),
58                                  config.environment['PATH']))
59     config.environment['PATH'] = path
60
61     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
62     if not llvm_tools_dir:
63         lit.fatal('No LLVM tools dir set!')
64     path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
65     config.environment['PATH'] = path
66
67 # Propagate 'HOME' through the environment.
68 if 'HOME' in os.environ:
69     config.environment['HOME'] = os.environ['HOME']
70
71 # Propagate 'INCLUDE' through the environment.
72 if 'INCLUDE' in os.environ:
73     config.environment['INCLUDE'] = os.environ['INCLUDE']
74
75 # Propagate 'LIB' through the environment.
76 if 'LIB' in os.environ:
77     config.environment['LIB'] = os.environ['LIB']
78
79 # Propagate the temp directory. Windows requires this because it uses \Windows\
80 # if none of these are present.
81 if 'TMP' in os.environ:
82     config.environment['TMP'] = os.environ['TMP']
83 if 'TEMP' in os.environ:
84     config.environment['TEMP'] = os.environ['TEMP']
85
86 # Propagate LLVM_SRC_ROOT into the environment.
87 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
88
89 # Propagate PYTHON_EXECUTABLE into the environment
90 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
91                                                   '')
92
93 ###
94
95 import os
96
97 # Check that the object root is known.
98 if config.test_exec_root is None:
99     # Otherwise, we haven't loaded the site specific configuration (the user is
100     # probably trying to run on a test file directly, and either the site
101     # configuration hasn't been created by the build system, or we are in an
102     # out-of-tree build situation).
103
104     # Check for 'llvm_site_config' user parameter, and use that if available.
105     site_cfg = lit.params.get('llvm_site_config', None)
106     if site_cfg and os.path.exists(site_cfg):
107         lit.load_config(config, site_cfg)
108         raise SystemExit
109
110     # Try to detect the situation where we are using an out-of-tree build by
111     # looking for 'llvm-config'.
112     #
113     # FIXME: I debated (i.e., wrote and threw away) adding logic to
114     # automagically generate the lit.site.cfg if we are in some kind of fresh
115     # build situation. This means knowing how to invoke the build system
116     # though, and I decided it was too much magic.
117
118     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
119     if not llvm_config:
120         lit.fatal('No site specific configuration available!')
121
122     # Get the source and object roots.
123     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
124     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
125
126     # Validate that we got a tree which points to here.
127     this_src_root = os.path.dirname(config.test_source_root)
128     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
129         lit.fatal('No site specific configuration available!')
130
131     # Check that the site specific configuration exists.
132     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
133     if not os.path.exists(site_cfg):
134         lit.fatal('No site specific configuration available!')
135
136     # Okay, that worked. Notify the user of the automagic, and reconfigure.
137     lit.note('using out-of-tree build at %r' % llvm_obj_root)
138     lit.load_config(config, site_cfg)
139     raise SystemExit
140
141 ###
142
143 # Provide a command line for mcjit tests
144 lli_mcjit = 'lli -use-mcjit'
145 # The target triple used by default by lli is the process target triple (some
146 # triple appropriate for generating code for the current process) but because
147 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
148 # Windows.  FIXME: the process target triple should be used here, but this is
149 # difficult to obtain on Windows.
150 if re.search(r'cygwin|mingw32|win32', config.host_triple):
151   lli_mcjit += ' -mtriple='+config.host_triple+'-elf'
152 config.substitutions.append( ('%lli_mcjit', lli_mcjit) )
153
154 # Provide a substition for those tests that need to run the jit to obtain data
155 # but simply want use the currently considered most reliable jit for platform
156 # FIXME: ppc32 is not ready for mcjit.
157 if 'arm' in config.target_triple \
158    or 'powerpc64' in config.target_triple:
159     defaultIsMCJIT = 'true'
160 else:
161     defaultIsMCJIT = 'false'
162 config.substitutions.append( ('%defaultjit', '-use-mcjit='+defaultIsMCJIT) )
163
164 # Process jit implementation option
165 jit_impl_cfg = lit.params.get('jit_impl', None)
166 if jit_impl_cfg == 'mcjit':
167   # When running with mcjit, mangle -mcjit into target triple
168   # and add -use-mcjit flag to lli invocation
169   if 'i686' in config.target_triple:
170     config.target_triple += jit_impl_cfg + '-ia32'
171   elif 'x86_64' in config.target_triple:
172     config.target_triple += jit_impl_cfg + '-ia64'
173   else:
174     config.target_triple += jit_impl_cfg
175
176   config.substitutions.append( ('%lli', 'lli -use-mcjit') )
177 else:
178   config.substitutions.append( ('%lli', 'lli') )
179
180 # Add site-specific substitutions.
181 config.substitutions.append( ('%ocamlopt', config.ocamlopt_executable) )
182 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
183 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
184
185 # For each occurrence of an llvm tool name as its own word, replace it
186 # with the full path to the build directory holding that tool.  This
187 # ensures that we are testing the tools just built and not some random
188 # tools that might happen to be in the user's PATH.  Thus this list
189 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
190 # (llvm_tools_dir in lit parlance).
191                 # Don't match 'bugpoint-' or 'clang-'.
192                 # Don't match '/clang' or '-clang'.
193 if os.pathsep == ';':
194     pathext = os.environ.get('PATHEXT', '').split(';')
195 else:
196     pathext = ['']
197 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/|-)\bclang\b(?!-)",
198                 r"\bgold\b",
199                 r"\bllc\b",             r"\blli\b",
200                 r"\bllvm-ar\b",         r"\bllvm-as\b",
201                 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
202                 r"\bllvm-cov\b",        r"\bllvm-diff\b",
203                 r"\bllvm-dis\b",        r"\bllvm-dwarfdump\b",
204                 r"\bllvm-extract\b",    r"\bllvm-jistlistener\b",
205                 r"\bllvm-link\b",       r"\bllvm-mc\b",
206                 r"\bllvm-nm\b",         r"\bllvm-objdump\b",
207                 r"\bllvm-prof\b",       r"\bllvm-ranlib\b",
208                 r"\bllvm-rtdyld\b",     r"\bllvm-shlib\b",
209                 r"\bllvm-size\b",
210                 # Don't match '-llvmc'.
211                 r"(?<!-)\bllvmc\b",     r"\blto\b",
212                                         # Don't match '.opt', '-opt',
213                                         # '^opt' or '/opt'.
214                 r"\bmacho-dump\b",      r"(?<!\.|-|\^|/)\bopt\b",
215                 r"\bllvm-tblgen\b",     r"\bFileCheck\b",
216                 r"\bFileUpdate\b",      r"\bc-index-test\b",
217                 r"\bfpcmp\b",           r"\bllvm-PerfectShuffle\b",
218                 # Handle these specially as they are strings searched
219                 # for during testing.
220                 r"\| \bcount\b",         r"\| \bnot\b"]:
221     # Extract the tool name from the pattern.  This relies on the tool
222     # name being surrounded by \b word match operators.  If the
223     # pattern starts with "| ", include it in the string to be
224     # substituted.
225     substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
226                           r"\2" + llvm_tools_dir + "/" + r"\4",
227                           pattern)
228     for ext in pathext:
229         substitution_ext = substitution + ext
230         if os.path.exists(substitution_ext):
231              substitution = substitution_ext
232              break
233     config.substitutions.append((pattern, substitution))
234
235 ### Features
236
237 # Shell execution
238 if sys.platform not in ['win32'] or lit.getBashPath() != '':
239     config.available_features.add('shell')
240
241 # Loadable module
242 # FIXME: This should be supplied by Makefile or autoconf.
243 if sys.platform in ['win32', 'cygwin']:
244     loadable_module = (config.enable_shared == 1)
245 else:
246     loadable_module = True
247
248 if loadable_module:
249     config.available_features.add('loadable_module')
250
251 # LTO on OS X
252 if config.lto_is_enabled == "1" and platform.system() == "Darwin":
253     config.available_features.add('lto_on_osx')
254
255 # llc knows whether he is compiled with -DNDEBUG.
256 import subprocess
257 try:
258     llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'],
259                            stdout = subprocess.PIPE)
260 except OSError, why:
261     print "Could not find llc in " + llvm_tools_dir
262     exit(42)
263
264 if re.search(r'with assertions', llc_cmd.stdout.read()):
265     config.available_features.add('asserts')
266 llc_cmd.wait()