summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2003-08-14 08:53:17 +0000
committerrpj <rpj>2003-08-14 08:53:17 +0000
commita50745ec922a917513029f3f87bf820827b43f29 (patch)
tree1e221862e0550d163baef12d17634430ae677824 /tests
parent414f4bd7e70d94025576d9264c86da63c506f6ca (diff)
Reuse of thread IDs, improved thread ID validation, new tests, bug fixes.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog33
-rw-r--r--tests/GNUmakefile10
-rw-r--r--tests/Makefile9
-rw-r--r--tests/create2.c6
-rw-r--r--tests/exception2.c2
-rw-r--r--tests/kill1.c87
-rw-r--r--tests/reuse1.c119
-rw-r--r--tests/reuse2.c162
-rw-r--r--tests/valid1.c104
-rw-r--r--tests/valid2.c91
10 files changed, 604 insertions, 19 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index fb52cef..7dd3076 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,16 +1,25 @@
-2003-07-19 Ross Johnson <ross@ise.canberra.edu.au>
+2003-08-13 Ross Johnson <rpj@ise.canberra.edu.au>
- * eyal1.c (waste_time): Make threads do more work to ensure that
- all threads get to do some work.
- * semaphore1.c: Make it clear that certain errors are expected.
- * exception2.c (non_MSVC code sections): Change to include
- C++ standard include file, i.e. change <new.h> to <exception>.
- * exception3.c (non_MSVC code sections): Likewise; qualify std::
- namespace entities where necessary.
- * GNUmakefile: modified to work in the MsysDTK (newer MinGW)
- environment; define CC as gcc or g++ as appropriate because
- using gcc -x c++ doesn't link with required c++ libs by default,
- but g++ does.
+ * 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>
+
+ * eyal1.c (waste_time): Make threads do more work to ensure that
+ all threads get to do some work.
+ * semaphore1.c: Make it clear that certain errors are expected.
+ * exception2.c (non_MSVC code sections): Change to include
+ C++ standard include file, i.e. change <new.h> to <exception>.
+ * exception3.c (non_MSVC code sections): Likewise; qualify std::
+ namespace entities where necessary.
+ * GNUmakefile: modified to work in the MsysDTK (newer MinGW)
+ environment; define CC as gcc or g++ as appropriate because
+ using gcc -x c++ doesn't link with required c++ libs by default,
+ but g++ does.
2002-12-11 Ross Johnson <ross@special.ise.canberra.edu.au>
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index 132f84b..ba4c78d 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -64,7 +64,9 @@ COPYFILES = $(HDR) $(LIB) $(DLL)
TESTS = loadfree \
semaphore1 semaphore2 self1 mutex5 mutex1 mutex1e mutex1n mutex1r \
- condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 create1 equal1 \
+ condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 \
+ create1 create2 reuse1 reuse2 equal1 \
+ kill1 valid1 valid2 \
exit2 exit3 \
join0 join1 join2 \
mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \
@@ -164,6 +166,7 @@ condvar9.pass: condvar8.pass
context1.pass: cancel2.pass
count1.pass: join1.pass
create1.pass: mutex2.pass
+create2.pass: create1.pass
delay1.pass: cancel2.pass
delay2.pass: delay1.pass
equal1.pass: create1.pass
@@ -179,6 +182,7 @@ inherit1.pass: join1.pass
join0.pass: create1.pass
join1.pass: create1.pass
join2.pass: create1.pass
+kill1.pass:
loadfree.pass: pthread.dll
mutex1.pass: self1.pass
mutex1n.pass: mutex1.pass
@@ -203,6 +207,8 @@ mutex8r.pass: mutex7r.pass
once1.pass: create1.pass
priority1.pass: join1.pass
priority2.pass: priority1.pass
+reuse1.pass: create2.pass
+reuse2.pass: reuse1.pass
rwlock1.pass: condvar6.pass
rwlock2.pass: rwlock1.pass
rwlock3.pass: rwlock2.pass
@@ -225,6 +231,8 @@ spin2.pass: spin1.pass
spin3.pass: spin2.pass
spin4.pass: spin3.pass
tsd1.pass: join1.pass
+valid1.pass: join1.pass
+valid2.pass: valid1.pass
#%.pass: %.exe $(HDR)
%.pass: %.exe $(LIB) $(DLL) $(HDR)
diff --git a/tests/Makefile b/tests/Makefile
index 014b767..e16d21a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -74,7 +74,8 @@ PASSES= loadfree.pass \
semaphore1.pass semaphore2.pass self1.pass mutex5.pass \
mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass mutex2.pass mutex3.pass \
condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \
- exit1.pass create1.pass equal1.pass \
+ exit1.pass create1.pass create2.pass reuse1.pass reuse2.pass equal1.pass \
+ kill1.pass valid1.pass valid2.pass \
exit2.pass exit3.pass \
join0.pass join1.pass join2.pass \
mutex4.pass mutex6.pass mutex6n.pass mutex6e.pass mutex6r.pass \
@@ -232,6 +233,7 @@ condvar9.pass: condvar8.pass
context1.pass: cancel2.pass
count1.pass: join1.pass
create1.pass: mutex2.pass
+create2.pass: create1.pass
delay1.pass:
delay2.pass: delay1.pass
equal1.pass: create1.pass
@@ -247,6 +249,7 @@ inherit1.pass: join1.pass
join0.pass: create1.pass
join1.pass: create1.pass
join2.pass: create1.pass
+kill1.pass:
loadfree.pass: pthread.dll
mutex1.pass: self1.pass
mutex1n.pass: mutex1.pass
@@ -271,6 +274,8 @@ mutex8r.pass: mutex7r.pass
once1.pass: create1.pass
priority1.pass: join1.pass
priority2.pass: priority1.pass
+reuse1.pass: create2.pass
+reuse2.pass: reuse1.pass
rwlock1.pass: condvar6.pass
rwlock2.pass: rwlock1.pass
rwlock3.pass: rwlock2.pass
@@ -293,3 +298,5 @@ spin2.pass: spin1.pass
spin3.pass: spin2.pass
spin4.pass: spin3.pass
tsd1.pass: join1.pass
+valid1.pass: join1.pass
+valid2.pass: valid1.pass
diff --git a/tests/create2.c b/tests/create2.c
index ea2979f..d23d19f 100644
--- a/tests/create2.c
+++ b/tests/create2.c
@@ -76,16 +76,13 @@
#include "test.h"
enum {
- NUMTHREADS = 10000;
+ NUMTHREADS = 10000
};
static int washere = 0;
void * func(void * arg)
{
- HANDLE w32ThreadH = (pthread_self())->threadH;
-
- assert(w32ThreadH != 0);
washere = 1;
return (void *) 0;
}
@@ -96,6 +93,7 @@ main()
pthread_t t;
pthread_attr_t attr;
void * result = NULL;
+ int i;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
diff --git a/tests/exception2.c b/tests/exception2.c
index 36edd9c..35ae606 100644
--- a/tests/exception2.c
+++ b/tests/exception2.c
@@ -78,7 +78,7 @@
#if defined(_MSC_VER) && defined(__cplusplus)
#include <eh.h>
-#else
+#elif defined(__cplusplus)
#include <exception>
#endif
diff --git a/tests/kill1.c b/tests/kill1.c
new file mode 100644
index 0000000..28d0c6b
--- /dev/null
+++ b/tests/kill1.c
@@ -0,0 +1,87 @@
+/*
+ * File: kill.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 998 John E. Bossom
+ * Copyright(C) 999,22 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.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.,
+ * 9 Temple Place - Suite 33, Boston, MA 2-37, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis:
+ * - pthread_kill() does not support non zero signals..
+ *
+ * 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:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+
+int
+main()
+{
+ void * result = NULL;
+
+ assert(pthread_kill(pthread_self(), ) == EINVAL);
+
+ return ;
+}
diff --git a/tests/reuse1.c b/tests/reuse1.c
new file mode 100644
index 0000000..f56ac9d
--- /dev/null
+++ b/tests/reuse1.c
@@ -0,0 +1,119 @@
+/*
+ * File: reuse.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 998 John E. Bossom
+ * Copyright(C) 999,22 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.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.,
+ * 9 Temple Place - Suite 33, Boston, MA 2-37, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis:
+ * - Confirm that thread reuse works for joined threads.
+ *
+ * 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:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+enum {
+ NUMTHREADS =
+};
+
+static int washere = ;
+
+void * func(void * arg)
+{
+ washere = ;
+ return (void *) ;
+}
+
+int
+main()
+{
+ pthread_t t,
+ last_t;
+ pthread_attr_t attr;
+ void * result = NULL;
+ int i;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+ washere = ;
+ assert(pthread_create(&t, &attr, func, NULL) == );
+ pthread_join(t, &result);
+ assert(washere == );
+ last_t = t;
+
+ for (i = ; i < NUMTHREADS; i++)
+ {
+ washere = ;
+ assert(pthread_create(&t, &attr, func, NULL) == );
+ pthread_join(t, &result);
+ assert(washere == );
+ assert(t == last_t);
+ last_t = t;
+ }
+
+ return ;
+}
diff --git a/tests/reuse2.c b/tests/reuse2.c
new file mode 100644
index 0000000..341dfcc
--- /dev/null
+++ b/tests/reuse2.c
@@ -0,0 +1,162 @@
+/*
+ * File: reuse2.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 998 John E. Bossom
+ * Copyright(C) 999,22 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.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.,
+ * 9 Temple Place - Suite 33, Boston, MA 2-37, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis:
+ * - Test that thread reuse works for detached threads.
+ * - Analyse thread struct reuse.
+ *
+ * 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:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+enum {
+ NUMTHREADS =
+};
+
+
+static int done = ;
+
+void * func(void * arg)
+{
+ sched_yield();
+
+ InterlockedIncrement((void *) &done);
+
+ return (void *) ;
+}
+
+int
+main()
+{
+ pthread_t t[NUMTHREADS];
+ pthread_attr_t attr;
+ int i, j;
+ int reuse,
+ reuseMax = ,
+ reuseMin = NUMTHREADS,
+ idTotal = ;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ for (i = ; i < NUMTHREADS; i++)
+ {
+ assert(pthread_create(&t[i], &attr, func, NULL) == );
+ }
+
+ while (NUMTHREADS > done)
+ Sleep();
+
+ /*
+ * Analyse reuse by computing min and max times pthread_create()
+ * returned the same pthread_t value.
+ */
+ for (i = ; i < NUMTHREADS; i++)
+ {
+ reuse = ;
+
+ if (t[i] == NULL)
+ continue;
+
+ for (j = ; j < i; j++)
+ {
+ if (t[j] == t[i])
+ {
+ reuse++;
+ t[j] = NULL;
+ }
+ }
+ for (j = i + ; j < NUMTHREADS; j++)
+ {
+ if (t[j] == t[i])
+ {
+ reuse++;
+ t[j] = NULL;
+ }
+ }
+ if (reuseMax < reuse)
+ reuseMax = reuse;
+ if (reuseMin > reuse)
+ reuseMin = reuse;
+ }
+
+ for (i = ; i < NUMTHREADS; i++)
+ {
+ if (t[i] != NULL)
+ idTotal++;
+ }
+
+ printf("For %d total threads:\n", NUMTHREADS);
+ printf("Reuse maximum = %d\n", reuseMax);
+ printf("Reuse minimum = %d\n", reuseMin);
+ printf("Total thread IDs allocated = %d\n", idTotal);
+
+ return ;
+}
diff --git a/tests/valid1.c b/tests/valid1.c
new file mode 100644
index 0000000..acaaa82
--- /dev/null
+++ b/tests/valid1.c
@@ -0,0 +1,104 @@
+/*
+ * File: valid.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 998 John E. Bossom
+ * Copyright(C) 999,22 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.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.,
+ * 9 Temple Place - Suite 33, Boston, MA 2-37, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis:
+ * - Test that thread validation works.
+ *
+ * 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:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+enum {
+ NUMTHREADS =
+};
+
+static int washere = ;
+
+void * func(void * arg)
+{
+ washere = ;
+ return (void *) ;
+}
+
+int
+main()
+{
+ pthread_t t;
+ void * result = NULL;
+
+ washere = ;
+ assert(pthread_create(&t, NULL, func, NULL) == );
+ pthread_join(t, &result);
+ assert(washere == );
+ sched_yield();
+ assert(pthread_kill(t, ) == ESRCH);
+
+ return ;
+}
diff --git a/tests/valid2.c b/tests/valid2.c
new file mode 100644
index 0000000..e1f9131
--- /dev/null
+++ b/tests/valid2.c
@@ -0,0 +1,91 @@
+/*
+ * File: valid2.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 998 John E. Bossom
+ * Copyright(C) 999,22 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.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.,
+ * 9 Temple Place - Suite 33, Boston, MA 2-37, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis:
+ * - Confirm that thread validation fails for garbage thread ID.
+ *
+ * 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:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+
+int
+main()
+{
+ pthread_t t;
+
+ t = (pthread_t) malloc(sizeof(t));;
+
+ assert(t != NULL);
+ memset(t, xA, sizeof(t));
+ assert(pthread_kill(t, ) == ESRCH);
+
+ return ;
+}