1 //===-- Unittests for sigaddset -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/signal/sigaddset.h"
11 #include "test/UnitTest/ErrnoSetterMatcher.h"
12 #include "test/UnitTest/Test.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
));
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),
31 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset
, 0), Fails(EINVAL
));
32 EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&sigset
, bitsInSigsetT
), Succeeds());