blob: e27d0903d46fa8eb7c296b9569a49170a115b763 [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
Zachary Turnerce92db12017-09-15 22:10:46 +000058config.test_exec_root = os.path.join(config.lld_obj_root, 'test')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000059
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000060
61# Tweak the PATH to include the tools dir and the scripts dir.
Zachary Turnerce92db12017-09-15 22:10:46 +000062path = os.path.pathsep.join((config.lld_tools_dir, config.llvm_tools_dir, config.environment['PATH']))
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000063
Zachary Turnerce92db12017-09-15 22:10:46 +000064config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000065
Zachary Turnerce92db12017-09-15 22:10:46 +000066path = os.path.pathsep.join((config.lld_libs_dir, config.llvm_libs_dir,
67 config.environment.get('LD_LIBRARY_PATH','')))
68config.environment['LD_LIBRARY_PATH'] = path
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000069
Zachary Turnerce92db12017-09-15 22:10:46 +000070# Propagate LLVM_SRC_ROOT into the environment.
71config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000072
Zachary Turnerce92db12017-09-15 22:10:46 +000073# Propagate PYTHON_EXECUTABLE into the environment
74config.environment['PYTHON_EXECUTABLE'] = sys.executable
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000075
Pete Cooper80c9b942015-12-10 19:17:35 +000076# For each occurrence of a lld tool name as its own word, replace it
77# with the full path to the build directory holding that tool. This
78# ensures that we are testing the tools just built and not some random
79# tools that might happen to be in the user's PATH.
80
81# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
82# For example, we want to prefix 'lld' and 'ld.lld' but not the 'lld' inside
83# of 'ld.lld'.
Lang Hamesfc3438c2015-12-11 22:09:03 +000084NoPreJunk = r"(?<!(-|\.|/))"
85NoPostJunk = r"(?!(-|\.))"
Pete Cooper80c9b942015-12-10 19:17:35 +000086
Rafael Espindolacb09daa2016-10-26 18:59:00 +000087config.substitutions.append( (r"\bld.lld\b", 'ld.lld --full-shutdown') )
88
Pete Cooper80c9b942015-12-10 19:17:35 +000089tool_patterns = [r"\bFileCheck\b",
90 r"\bnot\b",
Lang Hamesfc3438c2015-12-11 22:09:03 +000091 NoPreJunk + r"\blld\b" + NoPostJunk,
Pete Cooper80c9b942015-12-10 19:17:35 +000092 r"\bld.lld\b",
93 r"\blld-link\b",
Rafael Espindola069b1c12016-07-21 18:08:36 +000094 r"\bllvm-as\b",
Pete Cooper80c9b942015-12-10 19:17:35 +000095 r"\bllvm-mc\b",
96 r"\bllvm-nm\b",
97 r"\bllvm-objdump\b",
Sam Cleggbe373672017-06-13 15:53:53 +000098 r"\bllvm-pdbutil\b",
Pete Cooper80c9b942015-12-10 19:17:35 +000099 r"\bllvm-readobj\b",
Pete Coopercb7d83c2016-08-11 21:03:56 +0000100 r"\bobj2yaml\b",
Pete Cooper80c9b942015-12-10 19:17:35 +0000101 r"\byaml2obj\b"]
102
103for pattern in tool_patterns:
104 # Extract the tool name from the pattern. This relies on the tool
105 # name being surrounded by \b word match operators. If the
106 # pattern starts with "| ", include it in the string to be
107 # substituted.
108 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
109 pattern)
110 tool_pipe = tool_match.group(2)
111 tool_name = tool_match.group(4)
Michal Gorny7d0f0e32017-02-08 20:08:25 +0000112 tool_path = lit.util.which(tool_name, config.environment['PATH'])
Pete Cooper80c9b942015-12-10 19:17:35 +0000113 if not tool_path:
114 # Warn, but still provide a substitution.
Michal Gorny7d0f0e32017-02-08 20:08:25 +0000115 lit_config.note('Did not find ' + tool_name + ' in ' + path)
Zachary Turnerce92db12017-09-15 22:10:46 +0000116 tool_path = config.llvm_tools_dir + '/' + tool_name
Pete Cooper80c9b942015-12-10 19:17:35 +0000117 config.substitutions.append((pattern, tool_pipe + tool_path))
118
NAKAMURA Takumi12729542016-02-09 07:30:18 +0000119# Add site-specific substitutions.
120config.substitutions.append( ('%python', config.python_executable) )
121
Pete Cooper80c9b942015-12-10 19:17:35 +0000122###
123
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000124# When running under valgrind, we mangle '-vg' onto the end of the triple so we
125# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000126if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000127 config.target_triple += '-vg'
128
129# Shell execution
Reid Kleckner750e76d2016-03-30 20:15:50 +0000130if execute_external:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000131 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000132
Rui Ueyama287956f2016-07-07 03:55:57 +0000133# zlib compression library
Michal Gornya028b332017-02-08 20:08:29 +0000134if config.have_zlib:
Rui Ueyama287956f2016-07-07 03:55:57 +0000135 config.available_features.add("zlib")
136
Nick Kledzik50bda292014-09-11 00:52:05 +0000137# Running on Darwin OS
138if platform.system() in ['Darwin']:
139 config.available_features.add('system-linker-mach-o')
140
141# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000142if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000143 config.available_features.add('system-linker-elf')
144
George Rimare8936892016-11-11 13:23:13 +0000145# Running on Windows
146if platform.system() in ['Windows']:
147 config.available_features.add('system-windows')
148
NAKAMURA Takumic96ae0c2016-02-09 07:30:11 +0000149# Set if host-cxxabi's demangler can handle target's symbols.
150if platform.system() not in ['Windows']:
151 config.available_features.add('demangler')
152
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000153# llvm-config knows whether it is compiled with asserts (and)
154# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000155import subprocess
156try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000157 llvm_config_cmd = \
Zachary Turnerce92db12017-09-15 22:10:46 +0000158 subprocess.Popen([os.path.join(config.llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000159 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000160 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000161except OSError as why:
Zachary Turnerce92db12017-09-15 22:10:46 +0000162 print("Could not find llvm-config in " + config.llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000163 exit(42)
164
Michael J. Spencer876bee82014-03-26 01:19:07 +0000165llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000166llvm_config_output_list = llvm_config_output.split("\n")
167
168if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000169 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000170if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000171 config.available_features.add('asserts')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000172
173archs = llvm_config_output_list[2]
174if re.search(r'AArch64', archs):
175 config.available_features.add('aarch64')
Ed Maste87b0ab12017-06-27 12:21:50 +0000176if re.search(r'AMDGPU', archs):
177 config.available_features.add('amdgpu')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000178if re.search(r'ARM', archs):
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000179 config.available_features.add('arm')
Leslie Zhai49ba7952017-06-15 02:27:50 +0000180if re.search(r'AVR', archs):
181 config.available_features.add('avr')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000182if re.search(r'Mips', archs):
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000183 config.available_features.add('mips')
Rafael Espindola83af95d2015-09-28 12:22:25 +0000184if re.search(r'PowerPC', archs):
Rafael Espindola1c2f64d2015-08-05 23:40:20 +0000185 config.available_features.add('ppc')
Rui Ueyama0cc14832017-06-28 17:05:39 +0000186if re.search(r'Sparc', archs):
187 config.available_features.add('sparc')
Ed Maste87b0ab12017-06-27 12:21:50 +0000188if re.search(r'X86', archs):
189 config.available_features.add('x86')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000190llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000191
Rui Ueyama3da3f062016-11-10 20:20:37 +0000192# Set a fake constant version so that we get consitent output.
193config.environment['LLD_VERSION'] = 'LLD 1.0'
194
Eric Beckmannc8dba242017-07-08 03:06:10 +0000195# Indirectly check if the mt.exe Microsoft utility exists by searching for
Eric Beckmann87c6acf2017-08-22 03:15:28 +0000196# cvtres, which always accompanies it. Alternatively, check if we can use
197# libxml2 to merge manifests.
198if (lit.util.which('cvtres', config.environment['PATH'])) or \
199 (config.llvm_libxml2_enabled == "1"):
200 config.available_features.add('manifest_tool')
Eric Beckmann0aa4b7d2017-09-06 01:50:36 +0000201
202if (config.llvm_libxml2_enabled == "1"):
203 config.available_features.add('libxml2')