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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/signal/sigaddset.h" |
10 | |
11 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
12 | #include "test/UnitTest/Test.h" |
13 | |
14 | #include <errno.h> |
15 | #include <signal.h> |
16 | |
17 | // This tests invalid inputs and ensures errno is properly set. |
18 | TEST(LlvmLibcSignalTest, SigaddsetInvalid) { |
19 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; |
20 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; |
21 | EXPECT_THAT(LIBC_NAMESPACE::sigaddset(nullptr, SIGSEGV), Fails(EINVAL)); |
22 | |
23 | sigset_t sigset; |
24 | EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, -1), Fails(EINVAL)); |
25 | |
26 | // This doesn't use NSIG because LIBC_NAMESPACE::sigaddset error checking is |
27 | // against sizeof(sigset_t) not NSIG. |
28 | constexpr int bitsInSigsetT = 8 * sizeof(sigset_t); |
29 | |
30 | EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, bitsInSigsetT + 1), |
31 | Fails(EINVAL)); |
32 | EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, 0), Fails(EINVAL)); |
33 | EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset, bitsInSigsetT), Succeeds()); |
34 | } |
35 | |