Sync with HEAD.
[dragonfly.git] / test / sysperf / pipe1.c
blob50a2d686d3f3772f18fe5d7c9c66663491fd09d6
1 /*
2 * pipe1.c
4 * $DragonFly: src/test/sysperf/pipe1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
5 */
7 #include "blib.h"
9 int
10 main(int ac, char **av)
12 long long count = 0;
13 long long max;
14 char c;
15 int j;
16 int fds[2];
18 printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
19 if (pipe(fds)) {
20 perror("pipe");
21 exit(1);
23 if (fork() == 0) {
25 * child process
27 close(fds[0]);
28 while (read(fds[1], &c, 1) == 1) {
29 write(fds[1], &c, 1);
31 _exit(0);
32 } else {
33 /*
34 * parent process.
36 close(fds[1]);
37 write(fds[0], &c, 1); /* prime the caches */
38 read(fds[0], &c, 1);
39 start_timing();
40 for (j = 0; j < 100000; ++j) {
41 write(fds[0], &c, 1);
42 if (read(fds[0], &c, 1) != 1) {
43 fprintf(stderr, "broken pipe during test\n");
44 exit(1);
47 stop_timing(j, "full duplex pipe / 1char:");
48 close(fds[0]);
49 while(wait(NULL) >= 0);
51 return(0);