Merge "Add ASSERT_ERRNO and EXPECT_ERRNO (and use them)." into main am: 68011a4ac7

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2759533

Change-Id: Ie200a94f536c90f9ef92b550c61975548a73f842
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Elliott Hughes 2023-09-22 15:25:41 +00:00 committed by Automerger Merge Worker
commit d5835f3a5a
48 changed files with 525 additions and 447 deletions

View file

@ -29,6 +29,8 @@
#include <set>
#include <string>
#include "utils.h"
static void CheckProcSelf(std::set<std::string>& names) {
// We have a good idea of what should be in /proc/self.
ASSERT_TRUE(names.find(".") != names.end());
@ -124,7 +126,6 @@ static int is_version_filter(const dirent* de) {
TEST(dirent, scandir_filter) {
dirent** entries;
errno = 0;
ASSERT_EQ(1, scandir("/proc", &entries, is_version_filter, nullptr));
ASSERT_STREQ("version", entries[0]->d_name);
free(entries);
@ -134,14 +135,14 @@ TEST(dirent, scandir_ENOENT) {
dirent** entries;
errno = 0;
ASSERT_EQ(-1, scandir("/does-not-exist", &entries, nullptr, nullptr));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(dirent, scandir64_ENOENT) {
dirent64** entries;
errno = 0;
ASSERT_EQ(-1, scandir64("/does-not-exist", &entries, nullptr, nullptr));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(dirent, scandirat_ENOENT) {
@ -151,7 +152,7 @@ TEST(dirent, scandirat_ENOENT) {
dirent** entries;
errno = 0;
ASSERT_EQ(-1, scandirat(root_fd, "does-not-exist", &entries, nullptr, nullptr));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
close(root_fd);
#else
GTEST_SKIP() << "musl doesn't have scandirat or scandirat64";
@ -165,7 +166,7 @@ TEST(dirent, scandirat64_ENOENT) {
dirent64** entries;
errno = 0;
ASSERT_EQ(-1, scandirat64(root_fd, "does-not-exist", &entries, nullptr, nullptr));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
close(root_fd);
#else
GTEST_SKIP() << "musl doesn't have scandirat or scandirat64";
@ -174,12 +175,12 @@ TEST(dirent, scandirat64_ENOENT) {
TEST(dirent, fdopendir_invalid) {
ASSERT_TRUE(fdopendir(-1) == nullptr);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
int fd = open("/dev/null", O_RDONLY);
ASSERT_NE(fd, -1);
ASSERT_TRUE(fdopendir(fd) == nullptr);
ASSERT_EQ(ENOTDIR, errno);
ASSERT_ERRNO(ENOTDIR);
close(fd);
}
@ -193,15 +194,17 @@ TEST(dirent, fdopendir) {
// fdopendir(3) took ownership, so closedir(3) closed our fd.
ASSERT_EQ(close(fd), -1);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(dirent, opendir_invalid) {
errno = 0;
ASSERT_TRUE(opendir("/does/not/exist") == nullptr);
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_TRUE(opendir("/dev/null") == nullptr);
ASSERT_EQ(ENOTDIR, errno);
ASSERT_ERRNO(ENOTDIR);
}
TEST(dirent, opendir) {
@ -215,7 +218,7 @@ TEST(dirent, opendir) {
TEST(dirent, closedir_invalid) {
DIR* d = nullptr;
ASSERT_EQ(closedir(d), -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(dirent, closedir) {
@ -235,7 +238,7 @@ TEST(dirent, readdir) {
}
// Reading to the end of the directory is not an error.
// readdir(3) returns NULL, but leaves errno as 0.
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
@ -252,7 +255,7 @@ TEST(dirent, readdir64_smoke) {
}
// Reading to the end of the directory is not an error.
// readdir64(3) returns NULL, but leaves errno as 0.
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
@ -270,7 +273,7 @@ TEST(dirent, readdir_r) {
}
// Reading to the end of the directory is not an error.
// readdir_r(3) returns NULL, but leaves errno as 0.
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
@ -288,7 +291,7 @@ TEST(dirent, readdir64_r_smoke) {
}
// Reading to the end of the directory is not an error.
// readdir64_r(3) returns NULL, but leaves errno as 0.
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
@ -365,7 +368,7 @@ TEST(dirent, seekdir_telldir) {
ASSERT_EQ(end_offset, telldir(d));
errno = 0;
ASSERT_EQ(nullptr, readdir(d));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(0, closedir(d));
}

View file

@ -835,7 +835,7 @@ TEST(dlfcn, dlclose_unload) {
// this case.
uintptr_t page_start = reinterpret_cast<uintptr_t>(taxicab_number) & ~(PAGE_SIZE - 1);
ASSERT_TRUE(mprotect(reinterpret_cast<void*>(page_start), PAGE_SIZE, PROT_NONE) != 0);
ASSERT_EQ(ENOMEM, errno) << strerror(errno);
ASSERT_ERRNO(ENOMEM);
}
static void ConcurrentDlErrorFn(std::string& error) {

View file

@ -34,7 +34,7 @@ TEST(eventfd, smoke) {
// Reading clears the counter.
ASSERT_EQ(-1, eventfd_read(fd, &value));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
// Values written are added until the next read.
ASSERT_EQ(0, eventfd_write(fd, 1));
@ -88,7 +88,7 @@ TEST(eventfd, semaphore) {
// The counter is cleared after the initial value decrements to 0.
ASSERT_EQ(-1, eventfd_read(fd, &value));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
close(fd);
}

View file

@ -34,6 +34,8 @@
#include <linux/magic.h>
#endif
#include "utils.h"
using fcntl_DeathTest = SilentDeathTest;
TEST(fcntl, fcntl_smoke) {
@ -80,9 +82,9 @@ TEST(fcntl, openat_openat64) {
TEST(fcntl, creat_creat64) {
ASSERT_EQ(-1, creat("", 0666));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
ASSERT_EQ(-1, creat64("", 0666));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(fcntl, posix_fadvise) {
@ -90,16 +92,16 @@ TEST(fcntl, posix_fadvise) {
errno = 0;
EXPECT_EQ(EBADF, posix_fadvise(-1, 0, 0, POSIX_FADV_NORMAL));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(EBADF, posix_fadvise64(-1, 0, 0, POSIX_FADV_NORMAL));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(EINVAL, posix_fadvise(tf.fd, 0, 0, -1));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(EINVAL, posix_fadvise64(tf.fd, 0, 0, -1));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(0, posix_fadvise(tf.fd, 0, 0, POSIX_FADV_NORMAL));
EXPECT_EQ(0, posix_fadvise64(tf.fd, 0, 0, POSIX_FADV_NORMAL));
@ -113,19 +115,19 @@ TEST(fcntl, fallocate_EINVAL) {
errno = 0;
ASSERT_EQ(-1, fallocate(tf.fd, 0, 0, -1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(-1, fallocate64(tf.fd, 0, 0, -1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(EINVAL, posix_fallocate(tf.fd, 0, -1));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
errno = 0;
ASSERT_EQ(EINVAL, posix_fallocate64(tf.fd, 0, -1));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(fcntl, fallocate) {
@ -269,14 +271,14 @@ TEST(fcntl, readahead) {
// Just check that the function is available.
errno = 0;
ASSERT_EQ(-1, readahead(-1, 0, 123));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(fcntl, sync_file_range) {
// Just check that the function is available.
errno = 0;
ASSERT_EQ(-1, sync_file_range(-1, 0, 0, 0));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
TemporaryFile tf;
ASSERT_EQ(0, sync_file_range(tf.fd, 0, 0, 0));
@ -285,7 +287,7 @@ TEST(fcntl, sync_file_range) {
// Check that the `flags` argument gets passed to the kernel correctly.
errno = 0;
ASSERT_EQ(-1, sync_file_range(tf.fd, 0, 0, ~0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
static bool parse_kernel_release(long* const major, long* const minor) {
@ -312,7 +314,7 @@ TEST(fcntl, falloc_punch) {
ASSERT_EQ(0, fstatfs(tf.fd, &sfs));
if (sfs.f_type == EXT4_SUPER_MAGIC) {
ASSERT_EQ(-1, fallocate(tf.fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1));
ASSERT_EQ(errno, EOPNOTSUPP);
ASSERT_ERRNO(EOPNOTSUPP);
}
}
}
@ -355,7 +357,7 @@ TEST(fcntl, open_O_TMPFILE_mode) {
ASSERT_EQ(-1, linkat(AT_FDCWD, android::base::StringPrintf("/proc/self/fd/%d", fd).c_str(),
AT_FDCWD, android::base::StringPrintf("%s/no_chance", dir.path).c_str(),
AT_SYMLINK_FOLLOW));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
ASSERT_EQ(0, close(fd));
#endif
}

View file

@ -40,6 +40,8 @@
#include <android-base/logging.h>
#include <android-base/unique_fd.h>
#include "utils.h"
using android::base::ReceiveFileDescriptors;
using android::base::SendFileDescriptors;
using android::base::unique_fd;
@ -234,7 +236,7 @@ FDTRACK_TEST(socket, socket(AF_UNIX, SOCK_STREAM, 0));
FDTRACK_TEST(pidfd_open, ({
int rc = pidfd_open(getpid(), 0);
if (rc == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_open not available";
}
rc;
@ -244,14 +246,14 @@ FDTRACK_TEST(pidfd_getfd, ({
android_fdtrack_set_enabled(false);
int pidfd_self = pidfd_open(getpid(), 0);
if (pidfd_self == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_open not available";
}
android_fdtrack_set_enabled(true);
int rc = pidfd_getfd(pidfd_self, STDIN_FILENO, 0);
if (rc == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_getfd not available";
}

View file

@ -28,6 +28,8 @@
#include <android-base/stringprintf.h>
#include <gtest/gtest.h>
#include "utils.h"
static void MakeTree(const char* root) {
char path[PATH_MAX];
@ -167,35 +169,35 @@ static int null_nftw_callback(const char*, const StatT*, int, FTW*) {
TEST(ftw, ftw_non_existent_ENOENT) {
errno = 0;
ASSERT_EQ(-1, ftw("/does/not/exist", null_ftw_callback<struct stat>, 128));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, ftw64("/does/not/exist", null_ftw_callback<struct stat64>, 128));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(ftw, nftw_non_existent_ENOENT) {
errno = 0;
ASSERT_EQ(-1, nftw("/does/not/exist", null_nftw_callback<struct stat>, 128, FTW_PHYS));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, nftw64("/does/not/exist", null_nftw_callback<struct stat64>, 128, FTW_PHYS));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(ftw, ftw_empty_ENOENT) {
errno = 0;
ASSERT_EQ(-1, ftw("", null_ftw_callback<struct stat>, 128));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, ftw64("", null_ftw_callback<struct stat64>, 128));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(ftw, nftw_empty_ENOENT) {
errno = 0;
ASSERT_EQ(-1, nftw("", null_nftw_callback<struct stat>, 128, FTW_PHYS));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, nftw64("", null_nftw_callback<struct stat64>, 128, FTW_PHYS));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}

View file

@ -21,6 +21,8 @@
#include <sys/utsname.h>
#include <gtest/gtest.h>
#include "utils.h"
TEST(getauxval, expected_values) {
ASSERT_EQ(0UL, getauxval(AT_SECURE));
ASSERT_EQ(getuid(), getauxval(AT_UID));
@ -38,7 +40,7 @@ TEST(getauxval, expected_values) {
TEST(getauxval, unexpected_values) {
errno = 0;
ASSERT_EQ(0UL, getauxval(0xdeadbeef));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(getauxval, arm_has_AT_HWCAP2) {
@ -57,7 +59,7 @@ TEST(getauxval, arm_has_AT_HWCAP2) {
// to check errno to see whether we got a "true" 0 or a "not found" 0.
errno = 0;
getauxval(AT_HWCAP2);
ASSERT_EQ(0, errno) << "64-bit kernel not reporting AT_HWCAP2 to 32-bit ARM process";
ASSERT_ERRNO(0) << "64-bit kernel not reporting AT_HWCAP2 to 32-bit ARM process";
return;
}
#endif

View file

@ -29,7 +29,7 @@ TEST(getcwd, auto_full) {
errno = 0;
char* cwd = getcwd(nullptr, 0);
ASSERT_TRUE(cwd != nullptr);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
@ -39,7 +39,7 @@ TEST(getcwd, auto_reasonable) {
errno = 0;
char* cwd = getcwd(nullptr, PATH_MAX);
ASSERT_TRUE(cwd != nullptr);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
@ -49,7 +49,7 @@ TEST(getcwd, auto_too_small) {
errno = 0;
char* cwd = getcwd(nullptr, 1);
ASSERT_TRUE(cwd == nullptr);
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
}
TEST(getcwd, auto_too_large) {
@ -58,7 +58,7 @@ TEST(getcwd, auto_too_large) {
errno = 0;
char* cwd = getcwd(nullptr, static_cast<size_t>(-1));
ASSERT_TRUE(cwd == nullptr);
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
TEST(getcwd, manual_too_small) {
@ -67,7 +67,7 @@ TEST(getcwd, manual_too_small) {
errno = 0;
char* cwd = getcwd(tiny_buf, sizeof(tiny_buf));
ASSERT_TRUE(cwd == nullptr);
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
}
TEST(getcwd, manual_zero) {
@ -76,7 +76,7 @@ TEST(getcwd, manual_zero) {
errno = 0;
char* cwd = getcwd(tiny_buf, 0);
ASSERT_TRUE(cwd == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(getcwd, manual_path_max) {
@ -84,7 +84,7 @@ TEST(getcwd, manual_path_max) {
errno = 0;
char* cwd = getcwd(buf, PATH_MAX);
ASSERT_TRUE(cwd == buf);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_GE(strlen(cwd), 1U);
delete[] cwd;
}

View file

@ -41,6 +41,8 @@
// Generated android_ids array
#include "generated_android_ids.h"
#include "utils.h"
using android::base::Join;
using android::base::ReadFileToString;
using android::base::Split;
@ -86,7 +88,7 @@ static void check_getpwuid(const char* username, uid_t uid, uid_type_t uid_type,
bool check_username) {
errno = 0;
passwd* pwd = getpwuid(uid);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getpwuid");
check_passwd(pwd, username, uid, uid_type, check_username);
}
@ -95,7 +97,7 @@ static void check_getpwnam(const char* username, uid_t uid, uid_type_t uid_type,
bool check_username) {
errno = 0;
passwd* pwd = getpwnam(username);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getpwnam");
check_passwd(pwd, username, uid, uid_type, check_username);
}
@ -110,7 +112,7 @@ static void check_getpwuid_r(const char* username, uid_t uid, uid_type_t uid_typ
passwd* pwd = nullptr;
result = getpwuid_r(uid, &pwd_storage, buf, sizeof(buf), &pwd);
ASSERT_EQ(0, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getpwuid_r");
check_passwd(pwd, username, uid, uid_type, check_username);
}
@ -125,7 +127,7 @@ static void check_getpwnam_r(const char* username, uid_t uid, uid_type_t uid_typ
passwd* pwd = nullptr;
result = getpwnam_r(username, &pwd_storage, buf, sizeof(buf), &pwd);
ASSERT_EQ(0, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getpwnam_r");
check_passwd(pwd, username, uid, uid_type, check_username);
}
@ -145,7 +147,7 @@ static void expect_no_passwd_id(uid_t uid) {
passwd* passwd = nullptr;
passwd = getpwuid(uid);
EXPECT_EQ(nullptr, passwd) << "name = '" << passwd->pw_name << "'";
EXPECT_EQ(ENOENT, errno);
EXPECT_ERRNO(ENOENT);
struct passwd passwd_storage;
char buf[512];
@ -159,7 +161,7 @@ static void expect_no_passwd_name(const char* username) {
passwd* passwd = nullptr;
passwd = getpwnam(username);
EXPECT_EQ(nullptr, passwd) << "name = '" << passwd->pw_name << "'";
EXPECT_EQ(ENOENT, errno);
EXPECT_ERRNO(ENOENT);
struct passwd passwd_storage;
char buf[512];
@ -507,7 +509,7 @@ static void check_group(const group* grp, const char* group_name, gid_t gid,
static void check_getgrgid(const char* group_name, gid_t gid, bool check_groupname) {
errno = 0;
group* grp = getgrgid(gid);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getgrgid");
check_group(grp, group_name, gid, check_groupname);
}
@ -515,7 +517,7 @@ static void check_getgrgid(const char* group_name, gid_t gid, bool check_groupna
static void check_getgrnam(const char* group_name, gid_t gid, bool check_groupname) {
errno = 0;
group* grp = getgrnam(group_name);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getgrnam");
check_group(grp, group_name, gid, check_groupname);
}
@ -528,7 +530,7 @@ static void check_getgrgid_r(const char* group_name, gid_t gid, bool check_group
errno = 0;
int result = getgrgid_r(gid, &grp_storage, buf, sizeof(buf), &grp);
ASSERT_EQ(0, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getgrgid_r");
check_group(grp, group_name, gid, check_groupname);
}
@ -541,7 +543,7 @@ static void check_getgrnam_r(const char* group_name, gid_t gid, bool check_group
errno = 0;
int result = getgrnam_r(group_name, &grp_storage, buf, sizeof(buf), &grp);
ASSERT_EQ(0, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
SCOPED_TRACE("getgrnam_r");
check_group(grp, group_name, gid, check_groupname);
}
@ -560,7 +562,7 @@ static void expect_no_group_id(gid_t gid) {
group* group = nullptr;
group = getgrgid(gid);
EXPECT_EQ(nullptr, group) << "name = '" << group->gr_name << "'";
EXPECT_EQ(ENOENT, errno);
EXPECT_ERRNO(ENOENT);
struct group group_storage;
char buf[512];
@ -574,7 +576,7 @@ static void expect_no_group_name(const char* groupname) {
group* group = nullptr;
group = getgrnam(groupname);
EXPECT_EQ(nullptr, group) << "name = '" << group->gr_name << "'";
EXPECT_EQ(ENOENT, errno);
EXPECT_ERRNO(ENOENT);
struct group group_storage;
char buf[512];

View file

@ -18,18 +18,20 @@
#include <iconv.h>
#include "utils.h"
#define INVALID_ICONV_T reinterpret_cast<iconv_t>(-1)
TEST(iconv, iconv_open_EINVAL) {
errno = 0;
ASSERT_EQ(INVALID_ICONV_T, iconv_open("silly", "silly"));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(INVALID_ICONV_T, iconv_open("silly", "UTF-8"));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(INVALID_ICONV_T, iconv_open("UTF-8", "silly"));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(iconv, iconv_open_comparator) {
@ -44,10 +46,10 @@ TEST(iconv, iconv_open_comparator) {
// "...but not "utf-80" or "ut8"."
errno = 0;
ASSERT_EQ(INVALID_ICONV_T, iconv_open("UTF-8", "utf-80"));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(INVALID_ICONV_T, iconv_open("UTF-8", "ut80"));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(iconv, iconv_smoke) {
@ -122,7 +124,7 @@ TEST(iconv, iconv_lossy_IGNORE) {
// With "//IGNORE", we just skip them (but return failure).
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_EQ('a', buf[0]);
EXPECT_EQ('z', buf[1]);
@ -149,7 +151,7 @@ TEST(iconv, iconv_lossy) {
// The second input character isn't representable as ASCII, so we stop there.
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_EQ('a', buf[0]);
EXPECT_EQ(0, buf[1]);
@ -175,13 +177,13 @@ TEST(iconv, iconv_malformed_sequence_EILSEQ) {
// The second input byte is a malformed character, so we stop there.
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_EQ('\xd9', *in); // *in is left pointing to the start of the invalid sequence.
++in;
--in_bytes;
errno = 0;
EXPECT_EQ(0U, iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ('a', buf[0]);
EXPECT_EQ('z', buf[1]);
@ -208,7 +210,7 @@ TEST(iconv, iconv_incomplete_sequence_EINVAL) {
// The second input byte is just the start of a character, and we don't have any more bytes.
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ('\xd9', *in); // *in is left pointing to the start of the incomplete sequence.
EXPECT_EQ('a', buf[0]);
@ -236,7 +238,7 @@ TEST(iconv, iconv_E2BIG) {
out_bytes = 1;
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(E2BIG, errno);
EXPECT_ERRNO(E2BIG);
EXPECT_EQ(2U, in_bytes);
EXPECT_EQ(0U, out_bytes);
@ -244,7 +246,7 @@ TEST(iconv, iconv_E2BIG) {
out_bytes = 0;
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(E2BIG, errno);
EXPECT_ERRNO(E2BIG);
EXPECT_EQ(2U, in_bytes);
EXPECT_EQ(0U, out_bytes);
@ -252,7 +254,7 @@ TEST(iconv, iconv_E2BIG) {
out_bytes = 1;
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(E2BIG, errno);
EXPECT_ERRNO(E2BIG);
EXPECT_EQ(1U, in_bytes);
EXPECT_EQ(0U, out_bytes);
@ -260,7 +262,7 @@ TEST(iconv, iconv_E2BIG) {
out_bytes = 1;
errno = 0;
EXPECT_EQ(0U, iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(0U, in_bytes);
EXPECT_EQ(0U, out_bytes);
@ -279,13 +281,13 @@ TEST(iconv, iconv_invalid_converter_EBADF) {
size_t out_bytes = 0;
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), iconv(INVALID_ICONV_T, &in, &in_bytes, &out, &out_bytes));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(iconv, iconv_close_invalid_converter_EBADF) {
errno = 0;
ASSERT_EQ(-1, iconv_close(INVALID_ICONV_T));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
static void RoundTrip(const char* dst_enc, const char* expected_bytes, size_t n) {
@ -368,7 +370,7 @@ static void Check(int expected_errno, const char* src_enc, const char* src, size
char* out = reinterpret_cast<char*>(out_buf);
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(expected_errno, errno);
EXPECT_ERRNO(expected_errno);
EXPECT_EQ(0, iconv_close(c));
}
@ -442,13 +444,13 @@ TEST(iconv, iconv_initial_shift_state) {
// Points to a null pointer...
errno = 0;
ASSERT_EQ(static_cast<size_t>(0), iconv(c, &in, &in_bytes, &out, &out_bytes));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(sizeof(out_buf), out_bytes);
// Is a null pointer...
errno = 0;
ASSERT_EQ(static_cast<size_t>(0), iconv(c, nullptr, &in_bytes, &out, &out_bytes));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(sizeof(out_buf), out_bytes);
// Is a null pointer and so is in_bytes. This isn't specified by POSIX, but
@ -456,7 +458,7 @@ TEST(iconv, iconv_initial_shift_state) {
// https://issuetracker.google.com/180598400
errno = 0;
ASSERT_EQ(static_cast<size_t>(0), iconv(c, nullptr, nullptr, &out, &out_bytes));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(sizeof(out_buf), out_bytes);
EXPECT_EQ(0, iconv_close(c));

View file

@ -32,6 +32,8 @@
#include <thread>
#include <vector>
#include "utils.h"
TEST(ifaddrs, freeifaddrs_null) {
freeifaddrs(nullptr);
}
@ -294,7 +296,7 @@ TEST(ifaddrs, errno_EMFILE) {
while (true) {
int fd = open("/dev/null", O_RDONLY|O_CLOEXEC);
if (fd == -1) {
ASSERT_EQ(EMFILE, errno);
ASSERT_ERRNO(EMFILE);
break;
}
fds.push_back(fd);
@ -302,7 +304,7 @@ TEST(ifaddrs, errno_EMFILE) {
ifaddrs* addrs;
EXPECT_EQ(-1, getifaddrs(&addrs));
EXPECT_EQ(EMFILE, errno);
EXPECT_ERRNO(EMFILE);
for (int fd : fds) close(fd);
}

View file

@ -20,6 +20,8 @@
#include <gtest/gtest.h>
#include <stdio.h>
#include "utils.h"
#define PRINTF_TYPED(FMT_SUFFIX, TYPE_SUFFIX) \
do { \
char buf[512]; \
@ -124,13 +126,13 @@ TEST(inttypes, strtoimax_hex) {
TEST(inttypes, strtoimax_EINVAL) {
errno = 0;
strtoimax("123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
strtoimax("123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
strtoimax("123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(inttypes, strtoumax_dec) {
@ -154,37 +156,37 @@ TEST(inttypes, strtoumax_negative) {
TEST(inttypes, strtoumax_EINVAL) {
errno = 0;
strtoumax("123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
strtoumax("123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
strtoumax("123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(inttypes, wcstoimax_EINVAL) {
errno = 0;
wcstoimax(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoimax(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoimax(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(inttypes, wcstoumax_EINVAL) {
errno = 0;
wcstoumax(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoumax(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoumax(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(inttypes, div) {

View file

@ -48,7 +48,7 @@ static void WaitUntilAllThreadsExited(pid_t* tids, size_t tid_count) {
if (syscall(__NR_tgkill, getpid(), tids[i], 0) == 0) {
alive = true;
} else {
EXPECT_EQ(errno, ESRCH);
EXPECT_ERRNO(ESRCH);
tids[i] = 0; // Skip in next loop.
}
}

View file

@ -20,6 +20,8 @@
#include <limits.h>
#include <locale.h>
#include "utils.h"
TEST(locale, localeconv) {
EXPECT_STREQ(".", localeconv()->decimal_point);
EXPECT_STREQ("", localeconv()->thousands_sep);
@ -53,10 +55,10 @@ TEST(locale, setlocale) {
errno = 0;
EXPECT_EQ(nullptr, setlocale(-1, nullptr));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
errno = 0;
EXPECT_EQ(nullptr, setlocale(13, nullptr));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
#if defined(__BIONIC__)
// The "" locale is implementation-defined. For bionic, it's the C.UTF-8 locale, which is
@ -69,13 +71,13 @@ TEST(locale, setlocale) {
errno = 0;
EXPECT_EQ(nullptr, setlocale(LC_ALL, "this-is-not-a-locale"));
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
EXPECT_ERRNO(ENOENT); // POSIX specified, not an implementation detail!
}
TEST(locale, newlocale_invalid_category_mask) {
errno = 0;
EXPECT_EQ(nullptr, newlocale(1 << 20, "C", nullptr));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
}
TEST(locale, newlocale_NULL_locale_name) {
@ -83,14 +85,14 @@ TEST(locale, newlocale_NULL_locale_name) {
#pragma clang diagnostic ignored "-Wnonnull"
errno = 0;
EXPECT_EQ(nullptr, newlocale(LC_ALL, nullptr, nullptr));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
#pragma clang diagnostic pop
}
TEST(locale, newlocale_bad_locale_name) {
errno = 0;
EXPECT_EQ(nullptr, newlocale(LC_ALL, "this-is-not-a-locale", nullptr));
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
EXPECT_ERRNO(ENOENT); // POSIX specified, not an implementation detail!
}
TEST(locale, newlocale) {

View file

@ -83,7 +83,7 @@ TEST(malloc, malloc_overflow) {
SKIP_WITH_HWASAN;
errno = 0;
ASSERT_EQ(nullptr, malloc(SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
TEST(malloc, calloc_std) {
@ -120,23 +120,23 @@ TEST(malloc, calloc_illegal) {
SKIP_WITH_HWASAN;
errno = 0;
ASSERT_EQ(nullptr, calloc(-1, 100));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
TEST(malloc, calloc_overflow) {
SKIP_WITH_HWASAN;
errno = 0;
ASSERT_EQ(nullptr, calloc(1, SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
errno = 0;
ASSERT_EQ(nullptr, calloc(SIZE_MAX, SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
errno = 0;
ASSERT_EQ(nullptr, calloc(2, SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
errno = 0;
ASSERT_EQ(nullptr, calloc(SIZE_MAX, 2));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
TEST(malloc, memalign_multiple) {
@ -346,12 +346,12 @@ TEST(malloc, realloc_overflow) {
SKIP_WITH_HWASAN;
errno = 0;
ASSERT_EQ(nullptr, realloc(nullptr, SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
void* ptr = malloc(100);
ASSERT_TRUE(ptr != nullptr);
errno = 0;
ASSERT_EQ(nullptr, realloc(ptr, SIZE_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
free(ptr);
}
@ -669,7 +669,7 @@ TEST(malloc, mallopt_smoke) {
errno = 0;
ASSERT_EQ(0, mallopt(-1000, 1));
// mallopt doesn't set errno.
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#else
GTEST_SKIP() << "bionic-only test";
#endif
@ -678,7 +678,6 @@ TEST(malloc, mallopt_smoke) {
TEST(malloc, mallopt_decay) {
#if defined(__BIONIC__)
SKIP_WITH_HWASAN << "hwasan does not implement mallopt";
errno = 0;
ASSERT_EQ(1, mallopt(M_DECAY_TIME, 1));
ASSERT_EQ(1, mallopt(M_DECAY_TIME, 0));
ASSERT_EQ(1, mallopt(M_DECAY_TIME, 1));
@ -691,7 +690,6 @@ TEST(malloc, mallopt_decay) {
TEST(malloc, mallopt_purge) {
#if defined(__BIONIC__)
SKIP_WITH_HWASAN << "hwasan does not implement mallopt";
errno = 0;
ASSERT_EQ(1, mallopt(M_PURGE, 0));
#else
GTEST_SKIP() << "bionic-only test";
@ -701,7 +699,6 @@ TEST(malloc, mallopt_purge) {
TEST(malloc, mallopt_purge_all) {
#if defined(__BIONIC__)
SKIP_WITH_HWASAN << "hwasan does not implement mallopt";
errno = 0;
ASSERT_EQ(1, mallopt(M_PURGE_ALL, 0));
#else
GTEST_SKIP() << "bionic-only test";
@ -797,11 +794,11 @@ TEST(malloc, reallocarray_overflow) {
errno = 0;
ASSERT_TRUE(reallocarray(nullptr, a, b) == nullptr);
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
errno = 0;
ASSERT_TRUE(reallocarray(nullptr, b, a) == nullptr);
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
#else
GTEST_SKIP() << "reallocarray not available";
#endif
@ -1120,7 +1117,7 @@ TEST(android_mallopt, error_on_unexpected_option) {
const int unrecognized_option = -1;
errno = 0;
EXPECT_EQ(false, android_mallopt(unrecognized_option, nullptr, 0));
EXPECT_EQ(ENOTSUP, errno);
EXPECT_ERRNO(ENOTSUP);
#else
GTEST_SKIP() << "bionic-only test";
#endif
@ -1151,11 +1148,11 @@ TEST(android_mallopt, init_zygote_child_profiling) {
errno = 0;
if (IsDynamic()) {
EXPECT_EQ(true, android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0));
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
} else {
// Not supported in static executables.
EXPECT_EQ(false, android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0));
EXPECT_EQ(ENOTSUP, errno);
EXPECT_ERRNO(ENOTSUP);
}
// Unexpected arguments rejected.
@ -1163,9 +1160,9 @@ TEST(android_mallopt, init_zygote_child_profiling) {
char unexpected = 0;
EXPECT_EQ(false, android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, &unexpected, 1));
if (IsDynamic()) {
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
} else {
EXPECT_EQ(ENOTSUP, errno);
EXPECT_ERRNO(ENOTSUP);
}
#else
GTEST_SKIP() << "bionic-only test";

View file

@ -22,6 +22,8 @@
#include <linux/membarrier.h>
#include <sys/syscall.h>
#include "utils.h"
class ScopedErrnoCleaner {
public:
ScopedErrnoCleaner() { errno = 0; }
@ -92,7 +94,7 @@ static void TestRegisterAndBarrierCommands(int membarrier_cmd_register,
} else {
// Private barrier should fail.
ASSERT_EQ(-1, syscall(__NR_membarrier, membarrier_cmd_barrier, 0));
ASSERT_EQ(EPERM, errno);
ASSERT_ERRNO(EPERM);
errno = 0;
}

View file

@ -23,6 +23,8 @@
#include <android-base/macros.h>
#include "utils.h"
static constexpr uint16_t le16 = 0x1234;
static constexpr uint32_t le32 = 0x12345678;
static constexpr uint64_t le64 = 0x123456789abcdef0;
@ -41,7 +43,7 @@ TEST(netinet_in, bindresvport) {
sockaddr_in sin = {.sin_family = AF_INET6};
errno = 0;
ASSERT_EQ(-1, bindresvport(-1, &sin));
ASSERT_EQ(EPFNOSUPPORT, errno);
ASSERT_ERRNO(EPFNOSUPPORT);
#else
GTEST_SKIP() << "musl doesn't support bindresvport";
#endif

View file

@ -19,6 +19,8 @@
#include <errno.h>
#include <gtest/gtest.h>
#include "utils.h"
TEST(nl_types, smoke) {
nl_catd cat = catopen("/does/not/exist", NL_CAT_LOCALE);
ASSERT_EQ(reinterpret_cast<nl_catd>(-1), cat);
@ -27,5 +29,5 @@ TEST(nl_types, smoke) {
errno = 0;
ASSERT_EQ(-1, catclose(cat));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}

View file

@ -29,6 +29,8 @@
#include <android-base/silent_death_test.h>
#include <android-base/unique_fd.h>
#include "utils.h"
using android::base::unique_fd;
using namespace std::chrono_literals;
@ -44,14 +46,14 @@ TEST(pidfd, pidfd_open) {
unique_fd pidfd(pidfd_open(child, 0));
if (pidfd.get() == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_open not available";
}
siginfo_t siginfo;
int rc = waitid(P_PIDFD, pidfd.get(), &siginfo, WEXITED);
if (rc == -1) {
ASSERT_EQ(EINVAL, errno) << strerror(errno);
ASSERT_ERRNO(EINVAL);
GTEST_SKIP() << "P_PIDFD not available";
}
@ -65,13 +67,13 @@ TEST(pidfd, pidfd_getfd) {
ASSERT_TRUE(android::base::Pipe(&r, &w));
unique_fd self(pidfd_open(getpid(), 0));
if (self.get() == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_open not available";
}
unique_fd dup(pidfd_getfd(self.get(), r.get(), 0));
if (dup.get() == -1) {
ASSERT_EQ(ENOSYS, errno) << strerror(errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_getfd not available";
}
@ -87,12 +89,12 @@ TEST_F(pidfd_DeathTest, pidfd_send_signal) {
#if defined(__BIONIC__)
unique_fd self(pidfd_open(getpid(), 0));
if (self.get() == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_open not available";
}
if (pidfd_send_signal(self.get(), 0, nullptr, 0) == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "pidfd_send_signal not available";
}

View file

@ -31,11 +31,13 @@
#include <errno.h>
#include <poll.h>
#include "utils.h"
TEST(poll, poll_null_fds) {
// Because nanosleep(2) is relatively new to POSIX, code sometimes abuses poll.
errno = 0;
ASSERT_EQ(0, poll(nullptr, 0, 1));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(poll, ppoll_null_fds) {
@ -43,7 +45,7 @@ TEST(poll, ppoll_null_fds) {
errno = 0;
timespec ts = { .tv_nsec = 100 };
ASSERT_EQ(0, ppoll(nullptr, 0, &ts, nullptr));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(poll, ppoll64_null_fds) {
@ -52,6 +54,6 @@ TEST(poll, ppoll64_null_fds) {
errno = 0;
timespec ts = { .tv_nsec = 100 };
ASSERT_EQ(0, ppoll64(nullptr, 0, &ts, nullptr));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#endif
}

View file

@ -585,7 +585,7 @@ TEST(pthread, pthread_kill__exited_thread) {
while (TEMP_FAILURE_RETRY(syscall(__NR_tgkill, getpid(), tid, 0)) != -1) {
continue;
}
ASSERT_EQ(ESRCH, errno);
ASSERT_ERRNO(ESRCH);
ASSERT_EQ(ESRCH, pthread_kill(thread, 0));
}

View file

@ -21,6 +21,8 @@
#include <sys/types.h>
#include <sys/wait.h>
#include "utils.h"
static int child_fn(void* i_ptr) {
*reinterpret_cast<int*>(i_ptr) = 42;
return 123;
@ -57,14 +59,14 @@ TEST(sched, clone_errno) {
errno = 0;
// If CLONE_THREAD is set, CLONE_SIGHAND must be set too.
ASSERT_EQ(-1, clone(child_fn, &fake_child_stack[16], CLONE_THREAD, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sched, clone_null_child_stack) {
int i = 0;
errno = 0;
ASSERT_EQ(-1, clone(child_fn, nullptr, CLONE_VM, &i));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sched, cpu_set) {
@ -289,7 +291,7 @@ TEST(sched, sched_getscheduler_sched_setscheduler) {
p.sched_priority = sched_get_priority_min(original_policy);
errno = 0;
ASSERT_EQ(-1, sched_setscheduler(getpid(), INT_MAX, &p));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
ASSERT_EQ(0, sched_getparam(getpid(), &p));
ASSERT_EQ(original_policy, sched_setscheduler(getpid(), SCHED_BATCH, &p));

View file

@ -18,6 +18,8 @@
#include <search.h>
#include "utils.h"
static int int_cmp(const void* lhs, const void* rhs) {
return *reinterpret_cast<const int*>(rhs) - *reinterpret_cast<const int*>(lhs);
}
@ -276,7 +278,7 @@ TEST(search, hcreate_r_hsearch_r_hdestroy_r) {
// Check missing.
errno = 0;
ASSERT_EQ(0, hsearch_r(ENTRY{.key = const_cast<char*>("b"), .data = nullptr}, FIND, &e, &h1));
ASSERT_EQ(ESRCH, errno);
ASSERT_ERRNO(ESRCH);
// Check present.
ASSERT_EQ(1, hsearch_r(ENTRY{.key = const_cast<char*>("a"), .data = nullptr}, FIND, &e, &h1));

View file

@ -28,6 +28,8 @@
#include "SignalUtils.h"
#include "private/bionic_constants.h"
#include "utils.h"
using semaphore_DeathTest = SilentDeathTest;
TEST(semaphore, sem_init) {
@ -41,7 +43,7 @@ TEST(semaphore, sem_init) {
// Too small an initial value.
errno = 0;
ASSERT_EQ(-1, sem_init(&s, 0, -1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
ASSERT_EQ(SEM_VALUE_MAX, sysconf(_SC_SEM_VALUE_MAX));
@ -51,7 +53,7 @@ TEST(semaphore, sem_init) {
// Too large an initial value.
errno = 0;
ASSERT_EQ(-1, sem_init(&s, 0, SEM_VALUE_MAX + 1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
ASSERT_EQ(0, sem_destroy(&s));
}
@ -64,7 +66,7 @@ TEST(semaphore, sem_trywait) {
ASSERT_EQ(0, sem_trywait(&s));
errno = 0;
ASSERT_EQ(-1, sem_trywait(&s));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
ASSERT_EQ(0, sem_destroy(&s));
}
@ -116,23 +118,23 @@ static void sem_timedwait_helper(clockid_t clock,
errno = 0;
ASSERT_EQ(-1, wait_function(&s, &ts));
ASSERT_EQ(ETIMEDOUT, errno);
ASSERT_ERRNO(ETIMEDOUT);
// A negative timeout is an error.
errno = 0;
ts.tv_nsec = -1;
ASSERT_EQ(-1, wait_function(&s, &ts));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ts.tv_nsec = NS_PER_S;
ASSERT_EQ(-1, wait_function(&s, &ts));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ts.tv_nsec = NS_PER_S - 1;
ts.tv_sec = -1;
ASSERT_EQ(-1, wait_function(&s, &ts));
ASSERT_EQ(ETIMEDOUT, errno);
ASSERT_ERRNO(ETIMEDOUT);
ASSERT_EQ(0, sem_destroy(&s));
}

View file

@ -56,13 +56,13 @@ static void TestSigSet1(int (fn)(SigSetT*)) {
SigSetT* set_ptr = nullptr;
errno = 0;
ASSERT_EQ(-1, fn(set_ptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Non-nullptr.
SigSetT set = {};
errno = 0;
ASSERT_EQ(0, fn(&set));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
template <typename SigSetT>
@ -71,26 +71,26 @@ static void TestSigSet2(int (fn)(SigSetT*, int)) {
SigSetT* set_ptr = nullptr;
errno = 0;
ASSERT_EQ(-1, fn(set_ptr, SIGSEGV));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
SigSetT set = {};
// Bad signal number: too small.
errno = 0;
ASSERT_EQ(-1, fn(&set, 0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Bad signal number: too high.
errno = 0;
ASSERT_EQ(-1, fn(&set, SIGNAL_MAX(&set) + 1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Good signal numbers, low and high ends of range.
errno = 0;
ASSERT_EQ(0, fn(&set, SIGNAL_MIN()));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(0, fn(&set, SIGNAL_MAX(&set)));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(signal, sigaddset_invalid) {
@ -146,7 +146,7 @@ TEST(signal, sigismember64_invalid) {
TEST(signal, raise_invalid) {
errno = 0;
ASSERT_EQ(-1, raise(-1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
static void raise_in_signal_handler_helper(int signal_number) {
@ -199,7 +199,7 @@ TEST(signal, sigsuspend_sigpending) {
sigfillset(&not_SIGALRM);
sigdelset(&not_SIGALRM, SIGALRM);
ASSERT_EQ(-1, sigsuspend(&not_SIGALRM));
ASSERT_EQ(EINTR, errno);
ASSERT_ERRNO(EINTR);
// ...and check that we now receive our pending SIGALRM.
ASSERT_EQ(1, g_sigsuspend_signal_handler_call_count);
}
@ -241,7 +241,7 @@ TEST(signal, sigsuspend64_sigpending64) {
sigfillset64(&not_SIGRTMIN);
sigdelset64(&not_SIGRTMIN, SIGRTMIN);
ASSERT_EQ(-1, sigsuspend64(&not_SIGRTMIN));
ASSERT_EQ(EINTR, errno);
ASSERT_ERRNO(EINTR);
// ...and check that we now receive our pending SIGRTMIN.
ASSERT_EQ(1, g_sigsuspend64_signal_handler_call_count);
}
@ -598,7 +598,7 @@ TEST(signal, sigqueue) {
sigval sigval = {.sival_int = 1};
errno = 0;
ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(1, g_sigqueue_signal_handler_call_count);
}
@ -608,7 +608,7 @@ TEST(signal, pthread_sigqueue_self) {
sigval sigval = {.sival_int = 1};
errno = 0;
ASSERT_EQ(0, pthread_sigqueue(pthread_self(), SIGALRM, sigval));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(1, g_sigqueue_signal_handler_call_count);
#else
GTEST_SKIP() << "musl doesn't have pthread_sigqueue";
@ -636,7 +636,7 @@ TEST(signal, pthread_sigqueue_other) {
errno = 0;
ASSERT_EQ(0, pthread_sigqueue(thread, SIGALRM, sigval));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
pthread_join(thread, nullptr);
ASSERT_EQ(1, g_sigqueue_signal_handler_call_count);
#else
@ -699,7 +699,7 @@ TEST(signal, sigwaitinfo) {
siginfo_t info;
errno = 0;
ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(SIGALRM, info.si_signo);
ASSERT_EQ(1, info.si_value.sival_int);
}
@ -721,7 +721,7 @@ TEST(signal, sigwaitinfo64_SIGRTMIN) {
siginfo_t info;
errno = 0;
ASSERT_EQ(SIGRTMIN, sigwaitinfo64(&just_SIGRTMIN, &info));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ(SIGRTMIN, info.si_signo);
ASSERT_EQ(1, info.si_value.sival_int);
}
@ -744,7 +744,7 @@ TEST(signal, sigtimedwait) {
timespec timeout = { .tv_sec = 2, .tv_nsec = 0 };
errno = 0;
ASSERT_EQ(SIGALRM, sigtimedwait(&just_SIGALRM, &info, &timeout));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(signal, sigtimedwait64_SIGRTMIN) {
@ -765,7 +765,7 @@ TEST(signal, sigtimedwait64_SIGRTMIN) {
timespec timeout = { .tv_sec = 2, .tv_nsec = 0 };
errno = 0;
ASSERT_EQ(SIGRTMIN, sigtimedwait64(&just_SIGRTMIN, &info, &timeout));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(signal, sigtimedwait_timeout) {
@ -782,7 +782,7 @@ TEST(signal, sigtimedwait_timeout) {
timespec timeout = { .tv_sec = 0, .tv_nsec = 1000000 };
errno = 0;
ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
auto t1 = std::chrono::steady_clock::now();
ASSERT_GE(t1-t0, 1000000ns);
@ -836,17 +836,17 @@ TEST(signal, sigset_size) {
TEST(signal, sigignore_EINVAL) {
errno = 0;
ASSERT_EQ(-1, sigignore(99999));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(signal, sigignore) {
errno = 0;
EXPECT_EQ(-1, sigignore(SIGKILL));
EXPECT_EQ(errno, EINVAL);
EXPECT_ERRNO(EINVAL);
errno = 0;
EXPECT_EQ(-1, sigignore(SIGSTOP));
EXPECT_EQ(errno, EINVAL);
EXPECT_ERRNO(EINVAL);
ScopedSignalHandler sigalrm{SIGALRM};
ASSERT_EQ(0, sigignore(SIGALRM));
@ -859,19 +859,19 @@ TEST(signal, sigignore) {
TEST(signal, sighold_EINVAL) {
errno = 0;
ASSERT_EQ(-1, sighold(99999));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(signal, sigpause_EINVAL) {
errno = 0;
ASSERT_EQ(-1, sigpause(99999));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(signal, sigrelse_EINVAL) {
errno = 0;
ASSERT_EQ(-1, sigpause(99999));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
static void TestSigholdSigpauseSigrelse(int sig) {
@ -890,7 +890,7 @@ static void TestSigholdSigpauseSigrelse(int sig) {
ASSERT_EQ(0, signal_handler_call_count);
// ... until sigpause(SIGALRM/SIGRTMIN) temporarily unblocks it.
ASSERT_EQ(-1, sigpause(sig));
ASSERT_EQ(EINTR, errno);
ASSERT_ERRNO(EINTR);
ASSERT_EQ(1, signal_handler_call_count);
if (sig >= SIGRTMIN && sizeof(void*) == 8) {
@ -918,7 +918,7 @@ TEST(signal, sighold_sigpause_sigrelse_RT) {
TEST(signal, sigset_EINVAL) {
errno = 0;
ASSERT_EQ(SIG_ERR, sigset(99999, SIG_DFL));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(signal, sigset_RT) {
@ -980,5 +980,5 @@ TEST(signal, killpg_EINVAL) {
// and passes 0 through to kill(2).
errno = 0;
ASSERT_EQ(-1, killpg(-1, SIGKILL));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}

View file

@ -220,7 +220,7 @@ TEST(STDIO_TEST, getdelim) {
// It should set the end-of-file indicator for the stream, though.
errno = 0;
ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), -1);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_TRUE(feof(fp));
free(word_read);
@ -239,12 +239,12 @@ TEST(STDIO_TEST, getdelim_invalid) {
// The first argument can't be NULL.
errno = 0;
ASSERT_EQ(getdelim(nullptr, &buffer_length, ' ', fp), -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// The second argument can't be NULL.
errno = 0;
ASSERT_EQ(getdelim(&buffer, nullptr, ' ', fp), -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
fclose(fp);
#pragma clang diagnostic pop
}
@ -293,7 +293,7 @@ TEST(STDIO_TEST, getline) {
// It should set the end-of-file indicator for the stream, though.
errno = 0;
ASSERT_EQ(getline(&line_read, &allocated_length, fp), -1);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_TRUE(feof(fp));
free(line_read);
@ -312,12 +312,12 @@ TEST(STDIO_TEST, getline_invalid) {
// The first argument can't be NULL.
errno = 0;
ASSERT_EQ(getline(nullptr, &buffer_length, fp), -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// The second argument can't be NULL.
errno = 0;
ASSERT_EQ(getline(&buffer, nullptr, fp), -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
fclose(fp);
#pragma clang diagnostic pop
}
@ -916,7 +916,7 @@ TEST(STDIO_TEST, snprintf_asterisk_overflow) {
ASSERT_EQ(12, snprintf(buf, sizeof(buf), "%.2147483646s%c", "hello world", '!'));
ASSERT_EQ(12, snprintf(buf, sizeof(buf), "%.2147483647s%c", "hello world", '!'));
ASSERT_EQ(-1, snprintf(buf, sizeof(buf), "%.2147483648s%c", "hello world", '!'));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
TEST(STDIO_TEST, swprintf_asterisk_overflow) {
@ -931,7 +931,7 @@ TEST(STDIO_TEST, swprintf_asterisk_overflow) {
ASSERT_EQ(12, swprintf(buf, sizeof(buf), L"%.2147483646s%c", "hello world", '!'));
ASSERT_EQ(12, swprintf(buf, sizeof(buf), L"%.2147483647s%c", "hello world", '!'));
ASSERT_EQ(-1, swprintf(buf, sizeof(buf), L"%.2147483648s%c", "hello world", '!'));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
// Inspired by https://github.com/landley/toybox/issues/163.
@ -1402,30 +1402,30 @@ TEST(STDIO_TEST, cantwrite_EBADF) {
errno = 0;
EXPECT_EQ(EOF, putc('x', fp));
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
errno = 0;
EXPECT_EQ(EOF, fprintf(fp, "hello"));
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
errno = 0;
EXPECT_EQ(EOF, fwprintf(fp, L"hello"));
#if defined(__BIONIC__)
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
#endif
errno = 0;
EXPECT_EQ(0U, fwrite("hello", 1, 2, fp));
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
errno = 0;
EXPECT_EQ(EOF, fputs("hello", fp));
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
errno = 0;
EXPECT_EQ(WEOF, fputwc(L'x', fp));
#if defined(__BIONIC__)
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
#endif
}
@ -1540,7 +1540,7 @@ TEST(STDIO_TEST, fpos_t_and_seek) {
// Reading from within a byte should produce an error.
ASSERT_EQ(WEOF, fgetwc(fp));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
// Reverting to a valid position should work.
ASSERT_EQ(0, fsetpos(fp, &mb_two_bytes_pos));
@ -1550,7 +1550,7 @@ TEST(STDIO_TEST, fpos_t_and_seek) {
// produce an error.
ASSERT_EQ(0, fsetpos(fp, &pos_inside_mb));
ASSERT_EQ(WEOF, fgetwc(fp));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
ASSERT_EQ(0, fclose(fp));
}
@ -1951,7 +1951,7 @@ TEST(STDIO_TEST, fmemopen_fileno) {
ASSERT_TRUE(fp != nullptr);
errno = 0;
ASSERT_EQ(-1, fileno(fp));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
ASSERT_EQ(0, fclose(fp));
}
@ -1999,12 +1999,12 @@ TEST(STDIO_TEST, open_memstream_EINVAL) {
// Invalid buffer.
errno = 0;
ASSERT_EQ(nullptr, open_memstream(nullptr, &size));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Invalid size.
errno = 0;
ASSERT_EQ(nullptr, open_memstream(&p, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#pragma clang diagnostic pop
#else
GTEST_SKIP() << "glibc is broken";
@ -2139,7 +2139,7 @@ static void test_fread_from_write_only_stream(size_t n) {
std::vector<char> buf(n, 0);
errno = 0;
ASSERT_EQ(0U, fread(&buf[0], n, 1, fp));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
ASSERT_TRUE(ferror(fp));
ASSERT_FALSE(feof(fp));
fclose(fp);
@ -2271,7 +2271,7 @@ TEST(STDIO_TEST, fclose_invalidates_fd) {
// especially because they might actually correspond to a real stream.
errno = 0;
ASSERT_EQ(-1, fileno(stdin));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(STDIO_TEST, fseek_ftell_unseekable) {
@ -2283,17 +2283,17 @@ TEST(STDIO_TEST, fseek_ftell_unseekable) {
// Check that ftell balks on an unseekable FILE*.
errno = 0;
ASSERT_EQ(-1, ftell(fp));
ASSERT_EQ(ESPIPE, errno);
ASSERT_ERRNO(ESPIPE);
// SEEK_CUR is rewritten as SEEK_SET internally...
errno = 0;
ASSERT_EQ(-1, fseek(fp, 0, SEEK_CUR));
ASSERT_EQ(ESPIPE, errno);
ASSERT_ERRNO(ESPIPE);
// ...so it's worth testing the direct seek path too.
errno = 0;
ASSERT_EQ(-1, fseek(fp, 0, SEEK_SET));
ASSERT_EQ(ESPIPE, errno);
ASSERT_ERRNO(ESPIPE);
fclose(fp);
#else
@ -2305,7 +2305,7 @@ TEST(STDIO_TEST, funopen_EINVAL) {
#if defined(__BIONIC__)
errno = 0;
ASSERT_EQ(nullptr, funopen(nullptr, nullptr, nullptr, nullptr, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#else
GTEST_SKIP() << "glibc uses fopencookie instead";
#endif
@ -2326,7 +2326,7 @@ TEST(STDIO_TEST, funopen_seek) {
EXPECT_EQ(0xfedcba12LL, pos);
#else
EXPECT_EQ(-1, fgetpos(fp, &pos)) << strerror(errno);
EXPECT_EQ(EOVERFLOW, errno);
EXPECT_ERRNO(EOVERFLOW);
#endif
FILE* fp64 = funopen64(nullptr, read_fn, nullptr, seek64_fn, nullptr);
@ -2428,24 +2428,24 @@ TEST(STDIO_TEST, fseek_fseeko_EINVAL) {
// Bad whence.
errno = 0;
ASSERT_EQ(-1, fseek(fp, 0, 123));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(-1, fseeko(fp, 0, 123));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(-1, fseeko64(fp, 0, 123));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Bad offset.
errno = 0;
ASSERT_EQ(-1, fseek(fp, -1, SEEK_SET));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(-1, fseeko(fp, -1, SEEK_SET));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
ASSERT_EQ(-1, fseeko64(fp, -1, SEEK_SET));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
fclose(fp);
}
@ -2464,20 +2464,20 @@ TEST(STDIO_TEST, remove) {
TemporaryFile tf;
ASSERT_EQ(0, remove(tf.path));
ASSERT_EQ(-1, lstat(tf.path, &sb));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
TemporaryDir td;
ASSERT_EQ(0, remove(td.path));
ASSERT_EQ(-1, lstat(td.path, &sb));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, remove(tf.path));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
errno = 0;
ASSERT_EQ(-1, remove(td.path));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST_F(STDIO_DEATHTEST, snprintf_30445072_known_buffer_size) {
@ -2688,7 +2688,7 @@ TEST(STDIO_TEST, fseek_overflow_32bit) {
#if defined(__BIONIC__) && !defined(__LP64__)
ASSERT_EQ(0, fseek(fp, 0x7fff'ffff, SEEK_SET));
ASSERT_EQ(-1, fseek(fp, 1, SEEK_CUR));
ASSERT_EQ(EOVERFLOW, errno);
ASSERT_ERRNO(EOVERFLOW);
#endif
// Neither Bionic nor glibc implement the overflow checking for SEEK_END.
@ -2807,7 +2807,7 @@ TEST(STDIO_TEST, renameat2) {
// Rename and check it moved.
ASSERT_EQ(-1, renameat2(dirfd, "old", dirfd, "new", RENAME_NOREPLACE));
ASSERT_EQ(EEXIST, errno);
ASSERT_ERRNO(EEXIST);
#endif
}
@ -2830,25 +2830,25 @@ TEST(STDIO_TEST, fdopen_failures) {
errno = 0;
fp = fdopen(fd, "nonsense");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Mode that isn't a subset of the fd's actual mode.
errno = 0;
fp = fdopen(fd, "w");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Can't set append on the underlying fd.
errno = 0;
fp = fdopen(fd, "a");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Bad fd.
errno = 0;
fp = fdopen(-1, "re");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
close(fd);
}
@ -2857,14 +2857,14 @@ TEST(STDIO_TEST, fmemopen_invalid_mode) {
errno = 0;
FILE* fp = fmemopen(nullptr, 16, "nonsense");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(STDIO_TEST, fopen_invalid_mode) {
errno = 0;
FILE* fp = fopen("/proc/version", "nonsense");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(STDIO_TEST, freopen_invalid_mode) {
@ -2874,7 +2874,7 @@ TEST(STDIO_TEST, freopen_invalid_mode) {
errno = 0;
fp = freopen("/proc/version", "nonsense", fp);
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(STDIO_TEST, asprintf_smoke) {
@ -2888,7 +2888,7 @@ TEST(STDIO_TEST, fopen_ENOENT) {
errno = 0;
FILE* fp = fopen("/proc/does-not-exist", "re");
ASSERT_TRUE(fp == nullptr);
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
static void tempnam_test(bool has_TMPDIR, const char* dir, const char* prefix, const char* re) {

View file

@ -279,7 +279,7 @@ TEST(stdlib, aligned_alloc_sweep) {
for (size_t fail_align = last_align + 1; fail_align < align; fail_align++) {
ASSERT_TRUE(aligned_alloc(fail_align, fail_align) == nullptr)
<< "Unexpected success at align " << fail_align;
ASSERT_EQ(EINVAL, errno) << "Unexpected errno at align " << fail_align;
ASSERT_ERRNO(EINVAL) << "Unexpected errno at align " << fail_align;
}
void* ptr = aligned_alloc(align, 2 * align);
ASSERT_TRUE(ptr != nullptr) << "Unexpected failure at align " << align;
@ -310,21 +310,21 @@ TEST(stdlib, realpath__NULL_filename) {
const char* path = nullptr;
char* p = realpath(path, nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(stdlib, realpath__empty_filename) {
errno = 0;
char* p = realpath("", nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(stdlib, realpath__ENOENT) {
errno = 0;
char* p = realpath("/this/directory/path/almost/certainly/does/not/exist", nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(stdlib, realpath__ELOOP) {
@ -335,19 +335,19 @@ TEST(stdlib, realpath__ELOOP) {
errno = 0;
char* p = realpath(link.c_str(), nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(ELOOP, errno);
ASSERT_ERRNO(ELOOP);
}
TEST(stdlib, realpath__component_after_non_directory) {
errno = 0;
char* p = realpath("/dev/null/.", nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(ENOTDIR, errno);
ASSERT_ERRNO(ENOTDIR);
errno = 0;
p = realpath("/dev/null/..", nullptr);
ASSERT_TRUE(p == nullptr);
ASSERT_EQ(ENOTDIR, errno);
ASSERT_ERRNO(ENOTDIR);
}
TEST(stdlib, realpath) {
@ -403,7 +403,7 @@ TEST(stdlib, realpath__deleted) {
errno = 0;
char* result = realpath(path.c_str(), nullptr);
ASSERT_EQ(nullptr, result) << result;
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
free(result);
}
@ -695,7 +695,7 @@ TEST(stdlib, ptsname_r_ENOTTY) {
errno = 0;
char buf[128];
ASSERT_EQ(ENOTTY, ptsname_r(STDOUT_FILENO, buf, sizeof(buf)));
ASSERT_EQ(ENOTTY, errno);
ASSERT_ERRNO(ENOTTY);
}
TEST(stdlib, ptsname_r_EINVAL) {
@ -704,7 +704,7 @@ TEST(stdlib, ptsname_r_EINVAL) {
errno = 0;
char* buf = nullptr;
ASSERT_EQ(EINVAL, ptsname_r(fd, buf, 128));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
close(fd);
}
@ -714,7 +714,7 @@ TEST(stdlib, ptsname_r_ERANGE) {
errno = 0;
char buf[1];
ASSERT_EQ(ERANGE, ptsname_r(fd, buf, sizeof(buf)));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
close(fd);
}
@ -745,7 +745,7 @@ TEST(stdlib, ttyname_r_ENOTTY) {
errno = 0;
char buf[128];
ASSERT_EQ(ENOTTY, ttyname_r(fd, buf, sizeof(buf)));
ASSERT_EQ(ENOTTY, errno);
ASSERT_ERRNO(ENOTTY);
close(fd);
}
@ -755,7 +755,7 @@ TEST(stdlib, ttyname_r_EINVAL) {
errno = 0;
char* buf = nullptr;
ASSERT_EQ(EINVAL, ttyname_r(fd, buf, 128));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
close(fd);
}
@ -765,7 +765,7 @@ TEST(stdlib, ttyname_r_ERANGE) {
errno = 0;
char buf[1];
ASSERT_EQ(ERANGE, ttyname_r(fd, buf, sizeof(buf)));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
close(fd);
}
@ -773,7 +773,7 @@ TEST(stdlib, unlockpt_ENOTTY) {
int fd = open("/dev/null", O_WRONLY);
errno = 0;
ASSERT_EQ(-1, unlockpt(fd));
ASSERT_EQ(ENOTTY, errno);
ASSERT_ERRNO(ENOTTY);
close(fd);
}
@ -830,17 +830,17 @@ static void CheckStrToInt(T fn(const char* s, char** end, int base)) {
// Negative base => invalid.
errno = 0;
ASSERT_EQ(T(0), fn("123", &end_p, -1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Base 1 => invalid (base 0 means "please guess").
errno = 0;
ASSERT_EQ(T(0), fn("123", &end_p, 1));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Base > 36 => invalid.
errno = 0;
ASSERT_EQ(T(0), fn("123", &end_p, 37));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Both leading + or - are always allowed (even for the strtou* family).
ASSERT_EQ(T(-123), fn("-123", &end_p, 10));
@ -875,14 +875,14 @@ static void CheckStrToInt(T fn(const char* s, char** end, int base)) {
end_p = nullptr;
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::min(), fn(min.c_str(), &end_p, 0));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ('\0', *end_p);
// Too negative (such as -129).
min.back() = (min.back() + 1);
end_p = nullptr;
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::min(), fn(min.c_str(), &end_p, 0));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
ASSERT_EQ('\0', *end_p);
}
@ -891,14 +891,14 @@ static void CheckStrToInt(T fn(const char* s, char** end, int base)) {
end_p = nullptr;
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::max(), fn(max.c_str(), &end_p, 0));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
ASSERT_EQ('\0', *end_p);
// Too positive (such as 128).
max.back() = (max.back() + 1);
end_p = nullptr;
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::max(), fn(max.c_str(), &end_p, 0));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
ASSERT_EQ('\0', *end_p);
// In case of overflow, strto* leaves us pointing past the end of the number,
@ -907,14 +907,14 @@ static void CheckStrToInt(T fn(const char* s, char** end, int base)) {
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::max(),
fn("99999999999999999999999999999999999999999999999999999abc", &end_p, 0));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
ASSERT_STREQ("abc", end_p);
if (std::numeric_limits<T>::is_signed) {
end_p = nullptr;
errno = 0;
ASSERT_EQ(std::numeric_limits<T>::min(),
fn("-99999999999999999999999999999999999999999999999999999abc", &end_p, 0));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
ASSERT_STREQ("abc", end_p);
}
}

View file

@ -29,6 +29,7 @@
#include <vector>
#include "buffer_tests.h"
#include "utils.h"
#if defined(NOFORTIFY)
#define STRING_TEST string_nofortify
@ -123,7 +124,7 @@ TEST(STRING_TEST, gnu_strerror_r) {
ASSERT_EQ(buf, strerror_r(4567, buf, 2));
ASSERT_STREQ("U", buf);
// The GNU strerror_r doesn't set errno (the POSIX one sets it to ERANGE).
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#else
GTEST_SKIP() << "musl doesn't have GNU strerror_r";
#endif
@ -1483,7 +1484,7 @@ static void TestBasename(const char* in, const char* expected_out) {
errno = 0;
const char* out = basename(in);
ASSERT_STREQ(expected_out, out) << in;
ASSERT_EQ(0, errno) << in;
ASSERT_ERRNO(0) << in;
}
#endif

View file

@ -122,7 +122,7 @@ TEST(sys_epoll, epoll_pwait2_64_with_sigset) {
TEST(sys_epoll, epoll_create_invalid_size) {
errno = 0;
ASSERT_EQ(-1, epoll_create(0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_epoll, epoll_event_data) {

View file

@ -23,6 +23,8 @@
#include <android-base/file.h>
#include <gtest/gtest.h>
#include "utils.h"
TEST(sys_mman, mmap_std) {
void* map = mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
ASSERT_NE(MAP_FAILED, map);
@ -278,7 +280,7 @@ TEST(sys_mman, memfd_create) {
errno = 0;
int fd = memfd_create("doesn't matter", 0);
if (fd == -1) {
ASSERT_EQ(ENOSYS, errno);
ASSERT_ERRNO(ENOSYS);
GTEST_SKIP() << "no memfd_create available";
}
int f = fcntl(fd, F_GETFD);

View file

@ -31,6 +31,8 @@
#include "android-base/file.h"
#include "android-base/strings.h"
#include "utils.h"
// http://b/20017123.
TEST(sys_prctl, bug_20017123) {
#if defined(PR_SET_VMA) // PR_SET_VMA is only available in Android kernels.
@ -91,7 +93,7 @@ TEST(sys_prctl, pr_cap_ambient) {
// but they can check or lower it
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_SYS_ADMIN, 0, 0);
EXPECT_EQ(-1, err);
EXPECT_EQ(EPERM, errno);
EXPECT_ERRNO(EPERM);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_SYS_ADMIN, 0, 0);
EXPECT_EQ(0, err);
@ -102,15 +104,15 @@ TEST(sys_prctl, pr_cap_ambient) {
// ULONG_MAX isn't a legal cap
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
#else
GTEST_SKIP() << "PR_CAP_AMBIENT not available";
#endif

View file

@ -64,10 +64,11 @@ enum class HwFeature { Watchpoint, Breakpoint };
static void check_hw_feature_supported(pid_t child, HwFeature feature) {
#if defined(__arm__)
errno = 0;
long capabilities;
long result = ptrace(PTRACE_GETHBPREGS, child, 0, &capabilities);
if (result == -1) {
EXPECT_EQ(EIO, errno);
EXPECT_ERRNO(EIO);
GTEST_SKIP() << "Hardware debug support disabled at kernel configuration time";
}
uint8_t hb_count = capabilities & 0xff;
@ -88,10 +89,11 @@ static void check_hw_feature_supported(pid_t child, HwFeature feature) {
iov.iov_base = &dreg_state;
iov.iov_len = sizeof(dreg_state);
errno = 0;
long result = ptrace(PTRACE_GETREGSET, child,
feature == HwFeature::Watchpoint ? NT_ARM_HW_WATCH : NT_ARM_HW_BREAK, &iov);
if (result == -1) {
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
GTEST_SKIP() << "Hardware support missing";
} else if ((dreg_state.dbg_info & 0xff) == 0) {
if (feature == HwFeature::Watchpoint) {
@ -134,7 +136,7 @@ static void set_watchpoint(pid_t child, uintptr_t address, size_t size) {
ASSERT_EQ(0, ptrace(PTRACE_POKEUSER, child, offsetof(user, u_debugreg[0]), address)) << strerror(errno);
errno = 0;
unsigned data = ptrace(PTRACE_PEEKUSER, child, offsetof(user, u_debugreg[7]), nullptr);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
const unsigned size_flag = (size == 8) ? 2 : size - 1;
const unsigned enable = 1;
@ -323,7 +325,7 @@ static void set_breakpoint(pid_t child) {
<< strerror(errno);
errno = 0;
unsigned data = ptrace(PTRACE_PEEKUSER, child, offsetof(user, u_debugreg[7]), nullptr);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
const unsigned size = 0;
const unsigned enable = 1;

View file

@ -34,6 +34,8 @@
#include <errno.h>
#include <gtest/gtest.h>
#include "utils.h"
TEST(sys_random, getentropy) {
#if defined(HAVE_SYS_RANDOM)
char buf1[64];
@ -53,7 +55,7 @@ TEST(sys_random, getentropy_EFAULT) {
#if defined(HAVE_SYS_RANDOM)
errno = 0;
ASSERT_EQ(-1, getentropy(nullptr, 1));
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
#else
GTEST_SKIP() << "<sys/random.h> not available";
#endif
@ -67,7 +69,7 @@ TEST(sys_random, getentropy_EIO) {
errno = 0;
ASSERT_EQ(-1, getentropy(buf, sizeof(buf)));
ASSERT_EQ(EIO, errno);
ASSERT_ERRNO(EIO);
#else
GTEST_SKIP() << "<sys/random.h> not available";
#endif
@ -92,7 +94,7 @@ TEST(sys_random, getrandom_EFAULT) {
#if defined(HAVE_SYS_RANDOM)
errno = 0;
ASSERT_EQ(-1, getrandom(nullptr, 256, 0));
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
#else
GTEST_SKIP() << "<sys/random.h> not available";
#endif
@ -104,7 +106,7 @@ TEST(sys_random, getrandom_EINVAL) {
errno = 0;
char buf[64];
ASSERT_EQ(-1, getrandom(buf, sizeof(buf), ~0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#else
GTEST_SKIP() << "<sys/random.h> not available";
#endif

View file

@ -90,7 +90,7 @@ TEST(sys_select, select_smoke) {
// Invalid max fd.
ASSERT_EQ(-1, select(-1, &r, &w, &e, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
int num_fds = select(max, &r, &w, &e, nullptr);
// If there is data to be read on STDIN, then the number of
@ -108,7 +108,7 @@ TEST(sys_select, select_smoke) {
tv.tv_sec = -1;
tv.tv_usec = 0;
ASSERT_EQ(-1, select(max, &r, &w, &e, &tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Valid timeout...
tv.tv_sec = 1;
@ -145,7 +145,7 @@ TEST(sys_select, pselect_smoke) {
// Invalid max fd.
ASSERT_EQ(-1, pselect(-1, &r, &w, &e, nullptr, &ss));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// If there is data to be read on STDIN, then the number of
// fds ready will be 3 instead of 2. Allow this case, but verify
@ -163,7 +163,7 @@ TEST(sys_select, pselect_smoke) {
tv.tv_sec = -1;
tv.tv_nsec = 0;
ASSERT_EQ(-1, pselect(max, &r, &w, &e, &tv, &ss));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Valid timeout...
tv.tv_sec = 1;

View file

@ -33,6 +33,8 @@
#include <android-base/file.h>
#include "utils.h"
TEST(sys_sem, smoke) {
if (semctl(-1, 0, IPC_RMID) == -1 && errno == ENOSYS) {
GTEST_SKIP() << "no <sys/sem.h> support in this kernel";
@ -62,7 +64,7 @@ TEST(sys_sem, smoke) {
ops[0] = { .sem_num = 0, .sem_op = 0, .sem_flg = 0 };
errno = 0;
ASSERT_EQ(-1, semtimedop(id, ops, 1, &ts));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
ASSERT_EQ(1, semctl(id, 0, GETVAL));
// Decrement.

View file

@ -100,7 +100,7 @@ static void RunTest(void (*test_fn)(struct sockaddr_un*, int),
TEST(sys_socket, accept4_error) {
ASSERT_EQ(-1, accept4(-1, nullptr, nullptr, 0));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
static void TestAccept4(struct sockaddr_un* addr, int fd) {
@ -177,7 +177,7 @@ TEST(sys_socket, recvmmsg_error) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
ASSERT_EQ(-1, recvmmsg(-1, nullptr, 0, 0, nullptr));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#pragma clang diagnostic pop
}
@ -238,6 +238,6 @@ TEST(sys_socket, sendmmsg_error) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
ASSERT_EQ(-1, sendmmsg(-1, nullptr, 0, 0));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#pragma clang diagnostic pop
}

View file

@ -22,6 +22,8 @@
#include <android-base/file.h>
#include <gtest/gtest.h>
#include "utils.h"
#if defined(__BIONIC__)
#define HAVE_STATX
#elif defined(__GLIBC_PREREQ)
@ -59,19 +61,19 @@ TEST(sys_stat, futimens_EBADF) {
times[1].tv_sec = 456;
times[1].tv_nsec = 0;
ASSERT_EQ(-1, futimens(-1, times));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(sys_stat, mkfifo_failure) {
errno = 0;
ASSERT_EQ(-1, mkfifo("/", 0666));
ASSERT_EQ(EEXIST, errno);
ASSERT_ERRNO(EEXIST);
}
TEST(sys_stat, mkfifoat_failure) {
errno = 0;
ASSERT_EQ(-1, mkfifoat(-2, "x", 0666));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(sys_stat, mkfifo) {
@ -122,48 +124,48 @@ TEST(sys_stat, statx) {
TEST(sys_stat, fchmod_EBADF) {
ASSERT_EQ(-1, fchmod(-1, 0751));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(sys_stat, fchmodat_EFAULT_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, (char *) 0x1, 0751, 0));
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
}
TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_EFAULT_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, (char *) 0x1, 0751, AT_SYMLINK_NOFOLLOW));
#if defined(__BIONIC__)
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
#else
// glibc 2.19 does not implement AT_SYMLINK_NOFOLLOW and always
// returns ENOTSUP
ASSERT_EQ(ENOTSUP, errno);
ASSERT_ERRNO(ENOTSUP);
#endif
}
TEST(sys_stat, fchmodat_bad_flags) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, ~AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_stat, fchmodat_bad_flags_ALL) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, ~0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_stat, fchmodat_nonexistant_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, 0));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_nonexistant_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, AT_SYMLINK_NOFOLLOW));
#if defined(__BIONIC__)
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
#else
// glibc 2.19 does not implement AT_SYMLINK_NOFOLLOW and always
// returns ENOTSUP
ASSERT_EQ(ENOTSUP, errno);
ASSERT_ERRNO(ENOTSUP);
#endif
}
@ -188,13 +190,13 @@ TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_file) {
#if defined(__BIONIC__)
ASSERT_EQ(0, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
AssertFileModeEquals(0751, tf.path);
#else
// glibc 2.19 does not implement AT_SYMLINK_NOFOLLOW and always
// returns ENOTSUP
ASSERT_EQ(-1, result);
ASSERT_EQ(ENOTSUP, errno);
ASSERT_ERRNO(ENOTSUP);
#endif
}
@ -220,7 +222,7 @@ TEST(sys_stat, fchmodat_dangling_symlink) {
ASSERT_EQ(0, symlink(target, linkname));
ASSERT_EQ(-1, fchmodat(AT_FDCWD, linkname, 0751, 0));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
unlink(linkname);
}
@ -246,7 +248,7 @@ TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_with_symlink) {
AssertSymlinkModeEquals(0751, linkname);
} else {
ASSERT_EQ(-1, result);
ASSERT_EQ(ENOTSUP, errno);
ASSERT_ERRNO(ENOTSUP);
}
// Target file mode shouldn't be modified.
@ -269,7 +271,7 @@ TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_with_dangling_symlink) {
AssertSymlinkModeEquals(0751, linkname);
} else {
ASSERT_EQ(-1, result);
ASSERT_EQ(ENOTSUP, errno);
ASSERT_ERRNO(ENOTSUP);
}
unlink(linkname);
@ -277,14 +279,14 @@ TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_with_dangling_symlink) {
TEST(sys_stat, faccessat_EINVAL) {
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", F_OK, ~AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#if defined(__BIONIC__)
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), 0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#else
ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), 0));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#endif
}
@ -292,7 +294,7 @@ TEST(sys_stat, faccessat_AT_SYMLINK_NOFOLLOW_EINVAL) {
#if defined(__BIONIC__)
// Android doesn't support AT_SYMLINK_NOFOLLOW
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", F_OK, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#else
ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", F_OK, AT_SYMLINK_NOFOLLOW));
#endif
@ -309,8 +311,8 @@ TEST(sys_stat, faccessat_nonexistant) {
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/blah", F_OK, AT_SYMLINK_NOFOLLOW));
#if defined(__BIONIC__)
// Android doesn't support AT_SYMLINK_NOFOLLOW
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#else
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
#endif
}

View file

@ -23,6 +23,8 @@
#include <android-base/file.h>
#include "utils.h"
// http://b/11383777
TEST(sys_time, utimes_nullptr) {
TemporaryFile tf;
@ -36,19 +38,19 @@ TEST(sys_time, utimes_EINVAL) {
tv[0].tv_usec = -123;
ASSERT_EQ(-1, utimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 1234567;
ASSERT_EQ(-1, utimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 0;
tv[1].tv_usec = -123;
ASSERT_EQ(-1, utimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[1].tv_usec = 1234567;
ASSERT_EQ(-1, utimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_time, futimes_nullptr) {
@ -63,19 +65,19 @@ TEST(sys_time, futimes_EINVAL) {
tv[0].tv_usec = -123;
ASSERT_EQ(-1, futimes(tf.fd, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 1234567;
ASSERT_EQ(-1, futimes(tf.fd, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 0;
tv[1].tv_usec = -123;
ASSERT_EQ(-1, futimes(tf.fd, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[1].tv_usec = 1234567;
ASSERT_EQ(-1, futimes(tf.fd, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_time, futimesat_nullptr) {
@ -90,19 +92,19 @@ TEST(sys_time, futimesat_EINVAL) {
tv[0].tv_usec = -123;
ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 1234567;
ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 0;
tv[1].tv_usec = -123;
ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[1].tv_usec = 1234567;
ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(sys_time, lutimes_nullptr) {
@ -117,19 +119,19 @@ TEST(sys_time, lutimes_EINVAL) {
tv[0].tv_usec = -123;
ASSERT_EQ(-1, lutimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 1234567;
ASSERT_EQ(-1, lutimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[0].tv_usec = 0;
tv[1].tv_usec = -123;
ASSERT_EQ(-1, lutimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
tv[1].tv_usec = 1234567;
ASSERT_EQ(-1, lutimes(tf.path, tv));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
// Musl doesn't define __NR_gettimeofday on 32-bit architectures.

View file

@ -24,6 +24,8 @@
#include <android-base/file.h>
#include "utils.h"
TEST(sys_uio, readv_writev) {
TemporaryFile tf;
@ -123,8 +125,9 @@ TEST(sys_uio, process_vm_readv) {
// Reading from non-allocated memory should return an error
remote = { nullptr, sizeof dst };
errno = 0;
ASSERT_EQ(-1, process_vm_readv(getpid(), &local, 1, &remote, 1, 0));
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
}
TEST(sys_uio, process_vm_writev) {
@ -142,6 +145,7 @@ TEST(sys_uio, process_vm_writev) {
// Writing to non-allocated memory should return an error
remote = { nullptr, sizeof dst };
errno = 0;
ASSERT_EQ(-1, process_vm_writev(getpid(), &local, 1, &remote, 1, 0));
ASSERT_EQ(EFAULT, errno);
ASSERT_ERRNO(EFAULT);
}

View file

@ -24,6 +24,8 @@
#include <string>
#include "utils.h"
template <typename StatFsT> void Check(StatFsT& sb) {
EXPECT_EQ(4096, static_cast<int>(sb.f_bsize));
EXPECT_EQ(0U, sb.f_bfree);
@ -48,7 +50,7 @@ TEST(sys_vfs, statfs_failure) {
struct statfs sb;
errno = 0;
ASSERT_EQ(-1, statfs("/does-not-exist", &sb));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(sys_vfs, statfs64_smoke) {
@ -61,7 +63,7 @@ TEST(sys_vfs, statfs64_failure) {
struct statfs64 sb;
errno = 0;
ASSERT_EQ(-1, statfs64("/does-not-exist", &sb));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(sys_vfs, fstatfs) {
@ -76,7 +78,7 @@ TEST(sys_vfs, fstatfs_failure) {
struct statfs sb;
errno = 0;
ASSERT_EQ(-1, fstatfs(-1, &sb));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(sys_vfs, fstatfs64_smoke) {
@ -91,5 +93,5 @@ TEST(sys_vfs, fstatfs64_failure) {
struct statfs sb;
errno = 0;
ASSERT_EQ(-1, fstatfs(-1, &sb));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}

View file

@ -21,6 +21,8 @@
#include <android-base/file.h>
#include <gtest/gtest.h>
#include "utils.h"
TEST(sys_xattr, setxattr) {
TemporaryFile tf;
char buf[10];
@ -52,17 +54,17 @@ TEST(sys_xattr, fsetxattr_toosmallbuf) {
char buf[10];
ASSERT_EQ(0, fsetxattr(tf.fd, "user.foo", "01234567890123456789", 21, 0));
ASSERT_EQ(-1, fgetxattr(tf.fd, "user.foo", buf, sizeof(buf)));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
}
TEST(sys_xattr, fsetxattr_invalid_fd) {
char buf[10];
errno = 0;
ASSERT_EQ(-1, fsetxattr(-1, "user.foo", "0123", 5, 0));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
errno = 0;
ASSERT_EQ(-1, fgetxattr(-1, "user.foo", buf, sizeof(buf)));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(sys_xattr, fsetxattr_with_opath) {
@ -78,7 +80,7 @@ TEST(sys_xattr, fsetxattr_with_opath) {
ASSERT_STREQ("bar", buf);
#else
ASSERT_EQ(-1, res);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#endif
close(fd);
}
@ -93,10 +95,10 @@ TEST(sys_xattr, fsetxattr_with_opath_toosmall) {
char buf[10];
ASSERT_EQ(0, res);
ASSERT_EQ(-1, fgetxattr(fd, "user.foo", buf, sizeof(buf)));
ASSERT_EQ(ERANGE, errno);
ASSERT_ERRNO(ERANGE);
#else
ASSERT_EQ(-1, res);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#endif
close(fd);
}
@ -123,7 +125,7 @@ TEST(sys_xattr, flistattr_opath) {
ASSERT_TRUE(memmem(buf, res, "user.foo", 9) != nullptr);
#else
ASSERT_EQ(-1, res);
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#endif
close(fd);
}
@ -132,5 +134,5 @@ TEST(sys_xattr, flistattr_invalid_fd) {
char buf[65536]; // 64kB is max possible xattr list size. See "man 7 xattr".
errno = 0;
ASSERT_EQ(-1, flistxattr(-1, buf, sizeof(buf)));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}

View file

@ -34,6 +34,8 @@
#include <gtest/gtest.h>
#include "utils.h"
// TODO:
// tcdrain
// tcflow
@ -53,7 +55,7 @@ TEST(termios, cfsetispeed_EINVAL) {
termios t = {};
errno = 0;
ASSERT_EQ(-1, cfsetispeed(&t, 1200));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(termios, cfgetospeed_cfsetospeed) {
@ -66,7 +68,7 @@ TEST(termios, cfsetospeed_EINVAL) {
termios t = {};
errno = 0;
ASSERT_EQ(-1, cfsetospeed(&t, 1200));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(termios, cfsetspeed) {
@ -82,7 +84,7 @@ TEST(termios, cfsetspeed_EINVAL) {
// glibc seems to allow 1200 as well as B1200 here, presumably for
// BSD compatibility (where Bxxx == xxx, unlike Linux).
ASSERT_EQ(-1, cfsetspeed(&t, 123));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(termios, cfmakeraw) {
@ -105,11 +107,11 @@ TEST(termios, tcgetwinsize_tcsetwinsize_invalid) {
errno = 0;
ASSERT_EQ(-1, tcgetwinsize(-1, &ws));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
errno = 0;
ASSERT_EQ(-1, tcsetwinsize(-1, &ws));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
#else
GTEST_SKIP() << "glibc too old";
#endif

View file

@ -150,7 +150,7 @@ TEST(time, mktime_10310929) {
#if !defined(__LP64__)
// 32-bit bionic has a signed 32-bit time_t.
ASSERT_EQ(-1, mktime(&tm));
ASSERT_EQ(EOVERFLOW, errno);
ASSERT_ERRNO(EOVERFLOW);
#else
// Everyone else should be using a signed 64-bit time_t.
ASSERT_GE(sizeof(time_t) * 8, 64U);
@ -164,7 +164,7 @@ TEST(time, mktime_10310929) {
// mktime to interpret that time as local standard, hence offset
// is 8 hours, not 7.
ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&tm));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#endif
}
@ -182,7 +182,7 @@ TEST(time, mktime_EOVERFLOW) {
errno = 0;
ASSERT_NE(static_cast<time_t>(-1), mktime(&t));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
// This will overflow for LP32.
t.tm_year = INT_MAX;
@ -190,10 +190,10 @@ TEST(time, mktime_EOVERFLOW) {
errno = 0;
#if !defined(__LP64__)
ASSERT_EQ(static_cast<time_t>(-1), mktime(&t));
ASSERT_EQ(EOVERFLOW, errno);
ASSERT_ERRNO(EOVERFLOW);
#else
ASSERT_EQ(static_cast<time_t>(67768036166016000U), mktime(&t));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#endif
// This will overflow for LP32 or LP64.
@ -204,7 +204,7 @@ TEST(time, mktime_EOVERFLOW) {
errno = 0;
ASSERT_EQ(static_cast<time_t>(-1), mktime(&t));
ASSERT_EQ(EOVERFLOW, errno);
ASSERT_ERRNO(EOVERFLOW);
}
TEST(time, mktime_invalid_tm_TZ_combination) {
@ -222,7 +222,7 @@ TEST(time, mktime_invalid_tm_TZ_combination) {
EXPECT_EQ(static_cast<time_t>(-1), mktime(&t));
// mktime sets errno to EOVERFLOW if result is unrepresentable.
EXPECT_EQ(EOVERFLOW, errno);
EXPECT_ERRNO(EOVERFLOW);
}
// Transitions in the tzdata file are generated up to the year 2100. Testing
@ -233,14 +233,13 @@ TEST(time, mktime_after_2100) {
#if !defined(__LP64__)
// 32-bit bionic has a signed 32-bit time_t.
ASSERT_EQ(-1, mktime(&tm));
ASSERT_EQ(EOVERFLOW, errno);
ASSERT_ERRNO(EOVERFLOW);
#else
setenv("TZ", "Europe/London", 1);
tzset();
errno = 0;
ASSERT_EQ(static_cast<time_t>(5686156800U), mktime(&tm));
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
#endif
}
@ -649,7 +648,7 @@ TEST(time, timer_create) {
if (pid == 0) {
// Timers are not inherited by the child.
ASSERT_EQ(-1, timer_delete(timer_id));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
_exit(0);
}
@ -804,7 +803,7 @@ TEST(time, timer_create_EINVAL) {
// A SIGEV_SIGNAL timer is easy; the kernel does all that.
timer_t timer_id;
ASSERT_EQ(-1, timer_create(invalid_clock, nullptr, &timer_id));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// A SIGEV_THREAD timer is more interesting because we have stuff to clean up.
sigevent se;
@ -812,7 +811,7 @@ TEST(time, timer_create_EINVAL) {
se.sigev_notify = SIGEV_THREAD;
se.sigev_notify_function = NoOpNotifyFunction;
ASSERT_EQ(-1, timer_create(invalid_clock, &se, &timer_id));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(time, timer_create_multiple) {
@ -915,7 +914,7 @@ TEST(time, timer_delete_from_timer_thread) {
cur_time = time(NULL);
while ((kill(tdd.tid, 0) != -1 || errno != ESRCH) && (time(NULL) - cur_time) < 5);
ASSERT_EQ(-1, kill(tdd.tid, 0));
ASSERT_EQ(ESRCH, errno);
ASSERT_ERRNO(ESRCH);
#endif
}
@ -973,7 +972,7 @@ TEST(time, clock_gettime_unknown) {
errno = 0;
timespec ts;
ASSERT_EQ(-1, clock_gettime(-1, &ts));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(time, clock_getres_CLOCK_REALTIME) {
@ -1011,7 +1010,7 @@ TEST(time, clock_getres_unknown) {
errno = 0;
timespec ts = { -1, -1 };
ASSERT_EQ(-1, clock_getres(-1, &ts));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
ASSERT_EQ(-1, ts.tv_nsec);
ASSERT_EQ(-1, ts.tv_sec);
}
@ -1064,14 +1063,14 @@ TEST(time, clock_getcpuclockid_ESRCH) {
<< "commit/?id=e1b6b6ce55a0a25c8aa8af019095253b2133a41a\n"
<< "* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/"
<< "commit/?id=c80ed088a519da53f27b798a69748eaabc66aadf\n";
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
TEST(time, clock_settime) {
errno = 0;
timespec ts;
ASSERT_EQ(-1, clock_settime(-1, &ts));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(time, clock_nanosleep_EINVAL) {
@ -1107,7 +1106,7 @@ TEST(time, nanosleep_EINVAL) {
timespec ts = {.tv_sec = -1};
errno = 0;
ASSERT_EQ(-1, nanosleep(&ts, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(time, bug_31938693) {

View file

@ -24,6 +24,8 @@
#include <locale.h>
#include <stdint.h>
#include "utils.h"
// Modern versions of UTF-8 (https://datatracker.ietf.org/doc/html/rfc3629 and
// newer) explicitly disallow code points beyond U+10FFFF, which exclude all 5-
// and 6-byte sequences. Earlier versions of UTF-8 allowed the wider range:
@ -77,7 +79,7 @@ TEST(uchar, start_state) {
EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
// Similarly (but not in compliance with the standard afaict), musl seems to
// ignore the state entirely for the UTF-32 functions rather than reset it.
@ -217,11 +219,11 @@ TEST(uchar, mbrtoc16_long_sequences) {
auto result = mbrtoc16(&out, "\xf8\xa1\xa2\xa3\xa4", 5, nullptr);
if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_EQ(u'\0', out);
} else {
EXPECT_EQ(5U, result);
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(u'\uf94a', out);
}
}
@ -234,7 +236,7 @@ TEST(uchar, mbrtoc16_reserved_range) {
char16_t out = u'\0';
EXPECT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, nullptr));
EXPECT_EQ(u'\0', out);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
TEST(uchar, mbrtoc16_beyond_range) {
@ -247,11 +249,11 @@ TEST(uchar, mbrtoc16_beyond_range) {
if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(u'\0', out);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
} else {
EXPECT_EQ(4U, result);
EXPECT_EQ(u'\xdcc0', out);
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
}
}
@ -290,7 +292,7 @@ void test_mbrtoc16_incomplete(mbstate_t* ps) {
ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps));
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
}
TEST(uchar, mbrtoc16_incomplete) {
@ -347,7 +349,7 @@ TEST(uchar, c32rtomb) {
// Invalid code point.
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
TEST(uchar, mbrtoc32_valid_non_characters) {
@ -370,11 +372,11 @@ TEST(uchar, mbrtoc32_out_of_range) {
auto result = mbrtoc32(&out, "\xf5\x80\x80\x80", 4, nullptr);
if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_EQ(U'\0', out);
} else {
EXPECT_EQ(4U, result);
EXPECT_EQ(0, errno);
EXPECT_ERRNO(0);
EXPECT_EQ(U'\x140000', out);
}
}
@ -428,7 +430,7 @@ TEST(uchar, mbrtoc32) {
"\xf8\xa1\xa2\xa3\xa4"
"f",
6, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
#endif
// Illegal over-long sequence.
errno = 0;
@ -436,7 +438,7 @@ TEST(uchar, mbrtoc32) {
"\xf0\x82\x82\xac"
"ef",
6, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
void test_mbrtoc32_incomplete(mbstate_t* ps) {
@ -466,7 +468,7 @@ void test_mbrtoc32_incomplete(mbstate_t* ps) {
ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps));
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
}
TEST(uchar, mbrtoc32_incomplete) {

View file

@ -72,7 +72,7 @@ TEST(UNISTD_TEST, brk) {
void* new_break = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(initial_break) + 1);
int ret = brk(new_break);
if (ret == -1) {
ASSERT_EQ(errno, ENOMEM);
ASSERT_ERRNO(ENOMEM);
} else {
ASSERT_EQ(0, ret);
ASSERT_GE(get_brk(), new_break);
@ -82,7 +82,7 @@ TEST(UNISTD_TEST, brk) {
new_break = page_align(reinterpret_cast<uintptr_t>(initial_break) + sysconf(_SC_PAGE_SIZE));
ret = brk(new_break);
if (ret == -1) {
ASSERT_EQ(errno, ENOMEM);
ASSERT_ERRNO(ENOMEM);
} else {
ASSERT_EQ(0, ret);
ASSERT_EQ(get_brk(), new_break);
@ -91,7 +91,7 @@ TEST(UNISTD_TEST, brk) {
TEST(UNISTD_TEST, brk_ENOMEM) {
ASSERT_EQ(-1, brk(reinterpret_cast<void*>(-1)));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
}
#if defined(__GLIBC__)
@ -124,18 +124,18 @@ TEST(UNISTD_TEST, sbrk_ENOMEM) {
// Can't increase by so much that we'd overflow.
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MAX));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
// Set the current break to a point that will cause an overflow.
__bionic_brk = reinterpret_cast<void*>(static_cast<uintptr_t>(PTRDIFF_MAX));
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MIN));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
__bionic_brk = reinterpret_cast<void*>(static_cast<uintptr_t>(PTRDIFF_MAX) - 1);
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MIN + 1));
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
#else
class ScopedBrk {
public:
@ -154,7 +154,7 @@ TEST(UNISTD_TEST, sbrk_ENOMEM) {
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(SBRK_MIN));
#if defined(__BIONIC__)
// GLIBC does not set errno in overflow case.
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
#endif
}
@ -167,7 +167,7 @@ TEST(UNISTD_TEST, sbrk_ENOMEM) {
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(SBRK_MAX));
#if defined(__BIONIC__)
// GLIBC does not set errno in overflow case.
ASSERT_EQ(ENOMEM, errno);
ASSERT_ERRNO(ENOMEM);
#endif
}
#endif
@ -217,7 +217,7 @@ TEST(UNISTD_TEST, ftruncate_negative) {
TemporaryFile tf;
errno = 0;
ASSERT_EQ(-1, ftruncate(tf.fd, -123));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
static bool g_pause_test_flag = false;
@ -253,7 +253,7 @@ TEST(UNISTD_TEST, read_EBADF) {
// our syscall stubs correctly return a 64-bit -1.
char buf[1];
ASSERT_EQ(-1, read(-1, buf, sizeof(buf)));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(UNISTD_TEST, syscall_long) {
@ -288,27 +288,27 @@ TEST(UNISTD_TEST, getenv_unsetenv) {
TEST(UNISTD_TEST, unsetenv_EINVAL) {
EXPECT_EQ(-1, unsetenv(""));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ(-1, unsetenv("a=b"));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
}
TEST(UNISTD_TEST, setenv_EINVAL) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
EXPECT_EQ(-1, setenv(nullptr, "value", 0));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ(-1, setenv(nullptr, "value", 1));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
#pragma clang diagnostic pop
EXPECT_EQ(-1, setenv("", "value", 0));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ(-1, setenv("", "value", 1));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ(-1, setenv("a=b", "value", 0));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
EXPECT_EQ(-1, setenv("a=b", "value", 1));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
}
TEST(UNISTD_TEST, setenv) {
@ -394,7 +394,7 @@ static void TestSyncFunction(int (*fn)(int)) {
// Can't sync an invalid fd.
errno = 0;
EXPECT_EQ(-1, fn(-1));
EXPECT_EQ(EBADF, errno);
EXPECT_ERRNO(EBADF);
// It doesn't matter whether you've opened a file for write or not.
TemporaryFile tf;
@ -424,7 +424,7 @@ static void TestFsyncFunction(int (*fn)(int)) {
int fd = open("/proc/version", O_RDONLY);
ASSERT_NE(-1, fd);
EXPECT_EQ(-1, fn(fd));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
close(fd);
}
@ -737,7 +737,6 @@ TEST(UNISTD_TEST, gethostname) {
ASSERT_EQ(0, gethostname(hostname, HOST_NAME_MAX));
// Can we get the hostname with a right-sized buffer?
errno = 0;
ASSERT_EQ(0, gethostname(hostname, strlen(hostname) + 1));
// Does uname(2) agree?
@ -749,7 +748,7 @@ TEST(UNISTD_TEST, gethostname) {
// Do we correctly detect truncation?
errno = 0;
ASSERT_EQ(-1, gethostname(hostname, strlen(hostname)));
ASSERT_EQ(ENAMETOOLONG, errno);
ASSERT_ERRNO(ENAMETOOLONG);
}
TEST(UNISTD_TEST, pathconf_fpathconf) {
@ -1206,7 +1205,7 @@ TEST(UNISTD_TEST, dup2_same) {
// Equal, but invalid.
errno = 0;
ASSERT_EQ(-1, dup2(fd, fd));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(UNISTD_TEST, dup3) {
@ -1297,11 +1296,11 @@ TEST(UNISTD_TEST, lockf_with_child) {
// Check that the child cannot lock the file.
ASSERT_EQ(0, lseek64(tf.fd, 0, SEEK_SET));
ASSERT_EQ(-1, lockf64(tf.fd, F_TLOCK, file_size));
ASSERT_EQ(EAGAIN, errno);
ASSERT_ERRNO(EAGAIN);
// Check also that it reports itself as locked.
ASSERT_EQ(0, lseek64(tf.fd, 0, SEEK_SET));
ASSERT_EQ(-1, lockf64(tf.fd, F_TEST, file_size));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
_exit(0);
}
AssertChildExited(pid, 0);
@ -1327,11 +1326,11 @@ TEST(UNISTD_TEST, lockf_partial_with_child) {
// Check that the child cannot lock the first half.
ASSERT_EQ(0, lseek64(tf.fd, 0, SEEK_SET));
ASSERT_EQ(-1, lockf64(tf.fd, F_TEST, file_size/2));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
// Check also that it reports itself as locked.
ASSERT_EQ(0, lseek64(tf.fd, 0, SEEK_SET));
ASSERT_EQ(-1, lockf64(tf.fd, F_TEST, file_size/2));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
_exit(0);
}
AssertChildExited(pid, 0);
@ -1353,7 +1352,7 @@ TEST(UNISTD_TEST, getdomainname) {
#if defined(__BIONIC__)
// bionic and glibc have different behaviors when len is too small
ASSERT_EQ(-1, getdomainname(buf, strlen(u.domainname)));
EXPECT_EQ(EINVAL, errno);
EXPECT_ERRNO(EINVAL);
#endif
}
@ -1378,7 +1377,7 @@ TEST(UNISTD_TEST, setdomainname) {
const char* name = "newdomainname";
ASSERT_EQ(-1, setdomainname(name, strlen(name)));
ASSERT_EQ(EPERM, errno);
ASSERT_ERRNO(EPERM);
if (has_admin) {
ASSERT_EQ(0, capset(&header, &old_caps[0])) << "failed to restore admin privileges";
@ -1389,7 +1388,7 @@ TEST(UNISTD_TEST, execve_failure) {
ExecTestHelper eth;
errno = 0;
ASSERT_EQ(-1, execve("/", eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
static void append_llvm_cov_env_var(std::string& env_str) {
@ -1419,7 +1418,7 @@ TEST(UNISTD_TEST, execve_args) {
TEST(UNISTD_TEST, execl_failure) {
errno = 0;
ASSERT_EQ(-1, execl("/", "/", nullptr));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
TEST(UNISTD_TEST, execl) {
@ -1432,7 +1431,7 @@ TEST(UNISTD_TEST, execle_failure) {
ExecTestHelper eth;
errno = 0;
ASSERT_EQ(-1, execle("/", "/", nullptr, eth.GetEnv()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
TEST(UNISTD_TEST, execle) {
@ -1451,7 +1450,7 @@ TEST(UNISTD_TEST, execv_failure) {
ExecTestHelper eth;
errno = 0;
ASSERT_EQ(-1, execv("/", eth.GetArgs()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
TEST(UNISTD_TEST, execv) {
@ -1464,7 +1463,7 @@ TEST(UNISTD_TEST, execv) {
TEST(UNISTD_TEST, execlp_failure) {
errno = 0;
ASSERT_EQ(-1, execlp("/", "/", nullptr));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
TEST(UNISTD_TEST, execlp) {
@ -1478,7 +1477,7 @@ TEST(UNISTD_TEST, execvp_failure) {
eth.SetArgs({nullptr});
errno = 0;
ASSERT_EQ(-1, execvp("/", eth.GetArgs()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
}
TEST(UNISTD_TEST, execvp) {
@ -1493,7 +1492,7 @@ TEST(UNISTD_TEST, execvpe_failure) {
errno = 0;
ASSERT_EQ(-1, execvpe("this-does-not-exist", eth.GetArgs(), eth.GetEnv()));
// Running in CTS we might not even be able to search all directories in $PATH.
ASSERT_TRUE(errno == ENOENT || errno == EACCES);
ASSERT_TRUE(errno == ENOENT || errno == EACCES) << strerror(errno);
}
TEST(UNISTD_TEST, execvpe) {
@ -1528,7 +1527,7 @@ TEST(UNISTD_TEST, execvpe_ENOEXEC) {
// It's not inherently executable.
errno = 0;
ASSERT_EQ(-1, execvpe(basename(tf.path), eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
// Make it executable (and keep it writable because we're going to rewrite it below).
ASSERT_EQ(0, chmod(tf.path, 0777));
@ -1536,7 +1535,7 @@ TEST(UNISTD_TEST, execvpe_ENOEXEC) {
// TemporaryFile will have a writable fd, so we can test ETXTBSY while we're here...
errno = 0;
ASSERT_EQ(-1, execvpe(basename(tf.path), eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(ETXTBSY, errno);
ASSERT_ERRNO(ETXTBSY);
// 1. The simplest test: the kernel should handle this.
ASSERT_EQ(0, close(tf.fd));
@ -1557,7 +1556,7 @@ TEST(UNISTD_TEST, execvp_libcore_test_55017) {
errno = 0;
ASSERT_EQ(-1, execvp("/system/bin/does-not-exist", eth.GetArgs()));
ASSERT_EQ(ENOENT, errno);
ASSERT_ERRNO(ENOENT);
}
TEST(UNISTD_TEST, exec_argv0_null) {
@ -1584,7 +1583,7 @@ TEST(UNISTD_TEST, fexecve_failure) {
int fd = open("/", O_RDONLY);
ASSERT_NE(-1, fd);
ASSERT_EQ(-1, fexecve(fd, eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(EACCES, errno);
ASSERT_ERRNO(EACCES);
close(fd);
}
@ -1592,7 +1591,7 @@ TEST(UNISTD_TEST, fexecve_bad_fd) {
ExecTestHelper eth;
errno = 0;
ASSERT_EQ(-1, fexecve(-1, eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(EBADF, errno);
ASSERT_ERRNO(EBADF);
}
TEST(UNISTD_TEST, fexecve_args) {
@ -1694,9 +1693,9 @@ TEST(UNISTD_TEST, close_range) {
if (close_range(fd, fd, 0) == 0) {
// we can't close it *again*
ASSERT_EQ(close(fd), -1);
ASSERT_EQ(errno, EBADF);
ASSERT_ERRNO(EBADF);
} else {
ASSERT_EQ(errno, ENOSYS);
ASSERT_ERRNO(ENOSYS);
// since close_range() failed, we can close it normally
ASSERT_EQ(close(fd), 0);
}

View file

@ -70,3 +70,12 @@ pid_t gettid() {
return syscall(__NR_gettid);
}
#endif
void PrintTo(const Errno& e, std::ostream* os) {
// TODO: strerrorname_np() might be more useful here, but we'd need to implement it first!
*os << strerror(e.errno_);
}
bool operator==(const Errno& lhs, const Errno& rhs) {
return lhs.errno_ == rhs.errno_;
}

View file

@ -315,3 +315,13 @@ static inline bool running_with_mte() {
}
bool IsLowRamDevice();
class Errno {
public:
Errno(int e) : errno_(e) {}
int errno_;
};
void PrintTo(const Errno& e, std::ostream* os);
bool operator==(const Errno& lhs, const Errno& rhs);
#define ASSERT_ERRNO(expected_errno) ASSERT_EQ(Errno(expected_errno), Errno(errno))
#define EXPECT_ERRNO(expected_errno) EXPECT_EQ(Errno(expected_errno), Errno(errno))

View file

@ -122,7 +122,7 @@ TEST(wchar, wctomb_wcrtomb) {
EXPECT_EQ('\xa2', bytes[3]);
// Invalid code point.
EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(bytes, 0xffffffff, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
TEST(wchar, wcrtomb_start_state) {
@ -136,7 +136,7 @@ TEST(wchar, wcrtomb_start_state) {
memset(&ps, 0, sizeof(ps));
EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(out, 0x00a2, &ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
// If the first argument to wcrtomb is NULL or the second is L'\0' the shift
// state should be reset.
@ -177,10 +177,10 @@ TEST(wchar, wcstombs_wcrtombs) {
// An unrepresentable char just returns an error from wcstombs...
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), wcstombs(nullptr, bad_chars, 0));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), wcstombs(nullptr, bad_chars, 256));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
// And wcsrtombs doesn't tell us where it got stuck because we didn't ask it
// to actually convert anything...
@ -188,12 +188,12 @@ TEST(wchar, wcstombs_wcrtombs) {
src = bad_chars;
EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 0, nullptr));
EXPECT_EQ(&bad_chars[0], src);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
errno = 0;
src = bad_chars;
EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 256, nullptr));
EXPECT_EQ(&bad_chars[0], src);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
// Okay, now let's test actually converting something...
memset(bytes, 'x', sizeof(bytes));
@ -211,7 +211,7 @@ TEST(wchar, wcstombs_wcrtombs) {
errno = 0;
memset(bytes, 'x', sizeof(bytes));
EXPECT_EQ(static_cast<size_t>(-1), wcstombs(bytes, bad_chars, 256));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
bytes[3] = 0;
EXPECT_STREQ("hix", bytes);
@ -220,13 +220,13 @@ TEST(wchar, wcstombs_wcrtombs) {
src = chars;
EXPECT_EQ(0U, wcsrtombs(bytes, &src, 0, nullptr));
EXPECT_EQ(&chars[0], src); // No input consumed.
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
memset(bytes, 'x', sizeof(bytes));
src = chars;
EXPECT_EQ(4U, wcsrtombs(bytes, &src, 4, nullptr));
EXPECT_EQ(&chars[4], src); // Some input consumed.
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
bytes[5] = 0;
EXPECT_STREQ("hellx", bytes);
@ -234,21 +234,21 @@ TEST(wchar, wcstombs_wcrtombs) {
src = chars;
EXPECT_EQ(5U, wcsrtombs(bytes, &src, 256, nullptr));
EXPECT_EQ(nullptr, src); // All input consumed!
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_STREQ("hello", bytes);
memset(bytes, 'x', sizeof(bytes));
src = chars;
EXPECT_EQ(5U, wcsrtombs(bytes, &src, 6, nullptr));
EXPECT_EQ(nullptr, src); // All input consumed.
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
EXPECT_STREQ("hello", bytes);
memset(bytes, 'x', sizeof(bytes));
src = bad_chars;
EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(bytes, &src, 256, nullptr));
EXPECT_EQ(&bad_chars[2], src);
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
bytes[3] = 0;
EXPECT_STREQ("hix", bytes);
@ -258,7 +258,7 @@ TEST(wchar, wcstombs_wcrtombs) {
memset(&ps, 0, sizeof(ps));
ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 0, &ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
TEST(wchar, limits) {
@ -375,14 +375,14 @@ TEST(wchar, mbrtowc) {
"\xf8\xa1\xa2\xa3\xa4"
"f",
6, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
#endif
// Illegal over-long sequence.
EXPECT_EQ(static_cast<size_t>(-1), mbrtowc(out,
"\xf0\x82\x82\xac"
"ef",
6, nullptr));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
}
TEST(wchar, mbrtowc_valid_non_characters) {
@ -406,10 +406,10 @@ TEST(wchar, mbrtowc_out_of_range) {
auto result = mbrtowc(out, "\xf5\x80\x80\x80", 4, nullptr);
if (kLibcRejectsOverLongUtf8Sequences) {
ASSERT_EQ(static_cast<size_t>(-1), result);
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
} else {
ASSERT_EQ(4U, result);
ASSERT_EQ(0, errno);
ASSERT_ERRNO(0);
}
}
@ -439,7 +439,7 @@ static void test_mbrtowc_incomplete(mbstate_t* ps) {
// Invalid 2-byte
ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xc2", 1, ps));
ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
}
TEST(wchar, mbrtowc_incomplete) {
@ -477,12 +477,12 @@ static void test_mbsrtowcs(mbstate_t* ps) {
const char* invalid = INVALID;
ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &invalid, 4, ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
ASSERT_EQ('\xc2', *invalid);
const char* incomplete = INCOMPLETE;
ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &incomplete, 2, ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
ASSERT_EQ('\xc2', *incomplete);
// If dst is null, *src shouldn't be updated.
@ -512,7 +512,7 @@ TEST(wchar, mbsrtowcs) {
wchar_t out;
ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xc2", 1, &ps));
ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(&out, &invalid, 1, &ps));
EXPECT_EQ(EILSEQ, errno);
EXPECT_ERRNO(EILSEQ);
ASSERT_EQ('\x20', *invalid);
}
@ -642,12 +642,12 @@ TEST(wchar, mbsnrtowcs) {
src = incomplete;
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbsnrtowcs(dst, &src, SIZE_MAX, 3, nullptr));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
src = incomplete;
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbsnrtowcs(nullptr, &src, SIZE_MAX, 3, nullptr));
ASSERT_EQ(EILSEQ, errno);
ASSERT_ERRNO(EILSEQ);
}
TEST(wchar, wcsftime__wcsftime_l) {
@ -798,12 +798,12 @@ TEST(stdio, open_wmemstream_EINVAL) {
// Invalid buffer.
errno = 0;
ASSERT_EQ(nullptr, open_wmemstream(nullptr, &size));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
// Invalid size.
errno = 0;
ASSERT_EQ(nullptr, open_wmemstream(&p, nullptr));
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
#pragma clang diagnostic pop
#else
GTEST_SKIP() << "This test is bionic-specific";
@ -813,73 +813,73 @@ TEST(stdio, open_wmemstream_EINVAL) {
TEST(wchar, wcstol_EINVAL) {
errno = 0;
wcstol(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstol(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstol(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wcstoll_EINVAL) {
errno = 0;
wcstoll(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoll(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoll(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wcstoul_EINVAL) {
errno = 0;
wcstoul(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoul(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoul(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wcstoull_EINVAL) {
errno = 0;
wcstoull(L"123", nullptr, -1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoull(L"123", nullptr, 1);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoull(L"123", nullptr, 37);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wcstoll_l_EINVAL) {
errno = 0;
wcstoll_l(L"123", nullptr, -1, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoll_l(L"123", nullptr, 1, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoll_l(L"123", nullptr, 37, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wcstoull_l_EINVAL) {
errno = 0;
wcstoull_l(L"123", nullptr, -1, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoull_l(L"123", nullptr, 1, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
errno = 0;
wcstoull_l(L"123", nullptr, 37, SAFE_LC_GLOBAL_LOCALE);
ASSERT_EQ(EINVAL, errno);
ASSERT_ERRNO(EINVAL);
}
TEST(wchar, wmempcpy) {