blob: 4fa6e78ed63b34eaa643fbbf3bc2a6cfabdd8f39 [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
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +00007
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +00008import lit.formats
9import lit.util
10
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000011# name: The name of this test suite.
12config.name = 'Clang-Unit'
13
14# suffixes: A list of file extensions to treat as test files.
15config.suffixes = []
16
17# test_source_root: The root path where tests are located.
18# test_exec_root: The root path where tests should be run.
19clang_obj_root = getattr(config, 'clang_obj_root', None)
20if clang_obj_root is not None:
21 config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
22 config.test_source_root = config.test_exec_root
23
24# testFormat: The test format to use to interpret tests.
25llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
26config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
27
28# Propagate the temp directory. Windows requires this because it uses \Windows\
29# if none of these are present.
30if 'TMP' in os.environ:
31 config.environment['TMP'] = os.environ['TMP']
32if 'TEMP' in os.environ:
33 config.environment['TEMP'] = os.environ['TEMP']
34
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000035# Propagate path to symbolizer for ASan/MSan.
36for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
37 if symbolizer in os.environ:
38 config.environment[symbolizer] = os.environ[symbolizer]
39
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000040###
41
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000042# Check that the object root is known.
43if config.test_exec_root is None:
44 # Otherwise, we haven't loaded the site specific configuration (the user is
45 # probably trying to run on a test file directly, and either the site
46 # configuration hasn't been created by the build system, or we are in an
47 # out-of-tree build situation).
48
Jeffrey Yasskincd3858b2011-02-15 07:54:28 +000049 # Check for 'clang_unit_site_config' user parameter, and use that if available.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000050 site_cfg = lit_config.params.get('clang_unit_site_config', None)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000051 if site_cfg and os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000052 lit_config.load_config(config, site_cfg)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000053 raise SystemExit
54
55 # Try to detect the situation where we are using an out-of-tree build by
56 # looking for 'llvm-config'.
57 #
58 # FIXME: I debated (i.e., wrote and threw away) adding logic to
59 # automagically generate the lit.site.cfg if we are in some kind of fresh
60 # build situation. This means knowing how to invoke the build system
61 # though, and I decided it was too much magic.
62
63 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
64 if not llvm_config:
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000065 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000066
67 # Get the source and object roots.
68 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
69 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
70 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
71 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
72
73 # Validate that we got a tree which points to here, using the standard
74 # tools/clang layout.
Daniel Dunbara60a2692011-06-22 21:46:43 +000075 this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000076 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000077 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000078
79 # Check that the site specific configuration exists.
80 site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg')
81 if not os.path.exists(site_cfg):
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000082 lit_config.fatal('No site specific configuration available!')
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000083
84 # Okay, that worked. Notify the user of the automagic, and reconfigure.
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +000085 lit_config.note('using out-of-tree build at %r' % clang_obj_root)
86 lit_config.load_config(config, site_cfg)
Jeffrey Yasskinc7da9932011-02-03 04:51:52 +000087 raise SystemExit
Daniel Dunbara60a2692011-06-22 21:46:43 +000088
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +000089shlibpath_var = ''
90if platform.system() == 'Linux':
91 shlibpath_var = 'LD_LIBRARY_PATH'
92elif platform.system() == 'Darwin':
93 shlibpath_var = 'DYLD_LIBRARY_PATH'
94elif platform.system() == 'Windows':
95 shlibpath_var = 'PATH'
96
97# Point the dynamic loader at dynamic libraries in 'lib'.
98llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
99if not llvm_libs_dir:
100 lit_config.fatal('No LLVM libs dir set!')
101shlibpath = os.path.pathsep.join((llvm_libs_dir,
102 config.environment.get(shlibpath_var,'')))
NAKAMURA Takumib52c7612014-07-04 05:11:55 +0000103
104# Win32 seeks DLLs along %PATH%.
105if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
106 shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
107
Dmitri Gribenko1bf8d912014-02-18 15:20:02 +0000108config.environment[shlibpath_var] = shlibpath