1 /* Test program for POSIX clock_* functions.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
25 /* We want to see output immediately. */
26 #define STDOUT_UNBUFFERED
28 /* We expect to run at least 10 seconds. */
32 clock_test (clockid_t cl
)
34 struct timespec old_ts
;
36 struct timespec waitit
;
40 memset (&ts
, '\0', sizeof ts
);
43 waitit
.tv_nsec
= 500000000;
45 /* Get and print resolution of the clock. */
46 if (clock_getres (cl
, &ts
) == 0)
48 if (ts
.tv_nsec
< 0 || ts
.tv_nsec
>= 1000000000)
50 printf ("clock %d: nanosecond value of resolution wrong\n", cl
);
54 printf ("clock %d: resolution = %ld.%09ld secs\n",
55 cl
, ts
.tv_sec
, ts
.tv_nsec
);
59 printf ("clock %d: cannot get resolution\n", cl
);
63 memset (&ts
, '\0', sizeof ts
);
64 memset (&old_ts
, '\0', sizeof old_ts
);
66 /* Next get the current time value a few times. */
67 for (i
= 0; i
< 10; ++i
)
69 if (clock_gettime (cl
, &ts
) == 0)
71 if (ts
.tv_nsec
< 0 || ts
.tv_nsec
>= 1000000000)
73 printf ("clock %d: nanosecond value of time wrong (try %d)\n",
79 printf ("clock %d: time = %ld.%09ld secs\n",
80 cl
, ts
.tv_sec
, ts
.tv_nsec
);
82 if (memcmp (&ts
, &old_ts
, sizeof ts
) == 0)
84 printf ("clock %d: time hasn't changed (try %d)\n", cl
, i
);
93 printf ("clock %d: cannot get time (try %d)\n", cl
, i
);
97 /* Wait a bit before the next iteration. */
98 nanosleep (&waitit
, NULL
);
110 result
= clock_test (CLOCK_REALTIME
);
112 if (clock_getcpuclockid (0, &cl
) == 0)
113 /* XXX It's not yet a bug when this fails. */
118 #define TEST_FUNCTION do_test ()
121 #include "../test-skeleton.c"