summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2003-09-02 16:15:05 +0000
committerrpj <rpj>2003-09-02 16:15:05 +0000
commit879bb0613c03b10bdf91aa862c2463b7f9f99087 (patch)
tree6e91c26a0f16a0e4bfd3ed436f27e470b5db7307 /tests
parenta5f3d62017a8e705016d0083a24837d6a56f178d (diff)
Added cancelation of/from non-POSIX threads; minor fixes; minor changes.snap-2003-09-03
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog18
-rw-r--r--tests/GNUmakefile6
-rw-r--r--tests/Makefile6
-rw-r--r--tests/cancel7.c215
-rw-r--r--tests/exit4.c198
-rw-r--r--tests/exit5.c204
6 files changed, 639 insertions, 8 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 7dd3076..4873c31 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,11 +1,17 @@
+2003-09-03 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * exit4.c: New test.
+ * exit5.c: New test.
+ * cancel7.c: New test.
+
2003-08-13 Ross Johnson <rpj@ise.canberra.edu.au>
- * reuse1.c: New test.
- * reuse1.c: New test.
- * valid1.c: New test.
- * valid2.c: New test.
- * kill1.c: New test.
- * create2.c: Now included in test regime.
+ * reuse1.c: New test.
+ * reuse1.c: New test.
+ * valid1.c: New test.
+ * valid2.c: New test.
+ * kill1.c: New test.
+ * create2.c: Now included in test regime.
2003-07-19 Ross Johnson <rpj@ise.canberra.edu.au>
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index d4ce2ce..769beaa 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -67,7 +67,7 @@ TESTS = loadfree \
condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 \
create1 create2 reuse1 reuse2 equal1 \
kill1 valid1 valid2 \
- exit2 exit3 \
+ exit2 exit3 exit4 exit5 \
join0 join1 join2 \
mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \
mutex7 mutex7n mutex7e mutex7r mutex8 mutex8n mutex8e mutex8r \
@@ -79,6 +79,7 @@ TESTS = loadfree \
rwlock1 rwlock2 rwlock3 rwlock4 rwlock5 rwlock6 rwlock7 \
rwlock2_t rwlock3_t rwlock4_t rwlock5_t rwlock6_t rwlock6_t2 \
context1 cancel3 cancel4 cancel5 cancel6a cancel6d \
+ cancel7 \
cleanup0 cleanup1 cleanup2 cleanup3 \
priority1 priority2 inherit1 \
spin1 spin2 spin3 spin4 \
@@ -144,6 +145,7 @@ cancel4.pass: cancel3.pass
cancel5.pass: cancel3.pass
cancel6a.pass: cancel3.pass
cancel6d.pass: cancel3.pass
+cancel7.pass: kill1.pass
cleanup0.pass: cancel5.pass
cleanup1.pass: cleanup0.pass
cleanup2.pass: cleanup1.pass
@@ -177,6 +179,8 @@ exception3.pass: exception2.pass
exit1.pass:
exit2.pass: create1.pass
exit3.pass: create1.pass
+exit4.pass:
+exit5.pass: exit4.pass kill1.pass
eyal1.pass: tsd1.pass
inherit1.pass: join1.pass
join0.pass: create1.pass
diff --git a/tests/Makefile b/tests/Makefile
index 0000e8c..b743872 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -76,7 +76,7 @@ PASSES= loadfree.pass \
condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \
exit1.pass create1.pass create2.pass reuse1.pass reuse2.pass equal1.pass \
kill1.pass valid1.pass valid2.pass \
- exit2.pass exit3.pass \
+ exit2.pass exit3.pass exit4 exit5 \
join0.pass join1.pass join2.pass \
mutex4.pass mutex6.pass mutex6n.pass mutex6e.pass mutex6r.pass \
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \
@@ -93,6 +93,7 @@ PASSES= loadfree.pass \
rwlock2_t.pass rwlock3_t.pass rwlock4_t.pass rwlock5_t.pass rwlock6_t.pass rwlock6_t2.pass \
context1.pass \
cancel3.pass cancel4.pass cancel5.pass cancel6a.pass cancel6d.pass \
+ cancel7 \
cleanup0.pass cleanup1.pass cleanup2.pass cleanup3.pass \
priority1.pass priority2.pass inherit1.pass \
spin1.pass spin2.pass spin3.pass spin4.pass \
@@ -211,6 +212,7 @@ cancel4.pass: cancel3.pass
cancel5.pass: cancel3.pass
cancel6a.pass: cancel3.pass
cancel6d.pass: cancel3.pass
+cancel7.pass: kill1.pass
cleanup0.pass: cancel5.pass
cleanup1.pass: cleanup0.pass
cleanup2.pass: cleanup1.pass
@@ -244,6 +246,8 @@ exception3.pass: exception2.pass
exit1.pass:
exit2.pass: create1.pass
exit3.pass: create1.pass
+exit4.pass:
+exit5.pass: kill1.pass
eyal1.pass: tsd1.pass
inherit1.pass: join1.pass
join0.pass: create1.pass
diff --git a/tests/cancel7.c b/tests/cancel7.c
new file mode 100644
index 0000000..eda393b
--- /dev/null
+++ b/tests/cancel7.c
@@ -0,0 +1,215 @@
+/*
+ * File: cancel7.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * 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 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 in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis: Test canceling a Win32 thread having created an
+ * implicit POSIX handle for it.
+ *
+ * Test Method (Validation or Falsification):
+ * - Validate return value and that POSIX handle is created and destroyed.
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
+ * pthread_testcancel, pthread_cancel, pthread_join
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#ifndef _UWIN
+#include <process.h>
+#endif
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
+ */
+enum {
+ NUMTHREADS = 4
+};
+
+typedef struct bag_t_ bag_t;
+struct bag_t_ {
+ int threadnum;
+ int started;
+ /* Add more per-thread state variables here */
+ int count;
+ pthread_t self;
+};
+
+static bag_t threadbag[NUMTHREADS + 1];
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+unsigned __stdcall
+#else
+void
+#endif
+Win32thread(void * arg)
+{
+ int i;
+ bag_t * bag = (bag_t *) arg;
+
+ assert(bag == &threadbag[bag->threadnum]);
+ assert(bag->started == 0);
+ bag->started = 1;
+
+ assert((bag->self = pthread_self()) != NULL);
+ assert(pthread_kill(bag->self, 0) == 0);
+
+ for (i = 0; i < 100; i++)
+ {
+ Sleep(100);
+ pthread_testcancel();
+ }
+
+ return 0;
+}
+
+int
+main()
+{
+ int failed = 0;
+ int i;
+ HANDLE h[NUMTHREADS + 1];
+
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ threadbag[i].started = 0;
+ threadbag[i].threadnum = i;
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ h[i] = (HANDLE) _beginthreadex(NULL, 0, Win32thread, (void *) &threadbag[i], 0, NULL);
+#else
+ h[i] = (HANDLE) _beginthread(Win32thread, 0, (void *) &threadbag[i]);
+#endif
+ }
+
+ /*
+ * Code to control or munipulate child threads should probably go here.
+ */
+ Sleep(500);
+
+ /*
+ * Cancel all threads.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ assert(pthread_kill(threadbag[i].self, 0) == 0);
+ assert(pthread_cancel(threadbag[i].self) == 0);
+ }
+
+ /*
+ * Give threads time to run.
+ */
+ Sleep(NUMTHREADS * 100);
+
+ /*
+ * Standard check that all threads started.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ if (!threadbag[i].started)
+ {
+ failed |= !threadbag[i].started;
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ }
+
+ assert(!failed);
+
+ /*
+ * Check any results here. Set "failed" and only print output on failure.
+ */
+ failed = 0;
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ int fail = 0;
+ int result = 0;
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ assert(GetExitCodeThread(h[i], (LPDWORD) &result) == TRUE);
+#else
+ /*
+ * Can't get a result code.
+ */
+ result = (int) PTHREAD_CANCELED;
+#endif
+
+ assert(threadbag[i].self != NULL);
+ assert(pthread_kill(threadbag[i].self, 0) == ESRCH);
+
+ fail = (result != (int) PTHREAD_CANCELED);
+
+ if (fail)
+ {
+ fprintf(stderr, "Thread %d: started %d: count %d\n",
+ i,
+ threadbag[i].started,
+ threadbag[i].count);
+ }
+ failed = (failed || fail);
+ }
+
+ assert(!failed);
+
+ /*
+ * Success.
+ */
+ return 0;
+}
+
diff --git a/tests/exit4.c b/tests/exit4.c
new file mode 100644
index 0000000..6c2fea1
--- /dev/null
+++ b/tests/exit4.c
@@ -0,0 +1,198 @@
+/*
+ * File: exit4.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * 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 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 in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis: Test calling pthread_exit from a Win32 thread
+ * without having created an implicit POSIX handle for it.
+ *
+ * Test Method (Validation or Falsification):
+ * -
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
+ * pthread_testcancel, pthread_cancel, pthread_join
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#ifndef _UWIN
+#include <process.h>
+#endif
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
+ */
+enum {
+ NUMTHREADS = 4
+};
+
+typedef struct bag_t_ bag_t;
+struct bag_t_ {
+ int threadnum;
+ int started;
+ /* Add more per-thread state variables here */
+ int count;
+};
+
+static bag_t threadbag[NUMTHREADS + 1];
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+unsigned __stdcall
+#else
+void
+#endif
+Win32thread(void * arg)
+{
+ int result = 1;
+ bag_t * bag = (bag_t *) arg;
+
+ assert(bag == &threadbag[bag->threadnum]);
+ assert(bag->started == 0);
+ bag->started = 1;
+
+ /*
+ * Doesn't return and doesn't create an implicit POSIX handle.
+ */
+ pthread_exit((void *) result);
+
+ return 0;
+}
+
+int
+main()
+{
+ int failed = 0;
+ int i;
+ HANDLE h[NUMTHREADS + 1];
+
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ threadbag[i].started = 0;
+ threadbag[i].threadnum = i;
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ h[i] = (HANDLE) _beginthreadex(NULL, 0, Win32thread, (void *) &threadbag[i], 0, NULL);
+#else
+ h[i] = (HANDLE) _beginthread(Win32thread, 0, (void *) &threadbag[i]);
+#endif
+ }
+
+ /*
+ * Code to control or munipulate child threads should probably go here.
+ */
+ Sleep(500);
+
+ /*
+ * Give threads time to run.
+ */
+ Sleep(NUMTHREADS * 100);
+
+ /*
+ * Standard check that all threads started.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ if (!threadbag[i].started)
+ {
+ failed |= !threadbag[i].started;
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ }
+
+ assert(!failed);
+
+ /*
+ * Check any results here. Set "failed" and only print output on failure.
+ */
+ failed = 0;
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ int fail = 0;
+ int result = 0;
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ assert(GetExitCodeThread(h[i], (LPDWORD) &result) == TRUE);
+#else
+ /*
+ * Can't get a result code.
+ */
+ result = 1;
+#endif
+
+ fail = (result != 1);
+
+ if (fail)
+ {
+ fprintf(stderr, "Thread %d: started %d: count %d\n",
+ i,
+ threadbag[i].started,
+ threadbag[i].count);
+ }
+ failed = (failed || fail);
+ }
+
+ assert(!failed);
+
+ /*
+ * Success.
+ */
+ return 0;
+}
+
diff --git a/tests/exit5.c b/tests/exit5.c
new file mode 100644
index 0000000..f554fce
--- /dev/null
+++ b/tests/exit5.c
@@ -0,0 +1,204 @@
+/*
+ * File: exit5.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * 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 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 in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis: Test calling pthread_exit from a Win32 thread
+ * having created an implicit POSIX handle for it.
+ *
+ * Test Method (Validation or Falsification):
+ * - Validate return value and that POSIX handle is created and destroyed.
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
+ * pthread_testcancel, pthread_cancel, pthread_join
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#ifndef _UWIN
+#include <process.h>
+#endif
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
+ */
+enum {
+ NUMTHREADS = 4
+};
+
+typedef struct bag_t_ bag_t;
+struct bag_t_ {
+ int threadnum;
+ int started;
+ /* Add more per-thread state variables here */
+ int count;
+ pthread_t self;
+};
+
+static bag_t threadbag[NUMTHREADS + 1];
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+unsigned __stdcall
+#else
+void
+#endif
+Win32thread(void * arg)
+{
+ int result = 1;
+ bag_t * bag = (bag_t *) arg;
+
+ assert(bag == &threadbag[bag->threadnum]);
+ assert(bag->started == 0);
+ bag->started = 1;
+
+ assert((bag->self = pthread_self()) != NULL);
+ assert(pthread_kill(bag->self, 0) == 0);
+
+ /*
+ * Doesn't return.
+ */
+ pthread_exit((void *) result);
+
+ return 0;
+}
+
+int
+main()
+{
+ int failed = 0;
+ int i;
+ HANDLE h[NUMTHREADS + 1];
+
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ threadbag[i].started = 0;
+ threadbag[i].threadnum = i;
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ h[i] = (HANDLE) _beginthreadex(NULL, 0, Win32thread, (void *) &threadbag[i], 0, NULL);
+#else
+ h[i] = (HANDLE) _beginthread(Win32thread, 0, (void *) &threadbag[i]);
+#endif
+ }
+
+ /*
+ * Code to control or munipulate child threads should probably go here.
+ */
+ Sleep(500);
+
+ /*
+ * Give threads time to run.
+ */
+ Sleep(NUMTHREADS * 100);
+
+ /*
+ * Standard check that all threads started.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ if (!threadbag[i].started)
+ {
+ failed |= !threadbag[i].started;
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ }
+
+ assert(!failed);
+
+ /*
+ * Check any results here. Set "failed" and only print output on failure.
+ */
+ failed = 0;
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ int fail = 0;
+ int result = 0;
+
+#if ! defined (__MINGW32__) || defined (__MSVCRT__)
+ assert(GetExitCodeThread(h[i], (LPDWORD) &result) == TRUE);
+#else
+ /*
+ * Can't get a result code.
+ */
+ result = 1;
+#endif
+
+ assert(threadbag[i].self != NULL && pthread_kill(threadbag[i].self, 0) == ESRCH);
+
+ fail = (result != 1);
+
+ if (fail)
+ {
+ fprintf(stderr, "Thread %d: started %d: count %d\n",
+ i,
+ threadbag[i].started,
+ threadbag[i].count);
+ }
+ failed = (failed || fail);
+ }
+
+ assert(!failed);
+
+ /*
+ * Success.
+ */
+ return 0;
+}
+