Module Name: src Committed By: tron Date: Sat May 28 16:12:56 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/kernel: Makefile src/tests/syscall: Makefile Added Files: src/tests/syscall: t_pollts.c Removed Files: src/tests/kernel: t_pollts.c Log Message: Move regression test for PR kern/44986 from "kernel" to "syscalls" as the later directory seems to be a better fit. To generate a diff of this commit: cvs rdiff -u -r1.339 -r1.340 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/Makefile cvs rdiff -u -r1.2 -r0 src/tests/kernel/t_pollts.c cvs rdiff -u -r1.27 -r1.28 src/tests/syscall/Makefile cvs rdiff -u -r0 -r1.1 src/tests/syscall/t_pollts.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.339 src/distrib/sets/lists/tests/mi:1.340 --- src/distrib/sets/lists/tests/mi:1.339 Sat May 28 15:24:49 2011 +++ src/distrib/sets/lists/tests/mi Sat May 28 16:12:56 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.339 2011/05/28 15:24:49 tron Exp $ +# $NetBSD: mi,v 1.340 2011/05/28 16:12:56 tron Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -324,7 +324,7 @@ ./usr/libdata/debug/usr/tests/kernel/t_mkdir.debug tests-kernel-tests debug,atf ./usr/libdata/debug/usr/tests/kernel/t_pipe.debug tests-kernel-tests debug,atf ./usr/libdata/debug/usr/tests/kernel/t_poll3w.debug tests-kernel-tests debug,atf -./usr/libdata/debug/usr/tests/kernel/t_pollts.debug tests-kernel-tests debug,atf +./usr/libdata/debug/usr/tests/kernel/t_pollts.debug tests-obsolete obsolete ./usr/libdata/debug/usr/tests/kernel/t_posix_fadvise.debug tests-kernel-tests debug,atf ./usr/libdata/debug/usr/tests/kernel/t_rnd.debug tests-kernel-tests debug,atf ./usr/libdata/debug/usr/tests/kernel/t_sigaction.debug tests-kernel-tests debug,atf @@ -621,6 +621,7 @@ ./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_msync.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_nanosleep.debug tests-syscall-debug debug,atf +./usr/libdata/debug/usr/tests/syscall/t_pollts.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_pselect.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_setrlimit.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_setuid.debug tests-syscall-debug debug,atf @@ -1744,7 +1745,7 @@ ./usr/tests/kernel/t_mkdir tests-kernel-tests atf ./usr/tests/kernel/t_pipe tests-kernel-tests atf ./usr/tests/kernel/t_poll3w tests-kernel-tests atf -./usr/tests/kernel/t_pollts tests-kernel-tests atf +./usr/tests/kernel/t_pollts tests-obsolete obsolete ./usr/tests/kernel/t_posix_fadvise tests-kernel-tests atf ./usr/tests/kernel/t_ps_strings tests-kernel-tests atf ./usr/tests/kernel/t_rnd tests-kernel-tests atf @@ -2325,6 +2326,7 @@ ./usr/tests/syscall/t_mprotect tests-syscall-tests atf ./usr/tests/syscall/t_msync tests-syscall-tests atf ./usr/tests/syscall/t_nanosleep tests-syscall-tests atf +./usr/tests/syscall/t_pollts tests-syscall-tests atf ./usr/tests/syscall/t_pselect tests-syscall-tests atf ./usr/tests/syscall/t_setrlimit tests-syscall-tests atf ./usr/tests/syscall/t_setuid tests-syscall-tests atf Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.11 src/tests/kernel/Makefile:1.12 --- src/tests/kernel/Makefile:1.11 Sat May 28 15:24:49 2011 +++ src/tests/kernel/Makefile Sat May 28 16:12:56 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2011/05/28 15:24:49 tron Exp $ +# $NetBSD: Makefile,v 1.12 2011/05/28 16:12:56 tron Exp $ NOMAN= # defined @@ -21,7 +21,6 @@ TESTS_C+= t_extattrctl TESTS_C+= t_sigaction TESTS_C+= t_filedesc -TESTS_C+= t_pollts TESTS_SH= t_umount TESTS_SH+= t_ps_strings Index: src/tests/syscall/Makefile diff -u src/tests/syscall/Makefile:1.27 src/tests/syscall/Makefile:1.28 --- src/tests/syscall/Makefile:1.27 Wed May 18 02:57:48 2011 +++ src/tests/syscall/Makefile Sat May 28 16:12:56 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.27 2011/05/18 02:57:48 christos Exp $ +# $NetBSD: Makefile,v 1.28 2011/05/28 16:12:56 tron Exp $ .include <bsd.own.mk> @@ -7,7 +7,7 @@ TESTS_C+= t_access t_cmsg t_dup t_fsync TESTS_C+= t_getgroups t_getpid t_getrusage t_getsid t_gettimeofday TESTS_C+= t_itimer t_kill t_mmap t_mprotect t_msync t_nanosleep -TESTS_C+= t_pselect t_setrlimit t_setuid t_timer t_umask +TESTS_C+= t_pollts t_pselect t_setrlimit t_setuid t_timer t_umask LDADD.t_getpid+= -lpthread LDADD.t_timer+= -lpthread Added files: Index: src/tests/syscall/t_pollts.c diff -u /dev/null src/tests/syscall/t_pollts.c:1.1 --- /dev/null Sat May 28 16:12:56 2011 +++ src/tests/syscall/t_pollts.c Sat May 28 16:12:56 2011 @@ -0,0 +1,168 @@ +/* $NetBSD: t_pollts.c,v 1.1 2011/05/28 16:12:56 tron Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matthias Scheler. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/time.h> + +#include <assert.h> +#include <fcntl.h> +#include <paths.h> +#include <poll.h> +#include <signal.h> +#include <unistd.h> + +#include <atf-c.h> + +ATF_TC(pollts); +ATF_TC_HEAD(pollts, tc) +{ + atf_tc_set_md_var(tc, "timeout", "10"); + atf_tc_set_md_var(tc, "descr", + "Basis functionality test for pollts(2)"); +} + +ATF_TC(pollts_sigmask); +ATF_TC_HEAD(pollts_sigmask, tc) +{ + atf_tc_set_md_var(tc, "timeout", "10"); + atf_tc_set_md_var(tc, "descr", + "Check that pollts_sigmask(2) restores the signal mask"); +} + +ATF_TC_BODY(pollts, tc) +{ + int fds[2]; + struct pollfd pfds[2]; + struct timespec timeout; + int ret; + + assert(pipe(fds) == 0); + + pfds[0].fd = fds[0]; + pfds[0].events = POLLIN; + pfds[1].fd = fds[1]; + pfds[1].events = POLLOUT; + + /* Use a timeout of 1 second. */ + timeout.tv_sec = 1; + timeout.tv_nsec = 0; + + /* + * Check that we get a timeout waiting for data on the read end + * of our pipe. + */ + pfds[0].revents = -1; + pfds[1].revents = -1; + ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[0], 1, &timeout, NULL), 0, + "got: %d", ret); + ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); + ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); + + /* Check that the write end of the pipe as reported as ready. */ + pfds[0].revents = -1; + pfds[1].revents = -1; + ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[1], 1, &timeout, NULL), 1, + "got: %d", ret); + ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); + ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ + pfds[1].revents); + + /* Check that only the write end of the pipe as reported as ready. */ + pfds[0].revents = -1; + pfds[1].revents = -1; + ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 1, + "got: %d", ret); + ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); + ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", + pfds[1].revents); + + /* Write data to our pipe. */ + assert(write(fds[1], "", 1) == 1); + + /* Check that both ends of our pipe are reported as ready. */ + pfds[0].revents = -1; + pfds[1].revents = -1; + ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 2, + "got: %d", ret); + ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", + pfds[0].revents); + ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", + pfds[1].revents); + + assert(close(fds[0]) == 0); + assert(close(fds[1]) == 0); +} + +ATF_TC_BODY(pollts_sigmask, tc) +{ + int fd; + struct pollfd pfd; + struct timespec timeout; + sigset_t mask; + int ret; + + /* Cf kern/44986 */ + + fd = open(_PATH_DEVNULL, O_RDONLY); + assert(fd >= 0); + + pfd.fd = fd; + pfd.events = POLLIN; + + /* Use a timeout of 1 second. */ + timeout.tv_sec = 1; + timeout.tv_nsec = 0; + + /* Unblock all signals. */ + assert(sigfillset(&mask) == 0); + assert(sigprocmask(SIG_UNBLOCK, &mask, NULL) == 0); + + /* + * Check that pollts(2) immediately returns. We block *all* + * signals during pollts(2). + */ + ATF_REQUIRE_EQ_MSG(ret = pollts(&pfd, 1, &timeout, &mask), 1, + "got: %d", ret); + + /* Check that signals are now longer blocked. */ + assert(sigprocmask(SIG_SETMASK, NULL, &mask) == 0); + ATF_REQUIRE_MSG(sigismember(&mask, SIGUSR1) == 0, + "signal mask was changed."); + + assert(close(fd) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, pollts); + ATF_TP_ADD_TC(tp, pollts_sigmask); + + return atf_no_error(); +}