alsa.audio: add debug logs
[AROS.git] / test / clib / pipe.c
blob109ee563875ffb6fb67b05a273bb5cffc76376ec
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include "test.h"
11 #define BUFLEN 100
13 int filedes[2] = { 0, 0 };
14 int dupfiledes[2] = { 0, 0 };
16 int main()
18 char source[BUFLEN];
19 char destination[BUFLEN];
20 char *str = "foo";
21 char *str2 = "bar";
22 int i;
24 for(i = 0; i < BUFLEN; i++)
25 source[i] = str[i % strlen(str)];
27 TEST((pipe(filedes) == 0));
28 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
29 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
30 TEST((memcmp(source, destination, BUFLEN) == 0));
32 for(i = 0; i < BUFLEN; i++)
33 source[i] = str2[i % strlen(str2)];
35 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
36 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
37 TEST((memcmp(source, destination, BUFLEN) == 0));
39 for(i = 0; i < 10000; i++)
41 char src = i % 256;
42 char dst;
43 TESTFALSE((write(filedes[1], &src, 1) == 1));
44 TESTFALSE((read(filedes[0], &dst, 1) == 1));
45 TESTFALSE((src == dst));
47 printf("10000 read-writes passed, line %d.\n", __LINE__);
49 dupfiledes[0] = dup(filedes[0]);
50 TEST((dupfiledes[0] != -1));
52 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
53 TEST((read(dupfiledes[0], destination, BUFLEN) == BUFLEN));
54 TEST((memcmp(source, destination, BUFLEN) == 0));
56 for(i = 0; i < 10000; i++)
58 char src = i % 256;
59 char dst;
60 TESTFALSE((write(filedes[1], &src, 1) == 1));
61 TESTFALSE((read(dupfiledes[0], &dst, 1) == 1));
62 TESTFALSE((src == dst));
64 printf("10000 read-writes passed, line %d.\n", __LINE__);
66 dupfiledes[1] = dup(filedes[1]);
67 TEST((dupfiledes[1] != -1));
69 TEST((write(dupfiledes[1], source, BUFLEN) == BUFLEN));
70 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
71 TEST((memcmp(source, destination, BUFLEN) == 0));
73 for(i = 0; i < 10000; i++)
75 char src = i % 256;
76 char dst;
77 TESTFALSE((write(dupfiledes[1], &src, 1) == 1));
78 TESTFALSE((read(filedes[0], &dst, 1) == 1));
79 TESTFALSE((src == dst));
81 printf("10000 read-writes passed, line %d.\n", __LINE__);
83 TEST((write(dupfiledes[1], source, BUFLEN) == BUFLEN));
84 TEST((read(dupfiledes[0], destination, BUFLEN) == BUFLEN));
85 TEST((memcmp(source, destination, BUFLEN) == 0));
87 for(i = 0; i < 10000; i++)
89 char src = i % 256;
90 char dst;
91 TESTFALSE((write(dupfiledes[1], &src, 1) == 1));
92 TESTFALSE((read(dupfiledes[0], &dst, 1) == 1));
93 TESTFALSE((src == dst));
95 printf("10000 read-writes passed, line %d.\n", __LINE__);
97 TEST((close(dupfiledes[0]) != -1));
98 dupfiledes[0] = 0;
99 TEST((close(dupfiledes[1]) != -1));
100 dupfiledes[1] = 0;
102 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
103 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
104 TEST((memcmp(source, destination, BUFLEN) == 0));
106 for(i = 0; i < 10000; i++)
108 char src = i % 256;
109 char dst;
110 TESTFALSE((write(filedes[1], &src, 1) == 1));
111 TESTFALSE((read(filedes[0], &dst, 1) == 1));
112 TESTFALSE((src == dst));
114 printf("10000 read-writes passed, line %d.\n", __LINE__);
116 cleanup();
117 return OK;
120 void cleanup()
122 if(filedes[0])
123 close(filedes[0]);
124 if(filedes[1])
125 close(filedes[1]);
126 if(dupfiledes[0])
127 close(dupfiledes[0]);
128 if(dupfiledes[1])
129 close(dupfiledes[1]);