unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH v2 1/4] nptl: Convert tst-join3 to use libsupport
Date: Thu, 26 Sep 2019 13:45:48 -0700	[thread overview]
Message-ID: <ba67d314-bb27-7cb2-5912-2721cb6ab72a@linaro.org> (raw)
In-Reply-To: <4082031311e9899d534db037efdfba7ebde6593b.1568809830.git-series.mac@mcrowe.com>



On 18/09/2019 05:30, Mike Crowe wrote:
> * nptl/tst-join3.c: Use libsupport.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  ChangeLog        |  4 ++-
>  nptl/tst-join3.c | 86 +++++++++++--------------------------------------
>  2 files changed, 24 insertions(+), 66 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index adc93a7..d7943ff 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,7 @@
> +2019-09-18  Mike Crowe  <mac@mcrowe.com>
> +
> +	* nptl/tst-join3.c: Use libsupport.
> +
>  2019-09-18  Stefan Liebler  <stli@linux.ibm.com>
>  
>  	* elf/tst-pldd.c (do_test): Add UNSUPPORTED check.
> 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;
>  }

Ok.

> @@ -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);
>  

Ok.

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

Ok.

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

Ok.

> -      if (val != ETIMEDOUT)
> -	{
> -	  printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
> -		  strerror (val), val);
> -	  exit (1);
> -	}
> +      TEST_COMPARE (val, ETIMEDOUT);

Ok.

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

Ok.

  reply	other threads:[~2019-09-26 20:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18 12:30 [PATCH v2 0/4] nptl: Add pthread_clockjoin_np Mike Crowe
2019-09-18 12:30 ` [PATCH v2 1/4] nptl: Convert tst-join3 to use libsupport Mike Crowe
2019-09-26 20:45   ` Adhemerval Zanella [this message]
2019-09-18 12:30 ` [PATCH v2 2/4] manual: Add documentation for pthread_tryjoin_np and pthread_timedjoin_np Mike Crowe
2019-09-26 21:26   ` Adhemerval Zanella
2019-09-27  9:08     ` Yann Droneaud
2019-09-28  8:53     ` Mike Crowe
2019-10-14 19:15       ` Adhemerval Zanella
2019-10-18 16:28         ` Mike Crowe
2019-10-21 18:15           ` Adhemerval Zanella
2019-09-18 12:30 ` [PATCH v2 3/4] nptl: Add pthread_clockjoin_np Mike Crowe
2019-09-26 23:17   ` Adhemerval Zanella
2019-09-28 19:45     ` Mike Crowe
2019-10-14 19:16       ` Adhemerval Zanella
2019-10-08  8:26   ` Mike Crowe
2019-09-18 12:30 ` [PATCH v2 4/4] nptl: Add pthread_timedjoin_np, pthread_clockjoin_np NULL timeout test Mike Crowe
2019-09-26 23:30   ` Adhemerval Zanella
2019-10-31 14:31 ` [PATCH v2 0/4] nptl: Add pthread_clockjoin_np Adhemerval Zanella
2019-10-31 19:38   ` Mike Crowe
2019-10-31 20:51     ` Adhemerval Zanella
2019-11-01 21:05       ` Joseph Myers
2019-11-01 23:01       ` Rafal Luzynski
2019-11-02  9:14         ` Mike Crowe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ba67d314-bb27-7cb2-5912-2721cb6ab72a@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).