Blame rt/tst-clock_nanosleep.c

Packit Bot 0c2104
/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
Packit Bot 0c2104
   This file is part of the GNU C Library.
Packit Bot 0c2104
Packit Bot 0c2104
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 0c2104
   modify it under the terms of the GNU Lesser General Public
Packit Bot 0c2104
   License as published by the Free Software Foundation; either
Packit Bot 0c2104
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 0c2104
Packit Bot 0c2104
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 0c2104
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 0c2104
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 0c2104
   Lesser General Public License for more details.
Packit Bot 0c2104
Packit Bot 0c2104
   You should have received a copy of the GNU Lesser General Public
Packit Bot 0c2104
   License along with the GNU C Library; if not, see
Packit Bot 0c2104
   <http://www.gnu.org/licenses/>.  */
Packit Bot 0c2104
Packit Bot 0c2104
#include <errno.h>
Packit Bot 0c2104
#include <stdio.h>
Packit Bot 0c2104
#include <unistd.h>
Packit Bot 0c2104
#include <sys/time.h>
Packit Bot 0c2104
#include <time.h>
Packit Bot 0c2104
Packit Bot 0c2104
Packit Bot 0c2104
/* Test that clock_nanosleep() does sleep.  */
Packit Bot 0c2104
static int
Packit Bot 0c2104
do_test (void)
Packit Bot 0c2104
{
Packit Bot 0c2104
  /* Current time.  */
Packit Bot 0c2104
  struct timeval tv1;
Packit Bot 0c2104
  (void) gettimeofday (&tv1, NULL);
Packit Bot 0c2104
Packit Bot 0c2104
  struct timespec ts;
Packit Bot 0c2104
  ts.tv_sec = 1;
Packit Bot 0c2104
  ts.tv_nsec = 0;
Packit Bot 0c2104
  TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts);;
Packit Bot 0c2104
Packit Bot 0c2104
  /* At least one second must have passed.  */
Packit Bot 0c2104
  struct timeval tv2;
Packit Bot 0c2104
  (void) gettimeofday (&tv2, NULL);
Packit Bot 0c2104
Packit Bot 0c2104
  tv2.tv_sec -= tv1.tv_sec;
Packit Bot 0c2104
  tv2.tv_usec -= tv1.tv_usec;
Packit Bot 0c2104
  if (tv2.tv_usec < 0)
Packit Bot 0c2104
    --tv2.tv_sec;
Packit Bot 0c2104
Packit Bot 0c2104
  if (tv2.tv_sec < 1)
Packit Bot 0c2104
    {
Packit Bot 0c2104
      puts ("clock_nanosleep didn't sleep long enough");
Packit Bot 0c2104
      return 1;
Packit Bot 0c2104
    }
Packit Bot 0c2104
Packit Bot 0c2104
  return 0;
Packit Bot 0c2104
}
Packit Bot 0c2104
Packit Bot 0c2104
#define TEST_FUNCTION do_test ()
Packit Bot 0c2104
#include "../test-skeleton.c"