diff options
author | Mike Crowe <mac@mcrowe.com> | 2019-05-09 14:14:32 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2019-05-09 14:33:53 -0300 |
commit | 495514eec7d2b9ebb9beaa313211aca212de86da (patch) | |
tree | e267b6acd0938bd1631bd22beeaab75398260e90 /nptl/tst-rwlock7.c | |
parent | 40d0816faaacfb0b67ac660807b2b6a0927a7522 (diff) | |
download | glibc-495514eec7d2b9ebb9beaa313211aca212de86da.tar.gz glibc-495514eec7d2b9ebb9beaa313211aca212de86da.tar.xz glibc-495514eec7d2b9ebb9beaa313211aca212de86da.zip |
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 <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl/tst-rwlock7.c')
-rw-r--r-- | nptl/tst-rwlock7.c | 119 |
1 files changed, 28 insertions, 91 deletions
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 <stdio.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 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 <support/test-driver.c> |