Message ID | 807fb7a23ce8ce26c429922643fb2906ba7f0622.1553797867.git-series.mac@mcrowe.com |
---|---|
State | New |
Headers | show |
Series | Improve various nptl tests | expand |
On 29/03/2019 01:31, Mike Crowe wrote: > * nptl/tst-sem5.c(do_test): Use xclock_gettime and > TEST_TIMESPEC_NOW_OR_AFTER from libsupport. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> > --- > ChangeLog | 7 ++++++- > nptl/tst-sem5.c | 21 +++++---------------- > 2 files changed, 11 insertions(+), 17 deletions(-) > > diff --git a/ChangeLog b/ChangeLog > index 5ceb3a7..436736d 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,4 +1,9 @@ > -2019-03-20 Mike Crowe <mac@mcrowe.com> > +2019-03-28 Mike Crowe <mac@mcrowe.com> > + > + * nptl/tst-sem5.c(do_test): Use xclock_gettime and > + TEST_TIMESPEC_NOW_OR_AFTER from libsupport. > + > +2019-03-28 Mike Crowe <mac@mcrowe.com> > > * support/timespec.h: Create header to provide timespec helper > functions from sysdeps/pthread/posix-timer.h and macros in the > diff --git a/nptl/tst-sem5.c b/nptl/tst-sem5.c > index 50ab6f9..b27237e 100644 > --- a/nptl/tst-sem5.c > +++ b/nptl/tst-sem5.c > @@ -22,6 +22,7 @@ > #include <unistd.h> > #include <sys/time.h> > #include <support/check.h> > +#include <support/timespec.h> > > > static int > @@ -29,31 +30,19 @@ do_test (void) > { > sem_t s; > struct timespec ts; > - struct timeval tv; > > TEST_COMPARE (sem_init (&s, 0, 1), 0); > TEST_COMPARE (TEMP_FAILURE_RETRY (sem_wait (&s)), 0); > - TEST_COMPARE (gettimeofday (&tv, NULL), 0); > - > - TIMEVAL_TO_TIMESPEC (&tv, &ts); > + xclock_gettime(CLOCK_REALTIME, &ts); Space after xclock_gettime. > > /* We wait for half a second. */ > - ts.tv_nsec += 500000000; > - if (ts.tv_nsec >= 1000000000) > - { > - ++ts.tv_sec; > - ts.tv_nsec -= 1000000000; > - } > + const struct timespec ts_delay = { 0, 500000000 }; > + timespec_add(&ts, &ts, &ts_delay); Space after timespec_add. > > errno = 0; > TEST_COMPARE (TEMP_FAILURE_RETRY (sem_timedwait (&s, &ts)), -1); > TEST_COMPARE (errno, ETIMEDOUT); > - > - struct timespec ts2; > - TEST_COMPARE (clock_gettime (CLOCK_REALTIME, &ts2), 0); > - > - TEST_VERIFY (ts2.tv_sec > ts.tv_sec > - || (ts2.tv_sec == ts.tv_sec && ts2.tv_nsec > ts.tv_nsec)); > + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); > > return 0; > } >
diff --git a/ChangeLog b/ChangeLog index 5ceb3a7..436736d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2019-03-20 Mike Crowe <mac@mcrowe.com> +2019-03-28 Mike Crowe <mac@mcrowe.com> + + * nptl/tst-sem5.c(do_test): Use xclock_gettime and + TEST_TIMESPEC_NOW_OR_AFTER from libsupport. + +2019-03-28 Mike Crowe <mac@mcrowe.com> * support/timespec.h: Create header to provide timespec helper functions from sysdeps/pthread/posix-timer.h and macros in the diff --git a/nptl/tst-sem5.c b/nptl/tst-sem5.c index 50ab6f9..b27237e 100644 --- a/nptl/tst-sem5.c +++ b/nptl/tst-sem5.c @@ -22,6 +22,7 @@ #include <unistd.h> #include <sys/time.h> #include <support/check.h> +#include <support/timespec.h> static int @@ -29,31 +30,19 @@ do_test (void) { sem_t s; struct timespec ts; - struct timeval tv; TEST_COMPARE (sem_init (&s, 0, 1), 0); TEST_COMPARE (TEMP_FAILURE_RETRY (sem_wait (&s)), 0); - TEST_COMPARE (gettimeofday (&tv, NULL), 0); - - TIMEVAL_TO_TIMESPEC (&tv, &ts); + xclock_gettime(CLOCK_REALTIME, &ts); /* We wait for half a second. */ - ts.tv_nsec += 500000000; - if (ts.tv_nsec >= 1000000000) - { - ++ts.tv_sec; - ts.tv_nsec -= 1000000000; - } + const struct timespec ts_delay = { 0, 500000000 }; + timespec_add(&ts, &ts, &ts_delay); errno = 0; TEST_COMPARE (TEMP_FAILURE_RETRY (sem_timedwait (&s, &ts)), -1); TEST_COMPARE (errno, ETIMEDOUT); - - struct timespec ts2; - TEST_COMPARE (clock_gettime (CLOCK_REALTIME, &ts2), 0); - - TEST_VERIFY (ts2.tv_sec > ts.tv_sec - || (ts2.tv_sec == ts.tv_sec && ts2.tv_nsec > ts.tv_nsec)); + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); return 0; }