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.
|
|
|
|
config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
|
|
|
|
|
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
|
|
|
|
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 = [
|
2017-10-18 07:43:36 +08:00
|
|
|
'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt',
|
2017-11-21 09:20:28 +08:00
|
|
|
ToolSubst('%test_debuginfo', command=os.path.join(
|
|
|
|
config.llvm_src_root, 'utils', 'test_debuginfo.pl')),
|
2017-10-18 07:43:36 +08:00
|
|
|
ToolSubst('%clang_func_map', command=FindTool(
|
|
|
|
'clang-func-mapping'), unresolved='ignore'),
|
|
|
|
]
|
2017-10-14 01:11:13 +08:00
|
|
|
|
|
|
|
if config.clang_examples:
|
|
|
|
tools.append('clang-interpreter')
|
|
|
|
|
|
|
|
llvm_config.add_tool_substitutions(tools, tool_dirs)
|
|
|
|
|
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.
|
|
|
|
if not re.match(r'.*-win32$', config.target_triple):
|
|
|
|
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
|
2014-12-17 17:55:15 +08:00
|
|
|
if not re.match(r'^x86_64.*-(win32|mingw32|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)
|