16b055cd4SMatthew Dillon /*
26b055cd4SMatthew Dillon * pipe1.c
36b055cd4SMatthew Dillon *
46b055cd4SMatthew Dillon * $DragonFly: src/test/sysperf/pipe1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
56b055cd4SMatthew Dillon */
66b055cd4SMatthew Dillon
7*636b1f09SMatthew Dillon #include <sys/types.h>
8*636b1f09SMatthew Dillon #include <sys/wait.h>
96b055cd4SMatthew Dillon #include "blib.h"
106b055cd4SMatthew Dillon
116b055cd4SMatthew Dillon int
main(int ac,char ** av)126b055cd4SMatthew Dillon main(int ac, char **av)
136b055cd4SMatthew Dillon {
146b055cd4SMatthew Dillon long long count = 0;
156b055cd4SMatthew Dillon long long max;
1692d10ba7SMatthew Dillon char c[1];
176b055cd4SMatthew Dillon int j;
1892d10ba7SMatthew Dillon int loops;
196b055cd4SMatthew Dillon int fds[2];
206b055cd4SMatthew Dillon
216b055cd4SMatthew Dillon printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
226b055cd4SMatthew Dillon if (pipe(fds)) {
236b055cd4SMatthew Dillon perror("pipe");
246b055cd4SMatthew Dillon exit(1);
256b055cd4SMatthew Dillon }
266b055cd4SMatthew Dillon if (fork() == 0) {
276b055cd4SMatthew Dillon /*
286b055cd4SMatthew Dillon * child process
296b055cd4SMatthew Dillon */
306b055cd4SMatthew Dillon close(fds[0]);
3192d10ba7SMatthew Dillon while (read(fds[1], c, sizeof(c)) == sizeof(c)) {
3292d10ba7SMatthew Dillon write(fds[1], c, sizeof(c));
336b055cd4SMatthew Dillon }
346b055cd4SMatthew Dillon _exit(0);
356b055cd4SMatthew Dillon } else {
366b055cd4SMatthew Dillon /*
376b055cd4SMatthew Dillon * parent process.
386b055cd4SMatthew Dillon */
396b055cd4SMatthew Dillon close(fds[1]);
4092d10ba7SMatthew Dillon write(fds[0], c, sizeof(c)); /* prime the caches */
4192d10ba7SMatthew Dillon read(fds[0], c, sizeof(c));
4292d10ba7SMatthew Dillon
436b055cd4SMatthew Dillon start_timing();
4492d10ba7SMatthew Dillon for (j = 0; ; ++j) {
4592d10ba7SMatthew Dillon write(fds[0], c, sizeof(c));
4692d10ba7SMatthew Dillon if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
4792d10ba7SMatthew Dillon fprintf(stderr, "broken pipe during test\n");
4892d10ba7SMatthew Dillon exit(1);
4992d10ba7SMatthew Dillon }
5092d10ba7SMatthew Dillon if ((j & 31) == 0 && stop_timing(0, NULL))
5192d10ba7SMatthew Dillon break;
5292d10ba7SMatthew Dillon }
5392d10ba7SMatthew Dillon loops = j;
5492d10ba7SMatthew Dillon
5592d10ba7SMatthew Dillon start_timing();
5692d10ba7SMatthew Dillon for (j = 0; j < loops; ++j) {
5792d10ba7SMatthew Dillon write(fds[0], c, sizeof(c));
5892d10ba7SMatthew Dillon if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
596b055cd4SMatthew Dillon fprintf(stderr, "broken pipe during test\n");
606b055cd4SMatthew Dillon exit(1);
616b055cd4SMatthew Dillon }
626b055cd4SMatthew Dillon }
636b055cd4SMatthew Dillon stop_timing(j, "full duplex pipe / 1char:");
646b055cd4SMatthew Dillon close(fds[0]);
656b055cd4SMatthew Dillon while(wait(NULL) >= 0);
666b055cd4SMatthew Dillon }
676b055cd4SMatthew Dillon return(0);
686b055cd4SMatthew Dillon }
696b055cd4SMatthew Dillon
70