OSDN Git Service

* winsup.api/pthread/mutex8e.c: New testcase.
authortpfaff <tpfaff>
Thu, 4 Mar 2004 21:08:22 +0000 (21:08 +0000)
committertpfaff <tpfaff>
Thu, 4 Mar 2004 21:08:22 +0000 (21:08 +0000)
* winsup.api/pthread/mutex8n.c: Ditto.
* winsup.api/pthread/mutex8r.c: Ditto.

winsup/testsuite/ChangeLog
winsup/testsuite/winsup.api/pthread/mutex8e.c [new file with mode: 0644]
winsup/testsuite/winsup.api/pthread/mutex8n.c [new file with mode: 0644]
winsup/testsuite/winsup.api/pthread/mutex8r.c [new file with mode: 0644]

index ec19bca..033be10 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-04  Thomas Pfaff  <tpfaff@gmx.net>
+
+       * winsup.api/pthread/mutex8e.c: New testcase.
+       * winsup.api/pthread/mutex8n.c: Ditto.
+       * winsup.api/pthread/mutex8r.c: Ditto.
+
 2003-12-23  Christopher Faylor  <cgf@redhat.com>
 
        * winsup.api/pthread/rwlock7.c (main): Don't assume that result of rand
diff --git a/winsup/testsuite/winsup.api/pthread/mutex8e.c b/winsup/testsuite/winsup.api/pthread/mutex8e.c
new file mode 100644 (file)
index 0000000..7108b02
--- /dev/null
@@ -0,0 +1,35 @@
+/* 
+ * mutex8e.c
+ *
+ * Tests PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP.
+ *
+ * Depends on API functions: 
+ *     pthread_mutex_lock()
+ *     pthread_mutex_unlock()
+ */
+
+#include "test.h"
+pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+
+int
+main()
+{
+  assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP);
+
+  assert(pthread_mutex_lock(&mutex) == 0);
+
+  assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP);
+
+  assert(mutex != NULL);
+
+  assert(pthread_mutex_lock(&mutex) == EDEADLK);
+
+  assert(pthread_mutex_unlock(&mutex) == 0);
+
+  assert(pthread_mutex_destroy(&mutex) == 0);
+
+  assert(mutex == NULL);
+
+  return 0;
+}
diff --git a/winsup/testsuite/winsup.api/pthread/mutex8n.c b/winsup/testsuite/winsup.api/pthread/mutex8n.c
new file mode 100644 (file)
index 0000000..46fc9c6
--- /dev/null
@@ -0,0 +1,60 @@
+/* 
+ * mutex8n.c
+ *
+ * Tests PTHREAD_NORMAL_MUTEX_INITIALIZER_NP.
+ * Thread locks mutex twice (recursive lock).
+ * The thread should deadlock.
+ *
+ * Depends on API functions: 
+ *      pthread_create()
+ *      pthread_mutex_init()
+ *     pthread_mutex_lock()
+ *     pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+static int lockCount = 0;
+
+pthread_mutex_t mutex = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP;
+
+void * locker(void * arg)
+{
+  assert(pthread_mutex_lock(&mutex) == 0);
+  lockCount++;
+
+  /* Should wait here (deadlocked) */
+  assert(pthread_mutex_lock(&mutex) == 0);
+  lockCount++;
+  assert(pthread_mutex_unlock(&mutex) == 0);
+
+  return (void *) 555;
+}
+int
+main()
+{
+  pthread_t t;
+
+  assert(pthread_create(&t, NULL, locker, NULL) == 0);
+
+  Sleep(1000);
+
+  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);
+
+  Sleep (1000);
+
+  assert(lockCount == 2);
+
+  exit(0);
+
+  /* Never reached */
+  return 0;
+}
+
diff --git a/winsup/testsuite/winsup.api/pthread/mutex8r.c b/winsup/testsuite/winsup.api/pthread/mutex8r.c
new file mode 100644 (file)
index 0000000..ecaccd3
--- /dev/null
@@ -0,0 +1,37 @@
+/* 
+ * mutex8r.c
+ *
+ * Tests PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP.
+ *
+ * Depends on API functions: 
+ *     pthread_mutex_lock()
+ *     pthread_mutex_unlock()
+ */
+
+#include "test.h"
+pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+
+int
+main()
+{
+  assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
+  assert(pthread_mutex_lock(&mutex) == 0);
+
+  assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
+  assert(mutex != NULL);
+
+  assert(pthread_mutex_lock(&mutex) == 0);
+
+  assert(pthread_mutex_unlock(&mutex) == 0);
+
+  assert(pthread_mutex_unlock(&mutex) == 0);
+
+  assert(pthread_mutex_destroy(&mutex) == 0);
+
+  assert(mutex == NULL);
+
+  return 0;
+}