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.
|
2017-10-07 01:54:27 +08:00
|
|
|
config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
|
|
|
|
'.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs']
|
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 = [
|
2018-05-19 11:12:04 +08:00
|
|
|
'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen',
|
2018-06-22 17:46:40 +08:00
|
|
|
'opt',
|
[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
|
|
|
ToolSubst('%clang_extdef_map', command=FindTool(
|
|
|
|
'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')
|
|
|
|
|
|
|
|
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)
|
|
|
|
# TODO: This should be supplied by Makefile or autoconf.
|
|
|
|
if sys.platform in ['win32', 'cygwin']:
|
|
|
|
has_plugins = config.enable_shared
|
2017-10-14 01:11:13 +08:00
|
|
|
else:
|
2017-10-18 07:43:36 +08:00
|
|
|
has_plugins = True
|
2017-10-14 01:11:13 +08:00
|
|
|
|
2017-10-18 07:43:36 +08:00
|
|
|
if has_plugins and config.llvm_plugin_ext:
|
|
|
|
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')
|
|
|
|
|
2014-07-16 20:05:45 +08:00
|
|
|
# Enabled/disabled features
|
2017-01-25 21:11:45 +08:00
|
|
|
if config.clang_staticanalyzer:
|
2017-10-07 01:54:27 +08:00
|
|
|
config.available_features.add('staticanalyzer')
|
2014-07-16 20:05:45 +08:00
|
|
|
|
2017-04-05 03:52:25 +08:00
|
|
|
if config.clang_staticanalyzer_z3 == '1':
|
2017-10-07 01:54:27 +08:00
|
|
|
config.available_features.add('z3')
|
2017-04-05 03:52:25 +08:00
|
|
|
|
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
|
|
|
|
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')
|
|
|
|
|
2014-02-16 18:15:57 +08:00
|
|
|
# Not set on native MS environment.
|
2018-08-09 10:16:18 +08:00
|
|
|
if not re.match(r'.*-(windows-msvc)$', config.target_triple):
|
2014-02-16 18:15:57 +08:00
|
|
|
config.available_features.add('non-ms-sdk')
|
|
|
|
|
2015-01-31 02:25:59 +08:00
|
|
|
# Not set on native PS4 environment.
|
2015-02-03 07:17:54 +08:00
|
|
|
if not re.match(r'.*-scei-ps4', config.target_triple):
|
2015-01-31 02:25:59 +08:00
|
|
|
config.available_features.add('non-ps4-sdk')
|
|
|
|
|
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')
|
|
|
|
|
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'}),
|
|
|
|
('--targets-built', calculate_arch_features)
|
|
|
|
])
|
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
|
|
|
|
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:
|
|
|
|
config.available_features.add('macos-sdk-' + macOSSDKVersion)
|
2018-12-23 23:07:26 +08:00
|
|
|
|
|
|
|
if os.path.exists('/etc/gentoo-release'):
|
|
|
|
config.available_features.add('gentoo')
|