Lines Matching +full:read +full:- +full:1
1 /*-
8 * 1. Redistributions of source code must retain the above copyright
50 * - If there's no data to read, then for blocking fifos, we block, and for
51 * non-blocking, we return EAGAIN.
53 * - If we write ten bytes, ten bytes can be read, and they're the same
56 * - If we write two batches of five bytes, we can read the same ten bytes in
57 * one read of ten bytes.
59 * - If we write ten bytes, we can read the same ten bytes in two reads of
62 * - If we over-fill a buffer (by writing 512k, which we take to be a large
65 * - That once 512k (ish) is read from the other end, the blocked writer
68 * - When a fifo is empty, poll, select, kqueue, and fionread report it is
71 * - When a fifo has data in it, poll, select, and kqueue report that it is
74 * - XXX: blocked reader semantics?
76 * - XXX: event behavior on remote close?
103 err(-1, "%s: makefifo: mkfifo: %s", testname, fifoname); in makefifo()
110 if (fd1 != -1) in cleanfifo2()
112 if (fd2 != -1) in cleanfifo2()
121 if (fd3 != -1) in cleanfifo3()
127 * Open two different file descriptors for a fifo: one read, one write. Do
128 * so using non-blocking opens in order to avoid deadlocking the process.
137 return (-1); in openfifo()
143 return (-1); in openfifo()
152 * Open one file descriptor for the fifo, supporting both read and write.
161 return (-1); in openfifo_rw()
175 return(-1); in set_nonblocking()
182 return (-1); in set_nonblocking()
196 return(-1); in set_blocking()
203 return (-1); in set_blocking()
220 return (-1); in drain_fd()
222 while ((len = read(fd, &ch, sizeof(ch))) > 0); in drain_fd()
228 warn("%s: drain_fd: read", testname); in drain_fd()
229 return (-1); in drain_fd()
232 warn("%s: drain_fd: read: returned 0 bytes", testname); in drain_fd()
233 return (-1); in drain_fd()
252 cleanfifo2("testfifo", -1, -1); in test_simpleio()
253 exit(-1); in test_simpleio()
263 exit(-1); in test_simpleio()
269 exit(-1); in test_simpleio()
272 len = read(reader_fd, (char *)buffer, sizeof(buffer)); in test_simpleio()
274 warn("test_simpleio: read"); in test_simpleio()
276 exit(-1); in test_simpleio()
279 warnx("test_simpleio: tried %zu but read %zd", sizeof(buffer), in test_simpleio()
282 exit(-1); in test_simpleio()
287 warnx("test_simpleio: write byte %d as 0x%02x, but read " in test_simpleio()
290 exit(-1); in test_simpleio()
298 * Non-destructive SIGALRM handler.
304 alarm_fired = 1; in sigalarm()
325 return (-1); in timed_write()
333 return (-1); in timed_write()
336 *timedoutp = 1; in timed_write()
342 return (-1); in timed_write()
348 * Wrapper function for read, which uses a timer to interrupt any blocking.
365 return (-1); in timed_read()
368 read_len = read(fd, data, len); in timed_read()
373 return (-1); in timed_read()
376 *timedoutp = 1; in timed_read()
382 return (-1); in timed_read()
388 * This test operates on blocking and non-blocking fifo file descriptors, in
390 * mean: don't block for non-blocking sockets, and do block for blocking
411 cleanfifo2("testfifo", -1, -1); in test_blocking_read_empty()
412 exit(-1); in test_blocking_read_empty()
416 * Read one byte from an empty blocking fifo, block as there is no in test_blocking_read_empty()
421 exit(-1); in test_blocking_read_empty()
426 if (ret != -1) { in test_blocking_read_empty()
430 exit(-1); in test_blocking_read_empty()
435 exit(-1); in test_blocking_read_empty()
439 * Read one byte from an empty non-blocking fifo, return EAGAIN as in test_blocking_read_empty()
444 exit(-1); in test_blocking_read_empty()
449 if (ret != -1) { in test_blocking_read_empty()
453 exit(-1); in test_blocking_read_empty()
458 exit(-1); in test_blocking_read_empty()
465 * Write one byte to an empty fifo, then try to read one byte and make sure
466 * we don't block in either the write or the read. This tests both for
479 cleanfifo2("testfifo", -1, -1); in test_blocking_one_byte()
480 exit(-1); in test_blocking_one_byte()
485 exit(-1); in test_blocking_one_byte()
489 exit(-1); in test_blocking_one_byte()
498 exit(-1); in test_blocking_one_byte()
504 exit(-1); in test_blocking_one_byte()
513 exit(-1); in test_blocking_one_byte()
517 "read %zd", sizeof(ch), len); in test_blocking_one_byte()
519 exit(-1); in test_blocking_one_byte()
522 warnx("test_blocking_one_byte: timed_read: expected to read " in test_blocking_one_byte()
523 "0x%02x, read 0x%02x", 0xfe, ch); in test_blocking_one_byte()
525 exit(-1); in test_blocking_one_byte()
532 * Write one byte to an empty fifo, then try to read one byte and make sure
545 cleanfifo2("testfifo", -1, -1); in test_nonblocking_one_byte()
546 exit(-1); in test_nonblocking_one_byte()
551 exit(-1); in test_nonblocking_one_byte()
560 exit(-1); in test_nonblocking_one_byte()
566 exit(-1); in test_nonblocking_one_byte()
575 exit(-1); in test_nonblocking_one_byte()
578 warnx("test_nonblocking_one_byte: timed_read: wanted %zu, read " in test_nonblocking_one_byte()
581 exit(-1); in test_nonblocking_one_byte()
584 warnx("test_nonblocking_one_byte: timed_read: expected to read " in test_nonblocking_one_byte()
585 "0x%02x, read 0x%02x", 0xfe, ch); in test_nonblocking_one_byte()
587 exit(-1); in test_nonblocking_one_byte()
609 cleanfifo2("testfifo", -1, -1); in test_blocking_partial_write()
610 exit(-1); in test_blocking_partial_write()
615 exit(-1); in test_blocking_partial_write()
622 exit(-1); in test_blocking_partial_write()
632 exit(-1); in test_blocking_partial_write()
640 exit(-1); in test_blocking_partial_write()
647 exit(-1); in test_blocking_partial_write()
654 * Write a 512K buffer to an empty fifo using a non-blocking file descriptor,
667 cleanfifo2("testfifo", -1, -1); in test_nonblocking_partial_write()
668 exit(-1); in test_nonblocking_partial_write()
673 exit(-1); in test_nonblocking_partial_write()
680 exit(-1); in test_nonblocking_partial_write()
690 exit(-1); in test_nonblocking_partial_write()
695 "non-blocking socket timed out"); in test_nonblocking_partial_write()
698 exit(-1); in test_nonblocking_partial_write()
706 exit(-1); in test_nonblocking_partial_write()
713 exit(-1); in test_nonblocking_partial_write()
721 * message boundaries by performing two small writes, then a bigger read
734 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_read()
735 exit(-1); in test_coalesce_big_read()
738 /* Write five, write five, read ten. */ in test_coalesce_big_read()
746 exit(-1); in test_coalesce_big_read()
751 exit(-1); in test_coalesce_big_read()
758 exit(-1); in test_coalesce_big_read()
763 exit(-1); in test_coalesce_big_read()
766 len = read(reader_fd, buffer, 10); in test_coalesce_big_read()
768 warn("test_coalesce_big_read: read 10"); in test_coalesce_big_read()
770 exit(-1); in test_coalesce_big_read()
773 warnx("test_coalesce_big_read: read 10 read %zd", len); in test_coalesce_big_read()
775 exit(-1); in test_coalesce_big_read()
781 warnx("test_coalesce_big_read: expected to read 0x%02x, " in test_coalesce_big_read()
782 "read 0x%02x", i, buffer[i]); in test_coalesce_big_read()
784 exit(-1); in test_coalesce_big_read()
787 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_read()
805 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_write()
806 exit(-1); in test_coalesce_big_write()
809 /* Write ten, read five, read five. */ in test_coalesce_big_write()
817 exit(-1); in test_coalesce_big_write()
822 exit(-1); in test_coalesce_big_write()
825 len = read(reader_fd, buffer, 5); in test_coalesce_big_write()
827 warn("test_coalesce_big_write: read 5"); in test_coalesce_big_write()
829 exit(-1); in test_coalesce_big_write()
832 warnx("test_coalesce_big_write: read 5 read %zd", len); in test_coalesce_big_write()
834 exit(-1); in test_coalesce_big_write()
837 len = read(reader_fd, buffer + 5, 5); in test_coalesce_big_write()
839 warn("test_coalesce_big_write: read 5"); in test_coalesce_big_write()
841 exit(-1); in test_coalesce_big_write()
844 warnx("test_coalesce_big_write: read 5 read %zd", len); in test_coalesce_big_write()
846 exit(-1); in test_coalesce_big_write()
852 warnx("test_coalesce_big_write: expected to read 0x%02x, " in test_coalesce_big_write()
853 "read 0x%02x", i, buffer[i]); in test_coalesce_big_write()
855 exit(-1); in test_coalesce_big_write()
858 cleanfifo2("testfifo", -1, -1); in test_coalesce_big_write()
865 struct pollfd fds[1]; in poll_status()
871 if (poll(fds, 1, 0) < 0) { in poll_status()
873 return (-1); in poll_status()
875 *readable = (fds[0].revents & POLLIN) ? 1 : 0; in poll_status()
876 *writable = (fds[0].revents & POLLOUT) ? 1 : 0; in poll_status()
877 *exception = (fds[0].revents & POLLERR) ? 1 : 0; in poll_status()
896 if (select(fd+1, &readfds, &writefds, &exceptfds, &timeout) < 0) { in select_status()
898 return (-1); in select_status()
900 *readable = FD_ISSET(fd, &readfds) ? 1 : 0; in select_status()
901 *writable = FD_ISSET(fd, &writefds) ? 1 : 0; in select_status()
902 *exception = FD_ISSET(fd, &exceptfds) ? 1 : 0; in select_status()
907 * Given an existing kqueue, set up read and write event filters for the
908 * passed file descriptor. Typically called once for the read endpoint, and
924 EV_SET(&kevent_changelist[1], fd, EVFILT_WRITE, EV_ADD, 0, 0, 0); in kqueue_setup()
931 return (-1); in kqueue_setup()
939 if (kp->flags != EV_ERROR) in kqueue_setup()
941 errno = kp->data; in kqueue_setup()
944 return (-1); in kqueue_setup()
965 return (-1); in kqueue_status()
971 if (kp->ident != (u_int)fd) in kqueue_status()
973 if (kp->filter == EVFILT_READ) in kqueue_status()
974 *readable = 1; in kqueue_status()
975 if (kp->filter == EVFILT_WRITE) in kqueue_status()
976 *writable = 1; in kqueue_status()
989 return (-1); in fionread_status()
993 *readable = 1; in fionread_status()
999 #define READABLE 1
1000 #define WRITABLE 1
1001 #define EXCEPTION 1
1015 return (-1); in assert_status()
1021 return (-1); in assert_status()
1025 return (-1); in assert_status()
1031 return (-1); in assert_status()
1036 return (-1); in assert_status()
1042 return (-1); in assert_status()
1046 return (-1); in assert_status()
1051 return (-1); in assert_status()
1074 cleanfifo2("testfifo", -1, -1); in test_events_outofbox()
1075 exit(-1); in test_events_outofbox()
1082 exit(-1); in test_events_outofbox()
1087 exit(-1); in test_events_outofbox()
1092 exit(-1); in test_events_outofbox()
1096 * Make sure that fresh, out-of-the-box fifo file descriptors have in test_events_outofbox()
1099 * a read-only descriptor), and there's no reason for error yet. in test_events_outofbox()
1104 exit(-1); in test_events_outofbox()
1108 * Make sure that fresh, out-of-the-box fifo file descriptors have in test_events_outofbox()
1114 exit(-1); in test_events_outofbox()
1130 cleanfifo2("testfifo", -1, -1); in test_events_write_read_byte()
1131 exit(-1); in test_events_write_read_byte()
1138 exit(-1); in test_events_write_read_byte()
1143 exit(-1); in test_events_write_read_byte()
1148 exit(-1); in test_events_write_read_byte()
1152 * Write a byte to the fifo, and make sure that the read end becomes in test_events_write_read_byte()
1160 exit(-1); in test_events_write_read_byte()
1166 exit(-1); in test_events_write_read_byte()
1175 exit(-1); in test_events_write_read_byte()
1179 * Read the byte from the reader_fd, and now confirm that the fifo in test_events_write_read_byte()
1182 len = read(reader_fd, &ch, sizeof(ch)); in test_events_write_read_byte()
1184 warn("%s: read", __func__); in test_events_write_read_byte()
1186 exit(-1); in test_events_write_read_byte()
1190 NOT_EXCEPTION, __func__, "write+read", "reader_fd") < 0) { in test_events_write_read_byte()
1192 exit(-1); in test_events_write_read_byte()
1199 NOT_EXCEPTION, __func__, "write+read", "writer_fd") < 0) { in test_events_write_read_byte()
1201 exit(-1); in test_events_write_read_byte()
1208 * Write a 512k buffer to the fifo in non-blocking mode, and make sure that
1209 * the write end becomes un-writable as a result of a partial write that
1222 cleanfifo2("testfifo", -1, -1); in test_events_partial_write()
1223 exit(-1); in test_events_partial_write()
1230 exit(-1); in test_events_partial_write()
1235 exit(-1); in test_events_partial_write()
1240 exit(-1); in test_events_partial_write()
1245 exit(-1); in test_events_partial_write()
1252 exit(-1); in test_events_partial_write()
1261 exit(-1); in test_events_partial_write()
1269 exit(-1); in test_events_partial_write()
1274 exit(-1); in test_events_partial_write()
1284 exit(-1); in test_events_partial_write()
1307 cleanfifo2("testfifo", -1, -1); in test_events_rdwr()
1308 exit(-1); in test_events_rdwr()
1314 cleanfifo2("testifo", fd, -1); in test_events_rdwr()
1315 exit(-1); in test_events_rdwr()
1320 exit(-1); in test_events_rdwr()
1330 exit(-1); in test_events_rdwr()
1342 exit(-1); in test_events_rdwr()
1348 exit(-1); in test_events_rdwr()
1352 * Read a byte, which should cause the file descriptor to return to in test_events_rdwr()
1355 len = read(fd, &ch, sizeof(ch)); in test_events_rdwr()
1357 warn("%s: read", __func__); in test_events_rdwr()
1359 exit(-1); in test_events_rdwr()
1363 NOT_EXCEPTION, __func__, "write+read", "fd") < 0) { in test_events_rdwr()
1365 exit(-1); in test_events_rdwr()
1377 err(-1, "mkdtemp"); in main()
1381 err(-1, "chdir %s", temp_dir); in main()