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