blob: 09a320f6e49d60e912276fa10b78b774956d7f9c [file] [log] [blame]
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00001# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
7
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +00008import lit.formats
9import lit.util
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000010
11# Configuration file for the 'lit' test runner.
12
13# name: The name of this test suite.
14config.name = 'lld'
15
16# testFormat: The test format to use to interpret tests.
17#
18# For now we require '&&' between commands, until they get globally killed and
19# the test runner updated.
20execute_external = (platform.system() != 'Windows'
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000021 or lit_config.getBashPath() not in [None, ""])
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000022config.test_format = lit.formats.ShTest(execute_external)
23
24# suffixes: A list of file extensions to treat as test files.
Michael J. Spencer74f29af2012-12-10 02:53:10 +000025config.suffixes = ['.objtxt', '.test']
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000026
27# test_source_root: The root path where tests are located.
28config.test_source_root = os.path.dirname(__file__)
29
30# test_exec_root: The root path where tests should be run.
31lld_obj_root = getattr(config, 'lld_obj_root', None)
32if lld_obj_root is not None:
33 config.test_exec_root = os.path.join(lld_obj_root, 'test')
34
35# Set llvm_{src,obj}_root for use by others.
36config.llvm_src_root = getattr(config, 'llvm_src_root', None)
37config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
38
39# Tweak the PATH to include the tools dir and the scripts dir.
40if lld_obj_root is not None:
41 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
42 if not llvm_tools_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000043 lit_config.fatal('No LLVM tools dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000044 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Sid Manning37e31202012-09-14 20:04:36 +000045 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 +000046
Sid Manning37e31202012-09-14 20:04:36 +000047 config.environment['PATH'] = path
Hemant Kulkarni927bbc22012-09-14 16:11:34 +000048
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000049 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
50 if not llvm_libs_dir:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000051 lit_config.fatal('No LLVM libs dir set!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000052 path = os.path.pathsep.join((llvm_libs_dir,
53 config.environment.get('LD_LIBRARY_PATH','')))
54 config.environment['LD_LIBRARY_PATH'] = path
55
Michael J. Spencerca20ffb2013-01-13 01:09:51 +000056 # Propagate LLVM_SRC_ROOT into the environment.
57 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
58
59 # Propagate PYTHON_EXECUTABLE into the environment
60 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
61 '')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000062###
63
64# Check that the object root is known.
65if config.test_exec_root is None:
66 # Otherwise, we haven't loaded the site specific configuration (the user is
67 # probably trying to run on a test file directly, and either the site
68 # configuration hasn't been created by the build system, or we are in an
69 # out-of-tree build situation).
70
71 # Check for 'lld_site_config' user parameter, and use that if available.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000072 site_cfg = lit_config.params.get('lld_site_config', None)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000073 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000074 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000075 raise SystemExit
76
77 # Try to detect the situation where we are using an out-of-tree build by
78 # looking for 'llvm-config'.
79 #
80 # FIXME: I debated (i.e., wrote and threw away) adding logic to
81 # automagically generate the lit.site.cfg if we are in some kind of fresh
82 # build situation. This means knowing how to invoke the build system though,
83 # and I decided it was too much magic. We should solve this by just having
84 # the .cfg files generated during the configuration step.
85
86 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
87 if not llvm_config:
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +000088 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000089
90 # Get the source and object roots.
91 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
92 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
93 lld_src_root = os.path.join(llvm_src_root, "tools", "lld")
94 lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld")
95
96 # Validate that we got a tree which points to here, using the standard
97 # tools/lld layout.
98 this_src_root = os.path.dirname(config.test_source_root)
99 if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000100 lit_config.fatal('No site specific configuration available!')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000101
102 # Check that the site specific configuration exists.
103 site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg')
104 if not os.path.exists(site_cfg):
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000105 lit_config.fatal(
106 'No site specific configuration available! You may need to '
107 'run "make test" in your lld build directory.')
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000108
109 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000110 lit_config.note('using out-of-tree build at %r' % lld_obj_root)
111 lit_config.load_config(config, site_cfg)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000112 raise SystemExit
113
114# When running under valgrind, we mangle '-vg' onto the end of the triple so we
115# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000116if lit_config.useValgrind:
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000117 config.target_triple += '-vg'
118
119# Shell execution
Daniel Dunbarbc7bfb12013-08-09 18:51:17 +0000120if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000121 config.available_features.add('shell')
Rui Ueyama92492222013-07-03 09:09:13 +0000122
123# llc knows whether it is compiled with -DNDEBUG.
124import subprocess
125try:
126 llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'],
127 stdout = subprocess.PIPE)
128except OSError, why:
129 print "Could not find llc in " + llvm_tools_dir
130 exit(42)
131
Rui Ueyama130a6eb2013-07-04 09:29:47 +0000132if re.search(r'DEBUG', llc_cmd.stdout.read()):
133 config.available_features.add('debug')
Rui Ueyama92492222013-07-03 09:09:13 +0000134if re.search(r'with assertions', llc_cmd.stdout.read()):
135 config.available_features.add('asserts')
136llc_cmd.wait()