y2038: testsuite/smokey/y2038: testcase for nanosleep64
PATCH v2 3/3 y2038: testsuite/smokey/y2038: testcase for nanosleep64
From: chensong <[email protected]>
add test case for clock_nanosleep64 in testsuite
---
v2:
1, REALTIME --> MONOTONIC
2, more combinations
3, smokey warning in clock_gettime
4, remove magic number
--- testsuite/smokey/y2038/syscall-tests.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +50 -0
@@ -228,6 +228,52 @@ static int test_sc_cobalt_clock_settime64(void)return 0 ; } +static int test_sc_cobalt_clock_nanosleep64 (void ) +{ +long ret; +int code =__xn_syscode (sc_cobalt_clock_nanosleep64); +struct xn_timespec64 next, rmt; +struct timespec now; + +/* Make sure we don't crash because of NULL pointers */ + ret =syscall (code,NULL ,NULL ,NULL ,NULL ); +if (ret ==-1 && errno ==ENOSYS ) { +smokey_note ("clock_nanosleep64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + +/* Provide a valid 64bit timespec*/ + ret =clock_gettime (CLOCK_MONOTONIC , &now); +if (ret) { +smokey_warning ("clock_gettime failed in clock_nanosleep64." ); +return errno; + } + +/* Providing an invalid address has to deliver EFAULT */ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + (void *)0xdeadbeefUL , &rmt); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = now.tv_sec +1 ; + next.tv_nsec = now.tv_nsec; + + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + &next, (void *)0xdeadbeefUL ); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = next.tv_sec +1 ; + + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , &next, &rmt); +if (!smokey_assert (!ret)) +return errno; + +return 0 ; +} +static int run_y2038 (struct smokey_test *t,int argc,char *const argv[]) {int ret;
@@ -244,5 +290,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])if (ret)return ret; + ret =test_sc_cobalt_clock_nanosleep64 (); +if (ret) +return ret; +return 0 ; }
Signature · 1 line
2.7.4
Quoted 29 lines · Song Chen
testsuite/smokey/y2038/syscall-tests.c +27
-0+static int test_sc_cobalt_clock_nanosleep64(void)+{ +long ret; +int code =__xn_syscode (sc_cobalt_clock_nanosleep64); +struct xn_timespec64 next, rmt; +struct timespec now; + +/* Make sure we don't crash because of NULL pointers */ + ret =syscall (code,NULL ,NULL ,NULL ,NULL ); +if (ret ==-1 && errno ==ENOSYS ) { +smokey_note ("clock_nanosleep64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + +/* Provide a valid 64bit timespec*/ + ret =clock_gettime (CLOCK_MONOTONIC , &now); +if (ret) { +smokey_warning ("clock_gettime failed in clock_nanosleep64." ); +return errno; + } + +/* Providing an invalid address has to deliver EFAULT */ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + (void *)0xdeadbeefUL , &rmt); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno;
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 268
Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10
-0+ + next.tv_sec = now.tv_sec +1 ; + next.tv_nsec = now.tv_nsec; + + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + &next, (void *)0xdeadbeefUL ); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = next.tv_sec +1 ;
That looks like duplicate code. The last call to nanosleep was an error handling check, so we would end up here adding 2 secs to "now".
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 273
Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , &next, &rmt); +if (!smokey_assert (!ret)) +return errno; +
As long as nobody has a better idea we should make sure that we don't come back to early. Checking for the upper boundary requires some magic numbers as already discussed, so let's check at least the lower boundary.
Quoted 16 lines
testsuite/smokey/y2038/syscall-tests.c +3
-0+return 0 ; +} +static int
run_y2038(struct smokey_test *t, int argc, char *const argv[]){
int ret;testsuite/smokey/y2038/syscall-tests.c +0
-0@@ -244,5 +290,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) if (ret) return ret;testsuite/smokey/y2038/syscall-tests.c +4
-0+ ret =test_sc_cobalt_clock_nanosleep64 (); +if (ret) +return ret; +return 0;
}
Quoted 35 lines · Florian
Quoted 34 lines · Song Chen
testsuite/smokey/y2038/syscall-tests.c +32
-0+static int test_sc_cobalt_clock_nanosleep64(void)+{ +long ret; +int code =__xn_syscode (sc_cobalt_clock_nanosleep64); +struct xn_timespec64 next, rmt; +struct timespec now; + +/* Make sure we don't crash because of NULL pointers */ + ret =syscall (code,NULL ,NULL ,NULL ,NULL ); +if (ret ==-1 && errno ==ENOSYS ) { +smokey_note ("clock_nanosleep64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + +/* Provide a valid 64bit timespec*/ + ret =clock_gettime (CLOCK_MONOTONIC , &now); +if (ret) { +smokey_warning ("clock_gettime failed in clock_nanosleep64." ); +return errno; + } + +/* Providing an invalid address has to deliver EFAULT */ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + (void *)0xdeadbeefUL , &rmt); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = now.tv_sec +1 ; + next.tv_nsec = now.tv_nsec; + + ret = syscall(code, CLOCK_MONOTONIC, TIMER_ABSTIME,
Quoted 8 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 268
Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ &next, (void *)0xdeadbeefUL); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = next.tv_sec +1 ;That looks like duplicate code. The last call to nanosleep was an error handling check, so we would end up here adding 2 secs to "now".
point taken
Quoted 11 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 273
Quoted 6 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , &next, &rmt); +if (!smokey_assert (!ret)) +return errno; +As long as nobody has a better idea we should make sure that we don't come back to early. Checking for the upper boundary requires some magic numbers as already discussed, so let's check at least the lower boundary.
point is not taken, could you please explain upper/lower boundary more specifically, thanks.
Song
Quoted 18 lines
Quoted 17 lines
testsuite/smokey/y2038/syscall-tests.c +7
-0+return 0 ; +} + static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) { int ret;@@ -244,5 +290,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) if (ret) return ret; + ret =test_sc_cobalt_clock_nanosleep64 (); +if (ret) +return ret; + return 0; }
Quoted 62 lines · On Tue, 2021-04-27 at 01:05 +0800, [email protected] wrote:
Quoted 38 lines · Florian
Quoted 37 lines · Song Chen
testsuite/smokey/y2038/syscall-tests.c +32
-0+static int test_sc_cobalt_clock_nanosleep64(void)+{ +long ret; +int code =__xn_syscode (sc_cobalt_clock_nanosleep64); +struct xn_timespec64 next, rmt; +struct timespec now; + +/* Make sure we don't crash because of NULL pointers */ + ret =syscall (code,NULL ,NULL ,NULL ,NULL ); +if (ret ==-1 && errno ==ENOSYS ) { +smokey_note ("clock_nanosleep64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + +/* Provide a valid 64bit timespec*/ + ret =clock_gettime (CLOCK_MONOTONIC , &now); +if (ret) { +smokey_warning ("clock_gettime failed in clock_nanosleep64." ); +return errno; + } + +/* Providing an invalid address has to deliver EFAULT */ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + (void *)0xdeadbeefUL , &rmt); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = now.tv_sec +1 ; + next.tv_nsec = now.tv_nsec; + + ret = syscall(code, CLOCK_MONOTONIC, TIMER_ABSTIME,Quoted 8 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 268
Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ &next, (void *)0xdeadbeefUL); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = next.tv_sec +1 ;That looks like duplicate code. The last call to nanosleep was an error handling check, so we would end up here adding 2 secs to "now".
point taken
Quoted 11 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 273
Quoted 6 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , &next, &rmt); +if (!smokey_assert (!ret)) +return errno; +As long as nobody has a better idea we should make sure that we don't come back to early. Checking for the upper boundary requires some magic numbers as already discussed, so let's check at least the lower boundary.
Quoted 2 lines
point is not taken, could you please explain upper/lower boundary more specifically, thanks.
Lower boundary: We should not come back too early
Upper boundary: We should not come back too late
While the lower boundary is defined, the upper boundary depends on the used architecture and/or platform.
I had something similar to [1] in mind. That's the test case for nanosleep() in glibc. Checking the lower boundary by making sure we don't come back too early.
Do you agree? Was that helpful?
[1] https://elixir.bootlin.com/glibc/latest/source/posix/tst-nanosleep.c
Quoted 24 lines
Song
Quoted 21 lines
Quoted 20 lines
testsuite/smokey/y2038/syscall-tests.c +3
-0+return 0 ; +} +static int
run_y2038(struct smokey_test *t, int argc, char *const argv[]){
int ret;testsuite/smokey/y2038/syscall-tests.c +0
-0@@ -244,5 +290,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) if (ret) return ret;testsuite/smokey/y2038/syscall-tests.c +4
-0+ ret =test_sc_cobalt_clock_nanosleep64 (); +if (ret) +return ret; +return 0;
}
Quoted 69 lines · Florian
Quoted 62 lines · On Tue, 2021-04-27 at 01:05 +0800, [email protected] wrote:
Quoted 38 lines · Florian
Quoted 37 lines · Song Chen
testsuite/smokey/y2038/syscall-tests.c +32
-0+static int test_sc_cobalt_clock_nanosleep64(void)+{ +long ret; +int code =__xn_syscode (sc_cobalt_clock_nanosleep64); +struct xn_timespec64 next, rmt; +struct timespec now; + +/* Make sure we don't crash because of NULL pointers */ + ret =syscall (code,NULL ,NULL ,NULL ,NULL ); +if (ret ==-1 && errno ==ENOSYS ) { +smokey_note ("clock_nanosleep64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + +/* Provide a valid 64bit timespec*/ + ret =clock_gettime (CLOCK_MONOTONIC , &now); +if (ret) { +smokey_warning ("clock_gettime failed in clock_nanosleep64." ); +return errno; + } + +/* Providing an invalid address has to deliver EFAULT */ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , + (void *)0xdeadbeefUL , &rmt); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = now.tv_sec +1 ; + next.tv_nsec = now.tv_nsec; + + ret = syscall(code, CLOCK_MONOTONIC, TIMER_ABSTIME,Quoted 8 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 268
Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ &next, (void *)0xdeadbeefUL); +if (!smokey_assert (ret ==-1 ) || !smokey_assert (errno ==EFAULT )) +return errno; + + next.tv_sec = next.tv_sec +1 ;That looks like duplicate code. The last call to nanosleep was an error handling check, so we would end up here adding 2 secs to "now".
point taken
Quoted 11 lines
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_settime64(void) · line 273
Quoted 6 lines
testsuite/smokey/y2038/syscall-tests.c +5
-0+ + ret =syscall (code,CLOCK_MONOTONIC ,TIMER_ABSTIME , &next, &rmt); +if (!smokey_assert (!ret)) +return errno; +As long as nobody has a better idea we should make sure that we don't come back to early. Checking for the upper boundary requires some magic numbers as already discussed, so let's check at least the lower boundary.
Quoted 2 lines
point is not taken, could you please explain upper/lower boundary more specifically, thanks.
Lower boundary: We should not come back too early
Upper boundary: We should not come back too late
Quoted 8 lines
While the lower boundary is defined, the upper boundary depends on the used architecture and/or platform.
I had something similar to [1] in mind. That's the test case for
nanosleep()in glibc. Checking the lower boundary by making sure we don't come back too early.Do you agree? Was that helpful?
make sense, understood, thanks.
Song
Quoted 29 lines
[1] https://elixir.bootlin.com/glibc/latest/source/posix/tst-nanosleep.c
Quoted 24 lines
Song
Quoted 21 lines
Quoted 20 lines
testsuite/smokey/y2038/syscall-tests.c +7
-0+return 0 ; +} + static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) { int ret;@@ -244,5 +290,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) if (ret) return ret; + ret =test_sc_cobalt_clock_nanosleep64 (); +if (ret) +return ret; + return 0; }