summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbje <bje>1999-02-20 05:45:45 +0000
committerbje <bje>1999-02-20 05:45:45 +0000
commit46cb13531327c59ce4e3189e1a5b1763ed248095 (patch)
tree287011531651457cdc018e13df8c23e368871b89 /tests
parent60784dc1a92121efe9301ac57476024fe64f968b (diff)
1999-02-21 Ben Elliston <bje@cygnus.com>snap-1999-02-21
* README: Update. * Makefile: New file. Run all tests automatically. Primitive tests are run first; more complex tests are run last. * count1.c: New test. Validate the thread count. * exit2.c: Perform a simpler test. * exit3.c: New test. Replaces exit2.c, since exit2.c needs to perform simpler checking first. * create1.c: Update to use the new testsuite exiting convention. * equal1.c: Likewise. * mutex1.c: Likewise. * mutex2.c: Likewise. * once1.c: Likewise. * self2.c: Likewise. * self3.c: Likewise. * tsd1.c: Likewise.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog30
-rw-r--r--tests/Makefile14
-rw-r--r--tests/README9
-rw-r--r--tests/count1.c62
-rw-r--r--tests/create1.c9
-rw-r--r--tests/equal1.c39
-rw-r--r--tests/exit2.c27
-rw-r--r--tests/exit3.c36
-rw-r--r--tests/mutex1.c17
-rw-r--r--tests/mutex2.c12
-rw-r--r--tests/once1.c18
-rw-r--r--tests/self2.c8
-rw-r--r--tests/self3.c12
-rw-r--r--tests/tsd1.c8
14 files changed, 244 insertions, 57 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 27834cb..cb1abab 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,33 @@
+1999-02-21 Ben Elliston <bje@cygnus.com>
+
+ * README: Update.
+
+ * Makefile: New file. Run all tests automatically. Primitive tests
+ are run first; more complex tests are run last.
+
+ * count1.c: New test. Validate the thread count.
+
+ * exit2.c: Perform a simpler test.
+
+ * exit3.c: New test. Replaces exit2.c, since exit2.c needs to
+ perform simpler checking first.
+
+ * create1.c: Update to use the new testsuite exiting convention.
+
+ * equal1.c: Likewise.
+
+ * mutex1.c: Likewise.
+
+ * mutex2.c: Likewise.
+
+ * once1.c: Likewise.
+
+ * self2.c: Likewise.
+
+ * self3.c: Likewise.
+
+ * tsd1.c: Likewise.
+
1999-02-20 Ross Johnson <rpj@ise.canberra.edu.au>
* mutex2.c: Test static mutex initialisation.
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..82c1d44
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,14 @@
+# Makefile for the pthreads test suite.
+# If all of the .pass files can be created, the test suite has passed.
+
+# If a test case returns a non-zero exit code to the shell, make will
+# stop.
+
+PASSES = count1.pass create1.pass equal1.pass exit1.pass exit2.pass \
+ exit3.pass eyal1.pass mutex1.pass mutex2.pass mutex3.pass \
+ once1.pass self1.pass self2.pass self3.pass tsd1.pass
+
+all: $(PASSES)
+
+%.pass: %.exe
+ touch $@
diff --git a/tests/README b/tests/README
index cce2924..fa3c0bf 100644
--- a/tests/README
+++ b/tests/README
@@ -9,3 +9,12 @@ Usage: runtest cl|gcc testname
"gcc" calls the GNU gcc compiler/linker
"testname" is the name of the C source file without the .c
+Tests written in this test suite should behave in the following manner:
+
+ * If a test fails, leave main() with a result of 1.
+
+ * If a test succeeds, leave main() with a result of 0.
+
+ * No diagnostic output should appear when the test is succeeding.
+ Diagnostic output may be emitted if something in the test
+ fails, to help determine the cause of the test failure.
diff --git a/tests/count1.c b/tests/count1.c
new file mode 100644
index 0000000..c4e0c4e
--- /dev/null
+++ b/tests/count1.c
@@ -0,0 +1,62 @@
+/*
+ * count1.c
+ *
+ * Written by Ben Elliston <bje@cygnus.com>.
+ *
+ * Description:
+ * Test some basic assertions about the number of threads at runtime.
+ */
+
+#include <windows.h>
+#include <pthread.h>
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t threads[10];
+static unsigned numThreads = 1;
+
+void *
+myfunc(void *arg)
+{
+ pthread_mutex_lock(&lock);
+ numThreads++;
+ pthread_mutex_unlock(&lock);
+
+ Sleep(1000);
+ return 0;
+}
+int
+main()
+{
+ int i, result;
+ int maxThreads = sizeof(threads) / sizeof(pthread_t);
+
+ /* Spawn ten threads. Each thread should increment the numThreads
+ variable, sleep for one second, decrement the variable and then
+ exit. The final result of numThreads should be 1 again. */
+ for (i = 0; i < maxThreads; i++)
+ {
+ result = pthread_create(&threads[i], NULL, myfunc, 0);
+ if (result != 0)
+ {
+ return 1;
+ }
+ }
+
+ /* Wait for all the threads to exit. */
+ for (i = 0; i < maxThreads; i++)
+ {
+ pthread_join(threads[i], NULL);
+ pthread_mutex_lock(&lock);
+ numThreads--;
+ pthread_mutex_unlock(&lock);
+ }
+
+ /* Check the number of live threads. */
+ if (numThreads != 1)
+ {
+ return 1;
+ }
+
+ /* Success. */
+ return 0;
+}
diff --git a/tests/create1.c b/tests/create1.c
index 841c565..2741401 100644
--- a/tests/create1.c
+++ b/tests/create1.c
@@ -4,7 +4,6 @@
void * func(void * arg)
{
- printf("Hello world\n");
return 0;
}
@@ -12,8 +11,14 @@ int
main()
{
pthread_t t;
- pthread_create(&t, NULL, func, NULL);
+ if (pthread_create(&t, NULL, func, NULL) != 0)
+ {
+ return 1;
+ }
+ /* A dirty hack, but we cannot rely on pthread_join in this
+ primitive test. */
Sleep(5000);
+
return 0;
}
diff --git a/tests/equal1.c b/tests/equal1.c
index e877990..d882adc 100644
--- a/tests/equal1.c
+++ b/tests/equal1.c
@@ -1,34 +1,47 @@
+/*
+ * Test for pthread_equal.
+ *
+ * Depends on functions: pthread_create().
+ */
+
#include <pthread.h>
#include <stdio.h>
#include <windows.h>
void * func(void * arg)
{
- printf("Hello world %d\n", (int) arg);
Sleep(2000);
- return arg;
+ return 0;
}
main()
{
int rc;
pthread_t t1, t2;
- rc = pthread_create(&t1, NULL, func, (void *) 1);
- rc = pthread_create(&t2, NULL, func, (void *) 2);
+ if (pthread_create(&t1, NULL, func, (void *) 1) != 0)
+ {
+ return 1;
+ }
+
+ if (pthread_create(&t2, NULL, func, (void *) 2) != 0)
+ {
+ return 1;
+ }
- puts("testing t1 and t2: ");
if (pthread_equal(t1, t2))
- printf("equal\n");
- else
- printf("not equal\n");
+ {
+ return 1;
+ }
- puts("testing t1 on itself: ");
- if (pthread_equal(t1,t1))
- printf("equal\n");
- else
- printf("not equal\n");
+ if (pthread_equal(t1,t1) == 0)
+ {
+ return 1;
+ }
+ /* This is a hack. We don't want to rely on pthread_join
+ yet if we can help it. */
Sleep(8000);
+ /* Success. */
return 0;
}
diff --git a/tests/exit2.c b/tests/exit2.c
index af906eb..48ad5d0 100644
--- a/tests/exit2.c
+++ b/tests/exit2.c
@@ -1,35 +1,12 @@
/*
* Test for pthread_exit().
- *
- * Depends on API functions: pthread_create().
*/
#include <pthread.h>
-#include <stdio.h>
-
-void *
-func(void * arg)
-{
- printf("Hello world\n");
- pthread_exit(arg);
-
- /* Never reached. */
- return 0;
-}
int
main(int argc, char * argv[])
{
- pthread_t id[4];
- int i;
-
- /* Create a few threads, make them say hello and then exit. */
-
- for (i = 0; i < 4; i++)
- {
- pthread_create(&id[i], NULL, func, (void *) i);
- }
-
- /* Semantics should be the same as POSIX. Wait for the workers. */
- pthread_exit((void *) 0);
+ /* Should be the same as return 0; */
+ pthread_exit(0);
}
diff --git a/tests/exit3.c b/tests/exit3.c
new file mode 100644
index 0000000..f15b39d
--- /dev/null
+++ b/tests/exit3.c
@@ -0,0 +1,36 @@
+/*
+ * Test for pthread_exit().
+ *
+ * Depends on API functions: pthread_create().
+ */
+
+#include <pthread.h>
+#include <stdio.h>
+
+void *
+func(void * arg)
+{
+ pthread_exit(arg);
+
+ /* Never reached. */
+ return 0;
+}
+
+int
+main(int argc, char * argv[])
+{
+ pthread_t id[4];
+ int i;
+
+ /* Create a few threads and then exit. */
+ for (i = 0; i < 4; i++)
+ {
+ if (pthread_create(&id[i], NULL, func, (void *) i) != 0)
+ {
+ return 1;
+ }
+ }
+
+ /* Success. */
+ return 0;
+}
diff --git a/tests/mutex1.c b/tests/mutex1.c
index 27e2a82..f1c9240 100644
--- a/tests/mutex1.c
+++ b/tests/mutex1.c
@@ -12,9 +12,20 @@ pthread_mutex_t mutex1;
int
main()
{
- pthread_mutex_init(&mutex1, NULL);
- pthread_mutex_lock(&mutex1);
- pthread_mutex_unlock(&mutex1);
+ if (pthread_mutex_init(&mutex1, NULL) != 0)
+ {
+ return 1;
+ }
+
+ if (pthread_mutex_lock(&mutex1) != 0)
+ {
+ return 1;
+ }
+
+ if (pthread_mutex_unlock(&mutex1) != 0)
+ {
+ return 1;
+ }
return 0;
}
diff --git a/tests/mutex2.c b/tests/mutex2.c
index d0885fc..cfbebdc 100644
--- a/tests/mutex2.c
+++ b/tests/mutex2.c
@@ -15,11 +15,15 @@ main()
result = pthread_mutex_trylock(&mutex1);
printf("pthread_mutex_trylock returned %s\n", error_string[result]);
+ if (result != 0)
+ {
+ return 1;
+ }
- if (result == 0)
- {
- pthread_mutex_unlock(&mutex1);
- }
+ if (pthread_mutex_unlock(&mutex1) != 0)
+ {
+ return 1;
+ }
return 0;
}
diff --git a/tests/once1.c b/tests/once1.c
index f4164ac..661d322 100644
--- a/tests/once1.c
+++ b/tests/once1.c
@@ -1,3 +1,9 @@
+/*
+ * Test for pthread_once().
+ *
+ * Depends on functions: pthread_create.
+ */
+
#include <pthread.h>
#include <stdio.h>
@@ -24,11 +30,15 @@ main()
int rc;
pthread_t t1, t2;
- rc = pthread_create(&t1, NULL, mythread, NULL);
- printf("pthread_create returned %d\n", rc);
+ if (pthread_create(&t1, NULL, mythread, NULL) != 0)
+ {
+ return 1;
+ }
- rc = pthread_create(&t2, NULL, mythread, NULL);
- printf("pthread_create returned %d\n", rc);
+ if (pthread_create(&t2, NULL, mythread, NULL) != 0)
+ {
+ return 1;
+ }
Sleep(2000);
return 0;
diff --git a/tests/self2.c b/tests/self2.c
index 76d7b71..51cc129 100644
--- a/tests/self2.c
+++ b/tests/self2.c
@@ -23,9 +23,13 @@ main()
int rc;
pthread_t t;
- rc = pthread_create(&t, NULL, entry, NULL);
- assert(rc == 0);
+ if (pthread_create(&t, NULL, entry, NULL) != 0)
+ {
+ return 1;
+ }
Sleep(2000);
+
+ /* Success. */
return 0;
}
diff --git a/tests/self3.c b/tests/self3.c
index 17d5ed3..5cc8296 100644
--- a/tests/self3.c
+++ b/tests/self3.c
@@ -23,11 +23,15 @@ main()
int rc;
pthread_t t[2];
- rc = pthread_create(&t[0], NULL, entry, (void *) 1);
- assert(rc == 0);
+ if (pthread_create(&t[0], NULL, entry, (void *) 1) != 0)
+ {
+ return 1;
+ }
- rc = pthread_create(&t[1], NULL, entry, (void *) 2);
- assert(rc == 0);
+ if (pthread_create(&t[1], NULL, entry, (void *) 2) != 0)
+ {
+ return 1;
+ }
Sleep(2000);
return 0;
diff --git a/tests/tsd1.c b/tests/tsd1.c
index 5236fe7..8137a64 100644
--- a/tests/tsd1.c
+++ b/tests/tsd1.c
@@ -130,6 +130,10 @@ main()
{
rc = pthread_create(&thread[t], NULL, mythread, (void *) (t + 1));
printf("pthread_create returned %d\n", rc);
+ if (rc != 0)
+ {
+ return 1;
+ }
}
(void) pthread_once(&key_once, make_key);
@@ -143,6 +147,10 @@ main()
{
rc = pthread_create(&thread[t], NULL, mythread, (void *) (t + 1));
printf("pthread_create returned %d\n", rc);
+ if (rc != 0)
+ {
+ return 1;
+ }
}
Sleep(2000);