Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test code for pipes, using dubious WINS extension for multiple processes...
25 #include <unistd.h> /* for MAXPATHLEN */
26 #include <sys/errno.h>
27 #include <sys/ioctl.h>
31 void fillbuf(int seed, char* buf, int buflen)
36 for (j=0; j<buflen; j++)
41 seed = seed - 127 + 'A';
46 @SYMTestCaseID SYSLIB-STDLIB-CT-1078
47 @SYMTestCaseDesc Tests for operations on pipes
49 @SYMTestActions Tests for writing to an opened pipe and a closed pipe
50 @SYMTestExpectedResults Test must not fail
53 void producer(int fid, int final)
61 test_Title("Producer");
65 fillbuf(i,buf,sizeof(buf));
68 nbytes=write(fid, buf, sizeof(buf));
71 test(nbytes==sizeof(buf));
78 test_Next("Writing to closed pipe");
80 fillbuf(0,buf,sizeof(buf));
82 nbytes=write(fid, buf, sizeof(buf));
85 test(t_errno==ENOENT);
88 #define select_test(fid) \
90 mask=E32SELECT_READ+E32SELECT_WRITE; \
91 err=ioctl(fid,E32IOSELECT,(void*)&mask); \
95 @SYMTestCaseID SYSLIB-STDLIB-CT-1079
96 @SYMTestCaseDesc Tests for operations on pipes
98 @SYMTestActions Tests for reading from the pipe,
99 @SYMTestExpectedResults Test must not fail
102 void consumer(int fid, int async)
108 int mask=E32SELECT_READ;
112 test_Title("Asynchronous consumer");
114 test_Title("Consumer");
116 fillbuf(1,checkbuf,128);
118 /* Simple read, exactly matching single write */
120 test_Next("Simple read, exactly matching write");
124 test(mask==E32SELECT_READ);
125 nbytes=read(fid,buf,128);
127 test(memcmp(buf,checkbuf,128)==0);
129 fillbuf(2,checkbuf,128);
130 fillbuf(3,checkbuf+128,128);
132 /* Simple read, exactly matching 2 writes */
134 test_Next("Simple read, exactly matching 2 writes");
138 test(mask==E32SELECT_READ);
139 nbytes=read(fid,buf,256);
141 #ifdef PIPES_SUPPORT_BUFFERING
144 test(nbytes==128); /* truncated at first write */
148 test(mask==E32SELECT_READ);
149 nbytes=read(fid,buf+128,128); /* manually continue the read */
152 test(memcmp(buf,checkbuf,256)==0);
154 fillbuf(4,checkbuf,128);
158 test_Next("Partial read");
162 test(mask==E32SELECT_READ);
163 nbytes=read(fid,buf,100);
165 test(memcmp(buf,checkbuf,100)==0);
167 /* Partial read, completing the write exactly */
169 test_Next("Partial read, completes matching write");
173 test(mask==E32SELECT_READ);
174 nbytes=read(fid,buf,28);
176 test(memcmp(buf,checkbuf+100,28)==0);
178 fillbuf(5,checkbuf,128);
179 fillbuf(6,checkbuf+128,128);
183 test_Next("Partial read");
187 test(mask==E32SELECT_READ);
188 nbytes=read(fid,buf,100);
190 test(memcmp(buf,checkbuf,100)==0);
192 /* Partial read, completing the write and the following write exactly */
194 test_Next("Partial read across write boundary, completes next write");
198 test(mask==E32SELECT_READ);
199 nbytes=read(fid,buf,156);
200 #ifdef PIPES_SUPPORT_BUFFERING
203 test(nbytes==28); /* truncated at first write */
207 test(mask==E32SELECT_READ);
208 nbytes=read(fid,buf+28,128); /* manually continue the read */
211 test(memcmp(buf,checkbuf+100,156)==0);
213 fillbuf(7,checkbuf,128);
214 fillbuf(8,checkbuf+128,128);
218 test_Next("Partial read");
222 test(mask==E32SELECT_READ);
223 nbytes=read(fid,buf,50);
225 test(memcmp(buf,checkbuf,50)==0);
227 /* Partial read, starting part way through the write and still not completing it */
229 test_Next("Partial read, starting part way through write");
233 test(mask==E32SELECT_READ);
234 nbytes=read(fid,buf,50);
236 test(memcmp(buf,checkbuf+50,50)==0);
238 /* Partial read, completing the 1st write and a partial read on the 2nd write */
240 test_Next("Partial read across write boundary");
242 nbytes=read(fid,buf,50);
243 #ifdef PIPES_SUPPORT_BUFFERING
246 test(nbytes==28); /* truncated at first write */
250 test(mask==E32SELECT_READ);
251 nbytes=read(fid,buf+28,22); /* manually continue the read */
254 test(memcmp(buf,checkbuf+100,50)==0);
256 /* Partial read, again in the 2nd write */
258 test_Next("Partial read, starting part way through write");
262 test(mask==E32SELECT_READ);
263 nbytes=read(fid,buf,100);
265 test(memcmp(buf,checkbuf+150,100)==0);
267 /* Partial read, completing the 2nd write exactly */
269 test_Next("Partial read completing write");
273 test(mask==E32SELECT_READ);
274 nbytes=read(fid,buf,6);
276 test(memcmp(buf,checkbuf+250,6)==0);
283 producer(2,0); /* produce on stderr */
284 producer(2,1); /* produce on stderr */
286 consumer(0,0); /* consume on stdin */
287 consumer(0,1); /* consume on stdin */
297 consumer(fids[2],0); /* consume on child stderr */
298 consumer(fids[2],1); /* consume on child stderr */
300 producer(fids[0],0); /* produce on child stdin */
301 producer(fids[0],1); /* produce on child stdin */
304 /* Linked with mcrt0.o, so that the exe starts the CPosixServer automatically as per the
308 int main(int argc, char* argv[])
312 start_redirection_server();
316 proc2 = create_process(do_child, "CHILD", "re", fids);
318 start_process(proc2);
320 perror("Failed to start processB: ");
326 exit=wait_for_process(proc2);
327 printf("wait_for_process returned %d\r\n", exit);