[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / signal / sigaddset_test.cpp
blobbc33750cf787d7fabb2689cd8ef829f34545b727
1 //===-- Unittests for sigaddset -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/signal/sigaddset.h"
11 #include "test/UnitTest/ErrnoSetterMatcher.h"
12 #include "test/UnitTest/Test.h"
14 #include <signal.h>
16 // This tests invalid inputs and ensures errno is properly set.
17 TEST(LlvmLibcSignalTest, SigaddsetInvalid) {
18 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
19 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
20 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(nullptr, SIGSEGV), Fails(EINVAL));
22 sigset_t sigset;
23 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, -1), Fails(EINVAL));
25 // This doesn't use NSIG because LIBC_NAMESPACE::sigaddset error checking is
26 // against sizeof(sigset_t) not NSIG.
27 constexpr int bitsInSigsetT = 8 * sizeof(sigset_t);
29 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, bitsInSigsetT + 1),
30 Fails(EINVAL));
31 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, 0), Fails(EINVAL));
32 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, bitsInSigsetT), Succeeds());