diff options
Diffstat (limited to 'winsup/testsuite')
-rw-r--r-- | winsup/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/testsuite/winsup.api/pthread/mutex8e.c | 35 | ||||
-rw-r--r-- | winsup/testsuite/winsup.api/pthread/mutex8n.c | 60 | ||||
-rw-r--r-- | winsup/testsuite/winsup.api/pthread/mutex8r.c | 37 |
4 files changed, 138 insertions, 0 deletions
diff --git a/winsup/testsuite/ChangeLog b/winsup/testsuite/ChangeLog index ec19bca95..033be1005 100644 --- a/winsup/testsuite/ChangeLog +++ b/winsup/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-03-04 Thomas Pfaff <tpfaff@gmx.net> + + * winsup.api/pthread/mutex8e.c: New testcase. + * winsup.api/pthread/mutex8n.c: Ditto. + * winsup.api/pthread/mutex8r.c: Ditto. + 2003-12-23 Christopher Faylor <cgf@redhat.com> * winsup.api/pthread/rwlock7.c (main): Don't assume that result of rand diff --git a/winsup/testsuite/winsup.api/pthread/mutex8e.c b/winsup/testsuite/winsup.api/pthread/mutex8e.c new file mode 100644 index 000000000..7108b02af --- /dev/null +++ b/winsup/testsuite/winsup.api/pthread/mutex8e.c @@ -0,0 +1,35 @@ +/* + * mutex8e.c + * + * Tests PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP. + * + * Depends on API functions: + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; + +int +main() +{ + assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP); + + assert(pthread_mutex_lock(&mutex) == 0); + + assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP); + + assert(mutex != NULL); + + assert(pthread_mutex_lock(&mutex) == EDEADLK); + + assert(pthread_mutex_unlock(&mutex) == 0); + + assert(pthread_mutex_destroy(&mutex) == 0); + + assert(mutex == NULL); + + return 0; +} diff --git a/winsup/testsuite/winsup.api/pthread/mutex8n.c b/winsup/testsuite/winsup.api/pthread/mutex8n.c new file mode 100644 index 000000000..46fc9c676 --- /dev/null +++ b/winsup/testsuite/winsup.api/pthread/mutex8n.c @@ -0,0 +1,60 @@ +/* + * mutex8n.c + * + * Tests PTHREAD_NORMAL_MUTEX_INITIALIZER_NP. + * Thread locks mutex twice (recursive lock). + * The thread should deadlock. + * + * Depends on API functions: + * pthread_create() + * pthread_mutex_init() + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +pthread_mutex_t mutex = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; + +void * locker(void * arg) +{ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + + /* Should wait here (deadlocked) */ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_unlock(&mutex) == 0); + + return (void *) 555; +} + +int +main() +{ + pthread_t t; + + assert(pthread_create(&t, NULL, locker, NULL) == 0); + + Sleep(1000); + + assert(lockCount == 1); + + /* + * Should succeed even though we don't own the lock + * because FAST mutexes don't check ownership. + */ + assert(pthread_mutex_unlock(&mutex) == 0); + + Sleep (1000); + + assert(lockCount == 2); + + exit(0); + + /* Never reached */ + return 0; +} + diff --git a/winsup/testsuite/winsup.api/pthread/mutex8r.c b/winsup/testsuite/winsup.api/pthread/mutex8r.c new file mode 100644 index 000000000..ecaccd3ec --- /dev/null +++ b/winsup/testsuite/winsup.api/pthread/mutex8r.c @@ -0,0 +1,37 @@ +/* + * mutex8r.c + * + * Tests PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP. + * + * Depends on API functions: + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +int +main() +{ + assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); + + assert(pthread_mutex_lock(&mutex) == 0); + + assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); + + assert(mutex != NULL); + + assert(pthread_mutex_lock(&mutex) == 0); + + assert(pthread_mutex_unlock(&mutex) == 0); + + assert(pthread_mutex_unlock(&mutex) == 0); + + assert(pthread_mutex_destroy(&mutex) == 0); + + assert(mutex == NULL); + + return 0; +} |