William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 1 | #include <signal.h> |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 2 | |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 3 | #include <stdplus/signal.hpp> |
| 4 | |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 5 | #include <cstring> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 9 | namespace stdplus |
| 10 | { |
| 11 | namespace signal |
| 12 | { |
| 13 | namespace |
| 14 | { |
| 15 | |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 16 | TEST(Signal, Block) |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 17 | { |
| 18 | constexpr int s = SIGINT; |
| 19 | constexpr int otherS = SIGTERM; |
| 20 | constexpr int notBlocked = SIGPROF; |
| 21 | |
| 22 | sigset_t expectedSet; |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 23 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet)); |
| 24 | ASSERT_EQ(0, sigaddset(&expectedSet, otherS)); |
| 25 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr)); |
| 26 | ASSERT_EQ(0, sigismember(&expectedSet, notBlocked)); |
| 27 | ASSERT_EQ(0, sigismember(&expectedSet, s)); |
| 28 | ASSERT_EQ(0, sigaddset(&expectedSet, s)); |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 29 | |
| 30 | block(s); |
| 31 | |
| 32 | sigset_t newSet; |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 33 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet)); |
| 34 | EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s)); |
| 35 | EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS)); |
| 36 | EXPECT_EQ(sigismember(&expectedSet, notBlocked), |
| 37 | sigismember(&newSet, notBlocked)); |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 40 | TEST(Signal, StayBlocked) |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 41 | { |
| 42 | constexpr int s = SIGINT; |
| 43 | constexpr int otherS = SIGTERM; |
| 44 | constexpr int notBlocked = SIGPROF; |
| 45 | |
| 46 | sigset_t expectedSet; |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 47 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet)); |
| 48 | ASSERT_EQ(0, sigaddset(&expectedSet, s)); |
| 49 | ASSERT_EQ(0, sigaddset(&expectedSet, otherS)); |
| 50 | ASSERT_EQ(0, sigismember(&expectedSet, notBlocked)); |
| 51 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr)); |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 52 | |
| 53 | block(s); |
| 54 | |
| 55 | sigset_t newSet; |
William A. Kennington III | 0bd1370 | 2022-08-24 13:33:34 -0700 | [diff] [blame] | 56 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet)); |
| 57 | EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s)); |
| 58 | EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS)); |
| 59 | EXPECT_EQ(sigismember(&expectedSet, notBlocked), |
| 60 | sigismember(&newSet, notBlocked)); |
William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } // namespace |
| 64 | } // namespace signal |
| 65 | } // namespace stdplus |