[libc-commits] [libc] 6ab2b87 - [libc] Clean up errno header usage in some more tests. (#157974)
via libc-commits
libc-commits at lists.llvm.org
Thu Sep 11 11:38:35 PDT 2025
Author: Alexey Samsonov
Date: 2025-09-11T11:38:30-07:00
New Revision: 6ab2b8745156269024de9098a4a6495ef19d546e
URL: https://github.com/llvm/llvm-project/commit/6ab2b8745156269024de9098a4a6495ef19d546e
DIFF: https://github.com/llvm/llvm-project/commit/6ab2b8745156269024de9098a4a6495ef19d546e.diff
LOG: [libc] Clean up errno header usage in some more tests. (#157974)
Either remove spurious libc_errno.h which are no longer needed, or
migrate some tests to ErrnoCheckingTest to remove manual errno
manipulation.
Added:
Modified:
libc/test/src/__support/CMakeLists.txt
libc/test/src/__support/str_to_fp_test.h
libc/test/src/__support/str_to_integer_test.cpp
libc/test/src/__support/wcs_to_integer_test.cpp
libc/test/src/poll/CMakeLists.txt
libc/test/src/poll/poll_test.cpp
libc/test/src/spawn/CMakeLists.txt
libc/test/src/spawn/posix_spawn_file_actions_test.cpp
libc/test/src/sys/ioctl/linux/CMakeLists.txt
libc/test/src/sys/ioctl/linux/ioctl_test.cpp
libc/test/src/termios/CMakeLists.txt
libc/test/src/termios/termios_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 5d1d0e0e5316b..a02514106a307 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -123,6 +123,8 @@ add_libc_test(
str_to_float_test.cpp
str_to_double_test.cpp
str_to_long_double_test.cpp
+ HDRS
+ str_to_fp_test.h
DEPENDS
libc.src.__support.integer_literals
libc.src.__support.str_to_float
diff --git a/libc/test/src/__support/str_to_fp_test.h b/libc/test/src/__support/str_to_fp_test.h
index 9b4844d410db2..d349192f107c0 100644
--- a/libc/test/src/__support/str_to_fp_test.h
+++ b/libc/test/src/__support/str_to_fp_test.h
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/str_to_float.h"
#include "src/__support/uint128.h"
diff --git a/libc/test/src/__support/str_to_integer_test.cpp b/libc/test/src/__support/str_to_integer_test.cpp
index 40cb76a8bd6a2..1ec882b212b8a 100644
--- a/libc/test/src/__support/str_to_integer_test.cpp
+++ b/libc/test/src/__support/str_to_integer_test.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/__support/str_to_integer.h"
#include <stddef.h>
diff --git a/libc/test/src/__support/wcs_to_integer_test.cpp b/libc/test/src/__support/wcs_to_integer_test.cpp
index e4107929c15fc..4554968be67ce 100644
--- a/libc/test/src/__support/wcs_to_integer_test.cpp
+++ b/libc/test/src/__support/wcs_to_integer_test.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/__support/wcs_to_integer.h"
#include <stddef.h>
diff --git a/libc/test/src/poll/CMakeLists.txt b/libc/test/src/poll/CMakeLists.txt
index c4af14168b906..54e00330f2bff 100644
--- a/libc/test/src/poll/CMakeLists.txt
+++ b/libc/test/src/poll/CMakeLists.txt
@@ -10,5 +10,5 @@ add_libc_unittest(
libc.hdr.limits_macros
libc.src.errno.errno
libc.src.poll.poll
- libc.test.UnitTest.ErrnoSetterMatcher
+ libc.test.UnitTest.ErrnoCheckingTest
)
diff --git a/libc/test/src/poll/poll_test.cpp b/libc/test/src/poll/poll_test.cpp
index 97b7b02718172..5bf2d5e4353f6 100644
--- a/libc/test/src/poll/poll_test.cpp
+++ b/libc/test/src/poll/poll_test.cpp
@@ -7,18 +7,19 @@
//===----------------------------------------------------------------------===//
#include "hdr/limits_macros.h" // UINT_MAX
-#include "src/__support/libc_errno.h"
#include "src/poll/poll.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
-TEST(LlvmLibcPollTest, SmokeTest) {
- libc_errno = 0;
+using LlvmLibcPollTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcPollTest, SmokeTest) {
int ret = LIBC_NAMESPACE::poll(nullptr, 0, 0);
ASSERT_ERRNO_SUCCESS();
ASSERT_EQ(0, ret);
}
-TEST(LlvmLibcPollTest, SmokeFailureTest) {
- libc_errno = 0;
+
+TEST_F(LlvmLibcPollTest, SmokeFailureTest) {
int ret = LIBC_NAMESPACE::poll(nullptr, UINT_MAX, 0);
ASSERT_ERRNO_EQ(EINVAL);
ASSERT_EQ(-1, ret);
diff --git a/libc/test/src/spawn/CMakeLists.txt b/libc/test/src/spawn/CMakeLists.txt
index 04814db46dca2..103925cf3a22d 100644
--- a/libc/test/src/spawn/CMakeLists.txt
+++ b/libc/test/src/spawn/CMakeLists.txt
@@ -7,6 +7,7 @@ add_libc_unittest(
SRCS
posix_spawn_file_actions_test.cpp
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.stdint_proxy
libc.include.spawn
libc.src.spawn.file_actions
@@ -15,5 +16,4 @@ add_libc_unittest(
libc.src.spawn.posix_spawn_file_actions_addopen
libc.src.spawn.posix_spawn_file_actions_destroy
libc.src.spawn.posix_spawn_file_actions_init
- libc.src.errno.errno
)
diff --git a/libc/test/src/spawn/posix_spawn_file_actions_test.cpp b/libc/test/src/spawn/posix_spawn_file_actions_test.cpp
index 935a3540d9a58..20ab312f1f999 100644
--- a/libc/test/src/spawn/posix_spawn_file_actions_test.cpp
+++ b/libc/test/src/spawn/posix_spawn_file_actions_test.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/stdint_proxy.h"
-#include "src/__support/libc_errno.h"
#include "src/spawn/file_actions.h"
#include "src/spawn/posix_spawn_file_actions_addclose.h"
#include "src/spawn/posix_spawn_file_actions_adddup2.h"
diff --git a/libc/test/src/sys/ioctl/linux/CMakeLists.txt b/libc/test/src/sys/ioctl/linux/CMakeLists.txt
index 2df67e9d9cbde..2ccef25f4264f 100644
--- a/libc/test/src/sys/ioctl/linux/CMakeLists.txt
+++ b/libc/test/src/sys/ioctl/linux/CMakeLists.txt
@@ -14,5 +14,7 @@ add_libc_unittest(
libc.src.unistd.close
libc.src.unistd.read
libc.src.unistd.write
+ libc.test.UnitTest.ErrnoCheckingTest
+ libc.test.UnitTest.ErrnoSetterMatcher
)
diff --git a/libc/test/src/sys/ioctl/linux/ioctl_test.cpp b/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
index b76dc14824c95..4560bcf6e2e96 100644
--- a/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
+++ b/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
@@ -6,13 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/ioctl/ioctl.h"
#include "src/unistd/close.h"
#include "src/unistd/read.h"
#include "src/unistd/write.h"
-
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -20,11 +19,10 @@
#include "hdr/sys_ioctl_macros.h"
+using LlvmLibcSysIoctlTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
-TEST(LlvmLibcSysIoctlTest, InvalidCommandAndFIONREAD) {
- LIBC_NAMESPACE::libc_errno = 0;
-
+TEST_F(LlvmLibcSysIoctlTest, InvalidCommandAndFIONREAD) {
// Setup the test file
constexpr const char *TEST_FILE_NAME = "ioctl.test";
constexpr const char TEST_MSG[] = "ioctl test";
diff --git a/libc/test/src/termios/CMakeLists.txt b/libc/test/src/termios/CMakeLists.txt
index 302dd300fb59f..059c272c105c4 100644
--- a/libc/test/src/termios/CMakeLists.txt
+++ b/libc/test/src/termios/CMakeLists.txt
@@ -18,5 +18,6 @@ add_libc_unittest(
libc.src.termios.tcgetsid
libc.src.termios.tcsetattr
libc.src.unistd.close
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
diff --git a/libc/test/src/termios/termios_test.cpp b/libc/test/src/termios/termios_test.cpp
index 5ec169a886b1e..7a8075997a4a8 100644
--- a/libc/test/src/termios/termios_test.cpp
+++ b/libc/test/src/termios/termios_test.cpp
@@ -16,49 +16,52 @@
#include "src/termios/tcgetsid.h"
#include "src/termios/tcsetattr.h"
#include "src/unistd/close.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <termios.h>
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+using LlvmLibcTermiosTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
// We just list a bunch of smoke tests here as it is not possible to
// test functionality at the least because we want to run the tests
// from ninja/make which change the terminal behavior.
-TEST(LlvmLibcTermiosTest, SpeedSmokeTest) {
+TEST_F(LlvmLibcTermiosTest, SpeedSmokeTest) {
struct termios t;
- libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::cfsetispeed(&t, B50), Succeeds(0));
ASSERT_EQ(LIBC_NAMESPACE::cfgetispeed(&t), speed_t(B50));
ASSERT_THAT(LIBC_NAMESPACE::cfsetospeed(&t, B75), Succeeds(0));
ASSERT_EQ(LIBC_NAMESPACE::cfgetospeed(&t), speed_t(B75));
- libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::cfsetispeed(&t, ~CBAUD), Fails(EINVAL));
- libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::cfsetospeed(&t, ~CBAUD), Fails(EINVAL));
}
-TEST(LlvmLibcTermiosTest, GetAttrSmokeTest) {
+TEST_F(LlvmLibcTermiosTest, GetAttrSmokeTest) {
struct termios t;
- libc_errno = 0;
int fd = LIBC_NAMESPACE::open("/dev/tty", O_RDONLY);
- if (fd < 0)
- return; // When /dev/tty is not available, no point continuing.
+ if (fd < 0) {
+ // When /dev/tty is not available, no point continuing
+ libc_errno = 0;
+ return;
+ }
ASSERT_ERRNO_SUCCESS();
ASSERT_THAT(LIBC_NAMESPACE::tcgetattr(fd, &t), Succeeds(0));
- ASSERT_EQ(LIBC_NAMESPACE::close(fd), 0);
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-TEST(LlvmLibcTermiosTest, TcGetSidSmokeTest) {
- libc_errno = 0;
+TEST_F(LlvmLibcTermiosTest, TcGetSidSmokeTest) {
int fd = LIBC_NAMESPACE::open("/dev/tty", O_RDONLY);
- if (fd < 0)
- return; // When /dev/tty is not available, no point continuing.
+ if (fd < 0) {
+ // When /dev/tty is not available, no point continuing
+ libc_errno = 0;
+ return;
+ }
ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(LIBC_NAMESPACE::tcgetsid(fd), pid_t(0));
- ASSERT_EQ(LIBC_NAMESPACE::close(fd), 0);
+ ASSERT_THAT(LIBC_NAMESPACE::tcgetsid(fd),
+ returns(GT(pid_t(0))).with_errno(EQ(0)));
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
More information about the libc-commits
mailing list