summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorPaul Irofti <pirofti@cvs.openbsd.org>2012-04-11 18:39:25 +0000
committerPaul Irofti <pirofti@cvs.openbsd.org>2012-04-11 18:39:25 +0000
commit5d8da5a88f6271f2da7baad706bae1e97506a70f (patch)
tree2e6af6d46ca4fa8dfe53eab4a9b01df098ccc40d /regress
parent712a46496ebd4d39f2018a6b7f657ffbee2810bd (diff)
Add a simple barrier regression test.
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libpthread/Makefile6
-rw-r--r--regress/lib/libpthread/barrier/Makefile5
-rw-r--r--regress/lib/libpthread/barrier/barrier.c47
3 files changed, 55 insertions, 3 deletions
diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile
index f2ad8771233..8c85aebd9e2 100644
--- a/regress/lib/libpthread/Makefile
+++ b/regress/lib/libpthread/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.36 2012/03/19 17:42:40 oga Exp $
+# $OpenBSD: Makefile,v 1.37 2012/04/11 18:39:24 pirofti Exp $
# disabled because it requires a buggy behavior that uthread had:
# dup2_race
-SUBDIR= blocked_close blocked_dup2 blocked_fifo blocked_shutdown cancel \
- cancel2 close close_race closefrom cwd errno execve fork \
+SUBDIR= barrier blocked_close blocked_dup2 blocked_fifo blocked_shutdown \
+ cancel cancel2 close close_race closefrom cwd errno execve fork \
group malloc_duel netdb pcap poll preemption preemption_float \
pthread_atfork pthread_cond_timedwait pthread_create \
pthread_join pthread_kill pthread_mutex \
diff --git a/regress/lib/libpthread/barrier/Makefile b/regress/lib/libpthread/barrier/Makefile
new file mode 100644
index 00000000000..4f1b8b9fe89
--- /dev/null
+++ b/regress/lib/libpthread/barrier/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2012/04/11 18:39:24 pirofti Exp $
+
+PROG= barrier
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/barrier/barrier.c b/regress/lib/libpthread/barrier/barrier.c
new file mode 100644
index 00000000000..c401ad997fc
--- /dev/null
+++ b/regress/lib/libpthread/barrier/barrier.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: barrier.c,v 1.1 2012/04/11 18:39:24 pirofti Exp $ */
+/* Paul Irofti <pirofti@openbsd.org>, 2012. Public Domain. */
+
+#include <stdio.h>
+
+#include <pthread.h>
+#include <errno.h>
+
+#include "test.h"
+
+void *
+foo(void *arg)
+{
+ int rc = 0;
+ pthread_barrier_t b = (pthread_barrier_t)arg;
+ rc = pthread_barrier_wait(&b);
+ if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD)
+ PANIC("pthread_barrier_wait returned %d", rc);
+ return NULL;
+}
+
+int main()
+{
+ int i;
+ pthread_t thr[10];
+ pthread_barrier_t b;
+
+ pthread_barrierattr_t attr;
+ CHECKr(pthread_barrierattr_init(&attr));
+ CHECKr(pthread_barrierattr_getpshared(&attr, &i));
+ _CHECK(i, == PTHREAD_PROCESS_PRIVATE, strerror(_x));
+ CHECKr(pthread_barrierattr_setpshared(&attr, i));
+ _CHECK(pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED), == ENOTSUP, strerror(_x));
+
+ CHECKr(pthread_barrier_init(&b, &attr, 10));
+ for (i = 0; i < 10; i++) {
+ printf("Thread %d started\n", i);
+ CHECKr(pthread_create(&thr[i], NULL, foo, (void *)b));
+ }
+ for (i = 0; i < 10; i++) {
+ CHECKr(pthread_join(thr[i], NULL));
+ }
+ CHECKr(pthread_barrierattr_destroy(&attr));
+ CHECKr(pthread_barrier_destroy(&b));
+
+ SUCCEED;
+}