aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/signal/kill_test.cpp
blob: 2033543c97a2b496729d03a6e6e5e4ed1a3ece39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//===-- Unittests for kill -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/signal/kill.h"

#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include <signal.h>
#include <sys/syscall.h> // For syscall numbers.

using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

TEST(LlvmLibcKillTest, TargetSelf) {
  pid_t parent_pid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getpid);
  ASSERT_THAT(LIBC_NAMESPACE::kill(parent_pid, 0), Succeeds(0));

  EXPECT_DEATH(
      [] {
        pid_t child_pid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getpid);
        LIBC_NAMESPACE::kill(child_pid, SIGKILL);
      },
      WITH_SIGNAL(SIGKILL));
}