11 // Test if we correctly intercept gettimeofday and clock_gettime, and sleeps
13 int main(int argc, char* argv[])
15 MPI_Init(&argc, &argv);
17 // gettimeofday - First test that two consecutive calls will return the same
18 // time, as computing power is set to -1
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
48 struct timespec tpsleep;
49 clock_gettime(CLOCK_REALTIME, &tp1);
50 clock_gettime(CLOCK_REALTIME, &tp2);
51 if (tp1.tv_sec != tp2.tv_sec || tp1.tv_nsec != tp2.tv_nsec)
52 printf("Error, two consecutive calls to clock_gettime did not return same time (with running power to 0)\n");
54 // nanosleep for 100ns
55 clock_gettime(CLOCK_REALTIME, &tp1);
57 tpsleep.tv_nsec = 100;
58 nanosleep(&tpsleep, NULL);
59 clock_gettime(CLOCK_REALTIME, &tp2);
60 res = (tp2.tv_sec * 1000000000 + tp2.tv_nsec) - (tp1.tv_sec * 1000000000 + tp1.tv_nsec);
61 if (res < 98 || res > 102)
62 printf("Error, nanosleep did not really sleep 100ns, but %ld\n", res);