Skip to content

Commit 6d3b72a

Browse files
authored
[libc] Pass config flags to unit tests. (#142085)
1 parent f70e920 commit 6d3b72a

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
function(_get_common_test_compile_options output_var c_test flags)
22
_get_compile_options_from_flags(compile_flags ${flags})
3+
_get_compile_options_from_config(config_flags)
34

45
# Remove -fno-math-errno if it was added.
56
if(LIBC_ADD_FNO_MATH_ERRNO)
6-
list(REMOVE_ITEM compile_options "-fno-math-errno")
7+
list(REMOVE_ITEM compile_flags "-fno-math-errno")
8+
endif()
9+
10+
# Death test executor is only available in Linux for now.
11+
if(NOT ${LIBC_TARGET_OS} STREQUAL "linux")
12+
list(REMOVE_ITEM config_flags "-DLIBC_ADD_NULL_CHECKS")
713
endif()
814

915
set(compile_options
1016
${LIBC_COMPILE_OPTIONS_DEFAULT}
1117
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
12-
${compile_flags})
18+
${compile_flags}
19+
${config_flags})
1320

1421
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
1522
list(APPEND compile_options "-fpie")
@@ -65,6 +72,11 @@ endfunction()
6572
function(_get_hermetic_test_compile_options output_var)
6673
_get_common_test_compile_options(compile_options "" "")
6774

75+
# null check tests are death tests, remove from hermetic tests for now.
76+
if(LIBC_ADD_NULL_CHECKS)
77+
list(REMOVE_ITEM compile_options "-DLIBC_ADD_NULL_CHECKS")
78+
endif()
79+
6880
# The GPU build requires overriding the default CMake triple and architecture.
6981
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
7082
list(APPEND compile_options

libc/test/src/math/smoke/nan_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ TEST_F(LlvmLibcNanTest, RandomString) {
4646

4747
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
4848
TEST_F(LlvmLibcNanTest, InvalidInput) {
49-
EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); });
49+
EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(-1));
5050
}
5151
#endif // LIBC_HAS_ADDRESS_SANITIZER

libc/test/src/math/smoke/nanf128_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ TEST_F(LlvmLibcNanf128Test, RandomString) {
5757

5858
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
5959
TEST_F(LlvmLibcNanf128Test, InvalidInput) {
60-
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); });
60+
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); }, WITH_SIGNAL(-1));
6161
}
6262
#endif // LIBC_HAS_ADDRESS_SANITIZER

libc/test/src/math/smoke/nanf16_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ TEST_F(LlvmLibcNanf16Test, RandomString) {
4545

4646
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
4747
TEST_F(LlvmLibcNanf16Test, InvalidInput) {
48-
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); });
48+
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); }, WITH_SIGNAL(-1));
4949
}
5050
#endif // LIBC_HAS_ADDRESS_SANITIZER

libc/test/src/math/smoke/nanf_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ TEST_F(LlvmLibcNanfTest, RandomString) {
4545

4646
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
4747
TEST_F(LlvmLibcNanfTest, InvalidInput) {
48-
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); });
48+
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(-1));
4949
}
5050
#endif // LIBC_HAS_ADDRESS_SANITIZER

libc/test/src/math/smoke/nanl_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ TEST_F(LlvmLibcNanlTest, RandomString) {
7373

7474
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
7575
TEST_F(LlvmLibcNanlTest, InvalidInput) {
76-
EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); });
76+
EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(-1));
7777
}
7878
#endif // LIBC_HAS_ADDRESS_SANITIZER

libc/test/src/stdfix/IdivTest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
6464
void testInvalidNumbers(IdivFunc func) {
6565
constexpr bool has_integral = (FXRep::INTEGRAL_LEN > 0);
6666

67-
EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(SIGILL));
67+
EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(-1));
6868
if constexpr (has_integral) {
69-
EXPECT_DEATH([func] { func(2.5, 0.0); }, WITH_SIGNAL(SIGSEGV));
69+
EXPECT_DEATH([func] { func(2.5, 0.0); }, WITH_SIGNAL(-1));
7070
}
7171
}
7272
};
7373

7474
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
75-
#define LIST_IDIV_TESTS(Name, T, XTYpe, func) \
75+
#define LIST_IDIV_TESTS(Name, T, XType, func) \
7676
using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \
7777
TEST_F(LlvmLibcIdiv##Name##Test, InvalidNumbers) { \
7878
testInvalidNumbers(&func); \

0 commit comments

Comments
 (0)