[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / signal / signal_test.cpp
blob4b57311eee2d86fd0d11fdda10cc67d8f4837b48
1 //===-- Unittests for signal ----------------------------------------------===//
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 //===----------------------------------------------------------------------===//
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));
30 static int sum;
31 TEST(LlvmLibcSignal, Basic) {
32 // In case test get run multiple times.
33 sum = 0;
34 ASSERT_NE(LIBC_NAMESPACE::signal(
35 SIGUSR1, +[](int) { sum++; }),
36 SIG_ERR);
37 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1), Succeeds());
38 EXPECT_EQ(sum, 1);
39 for (int i = 0; i < 10; i++)
40 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1), Succeeds());
41 EXPECT_EQ(sum, 11);