blob: 8661ac1c686c5ce6591aac2953d9182848120c3c [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
142# When running under valgrind, we mangle '-vg' onto the end of the triple so we
143# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000144if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000145 config.target_triple += '-vg'
146
147# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000148if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000149 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000150
Nick Kledzik50bda292014-09-11 00:52:05 +0000151# Running on Darwin OS
152if platform.system() in ['Darwin']:
153 config.available_features.add('system-linker-mach-o')
154
155# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000156if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000157 config.available_features.add('system-linker-elf')
158
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000159# llvm-config knows whether it is compiled with asserts (and)
160# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000161import subprocess
162try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000163 llvm_config_cmd = \
164 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000165 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000166 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000167except OSError as why:
168 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000169 exit(42)
170
Michael J. Spencer876bee82014-03-26 01:19:07 +0000171llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000172llvm_config_output_list = llvm_config_output.split("\n")
173
174if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000175 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000176if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000177 config.available_features.add('asserts')
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000178if re.search(r'ARM', llvm_config_output_list[2]):
179 config.available_features.add('arm')
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000180if re.search(r'Mips', llvm_config_output_list[2]):
181 config.available_features.add('mips')
Filipe Cabecinhasd1787ad2015-01-24 03:55:22 +0000182if re.search(r'X86', llvm_config_output_list[2]):
183 config.available_features.add('x86')
Rafael Espindola1c2f64d2015-08-05 23:40:20 +0000184if re.search(r'PowerPC', llvm_config_output_list[2]):
185 config.available_features.add('ppc')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000186llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000187
188# Check if Windows resource file compiler exists.
189cvtres = lit.util.which('cvtres', config.environment['PATH'])
190rc = lit.util.which('rc', config.environment['PATH'])
191if cvtres and rc:
192 config.available_features.add('winres')
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000193
Filipe Cabecinhas47f07f82014-04-23 04:38:13 +0000194# Check if "lib.exe" command exists.
Rafael Espindolaccd3adc2015-08-05 19:55:17 +0000195if lit.util.which('lib', config.environment['PATH']):
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000196 config.available_features.add('winlib')