[libc-commits] [libc] [libc][cmake] Make hermetic tests support C_TEST and FLAGS (PR #212460)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Wed Jul 29 01:38:35 PDT 2026
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/212460
>From b7eafaa0f65082f468f2206559248276bc875fc7 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 28 Jul 2026 07:59:35 +0000
Subject: [PATCH 1/2] [libc][cmake] Make hermetic tests support C_TEST and
FLAGS
Currently the tests skip themselves because this gets treated as a
(missing) dependency.
I also enable tests that were explicitly skipped with UNIT_TEST_ONLY.
Some of the FP tests are claiming to be failing on GPUs (in 2023). If
that is still true, I'll skip them with if(TARGET_IS_GPU).
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 65 ++++++++++++----------
libc/test/UnitTest/CMakeLists.txt | 2 +-
libc/test/include/CMakeLists.txt | 13 -----
libc/test/src/math/CMakeLists.txt | 14 -----
4 files changed, 37 insertions(+), 57 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 53f167e99eeb0..8bb09e727dfd2 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -105,8 +105,8 @@ function(_get_common_test_compile_options output_var c_test flags)
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
-function(_get_hermetic_test_compile_options output_var)
- _get_common_test_compile_options(compile_options "" "")
+function(_get_hermetic_test_compile_options output_var c_test flags)
+ _get_common_test_compile_options(compile_options "${c_test}" "${flags}")
libc_add_definition(compile_options "LIBC_TEST=HERMETIC")
# null check tests are death tests, remove from hermetic tests for now.
@@ -626,7 +626,7 @@ function(add_integration_test test_name)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
- _get_hermetic_test_compile_options(compile_options "")
+ _get_hermetic_test_compile_options(compile_options "" "")
target_compile_options(${fq_build_target_name} PRIVATE
${compile_options} ${INTEGRATION_TEST_COMPILE_OPTIONS})
@@ -761,9 +761,9 @@ function(add_libc_hermetic test_name)
endif()
cmake_parse_arguments(
"HERMETIC_TEST"
- "IS_GPU_BENCHMARK;NO_RUN_POSTBUILD" # Optional arguments
+ "IS_GPU_BENCHMARK;NO_RUN_POSTBUILD;C_TEST" # Optional arguments
"SUITE;CXX_STANDARD" # Single value arguments
- "SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;LOADER_ARGS" # Multi-value arguments
+ "SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS;LOADER_ARGS" # Multi-value arguments
${ARGN}
)
@@ -784,7 +784,6 @@ function(add_libc_hermetic test_name)
libc.startup.${LIBC_TARGET_OS}.crt1
# We always add the memory functions objects. This is because the
# compiler's codegen can emit calls to the C memory functions.
- libc.src.__support.StringUtil.error_to_string
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
@@ -792,36 +791,43 @@ function(add_libc_hermetic test_name)
libc.src.strings.bcmp
libc.src.strings.bzero
)
+
+ if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ # __stack_chk_fail should always be included if supported to allow building
+ # libc with the stack protector enabled.
+ list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
+ endif()
+
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
list(APPEND fq_deps_list libc.src.sys.auxv.getauxval)
endif()
- # Syscalls used by death tests.
- if(LIBC_TEST_SUBPROCESS_TESTS)
+ if (NOT HERMETIC_TEST_C_TEST)
list(APPEND fq_deps_list
- libc.src.poll.poll
- libc.src.signal.kill
- libc.src.stdio.fflush
- libc.src.stdio.stderr
- libc.src.stdio.stdout
- libc.src.stdlib.exit
- libc.src.string.strsignal
- libc.src.sys.wait.waitpid
- libc.src.unistd.close
- libc.src.unistd.fork
- libc.src.unistd.pipe
+ libc.src.__support.StringUtil.error_to_string
)
- endif()
- if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
- # __stack_chk_fail should always be included if supported to allow building
- # libc with the stack protector enabled.
- list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
- endif()
+ # Syscalls used by death tests.
+ if(LIBC_TEST_SUBPROCESS_TESTS)
+ list(APPEND fq_deps_list
+ libc.src.poll.poll
+ libc.src.signal.kill
+ libc.src.stdio.fflush
+ libc.src.stdio.stderr
+ libc.src.stdio.stdout
+ libc.src.stdlib.exit
+ libc.src.string.strsignal
+ libc.src.sys.wait.waitpid
+ libc.src.unistd.close
+ libc.src.unistd.fork
+ libc.src.unistd.pipe
+ )
+ endif()
- if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
- # We will link in the 'clock' implementation if it exists for test timing.
- list(APPEND fq_deps_list libc.src.time.clock)
+ if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ # We will link in the 'clock' implementation if it exists for test timing.
+ list(APPEND fq_deps_list libc.src.time.clock)
+ endif()
endif()
list(REMOVE_DUPLICATES fq_deps_list)
@@ -876,7 +882,8 @@ function(add_libc_hermetic test_name)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
- _get_hermetic_test_compile_options(compile_options "")
+ _get_hermetic_test_compile_options(compile_options "${HERMETIC_TEST_C_TEST}"
+ "${HERMETIC_TEST_FLAGS}")
target_compile_options(${fq_build_target_name} PRIVATE
${compile_options}
${HERMETIC_TEST_COMPILE_OPTIONS})
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 1732473e355dc..4f91590025413 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -40,7 +40,7 @@ function(add_unittest_framework_library name)
endif()
target_compile_options(${name}.unit PRIVATE ${compile_options})
- _get_hermetic_test_compile_options(compile_options "")
+ _get_hermetic_test_compile_options(compile_options "" "")
target_include_directories(${name}.hermetic PRIVATE ${LIBC_INCLUDE_DIR})
target_compile_options(${name}.hermetic PRIVATE ${compile_options} -nostdinc++)
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index ff56e4359dacd..6fc3c69c14dca 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -75,7 +75,6 @@ add_libc_test(
add_libc_test(
stdbit_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
HDRS
@@ -108,7 +107,6 @@ add_libc_test(
add_libc_test(
sched_test
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -370,7 +368,6 @@ add_libc_test(
add_libc_test(
signbit_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -385,7 +382,6 @@ add_libc_test(
add_libc_test(
isnan_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -400,7 +396,6 @@ add_libc_test(
add_libc_test(
isnormal_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -416,7 +411,6 @@ add_libc_test(
# add_libc_test(
# issignaling_c_test
# C_TEST
-# UNIT_TEST_ONLY
# SUITE
# libc_include_tests
# SRCS
@@ -434,7 +428,6 @@ add_libc_test(
# add_libc_test(
# iscanonical_c_test
# C_TEST
-# UNIT_TEST_ONLY
# SUITE
# libc_include_tests
# SRCS
@@ -452,7 +445,6 @@ add_libc_test(
add_libc_test(
isinf_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -467,7 +459,6 @@ add_libc_test(
add_libc_test(
isfinite_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -482,7 +473,6 @@ add_libc_test(
add_libc_test(
issubnormal_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -497,7 +487,6 @@ add_libc_test(
add_libc_test(
fpclassify_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -512,7 +501,6 @@ add_libc_test(
add_libc_test(
iszero_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -527,7 +515,6 @@ add_libc_test(
add_libc_test(
math_constants_c_test
C_TEST
- UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 240689c0de02f..6fbe43501e017 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1350,8 +1350,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.copysign
libc.src.__support.FPUtil.fp_bits
- # FIXME: Currently fails on the GPU build.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -1365,8 +1363,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.copysignf
libc.src.__support.FPUtil.fp_bits
- # FIXME: Currently fails on the GPU build.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -1380,8 +1376,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.copysignl
libc.src.__support.FPUtil.fp_bits
- # FIXME: Currently fails on the GPU build.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -1563,8 +1557,6 @@ add_fp_unittest(
libc.src.math.modf
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
- # Requires C++ limits.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -1579,8 +1571,6 @@ add_fp_unittest(
libc.src.math.modff
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
- # Requires C++ limits.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -2298,8 +2288,6 @@ add_fp_unittest(
libc.src.math.fmodf
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
- # FIXME: Currently fails on the GPU build.
- UNIT_TEST_ONLY
)
add_fp_unittest(
@@ -2315,8 +2303,6 @@ add_fp_unittest(
libc.src.math.fmod
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
- # FIXME: Currently fails on the GPU build.
- UNIT_TEST_ONLY
)
add_fp_unittest(
>From 635930f9c6ffa090ef506048cef508521864f38d Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 29 Jul 2026 08:36:35 +0000
Subject: [PATCH 2/2] revert C_TEST parts
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 63 ++++++++++------------
libc/test/UnitTest/CMakeLists.txt | 2 +-
libc/test/include/CMakeLists.txt | 13 +++++
3 files changed, 42 insertions(+), 36 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 8bb09e727dfd2..418551f137e44 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -105,8 +105,8 @@ function(_get_common_test_compile_options output_var c_test flags)
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
-function(_get_hermetic_test_compile_options output_var c_test flags)
- _get_common_test_compile_options(compile_options "${c_test}" "${flags}")
+function(_get_hermetic_test_compile_options output_var flags)
+ _get_common_test_compile_options(compile_options "" "${flags}")
libc_add_definition(compile_options "LIBC_TEST=HERMETIC")
# null check tests are death tests, remove from hermetic tests for now.
@@ -626,7 +626,7 @@ function(add_integration_test test_name)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
- _get_hermetic_test_compile_options(compile_options "" "")
+ _get_hermetic_test_compile_options(compile_options "")
target_compile_options(${fq_build_target_name} PRIVATE
${compile_options} ${INTEGRATION_TEST_COMPILE_OPTIONS})
@@ -761,7 +761,7 @@ function(add_libc_hermetic test_name)
endif()
cmake_parse_arguments(
"HERMETIC_TEST"
- "IS_GPU_BENCHMARK;NO_RUN_POSTBUILD;C_TEST" # Optional arguments
+ "IS_GPU_BENCHMARK;NO_RUN_POSTBUILD" # Optional arguments
"SUITE;CXX_STANDARD" # Single value arguments
"SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS;LOADER_ARGS" # Multi-value arguments
${ARGN}
@@ -784,6 +784,7 @@ function(add_libc_hermetic test_name)
libc.startup.${LIBC_TARGET_OS}.crt1
# We always add the memory functions objects. This is because the
# compiler's codegen can emit calls to the C memory functions.
+ libc.src.__support.StringUtil.error_to_string
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
@@ -791,43 +792,36 @@ function(add_libc_hermetic test_name)
libc.src.strings.bcmp
libc.src.strings.bzero
)
-
- if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
- # __stack_chk_fail should always be included if supported to allow building
- # libc with the stack protector enabled.
- list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
- endif()
-
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
list(APPEND fq_deps_list libc.src.sys.auxv.getauxval)
endif()
- if (NOT HERMETIC_TEST_C_TEST)
+ # Syscalls used by death tests.
+ if(LIBC_TEST_SUBPROCESS_TESTS)
list(APPEND fq_deps_list
- libc.src.__support.StringUtil.error_to_string
+ libc.src.poll.poll
+ libc.src.signal.kill
+ libc.src.stdio.fflush
+ libc.src.stdio.stderr
+ libc.src.stdio.stdout
+ libc.src.stdlib.exit
+ libc.src.string.strsignal
+ libc.src.sys.wait.waitpid
+ libc.src.unistd.close
+ libc.src.unistd.fork
+ libc.src.unistd.pipe
)
+ endif()
- # Syscalls used by death tests.
- if(LIBC_TEST_SUBPROCESS_TESTS)
- list(APPEND fq_deps_list
- libc.src.poll.poll
- libc.src.signal.kill
- libc.src.stdio.fflush
- libc.src.stdio.stderr
- libc.src.stdio.stdout
- libc.src.stdlib.exit
- libc.src.string.strsignal
- libc.src.sys.wait.waitpid
- libc.src.unistd.close
- libc.src.unistd.fork
- libc.src.unistd.pipe
- )
- endif()
+ if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ # __stack_chk_fail should always be included if supported to allow building
+ # libc with the stack protector enabled.
+ list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
+ endif()
- if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
- # We will link in the 'clock' implementation if it exists for test timing.
- list(APPEND fq_deps_list libc.src.time.clock)
- endif()
+ if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ # We will link in the 'clock' implementation if it exists for test timing.
+ list(APPEND fq_deps_list libc.src.time.clock)
endif()
list(REMOVE_DUPLICATES fq_deps_list)
@@ -882,8 +876,7 @@ function(add_libc_hermetic test_name)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
- _get_hermetic_test_compile_options(compile_options "${HERMETIC_TEST_C_TEST}"
- "${HERMETIC_TEST_FLAGS}")
+ _get_hermetic_test_compile_options(compile_options "${HERMETIC_TEST_FLAGS}")
target_compile_options(${fq_build_target_name} PRIVATE
${compile_options}
${HERMETIC_TEST_COMPILE_OPTIONS})
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 4f91590025413..1732473e355dc 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -40,7 +40,7 @@ function(add_unittest_framework_library name)
endif()
target_compile_options(${name}.unit PRIVATE ${compile_options})
- _get_hermetic_test_compile_options(compile_options "" "")
+ _get_hermetic_test_compile_options(compile_options "")
target_include_directories(${name}.hermetic PRIVATE ${LIBC_INCLUDE_DIR})
target_compile_options(${name}.hermetic PRIVATE ${compile_options} -nostdinc++)
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 6fc3c69c14dca..ff56e4359dacd 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -75,6 +75,7 @@ add_libc_test(
add_libc_test(
stdbit_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
HDRS
@@ -107,6 +108,7 @@ add_libc_test(
add_libc_test(
sched_test
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -368,6 +370,7 @@ add_libc_test(
add_libc_test(
signbit_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -382,6 +385,7 @@ add_libc_test(
add_libc_test(
isnan_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -396,6 +400,7 @@ add_libc_test(
add_libc_test(
isnormal_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -411,6 +416,7 @@ add_libc_test(
# add_libc_test(
# issignaling_c_test
# C_TEST
+# UNIT_TEST_ONLY
# SUITE
# libc_include_tests
# SRCS
@@ -428,6 +434,7 @@ add_libc_test(
# add_libc_test(
# iscanonical_c_test
# C_TEST
+# UNIT_TEST_ONLY
# SUITE
# libc_include_tests
# SRCS
@@ -445,6 +452,7 @@ add_libc_test(
add_libc_test(
isinf_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -459,6 +467,7 @@ add_libc_test(
add_libc_test(
isfinite_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -473,6 +482,7 @@ add_libc_test(
add_libc_test(
issubnormal_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -487,6 +497,7 @@ add_libc_test(
add_libc_test(
fpclassify_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -501,6 +512,7 @@ add_libc_test(
add_libc_test(
iszero_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
@@ -515,6 +527,7 @@ add_libc_test(
add_libc_test(
math_constants_c_test
C_TEST
+ UNIT_TEST_ONLY
SUITE
libc_include_tests
SRCS
More information about the libc-commits
mailing list