From patchwork Thu Mar 28 18:31:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1068569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-100970-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mcrowe.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="YSTyLSgC"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44VYPB6gsBz9sR7 for ; Fri, 29 Mar 2019 05:31:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; q=dns; s=default; b=epD+zLZE NJ8s7QJpGBg0Md8BGZWYJIOqHIXVYvRjNBo58A2oQmhuu58uYF+1xi4xrBU47rUB 587GeBZYMLkax3kK8DjmgIFFanMPqe5s+CNfd7A4knJSctx13JLrDoSWbGiYxk/c XH+bkb2ySbyNTzvRDPif9wCvZ7k98JmOmmk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; s=default; bh=q9YBMoWPmInqJY oOsCxs2URTD/o=; b=YSTyLSgCklIMSZ/1lWYtGTY6felxy5yf5OQPG+PhfAQNEB fKvG0uSJtaVysfYuOxmi7eRv9g5FwW6dq6bcMqNJ7npahE/ssHbi8GlkdQz2xIwX 1JHVDY3NBTSpd/ZrCnum/EA5S8XQi4fMgOIcQJ8S+uzoq4otx1U76O1KaECFc= Received: (qmail 63359 invoked by alias); 28 Mar 2019 18:31:32 -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 63264 invoked by uid 89); 28 Mar 2019 18:31:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.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=H*r:smtp, H*r:4.89, 1548, crowe X-HELO: avasout02.plus.net X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH 4/6] nptl/tst-rwlock: Use clock_gettime/timespec rather than gettimeofday/timeval Date: Thu, 28 Mar 2019 18:31:10 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: In preparation for adding pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock, convert various tests to only use clock_gettime and struct timespec. * nptl/tst-rwlock6.c: Fix small bug in timeout-checking code that could erroneously pass if the function incorrectly took more than a second. * nptl/tst-rwlock6.c: Use clock_gettime(2) rather than gettimeofday(2) and then converting to timespec in preparation for testing pthread_rwlock_clockrdclock and pthread_rwlock_clockwrlock. * nptl/tst-rwlock7.c, nptl/tst-rwlock9.c: Likewise. --- ChangeLog | 12 ++++++++++++- nptl/tst-rwlock6.c | 47 ++++++++++++++++++----------------------------- nptl/tst-rwlock7.c | 43 +++++++++++++++++-------------------------- nptl/tst-rwlock9.c | 8 ++------ 4 files changed, 49 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index 436736d..5507086 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2019-03-28 Mike Crowe + * nptl/tst-rwlock6.c: Fix small bug in timeout-checking code that + could erroneously pass if the function incorrectly took more than a + second. + + * nptl/tst-rwlock6.c: Use clock_gettime(2) rather than + gettimeofday(2) and then converting to timespec in preparation for + testing pthread_rwlock_clockrdclock and pthread_rwlock_clockwrlock. + + * nptl/tst-rwlock7.c, nptl/tst-rwlock9.c: Likewise. + +2019-03-28 Mike Crowe + * nptl/tst-sem5.c(do_test): Use xclock_gettime and TEST_TIMESPEC_NOW_OR_AFTER from libsupport. diff --git a/nptl/tst-rwlock6.c b/nptl/tst-rwlock6.c index 8d6c3dc..e57f045 100644 --- a/nptl/tst-rwlock6.c +++ b/nptl/tst-rwlock6.c @@ -22,6 +22,7 @@ #include #include #include +#include static int kind[] = @@ -38,21 +39,15 @@ tf (void *arg) pthread_rwlock_t *r = arg; /* Timeout: 0.3 secs. */ - struct timeval tv; - (void) gettimeofday (&tv, NULL); + struct timespec ts_start; + (void) clock_gettime(CLOCK_REALTIME, &ts_start); - struct timespec ts; - TIMEVAL_TO_TIMESPEC (&tv, &ts); - ts.tv_nsec += 300000000; - if (ts.tv_nsec >= 1000000000) - { - ts.tv_nsec -= 1000000000; - ++ts.tv_sec; - } + struct timespec ts_timeout = {0, 300000000}; + timespec_add(&ts_timeout, &ts_start, &ts_timeout); puts ("child calling timedrdlock"); - int err = pthread_rwlock_timedrdlock (r, &ts); + int err = pthread_rwlock_timedrdlock (r, &ts_timeout); if (err == 0) { puts ("rwlock_timedrdlock returned"); @@ -68,24 +63,24 @@ tf (void *arg) puts ("1st child timedrdlock done"); - struct timeval tv2; - (void) gettimeofday (&tv2, NULL); + struct timespec ts_end; + (void) clock_gettime (CLOCK_REALTIME, &ts_end); - timersub (&tv2, &tv, &tv); + struct timespec ts_duration; + timespec_sub (&ts_duration, &ts_end, &ts_start); - if (tv.tv_usec < 200000) + if (ts_duration.tv_sec !=0 || ts_duration.tv_nsec < 200000000) { puts ("timeout too short"); pthread_exit ((void *) 1l); } - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); - ts.tv_sec += 10; + (void) clock_gettime (CLOCK_REALTIME, &ts_timeout); + ts_timeout.tv_sec += 10; /* Note that the following operation makes ts invalid. */ - ts.tv_nsec += 1000000000; + ts_timeout.tv_nsec += 1000000000; - err = pthread_rwlock_timedrdlock (r, &ts); + err = pthread_rwlock_timedrdlock (r, &ts_timeout); if (err == 0) { puts ("2nd timedrdlock succeeded"); @@ -136,12 +131,8 @@ do_test (void) exit (1); } - struct timeval tv; - (void) gettimeofday (&tv, NULL); - struct timespec ts; - TIMEVAL_TO_TIMESPEC (&tv, &ts); - + (void) clock_gettime (CLOCK_REALTIME, &ts); ++ts.tv_sec; /* Get a write lock. */ @@ -154,8 +145,7 @@ do_test (void) puts ("1st timedwrlock done"); - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); + (void) clock_gettime (CLOCK_REALTIME, &ts); ++ts.tv_sec; e = pthread_rwlock_timedrdlock (&r, &ts); if (e == 0) @@ -171,8 +161,7 @@ do_test (void) puts ("1st timedrdlock done"); - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); + (void) clock_gettime (CLOCK_REALTIME, &ts); ++ts.tv_sec; e = pthread_rwlock_timedwrlock (&r, &ts); if (e == 0) diff --git a/nptl/tst-rwlock7.c b/nptl/tst-rwlock7.c index 4d6f561..1c64969 100644 --- a/nptl/tst-rwlock7.c +++ b/nptl/tst-rwlock7.c @@ -22,6 +22,7 @@ #include #include #include +#include static int kind[] = @@ -38,19 +39,12 @@ tf (void *arg) pthread_rwlock_t *r = arg; /* Timeout: 0.3 secs. */ - struct timeval tv; - (void) gettimeofday (&tv, NULL); + struct timespec ts_start; + (void) clock_gettime (CLOCK_REALTIME, &ts_start); + struct timespec ts_timeout = {0, 300000000}; + timespec_add(&ts_timeout, &ts_start, &ts_timeout); - struct timespec ts; - TIMEVAL_TO_TIMESPEC (&tv, &ts); - ts.tv_nsec += 300000000; - if (ts.tv_nsec >= 1000000000) - { - ts.tv_nsec -= 1000000000; - ++ts.tv_sec; - } - - int err = pthread_rwlock_timedwrlock (r, &ts); + int err = pthread_rwlock_timedwrlock (r, &ts_timeout); if (err == 0) { puts ("rwlock_timedwrlock returned"); @@ -65,24 +59,24 @@ tf (void *arg) } puts ("child: timedwrlock failed with ETIMEDOUT"); - struct timeval tv2; - (void) gettimeofday (&tv2, NULL); - - timersub (&tv2, &tv, &tv); + struct timespec ts_end; + (void) clock_gettime (CLOCK_REALTIME, &ts_end); + struct timespec ts_diff; + timespec_sub (&ts_diff, &ts_end, &ts_start); - if (tv.tv_usec < 200000) + if (ts_diff.tv_sec != 0 || ts_diff.tv_nsec < 200000000) { puts ("timeout too short"); pthread_exit ((void *) 1l); } - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); - ts.tv_sec += 10; + struct timespec ts_invalid; + (void) clock_gettime (CLOCK_REALTIME, &ts_invalid); + ts_invalid.tv_sec += 10; /* Note that the following operation makes ts invalid. */ - ts.tv_nsec += 1000000000; + ts_invalid.tv_nsec += 1000000000; - err = pthread_rwlock_timedwrlock (r, &ts); + err = pthread_rwlock_timedwrlock (r, &ts_invalid); if (err == 0) { puts ("2nd timedwrlock succeeded"); @@ -132,11 +126,8 @@ do_test (void) exit (1); } - struct timeval tv; - (void) gettimeofday (&tv, NULL); - struct timespec ts; - TIMEVAL_TO_TIMESPEC (&tv, &ts); + (void) clock_gettime (CLOCK_REALTIME, &ts); ++ts.tv_sec; diff --git a/nptl/tst-rwlock9.c b/nptl/tst-rwlock9.c index 34f2d04..ff15f90 100644 --- a/nptl/tst-rwlock9.c +++ b/nptl/tst-rwlock9.c @@ -56,9 +56,7 @@ writer_thread (void *nr) int e; do { - struct timeval tv; - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); + (void) clock_gettime (CLOCK_REALTIME, &ts); ts.tv_nsec += 2 * TIMEOUT; if (ts.tv_nsec >= 1000000000) @@ -110,9 +108,7 @@ reader_thread (void *nr) int e; do { - struct timeval tv; - (void) gettimeofday (&tv, NULL); - TIMEVAL_TO_TIMESPEC (&tv, &ts); + (void) clock_gettime (CLOCK_REALTIME, &ts); ts.tv_nsec += TIMEOUT; if (ts.tv_nsec >= 1000000000)