[libc-commits] [libc] [llvm] [libc] Fix death tests performance. (PR #199474)
via libc-commits
libc-commits at lists.llvm.org
Mon May 25 09:23:32 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/199474
>From c0d94bd9071681c3e49b6c5f040f17dc1ab1721c 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/2] [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 d11f8171804be5f66ad8b71b1f6254a0ecdf2362 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/2] 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
////////////////////////////////////////////////////////////////////////////////
More information about the libc-commits
mailing list