1 1.12 riastrad /* $NetBSD: t_poll.c,v 1.12 2025/02/10 02:41:34 riastradh 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.12 riastrad #include <sys/ioctl.h> 33 1.11 riastrad #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.11 riastrad #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.12 riastrad #include <termios.h> 48 1.1 jruoho #include <unistd.h> 49 1.1 jruoho 50 1.11 riastrad #include "h_macros.h" 51 1.11 riastrad 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.10 riastrad ssize_t nwrit; 111 1.2 jruoho 112 1.10 riastrad RL(pipe(pf)); 113 1.2 jruoho desc = pf[0]; 114 1.2 jruoho 115 1.10 riastrad RL(pid = fork()); 116 1.2 jruoho if (pid == 0) { 117 1.10 riastrad if (close(pf[1]) == -1) 118 1.10 riastrad _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.10 riastrad RL(pid = fork()); 125 1.2 jruoho if (pid == 0) { 126 1.10 riastrad if (close(pf[1]) == -1) 127 1.10 riastrad _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.10 riastrad RL(pid = fork()); 134 1.2 jruoho if (pid == 0) { 135 1.10 riastrad if (close(pf[1]) == -1) 136 1.10 riastrad _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.10 riastrad RL(nwrit = write(pf[1], "konec\n", 6)); 147 1.10 riastrad ATF_REQUIRE_EQ_MSG(nwrit, 6, "nwrit=%zd", nwrit); 148 1.2 jruoho 149 1.10 riastrad for (i = 0; i < 3; i++) 150 1.10 riastrad 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.10 riastrad ssize_t nwrit; 169 1.1 jruoho 170 1.10 riastrad 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.10 riastrad RL(ret = poll(&pfds[0], 1, 1)); 184 1.10 riastrad 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.10 riastrad RL(ret = poll(&pfds[1], 1, 1)); 192 1.10 riastrad 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.10 riastrad RL(ret = poll(pfds, 2, 1)); 201 1.10 riastrad 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.10 riastrad RL(nwrit = write(fds[1], "", 1)); 208 1.10 riastrad 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.10 riastrad RL(ret = poll(pfds, 2, 1)); 214 1.10 riastrad 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.10 riastrad RL(close(fds[0])); 221 1.10 riastrad 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.10 riastrad 251 1.5 thorpej errno = 0; 252 1.5 thorpej if (mkfifo(fifo_path, 0600) == 0) { 253 1.10 riastrad 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.10 riastrad int ret; 278 1.10 riastrad ssize_t nwrit, nread; 279 1.7 thorpej 280 1.7 thorpej fifo_support(); 281 1.7 thorpej 282 1.10 riastrad RL(mkfifo(fifo_path, 0600)); 283 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)); 284 1.10 riastrad 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.10 riastrad ATF_REQUIRE_MSG(pipe_buf > 1, "pipe_buf=%ld", pipe_buf); 289 1.7 thorpej 290 1.10 riastrad 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.10 riastrad RL(ret = poll(pfd, 2, 0)); 300 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 301 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0, 302 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents); 303 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM, 304 1.10 riastrad "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.10 riastrad RL(nwrit = write(wfd, buf, 1)); 308 1.10 riastrad 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.10 riastrad RL(ret = poll(pfd, 2, 0)); 312 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret); 313 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM, 314 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents); 315 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM, 316 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents); 317 1.7 thorpej 318 1.7 thorpej /* Read that single byte back out. */ 319 1.10 riastrad RL(nread = read(rfd, buf, 1)); 320 1.10 riastrad 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.10 riastrad 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.10 riastrad RL(ret = poll(pfd, 2, 0)); 334 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 335 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM, 336 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents); 337 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0, 338 1.10 riastrad "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.10 riastrad RL(nread = read(rfd, buf, 1)); 342 1.10 riastrad 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.10 riastrad RL(ret = poll(pfd, 2, 0)); 350 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 351 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM, 352 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents); 353 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0, 354 1.10 riastrad "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.10 riastrad RL(nread = read(rfd, buf, pipe_buf - 1)); 362 1.10 riastrad ATF_REQUIRE_EQ_MSG(nread, pipe_buf - 1, "nread=%zd pipe_buf-1=%ld", 363 1.10 riastrad nread, pipe_buf - 1); 364 1.10 riastrad RL(ret = poll(pfd, 2, 0)); 365 1.10 riastrad ATF_REQUIRE_MSG(ret >= 1, "got: %d", ret); 366 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM, 367 1.10 riastrad "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.10 riastrad ATF_REQUIRE_EQ_MSG(errno, EAGAIN, "errno=%d", errno); 377 1.7 thorpej 378 1.10 riastrad RL(ret = poll(pfd, 2, 0)); 379 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 380 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0, 381 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents); 382 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM, 383 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents); 384 1.7 thorpej 385 1.10 riastrad RL(close(wfd)); 386 1.10 riastrad 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.10 riastrad int ret; 406 1.5 thorpej 407 1.5 thorpej fifo_support(); 408 1.5 thorpej 409 1.10 riastrad RL(mkfifo(fifo_path, 0600)); 410 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)); 411 1.10 riastrad 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.10 riastrad RL(close(wfd)); 418 1.5 thorpej 419 1.10 riastrad RL(ret = poll(&pfd, 1, 0)); 420 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 421 1.9 riastrad ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP, 422 1.11 riastrad "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x", 423 1.9 riastrad 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.10 riastrad RL(wfd = open(fifo_path, O_WRONLY)); 435 1.10 riastrad RL(ret = poll(&pfd, 1, 0)); 436 1.10 riastrad 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.10 riastrad int ret; 458 1.5 thorpej 459 1.5 thorpej fifo_support(); 460 1.5 thorpej 461 1.10 riastrad RL(mkfifo(fifo_path, 0600)); 462 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)); 463 1.10 riastrad 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.10 riastrad RL(pid = fork()); 470 1.5 thorpej if (pid == 0) { 471 1.10 riastrad if (close(rfd)) 472 1.10 riastrad _exit(1); 473 1.5 thorpej sleep(5); 474 1.10 riastrad if (close(wfd)) 475 1.10 riastrad _exit(1); 476 1.5 thorpej _exit(0); 477 1.5 thorpej } 478 1.10 riastrad RL(close(wfd)); 479 1.5 thorpej 480 1.10 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &ts1)); 481 1.10 riastrad RL(ret = poll(&pfd, 1, INFTIM)); 482 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); 483 1.10 riastrad 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.10 riastrad ATF_REQUIRE_MSG(ts2.tv_sec - ts1.tv_sec >= 2, 487 1.10 riastrad "ts1=%lld.%09ld ts2=%lld.%09ld", 488 1.10 riastrad (long long)ts1.tv_sec, ts1.tv_nsec, 489 1.10 riastrad (long long)ts2.tv_sec, ts2.tv_nsec); 490 1.5 thorpej 491 1.9 riastrad ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP, 492 1.11 riastrad "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x", 493 1.9 riastrad 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.11 riastrad static void 502 1.11 riastrad fillpipebuf(int writefd) 503 1.11 riastrad { 504 1.11 riastrad char buf[BUFSIZ] = {0}; 505 1.11 riastrad size_t n = 0; 506 1.11 riastrad ssize_t nwrit; 507 1.11 riastrad int flags; 508 1.11 riastrad 509 1.11 riastrad RL(flags = fcntl(writefd, F_GETFL)); 510 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK)); 511 1.11 riastrad while ((nwrit = write(writefd, buf, sizeof(buf))) != -1) 512 1.11 riastrad n += (size_t)nwrit; 513 1.11 riastrad ATF_CHECK_EQ_MSG(errno, EAGAIN, "errno=%d", errno); 514 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags)); 515 1.11 riastrad fprintf(stderr, "filled %d with %zu bytes\n", writefd, n); 516 1.11 riastrad } 517 1.11 riastrad 518 1.11 riastrad static void 519 1.12 riastrad check_write_fail(int writefd, int error) 520 1.11 riastrad { 521 1.11 riastrad int flags; 522 1.11 riastrad void (*sighandler)(int); 523 1.11 riastrad char c = 0; 524 1.11 riastrad ssize_t nwrit; 525 1.11 riastrad 526 1.11 riastrad RL(flags = fcntl(writefd, F_GETFL)); 527 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK)); 528 1.11 riastrad 529 1.11 riastrad REQUIRE_LIBC(sighandler = signal(SIGPIPE, SIG_IGN), SIG_ERR); 530 1.12 riastrad ATF_CHECK_ERRNO(error, (nwrit = write(writefd, &c, 1)) == -1); 531 1.11 riastrad ATF_CHECK_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit); 532 1.11 riastrad REQUIRE_LIBC(signal(SIGPIPE, sighandler), SIG_ERR); 533 1.11 riastrad 534 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags)); 535 1.11 riastrad } 536 1.11 riastrad 537 1.11 riastrad static void 538 1.11 riastrad check_read_eof(int readfd) 539 1.11 riastrad { 540 1.11 riastrad int flags; 541 1.11 riastrad char c; 542 1.11 riastrad ssize_t nread; 543 1.11 riastrad 544 1.11 riastrad RL(flags = fcntl(readfd, F_GETFL)); 545 1.11 riastrad RL(fcntl(readfd, F_SETFL, flags|O_NONBLOCK)); 546 1.11 riastrad 547 1.11 riastrad RL(nread = read(readfd, &c, 1)); 548 1.11 riastrad ATF_CHECK_EQ_MSG(nread, 0, "nread=%zu", nread); 549 1.11 riastrad 550 1.11 riastrad RL(fcntl(readfd, F_SETFL, flags)); 551 1.11 riastrad } 552 1.11 riastrad 553 1.11 riastrad static void 554 1.12 riastrad check_pollclosed_delayed_write(int writefd, int readfd, 555 1.12 riastrad int expected, int writeerror) 556 1.11 riastrad { 557 1.11 riastrad struct pollfd pfd = { .fd = writefd, .events = POLLOUT }; 558 1.11 riastrad struct timespec start, end, delta; 559 1.11 riastrad int nfds; 560 1.11 riastrad 561 1.11 riastrad /* 562 1.11 riastrad * Don't let poll sleep for more than 3sec. (The close delay 563 1.11 riastrad * will be 2sec, and we make sure that we sleep at least 1sec.) 564 1.11 riastrad */ 565 1.11 riastrad REQUIRE_LIBC(alarm(3), (unsigned)-1); 566 1.11 riastrad 567 1.11 riastrad /* 568 1.11 riastrad * Wait in poll(2) indefinitely (subject to the alarm) and 569 1.11 riastrad * measure how long we slept. 570 1.11 riastrad */ 571 1.11 riastrad fprintf(stderr, "poll %d\n", writefd); 572 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &start)); 573 1.11 riastrad RL(nfds = poll(&pfd, 1, INFTIM)); 574 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &end)); 575 1.11 riastrad fprintf(stderr, "poll %d done nfds=%d\n", writefd, nfds); 576 1.11 riastrad 577 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1); 578 1.11 riastrad 579 1.11 riastrad /* 580 1.11 riastrad * The reader has been closed, so write will fail immediately 581 1.11 riastrad * with EPIPE/SIGPIPE, and thus POLLOUT must be set. POLLHUP 582 1.11 riastrad * is only returned for reads, not for writes (and is mutually 583 1.12 riastrad * exclusive with POLLOUT). Except we _do_ return POLLHUP 584 1.12 riastrad * instead of POLLOUT for terminals. 585 1.11 riastrad */ 586 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 587 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 588 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d", 589 1.11 riastrad pfd.fd, writefd); 590 1.12 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), expected, 591 1.12 riastrad "revents=0x%x expected=0x%x" 592 1.12 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 593 1.12 riastrad pfd.revents, expected, POLLOUT, POLLHUP, POLLIN); 594 1.11 riastrad 595 1.11 riastrad /* 596 1.11 riastrad * We should have slept at least 1sec. 597 1.11 riastrad */ 598 1.11 riastrad timespecsub(&end, &start, &delta); 599 1.11 riastrad ATF_CHECK_MSG(delta.tv_sec >= 1, 600 1.11 riastrad "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec); 601 1.11 riastrad 602 1.11 riastrad /* 603 1.12 riastrad * Write should fail with EPIPE/SIGPIPE now, or EIO for 604 1.12 riastrad * terminals -- and continue to do so. 605 1.11 riastrad */ 606 1.12 riastrad check_write_fail(writefd, writeerror); 607 1.12 riastrad check_write_fail(writefd, writeerror); 608 1.12 riastrad } 609 1.12 riastrad 610 1.12 riastrad static void 611 1.12 riastrad check_pollclosed_delayed_write_fifopipesocket(int writefd, int readfd) 612 1.12 riastrad { 613 1.12 riastrad 614 1.12 riastrad check_pollclosed_delayed_write(writefd, readfd, POLLOUT, EPIPE); 615 1.12 riastrad } 616 1.12 riastrad 617 1.12 riastrad static void 618 1.12 riastrad check_pollclosed_delayed_write_terminal(int writefd, int readfd) 619 1.12 riastrad { 620 1.12 riastrad 621 1.12 riastrad check_pollclosed_delayed_write(writefd, readfd, POLLHUP, EIO); 622 1.11 riastrad } 623 1.11 riastrad 624 1.11 riastrad static void 625 1.11 riastrad check_pollclosed_delayed_read(int readfd, int writefd, int pollhup) 626 1.11 riastrad { 627 1.11 riastrad struct pollfd pfd; 628 1.11 riastrad struct timespec start, end, delta; 629 1.11 riastrad int nfds; 630 1.11 riastrad 631 1.11 riastrad /* 632 1.11 riastrad * Don't let poll sleep for more than 3sec. (The close delay 633 1.11 riastrad * will be 2sec, and we make sure that we sleep at least 1sec.) 634 1.11 riastrad */ 635 1.11 riastrad REQUIRE_LIBC(alarm(3), (unsigned)-1); 636 1.11 riastrad 637 1.11 riastrad /* 638 1.11 riastrad * Wait in poll(2) indefinitely (subject to the alarm) and 639 1.11 riastrad * measure how long we slept. 640 1.11 riastrad */ 641 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN }; 642 1.11 riastrad fprintf(stderr, "poll %d\n", readfd); 643 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &start)); 644 1.11 riastrad RL(nfds = poll(&pfd, 1, INFTIM)); 645 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &end)); 646 1.11 riastrad fprintf(stderr, "poll %d done nfds=%d\n", readfd, nfds); 647 1.11 riastrad 648 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1); 649 1.11 riastrad 650 1.11 riastrad /* 651 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be 652 1.11 riastrad * set, and the write side has been closed, so POLLHUP should 653 1.11 riastrad * also be set, unsolicited, if this is a pipe or FIFO -- but 654 1.11 riastrad * not if it's a socket, where POLLHUP is never set. Since we 655 1.11 riastrad * didn't ask for POLLOUT, it should be clear. 656 1.11 riastrad */ 657 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 658 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d", 659 1.11 riastrad pfd.fd, readfd, writefd); 660 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 661 1.11 riastrad pollhup|POLLIN, 662 1.11 riastrad "revents=0x%x expected=0x%x" 663 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 664 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 665 1.11 riastrad 666 1.11 riastrad /* 667 1.11 riastrad * We should have slept at least 1sec. 668 1.11 riastrad */ 669 1.11 riastrad timespecsub(&end, &start, &delta); 670 1.11 riastrad ATF_CHECK_MSG(delta.tv_sec >= 1, 671 1.11 riastrad "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec); 672 1.11 riastrad 673 1.11 riastrad /* 674 1.11 riastrad * Read should return EOF now -- and continue to do so. 675 1.11 riastrad */ 676 1.11 riastrad check_read_eof(readfd); 677 1.11 riastrad check_read_eof(readfd); 678 1.11 riastrad 679 1.11 riastrad /* 680 1.11 riastrad * POLLHUP|POLLIN state should be persistent (until the writer 681 1.11 riastrad * side is reopened if possible, as in a named pipe). 682 1.11 riastrad */ 683 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN }; 684 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 685 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 686 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d", 687 1.11 riastrad pfd.fd, readfd, writefd); 688 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 689 1.11 riastrad pollhup|POLLIN, 690 1.11 riastrad "revents=0x%x expected=0x%x" 691 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 692 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 693 1.11 riastrad } 694 1.11 riastrad 695 1.11 riastrad static void 696 1.12 riastrad check_pollclosed_delayed_read_devfifopipe(int readfd, int writefd) 697 1.11 riastrad { 698 1.11 riastrad 699 1.11 riastrad check_pollclosed_delayed_read(readfd, writefd, POLLHUP); 700 1.11 riastrad } 701 1.11 riastrad 702 1.11 riastrad static void 703 1.11 riastrad check_pollclosed_delayed_read_socket(int readfd, int writefd) 704 1.11 riastrad { 705 1.11 riastrad 706 1.11 riastrad check_pollclosed_delayed_read(readfd, writefd, /*no POLLHUP*/0); 707 1.11 riastrad } 708 1.11 riastrad 709 1.11 riastrad static void 710 1.11 riastrad check_pollclosed_delayed_process(int pollfd, int closefd, 711 1.11 riastrad void (*check_pollhup)(int, int)) 712 1.11 riastrad { 713 1.11 riastrad pid_t pid; 714 1.11 riastrad int status; 715 1.11 riastrad 716 1.11 riastrad /* 717 1.11 riastrad * Fork a child to close closefd after a 2sec delay. 718 1.11 riastrad */ 719 1.11 riastrad RL(pid = fork()); 720 1.11 riastrad if (pid == 0) { 721 1.11 riastrad sleep(2); 722 1.11 riastrad fprintf(stderr, "[child] close %d\n", closefd); 723 1.11 riastrad if (close(closefd) == -1) 724 1.11 riastrad _exit(1); 725 1.11 riastrad _exit(0); 726 1.11 riastrad } 727 1.11 riastrad 728 1.11 riastrad /* 729 1.11 riastrad * Close closefd in the parent so the child has the last 730 1.11 riastrad * reference to it. 731 1.11 riastrad */ 732 1.11 riastrad fprintf(stderr, "[parent] close %d\n", closefd); 733 1.11 riastrad RL(close(closefd)); 734 1.11 riastrad 735 1.11 riastrad /* 736 1.11 riastrad * Test poll(2). 737 1.11 riastrad */ 738 1.11 riastrad (*check_pollhup)(pollfd, closefd); 739 1.11 riastrad 740 1.11 riastrad /* 741 1.11 riastrad * Wait for the child and make sure it exited successfully. 742 1.11 riastrad */ 743 1.11 riastrad RL(waitpid(pid, &status, 0)); 744 1.11 riastrad ATF_CHECK_EQ_MSG(status, 0, "child exited with status 0x%x", status); 745 1.11 riastrad } 746 1.11 riastrad 747 1.11 riastrad static void * 748 1.11 riastrad check_pollclosed_thread(void *cookie) 749 1.11 riastrad { 750 1.11 riastrad int *closefdp = cookie; 751 1.11 riastrad 752 1.11 riastrad sleep(2); 753 1.11 riastrad fprintf(stderr, "[thread] close %d\n", *closefdp); 754 1.11 riastrad RL(close(*closefdp)); 755 1.11 riastrad return NULL; 756 1.11 riastrad } 757 1.11 riastrad 758 1.11 riastrad static void 759 1.11 riastrad check_pollclosed_delayed_thread(int pollfd, int closefd, 760 1.11 riastrad void (*check_pollhup)(int, int)) 761 1.11 riastrad { 762 1.11 riastrad pthread_t t; 763 1.11 riastrad 764 1.11 riastrad /* 765 1.11 riastrad * Create a thread to close closefd (in this process, not a 766 1.11 riastrad * child) after a 2sec delay. 767 1.11 riastrad */ 768 1.11 riastrad RZ(pthread_create(&t, NULL, &check_pollclosed_thread, &closefd)); 769 1.11 riastrad 770 1.11 riastrad /* 771 1.11 riastrad * Test poll(2). 772 1.11 riastrad */ 773 1.11 riastrad (*check_pollhup)(pollfd, closefd); 774 1.11 riastrad 775 1.11 riastrad /* 776 1.11 riastrad * Wait for the thread to complete. 777 1.11 riastrad */ 778 1.11 riastrad RZ(pthread_join(t, NULL)); 779 1.11 riastrad } 780 1.11 riastrad 781 1.11 riastrad static void 782 1.12 riastrad check_pollclosed_immediate_write(int writefd, int readfd, int expected, 783 1.12 riastrad int writeerror) 784 1.11 riastrad { 785 1.11 riastrad struct pollfd pfd = { .fd = writefd, .events = POLLOUT }; 786 1.11 riastrad int nfds; 787 1.11 riastrad 788 1.11 riastrad /* 789 1.11 riastrad * Close the reader side immediately. 790 1.11 riastrad */ 791 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", readfd); 792 1.11 riastrad RL(close(readfd)); 793 1.11 riastrad 794 1.11 riastrad /* 795 1.11 riastrad * The reader has been closed, so write will fail immediately 796 1.11 riastrad * with EPIPE/SIGPIPE, and thus POLLOUT must be set. POLLHUP 797 1.11 riastrad * is only returned for reads, not for writes (and is mutually 798 1.12 riastrad * exclusive with POLLOUT). Except we _do_ return POLLHUP 799 1.12 riastrad * instead of POLLOUT for terminals. 800 1.11 riastrad */ 801 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 802 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 803 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d", 804 1.11 riastrad pfd.fd, writefd); 805 1.12 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), expected, 806 1.12 riastrad "revents=0x%x expected=0x%x" 807 1.12 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 808 1.12 riastrad pfd.revents, expected, POLLOUT, POLLHUP, POLLIN); 809 1.11 riastrad 810 1.11 riastrad /* 811 1.11 riastrad * Write should fail with EPIPE/SIGPIPE now -- and continue to 812 1.11 riastrad * do so. 813 1.11 riastrad */ 814 1.12 riastrad check_write_fail(writefd, writeerror); 815 1.12 riastrad check_write_fail(writefd, writeerror); 816 1.11 riastrad } 817 1.11 riastrad 818 1.11 riastrad static void 819 1.11 riastrad check_pollclosed_immediate_readnone(int readfd, int writefd, int pollhup) 820 1.11 riastrad { 821 1.11 riastrad struct pollfd pfd = { .fd = readfd, .events = POLLIN }; 822 1.11 riastrad int nfds; 823 1.11 riastrad 824 1.11 riastrad /* 825 1.11 riastrad * Close the writer side immediately. 826 1.11 riastrad */ 827 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", writefd); 828 1.11 riastrad RL(close(writefd)); 829 1.11 riastrad 830 1.11 riastrad /* 831 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be 832 1.11 riastrad * set, and the write side has been closed, so POLLHUP should 833 1.11 riastrad * be set, unsolicited, if this is a pipe or FIFO -- but not if 834 1.11 riastrad * it's a socket, where POLLHUP is never set. Since we didn't 835 1.11 riastrad * ask for POLLOUT, it should be clear. 836 1.11 riastrad */ 837 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 838 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 839 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 840 1.11 riastrad pollhup|POLLIN, 841 1.11 riastrad "revents=0x%x expected=0x%x" 842 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 843 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 844 1.11 riastrad 845 1.11 riastrad /* 846 1.11 riastrad * Read should return EOF now -- and continue to do so. 847 1.11 riastrad */ 848 1.11 riastrad check_read_eof(readfd); 849 1.11 riastrad check_read_eof(readfd); 850 1.11 riastrad } 851 1.11 riastrad 852 1.11 riastrad static void 853 1.11 riastrad check_pollclosed_immediate_readsome(int readfd, int writefd, int pollhup) 854 1.11 riastrad { 855 1.11 riastrad struct pollfd pfd; 856 1.11 riastrad char buf[BUFSIZ]; 857 1.11 riastrad ssize_t nread; 858 1.11 riastrad int nfds; 859 1.11 riastrad 860 1.11 riastrad /* 861 1.11 riastrad * Close the writer side immediately. 862 1.11 riastrad */ 863 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", writefd); 864 1.11 riastrad RL(close(writefd)); 865 1.11 riastrad 866 1.11 riastrad /* 867 1.11 riastrad * Some data should be ready to read, so POLLIN should be set, 868 1.11 riastrad * and the write side has been closed, so POLLHUP should also 869 1.11 riastrad * be set, unsolicited, if this is a pipe or FIFO -- but not if 870 1.11 riastrad * it's a socket, where POLLHUP is never set. Since we didn't 871 1.11 riastrad * ask for POLLOUT, it should be clear. 872 1.11 riastrad */ 873 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN }; 874 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 875 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 876 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 877 1.12 riastrad pollhup|POLLIN, 878 1.11 riastrad "revents=0x%x expected=0x%x" 879 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 880 1.12 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 881 1.11 riastrad 882 1.11 riastrad /* 883 1.11 riastrad * Read all the data. Each read should complete instantly -- 884 1.11 riastrad * no blocking, either because there's data to read or because 885 1.11 riastrad * the writer has hung up and we get EOF. 886 1.11 riastrad */ 887 1.11 riastrad do { 888 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1); 889 1.11 riastrad RL(nread = read(readfd, buf, sizeof(buf))); 890 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1); 891 1.11 riastrad } while (nread != 0); 892 1.11 riastrad 893 1.11 riastrad /* 894 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be 895 1.11 riastrad * set, and the write side has been closed, so POLLHUP should 896 1.11 riastrad * also be set, unsolicited, if this is a pipe or FIFO -- but 897 1.11 riastrad * not if it's a socket, where POLLHUP is never set. Since we 898 1.11 riastrad * didn't ask for POLLOUT, it should be clear. 899 1.11 riastrad */ 900 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN }; 901 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 902 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 903 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 904 1.11 riastrad pollhup|POLLIN, 905 1.11 riastrad "revents=0x%x expected=0x%x" 906 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 907 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 908 1.11 riastrad 909 1.11 riastrad /* 910 1.11 riastrad * Read should return EOF now -- and continue to do so. 911 1.11 riastrad */ 912 1.11 riastrad check_read_eof(readfd); 913 1.11 riastrad check_read_eof(readfd); 914 1.11 riastrad 915 1.11 riastrad /* 916 1.11 riastrad * POLLHUP|POLLIN state should be persistent (until the writer 917 1.11 riastrad * side is reopened if possible, as in a named pipe). 918 1.11 riastrad */ 919 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN }; 920 1.11 riastrad RL(nfds = poll(&pfd, 1, 0)); 921 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds); 922 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), 923 1.11 riastrad pollhup|POLLIN, 924 1.11 riastrad "revents=0x%x expected=0x%x" 925 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x", 926 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT); 927 1.11 riastrad } 928 1.11 riastrad 929 1.11 riastrad static void * 930 1.11 riastrad pollclosed_fifo_writer_thread(void *cookie) 931 1.11 riastrad { 932 1.11 riastrad int *pp = cookie; 933 1.11 riastrad 934 1.11 riastrad RL(*pp = open(fifo_path, O_WRONLY)); 935 1.11 riastrad return NULL; 936 1.11 riastrad } 937 1.11 riastrad 938 1.11 riastrad static void * 939 1.11 riastrad pollclosed_fifo_reader_thread(void *cookie) 940 1.11 riastrad { 941 1.11 riastrad int *pp = cookie; 942 1.11 riastrad 943 1.11 riastrad RL(*pp = open(fifo_path, O_RDONLY)); 944 1.11 riastrad return NULL; 945 1.11 riastrad } 946 1.11 riastrad 947 1.11 riastrad static void 948 1.11 riastrad pollclosed_fifo0_setup(int *writefdp, int *readfdp) 949 1.11 riastrad { 950 1.11 riastrad int p0, p1; 951 1.11 riastrad pthread_t t; 952 1.11 riastrad 953 1.11 riastrad fifo_support(); 954 1.11 riastrad 955 1.11 riastrad RL(mkfifo(fifo_path, 0600)); 956 1.11 riastrad RZ(pthread_create(&t, NULL, &pollclosed_fifo_reader_thread, &p0)); 957 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1); 958 1.11 riastrad RL(p1 = open(fifo_path, O_WRONLY)); 959 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1); 960 1.11 riastrad RZ(pthread_join(t, NULL)); 961 1.11 riastrad 962 1.11 riastrad *writefdp = p1; 963 1.11 riastrad *readfdp = p0; 964 1.11 riastrad } 965 1.11 riastrad 966 1.11 riastrad static void 967 1.11 riastrad pollclosed_fifo1_setup(int *writefdp, int *readfdp) 968 1.11 riastrad { 969 1.11 riastrad int p0, p1; 970 1.11 riastrad pthread_t t; 971 1.11 riastrad 972 1.11 riastrad fifo_support(); 973 1.11 riastrad 974 1.11 riastrad RL(mkfifo(fifo_path, 0600)); 975 1.11 riastrad RZ(pthread_create(&t, NULL, &pollclosed_fifo_writer_thread, &p0)); 976 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1); 977 1.11 riastrad RL(p1 = open(fifo_path, O_RDONLY)); 978 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1); 979 1.11 riastrad RZ(pthread_join(t, NULL)); 980 1.11 riastrad 981 1.11 riastrad *writefdp = p0; 982 1.11 riastrad *readfdp = p1; 983 1.11 riastrad } 984 1.11 riastrad 985 1.11 riastrad static void 986 1.11 riastrad pollclosed_pipe_setup(int *writefdp, int *readfdp) 987 1.11 riastrad { 988 1.11 riastrad int p[2]; 989 1.11 riastrad 990 1.11 riastrad RL(pipe(p)); 991 1.11 riastrad 992 1.11 riastrad *readfdp = p[0]; /* reader side */ 993 1.11 riastrad *writefdp = p[1]; /* writer side */ 994 1.11 riastrad } 995 1.11 riastrad 996 1.11 riastrad static void 997 1.12 riastrad pollclosed_ptyapp_setup(int *writefdp, int *readfdp) 998 1.12 riastrad { 999 1.12 riastrad int hostfd, appfd; 1000 1.12 riastrad struct termios t; 1001 1.12 riastrad char *pts; 1002 1.12 riastrad 1003 1.12 riastrad RL(hostfd = posix_openpt(O_RDWR|O_NOCTTY)); 1004 1.12 riastrad RL(grantpt(hostfd)); 1005 1.12 riastrad RL(unlockpt(hostfd)); 1006 1.12 riastrad REQUIRE_LIBC(pts = ptsname(hostfd), NULL); 1007 1.12 riastrad RL(appfd = open(pts, O_RDWR|O_NOCTTY)); 1008 1.12 riastrad 1009 1.12 riastrad RL(tcgetattr(appfd, &t)); 1010 1.12 riastrad t.c_lflag &= ~ICANON; /* block rather than drop input */ 1011 1.12 riastrad RL(tcsetattr(appfd, TCSANOW, &t)); 1012 1.12 riastrad 1013 1.12 riastrad *readfdp = appfd; 1014 1.12 riastrad *writefdp = hostfd; 1015 1.12 riastrad } 1016 1.12 riastrad 1017 1.12 riastrad static void 1018 1.12 riastrad pollclosed_ptyhost_setup(int *writefdp, int *readfdp) 1019 1.12 riastrad { 1020 1.12 riastrad int hostfd, appfd; 1021 1.12 riastrad struct termios t; 1022 1.12 riastrad char *pts; 1023 1.12 riastrad 1024 1.12 riastrad RL(hostfd = posix_openpt(O_RDWR|O_NOCTTY)); 1025 1.12 riastrad RL(grantpt(hostfd)); 1026 1.12 riastrad RL(unlockpt(hostfd)); 1027 1.12 riastrad REQUIRE_LIBC(pts = ptsname(hostfd), NULL); 1028 1.12 riastrad RL(appfd = open(pts, O_RDWR|O_NOCTTY)); 1029 1.12 riastrad 1030 1.12 riastrad RL(tcgetattr(appfd, &t)); 1031 1.12 riastrad t.c_lflag &= ~ICANON; /* block rather than drop input */ 1032 1.12 riastrad RL(tcsetattr(appfd, TCSANOW, &t)); 1033 1.12 riastrad 1034 1.12 riastrad *writefdp = appfd; 1035 1.12 riastrad *readfdp = hostfd; 1036 1.12 riastrad } 1037 1.12 riastrad 1038 1.12 riastrad static void 1039 1.11 riastrad pollclosed_socketpair0_setup(int *writefdp, int *readfdp) 1040 1.11 riastrad { 1041 1.11 riastrad int s[2]; 1042 1.11 riastrad 1043 1.11 riastrad RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s)); 1044 1.11 riastrad *readfdp = s[0]; 1045 1.11 riastrad *writefdp = s[1]; 1046 1.11 riastrad } 1047 1.11 riastrad 1048 1.11 riastrad static void 1049 1.11 riastrad pollclosed_socketpair1_setup(int *writefdp, int *readfdp) 1050 1.11 riastrad { 1051 1.11 riastrad int s[2]; 1052 1.11 riastrad 1053 1.11 riastrad RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s)); 1054 1.11 riastrad *readfdp = s[1]; 1055 1.11 riastrad *writefdp = s[0]; 1056 1.11 riastrad } 1057 1.11 riastrad 1058 1.11 riastrad /* 1059 1.11 riastrad * Cartesian product of: 1060 1.11 riastrad * 1061 1.11 riastrad * 1. [fifo0] first fifo opener 1062 1.11 riastrad * 2. [fifo1] second fifo opener 1063 1.11 riastrad * 3. [pipe] pipe 1064 1.12 riastrad * 4. [ptyhost] host side of pty 1065 1.12 riastrad * 5. [ptyapp] application side of pty 1066 1.12 riastrad * 6. [socketpair0] first side of socket pair 1067 1.12 riastrad * 7. [socketpair1] second side of socket pair 1068 1.11 riastrad * 1069 1.11 riastrad * with 1070 1.11 riastrad * 1071 1.11 riastrad * 1. [immediate] closed before poll starts 1072 1.11 riastrad * 2. [delayed_thread] closed by another thread after poll starts 1073 1.11 riastrad * 3. [delayed_process] closed by another process after poll starts 1074 1.11 riastrad * 1075 1.11 riastrad * with 1076 1.11 riastrad * 1077 1.11 riastrad * 1. [writefull] close reader, poll for write when buffer full 1078 1.11 riastrad * 2. [writeempty] close reader, poll for write when buffer empty 1079 1.11 riastrad * 3. [readnone] close writer, poll for read when nothing to read 1080 1.11 riastrad * 4. [readsome] close writer, poll for read when something to read 1081 1.11 riastrad * 1082 1.11 riastrad * except that in the delayed cases we only do writefull [write] and 1083 1.11 riastrad * readnone [read], because there's no delay in the writeempty/readsome 1084 1.11 riastrad * cases. 1085 1.11 riastrad */ 1086 1.11 riastrad 1087 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_writefull); 1088 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_writefull, tc) 1089 1.11 riastrad { 1090 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1091 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1092 1.11 riastrad } 1093 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_writefull, tc) 1094 1.11 riastrad { 1095 1.11 riastrad int writefd, readfd; 1096 1.11 riastrad 1097 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd); 1098 1.11 riastrad fillpipebuf(writefd); 1099 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1100 1.11 riastrad } 1101 1.11 riastrad 1102 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_writeempty); 1103 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_writeempty, tc) 1104 1.11 riastrad { 1105 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1106 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1107 1.11 riastrad } 1108 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_writeempty, tc) 1109 1.11 riastrad { 1110 1.11 riastrad int writefd, readfd; 1111 1.11 riastrad 1112 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd); 1113 1.11 riastrad /* don't fill the pipe buf */ 1114 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1115 1.11 riastrad } 1116 1.11 riastrad 1117 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_readsome); 1118 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_readsome, tc) 1119 1.11 riastrad { 1120 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1121 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1122 1.11 riastrad } 1123 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_readsome, tc) 1124 1.11 riastrad { 1125 1.11 riastrad int writefd, readfd; 1126 1.11 riastrad 1127 1.12 riastrad /* 1128 1.12 riastrad * poll(2) returns nothing, when it is supposed to return 1129 1.12 riastrad * POLLHUP|POLLIN. 1130 1.12 riastrad */ 1131 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1132 1.11 riastrad 1133 1.12 riastrad pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */ 1134 1.11 riastrad fillpipebuf(writefd); 1135 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP); 1136 1.11 riastrad } 1137 1.11 riastrad 1138 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_readnone); 1139 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_readnone, tc) 1140 1.11 riastrad { 1141 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1142 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1143 1.11 riastrad } 1144 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_readnone, tc) 1145 1.11 riastrad { 1146 1.11 riastrad int writefd, readfd; 1147 1.11 riastrad 1148 1.12 riastrad pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */ 1149 1.11 riastrad /* don't fill the pipe buf */ 1150 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP); 1151 1.11 riastrad } 1152 1.11 riastrad 1153 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_process_write); 1154 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_process_write, tc) 1155 1.11 riastrad { 1156 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1157 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1158 1.11 riastrad } 1159 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_process_write, tc) 1160 1.11 riastrad { 1161 1.11 riastrad int writefd, readfd; 1162 1.11 riastrad 1163 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd); 1164 1.11 riastrad fillpipebuf(writefd); 1165 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd, 1166 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1167 1.11 riastrad } 1168 1.11 riastrad 1169 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_process_read); 1170 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_process_read, tc) 1171 1.11 riastrad { 1172 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1173 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1174 1.11 riastrad } 1175 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_process_read, tc) 1176 1.11 riastrad { 1177 1.11 riastrad int writefd, readfd; 1178 1.11 riastrad 1179 1.12 riastrad /* 1180 1.12 riastrad * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't 1181 1.12 riastrad * persistent as it is supposed to be -- it returns nothing 1182 1.12 riastrad * after that. 1183 1.12 riastrad */ 1184 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1185 1.11 riastrad 1186 1.12 riastrad pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */ 1187 1.11 riastrad /* don't fill pipe buf */ 1188 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 1189 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1190 1.11 riastrad } 1191 1.11 riastrad 1192 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_thread_write); 1193 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_write, tc) 1194 1.11 riastrad { 1195 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1196 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1197 1.11 riastrad } 1198 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_thread_write, tc) 1199 1.11 riastrad { 1200 1.11 riastrad int writefd, readfd; 1201 1.11 riastrad 1202 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd); 1203 1.11 riastrad fillpipebuf(writefd); 1204 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1205 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1206 1.11 riastrad } 1207 1.11 riastrad 1208 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_thread_read); 1209 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_read, tc) 1210 1.11 riastrad { 1211 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1212 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe"); 1213 1.11 riastrad } 1214 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_thread_read, tc) 1215 1.11 riastrad { 1216 1.11 riastrad int writefd, readfd; 1217 1.11 riastrad 1218 1.12 riastrad /* 1219 1.12 riastrad * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't 1220 1.12 riastrad * persistent as it is supposed to be -- it returns nothing 1221 1.12 riastrad * after that. 1222 1.12 riastrad */ 1223 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1224 1.11 riastrad 1225 1.12 riastrad pollclosed_fifo1_setup(&writefd, &readfd); /* reverse r/w */ 1226 1.11 riastrad /* don't fill pipe buf */ 1227 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd, 1228 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1229 1.11 riastrad } 1230 1.11 riastrad 1231 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_writefull); 1232 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_writefull, tc) 1233 1.11 riastrad { 1234 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1235 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1236 1.11 riastrad } 1237 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_writefull, tc) 1238 1.11 riastrad { 1239 1.11 riastrad int writefd, readfd; 1240 1.11 riastrad 1241 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd); 1242 1.11 riastrad fillpipebuf(writefd); 1243 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1244 1.11 riastrad } 1245 1.11 riastrad 1246 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_writeempty); 1247 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_writeempty, tc) 1248 1.11 riastrad { 1249 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1250 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1251 1.11 riastrad } 1252 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_writeempty, tc) 1253 1.11 riastrad { 1254 1.11 riastrad int writefd, readfd; 1255 1.11 riastrad 1256 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd); 1257 1.11 riastrad /* don't fill the pipe buf */ 1258 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1259 1.11 riastrad } 1260 1.11 riastrad 1261 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_readsome); 1262 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_readsome, tc) 1263 1.11 riastrad { 1264 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1265 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1266 1.11 riastrad } 1267 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_readsome, tc) 1268 1.11 riastrad { 1269 1.11 riastrad int writefd, readfd; 1270 1.11 riastrad 1271 1.12 riastrad /* 1272 1.12 riastrad * poll(2) returns nothing, when it is supposed to return 1273 1.12 riastrad * POLLHUP|POLLIN. 1274 1.12 riastrad */ 1275 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1276 1.11 riastrad 1277 1.12 riastrad pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */ 1278 1.11 riastrad fillpipebuf(writefd); 1279 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP); 1280 1.11 riastrad } 1281 1.11 riastrad 1282 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_readnone); 1283 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_readnone, tc) 1284 1.11 riastrad { 1285 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1286 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1287 1.11 riastrad } 1288 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_readnone, tc) 1289 1.11 riastrad { 1290 1.11 riastrad int writefd, readfd; 1291 1.11 riastrad 1292 1.12 riastrad pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */ 1293 1.11 riastrad /* don't fill the pipe buf */ 1294 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP); 1295 1.11 riastrad } 1296 1.11 riastrad 1297 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_process_write); 1298 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_process_write, tc) 1299 1.11 riastrad { 1300 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1301 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1302 1.11 riastrad } 1303 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_process_write, tc) 1304 1.11 riastrad { 1305 1.11 riastrad int writefd, readfd; 1306 1.11 riastrad 1307 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd); 1308 1.11 riastrad fillpipebuf(writefd); 1309 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd, 1310 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1311 1.11 riastrad } 1312 1.11 riastrad 1313 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_process_read); 1314 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_process_read, tc) 1315 1.11 riastrad { 1316 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1317 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1318 1.11 riastrad } 1319 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_process_read, tc) 1320 1.11 riastrad { 1321 1.11 riastrad int writefd, readfd; 1322 1.11 riastrad 1323 1.12 riastrad /* 1324 1.12 riastrad * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't 1325 1.12 riastrad * persistent as it is supposed to be -- it returns nothing 1326 1.12 riastrad * after that. 1327 1.12 riastrad */ 1328 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1329 1.11 riastrad 1330 1.12 riastrad pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */ 1331 1.11 riastrad /* don't fill pipe buf */ 1332 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 1333 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1334 1.11 riastrad } 1335 1.11 riastrad 1336 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_thread_write); 1337 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_write, tc) 1338 1.11 riastrad { 1339 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1340 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1341 1.11 riastrad } 1342 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_thread_write, tc) 1343 1.11 riastrad { 1344 1.11 riastrad int writefd, readfd; 1345 1.11 riastrad 1346 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd); 1347 1.11 riastrad fillpipebuf(writefd); 1348 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1349 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1350 1.11 riastrad } 1351 1.11 riastrad 1352 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_thread_read); 1353 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_read, tc) 1354 1.11 riastrad { 1355 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1356 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe"); 1357 1.11 riastrad } 1358 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_thread_read, tc) 1359 1.11 riastrad { 1360 1.11 riastrad int writefd, readfd; 1361 1.11 riastrad 1362 1.12 riastrad /* 1363 1.12 riastrad * poll(2) wakes up with POLLHUP|POLLIN, but the state isn't 1364 1.12 riastrad * persistent as it is supposed to be -- it returns nothing 1365 1.12 riastrad * after that. 1366 1.12 riastrad */ 1367 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1368 1.11 riastrad 1369 1.12 riastrad pollclosed_fifo0_setup(&writefd, &readfd); /* reverse r/w */ 1370 1.11 riastrad /* don't fill pipe buf */ 1371 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 1372 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1373 1.11 riastrad } 1374 1.11 riastrad 1375 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_writefull); 1376 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_writefull, tc) 1377 1.11 riastrad { 1378 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1379 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1380 1.11 riastrad } 1381 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_writefull, tc) 1382 1.11 riastrad { 1383 1.11 riastrad int writefd, readfd; 1384 1.11 riastrad 1385 1.12 riastrad /* 1386 1.12 riastrad * poll(2) returns POLLHUP|POLLOUT, which is forbidden -- 1387 1.12 riastrad * POLLHUP and POLLOUT are mutually exclusive. And POLLHUP is 1388 1.12 riastrad * only supposed to be returned by polling for read, not 1389 1.12 riastrad * polling for write. So it should be POLLOUT. 1390 1.12 riastrad */ 1391 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1392 1.11 riastrad 1393 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1394 1.11 riastrad fillpipebuf(writefd); 1395 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1396 1.11 riastrad } 1397 1.11 riastrad 1398 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_writeempty); 1399 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_writeempty, tc) 1400 1.11 riastrad { 1401 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1402 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1403 1.11 riastrad } 1404 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_writeempty, tc) 1405 1.11 riastrad { 1406 1.11 riastrad int writefd, readfd; 1407 1.11 riastrad 1408 1.12 riastrad /* 1409 1.12 riastrad * poll(2) returns POLLHUP|POLLOUT, which is forbidden -- 1410 1.12 riastrad * POLLHUP and POLLOUT are mutually exclusive. And POLLHUP is 1411 1.12 riastrad * only supposed to be returned by polling for read, not 1412 1.12 riastrad * polling for write. So it should be POLLOUT. 1413 1.12 riastrad */ 1414 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1415 1.11 riastrad 1416 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1417 1.11 riastrad /* don't fill pipe buf */ 1418 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1419 1.11 riastrad } 1420 1.11 riastrad 1421 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_readsome); 1422 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_readsome, tc) 1423 1.11 riastrad { 1424 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1425 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1426 1.11 riastrad } 1427 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_readsome, tc) 1428 1.11 riastrad { 1429 1.11 riastrad int writefd, readfd; 1430 1.11 riastrad 1431 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1432 1.11 riastrad fillpipebuf(writefd); 1433 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP); 1434 1.11 riastrad } 1435 1.11 riastrad 1436 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_readnone); 1437 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_readnone, tc) 1438 1.11 riastrad { 1439 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1440 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1441 1.11 riastrad } 1442 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_readnone, tc) 1443 1.11 riastrad { 1444 1.11 riastrad int writefd, readfd; 1445 1.11 riastrad 1446 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1447 1.11 riastrad /* don't fill pipe buf */ 1448 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP); 1449 1.11 riastrad } 1450 1.11 riastrad 1451 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_process_write); 1452 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_process_write, tc) 1453 1.11 riastrad { 1454 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1455 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1456 1.11 riastrad } 1457 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_process_write, tc) 1458 1.11 riastrad { 1459 1.11 riastrad int writefd, readfd; 1460 1.11 riastrad 1461 1.12 riastrad /* 1462 1.12 riastrad * poll(2) returns POLLHUP|POLLOUT, which is forbidden -- 1463 1.12 riastrad * POLLHUP and POLLOUT are mutually exclusive. And POLLHUP is 1464 1.12 riastrad * only supposed to be returned by polling for read, not 1465 1.12 riastrad * polling for write. So it should be POLLOUT. 1466 1.12 riastrad */ 1467 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1468 1.11 riastrad 1469 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1470 1.11 riastrad fillpipebuf(writefd); 1471 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd, 1472 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1473 1.11 riastrad } 1474 1.11 riastrad 1475 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_process_read); 1476 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_process_read, tc) 1477 1.11 riastrad { 1478 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1479 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1480 1.11 riastrad } 1481 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_process_read, tc) 1482 1.11 riastrad { 1483 1.11 riastrad int writefd, readfd; 1484 1.11 riastrad 1485 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1486 1.11 riastrad /* don't fill pipe buf */ 1487 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 1488 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1489 1.11 riastrad } 1490 1.11 riastrad 1491 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_thread_write); 1492 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_thread_write, tc) 1493 1.11 riastrad { 1494 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1495 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1496 1.11 riastrad } 1497 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_thread_write, tc) 1498 1.11 riastrad { 1499 1.11 riastrad int writefd, readfd; 1500 1.11 riastrad 1501 1.12 riastrad /* 1502 1.12 riastrad * poll(2) returns POLLHUP|POLLOUT, which is forbidden -- 1503 1.12 riastrad * POLLHUP and POLLOUT are mutually exclusive. And POLLHUP is 1504 1.12 riastrad * only supposed to be returned by polling for read, not 1505 1.12 riastrad * polling for write. So it should be POLLOUT. 1506 1.12 riastrad */ 1507 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1508 1.11 riastrad 1509 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1510 1.11 riastrad fillpipebuf(writefd); 1511 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1512 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1513 1.11 riastrad } 1514 1.11 riastrad 1515 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_thread_read); 1516 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_thread_read, tc) 1517 1.11 riastrad { 1518 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1519 1.11 riastrad "Checks POLLHUP with a closed pipe"); 1520 1.11 riastrad } 1521 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_thread_read, tc) 1522 1.11 riastrad { 1523 1.11 riastrad int writefd, readfd; 1524 1.11 riastrad 1525 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd); 1526 1.11 riastrad /* don't fill pipe buf */ 1527 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd, 1528 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1529 1.12 riastrad } 1530 1.12 riastrad 1531 1.12 riastrad ATF_TC(pollclosed_ptyapp_immediate_writefull); 1532 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_immediate_writefull, tc) 1533 1.12 riastrad { 1534 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1535 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1536 1.12 riastrad } 1537 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_immediate_writefull, tc) 1538 1.12 riastrad { 1539 1.12 riastrad int writefd, readfd; 1540 1.12 riastrad 1541 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); 1542 1.12 riastrad fillpipebuf(writefd); 1543 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO); 1544 1.12 riastrad } 1545 1.12 riastrad 1546 1.12 riastrad ATF_TC(pollclosed_ptyapp_immediate_writeempty); 1547 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_immediate_writeempty, tc) 1548 1.12 riastrad { 1549 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1550 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1551 1.12 riastrad } 1552 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_immediate_writeempty, tc) 1553 1.12 riastrad { 1554 1.12 riastrad int writefd, readfd; 1555 1.12 riastrad 1556 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); 1557 1.12 riastrad /* don't fill the pipe buf */ 1558 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO); 1559 1.12 riastrad } 1560 1.12 riastrad 1561 1.12 riastrad ATF_TC(pollclosed_ptyapp_immediate_readsome); 1562 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_immediate_readsome, tc) 1563 1.12 riastrad { 1564 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1565 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1566 1.12 riastrad } 1567 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_immediate_readsome, tc) 1568 1.12 riastrad { 1569 1.12 riastrad int writefd, readfd; 1570 1.12 riastrad 1571 1.12 riastrad /* 1572 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1573 1.12 riastrad * would return EOF without blocking. 1574 1.12 riastrad */ 1575 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1576 1.12 riastrad 1577 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */ 1578 1.12 riastrad fillpipebuf(writefd); 1579 1.12 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP); 1580 1.12 riastrad } 1581 1.12 riastrad 1582 1.12 riastrad ATF_TC(pollclosed_ptyapp_immediate_readnone); 1583 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_immediate_readnone, tc) 1584 1.12 riastrad { 1585 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1586 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1587 1.12 riastrad } 1588 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_immediate_readnone, tc) 1589 1.12 riastrad { 1590 1.12 riastrad int writefd, readfd; 1591 1.12 riastrad 1592 1.12 riastrad /* 1593 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1594 1.12 riastrad * would return EOF without blocking. 1595 1.12 riastrad */ 1596 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1597 1.12 riastrad 1598 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */ 1599 1.12 riastrad /* don't fill the pipe buf */ 1600 1.12 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP); 1601 1.12 riastrad } 1602 1.12 riastrad 1603 1.12 riastrad ATF_TC(pollclosed_ptyapp_delayed_process_write); 1604 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_delayed_process_write, tc) 1605 1.12 riastrad { 1606 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1607 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1608 1.12 riastrad } 1609 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_delayed_process_write, tc) 1610 1.12 riastrad { 1611 1.12 riastrad int writefd, readfd; 1612 1.12 riastrad 1613 1.12 riastrad /* 1614 1.12 riastrad * The poll(2) call is not woken by the concurrent close(2) 1615 1.12 riastrad * call. 1616 1.12 riastrad */ 1617 1.12 riastrad atf_tc_expect_signal(SIGALRM, "PR kern/59056: poll POLLHUP bugs"); 1618 1.12 riastrad 1619 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); 1620 1.12 riastrad fillpipebuf(writefd); 1621 1.12 riastrad check_pollclosed_delayed_process(writefd, readfd, 1622 1.12 riastrad &check_pollclosed_delayed_write_terminal); 1623 1.12 riastrad } 1624 1.12 riastrad 1625 1.12 riastrad ATF_TC(pollclosed_ptyapp_delayed_process_read); 1626 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_delayed_process_read, tc) 1627 1.12 riastrad { 1628 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1629 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1630 1.12 riastrad } 1631 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_delayed_process_read, tc) 1632 1.12 riastrad { 1633 1.12 riastrad int writefd, readfd; 1634 1.12 riastrad 1635 1.12 riastrad /* 1636 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1637 1.12 riastrad * would return EOF without blocking. 1638 1.12 riastrad */ 1639 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1640 1.12 riastrad 1641 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */ 1642 1.12 riastrad /* don't fill pipe buf */ 1643 1.12 riastrad check_pollclosed_delayed_process(readfd, writefd, 1644 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1645 1.12 riastrad } 1646 1.12 riastrad 1647 1.12 riastrad ATF_TC(pollclosed_ptyapp_delayed_thread_write); 1648 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_delayed_thread_write, tc) 1649 1.12 riastrad { 1650 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1651 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1652 1.12 riastrad } 1653 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_delayed_thread_write, tc) 1654 1.12 riastrad { 1655 1.12 riastrad int writefd, readfd; 1656 1.12 riastrad 1657 1.12 riastrad /* 1658 1.12 riastrad * The poll(2) call is not woken by the concurrent close(2) 1659 1.12 riastrad * call. 1660 1.12 riastrad */ 1661 1.12 riastrad atf_tc_expect_signal(SIGALRM, "PR kern/59056: poll POLLHUP bugs"); 1662 1.12 riastrad 1663 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); 1664 1.12 riastrad fillpipebuf(writefd); 1665 1.12 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1666 1.12 riastrad &check_pollclosed_delayed_write_terminal); 1667 1.12 riastrad } 1668 1.12 riastrad 1669 1.12 riastrad ATF_TC(pollclosed_ptyapp_delayed_thread_read); 1670 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyapp_delayed_thread_read, tc) 1671 1.12 riastrad { 1672 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1673 1.12 riastrad "Checks POLLHUP with closing the pty application side"); 1674 1.12 riastrad } 1675 1.12 riastrad ATF_TC_BODY(pollclosed_ptyapp_delayed_thread_read, tc) 1676 1.12 riastrad { 1677 1.12 riastrad int writefd, readfd; 1678 1.12 riastrad 1679 1.12 riastrad /* 1680 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1681 1.12 riastrad * would return EOF without blocking. 1682 1.12 riastrad */ 1683 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1684 1.12 riastrad 1685 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); /* reverse r/w */ 1686 1.12 riastrad /* don't fill pipe buf */ 1687 1.12 riastrad check_pollclosed_delayed_process(readfd, writefd, 1688 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1689 1.12 riastrad } 1690 1.12 riastrad 1691 1.12 riastrad ATF_TC(pollclosed_ptyhost_immediate_writefull); 1692 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_immediate_writefull, tc) 1693 1.12 riastrad { 1694 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1695 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1696 1.12 riastrad } 1697 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_immediate_writefull, tc) 1698 1.12 riastrad { 1699 1.12 riastrad int writefd, readfd; 1700 1.12 riastrad 1701 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); 1702 1.12 riastrad fillpipebuf(writefd); 1703 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO); 1704 1.12 riastrad } 1705 1.12 riastrad 1706 1.12 riastrad ATF_TC(pollclosed_ptyhost_immediate_writeempty); 1707 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_immediate_writeempty, tc) 1708 1.12 riastrad { 1709 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1710 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1711 1.12 riastrad } 1712 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_immediate_writeempty, tc) 1713 1.12 riastrad { 1714 1.12 riastrad int writefd, readfd; 1715 1.12 riastrad 1716 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); 1717 1.12 riastrad /* don't fill the pipe buf */ 1718 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLHUP, EIO); 1719 1.12 riastrad } 1720 1.12 riastrad 1721 1.12 riastrad ATF_TC(pollclosed_ptyhost_immediate_readsome); 1722 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_immediate_readsome, tc) 1723 1.12 riastrad { 1724 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1725 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1726 1.12 riastrad } 1727 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_immediate_readsome, tc) 1728 1.12 riastrad { 1729 1.12 riastrad int writefd, readfd; 1730 1.12 riastrad 1731 1.12 riastrad /* 1732 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1733 1.12 riastrad * would return EOF without blocking. 1734 1.12 riastrad */ 1735 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1736 1.12 riastrad 1737 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */ 1738 1.12 riastrad fillpipebuf(writefd); 1739 1.12 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP); 1740 1.12 riastrad } 1741 1.12 riastrad 1742 1.12 riastrad ATF_TC(pollclosed_ptyhost_immediate_readnone); 1743 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_immediate_readnone, tc) 1744 1.12 riastrad { 1745 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1746 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1747 1.12 riastrad } 1748 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_immediate_readnone, tc) 1749 1.12 riastrad { 1750 1.12 riastrad int writefd, readfd; 1751 1.12 riastrad 1752 1.12 riastrad /* 1753 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1754 1.12 riastrad * would return EOF without blocking. 1755 1.12 riastrad */ 1756 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1757 1.12 riastrad 1758 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */ 1759 1.12 riastrad /* don't fill the pipe buf */ 1760 1.12 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP); 1761 1.12 riastrad } 1762 1.12 riastrad 1763 1.12 riastrad ATF_TC(pollclosed_ptyhost_delayed_process_write); 1764 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_delayed_process_write, tc) 1765 1.12 riastrad { 1766 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1767 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1768 1.12 riastrad } 1769 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_delayed_process_write, tc) 1770 1.12 riastrad { 1771 1.12 riastrad int writefd, readfd; 1772 1.12 riastrad 1773 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); 1774 1.12 riastrad fillpipebuf(writefd); 1775 1.12 riastrad check_pollclosed_delayed_process(writefd, readfd, 1776 1.12 riastrad &check_pollclosed_delayed_write_terminal); 1777 1.12 riastrad } 1778 1.12 riastrad 1779 1.12 riastrad ATF_TC(pollclosed_ptyhost_delayed_process_read); 1780 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_delayed_process_read, tc) 1781 1.12 riastrad { 1782 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1783 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1784 1.12 riastrad } 1785 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_delayed_process_read, tc) 1786 1.12 riastrad { 1787 1.12 riastrad int writefd, readfd; 1788 1.12 riastrad 1789 1.12 riastrad /* 1790 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1791 1.12 riastrad * would return EOF without blocking. 1792 1.12 riastrad */ 1793 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1794 1.12 riastrad 1795 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */ 1796 1.12 riastrad /* don't fill pipe buf */ 1797 1.12 riastrad check_pollclosed_delayed_process(readfd, writefd, 1798 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1799 1.12 riastrad } 1800 1.12 riastrad 1801 1.12 riastrad ATF_TC(pollclosed_ptyhost_delayed_thread_write); 1802 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_delayed_thread_write, tc) 1803 1.12 riastrad { 1804 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1805 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1806 1.12 riastrad } 1807 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_delayed_thread_write, tc) 1808 1.12 riastrad { 1809 1.12 riastrad int writefd, readfd; 1810 1.12 riastrad 1811 1.12 riastrad pollclosed_ptyhost_setup(&writefd, &readfd); 1812 1.12 riastrad fillpipebuf(writefd); 1813 1.12 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1814 1.12 riastrad &check_pollclosed_delayed_write_terminal); 1815 1.12 riastrad } 1816 1.12 riastrad 1817 1.12 riastrad ATF_TC(pollclosed_ptyhost_delayed_thread_read); 1818 1.12 riastrad ATF_TC_HEAD(pollclosed_ptyhost_delayed_thread_read, tc) 1819 1.12 riastrad { 1820 1.12 riastrad atf_tc_set_md_var(tc, "descr", 1821 1.12 riastrad "Checks POLLHUP with closing the pty host side"); 1822 1.12 riastrad } 1823 1.12 riastrad ATF_TC_BODY(pollclosed_ptyhost_delayed_thread_read, tc) 1824 1.12 riastrad { 1825 1.12 riastrad int writefd, readfd; 1826 1.12 riastrad 1827 1.12 riastrad /* 1828 1.12 riastrad * poll(2) returns POLLHUP but not POLLIN even though read(2) 1829 1.12 riastrad * would return EOF without blocking. 1830 1.12 riastrad */ 1831 1.12 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs"); 1832 1.12 riastrad 1833 1.12 riastrad pollclosed_ptyapp_setup(&writefd, &readfd); /* reverse r/w */ 1834 1.12 riastrad /* don't fill pipe buf */ 1835 1.12 riastrad check_pollclosed_delayed_thread(readfd, writefd, 1836 1.12 riastrad &check_pollclosed_delayed_read_devfifopipe); 1837 1.11 riastrad } 1838 1.11 riastrad 1839 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_writefull); 1840 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_writefull, tc) 1841 1.11 riastrad { 1842 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1843 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1844 1.11 riastrad } 1845 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_writefull, tc) 1846 1.11 riastrad { 1847 1.11 riastrad int writefd, readfd; 1848 1.11 riastrad 1849 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); 1850 1.11 riastrad fillpipebuf(writefd); 1851 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1852 1.11 riastrad } 1853 1.11 riastrad 1854 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_writeempty); 1855 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_writeempty, tc) 1856 1.11 riastrad { 1857 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1858 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1859 1.11 riastrad } 1860 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_writeempty, tc) 1861 1.11 riastrad { 1862 1.11 riastrad int writefd, readfd; 1863 1.11 riastrad 1864 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); 1865 1.11 riastrad /* don't fill the pipe buf */ 1866 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1867 1.11 riastrad } 1868 1.11 riastrad 1869 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_readsome); 1870 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_readsome, tc) 1871 1.11 riastrad { 1872 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1873 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1874 1.11 riastrad } 1875 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_readsome, tc) 1876 1.11 riastrad { 1877 1.11 riastrad int writefd, readfd; 1878 1.11 riastrad 1879 1.12 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */ 1880 1.11 riastrad fillpipebuf(writefd); 1881 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0); 1882 1.11 riastrad } 1883 1.11 riastrad 1884 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_readnone); 1885 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_readnone, tc) 1886 1.11 riastrad { 1887 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1888 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1889 1.11 riastrad } 1890 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_readnone, tc) 1891 1.11 riastrad { 1892 1.11 riastrad int writefd, readfd; 1893 1.11 riastrad 1894 1.12 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */ 1895 1.11 riastrad /* don't fill the pipe buf */ 1896 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0); 1897 1.11 riastrad } 1898 1.11 riastrad 1899 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_process_write); 1900 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_write, tc) 1901 1.11 riastrad { 1902 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1903 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1904 1.11 riastrad } 1905 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_process_write, tc) 1906 1.11 riastrad { 1907 1.11 riastrad int writefd, readfd; 1908 1.11 riastrad 1909 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); 1910 1.11 riastrad fillpipebuf(writefd); 1911 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd, 1912 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1913 1.11 riastrad } 1914 1.11 riastrad 1915 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_process_read); 1916 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_read, tc) 1917 1.11 riastrad { 1918 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1919 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1920 1.11 riastrad } 1921 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_process_read, tc) 1922 1.11 riastrad { 1923 1.11 riastrad int writefd, readfd; 1924 1.11 riastrad 1925 1.12 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */ 1926 1.11 riastrad /* don't fill pipe buf */ 1927 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 1928 1.11 riastrad &check_pollclosed_delayed_read_socket); 1929 1.11 riastrad } 1930 1.11 riastrad 1931 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_thread_write); 1932 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_write, tc) 1933 1.11 riastrad { 1934 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1935 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1936 1.11 riastrad } 1937 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_write, tc) 1938 1.11 riastrad { 1939 1.11 riastrad int writefd, readfd; 1940 1.11 riastrad 1941 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); 1942 1.11 riastrad fillpipebuf(writefd); 1943 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd, 1944 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 1945 1.11 riastrad } 1946 1.11 riastrad 1947 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_thread_read); 1948 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_read, tc) 1949 1.11 riastrad { 1950 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1951 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair"); 1952 1.11 riastrad } 1953 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_read, tc) 1954 1.11 riastrad { 1955 1.11 riastrad int writefd, readfd; 1956 1.11 riastrad 1957 1.12 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); /* reverse r/w */ 1958 1.11 riastrad /* don't fill pipe buf */ 1959 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd, 1960 1.11 riastrad &check_pollclosed_delayed_read_socket); 1961 1.11 riastrad } 1962 1.11 riastrad 1963 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_writefull); 1964 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_writefull, tc) 1965 1.11 riastrad { 1966 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1967 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 1968 1.11 riastrad } 1969 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_writefull, tc) 1970 1.11 riastrad { 1971 1.11 riastrad int writefd, readfd; 1972 1.11 riastrad 1973 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); 1974 1.11 riastrad fillpipebuf(writefd); 1975 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1976 1.11 riastrad } 1977 1.11 riastrad 1978 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_writeempty); 1979 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_writeempty, tc) 1980 1.11 riastrad { 1981 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1982 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 1983 1.11 riastrad } 1984 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_writeempty, tc) 1985 1.11 riastrad { 1986 1.11 riastrad int writefd, readfd; 1987 1.11 riastrad 1988 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); 1989 1.11 riastrad /* don't fill the pipe buf */ 1990 1.12 riastrad check_pollclosed_immediate_write(writefd, readfd, POLLOUT, EPIPE); 1991 1.11 riastrad } 1992 1.11 riastrad 1993 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_readsome); 1994 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_readsome, tc) 1995 1.11 riastrad { 1996 1.11 riastrad atf_tc_set_md_var(tc, "descr", 1997 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 1998 1.11 riastrad } 1999 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_readsome, tc) 2000 1.11 riastrad { 2001 1.11 riastrad int writefd, readfd; 2002 1.11 riastrad 2003 1.12 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */ 2004 1.11 riastrad fillpipebuf(writefd); 2005 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0); 2006 1.11 riastrad } 2007 1.11 riastrad 2008 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_readnone); 2009 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_readnone, tc) 2010 1.11 riastrad { 2011 1.11 riastrad atf_tc_set_md_var(tc, "descr", 2012 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 2013 1.11 riastrad } 2014 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_readnone, tc) 2015 1.11 riastrad { 2016 1.11 riastrad int writefd, readfd; 2017 1.11 riastrad 2018 1.12 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */ 2019 1.11 riastrad /* don't fill the pipe buf */ 2020 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0); 2021 1.11 riastrad } 2022 1.11 riastrad 2023 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_process_write); 2024 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_write, tc) 2025 1.11 riastrad { 2026 1.11 riastrad atf_tc_set_md_var(tc, "descr", 2027 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 2028 1.11 riastrad } 2029 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_process_write, tc) 2030 1.11 riastrad { 2031 1.11 riastrad int writefd, readfd; 2032 1.11 riastrad 2033 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); 2034 1.11 riastrad fillpipebuf(writefd); 2035 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd, 2036 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 2037 1.11 riastrad } 2038 1.11 riastrad 2039 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_process_read); 2040 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_read, tc) 2041 1.11 riastrad { 2042 1.11 riastrad atf_tc_set_md_var(tc, "descr", 2043 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 2044 1.11 riastrad } 2045 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_process_read, tc) 2046 1.11 riastrad { 2047 1.11 riastrad int writefd, readfd; 2048 1.11 riastrad 2049 1.12 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */ 2050 1.11 riastrad /* don't fill pipe buf */ 2051 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 2052 1.11 riastrad &check_pollclosed_delayed_read_socket); 2053 1.11 riastrad } 2054 1.11 riastrad 2055 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_thread_write); 2056 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_write, tc) 2057 1.11 riastrad { 2058 1.11 riastrad atf_tc_set_md_var(tc, "descr", 2059 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 2060 1.11 riastrad } 2061 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_write, tc) 2062 1.11 riastrad { 2063 1.11 riastrad int writefd, readfd; 2064 1.11 riastrad 2065 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd); 2066 1.11 riastrad fillpipebuf(writefd); 2067 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd, 2068 1.12 riastrad &check_pollclosed_delayed_write_fifopipesocket); 2069 1.11 riastrad } 2070 1.11 riastrad 2071 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_thread_read); 2072 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_read, tc) 2073 1.11 riastrad { 2074 1.11 riastrad atf_tc_set_md_var(tc, "descr", 2075 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair"); 2076 1.11 riastrad } 2077 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_read, tc) 2078 1.11 riastrad { 2079 1.11 riastrad int writefd, readfd; 2080 1.11 riastrad 2081 1.12 riastrad pollclosed_socketpair0_setup(&writefd, &readfd); /* reverse r/w */ 2082 1.11 riastrad /* don't fill pipe buf */ 2083 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd, 2084 1.11 riastrad &check_pollclosed_delayed_read_socket); 2085 1.11 riastrad } 2086 1.11 riastrad 2087 1.1 jruoho ATF_TP_ADD_TCS(tp) 2088 1.1 jruoho { 2089 1.1 jruoho 2090 1.4 kamil ATF_TP_ADD_TC(tp, 3way); 2091 1.4 kamil ATF_TP_ADD_TC(tp, basic); 2092 1.4 kamil ATF_TP_ADD_TC(tp, err); 2093 1.1 jruoho 2094 1.7 thorpej ATF_TP_ADD_TC(tp, fifo_inout); 2095 1.5 thorpej ATF_TP_ADD_TC(tp, fifo_hup1); 2096 1.5 thorpej ATF_TP_ADD_TC(tp, fifo_hup2); 2097 1.5 thorpej 2098 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writefull); 2099 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writefull); 2100 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writefull); 2101 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_writefull); 2102 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_writefull); 2103 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writefull); 2104 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writefull); 2105 1.11 riastrad 2106 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writeempty); 2107 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writeempty); 2108 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writeempty); 2109 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_writeempty); 2110 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_writeempty); 2111 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writeempty); 2112 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writeempty); 2113 1.11 riastrad 2114 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readsome); 2115 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readsome); 2116 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readsome); 2117 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_readsome); 2118 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_readsome); 2119 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readsome); 2120 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readsome); 2121 1.11 riastrad 2122 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readnone); 2123 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readnone); 2124 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readnone); 2125 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_immediate_readnone); 2126 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_immediate_readnone); 2127 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readnone); 2128 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readnone); 2129 1.11 riastrad 2130 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_write); 2131 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_write); 2132 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_write); 2133 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_process_write); 2134 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_process_write); 2135 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_write); 2136 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_write); 2137 1.11 riastrad 2138 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_read); 2139 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_read); 2140 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_read); 2141 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_process_read); 2142 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_process_read); 2143 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_read); 2144 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_read); 2145 1.11 riastrad 2146 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_write); 2147 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_write); 2148 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_write); 2149 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_thread_write); 2150 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_thread_write); 2151 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_write); 2152 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_write); 2153 1.11 riastrad 2154 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_read); 2155 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_read); 2156 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_read); 2157 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyapp_delayed_thread_read); 2158 1.12 riastrad ATF_TP_ADD_TC(tp, pollclosed_ptyhost_delayed_thread_read); 2159 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_read); 2160 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_read); 2161 1.11 riastrad 2162 1.1 jruoho return atf_no_error(); 2163 1.1 jruoho } 2164