[llvm] [libc][bazel] Add bazel targets for libc/include/... tests. (PR #141150)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 11:06:30 PDT 2025
https://github.com/jtstogel updated https://github.com/llvm/llvm-project/pull/141150
>From b53f71b5b69628fb7b95692991f866c0897714bc 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 | 3 +
.../libc/test/include/BUILD.bazel | 318 +++++++++++++++++-
.../libc/test/libc_test_rules.bzl | 30 +-
3 files changed, 340 insertions(+), 11 deletions(-)
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..31a3c4b09b37f 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,9 @@ libc_test_library(
"//libc:llvm_libc_macros_stdfix_macros",
"//llvm:Support",
],
+ # Force linking in this library's `main()` to surface
+ # a duplicate symbol error if a test defines its own main.
+ 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..5fc646ce23cab 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,335 @@
# Tests for LLVM libc public headers.
-load("//libc/test:libc_test_rules.bzl", "libc_test")
+load("//libc/test:libc_test_rules.bzl", "libc_test", "libc_test_library")
package(default_visibility = ["//visibility:public"])
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_test(
+ name = "fpclassify_c_test",
+ srcs = ["fpclassify_test.c"],
+ use_test_framework = False,
+ 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_test(
+ name = "isfinite_c_test",
+ srcs = ["isfinite_test.c"],
+ use_test_framework = False,
+ 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_test(
+ name = "isinf_c_test",
+ srcs = ["isinf_test.c"],
+ use_test_framework = False,
+ 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_test(
+ name = "isnan_c_test",
+ srcs = ["isnan_test.c"],
+ use_test_framework = False,
+ 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_test(
+ name = "isnormal_c_test",
+ srcs = ["isnormal_test.c"],
+ use_test_framework = False,
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test(
+ name = "issubnormal_c_test",
+ srcs = ["issubnormal_test.c"],
+ use_test_framework = False,
+ 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_test(
+ name = "iszero_c_test",
+ srcs = ["iszero_test.c"],
+ use_test_framework = False,
+ 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"],
+)
+
+libc_test(
+ name = "signbit_c_test",
+ srcs = ["signbit_test.c"],
+ use_test_framework = False,
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test(
+ name = "stdckdint_test",
+ srcs = ["stdckdint_test.cpp"],
+ deps = ["//libc:public_headers_deps"],
+)
+
+libc_test(
+ name = "sys_queue_test",
+ srcs = ["sys/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..bc2f61f4ac145 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
@@ -15,7 +15,13 @@ When performing tests we make sure to always use the internal version.
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,20 +29,24 @@ 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 to use the libc unit test `main` function.
**kwargs: Attributes relevant for a 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"]
+
native.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
More information about the llvm-commits
mailing list