[llvm] Add bazel targets for libc/include/... tests. (PR #141150)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 22 15:16:37 PDT 2025
https://github.com/jtstogel created https://github.com/llvm/llvm-project/pull/141150
This PR also sets `alwayslink=True` for `//libc/test:LibcUnitTest`. This ensures that the `main` function provided always gets linked into a test target. While not strictly necessary, it makes it so tests like https://github.com/llvm/llvm-project/blob/45d8759cbed0f216786729718608a8be72a505c6/libc/test/include/signbit_test.c will give a duplicate symbol error if they incorrectly depend on `//libc/test:LibcUnitTest`.
>From ea15c9eb6527edb56b766ea23b44ad8f6e3f5155 Mon Sep 17 00:00:00 2001
From: Jackson Stogel <jtstogel at google.com>
Date: Thu, 22 May 2025 22:12:40 +0000
Subject: [PATCH] Add bazel targets for libc/include/... tests.
Also, set `alwayslink=True` for `//libc/test:LibcUnitTest`. This ensures that the `main` function provided always gets linked into a test target. While not strictly necessary, it makes it so tests like https://github.com/llvm/llvm-project/blob/45d8759cbed0f216786729718608a8be72a505c6/libc/test/include/signbit_test.c will give a duplicate symbol error if they incorrectly depend on `LibcUnitTest`.
---
.../libc/test/UnitTest/BUILD.bazel | 1 +
.../libc/test/include/BUILD.bazel | 308 +++++++++++++++++-
.../libc/test/include/sys/BUILD.bazel | 21 ++
.../libc/test/libc_test_rules.bzl | 44 ++-
4 files changed, 356 insertions(+), 18 deletions(-)
create mode 100644 utils/bazel/llvm-project-overlay/libc/test/include/sys/BUILD.bazel
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index b37ec19330236..91820536d55f8 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -71,6 +71,7 @@ libc_test_library(
"//libc:llvm_libc_macros_stdfix_macros",
"//llvm:Support",
],
+ alwayslink = True,
)
libc_test_library(
diff --git a/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
index 51e8424282af0..0740b4c30334f 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
@@ -4,19 +4,315 @@
# Tests for LLVM libc public headers.
-load("//libc/test:libc_test_rules.bzl", "libc_test")
-
-package(default_visibility = ["//visibility:public"])
+load("//libc/test:libc_test_rules.bzl", "libc_c_test", "libc_test", "libc_test_library")
licenses(["notice"])
+libc_test(
+ name = "assert_test",
+ srcs = ["assert_test.cpp"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test(
+ name = "complex_test",
+ srcs = ["complex_test.cpp"],
+ deps = [
+ "//libc:public_headers_deps",
+ "//libc/test/UnitTest:fp_test_helpers",
+ ],
+)
+
+libc_test_library(
+ name = "fpclassify_test_fixture",
+ hdrs = ["FpClassifyTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "fpclassify_test",
+ srcs = ["fpclassify_test.cpp"],
+ deps = [
+ ":fpclassify_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "fpclassifyf_test",
+ srcs = ["fpclassifyf_test.cpp"],
+ deps = [
+ ":fpclassify_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "fpclassifyl_test",
+ srcs = ["fpclassifyl_test.cpp"],
+ deps = [
+ ":fpclassify_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "fpclassify_c_test",
+ srcs = ["fpclassify_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "isfinite_test_ficture",
+ hdrs = ["IsFiniteTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "isfinite_test",
+ srcs = ["isfinite_test.cpp"],
+ deps = [
+ ":isfinite_test_ficture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isfinitef_test",
+ srcs = ["isfinitef_test.cpp"],
+ deps = [
+ ":isfinite_test_ficture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isfinitel_test",
+ srcs = ["isfinitel_test.cpp"],
+ deps = [
+ ":isfinite_test_ficture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "isfinite_c_test",
+ srcs = ["isfinite_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "isinf_test_fixture",
+ hdrs = ["IsInfTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "isinf_test",
+ srcs = ["isinf_test.cpp"],
+ deps = [
+ ":isinf_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isinff_test",
+ srcs = ["isinff_test.cpp"],
+ deps = [
+ ":isinf_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isinfl_test",
+ srcs = ["isinfl_test.cpp"],
+ deps = [
+ ":isinf_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "isinf_c_test",
+ srcs = ["isinf_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "isnan_test_fixture",
+ hdrs = ["IsNanTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "isnan_test",
+ srcs = ["isnan_test.cpp"],
+ deps = [
+ ":isnan_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isnanf_test",
+ srcs = ["isnanf_test.cpp"],
+ deps = [
+ ":isnan_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isnanl_test",
+ srcs = ["isnanl_test.cpp"],
+ deps = [
+ ":isnan_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "isnan_c_test",
+ srcs = ["isnan_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "isnormal_test_fixture",
+ hdrs = ["IsNormalTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "isnormal_test",
+ srcs = ["isnormal_test.cpp"],
+ deps = [
+ ":isnormal_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isnormalf_test",
+ srcs = ["isnormalf_test.cpp"],
+ deps = [
+ ":isnormal_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "isnormall_test",
+ srcs = ["isnormall_test.cpp"],
+ deps = [
+ ":isnormal_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "isnormal_c_test",
+ srcs = ["isnormal_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_c_test(
+ name = "issubnormal_c_test",
+ srcs = ["issubnormal_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "iszero_test_fixture",
+ hdrs = ["IsZeroTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "iszero_test",
+ srcs = ["iszero_test.cpp"],
+ deps = [
+ ":iszero_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "iszerof_test",
+ srcs = ["iszerof_test.cpp"],
+ deps = [
+ ":iszero_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "iszerol_test",
+ srcs = ["iszerol_test.cpp"],
+ deps = [
+ ":iszero_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_c_test(
+ name = "iszero_c_test",
+ srcs = ["iszero_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test_library(
+ name = "signbit_test_fixture",
+ hdrs = ["SignbitTest.h"],
+ deps = ["//libc/test/UnitTest:fp_test_helpers"],
+)
+
+libc_test(
+ name = "signbit_test",
+ srcs = ["signbit_test.cpp"],
+ deps = [
+ ":signbit_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "signbitf_test",
+ srcs = ["signbitf_test.cpp"],
+ deps = [
+ ":signbit_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
+libc_test(
+ name = "signbitl_test",
+ srcs = ["signbitl_test.cpp"],
+ deps = [
+ ":signbit_test_fixture",
+ "//libc:public_headers_deps",
+ ],
+)
+
libc_test(
name = "stdbit_test",
srcs = [
"stdbit_stub.h",
"stdbit_test.cpp",
],
- deps = [
- "//libc:public_headers_deps",
- ],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_c_test(
+ name = "signbit_c_test",
+ srcs = ["signbit_test.c"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test(
+ name = "stdckdint_test",
+ srcs = ["stdckdint_test.cpp"],
+ deps = ["//libc:public_headers_deps"],
)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/include/sys/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/include/sys/BUILD.bazel
new file mode 100644
index 0000000000000..2ad56b00e8686
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libc/test/include/sys/BUILD.bazel
@@ -0,0 +1,21 @@
+# This file is licensed 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
+
+# Tests for LLVM libc public headers.
+
+load("//libc/test:libc_test_rules.bzl", "libc_test")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+libc_test(
+ name = "queue_test",
+ srcs = ["queue_test.cpp"],
+ deps = [
+ "//libc:__support_char_vector",
+ "//libc:__support_cpp_string",
+ "//libc:public_headers_deps",
+ ],
+)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index 123e05727aeff..60933fcffcf8c 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -12,10 +12,18 @@ They come in two flavors:
When performing tests we make sure to always use the internal version.
"""
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("//libc:libc_build_rules.bzl", "libc_common_copts")
load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
-def libc_test(name, copts = [], deps = [], local_defines = [], **kwargs):
+def _libc_test(
+ name,
+ copts = [],
+ deps = [],
+ local_defines = [],
+ use_test_framework = True,
+ **kwargs):
"""Add target for a libc test.
Args:
@@ -23,25 +31,37 @@ def libc_test(name, copts = [], deps = [], local_defines = [], **kwargs):
copts: The list of options to add to the C++ compilation command.
deps: The list of libc functions and libraries to be linked in.
local_defines: The list of target local_defines if any.
+ use_test_framework: Whether the unit test has a custom `main` function.
**kwargs: Attributes relevant for a cc_test.
"""
- native.cc_test(
+ deps = deps + [
+ "//libc:__support_macros_config",
+ "//libc:errno",
+ "//libc:func_aligned_alloc",
+ "//libc:func_free",
+ "//libc:func_malloc",
+ "//libc:func_realloc",
+ ]
+ if use_test_framework:
+ deps = deps + ["//libc/test/UnitTest:LibcUnitTest"]
+
+ cc_test(
name = name,
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
- deps = [
- "//libc/test/UnitTest:LibcUnitTest",
- "//libc:__support_macros_config",
- "//libc:errno",
- "//libc:func_aligned_alloc",
- "//libc:func_free",
- "//libc:func_malloc",
- "//libc:func_realloc",
- ] + deps,
+ deps = deps,
copts = copts + libc_common_copts(),
linkstatic = 1,
**kwargs
)
+def libc_test(name, **kwargs):
+ """Add a target for a libc configured for libc."""
+ _libc_test(name, **kwargs)
+
+def libc_c_test(name, **kwargs):
+ """Add a target for a libc test in C that does not use a test framework."""
+ _libc_test(name, use_test_framework = False, **kwargs)
+
def libc_test_library(name, copts = [], local_defines = [], **kwargs):
"""Add target for library used in libc tests.
@@ -51,7 +71,7 @@ def libc_test_library(name, copts = [], local_defines = [], **kwargs):
local_defines: See cc_library.local_defines.
**kwargs: Other attributes relevant to cc_library (e.g. "deps").
"""
- native.cc_library(
+ cc_library(
name = name,
testonly = True,
copts = copts + libc_common_copts(),
More information about the llvm-commits
mailing list