1 //===-- Unittests for signal ----------------------------------------------===//
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/errno/libc_errno.h"
10 #include "src/signal/raise.h"
11 #include "src/signal/signal.h"
13 #include "test/UnitTest/ErrnoSetterMatcher.h"
14 #include "test/UnitTest/Test.h"
16 #include "hdr/types/sighandler_t.h"
18 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails
;
19 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds
;
21 TEST(LlvmLibcSignal
, Invalid
) {
22 LIBC_NAMESPACE::libc_errno
= 0;
23 sighandler_t valid
= +[](int) {};
24 EXPECT_THAT((void *)LIBC_NAMESPACE::signal(0, valid
),
25 Fails(EINVAL
, (void *)SIG_ERR
));
26 EXPECT_THAT((void *)LIBC_NAMESPACE::signal(65, valid
),
27 Fails(EINVAL
, (void *)SIG_ERR
));
31 TEST(LlvmLibcSignal
, Basic
) {
32 // In case test get run multiple times.
34 ASSERT_NE(LIBC_NAMESPACE::signal(
35 SIGUSR1
, +[](int) { sum
++; }),
37 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1
), Succeeds());
39 for (int i
= 0; i
< 10; i
++)
40 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1
), Succeeds());