diff options
| author | rpj <rpj> | 2002-01-13 02:29:40 +0000 | 
|---|---|---|
| committer | rpj <rpj> | 2002-01-13 02:29:40 +0000 | 
| commit | 30a1e9738593302fa26e0a668f517bc7f5800190 (patch) | |
| tree | b7379d358ab465e2c2c57864699c91b9055fc9fd /tests | |
| parent | 0fee04f5eb2d9c1c484281afbc2b24278567a179 (diff) | |
	* attr.c (pthread_attr_setscope): Fix struct pointer
	indirection error introduced 2002-01-04.
	(pthread_attr_getscope): Likewise.
        * pthread.dsp (SOURCE): Add missing source files.
./tests/:
        * exception3.c (main): Shorten wait time.
        * mutex7.c: New test.
        * mutex7n.c: New test.
        * mutex7e.c: New test.
        * mutex7r.c: New test.
        * mutex6.c: Modified to avoid leaving the locked mutex
        around on exit.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 13 | ||||
| -rw-r--r-- | tests/GNUmakefile | 9 | ||||
| -rw-r--r-- | tests/Makefile | 9 | ||||
| -rw-r--r-- | tests/exception3.c | 4 | ||||
| -rw-r--r-- | tests/mutex6.c | 18 | ||||
| -rw-r--r-- | tests/mutex6n.c | 15 | ||||
| -rw-r--r-- | tests/mutex7.c | 73 | ||||
| -rw-r--r-- | tests/mutex7e.c | 93 | ||||
| -rw-r--r-- | tests/mutex7n.c | 84 | ||||
| -rw-r--r-- | tests/mutex7r.c | 91 | 
10 files changed, 401 insertions, 8 deletions
| diff --git a/tests/ChangeLog b/tests/ChangeLog index 77d81db..ce460e7 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,16 @@ +2002-01-14  Ross Johnson  <rpj@special.ise.canberra.edu.au>
 +
 +	* exception3.c (main): Shorten wait time.
 +
 +2002-01-09  Ross Johnson  <rpj@special.ise.canberra.edu.au>
 +
 +	* mutex7.c: New test.
 +	* mutex7n.c: New test.
 +	* mutex7e.c: New test.
 +	* mutex7r.c: New test.
 +	* mutex6.c: Modified to avoid leaving the locked mutex
 +	around on exit.
 +
  2001-10-25  Ross Johnson  <rpj@setup1.ise.canberra.edu.au>
  	* condvar2.c: Remove reference to cv->nWaitersUnblocked.
 diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 8e06c68..26b707c 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -40,6 +40,7 @@ TESTS	= loadfree \  	  condvar1 condvar2 condvar2_1 exit1 create1 equal1 \  	  exit2 exit3 \  	  join0 join1 join2 mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \ +	  mutex7 mutex7n mutex7e mutex7r \  	  count1 once1 tsd1 self2 cancel1 cancel2 eyal1 \  	  condvar3 condvar3_1 condvar3_2 condvar3_3 \  	  condvar4 condvar5 condvar6 condvar7 condvar8 condvar9 \ @@ -146,6 +147,14 @@ mutex2.pass: mutex1.pass  mutex3.pass: create1.pass  mutex4.pass: mutex3.pass  mutex5.pass: +mutex6.pass: mutex4.pass +mutex6n.pass: mutex4.pass +mutex6e.pass: mutex4.pass +mutex6r.pass: mutex4.pass +mutex7.pass: mutex6.pass +mutex7n.pass: mutex6n.pass +mutex7e.pass: mutex6e.pass +mutex7r.pass: mutex6r.pass  once1.pass: create1.pass  priority1.pass: join1.pass  priority2.pass: priority1.pass diff --git a/tests/Makefile b/tests/Makefile index 1a7b6bf..9eade03 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -44,6 +44,7 @@ PASSES= loadfree.pass \  	  exit2.pass  exit3.pass  \
  	  join0.pass  join1.pass  join2.pass  \
  	  mutex4.pass  mutex6.pass  mutex6n.pass  mutex6e.pass  mutex6r.pass  \
 +	  mutex7.pass  mutex7n.pass  mutex7e.pass  mutex7r.pass  \
  	  count1.pass  once1.pass  tsd1.pass  \
  	  self2.pass  \
  	  cancel1.pass  cancel2.pass  \
 @@ -200,6 +201,14 @@ mutex2.pass: mutex1.pass  mutex3.pass: create1.pass
  mutex4.pass: mutex3.pass
  mutex5.pass:
 +mutex6.pass: mutex4.pass
 +mutex6n.pass: mutex4.pass
 +mutex6e.pass: mutex4.pass
 +mutex6r.pass: mutex4.pass
 +mutex7.pass: mutex6.pass
 +mutex7n.pass: mutex6n.pass
 +mutex7e.pass: mutex6e.pass
 +mutex7r.pass: mutex6r.pass
  once1.pass: create1.pass
  priority1.pass: join1.pass
  priority2.pass: priority1.pass
 diff --git a/tests/exception3.c b/tests/exception3.c index bb27ff7..08f88a7 100644 --- a/tests/exception3.c +++ b/tests/exception3.c @@ -87,7 +87,7 @@ terminateFunction ()  {    pthread_mutex_lock(&caughtLock);    caught++; -#if 0 +#if 1    {       FILE * fp = fopen("pthread.log", "a");       fprintf(fp, "Caught = %d\n", caught); @@ -123,7 +123,7 @@ main()        assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0);      } -  Sleep(10000); +  Sleep(5000);    assert(caught == NUMTHREADS); diff --git a/tests/mutex6.c b/tests/mutex6.c index 5cd6d46..dc14c46 100644 --- a/tests/mutex6.c +++ b/tests/mutex6.c @@ -45,10 +45,10 @@ void * locker(void * arg)  {    assert(pthread_mutex_lock(&mutex) == 0);    lockCount++; -  assert(pthread_mutex_lock(&mutex) != 0); + +  /* Should wait here (deadlocked) */ +  assert(pthread_mutex_lock(&mutex) == 0);    lockCount++; -  Sleep(1000); -  assert(pthread_mutex_unlock(&mutex) == 0);    assert(pthread_mutex_unlock(&mutex) == 0);    return 0; @@ -63,10 +63,20 @@ main()    assert(pthread_create(&t, NULL, locker, NULL) == 0); -  Sleep(2000); +  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 */ diff --git a/tests/mutex6n.c b/tests/mutex6n.c index d982c4c..e006f24 100644 --- a/tests/mutex6n.c +++ b/tests/mutex6n.c @@ -49,10 +49,11 @@ void * locker(void * arg)  {    assert(pthread_mutex_lock(&mutex) == 0);    lockCount++; -  assert(pthread_mutex_lock(&mutex) != 0); + +  /* Should wait here (deadlocked) */ +  assert(pthread_mutex_lock(&mutex) == 0);    lockCount++;    assert(pthread_mutex_unlock(&mutex) == 0); -  assert(pthread_mutex_unlock(&mutex) == 0);    return (void *) 555;  } @@ -76,6 +77,16 @@ main()    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 */ diff --git a/tests/mutex7.c b/tests/mutex7.c new file mode 100644 index 0000000..9b0c9d0 --- /dev/null +++ b/tests/mutex7.c @@ -0,0 +1,73 @@ +/*  + * mutex7.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + * -------------------------------------------------------------------------- + * + * Test the default (type not set) mutex type. + * Should be the same as PTHREAD_MUTEX_NORMAL. + * Thread locks then trylocks mutex (attempted recursive lock). + * The thread should lock first time and EBUSY second time. + * + * Depends on API functions:  + *	pthread_mutex_lock() + *	pthread_mutex_trylock() + *	pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; + +void * locker(void * arg) +{ +  assert(pthread_mutex_lock(&mutex) == 0); +  lockCount++; +  assert(pthread_mutex_trylock(&mutex) == EBUSY); +  lockCount++; +  assert(pthread_mutex_unlock(&mutex) == 0); +  assert(pthread_mutex_unlock(&mutex) == EPERM); + +  return 0; +} +  +int +main() +{ +  pthread_t t; + +  assert(pthread_mutex_init(&mutex, NULL) == 0); + +  assert(pthread_create(&t, NULL, locker, NULL) == 0); + +  Sleep(1000); + +  assert(lockCount == 2); + +  exit(0); + +  /* Never reached */ +  return 0; +} diff --git a/tests/mutex7e.c b/tests/mutex7e.c new file mode 100644 index 0000000..95b339c --- /dev/null +++ b/tests/mutex7e.c @@ -0,0 +1,93 @@ +/*  + * mutex7e.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_ERRORCHECK mutex type. + * Thread locks and then trylocks mutex (attempted recursive lock). + * Trylock should fail with an EDEADLK error. + * The second unlock attempt should fail with an EPERM error. + * + * Depends on API functions:  + *      pthread_create() + *      pthread_join() + *      pthread_mutexattr_init() + *      pthread_mutexattr_destroy() + *      pthread_mutexattr_settype() + *      pthread_mutexattr_gettype() + *      pthread_mutex_init() + *      pthread_mutex_destroy() + *	pthread_mutex_lock() + *	pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ +  assert(pthread_mutex_lock(&mutex) == 0); +  lockCount++; +  assert(pthread_mutex_trylock(&mutex) == EDEADLK); +  lockCount++; +  assert(pthread_mutex_unlock(&mutex) == 0); +  assert(pthread_mutex_unlock(&mutex) == EPERM); + +  return (void *) 555; +} +  +int +main() +{ +  pthread_t t; +  int result = 0; +  int mxType = -1; + +  assert(pthread_mutexattr_init(&mxAttr) == 0); +  assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0); +  assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); +  assert(mxType == PTHREAD_MUTEX_ERRORCHECK); + +  assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + +  assert(pthread_create(&t, NULL, locker, NULL) == 0); + +  assert(pthread_join(t, (void **) &result) == 0); +  assert(result == 555); + +  assert(lockCount == 2); + +  assert(pthread_mutex_destroy(&mutex) == 0); +  assert(pthread_mutexattr_destroy(&mxAttr) == 0); + +  exit(0); + +  /* Never reached */ +  return 0; +} + diff --git a/tests/mutex7n.c b/tests/mutex7n.c new file mode 100644 index 0000000..d3f2206 --- /dev/null +++ b/tests/mutex7n.c @@ -0,0 +1,84 @@ +/*  + * mutex7n.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_NORMAL mutex type. + * Thread locks then trylocks mutex (attempted recursive lock). + * The thread should lock first time and EBUSY second time. + * + * Depends on API functions:  + *      pthread_create() + *      pthread_mutexattr_init() + *      pthread_mutexattr_settype() + *      pthread_mutexattr_gettype() + *      pthread_mutex_init() + *	pthread_mutex_lock() + *	pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ +  assert(pthread_mutex_lock(&mutex) == 0); +  lockCount++; +  assert(pthread_mutex_trylock(&mutex) == EBUSY); +  lockCount++; +  assert(pthread_mutex_unlock(&mutex) == 0); +  assert(pthread_mutex_unlock(&mutex) == EPERM); + +  return (void *) 555; +} +  +int +main() +{ +  pthread_t t; +  int mxType = -1; + +  assert(pthread_mutexattr_init(&mxAttr) == 0); +  assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0); +  assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); +  assert(mxType == PTHREAD_MUTEX_NORMAL); + +  assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + +  assert(pthread_create(&t, NULL, locker, NULL) == 0); + +  Sleep(1000); + +  assert(lockCount == 2); + +  exit(0); + +  /* Never reached */ +  return 0; +} + diff --git a/tests/mutex7r.c b/tests/mutex7r.c new file mode 100644 index 0000000..febac75 --- /dev/null +++ b/tests/mutex7r.c @@ -0,0 +1,91 @@ +/*  + * mutex7r.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_RECURSIVE mutex type. + * Thread locks mutex then trylocks mutex (recursive lock twice). + * Both locks and unlocks should succeed. + * + * Depends on API functions:  + *      pthread_create() + *      pthread_join() + *      pthread_mutexattr_init() + *      pthread_mutexattr_destroy() + *      pthread_mutexattr_settype() + *      pthread_mutexattr_gettype() + *      pthread_mutex_init() + *      pthread_mutex_destroy() + *	pthread_mutex_lock() + *	pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ +  assert(pthread_mutex_lock(&mutex) == 0); +  lockCount++; +  assert(pthread_mutex_trylock(&mutex) == 0); +  lockCount++; +  assert(pthread_mutex_unlock(&mutex) == 0); +  assert(pthread_mutex_unlock(&mutex) == 0); + +  return (void *) 555; +} +  +int +main() +{ +  pthread_t t; +  int result = 0; +  int mxType = -1; + +  assert(pthread_mutexattr_init(&mxAttr) == 0); +  assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0); +  assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); +  assert(mxType == PTHREAD_MUTEX_RECURSIVE); + +  assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + +  assert(pthread_create(&t, NULL, locker, NULL) == 0); + +  assert(pthread_join(t, (void **) &result) == 0); +  assert(result == 555); + +  assert(lockCount == 2); + +  assert(pthread_mutex_destroy(&mutex) == 0); +  assert(pthread_mutexattr_destroy(&mxAttr) == 0); + +  exit(0); + +  /* Never reached */ +  return 0; +} | 
