1 // commit 5f95f965e933c5b155db75520ac27c92ddbcf400 2014-03-18
2 // syscall should not sign extend pointers on x32
8 #include <sys/syscall.h>
11 #define T(f) ((f) && (t_error(#f " failed: %s\n", strerror(errno)), 0))
13 static unsigned long long tsdiff(struct timespec ts2, struct timespec ts)
15 if (ts2.tv_nsec < ts.tv_nsec) {
16 ts2.tv_nsec += 1000000000;
19 if (ts2.tv_sec < ts.tv_sec) {
20 t_error("non-monotonic SYS_clock_gettime vs clock_gettime: %llu ns\n",
21 (ts.tv_sec - ts2.tv_sec)*1000000000ULL + ts.tv_nsec - ts2.tv_nsec);
24 return (ts2.tv_sec - ts.tv_sec)*1000000000ULL + (ts2.tv_nsec - ts.tv_nsec);
29 struct timespec ts, ts2;
30 unsigned long long diff;
32 // test syscall with pointer
33 T(syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts));
35 // check if timespec is filled correctly
36 T(clock_gettime(CLOCK_REALTIME, &ts2));
37 // adjust because linux vdso is non-monotonic wrt the syscall..
39 diff = tsdiff(ts2, ts);
40 if (diff > 5 * 1000000000ULL)
41 t_error("large diff between clock_gettime calls: %llu ns\n", diff);