[libc][NFC] Switch mman.h tests to libc_errno and update Bazel build.

This commit is contained in:
Siva Chandra Reddy 2023-03-13 22:46:19 +00:00
parent 0b70f95c16
commit 40c443e28b
6 changed files with 16 additions and 19 deletions

View File

@ -7,7 +7,6 @@ add_libc_unittest(
SRCS
mmap_test.cpp
DEPENDS
libc.include.errno
libc.include.sys_mman
libc.src.errno.errno
libc.src.sys.mman.mmap
@ -23,7 +22,6 @@ if (NOT LLVM_USE_SANITIZER)
SRCS
mprotect_test.cpp
DEPENDS
libc.include.errno
libc.include.sys_mman
libc.include.signal
libc.src.errno.errno
@ -41,7 +39,6 @@ add_libc_unittest(
SRCS
madvise_test.cpp
DEPENDS
libc.include.errno
libc.include.sys_mman
libc.src.errno.errno
libc.src.sys.mman.mmap
@ -58,7 +55,6 @@ add_libc_unittest(
SRCS
posix_madvise_test.cpp
DEPENDS
libc.include.errno
libc.include.sys_mman
libc.src.errno.errno
libc.src.sys.mman.mmap

View File

@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
#include "src/errno/libc_errno.h"
#include "src/sys/mman/madvise.h"
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/munmap.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <errno.h>
#include <sys/mman.h>
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
@ -20,10 +20,10 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcMadviseTest, NoError) {
size_t alloc_size = 128;
errno = 0;
libc_errno = 0;
void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_EQ(0, errno);
EXPECT_EQ(0, libc_errno);
EXPECT_NE(addr, MAP_FAILED);
EXPECT_THAT(__llvm_libc::madvise(addr, alloc_size, MADV_RANDOM), Succeeds());
@ -37,6 +37,6 @@ TEST(LlvmLibcMadviseTest, NoError) {
}
TEST(LlvmLibcMadviseTest, Error_BadPtr) {
errno = 0;
libc_errno = 0;
EXPECT_THAT(__llvm_libc::madvise(nullptr, 8, MADV_SEQUENTIAL), Fails(ENOMEM));
}

View File

@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
#include "src/errno/libc_errno.h"
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/munmap.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <errno.h>
#include <sys/mman.h>
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
@ -19,10 +19,10 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcMMapTest, NoError) {
size_t alloc_size = 128;
errno = 0;
libc_errno = 0;
void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_EQ(0, errno);
EXPECT_EQ(0, libc_errno);
EXPECT_NE(addr, MAP_FAILED);
int *array = reinterpret_cast<int *>(addr);
@ -34,7 +34,7 @@ TEST(LlvmLibcMMapTest, NoError) {
}
TEST(LlvmLibcMMapTest, Error_InvalidSize) {
errno = 0;
libc_errno = 0;
void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_THAT(addr, Fails(EINVAL, MAP_FAILED));

View File

@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
#include "src/errno/libc_errno.h"
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/mprotect.h"
#include "src/sys/mman/munmap.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <errno.h>
#include <signal.h>
#include <sys/mman.h>
@ -21,10 +21,10 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcMProtectTest, NoError) {
size_t alloc_size = 128;
errno = 0;
libc_errno = 0;
void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_EQ(0, errno);
EXPECT_EQ(0, libc_errno);
EXPECT_NE(addr, MAP_FAILED);
int *array = reinterpret_cast<int *>(addr);

View File

@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
#include "src/errno/libc_errno.h"
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/munmap.h"
#include "src/sys/mman/posix_madvise.h"
#include "test/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <errno.h>
#include <sys/mman.h>
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
@ -20,10 +20,10 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcPosixMadviseTest, NoError) {
size_t alloc_size = 128;
errno = 0;
libc_errno = 0;
void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_EQ(0, errno);
EXPECT_EQ(0, libc_errno);
EXPECT_NE(addr, MAP_FAILED);
EXPECT_EQ(__llvm_libc::posix_madvise(addr, alloc_size, POSIX_MADV_RANDOM), 0);
@ -37,7 +37,7 @@ TEST(LlvmLibcPosixMadviseTest, NoError) {
}
TEST(LlvmLibcPosixMadviseTest, Error_BadPtr) {
errno = 0;
libc_errno = 0;
// posix_madvise is a no-op on DONTNEED, so it shouldn't fail even with the
// nullptr.
EXPECT_EQ(__llvm_libc::posix_madvise(nullptr, 8, POSIX_MADV_DONTNEED), 0);

View File

@ -763,6 +763,7 @@ libc_support_library(
"__support_cpp_bit",
"__support_cpp_type_traits",
":__support_common",
":errno",
":libc_root",
],
)