[libc-commits] [libc] [libc][cmake] Make hermetic tests support C_TEST and FLAGS (PR #212460)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 28 05:34:13 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
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).
---
Full diff: https://github.com/llvm/llvm-project/pull/212460.diff
4 Files Affected:
- (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+36-29)
- (modified) libc/test/UnitTest/CMakeLists.txt (+1-1)
- (modified) libc/test/include/CMakeLists.txt (-13)
- (modified) libc/test/src/math/CMakeLists.txt (-14)
``````````diff
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(
``````````
</details>
https://github.com/llvm/llvm-project/pull/212460
More information about the libc-commits
mailing list