blob: 95bf3c0dc4347bfeab9bb2acec353cd3bb17175f [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.
Reid Kleckner892d2a52017-06-26 16:42:44 +000048config.suffixes = ['.ll', '.s', '.test', '.yaml', '.objtxt']
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:
Michal Gorny7d0f0e32017-02-08 20:08:25 +000069 lld_tools_dir = getattr(config, 'lld_tools_dir', None)
70 if not lld_tools_dir:
71 lit_config.fatal('No LLD tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000072 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
73 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000074 lit_config.fatal('No LLVM tools dir set!')
Michal Gorny7d0f0e32017-02-08 20:08:25 +000075 path = os.path.pathsep.join((lld_tools_dir, llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000076 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 +000077
Sid Manning37e31202012-09-14 20:04:36 +000078 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000079
Michal Gorny7d0f0e32017-02-08 20:08:25 +000080 lld_libs_dir = getattr(config, 'lld_libs_dir', None)
81 if not lld_libs_dir:
82 lit_config.fatal('No LLD libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000083 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
84 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000085 lit_config.fatal('No LLVM libs dir set!')
Michal Gorny7d0f0e32017-02-08 20:08:25 +000086 path = os.path.pathsep.join((lld_libs_dir, llvm_libs_dir,
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000087 config.environment.get('LD_LIBRARY_PATH','')))
88 config.environment['LD_LIBRARY_PATH'] = path
89
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000090 # Propagate LLVM_SRC_ROOT into the environment.
91 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
92
93 # Propagate PYTHON_EXECUTABLE into the environment
94 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
95 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000096###
97
98# Check that the object root is known.
99if config.test_exec_root is None:
100 # Otherwise, we haven't loaded the site specific configuration (the user is
101 # probably trying to run on a test file directly, and either the site
102 # configuration hasn't been created by the build system, or we are in an
103 # out-of-tree build situation).
104
105 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000106 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000107 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000108 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000109 raise SystemExit
110
111 # Try to detect the situation where we are using an out-of-tree build by
112 # looking for 'llvm-config'.
113 #
114 # FIXME: I debated (i.e., wrote and threw away) adding logic to
115 # automagically generate the lit.site.cfg if we are in some kind of fresh
116 # build situation. This means knowing how to invoke the build system though,
117 # and I decided it was too much magic. We should solve this by just having
118 # the .cfg files generated during the configuration step.
119
120 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
121 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000122 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000123
124 # Get the source and object roots.
David L. Jonesd4053fb2017-07-06 21:46:47 +0000125 llvm_src_root = subprocess.check_output(['llvm-config', '--src-root']).strip()
126 llvm_obj_root = subprocess.check_output(['llvm-config', '--obj-root']).strip()
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000127 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
128 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
129
130 # Validate that we got a tree which points to here, using the standard
131 # tools/lld layout.
132 this_src_root = os.path.dirname(config.test_source_root)
133 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000134 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000135
136 # Check that the site specific configuration exists.
137 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
138 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000139 lit_config.fatal(
140 'No site specific configuration available! You may need to '
141 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000142
143 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000144 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
145 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000146 raise SystemExit
147
Pete Cooper80c9b942015-12-10 19:17:35 +0000148# For each occurrence of a lld tool name as its own word, replace it
149# with the full path to the build directory holding that tool. This
150# ensures that we are testing the tools just built and not some random
151# tools that might happen to be in the user's PATH.
152
153# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
154# For example, we want to prefix 'lld' and 'ld.lld' but not the 'lld' inside
155# of 'ld.lld'.
Lang Hamesfc3438c2015-12-11 22:09:03 +0000156NoPreJunk = r"(?<!(-|\.|/))"
157NoPostJunk = r"(?!(-|\.))"
Pete Cooper80c9b942015-12-10 19:17:35 +0000158
Rafael Espindolacb09daa2016-10-26 18:59:00 +0000159config.substitutions.append( (r"\bld.lld\b", 'ld.lld --full-shutdown') )
160
Pete Cooper80c9b942015-12-10 19:17:35 +0000161tool_patterns = [r"\bFileCheck\b",
162 r"\bnot\b",
Lang Hamesfc3438c2015-12-11 22:09:03 +0000163 NoPreJunk + r"\blld\b" + NoPostJunk,
Pete Cooper80c9b942015-12-10 19:17:35 +0000164 r"\bld.lld\b",
165 r"\blld-link\b",
Rafael Espindola069b1c12016-07-21 18:08:36 +0000166 r"\bllvm-as\b",
Pete Cooper80c9b942015-12-10 19:17:35 +0000167 r"\bllvm-mc\b",
168 r"\bllvm-nm\b",
169 r"\bllvm-objdump\b",
Sam Cleggbe373672017-06-13 15:53:53 +0000170 r"\bllvm-pdbutil\b",
Pete Cooper80c9b942015-12-10 19:17:35 +0000171 r"\bllvm-readobj\b",
Pete Coopercb7d83c2016-08-11 21:03:56 +0000172 r"\bobj2yaml\b",
Pete Cooper80c9b942015-12-10 19:17:35 +0000173 r"\byaml2obj\b"]
174
175for pattern in tool_patterns:
176 # Extract the tool name from the pattern. This relies on the tool
177 # name being surrounded by \b word match operators. If the
178 # pattern starts with "| ", include it in the string to be
179 # substituted.
180 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
181 pattern)
182 tool_pipe = tool_match.group(2)
183 tool_name = tool_match.group(4)
Michal Gorny7d0f0e32017-02-08 20:08:25 +0000184 tool_path = lit.util.which(tool_name, config.environment['PATH'])
Pete Cooper80c9b942015-12-10 19:17:35 +0000185 if not tool_path:
186 # Warn, but still provide a substitution.
Michal Gorny7d0f0e32017-02-08 20:08:25 +0000187 lit_config.note('Did not find ' + tool_name + ' in ' + path)
Pete Cooper80c9b942015-12-10 19:17:35 +0000188 tool_path = llvm_tools_dir + '/' + tool_name
189 config.substitutions.append((pattern, tool_pipe + tool_path))
190
NAKAMURA Takumi12729542016-02-09 07:30:18 +0000191# Add site-specific substitutions.
192config.substitutions.append( ('%python', config.python_executable) )
193
Pete Cooper80c9b942015-12-10 19:17:35 +0000194###
195
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000196# When running under valgrind, we mangle '-vg' onto the end of the triple so we
197# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000198if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000199 config.target_triple += '-vg'
200
201# Shell execution
Reid Kleckner750e76d2016-03-30 20:15:50 +0000202if execute_external:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000203 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000204
Rui Ueyama287956f2016-07-07 03:55:57 +0000205# zlib compression library
Michal Gornya028b332017-02-08 20:08:29 +0000206if config.have_zlib:
Rui Ueyama287956f2016-07-07 03:55:57 +0000207 config.available_features.add("zlib")
208
Nick Kledzik50bda292014-09-11 00:52:05 +0000209# Running on Darwin OS
210if platform.system() in ['Darwin']:
211 config.available_features.add('system-linker-mach-o')
212
213# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000214if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000215 config.available_features.add('system-linker-elf')
216
George Rimare8936892016-11-11 13:23:13 +0000217# Running on Windows
218if platform.system() in ['Windows']:
219 config.available_features.add('system-windows')
220
NAKAMURA Takumic96ae0c2016-02-09 07:30:11 +0000221# Set if host-cxxabi's demangler can handle target's symbols.
222if platform.system() not in ['Windows']:
223 config.available_features.add('demangler')
224
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000225# llvm-config knows whether it is compiled with asserts (and)
226# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000227import subprocess
228try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000229 llvm_config_cmd = \
230 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000231 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000232 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000233except OSError as why:
234 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000235 exit(42)
236
Michael J. Spencer876bee82014-03-26 01:19:07 +0000237llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000238llvm_config_output_list = llvm_config_output.split("\n")
239
240if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000241 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000242if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000243 config.available_features.add('asserts')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000244
245archs = llvm_config_output_list[2]
246if re.search(r'AArch64', archs):
247 config.available_features.add('aarch64')
Ed Maste87b0ab12017-06-27 12:21:50 +0000248if re.search(r'AMDGPU', archs):
249 config.available_features.add('amdgpu')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000250if re.search(r'ARM', archs):
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000251 config.available_features.add('arm')
Leslie Zhai49ba7952017-06-15 02:27:50 +0000252if re.search(r'AVR', archs):
253 config.available_features.add('avr')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000254if re.search(r'Mips', archs):
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000255 config.available_features.add('mips')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000256if re.search(r'PowerPC', archs):
Rafael Espindola1c2f64d2015-08-05 23:40:20 +0000257 config.available_features.add('ppc')
Rui Ueyama0cc14832017-06-28 17:05:39 +0000258if re.search(r'Sparc', archs):
259 config.available_features.add('sparc')
Ed Maste87b0ab12017-06-27 12:21:50 +0000260if re.search(r'X86', archs):
261 config.available_features.add('x86')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000262llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000263
Rui Ueyama3da3f062016-11-10 20:20:37 +0000264# Set a fake constant version so that we get consitent output.
265config.environment['LLD_VERSION'] = 'LLD 1.0'
266
Eric Beckmannc8dba242017-07-08 03:06:10 +0000267# Indirectly check if the mt.exe Microsoft utility exists by searching for
268# cvtres, which always accompanies it.
269if lit.util.which('cvtres', config.environment['PATH']):
270 config.available_features.add('win_mt')