summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>1999-03-06 16:53:35 +0000
committerrpj <rpj>1999-03-06 16:53:35 +0000
commit04424402ab85dd4e542afb8f1a51c8cfb6d33dc2 (patch)
tree40ec159a4c66c50d470bb59ede2642227a01a4e9 /tests
parent5e3dd7f951d0c8b284d9d64a4de9561142a777e9 (diff)
Sun Mar 7 10:41:52 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* condvar4.c (General): Reduce to simple test case; prerequisite is condvar3.c; add description. * condvar3.c (General): Reduce to simple test case; prerequisite is condvar2.c; add description. * condvar2.c (General): Reduce to simple test case; prerequisite is condvar1.c; add description. * condvar1.c (General): Reduce to simple test case; add description. * Template.c (Comments): Add generic test detail.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog16
-rw-r--r--tests/Template.c9
-rw-r--r--tests/condvar1.c92
-rw-r--r--tests/condvar2.c92
-rw-r--r--tests/condvar3.c103
-rw-r--r--tests/condvar4.c106
6 files changed, 270 insertions, 148 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 1519780..ae8015a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,19 @@
+Sun Mar 7 10:41:52 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
+
+ * condvar4.c (General): Reduce to simple test case; prerequisite
+ is condvar3.c; add description.
+
+ * condvar3.c (General): Reduce to simple test case; prerequisite
+ is condvar2.c; add description.
+
+ * condvar2.c (General): Reduce to simple test case; prerequisite
+ is condvar1.c; add description.
+
+ * condvar1.c (General): Reduce to simple test case; add
+ description.
+
+ * Template.c (Comments): Add generic test detail.
+
1999-02-23 Ross Johnson <rpj@ise.canberra.edu.au>
* Template.c: Revamp.
diff --git a/tests/Template.c b/tests/Template.c
index 470003d..0663a85 100644
--- a/tests/Template.c
+++ b/tests/Template.c
@@ -23,19 +23,20 @@
* -
*
* Input:
- * -
+ * - None.
*
* Output:
- * -
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
*
* Assumptions:
* -
*
* Pass Criteria:
- * -
+ * - Process returns zero exit status.
*
* Fail Criteria:
- * -
+ * - Process returns non-zero exit status.
*/
#include "test.h"
diff --git a/tests/condvar1.c b/tests/condvar1.c
index 4c52651..97c870b 100644
--- a/tests/condvar1.c
+++ b/tests/condvar1.c
@@ -2,7 +2,7 @@
* File: condvar1.c
*
* Test Synopsis:
- * - Test basic function of condition variable code.
+ * - Test initialisation and destruction of a CV.
*
* Test Method (Validation or Falsification):
* - Validation
@@ -17,105 +17,43 @@
* -
*
* Description:
- * -
+ * - Creates and then imediately destroys a CV. Does not
+ * test the CV.
*
* Environment:
* -
*
* Input:
- * -
+ * - None.
*
* Output:
- * -
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
*
* Assumptions:
* -
*
* Pass Criteria:
- * -
+ * - pthread_cond_init returns 0, and
+ * - pthread_cond_destroy returns 0.
+ * - Process returns zero exit status.
*
* Fail Criteria:
- * -
+ * - pthread_cond_init returns non-zero, or
+ * - pthread_cond_destroy returns non-zero.
+ * - Process returns non-zero exit status.
*/
#include "test.h"
-typedef struct cvthing_t_ cvthing_t;
-
-struct cvthing_t_ {
- pthread_cond_t notbusy;
- pthread_mutex_t lock;
- int busy;
- int count;
-};
-
-static cvthing_t cvthing;
-
-static enum {
- NUMTHREADS = 10
-};
-
-static pthread_key_t key;
-
-void *
-mythread(void * arg)
-{
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
-
- cvthing.count++;
-
- while (cvthing.busy)
- {
- assert(pthread_cond_wait(&cvthing.notbusy, &cvthing.lock) == 0);
- }
-
- assert(cvthing.busy == 0);
-
- cvthing.count--;
-
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- return 0;
-}
+pthread_cond_t cv;
int
main()
{
- pthread_t t[NUMTHREADS];
- int result[NUMTHREADS];
-
- assert((t[0] = pthread_self()) != NULL);
-
- assert(pthread_cond_init(&cvthing, NULL) == 0);
-
- for (i = 1; i < NUMTHREADS; i++)
- {
- assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0);
- }
-
- while (cvthing.count < NUMTHREADS)
- {}
-
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
- cvthing.busy = 0;
- assert(pthread_cond_signal(&cvthing.notbusy) == 0);
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- for (i = 1; i < NUMTHREADS; i++)
- {
- assert(pthread_join(t[i], (void *) &result[i]) == 0);
- }
+ assert(pthread_cond_init(&cv, NULL) == 0);
- assert(cvthing.count == 0);
-
- assert(pthread_cond_destroy(&cvthing) == 0);
+ assert(pthread_cond_destroy(&cv) == 0);
return 0;
}
-
-
-
-
-
-
-
diff --git a/tests/condvar2.c b/tests/condvar2.c
index 14097ed..107ed8f 100644
--- a/tests/condvar2.c
+++ b/tests/condvar2.c
@@ -2,7 +2,7 @@
* File: condvar1.c
*
* Test Synopsis:
- * - Test basic function of condition variable code.
+ * - Test timed wait on a CV.
*
* Test Method (Validation or Falsification):
* - Validation
@@ -17,99 +17,57 @@
* -
*
* Description:
- * -
+ * - Because the CV is never signaled, we expect the wait to time out.
*
* Environment:
- * -
+ * -
*
* Input:
- * -
+ * - None.
*
* Output:
- * -
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
*
* Assumptions:
* -
*
* Pass Criteria:
- * -
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns zero exit status.
*
* Fail Criteria:
- * -
+ * - pthread_cond_timedwait does not return ETIMEDOUT.
+ * - Process returns non-zero exit status.
*/
#include "test.h"
-typedef struct cvthing_t_ cvthing_t;
+pthread_cond_t cv;
+pthread_mutex_t mutex;
-struct cvthing_t_ {
- pthread_cond_t notbusy;
- pthread_mutex_t lock;
- int busy;
- int count;
-};
-
-static enum {
- NUMTHREADS = 10
-};
-
-static pthread_key_t key;
-
-static cvthing_t cvthing = {
- PTHREAD_COND_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER,
- 1,
- 0
-};
-
-void *
-mythread(void * arg)
+int
+main()
{
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
+ struct timespec abstime = { 0, 0 };
+ struct timeval curtime;
- cvthing.count++;
+ assert(pthread_cond_init(&cv, NULL) == 0);
- while (cvthing.busy)
- {
- assert(pthread_cond_wait(&cvthing.notbusy, &cvthing.lock) == 0);
- }
+ assert(pthread_mutex_init(&mutex) == 0);
- assert(cvthing.busy == 0);
+ assert(pthread_mutex_lock(&mutex) == 0);
- cvthing.count--;
+ assert(gettimeofday(&curtime, NULL) == 0);
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+ abstime.tv_sec = curtime.tv_sec + 5;
- return 0;
-}
-
-int
-main()
-{
- pthread_t t[NUMTHREADS];
- int result[NUMTHREADS];
+ assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT);
- assert((t[0] = pthread_self()) != NULL);
+ assert(pthread_mutex_unlock(&mutex) == 0);
- for (i = 1; i < NUMTHREADS; i++)
- {
- assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0);
- }
-
- while (cvthing.count < NUMTHREADS)
- {}
-
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
- cvthing.busy = 0;
- assert(pthread_cond_signal(&cvthing.notbusy) == 0);
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- for (i = 1; i < NUMTHREADS; i++)
- {
- assert(pthread_join(t[i], (void *) &result[i]) == 0);
- }
-
- assert(cvthing.count == 0);
+ assert(pthread_cond_destroy(&cv) == 0);
return 0;
}
+
diff --git a/tests/condvar3.c b/tests/condvar3.c
new file mode 100644
index 0000000..97a17cf
--- /dev/null
+++ b/tests/condvar3.c
@@ -0,0 +1,103 @@
+/*
+ * File: condvar1.c
+ *
+ * Test Synopsis:
+ * - Test basic function of a CV
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * - The primary thread takes the lock before creating any threads.
+ * The secondary thread blocks on the lock allowing the primary
+ * thread to enter the cv wait state which releases the lock.
+ * The secondary thread then takes the lock and signals the waiting
+ * primary thread.
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - pthread_cond_timedwait returns 0.
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+typedef struct cvthing_t_ cvthing_t;
+
+struct cvthing_t_ {
+ pthread_cond_t notbusy;
+ pthread_mutex_t lock;
+};
+
+static cvthing_t cvthing;
+
+static enum {
+ NUMTHREADS = 2 /* Including the primary thread. */
+};
+
+void *
+mythread(void * arg)
+{
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_signal(&cvthing.notbusy) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t[NUMTHREADS];
+ struct timespec abstime = { 0, 0 };
+ struct timeval curtime;
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ assert(pthread_cond_init(&cvthing, NULL) == 0);
+
+ assert(pthread_mutex_init(&cvthing.lock) == 0);
+
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ assert(gettimeofday(&curtime, NULL) == 0);
+
+ abstime.tv_sec = curtime.tv_sec + 5;
+
+ assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
+
+ assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_destroy(&cvthing) == 0);
+
+ return 0;
+}
diff --git a/tests/condvar4.c b/tests/condvar4.c
new file mode 100644
index 0000000..867746b
--- /dev/null
+++ b/tests/condvar4.c
@@ -0,0 +1,106 @@
+/*
+ * File: condvar1.c
+ *
+ * Test Synopsis:
+ * - Test PTHREAD_COND_INITIALIZER.
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * - Test basic CV function but starting with a static initialised
+ * CV.
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - pthread_cond_timedwait returns 0.
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+typedef struct cvthing_t_ cvthing_t;
+
+struct cvthing_t_ {
+ pthread_cond_t notbusy;
+ pthread_mutex_t lock;
+ int busy;
+ int count;
+};
+
+static cvthing_t cvthing = {
+ PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_COND_INITIALIZER,
+};
+
+static enum {
+ NUMTHREADS = 2
+};
+
+void *
+mythread(void * arg)
+{
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_signal(&cvthing.notbusy) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t[NUMTHREADS];
+ int result[NUMTHREADS];
+ struct timespec abstime = { 0, 0 };
+ struct timeval curtime;
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ gettimeofday(&curtime, NULL);
+ abstime.tv_sec = curtime.tv_sec + 5;
+
+ assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT);
+
+ assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
+
+ gettimeofday(&curtime, NULL);
+ abstime.tv_sec = curtime.tv_sec + 10;
+
+ assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_destroy(&cvthing) == 0);
+
+ return 0;
+}