blob: 07eeca77984cf02f5f1b2bae6b319cebaeddfd54 [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
Rui Ueyamabc6b52e2014-03-20 02:49:33 +000031# run RoundTrip{YAML,Native}Tests.
32config.environment['LLD_RUN_ROUNDTRIP_TEST'] = '1'
33
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000034# test_exec_root: The root path where tests should be run.
35lld_obj_root = getattr(config, 'lld_obj_root', None)
36if lld_obj_root is not None:
37 config.test_exec_root = os.path.join(lld_obj_root, 'test')
38
39# Set llvm_{src,obj}_root for use by others.
40config.llvm_src_root = getattr(config, 'llvm_src_root', None)
41config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
42
43# Tweak the PATH to include the tools dir and the scripts dir.
44if lld_obj_root is not None:
45 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
46 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000047 lit_config.fatal('No LLVM tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000048 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000049 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 +000050
Sid Manning37e31202012-09-14 20:04:36 +000051 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000052
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000053 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
54 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000055 lit_config.fatal('No LLVM libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000056 path = os.path.pathsep.join((llvm_libs_dir,
57 config.environment.get('LD_LIBRARY_PATH','')))
58 config.environment['LD_LIBRARY_PATH'] = path
59
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000060 # Propagate LLVM_SRC_ROOT into the environment.
61 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
62
63 # Propagate PYTHON_EXECUTABLE into the environment
64 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
65 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000066###
67
68# Check that the object root is known.
69if config.test_exec_root is None:
70 # Otherwise, we haven't loaded the site specific configuration (the user is
71 # probably trying to run on a test file directly, and either the site
72 # configuration hasn't been created by the build system, or we are in an
73 # out-of-tree build situation).
74
75 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000076 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000077 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000078 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000079 raise SystemExit
80
81 # Try to detect the situation where we are using an out-of-tree build by
82 # looking for 'llvm-config'.
83 #
84 # FIXME: I debated (i.e., wrote and threw away) adding logic to
85 # automagically generate the lit.site.cfg if we are in some kind of fresh
86 # build situation. This means knowing how to invoke the build system though,
87 # and I decided it was too much magic. We should solve this by just having
88 # the .cfg files generated during the configuration step.
89
90 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
91 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000092 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000093
94 # Get the source and object roots.
95 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
96 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
97 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
98 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
99
100 # Validate that we got a tree which points to here, using the standard
101 # tools/lld layout.
102 this_src_root = os.path.dirname(config.test_source_root)
103 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000104 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000105
106 # Check that the site specific configuration exists.
107 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
108 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000109 lit_config.fatal(
110 'No site specific configuration available! You may need to '
111 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000112
113 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000114 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
115 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000116 raise SystemExit
117
118# When running under valgrind, we mangle '-vg' onto the end of the triple so we
119# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000120if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000121 config.target_triple += '-vg'
122
123# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000124if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000125 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000126
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000127# llvm-config knows whether it is compiled with asserts (and)
128# whether we are operating in release/debug mode.
Rui Ueyama92492222013-07-03 09:09:13 +0000129import subprocess
130try:
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000131 llvm_config_cmd = \
132 subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'),
133 '--build-mode', '--assertion-mode'],
134 stdout = subprocess.PIPE)
Michael J. Spencera4f983e2014-03-26 00:53:48 +0000135except OSError as why:
136 print("Could not find llvm-config in " + llvm_tools_dir)
Rui Ueyama92492222013-07-03 09:09:13 +0000137 exit(42)
138
Michael J. Spencer876bee82014-03-26 01:19:07 +0000139llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000140llvm_config_output_list = llvm_config_output.split("\n")
141
142if re.search(r'DEBUG', llvm_config_output_list[0]):
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000143 config.available_features.add('debug')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000144if re.search(r'ON', llvm_config_output_list[1]):
Rui Ueyama92492222013-07-03 09:09:13 +0000145 config.available_features.add('asserts')
Shankar Easwaran7a0818d2014-02-25 02:29:17 +0000146llvm_config_cmd.wait()
Rui Ueyamaf23b27a2013-11-04 05:17:54 +0000147
148# Check if Windows resource file compiler exists.
149cvtres = lit.util.which('cvtres', config.environment['PATH'])
150rc = lit.util.which('rc', config.environment['PATH'])
151if cvtres and rc:
152 config.available_features.add('winres')
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000153
Filipe Cabecinhas47f07f82014-04-23 04:38:13 +0000154# Check if "lib.exe" command exists.
155if lit.util.which('lib.exe', config.environment['PATH']):
Rui Ueyama76d2fa72014-01-09 01:11:48 +0000156 config.available_features.add('winlib')