sign-extend regression test for x32
[libc-test] / src / regression / syscall-sign-extend.c
1 // commit 5f95f965e933c5b155db75520ac27c92ddbcf400 2014-03-18
2 // syscall should not sign extend pointers on x32
3 #define _GNU_SOURCE
4 #include <string.h>
5 #include <errno.h>
6 #include <unistd.h>
7 #include <time.h>
8 #include <sys/syscall.h>
9 #include "test.h"
10
11 #define T(f) ((f) && (t_error(#f " failed: %s\n", strerror(errno)), 0))
12
13 static unsigned long long tsdiff(struct timespec ts2, struct timespec ts)
14 {
15         if (ts2.tv_nsec < ts.tv_nsec) {
16                 ts2.tv_nsec += 1000000000;
17                 ts2.tv_sec--;
18         }
19         if (ts2.tv_sec < ts.tv_sec)
20                 return -1;
21         return (ts2.tv_sec - ts.tv_sec)*1000000000ULL + (ts2.tv_nsec - ts.tv_nsec);
22 }
23
24 int main(void)
25 {
26         struct timespec ts, ts2;
27         unsigned long long diff;
28
29         // test syscall with pointer
30         T(syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts));
31
32         // check if timespec is filled correctly
33         T(clock_gettime(CLOCK_REALTIME, &ts2));
34         diff = tsdiff(ts2, ts);
35         if (diff > 10 * 1000000000ULL)
36                 t_error("large diff between clock_gettime calls: %llu ns\n", diff);
37
38         return t_status;
39 }