Clang Project

clang_source_code/test/lit.cfg.py
1# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
7import tempfile
8
9import lit.formats
10import lit.util
11
12from lit.llvm import llvm_config
13from lit.llvm.subst import ToolSubst
14from lit.llvm.subst import FindTool
15
16# Configuration file for the 'lit' test runner.
17
18# name: The name of this test suite.
19config.name = 'Clang'
20
21# testFormat: The test format to use to interpret tests.
22#
23# For now we require '&&' between commands, until they get globally killed and
24# the test runner updated.
25config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
26
27# suffixes: A list of file extensions to treat as test files.
28config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
29                   '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs']
30
31# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
32# subdirectories contain auxiliary inputs for various tests in their parent
33# directories.
34config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests']
35
36# test_source_root: The root path where tests are located.
37config.test_source_root = os.path.dirname(__file__)
38
39# test_exec_root: The root path where tests should be run.
40config.test_exec_root = os.path.join(config.clang_obj_root, 'test')
41
42llvm_config.use_default_substitutions()
43
44llvm_config.use_clang()
45
46config.substitutions.append(
47    ('%src_include_dir', config.clang_src_dir + '/include'))
48
49
50# Propagate path to symbolizer for ASan/MSan.
51llvm_config.with_system_environment(
52    ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
53
54config.substitutions.append(('%PATH%', config.environment['PATH']))
55
56
57# For each occurrence of a clang tool name, replace it with the full path to
58# the build directory holding that tool.  We explicitly specify the directories
59# to search to ensure that we get the tools just built and not some random
60# tools that might happen to be in the user's PATH.
61tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
62
63tools = [
64    'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen',
65    'opt',
66    ToolSubst('%clang_extdef_map', command=FindTool(
67        'clang-extdef-mapping'), unresolved='ignore'),
68]
69
70if config.clang_examples:
71    config.available_features.add('examples')
72    tools.append('clang-interpreter')
73
74llvm_config.add_tool_substitutions(tools, tool_dirs)
75
76config.substitutions.append(
77    ('%hmaptool', "'%s' %s" % (config.python_executable,
78                             os.path.join(config.clang_tools_dir, 'hmaptool'))))
79
80# Plugins (loadable modules)
81# TODO: This should be supplied by Makefile or autoconf.
82if sys.platform in ['win32', 'cygwin']:
83    has_plugins = config.enable_shared
84else:
85    has_plugins = True
86
87if has_plugins and config.llvm_plugin_ext:
88    config.available_features.add('plugins')
89
90# Set available features we allow tests to conditionalize on.
91#
92if config.clang_default_cxx_stdlib != '':
93    config.available_features.add('default-cxx-stdlib-set')
94
95# Enabled/disabled features
96if config.clang_staticanalyzer:
97    config.available_features.add('staticanalyzer')
98
99    if config.clang_staticanalyzer_z3 == '1':
100        config.available_features.add('z3')
101
102# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
103if platform.system() not in ['FreeBSD']:
104    config.available_features.add('crash-recovery')
105
106# ANSI escape sequences in non-dumb terminal
107if platform.system() not in ['Windows']:
108    config.available_features.add('ansi-escape-sequences')
109
110# Capability to print utf8 to the terminal.
111# Windows expects codepage, unless Wide API.
112if platform.system() not in ['Windows']:
113    config.available_features.add('utf8-capable-terminal')
114
115# Support for libgcc runtime. Used to rule out tests that require
116# clang to run with -rtlib=libgcc.
117if platform.system() not in ['Darwin', 'Fuchsia']:
118    config.available_features.add('libgcc')
119
120# Case-insensitive file system
121
122
123def is_filesystem_case_insensitive():
124    handle, path = tempfile.mkstemp(
125        prefix='case-test', dir=config.test_exec_root)
126    isInsensitive = os.path.exists(
127        os.path.join(
128            os.path.dirname(path),
129            os.path.basename(path).upper()
130        ))
131    os.close(handle)
132    os.remove(path)
133    return isInsensitive
134
135
136if is_filesystem_case_insensitive():
137    config.available_features.add('case-insensitive-filesystem')
138
139# Tests that require the /dev/fd filesystem.
140if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
141    config.available_features.add('dev-fd-fs')
142
143# Not set on native MS environment.
144if not re.match(r'.*-(windows-msvc)$', config.target_triple):
145    config.available_features.add('non-ms-sdk')
146
147# Not set on native PS4 environment.
148if not re.match(r'.*-scei-ps4', config.target_triple):
149    config.available_features.add('non-ps4-sdk')
150
151# [PR8833] LLP64-incompatible tests
152if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple):
153    config.available_features.add('LP64')
154
155# [PR12920] "clang-driver" -- set if gcc driver is not used.
156if not re.match(r'.*-(cygwin)$', config.target_triple):
157    config.available_features.add('clang-driver')
158
159# [PR18856] Depends to remove opened file. On win32, a file could be removed
160# only if all handles were closed.
161if platform.system() not in ['Windows']:
162    config.available_features.add('can-remove-opened-file')
163
164
165def calculate_arch_features(arch_string):
166    features = []
167    for arch in arch_string.split():
168        features.append(arch.lower() + '-registered-target')
169    return features
170
171
172llvm_config.feature_config(
173    [('--assertion-mode', {'ON': 'asserts'}),
174     ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
175        ('--targets-built', calculate_arch_features)
176     ])
177
178if lit.util.which('xmllint'):
179    config.available_features.add('xmllint')
180
181if config.enable_backtrace:
182    config.available_features.add('backtrace')
183
184# Check if we should allow outputs to console.
185run_console_tests = int(lit_config.params.get('enable_console', '0'))
186if run_console_tests != 0:
187    config.available_features.add('console')
188
189lit.util.usePlatformSdkOnDarwin(config, lit_config)
190macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
191if macOSSDKVersion is not None:
192    config.available_features.add('macos-sdk-' + macOSSDKVersion)
193
194if os.path.exists('/etc/gentoo-release'):
195    config.available_features.add('gentoo')
196