xref: /aosp_15_r20/external/clang/test/Unit/lit.cfg (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li# -*- Python -*-
2*67e74705SXin Li
3*67e74705SXin Li# Configuration file for the 'lit' test runner.
4*67e74705SXin Li
5*67e74705SXin Liimport os
6*67e74705SXin Liimport platform
7*67e74705SXin Li
8*67e74705SXin Liimport lit.formats
9*67e74705SXin Liimport lit.util
10*67e74705SXin Li
11*67e74705SXin Li# name: The name of this test suite.
12*67e74705SXin Liconfig.name = 'Clang-Unit'
13*67e74705SXin Li
14*67e74705SXin Li# suffixes: A list of file extensions to treat as test files.
15*67e74705SXin Liconfig.suffixes = []
16*67e74705SXin Li
17*67e74705SXin Li# test_source_root: The root path where tests are located.
18*67e74705SXin Li# test_exec_root: The root path where tests should be run.
19*67e74705SXin Liclang_obj_root = getattr(config, 'clang_obj_root', None)
20*67e74705SXin Liif clang_obj_root is not None:
21*67e74705SXin Li    config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
22*67e74705SXin Li    config.test_source_root = config.test_exec_root
23*67e74705SXin Li
24*67e74705SXin Li# testFormat: The test format to use to interpret tests.
25*67e74705SXin Lillvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
26*67e74705SXin Liconfig.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
27*67e74705SXin Li
28*67e74705SXin Li# Propagate the temp directory. Windows requires this because it uses \Windows\
29*67e74705SXin Li# if none of these are present.
30*67e74705SXin Liif 'TMP' in os.environ:
31*67e74705SXin Li    config.environment['TMP'] = os.environ['TMP']
32*67e74705SXin Liif 'TEMP' in os.environ:
33*67e74705SXin Li    config.environment['TEMP'] = os.environ['TEMP']
34*67e74705SXin Li
35*67e74705SXin Li# Propagate path to symbolizer for ASan/MSan.
36*67e74705SXin Lifor symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
37*67e74705SXin Li    if symbolizer in os.environ:
38*67e74705SXin Li        config.environment[symbolizer] = os.environ[symbolizer]
39*67e74705SXin Li
40*67e74705SXin Li###
41*67e74705SXin Li
42*67e74705SXin Li# Check that the object root is known.
43*67e74705SXin Liif config.test_exec_root is None:
44*67e74705SXin Li    # Otherwise, we haven't loaded the site specific configuration (the user is
45*67e74705SXin Li    # probably trying to run on a test file directly, and either the site
46*67e74705SXin Li    # configuration hasn't been created by the build system, or we are in an
47*67e74705SXin Li    # out-of-tree build situation).
48*67e74705SXin Li
49*67e74705SXin Li    # Check for 'clang_unit_site_config' user parameter, and use that if available.
50*67e74705SXin Li    site_cfg = lit_config.params.get('clang_unit_site_config', None)
51*67e74705SXin Li    if site_cfg and os.path.exists(site_cfg):
52*67e74705SXin Li        lit_config.load_config(config, site_cfg)
53*67e74705SXin Li        raise SystemExit
54*67e74705SXin Li
55*67e74705SXin Li    # Try to detect the situation where we are using an out-of-tree build by
56*67e74705SXin Li    # looking for 'llvm-config'.
57*67e74705SXin Li    #
58*67e74705SXin Li    # FIXME: I debated (i.e., wrote and threw away) adding logic to
59*67e74705SXin Li    # automagically generate the lit.site.cfg if we are in some kind of fresh
60*67e74705SXin Li    # build situation. This means knowing how to invoke the build system
61*67e74705SXin Li    # though, and I decided it was too much magic.
62*67e74705SXin Li
63*67e74705SXin Li    llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
64*67e74705SXin Li    if not llvm_config:
65*67e74705SXin Li        lit_config.fatal('No site specific configuration available!')
66*67e74705SXin Li
67*67e74705SXin Li    # Get the source and object roots.
68*67e74705SXin Li    llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
69*67e74705SXin Li    llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
70*67e74705SXin Li    clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
71*67e74705SXin Li    clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
72*67e74705SXin Li
73*67e74705SXin Li    # Validate that we got a tree which points to here, using the standard
74*67e74705SXin Li    # tools/clang layout.
75*67e74705SXin Li    this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
76*67e74705SXin Li    if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
77*67e74705SXin Li        lit_config.fatal('No site specific configuration available!')
78*67e74705SXin Li
79*67e74705SXin Li    # Check that the site specific configuration exists.
80*67e74705SXin Li    site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg')
81*67e74705SXin Li    if not os.path.exists(site_cfg):
82*67e74705SXin Li        lit_config.fatal('No site specific configuration available!')
83*67e74705SXin Li
84*67e74705SXin Li    # Okay, that worked. Notify the user of the automagic, and reconfigure.
85*67e74705SXin Li    lit_config.note('using out-of-tree build at %r' % clang_obj_root)
86*67e74705SXin Li    lit_config.load_config(config, site_cfg)
87*67e74705SXin Li    raise SystemExit
88*67e74705SXin Li
89*67e74705SXin Lishlibpath_var = ''
90*67e74705SXin Liif platform.system() == 'Linux':
91*67e74705SXin Li    shlibpath_var = 'LD_LIBRARY_PATH'
92*67e74705SXin Lielif platform.system() == 'Darwin':
93*67e74705SXin Li    shlibpath_var = 'DYLD_LIBRARY_PATH'
94*67e74705SXin Lielif platform.system() == 'Windows':
95*67e74705SXin Li    shlibpath_var = 'PATH'
96*67e74705SXin Li
97*67e74705SXin Li# Point the dynamic loader at dynamic libraries in 'lib'.
98*67e74705SXin Lillvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
99*67e74705SXin Liif not llvm_libs_dir:
100*67e74705SXin Li    lit_config.fatal('No LLVM libs dir set!')
101*67e74705SXin Lishlibpath = os.path.pathsep.join((llvm_libs_dir,
102*67e74705SXin Li                                 config.environment.get(shlibpath_var,'')))
103*67e74705SXin Li
104*67e74705SXin Li# Win32 seeks DLLs along %PATH%.
105*67e74705SXin Liif sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
106*67e74705SXin Li    shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
107*67e74705SXin Li
108*67e74705SXin Liconfig.environment[shlibpath_var] = shlibpath
109