]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Use recent additions to libsupport in tst-sem5
authorMike Crowe <mac@mcrowe.com>
Thu, 9 May 2019 17:06:06 +0000 (14:06 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 9 May 2019 17:33:53 +0000 (14:33 -0300)
Checked on x86_64-linux-gnu and i686-linux-gnu.

* nptl/tst-sem5.c(do_test): Use xclock_gettime, timespec_add and
TEST_TIMESPEC_NOW_OR_AFTER from libsupport.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
ChangeLog
nptl/tst-sem5.c

index eb0f0460bfbf47e5c6ff08d4fa8902c5a3b2d69b..a5b37febbd75216c0026284c386b3191fa706f92 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2019-05-09  Mike Crowe <mac@mcrowe.com>
 
+       * nptl/tst-sem5.c (do_test): Use xclock_gettime, timespec_add and
+       TEST_TIMESPEC_NOW_OR_AFTER from libsupport.
+
        * nptl/tst-cond11.c: Use libsupport.
 
        * support/timespec.h: New file.  Provide timespec helper functions
index 50ab6f932c6954ebf388b57ea0cd654e2690fd94..396222b85f647feea1035c23bb9e48d4a9c1d972 100644 (file)
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <support/check.h>
+#include <support/timespec.h>
+#include <support/xtime.h>
 
 
 static int
@@ -29,31 +31,18 @@ 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);
 
   /* We wait for half a second.  */
-  ts.tv_nsec += 500000000;
-  if (ts.tv_nsec >= 1000000000)
-    {
-      ++ts.tv_sec;
-      ts.tv_nsec -= 1000000000;
-    }
+  xclock_gettime (CLOCK_REALTIME, &ts);
+  ts = timespec_add (ts, make_timespec (0, TIMESPEC_HZ/2));
 
   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;
 }