blob: 54f08f4da2e4f57181dc04ba3e9b6994c8f7eb7d [file] [log] [blame]
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00001# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
Michael J. Spencera4f983e2014-03-26 00:53:48 +00007import locale
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00008
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +00009import lit.formats
10import lit.util
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000011
12# Configuration file for the 'lit' test runner.
13
14# name: The name of this test suite.
15config.name = 'lld'
16
Rafael Espindolaccd3adc2015-08-05 19:55:17 +000017# Tweak PATH for Win32
18if sys.platform in ['win32']:
19 # Seek sane tools in directories and set to $PATH.
20 path = getattr(config, 'lit_tools_dir', None)
21 path = lit_config.getToolsPath(path,
22 config.environment['PATH'],
23 ['cmp.exe', 'grep.exe', 'sed.exe'])
24 if path is not None:
25 path = os.path.pathsep.join((path,
26 config.environment['PATH']))
27 config.environment['PATH'] = path
28
Reid Kleckner59591762015-05-20 20:41:45 +000029# Choose between lit's internal shell pipeline runner and a real shell. If
30# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
31use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
32if use_lit_shell:
33 # 0 is external, "" is default, and everything else is internal.
34 execute_external = (use_lit_shell == "0")
35else:
36 # Otherwise we default to internal on Windows and external elsewhere, as
37 # bash on Windows is usually very slow.
38 execute_external = (not sys.platform in ['win32'])
39
40
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000041# testFormat: The test format to use to interpret tests.
42#
43# For now we require '&&' between commands, until they get globally killed and
44# the test runner updated.
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000045config.test_format = lit.formats.ShTest(execute_external)
46
47# suffixes: A list of file extensions to treat as test files.
Peter Collingbourne60c16162015-06-01 20:10:10 +000048config.suffixes = ['.ll', '.objtxt', '.test']
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000049
Rafael Espindolac08ab8e2015-04-24 15:51:45 +000050# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
51# subdirectories contain auxiliary inputs for various tests in their parent
52# directories.
53config.excludes = ['Inputs']
54
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000055# test_source_root: The root path where tests are located.
56config.test_source_root = os.path.dirname(__file__)
57
58# test_exec_root: The root path where tests should be run.
59lld_obj_root = getattr(config, 'lld_obj_root', None)
60if lld_obj_root is not None:
61 config.test_exec_root = os.path.join(lld_obj_root, 'test')
62
63# Set llvm_{src,obj}_root for use by others.
64config.llvm_src_root = getattr(config, 'llvm_src_root', None)
65config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
66
67# Tweak the PATH to include the tools dir and the scripts dir.
68if lld_obj_root is not None:
69 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
70 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000071 lit_config.fatal('No LLVM tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000072 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000073 path = os.path.pathsep.join((os.path.join(getattr(config, 'llvm_src_root', None),'test','Scripts'),path))
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000074
Sid Manning37e31202012-09-14 20:04:36 +000075 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000076
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000077 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
78 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000079 lit_config.fatal('No LLVM libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000080 path = os.path.pathsep.join((llvm_libs_dir,
81 config.environment.get('LD_LIBRARY_PATH','')))
82 config.environment['LD_LIBRARY_PATH'] = path
83
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000084 # Propagate LLVM_SRC_ROOT into the environment.
85 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
86
87 # Propagate PYTHON_EXECUTABLE into the environment
88 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
89 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000090###
91
92# Check that the object root is known.
93if config.test_exec_root is None:
94 # Otherwise, we haven't loaded the site specific configuration (the user is
95 # probably trying to run on a test file directly, and either the site
96 # configuration hasn't been created by the build system, or we are in an
97 # out-of-tree build situation).
98
99 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000100 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000101 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000102 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000103 raise SystemExit
104
105 # Try to detect the situation where we are using an out-of-tree build by
106 # looking for 'llvm-config'.
107 #
108 # FIXME: I debated (i.e., wrote and threw away) adding logic to
109 # automagically generate the lit.site.cfg if we are in some kind of fresh
110 # build situation. This means knowing how to invoke the build system though,
111 # and I decided it was too much magic. We should solve this by just having
112 # the .cfg files generated during the configuration step.
113
114 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
115 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000116 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000117
118 # Get the source and object roots.
119 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
120 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
121 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
122 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
123
124 # Validate that we got a tree which points to here, using the standard
125 # tools/lld layout.
126 this_src_root = os.path.dirname(config.test_source_root)
127 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000128 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000129
130 # Check that the site specific configuration exists.
131 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
132 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000133 lit_config.fatal(
134 'No site specific configuration available! You may need to '
135 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000136
137 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000138 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
139 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000140 raise SystemExit
141
Pete Cooper80c9b942015-12-10 19:17:35 +0000142# For each occurrence of a lld tool name as its own word, replace it
143# with the full path to the build directory holding that tool. This
144# ensures that we are testing the tools just built and not some random
145# tools that might happen to be in the user's PATH.
146
147# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
148# For example, we want to prefix 'lld' and 'ld.lld' but not the 'lld' inside
149# of 'ld.lld'.
Lang Hamesfc3438c2015-12-11 22:09:03 +0000150NoPreJunk = r"(?<!(-|\.|/))"
151NoPostJunk = r"(?!(-|\.))"
Pete Cooper80c9b942015-12-10 19:17:35 +0000152
153tool_patterns = [r"\bFileCheck\b",
154 r"\bnot\b",
Lang Hamesfc3438c2015-12-11 22:09:03 +0000155 NoPreJunk + r"\blld\b" + NoPostJunk,
Pete Cooper80c9b942015-12-10 19:17:35 +0000156 r"\bld.lld\b",
157 r"\blld-link\b",
158 r"\bllvm-mc\b",
159 r"\bllvm-nm\b",
160 r"\bllvm-objdump\b",
161 r"\bllvm-readobj\b",
162 r"\byaml2obj\b"]
163
164for pattern in tool_patterns:
165 # Extract the tool name from the pattern. This relies on the tool
166 # name being surrounded by \b word match operators. If the
167 # pattern starts with "| ", include it in the string to be
168 # substituted.
169 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
170 pattern)
171 tool_pipe = tool_match.group(2)
172 tool_name = tool_match.group(4)
173 tool_path = lit.util.which(tool_name, llvm_tools_dir)
174 if not tool_path:
175 # Warn, but still provide a substitution.
176 lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
177 tool_path = llvm_tools_dir + '/' + tool_name
178 config.substitutions.append((pattern, tool_pipe + tool_path))
179
NAKAMURA Takumi12729542016-02-09 07:30:18 +0000180# Add site-specific substitutions.
181config.substitutions.append( ('%python', config.python_executable) )
182
Pete Cooper80c9b942015-12-10 19:17:35 +0000183###
184
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000185# When running under valgrind, we mangle '-vg' onto the end of the triple so we
186# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000187if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000188 config.target_triple += '-vg'
189
190# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000191if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000192 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000193
Nick Kledzik50bda292014-09-11 00:52:05 +0000194# Running on Darwin OS
195if platform.system() in ['Darwin']:
196 config.available_features.add('system-linker-mach-o')
197
198# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000199if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000200 config.available_features.add('system-linker-elf')
201
NAKAMURA Takumic96ae0c2016-02-09 07:30:11 +0000202# Set if host-cxxabi's demangler can handle target's symbols.
203if platform.system() not in ['Windows']:
204 config.available_features.add('demangler')
205
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000206# llvm-config knows whether it is compiled with asserts (and)
207# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000208import subprocess
209try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000210 llvm_config_cmd = \
211 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000212 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000213 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000214except OSError as why:
215 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000216 exit(42)
217
Michael J. Spencer876bee82014-03-26 01:19:07 +0000218llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000219llvm_config_output_list = llvm_config_output.split("\n")
220
221if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000222 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000223if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000224 config.available_features.add('asserts')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000225
226archs = llvm_config_output_list[2]
227if re.search(r'AArch64', archs):
228 config.available_features.add('aarch64')
229if re.search(r'ARM', archs):
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000230 config.available_features.add('arm')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000231if re.search(r'Mips', archs):
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000232 config.available_features.add('mips')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000233if re.search(r'X86', archs):
Filipe Cabecinhasd1787ad2015-01-24 03:55:22 +0000234 config.available_features.add('x86')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000235if re.search(r'PowerPC', archs):
Rafael Espindola1c2f64d2015-08-05 23:40:20 +0000236 config.available_features.add('ppc')
Tom Stellard68a55e62016-01-07 05:02:38 +0000237if re.search(r'AMDGPU', archs):
238 config.available_features.add('amdgpu')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000239llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000240
241# Check if Windows resource file compiler exists.
242cvtres = lit.util.which('cvtres', config.environment['PATH'])
243rc = lit.util.which('rc', config.environment['PATH'])
244if cvtres and rc:
245 config.available_features.add('winres')
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000246
Filipe Cabecinhas47f07f82014-04-23 04:38:13 +0000247# Check if "lib.exe" command exists.
Rafael Espindolaccd3adc2015-08-05 19:55:17 +0000248if lit.util.which('lib', config.environment['PATH']):
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000249 config.available_features.add('winlib')