Skip to content

[libc] Pass config flags to unit tests. #142085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
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)
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
${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")
Expand Down Expand Up @@ -65,6 +72,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 compile_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
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/nan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/nanf128_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/nanf16_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/nanf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/nanl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions libc/test/src/stdfix/IdivTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
void testInvalidNumbers(IdivFunc func) {
constexpr bool has_integral = (FXRep::INTEGRAL_LEN > 0);

EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(SIGILL));
EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(-1));
if constexpr (has_integral) {
EXPECT_DEATH([func] { func(2.5, 0.0); }, WITH_SIGNAL(SIGSEGV));
EXPECT_DEATH([func] { func(2.5, 0.0); }, WITH_SIGNAL(-1));
}
}
};

#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); \
Expand Down
Loading