summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2011-09-13 23:50:18 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2011-09-13 23:50:18 +0000
commitf8da53c4f0c9e52da3aa0b728ffb70fe3e083210 (patch)
tree5fa5f068c64228c5ca3277e81cf17bf4e1737ac2
parent988fec4cab4ce922c4ff856dc7a2b9f500de9f65 (diff)
first round of tests to check system calls restarting with pthreads.
guenther@ ok
-rw-r--r--regress/lib/libpthread/Makefile16
-rw-r--r--regress/lib/libpthread/restart/Makefile5
-rw-r--r--regress/lib/libpthread/restart/Makefile.inc3
-rw-r--r--regress/lib/libpthread/restart/accept/Makefile6
-rw-r--r--regress/lib/libpthread/restart/accept/accept.c67
-rw-r--r--regress/lib/libpthread/restart/kevent/Makefile6
-rw-r--r--regress/lib/libpthread/restart/kevent/kevent.c56
-rw-r--r--regress/lib/libpthread/restart/read/Makefile6
-rw-r--r--regress/lib/libpthread/restart/read/read.c59
-rw-r--r--regress/lib/libpthread/restart/readv/Makefile6
-rw-r--r--regress/lib/libpthread/restart/readv/readv.c63
-rw-r--r--regress/lib/libpthread/restart/recvfrom/Makefile6
-rw-r--r--regress/lib/libpthread/restart/recvfrom/recvfrom.c67
-rw-r--r--regress/lib/libpthread/restart/recvmsg/Makefile6
-rw-r--r--regress/lib/libpthread/restart/recvmsg/recvmsg.c73
-rw-r--r--regress/lib/libpthread/siginterrupt/Makefile5
-rw-r--r--regress/lib/libpthread/siginterrupt/siginterrupt.c58
17 files changed, 500 insertions, 8 deletions
diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile
index 8c92bd39547..8703e98ab30 100644
--- a/regress/lib/libpthread/Makefile
+++ b/regress/lib/libpthread/Makefile
@@ -1,13 +1,13 @@
-# $OpenBSD: Makefile,v 1.27 2010/01/03 23:02:33 fgsch Exp $
+# $OpenBSD: Makefile,v 1.28 2011/09/13 23:50:17 fgsch Exp $
-SUBDIR= blocked_close blocked_dup2 blocked_shutdown cancel cancel2 close \
- closefrom close_race cwd dup2_race execve fork group \
- malloc_duel netdb pcap poll \
- preemption preemption_float \
+SUBDIR= blocked_close blocked_dup2 blocked_shutdown cancel cancel2 \
+ close close_race closefrom cwd dup2_race execve fork \
+ group malloc_duel netdb pcap poll preemption preemption_float \
pthread_atfork pthread_cond_timedwait pthread_create \
- pthread_join pthread_kill pthread_mutex pthread_specific readdir \
- select setjmp setsockopt signal sigdeliver siginfo signodefer \
- sigsuspend sigwait sleep socket stdarg stdio switch system
+ pthread_join pthread_kill pthread_mutex pthread_specific \
+ readdir restart select setjmp setsockopt sigdeliver siginfo \
+ siginterrupt signal signodefer sigsuspend sigwait sleep socket \
+ stdarg stdio switch system
# Not available or disabled: fcntl, getaddrinfo, pause, pw, sigmask, stdfiles
diff --git a/regress/lib/libpthread/restart/Makefile b/regress/lib/libpthread/restart/Makefile
new file mode 100644
index 00000000000..897199ed8a9
--- /dev/null
+++ b/regress/lib/libpthread/restart/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+SUBDIR = accept kevent read readv recvfrom recvmsg
+
+.include <bsd.subdir.mk>
diff --git a/regress/lib/libpthread/restart/Makefile.inc b/regress/lib/libpthread/restart/Makefile.inc
new file mode 100644
index 00000000000..5edc38f4269
--- /dev/null
+++ b/regress/lib/libpthread/restart/Makefile.inc
@@ -0,0 +1,3 @@
+# $OpenBSD: Makefile.inc,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+.include "${.CURDIR}/../../Makefile.inc"
diff --git a/regress/lib/libpthread/restart/accept/Makefile b/regress/lib/libpthread/restart/accept/Makefile
new file mode 100644
index 00000000000..bc92a099ff1
--- /dev/null
+++ b/regress/lib/libpthread/restart/accept/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = accept
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/accept/accept.c b/regress/lib/libpthread/restart/accept/accept.c
new file mode 100644
index 00000000000..635b2e2bd42
--- /dev/null
+++ b/regress/lib/libpthread/restart/accept/accept.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: accept.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_accept(void *arg)
+{
+ struct sockaddr_in sa;
+ socklen_t salen;
+ int s;
+
+ CHECKe(s = socket(AF_INET, SOCK_STREAM, 0));
+ bzero(&sa, sizeof(sa));
+ sa.sin_port = htons(6543);
+ CHECKe(bind(s, (const void*)&sa, sizeof(sa)));
+ CHECKe(listen(s, 10));
+ salen = sizeof(sa);
+ ASSERT(accept(s, (struct sockaddr *)&sa, &salen) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_accept, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/restart/kevent/Makefile b/regress/lib/libpthread/restart/kevent/Makefile
new file mode 100644
index 00000000000..d91fb4acc42
--- /dev/null
+++ b/regress/lib/libpthread/restart/kevent/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = kevent
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/kevent/kevent.c b/regress/lib/libpthread/restart/kevent/kevent.c
new file mode 100644
index 00000000000..f4ad10e8275
--- /dev/null
+++ b/regress/lib/libpthread/restart/kevent/kevent.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: kevent.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_kevent(void *arg)
+{
+ struct kevent ev;
+ struct timespec ts = { 10, 0 };
+ int kq;
+
+ CHECKe(kq = kqueue());
+ ASSERT(kevent(kq, NULL, 0, &ev, 1, &ts) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_kevent, NULL));
+ sleep(2);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 1);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/restart/read/Makefile b/regress/lib/libpthread/restart/read/Makefile
new file mode 100644
index 00000000000..70b244c9672
--- /dev/null
+++ b/regress/lib/libpthread/restart/read/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = read
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/read/read.c b/regress/lib/libpthread/restart/read/read.c
new file mode 100644
index 00000000000..581e65c9b71
--- /dev/null
+++ b/regress/lib/libpthread/restart/read/read.c
@@ -0,0 +1,59 @@
+/* $OpenBSD: read.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_read(void *arg)
+{
+ int fds[2];
+ char buf;
+
+ CHECKe(pipe(fds));
+ ASSERT(read(fds[0], &buf, 1) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_read, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/restart/readv/Makefile b/regress/lib/libpthread/restart/readv/Makefile
new file mode 100644
index 00000000000..120603677bb
--- /dev/null
+++ b/regress/lib/libpthread/restart/readv/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = readv
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/readv/readv.c b/regress/lib/libpthread/restart/readv/readv.c
new file mode 100644
index 00000000000..e53eaa9ec1a
--- /dev/null
+++ b/regress/lib/libpthread/restart/readv/readv.c
@@ -0,0 +1,63 @@
+/* $OpenBSD: readv.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_readv(void *arg)
+{
+ struct iovec iov;
+ int fds[2];
+ char buf;
+
+ CHECKe(pipe(fds));
+ iov.iov_base = &buf;
+ iov.iov_len = 1;
+ ASSERT(readv(fds[0], &iov, 1) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_readv, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/restart/recvfrom/Makefile b/regress/lib/libpthread/restart/recvfrom/Makefile
new file mode 100644
index 00000000000..8134d80c926
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvfrom/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = recvfrom
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/recvfrom/recvfrom.c b/regress/lib/libpthread/restart/recvfrom/recvfrom.c
new file mode 100644
index 00000000000..7b4f185a27a
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvfrom/recvfrom.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: recvfrom.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_recvfrom(void *arg)
+{
+ struct sockaddr_in sa;
+ socklen_t salen;
+ char buf;
+ int s;
+
+ CHECKe(s = socket(AF_INET, SOCK_DGRAM, 0));
+ bzero(&sa, sizeof(sa));
+ sa.sin_port = htons(6543);
+ CHECKe(bind(s, (const void*)&sa, sizeof(sa)));
+ salen = sizeof(sa);
+ ASSERT(recvfrom(s, &buf, 1, 0,(struct sockaddr *)&sa, &salen) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_recvfrom, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/restart/recvmsg/Makefile b/regress/lib/libpthread/restart/recvmsg/Makefile
new file mode 100644
index 00000000000..c8f8335b8bb
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvmsg/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = recvmsg
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/recvmsg/recvmsg.c b/regress/lib/libpthread/restart/recvmsg/recvmsg.c
new file mode 100644
index 00000000000..e1fd7b64d65
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvmsg/recvmsg.c
@@ -0,0 +1,73 @@
+/* $OpenBSD: recvmsg.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_recvmsg(void *arg)
+{
+ struct sockaddr_in sa;
+ struct msghdr msg;
+ struct iovec iov;
+ char buf;
+ int s;
+
+ CHECKe(s = socket(AF_INET, SOCK_DGRAM, 0));
+ bzero(&sa, sizeof(sa));
+ sa.sin_port = htons(6543);
+ CHECKe(bind(s, (const void*)&sa, sizeof(sa)));
+ bzero(&msg, sizeof(msg));
+ iov.iov_base = &buf;
+ iov.iov_len = 1;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ ASSERT(recvmsg(s, &msg, 0) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_recvmsg, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}
diff --git a/regress/lib/libpthread/siginterrupt/Makefile b/regress/lib/libpthread/siginterrupt/Makefile
new file mode 100644
index 00000000000..e8f4f5422ec
--- /dev/null
+++ b/regress/lib/libpthread/siginterrupt/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = siginterrupt
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/siginterrupt/siginterrupt.c b/regress/lib/libpthread/siginterrupt/siginterrupt.c
new file mode 100644
index 00000000000..82aae9f45d4
--- /dev/null
+++ b/regress/lib/libpthread/siginterrupt/siginterrupt.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: siginterrupt.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+blocker(void *arg)
+{
+ int fds[2];
+ char buf;
+
+ CHECKe(pipe(fds));
+ ASSERT(read(fds[0], &buf, 1) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ pthread_t tid;
+ void *retval;
+
+ ASSERT(signal(SIGUSR1, handler) != SIG_ERR);
+
+ CHECKr(pthread_create(&tid, NULL, blocker, NULL));
+ sleep(1);
+
+ /* With signal(3) system calls will be restarted. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Same as default with signal(3). */
+ CHECKe(siginterrupt(SIGUSR1, 0));
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt the call now. */
+ CHECKe(siginterrupt(SIGUSR1, 1));
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 3);
+ SUCCEED;
+}