summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/sys/t_poll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/sys/t_poll.c')
-rw-r--r--src/regress/lib/libc/sys/t_poll.c179
1 files changed, 14 insertions, 165 deletions
diff --git a/src/regress/lib/libc/sys/t_poll.c b/src/regress/lib/libc/sys/t_poll.c
index bbb8dc2d14..d27fbf159f 100644
--- a/src/regress/lib/libc/sys/t_poll.c
+++ b/src/regress/lib/libc/sys/t_poll.c
@@ -1,5 +1,5 @@
1/* $OpenBSD: t_poll.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ 1/* $OpenBSD: t_poll.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */
2/* $NetBSD: t_poll.c,v 1.3 2012/03/18 07:00:52 jruoho Exp $ */ 2/* $NetBSD: t_poll.c,v 1.4 2020/07/17 15:34:16 kamil Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -85,8 +85,8 @@ child3(void)
85 (void)printf("child3 exit\n"); 85 (void)printf("child3 exit\n");
86} 86}
87 87
88ATF_TC(poll_3way); 88ATF_TC(3way);
89ATF_TC_HEAD(poll_3way, tc) 89ATF_TC_HEAD(3way, tc)
90{ 90{
91 atf_tc_set_md_var(tc, "timeout", "15"); 91 atf_tc_set_md_var(tc, "timeout", "15");
92 atf_tc_set_md_var(tc, "descr", 92 atf_tc_set_md_var(tc, "descr",
@@ -97,7 +97,7 @@ ATF_TC_HEAD(poll_3way, tc)
97 "both be awaken. (kern/17517)"); 97 "both be awaken. (kern/17517)");
98} 98}
99 99
100ATF_TC_BODY(poll_3way, tc) 100ATF_TC_BODY(3way, tc)
101{ 101{
102 int pf[2]; 102 int pf[2];
103 int status, i; 103 int status, i;
@@ -148,15 +148,15 @@ ATF_TC_BODY(poll_3way, tc)
148 (void)printf("parent terminated\n"); 148 (void)printf("parent terminated\n");
149} 149}
150 150
151ATF_TC(poll_basic); 151ATF_TC(basic);
152ATF_TC_HEAD(poll_basic, tc) 152ATF_TC_HEAD(basic, tc)
153{ 153{
154 atf_tc_set_md_var(tc, "timeout", "10"); 154 atf_tc_set_md_var(tc, "timeout", "10");
155 atf_tc_set_md_var(tc, "descr", 155 atf_tc_set_md_var(tc, "descr",
156 "Basis functionality test for poll(2)"); 156 "Basis functionality test for poll(2)");
157} 157}
158 158
159ATF_TC_BODY(poll_basic, tc) 159ATF_TC_BODY(basic, tc)
160{ 160{
161 int fds[2]; 161 int fds[2];
162 struct pollfd pfds[2]; 162 struct pollfd pfds[2];
@@ -215,13 +215,13 @@ ATF_TC_BODY(poll_basic, tc)
215 ATF_REQUIRE_EQ(close(fds[1]), 0); 215 ATF_REQUIRE_EQ(close(fds[1]), 0);
216} 216}
217 217
218ATF_TC(poll_err); 218ATF_TC(err);
219ATF_TC_HEAD(poll_err, tc) 219ATF_TC_HEAD(err, tc)
220{ 220{
221 atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)"); 221 atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)");
222} 222}
223 223
224ATF_TC_BODY(poll_err, tc) 224ATF_TC_BODY(err, tc)
225{ 225{
226 struct pollfd pfd; 226 struct pollfd pfd;
227 int fd = 0; 227 int fd = 0;
@@ -236,163 +236,12 @@ ATF_TC_BODY(poll_err, tc)
236 ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1); 236 ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1);
237} 237}
238 238
239ATF_TC(pollts_basic);
240ATF_TC_HEAD(pollts_basic, tc)
241{
242 atf_tc_set_md_var(tc, "timeout", "10");
243 atf_tc_set_md_var(tc, "descr",
244 "Basis functionality test for pollts(2)");
245}
246
247ATF_TC_BODY(pollts_basic, tc)
248{
249 int fds[2];
250 struct pollfd pfds[2];
251 struct timespec timeout;
252 int ret;
253
254 ATF_REQUIRE_EQ(pipe(fds), 0);
255
256 pfds[0].fd = fds[0];
257 pfds[0].events = POLLIN;
258 pfds[1].fd = fds[1];
259 pfds[1].events = POLLOUT;
260
261 /* Use a timeout of 1 second. */
262 timeout.tv_sec = 1;
263 timeout.tv_nsec = 0;
264
265 /*
266 * Check that we get a timeout waiting for data on the read end
267 * of our pipe.
268 */
269 pfds[0].revents = -1;
270 pfds[1].revents = -1;
271 ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[0], 1, &timeout, NULL), 0,
272 "got: %d", ret);
273 ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
274 ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents);
275
276 /* Check that the write end of the pipe as reported as ready. */
277 pfds[0].revents = -1;
278 pfds[1].revents = -1;
279 ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[1], 1, &timeout, NULL), 1,
280 "got: %d", ret);
281 ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents);
282 ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\
283 pfds[1].revents);
284
285 /* Check that only the write end of the pipe as reported as ready. */
286 pfds[0].revents = -1;
287 pfds[1].revents = -1;
288 ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 1,
289 "got: %d", ret);
290 ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents);
291 ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
292 pfds[1].revents);
293
294 /* Write data to our pipe. */
295 ATF_REQUIRE_EQ(write(fds[1], "", 1), 1);
296
297 /* Check that both ends of our pipe are reported as ready. */
298 pfds[0].revents = -1;
299 pfds[1].revents = -1;
300 ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 2,
301 "got: %d", ret);
302 ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d",
303 pfds[0].revents);
304 ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",
305 pfds[1].revents);
306
307 ATF_REQUIRE_EQ(close(fds[0]), 0);
308 ATF_REQUIRE_EQ(close(fds[1]), 0);
309}
310
311ATF_TC(pollts_err);
312ATF_TC_HEAD(pollts_err, tc)
313{
314 atf_tc_set_md_var(tc, "descr", "Check errors from pollts(2)");
315}
316
317ATF_TC_BODY(pollts_err, tc)
318{
319 struct timespec timeout;
320 struct pollfd pfd;
321 int fd = 0;
322
323 pfd.fd = fd;
324 pfd.events = POLLIN;
325
326 timeout.tv_sec = 1;
327 timeout.tv_nsec = 0;
328
329 errno = 0;
330 ATF_REQUIRE_ERRNO(EFAULT, pollts((void *)-1, 1, &timeout, NULL) == -1);
331
332 timeout.tv_sec = -1;
333 timeout.tv_nsec = -1;
334
335 errno = 0;
336 ATF_REQUIRE_ERRNO(EINVAL, pollts(&pfd, 1, &timeout, NULL) == -1);
337}
338
339ATF_TC(pollts_sigmask);
340ATF_TC_HEAD(pollts_sigmask, tc)
341{
342 atf_tc_set_md_var(tc, "timeout", "10");
343 atf_tc_set_md_var(tc, "descr",
344 "Check that pollts(2) restores the signal mask (PR kern/44986)");
345}
346
347ATF_TC_BODY(pollts_sigmask, tc)
348{
349 int fd;
350 struct pollfd pfd;
351 struct timespec timeout;
352 sigset_t mask;
353 int ret;
354
355 fd = open(_PATH_DEVNULL, O_RDONLY);
356 ATF_REQUIRE(fd >= 0);
357
358 pfd.fd = fd;
359 pfd.events = POLLIN;
360
361 /* Use a timeout of 1 second. */
362 timeout.tv_sec = 1;
363 timeout.tv_nsec = 0;
364
365 /* Unblock all signals. */
366 ATF_REQUIRE_EQ(sigfillset(&mask), 0);
367 ATF_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &mask, NULL), 0);
368
369 /*
370 * Check that pollts(2) immediately returns. We block *all*
371 * signals during pollts(2).
372 */
373 ATF_REQUIRE_EQ_MSG(ret = pollts(&pfd, 1, &timeout, &mask), 1,
374 "got: %d", ret);
375
376 /* Check that signals are now longer blocked. */
377 ATF_REQUIRE_EQ(sigprocmask(SIG_SETMASK, NULL, &mask), 0);
378 ATF_REQUIRE_EQ_MSG(sigismember(&mask, SIGUSR1), 0,
379 "signal mask was changed.");
380
381 ATF_REQUIRE_EQ(close(fd), 0);
382}
383
384ATF_TP_ADD_TCS(tp) 239ATF_TP_ADD_TCS(tp)
385{ 240{
386 241
387 ATF_TP_ADD_TC(tp, poll_3way); 242 ATF_TP_ADD_TC(tp, 3way);
388 ATF_TP_ADD_TC(tp, poll_basic); 243 ATF_TP_ADD_TC(tp, basic);
389 ATF_TP_ADD_TC(tp, poll_err); 244 ATF_TP_ADD_TC(tp, err);
390 /*
391 * Adjusted for OpenBSD, not supported
392 * ATF_TP_ADD_TC(tp, pollts_basic);
393 * ATF_TP_ADD_TC(tp, pollts_err);
394 * ATF_TP_ADD_TC(tp, pollts_sigmask);
395 */
396 245
397 return atf_no_error(); 246 return atf_no_error();
398} 247}