hammer - Fix bugs, fix serious snapshot bug, flush adjustments
[dragonfly.git] / test / sysperf / pipe1.c
blob87978989c15910cc0a03b0953a981eee9692c228
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 <sys/types.h>
8 #include <sys/wait.h>
9 #include "blib.h"
11 int
12 main(int ac, char **av)
14 long long count = 0;
15 long long max;
16 char c[1];
17 int j;
18 int loops;
19 int fds[2];
21 printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
22 if (pipe(fds)) {
23 perror("pipe");
24 exit(1);
26 if (fork() == 0) {
28 * child process
30 close(fds[0]);
31 while (read(fds[1], c, sizeof(c)) == sizeof(c)) {
32 write(fds[1], c, sizeof(c));
34 _exit(0);
35 } else {
36 /*
37 * parent process.
39 close(fds[1]);
40 write(fds[0], c, sizeof(c)); /* prime the caches */
41 read(fds[0], c, sizeof(c));
43 start_timing();
44 for (j = 0; ; ++j) {
45 write(fds[0], c, sizeof(c));
46 if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
47 fprintf(stderr, "broken pipe during test\n");
48 exit(1);
50 if ((j & 31) == 0 && stop_timing(0, NULL))
51 break;
53 loops = j;
55 start_timing();
56 for (j = 0; j < loops; ++j) {
57 write(fds[0], c, sizeof(c));
58 if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
59 fprintf(stderr, "broken pipe during test\n");
60 exit(1);
63 stop_timing(j, "full duplex pipe / 1char:");
64 close(fds[0]);
65 while(wait(NULL) >= 0);
67 return(0);