forked from OSchip/llvm-project
[libc] [NFC] Use matchers in tests
Summary: Use `EXPECT_THAT` where possible in tests NFC intended. Added a `void *` template instantiation of `StreamWrapper::operator<<` Reviewers: sivachandra, PaulkaToast Reviewed By: sivachandra Subscribers: MaskRay, tschuett, libc-commits Differential Revision: https://reviews.llvm.org/D75717
This commit is contained in:
parent
2a41b31fcd
commit
1348ca4046
|
@ -14,6 +14,7 @@
|
|||
#include "src/signal/sigemptyset.h"
|
||||
#include "src/signal/sigprocmask.h"
|
||||
|
||||
#include "utils/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
class SignalTest : public __llvm_libc::testing::Test {
|
||||
|
@ -27,28 +28,23 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
|
||||
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
|
||||
|
||||
// This tests for invalid input.
|
||||
TEST_F(SignalTest, SigprocmaskInvalid) {
|
||||
llvmlibc_errno = 0;
|
||||
|
||||
sigset_t valid;
|
||||
// 17 and -4 are out of the range for sigprocmask's how paramater.
|
||||
llvmlibc_errno = 0;
|
||||
EXPECT_EQ(__llvm_libc::sigprocmask(17, &valid, nullptr), -1);
|
||||
EXPECT_EQ(llvmlibc_errno, EINVAL);
|
||||
|
||||
llvmlibc_errno = 0;
|
||||
EXPECT_EQ(__llvm_libc::sigprocmask(-4, &valid, nullptr), -1);
|
||||
EXPECT_EQ(llvmlibc_errno, EINVAL);
|
||||
EXPECT_THAT(__llvm_libc::sigprocmask(17, &valid, nullptr), Fails(EINVAL));
|
||||
EXPECT_THAT(__llvm_libc::sigprocmask(-4, &valid, nullptr), Fails(EINVAL));
|
||||
|
||||
// This pointer is out of this processes address range.
|
||||
sigset_t *invalid = reinterpret_cast<sigset_t *>(-1);
|
||||
|
||||
llvmlibc_errno = 0;
|
||||
EXPECT_EQ(__llvm_libc::sigprocmask(SIG_SETMASK, invalid, nullptr), -1);
|
||||
EXPECT_EQ(llvmlibc_errno, EFAULT);
|
||||
|
||||
llvmlibc_errno = 0;
|
||||
EXPECT_EQ(__llvm_libc::sigprocmask(-4, nullptr, invalid), -1);
|
||||
EXPECT_EQ(llvmlibc_errno, EFAULT);
|
||||
EXPECT_THAT(__llvm_libc::sigprocmask(SIG_SETMASK, invalid, nullptr),
|
||||
Fails(EFAULT));
|
||||
EXPECT_THAT(__llvm_libc::sigprocmask(-4, nullptr, invalid), Fails(EFAULT));
|
||||
}
|
||||
|
||||
// This tests that when nothing is blocked, a process gets killed and alse tests
|
||||
|
|
|
@ -11,8 +11,12 @@
|
|||
#include "src/errno/llvmlibc_errno.h"
|
||||
#include "src/sys/mman/mmap.h"
|
||||
#include "src/sys/mman/munmap.h"
|
||||
#include "utils/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
|
||||
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
|
||||
|
||||
TEST(MMapTest, NoError) {
|
||||
size_t alloc_size = 128;
|
||||
llvmlibc_errno = 0;
|
||||
|
@ -26,21 +30,14 @@ TEST(MMapTest, NoError) {
|
|||
// Since we used the MAP_ANONYMOUS flag, the contents of the newly
|
||||
// allocated memory should be initialized to zero.
|
||||
EXPECT_EQ(array[0], 0);
|
||||
|
||||
int ret_val = __llvm_libc::munmap(addr, alloc_size);
|
||||
EXPECT_EQ(0, ret_val);
|
||||
EXPECT_EQ(0, llvmlibc_errno);
|
||||
EXPECT_THAT(__llvm_libc::munmap(addr, alloc_size), Succeeds());
|
||||
}
|
||||
|
||||
TEST(MMapTest, Error_InvalidSize) {
|
||||
llvmlibc_errno = 0;
|
||||
void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||
EXPECT_EQ(EINVAL, llvmlibc_errno);
|
||||
EXPECT_EQ(addr, MAP_FAILED);
|
||||
EXPECT_THAT(addr, Fails(EINVAL, MAP_FAILED));
|
||||
|
||||
llvmlibc_errno = 0;
|
||||
int ret_val = __llvm_libc::munmap(0, 0);
|
||||
EXPECT_EQ(-1, ret_val);
|
||||
EXPECT_EQ(EINVAL, llvmlibc_errno);
|
||||
EXPECT_THAT(__llvm_libc::munmap(0, 0), Fails(EINVAL));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ template <typename T> StreamWrapper &StreamWrapper::operator<<(T t) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template StreamWrapper &StreamWrapper::operator<<<void *>(void *t);
|
||||
template StreamWrapper &StreamWrapper::operator<<<const char *>(const char *t);
|
||||
template StreamWrapper &StreamWrapper::operator<<<char *>(char *t);
|
||||
template StreamWrapper &StreamWrapper::operator<<<char>(char t);
|
||||
|
|
Loading…
Reference in New Issue