xref: /dragonfly/test/sysperf/pipe1.c (revision b40e316c)
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;
15     int j;
16     int fds[2];
17 
18     printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
19     if (pipe(fds)) {
20 	perror("pipe");
21 	exit(1);
22     }
23     if (fork() == 0) {
24 	/*
25 	 * child process
26 	 */
27 	close(fds[0]);
28 	while (read(fds[1], &c, 1) == 1) {
29 	    write(fds[1], &c, 1);
30 	}
31 	_exit(0);
32     } else {
33 	/*
34 	 * parent process.
35 	 */
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);
45 	    }
46 	}
47 	stop_timing(j, "full duplex pipe / 1char:");
48 	close(fds[0]);
49 	while(wait(NULL) >= 0);
50     }
51     return(0);
52 }
53 
54