• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 
main()5 int main() {
6   struct timeval tv1;
7   struct timeval tv2;
8   long long s1;
9   long long us1;
10   long long s2;
11   long long us2;
12   int r;
13   int success = 0;
14 
15   r = gettimeofday(&tv1, NULL);
16   assert(r == 0);
17   s1 = tv1.tv_sec;
18   us1 = tv1.tv_usec;
19 
20   for (int i = 0; i < 10000; i++) {
21     r = gettimeofday(&tv2, NULL);
22     assert(r == 0);
23     s2 = tv2.tv_sec;
24     us2 = tv2.tv_usec;
25     assert(s1 <= s2);
26 
27     // Verify that some time has passed.
28     if (s2 > s1 || (s2 == s1 && us2 > us1)) {
29       success = 1;
30       break;
31     }
32   }
33 
34   assert(success == 1);
35 }
36