blob: 90eb2ac604a57b48a0502866ece6bf892bef255f [file] [log] [blame]
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +00001# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +00006import platform
David L. Jonesd4053fb2017-07-06 21:46:47 +00007import subprocess
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +00008
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +00009import lit.formats
10import lit.util
11
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000012# name: The name of this test suite.
13config.name = 'Clang-Unit'
14
15# suffixes: A list of file extensions to treat as test files.
16config.suffixes = []
17
18# test_source_root: The root path where tests are located.
19# test_exec_root: The root path where tests should be run.
20clang_obj_root = getattr(config, 'clang_obj_root', None)
21if clang_obj_root is not None:
22 config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
23 config.test_source_root = config.test_exec_root
24
25# testFormat: The test format to use to interpret tests.
26llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
27config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
28
29# Propagate the temp directory. Windows requires this because it uses \Windows\
30# if none of these are present.
31if 'TMP' in os.environ:
32 config.environment['TMP'] = os.environ['TMP']
33if 'TEMP' in os.environ:
34 config.environment['TEMP'] = os.environ['TEMP']
35
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000036# Propagate path to symbolizer for ASan/MSan.
37for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
38 if symbolizer in os.environ:
39 config.environment[symbolizer] = os.environ[symbolizer]
40
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000041###
42
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000043# Check that the object root is known.
44if config.test_exec_root is None:
45 # Otherwise, we haven't loaded the site specific configuration (the user is
46 # probably trying to run on a test file directly, and either the site
47 # configuration hasn't been created by the build system, or we are in an
48 # out-of-tree build situation).
49
Jeffrey Yasskincd3858b2011-02-15 07:54:28 +000050 # Check for 'clang_unit_site_config' user parameter, and use that if available.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000051 site_cfg = lit_config.params.get('clang_unit_site_config', None)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000052 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000053 lit_config.load_config(config, site_cfg)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000054 raise SystemExit
55
56 # Try to detect the situation where we are using an out-of-tree build by
57 # looking for 'llvm-config'.
58 #
59 # FIXME: I debated (i.e., wrote and threw away) adding logic to
60 # automagically generate the lit.site.cfg if we are in some kind of fresh
61 # build situation. This means knowing how to invoke the build system
62 # though, and I decided it was too much magic.
63
64 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
65 if not llvm_config:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000066 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000067
68 # Get the source and object roots.
David L. Jonesd4053fb2017-07-06 21:46:47 +000069 llvm_src_root = subprocess.check_output(['llvm-config', '--src-root']).strip()
70 llvm_obj_root = subprocess.check_output(['llvm-config', '--obj-root']).strip()
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000071 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
72 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
73
74 # Validate that we got a tree which points to here, using the standard
75 # tools/clang layout.
Daniel Dunbara60a2692011-06-22 21:46:43 +000076 this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000077 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000078 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000079
80 # Check that the site specific configuration exists.
81 site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg')
82 if not os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000083 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000084
85 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000086 lit_config.note('using out-of-tree build at %r' % clang_obj_root)
87 lit_config.load_config(config, site_cfg)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000088 raise SystemExit
Daniel Dunbara60a2692011-06-22 21:46:43 +000089
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +000090shlibpath_var = ''
91if platform.system() == 'Linux':
92 shlibpath_var = 'LD_LIBRARY_PATH'
93elif platform.system() == 'Darwin':
94 shlibpath_var = 'DYLD_LIBRARY_PATH'
95elif platform.system() == 'Windows':
96 shlibpath_var = 'PATH'
97
Michal Gorny391f2212016-12-15 20:31:08 +000098# in stand-alone builds, shlibdir is clang's build tree
99# while llvm_libs_dir is installed LLVM (and possibly older clang)
100llvm_shlib_dir = getattr(config, 'shlibdir', None)
101if not llvm_shlib_dir:
102 lit_config.fatal('No shlibdir set!')
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +0000103# Point the dynamic loader at dynamic libraries in 'lib'.
104llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
105if not llvm_libs_dir:
106 lit_config.fatal('No LLVM libs dir set!')
Michal Gorny391f2212016-12-15 20:31:08 +0000107shlibpath = os.path.pathsep.join((llvm_shlib_dir, llvm_libs_dir,
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +0000108 config.environment.get(shlibpath_var,'')))
NAKAMURA Takumib52c7612014-07-04 05:11:55 +0000109
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +0000110config.environment[shlibpath_var] = shlibpath