1 | //===-- Unittests for sigdelset -------------------------------------------===// |
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/raise.h" |
10 | #include "src/signal/sigdelset.h" |
11 | #include "src/signal/sigfillset.h" |
12 | #include "src/signal/sigprocmask.h" |
13 | |
14 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
15 | #include "test/UnitTest/Test.h" |
16 | |
17 | #include <errno.h> |
18 | #include <signal.h> |
19 | |
20 | TEST(LlvmLibcSigdelset, Invalid) { |
21 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; |
22 | // Invalid set. |
23 | EXPECT_THAT(LIBC_NAMESPACE::sigdelset(nullptr, SIGUSR1), Fails(EINVAL)); |
24 | |
25 | sigset_t set; |
26 | // Valid set, invalid signum. |
27 | EXPECT_THAT(LIBC_NAMESPACE::sigdelset(&set, -1), Fails(EINVAL)); |
28 | } |
29 | |
30 | TEST(LlvmLibcSigdelset, UnblockOne) { |
31 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; |
32 | sigset_t set; |
33 | EXPECT_THAT(LIBC_NAMESPACE::sigfillset(&set), Succeeds()); |
34 | EXPECT_THAT(LIBC_NAMESPACE::sigdelset(&set, SIGUSR1), Succeeds()); |
35 | EXPECT_THAT(LIBC_NAMESPACE::sigprocmask(SIG_SETMASK, &set, nullptr), |
36 | Succeeds()); |
37 | EXPECT_DEATH([] { LIBC_NAMESPACE::raise(SIGUSR1); }, WITH_SIGNAL(SIGUSR1)); |
38 | } |
39 | |