diff --git a/libc/test/src/signal/sigprocmask_test.cpp b/libc/test/src/signal/sigprocmask_test.cpp --- a/libc/test/src/signal/sigprocmask_test.cpp +++ b/libc/test/src/signal/sigprocmask_test.cpp @@ -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 @@ } }; +using __llvm_libc::testing::ErrnoSetterMatcher::Fails; +using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; + // This tests for invalid input. TEST_F(SignalTest, SigprocmaskInvalid) { - 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); + sigset_t valid; + // 17 and -4 are out of the range for sigprocmask's how paramater. + 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(-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 diff --git a/libc/test/src/sys/mman/linux/mmap_test.cpp b/libc/test/src/sys/mman/linux/mmap_test.cpp --- a/libc/test/src/sys/mman/linux/mmap_test.cpp +++ b/libc/test/src/sys/mman/linux/mmap_test.cpp @@ -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 @@ // 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)); } diff --git a/libc/utils/testutils/StreamWrapper.cpp b/libc/utils/testutils/StreamWrapper.cpp --- a/libc/utils/testutils/StreamWrapper.cpp +++ b/libc/utils/testutils/StreamWrapper.cpp @@ -23,6 +23,7 @@ return *this; } +template StreamWrapper &StreamWrapper::operator<<(void *t); template StreamWrapper &StreamWrapper::operator<<(const char *t); template StreamWrapper &StreamWrapper::operator<<(char *t); template StreamWrapper &StreamWrapper::operator<<(char t);