taskqueue - Improve _start_threads, refactor code
[dragonfly.git] / test / sysperf / pipe1.c
blob9e06a6b3c892ebc8536e316bb2822c71807d7084
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[1];
15 int j;
16 int loops;
17 int fds[2];
19 printf("tests full duplex pipe 1write,2read,2write,1read loop\n");
20 if (pipe(fds)) {
21 perror("pipe");
22 exit(1);
24 if (fork() == 0) {
26 * child process
28 close(fds[0]);
29 while (read(fds[1], c, sizeof(c)) == sizeof(c)) {
30 write(fds[1], c, sizeof(c));
32 _exit(0);
33 } else {
34 /*
35 * parent process.
37 close(fds[1]);
38 write(fds[0], c, sizeof(c)); /* prime the caches */
39 read(fds[0], c, sizeof(c));
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);
48 if ((j & 31) == 0 && stop_timing(0, NULL))
49 break;
51 loops = j;
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);
61 stop_timing(j, "full duplex pipe / 1char:");
62 close(fds[0]);
63 while(wait(NULL) >= 0);
65 return(0);