lit.cfg revision db5fe936db5e718ec6189f969749444ecdc1c484
1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6
7# name: The name of this test suite.
8config.name = 'LLVM-Unit'
9
10# suffixes: A list of file extensions to treat as test files, this is actually
11# set by on_clone().
12config.suffixes = []
13
14# test_source_root: The root path where tests are located.
15# test_exec_root: The root path where tests should be run.
16llvm_obj_root = getattr(config, 'llvm_obj_root', None)
17if llvm_obj_root is not None:
18    config.test_exec_root = os.path.join(llvm_obj_root, 'unittests')
19    config.test_source_root = config.test_exec_root
20
21# testFormat: The test format to use to interpret tests.
22llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
23config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
24
25###
26
27import os
28
29# Check that the object root is known.
30if config.test_exec_root is None:
31    # Otherwise, we haven't loaded the site specific configuration (the user is
32    # probably trying to run on a test file directly, and either the site
33    # configuration hasn't been created by the build system, or we are in an
34    # out-of-tree build situation).
35
36    # Try to detect the situation where we are using an out-of-tree build by
37    # looking for 'llvm-config'.
38    #
39    # FIXME: I debated (i.e., wrote and threw away) adding logic to
40    # automagically generate the lit.site.cfg if we are in some kind of fresh
41    # build situation. This means knowing how to invoke the build system
42    # though, and I decided it was too much magic.
43
44    llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
45    if not llvm_config:
46        lit.fatal('No site specific configuration available!')
47
48    # Get the source and object roots.
49    llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
50    llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
51
52    # Validate that we got a tree which points to here.
53    this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
54    if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
55        lit.fatal('No site specific configuration available!')
56
57    # Check that the site specific configuration exists.
58    site_cfg = os.path.join(llvm_obj_root, 'test', 'Unit', 'lit.site.cfg')
59    if not os.path.exists(site_cfg):
60        lit.fatal('No site specific configuration available!')
61
62    # Okay, that worked. Notify the user of the automagic, and reconfigure.
63    lit.note('using out-of-tree build at %r' % llvm_obj_root)
64    lit.load_config(config, site_cfg)
65    raise SystemExit
66