[libc-commits] [libc] [libc] Pass config flags to unit tests. (PR #142085)
via libc-commits
libc-commits at lists.llvm.org
Fri May 30 06:48:43 PDT 2025
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/142085
>From 8dcb09ac8c5044351b83099471ab391524b7d94f Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 30 May 2025 04:12:54 +0000
Subject: [PATCH 1/3] [libc] Pass config flags to unit tests.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 9 ++++++++-
libc/test/src/math/smoke/nan_test.cpp | 2 +-
libc/test/src/math/smoke/nanf128_test.cpp | 2 +-
libc/test/src/math/smoke/nanf16_test.cpp | 2 +-
libc/test/src/math/smoke/nanf_test.cpp | 2 +-
libc/test/src/math/smoke/nanl_test.cpp | 2 +-
6 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 3f804694b5bae..886781d4e6ca2 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -1,5 +1,6 @@
function(_get_common_test_compile_options output_var c_test flags)
_get_compile_options_from_flags(compile_flags ${flags})
+ _get_compile_options_from_config(config_flags)
# Remove -fno-math-errno if it was added.
if(LIBC_ADD_FNO_MATH_ERRNO)
@@ -9,7 +10,8 @@ function(_get_common_test_compile_options output_var c_test flags)
set(compile_options
${LIBC_COMPILE_OPTIONS_DEFAULT}
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
- ${compile_flags})
+ ${compile_flags}
+ ${config_flags})
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fpie")
@@ -65,6 +67,11 @@ endfunction()
function(_get_hermetic_test_compile_options output_var)
_get_common_test_compile_options(compile_options "" "")
+ # null check tests are death tests, remove from hermetic tests for now.
+ if(LIBC_ADD_NULL_CHECKS)
+ list(REMOVE_ITEM config_options "-DLIBC_ADD_NULL_CHECKS")
+ endif()
+
# The GPU build requires overriding the default CMake triple and architecture.
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
list(APPEND compile_options
diff --git a/libc/test/src/math/smoke/nan_test.cpp b/libc/test/src/math/smoke/nan_test.cpp
index e45e2e6d499a2..e8376c03e92fd 100644
--- a/libc/test/src/math/smoke/nan_test.cpp
+++ b/libc/test/src/math/smoke/nan_test.cpp
@@ -46,6 +46,6 @@ TEST_F(LlvmLibcNanTest, RandomString) {
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
TEST_F(LlvmLibcNanTest, InvalidInput) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); });
+ EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(-1));
}
#endif // LIBC_HAS_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp
index aa59b79aac9d8..a63ce88524a1d 100644
--- a/libc/test/src/math/smoke/nanf128_test.cpp
+++ b/libc/test/src/math/smoke/nanf128_test.cpp
@@ -57,6 +57,6 @@ TEST_F(LlvmLibcNanf128Test, RandomString) {
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
TEST_F(LlvmLibcNanf128Test, InvalidInput) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); });
+ EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); }, WITH_SIGNAL(-1));
}
#endif // LIBC_HAS_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanf16_test.cpp b/libc/test/src/math/smoke/nanf16_test.cpp
index 04a8c7bb5d933..694470b7f7fec 100644
--- a/libc/test/src/math/smoke/nanf16_test.cpp
+++ b/libc/test/src/math/smoke/nanf16_test.cpp
@@ -45,6 +45,6 @@ TEST_F(LlvmLibcNanf16Test, RandomString) {
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
TEST_F(LlvmLibcNanf16Test, InvalidInput) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); });
+ EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); }, WITH_SIGNAL(-1));
}
#endif // LIBC_HAS_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanf_test.cpp b/libc/test/src/math/smoke/nanf_test.cpp
index 40e90c48d8cda..cb57f65e70943 100644
--- a/libc/test/src/math/smoke/nanf_test.cpp
+++ b/libc/test/src/math/smoke/nanf_test.cpp
@@ -45,6 +45,6 @@ TEST_F(LlvmLibcNanfTest, RandomString) {
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
TEST_F(LlvmLibcNanfTest, InvalidInput) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); });
+ EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(-1));
}
#endif // LIBC_HAS_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanl_test.cpp b/libc/test/src/math/smoke/nanl_test.cpp
index dea969fd3d2ad..3bcb914935954 100644
--- a/libc/test/src/math/smoke/nanl_test.cpp
+++ b/libc/test/src/math/smoke/nanl_test.cpp
@@ -73,6 +73,6 @@ TEST_F(LlvmLibcNanlTest, RandomString) {
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
TEST_F(LlvmLibcNanlTest, InvalidInput) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); });
+ EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(-1));
}
#endif // LIBC_HAS_ADDRESS_SANITIZER
>From 3d17512fa9002a1ba788d154f2e7c9b4ea902562 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 30 May 2025 05:03:35 +0000
Subject: [PATCH 2/3] Only enable null check tests for linux.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 886781d4e6ca2..54f337ecf0999 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -4,7 +4,12 @@ function(_get_common_test_compile_options output_var c_test flags)
# Remove -fno-math-errno if it was added.
if(LIBC_ADD_FNO_MATH_ERRNO)
- list(REMOVE_ITEM compile_options "-fno-math-errno")
+ list(REMOVE_ITEM compile_flags "-fno-math-errno")
+ endif()
+
+ # Death test executor is only available in Linux for now.
+ if(NOT ${LIBC_TARGET_OS} STREQUAL "linux")
+ list(REMOVE_ITEM config_flags "-DLIBC_ADD_NULL_CHECKS")
endif()
set(compile_options
@@ -69,7 +74,7 @@ function(_get_hermetic_test_compile_options output_var)
# null check tests are death tests, remove from hermetic tests for now.
if(LIBC_ADD_NULL_CHECKS)
- list(REMOVE_ITEM config_options "-DLIBC_ADD_NULL_CHECKS")
+ list(REMOVE_ITEM compile_options "-DLIBC_ADD_NULL_CHECKS")
endif()
# The GPU build requires overriding the default CMake triple and architecture.
>From c0795c8382b99fb615047c2979c2eda4ecc64082 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 30 May 2025 13:48:21 +0000
Subject: [PATCH 3/3] Fix a typo in IdivTest.h
---
libc/test/src/stdfix/IdivTest.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/stdfix/IdivTest.h b/libc/test/src/stdfix/IdivTest.h
index 6bfe9dff01a39..5c700ceca80e9 100644
--- a/libc/test/src/stdfix/IdivTest.h
+++ b/libc/test/src/stdfix/IdivTest.h
@@ -72,7 +72,7 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
};
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
-#define LIST_IDIV_TESTS(Name, T, XTYpe, func) \
+#define LIST_IDIV_TESTS(Name, T, XType, func) \
using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \
TEST_F(LlvmLibcIdiv##Name##Test, InvalidNumbers) { \
testInvalidNumbers(&func); \
More information about the libc-commits
mailing list