public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/pthread_clockjoin_np] nptl: Convert tst-join3 to use libsupport
@ 2019-10-31 13:10 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2019-10-31 13:10 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7621b46e258ed026560cf9aa4b593240505dfa5d

commit 7621b46e258ed026560cf9aa4b593240505dfa5d
Author: Mike Crowe <mac@mcrowe.com>
Date:   Thu Oct 31 09:08:10 2019 -0300

    nptl: Convert tst-join3 to use libsupport
    
    Checked on x86_64-linux-gnu.
    
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Diff:
---
 nptl/tst-join3.c | 86 +++++++++++++-------------------------------------------
 1 file changed, 20 insertions(+), 66 deletions(-)

diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
index d8785c5..a4ae459 100644
--- a/nptl/tst-join3.c
+++ b/nptl/tst-join3.c
@@ -22,6 +22,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
+#include <support/check.h>
+#include <support/timespec.h>
+#include <support/xthread.h>
+#include <support/xtime.h>
 
 
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
@@ -30,11 +34,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 static void *
 tf (void *arg)
 {
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("child: mutex_lock failed");
-      return NULL;
-    }
+  xpthread_mutex_lock (&lock);
 
   return (void *) 42l;
 }
@@ -43,80 +43,34 @@ tf (void *arg)
 static int
 do_test (void)
 {
-  pthread_t th;
-
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("mutex_lock failed");
-      exit (1);
-    }
-
-  if (pthread_create (&th, NULL, tf, NULL) != 0)
-    {
-      puts ("mutex_create failed");
-      exit (1);
-    }
+  xpthread_mutex_lock (&lock);
+  pthread_t th = xpthread_create (NULL, tf, NULL);
 
   void *status;
-  struct timespec ts;
-  struct timeval tv;
-  (void) gettimeofday (&tv, NULL);
-  TIMEVAL_TO_TIMESPEC (&tv, &ts);
-  ts.tv_nsec += 200000000;
-  if (ts.tv_nsec >= 1000000000)
-    {
-      ts.tv_nsec -= 1000000000;
-      ++ts.tv_sec;
-    }
-  int val = pthread_timedjoin_np (th, &status, &ts);
-  if (val == 0)
-    {
-      puts ("1st timedjoin succeeded");
-      exit (1);
-    }
-  else if (val != ETIMEDOUT)
-    {
-      puts ("1st timedjoin didn't return ETIMEDOUT");
-      exit (1);
-    }
+  struct timespec timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                                          make_timespec (0, 200000000));
 
-  if (pthread_mutex_unlock (&lock) != 0)
-    {
-      puts ("mutex_unlock failed");
-      exit (1);
-    }
+  int val = pthread_timedjoin_np (th, &status, &timeout);
+  TEST_COMPARE (val, ETIMEDOUT);
+
+  xpthread_mutex_unlock (&lock);
 
   while (1)
     {
-      (void) gettimeofday (&tv, NULL);
-      TIMEVAL_TO_TIMESPEC (&tv, &ts);
-      ts.tv_nsec += 200000000;
-      if (ts.tv_nsec >= 1000000000)
-	{
-	  ts.tv_nsec -= 1000000000;
-	  ++ts.tv_sec;
-	}
-
-      val = pthread_timedjoin_np (th, &status, &ts);
+      timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                              make_timespec (0, 200000000));
+
+      val = pthread_timedjoin_np (th, &status, &timeout);
       if (val == 0)
 	break;
 
-      if (val != ETIMEDOUT)
-	{
-	  printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
-		  strerror (val), val);
-	  exit (1);
-	}
+      TEST_COMPARE (val, ETIMEDOUT);
     }
 
   if (status != (void *) 42l)
-    {
-      printf ("return value %p, expected %p\n", status, (void *) 42l);
-      exit (1);
-    }
+    FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
 
   return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/azanella/pthread_clockjoin_np] nptl: Convert tst-join3 to use libsupport
@ 2019-10-31 20:51 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2019-10-31 20:51 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a2b8a325331a1d0e0fe09ba055fe2056f533f808

commit a2b8a325331a1d0e0fe09ba055fe2056f533f808
Author: Mike Crowe <mac@mcrowe.com>
Date:   Thu Oct 31 09:08:10 2019 -0300

    nptl: Convert tst-join3 to use libsupport
    
    Checked on x86_64-linux-gnu.
    
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Diff:
---
 nptl/tst-join3.c | 86 +++++++++++++-------------------------------------------
 1 file changed, 20 insertions(+), 66 deletions(-)

diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
index d8785c5..a4ae459 100644
--- a/nptl/tst-join3.c
+++ b/nptl/tst-join3.c
@@ -22,6 +22,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
+#include <support/check.h>
+#include <support/timespec.h>
+#include <support/xthread.h>
+#include <support/xtime.h>
 
 
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
@@ -30,11 +34,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 static void *
 tf (void *arg)
 {
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("child: mutex_lock failed");
-      return NULL;
-    }
+  xpthread_mutex_lock (&lock);
 
   return (void *) 42l;
 }
@@ -43,80 +43,34 @@ tf (void *arg)
 static int
 do_test (void)
 {
-  pthread_t th;
-
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("mutex_lock failed");
-      exit (1);
-    }
-
-  if (pthread_create (&th, NULL, tf, NULL) != 0)
-    {
-      puts ("mutex_create failed");
-      exit (1);
-    }
+  xpthread_mutex_lock (&lock);
+  pthread_t th = xpthread_create (NULL, tf, NULL);
 
   void *status;
-  struct timespec ts;
-  struct timeval tv;
-  (void) gettimeofday (&tv, NULL);
-  TIMEVAL_TO_TIMESPEC (&tv, &ts);
-  ts.tv_nsec += 200000000;
-  if (ts.tv_nsec >= 1000000000)
-    {
-      ts.tv_nsec -= 1000000000;
-      ++ts.tv_sec;
-    }
-  int val = pthread_timedjoin_np (th, &status, &ts);
-  if (val == 0)
-    {
-      puts ("1st timedjoin succeeded");
-      exit (1);
-    }
-  else if (val != ETIMEDOUT)
-    {
-      puts ("1st timedjoin didn't return ETIMEDOUT");
-      exit (1);
-    }
+  struct timespec timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                                          make_timespec (0, 200000000));
 
-  if (pthread_mutex_unlock (&lock) != 0)
-    {
-      puts ("mutex_unlock failed");
-      exit (1);
-    }
+  int val = pthread_timedjoin_np (th, &status, &timeout);
+  TEST_COMPARE (val, ETIMEDOUT);
+
+  xpthread_mutex_unlock (&lock);
 
   while (1)
     {
-      (void) gettimeofday (&tv, NULL);
-      TIMEVAL_TO_TIMESPEC (&tv, &ts);
-      ts.tv_nsec += 200000000;
-      if (ts.tv_nsec >= 1000000000)
-	{
-	  ts.tv_nsec -= 1000000000;
-	  ++ts.tv_sec;
-	}
-
-      val = pthread_timedjoin_np (th, &status, &ts);
+      timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                              make_timespec (0, 200000000));
+
+      val = pthread_timedjoin_np (th, &status, &timeout);
       if (val == 0)
 	break;
 
-      if (val != ETIMEDOUT)
-	{
-	  printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
-		  strerror (val), val);
-	  exit (1);
-	}
+      TEST_COMPARE (val, ETIMEDOUT);
     }
 
   if (status != (void *) 42l)
-    {
-      printf ("return value %p, expected %p\n", status, (void *) 42l);
-      exit (1);
-    }
+    FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
 
   return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/azanella/pthread_clockjoin_np] nptl: Convert tst-join3 to use libsupport
@ 2019-10-31 14:24 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2019-10-31 14:24 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a2b8a325331a1d0e0fe09ba055fe2056f533f808

commit a2b8a325331a1d0e0fe09ba055fe2056f533f808
Author: Mike Crowe <mac@mcrowe.com>
Date:   Thu Oct 31 09:08:10 2019 -0300

    nptl: Convert tst-join3 to use libsupport
    
    Checked on x86_64-linux-gnu.
    
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Diff:
---
 nptl/tst-join3.c | 86 +++++++++++++-------------------------------------------
 1 file changed, 20 insertions(+), 66 deletions(-)

diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
index d8785c5..a4ae459 100644
--- a/nptl/tst-join3.c
+++ b/nptl/tst-join3.c
@@ -22,6 +22,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
+#include <support/check.h>
+#include <support/timespec.h>
+#include <support/xthread.h>
+#include <support/xtime.h>
 
 
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
@@ -30,11 +34,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 static void *
 tf (void *arg)
 {
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("child: mutex_lock failed");
-      return NULL;
-    }
+  xpthread_mutex_lock (&lock);
 
   return (void *) 42l;
 }
@@ -43,80 +43,34 @@ tf (void *arg)
 static int
 do_test (void)
 {
-  pthread_t th;
-
-  if (pthread_mutex_lock (&lock) != 0)
-    {
-      puts ("mutex_lock failed");
-      exit (1);
-    }
-
-  if (pthread_create (&th, NULL, tf, NULL) != 0)
-    {
-      puts ("mutex_create failed");
-      exit (1);
-    }
+  xpthread_mutex_lock (&lock);
+  pthread_t th = xpthread_create (NULL, tf, NULL);
 
   void *status;
-  struct timespec ts;
-  struct timeval tv;
-  (void) gettimeofday (&tv, NULL);
-  TIMEVAL_TO_TIMESPEC (&tv, &ts);
-  ts.tv_nsec += 200000000;
-  if (ts.tv_nsec >= 1000000000)
-    {
-      ts.tv_nsec -= 1000000000;
-      ++ts.tv_sec;
-    }
-  int val = pthread_timedjoin_np (th, &status, &ts);
-  if (val == 0)
-    {
-      puts ("1st timedjoin succeeded");
-      exit (1);
-    }
-  else if (val != ETIMEDOUT)
-    {
-      puts ("1st timedjoin didn't return ETIMEDOUT");
-      exit (1);
-    }
+  struct timespec timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                                          make_timespec (0, 200000000));
 
-  if (pthread_mutex_unlock (&lock) != 0)
-    {
-      puts ("mutex_unlock failed");
-      exit (1);
-    }
+  int val = pthread_timedjoin_np (th, &status, &timeout);
+  TEST_COMPARE (val, ETIMEDOUT);
+
+  xpthread_mutex_unlock (&lock);
 
   while (1)
     {
-      (void) gettimeofday (&tv, NULL);
-      TIMEVAL_TO_TIMESPEC (&tv, &ts);
-      ts.tv_nsec += 200000000;
-      if (ts.tv_nsec >= 1000000000)
-	{
-	  ts.tv_nsec -= 1000000000;
-	  ++ts.tv_sec;
-	}
-
-      val = pthread_timedjoin_np (th, &status, &ts);
+      timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+                              make_timespec (0, 200000000));
+
+      val = pthread_timedjoin_np (th, &status, &timeout);
       if (val == 0)
 	break;
 
-      if (val != ETIMEDOUT)
-	{
-	  printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
-		  strerror (val), val);
-	  exit (1);
-	}
+      TEST_COMPARE (val, ETIMEDOUT);
     }
 
   if (status != (void *) 42l)
-    {
-      printf ("return value %p, expected %p\n", status, (void *) 42l);
-      exit (1);
-    }
+    FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
 
   return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-31 20:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 13:10 [glibc/azanella/pthread_clockjoin_np] nptl: Convert tst-join3 to use libsupport Adhemerval Zanella
2019-10-31 14:24 Adhemerval Zanella
2019-10-31 20:51 Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).