source: trunk/src/libctests/glibc/rt/tst-clock_nanosleep.c@ 2036

Last change on this file since 2036 was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1/* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19#include <errno.h>
20#include <stdio.h>
21#include <unistd.h>
22#include <sys/time.h>
23#include <time.h>
24
25
26/* Test that clock_nanosleep() does sleep. */
27static int
28do_test (void)
29{
30 /* Current time. */
31 struct timeval tv1;
32 (void) gettimeofday (&tv1, NULL);
33
34 struct timespec ts;
35 ts.tv_sec = 1;
36 ts.tv_nsec = 0;
37 TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts));
38
39 /* At least one second must have passed. */
40 struct timeval tv2;
41 (void) gettimeofday (&tv2, NULL);
42
43 tv2.tv_sec -= tv1.tv_sec;
44 tv2.tv_usec -= tv1.tv_usec;
45 if (tv2.tv_usec < 0)
46 --tv2.tv_sec;
47
48 if (tv2.tv_sec < 1)
49 {
50 puts ("clock_nanosleep didn't sleep long enough");
51 return 1;
52 }
53
54 return 0;
55}
56
57#define TEST_FUNCTION do_test ()
58#include "../test-skeleton.c"
Note: See TracBrowser for help on using the repository browser.