Home | History | Annotate | Line # | Download | only in c
      1  1.1  christos /* Basic time functionality test.  */
      2  1.1  christos #include <stdio.h>
      3  1.1  christos #include <stdlib.h>
      4  1.1  christos #include <time.h>
      5  1.1  christos #include <sys/time.h>
      6  1.1  christos int
      7  1.1  christos main (void)
      8  1.1  christos {
      9  1.1  christos   struct timeval t_m = {0, 0};
     10  1.1  christos   time_t t;
     11  1.1  christos 
     12  1.1  christos   if ((t = time (NULL)) == (time_t) -1
     13  1.1  christos       || gettimeofday (&t_m, NULL) != 0
     14  1.1  christos       || t_m.tv_sec == 0
     15  1.1  christos 
     16  1.1  christos       /* We assume there will be no delay between the time and
     17  1.1  christos 	 gettimeofday calls above, but allow a timer-tick to make the
     18  1.1  christos 	 seconds increase by one.  */
     19  1.1  christos       || (t != t_m.tv_sec && t+1 != t_m.tv_sec))
     20  1.1  christos     {
     21  1.1  christos       printf ("fail\n");
     22  1.1  christos       exit (1);
     23  1.1  christos     }
     24  1.1  christos 
     25  1.1  christos   printf ("pass\n");
     26  1.1  christos   exit (0);
     27  1.1  christos }
     28