pthread_rwlock regression test
authorSzabolcs Nagy <nsz@port70.net>
Thu, 8 Aug 2013 19:21:22 +0000 (19:21 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Thu, 8 Aug 2013 19:21:22 +0000 (19:21 +0000)
src/regression/pthread_create-oom.c
src/regression/pthread_rwlock-ebusy.c [new file with mode: 0644]

index 56993ec..e8d8169 100644 (file)
@@ -1,7 +1,6 @@
 // commit: 59666802fba592a59f2f4ea4dcb053287fd55826 2011-02-15
 // pthread_create should return EAGAIN on failure
 #include <pthread.h>
-#include <stdio.h>
 #include <errno.h>
 #include <string.h>
 #include "test.h"
diff --git a/src/regression/pthread_rwlock-ebusy.c b/src/regression/pthread_rwlock-ebusy.c
new file mode 100644 (file)
index 0000000..c2bc2d7
--- /dev/null
@@ -0,0 +1,44 @@
+// commit: e5dd18319bbd47c89aac5e1571771958a43e067d 2011-03-08
+// pthread_rwlock_try* should fail with EBUSY
+#include <pthread.h>
+#include <errno.h>
+#include <string.h>
+#include "test.h"
+
+#define T(f) if ((r=(f))) t_error(#f " failed: %s\n", strerror(r))
+
+static void *tryrdlock(void *arg)
+{
+       int r = pthread_rwlock_tryrdlock(arg);
+       if (r != EBUSY)
+               t_error("tryrdlock for wrlocked lock returned %s, want EBUSY\n", strerror(errno));
+       return 0;
+}
+
+static void *trywrlock(void *arg)
+{
+       int r = pthread_rwlock_trywrlock(arg);
+       if (r != EBUSY)
+               t_error("trywrlock for rdlocked lock returned %s, want EBUSY\n", strerror(errno));
+       return 0;
+}
+
+int main(void)
+{
+       pthread_t t;
+       pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
+       void *p;
+       int r;
+
+       T(pthread_rwlock_rdlock(&rw));
+       T(pthread_create(&t, 0, trywrlock, &rw));
+       T(pthread_join(t, &p));
+       T(pthread_rwlock_unlock(&rw));
+
+       T(pthread_rwlock_wrlock(&rw));
+       T(pthread_create(&t, 0, tryrdlock, &rw));
+       T(pthread_join(t, &p));
+       T(pthread_rwlock_unlock(&rw));
+
+       return t_status;
+}