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