[libc-commits] [libc] [libc] Disable Death Tests While Hermetic (PR #77388)

via libc-commits libc-commits at lists.llvm.org
Tue Jan 9 13:46:20 PST 2024


https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/77388

>From f78aaf9c228cb67720e713c77e49ef398a20e07b Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Mon, 8 Jan 2024 14:48:49 -0800
Subject: [PATCH 1/2] [libc] Disable Death Tests While Hermetic

The death test infrastructure seems to depend on operator new, which
isn't currently supported in our hermetic tests. This patch just
disables the death tests in hermetic mode since they only overlap in the
nan tests.
---
 libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
 libc/test/src/math/smoke/nan_test.cpp      | 4 ++--
 libc/test/src/math/smoke/nanf_test.cpp     | 4 ++--
 libc/test/src/math/smoke/nanl_test.cpp     | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 24f543f6e4c132..8029500f63e68b 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -605,7 +605,7 @@ function(add_integration_test test_name)
 endfunction(add_integration_test)
 
 set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
-    -fpie -ffreestanding -fno-exceptions -fno-rtti)
+    -fpie -ffreestanding -fno-exceptions -fno-rtti -DLIBC_HERMETIC_TEST)
 # The GPU build requires overriding the default CMake triple and architecture.
 if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
   list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
diff --git a/libc/test/src/math/smoke/nan_test.cpp b/libc/test/src/math/smoke/nan_test.cpp
index 81e1400f0bb6b9..f7a05d0f73008f 100644
--- a/libc/test/src/math/smoke/nan_test.cpp
+++ b/libc/test/src/math/smoke/nan_test.cpp
@@ -42,8 +42,8 @@ TEST_F(LlvmLibcNanTest, RandomString) {
   run_test("123 ", 0x7ff8000000000000);
 }
 
-#ifndef LIBC_HAVE_ADDRESS_SANITIZER
+#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
 TEST_F(LlvmLibcNanTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // LIBC_HAVE_ADDRESS_SANITIZER
+#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST
diff --git a/libc/test/src/math/smoke/nanf_test.cpp b/libc/test/src/math/smoke/nanf_test.cpp
index 1d337ecf1dcd08..1aa4f00f00c3a1 100644
--- a/libc/test/src/math/smoke/nanf_test.cpp
+++ b/libc/test/src/math/smoke/nanf_test.cpp
@@ -41,8 +41,8 @@ TEST_F(LlvmLibcNanfTest, RandomString) {
   run_test("123 ", 0x7fc00000);
 }
 
-#ifndef LIBC_HAVE_ADDRESS_SANITIZER
+#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
 TEST_F(LlvmLibcNanfTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // LIBC_HAVE_ADDRESS_SANITIZER
+#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST
diff --git a/libc/test/src/math/smoke/nanl_test.cpp b/libc/test/src/math/smoke/nanl_test.cpp
index 009710b49c832e..f3f241e8786e0d 100644
--- a/libc/test/src/math/smoke/nanl_test.cpp
+++ b/libc/test/src/math/smoke/nanl_test.cpp
@@ -67,8 +67,8 @@ TEST_F(LlvmLibcNanlTest, RandomString) {
   run_test("123 ", expected);
 }
 
-#ifndef LIBC_HAVE_ADDRESS_SANITIZER
+#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
 TEST_F(LlvmLibcNanlTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // LIBC_HAVE_ADDRESS_SANITIZER
+#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST

>From d962880c612e00264ce3a9a7a57310de0691dda9 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 9 Jan 2024 13:45:34 -0800
Subject: [PATCH 2/2] add hermetic new and switch to UNIT_TEST_ONLY flag

---
 libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
 libc/test/UnitTest/HermeticTestUtils.cpp   | 4 ++++
 libc/test/src/math/smoke/CMakeLists.txt    | 9 +++++++++
 libc/test/src/math/smoke/nan_test.cpp      | 4 ++--
 libc/test/src/math/smoke/nanf_test.cpp     | 4 ++--
 libc/test/src/math/smoke/nanl_test.cpp     | 4 ++--
 6 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 8029500f63e68b..24f543f6e4c132 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -605,7 +605,7 @@ function(add_integration_test test_name)
 endfunction(add_integration_test)
 
 set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
-    -fpie -ffreestanding -fno-exceptions -fno-rtti -DLIBC_HERMETIC_TEST)
+    -fpie -ffreestanding -fno-exceptions -fno-rtti)
 # The GPU build requires overriding the default CMake triple and architecture.
 if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
   list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 73d54b9eeb5ecc..68e31f478d79ab 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -104,6 +104,10 @@ void *__dso_handle = nullptr;
 
 } // extern "C"
 
+void *operator new(size_t size) { return malloc(size); }
+
+void *operator new[](size_t size) { return malloc(size); }
+
 void operator delete(void *) {
   // The libc runtime should not use the global delete operator. Hence,
   // we just trap here to catch any such accidental usages.
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 65dc80c2a882a5..87b72e2a8eca2e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1214,6 +1214,9 @@ add_fp_unittest(
     libc.include.signal
     libc.src.math.nanf
     libc.src.__support.FPUtil.fp_bits
+  # FIXME: The nan tests currently have death tests, which aren't supported for
+  # hermetic tests.
+  UNIT_TEST_ONLY
 )
 
 add_fp_unittest(
@@ -1227,6 +1230,9 @@ add_fp_unittest(
     libc.include.signal
     libc.src.math.nan
     libc.src.__support.FPUtil.fp_bits
+  # FIXME: The nan tests currently have death tests, which aren't supported for
+  # hermetic tests.
+  UNIT_TEST_ONLY
 )
 
 add_fp_unittest(
@@ -1240,6 +1246,9 @@ add_fp_unittest(
     libc.include.signal
     libc.src.math.nanl
     libc.src.__support.FPUtil.fp_bits
+  # FIXME: The nan tests currently have death tests, which aren't supported for
+  # hermetic tests.
+  UNIT_TEST_ONLY
 )
 
 # FIXME: These tests are currently spurious for NVPTX.
diff --git a/libc/test/src/math/smoke/nan_test.cpp b/libc/test/src/math/smoke/nan_test.cpp
index f7a05d0f73008f..81e1400f0bb6b9 100644
--- a/libc/test/src/math/smoke/nan_test.cpp
+++ b/libc/test/src/math/smoke/nan_test.cpp
@@ -42,8 +42,8 @@ TEST_F(LlvmLibcNanTest, RandomString) {
   run_test("123 ", 0x7ff8000000000000);
 }
 
-#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
+#ifndef LIBC_HAVE_ADDRESS_SANITIZER
 TEST_F(LlvmLibcNanTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST
+#endif // LIBC_HAVE_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanf_test.cpp b/libc/test/src/math/smoke/nanf_test.cpp
index 1aa4f00f00c3a1..1d337ecf1dcd08 100644
--- a/libc/test/src/math/smoke/nanf_test.cpp
+++ b/libc/test/src/math/smoke/nanf_test.cpp
@@ -41,8 +41,8 @@ TEST_F(LlvmLibcNanfTest, RandomString) {
   run_test("123 ", 0x7fc00000);
 }
 
-#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
+#ifndef LIBC_HAVE_ADDRESS_SANITIZER
 TEST_F(LlvmLibcNanfTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST
+#endif // LIBC_HAVE_ADDRESS_SANITIZER
diff --git a/libc/test/src/math/smoke/nanl_test.cpp b/libc/test/src/math/smoke/nanl_test.cpp
index f3f241e8786e0d..009710b49c832e 100644
--- a/libc/test/src/math/smoke/nanl_test.cpp
+++ b/libc/test/src/math/smoke/nanl_test.cpp
@@ -67,8 +67,8 @@ TEST_F(LlvmLibcNanlTest, RandomString) {
   run_test("123 ", expected);
 }
 
-#if !defined(LIBC_HAVE_ADDRESS_SANITIZER) && !defined(LIBC_HERMETIC_TEST)
+#ifndef LIBC_HAVE_ADDRESS_SANITIZER
 TEST_F(LlvmLibcNanlTest, InvalidInput) {
   EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(SIGSEGV));
 }
-#endif // !LIBC_HAVE_ADDRESS_SANITIZER && !LIBC_HERMETIC_TEST
+#endif // LIBC_HAVE_ADDRESS_SANITIZER



More information about the libc-commits mailing list