Jan Kiszka <[email protected]> writes:

> On 04.06.21 13:43, Jan Kiszka via Xenomai wrote:
>> On 04.06.21 13:41, Jan Kiszka via Xenomai wrote:
>>> On 01.06.21 11:43, Florian Bezdeka wrote:
>>>> From: chensong <[email protected]>
>>>>
>>>> Add test case for clock_nanosleep64 in smokey testsuite
>>>>
>>>> Signed-off-by: chensong <[email protected]>
>>>> [Florian: Reword commit msg, syscall()->XENOMAI_SYSCALLx()]
>>>> Signed-off-by: Florian Bezdeka <[email protected]>
>>>> ---
>>>>  testsuite/smokey/y2038/syscall-tests.c | 67 ++++++++++++++++++++++++++
>>>>  1 file changed, 67 insertions(+)
>>>>
>>>> diff --git a/testsuite/smokey/y2038/syscall-tests.c 
>>>> b/testsuite/smokey/y2038/syscall-tests.c
>>>> index 840be89a5..54d529b6b 100644
>>>> --- a/testsuite/smokey/y2038/syscall-tests.c
>>>> +++ b/testsuite/smokey/y2038/syscall-tests.c
>>>> @@ -242,6 +242,69 @@ static int test_sc_cobalt_clock_settime64(void)
>>>>    return 0;
>>>>  }
>>>>  
>>>> +static int test_sc_cobalt_clock_nanosleep64(void)
>>>> +{
>>>> +  int ret;
>>>> +  int sc_nr = sc_cobalt_clock_nanosleep64;
>>>> +  struct xn_timespec64 next, rmt;
>>>> +  struct timespec ts1, ts2, delta;
>>>> +  long interval = 1;
>>>> +
>>>> +  /* Make sure we don't crash because of NULL pointers */
>>>> +  ret = XENOMAI_SYSCALL4(sc_nr, NULL, NULL, NULL, NULL);
>>>> +  if (ret == -ENOSYS) {
>>>> +          smokey_note("clock_nanosleep64: skipped. (no kernel support)");
>>>> +          return 0; // Not implemented, nothing to test, success
>>>> +  }
>>>> +  if (!smokey_assert(ret == -EFAULT))
>>>> +          return ret ? ret : -EINVAL;
>>>> +
>>>> +  /* Providing an invalid address has to deliver EFAULT */
>>>> +  ret = XENOMAI_SYSCALL4(sc_nr, CLOCK_MONOTONIC, TIMER_ABSTIME,
>>>> +                         (void *)0xdeadbeefUL, &rmt);
>>>> +  if (!smokey_assert(ret == -EFAULT))
>>>> +          return ret ? ret : -EINVAL;
>>>> +
>>>> +  /* Provide a valid 64bit timespec, round 1 */
>>>> +  ret = clock_gettime(CLOCK_MONOTONIC, &ts1);
>>>> +  if (ret)
>>>> +          return -errno;
>>>> +
>>>> +  next.tv_sec  = ts1.tv_sec + interval;
>>>> +  next.tv_nsec = ts1.tv_nsec;
>>>> +
>>>> +  ret = XENOMAI_SYSCALL4(sc_nr, CLOCK_MONOTONIC, TIMER_ABSTIME,
>>>> +                         &next, (void *)0xdeadbeefUL);
>>>> +  if (!smokey_assert(!ret))
>>>> +          return ret ? ret : -EINVAL;
>>>
>>> Unneeded test here - ret is != 0.
>>>
>>>> +
>>>> +  ret = clock_gettime(CLOCK_MONOTONIC, &ts2);
>>>> +  if (ret)
>>>> +          return -errno;
>>>> +
>>>> +  timespec_sub(&delta, &ts2, &ts1);
>>>> +  if (delta.tv_sec < interval)
>>>> +          smokey_warning("nanosleep didn't sleep long enough.");
>>>> +
>>>> +  /* Provide a valid 64bit timespec, round 2*/
>>>> +  next.tv_sec  = ts2.tv_sec + interval;
>>>> +  next.tv_nsec = ts2.tv_nsec;
>>>> +
>>>> +  ret = XENOMAI_SYSCALL4(sc_nr, CLOCK_MONOTONIC, TIMER_ABSTIME, &next, 
>>>> &rmt);
>>>> +  if (!smokey_assert(!ret))
>>>> +          return ret ? ret : -EINVAL;
>>>
>>> Same here.
>>>
>>> I can fix those up - once I understood why they trigger here ATM.
>>>
>> 
>> In fact, if we want to return the real error, errno needs to be
>> consulted. What is the intention then?
>
> Err, no, it's direct syscall invocation, no errno at this point yet.
>
> Found the reason for the failing test meanwhile: I was on wip/dovetail
> already, and there we have
>
> static inline int pipeline_set_wallclock(xnticks_t epoch_ns)
> {
>       return -EOPNOTSUPP;
> }
>
> Philippe, any particular reason for this?
>

Yes, because setting the wallclock from oob context over Dovetail does
not make sense because Xenomai shares the time base with the common
kernel when running on top of Dovetail. The latter can jump to the vDSO
for reading time using the common services on the regular time base, but
setting that time base does require a regular in-band context.

What you could do is handing the clock_settime request over to the glibc
instead, but that would entail a stage switch to in-band then.

-- 
Philippe.

Reply via email to