root / tests / cris / check_time1.c @ 640e5404
History | View | Annotate | Download (962 Bytes)
1 | dd43edf4 | ths | /* Basic time functionality test: check that milliseconds are
|
---|---|---|---|
2 | dd43edf4 | ths | incremented for each syscall (does not work on host). */
|
3 | dd43edf4 | ths | #include <stdio.h> |
4 | dd43edf4 | ths | #include <time.h> |
5 | dd43edf4 | ths | #include <sys/time.h> |
6 | dd43edf4 | ths | #include <string.h> |
7 | dd43edf4 | ths | #include <stdlib.h> |
8 | dd43edf4 | ths | |
9 | dd43edf4 | ths | void err (const char *s) |
10 | dd43edf4 | ths | { |
11 | dd43edf4 | ths | perror (s); |
12 | dd43edf4 | ths | abort (); |
13 | dd43edf4 | ths | } |
14 | dd43edf4 | ths | |
15 | dd43edf4 | ths | int
|
16 | dd43edf4 | ths | main (void)
|
17 | dd43edf4 | ths | { |
18 | dd43edf4 | ths | struct timeval t_m = {0, 0}; |
19 | dd43edf4 | ths | struct timezone t_z = {0, 0}; |
20 | dd43edf4 | ths | struct timeval t_m1 = {0, 0}; |
21 | dd43edf4 | ths | int i;
|
22 | dd43edf4 | ths | |
23 | dd43edf4 | ths | if (gettimeofday (&t_m, &t_z) != 0) |
24 | dd43edf4 | ths | err ("gettimeofday");
|
25 | dd43edf4 | ths | |
26 | dd43edf4 | ths | for (i = 1; i < 10000; i++) |
27 | dd43edf4 | ths | if (gettimeofday (&t_m1, NULL) != 0) |
28 | dd43edf4 | ths | err ("gettimeofday 1");
|
29 | dd43edf4 | ths | else
|
30 | dd43edf4 | ths | if (t_m1.tv_sec * 1000000 + t_m1.tv_usec |
31 | dd43edf4 | ths | != (t_m.tv_sec * 1000000 + t_m.tv_usec + i * 1000)) |
32 | dd43edf4 | ths | { |
33 | dd43edf4 | ths | fprintf (stderr, "t0 (%ld, %ld), i %d, t1 (%ld, %ld)\n",
|
34 | dd43edf4 | ths | t_m.tv_sec, t_m.tv_usec, i, t_m1.tv_sec, t_m1.tv_usec); |
35 | dd43edf4 | ths | abort (); |
36 | dd43edf4 | ths | } |
37 | dd43edf4 | ths | |
38 | dd43edf4 | ths | if (time (NULL) != t_m1.tv_sec) |
39 | dd43edf4 | ths | { |
40 | dd43edf4 | ths | fprintf (stderr, "time != gettod\n");
|
41 | dd43edf4 | ths | abort (); |
42 | dd43edf4 | ths | } |
43 | dd43edf4 | ths | |
44 | dd43edf4 | ths | printf ("pass\n");
|
45 | dd43edf4 | ths | exit (0);
|
46 | dd43edf4 | ths | } |