[libc-commits] [libc] 67de538 - [libc][NFC] Switch unistd.h tests to libc_errno.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Mon Mar 13 17:53:05 PDT 2023
Author: Siva Chandra Reddy
Date: 2023-03-14T00:52:33Z
New Revision: 67de5381a3ebe1cacbef4f0f7b382b6a40841608
URL: https://github.com/llvm/llvm-project/commit/67de5381a3ebe1cacbef4f0f7b382b6a40841608
DIFF: https://github.com/llvm/llvm-project/commit/67de5381a3ebe1cacbef4f0f7b382b6a40841608.diff
LOG: [libc][NFC] Switch unistd.h tests to libc_errno.
Added:
Modified:
libc/test/src/unistd/CMakeLists.txt
libc/test/src/unistd/access_test.cpp
libc/test/src/unistd/chdir_test.cpp
libc/test/src/unistd/dup2_test.cpp
libc/test/src/unistd/dup3_test.cpp
libc/test/src/unistd/dup_test.cpp
libc/test/src/unistd/fchdir_test.cpp
libc/test/src/unistd/ftruncate_test.cpp
libc/test/src/unistd/isatty_test.cpp
libc/test/src/unistd/link_test.cpp
libc/test/src/unistd/linkat_test.cpp
libc/test/src/unistd/lseek_test.cpp
libc/test/src/unistd/pread_pwrite_test.cpp
libc/test/src/unistd/read_write_test.cpp
libc/test/src/unistd/readlink_test.cpp
libc/test/src/unistd/readlinkat_test.cpp
libc/test/src/unistd/rmdir_test.cpp
libc/test/src/unistd/symlink_test.cpp
libc/test/src/unistd/symlinkat_test.cpp
libc/test/src/unistd/syscall_test.cpp
libc/test/src/unistd/truncate_test.cpp
libc/test/src/unistd/unlink_test.cpp
libc/test/src/unistd/unlinkat_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index b278c35eaa6cf..ea19aba0943ea 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -9,8 +9,8 @@ add_libc_unittest(
SRCS
access_test.cpp
DEPENDS
- libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.access
libc.src.unistd.close
@@ -24,8 +24,8 @@ add_libc_unittest(
SRCS
chdir_test.cpp
DEPENDS
- libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.chdir
libc.src.unistd.close
@@ -41,6 +41,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.dup
@@ -59,6 +60,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.dup2
@@ -77,6 +79,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.dup3
@@ -95,6 +98,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.fchdir
libc.src.unistd.close
@@ -110,6 +114,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.read
@@ -128,6 +133,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.fsync
@@ -147,6 +153,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.fsync
@@ -164,6 +171,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.link
@@ -179,6 +187,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.linkat
@@ -194,6 +203,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.lseek
@@ -210,6 +220,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.fcntl
+ libc.src.errno.errno
libc.src.sys.stat.mkdir
libc.src.unistd.rmdir
)
@@ -223,6 +234,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.unistd.readlink
libc.src.unistd.symlink
libc.src.unistd.unlink
@@ -239,6 +251,7 @@ add_libc_unittest(
libc.include.errno
libc.include.fcntl
libc.include.unistd
+ libc.src.errno.errno
libc.src.unistd.readlinkat
libc.src.unistd.symlink
libc.src.unistd.unlink
@@ -254,6 +267,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.symlink
@@ -269,6 +283,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.symlinkat
@@ -284,6 +299,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.read
@@ -302,6 +318,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.unistd.close
libc.src.unistd.unlink
@@ -316,6 +333,7 @@ add_libc_unittest(
DEPENDS
libc.include.errno
libc.include.unistd
+ libc.src.errno.errno
libc.src.fcntl.open
libc.src.fcntl.openat
libc.src.unistd.close
@@ -362,7 +380,6 @@ add_libc_unittest(
libc.src.unistd.isatty
libc.src.fcntl.open
libc.src.unistd.close
- libc.include.errno
libc.src.errno.errno
)
diff --git a/libc/test/src/unistd/access_test.cpp b/libc/test/src/unistd/access_test.cpp
index 30c3cb4572c19..92e7685567d84 100644
--- a/libc/test/src/unistd/access_test.cpp
+++ b/libc/test/src/unistd/access_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/access.h"
#include "src/unistd/close.h"
@@ -14,40 +15,39 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <unistd.h>
TEST(LlvmLibcAccessTest, CreateAndTest) {
// The test strategy is to repeatedly create a file in
diff erent modes and
// test that it is accessable in those modes but not in others.
- errno = 0;
+ libc_errno = 0;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/access.test";
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
ASSERT_EQ(__llvm_libc::access(TEST_FILE, F_OK), 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(__llvm_libc::access(TEST_FILE, X_OK | W_OK | R_OK), 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IXUSR);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
ASSERT_EQ(__llvm_libc::access(TEST_FILE, F_OK), 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(__llvm_libc::access(TEST_FILE, X_OK), 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(__llvm_libc::access(TEST_FILE, R_OK), -1);
- ASSERT_EQ(errno, EACCES);
- errno = 0;
+ ASSERT_EQ(libc_errno, EACCES);
+ libc_errno = 0;
ASSERT_EQ(__llvm_libc::access(TEST_FILE, W_OK), -1);
- ASSERT_EQ(errno, EACCES);
- errno = 0;
+ ASSERT_EQ(libc_errno, EACCES);
+ libc_errno = 0;
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
}
diff --git a/libc/test/src/unistd/chdir_test.cpp b/libc/test/src/unistd/chdir_test.cpp
index 998d42aeddfda..05e3e5dcbca28 100644
--- a/libc/test/src/unistd/chdir_test.cpp
+++ b/libc/test/src/unistd/chdir_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/chdir.h"
#include "src/unistd/close.h"
@@ -13,7 +14,6 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
TEST(LlvmLibcChdirTest, ChangeAndOpen) {
@@ -25,23 +25,23 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "testdata/chdir.test";
constexpr const char *TEST_FILE_BASE = "chdir.test";
- errno = 0;
+ libc_errno = 0;
int 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));
ASSERT_THAT(__llvm_libc::chdir(TEST_DIR), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE_BASE, O_PATH);
ASSERT_GT(fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
}
TEST(LlvmLibcChdirTest, ChangeToNonExistentDir) {
- errno = 0;
+ libc_errno = 0;
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(__llvm_libc::chdir("non-existent-dir"), Fails(ENOENT));
- errno = 0;
+ libc_errno = 0;
}
diff --git a/libc/test/src/unistd/dup2_test.cpp b/libc/test/src/unistd/dup2_test.cpp
index b595a66a5a109..545ea2eff80be 100644
--- a/libc/test/src/unistd/dup2_test.cpp
+++ b/libc/test/src/unistd/dup2_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/dup2.h"
@@ -16,18 +17,16 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
constexpr int DUPFD = 0xD0;
- errno = 0;
+ libc_errno = 0;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup2.test";
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
int dupfd = __llvm_libc::dup2(fd, DUPFD);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(dupfd, DUPFD);
// Write something via the dup
@@ -39,10 +38,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
dupfd = __llvm_libc::dup2(fd, DUPFD);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(dupfd, DUPFD);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/dup3_test.cpp b/libc/test/src/unistd/dup3_test.cpp
index 3d4b2e50cbff3..575e1291b9a27 100644
--- a/libc/test/src/unistd/dup3_test.cpp
+++ b/libc/test/src/unistd/dup3_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/dup3.h"
@@ -16,8 +17,6 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
// The tests here are exactly the same as those of dup2. We only test the
// plumbing of the dup3 syscall and not the dup3 functionality itself as it is
// a simple syscall wrapper. Testing dup3 functionality is beyond the scope of
@@ -25,15 +24,15 @@
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
constexpr int DUPFD = 0xD0;
- errno = 0;
+ libc_errno = 0;
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup3.test";
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
int dupfd = __llvm_libc::dup3(fd, DUPFD, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(dupfd, DUPFD);
// Write something via the dup
@@ -45,10 +44,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
dupfd = __llvm_libc::dup3(fd, DUPFD, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(dupfd, DUPFD);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/dup_test.cpp b/libc/test/src/unistd/dup_test.cpp
index 414176261f437..ff877727b0470 100644
--- a/libc/test/src/unistd/dup_test.cpp
+++ b/libc/test/src/unistd/dup_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/dup.h"
@@ -16,17 +17,15 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
- errno = 0;
+ libc_errno = 0;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup.test";
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
int dupfd = __llvm_libc::dup(fd);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(dupfd, 0);
// Write something via the dup
@@ -38,10 +37,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
dupfd = __llvm_libc::dup(fd);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(dupfd, 0);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/fchdir_test.cpp b/libc/test/src/unistd/fchdir_test.cpp
index b331f4e193794..35d3cd3b76eab 100644
--- a/libc/test/src/unistd/fchdir_test.cpp
+++ b/libc/test/src/unistd/fchdir_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/fchdir.h"
@@ -13,7 +14,6 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
TEST(LlvmLibcChdirTest, ChangeAndOpen) {
@@ -25,28 +25,28 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "testdata/fchdir.test";
constexpr const char *TEST_FILE_BASE = "fchdir.test";
- errno = 0;
+ libc_errno = 0;
int dir_fd = __llvm_libc::open(TEST_DIR, O_DIRECTORY);
ASSERT_GT(dir_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
int file_fd = __llvm_libc::open(TEST_FILE, O_PATH);
ASSERT_GT(file_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(file_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::fchdir(dir_fd), Succeeds(0));
file_fd = __llvm_libc::open(TEST_FILE_BASE, O_PATH);
ASSERT_GT(file_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(file_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::close(dir_fd), Succeeds(0));
}
TEST(LlvmLibcChdirTest, ChangeToNonExistentDir) {
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
- errno = 0;
+ libc_errno = 0;
ASSERT_EQ(__llvm_libc::fchdir(0), -1);
- ASSERT_NE(errno, 0);
- errno = 0;
+ ASSERT_NE(libc_errno, 0);
+ libc_errno = 0;
}
diff --git a/libc/test/src/unistd/ftruncate_test.cpp b/libc/test/src/unistd/ftruncate_test.cpp
index 77d3bd7931bf7..0814ef3862618 100644
--- a/libc/test/src/unistd/ftruncate_test.cpp
+++ b/libc/test/src/unistd/ftruncate_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/unistd/close.h"
#include "src/unistd/ftruncate.h"
@@ -16,8 +17,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
namespace cpp = __llvm_libc::cpp;
TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
@@ -32,16 +31,16 @@ TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
// 2. Read it to make sure what was written is actually in the file.
// 3. Truncate to 1 byte.
// 4. Try to read more than 1 byte and fail.
- errno = 0;
+ libc_errno = 0;
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE),
__llvm_libc::write(fd, WRITE_DATA, WRITE_SIZE));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE), __llvm_libc::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(cpp::string_view(buf), cpp::string_view(WRITE_DATA));
@@ -51,12 +50,12 @@ TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
// writing.
fd = __llvm_libc::open(TEST_FILE, O_WRONLY);
ASSERT_GT(fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::ftruncate(fd, off_t(1)), Succeeds(0));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(1), __llvm_libc::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(buf[0], WRITE_DATA[0]);
diff --git a/libc/test/src/unistd/isatty_test.cpp b/libc/test/src/unistd/isatty_test.cpp
index 0d949eec88f8c..c910e360192d4 100644
--- a/libc/test/src/unistd/isatty_test.cpp
+++ b/libc/test/src/unistd/isatty_test.cpp
@@ -6,21 +6,20 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/isatty.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcIsATTYTest, StdInOutTests) {
// If stdin is connected to a terminal, assume that all of the standard i/o
// fds are.
- errno = 0;
+ libc_errno = 0;
if (__llvm_libc::isatty(0)) {
EXPECT_THAT(__llvm_libc::isatty(0), Succeeds(1)); // stdin
EXPECT_THAT(__llvm_libc::isatty(1), Succeeds(1)); // stdout
@@ -33,16 +32,16 @@ TEST(LlvmLibcIsATTYTest, StdInOutTests) {
}
TEST(LlvmLibcIsATTYTest, BadFdTest) {
- errno = 0;
+ libc_errno = 0;
EXPECT_THAT(__llvm_libc::isatty(-1), Fails(EBADF, 0)); // invalid fd
}
TEST(LlvmLibcIsATTYTest, DevTTYTest) {
constexpr const char *TTY_FILE = "/dev/tty";
- errno = 0;
+ libc_errno = 0;
int fd = __llvm_libc::open(TTY_FILE, O_RDONLY);
if (fd > 0) {
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
EXPECT_THAT(__llvm_libc::isatty(fd), Succeeds(1));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
}
@@ -50,9 +49,9 @@ TEST(LlvmLibcIsATTYTest, DevTTYTest) {
TEST(LlvmLibcIsATTYTest, FileTest) {
constexpr const char *TEST_FILE = "testdata/isatty.test";
- errno = 0;
+ libc_errno = 0;
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
EXPECT_THAT(__llvm_libc::isatty(fd), Fails(ENOTTY, 0));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
diff --git a/libc/test/src/unistd/link_test.cpp b/libc/test/src/unistd/link_test.cpp
index b42336f171fe2..ef98559877e0f 100644
--- a/libc/test/src/unistd/link_test.cpp
+++ b/libc/test/src/unistd/link_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/link.h"
@@ -13,8 +14,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
TEST(LlvmLibcLinkTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/link.test";
@@ -25,16 +24,16 @@ TEST(LlvmLibcLinkTest, CreateAndUnlink) {
// 2. Create a link to that file.
// 3. Open the link to check that the link was created.
// 4. Cleanup the file and its link.
- errno = 0;
+ libc_errno = 0;
int write_fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::link(TEST_FILE, TEST_FILE_LINK), Succeeds(0));
int link_fd = __llvm_libc::open(TEST_FILE_LINK, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(link_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/linkat_test.cpp b/libc/test/src/unistd/linkat_test.cpp
index 5a61b4e9301e8..e61c7c17a80f2 100644
--- a/libc/test/src/unistd/linkat_test.cpp
+++ b/libc/test/src/unistd/linkat_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/linkat.h"
@@ -13,8 +14,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
@@ -28,9 +27,9 @@ TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
// 2. Create a link to that file.
// 3. Open the link to check that the link was created.
// 4. Cleanup the file and its link.
- errno = 0;
+ libc_errno = 0;
int write_fd = __llvm_libc::open(TEST_FILE_PATH, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
@@ -40,7 +39,7 @@ TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
int link_fd = __llvm_libc::open(TEST_FILE_LINK_PATH, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(link_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE_PATH), Succeeds(0));
diff --git a/libc/test/src/unistd/lseek_test.cpp b/libc/test/src/unistd/lseek_test.cpp
index 065753fe427db..f235f7fcb12eb 100644
--- a/libc/test/src/unistd/lseek_test.cpp
+++ b/libc/test/src/unistd/lseek_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/lseek.h"
@@ -14,14 +15,13 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <unistd.h>
TEST(LlvmLibcUniStd, LseekTest) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
int fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
constexpr const char LSEEK_TEST[] = "lseek test";
constexpr int LSEEK_TEST_SIZE = sizeof(LSEEK_TEST) - 1;
@@ -54,7 +54,7 @@ TEST(LlvmLibcUniStd, LseekFailsTest) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
int fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
EXPECT_THAT(__llvm_libc::lseek(fd, -1, SEEK_CUR), Fails(EINVAL));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
diff --git a/libc/test/src/unistd/pread_pwrite_test.cpp b/libc/test/src/unistd/pread_pwrite_test.cpp
index cfc5e37d43c7c..4cfbeaf6c7936 100644
--- a/libc/test/src/unistd/pread_pwrite_test.cpp
+++ b/libc/test/src/unistd/pread_pwrite_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/fsync.h"
@@ -17,8 +18,6 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
// The strategy here is that we first create a file and write to it. Next,
// we open that file again and write at an offset. Finally, we open the
@@ -34,14 +33,14 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
constexpr const char *TEST_FILE = "testdata/pread_pwrite.test";
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(__llvm_libc::write(fd, HELLO, HELLO_SIZE), Succeeds(HELLO_SIZE));
ASSERT_THAT(__llvm_libc::fsync(fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_WRONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(__llvm_libc::pwrite(fd, HELLO, HELLO_SIZE, OFFSET),
Succeeds(HELLO_SIZE));
@@ -49,7 +48,7 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
char read_buf[OFFSET_TEXT_SIZE];
ASSERT_THAT(__llvm_libc::pread(fd, read_buf, HELLO_SIZE, OFFSET),
diff --git a/libc/test/src/unistd/read_write_test.cpp b/libc/test/src/unistd/read_write_test.cpp
index aa402e2977805..68299f639878a 100644
--- a/libc/test/src/unistd/read_write_test.cpp
+++ b/libc/test/src/unistd/read_write_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/fsync.h"
@@ -15,13 +16,11 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "__unistd_read_write.test";
int write_fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
constexpr const char HELLO[] = "hello";
constexpr int HELLO_SIZE = sizeof(HELLO);
@@ -31,7 +30,7 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
int read_fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(read_fd, 0);
char read_buf[10];
ASSERT_THAT(__llvm_libc::read(read_fd, read_buf, HELLO_SIZE),
diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp
index df02a05429a26..ab9223fffcd80 100644
--- a/libc/test/src/unistd/readlink_test.cpp
+++ b/libc/test/src/unistd/readlink_test.cpp
@@ -7,21 +7,20 @@
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/string_view.h"
+#include "src/errno/libc_errno.h"
#include "src/unistd/readlink.h"
#include "src/unistd/symlink.h"
#include "src/unistd/unlink.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
namespace cpp = __llvm_libc::cpp;
TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char LINK_VAL[] = "readlink_test_value";
constexpr const char LINK[] = "testdata/readlink.test.link";
- errno = 0;
+ libc_errno = 0;
// The test strategy is as follows:
// 1. Create a symlink with value LINK_VAL.
@@ -31,7 +30,7 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
char buf[sizeof(LINK_VAL)];
ssize_t len = __llvm_libc::readlink(LINK, buf, sizeof(buf));
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
ASSERT_THAT(__llvm_libc::unlink(LINK), Succeeds(0));
diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp
index e92ded5b7a479..eb23f2ee85b6f 100644
--- a/libc/test/src/unistd/readlinkat_test.cpp
+++ b/libc/test/src/unistd/readlinkat_test.cpp
@@ -7,13 +7,13 @@
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/string_view.h"
+#include "src/errno/libc_errno.h"
#include "src/unistd/readlinkat.h"
#include "src/unistd/symlink.h"
#include "src/unistd/unlink.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
#include <fcntl.h>
namespace cpp = __llvm_libc::cpp;
@@ -22,7 +22,7 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char LINK_VAL[] = "readlinkat_test_value";
constexpr const char LINK[] = "testdata/readlinkat.test.link";
- errno = 0;
+ libc_errno = 0;
// The test strategy is as follows:
// 1. Create a symlink with value LINK_VAL.
@@ -32,7 +32,7 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
char buf[sizeof(LINK_VAL)];
ssize_t len = __llvm_libc::readlinkat(AT_FDCWD, LINK, buf, sizeof(buf));
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
ASSERT_THAT(__llvm_libc::unlink(LINK), Succeeds(0));
diff --git a/libc/test/src/unistd/rmdir_test.cpp b/libc/test/src/unistd/rmdir_test.cpp
index 1580166c90a4f..a5eb8d3a974c5 100644
--- a/libc/test/src/unistd/rmdir_test.cpp
+++ b/libc/test/src/unistd/rmdir_test.cpp
@@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/sys/stat/mkdir.h"
#include "src/unistd/rmdir.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
TEST(LlvmLibcRmdirTest, CreateAndRemove) {
diff --git a/libc/test/src/unistd/symlink_test.cpp b/libc/test/src/unistd/symlink_test.cpp
index 489ecfd5dda9e..44821e720b875 100644
--- a/libc/test/src/unistd/symlink_test.cpp
+++ b/libc/test/src/unistd/symlink_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/symlink.h"
@@ -13,8 +14,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_BASE = "symlink.test";
@@ -26,9 +25,9 @@ TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
// 2. Create a symlink to that file.
// 3. Open the symlink to check that the symlink was created.
// 4. Cleanup the file and its symlink.
- errno = 0;
+ libc_errno = 0;
int write_fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
@@ -37,7 +36,7 @@ TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
int symlink_fd = __llvm_libc::open(TEST_FILE_LINK, O_PATH);
ASSERT_GT(symlink_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(symlink_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/symlinkat_test.cpp b/libc/test/src/unistd/symlinkat_test.cpp
index 9f4658d275c0c..847bbbf5d5301 100644
--- a/libc/test/src/unistd/symlinkat_test.cpp
+++ b/libc/test/src/unistd/symlinkat_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/symlinkat.h"
@@ -13,8 +14,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
@@ -28,9 +27,9 @@ TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
// 2. Create a link to that file.
// 3. Open the link to check that the link was created.
// 4. Cleanup the file and its link.
- errno = 0;
+ libc_errno = 0;
int write_fd = __llvm_libc::open(TEST_FILE_PATH, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
@@ -40,7 +39,7 @@ TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
int link_fd = __llvm_libc::open(TEST_FILE_LINK_PATH, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_THAT(__llvm_libc::close(link_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::close(dir_fd), Succeeds(0));
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index 7d0cc309806bf..3f95f18041d2b 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/unistd/syscall.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
@@ -26,10 +26,10 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
// because the macro generates a call to the actual internal function
// (__llvm_libc_syscall) which is inside the namespace.
TEST(LlvmLibcSyscallTest, TrivialCall) {
- errno = 0;
+ libc_errno = 0;
ASSERT_GE(__llvm_libc::syscall(SYS_gettid), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
}
TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
@@ -37,15 +37,15 @@ TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
constexpr const char LINK[] = "testdata/syscall_readlink.test.link";
ASSERT_GE(__llvm_libc::syscall(SYS_symlink, LINK_VAL, LINK), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
char buf[sizeof(LINK_VAL)];
ASSERT_GE(__llvm_libc::syscall(SYS_readlink, LINK, buf, sizeof(buf)), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, LINK), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
}
TEST(LlvmLibcSyscallTest, FileReadWrite) {
@@ -57,16 +57,16 @@ TEST(LlvmLibcSyscallTest, FileReadWrite) {
int fd =
__llvm_libc::syscall(SYS_open, TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_GT(fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_pwrite64, fd, HELLO, HELLO_SIZE, 0), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_fsync, fd), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_close, fd), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
}
TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
@@ -86,30 +86,30 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
int write_fd = __llvm_libc::syscall(SYS_open, TEST_FILE_PATH,
O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_GT(write_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_close, write_fd), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
int dir_fd = __llvm_libc::syscall(SYS_open, TEST_DIR, O_DIRECTORY, 0);
ASSERT_GT(dir_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_linkat, dir_fd, TEST_FILE, dir_fd,
TEST_FILE_LINK, 0),
0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
int link_fd = __llvm_libc::syscall(SYS_open, TEST_FILE_LINK_PATH, O_PATH, 0);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, TEST_FILE_PATH), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, TEST_FILE_LINK_PATH), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_close, dir_fd), 0l);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
}
diff --git a/libc/test/src/unistd/truncate_test.cpp b/libc/test/src/unistd/truncate_test.cpp
index 70d6d8944c403..85047d2899305 100644
--- a/libc/test/src/unistd/truncate_test.cpp
+++ b/libc/test/src/unistd/truncate_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/unistd/close.h"
#include "src/unistd/read.h"
@@ -16,8 +17,6 @@
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
-
namespace cpp = __llvm_libc::cpp;
TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
@@ -32,16 +31,16 @@ TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
// 2. Read it to make sure what was written is actually in the file.
// 3. Truncate to 1 byte.
// 4. Try to read more than 1 byte and fail.
- errno = 0;
+ libc_errno = 0;
int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE),
__llvm_libc::write(fd, WRITE_DATA, WRITE_SIZE));
ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE), __llvm_libc::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(cpp::string_view(buf), cpp::string_view(WRITE_DATA));
@@ -50,7 +49,7 @@ TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
ASSERT_THAT(__llvm_libc::truncate(TEST_FILE, off_t(1)), Succeeds(0));
fd = __llvm_libc::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(1), __llvm_libc::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(buf[0], WRITE_DATA[0]);
diff --git a/libc/test/src/unistd/unlink_test.cpp b/libc/test/src/unistd/unlink_test.cpp
index d8588a5a7d744..2f6eeb1cc0c5f 100644
--- a/libc/test/src/unistd/unlink_test.cpp
+++ b/libc/test/src/unistd/unlink_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/unlink.h"
@@ -13,13 +14,11 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/unlink.test";
int write_fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/unlinkat_test.cpp b/libc/test/src/unistd/unlinkat_test.cpp
index 32cecc2d669e3..dbec719dc6635 100644
--- a/libc/test/src/unistd/unlinkat_test.cpp
+++ b/libc/test/src/unistd/unlinkat_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/fcntl/openat.h"
#include "src/unistd/close.h"
@@ -14,18 +15,16 @@
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
-
TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
int dir_fd = __llvm_libc::open(TEST_DIR, O_DIRECTORY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(dir_fd, 0);
int write_fd =
__llvm_libc::openat(dir_fd, TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
ASSERT_THAT(__llvm_libc::unlinkat(dir_fd, TEST_FILE, 0), Succeeds(0));
@@ -35,7 +34,7 @@ TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
TEST(LlvmLibcUnlinkatTest, UnlinkatNonExistentFile) {
constexpr const char *TEST_DIR = "testdata";
int dir_fd = __llvm_libc::open(TEST_DIR, O_DIRECTORY);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(libc_errno, 0);
ASSERT_GT(dir_fd, 0);
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
More information about the libc-commits
mailing list