Skip to content

Conversation

vonosmas
Copy link
Contributor

Move these macro away from Test.h, since the generic Test.h (and associated test framework library) doesn't #include or depend on any errno-handling logic. Conversely, all tests that directly ASSERT various errno values are now migrated to ErrnoCheckingTest framework, which clears it our / validates it after every use case.

Move these macro away from Test.h, since the generic Test.h (and
associated test framework library) doesn't #include or depend on
any errno-handling logic. Conversely, all tests that directly ASSERT
various errno values are now migrated to ErrnoCheckingTest framework,
which clears it our / validates it after every use case.
@vonosmas vonosmas requested review from frobtech and lntue September 15, 2025 19:59
@llvmbot llvmbot added the libc label Sep 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 15, 2025

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Changes

Move these macro away from Test.h, since the generic Test.h (and associated test framework library) doesn't #include or depend on any errno-handling logic. Conversely, all tests that directly ASSERT various errno values are now migrated to ErrnoCheckingTest framework, which clears it our / validates it after every use case.


Full diff: https://github.com/llvm/llvm-project/pull/158727.diff

4 Files Affected:

  • (modified) libc/test/UnitTest/ErrnoCheckingTest.h (+15)
  • (modified) libc/test/UnitTest/Test.h (-15)
  • (modified) libc/test/src/errno/CMakeLists.txt (+1)
  • (modified) libc/test/src/errno/errno_test.cpp (+1)
diff --git a/libc/test/UnitTest/ErrnoCheckingTest.h b/libc/test/UnitTest/ErrnoCheckingTest.h
index 4b7ff452f409c..5b1bc9441d830 100644
--- a/libc/test/UnitTest/ErrnoCheckingTest.h
+++ b/libc/test/UnitTest/ErrnoCheckingTest.h
@@ -13,6 +13,21 @@
 #include "src/__support/macros/config.h"
 #include "test/UnitTest/Test.h"
 
+// Define macro to validate the value stored in the errno and restore it
+// to zero.
+
+#define ASSERT_ERRNO_EQ(VAL)                                                   \
+  do {                                                                         \
+    ASSERT_EQ(VAL, static_cast<int>(libc_errno));                              \
+    libc_errno = 0;                                                            \
+  } while (0)
+#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
+#define ASSERT_ERRNO_FAILURE()                                                 \
+  do {                                                                         \
+    ASSERT_NE(0, static_cast<int>(libc_errno));                                \
+    libc_errno = 0;                                                            \
+  } while (0)
+
 namespace LIBC_NAMESPACE_DECL {
 namespace testing {
 
diff --git a/libc/test/UnitTest/Test.h b/libc/test/UnitTest/Test.h
index e70fc51869624..6643e3882fd2b 100644
--- a/libc/test/UnitTest/Test.h
+++ b/libc/test/UnitTest/Test.h
@@ -37,21 +37,6 @@
 #include "LibcTest.h"
 #endif
 
-// These are defined the same way for each framework, in terms of the macros
-// they all provide.
-
-#define ASSERT_ERRNO_EQ(VAL)                                                   \
-  do {                                                                         \
-    ASSERT_EQ(VAL, static_cast<int>(libc_errno));                              \
-    libc_errno = 0;                                                            \
-  } while (0)
-#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
-#define ASSERT_ERRNO_FAILURE()                                                 \
-  do {                                                                         \
-    ASSERT_NE(0, static_cast<int>(libc_errno));                                \
-    libc_errno = 0;                                                            \
-  } while (0)
-
 // Some macro utility to append file names with LIBC_TEST macro's value to be
 // used in stdio tests.
 #undef STR
diff --git a/libc/test/src/errno/CMakeLists.txt b/libc/test/src/errno/CMakeLists.txt
index b73962fb4de4d..264574204e6cb 100644
--- a/libc/test/src/errno/CMakeLists.txt
+++ b/libc/test/src/errno/CMakeLists.txt
@@ -12,4 +12,5 @@ add_libc_unittest(
     errno_test.cpp
   DEPENDS
     libc.src.errno.errno
+    libc.test.UnitTest.ErrnoCheckingTest
 )
diff --git a/libc/test/src/errno/errno_test.cpp b/libc/test/src/errno/errno_test.cpp
index de82b0077f177..32fb3ec764063 100644
--- a/libc/test/src/errno/errno_test.cpp
+++ b/libc/test/src/errno/errno_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/libc_errno.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcErrnoTest, Basic) {

@vonosmas vonosmas merged commit 4a8bb08 into llvm:main Sep 15, 2025
21 checks passed
@vonosmas vonosmas deleted the assert-errno-move branch September 15, 2025 21:33
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 16, 2025

LLVM Buildbot has detected a new failure on builder libc-riscv32-qemu-yocto-fullbuild-dbg running on rv32gc-qemu-system while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/196/builds/12105

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
Ran 7 tests.  PASS: 7  FAIL: 0
[4702/4839] Running unit test libc.test.src.poll.poll_test
sh: line 1: /timer.7675: Permission denied
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcPollTest.SmokeTest
[       OK ] LlvmLibcPollTest.SmokeTest (497 us)
[ RUN      ] LlvmLibcPollTest.SmokeFailureTest
[       OK ] LlvmLibcPollTest.SmokeFailureTest (111 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[4703/4839] Running unit test libc.test.src.fcntl.openat_test
FAILED: libc/test/src/fcntl/CMakeFiles/libc.test.src.fcntl.openat_test /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl/CMakeFiles/libc.test.src.fcntl.openat_test 
cd /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl && /home/libcrv32buildbot/cross.sh /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl/libc.test.src.fcntl.openat_test.__build__
sh: line 1: /timer.7673: Permission denied
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcOpenAtTest.OpenAndReadTest
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/fcntl/openat_test.cpp:32: FAILURE
      Expected: 0
      Which is: 0
To be equal to: static_cast<int>(libc_errno)
      Which is: 2
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/UnitTest/ErrnoCheckingTest.h:47: FAILURE
      Expected: 0
      Which is: 0
To be equal to: static_cast<int>(libc_errno)
      Which is: 2
[  FAILED  ] LlvmLibcOpenAtTest.OpenAndReadTest
[ RUN      ] LlvmLibcOpenAtTest.FailTest
[       OK ] LlvmLibcOpenAtTest.FailTest (402 us)
Ran 2 tests.  PASS: 1  FAIL: 1
[4704/4839] Running unit test libc.test.src.unistd.getentropy_test.__unit__
sh: line 1: /timer.7691: Permission denied
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcUnistdGetEntropyTest.LengthTooLong
[       OK ] LlvmLibcUnistdGetEntropyTest.LengthTooLong (749 us)
[ RUN      ] LlvmLibcUnistdGetEntropyTest.SmokeTest
[       OK ] LlvmLibcUnistdGetEntropyTest.SmokeTest (581 us)
[ RUN      ] LlvmLibcUnistdGetEntropyTest.OtherError
[       OK ] LlvmLibcUnistdGetEntropyTest.OtherError (130 us)
Ran 3 tests.  PASS: 3  FAIL: 0
[4705/4839] Running unit test libc.test.src.unistd.fpathconf_test
sh: line 1: /timer.7690: Permission denied
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFpathconfTest.SmokeTest
[       OK ] LlvmLibcFpathconfTest.SmokeTest (2 ms)
Ran 1 tests.  PASS: 1  FAIL: 0
[4706/4839] Running unit test libc.test.src.inttypes.imaxabs_test.__unit__
sh: line 1: /timer.7693: Permission denied
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcImaxAbsTest.Zero
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
Ran 7 tests.  PASS: 7  FAIL: 0
[4702/4839] Running unit test libc.test.src.poll.poll_test
sh: line 1: /timer.7675: Permission denied
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcPollTest.SmokeTest
[       OK ] LlvmLibcPollTest.SmokeTest (497 us)
[ RUN      ] LlvmLibcPollTest.SmokeFailureTest
[       OK ] LlvmLibcPollTest.SmokeFailureTest (111 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[4703/4839] Running unit test libc.test.src.fcntl.openat_test
FAILED: libc/test/src/fcntl/CMakeFiles/libc.test.src.fcntl.openat_test /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl/CMakeFiles/libc.test.src.fcntl.openat_test 
cd /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl && /home/libcrv32buildbot/cross.sh /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/build/libc/test/src/fcntl/libc.test.src.fcntl.openat_test.__build__
sh: line 1: /timer.7673: Permission denied
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcOpenAtTest.OpenAndReadTest
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/fcntl/openat_test.cpp:32: FAILURE
      Expected: 0
      Which is: 0
To be equal to: static_cast<int>(libc_errno)
      Which is: 2
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/UnitTest/ErrnoCheckingTest.h:47: FAILURE
      Expected: 0
      Which is: 0
To be equal to: static_cast<int>(libc_errno)
      Which is: 2
[  FAILED  ] LlvmLibcOpenAtTest.OpenAndReadTest
[ RUN      ] LlvmLibcOpenAtTest.FailTest
[       OK ] LlvmLibcOpenAtTest.FailTest (402 us)
Ran 2 tests.  PASS: 1  FAIL: 1
[4704/4839] Running unit test libc.test.src.unistd.getentropy_test.__unit__
sh: line 1: /timer.7691: Permission denied
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcUnistdGetEntropyTest.LengthTooLong
[       OK ] LlvmLibcUnistdGetEntropyTest.LengthTooLong (749 us)
[ RUN      ] LlvmLibcUnistdGetEntropyTest.SmokeTest
[       OK ] LlvmLibcUnistdGetEntropyTest.SmokeTest (581 us)
[ RUN      ] LlvmLibcUnistdGetEntropyTest.OtherError
[       OK ] LlvmLibcUnistdGetEntropyTest.OtherError (130 us)
Ran 3 tests.  PASS: 3  FAIL: 0
[4705/4839] Running unit test libc.test.src.unistd.fpathconf_test
sh: line 1: /timer.7690: Permission denied
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFpathconfTest.SmokeTest
[       OK ] LlvmLibcFpathconfTest.SmokeTest (2 ms)
Ran 1 tests.  PASS: 1  FAIL: 0
[4706/4839] Running unit test libc.test.src.inttypes.imaxabs_test.__unit__
sh: line 1: /timer.7693: Permission denied
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcImaxAbsTest.Zero

@vonosmas
Copy link
Contributor Author

Build is green since then, looks like a transient error

SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
Move these macro away from Test.h, since the generic Test.h (and
associated test framework library) doesn't #include or depend on any
errno-handling logic. Conversely, all tests that directly ASSERT various
errno values are now migrated to ErrnoCheckingTest framework, which
clears it our / validates it after every use case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants