xref: /dragonfly/test/sysperf/pipe1.c (revision 0db87cb7)
1 /*
2  * pipe1.c
3  *
4  * $DragonFly: src/test/sysperf/pipe1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
5  */
6 
7 #include "blib.h"
8 
9 int
10 main(int ac, char **av)
11 {
12     long long count = 0;
13     long long max;
14     char c[1];
15     int j;
16     int loops;
17     int fds[2];
18 
19     printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
20     if (pipe(fds)) {
21 	perror("pipe");
22 	exit(1);
23     }
24     if (fork() == 0) {
25 	/*
26 	 * child process
27 	 */
28 	close(fds[0]);
29 	while (read(fds[1], c, sizeof(c)) == sizeof(c)) {
30 	    write(fds[1], c, sizeof(c));
31 	}
32 	_exit(0);
33     } else {
34 	/*
35 	 * parent process.
36 	 */
37 	close(fds[1]);
38 	write(fds[0], c, sizeof(c));	/* prime the caches */
39 	read(fds[0], c, sizeof(c));
40 
41 	start_timing();
42 	for (j = 0; ; ++j) {
43 	    write(fds[0], c, sizeof(c));
44 	    if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
45 		fprintf(stderr, "broken pipe during test\n");
46 		exit(1);
47 	    }
48 	   if ((j & 31) == 0 && stop_timing(0, NULL))
49 		break;
50 	}
51 	loops = j;
52 
53 	start_timing();
54 	for (j = 0; j < loops; ++j) {
55 	    write(fds[0], c, sizeof(c));
56 	    if (read(fds[0], c, sizeof(c)) != sizeof(c)) {
57 		fprintf(stderr, "broken pipe during test\n");
58 		exit(1);
59 	    }
60 	}
61 	stop_timing(j, "full duplex pipe / 1char:");
62 	close(fds[0]);
63 	while(wait(NULL) >= 0);
64     }
65     return(0);
66 }
67 
68