Esempio n. 1
0
static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tfun, int i)
{
  pid_t pid_w;
  pid_t pid;
  int status = 0;

  pid = fork();
  if (pid == -1)
    eprintf("Error in call to fork:", __FILE__, __LINE__ - 2);
  if (pid == 0) {
    setpgid(0, 0);
    group_pid = getpgrp();
    tcase_run_checked_setup(sr, tc);
    tfun->fn(i);
    tcase_run_checked_teardown(tc);
    exit(EXIT_SUCCESS);
  } else {
    group_pid = pid;
  }

  alarm_received = 0;
  alarm(tc->timeout);
  do {
    pid_w = waitpid(pid, &status, 0);
  } while (pid_w == -1);
  
  killpg(pid, SIGKILL); /* Kill remaining processes. */

  return receive_result_info_fork(tc->name, tfun->name, i, status, tfun->signal,  tfun->allowed_exit_value);
}
Esempio n. 2
0
static TestResult *tcase_run_tfun_nofork (SRunner *sr, TCase *tc, TF *tfun, int i)
{
  TestResult *tr;
  
  tr = tcase_run_checked_setup(sr, tc);
  if (tr == NULL) {
    tfun->fn(i);
    tcase_run_checked_teardown(tc);
    return receive_result_info_nofork(tc->name, tfun->name, i);
  }
  
  return tr;
}
static TestResult *
tcase_run_tfun_nofork (SRunner * sr, TCase * tc, TF * tfun, int i)
{
  TestResult *tr;
  struct timespec ts_start = { 0, 0 }, ts_end = {
  0, 0};

  tr = tcase_run_checked_setup (sr, tc);
  if (tr == NULL) {
    clock_gettime (check_get_clockid (), &ts_start);
    if (0 == setjmp (error_jmp_buffer)) {
      tfun->fn (i);
    }
    clock_gettime (check_get_clockid (), &ts_end);
    tcase_run_checked_teardown (tc);
    return receive_result_info_nofork (tc->name, tfun->name, i,
        DIFF_IN_USEC (ts_start, ts_end));
  }

  return tr;
}
static TestResult *
tcase_run_tfun_fork (SRunner * sr, TCase * tc, TF * tfun, int i)
{
  pid_t pid_w;
  pid_t pid;
  int status = 0;
  struct timespec ts_start = { 0, 0 }, ts_end = {
  0, 0};

  timer_t timerid;
  struct itimerspec timer_spec;
  TestResult *tr;


  pid = fork ();
  if (pid == -1)
    eprintf ("Error in call to fork:", __FILE__, __LINE__ - 2);
  if (pid == 0) {
    setpgid (0, 0);
    group_pid = getpgrp ();
    tr = tcase_run_checked_setup (sr, tc);
    free (tr);
    clock_gettime (check_get_clockid (), &ts_start);
    tfun->fn (i);
    clock_gettime (check_get_clockid (), &ts_end);
    tcase_run_checked_teardown (tc);
    send_duration_info (DIFF_IN_USEC (ts_start, ts_end));
    exit (EXIT_SUCCESS);
  } else {
    group_pid = pid;
  }

  alarm_received = 0;

  if (timer_create (check_get_clockid (),
          NULL /* fire SIGALRM if timer expires */ ,
          &timerid) == 0) {
    /* Set the timer to fire once */
    timer_spec.it_value = tc->timeout;
    timer_spec.it_interval.tv_sec = 0;
    timer_spec.it_interval.tv_nsec = 0;
    if (timer_settime (timerid, 0, &timer_spec, NULL) == 0) {
      do {
        pid_w = waitpid (pid, &status, 0);
      }
      while (pid_w == -1);
    } else {
      eprintf ("Error in call to timer_settime:", __FILE__, __LINE__);
    }

    /* If the timer has not fired, disable it */
    timer_delete (timerid);
  } else {
    eprintf ("Error in call to timer_create:", __FILE__, __LINE__);
  }

  killpg (pid, SIGKILL);        /* Kill remaining processes. */

  return receive_result_info_fork (tc->name, tfun->name, i, status,
      tfun->signal, tfun->allowed_exit_value);
}