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