Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
920 changes: 0 additions & 920 deletions libcxx/utils/libcxx/test/features.py

This file was deleted.

21 changes: 21 additions & 0 deletions libcxx/utils/libcxx/test/features/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##

from . import availability, compiler, gdb, libcxx_macros, localization, misc, platform

# Lit features are evaluated in order. Some features depend on other features, so
# we are careful to define them in the correct order. For example, several features
# require the compiler detection to have been performed.
DEFAULT_FEATURES = []
DEFAULT_FEATURES += compiler.features
DEFAULT_FEATURES += libcxx_macros.features
DEFAULT_FEATURES += platform.features
DEFAULT_FEATURES += localization.features
DEFAULT_FEATURES += gdb.features
DEFAULT_FEATURES += misc.features
DEFAULT_FEATURES += availability.features
199 changes: 199 additions & 0 deletions libcxx/utils/libcxx/test/features/availability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# ===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##

from libcxx.test.dsl import Feature
from lit.BooleanExpression import BooleanExpression

# Helpers to define correspondances between LLVM versions and vendor system versions.
# Those are used for backdeployment features below, do not use directly in tests.
features = [
Feature(
name="_target-has-llvm-22",
when=lambda cfg: BooleanExpression.evaluate(
"TBD",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-21",
when=lambda cfg: BooleanExpression.evaluate(
"TBD",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-20",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-21 || target={{.+}}-apple-macosx{{26.[0-9](.\d+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-19",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-20 || target={{.+}}-apple-macosx{{15.[4-9](.\d+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-18",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-19 || target={{.+}}-apple-macosx{{15.[0-3](.\d+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-17",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-18 || target={{.+}}-apple-macosx{{14.[4-9](.\d+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-16",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-17 || target={{.+}}-apple-macosx{{14.[0-3](.[0-9]+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-15",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-16 || target={{.+}}-apple-macosx{{13.[4-9](.[0-9]+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-14",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-15",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-13",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-14 || target={{.+}}-apple-macosx{{13.[0-3](.[0-9]+)?}}",
cfg.available_features,
),
),
Feature(
name="_target-has-llvm-12",
when=lambda cfg: BooleanExpression.evaluate(
"_target-has-llvm-13 || target={{.+}}-apple-macosx{{12.[3-9](.[0-9]+)?}}",
cfg.available_features,
),
),
]

# Define features for back-deployment testing.
#
# These features can be used to XFAIL tests that fail when deployed on (or compiled
# for) an older system. For example, if a test exhibits a bug in the libc++ on a
# particular system version, or if it uses a symbol that is not available on an
# older version of the dylib, it can be marked as XFAIL with these features.
#
# We have two families of Lit features:
#
# The first one is `using-built-library-before-llvm-XYZ`. These features encode the
# fact that the test suite is being *run* against a version of the shared/static library
# that predates LLVM version XYZ. This is useful to represent the use case of compiling
# a program against the latest libc++ but then deploying it and running it on an older
# system with an older version of the (usually shared) library.
#
# This feature is built up using the target triple passed to the compiler and the
# `stdlib=system` Lit feature, which encodes that we're running against the same library
# as described by the target triple.
#
# The second set of features is `availability-<FEATURE>-missing`. This family of Lit
# features encodes the presence of availability markup in the libc++ headers. This is
# useful to check that a test fails specifically when compiled for a given deployment
# target, such as when testing availability markup where we want to make sure that
# using the annotated facility on a deployment target that doesn't support it will fail
# at compile time. This can be achieved by creating a `.verify.cpp` test that checks for
# the right errors and marking the test as `REQUIRES: availability-<FEATURE>-missing`.
#
# This feature is built up using the presence of availability markup detected inside
# __config, the flavor of the library being tested and the target triple passed to the
# compiler.
#
# Note that both families of Lit features are similar but different in important ways.
# For example, tests for availability markup should be expected to produce diagnostics
# regardless of whether we're running against a system library, as long as we're using
# a libc++ flavor that enables availability markup. Similarly, a test could fail when
# run against the system library of an older version of FreeBSD, even though FreeBSD
# doesn't provide availability markup at the time of writing this.
for version in ("12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"):
features.append(
Feature(
name="using-built-library-before-llvm-{}".format(version),
when=lambda cfg, v=version: BooleanExpression.evaluate(
"stdlib=system && !_target-has-llvm-{}".format(v),
cfg.available_features,
),
)
)

features += [
# Tests that require https://wg21.link/P0482 support in the built library
Feature(
name="availability-char8_t_support-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-12)",
cfg.available_features,
),
),
# Tests that require std::to_chars(floating-point) in the built library
Feature(
name="availability-fp_to_chars-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-14)",
cfg.available_features,
),
),
# Tests that require __libcpp_verbose_abort support in the built library
Feature(
name="availability-verbose_abort-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-15)",
cfg.available_features,
),
),
# Tests that require std::pmr support in the built library
Feature(
name="availability-pmr-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-16)",
cfg.available_features,
),
),
# Tests that require support for <print> and std::print in <ostream> in the built library.
Feature(
name="availability-print-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-18)",
cfg.available_features,
),
),
# Tests that require time zone database support in the built library
Feature(
name="availability-tzdb-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-19)",
cfg.available_features,
),
),
# Tests that require std::from_chars(floating-point) in the built library
Feature(
name="availability-fp_from_chars-missing",
when=lambda cfg: BooleanExpression.evaluate(
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-20)",
cfg.available_features,
),
),
]
82 changes: 82 additions & 0 deletions libcxx/utils/libcxx/test/features/compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# ===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##

from libcxx.test.dsl import compilerMacros, Feature, AddCompileFlag, AddFeature

_isAnyClang = lambda cfg: "__clang__" in compilerMacros(cfg)
_isAppleClang = lambda cfg: "__apple_build_version__" in compilerMacros(cfg)
_isAnyGCC = lambda cfg: "__GNUC__" in compilerMacros(cfg)
_isClang = lambda cfg: _isAnyClang(cfg) and not _isAppleClang(cfg)
_isGCC = lambda cfg: _isAnyGCC(cfg) and not _isAnyClang(cfg)
_isAnyClangOrGCC = lambda cfg: _isAnyClang(cfg) or _isAnyGCC(cfg)
_isClExe = lambda cfg: not _isAnyClangOrGCC(cfg)
_isMSVC = lambda cfg: "_MSC_VER" in compilerMacros(cfg)
_msvcVersion = lambda cfg: (int(compilerMacros(cfg)["_MSC_VER"]) // 100, int(compilerMacros(cfg)["_MSC_VER"]) % 100)

features = [
# gcc-style-warnings detects compilers that understand -Wno-meow flags, unlike MSVC's compiler driver cl.exe.
Feature(name="gcc-style-warnings", when=_isAnyClangOrGCC),
Feature(name="cl-style-warnings", when=_isClExe),

Feature(name="apple-clang", when=_isAppleClang),
Feature(
name=lambda cfg: "apple-clang-{__clang_major__}".format(**compilerMacros(cfg)),
when=_isAppleClang,
),
Feature(
name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}".format(**compilerMacros(cfg)),
when=_isAppleClang,
),
Feature(
name=lambda cfg: "apple-clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(**compilerMacros(cfg)),
when=_isAppleClang,
),
Feature(name="clang", when=_isClang),
Feature(
name=lambda cfg: "clang-{__clang_major__}".format(**compilerMacros(cfg)),
when=_isClang,
),
Feature(
name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}".format(**compilerMacros(cfg)),
when=_isClang,
),
Feature(
name=lambda cfg: "clang-{__clang_major__}.{__clang_minor__}.{__clang_patchlevel__}".format(**compilerMacros(cfg)),
when=_isClang,
),
# Note: Due to a GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104760), we must disable deprecation warnings
# on GCC or spurious diagnostics are issued.
#
# TODO:
# - Enable -Wplacement-new with GCC.
# - Enable -Wclass-memaccess with GCC.
Feature(
name="gcc",
when=_isGCC,
actions=[
AddCompileFlag("-D_LIBCPP_DISABLE_DEPRECATION_WARNINGS"),
AddCompileFlag("-Wno-placement-new"),
AddCompileFlag("-Wno-class-memaccess"),
AddFeature("GCC-ALWAYS_INLINE-FIXME"),
],
),
Feature(
name=lambda cfg: "gcc-{__GNUC__}".format(**compilerMacros(cfg)), when=_isGCC
),
Feature(
name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}".format(**compilerMacros(cfg)),
when=_isGCC,
),
Feature(
name=lambda cfg: "gcc-{__GNUC__}.{__GNUC_MINOR__}.{__GNUC_PATCHLEVEL__}".format(**compilerMacros(cfg)),
when=_isGCC,
),
Feature(name="msvc", when=_isMSVC),
Feature(name=lambda cfg: "msvc-{}".format(*_msvcVersion(cfg)), when=_isMSVC),
Feature(name=lambda cfg: "msvc-{}.{}".format(*_msvcVersion(cfg)), when=_isMSVC),
]
50 changes: 50 additions & 0 deletions libcxx/utils/libcxx/test/features/gdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##

from libcxx.test.dsl import Feature, AddSubstitution
import shutil
import subprocess

# Detect whether GDB is on the system, has Python scripting and supports
# adding breakpoint commands. If so add a substitution to access it.
def check_gdb(cfg):
gdb_path = shutil.which("gdb")
if gdb_path is None:
return False

# Check that we can set breakpoint commands, which was added in 8.3.
# Using the quit command here means that gdb itself exits, not just
# the "python <...>" command.
test_src = """\
try:
gdb.Breakpoint(\"main\").commands=\"foo\"
except AttributeError:
gdb.execute(\"quit 1\")
gdb.execute(\"quit\")"""

try:
stdout = subprocess.check_output(
[gdb_path, "-ex", "python " + test_src, "--batch"],
stderr=subprocess.DEVNULL,
universal_newlines=True,
)
except subprocess.CalledProcessError:
# We can't set breakpoint commands
return False

# Check we actually ran the Python
return not "Python scripting is not supported" in stdout


features = [
Feature(
name="host-has-gdb-with-python",
when=check_gdb,
actions=[AddSubstitution("%{gdb}", lambda cfg: shutil.which("gdb"))],
)
]
Loading
Loading