diff options
author | 2011-09-13 23:50:17 +0000 | |
---|---|---|
committer | 2011-09-13 23:50:17 +0000 | |
commit | d13be5d47e4149db2549a9828e244d59dbc43f15 (patch) | |
tree | 24654cab1dc6977bb362e8b14917c0d71534ad8b /regress/lib/libpthread/siginterrupt | |
parent | On KA43: (diff) | |
download | wireguard-openbsd-d13be5d47e4149db2549a9828e244d59dbc43f15.tar.xz wireguard-openbsd-d13be5d47e4149db2549a9828e244d59dbc43f15.zip |
first round of tests to check system calls restarting with pthreads.
guenther@ ok
Diffstat (limited to 'regress/lib/libpthread/siginterrupt')
-rw-r--r-- | regress/lib/libpthread/siginterrupt/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libpthread/siginterrupt/siginterrupt.c | 58 |
2 files changed, 63 insertions, 0 deletions
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; +} |