blob: 5b49765f7894352407fa407568cf55ecca716e98 [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
28# test_source_root: The root path where tests are located.
29config.test_source_root = os.path.dirname(__file__)
30
31# test_exec_root: The root path where tests should be run.
32lld_obj_root = getattr(config, 'lld_obj_root', None)
33if lld_obj_root is not None:
34 config.test_exec_root = os.path.join(lld_obj_root, 'test')
35
36# Set llvm_{src,obj}_root for use by others.
37config.llvm_src_root = getattr(config, 'llvm_src_root', None)
38config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
39
40# Tweak the PATH to include the tools dir and the scripts dir.
41if lld_obj_root is not None:
42 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
43 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000044 lit_config.fatal('No LLVM tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000045 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000046 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 +000047
Sid Manning37e31202012-09-14 20:04:36 +000048 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000049
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000050 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
51 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000052 lit_config.fatal('No LLVM libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000053 path = os.path.pathsep.join((llvm_libs_dir,
54 config.environment.get('LD_LIBRARY_PATH','')))
55 config.environment['LD_LIBRARY_PATH'] = path
56
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000057 # Propagate LLVM_SRC_ROOT into the environment.
58 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
59
60 # Propagate PYTHON_EXECUTABLE into the environment
61 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
62 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000063###
64
65# Check that the object root is known.
66if config.test_exec_root is None:
67 # Otherwise, we haven't loaded the site specific configuration (the user is
68 # probably trying to run on a test file directly, and either the site
69 # configuration hasn't been created by the build system, or we are in an
70 # out-of-tree build situation).
71
72 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000073 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000074 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000075 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000076 raise SystemExit
77
78 # Try to detect the situation where we are using an out-of-tree build by
79 # looking for 'llvm-config'.
80 #
81 # FIXME: I debated (i.e., wrote and threw away) adding logic to
82 # automagically generate the lit.site.cfg if we are in some kind of fresh
83 # build situation. This means knowing how to invoke the build system though,
84 # and I decided it was too much magic. We should solve this by just having
85 # the .cfg files generated during the configuration step.
86
87 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
88 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000089 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000090
91 # Get the source and object roots.
92 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
93 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
94 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
95 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
96
97 # Validate that we got a tree which points to here, using the standard
98 # tools/lld layout.
99 this_src_root = os.path.dirname(config.test_source_root)
100 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000101 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000102
103 # Check that the site specific configuration exists.
104 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
105 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000106 lit_config.fatal(
107 'No site specific configuration available! You may need to '
108 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000109
110 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000111 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
112 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000113 raise SystemExit
114
115# When running under valgrind, we mangle '-vg' onto the end of the triple so we
116# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000117if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000118 config.target_triple += '-vg'
119
120# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000121if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000122 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000123
Nick Kledzik50bda292014-09-11 00:52:05 +0000124# Running on Darwin OS
125if platform.system() in ['Darwin']:
126 config.available_features.add('system-linker-mach-o')
127
128# Running on ELF based *nix
Ed Maste933daef2014-09-12 13:16:30 +0000129if platform.system() in ['FreeBSD', 'Linux']:
Nick Kledzik50bda292014-09-11 00:52:05 +0000130 config.available_features.add('system-linker-elf')
131
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000132# llvm-config knows whether it is compiled with asserts (and)
133# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000134import subprocess
135try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000136 llvm_config_cmd = \
137 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000138 '--build-mode', '--assertion-mode', '--targets-built'],
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000139 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000140except OSError as why:
141 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000142 exit(42)
143
Michael J. Spencer876bee82014-03-26 01:19:07 +0000144llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000145llvm_config_output_list = llvm_config_output.split("\n")
146
147if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000148 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000149if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000150 config.available_features.add('asserts')
Simon Atanasyand7bc5d02014-07-31 19:02:10 +0000151if re.search(r'ARM', llvm_config_output_list[2]):
152 config.available_features.add('arm')
Filipe Cabecinhascd8c6102014-04-23 05:35:26 +0000153if re.search(r'Mips', llvm_config_output_list[2]):
154 config.available_features.add('mips')
Filipe Cabecinhasd1787ad2015-01-24 03:55:22 +0000155if re.search(r'X86', llvm_config_output_list[2]):
156 config.available_features.add('x86')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000157llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000158
159# Check if Windows resource file compiler exists.
160cvtres = lit.util.which('cvtres', config.environment['PATH'])
161rc = lit.util.which('rc', config.environment['PATH'])
162if cvtres and rc:
163 config.available_features.add('winres')
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000164
Filipe Cabecinhas47f07f82014-04-23 04:38:13 +0000165# Check if "lib.exe" command exists.
166if lit.util.which('lib.exe', config.environment['PATH']):
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000167 config.available_features.add('winlib')