0
|
1 |
// Copyright (c) 2002-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 the License "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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\pipe\t_pipe.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test pipe mechanism
|
|
17 |
// API Information:
|
|
18 |
// RPipe
|
|
19 |
// Details:
|
|
20 |
// - Create various leagal and illegal pipe and verify that pipe
|
|
21 |
// functionality works as stated in requirements.
|
|
22 |
// - Create Named and UnNamed Pipes and verify.
|
|
23 |
// - Test Pipes communication in multiprocess , multithreaded , single process
|
|
24 |
// single threaded environment.
|
|
25 |
// Platforms/Drives/Compatibility:
|
|
26 |
// All.
|
|
27 |
// Assumptions/Requirement/Pre-requisites:
|
|
28 |
// Refer Pipes design and requirement document.
|
|
29 |
// 1. SGL.GT0314.202 PREQ1460 Design Doc
|
|
30 |
// 2. SGL.GT0314.203 PREQ1460 Pipe Functional Specification
|
|
31 |
// Refer Pipe test specification document.
|
|
32 |
// 1. SGL.GT0314.601 Pipes_Test_Specifications
|
|
33 |
// Failures and causes:
|
|
34 |
// Base Port information:
|
|
35 |
// MMP File:
|
|
36 |
// t_pipe.mmp
|
|
37 |
//
|
|
38 |
//
|
|
39 |
|
|
40 |
/**
|
|
41 |
@STMTestCaseID KBASE-T_PIPE-0217
|
|
42 |
@SYMPREQ PREQ1460
|
|
43 |
@SYMREQ REQ6141
|
|
44 |
@SYMCR CR0923
|
|
45 |
@SYMTestCaseDesc Pipe functional tests
|
|
46 |
@SYMTestPriority High
|
|
47 |
@SYMTestActions Tests the functionality of the pipe. Success and failure tests are performed.
|
|
48 |
@SYMTestExpectedResults Test should pass
|
|
49 |
*/
|
|
50 |
|
|
51 |
#define __E32TEST_EXTENSION__
|
|
52 |
#include <e32test.h>
|
|
53 |
#include <e32svr.h>
|
|
54 |
#include <e32des8.h>
|
|
55 |
#include <e32des8_private.h>
|
|
56 |
#include <e32cmn.h>
|
|
57 |
#include <e32cmn_private.h>
|
|
58 |
#include <e32math.h>
|
|
59 |
#include <hal.h>
|
|
60 |
|
|
61 |
#include "RPipe.h"
|
|
62 |
|
|
63 |
LOCAL_D RTest test(_L("t_pipe"));
|
|
64 |
|
|
65 |
|
|
66 |
//if the test is to run under the debugger, uncomment the following line
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
const TInt KHeapSize=0x2000;
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
// Test Data
|
|
75 |
_LIT8(KTestData,"Pipe Data To Be Passed");
|
|
76 |
_LIT8(KTestData1,"P");
|
|
77 |
_LIT8(KTestData2,"Pipe Data To Be Passed");
|
|
78 |
_LIT8(KTestData3,"ipe Data To Be Passed");
|
|
79 |
|
|
80 |
|
|
81 |
// Test Pipe Names
|
|
82 |
_LIT(KPipe1Name,"TestPipe1");
|
|
83 |
_LIT(KPipe3Name,"TestPipe3");
|
|
84 |
|
|
85 |
//Global semaphore name
|
|
86 |
_LIT(KSemaphoreName,"Semaphore1");
|
|
87 |
|
|
88 |
// Pipename of max pipe length 80 Charecters.
|
|
89 |
_LIT(KMaxPipeName,"abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrst");
|
|
90 |
// PipeName of max pipe length plus one ,81 charecters
|
|
91 |
_LIT(KMaxPipeNamePlusOne,"abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrst1");
|
|
92 |
|
|
93 |
// Thread Name Constants
|
|
94 |
_LIT(KThread2Name, "thread2");
|
|
95 |
_LIT(KThread3Name, "thread3");
|
|
96 |
_LIT(KThread4Name, "thread4");
|
|
97 |
_LIT(KThread5Name, "thread5");
|
|
98 |
_LIT(KReaderThread, "ReaderThread");
|
|
99 |
_LIT(KWriterThread, "WriterThread");
|
|
100 |
_LIT(KThread8Name, "thread8");
|
|
101 |
_LIT(KThread9Name, "thread9");
|
|
102 |
_LIT(KThread11Name, "thread11");
|
|
103 |
|
|
104 |
// Test Process Name Constants
|
|
105 |
_LIT(KProcessName, "t_pipe2.exe");
|
|
106 |
|
|
107 |
|
|
108 |
// Following class is used to pass thread handle information to different threads.
|
|
109 |
class TData
|
|
110 |
{
|
|
111 |
public:
|
|
112 |
TData(RPipe* aReadEnd, RPipe *aWriteEnd);
|
|
113 |
TData(RPipe* aReadEnd, RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations=1);
|
|
114 |
RPipe* iReadEnd;
|
|
115 |
RPipe* iWriteEnd;
|
|
116 |
const TDesC8* iPipeData;
|
|
117 |
TInt iIterations;
|
|
118 |
};
|
|
119 |
|
|
120 |
TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd)
|
|
121 |
:iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(NULL), iIterations(NULL)
|
|
122 |
{}
|
|
123 |
|
|
124 |
TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations)
|
|
125 |
:iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(aPipeData), iIterations(aIterations)
|
|
126 |
{}
|
|
127 |
|
|
128 |
/**
|
|
129 |
A utility class for running functions in other threads/processes
|
|
130 |
*/
|
|
131 |
class TTestRemote
|
|
132 |
{
|
|
133 |
public:
|
|
134 |
virtual TInt WaitForExitL()=0;
|
|
135 |
virtual ~TTestRemote()
|
|
136 |
{}
|
|
137 |
|
|
138 |
virtual void Rendezvous(TRequestStatus& aStatus) =0;
|
|
139 |
|
|
140 |
protected:
|
|
141 |
TTestRemote()
|
|
142 |
{}
|
|
143 |
|
|
144 |
static TInt RunFunctor(TAny* aFunctor)
|
|
145 |
{
|
|
146 |
TFunctor& functor = *(TFunctor*)aFunctor;
|
|
147 |
functor();
|
|
148 |
return KErrNone;
|
|
149 |
}
|
|
150 |
|
|
151 |
TRequestStatus iLogonStatus;
|
|
152 |
static TInt iCount;
|
|
153 |
};
|
|
154 |
TInt TTestRemote::iCount=0;
|
|
155 |
|
|
156 |
class TTestThread : public TTestRemote
|
|
157 |
{
|
|
158 |
public:
|
|
159 |
TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue)
|
|
160 |
{
|
|
161 |
Init(aName, aFn, aData, aAutoResume);
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
165 |
Run aFunctor in another thread
|
|
166 |
*/
|
|
167 |
TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue)
|
|
168 |
{
|
|
169 |
Init(aName, RunFunctor, &aFunctor, aAutoResume);
|
|
170 |
}
|
|
171 |
|
|
172 |
~TTestThread()
|
|
173 |
{
|
|
174 |
//RTest::CloseHandleAndWaitForDestruction(iThread);
|
|
175 |
iThread.Close();
|
|
176 |
}
|
|
177 |
|
|
178 |
void Resume()
|
|
179 |
{
|
|
180 |
iThread.Resume();
|
|
181 |
}
|
|
182 |
|
|
183 |
/**
|
|
184 |
If thread exited normally, return its return code
|
|
185 |
Otherwise, leave with exit reason
|
|
186 |
*/
|
|
187 |
virtual TInt WaitForExitL()
|
|
188 |
{
|
|
189 |
User::WaitForRequest(iLogonStatus);
|
|
190 |
const TInt exitType = iThread.ExitType();
|
|
191 |
const TInt exitReason = iThread.ExitReason();
|
|
192 |
|
|
193 |
__ASSERT_ALWAYS(exitType != EExitPending, User::Panic(_L("TTestThread"),0));
|
|
194 |
|
|
195 |
if(exitType != EExitKill)
|
|
196 |
User::Leave(exitReason);
|
|
197 |
|
|
198 |
return exitReason;
|
|
199 |
}
|
|
200 |
|
|
201 |
virtual void Rendezvous(TRequestStatus& aStatus)
|
|
202 |
{
|
|
203 |
iThread.Rendezvous(aStatus);
|
|
204 |
}
|
|
205 |
|
|
206 |
private:
|
|
207 |
void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume)
|
|
208 |
{
|
|
209 |
TKName name(aName);
|
|
210 |
name.AppendFormat(_L("-%d"), iCount++);
|
|
211 |
TInt r=iThread.Create(name, aFn, KDefaultStackSize, KHeapSize, KHeapSize, aData);
|
|
212 |
User::LeaveIfError(r);
|
|
213 |
|
|
214 |
iThread.Logon(iLogonStatus);
|
|
215 |
__ASSERT_ALWAYS(iLogonStatus == KRequestPending, User::Panic(_L("TTestThread"),0));
|
|
216 |
|
|
217 |
if(aAutoResume)
|
|
218 |
iThread.Resume();
|
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
RThread iThread;
|
|
224 |
};
|
|
225 |
|
|
226 |
|
|
227 |
/**
|
|
228 |
Non blocking reads, verifying data as expected
|
|
229 |
*/
|
|
230 |
TInt TestThread2(TAny* aData)
|
|
231 |
{
|
|
232 |
RTest test(_L("t_pipe_t2"));
|
|
233 |
|
|
234 |
test.Start(_L("Thread 2"));
|
|
235 |
test.Printf(_L("THREAD 2 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
|
|
236 |
|
|
237 |
TBuf8<50> cPipeReadData;
|
|
238 |
TInt ret,readsize;
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
243 |
|
|
244 |
|
|
245 |
test.Next(_L("PIPE TEST:Thread 2-1 Read 1 byte of data from the pipe : Test for success\n"));
|
|
246 |
readsize = 1;
|
|
247 |
|
|
248 |
ret = data.iReadEnd->Read(cPipeReadData ,readsize);
|
|
249 |
test_Equal(readsize, ret);
|
|
250 |
|
|
251 |
|
|
252 |
test.Next(_L("PIPE TEST:Thread 2-2 Validate 1 byte received is correct\n"));
|
|
253 |
ret = cPipeReadData.Compare(KTestData1);
|
|
254 |
test_KErrNone(ret);
|
|
255 |
|
|
256 |
|
|
257 |
test.Next(_L("PIPE TEST:Thread 2-3 Read remaining data from the pipe\n"));
|
|
258 |
readsize = 21;
|
|
259 |
ret = data.iReadEnd->Read(cPipeReadData , readsize);
|
|
260 |
test_Equal(readsize, ret);
|
|
261 |
|
|
262 |
test.Next(_L("PIPE TEST:Thread 2-4 Validate received data\n"));
|
|
263 |
ret = cPipeReadData.Compare(KTestData3);
|
|
264 |
test_KErrNone(ret);
|
|
265 |
|
|
266 |
test.End();
|
|
267 |
test.Close();
|
|
268 |
return KErrNone;
|
|
269 |
|
|
270 |
|
|
271 |
}
|
|
272 |
/****************************************************************************
|
|
273 |
This function is used as thread to test Unnamed pipes.
|
|
274 |
TestMultiThreadUnNamedPipes() will use this function.
|
|
275 |
TestMultiThreadNamedPipes() will use this function.
|
|
276 |
@aData : Used to pass the pipe and handle its size information.
|
|
277 |
|
|
278 |
Return Value : TInt
|
|
279 |
|
|
280 |
******************************************************************************/
|
|
281 |
TInt TestThread3(TAny* aData) {
|
|
282 |
|
|
283 |
|
|
284 |
TInt ret, aWriteSize;
|
|
285 |
|
|
286 |
TBufC8<50> cTestData3(KTestData2); // Test Data
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
291 |
RTest test(_L("t_pipe_t3"));
|
|
292 |
|
|
293 |
test.Start(_L("Thread 3"));
|
|
294 |
|
|
295 |
test.Printf(_L(" THREAD 3 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
|
|
296 |
|
|
297 |
test.Next(_L("PIPE TEST:Thread 3-1 Call Write blocking and write data\n"));
|
|
298 |
|
|
299 |
// Call Writeblocking function. Write one byte of data.
|
|
300 |
|
|
301 |
aWriteSize = cTestData3.Length();
|
|
302 |
ret = data.iWriteEnd->WriteBlocking(cTestData3,aWriteSize);
|
|
303 |
test_Equal(aWriteSize, ret);
|
|
304 |
|
|
305 |
// Call Writeblocking function. Write aSize bye data.
|
|
306 |
|
|
307 |
// Write data so that pipe get filled.
|
|
308 |
test.Next(_L("PIPE TEST:Thread 3-2 Write data till pipe is filled up \n"));
|
|
309 |
ret = data.iWriteEnd->WriteBlocking(cTestData3,aWriteSize);
|
|
310 |
test_Equal(aWriteSize, ret);
|
|
311 |
|
|
312 |
test.End();
|
|
313 |
test.Close();
|
|
314 |
return KErrNone;
|
|
315 |
}
|
|
316 |
/****************************************************************************
|
|
317 |
This function is used as thread to test Unnamed pipes.
|
|
318 |
TestMultiThreadUnNamedPipes() will use this function.
|
|
319 |
|
|
320 |
@aData : Used to pass the pipe and handle its size information.
|
|
321 |
|
|
322 |
Return Value : TInt
|
|
323 |
|
|
324 |
******************************************************************************/
|
|
325 |
//TRequestStatus stat1;
|
|
326 |
TInt TestThread4(TAny* aData) {
|
|
327 |
|
|
328 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
329 |
TRequestStatus stat1;
|
|
330 |
TBuf8<150> cPipeReadData;
|
|
331 |
TInt ret;
|
|
332 |
RTest test(_L("t_pipe_t4"));
|
|
333 |
test.Start(_L("Thread 4"));
|
|
334 |
|
|
335 |
RSemaphore sem; // Handle to the global semaphore
|
|
336 |
ret = sem.OpenGlobal(KSemaphoreName); // Access to the global semaphore identified by its name.
|
|
337 |
test(ret == KErrNone);
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
test.Printf(_L("Thread 4:Created by TestNotifyMechanismPipes.\n"));
|
|
342 |
test.Next(_L("PIPE TEST:Thread 4-1 Register Notify Data available request.\n"));
|
|
343 |
data.iReadEnd->NotifyDataAvailable(stat1);
|
|
344 |
test_Equal(KRequestPending, stat1.Int());
|
|
345 |
sem.Signal(); //signal to say that we have issued notification request
|
|
346 |
|
|
347 |
test.Next(_L("PIPE TEST:Thread 4-2 Wait till notified for data. Check for Available.\n"));
|
|
348 |
User::WaitForRequest(stat1);
|
|
349 |
test ( stat1.Int() == KErrNone);
|
|
350 |
|
|
351 |
test.Next(_L("PIPE TEST:Thread 4-3 Read One byte of data from the pipe.\n"));
|
|
352 |
sem.Wait(); //wait for signal that 1 byte should be read
|
|
353 |
ret = data.iReadEnd->Read(cPipeReadData,1);
|
|
354 |
test (ret == 1);
|
|
355 |
|
|
356 |
test.Next(_L("PIPE TEST:Thread 4-4 Verify data is correct ?.\n"));
|
|
357 |
test (KErrNone == cPipeReadData.Compare(KTestData1));
|
|
358 |
|
|
359 |
test.Next(_L("PIPE TEST:Thread 4-5 Read remaining data from the pipe.\n"));
|
|
360 |
ret = data.iReadEnd->Read(cPipeReadData,21);
|
|
361 |
test (ret == 21);
|
|
362 |
|
|
363 |
|
|
364 |
test.Next(_L("PIPE TEST:Thread 4-6 Verify data is correct ?.\n"));
|
|
365 |
test (KErrNone == cPipeReadData.Compare(KTestData3));
|
|
366 |
|
|
367 |
sem.Signal(); //signalling to the main thread to continue its operation
|
|
368 |
sem.Close(); //closing the handle to the semaphore
|
|
369 |
test.End();
|
|
370 |
test.Close();
|
|
371 |
|
|
372 |
return KErrNone;
|
|
373 |
|
|
374 |
}
|
|
375 |
|
|
376 |
/****************************************************************************
|
|
377 |
This function is used as thread to test Unnamed pipes.
|
|
378 |
TestWaitMechanismPipes() will use this function.
|
|
379 |
|
|
380 |
@aData : Used to pass the pipe and handle its size information.
|
|
381 |
|
|
382 |
Return Value : TInt
|
|
383 |
|
|
384 |
******************************************************************************/
|
|
385 |
|
|
386 |
TInt TestThread5(TAny* aData) {
|
|
387 |
|
|
388 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
389 |
TRequestStatus stat1;
|
|
390 |
TInt ret;
|
|
391 |
|
|
392 |
RTest test(_L("t_pipe_t5"));
|
|
393 |
|
|
394 |
test.Start(_L("Thread 5"));
|
|
395 |
test.Printf(_L("PIPE TEST:Thread 5:Created by TestWaitMechanismPipes.\n"));
|
|
396 |
|
|
397 |
test.Next(_L("PIPE TEST:Thread 5-1:Register one more request to wait till open to read. It shall not allow\n"));
|
|
398 |
data.iWriteEnd->Wait(KPipe3Name, stat1);
|
|
399 |
test (stat1.Int() == KErrInUse);
|
|
400 |
data.iWriteEnd->WaitForReader(KPipe3Name, stat1);
|
|
401 |
test (stat1.Int() == KErrInUse);
|
|
402 |
|
|
403 |
|
|
404 |
test.Next(_L("PIPE TEST:Thread 5-2:Open Pipe handle to Read.\n"));
|
|
405 |
ret = data.iReadEnd->Open(KPipe3Name,RPipe::EOpenToRead);
|
|
406 |
test(ret == KErrNone);
|
|
407 |
|
|
408 |
test.End();
|
|
409 |
test.Close();
|
|
410 |
return KErrNone;
|
|
411 |
}
|
|
412 |
|
|
413 |
/**
|
|
414 |
The reader thread will wait till there is data in the pipe
|
|
415 |
and then continuously read till it has read the total length
|
|
416 |
of the pipe.
|
|
417 |
*/
|
|
418 |
TInt ReaderThread(TAny* aData) {
|
|
419 |
// Read data from Pipe
|
|
420 |
RTest test(KReaderThread);
|
|
421 |
test.Title();
|
|
422 |
test.Start(_L("Reader Thread"));
|
|
423 |
|
|
424 |
TData& data = *(TData *)aData;
|
|
425 |
TBuf8<10> pipeReadData;
|
|
426 |
|
|
427 |
const TInt sizeToRead = data.iReadEnd->MaxSize(); //attempt to read everything from pipe
|
|
428 |
TRequestStatus status(KErrGeneral);
|
|
429 |
|
|
430 |
//do read in loop in case thread is notified before pipe is full
|
|
431 |
TInt totalDataRead=0;
|
|
432 |
do
|
|
433 |
{
|
|
434 |
data.iReadEnd->NotifyDataAvailable(status);
|
|
435 |
test.Printf(_L("notify data request status is %d\n"), status.Int());
|
|
436 |
if(status==KRequestPending)
|
|
437 |
User::WaitForRequest(status);
|
|
438 |
test(status==KErrNone);
|
|
439 |
test.Printf(_L("ready to read data\n"), status.Int());
|
|
440 |
|
|
441 |
const TInt sizeRead = data.iReadEnd->Read(pipeReadData, sizeToRead);
|
|
442 |
test.Printf(_L("Read %d bytes from pipe\n"), sizeRead);
|
|
443 |
test(sizeRead>0);
|
|
444 |
totalDataRead+=sizeRead;
|
|
445 |
}
|
|
446 |
while(totalDataRead<sizeToRead);
|
|
447 |
|
|
448 |
test(totalDataRead==sizeToRead);
|
|
449 |
test.End();
|
|
450 |
test.Close();
|
|
451 |
|
|
452 |
return KErrNone;
|
|
453 |
}
|
|
454 |
|
|
455 |
_LIT8(KTestDataNum1 , "12345");
|
|
456 |
_LIT8(KTestDataNum , "1234567890");
|
|
457 |
|
|
458 |
|
|
459 |
|
|
460 |
/**
|
|
461 |
Write into pipe to completely fill it.
|
|
462 |
*/
|
|
463 |
TInt WriterThread(TAny* aData)
|
|
464 |
{
|
|
465 |
// Write data to pipe
|
|
466 |
RPipe* writeEnd = static_cast<TData*>(aData)->iWriteEnd;
|
|
467 |
RTest test(_L("WriterThread"));
|
|
468 |
test.Start(_L("WriterThread"));
|
|
469 |
writeEnd->Flush(); //make sure pipe is empty
|
|
470 |
const TInt sizeToWrite = writeEnd->MaxSize();
|
|
471 |
test.Printf(_L("Writing %d bytes in to pipe\n"), sizeToWrite);
|
|
472 |
TInt length=writeEnd->WriteBlocking(KTestDataNum1,sizeToWrite);
|
|
473 |
test(length==sizeToWrite);
|
|
474 |
test.End();
|
|
475 |
test.Close();
|
|
476 |
return KErrNone;
|
|
477 |
}
|
|
478 |
|
|
479 |
/**
|
|
480 |
The FlusherThread waits till the supplied pipe
|
|
481 |
is full before flushing it.
|
|
482 |
*/
|
|
483 |
TInt FlusherThread(TAny* aData)
|
|
484 |
{
|
|
485 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
486 |
|
|
487 |
//wait for pipe to fill, then flush
|
|
488 |
TRequestStatus status;
|
|
489 |
const TInt maxSize=data.iReadEnd->MaxSize();
|
|
490 |
do
|
|
491 |
{
|
|
492 |
data.iReadEnd->NotifyDataAvailable(status);
|
|
493 |
if(status==KRequestPending)
|
|
494 |
User::WaitForRequest(status);
|
|
495 |
if(status!=KErrNone)
|
|
496 |
return status.Int();
|
|
497 |
} while(data.iReadEnd->Size()<maxSize);
|
|
498 |
data.iReadEnd->Flush();
|
|
499 |
return KErrNone;
|
|
500 |
}
|
|
501 |
|
|
502 |
/****************************************************************************
|
|
503 |
This function is used as thread to test Unnamed pipes.
|
|
504 |
TestWaitMechanismPipes() will use this function.
|
|
505 |
|
|
506 |
@aData : Used to pass the pipe and handle its size information.
|
|
507 |
|
|
508 |
Return Value : TInt
|
|
509 |
|
|
510 |
******************************************************************************/
|
|
511 |
TInt CloseFlag;
|
|
512 |
|
|
513 |
TInt TestThread9(TAny* aData) {
|
|
514 |
|
|
515 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
516 |
|
|
517 |
if (CloseFlag == 1)
|
|
518 |
data.iReadEnd->Close();
|
|
519 |
if (CloseFlag == 0)
|
|
520 |
data.iWriteEnd->Close();
|
|
521 |
|
|
522 |
|
|
523 |
return 0;
|
|
524 |
}
|
|
525 |
|
|
526 |
/**
|
|
527 |
The test will create 2 threads running this function. They will
|
|
528 |
race to placing the blocking read request. The first
|
|
529 |
will succeed and wait, the second will write to pipe
|
|
530 |
*/
|
|
531 |
TInt ReadBlockThenWrite(TAny* aData) {
|
|
532 |
|
|
533 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
534 |
TBuf8<10> cReadData;
|
|
535 |
RTest test(_L("Concurrent blocking read"));
|
|
536 |
test.Start(_L("Call blocking read on pipe\n"));
|
|
537 |
|
|
538 |
TInt ret = data.iReadEnd->ReadBlocking(cReadData,5);
|
|
539 |
if(ret == KErrNone)
|
|
540 |
{
|
|
541 |
test_KErrNone(cReadData.Compare(KTestDataNum1));
|
|
542 |
}
|
|
543 |
|
|
544 |
if(ret == KErrInUse)
|
|
545 |
{
|
|
546 |
test.Next(_L("Other thread beat us - write to pipe so it may proceed"));
|
|
547 |
TInt write = data.iWriteEnd->Write(KTestDataNum,5);
|
|
548 |
test_Equal(5, write);
|
|
549 |
}
|
|
550 |
|
|
551 |
test.End();
|
|
552 |
test.Close();
|
|
553 |
|
|
554 |
return ret;
|
|
555 |
}
|
|
556 |
|
|
557 |
/**
|
|
558 |
The test will create 2 threads running this function. They will
|
|
559 |
race to placing the blocking write request. The first
|
|
560 |
will succeed and wait, the second will read from pipe
|
|
561 |
*/
|
|
562 |
TInt WriteBlockThenRead(TAny* aData) {
|
|
563 |
|
|
564 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
565 |
TBuf8<10> cReadData;
|
|
566 |
RTest test(_L("Concurrent blocking write"));
|
|
567 |
test.Start(_L("test writing blocked pipe\n"));
|
|
568 |
|
|
569 |
TInt ret = data.iWriteEnd->WriteBlocking(KTestDataNum,10);
|
|
570 |
if(ret == KErrInUse)
|
|
571 |
{
|
|
572 |
test.Next(_L("The other thread beat us - read from pipe so it may proceed"));
|
|
573 |
TInt read = data.iReadEnd->Read(cReadData,5);
|
|
574 |
test_Equal(5, read);
|
|
575 |
test_KErrNone(cReadData.Compare(KTestDataNum1));
|
|
576 |
}
|
|
577 |
|
|
578 |
test.End();
|
|
579 |
test.Close();
|
|
580 |
|
|
581 |
return ret;
|
|
582 |
}
|
|
583 |
|
|
584 |
/****************************************************************************
|
|
585 |
This function is used as thread to test Unnamed pipes.
|
|
586 |
TestWaitMechanismPipes() will use this function.
|
|
587 |
|
|
588 |
@aData : Used to pass the pipe and handle its size information.
|
|
589 |
|
|
590 |
Return Value : TInt
|
|
591 |
|
|
592 |
******************************************************************************/
|
|
593 |
|
|
594 |
TInt TestThread11(TAny* aData) {
|
|
595 |
|
|
596 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
|
597 |
TRequestStatus stat1;
|
|
598 |
TBufC<50> cPipeName(KPipe3Name); // Descriptor to hold data for Writing.
|
|
599 |
TInt ret;
|
|
600 |
RTest test(_L("t_pipe_t11"));
|
|
601 |
|
|
602 |
test.Start(_L("PIPE TEST:Thread 11:Created by TestWaitMechanismPipes.\n"));
|
|
603 |
|
|
604 |
test.Next(_L("PIPE TEST:Thread 11-1:Register one more request to wait till open to read. It shall not allow\n"));
|
|
605 |
data.iReadEnd->WaitForWriter(cPipeName, stat1);
|
|
606 |
test_Equal(KErrInUse, stat1.Int());
|
|
607 |
|
|
608 |
|
|
609 |
test.Next(_L("PIPE TEST:Thread 11-2:Open Pipe handle to write.\n"));
|
|
610 |
ret = data.iWriteEnd->Open(cPipeName,RPipe::EOpenToWrite);
|
|
611 |
test_KErrNone(ret);
|
|
612 |
|
|
613 |
test.End();
|
|
614 |
test.Close();
|
|
615 |
return KErrNone;
|
|
616 |
}
|
|
617 |
|
|
618 |
/****************************************************************************
|
|
619 |
This is a function to test Named/UnNamed pipes Performace.
|
|
620 |
Check the functionality of following library functions
|
|
621 |
-
|
|
622 |
-
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
******************************************************************************/
|
|
627 |
/**
|
|
628 |
- test that WriteBlocking unblocks
|
|
629 |
- when data is read
|
|
630 |
- whed date is flushed
|
|
631 |
- test that notify data available request is completed as data is read
|
|
632 |
- test that ReadBlocking unblocks
|
|
633 |
- test that data available notification works
|
|
634 |
|
|
635 |
*/
|
|
636 |
void TestBlockingAndNotify() {
|
|
637 |
|
|
638 |
TRequestStatus stat1;
|
|
639 |
RPipe aReader,aWriter;
|
|
640 |
TInt aSize,ret;
|
|
641 |
TBufC8<10> cPipeTestDataNum(KTestDataNum);
|
|
642 |
|
|
643 |
TBuf8<10> cReadData;
|
|
644 |
|
|
645 |
|
|
646 |
aSize = 5;
|
|
647 |
ret = RPipe::Create( aSize,
|
|
648 |
aReader,
|
|
649 |
aWriter,
|
|
650 |
EOwnerProcess, //
|
|
651 |
EOwnerProcess //
|
|
652 |
);
|
|
653 |
test_KErrNone(ret);
|
|
654 |
|
|
655 |
TData data( &aReader, &aWriter);
|
|
656 |
|
|
657 |
{
|
|
658 |
TTestThread readerThread(KReaderThread, ReaderThread, &data);
|
|
659 |
|
|
660 |
test.Start(_L("Test that WriteBlock unblocks as data is read from pipe\n"));
|
|
661 |
ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
|
|
662 |
test(ret == 10);
|
|
663 |
test(aWriter.Size()==5);
|
|
664 |
aWriter.Flush();
|
|
665 |
test(aWriter.Size()==0);
|
|
666 |
|
|
667 |
ret = readerThread.WaitForExitL();
|
|
668 |
test_KErrNone(ret);
|
|
669 |
}
|
|
670 |
|
|
671 |
{
|
|
672 |
TTestThread flusherThread(KThread8Name, FlusherThread, &data);
|
|
673 |
test.Next(_L("Test that WriteBlock unblocks as data is flushed from read end of pipe\n"));
|
|
674 |
|
|
675 |
ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
|
|
676 |
test (ret == 10);
|
|
677 |
ret = flusherThread.WaitForExitL();
|
|
678 |
test_KErrNone(ret);
|
|
679 |
}
|
|
680 |
|
|
681 |
test.Next(_L("Test that NotifyDataAvailable request is completed as data is read from pipe\n"));
|
|
682 |
|
|
683 |
aWriter.NotifySpaceAvailable(aSize,stat1);
|
|
684 |
test(stat1==KRequestPending);
|
|
685 |
|
|
686 |
{
|
|
687 |
TTestThread readerThread2(KReaderThread, ReaderThread, &data);
|
|
688 |
|
|
689 |
User::WaitForRequest(stat1);
|
|
690 |
test(stat1==KErrNone);
|
|
691 |
|
|
692 |
ret = readerThread2.WaitForExitL();
|
|
693 |
test_KErrNone(ret);
|
|
694 |
}
|
|
695 |
|
|
696 |
aReader.Flush();
|
|
697 |
|
|
698 |
test.Next(_L("PIPE TEST: Test that ReadBlocking unblocks\n"));
|
|
699 |
{
|
|
700 |
TTestThread writeThread(KWriterThread, WriterThread, &data);
|
|
701 |
|
|
702 |
ret = aReader.ReadBlocking(cReadData,5);
|
|
703 |
test(ret == 5);
|
|
704 |
|
|
705 |
ret = writeThread.WaitForExitL();
|
|
706 |
test_KErrNone(ret);
|
|
707 |
}
|
|
708 |
|
|
709 |
test.Next(_L("PIPE TEST: Test NotifyDataAvailable\n"));
|
|
710 |
aReader.Flush();
|
|
711 |
aReader.NotifyDataAvailable(stat1);
|
|
712 |
test(stat1==KRequestPending);
|
|
713 |
|
|
714 |
{
|
|
715 |
TTestThread writeThread2(KWriterThread,WriterThread, &data);
|
|
716 |
|
|
717 |
User::WaitForRequest(stat1);
|
|
718 |
test(stat1==KErrNone);
|
|
719 |
|
|
720 |
aReader.Flush();
|
|
721 |
|
|
722 |
ret = writeThread2.WaitForExitL();
|
|
723 |
test_KErrNone(ret);
|
|
724 |
}
|
|
725 |
test.Next(_L("PIPE TEST: Test reading from pipe closed by the writer\n"));
|
|
726 |
|
|
727 |
CloseFlag = 0; // 0 Close Write Handle
|
|
728 |
//CloseFlag = 1; // 1 Close Read Handle
|
|
729 |
test.Next(_L("PIPE TEST: TestBlockingAndNotify 10.6\n"));
|
|
730 |
TTestThread closeThread(KThread9Name, TestThread9, &data);
|
|
731 |
|
|
732 |
ret = closeThread.WaitForExitL();
|
|
733 |
test_KErrNone(ret);
|
|
734 |
|
|
735 |
ret = aReader.ReadBlocking(cReadData,5);
|
|
736 |
test_Equal(KErrNotReady, ret);
|
|
737 |
|
|
738 |
aWriter.Close();
|
|
739 |
aReader.Close();
|
|
740 |
aSize = 5;
|
|
741 |
ret = RPipe::Create( aSize,
|
|
742 |
aReader,
|
|
743 |
aWriter,
|
|
744 |
EOwnerProcess, //
|
|
745 |
EOwnerProcess //
|
|
746 |
);
|
|
747 |
test_KErrNone(ret);
|
|
748 |
|
|
749 |
TData data1(&aReader,&aWriter);
|
|
750 |
|
|
751 |
|
|
752 |
//CloseFlag = 0; // 0 Close Write Handle
|
|
753 |
CloseFlag = 1; // 1 Close Read Handle
|
|
754 |
test.Printf(_L("PIPE TEST: TestBlockingAndNotify 10.7\n"));
|
|
755 |
TTestThread closeThread2(KThread9Name, TestThread9, &data1);
|
|
756 |
ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
|
|
757 |
test_Equal(KErrNotReady, ret);
|
|
758 |
|
|
759 |
ret = closeThread2.WaitForExitL();
|
|
760 |
test_KErrNone(ret);
|
|
761 |
|
|
762 |
aWriter.Close();
|
|
763 |
aReader.Close();
|
|
764 |
|
|
765 |
test.End();
|
|
766 |
}
|
|
767 |
|
|
768 |
|
|
769 |
/****************************************************************************
|
|
770 |
TestPipesPermissionCheck :
|
|
771 |
This function is used to test Permission and Access related
|
|
772 |
Errors of Pipes API.
|
|
773 |
APIs tested are Define , Create , Destroy , Read and Write.
|
|
774 |
|
|
775 |
|
|
776 |
******************************************************************************/
|
|
777 |
// Different pipes for different capability , VID values.
|
|
778 |
_LIT(KPipeName2, "PipeWithNoCap");
|
|
779 |
_LIT(KPipeName3, "PipeWithNoCapVID");
|
|
780 |
_LIT(KPipeName4, "PipeWithRWCap");
|
|
781 |
_LIT(KPipeName5, "PipeWithComDDCap");
|
|
782 |
_LIT(KPipeName6, "PipeWithRWComDDCap");
|
|
783 |
_LIT(KPipeName7, "PipeWithRWComDDCapVID");
|
|
784 |
_LIT(KPipeName8, "PipeWithRWRUCap");
|
|
785 |
|
|
786 |
// Different processes with different capability , VID values.
|
|
787 |
_LIT(KProcessNoCap, "t_pipe3.exe");
|
|
788 |
_LIT(KProcessRCap, "t_pipe5.exe");
|
|
789 |
|
|
790 |
// My VID and SID
|
|
791 |
_LIT_VENDOR_ID(MyVID,0x70000001);
|
|
792 |
void TestPipesPermissionCheck() {
|
|
793 |
|
|
794 |
RProcess proc;
|
|
795 |
TInt ret;
|
|
796 |
|
|
797 |
// Define TSecurity objects with different capabilities and VID .
|
|
798 |
TSecurityPolicy NoCapVID(MyVID,ECapability_None,ECapability_None,ECapability_None);
|
|
799 |
TSecurityPolicy RWCap(ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
|
|
800 |
TSecurityPolicy ComDDCap(ECapabilityCommDD);
|
|
801 |
TSecurityPolicy RWComDDCap(ECapabilityReadDeviceData,ECapabilityCommDD,ECapabilityWriteDeviceData);
|
|
802 |
TSecurityPolicy RWComDDCapVID(MyVID,ECapabilityCommDD,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
|
|
803 |
TSecurityPolicy RWRUCap(ECapabilityReadUserData,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
|
|
804 |
|
|
805 |
// Define Named pipes with No Cap , combination of Cap and VID
|
|
806 |
|
|
807 |
TInt aSize = 10;
|
|
808 |
ret = RPipe::Define(KPipeName2, aSize);
|
|
809 |
test (ret == KErrNone);
|
|
810 |
ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
|
|
811 |
test (ret == KErrNone);
|
|
812 |
ret = RPipe::Define(KPipeName4, aSize,RWCap);
|
|
813 |
test (ret == KErrNone);
|
|
814 |
ret = RPipe::Define(KPipeName5, aSize,ComDDCap);
|
|
815 |
test (ret == KErrNone);
|
|
816 |
ret = RPipe::Define(KPipeName6, aSize,RWComDDCap);
|
|
817 |
test (ret == KErrNone);
|
|
818 |
ret = RPipe::Define(KPipeName7, aSize,RWComDDCapVID);
|
|
819 |
test (ret == KErrNone);
|
|
820 |
ret = RPipe::Define(KPipeName8, aSize,RWRUCap);
|
|
821 |
test (ret == KErrNone);
|
|
822 |
|
|
823 |
//Lets see who can use pipes. Check for Permissions and Access
|
|
824 |
test.Next(_L("PIPE TEST:8.1 Create Process with No Cap t_pipe3.exe\n"));
|
|
825 |
ret = proc.Create (
|
|
826 |
KProcessNoCap, // Launch t_pipe3.exe process
|
|
827 |
KNullDesC // No arguments passed to t_pipe3.exe
|
|
828 |
);
|
|
829 |
|
|
830 |
if (ret != KErrNone)
|
|
831 |
{
|
|
832 |
test.Printf(_L(" ***** t_pipe3.exe could not start ****"));
|
|
833 |
}
|
|
834 |
test_KErrNone(ret);
|
|
835 |
test.Printf(_L("Process Created successfully"));
|
|
836 |
|
|
837 |
TRequestStatus procLogon;
|
|
838 |
proc.Logon(procLogon);
|
|
839 |
test(procLogon==KRequestPending);
|
|
840 |
proc.Resume();
|
|
841 |
User::WaitForRequest(procLogon);
|
|
842 |
proc.Close();
|
|
843 |
|
|
844 |
// Lets see what happens with Read Capability.
|
|
845 |
test.Next(_L("PIPE TEST:8.2 Create Process with Read-Write-CommDD Cap t_pipe5.exe\n"));
|
|
846 |
ret = RPipe::Define(KPipeName2, aSize);
|
|
847 |
test_KErrNone(ret);
|
|
848 |
ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
|
|
849 |
test_KErrNone(ret);
|
|
850 |
|
|
851 |
ret = proc.Create (
|
|
852 |
KProcessRCap, // Launch t_pipe3.exe process
|
|
853 |
KNullDesC // No arguments passed to t_pipe3.exe
|
|
854 |
);
|
|
855 |
|
|
856 |
if (ret != KErrNone)
|
|
857 |
{
|
|
858 |
test.Printf(_L(" ***** t_pipe5.exe could not start ****"));
|
|
859 |
}
|
|
860 |
test_KErrNone(ret);
|
|
861 |
test.Printf(_L("Process Created successfully"));
|
|
862 |
proc.Logon(procLogon);
|
|
863 |
test(procLogon==KRequestPending);
|
|
864 |
proc.Resume();
|
|
865 |
User::WaitForRequest(procLogon);
|
|
866 |
proc.Close();
|
|
867 |
|
|
868 |
//the t_pipe5.exe process should destroy most of these
|
|
869 |
//but we call destroy again to verify this
|
|
870 |
ret = RPipe::Destroy (KPipeName2);
|
|
871 |
test_Equal(KErrNotFound, ret);
|
|
872 |
ret = RPipe::Destroy (KPipeName3);
|
|
873 |
test_KErrNone(ret); //KPipeName3 is not destroyed by the other process.
|
|
874 |
ret = RPipe::Destroy (KPipeName4);
|
|
875 |
test_Equal(KErrNotFound, ret);
|
|
876 |
ret = RPipe::Destroy (KPipeName5);
|
|
877 |
test_Equal(KErrNotFound, ret);
|
|
878 |
ret = RPipe::Destroy (KPipeName6);
|
|
879 |
test_Equal(KErrNotFound, ret);
|
|
880 |
ret = RPipe::Destroy (KPipeName7);
|
|
881 |
test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
|
|
882 |
ret = RPipe::Destroy (KPipeName8);
|
|
883 |
test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
|
|
884 |
|
|
885 |
|
|
886 |
|
|
887 |
return;
|
|
888 |
|
|
889 |
}
|
|
890 |
|
|
891 |
/****************************************************************************
|
|
892 |
|
|
893 |
TestMiscPipes :
|
|
894 |
This is a function to test Named/UnNamed pipes for all Misc test cases.
|
|
895 |
|
|
896 |
|
|
897 |
******************************************************************************/
|
|
898 |
|
|
899 |
void TestMiscPipes() {
|
|
900 |
|
|
901 |
_LIT(KInvalidPipeName,"PipeNotExist");
|
|
902 |
TInt ret,aSize;
|
|
903 |
RPipe aReader,aWriter;
|
|
904 |
TBufC<50> cPipeName(KInvalidPipeName); // Descriptor to hold data for Writing.
|
|
905 |
TBufC8<50> cPipeTestData2(KTestData2);
|
|
906 |
|
|
907 |
|
|
908 |
// Try to create unnamed pipe with Negative size
|
|
909 |
test.Next(_L("PIPE TEST:9.1 Create Pipe of Negative Size.\n"));
|
|
910 |
aSize = -1;
|
|
911 |
ret = RPipe::Create( aSize,
|
|
912 |
aReader,
|
|
913 |
aWriter,
|
|
914 |
EOwnerProcess, //
|
|
915 |
EOwnerProcess //
|
|
916 |
);
|
|
917 |
test( ret == KErrArgument);
|
|
918 |
|
|
919 |
|
|
920 |
// Try to create unnamed pipe with zero size
|
|
921 |
test.Next(_L("PIPE TEST:9.2 Create Pipe with of Zero size.\n"));
|
|
922 |
aSize = 0;
|
|
923 |
ret = RPipe::Create( aSize,
|
|
924 |
aReader,
|
|
925 |
aWriter,
|
|
926 |
EOwnerProcess, //
|
|
927 |
EOwnerProcess //
|
|
928 |
);
|
|
929 |
test( ret == KErrArgument);
|
|
930 |
|
|
931 |
|
|
932 |
// Try to define named pipe with Negative size
|
|
933 |
test.Next(_L("PIPE TEST:9.3 Define Pipe of Negative size.\n"));
|
|
934 |
aSize = -1;
|
|
935 |
ret = RPipe::Define(cPipeName, aSize);
|
|
936 |
test( ret == KErrArgument);
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
// Try to define named pipe with Zero size
|
|
941 |
test.Next(_L("PIPE TEST:9.4 Define Pipe of Zero size.\n"));
|
|
942 |
aSize = 0;
|
|
943 |
ret = RPipe::Define(cPipeName, aSize);
|
|
944 |
test( ret == KErrArgument);
|
|
945 |
|
|
946 |
|
|
947 |
// Try to destroy pipe which does not exists
|
|
948 |
test.Next(_L("PIPE TEST:9.5 Try to destroy named pipe which do not exist.\n"));
|
|
949 |
ret = RPipe::Destroy (cPipeName);
|
|
950 |
test (ret == KErrNotFound);
|
|
951 |
|
|
952 |
|
|
953 |
// Try to read from pipe with invalid length data to be read
|
|
954 |
RPipe aReaderUN,aWriterUN;
|
|
955 |
TBuf8<150> cPipeReadData;
|
|
956 |
aSize = 10;
|
|
957 |
ret = RPipe::Create( aSize,
|
|
958 |
aReaderUN,
|
|
959 |
aWriterUN,
|
|
960 |
EOwnerProcess, //
|
|
961 |
EOwnerProcess //
|
|
962 |
);
|
|
963 |
test (ret == KErrNone );
|
|
964 |
|
|
965 |
|
|
966 |
test.Next(_L("PIPE TEST:9.6 Try calling ReadBlocking using write handle and WriteBlocking using Read handle.\n"));
|
|
967 |
ret = aWriterUN.ReadBlocking(cPipeReadData, aSize);
|
|
968 |
test (ret == KErrAccessDenied);
|
|
969 |
ret = aReaderUN.WriteBlocking(cPipeTestData2,aSize);
|
|
970 |
test (ret == KErrAccessDenied);
|
|
971 |
|
|
972 |
|
|
973 |
|
|
974 |
|
|
975 |
test.Next(_L("PIPE TEST:9.7 Read negative size data from un-named pipe.\n"));
|
|
976 |
aSize = -1;
|
|
977 |
ret = aReaderUN.Read(cPipeReadData, aSize);
|
|
978 |
test( ret == KErrArgument);
|
|
979 |
ret = aWriterUN.Write(cPipeTestData2,aSize);
|
|
980 |
test( ret == KErrArgument);
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
test.Next(_L("PIPE TEST:9.8 Read/Write zero size data from/to un-named pipe\n"));
|
|
985 |
aSize = 0;
|
|
986 |
ret = aReaderUN.Read(cPipeReadData, aSize);
|
|
987 |
test( ret == KErrNone);
|
|
988 |
|
|
989 |
ret = aWriterUN.Write(cPipeTestData2,aSize);
|
|
990 |
test( ret == KErrNone);
|
|
991 |
|
|
992 |
|
|
993 |
test.Next(_L("PIPE TEST:9.9 Call ReadBlocking and WriteBlocking to Read and Write negative size data.\n"));
|
|
994 |
// Try to readblocking from pipe with invalid length data to be read
|
|
995 |
aSize = -1;
|
|
996 |
ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
|
|
997 |
test( ret == KErrArgument);
|
|
998 |
ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
|
|
999 |
test( ret == KErrArgument);
|
|
1000 |
|
|
1001 |
test.Next(_L("PIPE TEST:9.10 ReadBlocking/WriteBlocking to read/write zero size data.\n"));
|
|
1002 |
aSize = 0;
|
|
1003 |
ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
|
|
1004 |
test( ret == KErrArgument);
|
|
1005 |
ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
|
|
1006 |
test( ret == KErrArgument);
|
|
1007 |
|
|
1008 |
|
|
1009 |
test.Next(_L("PIPE TEST:9.11 Try calling ReadBlocking and WriteBlocking using un opened RPipe handles.\n"));
|
|
1010 |
RPipe aReaderT,aWriterT;
|
|
1011 |
ret = aReaderT.ReadBlocking(cPipeReadData, aSize);
|
|
1012 |
test (ret == KErrBadHandle);
|
|
1013 |
ret = aWriterT.WriteBlocking(cPipeTestData2,aSize);
|
|
1014 |
test (ret == KErrBadHandle);
|
|
1015 |
aReaderUN.Close();
|
|
1016 |
aWriterUN.Close();
|
|
1017 |
|
|
1018 |
|
|
1019 |
return;
|
|
1020 |
}
|
|
1021 |
|
|
1022 |
/****************************************************************************
|
|
1023 |
This is a function to test notify mechanism of pipes.
|
|
1024 |
Check the functionality of following library functions
|
|
1025 |
- Notify...()
|
|
1026 |
|
|
1027 |
|
|
1028 |
******************************************************************************/
|
|
1029 |
void TestWaitMechanismPipes() {
|
|
1030 |
|
|
1031 |
RPipe aReader,aWriter; // Used to pass to thread.
|
|
1032 |
RPipe aWriter2;
|
|
1033 |
TInt ret;
|
|
1034 |
TBufC<50> cPipeName(KPipe3Name); // Descriptor to hold data for Writing.
|
|
1035 |
TInt aSize;
|
|
1036 |
TRequestStatus stat1;
|
|
1037 |
|
|
1038 |
aSize = 22 * 10; // Sizeof(KTestData) * 10
|
|
1039 |
|
|
1040 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1041 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1042 |
test (ret == KErrNone);
|
|
1043 |
|
|
1044 |
|
|
1045 |
|
|
1046 |
test.Next(_L("PIPE TEST:7.1 Try calling Wait function on BadPipe name.\n"));
|
|
1047 |
|
|
1048 |
_LIT(KBadPipeName , "***R$@#$@#%#$%#^.12-.");
|
|
1049 |
aWriter.Wait(KBadPipeName,stat1);
|
|
1050 |
test(stat1.Int() == KErrBadName);
|
|
1051 |
aWriter.WaitForReader(KBadPipeName,stat1);
|
|
1052 |
test(stat1.Int() == KErrBadName);
|
|
1053 |
|
|
1054 |
|
|
1055 |
_LIT(KBadPipeName2 , "");
|
|
1056 |
aWriter.Wait(KBadPipeName2,stat1);
|
|
1057 |
test(stat1.Int() == KErrBadName);
|
|
1058 |
aWriter.WaitForReader(KBadPipeName2,stat1);
|
|
1059 |
test(stat1.Int() == KErrBadName);
|
|
1060 |
|
|
1061 |
|
|
1062 |
|
|
1063 |
test.Next(_L("PIPE TEST:7.2 Try calling Wait function on non existing Pipe\n"));
|
|
1064 |
_LIT(KInvalidPipe , "NotExistingPipe");
|
|
1065 |
aWriter.Wait(KInvalidPipe,stat1);
|
|
1066 |
test(stat1.Int() == KErrNotFound);
|
|
1067 |
aWriter.WaitForReader(KInvalidPipe,stat1);
|
|
1068 |
test(stat1.Int() == KErrNotFound);
|
|
1069 |
|
|
1070 |
|
|
1071 |
test.Next(_L("PIPE TEST:7.3 Try calling Wait function on Pipe name length more than maxlength.\n"));
|
|
1072 |
aWriter.Wait(KMaxPipeNamePlusOne,stat1);
|
|
1073 |
test(stat1.Int() == KErrBadName);
|
|
1074 |
aWriter.WaitForReader(KMaxPipeNamePlusOne,stat1);
|
|
1075 |
test(stat1.Int() == KErrBadName);
|
|
1076 |
|
|
1077 |
|
|
1078 |
test.Next(_L("PIPE TEST:7.4 Try calling Wait function from unopened handle.\n"));
|
|
1079 |
aWriter2.Wait(cPipeName, stat1);
|
|
1080 |
test (stat1.Int() == KErrInUse);
|
|
1081 |
aWriter2.WaitForReader(cPipeName, stat1);
|
|
1082 |
test (stat1.Int() == KErrInUse);
|
|
1083 |
|
|
1084 |
|
|
1085 |
test.Next(_L("PIPE TEST:7.5 Register a valid Wait Request .\n"));
|
|
1086 |
aWriter.Wait(cPipeName, stat1);
|
|
1087 |
|
|
1088 |
TData data( &aReader, &aWriter);
|
|
1089 |
|
|
1090 |
// Create Thread 5
|
|
1091 |
// Pass TData object with Write and Read handle both
|
|
1092 |
TTestThread thread5(KThread5Name, TestThread5, &data);
|
|
1093 |
User::WaitForRequest(stat1);
|
|
1094 |
|
|
1095 |
ret = thread5.WaitForExitL();
|
|
1096 |
test_KErrNone(ret);
|
|
1097 |
|
|
1098 |
test.Next(_L("PIPE TEST:7.6 After Wait finish check the value of status register.\n"));
|
|
1099 |
test_KErrNone(stat1.Int());
|
|
1100 |
aWriter.Close();
|
|
1101 |
aReader.Close();
|
|
1102 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1103 |
test_KErrNone(ret);
|
|
1104 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1105 |
test_KErrNone(ret);
|
|
1106 |
|
|
1107 |
test.Next(_L("PIPE TEST:7.7 After Read handle is open , register request to Wait\n"));
|
|
1108 |
|
|
1109 |
aWriter.Wait(cPipeName, stat1);
|
|
1110 |
test (stat1.Int() == KErrNone);
|
|
1111 |
|
|
1112 |
test.Next(_L("PIPE TEST:7.8 Check for CancelWait.\n"));
|
|
1113 |
aWriter.Close();
|
|
1114 |
aReader.Close();
|
|
1115 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1116 |
TRequestStatus stat2;
|
|
1117 |
aWriter.Wait(cPipeName, stat1);
|
|
1118 |
aWriter.Wait(cPipeName, stat2);
|
|
1119 |
test(stat2.Int() == KErrInUse);
|
|
1120 |
aWriter.CancelWait();
|
|
1121 |
test(stat1.Int() == KErrCancel);
|
|
1122 |
test(stat2.Int() == KErrInUse);
|
|
1123 |
aWriter.Wait(cPipeName, stat1);
|
|
1124 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1125 |
test(stat1.Int() == KErrNone);
|
|
1126 |
|
|
1127 |
test.Next(_L("PIPE TEST:7.9 Check Wait and CancelWait from reader end\n"));
|
|
1128 |
aWriter.Close();
|
|
1129 |
aReader.Close();
|
|
1130 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1131 |
aReader.Wait(cPipeName, stat1);
|
|
1132 |
test (stat1.Int() == KErrAccessDenied);
|
|
1133 |
aReader.CancelWait();
|
|
1134 |
|
|
1135 |
|
|
1136 |
aWriter.Close();
|
|
1137 |
aReader.Close();
|
|
1138 |
RPipe::Destroy(cPipeName);
|
|
1139 |
|
|
1140 |
/*****************Newly added tests for CR 1114 - WaitForReader *********/
|
|
1141 |
|
|
1142 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1143 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1144 |
test (ret == KErrNone);
|
|
1145 |
|
|
1146 |
|
|
1147 |
test.Next(_L("PIPE TEST:7.10 Register a valid Wait Request .\n"));
|
|
1148 |
aWriter.WaitForReader(cPipeName, stat1);
|
|
1149 |
test(stat1==KRequestPending);
|
|
1150 |
|
|
1151 |
// Create Thread 5
|
|
1152 |
// Pass TData object with Write and Read handle both
|
|
1153 |
{
|
|
1154 |
TTestThread thread5_1(KThread5Name, TestThread5, &data);
|
|
1155 |
User::WaitForRequest(stat1);
|
|
1156 |
|
|
1157 |
ret = thread5_1.WaitForExitL();
|
|
1158 |
test_KErrNone(ret);
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
test.Next(_L("PIPE TEST:7.11 After Wait finish check the value of status register.\n"));
|
|
1162 |
aWriter.Close();
|
|
1163 |
aReader.Close();
|
|
1164 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1165 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1166 |
|
|
1167 |
aReader.WaitForReader(cPipeName, stat1);
|
|
1168 |
test (stat1.Int() == KErrAccessDenied);
|
|
1169 |
|
|
1170 |
test.Next(_L("PIPE TEST:7.12 After Read handle is open , register request to Wait\n"));
|
|
1171 |
|
|
1172 |
aWriter.WaitForReader(cPipeName, stat1);
|
|
1173 |
test (stat1.Int() == KErrNone);
|
|
1174 |
|
|
1175 |
test.Next(_L("PIPE TEST:7.13 Check for CancelWait.\n"));
|
|
1176 |
aWriter.Close();
|
|
1177 |
aReader.Close();
|
|
1178 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1179 |
|
|
1180 |
aWriter.WaitForReader(cPipeName, stat1);
|
|
1181 |
aWriter.WaitForReader(cPipeName, stat2);
|
|
1182 |
test(stat2.Int() == KErrInUse);
|
|
1183 |
aWriter.CancelWait();
|
|
1184 |
test(stat1.Int() == KErrCancel);
|
|
1185 |
test(stat2.Int() == KErrInUse);
|
|
1186 |
aWriter.WaitForReader(cPipeName, stat1);
|
|
1187 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1188 |
test(stat1.Int() == KErrNone);
|
|
1189 |
|
|
1190 |
// Release all the resources.
|
|
1191 |
aWriter.Close();
|
|
1192 |
aReader.Close();
|
|
1193 |
|
|
1194 |
// Create Thread 5
|
|
1195 |
// Pass TData object with Write and Read handle both
|
|
1196 |
|
|
1197 |
test.Next(_L("PIPE TEST:7.14 Register a valid Wait Request .\n"));
|
|
1198 |
aWriter.WaitForReader(cPipeName, stat1);
|
|
1199 |
|
|
1200 |
{
|
|
1201 |
TTestThread thread5_2(KThread5Name, TestThread5, &data);
|
|
1202 |
User::WaitForRequest(stat1);
|
|
1203 |
|
|
1204 |
ret = thread5_2.WaitForExitL();
|
|
1205 |
test_KErrNone(ret);
|
|
1206 |
}
|
|
1207 |
test.Next(_L("PIPE TEST:7.15 After Wait finish close the handles.\n"));
|
|
1208 |
test (stat1.Int() == KErrNone);
|
|
1209 |
aWriter.Close();
|
|
1210 |
aReader.Close();
|
|
1211 |
// Release all the resources.
|
|
1212 |
ret = RPipe::Destroy(cPipeName);
|
|
1213 |
test_KErrNone(ret);
|
|
1214 |
|
|
1215 |
/*****************Newly added tests for CR 1114 - WaitForWriter *********/
|
|
1216 |
|
|
1217 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1218 |
test_KErrNone(ret);
|
|
1219 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1220 |
test (ret == KErrNone);
|
|
1221 |
|
|
1222 |
|
|
1223 |
// Create Thread 11
|
|
1224 |
// Pass TData object with Write and Read handle both
|
|
1225 |
|
|
1226 |
test.Next(_L("PIPE TEST:7.16 Register a valid Wait Request .\n"));
|
|
1227 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1228 |
test(stat1==KRequestPending);
|
|
1229 |
|
|
1230 |
{
|
|
1231 |
TTestThread thread11(KThread11Name, TestThread11, &data);
|
|
1232 |
User::WaitForRequest(stat1);
|
|
1233 |
|
|
1234 |
ret = thread11.WaitForExitL();
|
|
1235 |
test_KErrNone(ret);
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
test.Next(_L("PIPE TEST:7.17 After Wait finish check the value of status register.\n"));
|
|
1239 |
aWriter.Close();
|
|
1240 |
aReader.Close();
|
|
1241 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1242 |
test_KErrNone(ret);
|
|
1243 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1244 |
test_KErrNone(ret);
|
|
1245 |
|
|
1246 |
aWriter.WaitForWriter(cPipeName, stat1);
|
|
1247 |
test (stat1.Int() == KErrAccessDenied);
|
|
1248 |
|
|
1249 |
test.Next(_L("PIPE TEST:7.18 After Write handle is open , register request to Wait\n"));
|
|
1250 |
|
|
1251 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1252 |
test (stat1.Int() == KErrNone);
|
|
1253 |
|
|
1254 |
test.Next(_L("PIPE TEST:7.19 Check for CancelWait.\n"));
|
|
1255 |
aWriter.Close();
|
|
1256 |
aReader.Close();
|
|
1257 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1258 |
|
|
1259 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1260 |
aReader.WaitForWriter(cPipeName, stat2);
|
|
1261 |
test(stat2.Int() == KErrInUse);
|
|
1262 |
aReader.CancelWait();
|
|
1263 |
test(stat1.Int() == KErrCancel);
|
|
1264 |
test(stat2.Int() == KErrInUse);
|
|
1265 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1266 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1267 |
test(stat1.Int() == KErrNone);
|
|
1268 |
|
|
1269 |
// Release all the resources.
|
|
1270 |
aWriter.Close();
|
|
1271 |
aReader.Close();
|
|
1272 |
|
|
1273 |
// Create Thread 11
|
|
1274 |
// Pass TData object with Write and Read handle both
|
|
1275 |
|
|
1276 |
test.Next(_L("PIPE TEST:7.20 Register a valid Wait Request .\n"));
|
|
1277 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1278 |
|
|
1279 |
{
|
|
1280 |
TTestThread thread11_2(KThread11Name, TestThread11, &data);
|
|
1281 |
User::WaitForRequest(stat1);
|
|
1282 |
|
|
1283 |
test.Next(_L("PIPE TEST:7.21 After Wait finish , close the hadles.\n"));
|
|
1284 |
test (stat1.Int() == KErrNone);
|
|
1285 |
ret = thread11_2.WaitForExitL();
|
|
1286 |
test_KErrNone(ret);
|
|
1287 |
|
|
1288 |
// Release all the resources.
|
|
1289 |
aWriter.Close();
|
|
1290 |
aReader.Close();
|
|
1291 |
}
|
|
1292 |
|
|
1293 |
ret = RPipe::Destroy(cPipeName);
|
|
1294 |
test_KErrNone(ret);
|
|
1295 |
|
|
1296 |
/**********************************************************/
|
|
1297 |
|
|
1298 |
// Define the pipe.
|
|
1299 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1300 |
test(ret == KErrNone);
|
|
1301 |
|
|
1302 |
// Wait for Writer.
|
|
1303 |
aReader.WaitForWriter(cPipeName, stat1);
|
|
1304 |
// Try to open read end again. It should not open because WaitForWriter
|
|
1305 |
// will has already opened the Read End of the pipe.
|
|
1306 |
ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
|
|
1307 |
test(ret = KErrInUse );
|
|
1308 |
// Status of the wait request is pending because writer is not opened yet.
|
|
1309 |
test (stat1.Int() == KRequestPending);
|
|
1310 |
|
|
1311 |
// Wait on Reader.
|
|
1312 |
aWriter.WaitForReader(cPipeName , stat2);
|
|
1313 |
// Reader was already opened so status is KErrNone.
|
|
1314 |
test ( stat2.Int() == KErrNone);
|
|
1315 |
|
|
1316 |
// Try to open Write end. It should not allow because WaitForReader has
|
|
1317 |
// already opened the write end of the pipe.
|
|
1318 |
ret = aWriter.Open(cPipeName ,RPipe::EOpenToWrite);
|
|
1319 |
test (ret == KErrInUse);
|
|
1320 |
|
|
1321 |
// Check the status of the WaitForWriter request. It should be KErrNone now.
|
|
1322 |
test (stat1.Int() == KErrNone);
|
|
1323 |
|
|
1324 |
// Let's check for pipe attributes.
|
|
1325 |
ret = aReader.MaxSize();
|
|
1326 |
test (ret = aSize);
|
|
1327 |
ret = aWriter.MaxSize();
|
|
1328 |
test (ret = aSize);
|
|
1329 |
ret = aReader.Size();
|
|
1330 |
test (ret = aSize);
|
|
1331 |
ret = aWriter.Size();
|
|
1332 |
test (ret = aSize);
|
|
1333 |
|
|
1334 |
// Close the Reade handle.
|
|
1335 |
aReader.Close();
|
|
1336 |
|
|
1337 |
// Put request to wait for Reader.
|
|
1338 |
aWriter.WaitForReader(cPipeName , stat2);
|
|
1339 |
// It should be pending.
|
|
1340 |
test ( stat2.Int() == KRequestPending);
|
|
1341 |
// Open the reader end of the pipe. It should allow , KErrNone
|
|
1342 |
ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
|
|
1343 |
test ( stat2.Int() == KErrNone);
|
|
1344 |
test (ret == KErrNone);
|
|
1345 |
|
|
1346 |
aReader.Close();
|
|
1347 |
aWriter.Close();
|
|
1348 |
ret=RPipe::Destroy(cPipeName);
|
|
1349 |
test_KErrNone(ret);
|
|
1350 |
|
|
1351 |
return;
|
|
1352 |
|
|
1353 |
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
/****************************************************************************
|
|
1357 |
This is a function to test notify mechanism of pipes.
|
|
1358 |
Check the functionality of following library functions
|
|
1359 |
- Notify...()
|
|
1360 |
|
|
1361 |
|
|
1362 |
******************************************************************************/
|
|
1363 |
void TestNotifyMechanismPipes() {
|
|
1364 |
// Test NotifyDataAvailable , NotifySpaceAvailable
|
|
1365 |
RSemaphore globalSem; // Handle to a global semaphore. Semaphore is used to maintain synchronisation between thread4 and the main thread
|
|
1366 |
TInt ret; // Return Value variable.
|
|
1367 |
RPipe aReader,aWriter; // Used to pass to thread.
|
|
1368 |
RPipe aReader2,aWriter2; // Used to pass to thread.
|
|
1369 |
|
|
1370 |
TInt aSize; // Used to pass to thread.
|
|
1371 |
const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
|
|
1372 |
|
|
1373 |
TRequestStatus stat1;
|
|
1374 |
TBuf8<50> cPipeTestData1(KTestData2);
|
|
1375 |
|
|
1376 |
const TBufC<50> cSemaphoreName(KSemaphoreName); // Descriptor conataining the name of the global semaphore.
|
|
1377 |
|
|
1378 |
|
|
1379 |
ret = globalSem.CreateGlobal(cSemaphoreName,0); //create and open a global semaphore with initial count as 0.
|
|
1380 |
test (ret == KErrNone);
|
|
1381 |
|
|
1382 |
aSize = 22; // Size of KTestData * 10
|
|
1383 |
|
|
1384 |
ret = RPipe::Create( aSize,
|
|
1385 |
aReader,
|
|
1386 |
aWriter,
|
|
1387 |
EOwnerProcess, //
|
|
1388 |
EOwnerProcess //
|
|
1389 |
);
|
|
1390 |
|
|
1391 |
TData data( &aReader, &aWriter);
|
|
1392 |
|
|
1393 |
// Create Thread 4
|
|
1394 |
// Pass TData object with Write and Read handle both
|
|
1395 |
test.Next(_L("PIPE TEST:6.1 Call CancelDataAvailable/CancelSpaceAvailable using unopened RPipe handles.\n"));
|
|
1396 |
ret = aReader2.CancelDataAvailable();
|
|
1397 |
test ( ret == KErrBadHandle);
|
|
1398 |
ret = aWriter2.CancelSpaceAvailable();
|
|
1399 |
test (ret == KErrBadHandle);
|
|
1400 |
|
|
1401 |
test.Next(_L("PIPE TEST:6.2 Call NotifySpaceAvailable with Negative size \n"));
|
|
1402 |
// Call Notfifyspace
|
|
1403 |
TInt tempsize = -1;
|
|
1404 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1405 |
test ( stat1.Int() == KErrArgument);
|
|
1406 |
|
|
1407 |
test.Next(_L("PIPE TEST:6.2a Call NotifySpaceAvailable for space larger than pipe.\n"));
|
|
1408 |
aWriter.NotifySpaceAvailable(aSize+1, stat1);
|
|
1409 |
test_Equal( KErrArgument, stat1.Int());
|
|
1410 |
|
|
1411 |
|
|
1412 |
// Start the thread
|
|
1413 |
{
|
|
1414 |
TTestThread thread4(KThread4Name, TestThread4, &data);
|
|
1415 |
|
|
1416 |
// Thread 4
|
|
1417 |
// Call Notifydata available
|
|
1418 |
// Loop for Available
|
|
1419 |
// Read the data and validate
|
|
1420 |
|
|
1421 |
test.Next(_L("PIPE TEST:6.3 Write data into the pipe , verify return value.\n"));
|
|
1422 |
// Write one byte data into the pipe.
|
|
1423 |
globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
|
|
1424 |
ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
|
|
1425 |
test (ret == cPipeTestData1.Length());
|
|
1426 |
|
|
1427 |
|
|
1428 |
test.Next(_L("PIPE TEST:6.4 Call NotifySpaceAvailable with valid parameters \n"));
|
|
1429 |
tempsize = 1;
|
|
1430 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1431 |
test(stat1==KRequestPending);
|
|
1432 |
globalSem.Signal(); //signal that thread 4 may go ahead and read 1 byte
|
|
1433 |
|
|
1434 |
|
|
1435 |
test.Next(_L("PIPE TEST:6.5 Wait till request says AVAILABLE. Available ?\n"));
|
|
1436 |
User::WaitForRequest(stat1);
|
|
1437 |
test ( stat1.Int() == KErrNone || stat1.Int() == KErrCompletion);
|
|
1438 |
|
|
1439 |
// Thread 4
|
|
1440 |
// Notify data available
|
|
1441 |
// Loop for available
|
|
1442 |
// Flush the buffer
|
|
1443 |
// Register two request for Notifydata available
|
|
1444 |
// Register two request for Notifyspace available
|
|
1445 |
// Call Notifydata available using Read handle
|
|
1446 |
// Call Notifydata available using write handle
|
|
1447 |
// return
|
|
1448 |
|
|
1449 |
|
|
1450 |
// Check for Error conditions
|
|
1451 |
|
|
1452 |
// Flush buffer
|
|
1453 |
globalSem.Wait(); // this is waiting for a signal from thread4
|
|
1454 |
test.Next(_L("PIPE TEST:6.6 Register Notification for space availability. Allows ?\n"));
|
|
1455 |
ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
|
|
1456 |
ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
|
|
1457 |
// Register two request for Notifyspace available
|
|
1458 |
|
|
1459 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1460 |
test_Equal(KRequestPending, stat1.Int() );
|
|
1461 |
test.Next(_L("PIPE TEST:6.7 Register One more Notification for space availability. Allows ?\n"));
|
|
1462 |
TRequestStatus tempstat1;
|
|
1463 |
aWriter.NotifySpaceAvailable(tempsize, tempstat1);
|
|
1464 |
test ( tempstat1.Int() == KErrInUse);
|
|
1465 |
|
|
1466 |
test.Next(_L("PIPE TEST:6.7a Cancellation of non-outstanding requests must not disrupt oustanding requests\n"));
|
|
1467 |
aWriter.CancelWait();
|
|
1468 |
aWriter.NotifySpaceAvailable(tempsize, tempstat1);
|
|
1469 |
test_Equal( KErrInUse, tempstat1.Int());
|
|
1470 |
|
|
1471 |
test.Next(_L("PIPE TEST:6.8 Cancel all the pending Notifications.\n"));
|
|
1472 |
ret = aWriter.CancelSpaceAvailable();
|
|
1473 |
test ( ret == KErrNone);
|
|
1474 |
test_Equal(KErrCancel, stat1.Int() );
|
|
1475 |
|
|
1476 |
test.Next(_L("PIPE TEST:6.9 Try to cancel some more notifications. It should not allow\n"));
|
|
1477 |
ret = aWriter.CancelSpaceAvailable();
|
|
1478 |
test ( ret == KErrNone);
|
|
1479 |
|
|
1480 |
test.Next(_L("PIPE TEST:6.10 Register Notification for Data availability. Allows ?\n"));
|
|
1481 |
// Register two request for Notifydata available
|
|
1482 |
aWriter.Flush();
|
|
1483 |
aReader.NotifyDataAvailable(stat1);
|
|
1484 |
|
|
1485 |
test.Next(_L("PIPE TEST:6.11 Register One More Notification for Data availability. Allows ?\n"));
|
|
1486 |
|
|
1487 |
aReader.NotifyDataAvailable(tempstat1);
|
|
1488 |
test ( ( tempstat1.Int() == KErrInUse) || (tempstat1.Int() == KErrCompletion));
|
|
1489 |
|
|
1490 |
test.Next(_L("PIPE TEST:6.12 Cancel all the pending Notifications for Data.\n"));
|
|
1491 |
ret = aReader.CancelDataAvailable();
|
|
1492 |
test ( ( ret == KErrNone) || (ret == KErrNotFound));
|
|
1493 |
test (stat1.Int() == KErrCancel);
|
|
1494 |
|
|
1495 |
test.Next(_L("PIPE TEST:6.13 Try to cancel some more notifications. It should not allow\n"));
|
|
1496 |
ret = aReader.CancelDataAvailable();
|
|
1497 |
test ( ret == KErrNone);
|
|
1498 |
|
|
1499 |
test.Next(_L("PIPE TEST:6.14 Try to register Data available notification using Write handle. Should not allow.\n"));
|
|
1500 |
aWriter.NotifyDataAvailable(stat1);
|
|
1501 |
test ( stat1.Int() == KErrAccessDenied);
|
|
1502 |
|
|
1503 |
test.Next(_L("PIPE TEST:6.15 Try to register Space available notification using Read handle. Should not allow.\n"));
|
|
1504 |
aReader.NotifySpaceAvailable(tempsize, stat1);
|
|
1505 |
test ( stat1.Int() == KErrAccessDenied);
|
|
1506 |
|
|
1507 |
test.Next(_L("PIPE TEST:6.16 Try to Cancel Data available notification using Write handle. Should not allow.\n"));
|
|
1508 |
ret = aWriter.CancelDataAvailable();
|
|
1509 |
test ( ret == KErrAccessDenied);
|
|
1510 |
|
|
1511 |
test.Next(_L("PIPE TEST:6.17 Try to Cancel Space available notification using Write handle. Should not allow.\n"));
|
|
1512 |
ret = aReader.CancelSpaceAvailable();
|
|
1513 |
test ( ret == KErrAccessDenied);
|
|
1514 |
|
|
1515 |
// Stop the thread and Close the Thread
|
|
1516 |
ret = thread4.WaitForExitL();
|
|
1517 |
}
|
|
1518 |
test_KErrNone(ret);
|
|
1519 |
// Close all the pipe handles.
|
|
1520 |
aReader.Close();
|
|
1521 |
aWriter.Close();
|
|
1522 |
|
|
1523 |
|
|
1524 |
|
|
1525 |
test.Printf(_L(" TEST NOTIFICATION MECHNISM FOR NAMED PIPES\n"));
|
|
1526 |
|
|
1527 |
aSize = 22; // Size of KTestData
|
|
1528 |
|
|
1529 |
test.Next(_L("PIPE TEST:6.18 Create Named pipe and Open Read/Write Handles.\n"));
|
|
1530 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1531 |
test (ret == KErrNone);
|
|
1532 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1533 |
test (ret == KErrNone);
|
|
1534 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1535 |
test (ret == KErrNone);
|
|
1536 |
|
|
1537 |
|
|
1538 |
|
|
1539 |
TData data2( &aReader, &aWriter);
|
|
1540 |
|
|
1541 |
// Create Thread 4
|
|
1542 |
// Pass TData object with Write and Read handle both
|
|
1543 |
TTestThread thread4a(KThread4Name, TestThread4, &data2);
|
|
1544 |
|
|
1545 |
// Thread 4
|
|
1546 |
// Call Notifydata available
|
|
1547 |
// Loop for Available
|
|
1548 |
// Read the data and validate
|
|
1549 |
|
|
1550 |
// Write one byte data into the pipe.
|
|
1551 |
test.Next(_L("PIPE TEST:6.19 Write Data and check for return value.\n"));
|
|
1552 |
globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
|
|
1553 |
ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
|
|
1554 |
test (ret == cPipeTestData1.Length());
|
|
1555 |
|
|
1556 |
test.Next(_L("PIPE TEST:6.20 Register Notification for Space Available.\n"));
|
|
1557 |
// Call Notfifyspace
|
|
1558 |
tempsize = 1;
|
|
1559 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1560 |
test(stat1==KRequestPending);
|
|
1561 |
globalSem.Signal(); //signal that thread 4 may go ahead and read byte
|
|
1562 |
|
|
1563 |
test.Next(_L("PIPE TEST:6.21 Wait till notified for Space Availanle.\n"));
|
|
1564 |
User::WaitForRequest(stat1);
|
|
1565 |
test ( stat1.Int() == KErrNone);
|
|
1566 |
|
|
1567 |
// Thread 4
|
|
1568 |
// Read one byte of data
|
|
1569 |
// Thread 4
|
|
1570 |
// Notify data available
|
|
1571 |
// Loop for available
|
|
1572 |
// Flush the buffer
|
|
1573 |
// Register two request for Notifydata available
|
|
1574 |
// Register two request for Notifyspace available
|
|
1575 |
// Call Notifydata available using Read handle
|
|
1576 |
// Call Notifydata available using write handle
|
|
1577 |
// return
|
|
1578 |
|
|
1579 |
globalSem.Wait(); //waiting for a signal from thread4.
|
|
1580 |
test.Next(_L("PIPE TEST:6.22 Notify for Space available.\n"));
|
|
1581 |
// Register two request for Notifydata available
|
|
1582 |
ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
|
|
1583 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1584 |
|
|
1585 |
test.Next(_L("PIPE TEST:6.23 Notify one more notifier for Space available.\n"));
|
|
1586 |
// Register two request for Notifyspace available
|
|
1587 |
TRequestStatus notifyStatus;
|
|
1588 |
aWriter.NotifySpaceAvailable(tempsize, notifyStatus);
|
|
1589 |
test ( notifyStatus.Int() == KErrInUse);
|
|
1590 |
|
|
1591 |
aWriter.Flush();
|
|
1592 |
aWriter.NotifySpaceAvailable(tempsize, stat1);
|
|
1593 |
test ( stat1.Int() == KErrNone);
|
|
1594 |
|
|
1595 |
test.Next(_L("PIPE TEST:6.24 Cancel Notify for Space available.\n"));
|
|
1596 |
ret = aWriter.CancelSpaceAvailable();
|
|
1597 |
test (( ret == KErrNotFound) ||( ret == KErrNone));
|
|
1598 |
test.Next(_L("PIPE TEST:6.25 Cancel one more Notify for Space available.\n"));
|
|
1599 |
ret = aWriter.CancelSpaceAvailable();
|
|
1600 |
test ( ret == KErrNone);
|
|
1601 |
|
|
1602 |
test.Next(_L("PIPE TEST:6.26 Register Notify for Data available.\n"));
|
|
1603 |
// Register two request for Notifydata available
|
|
1604 |
|
|
1605 |
aWriter.Flush();
|
|
1606 |
TRequestStatus stat5,stat6;
|
|
1607 |
aReader.NotifyDataAvailable(stat5);
|
|
1608 |
|
|
1609 |
test.Next(_L("PIPE TEST:6.27 Register One more Notify for Data available.\n"));
|
|
1610 |
// Register two request for Notifyspace available
|
|
1611 |
aReader.NotifyDataAvailable(notifyStatus);
|
|
1612 |
test ( notifyStatus.Int() == KErrInUse);
|
|
1613 |
test.Next(_L("PIPE TEST:6.28 Cancel Notify for Data available.\n"));
|
|
1614 |
ret = aReader.CancelDataAvailable();
|
|
1615 |
test ( ret == KErrNone);
|
|
1616 |
test (stat5.Int() == KErrCancel);
|
|
1617 |
|
|
1618 |
test.Next(_L("PIPE TEST:6.29 Cancel One more Notify for Data available.\n"));
|
|
1619 |
ret = aReader.CancelDataAvailable();
|
|
1620 |
test ( ret == KErrNone);
|
|
1621 |
|
|
1622 |
test.Next(_L("PIPE TEST:6.30 Register Notify for Data available using Write handle\n"));
|
|
1623 |
aWriter.NotifyDataAvailable(stat6);
|
|
1624 |
test ( stat6.Int() == KErrAccessDenied);
|
|
1625 |
|
|
1626 |
test.Next(_L("PIPE TEST:6.31 Register Notify for Space available using Read handle\n"));
|
|
1627 |
aReader.NotifySpaceAvailable(tempsize, stat6);
|
|
1628 |
test ( stat6.Int() == KErrAccessDenied);
|
|
1629 |
|
|
1630 |
test.Next(_L("PIPE TEST:6.32 Cancel Notify for Data available using Write handle\n"));
|
|
1631 |
ret = aWriter.CancelDataAvailable();
|
|
1632 |
test ( ret == KErrAccessDenied);
|
|
1633 |
|
|
1634 |
test.Next(_L("PIPE TEST:6.33 Cancel Notify for Space available using Read handle\n"));
|
|
1635 |
ret = aReader.CancelSpaceAvailable();
|
|
1636 |
test ( ret == KErrAccessDenied);
|
|
1637 |
|
|
1638 |
//close the handle to the global semaphore
|
|
1639 |
|
|
1640 |
globalSem.Close();
|
|
1641 |
// Stop the thread and Close the Thread
|
|
1642 |
ret = thread4a.WaitForExitL();
|
|
1643 |
test_KErrNone(ret);
|
|
1644 |
aReader.Close();
|
|
1645 |
aWriter.Close();
|
|
1646 |
RPipe::Destroy(cPipeName);
|
|
1647 |
|
|
1648 |
|
|
1649 |
return;
|
|
1650 |
|
|
1651 |
|
|
1652 |
|
|
1653 |
} // End TestNotifyMechanismPipes()
|
|
1654 |
|
|
1655 |
/****************************************************************************
|
|
1656 |
This is a function to test Named pipes in Mutli process environment.
|
|
1657 |
Check the functionality of following library functions
|
|
1658 |
- Define ()
|
|
1659 |
-
|
|
1660 |
|
|
1661 |
|
|
1662 |
******************************************************************************/
|
|
1663 |
|
|
1664 |
|
|
1665 |
_LIT8(KTestDataIP, "ABCDEFGHIJ");
|
|
1666 |
|
|
1667 |
void TestMultiProcessNamedPipes() {
|
|
1668 |
|
|
1669 |
_LIT(KPipeName5, "InterProcessPipe1");
|
|
1670 |
TInt ret; // Return value variable
|
|
1671 |
RProcess proc; // Process Handle
|
|
1672 |
RPipe aWriter;
|
|
1673 |
RPipe aWriterUN,aReaderUN;
|
|
1674 |
const TBufC<150> cPipeName1(KPipeName5);
|
|
1675 |
|
|
1676 |
TBufC8<150> cPipeWriteData1(KTestDataIP);
|
|
1677 |
TInt aSize;
|
|
1678 |
TRequestStatus stat1;
|
|
1679 |
TBuf8<150> cPipeReadData1;
|
|
1680 |
|
|
1681 |
aSize = 10;
|
|
1682 |
|
|
1683 |
// Define Pipe with valid size.
|
|
1684 |
|
|
1685 |
test.Next(_L("PIPE TEST:5.1 Define Pipe and Create UnNAmed pipe and pass handle to other process.\n"));
|
|
1686 |
ret = RPipe::Define(cPipeName1, aSize);
|
|
1687 |
test_KErrNone(ret);
|
|
1688 |
ret = proc.Create(
|
|
1689 |
KProcessName, // Launch t_pipe2.exe process
|
|
1690 |
KNullDesC // No arguments passed to t_pipe2.exe
|
|
1691 |
);
|
|
1692 |
|
|
1693 |
if (ret != KErrNone) {
|
|
1694 |
// Check for process successfully launched
|
|
1695 |
test.Printf(_L("Error : Could not start the process t_pipe2.exe \n"));
|
|
1696 |
}
|
|
1697 |
test_KErrNone(ret);
|
|
1698 |
TRequestStatus procLogon;
|
|
1699 |
proc.Logon(procLogon);
|
|
1700 |
test(procLogon==KRequestPending);
|
|
1701 |
|
|
1702 |
aSize = 512;
|
|
1703 |
ret = RPipe::Create( aSize,
|
|
1704 |
aReaderUN,
|
|
1705 |
aWriterUN,
|
|
1706 |
EOwnerProcess,//TOwnerType aTypeW
|
|
1707 |
EOwnerProcess //TOwnerType aTypeW
|
|
1708 |
);
|
|
1709 |
test_KErrNone(ret);
|
|
1710 |
|
|
1711 |
ret = aWriterUN.Write(KTestData,22);
|
|
1712 |
test (ret == 22);
|
|
1713 |
ret = aReaderUN.Read(cPipeReadData1,10);
|
|
1714 |
test ( ret == 10);
|
|
1715 |
aWriterUN.Close();
|
|
1716 |
ret = aReaderUN.Read(cPipeReadData1,6);
|
|
1717 |
test (ret == 6);
|
|
1718 |
aReaderUN.NotifyDataAvailable(stat1);
|
|
1719 |
ret = stat1.Int();
|
|
1720 |
test (ret == KErrNone);
|
|
1721 |
ret = aReaderUN.ReadBlocking(cPipeReadData1,6);
|
|
1722 |
test (ret == 6);
|
|
1723 |
ret = aReaderUN.Read(cPipeReadData1,1);
|
|
1724 |
test ( ret == KErrNotReady);
|
|
1725 |
ret = aReaderUN.ReadBlocking(cPipeReadData1,1);
|
|
1726 |
test ( ret == KErrNotReady);
|
|
1727 |
aReaderUN.Close();
|
|
1728 |
|
|
1729 |
ret = RPipe::Create( aSize,
|
|
1730 |
aReaderUN,
|
|
1731 |
aWriterUN,
|
|
1732 |
EOwnerProcess,//TOwnerType aTypeW
|
|
1733 |
EOwnerProcess //TOwnerType aTypeW
|
|
1734 |
);
|
|
1735 |
test_KErrNone(ret);
|
|
1736 |
proc.SetParameter(3,aReaderUN);
|
|
1737 |
aReaderUN.Close();
|
|
1738 |
ret = aWriterUN.Write(KTestData,22);
|
|
1739 |
test (ret == 22 );
|
|
1740 |
|
|
1741 |
proc.Resume();
|
|
1742 |
|
|
1743 |
aSize = 10;
|
|
1744 |
test.Next(_L("PIPE TEST:5.2 Open Write handle to Pipe. Wait till Read handle Opened\n"));
|
|
1745 |
ret = aWriter.Open(cPipeName1, RPipe::EOpenToWrite);
|
|
1746 |
test_KErrNone(ret);
|
|
1747 |
aWriter.Wait(cPipeName1,stat1);
|
|
1748 |
User::WaitForRequest(stat1);
|
|
1749 |
test (stat1.Int() == KErrNone);
|
|
1750 |
|
|
1751 |
test.Next(_L("PIPE TEST:5.3 Write data to Pipe.\n"));
|
|
1752 |
ret = aWriter.Write(cPipeWriteData1,cPipeWriteData1.Length());
|
|
1753 |
test ( ret == cPipeWriteData1.Length());
|
|
1754 |
|
|
1755 |
test.Next(_L("PIPE TEST:5.4 Wait till Space Available in Pipe.\n"));
|
|
1756 |
aWriter.NotifySpaceAvailable(aSize,stat1);
|
|
1757 |
User::WaitForRequest(stat1);
|
|
1758 |
|
|
1759 |
test.Next(_L("PIPE TEST:5.5 Write the data using WriteBlocking call\n"));
|
|
1760 |
test_Equal(0, aWriter.Size());
|
|
1761 |
ret = aWriter.WriteBlocking(cPipeWriteData1,cPipeWriteData1.Length());
|
|
1762 |
test ( ret ==cPipeWriteData1.Length() );
|
|
1763 |
|
|
1764 |
User::WaitForRequest(procLogon);
|
|
1765 |
|
|
1766 |
aWriter.Close();
|
|
1767 |
ret=RPipe::Destroy(cPipeName1);
|
|
1768 |
test_KErrNone(ret);
|
|
1769 |
|
|
1770 |
proc.Close();
|
|
1771 |
aWriterUN.Close();
|
|
1772 |
aReaderUN.Close();
|
|
1773 |
return;
|
|
1774 |
|
|
1775 |
} // End TestMultiProcessNamedPipes ()
|
|
1776 |
/****************************************************************************
|
|
1777 |
This is a function to test Named pipes in Multi threaded environment.
|
|
1778 |
Check the functionality of following library functions
|
|
1779 |
- Define ()
|
|
1780 |
- Read()
|
|
1781 |
- Write()
|
|
1782 |
- ReadBlocking()
|
|
1783 |
- WriteBlocking()
|
|
1784 |
|
|
1785 |
|
|
1786 |
******************************************************************************/
|
|
1787 |
//
|
|
1788 |
// Test defining and opening both ends of pipe
|
|
1789 |
// Attempt to readblock from pipe closed at far end (should fail)
|
|
1790 |
// Attemp writeblock to pipe closed at far end
|
|
1791 |
//
|
|
1792 |
// Do some normal reading and writing between threads
|
|
1793 |
// do some blocking read/write between threads
|
|
1794 |
void TestMultiThreadNamedPipes() {
|
|
1795 |
|
|
1796 |
TInt ret; // Return Value variable.
|
|
1797 |
RPipe aReader,aWriter; // Used to pass to thread.
|
|
1798 |
TInt aSize; // Used to pass to thread.
|
|
1799 |
const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
|
|
1800 |
TInt aReadSize;
|
|
1801 |
TBuf8<150> cPipeReadData;
|
|
1802 |
TBufC8<50> cTestData(KTestData); // Test Data
|
|
1803 |
|
|
1804 |
|
|
1805 |
|
|
1806 |
|
|
1807 |
///////////////////////////////////////////////////////////
|
|
1808 |
// PART : 1 ///
|
|
1809 |
// Test Read and Write Functionality ///
|
|
1810 |
///////////////////////////////////////////////////////////
|
|
1811 |
|
|
1812 |
test.Next(_L("PIPE TEST:4.1 Define Pipe , Open Read and Write Handle.\n"));
|
|
1813 |
aSize = 22;
|
|
1814 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1815 |
test (ret == KErrNone);
|
|
1816 |
|
|
1817 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1818 |
test (ret == KErrNone);
|
|
1819 |
|
|
1820 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1821 |
test (ret == KErrNone);
|
|
1822 |
|
|
1823 |
aWriter.Close();
|
|
1824 |
|
|
1825 |
test.Next(_L("PIPE TEST:4.2 ReadBlocking: Check for KErrNotReady.\n"));
|
|
1826 |
aReadSize = 1;
|
|
1827 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
1828 |
test (ret == KErrNotReady);
|
|
1829 |
|
|
1830 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1831 |
test (ret == KErrNone);
|
|
1832 |
|
|
1833 |
|
|
1834 |
aReader.Close();
|
|
1835 |
test.Next(_L("PIPE TEST:4.3 WriteBlocking: Check for KErrNotReady.\n"));
|
|
1836 |
ret = aWriter.WriteBlocking(cTestData,cTestData.Length());
|
|
1837 |
test (ret == KErrNotReady);
|
|
1838 |
|
|
1839 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1840 |
test (ret == KErrNone);
|
|
1841 |
|
|
1842 |
|
|
1843 |
TData data( &aReader, &aWriter);
|
|
1844 |
|
|
1845 |
|
|
1846 |
|
|
1847 |
|
|
1848 |
// Write data to Pipe using valid handle
|
|
1849 |
test.Next(_L("PIPE TEST:4.4 Write into the pipe and verify return value.\n"));
|
|
1850 |
ret = aWriter.Write(cTestData,cTestData.Length());
|
|
1851 |
test (ret == cTestData.Length() );
|
|
1852 |
|
|
1853 |
|
|
1854 |
// Keep writing the data into pipe till it overflows
|
|
1855 |
|
|
1856 |
test.Next(_L("PIPE TEST:4.5 Write into the pipe till it overflows.\n"));
|
|
1857 |
ret = aWriter.Write(cTestData,cTestData.Length());
|
|
1858 |
test (( ret == KErrOverflow)) ;
|
|
1859 |
|
|
1860 |
// Start the thread.
|
|
1861 |
TTestThread thread2(KThread2Name, TestThread2, &data);
|
|
1862 |
// Read 1 byte data from pipe
|
|
1863 |
// Validate data
|
|
1864 |
// Read aByte size data
|
|
1865 |
// Validate data
|
|
1866 |
// Thread 2
|
|
1867 |
// Read aByte size data
|
|
1868 |
// User:: After (10000)
|
|
1869 |
// Keep reading data till zero return
|
|
1870 |
// return
|
|
1871 |
|
|
1872 |
// Stop the thread and Close the Thread
|
|
1873 |
ret = thread2.WaitForExitL();
|
|
1874 |
test_KErrNone(ret);
|
|
1875 |
|
|
1876 |
aReader.Close();
|
|
1877 |
aWriter.Close();
|
|
1878 |
ret = RPipe::Destroy(cPipeName);
|
|
1879 |
test_KErrNone(ret);
|
|
1880 |
|
|
1881 |
|
|
1882 |
///////////////////////////////////////////////////////////
|
|
1883 |
// PART : 2 ///
|
|
1884 |
// Test ReadBlocking and WriteBlocking Functionality ///
|
|
1885 |
///////////////////////////////////////////////////////////
|
|
1886 |
|
|
1887 |
// Test Read and Write blocking call
|
|
1888 |
|
|
1889 |
test.Next(_L("PIPE TEST:4.6 Create UnNamed Pipe with valid size.\n"));
|
|
1890 |
|
|
1891 |
aSize = 22;
|
|
1892 |
ret = RPipe::Define( cPipeName,aSize);
|
|
1893 |
test (ret == KErrNone);
|
|
1894 |
|
|
1895 |
ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
|
|
1896 |
test (ret == KErrNone);
|
|
1897 |
|
|
1898 |
ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
|
|
1899 |
test (ret == KErrNone);
|
|
1900 |
|
|
1901 |
// Create TData object to pass Pipe handles.
|
|
1902 |
TData data2( &aReader, &aWriter);
|
|
1903 |
|
|
1904 |
|
|
1905 |
// Create Thread ( Note : Thread is in pending state now)
|
|
1906 |
// Flush the data if any in pipe to make sure its empty.
|
|
1907 |
aWriter.Flush();
|
|
1908 |
|
|
1909 |
// Start the thread
|
|
1910 |
TTestThread thread3(KThread3Name, TestThread3, &data2);
|
|
1911 |
// Thread 3
|
|
1912 |
// Write one byte of data
|
|
1913 |
// Write one one byte of data using WriteBlocking call
|
|
1914 |
// Write aByte size data using Writblocking call
|
|
1915 |
|
|
1916 |
|
|
1917 |
// Call Readblocking function.Read one byte of data.
|
|
1918 |
test.Next(_L("PIPE TEST:4.7 Flush the buffer and Call ReadBlocking one byte into the pipe.\n"));
|
|
1919 |
aReadSize = 1;
|
|
1920 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
1921 |
test_Equal(aReadSize, ret);
|
|
1922 |
|
|
1923 |
test.Next(_L("PIPE TEST:4.8 Verify the data received.\n"));
|
|
1924 |
test ( KErrNone == cPipeReadData.Compare(KTestData1));
|
|
1925 |
|
|
1926 |
|
|
1927 |
test.Next(_L("PIPE TEST:4.9 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
|
|
1928 |
// Call Readblocking function.Read aSize bytes of data.
|
|
1929 |
aReadSize = aSize-aReadSize; //read rest of data
|
|
1930 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
1931 |
test_Equal(aReadSize, ret);
|
|
1932 |
test ( KErrNone == cPipeReadData.Compare(KTestData3));
|
|
1933 |
|
|
1934 |
// Thread 3
|
|
1935 |
// Wait for some time
|
|
1936 |
// Call Readblocking and read 1 byte of data
|
|
1937 |
// Call Readblocking and Read abyte size data
|
|
1938 |
// Call flush buffer
|
|
1939 |
// return
|
|
1940 |
test.Next(_L("PIPE TEST:4.10 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
|
|
1941 |
// Call Readblocking function.Read aSize bytes of data.
|
|
1942 |
aReadSize = aSize;
|
|
1943 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
1944 |
test_Equal(aReadSize, ret);
|
|
1945 |
test ( KErrNone == cPipeReadData.Compare(KTestData2));
|
|
1946 |
|
|
1947 |
// Stop the thread and Close the Thread
|
|
1948 |
ret = thread3.WaitForExitL();
|
|
1949 |
test_KErrNone(ret);
|
|
1950 |
|
|
1951 |
aReader.Close();
|
|
1952 |
aWriter.Close();
|
|
1953 |
ret=RPipe::Destroy(cPipeName);
|
|
1954 |
test_KErrNone(ret);
|
|
1955 |
return ;
|
|
1956 |
|
|
1957 |
} // End TestMultiThreadNamedPipes ()
|
|
1958 |
|
|
1959 |
|
|
1960 |
/****************************************************************************
|
|
1961 |
This is a function to test UnNamed pipes in Multi threaded environment.
|
|
1962 |
Check the functionality of following library functions
|
|
1963 |
- Create()
|
|
1964 |
- Read()
|
|
1965 |
- Write()
|
|
1966 |
- ReadBlocking()
|
|
1967 |
- WriteBlocking()
|
|
1968 |
|
|
1969 |
|
|
1970 |
******************************************************************************/
|
|
1971 |
void TestMultiThreadUnNamedPipes() {
|
|
1972 |
|
|
1973 |
TInt ret; // Return Value variable.
|
|
1974 |
RPipe aReader,aWriter; // Used to pass to thread.
|
|
1975 |
TInt aSize; // Used to pass to thread.
|
|
1976 |
TBuf8<250> cPipeReadData;
|
|
1977 |
TInt aReadSize;
|
|
1978 |
TBufC8<50> cTestData(KTestData); // Test Data
|
|
1979 |
|
|
1980 |
|
|
1981 |
///////////////////////////////////////////////////////////
|
|
1982 |
// PART : 1 ///
|
|
1983 |
// Test Read and Write Functionality ///
|
|
1984 |
///////////////////////////////////////////////////////////
|
|
1985 |
|
|
1986 |
test.Next(_L("PIPE TEST: 3.1 Create Pipe : Check for no erros on Pipe Creation \n"));
|
|
1987 |
ret = 100;
|
|
1988 |
aSize = 22; // Size of KTestData * 10
|
|
1989 |
|
|
1990 |
ret = RPipe::Create( aSize,
|
|
1991 |
aReader,
|
|
1992 |
aWriter,
|
|
1993 |
EOwnerProcess ,//TOwnerType aTypeW
|
|
1994 |
EOwnerProcess //TOwnerType aTypeW
|
|
1995 |
);
|
|
1996 |
|
|
1997 |
test (ret == KErrNone);
|
|
1998 |
|
|
1999 |
// Create TData object to pass Pipe handles.
|
|
2000 |
TData data1( &aReader, &aWriter);
|
|
2001 |
|
|
2002 |
// Create Thread ( Note : Thread is in pending state now)
|
|
2003 |
|
|
2004 |
// Create test data stream.
|
|
2005 |
test.Next(_L("PIPE TEST: 3.2 Write Function test : Write data into the pipe \n"));
|
|
2006 |
ret = aWriter.Write(cTestData,cTestData.Length()); // Write ""Pipe Data To Be Passed"
|
|
2007 |
test (ret == cTestData.Length());
|
|
2008 |
|
|
2009 |
// Keep writing the data into pipe till it overflows
|
|
2010 |
test.Next(_L("PIPE TEST: 3.3 Write Data till the Pipe returns KErrOverFlow\n"));
|
|
2011 |
ret = aWriter.Write(cTestData,cTestData.Length());
|
|
2012 |
test ( ret == KErrOverflow);
|
|
2013 |
|
|
2014 |
TTestThread thread2(KThread2Name, TestThread2, &data1);
|
|
2015 |
// Thread2
|
|
2016 |
// Read 1 byte data from pipe
|
|
2017 |
// Validate data
|
|
2018 |
// Read aByte size data
|
|
2019 |
// Validate data
|
|
2020 |
// Thread 2
|
|
2021 |
// Read aByte size data
|
|
2022 |
// User:: After (10000)
|
|
2023 |
// Keep reading data till zero return
|
|
2024 |
// return
|
|
2025 |
|
|
2026 |
// Stop the thread , Close it.
|
|
2027 |
|
|
2028 |
ret = thread2.WaitForExitL();
|
|
2029 |
test_KErrNone(ret);
|
|
2030 |
|
|
2031 |
aReader.Close();
|
|
2032 |
aWriter.Close();
|
|
2033 |
|
|
2034 |
|
|
2035 |
///////////////////////////////////////////////////////////
|
|
2036 |
// PART : 2 ///
|
|
2037 |
// Test ReadBlocking and WriteBlocking Functionality ///
|
|
2038 |
///////////////////////////////////////////////////////////
|
|
2039 |
|
|
2040 |
|
|
2041 |
aSize = 22; // Size of KTestData
|
|
2042 |
|
|
2043 |
ret = RPipe::Create( aSize,
|
|
2044 |
aReader,
|
|
2045 |
aWriter,
|
|
2046 |
EOwnerProcess , //TOwnerType aTypeW
|
|
2047 |
EOwnerProcess //TOwnerType aTypeW
|
|
2048 |
);
|
|
2049 |
test_KErrNone(ret);
|
|
2050 |
|
|
2051 |
// Create TData object to pass Pipe handles.
|
|
2052 |
|
|
2053 |
TData data2(&aReader, &aWriter);
|
|
2054 |
|
|
2055 |
// Flush the data if any in pipe to make sure its empty.
|
|
2056 |
aWriter.Flush();
|
|
2057 |
|
|
2058 |
// Start the thread
|
|
2059 |
TTestThread thread3(KThread3Name, TestThread3, &data2);
|
|
2060 |
// Thread 3
|
|
2061 |
// Write one byte of data
|
|
2062 |
// Write one one byte of data using WriteBlocking call
|
|
2063 |
// Write aByte size data using Writblocking call
|
|
2064 |
|
|
2065 |
|
|
2066 |
// Call Readblocking function.Read one byte of data.
|
|
2067 |
|
|
2068 |
aReadSize = 1;
|
|
2069 |
test.Next(_L("PIPE TEST: 3.4 : Call readblocking and read one byte of data \n"));
|
|
2070 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
2071 |
// Call goes to Thread 3
|
|
2072 |
test_Equal(aReadSize, ret);
|
|
2073 |
|
|
2074 |
test.Next(_L("PIPE TEST: 3.5 : Validate the data \n"));
|
|
2075 |
test_Equal(0, cPipeReadData.Compare(KTestData1));
|
|
2076 |
|
|
2077 |
|
|
2078 |
// Call Readblocking function.Read aSize bytes of data.
|
|
2079 |
test.Next(_L("PIPE TEST: 3.6 : Read remaining data \n"));
|
|
2080 |
aReadSize = 21;
|
|
2081 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
2082 |
test_Equal(aReadSize, ret);
|
|
2083 |
test_Equal(0, cPipeReadData.Compare(KTestData3));
|
|
2084 |
|
|
2085 |
|
|
2086 |
test.Next(_L("PIPE TEST: 3.7 : Read complete pipe size data \n"));
|
|
2087 |
aReadSize = 22;
|
|
2088 |
ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
|
|
2089 |
test_Equal(aReadSize, ret);
|
|
2090 |
test_Equal(0, cPipeReadData.Compare(KTestData2));
|
|
2091 |
|
|
2092 |
// Wait for thread to end and Close
|
|
2093 |
ret = thread3.WaitForExitL();
|
|
2094 |
test_KErrNone(ret);
|
|
2095 |
|
|
2096 |
aReader.Close();
|
|
2097 |
aWriter.Close();
|
|
2098 |
|
|
2099 |
return ;
|
|
2100 |
|
|
2101 |
|
|
2102 |
}// End TestMultiThreadUnNamedPipes()
|
|
2103 |
|
|
2104 |
/****************************************************************************
|
|
2105 |
This is a function to test Named pipes in Single threaded environment.
|
|
2106 |
Check the functionality of following library functions
|
|
2107 |
- Define ()
|
|
2108 |
-
|
|
2109 |
|
|
2110 |
|
|
2111 |
******************************************************************************/
|
|
2112 |
|
|
2113 |
void TestSingleThreadNamedPipes()
|
|
2114 |
|
|
2115 |
{
|
|
2116 |
|
|
2117 |
|
|
2118 |
const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
|
|
2119 |
TInt aSize, ret;
|
|
2120 |
RPipe testPipe1;
|
|
2121 |
RPipe testPipe2;
|
|
2122 |
RPipe testPipe3;
|
|
2123 |
RPipe testPipe4;
|
|
2124 |
RPipe testPipe5;
|
|
2125 |
const TBufC<100> cPipeNameMax(KMaxPipeName);
|
|
2126 |
const TBufC<100> cPipeNameMaxPlusOne(KMaxPipeNamePlusOne);
|
|
2127 |
|
|
2128 |
_LIT(KBadName , "***?SFSDFWE?*_-");
|
|
2129 |
_LIT(KBadName2 , "");
|
|
2130 |
|
|
2131 |
test.Next(_L("PIPE TEST: 2.1 Define Function test : Check for No Error\n"));
|
|
2132 |
aSize = 10;
|
|
2133 |
|
|
2134 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2135 |
test (ret == KErrNone);
|
|
2136 |
|
|
2137 |
ret = RPipe::Destroy (cPipeName);
|
|
2138 |
test (ret == KErrNone);
|
|
2139 |
|
|
2140 |
|
|
2141 |
|
|
2142 |
test.Next(_L("PIPE TEST: 2.2 Define Function test : Check for Max length \n"));
|
|
2143 |
|
|
2144 |
aSize = 10;
|
|
2145 |
|
|
2146 |
ret = RPipe::Define(cPipeNameMax , aSize);
|
|
2147 |
test (ret == KErrNone);
|
|
2148 |
|
|
2149 |
ret = RPipe::Destroy (cPipeNameMax);
|
|
2150 |
test (ret == KErrNone);
|
|
2151 |
|
|
2152 |
test.Next(_L("PIPE TEST: 2.3 Define Function test : Check for Max length \n"));
|
|
2153 |
|
|
2154 |
aSize = 10;
|
|
2155 |
ret = RPipe::Define(cPipeNameMaxPlusOne , aSize);
|
|
2156 |
test (ret == KErrBadName);
|
|
2157 |
ret = RPipe::Destroy (cPipeNameMaxPlusOne);
|
|
2158 |
test (ret == KErrBadName);
|
|
2159 |
|
|
2160 |
test.Next(_L("PIPE TEST: 2.4 Open Function test : Test Open \n"));
|
|
2161 |
aSize = 10;
|
|
2162 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2163 |
test_KErrNone(ret);
|
|
2164 |
|
|
2165 |
ret = testPipe1.Open(KBadName,RPipe::EOpenToRead);
|
|
2166 |
test (ret == KErrBadName);
|
|
2167 |
|
|
2168 |
ret = testPipe1.Open(KBadName2,RPipe::EOpenToRead);
|
|
2169 |
test (ret == KErrBadName);
|
|
2170 |
|
|
2171 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
|
|
2172 |
test (ret == KErrNone);
|
|
2173 |
|
|
2174 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToWrite);
|
|
2175 |
test (ret == KErrInUse);
|
|
2176 |
|
|
2177 |
|
|
2178 |
|
|
2179 |
test.Next(_L("PIPE TEST: 2.5 Destroy Function test : Destroy opened pipe error \n"));
|
|
2180 |
ret = RPipe::Destroy (cPipeName);
|
|
2181 |
test (ret == KErrInUse);
|
|
2182 |
|
|
2183 |
test.Next(_L("PIPE TEST: 2.6 Open Function test : Reopen pipe for reading\n"));
|
|
2184 |
ret = testPipe2.Open(cPipeName,RPipe::EOpenToRead);
|
|
2185 |
test (ret == KErrInUse);
|
|
2186 |
|
|
2187 |
test.Next(_L("PIPE TEST: 2.7 Open Function test : Bad name test \n"));
|
|
2188 |
ret = testPipe2.Open(cPipeNameMaxPlusOne,RPipe::EOpenToRead);
|
|
2189 |
test (ret == KErrBadName);
|
|
2190 |
|
|
2191 |
|
|
2192 |
test.Next(_L("PIPE TEST: 2.8 Open Function test : Write mode test\n"));
|
|
2193 |
|
|
2194 |
ret = testPipe3.Open(cPipeName,RPipe::EOpenToWrite);
|
|
2195 |
test (ret == KErrNone);
|
|
2196 |
|
|
2197 |
ret = testPipe3.Open(cPipeName,RPipe::EOpenToRead);
|
|
2198 |
test (ret == KErrInUse);
|
|
2199 |
|
|
2200 |
test.Next(_L("PIPE TEST: 2.9 Open Function test : Bad name test \n"));
|
|
2201 |
|
|
2202 |
ret = testPipe4.Open(cPipeNameMaxPlusOne,RPipe::EOpenToWrite);
|
|
2203 |
test (ret == KErrBadName);
|
|
2204 |
|
|
2205 |
|
|
2206 |
test.Next(_L("PIPE TEST: 2.10 Open Function test : Reopen for writing \n"));
|
|
2207 |
ret = testPipe4.Open(cPipeName,RPipe::EOpenToWrite);
|
|
2208 |
test (ret == KErrInUse);
|
|
2209 |
|
|
2210 |
|
|
2211 |
// Do we have pipes created ? Close and Destroy them ....!!
|
|
2212 |
|
|
2213 |
testPipe1.Close();
|
|
2214 |
testPipe2.Close();
|
|
2215 |
testPipe3.Close();
|
|
2216 |
testPipe4.Close();
|
|
2217 |
ret = RPipe::Destroy (cPipeName);
|
|
2218 |
test_KErrNone(ret);
|
|
2219 |
|
|
2220 |
|
|
2221 |
|
|
2222 |
test.Next(_L("PIPE TEST: 2.11a Open Function test : Write But Fail on no Readers mode before pipe defined\n"));
|
|
2223 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
|
|
2224 |
test_Equal(KErrNotFound,ret);
|
|
2225 |
|
|
2226 |
test.Next(_L("PIPE TEST: 2.11 Open Function test : Write But Fail on no Readers mode Error test\n"));
|
|
2227 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2228 |
test (ret == KErrNone);
|
|
2229 |
|
|
2230 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
|
|
2231 |
test (ret == KErrNotReady);
|
|
2232 |
|
|
2233 |
|
|
2234 |
test.Next(_L("PIPE TEST: 2.12 Open Function test : Write But Fail on no Readers mode Success test\n"));
|
|
2235 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
|
|
2236 |
test_KErrNone(ret);
|
|
2237 |
ret = testPipe2.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
|
|
2238 |
test ( ret == KErrNone);
|
|
2239 |
|
|
2240 |
|
|
2241 |
// Do we have pipes created ? Close and Destroy them ....!!
|
|
2242 |
|
|
2243 |
testPipe1.Close();
|
|
2244 |
testPipe2.Close();
|
|
2245 |
testPipe3.Close();
|
|
2246 |
testPipe4.Close();
|
|
2247 |
ret = RPipe::Destroy (cPipeName);
|
|
2248 |
test_KErrNone(ret);
|
|
2249 |
|
|
2250 |
|
|
2251 |
|
|
2252 |
test.Next(_L(" 2.13 Define Function test : Check Incorrect Size\n"));
|
|
2253 |
aSize = -1;
|
|
2254 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2255 |
test (ret == KErrArgument);
|
|
2256 |
|
|
2257 |
|
|
2258 |
test.Next(_L("PIPE TEST: 2.14 Define Function test : Check Incorrect Size\n"));
|
|
2259 |
aSize = 0x1fffffff;
|
|
2260 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2261 |
test (ret == KErrNoMemory);
|
|
2262 |
|
|
2263 |
|
|
2264 |
test.Next(_L("PIPE TEST: 2.15 Size Function test : Size\n"));
|
|
2265 |
aSize = 10;
|
|
2266 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2267 |
|
|
2268 |
ret = testPipe5.MaxSize();
|
|
2269 |
test (ret == KErrBadHandle);
|
|
2270 |
|
|
2271 |
|
|
2272 |
test.Next(_L("PIPE TEST: 2.16 Size Function test : Size\n"));
|
|
2273 |
aSize = 10;
|
|
2274 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2275 |
testPipe5.Open(cPipeName, RPipe::EOpenToRead);
|
|
2276 |
testPipe4.Open(cPipeName, RPipe::EOpenToWrite);
|
|
2277 |
ret = testPipe5.MaxSize();
|
|
2278 |
test (ret == aSize);
|
|
2279 |
ret = testPipe4.MaxSize();
|
|
2280 |
test (ret == aSize);
|
|
2281 |
|
|
2282 |
|
|
2283 |
/* Close all the pipes and Destroy*/
|
|
2284 |
testPipe1.Close();
|
|
2285 |
testPipe2.Close();
|
|
2286 |
testPipe3.Close();
|
|
2287 |
testPipe4.Close();
|
|
2288 |
testPipe5.Close();
|
|
2289 |
ret = RPipe::Destroy (cPipeName);
|
|
2290 |
test_KErrNone(ret);
|
|
2291 |
|
|
2292 |
_LIT(KRedefinePipe , "REDEFINEPIPE");
|
|
2293 |
|
|
2294 |
test.Next(_L("PIPE TEST: 2.17 Check for Redefining same pipe name \n"));
|
|
2295 |
ret = RPipe::Define(KRedefinePipe , aSize);
|
|
2296 |
test_KErrNone(ret);
|
|
2297 |
ret = RPipe::Define(KRedefinePipe , aSize);
|
|
2298 |
test (ret == KErrAlreadyExists);
|
|
2299 |
ret = RPipe::Destroy (KRedefinePipe);
|
|
2300 |
test_KErrNone(ret);
|
|
2301 |
|
|
2302 |
test.Next(_L("PIPE TEST: 2.18 Open Function test : Bad Pipe name\n"));
|
|
2303 |
aSize = 10;
|
|
2304 |
RPipe testPipe6;
|
|
2305 |
ret = testPipe6.Open(cPipeName, RPipe::EOpenToRead);
|
|
2306 |
test (ret == KErrNotFound);
|
|
2307 |
|
|
2308 |
|
|
2309 |
const TBufC<50> cPipeNameNull;
|
|
2310 |
test.Next(_L("PIPE TEST: 2.19 Define Function test : Null Pipe name and Bad Pipe name\n"));
|
|
2311 |
aSize = 10;
|
|
2312 |
ret = RPipe::Define(cPipeNameNull , aSize);
|
|
2313 |
test (ret == KErrBadName);
|
|
2314 |
|
|
2315 |
|
|
2316 |
ret = RPipe::Define(KBadName , aSize);
|
|
2317 |
test (ret == KErrBadName);
|
|
2318 |
ret = RPipe::Destroy(KBadName);
|
|
2319 |
test (ret == KErrBadName);
|
|
2320 |
|
|
2321 |
|
|
2322 |
ret = RPipe::Define(KBadName2 , aSize);
|
|
2323 |
test (ret == KErrBadName);
|
|
2324 |
ret = RPipe::Destroy(KBadName2);
|
|
2325 |
test (ret == KErrBadName);
|
|
2326 |
|
|
2327 |
|
|
2328 |
test.Next(_L("PIPE TEST: 2.20 Destroy a pipe while Write end is open\n"));
|
|
2329 |
ret = RPipe::Define(cPipeName , aSize);
|
|
2330 |
|
|
2331 |
testPipe1.Close();
|
|
2332 |
ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
|
|
2333 |
test (ret == KErrNone);
|
|
2334 |
testPipe2.Close();
|
|
2335 |
ret = testPipe2.Open(cPipeName,RPipe::EOpenToWrite);
|
|
2336 |
test (ret == KErrNone);
|
|
2337 |
testPipe1.Close();
|
|
2338 |
ret = RPipe::Destroy (cPipeName);
|
|
2339 |
test (ret == KErrInUse);
|
|
2340 |
|
|
2341 |
testPipe2.Close();
|
|
2342 |
ret = RPipe::Destroy (cPipeName);
|
|
2343 |
test (ret == KErrNone);
|
|
2344 |
|
|
2345 |
testPipe1.Close();
|
|
2346 |
testPipe2.Close();
|
|
2347 |
testPipe3.Close();
|
|
2348 |
testPipe4.Close();
|
|
2349 |
testPipe5.Close();
|
|
2350 |
|
|
2351 |
|
|
2352 |
_LIT(KPipe1Name,"TestPipeA");
|
|
2353 |
_LIT(KPipe2Name,"TestPipeB");
|
|
2354 |
_LIT(KPipe3Name,"TestPipeC");
|
|
2355 |
_LIT(KPipe4Name,"TestPipeD");
|
|
2356 |
|
|
2357 |
test.Next(_L("PIPE TEST: 2.21 Define Four pipes and Destroy in different sequence ( Code Coverage test)\n"));
|
|
2358 |
ret = RPipe::Define(KPipe1Name , aSize);
|
|
2359 |
test (ret == KErrNone);
|
|
2360 |
ret = RPipe::Define(KPipe2Name , aSize);
|
|
2361 |
test (ret == KErrNone);
|
|
2362 |
ret = RPipe::Define(KPipe3Name , aSize);
|
|
2363 |
test (ret == KErrNone);
|
|
2364 |
ret = RPipe::Define(KPipe4Name , aSize);
|
|
2365 |
test (ret == KErrNone);
|
|
2366 |
ret = RPipe::Destroy (KPipe2Name);
|
|
2367 |
test (ret == KErrNone);
|
|
2368 |
ret = RPipe::Destroy (KPipe4Name);
|
|
2369 |
test (ret == KErrNone);
|
|
2370 |
ret = RPipe::Destroy (KPipe1Name);
|
|
2371 |
test (ret == KErrNone);
|
|
2372 |
ret = RPipe::Destroy (KPipe3Name);
|
|
2373 |
test (ret == KErrNone);
|
|
2374 |
|
|
2375 |
return;
|
|
2376 |
|
|
2377 |
} // End TestSingleThreadNamedPipes()
|
|
2378 |
|
|
2379 |
/****************************************************************************
|
|
2380 |
This is a function to test UnNamed pipes in Single threaded environment.
|
|
2381 |
Check the functionality of following library functions
|
|
2382 |
- Create ()
|
|
2383 |
-
|
|
2384 |
|
|
2385 |
|
|
2386 |
******************************************************************************/
|
|
2387 |
|
|
2388 |
_LIT8(KTxtDataToSend,"*Test data to send**");
|
|
2389 |
|
|
2390 |
void TestSingleThreadUnNamedPipes() {
|
|
2391 |
|
|
2392 |
TInt ret = 1; // Return value test variable.
|
|
2393 |
TInt aSize;
|
|
2394 |
TBufC8<40> wData(KTxtDataToSend); // Descriptor to hold data for Writing.
|
|
2395 |
RPipe aReader,aWriter;
|
|
2396 |
RPipe aReader2,aWriter2;
|
|
2397 |
|
|
2398 |
|
|
2399 |
// Following tests will verify all the APIs in single thread
|
|
2400 |
// for all the possible return values.
|
|
2401 |
// This is to verify different paths of API
|
|
2402 |
// not for detail functional verification.
|
|
2403 |
// Create the Pipe and Check for No Errors when Valid parameters are passed.
|
|
2404 |
|
|
2405 |
test.Next(_L("PIPE TEST:1.1 Create Function test : Check for No Error\n"));
|
|
2406 |
aSize = 10;
|
|
2407 |
|
|
2408 |
ret = RPipe::Create( aSize,
|
|
2409 |
aReader,
|
|
2410 |
aWriter,
|
|
2411 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2412 |
EOwnerProcess //TOwnerType aTypeW
|
|
2413 |
);
|
|
2414 |
|
|
2415 |
test (ret == KErrNone);
|
|
2416 |
|
|
2417 |
ret = RPipe::Create( aSize,
|
|
2418 |
aReader,
|
|
2419 |
aWriter,
|
|
2420 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2421 |
EOwnerProcess //TOwnerType aTypeW
|
|
2422 |
);
|
|
2423 |
|
|
2424 |
test (ret == KErrInUse);
|
|
2425 |
|
|
2426 |
aWriter.Close();
|
|
2427 |
aReader.Close();
|
|
2428 |
|
|
2429 |
|
|
2430 |
// How big pipe we can create ?
|
|
2431 |
|
|
2432 |
test.Next(_L("PIPE TEST:1.2 Create Function test : Check for No Memory\n"));
|
|
2433 |
|
|
2434 |
aSize = 0x1BCDEFFF;
|
|
2435 |
|
|
2436 |
ret = RPipe::Create( aSize,
|
|
2437 |
aReader2,
|
|
2438 |
aWriter2,
|
|
2439 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2440 |
EOwnerProcess //TOwnerType aTypeW
|
|
2441 |
);
|
|
2442 |
|
|
2443 |
test (ret == KErrNoMemory);
|
|
2444 |
|
|
2445 |
aReader2.Close();
|
|
2446 |
aWriter2.Close();
|
|
2447 |
|
|
2448 |
|
|
2449 |
test.Next(_L("PIPE TEST:1.3 Create Function test : Check for Reopening pipe\n"));
|
|
2450 |
aSize = 10;
|
|
2451 |
|
|
2452 |
ret = RPipe::Create( aSize,
|
|
2453 |
aReader,
|
|
2454 |
aWriter,
|
|
2455 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2456 |
EOwnerProcess//TOwnerType aTypeW
|
|
2457 |
);
|
|
2458 |
test_KErrNone(ret);
|
|
2459 |
|
|
2460 |
|
|
2461 |
ret = RPipe::Create( aSize,
|
|
2462 |
aReader,
|
|
2463 |
aWriter,
|
|
2464 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2465 |
EOwnerProcess//TOwnerType aTypeW
|
|
2466 |
);
|
|
2467 |
|
|
2468 |
test (ret == KErrInUse);
|
|
2469 |
|
|
2470 |
aReader.Close();
|
|
2471 |
aWriter.Close();
|
|
2472 |
|
|
2473 |
|
|
2474 |
|
|
2475 |
test.Next(_L("PIPE TEST:1.4 Read/Write Function test : Check for Writing to pipe\n"));
|
|
2476 |
|
|
2477 |
aSize = 100;
|
|
2478 |
ret = RPipe::Create( aSize,
|
|
2479 |
aReader,
|
|
2480 |
aWriter,
|
|
2481 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2482 |
EOwnerProcess//TOwnerType aTypeW
|
|
2483 |
);
|
|
2484 |
test_KErrNone(ret);
|
|
2485 |
|
|
2486 |
ret=aWriter.Write(wData , wData.Size());
|
|
2487 |
test (ret == wData.Size() );
|
|
2488 |
|
|
2489 |
ret=aWriter.Write(wData , -1);
|
|
2490 |
test (ret == KErrArgument );
|
|
2491 |
|
|
2492 |
|
|
2493 |
test.Next(_L("PIPE TEST:1.5 Read/Write Function test : Check for Reading from pipe\n"));
|
|
2494 |
|
|
2495 |
|
|
2496 |
TBuf8<100> rData ;// Descriptor for reading data from Pipe.
|
|
2497 |
|
|
2498 |
ret=aReader.Read(rData,wData.Size()); // Length of the data to be read from Pipe
|
|
2499 |
test (ret == wData.Size());// Length of the data read from the Pipe
|
|
2500 |
|
|
2501 |
|
|
2502 |
test.Next(_L("PIPE TEST:1.6 Read/Write Function test : Validate data received\n"));
|
|
2503 |
|
|
2504 |
test (KErrNone == rData.Compare(wData));
|
|
2505 |
|
|
2506 |
|
|
2507 |
test.Next(_L("PIPE TEST:1.7 Read/Write Function test : Check for Reading from pipe\n"));
|
|
2508 |
|
|
2509 |
ret=aReader.Read(rData,1);
|
|
2510 |
test (ret == 0);
|
|
2511 |
{
|
|
2512 |
|
|
2513 |
|
|
2514 |
RPipe aReaderT, aWriterT;
|
|
2515 |
aSize = 20;
|
|
2516 |
ret = RPipe::Create( aSize,
|
|
2517 |
aReaderT,
|
|
2518 |
aWriterT,
|
|
2519 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2520 |
EOwnerProcess//TOwnerType aTypeW
|
|
2521 |
);
|
|
2522 |
test_KErrNone(ret);
|
|
2523 |
|
|
2524 |
ret=aWriterT.Write(wData ,15);
|
|
2525 |
test_Equal(15, ret);
|
|
2526 |
ret = aReaderT.Read(rData,10);
|
|
2527 |
test_Equal(10, ret);
|
|
2528 |
ret=aWriterT.Write(wData ,10);
|
|
2529 |
test_Equal(10, ret);
|
|
2530 |
ret = aReaderT.Read(rData,20);
|
|
2531 |
test (ret ==15);
|
|
2532 |
ret = aReaderT.Read(rData,5);
|
|
2533 |
test_Equal(0, ret);
|
|
2534 |
ret = aReaderT.Read(rData,25);
|
|
2535 |
test_Equal(0, ret);
|
|
2536 |
|
|
2537 |
aReaderT.Close();
|
|
2538 |
aWriterT.Close();
|
|
2539 |
|
|
2540 |
}
|
|
2541 |
|
|
2542 |
|
|
2543 |
test.Next(_L("PIPE TEST:1.8 Read/Write Function test : Check for Wrong RPipe Handle\n"));
|
|
2544 |
|
|
2545 |
|
|
2546 |
ret=aWriter.Read(rData,15 );// Length of the data to be read from Pipe
|
|
2547 |
test (ret == KErrAccessDenied );
|
|
2548 |
|
|
2549 |
test.Next(_L("PIPE TEST:1.9 Read/Write Function test : Check for Wrong RPipe Handle\n"));
|
|
2550 |
|
|
2551 |
ret=aReader.Write(rData,rData.Size());
|
|
2552 |
test (ret == KErrAccessDenied );
|
|
2553 |
|
|
2554 |
|
|
2555 |
test.Next(_L("PIPE TEST:1.10 Read/Write Function test : Check for write overflow\n"));
|
|
2556 |
|
|
2557 |
ret=aWriter.Write(wData,wData.Size());
|
|
2558 |
ret=aWriter.Write(wData,wData.Size());
|
|
2559 |
ret=aWriter.Write(wData,wData.Size());
|
|
2560 |
ret=aWriter.Write(wData,wData.Size());
|
|
2561 |
ret=aWriter.Write(wData,wData.Size());
|
|
2562 |
ret=aWriter.Write(wData,wData.Size());
|
|
2563 |
test (ret == KErrOverflow );
|
|
2564 |
|
|
2565 |
|
|
2566 |
|
|
2567 |
test.Next(_L("PIPE TEST:1.11 MaxSize Function test : MaxSize Check \n"));
|
|
2568 |
aSize = 10;
|
|
2569 |
// Just to be on safer side , close pipes if any.
|
|
2570 |
aReader.Close();
|
|
2571 |
aWriter.Close();
|
|
2572 |
|
|
2573 |
ret = RPipe::Create( aSize,
|
|
2574 |
aReader,
|
|
2575 |
aWriter,
|
|
2576 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2577 |
EOwnerProcess//TOwnerType aTypeW
|
|
2578 |
);
|
|
2579 |
test (ret == KErrNone); // This error condition is not defined yet.
|
|
2580 |
ret =aReader.MaxSize();
|
|
2581 |
test (ret == aSize);
|
|
2582 |
|
|
2583 |
|
|
2584 |
test.Next(_L("PIPE TEST:1.12 Size Function test : Size Check \n"));
|
|
2585 |
rData.Zero();
|
|
2586 |
|
|
2587 |
ret = aReader.Size();
|
|
2588 |
test_Equal(0, ret);
|
|
2589 |
|
|
2590 |
_LIT8(KSizeTestData1,"123456789");
|
|
2591 |
|
|
2592 |
ret = aWriter.Write(KSizeTestData1,9);
|
|
2593 |
test_Equal(9, ret);
|
|
2594 |
ret = aReader.Size();
|
|
2595 |
test_Equal(9, ret);
|
|
2596 |
|
|
2597 |
ret = aReader.Read(rData,1);
|
|
2598 |
test_Equal(1, ret);
|
|
2599 |
ret = rData.Compare(_L8("1"));
|
|
2600 |
test_KErrNone(ret);
|
|
2601 |
ret = aReader.Size();
|
|
2602 |
test_Equal(8, ret);
|
|
2603 |
|
|
2604 |
_LIT8(KSizeTestData2,"ab");
|
|
2605 |
ret = aWriter.Write(KSizeTestData2,2);
|
|
2606 |
test_Equal(2, ret);
|
|
2607 |
ret = aReader.Size();
|
|
2608 |
test_Equal(10, ret);
|
|
2609 |
|
|
2610 |
ret = aWriter.Write(KSizeTestData2,1);
|
|
2611 |
test_Equal(KErrOverflow, ret);
|
|
2612 |
ret = aReader.Size();
|
|
2613 |
test_Equal(10, ret);
|
|
2614 |
|
|
2615 |
ret = aReader.Read(rData,9);
|
|
2616 |
test_Equal(9, ret);
|
|
2617 |
ret = rData.Compare(_L8("23456789a"));
|
|
2618 |
test_KErrNone(ret);
|
|
2619 |
ret = aReader.Size();
|
|
2620 |
test_Equal(1, ret);
|
|
2621 |
|
|
2622 |
ret = aReader.Read(rData,1);
|
|
2623 |
test_Equal(1, ret);
|
|
2624 |
ret = rData.Compare(_L8("b"));
|
|
2625 |
test_KErrNone(ret);
|
|
2626 |
ret = aReader.Size();
|
|
2627 |
test_Equal(0, ret);
|
|
2628 |
|
|
2629 |
ret = aWriter.Size();
|
|
2630 |
test_Equal(0, ret);
|
|
2631 |
RPipe WrongPipeHandle;
|
|
2632 |
|
|
2633 |
ret = WrongPipeHandle.Size();
|
|
2634 |
test ( ret == KErrBadHandle);
|
|
2635 |
|
|
2636 |
test.Next(_L("PIPE TEST:1.13 Size Function test : Size Function call with Wrong handle \n"));
|
|
2637 |
|
|
2638 |
|
|
2639 |
|
|
2640 |
ret = WrongPipeHandle.MaxSize();
|
|
2641 |
test (ret == KErrBadHandle);
|
|
2642 |
|
|
2643 |
aReader.Close();
|
|
2644 |
aWriter.Close();
|
|
2645 |
aReader2.Close();
|
|
2646 |
aWriter2.Close();
|
|
2647 |
|
|
2648 |
test.Next(_L("PIPE TEST:1.14 Read Function : KErrNotReady \n"));
|
|
2649 |
aSize = 10;
|
|
2650 |
ret = RPipe::Create( aSize,
|
|
2651 |
aReader,
|
|
2652 |
aWriter,
|
|
2653 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2654 |
EOwnerProcess//TOwnerType aTypeW
|
|
2655 |
);
|
|
2656 |
test (ret == KErrNone); // This error condition is not defined yet.
|
|
2657 |
aWriter.Close();
|
|
2658 |
ret = aReader.Read(rData,aSize);
|
|
2659 |
test (ret == KErrNotReady);
|
|
2660 |
ret = aReader.Read(rData,110);
|
|
2661 |
test (ret == KErrArgument);
|
|
2662 |
|
|
2663 |
|
|
2664 |
test.Next(_L("PIPE TEST:1.15 Check Handle Type function \n"));
|
|
2665 |
aReader.Close();
|
|
2666 |
aWriter.Close();
|
|
2667 |
aSize = 10;
|
|
2668 |
ret = RPipe::Create( aSize,
|
|
2669 |
aReader,
|
|
2670 |
aWriter,
|
|
2671 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2672 |
EOwnerProcess//TOwnerType aTypeW
|
|
2673 |
);
|
|
2674 |
test_KErrNone(ret);
|
|
2675 |
|
|
2676 |
ret = aReader.HandleType();
|
|
2677 |
test (ret == RPipe::EReadChannel);
|
|
2678 |
|
|
2679 |
ret = aWriter.HandleType();
|
|
2680 |
test (ret == RPipe::EWriteChannel);
|
|
2681 |
|
|
2682 |
|
|
2683 |
aReader.Close();
|
|
2684 |
ret = aReader.HandleType();
|
|
2685 |
test (ret == KErrBadHandle);
|
|
2686 |
|
|
2687 |
test.Next(_L("PIPE TEST:1.16 Write Function : KErrNotReady \n"));
|
|
2688 |
aSize = 1;
|
|
2689 |
ret = aWriter.Write(wData,aSize);
|
|
2690 |
test (ret == KErrNotReady);
|
|
2691 |
|
|
2692 |
test.Next(_L("PIPE TEST:1.17 Write Function : Write data more than size of Descriptor \n"));
|
|
2693 |
ret = aWriter.Write(wData,110);
|
|
2694 |
test (ret == KErrArgument);
|
|
2695 |
|
|
2696 |
|
|
2697 |
test.Next(_L("PIPE TEST:1.18 Write Function : KErrCompletion \n"));
|
|
2698 |
aWriter.Close();
|
|
2699 |
ret = RPipe::Create( aSize,
|
|
2700 |
aReader,
|
|
2701 |
aWriter,
|
|
2702 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2703 |
EOwnerProcess//TOwnerType aTypeW
|
|
2704 |
);
|
|
2705 |
test_KErrNone(ret);
|
|
2706 |
ret = aWriter.Write(wData,wData.Size());
|
|
2707 |
test (ret == KErrOverflow);
|
|
2708 |
|
|
2709 |
test.Next(_L("PIPE TEST:1.19 Create Function : KErrInUse \n"));
|
|
2710 |
aReader.Close();
|
|
2711 |
ret = RPipe::Create( aSize,
|
|
2712 |
aReader,
|
|
2713 |
aWriter,
|
|
2714 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2715 |
EOwnerProcess//TOwnerType aTypeW
|
|
2716 |
);
|
|
2717 |
test (ret == KErrInUse);
|
|
2718 |
|
|
2719 |
aWriter.Close();
|
|
2720 |
ret = RPipe::Create( aSize,
|
|
2721 |
aReader,
|
|
2722 |
aWriter,
|
|
2723 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2724 |
EOwnerProcess//TOwnerType aTypeW
|
|
2725 |
);
|
|
2726 |
test (ret == KErrNone);
|
|
2727 |
aWriter.Close();
|
|
2728 |
ret = RPipe::Create( aSize,
|
|
2729 |
aReader,
|
|
2730 |
aWriter,
|
|
2731 |
EOwnerProcess,//TOwnerType aTypeW
|
|
2732 |
EOwnerProcess//TOwnerType aTypeW
|
|
2733 |
);
|
|
2734 |
test (ret == KErrInUse);
|
|
2735 |
|
|
2736 |
|
|
2737 |
|
|
2738 |
test.Next(_L("PIPE TEST:1.20 Read / Write using un opened handles \n"));
|
|
2739 |
RPipe aReaderT,aWriterT;
|
|
2740 |
|
|
2741 |
ret = aWriterT.Write(wData,wData.Size());
|
|
2742 |
test (ret == KErrBadHandle);
|
|
2743 |
ret = aReaderT.Read(rData,aSize);
|
|
2744 |
test (ret == KErrBadHandle);
|
|
2745 |
|
|
2746 |
|
|
2747 |
|
|
2748 |
|
|
2749 |
// Close all the pipes and return the resources.
|
|
2750 |
aReader.Close();
|
|
2751 |
aWriter.Close();
|
|
2752 |
aReader2.Close();
|
|
2753 |
aWriter2.Close();
|
|
2754 |
return;
|
|
2755 |
|
|
2756 |
} // End TestSingleThreadUnNamedPipes()
|
|
2757 |
|
|
2758 |
/****************************************************************************
|
|
2759 |
This is a function to test UnNamed pipes and named pipes in Single
|
|
2760 |
threaded environment.
|
|
2761 |
This test ensures that the memory is actually being released when:
|
|
2762 |
RPipe::Close() is called for unnamed pipes and
|
|
2763 |
RPipe::Destroy() is called for named pipes.
|
|
2764 |
******************************************************************************/
|
|
2765 |
void TestCreateClosePipe()
|
|
2766 |
{
|
|
2767 |
|
|
2768 |
//unnamed pipes
|
|
2769 |
RPipe readHandle, writeHandle;
|
|
2770 |
const TInt K3MB = 1024*1024*3;
|
|
2771 |
// The loop is run ten times to ensure that if memory allocated while pipe
|
|
2772 |
// creation is not deallocated by close,then creation of pipe will fail with
|
|
2773 |
// KErrNoMemory in the sixth iteration. Default heap size is assumed.
|
|
2774 |
TInt i;
|
|
2775 |
test.Next(_L("PIPE TEST:11.1 Create Function test in a loop : Check for No Error\n"));
|
|
2776 |
for(i=1; i<10; i++)
|
|
2777 |
{
|
|
2778 |
TInt r = RPipe::Create(K3MB, readHandle, writeHandle,EOwnerProcess, EOwnerProcess);
|
|
2779 |
test(KErrNone == r);
|
|
2780 |
readHandle.Close();
|
|
2781 |
writeHandle.Close();
|
|
2782 |
}
|
|
2783 |
|
|
2784 |
//named pipes
|
|
2785 |
_LIT(KPipeName, "testPipe");
|
|
2786 |
// The loop is run ten times to ensure that if memory allocated while pipe
|
|
2787 |
// creation is not deallocated by destroy,then creation of pipe will fail with
|
|
2788 |
// KErrNoMemory in the sixth iteration. Default heap size is assumed.
|
|
2789 |
test.Next(_L("PIPE TEST:11.2 Define Function test in a loop : Check for No Error\n"));
|
|
2790 |
for(i=1; i<10; i++)
|
|
2791 |
{
|
|
2792 |
TInt r = RPipe::Define(KPipeName,K3MB);
|
|
2793 |
test(KErrNone == r);
|
|
2794 |
r = RPipe::Destroy(KPipeName);
|
|
2795 |
test(KErrNone == r);
|
|
2796 |
}
|
|
2797 |
|
|
2798 |
}// End TestCreateClosePipe()
|
|
2799 |
|
|
2800 |
|
|
2801 |
struct TStressArgs
|
|
2802 |
{
|
|
2803 |
TStressArgs(TInt aIter, TInt aSize)
|
|
2804 |
:iIter(aIter), iSize(aSize)
|
|
2805 |
{}
|
|
2806 |
|
|
2807 |
const TInt iIter;
|
|
2808 |
const TInt iSize;
|
|
2809 |
};
|
|
2810 |
|
|
2811 |
struct TDefDesArgs: public TStressArgs
|
|
2812 |
{
|
|
2813 |
TDefDesArgs(TInt aIter, TInt aSize, const TDesC& aName)
|
|
2814 |
:TStressArgs(aIter,aSize), iName(aName)
|
|
2815 |
{}
|
|
2816 |
const TDesC& iName;
|
|
2817 |
};
|
|
2818 |
|
|
2819 |
/**
|
|
2820 |
Repeatedly define and destroy named pipe
|
|
2821 |
*/
|
|
2822 |
TInt DefineDestroy(TAny* aArgs)
|
|
2823 |
{
|
|
2824 |
const TDefDesArgs args = *static_cast<TDefDesArgs*>(aArgs);
|
|
2825 |
|
|
2826 |
for(TInt i=0; i<args.iIter; i++)
|
|
2827 |
{
|
|
2828 |
TInt r = RPipe::Define(args.iName, args.iSize);
|
|
2829 |
if(r!=KErrNone && r!=KErrAlreadyExists)
|
|
2830 |
{
|
|
2831 |
return r;
|
|
2832 |
}
|
|
2833 |
r = RPipe::Destroy(args.iName);
|
|
2834 |
if(r!=KErrNone && r!=KErrInUse && r!=KErrNotFound)
|
|
2835 |
{
|
|
2836 |
return r;
|
|
2837 |
}
|
|
2838 |
}
|
|
2839 |
return KErrNone;
|
|
2840 |
}
|
|
2841 |
|
|
2842 |
|
|
2843 |
/**
|
|
2844 |
The parent thread will try to repeatedly open and close a named pipe
|
|
2845 |
which is being repeatedly created and destroyed by the child thread.
|
|
2846 |
This attempts to catch race conditions.
|
|
2847 |
*/
|
|
2848 |
void TestRapidDefineDestroy()
|
|
2849 |
{
|
|
2850 |
const TInt iterations=1000;
|
|
2851 |
TDefDesArgs args(iterations, 16, KPipe1Name);
|
|
2852 |
|
|
2853 |
RPipe pipe;
|
|
2854 |
|
|
2855 |
TTestThread thread(_L("DefineDestroy"), DefineDestroy, &args);
|
|
2856 |
|
|
2857 |
TInt r=KErrNone;
|
|
2858 |
|
|
2859 |
for(TInt i=0; i<args.iIter; i++)
|
|
2860 |
{
|
|
2861 |
r = pipe.Open(args.iName, RPipe::EOpenToWrite);
|
|
2862 |
if(r!=KErrNone && r !=KErrNotFound)
|
|
2863 |
{
|
|
2864 |
test_KErrNone(r);
|
|
2865 |
}
|
|
2866 |
|
|
2867 |
pipe.Close();
|
|
2868 |
}
|
|
2869 |
r = thread.WaitForExitL();
|
|
2870 |
test_KErrNone(r);
|
|
2871 |
}
|
|
2872 |
|
|
2873 |
|
|
2874 |
/**
|
|
2875 |
Write the descriptor specified in to the pipe repeating
|
|
2876 |
as many times as specified by TData::iIterations
|
|
2877 |
*/
|
|
2878 |
TInt WriteThread(TAny* aData)
|
|
2879 |
{
|
|
2880 |
TData& data = *static_cast<TData*>(aData);
|
|
2881 |
|
|
2882 |
const TInt iter = data.iIterations;
|
|
2883 |
|
|
2884 |
TInt write=0;
|
|
2885 |
for(TInt i=0; i<iter; i++)
|
|
2886 |
{
|
|
2887 |
write = data.iWriteEnd->WriteBlocking(*data.iPipeData, data.iPipeData->Size());
|
|
2888 |
if(write <KErrNone)
|
|
2889 |
{
|
|
2890 |
return write;
|
|
2891 |
}
|
|
2892 |
}
|
|
2893 |
|
|
2894 |
return write*iter;
|
|
2895 |
}
|
|
2896 |
|
|
2897 |
/**
|
|
2898 |
Fill descriptor with random bytes
|
|
2899 |
*/
|
|
2900 |
void FillRandom(TDes8& aDes)
|
|
2901 |
{
|
|
2902 |
aDes.Zero();
|
|
2903 |
|
|
2904 |
while(aDes.Size()+4<=aDes.MaxSize())
|
|
2905 |
{
|
|
2906 |
TUint8 rand[4];
|
|
2907 |
*(TUint32*)rand = Math::Random();
|
|
2908 |
|
|
2909 |
aDes.Append(rand, 4);
|
|
2910 |
}
|
|
2911 |
}
|
|
2912 |
|
|
2913 |
/**
|
|
2914 |
@param aTotalBytes Bytes transfered in period
|
|
2915 |
@param aTicks number of ticks elapsed in period
|
|
2916 |
@return The rate of the transfer on kilobytes per second
|
|
2917 |
*/
|
|
2918 |
TReal KiloBytesPerSecond(TInt aTotalBytes, TInt aTicks)
|
|
2919 |
{
|
|
2920 |
TInt period=0; //period of nanotick in microseconds
|
|
2921 |
TInt r = HAL::Get(HAL::ENanoTickPeriod, period);
|
|
2922 |
User::LeaveIfError(r);
|
|
2923 |
|
|
2924 |
//we use the definition that a kilobytes is 1000 bytes
|
|
2925 |
TReal result = (aTotalBytes/(aTicks*period/1000));
|
|
2926 |
return result;
|
|
2927 |
}
|
|
2928 |
|
|
2929 |
|
|
2930 |
/**
|
|
2931 |
Create a source data buffer of aTotal bytes and fill with random data.
|
|
2932 |
Create a pipe and thread (WriteThread) to write the source buffer
|
|
2933 |
into the pipe.
|
|
2934 |
Read from the pipe into destination buffer
|
|
2935 |
and optionally verify that buffers match
|
|
2936 |
|
|
2937 |
@param aTotal Size of data buffer
|
|
2938 |
@param aPipeData Size of pipe to create
|
|
2939 |
@param aIter number of times to repeat transfer
|
|
2940 |
@param aVerify Confirm that destination buffer matches source buffer
|
|
2941 |
@param aPollRead read pipe by polling instead of using blocking read
|
|
2942 |
@return Total number of ticks elapsed
|
|
2943 |
*/
|
|
2944 |
TInt TestLoopBack(TInt aTotal, TInt aPipeSize, TInt aIter, TBool aVerify=ETrue, TBool aPollRead=EFalse)
|
|
2945 |
{
|
|
2946 |
const TInt bufferSize = aTotal;
|
|
2947 |
|
|
2948 |
RBuf8 sourceBuffer;
|
|
2949 |
sourceBuffer.CreateL(bufferSize);
|
|
2950 |
FillRandom(sourceBuffer);
|
|
2951 |
test_Equal(bufferSize,sourceBuffer.Size());
|
|
2952 |
|
|
2953 |
const TInt pipeSize=aPipeSize;
|
|
2954 |
|
|
2955 |
RPipe readEnd, writeEnd;
|
|
2956 |
TInt r = RPipe::Create(pipeSize, readEnd, writeEnd ,EOwnerProcess, EOwnerProcess);
|
|
2957 |
test_KErrNone(r);
|
|
2958 |
|
|
2959 |
|
|
2960 |
const TInt maxIter=aIter;
|
|
2961 |
TData data(NULL, &writeEnd, &sourceBuffer, maxIter);
|
|
2962 |
|
|
2963 |
|
|
2964 |
RBuf8 destBuffer;
|
|
2965 |
destBuffer.CreateL(bufferSize);
|
|
2966 |
|
|
2967 |
RBuf8 tempBuffer;
|
|
2968 |
tempBuffer.CreateL(bufferSize);
|
|
2969 |
|
|
2970 |
|
|
2971 |
TTestThread writer(_L("LoopBack"), WriteThread, &data);
|
|
2972 |
const TUint32 startTicks=User::NTickCount();
|
|
2973 |
|
|
2974 |
for(TInt iter=0; iter<maxIter; iter++)
|
|
2975 |
{
|
|
2976 |
TInt remainingData = bufferSize;
|
|
2977 |
do
|
|
2978 |
{
|
|
2979 |
const TInt toRead = Min(pipeSize,remainingData);
|
|
2980 |
if(aPollRead)
|
|
2981 |
{
|
|
2982 |
//an inefficient way to read a pipe!
|
|
2983 |
r = readEnd.Read(tempBuffer, toRead);
|
|
2984 |
test_NotNegative(r);
|
|
2985 |
}
|
|
2986 |
else
|
|
2987 |
{
|
|
2988 |
r = readEnd.ReadBlocking(tempBuffer, toRead );
|
|
2989 |
test_Equal(toRead, r);
|
|
2990 |
}
|
|
2991 |
destBuffer+=tempBuffer;
|
|
2992 |
tempBuffer.Zero();
|
|
2993 |
remainingData-=r;
|
|
2994 |
}
|
|
2995 |
while(remainingData);
|
|
2996 |
|
|
2997 |
if(aVerify)
|
|
2998 |
{
|
|
2999 |
r = sourceBuffer.Compare(destBuffer);
|
|
3000 |
test_KErrNone(r);
|
|
3001 |
}
|
|
3002 |
|
|
3003 |
destBuffer.Zero();
|
|
3004 |
}
|
|
3005 |
const TUint32 endTicks = User::NTickCount();
|
|
3006 |
|
|
3007 |
r = writer.WaitForExitL();
|
|
3008 |
test_Equal(bufferSize*maxIter, r);
|
|
3009 |
|
|
3010 |
const TUint32 ticksElapsed= endTicks - startTicks;
|
|
3011 |
|
|
3012 |
sourceBuffer.Close();
|
|
3013 |
tempBuffer.Close();
|
|
3014 |
destBuffer.Close();
|
|
3015 |
|
|
3016 |
readEnd.Close();
|
|
3017 |
writeEnd.Close();
|
|
3018 |
|
|
3019 |
return ticksElapsed;
|
|
3020 |
}
|
|
3021 |
|
|
3022 |
/**
|
|
3023 |
Simple test to confirm that data is reproduced after being fed through a pipe
|
|
3024 |
*/
|
|
3025 |
void TestTransferIntegrity()
|
|
3026 |
{
|
|
3027 |
|
|
3028 |
TestLoopBack(128*1024, 128, 1, ETrue);
|
|
3029 |
TestLoopBack(1024, 1, 1, ETrue);
|
|
3030 |
|
|
3031 |
//read by constantly polling
|
|
3032 |
TestLoopBack(128*1024, 1024, 1, ETrue, ETrue);
|
|
3033 |
}
|
|
3034 |
|
|
3035 |
|
|
3036 |
/**
|
|
3037 |
Enable Writeblocking and Readblocking notifications
|
|
3038 |
without actual reads and writes
|
|
3039 |
*/
|
|
3040 |
class RTestPipe: public RPipe
|
|
3041 |
{
|
|
3042 |
public:
|
|
3043 |
void RequestWriteBlocking(TInt aNumByte, TRequestStatus& aStatus)
|
|
3044 |
{
|
|
3045 |
DoRequest(EWriteBlocking, aStatus, &aNumByte);
|
|
3046 |
}
|
|
3047 |
|
|
3048 |
void RequestReadBlocking(TRequestStatus& aStatus)
|
|
3049 |
{
|
|
3050 |
DoRequest(EReadBlocking, aStatus);
|
|
3051 |
}
|
|
3052 |
};
|
|
3053 |
|
|
3054 |
|
|
3055 |
/**
|
|
3056 |
A test which will request some type of notification
|
|
3057 |
*/
|
|
3058 |
struct CNotificationTest : public TFunctor
|
|
3059 |
{
|
|
3060 |
CNotificationTest(RTestPipe& aPipe)
|
|
3061 |
:iPipe(aPipe)
|
|
3062 |
{
|
|
3063 |
TInt r = iParent.Open(iParent.Id());
|
|
3064 |
test_KErrNone(r);
|
|
3065 |
}
|
|
3066 |
|
|
3067 |
virtual ~CNotificationTest()
|
|
3068 |
{
|
|
3069 |
}
|
|
3070 |
|
|
3071 |
void operator()()
|
|
3072 |
{
|
|
3073 |
RunTest();
|
|
3074 |
|
|
3075 |
//set up rendezvous with parent
|
|
3076 |
iParent.Rendezvous(iRendezvousStatus);
|
|
3077 |
|
|
3078 |
//announce we have run test
|
|
3079 |
RThread::Rendezvous(KErrNone);
|
|
3080 |
|
|
3081 |
//wait untill parent has reached rendezvous
|
|
3082 |
User::WaitForRequest(iRendezvousStatus);
|
|
3083 |
}
|
|
3084 |
|
|
3085 |
virtual CNotificationTest* Clone()=0;
|
|
3086 |
|
|
3087 |
/**
|
|
3088 |
If necessary, gets pipe into correct state for the start of test
|
|
3089 |
*/
|
|
3090 |
virtual void PreparePipe() =0;
|
|
3091 |
virtual void RunTest() =0;
|
|
3092 |
|
|
3093 |
/**
|
|
3094 |
Cancel the notification
|
|
3095 |
*/
|
|
3096 |
virtual void Cancel() =0;
|
|
3097 |
|
|
3098 |
virtual TInt GetReturn()
|
|
3099 |
{
|
|
3100 |
return iStatus.Int();
|
|
3101 |
}
|
|
3102 |
|
|
3103 |
RTestPipe& iPipe;
|
|
3104 |
TRequestStatus iStatus;
|
|
3105 |
|
|
3106 |
TRequestStatus iRendezvousStatus;
|
|
3107 |
RThread iParent;
|
|
3108 |
};
|
|
3109 |
|
|
3110 |
|
|
3111 |
|
|
3112 |
/**
|
|
3113 |
Will request free space notification
|
|
3114 |
*/
|
|
3115 |
struct CSpaceNotificationTest : public CNotificationTest
|
|
3116 |
{
|
|
3117 |
typedef void (RTestPipe::*TSpaceNotification) (TInt, TRequestStatus&);
|
|
3118 |
|
|
3119 |
/**
|
|
3120 |
@param aPipe Pipe handle to use
|
|
3121 |
@param TSpaceNotification A pointer for the method to test
|
|
3122 |
@param aNumBytes Amount of space to request
|
|
3123 |
*/
|
|
3124 |
CSpaceNotificationTest(RTestPipe& aPipe, TSpaceNotification aFunc, TInt aNumBytes)
|
|
3125 |
:CNotificationTest(aPipe), iFn(aFunc), iNumBytes(aNumBytes)
|
|
3126 |
{}
|
|
3127 |
|
|
3128 |
CNotificationTest* Clone()
|
|
3129 |
{
|
|
3130 |
return new CSpaceNotificationTest(*this);
|
|
3131 |
}
|
|
3132 |
|
|
3133 |
void RunTest()
|
|
3134 |
{
|
|
3135 |
(iPipe.*iFn)(iNumBytes, iStatus);
|
|
3136 |
}
|
|
3137 |
|
|
3138 |
//Make sure space notification won't complete immediately
|
|
3139 |
void PreparePipe()
|
|
3140 |
{
|
|
3141 |
TInt freeSpace = iPipe.MaxSize() - iPipe.Size();
|
|
3142 |
if(freeSpace >= iNumBytes)
|
|
3143 |
{
|
|
3144 |
TInt r = iPipe.Write(KTestData, freeSpace);
|
|
3145 |
test_Equal(freeSpace, r);
|
|
3146 |
}
|
|
3147 |
}
|
|
3148 |
|
|
3149 |
void Cancel()
|
|
3150 |
{
|
|
3151 |
iPipe.CancelSpaceAvailable();
|
|
3152 |
};
|
|
3153 |
|
|
3154 |
TSpaceNotification iFn;
|
|
3155 |
TInt iNumBytes;
|
|
3156 |
};
|
|
3157 |
|
|
3158 |
struct CDataNotificationTest : public CNotificationTest
|
|
3159 |
{
|
|
3160 |
typedef void (RTestPipe::*TDataNotification) (TRequestStatus&);
|
|
3161 |
|
|
3162 |
CDataNotificationTest(RTestPipe& aPipe, TDataNotification aFunc)
|
|
3163 |
:CNotificationTest(aPipe), iFn(aFunc)
|
|
3164 |
{}
|
|
3165 |
|
|
3166 |
CNotificationTest* Clone()
|
|
3167 |
{
|
|
3168 |
return new CDataNotificationTest(*this);
|
|
3169 |
}
|
|
3170 |
|
|
3171 |
void RunTest()
|
|
3172 |
{
|
|
3173 |
(iPipe.*iFn)(iStatus);
|
|
3174 |
}
|
|
3175 |
|
|
3176 |
//make sure we start with an empty pipe
|
|
3177 |
void PreparePipe()
|
|
3178 |
{
|
|
3179 |
iPipe.Flush();
|
|
3180 |
}
|
|
3181 |
|
|
3182 |
void Cancel()
|
|
3183 |
{
|
|
3184 |
iPipe.CancelDataAvailable();
|
|
3185 |
};
|
|
3186 |
|
|
3187 |
TDataNotification iFn;
|
|
3188 |
};
|
|
3189 |
|
|
3190 |
|
|
3191 |
void ProcessNotificationTests(RPointerArray<CNotificationTest>& aArray)
|
|
3192 |
{
|
|
3193 |
const TInt count = aArray.Count();
|
|
3194 |
for(TInt i=0; i < count; i++)
|
|
3195 |
{
|
|
3196 |
for(TInt j=0; j < count; j++)
|
|
3197 |
{
|
|
3198 |
//need copies as objects contain request states
|
|
3199 |
CNotificationTest* testA = aArray[i]->Clone();
|
|
3200 |
test_NotNull(testA);
|
|
3201 |
CNotificationTest* testB = aArray[j]->Clone();
|
|
3202 |
test_NotNull(testB);
|
|
3203 |
|
|
3204 |
testA->PreparePipe(); testB->PreparePipe();
|
|
3205 |
|
|
3206 |
TTestThread a(_L("CNotificationTestA"), *testA, EFalse);
|
|
3207 |
TTestThread b(_L("CNotificationTestB"), *testB, EFalse);
|
|
3208 |
|
|
3209 |
TRequestStatus rendezvousA, rendezvousB;
|
|
3210 |
a.Rendezvous(rendezvousA);
|
|
3211 |
b.Rendezvous(rendezvousB);
|
|
3212 |
|
|
3213 |
a.Resume(); b.Resume();
|
|
3214 |
|
|
3215 |
//wait till after threads have made notification request.
|
|
3216 |
User::WaitForRequest(rendezvousA);
|
|
3217 |
User::WaitForRequest(rendezvousB);
|
|
3218 |
|
|
3219 |
TInt retA = testA->GetReturn(); TInt retB = testB->GetReturn();
|
|
3220 |
|
|
3221 |
//announce that we have read status requests, allowing
|
|
3222 |
//child threads to terminate
|
|
3223 |
RThread::Rendezvous(KErrNone);
|
|
3224 |
|
|
3225 |
a.WaitForExitL();
|
|
3226 |
b.WaitForExitL();
|
|
3227 |
|
|
3228 |
TBool oneRequestSupported = ((retA == KRequestPending) && (retB == KErrInUse))
|
|
3229 |
|| ((retB == KRequestPending) && (retA == KErrInUse));
|
|
3230 |
TBool bothSupported = (retA == KRequestPending) && (retB == KRequestPending);
|
|
3231 |
|
|
3232 |
if(!(oneRequestSupported || bothSupported))
|
|
3233 |
{
|
|
3234 |
test.Printf(_L("Failure: i=%d, j=%d"), i, j);
|
|
3235 |
test(EFalse);
|
|
3236 |
}
|
|
3237 |
|
|
3238 |
testA->Cancel(); testB->Cancel();
|
|
3239 |
delete testA;
|
|
3240 |
delete testB;
|
|
3241 |
}
|
|
3242 |
}
|
|
3243 |
}
|
|
3244 |
|
|
3245 |
/**
|
|
3246 |
Test abillity of pipe channels to handle multiple notification requests
|
|
3247 |
simultaneously.
|
|
3248 |
*/
|
|
3249 |
void TestNotifications()
|
|
3250 |
{
|
|
3251 |
RTestPipe readEnd, writeEnd;
|
|
3252 |
|
|
3253 |
TInt pipeSize = 5;
|
|
3254 |
TInt r = RPipe::Create(pipeSize, readEnd, writeEnd, EOwnerProcess, EOwnerProcess);
|
|
3255 |
test_KErrNone(r);
|
|
3256 |
|
|
3257 |
test.Next(_L("Test write end requests"));
|
|
3258 |
CSpaceNotificationTest writeBlocking(writeEnd, &RTestPipe::RequestWriteBlocking, pipeSize);
|
|
3259 |
CSpaceNotificationTest spaceAvailable(writeEnd, &RTestPipe::NotifySpaceAvailable, pipeSize);
|
|
3260 |
RPointerArray<CNotificationTest> writeEndTests;
|
|
3261 |
|
|
3262 |
writeEndTests.AppendL(&writeBlocking);
|
|
3263 |
writeEndTests.AppendL(&spaceAvailable);
|
|
3264 |
|
|
3265 |
for(TInt i=0; i<10; i++)
|
|
3266 |
{
|
|
3267 |
ProcessNotificationTests(writeEndTests);
|
|
3268 |
}
|
|
3269 |
writeEndTests.Close();
|
|
3270 |
|
|
3271 |
test.Next(_L("Test read end requests"));
|
|
3272 |
CDataNotificationTest readBlocking(readEnd, &RTestPipe::RequestReadBlocking);
|
|
3273 |
CDataNotificationTest dataAvailable(readEnd, &RTestPipe::NotifyDataAvailable);
|
|
3274 |
RPointerArray<CNotificationTest> readEndTests;
|
|
3275 |
|
|
3276 |
readEndTests.AppendL(&readBlocking);
|
|
3277 |
readEndTests.AppendL(&dataAvailable);
|
|
3278 |
|
|
3279 |
for(TInt j=0; j<10; j++)
|
|
3280 |
{
|
|
3281 |
ProcessNotificationTests(readEndTests);
|
|
3282 |
}
|
|
3283 |
|
|
3284 |
readEndTests.Close();
|
|
3285 |
|
|
3286 |
readEnd.Close();
|
|
3287 |
writeEnd.Close();
|
|
3288 |
}
|
|
3289 |
|
|
3290 |
LOCAL_C void RunTests(void)
|
|
3291 |
{
|
|
3292 |
// Test UnNamed Pipes in Single Thread
|
|
3293 |
test.Next(_L("PIPE TEST: 1.Un Named pipes in Single Thread\n"));
|
|
3294 |
TestSingleThreadUnNamedPipes();
|
|
3295 |
|
|
3296 |
// Test Named Pipes in Single Thread
|
|
3297 |
test.Next(_L("PIPE TEST: 2.Named pipes in Single Thread\n"));
|
|
3298 |
TestSingleThreadNamedPipes();
|
|
3299 |
|
|
3300 |
// Test UnNamed Pipes in MultiThread
|
|
3301 |
test.Next(_L("PIPE TEST: 3.Un Named pipes in Multi Thread\n"));
|
|
3302 |
TestMultiThreadUnNamedPipes();
|
|
3303 |
|
|
3304 |
// Test Named Pipes in MultiThread
|
|
3305 |
test.Next(_L("PIPE TEST: 4.Named pipes in Multi Thread\n"));
|
|
3306 |
TestMultiThreadNamedPipes();
|
|
3307 |
|
|
3308 |
// Test Named Pipes in Multi Process
|
|
3309 |
test.Next(_L("PIPE TEST: 5.Named pipes in Multi Process\n"));
|
|
3310 |
TestMultiProcessNamedPipes();
|
|
3311 |
|
|
3312 |
// Test Notify mechanism
|
|
3313 |
test.Next(_L("PIPE TEST: 6.Pipes Notify mechanism test\n"));
|
|
3314 |
TestNotifyMechanismPipes();
|
|
3315 |
|
|
3316 |
// Test Wait Mechanism
|
|
3317 |
test.Next(_L("PIPE TEST: 7.Pipes Wait mechanism test\n"));
|
|
3318 |
TestWaitMechanismPipes();
|
|
3319 |
|
|
3320 |
|
|
3321 |
// Test Pipes performance
|
|
3322 |
test.Next(_L("PIPE TEST: 8.Pipes Permission test\n"));
|
|
3323 |
TestPipesPermissionCheck ();
|
|
3324 |
|
|
3325 |
// Misc Pipe tests
|
|
3326 |
test.Next(_L("PIPE TEST: 9.Misc Pipe tests\n"));
|
|
3327 |
TestMiscPipes();
|
|
3328 |
|
|
3329 |
// Blocking and Notify method tests.
|
|
3330 |
test.Next(_L("PIPE TEST: 10.Blocking and Notification calls test\n"));
|
|
3331 |
TestBlockingAndNotify();
|
|
3332 |
|
|
3333 |
//Creation and closure of a large number of Pipes
|
|
3334 |
test.Next(_L("PIPE TEST: 11. Creation and subsequent closure of a large number of pipes\n"));
|
|
3335 |
TestCreateClosePipe();
|
|
3336 |
|
|
3337 |
test.Next(_L("Test concurrent notification requests"));
|
|
3338 |
TestNotifications();
|
|
3339 |
|
|
3340 |
test.Next(_L("Repeatedly open a named pipe whilst it's being created and destroyed"));
|
|
3341 |
TestRapidDefineDestroy();
|
|
3342 |
|
|
3343 |
test.Next(_L("Check integrity of data after transfer\n"));
|
|
3344 |
TestTransferIntegrity();
|
|
3345 |
|
|
3346 |
test.Next(_L("PIPE TEST: Ending test.\n"));
|
|
3347 |
return;
|
|
3348 |
}
|
|
3349 |
|
|
3350 |
TInt ParseCommandLine()
|
|
3351 |
{
|
|
3352 |
TBuf<20> cmdLine;
|
|
3353 |
//TInt r= cmdLine.Create(User::CommandLineLength());
|
|
3354 |
//test_KErrNone(r);
|
|
3355 |
User::CommandLine(cmdLine);
|
|
3356 |
TLex lex(cmdLine);
|
|
3357 |
|
|
3358 |
TPtrC token=lex.NextToken();
|
|
3359 |
if(token.Length()>0)
|
|
3360 |
{
|
|
3361 |
TInt os=token.Match(_L("-n*"));
|
|
3362 |
if(os==0)
|
|
3363 |
{
|
|
3364 |
if(token.Length()>2)
|
|
3365 |
lex.SkipAndMark(2-lex.TokenLength()); //set mark backwards to after the "-n"
|
|
3366 |
token.Set(lex.NextToken());
|
|
3367 |
if(token.Length()==0)
|
|
3368 |
return KErrArgument;
|
|
3369 |
|
|
3370 |
TLex valLex(token);
|
|
3371 |
TInt value;
|
|
3372 |
TInt r=valLex.Val(value);
|
|
3373 |
if(r<0)
|
|
3374 |
return r;
|
|
3375 |
else
|
|
3376 |
return value;
|
|
3377 |
}
|
|
3378 |
else
|
|
3379 |
{
|
|
3380 |
return KErrArgument;
|
|
3381 |
}
|
|
3382 |
}
|
|
3383 |
else
|
|
3384 |
{
|
|
3385 |
const TInt KDefaultRuns=1;
|
|
3386 |
return KDefaultRuns;
|
|
3387 |
}
|
|
3388 |
}
|
|
3389 |
|
|
3390 |
GLDEF_C TInt E32Main()
|
|
3391 |
// Main entry point for the test.
|
|
3392 |
{
|
|
3393 |
__UHEAP_MARK;
|
|
3394 |
TInt ret = 0;
|
|
3395 |
|
|
3396 |
test.Start(_L("PIPE TEST: Testing"));
|
|
3397 |
ret = RPipe::Init();
|
|
3398 |
if ( ret != KErrNone && ret != KErrAlreadyExists)
|
|
3399 |
{
|
|
3400 |
test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
|
|
3401 |
return KErrNone;
|
|
3402 |
}
|
|
3403 |
TName pddName(RPipe::Name());
|
|
3404 |
ret = RPipe::Define (KPipe1Name,10);
|
|
3405 |
test_KErrNone(ret);
|
|
3406 |
|
|
3407 |
User::FreeLogicalDevice(pddName);
|
|
3408 |
ret = RPipe::Define (KPipe1Name,10);
|
|
3409 |
test_Equal(KErrNotFound, ret);
|
|
3410 |
|
|
3411 |
ret = RPipe::Init();
|
|
3412 |
if ( ret != KErrNone && ret != KErrAlreadyExists)
|
|
3413 |
{
|
|
3414 |
test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
|
|
3415 |
return KErrNone;
|
|
3416 |
}
|
|
3417 |
|
|
3418 |
|
|
3419 |
TInt runs=ParseCommandLine();
|
|
3420 |
if(runs>=0)
|
|
3421 |
{
|
|
3422 |
TBool forever=(runs==0);
|
|
3423 |
for(TInt i=0; forever||(i<runs); ++i)
|
|
3424 |
{
|
|
3425 |
if(i!=0)
|
|
3426 |
test.Next(_L("Next iteration"));
|
|
3427 |
|
|
3428 |
test.Start(_L("Starting Run")); //sub nest each test iteration
|
|
3429 |
__UHEAP_MARK;
|
|
3430 |
TRAP(ret, RunTests());
|
|
3431 |
test_KErrNone(ret);
|
|
3432 |
__UHEAP_MARKEND;
|
|
3433 |
test.End();
|
|
3434 |
}
|
|
3435 |
}
|
|
3436 |
else
|
|
3437 |
{
|
|
3438 |
test.Printf(_L("Usage: t_pipe -n N\n N is number of runs to do. If N=0 run forever"));
|
|
3439 |
}
|
|
3440 |
|
|
3441 |
TName pddName2(RPipe::Name());
|
|
3442 |
ret= User::FreeLogicalDevice(pddName2);
|
|
3443 |
test_KErrNone(ret);
|
|
3444 |
test.End();
|
|
3445 |
test.Close();
|
|
3446 |
__UHEAP_MARKEND;
|
|
3447 |
return KErrNone;
|
|
3448 |
}
|
|
3449 |
|
|
3450 |
|