12 //Test if we correctly intercept gettimeofday and clock_gettime, and sleeps
14 int main( int argc, char *argv[] )
16 MPI_Init( &argc, &argv );
18 //gettimeofday - First test that two consecutive calls will return the same
19 //time, as computing power is set to -1
21 struct timeval tv1, tv2;
22 gettimeofday (&tv1, NULL);
23 gettimeofday (&tv2, NULL);
24 if ((tv1.tv_sec != tv2.tv_sec) || (tv1.tv_usec != tv2.tv_usec))
25 printf("Error, two consecutive calls to gettimeofday did not return same time (with cpu_threshold set to 0)\n");
28 gettimeofday (&tv1, NULL);
30 gettimeofday (&tv2, NULL);
31 long res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
32 if (res < 999998 || res > 1000002)
33 printf("Error, sleep(1) did not exactly slept 1s\n");
36 gettimeofday (&tv1, NULL);
38 gettimeofday (&tv2, NULL);
39 res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
40 if (res <98 || res > 102)
41 printf("Error, usleep did not really sleep 100us, but %ld\n", res);
44 // clock_gettime, only if available
46 struct timespec tp1, tp2, tpsleep;
47 clock_gettime (CLOCK_REALTIME, &tp1);
48 clock_gettime (CLOCK_REALTIME, &tp2);
49 if ((tp1.tv_sec != tp2.tv_sec) || (tp1.tv_nsec != tp2.tv_nsec))
50 printf("Error, two consecutive calls to gettimeofday did not return same time (with running power to 0)\n");
53 clock_gettime (CLOCK_REALTIME, &tp1);
56 nanosleep(&tpsleep, NULL);
57 clock_gettime (CLOCK_REALTIME, &tp2);
58 res = ((tp2.tv_sec * 1000000000 + tp2.tv_nsec)) - ((tp1.tv_sec * 1000000000 + tp1.tv_nsec));
59 if (res <98 || res > 102)
60 printf("Error, nanosleep did not really sleep 100ns, but %ld\n", res);