[libc-commits] [libc] 4769122 - [libc][test] split exit tests into two separate tests (#169820)

via libc-commits libc-commits at lists.llvm.org
Fri Nov 28 06:02:34 PST 2025


Author: Shreeyash Pandey
Date: 2025-11-28T19:32:29+05:30
New Revision: 4769122b2253c069e38107e80120caa2f1674aad

URL: https://github.com/llvm/llvm-project/commit/4769122b2253c069e38107e80120caa2f1674aad
DIFF: https://github.com/llvm/llvm-project/commit/4769122b2253c069e38107e80120caa2f1674aad.diff

LOG: [libc][test] split exit tests into two separate tests (#169820)

_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls
atexit-registered functions + whole lot of stuff that require support
for sync primitives.

Splitting the tests allows testing the former easily (especially for new
port projects)

---------

Signed-off-by: Shreeyash Pandey <shreeyash335 at gmail.com>

Added: 
    libc/test/src/stdlib/exit_test.cpp

Modified: 
    libc/test/UnitTest/ExecuteFunctionUnix.cpp
    libc/test/src/stdlib/CMakeLists.txt
    libc/test/src/stdlib/_Exit_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/UnitTest/ExecuteFunctionUnix.cpp b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
index 7c2eb7c6e887c..ab18f7a2ebf52 100644
--- a/libc/test/UnitTest/ExecuteFunctionUnix.cpp
+++ b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
@@ -57,7 +57,7 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
   }
   ::close(pipe_fds[1]);
 
-  struct pollfd poll_fd{pipe_fds[0], POLLIN, 0};
+  pollfd poll_fd{pipe_fds[0], POLLIN, 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) {

diff  --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index bcd3d139aa46c..05a74be4ca21f 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -448,6 +448,19 @@ if(LLVM_LIBC_FULL_BUILD)
       libc-stdlib-tests
     SRCS
       _Exit_test.cpp
+    DEPENDS
+      libc.src.__support.OSUtil.osutil
+      libc.src.stdlib._Exit
+  )
+
+  add_libc_test(
+    exit_test
+    # The EXPECT_EXITS test is only availible for unit tests.
+    UNIT_TEST_ONLY
+    SUITE
+      libc-stdlib-tests
+    SRCS
+      exit_test.cpp
     DEPENDS
       libc.src.stdlib._Exit
       libc.src.stdlib.exit

diff  --git a/libc/test/src/stdlib/_Exit_test.cpp b/libc/test/src/stdlib/_Exit_test.cpp
index 333277dc01dca..57c432828c2f3 100644
--- a/libc/test/src/stdlib/_Exit_test.cpp
+++ b/libc/test/src/stdlib/_Exit_test.cpp
@@ -7,13 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/stdlib/_Exit.h"
-#include "src/stdlib/exit.h"
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdlib, _Exit) {
   EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(1); }, 1);
   EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(65); }, 65);
-
-  EXPECT_EXITS([] { LIBC_NAMESPACE::exit(1); }, 1);
-  EXPECT_EXITS([] { LIBC_NAMESPACE::exit(65); }, 65);
 }

diff  --git a/libc/test/src/stdlib/exit_test.cpp b/libc/test/src/stdlib/exit_test.cpp
new file mode 100644
index 0000000000000..5c82d8303036a
--- /dev/null
+++ b/libc/test/src/stdlib/exit_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for exit -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/exit.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStdlib, exit) {
+  EXPECT_EXITS([] { LIBC_NAMESPACE::exit(1); }, 1);
+  EXPECT_EXITS([] { LIBC_NAMESPACE::exit(65); }, 65);
+}


        


More information about the libc-commits mailing list