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