2009-07-31 13:54:17 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
import os
|
2009-09-22 18:08:03 +08:00
|
|
|
import platform
|
2011-11-06 04:55:50 +08:00
|
|
|
import re
|
|
|
|
import subprocess
|
2012-11-01 04:59:50 +08:00
|
|
|
import tempfile
|
2011-11-06 04:55:50 +08:00
|
|
|
|
2013-08-09 22:43:04 +08:00
|
|
|
import lit.formats
|
|
|
|
import lit.util
|
2009-09-11 07:00:15 +08:00
|
|
|
|
2017-09-19 06:26:48 +08:00
|
|
|
from lit.llvm import llvm_config
|
[lit] Improve tool substitution in lit.
This addresses two sources of inconsistency in test configuration
files.
1. Substitution boundaries. Previously you would specify a
substitution, such as 'lli', and then additionally a set
of characters that should fail to match before and after
the tool. This was used, for example, so that matches that
are parts of full paths would not be replaced. But not all
tools did this, and those that did would often re-invent
the set of characters themselves, leading to inconsistency.
Now, every tool substitution defaults to using a sane set
of reasonable defaults and you have to explicitly opt out
of it. This actually fixed a few latent bugs that were
never being surfaced, but only on accident.
2. There was no standard way for the system to decide how to
locate a tool. Sometimes you have an explicit path, sometimes
we would search for it and build up a path ourselves, and
sometimes we would build up a full command line. Furthermore,
there was no standardized way to handle missing tools. Do we
warn, fail, ignore, etc? All of this is now encapsulated in
the ToolSubst class. You either specify an exact command to
run, or an instance of FindTool('<tool-name>') and everything
else just works. Furthermore, you can specify an action to
take if the tool cannot be resolved.
Differential Revision: https://reviews.llvm.org/D38565
llvm-svn: 315085
2017-10-07 01:54:46 +08:00
|
|
|
from lit.llvm.subst import ToolSubst
|
|
|
|
from lit.llvm.subst import FindTool
|
2017-09-19 06:26:48 +08:00
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
# Configuration file for the 'lit' test runner.
|
2009-09-09 00:39:23 +08:00
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
# name: The name of this test suite.
|
|
|
|
config.name = 'Clang'
|
2009-09-09 00:39:23 +08:00
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
# testFormat: The test format to use to interpret tests.
|
|
|
|
#
|
|
|
|
# For now we require '&&' between commands, until they get globally killed and
|
|
|
|
# the test runner updated.
|
2017-09-19 06:26:48 +08:00
|
|
|
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
|
2009-09-09 00:39:23 +08:00
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
# suffixes: A list of file extensions to treat as test files.
|
2020-03-21 04:41:29 +08:00
|
|
|
config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu',
|
2019-10-08 23:23:14 +08:00
|
|
|
'.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
|
2009-09-22 13:16:02 +08:00
|
|
|
|
2013-11-15 21:37:49 +08:00
|
|
|
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
|
|
|
|
# subdirectories contain auxiliary inputs for various tests in their parent
|
|
|
|
# directories.
|
2017-12-15 06:12:46 +08:00
|
|
|
config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests']
|
2013-11-15 21:37:49 +08:00
|
|
|
|
2009-09-22 13:16:02 +08:00
|
|
|
# test_source_root: The root path where tests are located.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# test_exec_root: The root path where tests should be run.
|
2017-09-16 06:10:46 +08:00
|
|
|
config.test_exec_root = os.path.join(config.clang_obj_root, 'test')
|
2009-09-22 13:16:02 +08:00
|
|
|
|
2017-10-18 07:43:36 +08:00
|
|
|
llvm_config.use_default_substitutions()
|
|
|
|
|
|
|
|
llvm_config.use_clang()
|
2009-09-26 15:36:09 +08:00
|
|
|
|
Fix some issues with LLDB's lit configuration files.
Recently I tried to port LLDB's lit configuration files over to use a
on the surface, but broke some cases that weren't broken before and also
exposed some additional problems with the old approach that we were just
getting lucky with.
When we set up a lit environment, the goal is to make it as hermetic as
possible. We should not be relying on PATH and enabling the use of
arbitrary shell commands. Instead, only whitelisted commands should be
allowed. These are, generally speaking, the lit builtins such as echo,
cd, etc, as well as anything for which substitutions have been
explicitly set up for. These substitutions should map to the build
output directory, but in some cases it's useful to be able to override
this (for example to point to an installed tools directory).
This is, of course, how it's supposed to work. What was actually
happening is that we were bringing in PATH and LD_LIBRARY_PATH and then
just running the given run line as a shell command. This led to problems
such as finding the wrong version of clang-cl on PATH since it wasn't
even a substitution, and flakiness / non-determinism since the
environment the tests were running in would change per-machine. On the
other hand, it also made other things possible. For example, we had some
tests that were explicitly running cl.exe and link.exe instead of
clang-cl and lld-link and the only reason it worked at all is because it
was finding them on PATH. Unfortunately we can't entirely get rid of
these tests, because they support a few things in debug info that
clang-cl and lld-link don't (notably, the LF_UDT_MOD_SRC_LINE record
which makes some of the tests fail.
The high level changes introduced in this patch are:
1. Removal of functionality - The lit test suite no longer respects
LLDB_TEST_C_COMPILER and LLDB_TEST_CXX_COMPILER. This means there is no
more support for gcc, but nobody was using this anyway (note: The
functionality is still there for the dotest suite, just not the lit test
suite). There is no longer a single substitution %cxx and %cc which maps
to <arbitrary-compiler>, you now explicitly specify the compiler with a
substitution like %clang or %clangxx or %clang_cl. We can revisit this
in the future when someone needs gcc.
2. Introduction of the LLDB_LIT_TOOLS_DIR directory. This does in spirit
what LLDB_TEST_C_COMPILER and LLDB_TEST_CXX_COMPILER used to do, but now
more friendly. If this is not specified, all tools are expected to be
the just-built tools. If it is specified, the tools which are not
themselves being tested but are being used to construct and run checks
(e.g. clang, FileCheck, llvm-mc, etc) will be searched for in this
directory first, then the build output directory.
3. Changes to core llvm lit files. The use_lld() and use_clang()
functions were introduced long ago in anticipation of using them in
lldb, but since they were never actually used anywhere but their
respective problems, there were some issues to be resolved regarding
generality and ability to use them outside their project.
4. Changes to .test files - These are all just replacing things like
clang-cl with %clang_cl and %cxx with %clangxx, etc.
5. Changes to lit.cfg.py - Previously we would load up some system
environment variables and then add some new things to them. Then do a
bunch of work building out our own substitutions. First, we delete the
system environment variable code, making the environment hermetic. Then,
we refactor the substitution logic into two separate helper functions,
one which sets up substitutions for the tools we want to test (which
must come from the build output directory), and another which sets up
substitutions for support tools (like compilers, etc).
6. New substitutions for MSVC -- Previously we relied on location of
MSVC by bringing in the entire parent's PATH and letting
subprocess.Popen just run the command line. Now we set up real
substitutions that should have the same effect. We use PATH to find
them, and then look for INCLUDE and LIB to construct a substitution
command line with appropriate /I and /LIBPATH: arguments. The nice thing
about this is that it opens the door to having separate %msvc-cl32 and
%msvc-cl64 substitutions, rather than only requiring the user to run
vcvars first. Because we can deduce the path to 32-bit libraries from
64-bit library directories, and vice versa. Without these substitutions
this would have been impossible.
Differential Revision: https://reviews.llvm.org/D54567
llvm-svn: 347216
2018-11-19 23:12:34 +08:00
|
|
|
config.substitutions.append(
|
|
|
|
('%src_include_dir', config.clang_src_dir + '/include'))
|
|
|
|
|
|
|
|
|
2013-04-04 15:41:20 +08:00
|
|
|
# Propagate path to symbolizer for ASan/MSan.
|
2017-10-07 01:54:27 +08:00
|
|
|
llvm_config.with_system_environment(
|
|
|
|
['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
|
2013-04-04 15:41:20 +08:00
|
|
|
|
2017-10-14 01:11:13 +08:00
|
|
|
config.substitutions.append(('%PATH%', config.environment['PATH']))
|
|
|
|
|
|
|
|
|
2017-10-18 07:43:36 +08:00
|
|
|
# For each occurrence of a clang tool name, replace it with the full path to
|
|
|
|
# the build directory holding that tool. We explicitly specify the directories
|
|
|
|
# to search to ensure that we get the tools just built and not some random
|
|
|
|
# tools that might happen to be in the user's PATH.
|
|
|
|
tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
|
2017-10-14 01:11:13 +08:00
|
|
|
|
|
|
|
tools = [
|
2019-10-08 23:23:14 +08:00
|
|
|
'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs',
|
2019-11-06 06:03:36 +08:00
|
|
|
ToolSubst('%clang_extdef_map', command=FindTool(
|
[analyzer][CrossTU][NFC] Generalize to external definitions instead of external functions
Summary: This is just changing naming and documentation to be general about external definitions that can be imported for cross translation unit analysis. There is at least a plan to add VarDecls: D46421
Reviewers: NoQ, xazax.hun, martong, a.sidorin, george.karpenkov, serge-sans-paille
Reviewed By: xazax.hun, martong
Subscribers: mgorny, whisperity, baloghadamsoftware, szepet, rnkovacs, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits
Differential Revision: https://reviews.llvm.org/D56441
llvm-svn: 350852
2019-01-11 01:44:04 +08:00
|
|
|
'clang-extdef-mapping'), unresolved='ignore'),
|
2017-10-18 07:43:36 +08:00
|
|
|
]
|
2017-10-14 01:11:13 +08:00
|
|
|
|
|
|
|
if config.clang_examples:
|
2018-05-09 02:20:10 +08:00
|
|
|
config.available_features.add('examples')
|
2017-10-14 01:11:13 +08:00
|
|
|
tools.append('clang-interpreter')
|
|
|
|
|
2019-05-03 03:47:05 +08:00
|
|
|
if config.clang_staticanalyzer:
|
|
|
|
config.available_features.add('staticanalyzer')
|
|
|
|
tools.append('clang-check')
|
|
|
|
|
|
|
|
if config.clang_staticanalyzer_z3 == '1':
|
|
|
|
config.available_features.add('z3')
|
|
|
|
|
2020-03-04 13:24:52 +08:00
|
|
|
check_analyzer_fixit_path = os.path.join(
|
|
|
|
config.test_source_root, "Analysis", "check-analyzer-fixit.py")
|
|
|
|
config.substitutions.append(
|
|
|
|
('%check_analyzer_fixit',
|
2020-03-04 23:22:31 +08:00
|
|
|
'"%s" %s' % (config.python_executable, check_analyzer_fixit_path)))
|
2019-05-03 03:47:05 +08:00
|
|
|
|
2017-10-14 01:11:13 +08:00
|
|
|
llvm_config.add_tool_substitutions(tools, tool_dirs)
|
|
|
|
|
2018-06-22 17:46:40 +08:00
|
|
|
config.substitutions.append(
|
2018-06-23 04:03:32 +08:00
|
|
|
('%hmaptool', "'%s' %s" % (config.python_executable,
|
2018-08-02 04:38:22 +08:00
|
|
|
os.path.join(config.clang_tools_dir, 'hmaptool'))))
|
2018-06-22 17:46:40 +08:00
|
|
|
|
2017-10-18 07:43:36 +08:00
|
|
|
# Plugins (loadable modules)
|
2019-05-17 14:07:37 +08:00
|
|
|
if config.has_plugins and config.llvm_plugin_ext:
|
2017-10-18 07:43:36 +08:00
|
|
|
config.available_features.add('plugins')
|
2017-10-14 01:11:13 +08:00
|
|
|
|
2010-08-25 05:39:55 +08:00
|
|
|
# Set available features we allow tests to conditionalize on.
|
2011-08-27 06:46:31 +08:00
|
|
|
#
|
2016-09-29 15:43:08 +08:00
|
|
|
if config.clang_default_cxx_stdlib != '':
|
|
|
|
config.available_features.add('default-cxx-stdlib-set')
|
|
|
|
|
2011-08-27 06:46:31 +08:00
|
|
|
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
|
|
|
|
if platform.system() not in ['FreeBSD']:
|
|
|
|
config.available_features.add('crash-recovery')
|
2011-02-28 17:41:07 +08:00
|
|
|
|
2019-06-20 01:41:30 +08:00
|
|
|
# Support for new pass manager.
|
|
|
|
if config.enable_experimental_new_pass_manager:
|
|
|
|
config.available_features.add('experimental-new-pass-manager')
|
|
|
|
|
2012-09-12 18:38:03 +08:00
|
|
|
# ANSI escape sequences in non-dumb terminal
|
2012-07-11 19:44:00 +08:00
|
|
|
if platform.system() not in ['Windows']:
|
|
|
|
config.available_features.add('ansi-escape-sequences')
|
|
|
|
|
2014-02-06 15:15:59 +08:00
|
|
|
# Capability to print utf8 to the terminal.
|
|
|
|
# Windows expects codepage, unless Wide API.
|
|
|
|
if platform.system() not in ['Windows']:
|
|
|
|
config.available_features.add('utf8-capable-terminal')
|
|
|
|
|
2016-10-10 20:23:40 +08:00
|
|
|
# Support for libgcc runtime. Used to rule out tests that require
|
|
|
|
# clang to run with -rtlib=libgcc.
|
|
|
|
if platform.system() not in ['Darwin', 'Fuchsia']:
|
|
|
|
config.available_features.add('libgcc')
|
|
|
|
|
2012-11-01 04:59:50 +08:00
|
|
|
# Case-insensitive file system
|
2017-10-18 07:43:36 +08:00
|
|
|
|
|
|
|
|
2012-11-01 04:59:50 +08:00
|
|
|
def is_filesystem_case_insensitive():
|
2017-10-07 01:54:27 +08:00
|
|
|
handle, path = tempfile.mkstemp(
|
|
|
|
prefix='case-test', dir=config.test_exec_root)
|
2013-07-01 17:51:55 +08:00
|
|
|
isInsensitive = os.path.exists(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(path),
|
|
|
|
os.path.basename(path).upper()
|
2017-10-07 01:54:27 +08:00
|
|
|
))
|
2012-11-01 04:59:50 +08:00
|
|
|
os.close(handle)
|
|
|
|
os.remove(path)
|
|
|
|
return isInsensitive
|
|
|
|
|
2017-10-07 01:54:27 +08:00
|
|
|
|
2012-11-01 04:59:50 +08:00
|
|
|
if is_filesystem_case_insensitive():
|
|
|
|
config.available_features.add('case-insensitive-filesystem')
|
|
|
|
|
2012-11-16 04:06:10 +08:00
|
|
|
# Tests that require the /dev/fd filesystem.
|
2017-10-07 01:54:27 +08:00
|
|
|
if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
|
2012-11-16 04:06:10 +08:00
|
|
|
config.available_features.add('dev-fd-fs')
|
|
|
|
|
2019-05-10 21:40:17 +08:00
|
|
|
# Set on native MS environment.
|
|
|
|
if re.match(r'.*-(windows-msvc)$', config.target_triple):
|
|
|
|
config.available_features.add('ms-sdk')
|
2015-01-31 02:25:59 +08:00
|
|
|
|
2012-09-12 18:45:40 +08:00
|
|
|
# [PR8833] LLP64-incompatible tests
|
2018-08-09 10:16:18 +08:00
|
|
|
if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple):
|
2012-09-12 18:45:40 +08:00
|
|
|
config.available_features.add('LP64')
|
|
|
|
|
2012-12-11 15:06:09 +08:00
|
|
|
# [PR12920] "clang-driver" -- set if gcc driver is not used.
|
2015-10-21 06:36:16 +08:00
|
|
|
if not re.match(r'.*-(cygwin)$', config.target_triple):
|
2012-12-11 15:06:09 +08:00
|
|
|
config.available_features.add('clang-driver')
|
|
|
|
|
2020-06-24 12:05:11 +08:00
|
|
|
# Tests that are specific to the Apple Silicon macOS.
|
|
|
|
if re.match(r'^arm64(e)?-apple-(macos|darwin)', config.target_triple):
|
|
|
|
config.available_features.add('apple-silicon-mac')
|
|
|
|
|
2014-02-16 18:15:34 +08:00
|
|
|
# [PR18856] Depends to remove opened file. On win32, a file could be removed
|
|
|
|
# only if all handles were closed.
|
|
|
|
if platform.system() not in ['Windows']:
|
|
|
|
config.available_features.add('can-remove-opened-file')
|
|
|
|
|
2017-10-07 01:54:27 +08:00
|
|
|
|
2017-09-19 06:26:48 +08:00
|
|
|
def calculate_arch_features(arch_string):
|
|
|
|
features = []
|
|
|
|
for arch in arch_string.split():
|
|
|
|
features.append(arch.lower() + '-registered-target')
|
|
|
|
return features
|
|
|
|
|
2017-10-07 01:54:27 +08:00
|
|
|
|
2017-09-19 06:26:48 +08:00
|
|
|
llvm_config.feature_config(
|
2017-10-07 01:54:27 +08:00
|
|
|
[('--assertion-mode', {'ON': 'asserts'}),
|
|
|
|
('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
|
2020-04-13 23:53:23 +08:00
|
|
|
('--targets-built', calculate_arch_features),
|
2017-10-07 01:54:27 +08:00
|
|
|
])
|
2012-08-08 01:54:38 +08:00
|
|
|
|
|
|
|
if lit.util.which('xmllint'):
|
|
|
|
config.available_features.add('xmllint')
|
|
|
|
|
2017-01-25 21:11:45 +08:00
|
|
|
if config.enable_backtrace:
|
2017-10-07 01:54:27 +08:00
|
|
|
config.available_features.add('backtrace')
|
2015-02-11 03:53:38 +08:00
|
|
|
|
Improve behavior in the case of stack exhaustion.
Summary:
Clang performs various recursive operations (such as template instantiation),
and may use non-trivial amounts of stack space in each recursive step (for
instance, due to recursive AST walks). While we try to keep the stack space
used by such steps to a minimum and we have explicit limits on the number of
such steps we perform, it's impractical to guarantee that we won't blow out the
stack on deeply recursive template instantiations on complex ASTs, even with
only a moderately high instantiation depth limit.
The user experience in these cases is generally terrible: we crash with
no hint of what went wrong. Under this patch, we attempt to do better:
* Detect when the stack is nearly exhausted, and produce a warning with a
nice template instantiation backtrace, telling the user that we might
run slowly or crash.
* For cases where we're forced to trigger recursive template
instantiation in arbitrarily-deeply-nested contexts, check whether
we're nearly out of stack space and allocate a new stack (by spawning
a new thread) after producing the warning.
Reviewers: rnk, aaron.ballman
Subscribers: mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66361
llvm-svn: 369940
2019-08-27 02:18:07 +08:00
|
|
|
if config.enable_threads:
|
|
|
|
config.available_features.add('thread_support')
|
|
|
|
|
2016-01-27 10:18:28 +08:00
|
|
|
# Check if we should allow outputs to console.
|
|
|
|
run_console_tests = int(lit_config.params.get('enable_console', '0'))
|
|
|
|
if run_console_tests != 0:
|
2017-10-07 01:54:27 +08:00
|
|
|
config.available_features.add('console')
|
2016-01-27 10:18:28 +08:00
|
|
|
|
2014-06-10 22:22:00 +08:00
|
|
|
lit.util.usePlatformSdkOnDarwin(config, lit_config)
|
2017-06-02 19:26:35 +08:00
|
|
|
macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
|
|
|
|
if macOSSDKVersion is not None:
|
2019-07-12 05:45:48 +08:00
|
|
|
config.available_features.add('macos-sdk-' + str(macOSSDKVersion))
|
2018-12-23 23:07:26 +08:00
|
|
|
|
|
|
|
if os.path.exists('/etc/gentoo-release'):
|
|
|
|
config.available_features.add('gentoo')
|
2019-06-16 04:09:54 +08:00
|
|
|
|
|
|
|
if config.enable_shared:
|
|
|
|
config.available_features.add("enable_shared")
|
2020-06-06 01:54:03 +08:00
|
|
|
|
|
|
|
# Add a vendor-specific feature.
|
|
|
|
if config.clang_vendor_uti:
|
|
|
|
config.available_features.add('clang-vendor=' + config.clang_vendor_uti)
|