From b2f05465748e7e1c0105776a1e0ceda7f7a599b0 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 15 Feb 2003 20:54:25 +0000 Subject: Update. * tst-mutex2.c: Tests of trylock and unlock with ERROR mutexes. --- nptl/tst-mutex3.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) (limited to 'nptl/tst-mutex3.c') diff --git a/nptl/tst-mutex3.c b/nptl/tst-mutex3.c index c45637b5cf..8e57924ba6 100644 --- a/nptl/tst-mutex3.c +++ b/nptl/tst-mutex3.c @@ -24,12 +24,25 @@ static pthread_mutex_t m; +static pthread_barrier_t b; static void * tf (void *arg) { - int e = pthread_mutex_trylock (&m); + int e = pthread_mutex_unlock (&m); + if (e == 0) + { + puts ("1st mutex_unlock in child succeeded"); + exit (1); + } + if (e != EPERM) + { + puts ("1st mutex_unlock in child didn't return EPERM"); + exit (1); + } + + e = pthread_mutex_trylock (&m); if (e == 0) { puts ("mutex_trylock in second thread succeeded"); @@ -41,6 +54,44 @@ tf (void *arg) exit (1); } + e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + e = pthread_mutex_unlock (&m); + if (e == 0) + { + puts ("2nd mutex_unlock in child succeeded"); + exit (1); + } + if (e != EPERM) + { + puts ("2nd mutex_unlock in child didn't return EPERM"); + exit (1); + } + + if (pthread_mutex_trylock (&m) != 0) + { + puts ("2nd mutex_trylock in second thread failed"); + exit (1); + } + + if (pthread_mutex_unlock (&m) != 0) + { + puts ("3rd mutex_unlock in second thread failed"); + exit (1); + } + return NULL; } @@ -68,6 +119,12 @@ do_test (void) return 1; } + if (pthread_barrier_init (&b, NULL, 2) != 0) + { + puts ("barrier_init failed"); + return 1; + } + if (pthread_mutex_lock (&m) != 0) { puts ("mutex_lock failed"); @@ -105,9 +162,10 @@ do_test (void) return 1; } - if (pthread_join (th, NULL) != 0) + int e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) { - puts ("join failed"); + puts ("barrier_wait failed"); return 1; } @@ -117,6 +175,37 @@ do_test (void) return 1; } + e = pthread_mutex_unlock (&m); + if (e == 0) + { + puts ("4th mutex_unlock succeeded"); + return 1; + } + if (e != EPERM) + { + puts ("4th mutex_unlock didn't return EPERM"); + return 1; + } + + e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + return 1; + } + + if (pthread_join (th, NULL) != 0) + { + puts ("join failed"); + return 1; + } + + if (pthread_barrier_destroy (&b) != 0) + { + puts ("barrier_destroy failed"); + return 1; + } + if (pthread_mutex_destroy (&m) != 0) { puts ("mutex_destroy failed"); -- cgit v1.2.3