blob: a965c3fa21f73d784e267c6abf05cbe79cd01381 [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
17# testFormat: The test format to use to interpret tests.
18#
19# For now we require '&&' between commands, until they get globally killed and
20# the test runner updated.
21execute_external = (platform.system() != 'Windows'
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000022 or lit_config.getBashPath() not in [None, ""])
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000023config.test_format = lit.formats.ShTest(execute_external)
24
25# suffixes: A list of file extensions to treat as test files.
Michael J. Spencer74f29af2012-12-10 02:53:10 +000026config.suffixes = ['.objtxt', '.test']
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000027
Rafael Espindolac08ab8e2015-04-24 15:51:45 +000028# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
29# subdirectories contain auxiliary inputs for various tests in their parent
30# directories.
31config.excludes = ['Inputs']
32
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000033# test_source_root: The root path where tests are located.
34config.test_source_root = os.path.dirname(__file__)
35
36# test_exec_root: The root path where tests should be run.
37lld_obj_root = getattr(config, 'lld_obj_root', None)
38if lld_obj_root is not None:
39 config.test_exec_root = os.path.join(lld_obj_root, 'test')
40
41# Set llvm_{src,obj}_root for use by others.
42config.llvm_src_root = getattr(config, 'llvm_src_root', None)
43config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
44
45# Tweak the PATH to include the tools dir and the scripts dir.
46if lld_obj_root is not None:
47 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
48 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000049 lit_config.fatal('No LLVM tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000050 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000051 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 +000052
Sid Manning37e31202012-09-14 20:04:36 +000053 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000054
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000055 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
56 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000057 lit_config.fatal('No LLVM libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000058 path = os.path.pathsep.join((llvm_libs_dir,
59 config.environment.get('LD_LIBRARY_PATH','')))
60 config.environment['LD_LIBRARY_PATH'] = path
61
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000062 # Propagate LLVM_SRC_ROOT into the environment.
63 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
64
65 # Propagate PYTHON_EXECUTABLE into the environment
66 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
67 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000068###
69
70# Check that the object root is known.
71if config.test_exec_root is None:
72 # Otherwise, we haven't loaded the site specific configuration (the user is
73 # probably trying to run on a test file directly, and either the site
74 # configuration hasn't been created by the build system, or we are in an
75 # out-of-tree build situation).
76
77 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000078 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000079 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000080 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000081 raise SystemExit
82
83 # Try to detect the situation where we are using an out-of-tree build by
84 # looking for 'llvm-config'.
85 #
86 # FIXME: I debated (i.e., wrote and threw away) adding logic to
87 # automagically generate the lit.site.cfg if we are in some kind of fresh
88 # build situation. This means knowing how to invoke the build system though,
89 # and I decided it was too much magic. We should solve this by just having
90 # the .cfg files generated during the configuration step.
91
92 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
93 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000094 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000095
96 # Get the source and object roots.
97 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
98 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
99 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
100 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
101
102 # Validate that we got a tree which points to here, using the standard
103 # tools/lld layout.
104 this_src_root = os.path.dirname(config.test_source_root)
105 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000106 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000107
108 # Check that the site specific configuration exists.
109 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
110 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000111 lit_config.fatal(
112 'No site specific configuration available! You may need to '
113 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000114
115 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000116 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
117 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000118 raise SystemExit
119
120# When running under valgrind, we mangle '-vg' onto the end of the triple so we
121# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000122if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000123 config.target_triple += '-vg'
124
125# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000126if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000127 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000128
Nick Kledzik50bda292014-09-11 00:52:05 +0000129# Running on Darwin OS
130if platform.system() in ['Darwin']:
131 config.available_features.add('system-linker-mach-o')
132
133# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000134if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000135 config.available_features.add('system-linker-elf')
136
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000137# llvm-config knows whether it is compiled with asserts (and)
138# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000139import subprocess
140try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000141 llvm_config_cmd = \
142 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000143 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000144 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000145except OSError as why:
146 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000147 exit(42)
148
Michael J. Spencer876bee82014-03-26 01:19:07 +0000149llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000150llvm_config_output_list = llvm_config_output.split("\n")
151
152if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000153 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000154if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000155 config.available_features.add('asserts')
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000156if re.search(r'ARM', llvm_config_output_list[2]):
157 config.available_features.add('arm')
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000158if re.search(r'Mips', llvm_config_output_list[2]):
159 config.available_features.add('mips')
Filipe Cabecinhasd1787ad2015-01-24 03:55:22 +0000160if re.search(r'X86', llvm_config_output_list[2]):
161 config.available_features.add('x86')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000162llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000163
164# Check if Windows resource file compiler exists.
165cvtres = lit.util.which('cvtres', config.environment['PATH'])
166rc = lit.util.which('rc', config.environment['PATH'])
167if cvtres and rc:
168 config.available_features.add('winres')
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000169
Filipe Cabecinhas47f07f82014-04-23 04:38:13 +0000170# Check if "lib.exe" command exists.
171if lit.util.which('lib.exe', config.environment['PATH']):
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000172 config.available_features.add('winlib')