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//===----------------------------------------------------------------------===//
8
9#include "src/__support/libc_errno.h"
10#include "src/signal/raise.h"
11#include "src/signal/signal.h"
12
13#include "test/UnitTest/ErrnoSetterMatcher.h"
14#include "test/UnitTest/Test.h"
15
16using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
17using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
18
19TEST(LlvmLibcSignal, Invalid) {
20 libc_errno = 0;
21 auto *valid = +[](int) {};
22 EXPECT_THAT((void *)LIBC_NAMESPACE::signal(0, valid),
23 Fails(EINVAL, (void *)SIG_ERR));
24 EXPECT_THAT((void *)LIBC_NAMESPACE::signal(65, valid),
25 Fails(EINVAL, (void *)SIG_ERR));
26}
27
28static int sum;
29TEST(LlvmLibcSignal, Basic) {
30 // In case test get run multiple times.
31 sum = 0;
32 ASSERT_NE(LIBC_NAMESPACE::signal(
33 SIGUSR1, +[](int) { sum++; }),
34 SIG_ERR);
35 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1), Succeeds());
36 EXPECT_EQ(sum, 1);
37 for (int i = 0; i < 10; i++)
38 ASSERT_THAT(LIBC_NAMESPACE::raise(SIGUSR1), Succeeds());
39 EXPECT_EQ(sum, 11);
40}
41

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libc/test/src/signal/signal_test.cpp