SRCS
getrandom_test.cpp
DEPENDS
- libc.include.errno
libc.include.math
libc.include.sys_random
libc.src.errno.errno
+//===-- 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"
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) {
//===----------------------------------------------------------------------===//
#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"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <errno.h>
#include <sys/resource.h>
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));
// 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));
//
//===----------------------------------------------------------------------===//
+#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>
// 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);
//===----------------------------------------------------------------------===//
#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"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
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));
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));
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
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
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
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
)
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
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
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
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/stat/chmod.h"
#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
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;
}
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/stat/fchmod.h"
#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
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;
}
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/stat/fchmodat.h"
#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
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),
}
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;
}
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/stat/fstat.h"
#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
// 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));
}
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;
}
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
TEST(LlvmLibcMkdiratTest, CreateAndRemove) {
//
//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/sys/stat/stat.h"
#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
#include "utils/testutils/FDReader.h"
-#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
// 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;
}
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;
}