[libc++] Allow specifying custom Lit config files
Before this patch, the libc++ test suite first loads lit.site.cfg (generated by CMake), and then lit.cfg. It's also possible to load lit.cfg before lit.site.cfg and to point to a custom lit.site.cfg file using '--param=libcxx_site_config'. However, in that case, lit.cfg still relies on the site configuration filling up the 'config' object like the default lit.site.cfg file does, which isn't flexible enough. This commit simplifies the setup by having just a single Lit site config file per CMake configuration, and always loading exactly that config file. However, the config file to use can be selected when setting up CMake via the LIBCXX_TEST_CONFIG setting. Furthermore, the site configs are entirely standalone, which means that a new site config can be added that doesn't need to conform what's expected by config.py. Differential Revision: https://reviews.llvm.org/D81846
This commit is contained in:
parent
7622ea5835
commit
0c66af970c
|
@ -109,6 +109,8 @@ option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ lib
|
|||
option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
|
||||
option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
|
||||
option(LIBCXX_TEST_GDB_PRETTY_PRINTERS "Test gdb pretty printers." OFF)
|
||||
set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
|
||||
"The Lit testing configuration to use when running the tests")
|
||||
|
||||
# Benchmark options -----------------------------------------------------------
|
||||
option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
|
||||
|
|
|
@ -77,22 +77,18 @@ the current CMake configuration. It does so by generating a ``lit.site.cfg``
|
|||
file in the build directory from the ``libcxx/test/lit.site.cfg.in`` template,
|
||||
and pointing ``llvm-lit`` (which is a wrapper around ``llvm/utils/lit/lit.py``)
|
||||
to that file. So when you're running ``<build>/bin/llvm-lit``, the generated
|
||||
``lit.site.cfg`` file is always loaded first, followed by the actual config in
|
||||
``libcxx/test/lit.cfg``. However, it is sometimes desirable to use a custom
|
||||
site configuration. To do that, you can use ``--param=libcxx_site_config`` or
|
||||
the ``LIBCXX_SITE_CONFIG`` environment variable to point to the right site
|
||||
configuration file. However, you must stop using ``llvm-lit``, or else the
|
||||
generated ``lit.site.cfg`` will still be preferred:
|
||||
``lit.site.cfg`` file is always loaded instead of ``libcxx/test/lit.cfg.py``.
|
||||
If you want to use a custom site configuration, simply point the CMake build
|
||||
to it using ``-DLIBCXX_TEST_CONFIG=<path-to-site-config>``, and that site
|
||||
configuration will be used instead. That file can use CMake variables inside
|
||||
itself to make configuration easier.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ LIBCXX_SITE_CONFIG=path/to/your/site/configuration llvm/utils/lit/lit.py -sv ...
|
||||
$ cmake <options> -DLIBCXX_TEST_CONFIG=<path-to-site-config>
|
||||
$ make -C <build> check-cxx-deps
|
||||
$ <build>/bin/llvm-lit -sv libcxx/test # will use your custom config file
|
||||
|
||||
$ llvm/utils/lit/lit.py -sv ... --param=libcxx_site_config=path/to/your/site/configuration
|
||||
|
||||
In both of these cases, your custom site configuration should set up the
|
||||
``config`` object in a way that is compatible with what libc++'s ``config.py``
|
||||
module expects.
|
||||
|
||||
LIT Options
|
||||
===========
|
||||
|
@ -127,11 +123,6 @@ default.
|
|||
|
||||
Change the standard version used when building the tests.
|
||||
|
||||
.. option:: libcxx_site_config=<path/to/lit.site.cfg>
|
||||
|
||||
Specify the site configuration to use when running the tests. This option
|
||||
overrides the environment variable LIBCXX_SITE_CONFIG.
|
||||
|
||||
.. option:: cxx_headers=<path/to/headers>
|
||||
|
||||
Specify the c++ standard library headers that are tested. By default the
|
||||
|
@ -199,14 +190,6 @@ default.
|
|||
Path to the builtins library to use instead of libgcc.
|
||||
|
||||
|
||||
Environment Variables
|
||||
---------------------
|
||||
|
||||
.. envvar:: LIBCXX_SITE_CONFIG=<path/to/lit.site.cfg>
|
||||
|
||||
Specify the site configuration to use when running the tests.
|
||||
Also see `libcxx_site_config`.
|
||||
|
||||
Writing Tests
|
||||
-------------
|
||||
|
||||
|
|
|
@ -103,11 +103,12 @@ if(LIBCXX_TEST_GDB_PRETTY_PRINTERS)
|
|||
endif()
|
||||
|
||||
if (LIBCXX_INCLUDE_TESTS)
|
||||
include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuit
|
||||
include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
|
||||
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
|
||||
"${LIBCXX_TEST_CONFIG}"
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
|
||||
MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py")
|
||||
|
||||
add_custom_target(check-cxx-deps
|
||||
DEPENDS cxx ${LIBCXX_TEST_DEPS}
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
|
||||
# Configuration file for the 'lit' test runner.
|
||||
import os
|
||||
import site
|
||||
|
||||
site.addsitedir(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'utils'))
|
||||
|
||||
|
||||
# Tell pylint that we know config and lit_config exist somewhere.
|
||||
if 'PYLINT_IMPORT' in os.environ:
|
||||
config = object()
|
||||
lit_config = object()
|
||||
|
||||
# name: The name of this test suite.
|
||||
config.name = 'libc++'
|
||||
|
||||
# suffixes: A list of file extensions to treat as test files.
|
||||
config.suffixes = ['.pass.cpp', '.fail.cpp', '.sh.cpp', '.pass.mm']
|
||||
|
||||
# test_source_root: The root path where tests are located.
|
||||
config.test_source_root = os.path.dirname(__file__)
|
||||
|
||||
# Allow expanding substitutions that are based on other substitutions
|
||||
config.recursiveExpansionLimit = 10
|
||||
|
||||
loaded_site_cfg = getattr(config, 'loaded_site_config', False)
|
||||
if not loaded_site_cfg:
|
||||
import libcxx.test.config
|
||||
libcxx.test.config.loadSiteConfig(lit_config, config, 'libcxx_site_config',
|
||||
'LIBCXX_SITE_CONFIG')
|
||||
|
||||
# Infer the test_exec_root from the libcxx_object root.
|
||||
obj_root = getattr(config, 'libcxx_obj_root', None)
|
||||
|
||||
# Check that the test exec root is known.
|
||||
if obj_root is None:
|
||||
obj_root = getattr(config, 'libcxx_obj_root', None)
|
||||
if obj_root is None:
|
||||
import tempfile
|
||||
obj_root = tempfile.mkdtemp(prefix='libcxx-testsuite-')
|
||||
lit_config.warning('Creating temporary directory for object root: %s' %
|
||||
obj_root)
|
||||
|
||||
if not config.test_exec_root:
|
||||
config.test_exec_root = os.path.join(obj_root, 'test')
|
||||
|
||||
cfg_variant = getattr(config, 'configuration_variant', 'libcxx')
|
||||
if cfg_variant:
|
||||
lit_config.note('Using configuration variant: %s' % cfg_variant)
|
||||
|
||||
# Load the Configuration class from the module name <cfg_variant>.test.config.
|
||||
config_module_name = '.'.join([cfg_variant, 'test', 'config'])
|
||||
config_module = __import__(config_module_name, fromlist=['Configuration'])
|
||||
|
||||
configuration = config_module.Configuration(lit_config, config)
|
||||
configuration.configure()
|
||||
configuration.print_config_info()
|
||||
if lit_config.params.get('use_old_format', False):
|
||||
lit_config.note("Using the old libc++ testing format")
|
||||
config.test_format = configuration.get_test_format()
|
||||
else:
|
||||
lit_config.note("Using the new libc++ testing format")
|
||||
import libcxx.test.newformat
|
||||
config.test_format = libcxx.test.newformat.CxxStandardLibraryTest()
|
10
libcxx/test/lit.cfg.py
Normal file
10
libcxx/test/lit.cfg.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
# All the Lit configuration is handled in the site configs -- this file is only
|
||||
# left as a canary to catch invocations of Lit that do not go through llvm-lit.
|
||||
#
|
||||
# Invocations that go through llvm-lit will automatically use the right Lit
|
||||
# site configuration inside the build directory.
|
||||
|
||||
lit_config.fatal(
|
||||
"You seem to be running Lit directly -- you should be running Lit through "
|
||||
"<build>/bin/llvm-lit, which will ensure that the right Lit configuration "
|
||||
"file is used.")
|
|
@ -1,4 +1,8 @@
|
|||
@AUTO_GEN_COMMENT@
|
||||
|
||||
import os
|
||||
import site
|
||||
|
||||
config.cxx_under_test = "@LIBCXX_COMPILER@"
|
||||
config.project_obj_root = "@CMAKE_BINARY_DIR@"
|
||||
config.libcxx_src_root = "@LIBCXX_SOURCE_DIR@"
|
||||
|
@ -39,6 +43,32 @@ config.libcxx_gdb = "@LIBCXX_GDB@"
|
|||
# Code signing
|
||||
config.llvm_codesign_identity = "@LLVM_CODESIGNING_IDENTITY@"
|
||||
|
||||
# Let the main config do the real work.
|
||||
config.loaded_site_config = True
|
||||
lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")
|
||||
site.addsitedir(os.path.join(config.libcxx_src_root, 'utils'))
|
||||
|
||||
# name: The name of this test suite.
|
||||
config.name = 'libc++'
|
||||
|
||||
# suffixes: A list of file extensions to treat as test files.
|
||||
config.suffixes = ['.pass.cpp', '.fail.cpp', '.sh.cpp', '.pass.mm']
|
||||
|
||||
# test_source_root: The root path where tests are located.
|
||||
config.test_source_root = os.path.join(config.libcxx_src_root, 'test')
|
||||
|
||||
# Allow expanding substitutions that are based on other substitutions
|
||||
config.recursiveExpansionLimit = 10
|
||||
|
||||
# Infer the test_exec_root from the libcxx_object root.
|
||||
config.test_exec_root = os.path.join(config.libcxx_obj_root, 'test')
|
||||
|
||||
lit_config.note('Using configuration variant: {}'.format(config.configuration_variant))
|
||||
import libcxx.test.config
|
||||
configuration = libcxx.test.config.Configuration(lit_config, config)
|
||||
configuration.configure()
|
||||
configuration.print_config_info()
|
||||
if lit_config.params.get('use_old_format', False):
|
||||
lit_config.note("Using the old libc++ testing format")
|
||||
config.test_format = configuration.get_test_format()
|
||||
else:
|
||||
lit_config.note("Using the new libc++ testing format")
|
||||
import libcxx.test.newformat
|
||||
config.test_format = libcxx.test.newformat.CxxStandardLibraryTest()
|
||||
|
|
Loading…
Reference in a new issue