[PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-19 Thread Song Chen via Xenomai
From: chensong 

add test case for clock_nanosleep64 in testsuite

Signed-off-by: chensong 

---
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(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c 
b/testsuite/smokey/y2038/syscall-tests.c
index 990e05c..0ea6ddd 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
 }
-- 
2.7.4




[PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-21 Thread Song Chen via Xenomai
From: chensong 

add test case for clock_nanosleep64 in testsuite

Signed-off-by: chensong 

---
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(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c 
b/testsuite/smokey/y2038/syscall-tests.c
index 990e05c..0ea6ddd 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
 }
-- 
2.7.4




Re: [PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-20 Thread Jan Kiszka via Xenomai
On 20.04.21 08:25, Song Chen via Xenomai wrote:
> From: chensong 
> 
> add test case for clock_nanosleep64 in testsuite
> 
> Signed-off-by: chensong 
> 
> ---
> 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(+)
> 
> diff --git a/testsuite/smokey/y2038/syscall-tests.c 
> b/testsuite/smokey/y2038/syscall-tests.c
> index 990e05c..0ea6ddd 100644
> --- a/testsuite/smokey/y2038/syscall-tests.c
> +++ b/testsuite/smokey/y2038/syscall-tests.c
> @@ -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;
>  }
> 

Looks like patch 2/3 didn't make it to the list. Also your other series
arrived incompletely. Please check. And also consider adding a cover
letter in order to associate patches of a series.

Thanks,
Jan

PS: Dropping chens...@tj.kylinos.cn as your server does not know you
anymore.

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux



Re: [PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-27 Thread chensong_2000--- via Xenomai




在 2021/4/23 下午8:48, Bezdeka, Florian 写道:

On Wed, 2021-04-21 at 16:38 +0800, Song Chen wrote:
  


+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;


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



+
+   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




+   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;
  }






Re: [PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-27 Thread Bezdeka, Florian via Xenomai
On Tue, 2021-04-27 at 01:05 +0800, chensong_2...@189.cn wrote:
> 
> 在 2021/4/23 下午8:48, Bezdeka, Florian 写道:
> > On Wed, 2021-04-21 at 16:38 +0800, Song Chen wrote:
> > >   
> > > 
> > > 
> > > 
> > > 
> > > +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;
> > 
> > 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
> > 
> > > +
> > > + 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.

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

> 
> Song
> 
> > 
> > > + 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;
> > >   }
> > 



Re: [PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-27 Thread chensong_2000--- via Xenomai




在 2021/4/26 下午7:57, Bezdeka, Florian 写道:

On Tue, 2021-04-27 at 01:05 +0800, chensong_2...@189.cn wrote:


在 2021/4/23 下午8:48, Bezdeka, Florian 写道:

On Wed, 2021-04-21 at 16:38 +0800, Song Chen wrote:
   





+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;


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



+
+   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.


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?


make sense, understood, thanks.

Song




[1] https://elixir.bootlin.com/glibc/latest/source/posix/tst-nanosleep.c



Song




+   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;
   }








Re: [PATCH v2 3/3] y2038: testsuite/smokey/y2038: testcase for nanosleep64

2021-04-27 Thread Bezdeka, Florian via Xenomai
On Wed, 2021-04-21 at 16:38 +0800, Song Chen wrote:
>  
> 
> +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;

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".

> +
> + 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.

> + 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;
>  }