summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2002-03-02 01:53:08 +0000
committerrpj <rpj>2002-03-02 01:53:08 +0000
commit44c245b3ed9e82cc44a5ade4a941c99f63174021 (patch)
tree4a7b209123299d176826442200de02fed08afb7d /tests
parent8200f6ff1edca15756a22e6359f20836c4b5425b (diff)
* errno.c: Compiler directive was incorrectly including code.
* pthread.h: Conditionally added some #defines from config.h needed when not building the library. e.g. NEED_ERRNO, NEED_SEM. (PTW32_DLLPORT): Now only defined if _DLL defined. (_errno): Compiler directive was incorrectly including prototype. * sched.h: Conditionally added some #defines from config.h needed when not building the library. * semaphore.h: Replace an instance of NEED_SEM that should have been NEED_ERRNO. This change currently has nil effect. * GNUmakefile: Correct some recent changes. * Makefile: Add rule to generate pre-processor output.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog8
-rw-r--r--tests/GNUmakefile4
-rw-r--r--tests/Makefile8
-rw-r--r--tests/exception3.c2
-rw-r--r--tests/rwlock2_t.c80
-rw-r--r--tests/rwlock3_t.c89
-rw-r--r--tests/rwlock4_t.c89
-rw-r--r--tests/rwlock5_t.c91
-rw-r--r--tests/rwlock6_t.c128
-rw-r--r--tests/rwlock6_t2.c121
-rw-r--r--tests/semaphore1.c159
11 files changed, 774 insertions, 5 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 663db9b..bc42f7e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,13 @@
2002-02-28 Ross Johnson <rpj@special.ise.canberra.edu.au>
+ * exception3.c: Correct recent change.
+
+ * semaphore1.c: New test.
+
+ * Makefile: Add rule to generate pre-processor output.
+
+2002-02-28 Ross Johnson <rpj@special.ise.canberra.edu.au>
+
* exception3.c (terminateFunction): For MSVC++, call
exit() rather than pthread_exit(). Add comments to explain
why.
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index 800d33a..9a0902e 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -65,7 +65,7 @@ COPYFILES = $(HDR) $(LIB) $(DLL)
# stop.
TESTS = loadfree \
- self1 mutex5 mutex1 mutex1e mutex1n mutex1r \
+ semaphore1 self1 mutex5 mutex1 mutex1e mutex1n mutex1r \
condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 create1 equal1 \
exit2 exit3 \
join0 join1 join2 \
@@ -222,6 +222,7 @@ rwlock6_t.pass: rwlock5_t.pass
rwlock6_t2.pass: rwlock6_t.pass
self1.pass:
self2.pass: create1.pass
+semaphore1.pass:
spin1.pass:
spin2.pass: spin1.pass
spin3.pass: spin2.pass
@@ -267,6 +268,7 @@ clean:
- $(RM) sched.h
- $(RM) *.a
- $(RM) *.e
+ - $(RM) *.i
- $(RM) *.obj
- $(RM) *.pdb
- $(RM) *.exe
diff --git a/tests/Makefile b/tests/Makefile
index 00e886f..f684f31 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -71,7 +71,7 @@ EHFLAGS =
# stop.
PASSES= loadfree.pass \
- self1.pass mutex5.pass \
+ semaphore1.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 \
@@ -166,8 +166,8 @@ VCX-bench:
@ $(ECHO) $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(CPLIB)
@ $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(CPLIB)
-.c.pre:
- @ $(CC) /E $(EHFLAGS) $(CFLAGS) $(INCLUDES) /Fe$@ $<
+.c.i:
+ @ $(CC) /P $(EHFLAGS) $(CFLAGS) $(INCLUDES) $<
$(COPYFILES):
@ $(ECHO) Copying $@
@@ -184,6 +184,7 @@ clean:
- $(RM) semaphore.h
- $(RM) sched.h
- $(RM) *.e
+ - $(RM) *.i
- $(RM) *.obj
- $(RM) *.pdb
- $(RM) *.o
@@ -287,6 +288,7 @@ rwlock6_t.pass: rwlock5_t.pass
rwlock6_t2.pass: rwlock6_t.pass
self1.pass:
self2.pass: create1.pass
+semaphore.pass:
spin1.pass:
spin2.pass: spin1.pass
spin3.pass: spin2.pass
diff --git a/tests/exception3.c b/tests/exception3.c
index 3d9ea86..d3eb364 100644
--- a/tests/exception3.c
+++ b/tests/exception3.c
@@ -117,7 +117,7 @@ terminateFunction ()
* through or to MSVC++ code, and vice versa.
* Applications should probably not depend on this.
*/
- pthread_exit((void *) 0));
+ pthread_exit((void *) 0);
#else
/*
* Notes from the MSVC++ manual:
diff --git a/tests/rwlock2_t.c b/tests/rwlock2_t.c
new file mode 100644
index 0000000..b0c9998
--- /dev/null
+++ b/tests/rwlock2_t.c
@@ -0,0 +1,80 @@
+/*
+ * rwlock2_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-lock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+int
+main()
+{
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(rwlock == PTHREAD_RWLOCK_INITIALIZER);
+
+ assert(pthread_rwlock_timedrdlock(&rwlock, &abstime) == 0);
+
+ assert(rwlock != PTHREAD_RWLOCK_INITIALIZER);
+
+ assert(rwlock != NULL);
+
+ assert(pthread_rwlock_unlock(&rwlock) == 0);
+
+ assert(pthread_rwlock_destroy(&rwlock) == 0);
+
+ assert(rwlock == NULL);
+
+ return 0;
+}
diff --git a/tests/rwlock3_t.c b/tests/rwlock3_t.c
new file mode 100644
index 0000000..ad4ea2c
--- /dev/null
+++ b/tests/rwlock3_t.c
@@ -0,0 +1,89 @@
+/*
+ * rwlock3_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-wrlock it, trywrlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedwrlock()
+ * pthread_rwlock_trywrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedwrlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock4_t.c b/tests/rwlock4_t.c
new file mode 100644
index 0000000..68e1420
--- /dev/null
+++ b/tests/rwlock4_t.c
@@ -0,0 +1,89 @@
+/*
+ * rwlock4_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-rdlock it, trywrlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_trywrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock5_t.c b/tests/rwlock5_t.c
new file mode 100644
index 0000000..dc3cd52
--- /dev/null
+++ b/tests/rwlock5_t.c
@@ -0,0 +1,91 @@
+/*
+ * rwlock5_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-rdlock it, tryrdlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_tryrdlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_tryrdlock(&rwlock1) == 0);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock6_t.c b/tests/rwlock6_t.c
new file mode 100644
index 0000000..bf40258
--- /dev/null
+++ b/tests/rwlock6_t.c
@@ -0,0 +1,128 @@
+/*
+ * rwlock6_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Check writer and reader locking with reader timeouts
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_wrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int bankAccount = 0;
+
+void * wrfunc(void * arg)
+{
+ assert(pthread_rwlock_wrlock(&rwlock1) == 0);
+ Sleep(2000);
+ bankAccount += 10;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ return ((void *) bankAccount);
+}
+
+void * rdfunc(void * arg)
+{
+ int ba = -1;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+
+ if ((int) arg == 1)
+ {
+ abstime.tv_sec += 1;
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == ETIMEDOUT);
+ ba = 0;
+ }
+ else if ((int) arg == 2)
+ {
+ abstime.tv_sec += 3;
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+ ba = bankAccount;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+ }
+
+ return ((void *) ba);
+}
+
+int
+main()
+{
+ pthread_t wrt1;
+ pthread_t wrt2;
+ pthread_t rdt1;
+ pthread_t rdt2;
+ int wr1Result = 0;
+ int wr2Result = 0;
+ int rd1Result = 0;
+ int rd2Result = 0;
+
+ bankAccount = 0;
+
+ assert(pthread_create(&wrt1, NULL, wrfunc, NULL) == 0);
+ Sleep(500);
+ assert(pthread_create(&rdt1, NULL, rdfunc, (void *) 1) == 0);
+ Sleep(500);
+ assert(pthread_create(&wrt2, NULL, wrfunc, NULL) == 0);
+ Sleep(500);
+ assert(pthread_create(&rdt2, NULL, rdfunc, (void *) 2) == 0);
+
+ assert(pthread_join(wrt1, (void **) &wr1Result) == 0);
+ assert(pthread_join(rdt1, (void **) &rd1Result) == 0);
+ assert(pthread_join(wrt2, (void **) &wr2Result) == 0);
+ assert(pthread_join(rdt2, (void **) &rd2Result) == 0);
+
+ assert(wr1Result == 10);
+ assert(rd1Result == 0);
+ assert(wr2Result == 20);
+ assert(rd2Result == 20);
+
+ return 0;
+}
+
+
diff --git a/tests/rwlock6_t2.c b/tests/rwlock6_t2.c
new file mode 100644
index 0000000..532cc39
--- /dev/null
+++ b/tests/rwlock6_t2.c
@@ -0,0 +1,121 @@
+/*
+ * rwlock6_t2.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Check writer and reader timeouts.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_timedwrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int bankAccount = 0;
+struct timespec abstime = { 0, 0 };
+
+void * wrfunc(void * arg)
+{
+ int result;
+
+ result = pthread_rwlock_timedwrlock(&rwlock1, &abstime);
+ if ((int) arg == 1)
+ {
+ assert(result == 0);
+ Sleep(2000);
+ bankAccount += 10;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+ return ((void *) bankAccount);
+ }
+ else if ((int) arg == 2)
+ {
+ assert(result == ETIMEDOUT);
+ return ((void *) 100);
+ }
+
+ return ((void *) -1);
+}
+
+void * rdfunc(void * arg)
+{
+ int ba = 0;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == ETIMEDOUT);
+
+ return ((void *) ba);
+}
+
+int
+main()
+{
+ pthread_t wrt1;
+ pthread_t wrt2;
+ pthread_t rdt;
+ int wr1Result = 0;
+ int wr2Result = 0;
+ int rdResult = 0;
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ bankAccount = 0;
+
+ assert(pthread_create(&wrt1, NULL, wrfunc, (void *) 1) == 0);
+ Sleep(100);
+ assert(pthread_create(&rdt, NULL, rdfunc, NULL) == 0);
+ Sleep(100);
+ assert(pthread_create(&wrt2, NULL, wrfunc, (void *) 2) == 0);
+
+ assert(pthread_join(wrt1, (void **) &wr1Result) == 0);
+ assert(pthread_join(rdt, (void **) &rdResult) == 0);
+ assert(pthread_join(wrt2, (void **) &wr2Result) == 0);
+
+ assert(wr1Result == 10);
+ assert(rdResult == 0);
+ assert(wr2Result == 100);
+
+ return 0;
+}
diff --git a/tests/semaphore1.c b/tests/semaphore1.c
new file mode 100644
index 0000000..c5911f9
--- /dev/null
+++ b/tests/semaphore1.c
@@ -0,0 +1,159 @@
+/*
+ * File: semaphore1.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 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.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis: Verify trywait() returns -1 and sets EAGAIN.
+ * -
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * 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"
+
+void *
+thr(void * arg)
+{
+ sem_t s;
+ int result;
+
+ assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
+
+ assert((result = sem_trywait(&s)) == -1);
+
+ if ( result == -1 )
+ {
+ perror("thread: sem_trywait 1"); // No error
+ assert(errno == EAGAIN);
+ }
+ else
+ {
+ printf("thread: ok 1\n");
+ }
+
+ assert((result = sem_post(&s)) == 0);
+
+ assert((result = sem_trywait(&s)) == 0);
+
+ if ( result == -1 )
+ {
+ perror("thread: sem_trywait 2");
+ }
+ else
+ {
+ printf("thread: ok 2\n");
+ }
+
+ assert(sem_post(&s) == 0);
+
+ return 0;
+}
+
+
+int
+main()
+{
+ pthread_t t;
+ sem_t s;
+ int result;
+
+ assert(pthread_create(&t, NULL, thr, NULL) == 0);
+ assert(pthread_join(t, (void **)&result) == 0);
+ assert(result == 0);
+
+ assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
+
+ assert((result = sem_trywait(&s)) == -1);
+
+ if ( result == -1 )
+ {
+ perror("main: sem_trywait 1"); // No error
+ assert(errno == EAGAIN);
+ }
+ else
+ {
+ printf("main: ok 1\n");
+ }
+
+ assert((result = sem_post(&s)) == 0);
+
+ assert((result = sem_trywait(&s)) == 0);
+
+ if ( result == -1 )
+ {
+ perror("main: sem_trywait 2");
+ }
+ else
+ {
+ printf("main: ok 2\n");
+ }
+
+ assert(sem_post(&s) == 0);
+
+ return 0;
+}
+