From 495514eec7d2b9ebb9beaa313211aca212de86da Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Thu, 9 May 2019 14:14:32 -0300 Subject: nptl: Convert some rwlock tests to use libsupport Checked on x86_64-linux-gnu and i686-linux-gnu. * 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 than a second. * nptl/tst-rwlock7.c, nptl/tst-rwlock9.c, nptl/tst-rwlock14.c: Use libsupport. Reviewed-by: Adhemerval Zanella --- nptl/tst-rwlock7.c | 119 +++++++++++++---------------------------------------- 1 file changed, 28 insertions(+), 91 deletions(-) (limited to 'nptl/tst-rwlock7.c') diff --git a/nptl/tst-rwlock7.c b/nptl/tst-rwlock7.c index 4d6f561737..df50f0a37d 100644 --- a/nptl/tst-rwlock7.c +++ b/nptl/tst-rwlock7.c @@ -22,6 +22,10 @@ #include #include #include +#include +#include +#include +#include static int kind[] = @@ -38,61 +42,24 @@ tf (void *arg) pthread_rwlock_t *r = arg; /* Timeout: 0.3 secs. */ - struct timeval tv; - (void) gettimeofday (&tv, NULL); + struct timespec ts_start; + xclock_gettime (CLOCK_REALTIME, &ts_start); + const struct timespec ts_timeout = timespec_add (ts_start, + make_timespec (0, 300000000)); - 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); - if (err == 0) - { - puts ("rwlock_timedwrlock returned"); - pthread_exit ((void *) 1l); - } - - if (err != ETIMEDOUT) - { - printf ("err = %s (%d), expected %s (%d)\n", - strerror (err), err, strerror (ETIMEDOUT), ETIMEDOUT); - pthread_exit ((void *) 1l); - } + TEST_COMPARE (pthread_rwlock_timedwrlock (r, &ts_timeout), ETIMEDOUT); puts ("child: timedwrlock failed with ETIMEDOUT"); - struct timeval tv2; - (void) gettimeofday (&tv2, NULL); - - timersub (&tv2, &tv, &tv); + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts_timeout); - if (tv.tv_usec < 200000) - { - 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; + xclock_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; + + TEST_COMPARE (pthread_rwlock_timedwrlock (r, &ts_invalid), EINVAL); - err = pthread_rwlock_timedwrlock (r, &ts); - if (err == 0) - { - puts ("2nd timedwrlock succeeded"); - pthread_exit ((void *) 1l); - } - if (err != EINVAL) - { - puts ("2nd timedwrlock did not return EINVAL"); - pthread_exit ((void *) 1l); - } puts ("child: timedwrlock failed with EINVAL"); return NULL; @@ -109,73 +76,43 @@ do_test (void) pthread_rwlockattr_t a; if (pthread_rwlockattr_init (&a) != 0) - { - printf ("round %Zu: rwlockattr_t failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: rwlockattr_t failed\n", cnt); if (pthread_rwlockattr_setkind_np (&a, kind[cnt]) != 0) - { - printf ("round %Zu: rwlockattr_setkind failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: rwlockattr_setkind failed\n", cnt); if (pthread_rwlock_init (&r, &a) != 0) - { - printf ("round %Zu: rwlock_init failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: rwlock_init failed\n", cnt); if (pthread_rwlockattr_destroy (&a) != 0) - { - printf ("round %Zu: rwlockattr_destroy failed\n", cnt); - exit (1); - } - - struct timeval tv; - (void) gettimeofday (&tv, NULL); + FAIL_EXIT1 ("round %Zu: rwlockattr_destroy failed\n", cnt); struct timespec ts; - TIMEVAL_TO_TIMESPEC (&tv, &ts); + xclock_gettime (CLOCK_REALTIME, &ts); ++ts.tv_sec; /* Get a read lock. */ if (pthread_rwlock_timedrdlock (&r, &ts) != 0) - { - printf ("round %Zu: rwlock_timedrdlock failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: rwlock_timedrdlock failed\n", cnt); + printf ("%zu: got timedrdlock\n", cnt); pthread_t th; if (pthread_create (&th, NULL, tf, &r) != 0) - { - printf ("round %Zu: create failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: create failed\n", cnt); void *status; if (pthread_join (th, &status) != 0) - { - printf ("round %Zu: join failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: join failed\n", cnt); if (status != NULL) - { - printf ("failure in round %Zu\n", cnt); - exit (1); - } + FAIL_EXIT1 ("failure in round %Zu\n", cnt); if (pthread_rwlock_destroy (&r) != 0) - { - printf ("round %Zu: rwlock_destroy failed\n", cnt); - exit (1); - } + FAIL_EXIT1 ("round %Zu: rwlock_destroy failed\n", cnt); } return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include -- cgit 1.4.1