Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Test code for pipes, using dubious WINS extension for multiple processes...
21 #include <unistd.h> // for MAXPATHLEN
22 #include <sys/errno.h>
23 #include <sys/ioctl.h>
24 #include <e32debug.h> // for RDebug::Print
27 #include <estlib.h> // for multi-threading control
34 #define DebugPrint RDebug::Print
36 inline void DebugPrint(const TDesC&, ...) {}
39 // prepare buf for pipe write/read opereations
40 void fillbuf(int seed, char* buf, int buflen)
45 for (j=0; j<buflen; j++)
50 seed = seed - 127 + 'A';
56 // Producer, writing buf to pipe(fid)
57 void producer(int fid)
64 test_Title("Producer");
66 fillbuf(1,buf,sizeof(buf));
70 nbytes=write(fid, buf, sizeof(buf));
73 test(nbytes==sizeof(buf));
75 TProcessId id=RProcess().Id();
76 TUint pid=*REINTERPRET_CAST(TUint*,&id);
77 DebugPrint(_L("Process %d: Pipe Write success"), pid);
83 #define select_test(fid) \
84 mask=E32SELECT_READ+E32SELECT_WRITE; \
85 err=ioctl(fid,E32IOSELECT,(void*)&mask);
87 // consumer, doing ioctl test and then read from pipe(fid)
88 void consumer(int fid)
95 int mask=E32SELECT_READ;
98 test_Title("Consumer");
99 fillbuf(1,checkbuf,128);
101 test_Next("Simple read, exactly matching write\n");
107 test(mask==E32SELECT_READ);
110 nbytes=read(fid,buf,128);
113 test(memcmp(buf,checkbuf,128)==0);
115 TProcessId id=RProcess().Id();
116 TUint pid=*REINTERPRET_CAST(TUint*,&id);
117 DebugPrint(_L("Process %d: Pipe Read success"), pid);
121 @SYMTestCaseID SYSLIB-STDLIB-UT-1572
122 @SYMTestCaseDesc Tests for cancellation on pipe operations
123 @SYMTestPriority High
124 @SYMTestActions Cancel an outstanding pipe operation request
125 and check if CPosixIPCSession::PipeCancel() handling correct.
126 @SYMTestExpectedResults Test must not fail
129 void pipeCancel(int fid)
133 int mask=E32SELECT_READ+E32SELECT_WRITE;
135 test_Title("Pipe cancellation");
136 DebugPrint(_L("Pipe cancellation test"));
137 TRequestStatus aStatus;
139 // Issue an ansynchronous pipe operation request
140 err=ioctl(fid,E32IOSELECT,(void*)&mask, aStatus);
143 err=ioctl_cancel(fid);
146 TProcessId id=RProcess().Id();
147 TUint pid=*REINTERPRET_CAST(TUint*,&id);
148 DebugPrint(_L("Process %d: Pipe Cancellation SUCCESS"), pid);
155 // testing pipe with writing to child stdin
161 // testing pipe with reading from stdin
164 // pipe cancellation test
172 // Linked with mcrt0.o, so that the exe starts the CPosixServer automatically as per the
175 int main(int argc, char* argv[])
179 start_redirection_server();
183 // create Child process with read/err pipes
184 proc2 = create_process(do_child, "CHILD", "r", fids);
186 start_process(proc2);
188 perror("Failed to start process CHILD: ");
196 exit=wait_for_process(proc2);
197 printf("wait_for_process() returned %d\r\n", exit);
206 // exit here, for the moment crt0 libraries panic