[libc-commits] [libc] af783db - [libc][NFC] Switch sys/*.h tests over to libc_errno.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Mon Mar 13 17:01:48 PDT 2023


Author: Siva Chandra Reddy
Date: 2023-03-13T23:44:52Z
New Revision: af783db7fd3b01b4c7dc880d5df13f8d78f6cf92

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

LOG: [libc][NFC] Switch sys/*.h tests over to libc_errno.

Added: 
    

Modified: 
    libc/test/src/sys/random/linux/CMakeLists.txt
    libc/test/src/sys/random/linux/getrandom_test.cpp
    libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
    libc/test/src/sys/select/select_ui_test.cpp
    libc/test/src/sys/sendfile/sendfile_test.cpp
    libc/test/src/sys/stat/CMakeLists.txt
    libc/test/src/sys/stat/chmod_test.cpp
    libc/test/src/sys/stat/fchmod_test.cpp
    libc/test/src/sys/stat/fchmodat_test.cpp
    libc/test/src/sys/stat/fstat_test.cpp
    libc/test/src/sys/stat/mkdirat_test.cpp
    libc/test/src/sys/stat/stat_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/sys/random/linux/CMakeLists.txt b/libc/test/src/sys/random/linux/CMakeLists.txt
index 3dcfd8626c05..627774908769 100644
--- a/libc/test/src/sys/random/linux/CMakeLists.txt
+++ b/libc/test/src/sys/random/linux/CMakeLists.txt
@@ -7,7 +7,6 @@ add_libc_unittest(
   SRCS
     getrandom_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.include.sys_random
     libc.src.errno.errno

diff  --git a/libc/test/src/sys/random/linux/getrandom_test.cpp b/libc/test/src/sys/random/linux/getrandom_test.cpp
index 3514613020fe..34b663627fe6 100644
--- a/libc/test/src/sys/random/linux/getrandom_test.cpp
+++ b/libc/test/src/sys/random/linux/getrandom_test.cpp
@@ -1,3 +1,12 @@
+//===-- Unittests for getrandom -------------------------------------------===//
+//
+// 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/errno/libc_errno.h"
 #include "src/math/fabs.h"
 #include "src/sys/random/getrandom.h"
 #include "test/ErrnoSetterMatcher.h"
@@ -7,17 +16,17 @@ TEST(LlvmLibcGetRandomTest, InvalidFlag) {
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   static constexpr size_t SIZE = 256;
   char data[SIZE];
-  errno = 0;
+  libc_errno = 0;
   ASSERT_THAT(__llvm_libc::getrandom(data, SIZE, -1), Fails(EINVAL));
-  errno = 0;
+  libc_errno = 0;
 }
 
 TEST(LlvmLibcGetRandomTest, InvalidBuffer) {
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
 
-  errno = 0;
+  libc_errno = 0;
   ASSERT_THAT(__llvm_libc::getrandom(nullptr, 65536, 0), Fails(EFAULT));
-  errno = 0;
+  libc_errno = 0;
 }
 
 TEST(LlvmLibcGetRandomTest, PiEstimation) {

diff  --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index 285624af6ef0..aa7a549876aa 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/CPP/string_view.h"
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/resource/getrlimit.h"
 #include "src/sys/resource/setrlimit.h"
@@ -15,7 +16,6 @@
 #include "test/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <sys/resource.h>
 
 TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
@@ -28,14 +28,14 @@ TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
 
   constexpr const char *TEST_FILE1 = "testdata/resource_limits1.test";
   constexpr const char *TEST_FILE2 = "testdata/resource_limits2.test";
-  errno = 0;
+  libc_errno = 0;
 
   int fd1 = __llvm_libc::open(TEST_FILE1, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd1, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   int fd2 = __llvm_libc::open(TEST_FILE2, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd2, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   ASSERT_THAT(__llvm_libc::close(fd1), Succeeds(0));
   ASSERT_THAT(__llvm_libc::close(fd2), Succeeds(0));
@@ -48,22 +48,22 @@ TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
   // One can now only open one of the files successfully.
   fd1 = __llvm_libc::open(TEST_FILE1, O_RDONLY);
   ASSERT_GT(fd1, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   fd2 = __llvm_libc::open(TEST_FILE2, O_RDONLY);
   ASSERT_LT(fd2, 0);
-  ASSERT_NE(errno, 0);
+  ASSERT_NE(libc_errno, 0);
 
-  errno = 0;
+  libc_errno = 0;
   ASSERT_THAT(__llvm_libc::close(fd1), Succeeds(0));
 
   fd2 = __llvm_libc::open(TEST_FILE2, O_RDONLY);
   ASSERT_GT(fd2, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   fd1 = __llvm_libc::open(TEST_FILE1, O_RDONLY);
   ASSERT_LT(fd1, 0);
-  ASSERT_NE(errno, 0);
+  ASSERT_NE(libc_errno, 0);
 
-  errno = 0;
+  libc_errno = 0;
   ASSERT_THAT(__llvm_libc::close(fd2), Succeeds(0));
 
   ASSERT_THAT(__llvm_libc::unlink(TEST_FILE1), Succeeds(0));

diff  --git a/libc/test/src/sys/select/select_ui_test.cpp b/libc/test/src/sys/select/select_ui_test.cpp
index d290b18654d2..e10d1aa17096 100644
--- a/libc/test/src/sys/select/select_ui_test.cpp
+++ b/libc/test/src/sys/select/select_ui_test.cpp
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/sys/select/select.h"
 #include "src/unistd/read.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <sys/select.h>
 #include <unistd.h>
 
@@ -18,7 +18,7 @@
 // Instead, one has to run it manually and press a key on the keyboard
 // to make the test succeed.
 TEST(LlvmLibcSelectTest, ReadStdinAfterSelect) {
-  errno = 0;
+  libc_errno = 0;
   constexpr int STDIN_FD = 0;
   fd_set set;
   FD_ZERO(&set);

diff  --git a/libc/test/src/sys/sendfile/sendfile_test.cpp b/libc/test/src/sys/sendfile/sendfile_test.cpp
index 95103aac7c10..c77965ea9640 100644
--- a/libc/test/src/sys/sendfile/sendfile_test.cpp
+++ b/libc/test/src/sys/sendfile/sendfile_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/CPP/string_view.h"
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/sendfile/sendfile.h"
 #include "src/unistd/close.h"
@@ -17,7 +18,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -36,20 +36,20 @@ TEST(LlvmLibcSendfileTest, CreateAndTransfer) {
   constexpr const char *OUT_FILE = "testdata/sendfile_out.test";
   const char IN_DATA[] = "sendfile test";
   constexpr ssize_t IN_SIZE = ssize_t(sizeof(IN_DATA));
-  errno = 0;
+  libc_errno = 0;
 
   int in_fd = __llvm_libc::open(IN_FILE, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(in_fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_EQ(__llvm_libc::write(in_fd, IN_DATA, IN_SIZE), IN_SIZE);
   ASSERT_THAT(__llvm_libc::close(in_fd), Succeeds(0));
 
   in_fd = __llvm_libc::open(IN_FILE, O_RDONLY);
   ASSERT_GT(in_fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   int out_fd = __llvm_libc::open(OUT_FILE, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(out_fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ssize_t size = __llvm_libc::sendfile(in_fd, out_fd, nullptr, IN_SIZE);
   ASSERT_EQ(size, IN_SIZE);
   ASSERT_THAT(__llvm_libc::close(in_fd), Succeeds(0));
@@ -57,7 +57,7 @@ TEST(LlvmLibcSendfileTest, CreateAndTransfer) {
 
   out_fd = __llvm_libc::open(OUT_FILE, O_RDONLY);
   ASSERT_GT(out_fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   char buf[IN_SIZE];
   ASSERT_EQ(IN_SIZE, __llvm_libc::read(out_fd, buf, IN_SIZE));
   ASSERT_EQ(cpp::string_view(buf), cpp::string_view(IN_DATA));

diff  --git a/libc/test/src/sys/stat/CMakeLists.txt b/libc/test/src/sys/stat/CMakeLists.txt
index ef2027dc2916..f21b7a0323a0 100644
--- a/libc/test/src/sys/stat/CMakeLists.txt
+++ b/libc/test/src/sys/stat/CMakeLists.txt
@@ -9,9 +9,9 @@ add_libc_unittest(
   SRCS
     chmod_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.fcntl.open
     libc.src.sys.stat.chmod
     libc.src.unistd.close
@@ -25,9 +25,9 @@ add_libc_unittest(
   SRCS
     fchmodat_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.fcntl.open
     libc.src.sys.stat.fchmodat
     libc.src.unistd.close
@@ -41,9 +41,9 @@ add_libc_unittest(
   SRCS
     fchmod_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.fcntl.open
     libc.src.sys.stat.fchmod
     libc.src.unistd.close
@@ -57,9 +57,9 @@ add_libc_unittest(
   SRCS
     mkdirat_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.sys.stat.mkdirat
     libc.src.unistd.rmdir
 )
@@ -71,9 +71,9 @@ add_libc_unittest(
   SRCS
     stat_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.sys.stat.stat
     libc.src.fcntl.open
     libc.src.unistd.close
@@ -87,9 +87,9 @@ add_libc_unittest(
   SRCS
     lstat_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.sys.stat.lstat
     libc.src.fcntl.open
     libc.src.unistd.close
@@ -103,9 +103,9 @@ add_libc_unittest(
   SRCS
     fstat_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.fcntl
     libc.include.sys_stat
+    libc.src.errno.errno
     libc.src.sys.stat.fstat
     libc.src.fcntl.open
     libc.src.unistd.close

diff  --git a/libc/test/src/sys/stat/chmod_test.cpp b/libc/test/src/sys/stat/chmod_test.cpp
index 456b867a2164..d8da9e390301 100644
--- a/libc/test/src/sys/stat/chmod_test.cpp
+++ b/libc/test/src/sys/stat/chmod_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/chmod.h"
 #include "src/unistd/close.h"
@@ -14,7 +15,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -29,36 +29,36 @@ TEST(LlvmLibcChmodTest, ChangeAndOpen) {
   constexpr const char *TEST_FILE = "testdata/chmod.test";
   const char WRITE_DATA[] = "test data";
   constexpr ssize_t WRITE_SIZE = ssize_t(sizeof(WRITE_DATA));
-  errno = 0;
+  libc_errno = 0;
 
   int fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_EQ(__llvm_libc::write(fd, WRITE_DATA, sizeof(WRITE_DATA)), WRITE_SIZE);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
   fd = __llvm_libc::open(TEST_FILE, O_PATH);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
   EXPECT_THAT(__llvm_libc::chmod(TEST_FILE, S_IRUSR), Succeeds(0));
 
   // Opening for writing should fail.
   EXPECT_EQ(__llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
-  EXPECT_NE(errno, 0);
-  errno = 0;
+  EXPECT_NE(libc_errno, 0);
+  libc_errno = 0;
   // But opening for reading should succeed.
   fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_RDONLY);
   EXPECT_GT(fd, 0);
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
 
   EXPECT_THAT(__llvm_libc::close(fd), Succeeds(0));
   EXPECT_THAT(__llvm_libc::chmod(TEST_FILE, S_IRWXU), Succeeds(0));
 }
 
 TEST(LlvmLibcChmodTest, NonExistentFile) {
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   ASSERT_THAT(__llvm_libc::chmod("non-existent-file", S_IRUSR), Fails(ENOENT));
-  errno = 0;
+  libc_errno = 0;
 }

diff  --git a/libc/test/src/sys/stat/fchmod_test.cpp b/libc/test/src/sys/stat/fchmod_test.cpp
index 54d945760865..c75688bac9d3 100644
--- a/libc/test/src/sys/stat/fchmod_test.cpp
+++ b/libc/test/src/sys/stat/fchmod_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/fchmod.h"
 #include "src/unistd/close.h"
@@ -14,7 +15,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -29,36 +29,36 @@ TEST(LlvmLibcChmodTest, ChangeAndOpen) {
   constexpr const char *TEST_FILE = "testdata/fchmod.test";
   const char WRITE_DATA[] = "test data";
   constexpr ssize_t WRITE_SIZE = ssize_t(sizeof(WRITE_DATA));
-  errno = 0;
+  libc_errno = 0;
 
   int fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_EQ(__llvm_libc::write(fd, WRITE_DATA, sizeof(WRITE_DATA)), WRITE_SIZE);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
   fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   EXPECT_THAT(__llvm_libc::fchmod(fd, S_IRUSR), Succeeds(0));
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
   // Opening for writing should fail.
   EXPECT_EQ(__llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
-  EXPECT_NE(errno, 0);
-  errno = 0;
+  EXPECT_NE(libc_errno, 0);
+  libc_errno = 0;
   // But opening for reading should succeed.
   fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_RDONLY);
   EXPECT_GT(fd, 0);
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
 
   EXPECT_THAT(__llvm_libc::fchmod(fd, S_IRWXU), Succeeds(0));
   EXPECT_THAT(__llvm_libc::close(fd), Succeeds(0));
 }
 
 TEST(LlvmLibcChmodTest, NonExistentFile) {
-  errno = 0;
+  libc_errno = 0;
   ASSERT_EQ(__llvm_libc::fchmod(-1, S_IRUSR), -1);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 }

diff  --git a/libc/test/src/sys/stat/fchmodat_test.cpp b/libc/test/src/sys/stat/fchmodat_test.cpp
index 109a162b8466..fd2a053d1233 100644
--- a/libc/test/src/sys/stat/fchmodat_test.cpp
+++ b/libc/test/src/sys/stat/fchmodat_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/fchmodat.h"
 #include "src/unistd/close.h"
@@ -14,7 +15,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -31,29 +31,29 @@ TEST(LlvmLibcFchmodatTest, ChangeAndOpen) {
   constexpr const char *TEST_FILE_BASENAME = "fchmodat.test";
   const char WRITE_DATA[] = "fchmodat test";
   constexpr ssize_t WRITE_SIZE = ssize_t(sizeof(WRITE_DATA));
-  errno = 0;
+  libc_errno = 0;
 
   int fd = __llvm_libc::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_EQ(__llvm_libc::write(fd, WRITE_DATA, sizeof(WRITE_DATA)), WRITE_SIZE);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
   int dirfd = __llvm_libc::open(TEST_DIR, O_DIRECTORY);
   ASSERT_GT(dirfd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   EXPECT_THAT(__llvm_libc::fchmodat(dirfd, TEST_FILE_BASENAME, S_IRUSR, 0),
               Succeeds(0));
 
   // Opening for writing should fail.
   EXPECT_EQ(__llvm_libc::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
-  EXPECT_NE(errno, 0);
-  errno = 0;
+  EXPECT_NE(libc_errno, 0);
+  libc_errno = 0;
   // But opening for reading should succeed.
   fd = __llvm_libc::open(TEST_FILE, O_APPEND | O_RDONLY);
   EXPECT_GT(fd, 0);
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
 
   EXPECT_THAT(__llvm_libc::close(fd), Succeeds(0));
   EXPECT_THAT(__llvm_libc::fchmodat(dirfd, TEST_FILE_BASENAME, S_IRWXU, 0),
@@ -63,9 +63,9 @@ TEST(LlvmLibcFchmodatTest, ChangeAndOpen) {
 }
 
 TEST(LlvmLibcFchmodatTest, NonExistentFile) {
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   ASSERT_THAT(__llvm_libc::fchmodat(AT_FDCWD, "non-existent-file", S_IRUSR, 0),
               Fails(ENOENT));
-  errno = 0;
+  libc_errno = 0;
 }

diff  --git a/libc/test/src/sys/stat/fstat_test.cpp b/libc/test/src/sys/stat/fstat_test.cpp
index 6db0d653fb60..66d9d3c83f90 100644
--- a/libc/test/src/sys/stat/fstat_test.cpp
+++ b/libc/test/src/sys/stat/fstat_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/fstat.h"
 #include "src/unistd/close.h"
@@ -14,7 +15,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -27,11 +27,11 @@ TEST(LlvmLibcFStatTest, CreatAndReadMode) {
   // make it readonly using chmod. We test that chmod actually succeeded by
   // trying to open the file for writing and failing.
   constexpr const char *TEST_FILE = "testdata/fstat.test";
-  errno = 0;
+  libc_errno = 0;
 
   int fd = __llvm_libc::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   struct stat statbuf;
   ASSERT_THAT(__llvm_libc::fstat(fd, &statbuf), Succeeds(0));
@@ -43,9 +43,9 @@ TEST(LlvmLibcFStatTest, CreatAndReadMode) {
 }
 
 TEST(LlvmLibcFStatTest, NonExistentFile) {
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   struct stat statbuf;
   ASSERT_THAT(__llvm_libc::fstat(-1, &statbuf), Fails(EBADF));
-  errno = 0;
+  libc_errno = 0;
 }

diff  --git a/libc/test/src/sys/stat/mkdirat_test.cpp b/libc/test/src/sys/stat/mkdirat_test.cpp
index 2e742009a0b1..7f302a41b54b 100644
--- a/libc/test/src/sys/stat/mkdirat_test.cpp
+++ b/libc/test/src/sys/stat/mkdirat_test.cpp
@@ -12,7 +12,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 
 TEST(LlvmLibcMkdiratTest, CreateAndRemove) {

diff  --git a/libc/test/src/sys/stat/stat_test.cpp b/libc/test/src/sys/stat/stat_test.cpp
index ba6e30246562..0a3eb3e070a1 100644
--- a/libc/test/src/sys/stat/stat_test.cpp
+++ b/libc/test/src/sys/stat/stat_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/errno/libc_errno.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/stat.h"
 #include "src/unistd/close.h"
@@ -14,7 +15,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -27,11 +27,11 @@ TEST(LlvmLibcStatTest, CreatAndReadMode) {
   // make it readonly using chmod. We test that chmod actually succeeded by
   // trying to open the file for writing and failing.
   constexpr const char *TEST_FILE = "testdata/stat.test";
-  errno = 0;
+  libc_errno = 0;
 
   int fd = __llvm_libc::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd, 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
   struct stat statbuf;
@@ -43,9 +43,9 @@ TEST(LlvmLibcStatTest, CreatAndReadMode) {
 }
 
 TEST(LlvmLibcStatTest, NonExistentFile) {
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   struct stat statbuf;
   ASSERT_THAT(__llvm_libc::stat("non-existent-file", &statbuf), Fails(ENOENT));
-  errno = 0;
+  libc_errno = 0;
 }


        


More information about the libc-commits mailing list