t_poll.c revision 1.11 1 1.11 riastrad /* $NetBSD: t_poll.c,v 1.11 2025/02/09 17:10:37 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.11 riastrad #include <sys/socket.h>
33 1.5 thorpej #include <sys/stat.h>
34 1.1 jruoho #include <sys/time.h>
35 1.2 jruoho #include <sys/wait.h>
36 1.1 jruoho
37 1.1 jruoho #include <atf-c.h>
38 1.1 jruoho #include <errno.h>
39 1.1 jruoho #include <fcntl.h>
40 1.1 jruoho #include <paths.h>
41 1.1 jruoho #include <poll.h>
42 1.11 riastrad #include <pthread.h>
43 1.2 jruoho #include <stdio.h>
44 1.7 thorpej #include <stdlib.h>
45 1.1 jruoho #include <signal.h>
46 1.1 jruoho #include <unistd.h>
47 1.1 jruoho
48 1.11 riastrad #include "h_macros.h"
49 1.11 riastrad
50 1.2 jruoho static int desc;
51 1.2 jruoho
52 1.2 jruoho static void
53 1.2 jruoho child1(void)
54 1.2 jruoho {
55 1.2 jruoho struct pollfd pfd;
56 1.2 jruoho
57 1.2 jruoho pfd.fd = desc;
58 1.2 jruoho pfd.events = POLLIN | POLLHUP | POLLOUT;
59 1.2 jruoho
60 1.2 jruoho (void)poll(&pfd, 1, 2000);
61 1.2 jruoho (void)printf("child1 exit\n");
62 1.2 jruoho }
63 1.2 jruoho
64 1.2 jruoho static void
65 1.2 jruoho child2(void)
66 1.2 jruoho {
67 1.2 jruoho struct pollfd pfd;
68 1.2 jruoho
69 1.2 jruoho pfd.fd = desc;
70 1.2 jruoho pfd.events = POLLIN | POLLHUP | POLLOUT;
71 1.2 jruoho
72 1.2 jruoho (void)sleep(1);
73 1.2 jruoho (void)poll(&pfd, 1, INFTIM);
74 1.2 jruoho (void)printf("child2 exit\n");
75 1.2 jruoho }
76 1.2 jruoho
77 1.2 jruoho static void
78 1.2 jruoho child3(void)
79 1.2 jruoho {
80 1.2 jruoho struct pollfd pfd;
81 1.2 jruoho
82 1.2 jruoho (void)sleep(5);
83 1.2 jruoho
84 1.2 jruoho pfd.fd = desc;
85 1.2 jruoho pfd.events = POLLIN | POLLHUP | POLLOUT;
86 1.2 jruoho
87 1.2 jruoho (void)poll(&pfd, 1, INFTIM);
88 1.2 jruoho (void)printf("child3 exit\n");
89 1.2 jruoho }
90 1.2 jruoho
91 1.4 kamil ATF_TC(3way);
92 1.4 kamil ATF_TC_HEAD(3way, tc)
93 1.2 jruoho {
94 1.2 jruoho atf_tc_set_md_var(tc, "timeout", "15");
95 1.2 jruoho atf_tc_set_md_var(tc, "descr",
96 1.2 jruoho "Check for 3-way collision for descriptor. First child comes "
97 1.2 jruoho "and polls on descriptor, second child comes and polls, first "
98 1.2 jruoho "child times out and exits, third child comes and polls. When "
99 1.2 jruoho "the wakeup event happens, the two remaining children should "
100 1.2 jruoho "both be awaken. (kern/17517)");
101 1.2 jruoho }
102 1.2 jruoho
103 1.4 kamil ATF_TC_BODY(3way, tc)
104 1.2 jruoho {
105 1.2 jruoho int pf[2];
106 1.2 jruoho int status, i;
107 1.2 jruoho pid_t pid;
108 1.10 riastrad ssize_t nwrit;
109 1.2 jruoho
110 1.10 riastrad RL(pipe(pf));
111 1.2 jruoho desc = pf[0];
112 1.2 jruoho
113 1.10 riastrad RL(pid = fork());
114 1.2 jruoho if (pid == 0) {
115 1.10 riastrad if (close(pf[1]) == -1)
116 1.10 riastrad _exit(1);
117 1.2 jruoho child1();
118 1.2 jruoho _exit(0);
119 1.2 jruoho /* NOTREACHED */
120 1.2 jruoho }
121 1.2 jruoho
122 1.10 riastrad RL(pid = fork());
123 1.2 jruoho if (pid == 0) {
124 1.10 riastrad if (close(pf[1]) == -1)
125 1.10 riastrad _exit(1);
126 1.2 jruoho child2();
127 1.2 jruoho _exit(0);
128 1.2 jruoho /* NOTREACHED */
129 1.2 jruoho }
130 1.2 jruoho
131 1.10 riastrad RL(pid = fork());
132 1.2 jruoho if (pid == 0) {
133 1.10 riastrad if (close(pf[1]) == -1)
134 1.10 riastrad _exit(1);
135 1.2 jruoho child3();
136 1.2 jruoho _exit(0);
137 1.2 jruoho /* NOTREACHED */
138 1.2 jruoho }
139 1.2 jruoho
140 1.2 jruoho (void)sleep(10);
141 1.2 jruoho
142 1.2 jruoho (void)printf("parent write\n");
143 1.2 jruoho
144 1.10 riastrad RL(nwrit = write(pf[1], "konec\n", 6));
145 1.10 riastrad ATF_REQUIRE_EQ_MSG(nwrit, 6, "nwrit=%zd", nwrit);
146 1.2 jruoho
147 1.10 riastrad for (i = 0; i < 3; i++)
148 1.10 riastrad RL(wait(&status));
149 1.2 jruoho
150 1.2 jruoho (void)printf("parent terminated\n");
151 1.2 jruoho }
152 1.2 jruoho
153 1.4 kamil ATF_TC(basic);
154 1.4 kamil ATF_TC_HEAD(basic, tc)
155 1.1 jruoho {
156 1.1 jruoho atf_tc_set_md_var(tc, "timeout", "10");
157 1.1 jruoho atf_tc_set_md_var(tc, "descr",
158 1.1 jruoho "Basis functionality test for poll(2)");
159 1.1 jruoho }
160 1.1 jruoho
161 1.4 kamil ATF_TC_BODY(basic, tc)
162 1.1 jruoho {
163 1.1 jruoho int fds[2];
164 1.1 jruoho struct pollfd pfds[2];
165 1.1 jruoho int ret;
166 1.10 riastrad ssize_t nwrit;
167 1.1 jruoho
168 1.10 riastrad RL(pipe(fds));
169 1.1 jruoho
170 1.1 jruoho pfds[0].fd = fds[0];
171 1.1 jruoho pfds[0].events = POLLIN;
172 1.1 jruoho pfds[1].fd = fds[1];
173 1.1 jruoho pfds[1].events = POLLOUT;
174 1.1 jruoho
175 1.1 jruoho /*
176 1.1 jruoho * Check that we get a timeout waiting for data on the read end
177 1.1 jruoho * of our pipe.
178 1.1 jruoho */
179 1.1 jruoho pfds[0].revents = -1;
180 1.1 jruoho pfds[1].revents = -1;
181 1.10 riastrad RL(ret = poll(&pfds[0], 1, 1));
182 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 0, "got: %d", ret);
183 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
184 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents);
185 1.1 jruoho
186 1.1 jruoho /* Check that the write end of the pipe as reported as ready. */
187 1.1 jruoho pfds[0].revents = -1;
188 1.1 jruoho pfds[1].revents = -1;
189 1.10 riastrad RL(ret = poll(&pfds[1], 1, 1));
190 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
191 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents);
192 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\
193 1.1 jruoho pfds[1].revents);
194 1.1 jruoho
195 1.1 jruoho /* Check that only the write end of the pipe as reported as ready. */
196 1.1 jruoho pfds[0].revents = -1;
197 1.1 jruoho pfds[1].revents = -1;
198 1.10 riastrad RL(ret = poll(pfds, 2, 1));
199 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
200 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
201 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
202 1.1 jruoho pfds[1].revents);
203 1.1 jruoho
204 1.1 jruoho /* Write data to our pipe. */
205 1.10 riastrad RL(nwrit = write(fds[1], "", 1));
206 1.10 riastrad ATF_REQUIRE_EQ_MSG(nwrit, 1, "nwrit=%zd", nwrit);
207 1.1 jruoho
208 1.1 jruoho /* Check that both ends of our pipe are reported as ready. */
209 1.1 jruoho pfds[0].revents = -1;
210 1.1 jruoho pfds[1].revents = -1;
211 1.10 riastrad RL(ret = poll(pfds, 2, 1));
212 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret);
213 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d",
214 1.1 jruoho pfds[0].revents);
215 1.1 jruoho ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
216 1.1 jruoho pfds[1].revents);
217 1.1 jruoho
218 1.10 riastrad RL(close(fds[0]));
219 1.10 riastrad RL(close(fds[1]));
220 1.1 jruoho }
221 1.1 jruoho
222 1.4 kamil ATF_TC(err);
223 1.4 kamil ATF_TC_HEAD(err, tc)
224 1.1 jruoho {
225 1.1 jruoho atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)");
226 1.1 jruoho }
227 1.1 jruoho
228 1.4 kamil ATF_TC_BODY(err, tc)
229 1.1 jruoho {
230 1.1 jruoho struct pollfd pfd;
231 1.1 jruoho int fd = 0;
232 1.1 jruoho
233 1.1 jruoho pfd.fd = fd;
234 1.1 jruoho pfd.events = POLLIN;
235 1.1 jruoho
236 1.1 jruoho errno = 0;
237 1.1 jruoho ATF_REQUIRE_ERRNO(EFAULT, poll((struct pollfd *)-1, 1, -1) == -1);
238 1.1 jruoho
239 1.1 jruoho errno = 0;
240 1.1 jruoho ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1);
241 1.1 jruoho }
242 1.1 jruoho
243 1.5 thorpej static const char fifo_path[] = "pollhup_fifo";
244 1.5 thorpej
245 1.5 thorpej static void
246 1.5 thorpej fifo_support(void)
247 1.5 thorpej {
248 1.10 riastrad
249 1.5 thorpej errno = 0;
250 1.5 thorpej if (mkfifo(fifo_path, 0600) == 0) {
251 1.10 riastrad RL(unlink(fifo_path));
252 1.5 thorpej return;
253 1.5 thorpej }
254 1.5 thorpej
255 1.5 thorpej if (errno == EOPNOTSUPP) {
256 1.5 thorpej atf_tc_skip("the kernel does not support FIFOs");
257 1.5 thorpej } else {
258 1.5 thorpej atf_tc_fail("mkfifo(2) failed");
259 1.5 thorpej }
260 1.5 thorpej }
261 1.5 thorpej
262 1.7 thorpej ATF_TC_WITH_CLEANUP(fifo_inout);
263 1.7 thorpej ATF_TC_HEAD(fifo_inout, tc)
264 1.7 thorpej {
265 1.7 thorpej atf_tc_set_md_var(tc, "descr",
266 1.7 thorpej "Check POLLIN/POLLOUT behavior with fifos");
267 1.7 thorpej }
268 1.7 thorpej
269 1.7 thorpej ATF_TC_BODY(fifo_inout, tc)
270 1.7 thorpej {
271 1.7 thorpej struct pollfd pfd[2];
272 1.7 thorpej char *buf;
273 1.7 thorpej int rfd, wfd;
274 1.7 thorpej long pipe_buf;
275 1.10 riastrad int ret;
276 1.10 riastrad ssize_t nwrit, nread;
277 1.7 thorpej
278 1.7 thorpej fifo_support();
279 1.7 thorpej
280 1.10 riastrad RL(mkfifo(fifo_path, 0600));
281 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
282 1.10 riastrad RL(wfd = open(fifo_path, O_WRONLY | O_NONBLOCK));
283 1.7 thorpej
284 1.7 thorpej /* Get the maximum atomic pipe write size. */
285 1.7 thorpej pipe_buf = fpathconf(wfd, _PC_PIPE_BUF);
286 1.10 riastrad ATF_REQUIRE_MSG(pipe_buf > 1, "pipe_buf=%ld", pipe_buf);
287 1.7 thorpej
288 1.10 riastrad REQUIRE_LIBC(buf = malloc(pipe_buf), NULL);
289 1.7 thorpej
290 1.7 thorpej memset(&pfd, 0, sizeof(pfd));
291 1.7 thorpej pfd[0].fd = rfd;
292 1.7 thorpej pfd[0].events = POLLIN | POLLRDNORM;
293 1.7 thorpej pfd[1].fd = wfd;
294 1.7 thorpej pfd[1].events = POLLOUT | POLLWRNORM;
295 1.7 thorpej
296 1.7 thorpej /* We expect the FIFO to be writable but not readable. */
297 1.10 riastrad RL(ret = poll(pfd, 2, 0));
298 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
299 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0,
300 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents);
301 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
302 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
303 1.7 thorpej
304 1.7 thorpej /* Write a single byte of data into the FIFO. */
305 1.10 riastrad RL(nwrit = write(wfd, buf, 1));
306 1.10 riastrad ATF_REQUIRE_EQ_MSG(nwrit, 1, "nwrit=%zd", nwrit);
307 1.7 thorpej
308 1.7 thorpej /* We expect the FIFO to be readable and writable. */
309 1.10 riastrad RL(ret = poll(pfd, 2, 0));
310 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret);
311 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
312 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents);
313 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
314 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
315 1.7 thorpej
316 1.7 thorpej /* Read that single byte back out. */
317 1.10 riastrad RL(nread = read(rfd, buf, 1));
318 1.10 riastrad ATF_REQUIRE_EQ_MSG(nread, 1, "nread=%zd", nread);
319 1.7 thorpej
320 1.7 thorpej /*
321 1.7 thorpej * Write data into the FIFO until it is full, which is
322 1.7 thorpej * defined as insufficient buffer space to hold a the
323 1.7 thorpej * maximum atomic pipe write size.
324 1.7 thorpej */
325 1.7 thorpej while (write(wfd, buf, pipe_buf) != -1) {
326 1.7 thorpej continue;
327 1.7 thorpej }
328 1.10 riastrad ATF_REQUIRE_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
329 1.7 thorpej
330 1.7 thorpej /* We expect the FIFO to be readble but not writable. */
331 1.10 riastrad RL(ret = poll(pfd, 2, 0));
332 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
333 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
334 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents);
335 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0,
336 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
337 1.7 thorpej
338 1.7 thorpej /* Read a single byte of data from the FIFO. */
339 1.10 riastrad RL(nread = read(rfd, buf, 1));
340 1.10 riastrad ATF_REQUIRE_EQ_MSG(nread, 1, "nread=%zd", nread);
341 1.7 thorpej
342 1.7 thorpej /*
343 1.7 thorpej * Because we have read only a single byte out, there will
344 1.7 thorpej * be insufficient space for a pipe_buf-sized message, so
345 1.7 thorpej * the FIFO should still not be writable.
346 1.7 thorpej */
347 1.10 riastrad RL(ret = poll(pfd, 2, 0));
348 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
349 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, POLLIN|POLLRDNORM,
350 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents);
351 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, 0,
352 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
353 1.7 thorpej
354 1.7 thorpej /*
355 1.8 thorpej * Now read enough so that exactly pipe_buf space should
356 1.8 thorpej * be available. The FIFO should be writable after that.
357 1.8 thorpej * N.B. we don't care if it's readable at this point.
358 1.8 thorpej */
359 1.10 riastrad RL(nread = read(rfd, buf, pipe_buf - 1));
360 1.10 riastrad ATF_REQUIRE_EQ_MSG(nread, pipe_buf - 1, "nread=%zd pipe_buf-1=%ld",
361 1.10 riastrad nread, pipe_buf - 1);
362 1.10 riastrad RL(ret = poll(pfd, 2, 0));
363 1.10 riastrad ATF_REQUIRE_MSG(ret >= 1, "got: %d", ret);
364 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
365 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
366 1.8 thorpej
367 1.8 thorpej /*
368 1.7 thorpej * Now read all of the data out of the FIFO and ensure that
369 1.7 thorpej * we get back to the initial state.
370 1.7 thorpej */
371 1.7 thorpej while (read(rfd, buf, pipe_buf) != -1) {
372 1.7 thorpej continue;
373 1.7 thorpej }
374 1.10 riastrad ATF_REQUIRE_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
375 1.7 thorpej
376 1.10 riastrad RL(ret = poll(pfd, 2, 0));
377 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
378 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[0].revents, 0,
379 1.10 riastrad "pfd[0].revents=0x%x", pfd[0].revents);
380 1.10 riastrad ATF_REQUIRE_EQ_MSG(pfd[1].revents, POLLOUT|POLLWRNORM,
381 1.10 riastrad "pfd[1].revents=0x%x", pfd[1].revents);
382 1.7 thorpej
383 1.10 riastrad RL(close(wfd));
384 1.10 riastrad RL(close(rfd));
385 1.7 thorpej }
386 1.7 thorpej
387 1.7 thorpej ATF_TC_CLEANUP(fifo_inout, tc)
388 1.7 thorpej {
389 1.7 thorpej (void)unlink(fifo_path);
390 1.7 thorpej }
391 1.7 thorpej
392 1.5 thorpej ATF_TC_WITH_CLEANUP(fifo_hup1);
393 1.5 thorpej ATF_TC_HEAD(fifo_hup1, tc)
394 1.5 thorpej {
395 1.5 thorpej atf_tc_set_md_var(tc, "descr",
396 1.5 thorpej "Check POLLHUP behavior with fifos [1]");
397 1.5 thorpej }
398 1.5 thorpej
399 1.5 thorpej ATF_TC_BODY(fifo_hup1, tc)
400 1.5 thorpej {
401 1.5 thorpej struct pollfd pfd;
402 1.5 thorpej int rfd, wfd;
403 1.10 riastrad int ret;
404 1.5 thorpej
405 1.5 thorpej fifo_support();
406 1.5 thorpej
407 1.10 riastrad RL(mkfifo(fifo_path, 0600));
408 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
409 1.10 riastrad RL(wfd = open(fifo_path, O_WRONLY));
410 1.5 thorpej
411 1.5 thorpej memset(&pfd, 0, sizeof(pfd));
412 1.5 thorpej pfd.fd = rfd;
413 1.5 thorpej pfd.events = POLLIN;
414 1.5 thorpej
415 1.10 riastrad RL(close(wfd));
416 1.5 thorpej
417 1.10 riastrad RL(ret = poll(&pfd, 1, 0));
418 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
419 1.9 riastrad ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP,
420 1.11 riastrad "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x",
421 1.9 riastrad pfd.revents, POLLHUP, POLLOUT);
422 1.6 thorpej
423 1.6 thorpej /*
424 1.6 thorpej * Check that POLLHUP is cleared when a writer re-connects.
425 1.6 thorpej * Since the writer will not put any data into the FIFO, we
426 1.6 thorpej * expect no events.
427 1.6 thorpej */
428 1.6 thorpej memset(&pfd, 0, sizeof(pfd));
429 1.6 thorpej pfd.fd = rfd;
430 1.6 thorpej pfd.events = POLLIN;
431 1.6 thorpej
432 1.10 riastrad RL(wfd = open(fifo_path, O_WRONLY));
433 1.10 riastrad RL(ret = poll(&pfd, 1, 0));
434 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 0, "got: %d", ret);
435 1.5 thorpej }
436 1.5 thorpej
437 1.5 thorpej ATF_TC_CLEANUP(fifo_hup1, tc)
438 1.5 thorpej {
439 1.5 thorpej (void)unlink(fifo_path);
440 1.5 thorpej }
441 1.5 thorpej
442 1.5 thorpej ATF_TC_WITH_CLEANUP(fifo_hup2);
443 1.5 thorpej ATF_TC_HEAD(fifo_hup2, tc)
444 1.5 thorpej {
445 1.5 thorpej atf_tc_set_md_var(tc, "descr",
446 1.5 thorpej "Check POLLHUP behavior with fifos [2]");
447 1.5 thorpej }
448 1.5 thorpej
449 1.5 thorpej ATF_TC_BODY(fifo_hup2, tc)
450 1.5 thorpej {
451 1.5 thorpej struct pollfd pfd;
452 1.5 thorpej int rfd, wfd;
453 1.5 thorpej pid_t pid;
454 1.5 thorpej struct timespec ts1, ts2;
455 1.10 riastrad int ret;
456 1.5 thorpej
457 1.5 thorpej fifo_support();
458 1.5 thorpej
459 1.10 riastrad RL(mkfifo(fifo_path, 0600));
460 1.10 riastrad RL(rfd = open(fifo_path, O_RDONLY | O_NONBLOCK));
461 1.10 riastrad RL(wfd = open(fifo_path, O_WRONLY));
462 1.5 thorpej
463 1.5 thorpej memset(&pfd, 0, sizeof(pfd));
464 1.5 thorpej pfd.fd = rfd;
465 1.5 thorpej pfd.events = POLLIN;
466 1.5 thorpej
467 1.10 riastrad RL(pid = fork());
468 1.5 thorpej if (pid == 0) {
469 1.10 riastrad if (close(rfd))
470 1.10 riastrad _exit(1);
471 1.5 thorpej sleep(5);
472 1.10 riastrad if (close(wfd))
473 1.10 riastrad _exit(1);
474 1.5 thorpej _exit(0);
475 1.5 thorpej }
476 1.10 riastrad RL(close(wfd));
477 1.5 thorpej
478 1.10 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &ts1));
479 1.10 riastrad RL(ret = poll(&pfd, 1, INFTIM));
480 1.10 riastrad ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret);
481 1.10 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &ts2));
482 1.5 thorpej
483 1.5 thorpej /* Make sure at least a couple of seconds have elapsed. */
484 1.10 riastrad ATF_REQUIRE_MSG(ts2.tv_sec - ts1.tv_sec >= 2,
485 1.10 riastrad "ts1=%lld.%09ld ts2=%lld.%09ld",
486 1.10 riastrad (long long)ts1.tv_sec, ts1.tv_nsec,
487 1.10 riastrad (long long)ts2.tv_sec, ts2.tv_nsec);
488 1.5 thorpej
489 1.9 riastrad ATF_REQUIRE_EQ_MSG((pfd.revents & (POLLHUP|POLLOUT)), POLLHUP,
490 1.11 riastrad "revents=0x%x expected POLLHUP=0x%x but not POLLOUT=0x%x",
491 1.9 riastrad pfd.revents, POLLHUP, POLLOUT);
492 1.5 thorpej }
493 1.5 thorpej
494 1.5 thorpej ATF_TC_CLEANUP(fifo_hup2, tc)
495 1.5 thorpej {
496 1.5 thorpej (void)unlink(fifo_path);
497 1.5 thorpej }
498 1.5 thorpej
499 1.11 riastrad static void
500 1.11 riastrad fillpipebuf(int writefd)
501 1.11 riastrad {
502 1.11 riastrad char buf[BUFSIZ] = {0};
503 1.11 riastrad size_t n = 0;
504 1.11 riastrad ssize_t nwrit;
505 1.11 riastrad int flags;
506 1.11 riastrad
507 1.11 riastrad RL(flags = fcntl(writefd, F_GETFL));
508 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK));
509 1.11 riastrad while ((nwrit = write(writefd, buf, sizeof(buf))) != -1)
510 1.11 riastrad n += (size_t)nwrit;
511 1.11 riastrad ATF_CHECK_EQ_MSG(errno, EAGAIN, "errno=%d", errno);
512 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags));
513 1.11 riastrad fprintf(stderr, "filled %d with %zu bytes\n", writefd, n);
514 1.11 riastrad }
515 1.11 riastrad
516 1.11 riastrad static void
517 1.11 riastrad check_write_epipe(int writefd)
518 1.11 riastrad {
519 1.11 riastrad int flags;
520 1.11 riastrad void (*sighandler)(int);
521 1.11 riastrad char c = 0;
522 1.11 riastrad ssize_t nwrit;
523 1.11 riastrad
524 1.11 riastrad RL(flags = fcntl(writefd, F_GETFL));
525 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags|O_NONBLOCK));
526 1.11 riastrad
527 1.11 riastrad REQUIRE_LIBC(sighandler = signal(SIGPIPE, SIG_IGN), SIG_ERR);
528 1.11 riastrad ATF_CHECK_ERRNO(EPIPE, (nwrit = write(writefd, &c, 1)) == -1);
529 1.11 riastrad ATF_CHECK_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit);
530 1.11 riastrad REQUIRE_LIBC(signal(SIGPIPE, sighandler), SIG_ERR);
531 1.11 riastrad
532 1.11 riastrad RL(fcntl(writefd, F_SETFL, flags));
533 1.11 riastrad }
534 1.11 riastrad
535 1.11 riastrad static void
536 1.11 riastrad check_read_eof(int readfd)
537 1.11 riastrad {
538 1.11 riastrad int flags;
539 1.11 riastrad char c;
540 1.11 riastrad ssize_t nread;
541 1.11 riastrad
542 1.11 riastrad RL(flags = fcntl(readfd, F_GETFL));
543 1.11 riastrad RL(fcntl(readfd, F_SETFL, flags|O_NONBLOCK));
544 1.11 riastrad
545 1.11 riastrad RL(nread = read(readfd, &c, 1));
546 1.11 riastrad ATF_CHECK_EQ_MSG(nread, 0, "nread=%zu", nread);
547 1.11 riastrad
548 1.11 riastrad RL(fcntl(readfd, F_SETFL, flags));
549 1.11 riastrad }
550 1.11 riastrad
551 1.11 riastrad static void
552 1.11 riastrad check_pollclosed_delayed_write(int writefd, int readfd)
553 1.11 riastrad {
554 1.11 riastrad struct pollfd pfd = { .fd = writefd, .events = POLLOUT };
555 1.11 riastrad struct timespec start, end, delta;
556 1.11 riastrad int nfds;
557 1.11 riastrad
558 1.11 riastrad /*
559 1.11 riastrad * Don't let poll sleep for more than 3sec. (The close delay
560 1.11 riastrad * will be 2sec, and we make sure that we sleep at least 1sec.)
561 1.11 riastrad */
562 1.11 riastrad REQUIRE_LIBC(alarm(3), (unsigned)-1);
563 1.11 riastrad
564 1.11 riastrad /*
565 1.11 riastrad * Wait in poll(2) indefinitely (subject to the alarm) and
566 1.11 riastrad * measure how long we slept.
567 1.11 riastrad */
568 1.11 riastrad fprintf(stderr, "poll %d\n", writefd);
569 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &start));
570 1.11 riastrad RL(nfds = poll(&pfd, 1, INFTIM));
571 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &end));
572 1.11 riastrad fprintf(stderr, "poll %d done nfds=%d\n", writefd, nfds);
573 1.11 riastrad
574 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1);
575 1.11 riastrad
576 1.11 riastrad /*
577 1.11 riastrad * The reader has been closed, so write will fail immediately
578 1.11 riastrad * with EPIPE/SIGPIPE, and thus POLLOUT must be set. POLLHUP
579 1.11 riastrad * is only returned for reads, not for writes (and is mutually
580 1.11 riastrad * exclusive with POLLOUT).
581 1.11 riastrad */
582 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
583 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
584 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d",
585 1.11 riastrad pfd.fd, writefd);
586 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), POLLOUT,
587 1.11 riastrad "revents=0x%x expected POLLOUT=0x%x"
588 1.11 riastrad " but not POLLHUP=0x%x or POLLIN=0x%x",
589 1.11 riastrad pfd.revents, POLLOUT, POLLHUP, POLLIN);
590 1.11 riastrad
591 1.11 riastrad /*
592 1.11 riastrad * We should have slept at least 1sec.
593 1.11 riastrad */
594 1.11 riastrad timespecsub(&end, &start, &delta);
595 1.11 riastrad ATF_CHECK_MSG(delta.tv_sec >= 1,
596 1.11 riastrad "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec);
597 1.11 riastrad
598 1.11 riastrad /*
599 1.11 riastrad * Write should fail with EPIPE/SIGPIPE now -- and continue to
600 1.11 riastrad * do so.
601 1.11 riastrad */
602 1.11 riastrad check_write_epipe(writefd);
603 1.11 riastrad check_write_epipe(writefd);
604 1.11 riastrad }
605 1.11 riastrad
606 1.11 riastrad static void
607 1.11 riastrad check_pollclosed_delayed_read(int readfd, int writefd, int pollhup)
608 1.11 riastrad {
609 1.11 riastrad struct pollfd pfd;
610 1.11 riastrad struct timespec start, end, delta;
611 1.11 riastrad int nfds;
612 1.11 riastrad
613 1.11 riastrad /*
614 1.11 riastrad * Don't let poll sleep for more than 3sec. (The close delay
615 1.11 riastrad * will be 2sec, and we make sure that we sleep at least 1sec.)
616 1.11 riastrad */
617 1.11 riastrad REQUIRE_LIBC(alarm(3), (unsigned)-1);
618 1.11 riastrad
619 1.11 riastrad /*
620 1.11 riastrad * Wait in poll(2) indefinitely (subject to the alarm) and
621 1.11 riastrad * measure how long we slept.
622 1.11 riastrad */
623 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
624 1.11 riastrad fprintf(stderr, "poll %d\n", readfd);
625 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &start));
626 1.11 riastrad RL(nfds = poll(&pfd, 1, INFTIM));
627 1.11 riastrad RL(clock_gettime(CLOCK_MONOTONIC, &end));
628 1.11 riastrad fprintf(stderr, "poll %d done nfds=%d\n", readfd, nfds);
629 1.11 riastrad
630 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1);
631 1.11 riastrad
632 1.11 riastrad /*
633 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be
634 1.11 riastrad * set, and the write side has been closed, so POLLHUP should
635 1.11 riastrad * also be set, unsolicited, if this is a pipe or FIFO -- but
636 1.11 riastrad * not if it's a socket, where POLLHUP is never set. Since we
637 1.11 riastrad * didn't ask for POLLOUT, it should be clear.
638 1.11 riastrad */
639 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
640 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d",
641 1.11 riastrad pfd.fd, readfd, writefd);
642 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
643 1.11 riastrad pollhup|POLLIN,
644 1.11 riastrad "revents=0x%x expected=0x%x"
645 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
646 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
647 1.11 riastrad
648 1.11 riastrad /*
649 1.11 riastrad * We should have slept at least 1sec.
650 1.11 riastrad */
651 1.11 riastrad timespecsub(&end, &start, &delta);
652 1.11 riastrad ATF_CHECK_MSG(delta.tv_sec >= 1,
653 1.11 riastrad "slept only %lld.%09ld", (long long)delta.tv_sec, delta.tv_nsec);
654 1.11 riastrad
655 1.11 riastrad /*
656 1.11 riastrad * Read should return EOF now -- and continue to do so.
657 1.11 riastrad */
658 1.11 riastrad check_read_eof(readfd);
659 1.11 riastrad check_read_eof(readfd);
660 1.11 riastrad
661 1.11 riastrad /*
662 1.11 riastrad * POLLHUP|POLLIN state should be persistent (until the writer
663 1.11 riastrad * side is reopened if possible, as in a named pipe).
664 1.11 riastrad */
665 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
666 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
667 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
668 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, readfd, "pfd.fd=%d readfd=%d writefd=%d",
669 1.11 riastrad pfd.fd, readfd, writefd);
670 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
671 1.11 riastrad pollhup|POLLIN,
672 1.11 riastrad "revents=0x%x expected=0x%x"
673 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
674 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
675 1.11 riastrad }
676 1.11 riastrad
677 1.11 riastrad static void
678 1.11 riastrad check_pollclosed_delayed_read_pipefifo(int readfd, int writefd)
679 1.11 riastrad {
680 1.11 riastrad
681 1.11 riastrad check_pollclosed_delayed_read(readfd, writefd, POLLHUP);
682 1.11 riastrad }
683 1.11 riastrad
684 1.11 riastrad static void
685 1.11 riastrad check_pollclosed_delayed_read_socket(int readfd, int writefd)
686 1.11 riastrad {
687 1.11 riastrad
688 1.11 riastrad check_pollclosed_delayed_read(readfd, writefd, /*no POLLHUP*/0);
689 1.11 riastrad }
690 1.11 riastrad
691 1.11 riastrad static void
692 1.11 riastrad check_pollclosed_delayed_process(int pollfd, int closefd,
693 1.11 riastrad void (*check_pollhup)(int, int))
694 1.11 riastrad {
695 1.11 riastrad pid_t pid;
696 1.11 riastrad int status;
697 1.11 riastrad
698 1.11 riastrad /*
699 1.11 riastrad * Fork a child to close closefd after a 2sec delay.
700 1.11 riastrad */
701 1.11 riastrad RL(pid = fork());
702 1.11 riastrad if (pid == 0) {
703 1.11 riastrad sleep(2);
704 1.11 riastrad fprintf(stderr, "[child] close %d\n", closefd);
705 1.11 riastrad if (close(closefd) == -1)
706 1.11 riastrad _exit(1);
707 1.11 riastrad _exit(0);
708 1.11 riastrad }
709 1.11 riastrad
710 1.11 riastrad /*
711 1.11 riastrad * Close closefd in the parent so the child has the last
712 1.11 riastrad * reference to it.
713 1.11 riastrad */
714 1.11 riastrad fprintf(stderr, "[parent] close %d\n", closefd);
715 1.11 riastrad RL(close(closefd));
716 1.11 riastrad
717 1.11 riastrad /*
718 1.11 riastrad * Test poll(2).
719 1.11 riastrad */
720 1.11 riastrad (*check_pollhup)(pollfd, closefd);
721 1.11 riastrad
722 1.11 riastrad /*
723 1.11 riastrad * Wait for the child and make sure it exited successfully.
724 1.11 riastrad */
725 1.11 riastrad RL(waitpid(pid, &status, 0));
726 1.11 riastrad ATF_CHECK_EQ_MSG(status, 0, "child exited with status 0x%x", status);
727 1.11 riastrad }
728 1.11 riastrad
729 1.11 riastrad static void *
730 1.11 riastrad check_pollclosed_thread(void *cookie)
731 1.11 riastrad {
732 1.11 riastrad int *closefdp = cookie;
733 1.11 riastrad
734 1.11 riastrad sleep(2);
735 1.11 riastrad fprintf(stderr, "[thread] close %d\n", *closefdp);
736 1.11 riastrad RL(close(*closefdp));
737 1.11 riastrad return NULL;
738 1.11 riastrad }
739 1.11 riastrad
740 1.11 riastrad static void
741 1.11 riastrad check_pollclosed_delayed_thread(int pollfd, int closefd,
742 1.11 riastrad void (*check_pollhup)(int, int))
743 1.11 riastrad {
744 1.11 riastrad pthread_t t;
745 1.11 riastrad
746 1.11 riastrad /*
747 1.11 riastrad * Create a thread to close closefd (in this process, not a
748 1.11 riastrad * child) after a 2sec delay.
749 1.11 riastrad */
750 1.11 riastrad RZ(pthread_create(&t, NULL, &check_pollclosed_thread, &closefd));
751 1.11 riastrad
752 1.11 riastrad /*
753 1.11 riastrad * Test poll(2).
754 1.11 riastrad */
755 1.11 riastrad (*check_pollhup)(pollfd, closefd);
756 1.11 riastrad
757 1.11 riastrad /*
758 1.11 riastrad * Wait for the thread to complete.
759 1.11 riastrad */
760 1.11 riastrad RZ(pthread_join(t, NULL));
761 1.11 riastrad }
762 1.11 riastrad
763 1.11 riastrad static void
764 1.11 riastrad check_pollclosed_immediate_write(int writefd, int readfd)
765 1.11 riastrad {
766 1.11 riastrad struct pollfd pfd = { .fd = writefd, .events = POLLOUT };
767 1.11 riastrad int nfds;
768 1.11 riastrad
769 1.11 riastrad /*
770 1.11 riastrad * Close the reader side immediately.
771 1.11 riastrad */
772 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", readfd);
773 1.11 riastrad RL(close(readfd));
774 1.11 riastrad
775 1.11 riastrad /*
776 1.11 riastrad * The reader has been closed, so write will fail immediately
777 1.11 riastrad * with EPIPE/SIGPIPE, and thus POLLOUT must be set. POLLHUP
778 1.11 riastrad * is only returned for reads, not for writes (and is mutually
779 1.11 riastrad * exclusive with POLLOUT).
780 1.11 riastrad */
781 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
782 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
783 1.11 riastrad ATF_CHECK_EQ_MSG(pfd.fd, writefd, "pfd.fd=%d writefd=%d",
784 1.11 riastrad pfd.fd, writefd);
785 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)), POLLOUT,
786 1.11 riastrad "revents=0x%x expected POLLOUT=0x%x"
787 1.11 riastrad " but not POLLHUP=0x%x or POLLIN=0x%x",
788 1.11 riastrad pfd.revents, POLLOUT, POLLHUP, POLLIN);
789 1.11 riastrad
790 1.11 riastrad /*
791 1.11 riastrad * Write should fail with EPIPE/SIGPIPE now -- and continue to
792 1.11 riastrad * do so.
793 1.11 riastrad */
794 1.11 riastrad check_write_epipe(writefd);
795 1.11 riastrad check_write_epipe(writefd);
796 1.11 riastrad }
797 1.11 riastrad
798 1.11 riastrad static void
799 1.11 riastrad check_pollclosed_immediate_readnone(int readfd, int writefd, int pollhup)
800 1.11 riastrad {
801 1.11 riastrad struct pollfd pfd = { .fd = readfd, .events = POLLIN };
802 1.11 riastrad int nfds;
803 1.11 riastrad
804 1.11 riastrad /*
805 1.11 riastrad * Close the writer side immediately.
806 1.11 riastrad */
807 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", writefd);
808 1.11 riastrad RL(close(writefd));
809 1.11 riastrad
810 1.11 riastrad /*
811 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be
812 1.11 riastrad * set, and the write side has been closed, so POLLHUP should
813 1.11 riastrad * be set, unsolicited, if this is a pipe or FIFO -- but not if
814 1.11 riastrad * it's a socket, where POLLHUP is never set. Since we didn't
815 1.11 riastrad * ask for POLLOUT, it should be clear.
816 1.11 riastrad */
817 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
818 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
819 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
820 1.11 riastrad pollhup|POLLIN,
821 1.11 riastrad "revents=0x%x expected=0x%x"
822 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
823 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
824 1.11 riastrad
825 1.11 riastrad /*
826 1.11 riastrad * Read should return EOF now -- and continue to do so.
827 1.11 riastrad */
828 1.11 riastrad check_read_eof(readfd);
829 1.11 riastrad check_read_eof(readfd);
830 1.11 riastrad }
831 1.11 riastrad
832 1.11 riastrad static void
833 1.11 riastrad check_pollclosed_immediate_readsome(int readfd, int writefd, int pollhup)
834 1.11 riastrad {
835 1.11 riastrad struct pollfd pfd;
836 1.11 riastrad char buf[BUFSIZ];
837 1.11 riastrad ssize_t nread;
838 1.11 riastrad int nfds;
839 1.11 riastrad
840 1.11 riastrad /*
841 1.11 riastrad * Close the writer side immediately.
842 1.11 riastrad */
843 1.11 riastrad fprintf(stderr, "[immediate] close %d\n", writefd);
844 1.11 riastrad RL(close(writefd));
845 1.11 riastrad
846 1.11 riastrad /*
847 1.11 riastrad * Some data should be ready to read, so POLLIN should be set,
848 1.11 riastrad * and the write side has been closed, so POLLHUP should also
849 1.11 riastrad * be set, unsolicited, if this is a pipe or FIFO -- but not if
850 1.11 riastrad * it's a socket, where POLLHUP is never set. Since we didn't
851 1.11 riastrad * ask for POLLOUT, it should be clear.
852 1.11 riastrad */
853 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
854 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
855 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
856 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
857 1.11 riastrad POLLIN|pollhup,
858 1.11 riastrad "revents=0x%x expected=0x%x"
859 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
860 1.11 riastrad pfd.revents, POLLIN|pollhup, POLLHUP, POLLIN, POLLOUT);
861 1.11 riastrad
862 1.11 riastrad /*
863 1.11 riastrad * Read all the data. Each read should complete instantly --
864 1.11 riastrad * no blocking, either because there's data to read or because
865 1.11 riastrad * the writer has hung up and we get EOF.
866 1.11 riastrad */
867 1.11 riastrad do {
868 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1);
869 1.11 riastrad RL(nread = read(readfd, buf, sizeof(buf)));
870 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1);
871 1.11 riastrad } while (nread != 0);
872 1.11 riastrad
873 1.11 riastrad /*
874 1.11 riastrad * Read will yield EOF without blocking, so POLLIN should be
875 1.11 riastrad * set, and the write side has been closed, so POLLHUP should
876 1.11 riastrad * also be set, unsolicited, if this is a pipe or FIFO -- but
877 1.11 riastrad * not if it's a socket, where POLLHUP is never set. Since we
878 1.11 riastrad * didn't ask for POLLOUT, it should be clear.
879 1.11 riastrad */
880 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
881 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
882 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
883 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
884 1.11 riastrad pollhup|POLLIN,
885 1.11 riastrad "revents=0x%x expected=0x%x"
886 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
887 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
888 1.11 riastrad
889 1.11 riastrad /*
890 1.11 riastrad * Read should return EOF now -- and continue to do so.
891 1.11 riastrad */
892 1.11 riastrad check_read_eof(readfd);
893 1.11 riastrad check_read_eof(readfd);
894 1.11 riastrad
895 1.11 riastrad /*
896 1.11 riastrad * POLLHUP|POLLIN state should be persistent (until the writer
897 1.11 riastrad * side is reopened if possible, as in a named pipe).
898 1.11 riastrad */
899 1.11 riastrad pfd = (struct pollfd) { .fd = readfd, .events = POLLIN };
900 1.11 riastrad RL(nfds = poll(&pfd, 1, 0));
901 1.11 riastrad ATF_CHECK_EQ_MSG(nfds, 1, "nfds=%d", nfds);
902 1.11 riastrad ATF_CHECK_EQ_MSG((pfd.revents & (POLLHUP|POLLIN|POLLOUT)),
903 1.11 riastrad pollhup|POLLIN,
904 1.11 riastrad "revents=0x%x expected=0x%x"
905 1.11 riastrad " POLLHUP=0x%x POLLIN=0x%x POLLOUT=0x%x",
906 1.11 riastrad pfd.revents, pollhup|POLLIN, POLLHUP, POLLIN, POLLOUT);
907 1.11 riastrad }
908 1.11 riastrad
909 1.11 riastrad static void *
910 1.11 riastrad pollclosed_fifo_writer_thread(void *cookie)
911 1.11 riastrad {
912 1.11 riastrad int *pp = cookie;
913 1.11 riastrad
914 1.11 riastrad RL(*pp = open(fifo_path, O_WRONLY));
915 1.11 riastrad return NULL;
916 1.11 riastrad }
917 1.11 riastrad
918 1.11 riastrad static void *
919 1.11 riastrad pollclosed_fifo_reader_thread(void *cookie)
920 1.11 riastrad {
921 1.11 riastrad int *pp = cookie;
922 1.11 riastrad
923 1.11 riastrad RL(*pp = open(fifo_path, O_RDONLY));
924 1.11 riastrad return NULL;
925 1.11 riastrad }
926 1.11 riastrad
927 1.11 riastrad static void
928 1.11 riastrad pollclosed_fifo0_setup(int *writefdp, int *readfdp)
929 1.11 riastrad {
930 1.11 riastrad int p0, p1;
931 1.11 riastrad pthread_t t;
932 1.11 riastrad
933 1.11 riastrad fifo_support();
934 1.11 riastrad
935 1.11 riastrad RL(mkfifo(fifo_path, 0600));
936 1.11 riastrad RZ(pthread_create(&t, NULL, &pollclosed_fifo_reader_thread, &p0));
937 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1);
938 1.11 riastrad RL(p1 = open(fifo_path, O_WRONLY));
939 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1);
940 1.11 riastrad RZ(pthread_join(t, NULL));
941 1.11 riastrad
942 1.11 riastrad *writefdp = p1;
943 1.11 riastrad *readfdp = p0;
944 1.11 riastrad }
945 1.11 riastrad
946 1.11 riastrad static void
947 1.11 riastrad pollclosed_fifo1_setup(int *writefdp, int *readfdp)
948 1.11 riastrad {
949 1.11 riastrad int p0, p1;
950 1.11 riastrad pthread_t t;
951 1.11 riastrad
952 1.11 riastrad fifo_support();
953 1.11 riastrad
954 1.11 riastrad RL(mkfifo(fifo_path, 0600));
955 1.11 riastrad RZ(pthread_create(&t, NULL, &pollclosed_fifo_writer_thread, &p0));
956 1.11 riastrad REQUIRE_LIBC(alarm(1), (unsigned)-1);
957 1.11 riastrad RL(p1 = open(fifo_path, O_RDONLY));
958 1.11 riastrad REQUIRE_LIBC(alarm(0), (unsigned)-1);
959 1.11 riastrad RZ(pthread_join(t, NULL));
960 1.11 riastrad
961 1.11 riastrad *writefdp = p0;
962 1.11 riastrad *readfdp = p1;
963 1.11 riastrad }
964 1.11 riastrad
965 1.11 riastrad static void
966 1.11 riastrad pollclosed_pipe_setup(int *writefdp, int *readfdp)
967 1.11 riastrad {
968 1.11 riastrad int p[2];
969 1.11 riastrad
970 1.11 riastrad RL(pipe(p));
971 1.11 riastrad
972 1.11 riastrad *readfdp = p[0]; /* reader side */
973 1.11 riastrad *writefdp = p[1]; /* writer side */
974 1.11 riastrad }
975 1.11 riastrad
976 1.11 riastrad static void
977 1.11 riastrad pollclosed_socketpair0_setup(int *writefdp, int *readfdp)
978 1.11 riastrad {
979 1.11 riastrad int s[2];
980 1.11 riastrad
981 1.11 riastrad RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s));
982 1.11 riastrad *readfdp = s[0];
983 1.11 riastrad *writefdp = s[1];
984 1.11 riastrad }
985 1.11 riastrad
986 1.11 riastrad static void
987 1.11 riastrad pollclosed_socketpair1_setup(int *writefdp, int *readfdp)
988 1.11 riastrad {
989 1.11 riastrad int s[2];
990 1.11 riastrad
991 1.11 riastrad RL(socketpair(AF_LOCAL, SOCK_STREAM, 0, s));
992 1.11 riastrad *readfdp = s[1];
993 1.11 riastrad *writefdp = s[0];
994 1.11 riastrad }
995 1.11 riastrad
996 1.11 riastrad /*
997 1.11 riastrad * Cartesian product of:
998 1.11 riastrad *
999 1.11 riastrad * 1. [fifo0] first fifo opener
1000 1.11 riastrad * 2. [fifo1] second fifo opener
1001 1.11 riastrad * 3. [pipe] pipe
1002 1.11 riastrad * 4. [socketpair0] first side of socket pair
1003 1.11 riastrad * 5. [socketpair1] second side of socket pair
1004 1.11 riastrad *
1005 1.11 riastrad * with
1006 1.11 riastrad *
1007 1.11 riastrad * 1. [immediate] closed before poll starts
1008 1.11 riastrad * 2. [delayed_thread] closed by another thread after poll starts
1009 1.11 riastrad * 3. [delayed_process] closed by another process after poll starts
1010 1.11 riastrad *
1011 1.11 riastrad * with
1012 1.11 riastrad *
1013 1.11 riastrad * 1. [writefull] close reader, poll for write when buffer full
1014 1.11 riastrad * 2. [writeempty] close reader, poll for write when buffer empty
1015 1.11 riastrad * 3. [readnone] close writer, poll for read when nothing to read
1016 1.11 riastrad * 4. [readsome] close writer, poll for read when something to read
1017 1.11 riastrad *
1018 1.11 riastrad * except that in the delayed cases we only do writefull [write] and
1019 1.11 riastrad * readnone [read], because there's no delay in the writeempty/readsome
1020 1.11 riastrad * cases.
1021 1.11 riastrad */
1022 1.11 riastrad
1023 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_writefull);
1024 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_writefull, tc)
1025 1.11 riastrad {
1026 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1027 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1028 1.11 riastrad }
1029 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_writefull, tc)
1030 1.11 riastrad {
1031 1.11 riastrad int writefd, readfd;
1032 1.11 riastrad
1033 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1034 1.11 riastrad fillpipebuf(writefd);
1035 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1036 1.11 riastrad }
1037 1.11 riastrad
1038 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_writeempty);
1039 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_writeempty, tc)
1040 1.11 riastrad {
1041 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1042 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1043 1.11 riastrad }
1044 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_writeempty, tc)
1045 1.11 riastrad {
1046 1.11 riastrad int writefd, readfd;
1047 1.11 riastrad
1048 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1049 1.11 riastrad /* don't fill the pipe buf */
1050 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1051 1.11 riastrad }
1052 1.11 riastrad
1053 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_readsome);
1054 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_readsome, tc)
1055 1.11 riastrad {
1056 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1057 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1058 1.11 riastrad }
1059 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_readsome, tc)
1060 1.11 riastrad {
1061 1.11 riastrad int writefd, readfd;
1062 1.11 riastrad
1063 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1064 1.11 riastrad
1065 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1066 1.11 riastrad fillpipebuf(writefd);
1067 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
1068 1.11 riastrad }
1069 1.11 riastrad
1070 1.11 riastrad ATF_TC(pollclosed_fifo0_immediate_readnone);
1071 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_immediate_readnone, tc)
1072 1.11 riastrad {
1073 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1074 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1075 1.11 riastrad }
1076 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_immediate_readnone, tc)
1077 1.11 riastrad {
1078 1.11 riastrad int writefd, readfd;
1079 1.11 riastrad
1080 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1081 1.11 riastrad /* don't fill the pipe buf */
1082 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
1083 1.11 riastrad }
1084 1.11 riastrad
1085 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_process_write);
1086 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_process_write, tc)
1087 1.11 riastrad {
1088 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1089 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1090 1.11 riastrad }
1091 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_process_write, tc)
1092 1.11 riastrad {
1093 1.11 riastrad int writefd, readfd;
1094 1.11 riastrad
1095 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1096 1.11 riastrad fillpipebuf(writefd);
1097 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd,
1098 1.11 riastrad &check_pollclosed_delayed_write);
1099 1.11 riastrad }
1100 1.11 riastrad
1101 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_process_read);
1102 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_process_read, tc)
1103 1.11 riastrad {
1104 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1105 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1106 1.11 riastrad }
1107 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_process_read, tc)
1108 1.11 riastrad {
1109 1.11 riastrad int writefd, readfd;
1110 1.11 riastrad
1111 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1112 1.11 riastrad
1113 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1114 1.11 riastrad /* don't fill pipe buf */
1115 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1116 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1117 1.11 riastrad }
1118 1.11 riastrad
1119 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_thread_write);
1120 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_write, tc)
1121 1.11 riastrad {
1122 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1123 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1124 1.11 riastrad }
1125 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_thread_write, tc)
1126 1.11 riastrad {
1127 1.11 riastrad int writefd, readfd;
1128 1.11 riastrad
1129 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1130 1.11 riastrad fillpipebuf(writefd);
1131 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd,
1132 1.11 riastrad &check_pollclosed_delayed_write);
1133 1.11 riastrad }
1134 1.11 riastrad
1135 1.11 riastrad ATF_TC(pollclosed_fifo0_delayed_thread_read);
1136 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo0_delayed_thread_read, tc)
1137 1.11 riastrad {
1138 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1139 1.11 riastrad "Checks POLLHUP with closing the first opener of a named pipe");
1140 1.11 riastrad }
1141 1.11 riastrad ATF_TC_BODY(pollclosed_fifo0_delayed_thread_read, tc)
1142 1.11 riastrad {
1143 1.11 riastrad int writefd, readfd;
1144 1.11 riastrad
1145 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1146 1.11 riastrad
1147 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1148 1.11 riastrad /* don't fill pipe buf */
1149 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd,
1150 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1151 1.11 riastrad }
1152 1.11 riastrad
1153 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_writefull);
1154 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_writefull, 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 second opener of a named pipe");
1158 1.11 riastrad }
1159 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_writefull, tc)
1160 1.11 riastrad {
1161 1.11 riastrad int writefd, readfd;
1162 1.11 riastrad
1163 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1164 1.11 riastrad fillpipebuf(writefd);
1165 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1166 1.11 riastrad }
1167 1.11 riastrad
1168 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_writeempty);
1169 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_writeempty, tc)
1170 1.11 riastrad {
1171 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1172 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1173 1.11 riastrad }
1174 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_writeempty, tc)
1175 1.11 riastrad {
1176 1.11 riastrad int writefd, readfd;
1177 1.11 riastrad
1178 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1179 1.11 riastrad /* don't fill the pipe buf */
1180 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1181 1.11 riastrad }
1182 1.11 riastrad
1183 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_readsome);
1184 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_readsome, tc)
1185 1.11 riastrad {
1186 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1187 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1188 1.11 riastrad }
1189 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_readsome, tc)
1190 1.11 riastrad {
1191 1.11 riastrad int writefd, readfd;
1192 1.11 riastrad
1193 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1194 1.11 riastrad
1195 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1196 1.11 riastrad fillpipebuf(writefd);
1197 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
1198 1.11 riastrad }
1199 1.11 riastrad
1200 1.11 riastrad ATF_TC(pollclosed_fifo1_immediate_readnone);
1201 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_immediate_readnone, tc)
1202 1.11 riastrad {
1203 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1204 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1205 1.11 riastrad }
1206 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_immediate_readnone, tc)
1207 1.11 riastrad {
1208 1.11 riastrad int writefd, readfd;
1209 1.11 riastrad
1210 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1211 1.11 riastrad /* don't fill the pipe buf */
1212 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
1213 1.11 riastrad }
1214 1.11 riastrad
1215 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_process_write);
1216 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_process_write, tc)
1217 1.11 riastrad {
1218 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1219 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1220 1.11 riastrad }
1221 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_process_write, tc)
1222 1.11 riastrad {
1223 1.11 riastrad int writefd, readfd;
1224 1.11 riastrad
1225 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1226 1.11 riastrad fillpipebuf(writefd);
1227 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd,
1228 1.11 riastrad &check_pollclosed_delayed_write);
1229 1.11 riastrad }
1230 1.11 riastrad
1231 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_process_read);
1232 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_process_read, 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_delayed_process_read, tc)
1238 1.11 riastrad {
1239 1.11 riastrad int writefd, readfd;
1240 1.11 riastrad
1241 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1242 1.11 riastrad
1243 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1244 1.11 riastrad /* don't fill pipe buf */
1245 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1246 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1247 1.11 riastrad }
1248 1.11 riastrad
1249 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_thread_write);
1250 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_write, tc)
1251 1.11 riastrad {
1252 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1253 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1254 1.11 riastrad }
1255 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_thread_write, tc)
1256 1.11 riastrad {
1257 1.11 riastrad int writefd, readfd;
1258 1.11 riastrad
1259 1.11 riastrad pollclosed_fifo1_setup(&writefd, &readfd);
1260 1.11 riastrad fillpipebuf(writefd);
1261 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd,
1262 1.11 riastrad &check_pollclosed_delayed_write);
1263 1.11 riastrad }
1264 1.11 riastrad
1265 1.11 riastrad ATF_TC(pollclosed_fifo1_delayed_thread_read);
1266 1.11 riastrad ATF_TC_HEAD(pollclosed_fifo1_delayed_thread_read, tc)
1267 1.11 riastrad {
1268 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1269 1.11 riastrad "Checks POLLHUP with closing the second opener of a named pipe");
1270 1.11 riastrad }
1271 1.11 riastrad ATF_TC_BODY(pollclosed_fifo1_delayed_thread_read, tc)
1272 1.11 riastrad {
1273 1.11 riastrad int writefd, readfd;
1274 1.11 riastrad
1275 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1276 1.11 riastrad
1277 1.11 riastrad pollclosed_fifo0_setup(&writefd, &readfd);
1278 1.11 riastrad /* don't fill pipe buf */
1279 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1280 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1281 1.11 riastrad }
1282 1.11 riastrad
1283 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_writefull);
1284 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_writefull, tc)
1285 1.11 riastrad {
1286 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1287 1.11 riastrad "Checks POLLHUP with a closed pipe");
1288 1.11 riastrad }
1289 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_writefull, tc)
1290 1.11 riastrad {
1291 1.11 riastrad int writefd, readfd;
1292 1.11 riastrad
1293 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1294 1.11 riastrad
1295 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1296 1.11 riastrad fillpipebuf(writefd);
1297 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1298 1.11 riastrad }
1299 1.11 riastrad
1300 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_writeempty);
1301 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_writeempty, tc)
1302 1.11 riastrad {
1303 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1304 1.11 riastrad "Checks POLLHUP with a closed pipe");
1305 1.11 riastrad }
1306 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_writeempty, tc)
1307 1.11 riastrad {
1308 1.11 riastrad int writefd, readfd;
1309 1.11 riastrad
1310 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1311 1.11 riastrad
1312 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1313 1.11 riastrad /* don't fill pipe buf */
1314 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1315 1.11 riastrad }
1316 1.11 riastrad
1317 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_readsome);
1318 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_readsome, tc)
1319 1.11 riastrad {
1320 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1321 1.11 riastrad "Checks POLLHUP with a closed pipe");
1322 1.11 riastrad }
1323 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_readsome, tc)
1324 1.11 riastrad {
1325 1.11 riastrad int writefd, readfd;
1326 1.11 riastrad
1327 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1328 1.11 riastrad fillpipebuf(writefd);
1329 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, POLLHUP);
1330 1.11 riastrad }
1331 1.11 riastrad
1332 1.11 riastrad ATF_TC(pollclosed_pipe_immediate_readnone);
1333 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_immediate_readnone, tc)
1334 1.11 riastrad {
1335 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1336 1.11 riastrad "Checks POLLHUP with a closed pipe");
1337 1.11 riastrad }
1338 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_immediate_readnone, tc)
1339 1.11 riastrad {
1340 1.11 riastrad int writefd, readfd;
1341 1.11 riastrad
1342 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1343 1.11 riastrad /* don't fill pipe buf */
1344 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, POLLHUP);
1345 1.11 riastrad }
1346 1.11 riastrad
1347 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_process_write);
1348 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_process_write, tc)
1349 1.11 riastrad {
1350 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1351 1.11 riastrad "Checks POLLHUP with a closed pipe");
1352 1.11 riastrad }
1353 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_process_write, tc)
1354 1.11 riastrad {
1355 1.11 riastrad int writefd, readfd;
1356 1.11 riastrad
1357 1.11 riastrad atf_tc_expect_fail("PR kern/59056: poll POLLHUP bugs");
1358 1.11 riastrad
1359 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1360 1.11 riastrad fillpipebuf(writefd);
1361 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd,
1362 1.11 riastrad &check_pollclosed_delayed_write);
1363 1.11 riastrad }
1364 1.11 riastrad
1365 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_process_read);
1366 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_process_read, tc)
1367 1.11 riastrad {
1368 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1369 1.11 riastrad "Checks POLLHUP with a closed pipe");
1370 1.11 riastrad }
1371 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_process_read, tc)
1372 1.11 riastrad {
1373 1.11 riastrad int writefd, readfd;
1374 1.11 riastrad
1375 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1376 1.11 riastrad /* don't fill pipe buf */
1377 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1378 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1379 1.11 riastrad }
1380 1.11 riastrad
1381 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_thread_write);
1382 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_thread_write, tc)
1383 1.11 riastrad {
1384 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1385 1.11 riastrad "Checks POLLHUP with a closed pipe");
1386 1.11 riastrad }
1387 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_thread_write, tc)
1388 1.11 riastrad {
1389 1.11 riastrad int writefd, readfd;
1390 1.11 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.11 riastrad check_pollclosed_delayed_thread(writefd, readfd,
1396 1.11 riastrad &check_pollclosed_delayed_write);
1397 1.11 riastrad }
1398 1.11 riastrad
1399 1.11 riastrad ATF_TC(pollclosed_pipe_delayed_thread_read);
1400 1.11 riastrad ATF_TC_HEAD(pollclosed_pipe_delayed_thread_read, tc)
1401 1.11 riastrad {
1402 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1403 1.11 riastrad "Checks POLLHUP with a closed pipe");
1404 1.11 riastrad }
1405 1.11 riastrad ATF_TC_BODY(pollclosed_pipe_delayed_thread_read, tc)
1406 1.11 riastrad {
1407 1.11 riastrad int writefd, readfd;
1408 1.11 riastrad
1409 1.11 riastrad pollclosed_pipe_setup(&writefd, &readfd);
1410 1.11 riastrad /* don't fill pipe buf */
1411 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd,
1412 1.11 riastrad &check_pollclosed_delayed_read_pipefifo);
1413 1.11 riastrad }
1414 1.11 riastrad
1415 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_writefull);
1416 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_writefull, tc)
1417 1.11 riastrad {
1418 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1419 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1420 1.11 riastrad }
1421 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_writefull, tc)
1422 1.11 riastrad {
1423 1.11 riastrad int writefd, readfd;
1424 1.11 riastrad
1425 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1426 1.11 riastrad fillpipebuf(writefd);
1427 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1428 1.11 riastrad }
1429 1.11 riastrad
1430 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_writeempty);
1431 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_writeempty, tc)
1432 1.11 riastrad {
1433 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1434 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1435 1.11 riastrad }
1436 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_writeempty, tc)
1437 1.11 riastrad {
1438 1.11 riastrad int writefd, readfd;
1439 1.11 riastrad
1440 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1441 1.11 riastrad /* don't fill the pipe buf */
1442 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1443 1.11 riastrad }
1444 1.11 riastrad
1445 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_readsome);
1446 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_readsome, tc)
1447 1.11 riastrad {
1448 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1449 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1450 1.11 riastrad }
1451 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_readsome, tc)
1452 1.11 riastrad {
1453 1.11 riastrad int writefd, readfd;
1454 1.11 riastrad
1455 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1456 1.11 riastrad fillpipebuf(writefd);
1457 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0);
1458 1.11 riastrad }
1459 1.11 riastrad
1460 1.11 riastrad ATF_TC(pollclosed_socketpair0_immediate_readnone);
1461 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_immediate_readnone, tc)
1462 1.11 riastrad {
1463 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1464 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1465 1.11 riastrad }
1466 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_immediate_readnone, tc)
1467 1.11 riastrad {
1468 1.11 riastrad int writefd, readfd;
1469 1.11 riastrad
1470 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1471 1.11 riastrad /* don't fill the pipe buf */
1472 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0);
1473 1.11 riastrad }
1474 1.11 riastrad
1475 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_process_write);
1476 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_write, tc)
1477 1.11 riastrad {
1478 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1479 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1480 1.11 riastrad }
1481 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_process_write, tc)
1482 1.11 riastrad {
1483 1.11 riastrad int writefd, readfd;
1484 1.11 riastrad
1485 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1486 1.11 riastrad fillpipebuf(writefd);
1487 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd,
1488 1.11 riastrad &check_pollclosed_delayed_write);
1489 1.11 riastrad }
1490 1.11 riastrad
1491 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_process_read);
1492 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_process_read, tc)
1493 1.11 riastrad {
1494 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1495 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1496 1.11 riastrad }
1497 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_process_read, tc)
1498 1.11 riastrad {
1499 1.11 riastrad int writefd, readfd;
1500 1.11 riastrad
1501 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1502 1.11 riastrad /* don't fill pipe buf */
1503 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1504 1.11 riastrad &check_pollclosed_delayed_read_socket);
1505 1.11 riastrad }
1506 1.11 riastrad
1507 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_thread_write);
1508 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_write, tc)
1509 1.11 riastrad {
1510 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1511 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1512 1.11 riastrad }
1513 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_write, tc)
1514 1.11 riastrad {
1515 1.11 riastrad int writefd, readfd;
1516 1.11 riastrad
1517 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1518 1.11 riastrad fillpipebuf(writefd);
1519 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd,
1520 1.11 riastrad &check_pollclosed_delayed_write);
1521 1.11 riastrad }
1522 1.11 riastrad
1523 1.11 riastrad ATF_TC(pollclosed_socketpair0_delayed_thread_read);
1524 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair0_delayed_thread_read, tc)
1525 1.11 riastrad {
1526 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1527 1.11 riastrad "Checks POLLHUP with closing the first half of a socketpair");
1528 1.11 riastrad }
1529 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair0_delayed_thread_read, tc)
1530 1.11 riastrad {
1531 1.11 riastrad int writefd, readfd;
1532 1.11 riastrad
1533 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1534 1.11 riastrad /* don't fill pipe buf */
1535 1.11 riastrad check_pollclosed_delayed_thread(readfd, writefd,
1536 1.11 riastrad &check_pollclosed_delayed_read_socket);
1537 1.11 riastrad }
1538 1.11 riastrad
1539 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_writefull);
1540 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_writefull, tc)
1541 1.11 riastrad {
1542 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1543 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1544 1.11 riastrad }
1545 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_writefull, tc)
1546 1.11 riastrad {
1547 1.11 riastrad int writefd, readfd;
1548 1.11 riastrad
1549 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1550 1.11 riastrad fillpipebuf(writefd);
1551 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1552 1.11 riastrad }
1553 1.11 riastrad
1554 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_writeempty);
1555 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_writeempty, tc)
1556 1.11 riastrad {
1557 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1558 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1559 1.11 riastrad }
1560 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_writeempty, tc)
1561 1.11 riastrad {
1562 1.11 riastrad int writefd, readfd;
1563 1.11 riastrad
1564 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1565 1.11 riastrad /* don't fill the pipe buf */
1566 1.11 riastrad check_pollclosed_immediate_write(writefd, readfd);
1567 1.11 riastrad }
1568 1.11 riastrad
1569 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_readsome);
1570 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_readsome, tc)
1571 1.11 riastrad {
1572 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1573 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1574 1.11 riastrad }
1575 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_readsome, tc)
1576 1.11 riastrad {
1577 1.11 riastrad int writefd, readfd;
1578 1.11 riastrad
1579 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1580 1.11 riastrad fillpipebuf(writefd);
1581 1.11 riastrad check_pollclosed_immediate_readsome(readfd, writefd, /*no POLLHUP*/0);
1582 1.11 riastrad }
1583 1.11 riastrad
1584 1.11 riastrad ATF_TC(pollclosed_socketpair1_immediate_readnone);
1585 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_immediate_readnone, tc)
1586 1.11 riastrad {
1587 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1588 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1589 1.11 riastrad }
1590 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_immediate_readnone, tc)
1591 1.11 riastrad {
1592 1.11 riastrad int writefd, readfd;
1593 1.11 riastrad
1594 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1595 1.11 riastrad /* don't fill the pipe buf */
1596 1.11 riastrad check_pollclosed_immediate_readnone(readfd, writefd, /*no POLLHUP*/0);
1597 1.11 riastrad }
1598 1.11 riastrad
1599 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_process_write);
1600 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_write, tc)
1601 1.11 riastrad {
1602 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1603 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1604 1.11 riastrad }
1605 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_process_write, tc)
1606 1.11 riastrad {
1607 1.11 riastrad int writefd, readfd;
1608 1.11 riastrad
1609 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1610 1.11 riastrad fillpipebuf(writefd);
1611 1.11 riastrad check_pollclosed_delayed_process(writefd, readfd,
1612 1.11 riastrad &check_pollclosed_delayed_write);
1613 1.11 riastrad }
1614 1.11 riastrad
1615 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_process_read);
1616 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_process_read, tc)
1617 1.11 riastrad {
1618 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1619 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1620 1.11 riastrad }
1621 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_process_read, tc)
1622 1.11 riastrad {
1623 1.11 riastrad int writefd, readfd;
1624 1.11 riastrad
1625 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1626 1.11 riastrad /* don't fill pipe buf */
1627 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1628 1.11 riastrad &check_pollclosed_delayed_read_socket);
1629 1.11 riastrad }
1630 1.11 riastrad
1631 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_thread_write);
1632 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_write, tc)
1633 1.11 riastrad {
1634 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1635 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1636 1.11 riastrad }
1637 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_write, tc)
1638 1.11 riastrad {
1639 1.11 riastrad int writefd, readfd;
1640 1.11 riastrad
1641 1.11 riastrad pollclosed_socketpair1_setup(&writefd, &readfd);
1642 1.11 riastrad fillpipebuf(writefd);
1643 1.11 riastrad check_pollclosed_delayed_thread(writefd, readfd,
1644 1.11 riastrad &check_pollclosed_delayed_write);
1645 1.11 riastrad }
1646 1.11 riastrad
1647 1.11 riastrad ATF_TC(pollclosed_socketpair1_delayed_thread_read);
1648 1.11 riastrad ATF_TC_HEAD(pollclosed_socketpair1_delayed_thread_read, tc)
1649 1.11 riastrad {
1650 1.11 riastrad atf_tc_set_md_var(tc, "descr",
1651 1.11 riastrad "Checks POLLHUP with closing the second half of a socketpair");
1652 1.11 riastrad }
1653 1.11 riastrad ATF_TC_BODY(pollclosed_socketpair1_delayed_thread_read, tc)
1654 1.11 riastrad {
1655 1.11 riastrad int writefd, readfd;
1656 1.11 riastrad
1657 1.11 riastrad pollclosed_socketpair0_setup(&writefd, &readfd);
1658 1.11 riastrad /* don't fill pipe buf */
1659 1.11 riastrad check_pollclosed_delayed_process(readfd, writefd,
1660 1.11 riastrad &check_pollclosed_delayed_read_socket);
1661 1.11 riastrad }
1662 1.11 riastrad
1663 1.1 jruoho ATF_TP_ADD_TCS(tp)
1664 1.1 jruoho {
1665 1.1 jruoho
1666 1.4 kamil ATF_TP_ADD_TC(tp, 3way);
1667 1.4 kamil ATF_TP_ADD_TC(tp, basic);
1668 1.4 kamil ATF_TP_ADD_TC(tp, err);
1669 1.1 jruoho
1670 1.7 thorpej ATF_TP_ADD_TC(tp, fifo_inout);
1671 1.5 thorpej ATF_TP_ADD_TC(tp, fifo_hup1);
1672 1.5 thorpej ATF_TP_ADD_TC(tp, fifo_hup2);
1673 1.5 thorpej
1674 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writefull);
1675 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writefull);
1676 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writefull);
1677 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writefull);
1678 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writefull);
1679 1.11 riastrad
1680 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_writeempty);
1681 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_writeempty);
1682 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_writeempty);
1683 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_writeempty);
1684 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_writeempty);
1685 1.11 riastrad
1686 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readsome);
1687 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readsome);
1688 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readsome);
1689 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readsome);
1690 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readsome);
1691 1.11 riastrad
1692 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_immediate_readnone);
1693 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_immediate_readnone);
1694 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_immediate_readnone);
1695 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_immediate_readnone);
1696 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_immediate_readnone);
1697 1.11 riastrad
1698 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_write);
1699 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_write);
1700 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_write);
1701 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_write);
1702 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_write);
1703 1.11 riastrad
1704 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_process_read);
1705 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_process_read);
1706 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_process_read);
1707 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_process_read);
1708 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_process_read);
1709 1.11 riastrad
1710 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_write);
1711 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_write);
1712 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_write);
1713 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_write);
1714 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_write);
1715 1.11 riastrad
1716 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo0_delayed_thread_read);
1717 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_fifo1_delayed_thread_read);
1718 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_pipe_delayed_thread_read);
1719 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair0_delayed_thread_read);
1720 1.11 riastrad ATF_TP_ADD_TC(tp, pollclosed_socketpair1_delayed_thread_read);
1721 1.11 riastrad
1722 1.1 jruoho return atf_no_error();
1723 1.1 jruoho }
1724