summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2011-03-24 23:33:14 +0000
committerrpj <rpj>2011-03-24 23:33:14 +0000
commitdb171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 (patch)
tree9d617a20a9e0ad1fcf415e353057c53e6d77d0f3 /tests
parente5229a33f8724a90cbb0b56c3ecc1d6691bf54d7 (diff)
First pass of robust mutexes
Diffstat (limited to 'tests')
-rw-r--r--tests/Bmakefile6
-rw-r--r--tests/ChangeLog15
-rw-r--r--tests/GNUmakefile17
-rw-r--r--tests/Makefile7
-rwxr-xr-xtests/SIZES.GC6
-rwxr-xr-xtests/SIZES.VC6
-rw-r--r--tests/Wmakefile6
-rw-r--r--tests/benchtest1.c24
-rw-r--r--tests/benchtest2.c26
-rw-r--r--tests/benchtest3.c24
-rw-r--r--tests/benchtest4.c24
-rw-r--r--tests/cancel6d.c5
-rw-r--r--tests/mutex1e.c4
-rw-r--r--tests/mutex1n.c4
-rw-r--r--tests/mutex1r.c4
-rw-r--r--tests/mutex4.c22
-rw-r--r--tests/mutex6e.c9
-rw-r--r--tests/mutex6n.c21
-rw-r--r--tests/mutex6r.c9
-rw-r--r--tests/mutex7.c2
-rw-r--r--tests/mutex7e.c10
-rw-r--r--tests/mutex7n.c13
-rw-r--r--tests/mutex7r.c9
-rw-r--r--tests/mutex8e.c8
-rw-r--r--tests/mutex8n.c8
-rw-r--r--tests/mutex8r.c8
-rw-r--r--tests/test.h26
27 files changed, 263 insertions, 60 deletions
diff --git a/tests/Bmakefile b/tests/Bmakefile
index 27228ad..263d127 100644
--- a/tests/Bmakefile
+++ b/tests/Bmakefile
@@ -92,6 +92,7 @@ PASSES= loadfree.pass \
mutex6s.pass mutex6es.pass mutex6rs.pass \
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \
mutex8.pass mutex8n.pass mutex8e.pass mutex8r.pass \
+ robust1.pass robust2.pass robust3.pass robust4.pass robust5.pass \
count1.pass \
once1.pass once2.pass once3.pass once4.pass \
self2.pass \
@@ -310,6 +311,11 @@ mutex8.pass: mutex7.pass
mutex8n.pass: mutex7n.pass
mutex8e.pass: mutex7e.pass
mutex8r.pass: mutex7r.pass
+robust1.pass: mutex8r.pass
+robust2.pass: mutex8r.pass
+robust3.pass: robust2.pass
+robust4.pass: robust3.pass
+robust5.pass: robust4.pass
once1.pass: create1.pass
once2.pass: once1.pass
once3.pass: once2.pass
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 1ca1711..8d7604f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,18 @@
+2011-03-24 Ross Johnson <ross.johnson at homemail.com.au>
+
+ * mutex*.c: Include tests for robust mutexes wherever
+ appropriate.
+ * benchtest*.c: Include comparisons for robust mutexes.
+ * robust1.c: New test for robust mutex handling.
+ * robust2.c: Likewise.
+ * robust3.c: Likewise.
+ * robust4.c: Likewise.
+ * robust5.c: Likewise.
+ * GNUmakefile: Include new tests.
+ * Makefile: Likewise.
+ * Bmakefile: Likewise (not tested).
+ * Wmakefile: Likewise (not tested).
+
2011-03-06 Ross Johnson <ross.johnson at homemail.com.au>
* several (MINGW64): Cast and call fixups for 64 bit compatibility;
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index d90fe79..98342cc 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -57,8 +57,10 @@ RANLIB = $(CROSS)ranlib
#
XXCFLAGS =
XXLIBS = -lws2_32 -lgomp
+OPT = -O3
+DOPT = -g -O0
#CFLAGS = -O3 -UNDEBUG -Wall $(XXCFLAGS)
-CFLAGS = -O3 -UNDEBUG -Wall $(XXCFLAGS)
+CFLAGS = ${OPT} -UNDEBUG -Wall $(XXCFLAGS)
BUILD_DIR = ..
INCLUDES = -I.
@@ -97,6 +99,7 @@ TESTS = \
mutex4 mutex6 mutex6n mutex6e mutex6r \
mutex6s mutex6es mutex6rs \
mutex7 mutex7n mutex7e mutex7r mutex8 mutex8n mutex8e mutex8r \
+ robust1 robust2 robust3 robust4 robust5 \
count1 \
once1 once2 once3 once4 self2 \
cancel1 cancel2 \
@@ -135,6 +138,7 @@ STATICTESTS = \
mutex4 mutex6 mutex6n mutex6e mutex6r \
mutex6s mutex6es mutex6rs \
mutex7 mutex7n mutex7e mutex7r mutex8 mutex8n mutex8e mutex8r \
+ robust1 robust2 robust3 robust4 robust5 \
count1 \
once1 once2 once3 once4 self2 \
cancel1 cancel2 \
@@ -172,6 +176,7 @@ help:
@ $(ECHO) "make clean GC-stress (to stresstest using GNU C dll with C cleanup code)"
@ $(ECHO) "make clean GCE-stress (to stresstest using GNU C dll with C++ exception handling)"
@ $(ECHO) "make clean GC-static (to test using GC static lib with C (no EH) applications)"
+ @ $(ECHO) "make clean GC-debug (to test using GC dll with C (no EH) applications)"
all:
@ $(MAKE) clean GC
@@ -197,7 +202,10 @@ GCE-bench:
$(MAKE) TEST=GCE CC=$(CXX) XXCFLAGS="-mthreads -D__CLEANUP_CXX" XXLIBS="benchlib." all-bench
GC-debug:
- $(MAKE) TEST=GC CC=$(CC) XXCFLAGS="-fopenmp -D__CLEANUP_C" DLL_VER="$(DLL_VER)d" all-pass
+ $(MAKE) TEST=GC CC=$(CC) XXCFLAGS="-fopenmp -D__CLEANUP_C" OPT="${DOPT}" DLL_VER="$(DLL_VER)d" all-pass
+
+GC-bench-debug:
+ $(MAKE) TEST=GC CC=$(CC) XXCFLAGS="-D__CLEANUP_C" XXLIBS="benchlib.o" OPT="${OPT}" DLL_VER="$(DLL_VER)d" all-bench
GC-static:
$(MAKE) TEST=GC CC=$(CC) XXCFLAGS="-D__CLEANUP_C -DPTW32_STATIC_LIB" XXLIBS="-lws2_32" DLL="" all-static
@@ -321,6 +329,11 @@ mutex8.pass: mutex7.pass
mutex8n.pass: mutex7n.pass
mutex8e.pass: mutex7e.pass
mutex8r.pass: mutex7r.pass
+robust1.pass: mutex8r.pass
+robust2.pass: mutex8r.pass
+robust3.pass: robust2.pass
+robust4.pass: robust3.pass
+robust5.pass: robust4.pass
once1.pass: create1.pass
once2.pass: once1.pass
once3.pass: once2.pass
diff --git a/tests/Makefile b/tests/Makefile
index 606f1d4..5439ee1 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -96,6 +96,7 @@ PASSES= sizes.pass loadfree.pass \
mutex6s.pass mutex6es.pass mutex6rs.pass \
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \
mutex8.pass mutex8n.pass mutex8e.pass mutex8r.pass \
+ robust1.pass robust2.pass robust3.pass robust4.pass robust5.pass \
count1.pass \
once1.pass once2.pass once3.pass once4.pass \
self2.pass \
@@ -141,6 +142,7 @@ STATICRESULTS = \
mutex6s.pass mutex6es.pass mutex6rs.pass \
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \
mutex8.pass mutex8n.pass mutex8e.pass mutex8r.pass \
+ robust1.pass robust2.pass robust3.pass robust4.pass robust5.pass \
count1.pass \
once1.pass once2.pass once3.pass once4.pass \
self2.pass \
@@ -398,6 +400,11 @@ mutex8.pass: mutex7.pass
mutex8n.pass: mutex7n.pass
mutex8e.pass: mutex7e.pass
mutex8r.pass: mutex7r.pass
+robust1.pass: mutex8r.pass
+robust2.pass: mutex8r.pass
+robust3.pass: robust2.pass
+robust4.pass: robust3.pass
+robust5.pass: robust4.pass
once1.pass: create1.pass
once2.pass: once1.pass
once3.pass: once2.pass
diff --git a/tests/SIZES.GC b/tests/SIZES.GC
index eddaad7..d5ddf36 100755
--- a/tests/SIZES.GC
+++ b/tests/SIZES.GC
@@ -1,11 +1,11 @@
Sizes of pthreads-win32 structs
-------------------------------
pthread_t 8
- ptw32_thread_t 152
+ ptw32_thread_t 160
pthread_attr_t_ 28
sem_t_ 12
- pthread_mutex_t_ 24
- pthread_mutexattr_t_ 8
+ pthread_mutex_t_ 28
+ pthread_mutexattr_t_ 12
pthread_spinlock_t_ 8
pthread_barrier_t_ 36
pthread_barrierattr_t_ 4
diff --git a/tests/SIZES.VC b/tests/SIZES.VC
index eddaad7..d5ddf36 100755
--- a/tests/SIZES.VC
+++ b/tests/SIZES.VC
@@ -1,11 +1,11 @@
Sizes of pthreads-win32 structs
-------------------------------
pthread_t 8
- ptw32_thread_t 152
+ ptw32_thread_t 160
pthread_attr_t_ 28
sem_t_ 12
- pthread_mutex_t_ 24
- pthread_mutexattr_t_ 8
+ pthread_mutex_t_ 28
+ pthread_mutexattr_t_ 12
pthread_spinlock_t_ 8
pthread_barrier_t_ 36
pthread_barrierattr_t_ 4
diff --git a/tests/Wmakefile b/tests/Wmakefile
index fb988e3..c7e97fb 100644
--- a/tests/Wmakefile
+++ b/tests/Wmakefile
@@ -94,6 +94,7 @@ PASSES = sizes.pass loadfree.pass &
mutex6s.pass mutex6es.pass mutex6rs.pass &
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass &
mutex8.pass mutex8n.pass mutex8e.pass mutex8r.pass &
+ robust1.pass robust2.pass robust3.pass robust4.pass robust5.pass &
count1.pass &
once1.pass once2.pass once3.pass once4.pass tsd1.pass &
self2.pass &
@@ -308,6 +309,11 @@ mutex8.pass: mutex7.pass
mutex8n.pass: mutex7n.pass
mutex8e.pass: mutex7e.pass
mutex8r.pass: mutex7r.pass
+robust1.pass: mutex8r.pass
+robust2.pass: mutex8r.pass
+robust3.pass: robust2.pass
+robust4.pass: robust3.pass
+robust5.pass: robust4.pass
once1.pass: create1.pass
once2.pass: once1.pass
once3.pass: once2.pass
diff --git a/tests/benchtest1.c b/tests/benchtest1.c
index ba4abc5..4184719 100644
--- a/tests/benchtest1.c
+++ b/tests/benchtest1.c
@@ -231,13 +231,29 @@ main (int argc, char *argv[])
* Now we can start the actual tests
*/
#ifdef PTW32_MUTEX_TYPES
- runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);
+ runTest("PTHREAD_MUTEX_DEFAULT", PTHREAD_MUTEX_DEFAULT);
- runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);
+ runTest("PTHREAD_MUTEX_NORMAL", PTHREAD_MUTEX_NORMAL);
- runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);
+ runTest("PTHREAD_MUTEX_ERRORCHECK", PTHREAD_MUTEX_ERRORCHECK);
- runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
+ runTest("PTHREAD_MUTEX_RECURSIVE", PTHREAD_MUTEX_RECURSIVE);
+#else
+ runTest("Non-blocking lock", 0);
+#endif
+
+ printf( ".............................................................................\n");
+
+ pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
+
+#ifdef PTW32_MUTEX_TYPES
+ runTest("PTHREAD_MUTEX_DEFAULT (Robust)", PTHREAD_MUTEX_DEFAULT);
+
+ runTest("PTHREAD_MUTEX_NORMAL (Robust)", PTHREAD_MUTEX_NORMAL);
+
+ runTest("PTHREAD_MUTEX_ERRORCHECK (Robust)", PTHREAD_MUTEX_ERRORCHECK);
+
+ runTest("PTHREAD_MUTEX_RECURSIVE (Robust)", PTHREAD_MUTEX_RECURSIVE);
#else
runTest("Non-blocking lock", 0);
#endif
diff --git a/tests/benchtest2.c b/tests/benchtest2.c
index 76df9a2..28e1cfe 100644
--- a/tests/benchtest2.c
+++ b/tests/benchtest2.c
@@ -294,15 +294,31 @@ main (int argc, char *argv[])
* Now we can start the actual tests
*/
#ifdef PTW32_MUTEX_TYPES
- runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);
+ runTest("PTHREAD_MUTEX_DEFAULT", PTHREAD_MUTEX_DEFAULT);
- runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);
+ runTest("PTHREAD_MUTEX_NORMAL", PTHREAD_MUTEX_NORMAL);
- runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);
+ runTest("PTHREAD_MUTEX_ERRORCHECK", PTHREAD_MUTEX_ERRORCHECK);
- runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
+ runTest("PTHREAD_MUTEX_RECURSIVE", PTHREAD_MUTEX_RECURSIVE);
#else
- runTest("Blocking locks", 0);
+ runTest("Non-blocking lock", 0);
+#endif
+
+ printf( ".............................................................................\n");
+
+ pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
+
+#ifdef PTW32_MUTEX_TYPES
+ runTest("PTHREAD_MUTEX_DEFAULT (Robust)", PTHREAD_MUTEX_DEFAULT);
+
+ runTest("PTHREAD_MUTEX_NORMAL (Robust)", PTHREAD_MUTEX_NORMAL);
+
+ runTest("PTHREAD_MUTEX_ERRORCHECK (Robust)", PTHREAD_MUTEX_ERRORCHECK);
+
+ runTest("PTHREAD_MUTEX_RECURSIVE (Robust)", PTHREAD_MUTEX_RECURSIVE);
+#else
+ runTest("Non-blocking lock", 0);
#endif
printf( "=============================================================================\n");
diff --git a/tests/benchtest3.c b/tests/benchtest3.c
index faf0fdb..1b6e823 100644
--- a/tests/benchtest3.c
+++ b/tests/benchtest3.c
@@ -183,13 +183,29 @@ main (int argc, char *argv[])
* Now we can start the actual tests
*/
#ifdef PTW32_MUTEX_TYPES
- runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);
+ runTest("PTHREAD_MUTEX_DEFAULT", PTHREAD_MUTEX_DEFAULT);
- runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);
+ runTest("PTHREAD_MUTEX_NORMAL", PTHREAD_MUTEX_NORMAL);
- runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);
+ runTest("PTHREAD_MUTEX_ERRORCHECK", PTHREAD_MUTEX_ERRORCHECK);
- runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
+ runTest("PTHREAD_MUTEX_RECURSIVE", PTHREAD_MUTEX_RECURSIVE);
+#else
+ runTest("Non-blocking lock", 0);
+#endif
+
+ printf( ".............................................................................\n");
+
+ pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
+
+#ifdef PTW32_MUTEX_TYPES
+ runTest("PTHREAD_MUTEX_DEFAULT (Robust)", PTHREAD_MUTEX_DEFAULT);
+
+ runTest("PTHREAD_MUTEX_NORMAL (Robust)", PTHREAD_MUTEX_NORMAL);
+
+ runTest("PTHREAD_MUTEX_ERRORCHECK (Robust)", PTHREAD_MUTEX_ERRORCHECK);
+
+ runTest("PTHREAD_MUTEX_RECURSIVE (Robust)", PTHREAD_MUTEX_RECURSIVE);
#else
runTest("Non-blocking lock", 0);
#endif
diff --git a/tests/benchtest4.c b/tests/benchtest4.c
index 53c529b..d64cd4a 100644
--- a/tests/benchtest4.c
+++ b/tests/benchtest4.c
@@ -164,13 +164,29 @@ main (int argc, char *argv[])
* Now we can start the actual tests
*/
#ifdef PTW32_MUTEX_TYPES
- runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);
+ runTest("PTHREAD_MUTEX_DEFAULT", PTHREAD_MUTEX_DEFAULT);
- runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);
+ runTest("PTHREAD_MUTEX_NORMAL", PTHREAD_MUTEX_NORMAL);
- runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);
+ runTest("PTHREAD_MUTEX_ERRORCHECK", PTHREAD_MUTEX_ERRORCHECK);
- runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
+ runTest("PTHREAD_MUTEX_RECURSIVE", PTHREAD_MUTEX_RECURSIVE);
+#else
+ runTest("Non-blocking lock", 0);
+#endif
+
+ printf( ".............................................................................\n");
+
+ pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);
+
+#ifdef PTW32_MUTEX_TYPES
+ runTest("PTHREAD_MUTEX_DEFAULT (Robust)", PTHREAD_MUTEX_DEFAULT);
+
+ runTest("PTHREAD_MUTEX_NORMAL (Robust)", PTHREAD_MUTEX_NORMAL);
+
+ runTest("PTHREAD_MUTEX_ERRORCHECK (Robust)", PTHREAD_MUTEX_ERRORCHECK);
+
+ runTest("PTHREAD_MUTEX_RECURSIVE (Robust)", PTHREAD_MUTEX_RECURSIVE);
#else
runTest("Non-blocking lock", 0);
#endif
diff --git a/tests/cancel6d.c b/tests/cancel6d.c
index 3fd296a..37f9ca5 100644
--- a/tests/cancel6d.c
+++ b/tests/cancel6d.c
@@ -136,7 +136,10 @@ main()
for (i = 1; i <= NUMTHREADS; i++)
{
assert(pthread_cancel(t[i]) == 0);
- assert(pthread_cancel(t[i]) == 0);
+ if (pthread_cancel(t[i]) != 0)
+ {
+ printf("Second cancelation failed but this is expected sometimes.\n");
+ }
}
/*
diff --git a/tests/mutex1e.c b/tests/mutex1e.c
index e528107..d32adb3 100644
--- a/tests/mutex1e.c
+++ b/tests/mutex1e.c
@@ -54,6 +54,8 @@ main()
{
assert(pthread_mutexattr_init(&mxAttr) == 0);
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0);
assert(mutex == NULL);
@@ -70,5 +72,7 @@ main()
assert(mutex == NULL);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/mutex1n.c b/tests/mutex1n.c
index 74850d6..fcfc134 100644
--- a/tests/mutex1n.c
+++ b/tests/mutex1n.c
@@ -54,6 +54,8 @@ main()
{
assert(pthread_mutexattr_init(&mxAttr) == 0);
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0);
assert(mutex == NULL);
@@ -70,5 +72,7 @@ main()
assert(mutex == NULL);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/mutex1r.c b/tests/mutex1r.c
index 0666dec..15083f2 100644
--- a/tests/mutex1r.c
+++ b/tests/mutex1r.c
@@ -54,6 +54,8 @@ main()
{
assert(pthread_mutexattr_init(&mxAttr) == 0);
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0);
assert(mutex == NULL);
@@ -70,5 +72,7 @@ main()
assert(mutex == NULL);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/mutex4.c b/tests/mutex4.c
index b728722..6d36e0a 100644
--- a/tests/mutex4.c
+++ b/tests/mutex4.c
@@ -65,35 +65,31 @@ main()
assert(pthread_mutexattr_init(&ma) == 0);
+ BEGIN_MUTEX_STALLED_ROBUST(ma)
+
wasHere = 0;
assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_DEFAULT) == 0);
assert(pthread_mutex_init(&mutex1, &ma) == 0);
assert(pthread_mutex_lock(&mutex1) == 0);
- /*
- * NORMAL (fast) mutexes don't check ownership.
- */
- assert(pthread_create(&t, NULL, unlocker, (void *)(size_t)0) == 0);
+ assert(pthread_create(&t, NULL, unlocker, (void *)(size_t)(IS_ROBUST?EPERM:0)) == 0);
assert(pthread_join(t, NULL) == 0);
- assert(pthread_mutex_unlock(&mutex1) == EPERM);
+ assert(pthread_mutex_unlock(&mutex1) == 0);
assert(wasHere == 2);
wasHere = 0;
assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_NORMAL) == 0);
assert(pthread_mutex_init(&mutex1, &ma) == 0);
assert(pthread_mutex_lock(&mutex1) == 0);
- /*
- * NORMAL (fast) mutexes don't check ownership.
- */
- assert(pthread_create(&t, NULL, unlocker, (void *) 0) == 0);
+ assert(pthread_create(&t, NULL, unlocker, (void *)(size_t)(IS_ROBUST?EPERM:0)) == 0);
assert(pthread_join(t, NULL) == 0);
- assert(pthread_mutex_unlock(&mutex1) == EPERM);
+ assert(pthread_mutex_unlock(&mutex1) == 0);
assert(wasHere == 2);
wasHere = 0;
assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK) == 0);
assert(pthread_mutex_init(&mutex1, &ma) == 0);
assert(pthread_mutex_lock(&mutex1) == 0);
- assert(pthread_create(&t, NULL, unlocker, (void *) EPERM) == 0);
+ assert(pthread_create(&t, NULL, unlocker, (void *)(size_t) EPERM) == 0);
assert(pthread_join(t, NULL) == 0);
assert(pthread_mutex_unlock(&mutex1) == 0);
assert(wasHere == 2);
@@ -102,10 +98,12 @@ main()
assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE) == 0);
assert(pthread_mutex_init(&mutex1, &ma) == 0);
assert(pthread_mutex_lock(&mutex1) == 0);
- assert(pthread_create(&t, NULL, unlocker, (void *) EPERM) == 0);
+ assert(pthread_create(&t, NULL, unlocker, (void *)(size_t) EPERM) == 0);
assert(pthread_join(t, NULL) == 0);
assert(pthread_mutex_unlock(&mutex1) == 0);
assert(wasHere == 2);
+ END_MUTEX_STALLED_ROBUST(ma)
+
return 0;
}
diff --git a/tests/mutex6e.c b/tests/mutex6e.c
index 3f28ee7..908a51b 100644
--- a/tests/mutex6e.c
+++ b/tests/mutex6e.c
@@ -53,7 +53,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -78,6 +78,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_ERRORCHECK);
@@ -92,6 +96,9 @@ main()
assert(lockCount == 2);
assert(pthread_mutex_destroy(&mutex) == 0);
+
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_destroy(&mxAttr) == 0);
exit(0);
diff --git a/tests/mutex6n.c b/tests/mutex6n.c
index 9b4bbb9..9cb309c 100644
--- a/tests/mutex6n.c
+++ b/tests/mutex6n.c
@@ -49,7 +49,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -61,6 +61,7 @@ void * locker(void * arg)
/* Should wait here (deadlocked) */
assert(pthread_mutex_lock(&mutex) == 0);
+
lockCount++;
assert(pthread_mutex_unlock(&mutex) == 0);
@@ -74,6 +75,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_NORMAL);
@@ -82,19 +87,17 @@ main()
assert(pthread_create(&t, NULL, locker, NULL) == 0);
- Sleep(1000);
+ Sleep(100);
assert(lockCount == 1);
- /*
- * Should succeed even though we don't own the lock
- * because FAST mutexes don't check ownership.
- */
- assert(pthread_mutex_unlock(&mutex) == 0);
+ assert(pthread_mutex_unlock(&mutex) == IS_ROBUST?EPERM:0);
+
+ Sleep (100);
- Sleep (1000);
+ assert(lockCount == IS_ROBUST?1:2);
- assert(lockCount == 2);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
exit(0);
diff --git a/tests/mutex6r.c b/tests/mutex6r.c
index 552f394..9d81ad8 100644
--- a/tests/mutex6r.c
+++ b/tests/mutex6r.c
@@ -52,7 +52,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -77,6 +77,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_RECURSIVE);
@@ -91,6 +95,9 @@ main()
assert(lockCount == 2);
assert(pthread_mutex_destroy(&mutex) == 0);
+
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_destroy(&mxAttr) == 0);
exit(0);
diff --git a/tests/mutex7.c b/tests/mutex7.c
index 8772b97..4137c35 100644
--- a/tests/mutex7.c
+++ b/tests/mutex7.c
@@ -57,7 +57,7 @@ void * locker(void * arg)
assert(pthread_mutex_trylock(&mutex) == EBUSY);
lockCount++;
assert(pthread_mutex_unlock(&mutex) == 0);
- assert(pthread_mutex_unlock(&mutex) == EPERM);
+ assert(pthread_mutex_unlock(&mutex) == 0);
return 0;
}
diff --git a/tests/mutex7e.c b/tests/mutex7e.c
index 82d941f..80981b3 100644
--- a/tests/mutex7e.c
+++ b/tests/mutex7e.c
@@ -53,7 +53,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -65,7 +65,6 @@ void * locker(void * arg)
assert(pthread_mutex_trylock(&mutex) == EBUSY);
lockCount++;
assert(pthread_mutex_unlock(&mutex) == 0);
- assert(pthread_mutex_unlock(&mutex) == EPERM);
return (void *) 555;
}
@@ -78,6 +77,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_ERRORCHECK);
@@ -92,6 +95,9 @@ main()
assert(lockCount == 2);
assert(pthread_mutex_destroy(&mutex) == 0);
+
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_destroy(&mxAttr) == 0);
exit(0);
diff --git a/tests/mutex7n.c b/tests/mutex7n.c
index 174355f..87ba10a 100644
--- a/tests/mutex7n.c
+++ b/tests/mutex7n.c
@@ -49,7 +49,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -61,7 +61,6 @@ void * locker(void * arg)
assert(pthread_mutex_trylock(&mutex) == EBUSY);
lockCount++;
assert(pthread_mutex_unlock(&mutex) == 0);
- assert(pthread_mutex_unlock(&mutex) == EPERM);
return (void *) 555;
}
@@ -73,6 +72,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_NORMAL);
@@ -81,10 +84,14 @@ main()
assert(pthread_create(&t, NULL, locker, NULL) == 0);
- Sleep(1000);
+ Sleep(100);
assert(lockCount == 2);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
+ assert(pthread_mutexattr_destroy(&mxAttr) == 0);
+
exit(0);
/* Never reached */
diff --git a/tests/mutex7r.c b/tests/mutex7r.c
index 2c1699b..4e4ae8a 100644
--- a/tests/mutex7r.c
+++ b/tests/mutex7r.c
@@ -52,7 +52,7 @@
#include "test.h"
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -77,6 +77,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_RECURSIVE);
@@ -91,6 +95,9 @@ main()
assert(lockCount == 2);
assert(pthread_mutex_destroy(&mutex) == 0);
+
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
assert(pthread_mutexattr_destroy(&mxAttr) == 0);
exit(0);
diff --git a/tests/mutex8e.c b/tests/mutex8e.c
index 0e1cbd7..58d7d1e 100644
--- a/tests/mutex8e.c
+++ b/tests/mutex8e.c
@@ -44,7 +44,7 @@
#include "test.h"
#include <sys/timeb.h>
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -80,6 +80,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_ERRORCHECK);
@@ -96,6 +100,8 @@ main()
assert(pthread_mutex_unlock(&mutex) == 0);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/mutex8n.c b/tests/mutex8n.c
index c7141e3..deb9215 100644
--- a/tests/mutex8n.c
+++ b/tests/mutex8n.c
@@ -44,7 +44,7 @@
#include "test.h"
#include <sys/timeb.h>
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -80,6 +80,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_NORMAL);
@@ -96,6 +100,8 @@ main()
assert(pthread_mutex_unlock(&mutex) == 0);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/mutex8r.c b/tests/mutex8r.c
index 58242fe..fe686c5 100644
--- a/tests/mutex8r.c
+++ b/tests/mutex8r.c
@@ -44,7 +44,7 @@
#include "test.h"
#include <sys/timeb.h>
-static int lockCount = 0;
+static int lockCount;
static pthread_mutex_t mutex;
static pthread_mutexattr_t mxAttr;
@@ -80,6 +80,10 @@ main()
int mxType = -1;
assert(pthread_mutexattr_init(&mxAttr) == 0);
+
+ BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
+
+ lockCount = 0;
assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
assert(mxType == PTHREAD_MUTEX_RECURSIVE);
@@ -96,6 +100,8 @@ main()
assert(pthread_mutex_unlock(&mutex) == 0);
+ END_MUTEX_STALLED_ROBUST(mxAttr)
+
return 0;
}
diff --git a/tests/test.h b/tests/test.h
index a6c2b60..639ee55 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -113,7 +113,9 @@ const char * error_string[] = {
"ENOLCK",
"ENOSYS",
"ENOTEMPTY",
- "EILSEQ"
+ "EILSEQ",
+ "EOWNERDEAD",
+ "ENOTRECOVERABLE"
};
/*
@@ -152,3 +154,25 @@ int assertE;
#e,#o,#r, __FILE__, (int) __LINE__, error_string[assertE]), exit(1), 0))
#endif
+
+# define BEGIN_MUTEX_STALLED_ROBUST(mxAttr) \
+ for(;;) \
+ { \
+ static int _i=0; \
+ static int _robust; \
+ pthread_mutexattr_getrobust(&(mxAttr), &_robust);
+
+# define END_MUTEX_STALLED_ROBUST(mxAttr) \
+ printf("Pass %s\n", _robust==PTHREAD_MUTEX_ROBUST?"Robust":"Non-robust"); \
+ if (++_i > 1) \
+ break; \
+ else \
+ { \
+ pthread_mutexattr_t *pma, *pmaEnd; \
+ for(pma = &(mxAttr), pmaEnd = pma + sizeof(mxAttr)/sizeof(pthread_mutexattr_t); \
+ pma < pmaEnd; \
+ pthread_mutexattr_setrobust(pma++, PTHREAD_MUTEX_ROBUST)); \
+ } \
+ }
+
+# define IS_ROBUST (_robust==PTHREAD_MUTEX_ROBUST)