[libc-commits] [libc] [llvm] [libc] Fix death tests performance. (PR #199474)
via libc-commits
libc-commits at lists.llvm.org
Mon May 25 10:22:20 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/199474
>From 79e64b7932bfab198a192a4dfbaa52b88e3e9687 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 25 May 2026 02:13:22 +0000
Subject: [PATCH 1/3] [libc] Fix death tests performance.
---
libc/test/UnitTest/ExecuteFunctionUnix.cpp | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/libc/test/UnitTest/ExecuteFunctionUnix.cpp b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
index ab18f7a2ebf52..ca09669ca844b 100644
--- a/libc/test/UnitTest/ExecuteFunctionUnix.cpp
+++ b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
@@ -10,11 +10,13 @@
#include "src/__support/macros/config.h"
#include "test/UnitTest/ExecuteFunction.h" // FunctionCaller
#include <assert.h>
+#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -36,7 +38,11 @@ int ProcessStatus::get_fatal_signal() {
ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
int pipe_fds[2];
+#ifdef SYS_pipe2
+ if (::syscall(SYS_pipe2, pipe_fds, O_CLOEXEC) == -1) {
+#else
if (::pipe(pipe_fds) == -1) {
+#endif
delete func;
return ProcessStatus::error("pipe(2) failed");
}
@@ -51,13 +57,20 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
}
if (!pid) {
+ ::close(pipe_fds[0]);
(*func)();
delete func;
- ::exit(0);
+ ::_exit(0);
}
::close(pipe_fds[1]);
- pollfd poll_fd{pipe_fds[0], POLLIN, 0};
+#ifdef __linux__
+ short poll_events = 0;
+#else
+ short poll_events = POLLIN;
+#endif
+
+ pollfd poll_fd{pipe_fds[0], poll_events, 0};
// No events requested so this call will only return after the timeout or if
// the pipes peer was closed, signaling the process exited.
if (::poll(&poll_fd, 1, timeout_ms) == -1) {
>From 37ac768985d03a9f94b6e9bbe8ce49c11dbbdbc6 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 25 May 2026 16:23:09 +0000
Subject: [PATCH 2/3] Try skip death tests.
---
.github/workflows/libc-fullbuild-tests.yml | 4 +++-
libc/cmake/modules/LLVMLibCTestRules.cmake | 4 ++++
libc/test/UnitTest/LibcTest.h | 9 +++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/libc-fullbuild-tests.yml b/.github/workflows/libc-fullbuild-tests.yml
index c9e9a4415a63c..f617d91e093fd 100644
--- a/.github/workflows/libc-fullbuild-tests.yml
+++ b/.github/workflows/libc-fullbuild-tests.yml
@@ -147,7 +147,9 @@ jobs:
-DCMAKE_C_COMPILER_LAUNCHER=sccache
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}
- -DLIBC_COMPILE_OPTIONS_NATIVE=''"
+ -DLIBC_COMPILE_OPTIONS_NATIVE=''
+ -DLIBC_TEST_SKIP_DEATH_TESTS=ON
+ "
if [[ "${{ matrix.include_scudo }}" == "ON" || "${{ matrix.build_fuzzing_tests }}" == "ON" ]]; then
export RUNTIMES="$RUNTIMES;compiler-rt"
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 89db3f0af50e0..bc3dd65d47edd 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -19,6 +19,10 @@ function(_get_common_test_compile_options output_var c_test flags)
${config_flags}
${arch_flags})
+ if(LIBC_TEST_SKIP_DEATH_TESTS)
+ list(APPEND compile_options "-DLIBC_TEST_SKIP_DEATH_TESTS")
+ endif()
+
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fpie")
diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index 8e41d3eeefcd5..133c198d42f15 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -495,11 +495,20 @@ CString libc_make_test_file_path_func(const char *file_name);
#define ASSERT_EXITS(FUNC, EXIT) \
LIBC_TEST_PROCESS_(testProcessExits, FUNC, EXIT, return)
+#ifdef LIBC_TEST_SKIP_DEATH_TESTS
+
+#define EXPECT_DEATH(FUNC, SIG)
+#define ASSERT_DEATH(FUNC, SIG)
+
+#else
+
#define EXPECT_DEATH(FUNC, SIG) \
LIBC_TEST_PROCESS_(testProcessKilled, FUNC, SIG, )
#define ASSERT_DEATH(FUNC, SIG) \
LIBC_TEST_PROCESS_(testProcessKilled, FUNC, SIG, return)
+#endif // LIBC_TEST_SKIP_DEATH_TESTS
+
#endif // ENABLE_SUBPROCESS_TESTS
////////////////////////////////////////////////////////////////////////////////
>From ef2b539d273bfdba0b2282b3f79a13b7d285d341 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 25 May 2026 17:22:02 +0000
Subject: [PATCH 3/3] Skip shared tests.
---
.github/workflows/libc-fullbuild-tests.yml | 1 +
libc/test/shared/CMakeLists.txt | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/.github/workflows/libc-fullbuild-tests.yml b/.github/workflows/libc-fullbuild-tests.yml
index f617d91e093fd..b5fc6045e27d8 100644
--- a/.github/workflows/libc-fullbuild-tests.yml
+++ b/.github/workflows/libc-fullbuild-tests.yml
@@ -149,6 +149,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}
-DLIBC_COMPILE_OPTIONS_NATIVE=''
-DLIBC_TEST_SKIP_DEATH_TESTS=ON
+ -DLIBC_TEST_SKIP_SHARED_TESTS=ON
"
if [[ "${{ matrix.include_scudo }}" == "ON" || "${{ matrix.build_fuzzing_tests }}" == "ON" ]]; then
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index e86b0a45eb77c..f141e549692bc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -1,5 +1,9 @@
add_custom_target(libc-shared-tests)
+if(LIBC_TEST_SKIP_SHARED_TESTS)
+ return()
+endif()
+
add_fp_unittest(
shared_math_test
SUITE
More information about the libc-commits
mailing list