From: Szabolcs Nagy Date: Thu, 31 Oct 2019 01:01:57 +0000 (+0000) Subject: change syscall-sign-extend test X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=c6fc4f04d62c2c495717268f73427f83ff685ff5 change syscall-sign-extend test don't use SYS_clock_gettime because raw syscall is not time64 safe, use a SYS_read which likely works across various abis without issues. --- diff --git a/src/regression/syscall-sign-extend.c b/src/regression/syscall-sign-extend.c index 7d3e0d8..ea47ab3 100644 --- a/src/regression/syscall-sign-extend.c +++ b/src/regression/syscall-sign-extend.c @@ -1,44 +1,26 @@ // commit 5f95f965e933c5b155db75520ac27c92ddbcf400 2014-03-18 // syscall should not sign extend pointers on x32 #define _GNU_SOURCE -#include #include -#include -#include +#include +#include #include +#include #include "test.h" -#define T(f) ((f) && (t_error(#f " failed: %s\n", strerror(errno)), 0)) - -static unsigned long long tsdiff(struct timespec ts2, struct timespec ts) -{ - if (ts2.tv_nsec < ts.tv_nsec) { - ts2.tv_nsec += 1000000000; - ts2.tv_sec--; - } - if (ts2.tv_sec < ts.tv_sec) { - t_error("non-monotonic SYS_clock_gettime vs clock_gettime: %llu ns\n", - (ts.tv_sec - ts2.tv_sec)*1000000000ULL + ts.tv_nsec - ts2.tv_nsec); - return 0; - } - return (ts2.tv_sec - ts.tv_sec)*1000000000ULL + (ts2.tv_nsec - ts.tv_nsec); -} +#define T(f) (!(f) && (t_error(#f " failed: %s\n", strerror(errno)), 0)) int main(void) { - struct timespec ts, ts2; - unsigned long long diff; + char buf[1] = {1}; + int fd; + int r; // test syscall with pointer - T(syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts)); - - // check if timespec is filled correctly - T(clock_gettime(CLOCK_REALTIME, &ts2)); - // adjust because linux vdso is non-monotonic wrt the syscall.. - ts.tv_nsec += 2; - diff = tsdiff(ts2, ts); - if (diff > 5 * 1000000000ULL) - t_error("large diff between clock_gettime calls: %llu ns\n", diff); + T((fd = open("/dev/zero", O_RDONLY)) >= 0); + T((r = syscall(SYS_read, fd, buf, 1)) == 1); + if (buf[0] != 0) + t_error("read %d instead of 0\n", buf[0]); return t_status; }