From patchwork Thu May 2 20:54:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 32489 Received: (qmail 125592 invoked by alias); 2 May 2019 20:55:30 -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 125528 invoked by uid 89); 2 May 2019 20:55:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 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=sem, HContent-Transfer-Encoding:8bit X-HELO: avasout02.plus.net X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH 5/5] nptl/tst-abstime: Use libsupport Date: Thu, 2 May 2019 21:54:35 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 * nptl/tst-abstime.c: Use libsupport. Reviewed-by: Adhemerval Zanella --- ChangeLog | 4 +++- nptl/tst-abstime.c | 70 ++++++++++++----------------------------------- 2 files changed, 22 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b73b4a..12736f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-05-02 Mike Crowe + * nptl/tst-abstime.c: Use libsupport. + +2019-05-02 Mike Crowe + * nptl/tst-rwlock6.c: Use libsupport. This also happens to fix a small bug where only tv.tv_usec was checked which could cause an erroneous pass if pthread_rwlock_timedrdlock incorrectly took more diff --git a/nptl/tst-abstime.c b/nptl/tst-abstime.c index 71610f8..56fb8a5 100644 --- a/nptl/tst-abstime.c +++ b/nptl/tst-abstime.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include static pthread_cond_t c = PTHREAD_COND_INITIALIZER; static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER; @@ -31,67 +33,31 @@ static sem_t sem; static void * th (void *arg) { - long int res = 0; - int r; struct timespec t = { -2, 0 }; - r = pthread_mutex_timedlock (&m1, &t); - if (r != ETIMEDOUT) - { - puts ("pthread_mutex_timedlock did not return ETIMEDOUT"); - res = 1; - } - r = pthread_rwlock_timedrdlock (&rw1, &t); - if (r != ETIMEDOUT) - { - puts ("pthread_rwlock_timedrdlock did not return ETIMEDOUT"); - res = 1; - } - r = pthread_rwlock_timedwrlock (&rw2, &t); - if (r != ETIMEDOUT) - { - puts ("pthread_rwlock_timedwrlock did not return ETIMEDOUT"); - res = 1; - } - return (void *) res; + TEST_COMPARE (pthread_mutex_timedlock (&m1, &t), ETIMEDOUT); + TEST_COMPARE (pthread_rwlock_timedrdlock (&rw1, &t), ETIMEDOUT); + TEST_COMPARE (pthread_rwlock_timedwrlock (&rw2, &t), ETIMEDOUT); + return NULL; } static int do_test (void) { - int res = 0; - int r; struct timespec t = { -2, 0 }; - pthread_t pth; sem_init (&sem, 0, 0); - r = sem_timedwait (&sem, &t); - if (r != -1 || errno != ETIMEDOUT) - { - puts ("sem_timedwait did not fail with ETIMEDOUT"); - res = 1; - } - - pthread_mutex_lock (&m1); - pthread_rwlock_wrlock (&rw1); - pthread_rwlock_rdlock (&rw2); - pthread_mutex_lock (&m2); - if (pthread_create (&pth, 0, th, 0) != 0) - { - puts ("cannot create thread"); - return 1; - } - r = pthread_cond_timedwait (&c, &m2, &t); - if (r != ETIMEDOUT) - { - puts ("pthread_cond_timedwait did not return ETIMEDOUT"); - res = 1; - } - void *thres; - pthread_join (pth, &thres); - return res | (thres != NULL); + TEST_COMPARE (sem_timedwait (&sem, &t), -1); + TEST_COMPARE (errno, ETIMEDOUT); + + xpthread_mutex_lock (&m1); + xpthread_rwlock_wrlock (&rw1); + xpthread_rwlock_rdlock (&rw2); + xpthread_mutex_lock (&m2); + pthread_t pth = xpthread_create (0, th, 0); + TEST_COMPARE (pthread_cond_timedwait (&c, &m2, &t), ETIMEDOUT); + xpthread_join (pth); + return 0; } - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include