[libc-commits] [libc] [libc] Fix death tests performance. (PR #199474)

via libc-commits libc-commits at lists.llvm.org
Sun May 24 19:14:07 PDT 2026


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/199474

None

>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] [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) {



More information about the libc-commits mailing list