tests: Stop mangling '-vg' into the triple, we don't use this currently.
[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'cygwin|mingw32|win32', mcjit_triple):
146   mcjit_triple += "-elf"
147 config.substitutions.append( ('%mcjit_triple', mcjit_triple) )
148
149 # Provide a substition for those tests that need to run the jit to obtain data
150 # but simply want use the currently considered most reliable jit for platform
151 if 'arm' in config.target_triple:
152     defaultIsMCJIT = 'true'
153 else:
154     defaultIsMCJIT = 'false'
155 config.substitutions.append( ('%defaultjit', '-use-mcjit='+defaultIsMCJIT) )
156
157 # Process jit implementation option
158 jit_impl_cfg = lit.params.get('jit_impl', None)
159 if jit_impl_cfg == 'mcjit':
160   # When running with mcjit, mangle -mcjit into target triple
161   # and add -use-mcjit flag to lli invocation
162   if 'i686' in config.target_triple:
163     config.target_triple += jit_impl_cfg + '-ia32'
164   elif 'x86_64' in config.target_triple:
165     config.target_triple += jit_impl_cfg + '-ia64'
166   else:
167     config.target_triple += jit_impl_cfg
168
169   config.substitutions.append( ('%lli', 'lli -use-mcjit') )
170 else:
171   config.substitutions.append( ('%lli', 'lli') )
172
173 # Add site-specific substitutions.
174 config.substitutions.append( ('%ocamlopt', config.ocamlopt_executable) )
175 config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
176 config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
177
178 # For each occurrence of an llvm tool name as its own word, replace it
179 # with the full path to the build directory holding that tool.  This
180 # ensures that we are testing the tools just built and not some random
181 # tools that might happen to be in the user's PATH.  Thus this list
182 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
183 # (llvm_tools_dir in lit parlance).
184                 # Don't match 'bugpoint-' or 'clang-'.
185                 # Don't match '/clang' or '-clang'.
186 if os.pathsep == ';':
187     pathext = os.environ.get('PATHEXT', '').split(';')
188 else:
189     pathext = ['']
190 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/|-)\bclang\b(?!-)",
191                 r"\bgold\b",
192                 r"\bllc\b",             r"\blli\b",
193                 r"\bllvm-ar\b",         r"\bllvm-as\b",
194                 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
195                 r"\bllvm-cov\b",        r"\bllvm-diff\b",
196                 r"\bllvm-dis\b",        r"\bllvm-dwarfdump\b",
197                 r"\bllvm-extract\b",
198                 r"\bllvm-link\b",       r"\bllvm-mc\b",
199                 r"\bllvm-nm\b",         r"\bllvm-objdump\b",
200                 r"\bllvm-prof\b",       r"\bllvm-ranlib\b",
201                 r"\bllvm-rtdyld\b",     r"\bllvm-shlib\b",
202                 r"\bllvm-size\b",
203                 # Don't match '-llvmc'.
204                 r"(?<!-)\bllvmc\b",     r"\blto\b",
205                                         # Don't match '.opt', '-opt',
206                                         # '^opt' or '/opt'.
207                 r"\bmacho-dump\b",      r"(?<!\.|-|\^|/)\bopt\b",
208                 r"\bllvm-tblgen\b",     r"\bFileCheck\b",
209                 r"\bFileUpdate\b",      r"\bc-index-test\b",
210                 r"\bfpcmp\b",           r"\bllvm-PerfectShuffle\b",
211                 # Handle these specially as they are strings searched
212                 # for during testing.
213                 r"\| \bcount\b",         r"\| \bnot\b"]:
214     # Extract the tool name from the pattern.  This relies on the tool
215     # name being surrounded by \b word match operators.  If the
216     # pattern starts with "| ", include it in the string to be
217     # substituted.
218     substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
219                           r"\2" + llvm_tools_dir + "/" + r"\4",
220                           pattern)
221     for ext in pathext:
222         substitution_ext = substitution + ext
223         if os.path.exists(substitution_ext):
224              substitution = substitution_ext
225              break
226     config.substitutions.append((pattern, substitution))
227
228 ### Features
229
230 # Shell execution
231 if sys.platform not in ['win32'] or lit.getBashPath() != '':
232     config.available_features.add('shell')
233
234 # Loadable module
235 # FIXME: This should be supplied by Makefile or autoconf.
236 if sys.platform in ['win32', 'cygwin']:
237     loadable_module = (config.enable_shared == 1)
238 else:
239     loadable_module = True
240
241 if loadable_module:
242     config.available_features.add('loadable_module')
243
244 # LTO
245 if config.lto_is_enabled == "1":
246     config.available_features.add('lto')
247
248 # llc knows whether he is compiled with -DNDEBUG.
249 import subprocess
250 try:
251     llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'],
252                            stdout = subprocess.PIPE)
253 except OSError, why:
254     print "Could not find llc in " + llvm_tools_dir
255     exit(42)
256
257 if re.search(r'with assertions', llc_cmd.stdout.read()):
258     config.available_features.add('asserts')
259 llc_cmd.wait()