• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6import platform
7
8import lit.formats
9import lit.util
10
11# 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
35# 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
40###
41
42# 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
49    # Check for 'clang_unit_site_config' user parameter, and use that if available.
50    site_cfg = lit_config.params.get('clang_unit_site_config', None)
51    if site_cfg and os.path.exists(site_cfg):
52        lit_config.load_config(config, site_cfg)
53        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:
65        lit_config.fatal('No site specific configuration available!')
66
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.
75    this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
76    if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
77        lit_config.fatal('No site specific configuration available!')
78
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):
82        lit_config.fatal('No site specific configuration available!')
83
84    # Okay, that worked. Notify the user of the automagic, and reconfigure.
85    lit_config.note('using out-of-tree build at %r' % clang_obj_root)
86    lit_config.load_config(config, site_cfg)
87    raise SystemExit
88
89shlibpath_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,'')))
103
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
108config.environment[shlibpath_var] = shlibpath
109