From patchwork Wed Sep 18 12:30:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 34565 Received: (qmail 68153 invoked by alias); 18 Sep 2019 12:31:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 68064 invoked by uid 89); 18 Sep 2019 12:31:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=200000000 X-HELO: avasout07.plus.net X-Clacks-Overhead: "GNU Terry Pratchett" X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH v2 1/4] nptl: Convert tst-join3 to use libsupport Date: Wed, 18 Sep 2019 13:30:53 +0100 Message-Id: <4082031311e9899d534db037efdfba7ebde6593b.1568809830.git-series.mac@mcrowe.com> In-Reply-To: References: MIME-Version: 1.0 * nptl/tst-join3.c: Use libsupport. Reviewed-by: Adhemerval Zanella --- 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 + + * nptl/tst-join3.c: Use libsupport. + 2019-09-18 Stefan Liebler * 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 #include #include +#include +#include +#include +#include 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