diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 2003-01-19 21:23:47 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 2003-01-19 21:23:47 +0000 |
commit | fbd275bc3a6941b17dea61a0bb698f9977e9e5e3 (patch) | |
tree | 76683d18455e6797353efbe6169d3234d7de0000 /regress/lib | |
parent | 0c99ae075c7b7425f108d8816ff2de6afcd15796 (diff) |
add test to ensure select can be cancelled.
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libc_r/Makefile | 4 | ||||
-rw-r--r-- | regress/lib/libc_r/cancel2/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libc_r/cancel2/cancel2.c | 43 | ||||
-rw-r--r-- | regress/lib/libpthread/Makefile | 4 | ||||
-rw-r--r-- | regress/lib/libpthread/cancel2/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libpthread/cancel2/cancel2.c | 43 |
6 files changed, 100 insertions, 4 deletions
diff --git a/regress/lib/libc_r/Makefile b/regress/lib/libc_r/Makefile index 02d1500c284..6165d505244 100644 --- a/regress/lib/libc_r/Makefile +++ b/regress/lib/libc_r/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.14 2002/11/12 03:17:16 marc Exp $ +# $OpenBSD: Makefile,v 1.15 2003/01/19 21:23:45 marc Exp $ -SUBDIR= cancel close cwd execve fork group malloc_duel netdb pcap poll \ +SUBDIR= cancel cancel2 close cwd execve fork group malloc_duel netdb pcap poll \ preemption preemption_float pthread_cond_timedwait pthread_create \ pthread_join pthread_kill pthread_mutex pthread_specific readdir \ select setjmp signal sigdeliver siginfo signodefer sigsuspend \ diff --git a/regress/lib/libc_r/cancel2/Makefile b/regress/lib/libc_r/cancel2/Makefile new file mode 100644 index 00000000000..8cf71cfe4c0 --- /dev/null +++ b/regress/lib/libc_r/cancel2/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2003/01/19 21:23:46 marc Exp $ + +PROG= cancel2 + +.include <bsd.regress.mk> diff --git a/regress/lib/libc_r/cancel2/cancel2.c b/regress/lib/libc_r/cancel2/cancel2.c new file mode 100644 index 00000000000..275ad8d8b61 --- /dev/null +++ b/regress/lib/libc_r/cancel2/cancel2.c @@ -0,0 +1,43 @@ +/* $OpenBSD: cancel2.c,v 1.1 2003/01/19 21:23:46 marc Exp $ */ +/* PUBLIC DOMAIN <marc@snafu.org> */ + +/* + * Check that a thread waiting on a select without timeout can be + * cancelled. + */ + +#include <sys/types.h> +#include <sys/time.h> + +#include <pthread.h> +#include <unistd.h> + +#include "test.h" + +void * +select_thread(void *arg) +{ + int read_fd = *(int*) arg; + fd_set read_fds; + int result; + + FD_ZERO(&read_fds); + FD_SET(read_fd, &read_fds); + result = select(read_fd + 1, &read_fds, NULL, NULL, NULL); + printf("select returned %d\n", result); + return 0; +} + +int +main(int argc, char *argv[]) +{ + pthread_t thread; + int pipe_fd[2]; + + CHECKe(pipe(pipe_fd)); + CHECKr(pthread_create(&thread, NULL, select_thread, pipe_fd)); + sleep(2); + CHECKr(pthread_cancel(thread)); + CHECKr(pthread_join(thread, NULL)); + SUCCEED; +} diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile index 02d1500c284..6165d505244 100644 --- a/regress/lib/libpthread/Makefile +++ b/regress/lib/libpthread/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.14 2002/11/12 03:17:16 marc Exp $ +# $OpenBSD: Makefile,v 1.15 2003/01/19 21:23:45 marc Exp $ -SUBDIR= cancel close cwd execve fork group malloc_duel netdb pcap poll \ +SUBDIR= cancel cancel2 close cwd execve fork group malloc_duel netdb pcap poll \ preemption preemption_float pthread_cond_timedwait pthread_create \ pthread_join pthread_kill pthread_mutex pthread_specific readdir \ select setjmp signal sigdeliver siginfo signodefer sigsuspend \ diff --git a/regress/lib/libpthread/cancel2/Makefile b/regress/lib/libpthread/cancel2/Makefile new file mode 100644 index 00000000000..8cf71cfe4c0 --- /dev/null +++ b/regress/lib/libpthread/cancel2/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2003/01/19 21:23:46 marc Exp $ + +PROG= cancel2 + +.include <bsd.regress.mk> diff --git a/regress/lib/libpthread/cancel2/cancel2.c b/regress/lib/libpthread/cancel2/cancel2.c new file mode 100644 index 00000000000..275ad8d8b61 --- /dev/null +++ b/regress/lib/libpthread/cancel2/cancel2.c @@ -0,0 +1,43 @@ +/* $OpenBSD: cancel2.c,v 1.1 2003/01/19 21:23:46 marc Exp $ */ +/* PUBLIC DOMAIN <marc@snafu.org> */ + +/* + * Check that a thread waiting on a select without timeout can be + * cancelled. + */ + +#include <sys/types.h> +#include <sys/time.h> + +#include <pthread.h> +#include <unistd.h> + +#include "test.h" + +void * +select_thread(void *arg) +{ + int read_fd = *(int*) arg; + fd_set read_fds; + int result; + + FD_ZERO(&read_fds); + FD_SET(read_fd, &read_fds); + result = select(read_fd + 1, &read_fds, NULL, NULL, NULL); + printf("select returned %d\n", result); + return 0; +} + +int +main(int argc, char *argv[]) +{ + pthread_t thread; + int pipe_fd[2]; + + CHECKe(pipe(pipe_fd)); + CHECKr(pthread_create(&thread, NULL, select_thread, pipe_fd)); + sleep(2); + CHECKr(pthread_cancel(thread)); + CHECKr(pthread_join(thread, NULL)); + SUCCEED; +} |