summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-22 15:06:41 +0000
committerrpj <rpj>2004-10-22 15:06:41 +0000
commit045278e11b53fc1ad59945427feab1cd9275988f (patch)
treeda8570a7a8962d9563814c4910e8a9d5fb6fa685 /tests
parentf84df26e12431bb9ecd07fbc52c804538635901f (diff)
Changes to mutexes and semaphores - considered alpha for now
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog17
-rw-r--r--tests/condvar1_1.c2
-rw-r--r--tests/condvar3.c10
-rw-r--r--tests/condvar3_1.c30
-rw-r--r--tests/condvar3_2.c8
-rw-r--r--tests/condvar4.c4
-rw-r--r--tests/condvar5.c4
-rw-r--r--tests/condvar6.c4
-rw-r--r--tests/condvar7.c4
-rw-r--r--tests/condvar8.c4
-rw-r--r--tests/condvar9.c4
-rw-r--r--tests/kill1.c2
12 files changed, 64 insertions, 29 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 65d52f1..27f4eea 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,20 @@
+2004-10-23 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * condvar3.c: Fixed mutex operations that were incorrectly
+ placed in relation to their condition variable operations.
+ The error became evident after sem_destroy() was rewritten
+ and conditions for destroing the semaphore were tightened.
+ As a result, pthread_cond_destroy() was not able to
+ destroy the cv queueing sempahore.
+ * condvar3_1.c: Likewise.
+ * condvar3_2.c: Likewise.
+ * condvar4.c: Likewise.
+ * condvar5.c: Likewise.
+ * condvar6.c: Likewise.
+ * condvar7.c: Likewise.
+ * condvar8.c: Likewise.
+ * condvar9.c: Likewise.
+
2004-10-19 Ross Johnson <rpj@callisto.canberra.edu.au>
* semaphore3.c: New test.
diff --git a/tests/condvar1_1.c b/tests/condvar1_1.c
index 0090fc0..17f4a31 100644
--- a/tests/condvar1_1.c
+++ b/tests/condvar1_1.c
@@ -38,7 +38,7 @@
*
* Test Method (Validation or Falsification):
* - Validation:
- * Initiate and destry several CVs in random order.
+ * Initiate and destroy several CVs in random order.
*
* Requirements Tested:
* -
diff --git a/tests/condvar3.c b/tests/condvar3.c
index aeeb915..8fa9ef7 100644
--- a/tests/condvar3.c
+++ b/tests/condvar3.c
@@ -97,25 +97,29 @@ mythread(void * arg)
shared++;
- assert(pthread_mutex_unlock(&mutex) == 0);
-
if ((result = pthread_cond_signal(&cv)) != 0)
{
printf("Error = %s\n", error_string[result]);
}
assert(result == 0);
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
return (void *) 0;
}
int
main()
{
+ pthread_attr_t attr;
pthread_t t[NUMTHREADS];
struct timespec abstime = { 0, 0 };
struct _timeb currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
+ assert(pthread_attr_init(&attr) == 0);
+ assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0);
+
assert((t[0] = pthread_self()) != NULL);
assert(pthread_cond_init(&cv, NULL) == 0);
@@ -130,7 +134,7 @@ main()
abstime.tv_sec = currSysTime.time;
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
- assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
+ assert(pthread_create(&t[1], &attr, mythread, (void *) 1) == 0);
abstime.tv_sec += 5;
diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c
index 200aaf9..c2c3d98 100644
--- a/tests/condvar3_1.c
+++ b/tests/condvar3_1.c
@@ -83,6 +83,7 @@
static pthread_cond_t cv;
static pthread_cond_t cv1;
static pthread_mutex_t mutex;
+static pthread_mutex_t mutex1;
static struct timespec abstime = { 0, 0 };
static int timedout = 0;
static int signaled = 0;
@@ -98,11 +99,12 @@ mythread(void * arg)
{
int result;
- assert(pthread_mutex_lock(&mutex) == 0);
-
- if ( ++waiting == NUMTHREADS)
- assert(pthread_cond_signal(&cv1) == 0);
+ assert(pthread_mutex_lock(&mutex1) == 0);
+ ++waiting;
+ assert(pthread_cond_signal(&cv1) == 0);
+ assert(pthread_mutex_unlock(&mutex1) == 0);
+ assert(pthread_mutex_lock(&mutex) == 0);
result = pthread_cond_timedwait(&cv, &mutex, &abstime);
if (result == ETIMEDOUT)
{
@@ -112,7 +114,6 @@ mythread(void * arg)
{
awoken++;
}
-
assert(pthread_mutex_unlock(&mutex) == 0);
return arg;
@@ -133,6 +134,7 @@ main()
assert(pthread_cond_init(&cv1, NULL) == 0);
assert(pthread_mutex_init(&mutex, NULL) == 0);
+ assert(pthread_mutex_init(&mutex1, NULL) == 0);
/* get current system time */
_ftime(&currSysTime);
@@ -142,7 +144,7 @@ main()
abstime.tv_sec += 5;
- assert(pthread_mutex_lock(&mutex) == 0);
+ assert(pthread_mutex_lock(&mutex1) == 0);
for (i = 1; i <= NUMTHREADS; i++)
{
@@ -150,19 +152,20 @@ main()
}
do {
- assert(pthread_cond_wait(&cv1,&mutex) == 0);
- } while ( NUMTHREADS != waiting );
+ assert(pthread_cond_wait(&cv1,&mutex1) == 0);
+ } while ( NUMTHREADS > waiting );
- assert(pthread_mutex_unlock(&mutex) == 0);
+ assert(pthread_mutex_unlock(&mutex1) == 0);
for (i = NUMTHREADS/3; i <= 2*NUMTHREADS/3; i++)
{
+ assert(pthread_mutex_lock(&mutex) == 0);
assert(pthread_cond_signal(&cv) == 0);
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
signaled++;
}
- assert(pthread_cond_destroy(&cv1) == 0);
-
for (i = 1; i <= NUMTHREADS; i++)
{
assert(pthread_join(t[i], (void **) &result) == 0);
@@ -176,6 +179,8 @@ main()
assert(signaled == awoken);
assert(timedout == NUMTHREADS - signaled);
+ assert(pthread_cond_destroy(&cv1) == 0);
+
{
int result = pthread_cond_destroy(&cv);
if (result != 0)
@@ -189,5 +194,8 @@ main()
assert(result == 0);
}
+ assert(pthread_mutex_destroy(&mutex1) == 0);
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
return 0;
}
diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c
index 865ca9d..525ddf6 100644
--- a/tests/condvar3_2.c
+++ b/tests/condvar3_2.c
@@ -160,10 +160,16 @@ main()
* and while some are still waking up after timeout.
* Also tests that redundant broadcasts don't return errors.
*/
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
if (awoken > NUMTHREADS/3)
{
assert(pthread_cond_broadcast(&cv) == 0);
}
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
}
assert(awoken == NUMTHREADS - timedout);
@@ -181,5 +187,7 @@ main()
assert(result == 0);
}
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
return 0;
}
diff --git a/tests/condvar4.c b/tests/condvar4.c
index a4f3299..15a32ba 100644
--- a/tests/condvar4.c
+++ b/tests/condvar4.c
@@ -102,10 +102,10 @@ mythread(void * arg)
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
assert(pthread_cond_signal(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
return (void *) 0;
}
diff --git a/tests/condvar5.c b/tests/condvar5.c
index 53311b4..ff5ad70 100644
--- a/tests/condvar5.c
+++ b/tests/condvar5.c
@@ -101,10 +101,10 @@ mythread(void * arg)
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
return (void *) 0;
}
diff --git a/tests/condvar6.c b/tests/condvar6.c
index 9587781..d642f9c 100644
--- a/tests/condvar6.c
+++ b/tests/condvar6.c
@@ -190,10 +190,10 @@ main()
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
/*
* Give threads time to complete.
*/
diff --git a/tests/condvar7.c b/tests/condvar7.c
index e79e0f8..a5bf4bf 100644
--- a/tests/condvar7.c
+++ b/tests/condvar7.c
@@ -200,8 +200,6 @@ main()
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
/*
* Cancel one of the threads.
*/
@@ -213,6 +211,8 @@ main()
*/
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
/*
* Give threads time to complete.
*/
diff --git a/tests/condvar8.c b/tests/condvar8.c
index 4d28f6a..2ab67b3 100644
--- a/tests/condvar8.c
+++ b/tests/condvar8.c
@@ -205,10 +205,10 @@ main()
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
/*
* Give threads time to complete.
*/
diff --git a/tests/condvar9.c b/tests/condvar9.c
index cf31240..b24d71e 100644
--- a/tests/condvar9.c
+++ b/tests/condvar9.c
@@ -211,13 +211,13 @@ main()
cvthing.shared++;
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
assert(pthread_cancel(t[(first + last) / 2]) == 0);
canceledThreads++;
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
/*
* Give threads time to complete.
*/
diff --git a/tests/kill1.c b/tests/kill1.c
index b9477fc..1ffd07a 100644
--- a/tests/kill1.c
+++ b/tests/kill1.c
@@ -77,8 +77,6 @@
int
main()
{
- void * result = NULL;
-
assert(pthread_kill(pthread_self(), 1) == EINVAL);
return 0;