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