Lines Matching +full:0 +full:- +full:1
4 * SPDX-License-Identifier: Apache-2.0
18 * Timeout should work the same for blocking & non-blocking threads
20 * - no bytes available to read after timeout, r: 0 (timeout)
21 * - no bytes available to write after timeout, r: 0 (timeout)
27 struct zsock_pollfd fds[1]; in test_socketpair_poll_timeout_common()
29 memset(fds, 0, sizeof(fds)); in test_socketpair_poll_timeout_common()
30 fds[0].fd = fixture->sv[0]; in test_socketpair_poll_timeout_common()
31 fds[0].events |= ZSOCK_POLLIN; in test_socketpair_poll_timeout_common()
32 res = zsock_poll(fds, 1, 1); in test_socketpair_poll_timeout_common()
33 zassert_equal(res, 0, "poll: expected: 0 actual: %d", res); in test_socketpair_poll_timeout_common()
35 for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) { in test_socketpair_poll_timeout_common()
36 res = zsock_send(fixture->sv[0], "x", 1, 0); in test_socketpair_poll_timeout_common()
37 zassert_equal(res, 1, "send() failed: %d", res); in test_socketpair_poll_timeout_common()
40 memset(fds, 0, sizeof(fds)); in test_socketpair_poll_timeout_common()
41 fds[0].fd = fixture->sv[0]; in test_socketpair_poll_timeout_common()
42 fds[0].events |= ZSOCK_POLLOUT; in test_socketpair_poll_timeout_common()
43 res = zsock_poll(fds, 1, 1); in test_socketpair_poll_timeout_common()
44 zassert_equal(res, 0, "poll: expected: 0 actual: %d", res); in test_socketpair_poll_timeout_common()
57 res = zsock_fcntl(fixture->sv[0], F_GETFL, 0); in ZTEST_USER_F()
58 zassert_not_equal(res, -1, "fcntl failed: %d", errno); in ZTEST_USER_F()
62 res = zsock_fcntl(fixture->sv[0], F_SETFL, O_NONBLOCK | flags); in ZTEST_USER_F()
63 zassert_not_equal(res, -1, "fcntl failed: %d", errno); in ZTEST_USER_F()
65 res = zsock_fcntl(fixture->sv[1], F_SETFL, O_NONBLOCK | flags); in ZTEST_USER_F()
66 zassert_not_equal(res, -1, "fcntl failed: %d", errno); in ZTEST_USER_F()
82 *ctx.fd = -1; in close_fun()
87 * - close remote fd while the local fd is blocking in poll. r: 1,
88 * POLLIN, read -> r: 0, errno: 0 -> EOF
89 * - close remote fd while the local fd is blocking in poll. r: 1,
90 * POLLOUT, write -> r: -1, errno: EPIPE.
96 struct zsock_pollfd fds[1]; in ZTEST_F()
103 memset(fds, 0, sizeof(fds)); in ZTEST_F()
104 fds[0].fd = fixture->sv[0]; in ZTEST_F()
105 fds[0].events |= ZSOCK_POLLIN; in ZTEST_F()
107 memset(&ctx, 0, sizeof(ctx)); in ZTEST_F()
108 ctx.fd = &fixture->sv[1]; in ZTEST_F()
115 res = zsock_poll(fds, 1, -1); in ZTEST_F()
116 zassert_equal(res, 1, "poll() failed: %d", res); in ZTEST_F()
117 zassert_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN not set"); in ZTEST_F()
119 res = zsock_recv(fixture->sv[0], &c, 1, 0); in ZTEST_F()
120 zassert_equal(res, 0, "read did not return EOF"); in ZTEST_F()
126 struct zsock_pollfd fds[1]; in ZTEST_F()
133 res = zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv); in ZTEST_F()
134 zassert_not_equal(res, -1, "socketpair() failed: %d", errno); in ZTEST_F()
136 for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) { in ZTEST_F()
137 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_F()
138 zassert_equal(res, 1, "send failed: %d", res); in ZTEST_F()
141 memset(fds, 0, sizeof(fds)); in ZTEST_F()
142 fds[0].fd = fixture->sv[0]; in ZTEST_F()
143 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_F()
145 memset(&ctx, 0, sizeof(ctx)); in ZTEST_F()
146 ctx.fd = &fixture->sv[1]; in ZTEST_F()
153 res = zsock_poll(fds, 1, -1); in ZTEST_F()
154 zassert_equal(res, 1, "poll() failed: %d", res); in ZTEST_F()
155 zassert_equal(fds[0].revents & ZSOCK_POLLHUP, ZSOCK_POLLHUP, "POLLHUP not set"); in ZTEST_F()
157 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_F()
158 zassert_equal(res, -1, "send(): expected: -1 actual: %d", res); in ZTEST_F()
164 * - even with a timeout value of 0 us, poll should return immediately with
165 * a value of 1 (for either read or write cases)
166 * - even with a timeout value of 0us, poll should return immediately with
174 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
175 fds[0].fd = fixture->sv[0]; in ZTEST_USER_F()
176 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_USER_F()
177 res = zsock_poll(fds, 1, 0); in ZTEST_USER_F()
178 zassert_not_equal(res, -1, "poll() failed: %d", errno); in ZTEST_USER_F()
179 zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res); in ZTEST_USER_F()
180 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set"); in ZTEST_USER_F()
182 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_USER_F()
183 zassert_not_equal(res, -1, "send() failed: %d", errno); in ZTEST_USER_F()
184 zassert_equal(res, 1, "write(): expected: 1 actual: %d", res); in ZTEST_USER_F()
186 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
187 fds[0].fd = fixture->sv[1]; in ZTEST_USER_F()
188 fds[0].events |= ZSOCK_POLLIN; in ZTEST_USER_F()
189 res = zsock_poll(fds, 1, 0); in ZTEST_USER_F()
190 zassert_not_equal(res, -1, "poll() failed: %d", errno); in ZTEST_USER_F()
191 zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res); in ZTEST_USER_F()
192 zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set"); in ZTEST_USER_F()
194 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
195 fds[0].fd = fixture->sv[0]; in ZTEST_USER_F()
196 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_USER_F()
197 fds[1].fd = fixture->sv[1]; in ZTEST_USER_F()
198 fds[1].events |= ZSOCK_POLLIN; in ZTEST_USER_F()
199 res = zsock_poll(fds, 2, 0); in ZTEST_USER_F()
200 zassert_not_equal(res, -1, "poll() failed: %d", errno); in ZTEST_USER_F()
201 zassert_equal(res, 2, "poll(): expected: 1 actual: %d", res); in ZTEST_USER_F()
202 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set"); in ZTEST_USER_F()
203 zassert_not_equal(fds[1].revents & ZSOCK_POLLIN, 0, "POLLIN not set"); in ZTEST_USER_F()
219 LOG_DBG("about to write 1 byte"); in rw_fun()
220 res = zsock_send(*ctx.fd, "x", 1, 0); in rw_fun()
221 if (-1 == res) { in rw_fun()
224 LOG_DBG("wrote 1 byte"); in rw_fun()
227 LOG_DBG("about to read 1 byte"); in rw_fun()
228 res = zsock_recv(*ctx.fd, &c, 1, 0); in rw_fun()
229 if (-1 == res) { in rw_fun()
232 LOG_DBG("read 1 byte"); in rw_fun()
239 * - say there is a timeout value of 5 s, poll should return immediately
240 * with the a value of 1 (for either read or write cases)
245 struct zsock_pollfd fds[1]; in ZTEST_F()
247 memset(fds, 0, sizeof(fds)); in ZTEST_F()
248 fds[0].fd = fixture->sv[0]; in ZTEST_F()
249 fds[0].events |= ZSOCK_POLLIN; in ZTEST_F()
251 memset(&ctx, 0, sizeof(ctx)); in ZTEST_F()
252 ctx.fd = &fixture->sv[1]; in ZTEST_F()
260 res = zsock_poll(fds, 1, 5000); in ZTEST_F()
261 zassert_not_equal(res, -1, "poll() failed: %d", errno); in ZTEST_F()
262 zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res); in ZTEST_F()
263 zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set"); in ZTEST_F()
265 for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) { in ZTEST_F()
266 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_F()
267 zassert_equal(res, 1, "send() failed: %d", res); in ZTEST_F()
270 memset(fds, 0, sizeof(fds)); in ZTEST_F()
271 fds[0].fd = fixture->sv[0]; in ZTEST_F()
272 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_F()
274 memset(&ctx, 0, sizeof(ctx)); in ZTEST_F()
275 ctx.fd = &fixture->sv[1]; in ZTEST_F()
283 res = zsock_poll(fds, 1, 5000); in ZTEST_F()
284 zassert_not_equal(res, -1, "poll() failed: %d", errno); in ZTEST_F()
285 zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res); in ZTEST_F()
286 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT was not set"); in ZTEST_F()
291 * - right after socket creation, POLLIN should not be reported
292 * - after data is written to a remote socket, POLLIN should be reported, even
294 * - after reading data from a remote socket, POLLIN shouldn't be reported
301 struct zsock_pollfd fds[1]; in ZTEST_USER_F()
303 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
304 fds[0].fd = fixture->sv[1]; in ZTEST_USER_F()
305 fds[0].events |= ZSOCK_POLLIN; in ZTEST_USER_F()
306 res = zsock_poll(fds, 1, 0); in ZTEST_USER_F()
307 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
308 zassert_equal(res, 0, "poll: expected: 0 actual: %d", res); in ZTEST_USER_F()
309 zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN set"); in ZTEST_USER_F()
311 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_USER_F()
312 zassert_equal(res, 1, "send failed: %d", res); in ZTEST_USER_F()
316 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
317 fds[0].fd = fixture->sv[1]; in ZTEST_USER_F()
318 fds[0].events |= ZSOCK_POLLIN; in ZTEST_USER_F()
319 res = zsock_poll(fds, 1, 1000); in ZTEST_USER_F()
320 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
321 zassert_equal(res, 1, "poll: expected: 1 actual: %d", res); in ZTEST_USER_F()
322 zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set"); in ZTEST_USER_F()
327 res = zsock_recv(fixture->sv[1], &c, 1, 0); in ZTEST_USER_F()
328 zassert_equal(res, 1, "recv failed: %d", res); in ZTEST_USER_F()
330 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
331 fds[0].fd = fixture->sv[1]; in ZTEST_USER_F()
332 fds[0].events |= ZSOCK_POLLIN; in ZTEST_USER_F()
333 res = zsock_poll(fds, 1, 0); in ZTEST_USER_F()
334 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
335 zassert_equal(res, 0, "poll: expected: 0 actual: %d", res); in ZTEST_USER_F()
336 zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN set"); in ZTEST_USER_F()
341 * - right after socket creation, POLLOUT should be reported
342 * - after remote buffer is filled up, POLLOUT shouldn't be reported
343 * - after reading data from a remote socket, POLLOUT should be reported
351 struct zsock_pollfd fds[1]; in ZTEST_USER_F()
355 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
356 fds[0].fd = fixture->sv[0]; in ZTEST_USER_F()
357 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_USER_F()
358 res = zsock_poll(fds, 1, 1000); in ZTEST_USER_F()
359 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
360 zassert_equal(res, 1, "poll: expected: 1 actual: %d", res); in ZTEST_USER_F()
361 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set"); in ZTEST_USER_F()
367 for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) { in ZTEST_USER_F()
368 res = zsock_send(fixture->sv[0], "x", 1, 0); in ZTEST_USER_F()
369 zassert_equal(res, 1, "send() failed: %d", res); in ZTEST_USER_F()
372 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
373 fds[0].fd = fixture->sv[0]; in ZTEST_USER_F()
374 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_USER_F()
375 res = zsock_poll(fds, 1, 0); in ZTEST_USER_F()
376 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
377 zassert_equal(res, 0, "poll: expected: 0 actual: %d", res); in ZTEST_USER_F()
378 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, ZSOCK_POLLOUT, "POLLOUT is set"); in ZTEST_USER_F()
380 res = zsock_recv(fixture->sv[1], &c, 1, 0); in ZTEST_USER_F()
381 zassert_equal(res, 1, "recv() failed: %d", res); in ZTEST_USER_F()
385 memset(fds, 0, sizeof(fds)); in ZTEST_USER_F()
386 fds[0].fd = fixture->sv[0]; in ZTEST_USER_F()
387 fds[0].events |= ZSOCK_POLLOUT; in ZTEST_USER_F()
388 res = zsock_poll(fds, 1, 1000); in ZTEST_USER_F()
389 zassert_not_equal(res, -1, "poll failed: %d", errno); in ZTEST_USER_F()
390 zassert_equal(res, 1, "poll: expected: 1 actual: %d", res); in ZTEST_USER_F()
391 zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set"); in ZTEST_USER_F()