Lines Matching +full:write +full:- +full:to +full:- +full:read

1 /*-
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * Regression test to exercise POSIX fifo I/O.
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?
79 * "reasonable" behavior, and run some additional tests relating to event
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()
237 * Simple I/O test: write ten integers, and make sure we get back the same
239 * bytes in order to not block and deadlock.
252 cleanfifo2("testfifo", -1, -1); in test_simpleio()
253 exit(-1); in test_simpleio()
259 len = write(writer_fd, (char *)buffer, sizeof(buffer)); in test_simpleio()
261 warn("test_simpleio: write"); 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.
308 * Wrapper function for write, which uses a timer to interrupt any blocking.
325 return (-1); in timed_write()
328 written_len = write(fd, data, len); in timed_write()
333 return (-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()
382 return (-1); in timed_read()
388 * This test operates on blocking and non-blocking fifo file descriptors, in
389 * order to determine whether they block at good moments or not. By good we
390 * mean: don't block for non-blocking sockets, and do block for blocking
391 * ones, assuming there isn't I/O buffer to satisfy the request.
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()
501 warnx("test_blocking_one_byte: timed_write: tried to write " 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()
563 warnx("test_nonblocking_one_byte: timed_write: tried to write " 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()
594 * First of two test cases involving a 512K buffer: write the buffer into a
595 * blocking file descriptor. We'd like to know it blocks, but the closest we
596 * can get is to see if SIGALRM fired during the I/O resulting in a partial
597 * write.
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()
742 len = write(writer_fd, buffer, 5); in test_coalesce_big_read()
744 warn("test_coalesce_big_read: write 5"); in test_coalesce_big_read()
746 exit(-1); in test_coalesce_big_read()
749 warnx("test_coalesce_big_read: write 5 wrote %zd", len); in test_coalesce_big_read()
751 exit(-1); in test_coalesce_big_read()
754 len = write(writer_fd, buffer + 5, 5); in test_coalesce_big_read()
756 warn("test_coalesce_big_read: write 5"); in test_coalesce_big_read()
758 exit(-1); in test_coalesce_big_read()
761 warnx("test_coalesce_big_read: write 5 wrote %zd", len); 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()
792 * message boundaries by performing one big write, then two smaller reads
793 * that should return sequential elements of data from the write.
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()
813 len = write(writer_fd, buffer, 10); in test_coalesce_big_write()
815 warn("test_coalesce_big_write: write 10"); in test_coalesce_big_write()
817 exit(-1); in test_coalesce_big_write()
820 warnx("test_coalesce_big_write: write 10 wrote %zd", len); 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()
873 return (-1); in poll_status()
898 return (-1); 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
909 * once for the write endpoint.
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()
975 if (kp->filter == EVFILT_WRITE) in kqueue_status()
989 return (-1); in fionread_status()
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()
1058 * test_events() uses poll(), select(), and kevent() to query the status of
1063 * It would be nice to also test status changes as a result of closing of one
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()
1109 * good initial states. The writer_fd should be ready to write. 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()
1153 * readable, and that the write end remains writable (small write). in test_events_write_read_byte()
1156 len = write(writer_fd, &ch, sizeof(ch)); in test_events_write_read_byte()
1158 warn("%s: write", __func__); in test_events_write_read_byte()
1160 exit(-1); in test_events_write_read_byte()
1164 NOT_EXCEPTION, __func__, "write", "reader_fd") < 0) { in test_events_write_read_byte()
1166 exit(-1); in test_events_write_read_byte()
1173 NOT_EXCEPTION, __func__, "write", "writer_fd") < 0) { 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()
1256 len = write(writer_fd, buffer, 512*1024); in test_events_partial_write()
1258 warn("test_events_partial_write: write"); in test_events_partial_write()
1261 exit(-1); in test_events_partial_write()
1267 NOT_EXCEPTION, __func__, "big write", "writer_fd") < 0) { in test_events_partial_write()
1269 exit(-1); in test_events_partial_write()
1274 exit(-1); in test_events_partial_write()
1278 * Test that the writer_fd has been restored to writable state after in test_events_partial_write()
1282 NOT_EXCEPTION, __func__, "big write + drain", "writer_fd") < 0) { in test_events_partial_write()
1284 exit(-1); in test_events_partial_write()
1292 * of event tests to make sure that the fifo implementation doesn't mixed up
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()
1334 * Write a byte, which should cause the file descriptor to become in test_events_rdwr()
1338 len = write(fd, &ch, sizeof(ch)); in test_events_rdwr()
1340 warn("%s: write", __func__); in test_events_rdwr()
1342 exit(-1); in test_events_rdwr()
1346 __func__, "write", "fd") < 0) { 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()