Home | History | Annotate | Line # | Download | only in sys
t_poll.c revision 1.8.4.1
      1  1.8.4.1  perseant /*	$NetBSD: t_poll.c,v 1.8.4.1 2025/08/02 05:58:06 perseant Exp $	*/
      2      1.1    jruoho 
      3      1.1    jruoho /*-
      4      1.1    jruoho  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5      1.1    jruoho  * All rights reserved.
      6      1.1    jruoho  *
      7      1.1    jruoho  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    jruoho  * by Matthias Scheler.
      9      1.1    jruoho  *
     10      1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     11      1.1    jruoho  * modification, are permitted provided that the following conditions
     12      1.1    jruoho  * are met:
     13      1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     14      1.1    jruoho  *    notice, this list of conditions and the following disclaimer.
     15      1.1    jruoho  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    jruoho  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    jruoho  *    documentation and/or other materials provided with the distribution.
     18      1.1    jruoho  *
     19      1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1    jruoho  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1    jruoho  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1    jruoho  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1    jruoho  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1    jruoho  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1    jruoho  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1    jruoho  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1    jruoho  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1    jruoho  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1    jruoho  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1    jruoho  */
     31      1.1    jruoho 
     32  1.8.4.1  perseant #include <sys/ioctl.h>
     33  1.8.4.1  perseant #include <sys/socket.h>
     34      1.5   thorpej #include <sys/stat.h>
     35      1.1    jruoho #include <sys/time.h>
     36      1.2    jruoho #include <sys/wait.h>
     37      1.1    jruoho 
     38      1.1    jruoho #include <atf-c.h>
     39      1.1    jruoho #include <errno.h>
     40      1.1    jruoho #include <fcntl.h>
     41      1.1    jruoho #include <paths.h>
     42      1.1    jruoho #include <poll.h>
     43  1.8.4.1  perseant #include <pthread.h>
     44      1.2    jruoho #include <stdio.h>
     45      1.7   thorpej #include <stdlib.h>
     46      1.1    jruoho #include <signal.h>
     47  1.8.4.1  perseant #include <termios.h>
     48      1.1    jruoho #include <unistd.h>
     49      1.1    jruoho 
     50  1.8.4.1  perseant #include "h_macros.h"
     51  1.8.4.1  perseant 
     52      1.2    jruoho static int desc;
     53      1.2    jruoho 
     54      1.2    jruoho static void
     55      1.2    jruoho child1(void)
     56      1.2    jruoho {
     57      1.2    jruoho 	struct pollfd pfd;
     58      1.2    jruoho 
     59      1.2    jruoho 	pfd.fd = desc;
     60      1.2    jruoho 	pfd.events = POLLIN | POLLHUP | POLLOUT;
     61      1.2    jruoho 
     62      1.2    jruoho 	(void)poll(&pfd, 1, 2000);
     63      1.2    jruoho 	(void)printf("child1 exit\n");
     64      1.2    jruoho }
     65      1.2    jruoho 
     66      1.2    jruoho static void
     67      1.2    jruoho child2(void)
     68      1.2    jruoho {
     69      1.2    jruoho 	struct pollfd pfd;
     70      1.2    jruoho 
     71      1.2    jruoho 	pfd.fd = desc;
     72      1.2    jruoho 	pfd.events = POLLIN | POLLHUP | POLLOUT;
     73      1.2    jruoho 
     74      1.2    jruoho 	(void)sleep(1);
     75      1.2    jruoho 	(void)poll(&pfd, 1, INFTIM);
     76      1.2    jruoho 	(void)printf("child2 exit\n");
     77      1.2    jruoho }
     78      1.2    jruoho 
     79      1.2    jruoho static void
     80      1.2    jruoho child3(void)
     81      1.2    jruoho {
     82      1.2    jruoho 	struct pollfd pfd;
     83      1.2    jruoho 
     84      1.2    jruoho 	(void)sleep(5);
     85      1.2    jruoho 
     86      1.2    jruoho 	pfd.fd = desc;
     87      1.2    jruoho 	pfd.events = POLLIN | POLLHUP | POLLOUT;
     88      1.2    jruoho 
     89      1.2    jruoho 	(void)poll(&pfd, 1, INFTIM);
     90      1.2    jruoho 	(void)printf("child3 exit\n");
     91      1.2    jruoho }
     92      1.2    jruoho 
     93      1.4     kamil ATF_TC(3way);
     94      1.4     kamil ATF_TC_HEAD(3way, tc)
     95      1.2    jruoho {
     96      1.2    jruoho 	atf_tc_set_md_var(tc, "timeout", "15");
     97      1.2    jruoho 	atf_tc_set_md_var(tc, "descr",
     98      1.2    jruoho 	    "Check for 3-way collision for descriptor. First child comes "
     99      1.2    jruoho 	    "and polls on descriptor, second child comes and polls, first "
    100      1.2    jruoho 	    "child times out and exits, third child comes and polls. When "
    101      1.2    jruoho 	    "the wakeup event happens, the two remaining children should "
    102      1.2    jruoho 	    "both be awaken. (kern/17517)");
    103      1.2    jruoho }
    104      1.2    jruoho 
    105      1.4     kamil ATF_TC_BODY(3way, tc)
    106      1.2    jruoho {
    107      1.2    jruoho 	int pf[2];
    108      1.2    jruoho 	int status, i;
    109      1.2    jruoho 	pid_t pid;
    110  1.8.4.1  perseant 	ssize_t nwrit;
    111      1.2    jruoho 
    112  1.8.4.1  perseant 	RL(pipe(pf));
    113      1.2    jruoho 	desc = pf[0];
    114      1.2    jruoho 
    115  1.8.4.1  perseant 	RL(pid = fork());
    116      1.2    jruoho 	if (pid == 0) {
    117  1.8.4.1  perseant 		if (close(pf[1]) == -1)
    118  1.8.4.1  perseant 			_exit(1);
    119      1.2    jruoho 		child1();
    120      1.2    jruoho 		_exit(0);
    121      1.2    jruoho 		/* NOTREACHED */
    122      1.2    jruoho 	}
    123      1.2    jruoho 
    124  1.8.4.1  perseant 	RL(pid = fork());
    125      1.2    jruoho 	if (pid == 0) {
    126  1.8.4.1  perseant 		if (close(pf[1]) == -1)
    127  1.8.4.1  perseant 			_exit(1);
    128      1.2    jruoho 		child2();
    129      1.2    jruoho 		_exit(0);
    130      1.2    jruoho 		/* NOTREACHED */
    131      1.2    jruoho 	}
    132      1.2    jruoho 
    133  1.8.4.1  perseant 	RL(pid = fork());
    134      1.2    jruoho 	if (pid == 0) {
    135  1.8.4.1  perseant 		if (close(pf[1]) == -1)
    136  1.8.4.1  perseant 			_exit(1);
    137      1.2    jruoho 		child3();
    138      1.2    jruoho 		_exit(0);
    139      1.2    jruoho 		/* NOTREACHED */
    140      1.2    jruoho 	}
    141      1.2    jruoho 
    142      1.2    jruoho 	(void)sleep(10);
    143      1.2    jruoho 
    144      1.2    jruoho 	(void)printf("parent write\n");
    145      1.2    jruoho 
    146  1.8.4.1  perseant 	RL(nwrit = write(pf[1], "konec\n", 6));
    147  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nwrit, 6, "nwrit=%zd", nwrit);
    148      1.2    jruoho 
    149  1.8.4.1  perseant 	for (i = 0; i < 3; i++)
    150  1.8.4.1  perseant 		RL(wait(&status));
    151      1.2    jruoho 
    152      1.2    jruoho 	(void)printf("parent terminated\n");
    153      1.2    jruoho }
    154      1.2    jruoho 
    155      1.4     kamil ATF_TC(basic);
    156      1.4     kamil ATF_TC_HEAD(basic, tc)
    157      1.1    jruoho {
    158      1.1    jruoho 	atf_tc_set_md_var(tc, "timeout", "10");
    159      1.1    jruoho 	atf_tc_set_md_var(tc, "descr",
    160      1.1    jruoho 	    "Basis functionality test for poll(2)");
    161      1.1    jruoho }
    162      1.1    jruoho 
    163      1.4     kamil ATF_TC_BODY(basic, tc)
    164      1.1    jruoho {
    165      1.1    jruoho 	int fds[2];
    166      1.1    jruoho 	struct pollfd pfds[2];
    167      1.1    jruoho 	int ret;
    168  1.8.4.1  perseant 	ssize_t nwrit;
    169      1.1    jruoho 
    170  1.8.4.1  perseant 	RL(pipe(fds));
    171      1.1    jruoho 
    172      1.1    jruoho 	pfds[0].fd = fds[0];
    173      1.1    jruoho 	pfds[0].events = POLLIN;
    174      1.1    jruoho 	pfds[1].fd = fds[1];
    175      1.1    jruoho 	pfds[1].events = POLLOUT;
    176      1.1    jruoho 
    177      1.1    jruoho 	/*
    178      1.1    jruoho 	 * Check that we get a timeout waiting for data on the read end
    179      1.1    jruoho 	 * of our pipe.
    180      1.1    jruoho 	 */
    181      1.1    jruoho 	pfds[0].revents = -1;
    182      1.1    jruoho 	pfds[1].revents = -1;
    183  1.8.4.1  perseant 	RL(ret = poll(&pfds[0], 1, 1));
    184  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 0, "got: %d", ret);
    185      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
    186      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents);
    187      1.1    jruoho 
    188      1.1    jruoho 	/* Check that the write end of the pipe as reported as ready. */
    189      1.1    jruoho 	pfds[0].revents = -1;
    190      1.1    jruoho 	pfds[1].revents = -1;
    191  1.8.4.1  perseant 	RL(ret = poll(&pfds[1], 1, 1));
    192  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    193      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents);
    194      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\
    195      1.1    jruoho 	    pfds[1].revents);
    196      1.1    jruoho 
    197      1.1    jruoho 	/* Check that only the write end of the pipe as reported as ready. */
    198      1.1    jruoho 	pfds[0].revents = -1;
    199      1.1    jruoho 	pfds[1].revents = -1;
    200  1.8.4.1  perseant 	RL(ret = poll(pfds, 2, 1));
    201  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    202      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
    203      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
    204      1.1    jruoho 	    pfds[1].revents);
    205      1.1    jruoho 
    206      1.1    jruoho 	/* Write data to our pipe. */
    207  1.8.4.1  perseant 	RL(nwrit = write(fds[1], "", 1));
    208  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nwrit, 1, "nwrit=%zd", nwrit);
    209      1.1    jruoho 
    210      1.1    jruoho 	/* Check that both ends of our pipe are reported as ready. */
    211      1.1    jruoho 	pfds[0].revents = -1;
    212      1.1    jruoho 	pfds[1].revents = -1;
    213  1.8.4.1  perseant 	RL(ret = poll(pfds, 2, 1));
    214  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret);
    215      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d",
    216      1.1    jruoho 	    pfds[0].revents);
    217      1.1    jruoho 	ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
    218      1.1    jruoho 	    pfds[1].revents);
    219      1.1    jruoho 
    220  1.8.4.1  perseant 	RL(close(fds[0]));
    221  1.8.4.1  perseant 	RL(close(fds[1]));
    222      1.1    jruoho }
    223      1.1    jruoho 
    224      1.4     kamil ATF_TC(err);
    225      1.4     kamil ATF_TC_HEAD(err, tc)
    226      1.1    jruoho {
    227      1.1    jruoho 	atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)");
    228      1.1    jruoho }
    229      1.1    jruoho 
    230      1.4     kamil ATF_TC_BODY(err, tc)
    231      1.1    jruoho {
    232      1.1    jruoho 	struct pollfd pfd;
    233      1.1    jruoho 	int fd = 0;
    234      1.1    jruoho 
    235      1.1    jruoho 	pfd.fd = fd;
    236      1.1    jruoho 	pfd.events = POLLIN;
    237      1.1    jruoho 
    238      1.1    jruoho 	errno = 0;
    239      1.1    jruoho 	ATF_REQUIRE_ERRNO(EFAULT, poll((struct pollfd *)-1, 1, -1) == -1);
    240      1.1    jruoho 
    241      1.1    jruoho 	errno = 0;
    242      1.1    jruoho 	ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1);
    243      1.1    jruoho }
    244      1.1    jruoho 
    245      1.5   thorpej static const char	fifo_path[] = "pollhup_fifo";
    246      1.5   thorpej 
    247      1.5   thorpej static void
    248      1.5   thorpej fifo_support(void)
    249      1.5   thorpej {
    250  1.8.4.1  perseant 
    251      1.5   thorpej 	errno = 0;
    252      1.5   thorpej 	if (mkfifo(fifo_path, 0600) == 0) {
    253  1.8.4.1  perseant 		RL(unlink(fifo_path));
    254      1.5   thorpej 		return;
    255      1.5   thorpej 	}
    256      1.5   thorpej 
    257      1.5   thorpej 	if (errno == EOPNOTSUPP) {
    258      1.5   thorpej 		atf_tc_skip("the kernel does not support FIFOs");
    259      1.5   thorpej 	} else {
    260      1.5   thorpej 		atf_tc_fail("mkfifo(2) failed");
    261      1.5   thorpej 	}
    262      1.5   thorpej }
    263      1.5   thorpej 
    264      1.7   thorpej ATF_TC_WITH_CLEANUP(fifo_inout);
    265      1.7   thorpej ATF_TC_HEAD(fifo_inout, tc)
    266      1.7   thorpej {
    267      1.7   thorpej 	atf_tc_set_md_var(tc, "descr",
    268      1.7   thorpej 	    "Check POLLIN/POLLOUT behavior with fifos");
    269      1.7   thorpej }
    270      1.7   thorpej 
    271      1.7   thorpej ATF_TC_BODY(fifo_inout, tc)
    272      1.7   thorpej {
    273      1.7   thorpej 	struct pollfd pfd[2];
    274      1.7   thorpej 	char *buf;
    275      1.7   thorpej 	int rfd, wfd;
    276      1.7   thorpej 	long pipe_buf;
    277  1.8.4.1  perseant 	int ret;
    278  1.8.4.1  perseant 	ssize_t nwrit, nread;
    279      1.7   thorpej 
    280      1.7   thorpej 	fifo_support();
    281      1.7   thorpej 
    282  1.8.4.1  perseant 	RL(mkfifo(fifo_path, 0600));
    283  1.8.4.1  perseant 	RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
    284  1.8.4.1  perseant 	RL(wfd = open(fifo_path, O_WRONLY | O_NONBLOCK));
    285      1.7   thorpej 
    286      1.7   thorpej 	/* Get the maximum atomic pipe write size. */
    287      1.7   thorpej 	pipe_buf = fpathconf(wfd, _PC_PIPE_BUF);
    288  1.8.4.1  perseant 	ATF_REQUIRE_MSG(pipe_buf > 1, "pipe_buf=%ld", pipe_buf);
    289      1.7   thorpej 
    290  1.8.4.1  perseant 	REQUIRE_LIBC(buf = malloc(pipe_buf), NULL);
    291      1.7   thorpej 
    292      1.7   thorpej 	memset(&pfd, 0, sizeof(pfd));
    293      1.7   thorpej 	pfd[0].fd = rfd;
    294      1.7   thorpej 	pfd[0].events = POLLIN | POLLRDNORM;
    295      1.7   thorpej 	pfd[1].fd = wfd;
    296      1.7   thorpej 	pfd[1].events = POLLOUT | POLLWRNORM;
    297      1.7   thorpej 
    298      1.7   thorpej 	/* We expect the FIFO to be writable but not readable. */
    299  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    300  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    301  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0,
    302  1.8.4.1  perseant 	    "pfd[0].revents=0x%x", pfd[0].revents);
    303  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
    304  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    305      1.7   thorpej 
    306      1.7   thorpej 	/* Write a single byte of data into the FIFO. */
    307  1.8.4.1  perseant 	RL(nwrit = write(wfd, buf, 1));
    308  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nwrit, 1, "nwrit=%zd", nwrit);
    309      1.7   thorpej 
    310      1.7   thorpej 	/* We expect the FIFO to be readable and writable. */
    311  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    312  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret);
    313  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
    314  1.8.4.1  perseant 	    "pfd[0].revents=0x%x", pfd[0].revents);
    315  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
    316  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    317      1.7   thorpej 
    318      1.7   thorpej 	/* Read that single byte back out. */
    319  1.8.4.1  perseant 	RL(nread = read(rfd, buf, 1));
    320  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nread, 1, "nread=%zd", nread);
    321      1.7   thorpej 
    322      1.7   thorpej 	/*
    323      1.7   thorpej 	 * Write data into the FIFO until it is full, which is
    324      1.7   thorpej 	 * defined as insufficient buffer space to hold a the
    325      1.7   thorpej 	 * maximum atomic pipe write size.
    326      1.7   thorpej 	 */
    327      1.7   thorpej 	while (write(wfd, buf, pipe_buf) != -1) {
    328      1.7   thorpej 		continue;
    329      1.7   thorpej 	}
    330  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
    331      1.7   thorpej 
    332      1.7   thorpej 	/* We expect the FIFO to be readble but not writable. */
    333  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    334  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    335  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
    336  1.8.4.1  perseant 	    "pfd[0].revents=0x%x", pfd[0].revents);
    337  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0,
    338  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    339      1.7   thorpej 
    340      1.7   thorpej 	/* Read a single byte of data from the FIFO. */
    341  1.8.4.1  perseant 	RL(nread = read(rfd, buf, 1));
    342  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nread, 1, "nread=%zd", nread);
    343      1.7   thorpej 
    344      1.7   thorpej 	/*
    345      1.7   thorpej 	 * Because we have read only a single byte out, there will
    346      1.7   thorpej 	 * be insufficient space for a pipe_buf-sized message, so
    347      1.7   thorpej 	 * the FIFO should still not be writable.
    348      1.7   thorpej 	 */
    349  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    350  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    351  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
    352  1.8.4.1  perseant 	    "pfd[0].revents=0x%x", pfd[0].revents);
    353  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0,
    354  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    355      1.7   thorpej 
    356      1.7   thorpej 	/*
    357      1.8   thorpej 	 * Now read enough so that exactly pipe_buf space should
    358      1.8   thorpej 	 * be available.  The FIFO should be writable after that.
    359      1.8   thorpej 	 * N.B. we don't care if it's readable at this point.
    360      1.8   thorpej 	 */
    361  1.8.4.1  perseant 	RL(nread = read(rfd, buf, pipe_buf - 1));
    362  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(nread, pipe_buf - 1, "nread=%zd pipe_buf-1=%ld",
    363  1.8.4.1  perseant 	    nread, pipe_buf - 1);
    364  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    365  1.8.4.1  perseant 	ATF_REQUIRE_MSG(ret >= 1, "got: %d", ret);
    366  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
    367  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    368      1.8   thorpej 
    369      1.8   thorpej 	/*
    370      1.7   thorpej 	 * Now read all of the data out of the FIFO and ensure that
    371      1.7   thorpej 	 * we get back to the initial state.
    372      1.7   thorpej 	 */
    373      1.7   thorpej 	while (read(rfd, buf, pipe_buf) != -1) {
    374      1.7   thorpej 		continue;
    375      1.7   thorpej 	}
    376  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
    377      1.7   thorpej 
    378  1.8.4.1  perseant 	RL(ret = poll(pfd, 2, 0));
    379  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    380  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0,
    381  1.8.4.1  perseant 	    "pfd[0].revents=0x%x", pfd[0].revents);
    382  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
    383  1.8.4.1  perseant 	    "pfd[1].revents=0x%x", pfd[1].revents);
    384      1.7   thorpej 
    385  1.8.4.1  perseant 	RL(close(wfd));
    386  1.8.4.1  perseant 	RL(close(rfd));
    387      1.7   thorpej }
    388      1.7   thorpej 
    389      1.7   thorpej ATF_TC_CLEANUP(fifo_inout, tc)
    390      1.7   thorpej {
    391      1.7   thorpej 	(void)unlink(fifo_path);
    392      1.7   thorpej }
    393      1.7   thorpej 
    394      1.5   thorpej ATF_TC_WITH_CLEANUP(fifo_hup1);
    395      1.5   thorpej ATF_TC_HEAD(fifo_hup1, tc)
    396      1.5   thorpej {
    397      1.5   thorpej 	atf_tc_set_md_var(tc, "descr",
    398      1.5   thorpej 	    "Check POLLHUP behavior with fifos [1]");
    399      1.5   thorpej }
    400      1.5   thorpej 
    401      1.5   thorpej ATF_TC_BODY(fifo_hup1, tc)
    402      1.5   thorpej {
    403      1.5   thorpej 	struct pollfd pfd;
    404      1.5   thorpej 	int rfd, wfd;
    405  1.8.4.1  perseant 	int ret;
    406      1.5   thorpej 
    407      1.5   thorpej 	fifo_support();
    408      1.5   thorpej 
    409  1.8.4.1  perseant 	RL(mkfifo(fifo_path, 0600));
    410  1.8.4.1  perseant 	RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
    411  1.8.4.1  perseant 	RL(wfd = open(fifo_path, O_WRONLY));
    412      1.5   thorpej 
    413      1.5   thorpej 	memset(&pfd, 0, sizeof(pfd));
    414      1.5   thorpej 	pfd.fd = rfd;
    415      1.5   thorpej 	pfd.events = POLLIN;
    416      1.5   thorpej 
    417  1.8.4.1  perseant 	RL(close(wfd));
    418      1.5   thorpej 
    419  1.8.4.1  perseant 	RL(ret = poll(&pfd, 1, 0));
    420  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    421  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP,
    422  1.8.4.1  perseant 	    "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x",
    423  1.8.4.1  perseant 	    pfd.revents, POLLHUP, POLLOUT);
    424      1.6   thorpej 
    425      1.6   thorpej 	/*
    426      1.6   thorpej 	 * Check that POLLHUP is cleared when a writer re-connects.
    427      1.6   thorpej 	 * Since the writer will not put any data into the FIFO, we
    428      1.6   thorpej 	 * expect no events.
    429      1.6   thorpej 	 */
    430      1.6   thorpej 	memset(&pfd, 0, sizeof(pfd));
    431      1.6   thorpej 	pfd.fd = rfd;
    432      1.6   thorpej 	pfd.events = POLLIN;
    433      1.6   thorpej 
    434  1.8.4.1  perseant 	RL(wfd = open(fifo_path, O_WRONLY));
    435  1.8.4.1  perseant 	RL(ret = poll(&pfd, 1, 0));
    436  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 0, "got: %d", ret);
    437      1.5   thorpej }
    438      1.5   thorpej 
    439      1.5   thorpej ATF_TC_CLEANUP(fifo_hup1, tc)
    440      1.5   thorpej {
    441      1.5   thorpej 	(void)unlink(fifo_path);
    442      1.5   thorpej }
    443      1.5   thorpej 
    444      1.5   thorpej ATF_TC_WITH_CLEANUP(fifo_hup2);
    445      1.5   thorpej ATF_TC_HEAD(fifo_hup2, tc)
    446      1.5   thorpej {
    447      1.5   thorpej 	atf_tc_set_md_var(tc, "descr",
    448      1.5   thorpej 	    "Check POLLHUP behavior with fifos [2]");
    449      1.5   thorpej }
    450      1.5   thorpej 
    451      1.5   thorpej ATF_TC_BODY(fifo_hup2, tc)
    452      1.5   thorpej {
    453      1.5   thorpej 	struct pollfd pfd;
    454      1.5   thorpej 	int rfd, wfd;
    455      1.5   thorpej 	pid_t pid;
    456      1.5   thorpej 	struct timespec ts1, ts2;
    457  1.8.4.1  perseant 	int ret;
    458      1.5   thorpej 
    459      1.5   thorpej 	fifo_support();
    460      1.5   thorpej 
    461  1.8.4.1  perseant 	RL(mkfifo(fifo_path, 0600));
    462  1.8.4.1  perseant 	RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
    463  1.8.4.1  perseant 	RL(wfd = open(fifo_path, O_WRONLY));
    464      1.5   thorpej 
    465      1.5   thorpej 	memset(&pfd, 0, sizeof(pfd));
    466      1.5   thorpej 	pfd.fd = rfd;
    467      1.5   thorpej 	pfd.events = POLLIN;
    468      1.5   thorpej 
    469  1.8.4.1  perseant 	RL(pid = fork());
    470      1.5   thorpej 	if (pid == 0) {
    471  1.8.4.1  perseant 		if (close(rfd))
    472  1.8.4.1  perseant 			_exit(1);
    473      1.5   thorpej 		sleep(5);
    474  1.8.4.1  perseant 		if (close(wfd))
    475  1.8.4.1  perseant 			_exit(1);
    476      1.5   thorpej 		_exit(0);
    477      1.5   thorpej 	}
    478  1.8.4.1  perseant 	RL(close(wfd));
    479      1.5   thorpej 
    480  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &ts1));
    481  1.8.4.1  perseant 	RL(ret = poll(&pfd, 1, INFTIM));
    482  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
    483  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &ts2));
    484      1.5   thorpej 
    485      1.5   thorpej 	/* Make sure at least a couple of seconds have elapsed. */
    486  1.8.4.1  perseant 	ATF_REQUIRE_MSG(ts2.tv_sec - ts1.tv_sec >= 2,
    487  1.8.4.1  perseant 	    "ts1=%lld.%09ld ts2=%lld.%09ld",
    488  1.8.4.1  perseant 	    (long long)ts1.tv_sec, ts1.tv_nsec,
    489  1.8.4.1  perseant 	    (long long)ts2.tv_sec, ts2.tv_nsec);
    490  1.8.4.1  perseant 
    491  1.8.4.1  perseant 	ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP,
    492  1.8.4.1  perseant 	    "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x",
    493  1.8.4.1  perseant 	    pfd.revents, POLLHUP, POLLOUT);
    494      1.5   thorpej }
    495      1.5   thorpej 
    496      1.5   thorpej ATF_TC_CLEANUP(fifo_hup2, tc)
    497      1.5   thorpej {
    498      1.5   thorpej 	(void)unlink(fifo_path);
    499      1.5   thorpej }
    500      1.5   thorpej 
    501  1.8.4.1  perseant static void
    502  1.8.4.1  perseant fillpipebuf(int writefd)
    503      1.1    jruoho {
    504  1.8.4.1  perseant 	char buf[BUFSIZ] = {0};
    505  1.8.4.1  perseant 	size_t n = 0;
    506  1.8.4.1  perseant 	ssize_t nwrit;
    507  1.8.4.1  perseant 	int flags;
    508  1.8.4.1  perseant 
    509  1.8.4.1  perseant 	RL(flags = fcntl(writefd, F_GETFL));
    510  1.8.4.1  perseant 	RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK));
    511  1.8.4.1  perseant 	while ((nwrit = write(writefd, buf, sizeof(buf))) != -1)
    512  1.8.4.1  perseant 		n += (size_t)nwrit;
    513  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
    514  1.8.4.1  perseant 	RL(fcntl(writefd, F_SETFL, flags));
    515  1.8.4.1  perseant 	fprintf(stderr, "filled %d with %zu bytes\n", writefd, n);
    516  1.8.4.1  perseant }
    517      1.1    jruoho 
    518  1.8.4.1  perseant static void
    519  1.8.4.1  perseant check_write_fail(int writefd, int error)
    520  1.8.4.1  perseant {
    521  1.8.4.1  perseant 	int flags;
    522  1.8.4.1  perseant 	void (*sighandler)(int);
    523  1.8.4.1  perseant 	char c = 0;
    524  1.8.4.1  perseant 	ssize_t nwrit;
    525  1.8.4.1  perseant 
    526  1.8.4.1  perseant 	RL(flags = fcntl(writefd, F_GETFL));
    527  1.8.4.1  perseant 	RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK));
    528  1.8.4.1  perseant 
    529  1.8.4.1  perseant 	REQUIRE_LIBC(sighandler = signal(SIGPIPE, SIG_IGN), SIG_ERR);
    530  1.8.4.1  perseant 	ATF_CHECK_ERRNO(error, (nwrit = write(writefd, &c, 1)) == -1);
    531  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit);
    532  1.8.4.1  perseant 	REQUIRE_LIBC(signal(SIGPIPE, sighandler), SIG_ERR);
    533      1.1    jruoho 
    534  1.8.4.1  perseant 	RL(fcntl(writefd, F_SETFL, flags));
    535  1.8.4.1  perseant }
    536  1.8.4.1  perseant 
    537  1.8.4.1  perseant static void
    538  1.8.4.1  perseant check_read_eof(int readfd)
    539  1.8.4.1  perseant {
    540  1.8.4.1  perseant 	int flags;
    541  1.8.4.1  perseant 	char c;
    542  1.8.4.1  perseant 	ssize_t nread;
    543  1.8.4.1  perseant 
    544  1.8.4.1  perseant 	RL(flags = fcntl(readfd, F_GETFL));
    545  1.8.4.1  perseant 	RL(fcntl(readfd, F_SETFL, flags|O_NONBLOCK));
    546  1.8.4.1  perseant 
    547  1.8.4.1  perseant 	RL(nread = read(readfd, &c, 1));
    548  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nread, 0, "nread=%zu", nread);
    549  1.8.4.1  perseant 
    550  1.8.4.1  perseant 	RL(fcntl(readfd, F_SETFL, flags));
    551  1.8.4.1  perseant }
    552  1.8.4.1  perseant 
    553  1.8.4.1  perseant static void
    554  1.8.4.1  perseant check_pollclosed_delayed_write(int writefd, int readfd,
    555  1.8.4.1  perseant     int expected, int writeerror)
    556  1.8.4.1  perseant {
    557  1.8.4.1  perseant 	struct pollfd pfd = { .fd = writefd, .events = POLLOUT };
    558  1.8.4.1  perseant 	struct timespec start, end, delta;
    559  1.8.4.1  perseant 	int nfds;
    560  1.8.4.1  perseant 
    561  1.8.4.1  perseant 	/*
    562  1.8.4.1  perseant 	 * Don't let poll sleep for more than 3sec.  (The close delay
    563  1.8.4.1  perseant 	 * will be 2sec, and we make sure that we sleep at least 1sec.)
    564  1.8.4.1  perseant 	 */
    565  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(3), (unsigned)-1);
    566  1.8.4.1  perseant 
    567  1.8.4.1  perseant 	/*
    568  1.8.4.1  perseant 	 * Wait in poll(2) indefinitely (subject to the alarm) and
    569  1.8.4.1  perseant 	 * measure how long we slept.
    570  1.8.4.1  perseant 	 */
    571  1.8.4.1  perseant 	fprintf(stderr, "poll %d\n", writefd);
    572  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &start));
    573  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, INFTIM));
    574  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &end));
    575  1.8.4.1  perseant 	fprintf(stderr, "poll %d done nfds=%d\n", writefd, nfds);
    576  1.8.4.1  perseant 
    577  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(0), (unsigned)-1);
    578  1.8.4.1  perseant 
    579  1.8.4.1  perseant 	/*
    580  1.8.4.1  perseant 	 * The reader has been closed, so write will fail immediately
    581  1.8.4.1  perseant 	 * with EPIPE/SIGPIPE, and thus POLLOUT must be set.  POLLHUP
    582  1.8.4.1  perseant 	 * is only returned for reads, not for writes (and is mutually
    583  1.8.4.1  perseant 	 * exclusive with POLLOUT).  Except we _do_ return POLLHUP
    584  1.8.4.1  perseant 	 * instead of POLLOUT for terminals.
    585  1.8.4.1  perseant 	 */
    586  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    587  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    588  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d",
    589  1.8.4.1  perseant 	    pfd.fd, writefd);
    590  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), expected,
    591  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    592  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    593  1.8.4.1  perseant 	    pfd.revents, expected, POLLOUT, POLLHUP, POLLIN);
    594  1.8.4.1  perseant 
    595  1.8.4.1  perseant 	/*
    596  1.8.4.1  perseant 	 * We should have slept at least 1sec.
    597  1.8.4.1  perseant 	 */
    598  1.8.4.1  perseant 	timespecsub(&end, &start, &delta);
    599  1.8.4.1  perseant 	ATF_CHECK_MSG(delta.tv_sec >= 1,
    600  1.8.4.1  perseant 	    "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec);
    601  1.8.4.1  perseant 
    602  1.8.4.1  perseant 	/*
    603  1.8.4.1  perseant 	 * Write should fail with EPIPE/SIGPIPE now, or EIO for
    604  1.8.4.1  perseant 	 * terminals -- and continue to do so.
    605  1.8.4.1  perseant 	 */
    606  1.8.4.1  perseant 	check_write_fail(writefd, writeerror);
    607  1.8.4.1  perseant 	check_write_fail(writefd, writeerror);
    608  1.8.4.1  perseant }
    609  1.8.4.1  perseant 
    610  1.8.4.1  perseant static void
    611  1.8.4.1  perseant check_pollclosed_delayed_write_fifopipesocket(int writefd, int readfd)
    612  1.8.4.1  perseant {
    613  1.8.4.1  perseant 
    614  1.8.4.1  perseant 	check_pollclosed_delayed_write(writefd, readfd, POLLOUT, EPIPE);
    615  1.8.4.1  perseant }
    616  1.8.4.1  perseant 
    617  1.8.4.1  perseant static void
    618  1.8.4.1  perseant check_pollclosed_delayed_write_terminal(int writefd, int readfd)
    619  1.8.4.1  perseant {
    620  1.8.4.1  perseant 
    621  1.8.4.1  perseant 	check_pollclosed_delayed_write(writefd, readfd, POLLHUP, EIO);
    622  1.8.4.1  perseant }
    623  1.8.4.1  perseant 
    624  1.8.4.1  perseant static void
    625  1.8.4.1  perseant check_pollclosed_delayed_read(int readfd, int writefd, int pollhup)
    626  1.8.4.1  perseant {
    627  1.8.4.1  perseant 	struct pollfd pfd;
    628  1.8.4.1  perseant 	struct timespec start, end, delta;
    629  1.8.4.1  perseant 	int nfds;
    630  1.8.4.1  perseant 
    631  1.8.4.1  perseant 	/*
    632  1.8.4.1  perseant 	 * Don't let poll sleep for more than 3sec.  (The close delay
    633  1.8.4.1  perseant 	 * will be 2sec, and we make sure that we sleep at least 1sec.)
    634  1.8.4.1  perseant 	 */
    635  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(3), (unsigned)-1);
    636  1.8.4.1  perseant 
    637  1.8.4.1  perseant 	/*
    638  1.8.4.1  perseant 	 * Wait in poll(2) indefinitely (subject to the alarm) and
    639  1.8.4.1  perseant 	 * measure how long we slept.
    640  1.8.4.1  perseant 	 */
    641  1.8.4.1  perseant 	pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
    642  1.8.4.1  perseant 	fprintf(stderr, "poll %d\n", readfd);
    643  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &start));
    644  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, INFTIM));
    645  1.8.4.1  perseant 	RL(clock_gettime(CLOCK_MONOTONIC, &end));
    646  1.8.4.1  perseant 	fprintf(stderr, "poll %d done nfds=%d\n", readfd, nfds);
    647  1.8.4.1  perseant 
    648  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(0), (unsigned)-1);
    649  1.8.4.1  perseant 
    650  1.8.4.1  perseant 	/*
    651  1.8.4.1  perseant 	 * Read will yield EOF without blocking, so POLLIN should be
    652  1.8.4.1  perseant 	 * set, and the write side has been closed, so POLLHUP should
    653  1.8.4.1  perseant 	 * also be set, unsolicited, if this is a pipe or FIFO -- but
    654  1.8.4.1  perseant 	 * not if it's a socket, where POLLHUP is never set.  Since we
    655  1.8.4.1  perseant 	 * didn't ask for POLLOUT, it should be clear.
    656  1.8.4.1  perseant 	 */
    657  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    658  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d",
    659  1.8.4.1  perseant 	    pfd.fd, readfd, writefd);
    660  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    661  1.8.4.1  perseant 	    pollhup|POLLIN,
    662  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    663  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    664  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    665  1.8.4.1  perseant 
    666  1.8.4.1  perseant 	/*
    667  1.8.4.1  perseant 	 * We should have slept at least 1sec.
    668  1.8.4.1  perseant 	 */
    669  1.8.4.1  perseant 	timespecsub(&end, &start, &delta);
    670  1.8.4.1  perseant 	ATF_CHECK_MSG(delta.tv_sec >= 1,
    671  1.8.4.1  perseant 	    "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec);
    672  1.8.4.1  perseant 
    673  1.8.4.1  perseant 	/*
    674  1.8.4.1  perseant 	 * Read should return EOF now -- and continue to do so.
    675  1.8.4.1  perseant 	 */
    676  1.8.4.1  perseant 	check_read_eof(readfd);
    677  1.8.4.1  perseant 	check_read_eof(readfd);
    678  1.8.4.1  perseant 
    679  1.8.4.1  perseant 	/*
    680  1.8.4.1  perseant 	 * POLLHUP|POLLIN state should be persistent (until the writer
    681  1.8.4.1  perseant 	 * side is reopened if possible, as in a named pipe).
    682  1.8.4.1  perseant 	 */
    683  1.8.4.1  perseant 	pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
    684  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    685  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    686  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d",
    687  1.8.4.1  perseant 	    pfd.fd, readfd, writefd);
    688  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    689  1.8.4.1  perseant 	    pollhup|POLLIN,
    690  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    691  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    692  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    693  1.8.4.1  perseant }
    694  1.8.4.1  perseant 
    695  1.8.4.1  perseant static void
    696  1.8.4.1  perseant check_pollclosed_delayed_read_devfifopipe(int readfd, int writefd)
    697  1.8.4.1  perseant {
    698  1.8.4.1  perseant 
    699  1.8.4.1  perseant 	check_pollclosed_delayed_read(readfd, writefd, POLLHUP);
    700  1.8.4.1  perseant }
    701  1.8.4.1  perseant 
    702  1.8.4.1  perseant static void
    703  1.8.4.1  perseant check_pollclosed_delayed_read_socket(int readfd, int writefd)
    704  1.8.4.1  perseant {
    705  1.8.4.1  perseant 
    706  1.8.4.1  perseant 	check_pollclosed_delayed_read(readfd, writefd, /*no POLLHUP*/0);
    707  1.8.4.1  perseant }
    708  1.8.4.1  perseant 
    709  1.8.4.1  perseant static void
    710  1.8.4.1  perseant check_pollclosed_delayed_process(int pollfd, int closefd,
    711  1.8.4.1  perseant     void (*check_pollhup)(int, int))
    712  1.8.4.1  perseant {
    713  1.8.4.1  perseant 	pid_t pid;
    714  1.8.4.1  perseant 	int status;
    715  1.8.4.1  perseant 
    716  1.8.4.1  perseant 	/*
    717  1.8.4.1  perseant 	 * Fork a child to close closefd after a 2sec delay.
    718  1.8.4.1  perseant 	 */
    719  1.8.4.1  perseant 	RL(pid = fork());
    720  1.8.4.1  perseant 	if (pid == 0) {
    721  1.8.4.1  perseant 		sleep(2);
    722  1.8.4.1  perseant 		fprintf(stderr, "[child] close %d\n", closefd);
    723  1.8.4.1  perseant 		if (close(closefd) == -1)
    724  1.8.4.1  perseant 			_exit(1);
    725  1.8.4.1  perseant 		_exit(0);
    726  1.8.4.1  perseant 	}
    727  1.8.4.1  perseant 
    728  1.8.4.1  perseant 	/*
    729  1.8.4.1  perseant 	 * Close closefd in the parent so the child has the last
    730  1.8.4.1  perseant 	 * reference to it.
    731  1.8.4.1  perseant 	 */
    732  1.8.4.1  perseant 	fprintf(stderr, "[parent] close %d\n", closefd);
    733  1.8.4.1  perseant 	RL(close(closefd));
    734  1.8.4.1  perseant 
    735  1.8.4.1  perseant 	/*
    736  1.8.4.1  perseant 	 * Test poll(2).
    737  1.8.4.1  perseant 	 */
    738  1.8.4.1  perseant 	(*check_pollhup)(pollfd, closefd);
    739  1.8.4.1  perseant 
    740  1.8.4.1  perseant 	/*
    741  1.8.4.1  perseant 	 * Wait for the child and make sure it exited successfully.
    742  1.8.4.1  perseant 	 */
    743  1.8.4.1  perseant 	RL(waitpid(pid, &status, 0));
    744  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(status, 0, "child exited with status 0x%x", status);
    745  1.8.4.1  perseant }
    746  1.8.4.1  perseant 
    747  1.8.4.1  perseant static void *
    748  1.8.4.1  perseant check_pollclosed_thread(void *cookie)
    749  1.8.4.1  perseant {
    750  1.8.4.1  perseant 	int *closefdp = cookie;
    751  1.8.4.1  perseant 
    752  1.8.4.1  perseant 	sleep(2);
    753  1.8.4.1  perseant 	fprintf(stderr, "[thread] close %d\n", *closefdp);
    754  1.8.4.1  perseant 	RL(close(*closefdp));
    755  1.8.4.1  perseant 	return NULL;
    756  1.8.4.1  perseant }
    757  1.8.4.1  perseant 
    758  1.8.4.1  perseant static void
    759  1.8.4.1  perseant check_pollclosed_delayed_thread(int pollfd, int closefd,
    760  1.8.4.1  perseant     void (*check_pollhup)(int, int))
    761  1.8.4.1  perseant {
    762  1.8.4.1  perseant 	pthread_t t;
    763  1.8.4.1  perseant 
    764  1.8.4.1  perseant 	/*
    765  1.8.4.1  perseant 	 * Create a thread to close closefd (in this process, not a
    766  1.8.4.1  perseant 	 * child) after a 2sec delay.
    767  1.8.4.1  perseant 	 */
    768  1.8.4.1  perseant 	RZ(pthread_create(&t, NULL, &check_pollclosed_thread, &closefd));
    769  1.8.4.1  perseant 
    770  1.8.4.1  perseant 	/*
    771  1.8.4.1  perseant 	 * Test poll(2).
    772  1.8.4.1  perseant 	 */
    773  1.8.4.1  perseant 	(*check_pollhup)(pollfd, closefd);
    774  1.8.4.1  perseant 
    775  1.8.4.1  perseant 	/*
    776  1.8.4.1  perseant 	 * Wait for the thread to complete.
    777  1.8.4.1  perseant 	 */
    778  1.8.4.1  perseant 	RZ(pthread_join(t, NULL));
    779  1.8.4.1  perseant }
    780  1.8.4.1  perseant 
    781  1.8.4.1  perseant static void
    782  1.8.4.1  perseant check_pollclosed_immediate_write(int writefd, int readfd, int expected,
    783  1.8.4.1  perseant     int writeerror)
    784  1.8.4.1  perseant {
    785  1.8.4.1  perseant 	struct pollfd pfd = { .fd = writefd, .events = POLLOUT };
    786  1.8.4.1  perseant 	int nfds;
    787  1.8.4.1  perseant 
    788  1.8.4.1  perseant 	/*
    789  1.8.4.1  perseant 	 * Close the reader side immediately.
    790  1.8.4.1  perseant 	 */
    791  1.8.4.1  perseant 	fprintf(stderr, "[immediate] close %d\n", readfd);
    792  1.8.4.1  perseant 	RL(close(readfd));
    793  1.8.4.1  perseant 
    794  1.8.4.1  perseant 	/*
    795  1.8.4.1  perseant 	 * The reader has been closed, so write will fail immediately
    796  1.8.4.1  perseant 	 * with EPIPE/SIGPIPE, and thus POLLOUT must be set.  POLLHUP
    797  1.8.4.1  perseant 	 * is only returned for reads, not for writes (and is mutually
    798  1.8.4.1  perseant 	 * exclusive with POLLOUT).  Except we _do_ return POLLHUP
    799  1.8.4.1  perseant 	 * instead of POLLOUT for terminals.
    800  1.8.4.1  perseant 	 */
    801  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    802  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    803  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d",
    804  1.8.4.1  perseant 	    pfd.fd, writefd);
    805  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), expected,
    806  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    807  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    808  1.8.4.1  perseant 	    pfd.revents, expected, POLLOUT, POLLHUP, POLLIN);
    809  1.8.4.1  perseant 
    810  1.8.4.1  perseant 	/*
    811  1.8.4.1  perseant 	 * Write should fail with EPIPE/SIGPIPE now -- and continue to
    812  1.8.4.1  perseant 	 * do so.
    813  1.8.4.1  perseant 	 */
    814  1.8.4.1  perseant 	check_write_fail(writefd, writeerror);
    815  1.8.4.1  perseant 	check_write_fail(writefd, writeerror);
    816  1.8.4.1  perseant }
    817  1.8.4.1  perseant 
    818  1.8.4.1  perseant static void
    819  1.8.4.1  perseant check_pollclosed_immediate_readnone(int readfd, int writefd, int pollhup)
    820  1.8.4.1  perseant {
    821  1.8.4.1  perseant 	struct pollfd pfd = { .fd = readfd, .events = POLLIN };
    822  1.8.4.1  perseant 	int nfds;
    823  1.8.4.1  perseant 
    824  1.8.4.1  perseant 	/*
    825  1.8.4.1  perseant 	 * Close the writer side immediately.
    826  1.8.4.1  perseant 	 */
    827  1.8.4.1  perseant 	fprintf(stderr, "[immediate] close %d\n", writefd);
    828  1.8.4.1  perseant 	RL(close(writefd));
    829  1.8.4.1  perseant 
    830  1.8.4.1  perseant 	/*
    831  1.8.4.1  perseant 	 * Read will yield EOF without blocking, so POLLIN should be
    832  1.8.4.1  perseant 	 * set, and the write side has been closed, so POLLHUP should
    833  1.8.4.1  perseant 	 * be set, unsolicited, if this is a pipe or FIFO -- but not if
    834  1.8.4.1  perseant 	 * it's a socket, where POLLHUP is never set.  Since we didn't
    835  1.8.4.1  perseant 	 * ask for POLLOUT, it should be clear.
    836  1.8.4.1  perseant 	 */
    837  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    838  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    839  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    840  1.8.4.1  perseant 	    pollhup|POLLIN,
    841  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    842  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    843  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    844  1.8.4.1  perseant 
    845  1.8.4.1  perseant 	/*
    846  1.8.4.1  perseant 	 * Read should return EOF now -- and continue to do so.
    847  1.8.4.1  perseant 	 */
    848  1.8.4.1  perseant 	check_read_eof(readfd);
    849  1.8.4.1  perseant 	check_read_eof(readfd);
    850  1.8.4.1  perseant }
    851  1.8.4.1  perseant 
    852  1.8.4.1  perseant static void
    853  1.8.4.1  perseant check_pollclosed_immediate_readsome(int readfd, int writefd, int pollhup)
    854  1.8.4.1  perseant {
    855  1.8.4.1  perseant 	struct pollfd pfd;
    856  1.8.4.1  perseant 	char buf[BUFSIZ];
    857  1.8.4.1  perseant 	ssize_t nread;
    858  1.8.4.1  perseant 	int nfds;
    859  1.8.4.1  perseant 
    860  1.8.4.1  perseant 	/*
    861  1.8.4.1  perseant 	 * Close the writer side immediately.
    862  1.8.4.1  perseant 	 */
    863  1.8.4.1  perseant 	fprintf(stderr, "[immediate] close %d\n", writefd);
    864  1.8.4.1  perseant 	RL(close(writefd));
    865  1.8.4.1  perseant 
    866  1.8.4.1  perseant 	/*
    867  1.8.4.1  perseant 	 * Some data should be ready to read, so POLLIN should be set,
    868  1.8.4.1  perseant 	 * and the write side has been closed, so POLLHUP should also
    869  1.8.4.1  perseant 	 * be set, unsolicited, if this is a pipe or FIFO -- but not if
    870  1.8.4.1  perseant 	 * it's a socket, where POLLHUP is never set.  Since we didn't
    871  1.8.4.1  perseant 	 * ask for POLLOUT, it should be clear.
    872  1.8.4.1  perseant 	 */
    873  1.8.4.1  perseant 	pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
    874  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    875  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    876  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    877  1.8.4.1  perseant 	    pollhup|POLLIN,
    878  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    879  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    880  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    881  1.8.4.1  perseant 
    882  1.8.4.1  perseant 	/*
    883  1.8.4.1  perseant 	 * Read all the data.  Each read should complete instantly --
    884  1.8.4.1  perseant 	 * no blocking, either because there's data to read or because
    885  1.8.4.1  perseant 	 * the writer has hung up and we get EOF.
    886  1.8.4.1  perseant 	 */
    887  1.8.4.1  perseant 	do {
    888  1.8.4.1  perseant 		REQUIRE_LIBC(alarm(1), (unsigned)-1);
    889  1.8.4.1  perseant 		RL(nread = read(readfd, buf, sizeof(buf)));
    890  1.8.4.1  perseant 		REQUIRE_LIBC(alarm(0), (unsigned)-1);
    891  1.8.4.1  perseant 	} while (nread != 0);
    892  1.8.4.1  perseant 
    893  1.8.4.1  perseant 	/*
    894  1.8.4.1  perseant 	 * Read will yield EOF without blocking, so POLLIN should be
    895  1.8.4.1  perseant 	 * set, and the write side has been closed, so POLLHUP should
    896  1.8.4.1  perseant 	 * also be set, unsolicited, if this is a pipe or FIFO -- but
    897  1.8.4.1  perseant 	 * not if it's a socket, where POLLHUP is never set.  Since we
    898  1.8.4.1  perseant 	 * didn't ask for POLLOUT, it should be clear.
    899  1.8.4.1  perseant 	 */
    900  1.8.4.1  perseant 	pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
    901  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    902  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    903  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    904  1.8.4.1  perseant 	    pollhup|POLLIN,
    905  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    906  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    907  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    908  1.8.4.1  perseant 
    909  1.8.4.1  perseant 	/*
    910  1.8.4.1  perseant 	 * Read should return EOF now -- and continue to do so.
    911  1.8.4.1  perseant 	 */
    912  1.8.4.1  perseant 	check_read_eof(readfd);
    913  1.8.4.1  perseant 	check_read_eof(readfd);
    914  1.8.4.1  perseant 
    915  1.8.4.1  perseant 	/*
    916  1.8.4.1  perseant 	 * POLLHUP|POLLIN state should be persistent (until the writer
    917  1.8.4.1  perseant 	 * side is reopened if possible, as in a named pipe).
    918  1.8.4.1  perseant 	 */
    919  1.8.4.1  perseant 	pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
    920  1.8.4.1  perseant 	RL(nfds = poll(&pfd, 1, 0));
    921  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
    922  1.8.4.1  perseant 	ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
    923  1.8.4.1  perseant 	    pollhup|POLLIN,
    924  1.8.4.1  perseant 	    "revents=0x%x expected=0x%x"
    925  1.8.4.1  perseant 	    " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
    926  1.8.4.1  perseant 	    pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
    927  1.8.4.1  perseant }
    928  1.8.4.1  perseant 
    929  1.8.4.1  perseant static void *
    930  1.8.4.1  perseant pollclosed_fifo_writer_thread(void *cookie)
    931  1.8.4.1  perseant {
    932  1.8.4.1  perseant 	int *pp = cookie;
    933  1.8.4.1  perseant 
    934  1.8.4.1  perseant 	RL(*pp = open(fifo_path, O_WRONLY));
    935  1.8.4.1  perseant 	return NULL;
    936  1.8.4.1  perseant }
    937  1.8.4.1  perseant 
    938  1.8.4.1  perseant static void *
    939  1.8.4.1  perseant pollclosed_fifo_reader_thread(void *cookie)
    940  1.8.4.1  perseant {
    941  1.8.4.1  perseant 	int *pp = cookie;
    942  1.8.4.1  perseant 
    943  1.8.4.1  perseant 	RL(*pp = open(fifo_path, O_RDONLY));
    944  1.8.4.1  perseant 	return NULL;
    945  1.8.4.1  perseant }
    946  1.8.4.1  perseant 
    947  1.8.4.1  perseant static void
    948  1.8.4.1  perseant pollclosed_fifo0_setup(int *writefdp, int *readfdp)
    949  1.8.4.1  perseant {
    950  1.8.4.1  perseant 	int p0, p1;
    951  1.8.4.1  perseant 	pthread_t t;
    952  1.8.4.1  perseant 
    953  1.8.4.1  perseant 	fifo_support();
    954  1.8.4.1  perseant 
    955  1.8.4.1  perseant 	RL(mkfifo(fifo_path, 0600));
    956  1.8.4.1  perseant 	RZ(pthread_create(&t, NULL, &pollclosed_fifo_reader_thread, &p0));
    957  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(1), (unsigned)-1);
    958  1.8.4.1  perseant 	RL(p1 = open(fifo_path, O_WRONLY));
    959  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(0), (unsigned)-1);
    960  1.8.4.1  perseant 	RZ(pthread_join(t, NULL));
    961  1.8.4.1  perseant 
    962  1.8.4.1  perseant 	*writefdp = p1;
    963  1.8.4.1  perseant 	*readfdp = p0;
    964  1.8.4.1  perseant }
    965  1.8.4.1  perseant 
    966  1.8.4.1  perseant static void
    967  1.8.4.1  perseant pollclosed_fifo1_setup(int *writefdp, int *readfdp)
    968  1.8.4.1  perseant {
    969  1.8.4.1  perseant 	int p0, p1;
    970  1.8.4.1  perseant 	pthread_t t;
    971  1.8.4.1  perseant 
    972  1.8.4.1  perseant 	fifo_support();
    973  1.8.4.1  perseant 
    974  1.8.4.1  perseant 	RL(mkfifo(fifo_path, 0600));
    975  1.8.4.1  perseant 	RZ(pthread_create(&t, NULL, &pollclosed_fifo_writer_thread, &p0));
    976  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(1), (unsigned)-1);
    977  1.8.4.1  perseant 	RL(p1 = open(fifo_path, O_RDONLY));
    978  1.8.4.1  perseant 	REQUIRE_LIBC(alarm(0), (unsigned)-1);
    979  1.8.4.1  perseant 	RZ(pthread_join(t, NULL));
    980  1.8.4.1  perseant 
    981  1.8.4.1  perseant 	*writefdp = p0;
    982  1.8.4.1  perseant 	*readfdp = p1;
    983  1.8.4.1  perseant }
    984  1.8.4.1  perseant 
    985  1.8.4.1  perseant static void
    986  1.8.4.1  perseant pollclosed_pipe_setup(int *writefdp, int *readfdp)
    987  1.8.4.1  perseant {
    988  1.8.4.1  perseant 	int p[2];
    989  1.8.4.1  perseant 
    990  1.8.4.1  perseant 	RL(pipe(p));
    991  1.8.4.1  perseant 
    992  1.8.4.1  perseant 	*readfdp = p[0];	/* reader side */
    993  1.8.4.1  perseant 	*writefdp = p[1];	/* writer side */
    994  1.8.4.1  perseant }
    995  1.8.4.1  perseant 
    996  1.8.4.1  perseant static void
    997  1.8.4.1  perseant pollclosed_ptyapp_setup(int *writefdp, int *readfdp)
    998  1.8.4.1  perseant {
    999  1.8.4.1  perseant 	int hostfd, appfd;
   1000  1.8.4.1  perseant 	struct termios t;
   1001  1.8.4.1  perseant 	char *pts;
   1002  1.8.4.1  perseant 
   1003  1.8.4.1  perseant 	RL(hostfd = posix_openpt(O_RDWR|O_NOCTTY));
   1004  1.8.4.1  perseant 	RL(grantpt(hostfd));
   1005  1.8.4.1  perseant 	RL(unlockpt(hostfd));
   1006  1.8.4.1  perseant 	REQUIRE_LIBC(pts = ptsname(hostfd), NULL);
   1007  1.8.4.1  perseant 	RL(appfd = open(pts, O_RDWR|O_NOCTTY));
   1008  1.8.4.1  perseant 
   1009  1.8.4.1  perseant 	RL(tcgetattr(appfd, &t));
   1010  1.8.4.1  perseant 	t.c_lflag &= ~ICANON;	/* block rather than drop input */
   1011  1.8.4.1  perseant 	RL(tcsetattr(appfd, TCSANOW, &t));
   1012  1.8.4.1  perseant 
   1013  1.8.4.1  perseant 	*readfdp = appfd;
   1014  1.8.4.1  perseant 	*writefdp = hostfd;
   1015  1.8.4.1  perseant }
   1016  1.8.4.1  perseant 
   1017  1.8.4.1  perseant static void
   1018  1.8.4.1  perseant pollclosed_ptyhost_setup(int *writefdp, int *readfdp)
   1019  1.8.4.1  perseant {
   1020  1.8.4.1  perseant 	int hostfd, appfd;
   1021  1.8.4.1  perseant 	struct termios t;
   1022  1.8.4.1  perseant 	char *pts;
   1023  1.8.4.1  perseant 
   1024  1.8.4.1  perseant 	RL(hostfd = posix_openpt(O_RDWR|O_NOCTTY));
   1025  1.8.4.1  perseant 	RL(grantpt(hostfd));
   1026  1.8.4.1  perseant 	RL(unlockpt(hostfd));
   1027  1.8.4.1  perseant 	REQUIRE_LIBC(pts = ptsname(hostfd), NULL);
   1028  1.8.4.1  perseant 	RL(appfd = open(pts, O_RDWR|O_NOCTTY));
   1029  1.8.4.1  perseant 
   1030  1.8.4.1  perseant 	RL(tcgetattr(appfd, &t));
   1031  1.8.4.1  perseant 	t.c_lflag &= ~ICANON;	/* block rather than drop input */
   1032  1.8.4.1  perseant 	RL(tcsetattr(appfd, TCSANOW, &t));
   1033  1.8.4.1  perseant 
   1034  1.8.4.1  perseant 	*writefdp = appfd;
   1035  1.8.4.1  perseant 	*readfdp = hostfd;
   1036  1.8.4.1  perseant }
   1037  1.8.4.1  perseant 
   1038  1.8.4.1  perseant static void
   1039  1.8.4.1  perseant pollclosed_socketpair0_setup(int *writefdp, int *readfdp)
   1040  1.8.4.1  perseant {
   1041  1.8.4.1  perseant 	int s[2];
   1042  1.8.4.1  perseant 
   1043  1.8.4.1  perseant 	RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s));
   1044  1.8.4.1  perseant 	*readfdp = s[0];
   1045  1.8.4.1  perseant 	*writefdp = s[1];
   1046  1.8.4.1  perseant }
   1047  1.8.4.1  perseant 
   1048  1.8.4.1  perseant static void
   1049  1.8.4.1  perseant pollclosed_socketpair1_setup(int *writefdp, int *readfdp)
   1050  1.8.4.1  perseant {
   1051  1.8.4.1  perseant 	int s[2];
   1052  1.8.4.1  perseant 
   1053  1.8.4.1  perseant 	RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s));
   1054  1.8.4.1  perseant 	*readfdp = s[1];
   1055  1.8.4.1  perseant 	*writefdp = s[0];
   1056  1.8.4.1  perseant }
   1057  1.8.4.1  perseant 
   1058  1.8.4.1  perseant /*
   1059  1.8.4.1  perseant  * Cartesian product of:
   1060  1.8.4.1  perseant  *
   1061  1.8.4.1  perseant  * 1. [fifo0] first fifo opener
   1062  1.8.4.1  perseant  * 2. [fifo1] second fifo opener
   1063  1.8.4.1  perseant  * 3. [pipe] pipe
   1064  1.8.4.1  perseant  * 4. [ptyhost] host side of pty
   1065  1.8.4.1  perseant  * 5. [ptyapp] application side of pty
   1066  1.8.4.1  perseant  * 6. [socketpair0] first side of socket pair
   1067  1.8.4.1  perseant  * 7. [socketpair1] second side of socket pair
   1068  1.8.4.1  perseant  *
   1069  1.8.4.1  perseant  * with
   1070  1.8.4.1  perseant  *
   1071  1.8.4.1  perseant  * 1. [immediate] closed before poll starts
   1072  1.8.4.1  perseant  * 2. [delayed_thread] closed by another thread after poll starts
   1073  1.8.4.1  perseant  * 3. [delayed_process] closed by another process after poll starts
   1074  1.8.4.1  perseant  *
   1075  1.8.4.1  perseant  * with
   1076  1.8.4.1  perseant  *
   1077  1.8.4.1  perseant  * 1. [writefull] close reader, poll for write when buffer full
   1078  1.8.4.1  perseant  * 2. [writeempty] close reader, poll for write when buffer empty
   1079  1.8.4.1  perseant  * 3. [readnone] close writer, poll for read when nothing to read
   1080  1.8.4.1  perseant  * 4. [readsome] close writer, poll for read when something to read
   1081  1.8.4.1  perseant  *
   1082  1.8.4.1  perseant  * except that in the delayed cases we only do writefull [write] and
   1083  1.8.4.1  perseant  * readnone [read], because there's no delay in the writeempty/readsome
   1084  1.8.4.1  perseant  * cases.
   1085  1.8.4.1  perseant  */
   1086  1.8.4.1  perseant 
   1087  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_immediate_writefull);
   1088  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_immediate_writefull, tc)
   1089  1.8.4.1  perseant {
   1090  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1091  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1092  1.8.4.1  perseant }
   1093  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_immediate_writefull, tc)
   1094  1.8.4.1  perseant {
   1095  1.8.4.1  perseant 	int writefd, readfd;
   1096  1.8.4.1  perseant 
   1097  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd);
   1098  1.8.4.1  perseant 	fillpipebuf(writefd);
   1099  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1100  1.8.4.1  perseant }
   1101  1.8.4.1  perseant 
   1102  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_immediate_writeempty);
   1103  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_immediate_writeempty, tc)
   1104  1.8.4.1  perseant {
   1105  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1106  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1107  1.8.4.1  perseant }
   1108  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_immediate_writeempty, tc)
   1109  1.8.4.1  perseant {
   1110  1.8.4.1  perseant 	int writefd, readfd;
   1111  1.8.4.1  perseant 
   1112  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd);
   1113  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1114  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1115  1.8.4.1  perseant }
   1116  1.8.4.1  perseant 
   1117  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_immediate_readsome);
   1118  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_immediate_readsome, tc)
   1119  1.8.4.1  perseant {
   1120  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1121  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1122  1.8.4.1  perseant }
   1123  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_immediate_readsome, tc)
   1124  1.8.4.1  perseant {
   1125  1.8.4.1  perseant 	int writefd, readfd;
   1126  1.8.4.1  perseant 
   1127  1.8.4.1  perseant 	/*
   1128  1.8.4.1  perseant 	 * poll(2) returns nothing, when it is supposed to return
   1129  1.8.4.1  perseant 	 * POLLHUP|POLLIN.
   1130  1.8.4.1  perseant 	 */
   1131  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1132  1.8.4.1  perseant 
   1133  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */
   1134  1.8.4.1  perseant 	fillpipebuf(writefd);
   1135  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
   1136  1.8.4.1  perseant }
   1137  1.8.4.1  perseant 
   1138  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_immediate_readnone);
   1139  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_immediate_readnone, tc)
   1140  1.8.4.1  perseant {
   1141  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1142  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1143  1.8.4.1  perseant }
   1144  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_immediate_readnone, tc)
   1145  1.8.4.1  perseant {
   1146  1.8.4.1  perseant 	int writefd, readfd;
   1147  1.8.4.1  perseant 
   1148  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */
   1149  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1150  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
   1151  1.8.4.1  perseant }
   1152  1.8.4.1  perseant 
   1153  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_delayed_process_write);
   1154  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_delayed_process_write, tc)
   1155  1.8.4.1  perseant {
   1156  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1157  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1158  1.8.4.1  perseant }
   1159  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_delayed_process_write, tc)
   1160  1.8.4.1  perseant {
   1161  1.8.4.1  perseant 	int writefd, readfd;
   1162  1.8.4.1  perseant 
   1163  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd);
   1164  1.8.4.1  perseant 	fillpipebuf(writefd);
   1165  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1166  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1167  1.8.4.1  perseant }
   1168  1.8.4.1  perseant 
   1169  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_delayed_process_read);
   1170  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_delayed_process_read, tc)
   1171  1.8.4.1  perseant {
   1172  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1173  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1174  1.8.4.1  perseant }
   1175  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_delayed_process_read, tc)
   1176  1.8.4.1  perseant {
   1177  1.8.4.1  perseant 	int writefd, readfd;
   1178  1.8.4.1  perseant 
   1179  1.8.4.1  perseant 	/*
   1180  1.8.4.1  perseant 	 * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't
   1181  1.8.4.1  perseant 	 * persistent as it is supposed to be -- it returns nothing
   1182  1.8.4.1  perseant 	 * after that.
   1183  1.8.4.1  perseant 	 */
   1184  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1185  1.8.4.1  perseant 
   1186  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */
   1187  1.8.4.1  perseant 	/* don't fill pipe buf */
   1188  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1189  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1190  1.8.4.1  perseant }
   1191  1.8.4.1  perseant 
   1192  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_delayed_thread_write);
   1193  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_write, tc)
   1194  1.8.4.1  perseant {
   1195  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1196  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1197  1.8.4.1  perseant }
   1198  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_delayed_thread_write, tc)
   1199  1.8.4.1  perseant {
   1200  1.8.4.1  perseant 	int writefd, readfd;
   1201  1.8.4.1  perseant 
   1202  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd);
   1203  1.8.4.1  perseant 	fillpipebuf(writefd);
   1204  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1205  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1206  1.8.4.1  perseant }
   1207  1.8.4.1  perseant 
   1208  1.8.4.1  perseant ATF_TC(pollclosed_fifo0_delayed_thread_read);
   1209  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_read, tc)
   1210  1.8.4.1  perseant {
   1211  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1212  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first opener of a named pipe");
   1213  1.8.4.1  perseant }
   1214  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo0_delayed_thread_read, tc)
   1215  1.8.4.1  perseant {
   1216  1.8.4.1  perseant 	int writefd, readfd;
   1217  1.8.4.1  perseant 
   1218  1.8.4.1  perseant 	/*
   1219  1.8.4.1  perseant 	 * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't
   1220  1.8.4.1  perseant 	 * persistent as it is supposed to be -- it returns nothing
   1221  1.8.4.1  perseant 	 * after that.
   1222  1.8.4.1  perseant 	 */
   1223  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1224  1.8.4.1  perseant 
   1225  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */
   1226  1.8.4.1  perseant 	/* don't fill pipe buf */
   1227  1.8.4.1  perseant 	check_pollclosed_delayed_thread(readfd, writefd,
   1228  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1229  1.8.4.1  perseant }
   1230  1.8.4.1  perseant 
   1231  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_immediate_writefull);
   1232  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_immediate_writefull, tc)
   1233  1.8.4.1  perseant {
   1234  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1235  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1236  1.8.4.1  perseant }
   1237  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_immediate_writefull, tc)
   1238  1.8.4.1  perseant {
   1239  1.8.4.1  perseant 	int writefd, readfd;
   1240  1.8.4.1  perseant 
   1241  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd);
   1242  1.8.4.1  perseant 	fillpipebuf(writefd);
   1243  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1244  1.8.4.1  perseant }
   1245  1.8.4.1  perseant 
   1246  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_immediate_writeempty);
   1247  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_immediate_writeempty, tc)
   1248  1.8.4.1  perseant {
   1249  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1250  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1251  1.8.4.1  perseant }
   1252  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_immediate_writeempty, tc)
   1253  1.8.4.1  perseant {
   1254  1.8.4.1  perseant 	int writefd, readfd;
   1255  1.8.4.1  perseant 
   1256  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd);
   1257  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1258  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1259  1.8.4.1  perseant }
   1260  1.8.4.1  perseant 
   1261  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_immediate_readsome);
   1262  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_immediate_readsome, tc)
   1263  1.8.4.1  perseant {
   1264  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1265  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1266  1.8.4.1  perseant }
   1267  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_immediate_readsome, tc)
   1268  1.8.4.1  perseant {
   1269  1.8.4.1  perseant 	int writefd, readfd;
   1270  1.8.4.1  perseant 
   1271  1.8.4.1  perseant 	/*
   1272  1.8.4.1  perseant 	 * poll(2) returns nothing, when it is supposed to return
   1273  1.8.4.1  perseant 	 * POLLHUP|POLLIN.
   1274  1.8.4.1  perseant 	 */
   1275  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1276  1.8.4.1  perseant 
   1277  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */
   1278  1.8.4.1  perseant 	fillpipebuf(writefd);
   1279  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
   1280  1.8.4.1  perseant }
   1281  1.8.4.1  perseant 
   1282  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_immediate_readnone);
   1283  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_immediate_readnone, tc)
   1284  1.8.4.1  perseant {
   1285  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1286  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1287  1.8.4.1  perseant }
   1288  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_immediate_readnone, tc)
   1289  1.8.4.1  perseant {
   1290  1.8.4.1  perseant 	int writefd, readfd;
   1291  1.8.4.1  perseant 
   1292  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */
   1293  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1294  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
   1295  1.8.4.1  perseant }
   1296  1.8.4.1  perseant 
   1297  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_delayed_process_write);
   1298  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_delayed_process_write, tc)
   1299  1.8.4.1  perseant {
   1300  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1301  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1302  1.8.4.1  perseant }
   1303  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_delayed_process_write, tc)
   1304  1.8.4.1  perseant {
   1305  1.8.4.1  perseant 	int writefd, readfd;
   1306  1.8.4.1  perseant 
   1307  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd);
   1308  1.8.4.1  perseant 	fillpipebuf(writefd);
   1309  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1310  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1311  1.8.4.1  perseant }
   1312  1.8.4.1  perseant 
   1313  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_delayed_process_read);
   1314  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_delayed_process_read, tc)
   1315  1.8.4.1  perseant {
   1316  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1317  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1318  1.8.4.1  perseant }
   1319  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_delayed_process_read, tc)
   1320  1.8.4.1  perseant {
   1321  1.8.4.1  perseant 	int writefd, readfd;
   1322  1.8.4.1  perseant 
   1323  1.8.4.1  perseant 	/*
   1324  1.8.4.1  perseant 	 * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't
   1325  1.8.4.1  perseant 	 * persistent as it is supposed to be -- it returns nothing
   1326  1.8.4.1  perseant 	 * after that.
   1327  1.8.4.1  perseant 	 */
   1328  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1329  1.8.4.1  perseant 
   1330  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */
   1331  1.8.4.1  perseant 	/* don't fill pipe buf */
   1332  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1333  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1334  1.8.4.1  perseant }
   1335  1.8.4.1  perseant 
   1336  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_delayed_thread_write);
   1337  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_write, tc)
   1338  1.8.4.1  perseant {
   1339  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1340  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1341  1.8.4.1  perseant }
   1342  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_delayed_thread_write, tc)
   1343  1.8.4.1  perseant {
   1344  1.8.4.1  perseant 	int writefd, readfd;
   1345  1.8.4.1  perseant 
   1346  1.8.4.1  perseant 	pollclosed_fifo1_setup(&writefd, &readfd);
   1347  1.8.4.1  perseant 	fillpipebuf(writefd);
   1348  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1349  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1350  1.8.4.1  perseant }
   1351  1.8.4.1  perseant 
   1352  1.8.4.1  perseant ATF_TC(pollclosed_fifo1_delayed_thread_read);
   1353  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_read, tc)
   1354  1.8.4.1  perseant {
   1355  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1356  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second opener of a named pipe");
   1357  1.8.4.1  perseant }
   1358  1.8.4.1  perseant ATF_TC_BODY(pollclosed_fifo1_delayed_thread_read, tc)
   1359  1.8.4.1  perseant {
   1360  1.8.4.1  perseant 	int writefd, readfd;
   1361  1.8.4.1  perseant 
   1362  1.8.4.1  perseant 	/*
   1363  1.8.4.1  perseant 	 * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't
   1364  1.8.4.1  perseant 	 * persistent as it is supposed to be -- it returns nothing
   1365  1.8.4.1  perseant 	 * after that.
   1366  1.8.4.1  perseant 	 */
   1367  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1368  1.8.4.1  perseant 
   1369  1.8.4.1  perseant 	pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */
   1370  1.8.4.1  perseant 	/* don't fill pipe buf */
   1371  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1372  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1373  1.8.4.1  perseant }
   1374  1.8.4.1  perseant 
   1375  1.8.4.1  perseant ATF_TC(pollclosed_pipe_immediate_writefull);
   1376  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_immediate_writefull, tc)
   1377  1.8.4.1  perseant {
   1378  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1379  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1380  1.8.4.1  perseant }
   1381  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_immediate_writefull, tc)
   1382  1.8.4.1  perseant {
   1383  1.8.4.1  perseant 	int writefd, readfd;
   1384  1.8.4.1  perseant 
   1385  1.8.4.1  perseant 	/*
   1386  1.8.4.1  perseant 	 * poll(2) returns POLLHUP|POLLOUT, which is forbidden --
   1387  1.8.4.1  perseant 	 * POLLHUP and POLLOUT are mutually exclusive.  And POLLHUP is
   1388  1.8.4.1  perseant 	 * only supposed to be returned by polling for read, not
   1389  1.8.4.1  perseant 	 * polling for write.  So it should be POLLOUT.
   1390  1.8.4.1  perseant 	 */
   1391  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1392  1.8.4.1  perseant 
   1393  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1394  1.8.4.1  perseant 	fillpipebuf(writefd);
   1395  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1396  1.8.4.1  perseant }
   1397  1.8.4.1  perseant 
   1398  1.8.4.1  perseant ATF_TC(pollclosed_pipe_immediate_writeempty);
   1399  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_immediate_writeempty, tc)
   1400  1.8.4.1  perseant {
   1401  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1402  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1403  1.8.4.1  perseant }
   1404  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_immediate_writeempty, tc)
   1405  1.8.4.1  perseant {
   1406  1.8.4.1  perseant 	int writefd, readfd;
   1407  1.8.4.1  perseant 
   1408  1.8.4.1  perseant 	/*
   1409  1.8.4.1  perseant 	 * poll(2) returns POLLHUP|POLLOUT, which is forbidden --
   1410  1.8.4.1  perseant 	 * POLLHUP and POLLOUT are mutually exclusive.  And POLLHUP is
   1411  1.8.4.1  perseant 	 * only supposed to be returned by polling for read, not
   1412  1.8.4.1  perseant 	 * polling for write.  So it should be POLLOUT.
   1413  1.8.4.1  perseant 	 */
   1414  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1415  1.8.4.1  perseant 
   1416  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1417  1.8.4.1  perseant 	/* don't fill pipe buf */
   1418  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1419  1.8.4.1  perseant }
   1420  1.8.4.1  perseant 
   1421  1.8.4.1  perseant ATF_TC(pollclosed_pipe_immediate_readsome);
   1422  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_immediate_readsome, tc)
   1423  1.8.4.1  perseant {
   1424  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1425  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1426  1.8.4.1  perseant }
   1427  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_immediate_readsome, tc)
   1428  1.8.4.1  perseant {
   1429  1.8.4.1  perseant 	int writefd, readfd;
   1430  1.8.4.1  perseant 
   1431  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1432  1.8.4.1  perseant 	fillpipebuf(writefd);
   1433  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
   1434  1.8.4.1  perseant }
   1435  1.8.4.1  perseant 
   1436  1.8.4.1  perseant ATF_TC(pollclosed_pipe_immediate_readnone);
   1437  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_immediate_readnone, tc)
   1438  1.8.4.1  perseant {
   1439  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1440  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1441  1.8.4.1  perseant }
   1442  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_immediate_readnone, tc)
   1443  1.8.4.1  perseant {
   1444  1.8.4.1  perseant 	int writefd, readfd;
   1445  1.8.4.1  perseant 
   1446  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1447  1.8.4.1  perseant 	/* don't fill pipe buf */
   1448  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
   1449  1.8.4.1  perseant }
   1450  1.8.4.1  perseant 
   1451  1.8.4.1  perseant ATF_TC(pollclosed_pipe_delayed_process_write);
   1452  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_delayed_process_write, tc)
   1453  1.8.4.1  perseant {
   1454  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1455  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1456  1.8.4.1  perseant }
   1457  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_delayed_process_write, tc)
   1458  1.8.4.1  perseant {
   1459  1.8.4.1  perseant 	int writefd, readfd;
   1460  1.8.4.1  perseant 
   1461  1.8.4.1  perseant 	/*
   1462  1.8.4.1  perseant 	 * poll(2) returns POLLHUP|POLLOUT, which is forbidden --
   1463  1.8.4.1  perseant 	 * POLLHUP and POLLOUT are mutually exclusive.  And POLLHUP is
   1464  1.8.4.1  perseant 	 * only supposed to be returned by polling for read, not
   1465  1.8.4.1  perseant 	 * polling for write.  So it should be POLLOUT.
   1466  1.8.4.1  perseant 	 */
   1467  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1468  1.8.4.1  perseant 
   1469  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1470  1.8.4.1  perseant 	fillpipebuf(writefd);
   1471  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1472  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1473  1.8.4.1  perseant }
   1474  1.8.4.1  perseant 
   1475  1.8.4.1  perseant ATF_TC(pollclosed_pipe_delayed_process_read);
   1476  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_delayed_process_read, tc)
   1477  1.8.4.1  perseant {
   1478  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1479  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1480  1.8.4.1  perseant }
   1481  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_delayed_process_read, tc)
   1482  1.8.4.1  perseant {
   1483  1.8.4.1  perseant 	int writefd, readfd;
   1484  1.8.4.1  perseant 
   1485  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1486  1.8.4.1  perseant 	/* don't fill pipe buf */
   1487  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1488  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1489  1.8.4.1  perseant }
   1490  1.8.4.1  perseant 
   1491  1.8.4.1  perseant ATF_TC(pollclosed_pipe_delayed_thread_write);
   1492  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_delayed_thread_write, tc)
   1493  1.8.4.1  perseant {
   1494  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1495  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1496  1.8.4.1  perseant }
   1497  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_delayed_thread_write, tc)
   1498  1.8.4.1  perseant {
   1499  1.8.4.1  perseant 	int writefd, readfd;
   1500  1.8.4.1  perseant 
   1501  1.8.4.1  perseant 	/*
   1502  1.8.4.1  perseant 	 * poll(2) returns POLLHUP|POLLOUT, which is forbidden --
   1503  1.8.4.1  perseant 	 * POLLHUP and POLLOUT are mutually exclusive.  And POLLHUP is
   1504  1.8.4.1  perseant 	 * only supposed to be returned by polling for read, not
   1505  1.8.4.1  perseant 	 * polling for write.  So it should be POLLOUT.
   1506  1.8.4.1  perseant 	 */
   1507  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1508  1.8.4.1  perseant 
   1509  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1510  1.8.4.1  perseant 	fillpipebuf(writefd);
   1511  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1512  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1513  1.8.4.1  perseant }
   1514  1.8.4.1  perseant 
   1515  1.8.4.1  perseant ATF_TC(pollclosed_pipe_delayed_thread_read);
   1516  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_pipe_delayed_thread_read, tc)
   1517  1.8.4.1  perseant {
   1518  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1519  1.8.4.1  perseant 	    "Checks POLLHUP with a closed pipe");
   1520  1.8.4.1  perseant }
   1521  1.8.4.1  perseant ATF_TC_BODY(pollclosed_pipe_delayed_thread_read, tc)
   1522  1.8.4.1  perseant {
   1523  1.8.4.1  perseant 	int writefd, readfd;
   1524  1.8.4.1  perseant 
   1525  1.8.4.1  perseant 	pollclosed_pipe_setup(&writefd, &readfd);
   1526  1.8.4.1  perseant 	/* don't fill pipe buf */
   1527  1.8.4.1  perseant 	check_pollclosed_delayed_thread(readfd, writefd,
   1528  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1529  1.8.4.1  perseant }
   1530  1.8.4.1  perseant 
   1531  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_immediate_writefull);
   1532  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_immediate_writefull, tc)
   1533  1.8.4.1  perseant {
   1534  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1535  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1536  1.8.4.1  perseant }
   1537  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_immediate_writefull, tc)
   1538  1.8.4.1  perseant {
   1539  1.8.4.1  perseant 	int writefd, readfd;
   1540  1.8.4.1  perseant 
   1541  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd);
   1542  1.8.4.1  perseant 	fillpipebuf(writefd);
   1543  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO);
   1544  1.8.4.1  perseant }
   1545  1.8.4.1  perseant 
   1546  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_immediate_writeempty);
   1547  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_immediate_writeempty, tc)
   1548  1.8.4.1  perseant {
   1549  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1550  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1551  1.8.4.1  perseant }
   1552  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_immediate_writeempty, tc)
   1553  1.8.4.1  perseant {
   1554  1.8.4.1  perseant 	int writefd, readfd;
   1555  1.8.4.1  perseant 
   1556  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd);
   1557  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1558  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO);
   1559  1.8.4.1  perseant }
   1560  1.8.4.1  perseant 
   1561  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_immediate_readsome);
   1562  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_immediate_readsome, tc)
   1563  1.8.4.1  perseant {
   1564  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1565  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1566  1.8.4.1  perseant }
   1567  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_immediate_readsome, tc)
   1568  1.8.4.1  perseant {
   1569  1.8.4.1  perseant 	int writefd, readfd;
   1570  1.8.4.1  perseant 
   1571  1.8.4.1  perseant 	/*
   1572  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1573  1.8.4.1  perseant 	 * would return EOF without blocking.
   1574  1.8.4.1  perseant 	 */
   1575  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1576  1.8.4.1  perseant 
   1577  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */
   1578  1.8.4.1  perseant 	fillpipebuf(writefd);
   1579  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
   1580  1.8.4.1  perseant }
   1581  1.8.4.1  perseant 
   1582  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_immediate_readnone);
   1583  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_immediate_readnone, tc)
   1584  1.8.4.1  perseant {
   1585  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1586  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1587  1.8.4.1  perseant }
   1588  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_immediate_readnone, tc)
   1589  1.8.4.1  perseant {
   1590  1.8.4.1  perseant 	int writefd, readfd;
   1591  1.8.4.1  perseant 
   1592  1.8.4.1  perseant 	/*
   1593  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1594  1.8.4.1  perseant 	 * would return EOF without blocking.
   1595  1.8.4.1  perseant 	 */
   1596  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1597  1.8.4.1  perseant 
   1598  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */
   1599  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1600  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
   1601  1.8.4.1  perseant }
   1602  1.8.4.1  perseant 
   1603  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_delayed_process_write);
   1604  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_delayed_process_write, tc)
   1605  1.8.4.1  perseant {
   1606  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1607  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1608  1.8.4.1  perseant }
   1609  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_delayed_process_write, tc)
   1610  1.8.4.1  perseant {
   1611  1.8.4.1  perseant 	int writefd, readfd;
   1612  1.8.4.1  perseant 
   1613  1.8.4.1  perseant 	/*
   1614  1.8.4.1  perseant 	 * The poll(2) call is not woken by the concurrent close(2)
   1615  1.8.4.1  perseant 	 * call.
   1616  1.8.4.1  perseant 	 */
   1617  1.8.4.1  perseant 	atf_tc_expect_signal(SIGALRM, "PR kern/59056: poll POLLHUP bugs");
   1618  1.8.4.1  perseant 
   1619  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd);
   1620  1.8.4.1  perseant 	fillpipebuf(writefd);
   1621  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1622  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_terminal);
   1623  1.8.4.1  perseant }
   1624  1.8.4.1  perseant 
   1625  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_delayed_process_read);
   1626  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_delayed_process_read, tc)
   1627  1.8.4.1  perseant {
   1628  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1629  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1630  1.8.4.1  perseant }
   1631  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_delayed_process_read, tc)
   1632  1.8.4.1  perseant {
   1633  1.8.4.1  perseant 	int writefd, readfd;
   1634  1.8.4.1  perseant 
   1635  1.8.4.1  perseant 	/*
   1636  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1637  1.8.4.1  perseant 	 * would return EOF without blocking.
   1638  1.8.4.1  perseant 	 */
   1639  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1640  1.8.4.1  perseant 
   1641  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */
   1642  1.8.4.1  perseant 	/* don't fill pipe buf */
   1643  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1644  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1645  1.8.4.1  perseant }
   1646  1.8.4.1  perseant 
   1647  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_delayed_thread_write);
   1648  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_delayed_thread_write, tc)
   1649  1.8.4.1  perseant {
   1650  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1651  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1652  1.8.4.1  perseant }
   1653  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_delayed_thread_write, tc)
   1654  1.8.4.1  perseant {
   1655  1.8.4.1  perseant 	int writefd, readfd;
   1656  1.8.4.1  perseant 
   1657  1.8.4.1  perseant 	/*
   1658  1.8.4.1  perseant 	 * The poll(2) call is not woken by the concurrent close(2)
   1659  1.8.4.1  perseant 	 * call.
   1660  1.8.4.1  perseant 	 */
   1661  1.8.4.1  perseant 	atf_tc_expect_signal(SIGALRM, "PR kern/59056: poll POLLHUP bugs");
   1662  1.8.4.1  perseant 
   1663  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd);
   1664  1.8.4.1  perseant 	fillpipebuf(writefd);
   1665  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1666  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_terminal);
   1667  1.8.4.1  perseant }
   1668  1.8.4.1  perseant 
   1669  1.8.4.1  perseant ATF_TC(pollclosed_ptyapp_delayed_thread_read);
   1670  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyapp_delayed_thread_read, tc)
   1671  1.8.4.1  perseant {
   1672  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1673  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty application side");
   1674  1.8.4.1  perseant }
   1675  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyapp_delayed_thread_read, tc)
   1676  1.8.4.1  perseant {
   1677  1.8.4.1  perseant 	int writefd, readfd;
   1678  1.8.4.1  perseant 
   1679  1.8.4.1  perseant 	/*
   1680  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1681  1.8.4.1  perseant 	 * would return EOF without blocking.
   1682  1.8.4.1  perseant 	 */
   1683  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1684  1.8.4.1  perseant 
   1685  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */
   1686  1.8.4.1  perseant 	/* don't fill pipe buf */
   1687  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1688  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1689  1.8.4.1  perseant }
   1690  1.8.4.1  perseant 
   1691  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_immediate_writefull);
   1692  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_immediate_writefull, tc)
   1693  1.8.4.1  perseant {
   1694  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1695  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1696  1.8.4.1  perseant }
   1697  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_immediate_writefull, tc)
   1698  1.8.4.1  perseant {
   1699  1.8.4.1  perseant 	int writefd, readfd;
   1700  1.8.4.1  perseant 
   1701  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd);
   1702  1.8.4.1  perseant 	fillpipebuf(writefd);
   1703  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO);
   1704  1.8.4.1  perseant }
   1705  1.8.4.1  perseant 
   1706  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_immediate_writeempty);
   1707  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_immediate_writeempty, tc)
   1708  1.8.4.1  perseant {
   1709  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1710  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1711  1.8.4.1  perseant }
   1712  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_immediate_writeempty, tc)
   1713  1.8.4.1  perseant {
   1714  1.8.4.1  perseant 	int writefd, readfd;
   1715  1.8.4.1  perseant 
   1716  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd);
   1717  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1718  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO);
   1719  1.8.4.1  perseant }
   1720  1.8.4.1  perseant 
   1721  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_immediate_readsome);
   1722  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_immediate_readsome, tc)
   1723  1.8.4.1  perseant {
   1724  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1725  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1726  1.8.4.1  perseant }
   1727  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_immediate_readsome, tc)
   1728  1.8.4.1  perseant {
   1729  1.8.4.1  perseant 	int writefd, readfd;
   1730  1.8.4.1  perseant 
   1731  1.8.4.1  perseant 	/*
   1732  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1733  1.8.4.1  perseant 	 * would return EOF without blocking.
   1734  1.8.4.1  perseant 	 */
   1735  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1736  1.8.4.1  perseant 
   1737  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */
   1738  1.8.4.1  perseant 	fillpipebuf(writefd);
   1739  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
   1740  1.8.4.1  perseant }
   1741  1.8.4.1  perseant 
   1742  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_immediate_readnone);
   1743  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_immediate_readnone, tc)
   1744  1.8.4.1  perseant {
   1745  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1746  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1747  1.8.4.1  perseant }
   1748  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_immediate_readnone, tc)
   1749  1.8.4.1  perseant {
   1750  1.8.4.1  perseant 	int writefd, readfd;
   1751  1.8.4.1  perseant 
   1752  1.8.4.1  perseant 	/*
   1753  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1754  1.8.4.1  perseant 	 * would return EOF without blocking.
   1755  1.8.4.1  perseant 	 */
   1756  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1757  1.8.4.1  perseant 
   1758  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */
   1759  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1760  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
   1761  1.8.4.1  perseant }
   1762  1.8.4.1  perseant 
   1763  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_delayed_process_write);
   1764  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_delayed_process_write, tc)
   1765  1.8.4.1  perseant {
   1766  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1767  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1768  1.8.4.1  perseant }
   1769  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_delayed_process_write, tc)
   1770  1.8.4.1  perseant {
   1771  1.8.4.1  perseant 	int writefd, readfd;
   1772  1.8.4.1  perseant 
   1773  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd);
   1774  1.8.4.1  perseant 	fillpipebuf(writefd);
   1775  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1776  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_terminal);
   1777  1.8.4.1  perseant }
   1778  1.8.4.1  perseant 
   1779  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_delayed_process_read);
   1780  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_delayed_process_read, tc)
   1781  1.8.4.1  perseant {
   1782  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1783  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1784  1.8.4.1  perseant }
   1785  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_delayed_process_read, tc)
   1786  1.8.4.1  perseant {
   1787  1.8.4.1  perseant 	int writefd, readfd;
   1788  1.8.4.1  perseant 
   1789  1.8.4.1  perseant 	/*
   1790  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1791  1.8.4.1  perseant 	 * would return EOF without blocking.
   1792  1.8.4.1  perseant 	 */
   1793  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1794  1.8.4.1  perseant 
   1795  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */
   1796  1.8.4.1  perseant 	/* don't fill pipe buf */
   1797  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1798  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1799  1.8.4.1  perseant }
   1800  1.8.4.1  perseant 
   1801  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_delayed_thread_write);
   1802  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_delayed_thread_write, tc)
   1803  1.8.4.1  perseant {
   1804  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1805  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1806  1.8.4.1  perseant }
   1807  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_delayed_thread_write, tc)
   1808  1.8.4.1  perseant {
   1809  1.8.4.1  perseant 	int writefd, readfd;
   1810  1.8.4.1  perseant 
   1811  1.8.4.1  perseant 	pollclosed_ptyhost_setup(&writefd, &readfd);
   1812  1.8.4.1  perseant 	fillpipebuf(writefd);
   1813  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1814  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_terminal);
   1815  1.8.4.1  perseant }
   1816  1.8.4.1  perseant 
   1817  1.8.4.1  perseant ATF_TC(pollclosed_ptyhost_delayed_thread_read);
   1818  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_ptyhost_delayed_thread_read, tc)
   1819  1.8.4.1  perseant {
   1820  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1821  1.8.4.1  perseant 	    "Checks POLLHUP with closing the pty host side");
   1822  1.8.4.1  perseant }
   1823  1.8.4.1  perseant ATF_TC_BODY(pollclosed_ptyhost_delayed_thread_read, tc)
   1824  1.8.4.1  perseant {
   1825  1.8.4.1  perseant 	int writefd, readfd;
   1826  1.8.4.1  perseant 
   1827  1.8.4.1  perseant 	/*
   1828  1.8.4.1  perseant 	 * poll(2) returns POLLHUP but not POLLIN even though read(2)
   1829  1.8.4.1  perseant 	 * would return EOF without blocking.
   1830  1.8.4.1  perseant 	 */
   1831  1.8.4.1  perseant 	atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
   1832  1.8.4.1  perseant 
   1833  1.8.4.1  perseant 	pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */
   1834  1.8.4.1  perseant 	/* don't fill pipe buf */
   1835  1.8.4.1  perseant 	check_pollclosed_delayed_thread(readfd, writefd,
   1836  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_devfifopipe);
   1837  1.8.4.1  perseant }
   1838  1.8.4.1  perseant 
   1839  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_immediate_writefull);
   1840  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_immediate_writefull, tc)
   1841  1.8.4.1  perseant {
   1842  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1843  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1844  1.8.4.1  perseant }
   1845  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_immediate_writefull, tc)
   1846  1.8.4.1  perseant {
   1847  1.8.4.1  perseant 	int writefd, readfd;
   1848  1.8.4.1  perseant 
   1849  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd);
   1850  1.8.4.1  perseant 	fillpipebuf(writefd);
   1851  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1852  1.8.4.1  perseant }
   1853  1.8.4.1  perseant 
   1854  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_immediate_writeempty);
   1855  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_immediate_writeempty, tc)
   1856  1.8.4.1  perseant {
   1857  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1858  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1859  1.8.4.1  perseant }
   1860  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_immediate_writeempty, tc)
   1861  1.8.4.1  perseant {
   1862  1.8.4.1  perseant 	int writefd, readfd;
   1863  1.8.4.1  perseant 
   1864  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd);
   1865  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1866  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1867  1.8.4.1  perseant }
   1868  1.8.4.1  perseant 
   1869  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_immediate_readsome);
   1870  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_immediate_readsome, tc)
   1871  1.8.4.1  perseant {
   1872  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1873  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1874  1.8.4.1  perseant }
   1875  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_immediate_readsome, tc)
   1876  1.8.4.1  perseant {
   1877  1.8.4.1  perseant 	int writefd, readfd;
   1878  1.8.4.1  perseant 
   1879  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */
   1880  1.8.4.1  perseant 	fillpipebuf(writefd);
   1881  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0);
   1882  1.8.4.1  perseant }
   1883  1.8.4.1  perseant 
   1884  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_immediate_readnone);
   1885  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_immediate_readnone, tc)
   1886  1.8.4.1  perseant {
   1887  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1888  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1889  1.8.4.1  perseant }
   1890  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_immediate_readnone, tc)
   1891  1.8.4.1  perseant {
   1892  1.8.4.1  perseant 	int writefd, readfd;
   1893  1.8.4.1  perseant 
   1894  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */
   1895  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1896  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0);
   1897  1.8.4.1  perseant }
   1898  1.8.4.1  perseant 
   1899  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_delayed_process_write);
   1900  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_write, tc)
   1901  1.8.4.1  perseant {
   1902  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1903  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1904  1.8.4.1  perseant }
   1905  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_delayed_process_write, tc)
   1906  1.8.4.1  perseant {
   1907  1.8.4.1  perseant 	int writefd, readfd;
   1908  1.8.4.1  perseant 
   1909  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd);
   1910  1.8.4.1  perseant 	fillpipebuf(writefd);
   1911  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   1912  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1913  1.8.4.1  perseant }
   1914  1.8.4.1  perseant 
   1915  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_delayed_process_read);
   1916  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_read, tc)
   1917  1.8.4.1  perseant {
   1918  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1919  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1920  1.8.4.1  perseant }
   1921  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_delayed_process_read, tc)
   1922  1.8.4.1  perseant {
   1923  1.8.4.1  perseant 	int writefd, readfd;
   1924  1.8.4.1  perseant 
   1925  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */
   1926  1.8.4.1  perseant 	/* don't fill pipe buf */
   1927  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   1928  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_socket);
   1929  1.8.4.1  perseant }
   1930  1.8.4.1  perseant 
   1931  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_delayed_thread_write);
   1932  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_write, tc)
   1933  1.8.4.1  perseant {
   1934  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1935  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1936  1.8.4.1  perseant }
   1937  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_write, tc)
   1938  1.8.4.1  perseant {
   1939  1.8.4.1  perseant 	int writefd, readfd;
   1940  1.8.4.1  perseant 
   1941  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd);
   1942  1.8.4.1  perseant 	fillpipebuf(writefd);
   1943  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   1944  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   1945  1.8.4.1  perseant }
   1946  1.8.4.1  perseant 
   1947  1.8.4.1  perseant ATF_TC(pollclosed_socketpair0_delayed_thread_read);
   1948  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_read, tc)
   1949  1.8.4.1  perseant {
   1950  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1951  1.8.4.1  perseant 	    "Checks POLLHUP with closing the first half of a socketpair");
   1952  1.8.4.1  perseant }
   1953  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_read, tc)
   1954  1.8.4.1  perseant {
   1955  1.8.4.1  perseant 	int writefd, readfd;
   1956  1.8.4.1  perseant 
   1957  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */
   1958  1.8.4.1  perseant 	/* don't fill pipe buf */
   1959  1.8.4.1  perseant 	check_pollclosed_delayed_thread(readfd, writefd,
   1960  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_socket);
   1961  1.8.4.1  perseant }
   1962  1.8.4.1  perseant 
   1963  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_immediate_writefull);
   1964  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_immediate_writefull, tc)
   1965  1.8.4.1  perseant {
   1966  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1967  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   1968  1.8.4.1  perseant }
   1969  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_immediate_writefull, tc)
   1970  1.8.4.1  perseant {
   1971  1.8.4.1  perseant 	int writefd, readfd;
   1972  1.8.4.1  perseant 
   1973  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd);
   1974  1.8.4.1  perseant 	fillpipebuf(writefd);
   1975  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1976  1.8.4.1  perseant }
   1977  1.8.4.1  perseant 
   1978  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_immediate_writeempty);
   1979  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_immediate_writeempty, tc)
   1980  1.8.4.1  perseant {
   1981  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1982  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   1983  1.8.4.1  perseant }
   1984  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_immediate_writeempty, tc)
   1985  1.8.4.1  perseant {
   1986  1.8.4.1  perseant 	int writefd, readfd;
   1987  1.8.4.1  perseant 
   1988  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd);
   1989  1.8.4.1  perseant 	/* don't fill the pipe buf */
   1990  1.8.4.1  perseant 	check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE);
   1991  1.8.4.1  perseant }
   1992  1.8.4.1  perseant 
   1993  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_immediate_readsome);
   1994  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_immediate_readsome, tc)
   1995  1.8.4.1  perseant {
   1996  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   1997  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   1998  1.8.4.1  perseant }
   1999  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_immediate_readsome, tc)
   2000  1.8.4.1  perseant {
   2001  1.8.4.1  perseant 	int writefd, readfd;
   2002  1.8.4.1  perseant 
   2003  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */
   2004  1.8.4.1  perseant 	fillpipebuf(writefd);
   2005  1.8.4.1  perseant 	check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0);
   2006  1.8.4.1  perseant }
   2007  1.8.4.1  perseant 
   2008  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_immediate_readnone);
   2009  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_immediate_readnone, tc)
   2010  1.8.4.1  perseant {
   2011  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   2012  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   2013  1.8.4.1  perseant }
   2014  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_immediate_readnone, tc)
   2015  1.8.4.1  perseant {
   2016  1.8.4.1  perseant 	int writefd, readfd;
   2017  1.8.4.1  perseant 
   2018  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */
   2019  1.8.4.1  perseant 	/* don't fill the pipe buf */
   2020  1.8.4.1  perseant 	check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0);
   2021  1.8.4.1  perseant }
   2022  1.8.4.1  perseant 
   2023  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_delayed_process_write);
   2024  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_write, tc)
   2025  1.8.4.1  perseant {
   2026  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   2027  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   2028  1.8.4.1  perseant }
   2029  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_delayed_process_write, tc)
   2030  1.8.4.1  perseant {
   2031  1.8.4.1  perseant 	int writefd, readfd;
   2032  1.8.4.1  perseant 
   2033  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd);
   2034  1.8.4.1  perseant 	fillpipebuf(writefd);
   2035  1.8.4.1  perseant 	check_pollclosed_delayed_process(writefd, readfd,
   2036  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   2037  1.8.4.1  perseant }
   2038  1.8.4.1  perseant 
   2039  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_delayed_process_read);
   2040  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_read, tc)
   2041  1.8.4.1  perseant {
   2042  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   2043  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   2044  1.8.4.1  perseant }
   2045  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_delayed_process_read, tc)
   2046  1.8.4.1  perseant {
   2047  1.8.4.1  perseant 	int writefd, readfd;
   2048  1.8.4.1  perseant 
   2049  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */
   2050  1.8.4.1  perseant 	/* don't fill pipe buf */
   2051  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   2052  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_socket);
   2053  1.8.4.1  perseant }
   2054  1.8.4.1  perseant 
   2055  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_delayed_thread_write);
   2056  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_write, tc)
   2057  1.8.4.1  perseant {
   2058  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   2059  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   2060  1.8.4.1  perseant }
   2061  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_write, tc)
   2062  1.8.4.1  perseant {
   2063  1.8.4.1  perseant 	int writefd, readfd;
   2064  1.8.4.1  perseant 
   2065  1.8.4.1  perseant 	pollclosed_socketpair1_setup(&writefd, &readfd);
   2066  1.8.4.1  perseant 	fillpipebuf(writefd);
   2067  1.8.4.1  perseant 	check_pollclosed_delayed_thread(writefd, readfd,
   2068  1.8.4.1  perseant 	    &check_pollclosed_delayed_write_fifopipesocket);
   2069  1.8.4.1  perseant }
   2070  1.8.4.1  perseant 
   2071  1.8.4.1  perseant ATF_TC(pollclosed_socketpair1_delayed_thread_read);
   2072  1.8.4.1  perseant ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_read, tc)
   2073  1.8.4.1  perseant {
   2074  1.8.4.1  perseant 	atf_tc_set_md_var(tc, "descr",
   2075  1.8.4.1  perseant 	    "Checks POLLHUP with closing the second half of a socketpair");
   2076  1.8.4.1  perseant }
   2077  1.8.4.1  perseant ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_read, tc)
   2078  1.8.4.1  perseant {
   2079  1.8.4.1  perseant 	int writefd, readfd;
   2080  1.8.4.1  perseant 
   2081  1.8.4.1  perseant 	pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */
   2082  1.8.4.1  perseant 	/* don't fill pipe buf */
   2083  1.8.4.1  perseant 	check_pollclosed_delayed_process(readfd, writefd,
   2084  1.8.4.1  perseant 	    &check_pollclosed_delayed_read_socket);
   2085  1.8.4.1  perseant }
   2086  1.8.4.1  perseant 
   2087  1.8.4.1  perseant ATF_TP_ADD_TCS(tp)
   2088  1.8.4.1  perseant {
   2089  1.8.4.1  perseant 
   2090  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, 3way);
   2091  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, basic);
   2092  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, err);
   2093  1.8.4.1  perseant 
   2094  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, fifo_inout);
   2095  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, fifo_hup1);
   2096  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, fifo_hup2);
   2097  1.8.4.1  perseant 
   2098  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writefull);
   2099  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writefull);
   2100  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writefull);
   2101  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_writefull);
   2102  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_writefull);
   2103  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writefull);
   2104  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writefull);
   2105  1.8.4.1  perseant 
   2106  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writeempty);
   2107  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writeempty);
   2108  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writeempty);
   2109  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_writeempty);
   2110  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_writeempty);
   2111  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writeempty);
   2112  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writeempty);
   2113  1.8.4.1  perseant 
   2114  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readsome);
   2115  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readsome);
   2116  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readsome);
   2117  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_readsome);
   2118  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_readsome);
   2119  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readsome);
   2120  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readsome);
   2121  1.8.4.1  perseant 
   2122  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readnone);
   2123  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readnone);
   2124  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readnone);
   2125  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_readnone);
   2126  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_readnone);
   2127  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readnone);
   2128  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readnone);
   2129  1.8.4.1  perseant 
   2130  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_write);
   2131  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_write);
   2132  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_write);
   2133  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_process_write);
   2134  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_process_write);
   2135  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_write);
   2136  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_write);
   2137  1.8.4.1  perseant 
   2138  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_read);
   2139  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_read);
   2140  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_read);
   2141  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_process_read);
   2142  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_process_read);
   2143  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_read);
   2144  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_read);
   2145  1.8.4.1  perseant 
   2146  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_write);
   2147  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_write);
   2148  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_write);
   2149  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_thread_write);
   2150  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_thread_write);
   2151  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_write);
   2152  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_write);
   2153  1.8.4.1  perseant 
   2154  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_read);
   2155  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_read);
   2156  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_read);
   2157  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_thread_read);
   2158  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_thread_read);
   2159  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_read);
   2160  1.8.4.1  perseant 	ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_read);
   2161      1.5   thorpej 
   2162      1.1    jruoho 	return atf_no_error();
   2163      1.1    jruoho }
   2164