Blame support/tst-support-process_state.c

Packit Service 996b63
/* Wait for process state tests.
Packit Service 996b63
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service 996b63
   This file is part of the GNU C Library.
Packit Service 996b63
Packit Service 996b63
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 996b63
   modify it under the terms of the GNU Lesser General Public
Packit Service 996b63
   License as published by the Free Software Foundation; either
Packit Service 996b63
   version 2.1 of the License, or (at your option) any later version.
Packit Service 996b63
Packit Service 996b63
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 996b63
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 996b63
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 996b63
   Lesser General Public License for more details.
Packit Service 996b63
Packit Service 996b63
   You should have received a copy of the GNU Lesser General Public
Packit Service 996b63
   License along with the GNU C Library; if not, see
Packit Service 996b63
   <https://www.gnu.org/licenses/>.  */
Packit Service 996b63
Packit Service 996b63
#include <stdio.h>
Packit Service 996b63
#include <sys/wait.h>
Packit Service 996b63
#include <unistd.h>
Packit Service 996b63
#include <errno.h>
Packit Service 996b63
Packit Service 996b63
#include <support/test-driver.h>
Packit Service 996b63
#include <support/process_state.h>
Packit Service 996b63
#include <support/check.h>
Packit Service 996b63
#include <support/xsignal.h>
Packit Service 996b63
#include <support/xunistd.h>
Packit Service 996b63
Packit Service 996b63
#ifndef WEXITED
Packit Service 996b63
# define WEXITED	0
Packit Service 996b63
#endif
Packit Service 996b63
Packit Service 996b63
static void
Packit Service 996b63
sigusr1_handler (int signo)
Packit Service 996b63
{
Packit Service 996b63
}
Packit Service 996b63
Packit Service 996b63
static void
Packit Service 996b63
test_child (void)
Packit Service 996b63
{
Packit Service 996b63
  xsignal (SIGUSR1, sigusr1_handler);
Packit Service 996b63
Packit Service 996b63
  raise (SIGSTOP);
Packit Service 996b63
Packit Service 996b63
  TEST_COMPARE (pause (), -1);
Packit Service 996b63
  TEST_COMPARE (errno, EINTR);
Packit Service 996b63
Packit Service 996b63
  while (1)
Packit Service 996b63
    asm ("");
Packit Service 996b63
}
Packit Service 996b63
Packit Service 996b63
static int
Packit Service 996b63
do_test (void)
Packit Service 996b63
{
Packit Service 996b63
  pid_t pid = xfork ();
Packit Service 996b63
  if (pid == 0)
Packit Service 996b63
    {
Packit Service 996b63
      test_child ();
Packit Service 996b63
      _exit (127);
Packit Service 996b63
    }
Packit Service 996b63
Packit Service 996b63
  /* Adding process_state_tracing_stop ('t') allows the test to work under
Packit Service 996b63
     trace programs such as ptrace.  */
Packit Service 996b63
  enum support_process_state stop_state = support_process_state_stopped
Packit Service 996b63
				    | support_process_state_tracing_stop;
Packit Service 996b63
Packit Service 996b63
  if (test_verbose)
Packit Service 996b63
    printf ("info: waiting pid %d, state_stopped/state_tracing_stop\n",
Packit Service 996b63
	    (int) pid);
Packit Service 996b63
  support_process_state_wait (pid, stop_state);
Packit Service 996b63
Packit Service 996b63
  if (kill (pid, SIGCONT) != 0)
Packit Service 996b63
    FAIL_RET ("kill (%d, SIGCONT): %m\n", pid);
Packit Service 996b63
Packit Service 996b63
  if (test_verbose)
Packit Service 996b63
    printf ("info: waiting pid %d, state_sleeping\n", (int) pid);
Packit Service 996b63
  support_process_state_wait (pid, support_process_state_sleeping);
Packit Service 996b63
Packit Service 996b63
  if (kill (pid, SIGUSR1) != 0)
Packit Service 996b63
    FAIL_RET ("kill (%d, SIGUSR1): %m\n", pid);
Packit Service 996b63
Packit Service 996b63
  if (test_verbose)
Packit Service 996b63
    printf ("info: waiting pid %d, state_running\n", (int) pid);
Packit Service 996b63
  support_process_state_wait (pid, support_process_state_running);
Packit Service 996b63
Packit Service 996b63
  if (kill (pid, SIGKILL) != 0)
Packit Service 996b63
    FAIL_RET ("kill (%d, SIGKILL): %m\n", pid);
Packit Service 996b63
Packit Service 996b63
  if (test_verbose)
Packit Service 996b63
    printf ("info: waiting pid %d, state_zombie\n", (int) pid);
Packit Service 996b63
  support_process_state_wait (pid, support_process_state_zombie);
Packit Service 996b63
Packit Service 996b63
  siginfo_t info;
Packit Service 996b63
  int r = waitid (P_PID, pid, &info, WEXITED);
Packit Service 996b63
  TEST_COMPARE (r, 0);
Packit Service 996b63
  TEST_COMPARE (info.si_signo, SIGCHLD);
Packit Service 996b63
  TEST_COMPARE (info.si_code, CLD_KILLED);
Packit Service 996b63
  TEST_COMPARE (info.si_status, SIGKILL);
Packit Service 996b63
  TEST_COMPARE (info.si_pid, pid);
Packit Service 996b63
Packit Service 996b63
  return 0;
Packit Service 996b63
}
Packit Service 996b63
Packit Service 996b63
#include <support/test-driver.c>