diff options
author | bluhm <> | 2020-11-09 23:18:51 +0000 |
---|---|---|
committer | bluhm <> | 2020-11-09 23:18:51 +0000 |
commit | c369d42df84f5bdabcac9041e6c5680a0cbfeaf9 (patch) | |
tree | 2233f16128b2705882f46a8369c9f9f47f40af5c /src/regress/lib/libc/sys/t_poll.c | |
parent | 999ec352efbeb24cccd1d584b91a659b15764151 (diff) | |
download | openbsd-c369d42df84f5bdabcac9041e6c5680a0cbfeaf9.tar.gz openbsd-c369d42df84f5bdabcac9041e6c5680a0cbfeaf9.tar.bz2 openbsd-c369d42df84f5bdabcac9041e6c5680a0cbfeaf9.zip |
Sync libc syscall tests with changes in upstream NetBSD. Use #ifdef
to document differences to NetBSD behaviour, this helps to track
upstream. Mark currently failing test as expected failures. So
test programs get compiled and executed, but it shows that further
investigation is necceassry.
Diffstat (limited to 'src/regress/lib/libc/sys/t_poll.c')
-rw-r--r-- | src/regress/lib/libc/sys/t_poll.c | 179 |
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 | ||
88 | ATF_TC(poll_3way); | 88 | ATF_TC(3way); |
89 | ATF_TC_HEAD(poll_3way, tc) | 89 | ATF_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 | ||
100 | ATF_TC_BODY(poll_3way, tc) | 100 | ATF_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 | ||
151 | ATF_TC(poll_basic); | 151 | ATF_TC(basic); |
152 | ATF_TC_HEAD(poll_basic, tc) | 152 | ATF_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 | ||
159 | ATF_TC_BODY(poll_basic, tc) | 159 | ATF_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 | ||
218 | ATF_TC(poll_err); | 218 | ATF_TC(err); |
219 | ATF_TC_HEAD(poll_err, tc) | 219 | ATF_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 | ||
224 | ATF_TC_BODY(poll_err, tc) | 224 | ATF_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 | ||
239 | ATF_TC(pollts_basic); | ||
240 | ATF_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 | |||
247 | ATF_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 | |||
311 | ATF_TC(pollts_err); | ||
312 | ATF_TC_HEAD(pollts_err, tc) | ||
313 | { | ||
314 | atf_tc_set_md_var(tc, "descr", "Check errors from pollts(2)"); | ||
315 | } | ||
316 | |||
317 | ATF_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 | |||
339 | ATF_TC(pollts_sigmask); | ||
340 | ATF_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 | |||
347 | ATF_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 | |||
384 | ATF_TP_ADD_TCS(tp) | 239 | ATF_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 | } |