First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pipe\t_pipe.cpp
16 // Test pipe mechanism
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:
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:
41 @STMTestCaseID KBASE-T_PIPE-0217
45 @SYMTestCaseDesc Pipe functional tests
47 @SYMTestActions Tests the functionality of the pipe. Success and failure tests are performed.
48 @SYMTestExpectedResults Test should pass
51 #define __E32TEST_EXTENSION__
55 #include <e32des8_private.h>
57 #include <e32cmn_private.h>
63 LOCAL_D RTest test(_L("t_pipe"));
66 //if the test is to run under the debugger, uncomment the following line
70 const TInt KHeapSize=0x2000;
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");
82 _LIT(KPipe1Name,"TestPipe1");
83 _LIT(KPipe3Name,"TestPipe3");
85 //Global semaphore name
86 _LIT(KSemaphoreName,"Semaphore1");
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");
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");
104 // Test Process Name Constants
105 _LIT(KProcessName, "t_pipe2.exe");
108 // Following class is used to pass thread handle information to different threads.
112 TData(RPipe* aReadEnd, RPipe *aWriteEnd);
113 TData(RPipe* aReadEnd, RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations=1);
116 const TDesC8* iPipeData;
120 TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd)
121 :iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(NULL), iIterations(NULL)
124 TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations)
125 :iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(aPipeData), iIterations(aIterations)
129 A utility class for running functions in other threads/processes
134 virtual TInt WaitForExitL()=0;
135 virtual ~TTestRemote()
138 virtual void Rendezvous(TRequestStatus& aStatus) =0;
144 static TInt RunFunctor(TAny* aFunctor)
146 TFunctor& functor = *(TFunctor*)aFunctor;
151 TRequestStatus iLogonStatus;
154 TInt TTestRemote::iCount=0;
156 class TTestThread : public TTestRemote
159 TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue)
161 Init(aName, aFn, aData, aAutoResume);
165 Run aFunctor in another thread
167 TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue)
169 Init(aName, RunFunctor, &aFunctor, aAutoResume);
174 //RTest::CloseHandleAndWaitForDestruction(iThread);
184 If thread exited normally, return its return code
185 Otherwise, leave with exit reason
187 virtual TInt WaitForExitL()
189 User::WaitForRequest(iLogonStatus);
190 const TInt exitType = iThread.ExitType();
191 const TInt exitReason = iThread.ExitReason();
193 __ASSERT_ALWAYS(exitType != EExitPending, User::Panic(_L("TTestThread"),0));
195 if(exitType != EExitKill)
196 User::Leave(exitReason);
201 virtual void Rendezvous(TRequestStatus& aStatus)
203 iThread.Rendezvous(aStatus);
207 void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume)
210 name.AppendFormat(_L("-%d"), iCount++);
211 TInt r=iThread.Create(name, aFn, KDefaultStackSize, KHeapSize, KHeapSize, aData);
212 User::LeaveIfError(r);
214 iThread.Logon(iLogonStatus);
215 __ASSERT_ALWAYS(iLogonStatus == KRequestPending, User::Panic(_L("TTestThread"),0));
228 Non blocking reads, verifying data as expected
230 TInt TestThread2(TAny* aData)
232 RTest test(_L("t_pipe_t2"));
234 test.Start(_L("Thread 2"));
235 test.Printf(_L("THREAD 2 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
237 TBuf8<50> cPipeReadData;
242 TData& data = *(TData *)aData; // aData will have pipe handles and size.
245 test.Next(_L("PIPE TEST:Thread 2-1 Read 1 byte of data from the pipe : Test for success\n"));
248 ret = data.iReadEnd->Read(cPipeReadData ,readsize);
249 test_Equal(readsize, ret);
252 test.Next(_L("PIPE TEST:Thread 2-2 Validate 1 byte received is correct\n"));
253 ret = cPipeReadData.Compare(KTestData1);
257 test.Next(_L("PIPE TEST:Thread 2-3 Read remaining data from the pipe\n"));
259 ret = data.iReadEnd->Read(cPipeReadData , readsize);
260 test_Equal(readsize, ret);
262 test.Next(_L("PIPE TEST:Thread 2-4 Validate received data\n"));
263 ret = cPipeReadData.Compare(KTestData3);
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.
280 ******************************************************************************/
281 TInt TestThread3(TAny* aData) {
284 TInt ret, aWriteSize;
286 TBufC8<50> cTestData3(KTestData2); // Test Data
290 TData& data = *(TData *)aData; // aData will have pipe handles and size.
291 RTest test(_L("t_pipe_t3"));
293 test.Start(_L("Thread 3"));
295 test.Printf(_L(" THREAD 3 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
297 test.Next(_L("PIPE TEST:Thread 3-1 Call Write blocking and write data\n"));
299 // Call Writeblocking function. Write one byte of data.
301 aWriteSize = cTestData3.Length();
302 ret = data.iWriteEnd->WriteBlocking(cTestData3,aWriteSize);
303 test_Equal(aWriteSize, ret);
305 // Call Writeblocking function. Write aSize bye data.
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);
316 /****************************************************************************
317 This function is used as thread to test Unnamed pipes.
318 TestMultiThreadUnNamedPipes() will use this function.
320 @aData : Used to pass the pipe and handle its size information.
324 ******************************************************************************/
325 //TRequestStatus stat1;
326 TInt TestThread4(TAny* aData) {
328 TData& data = *(TData *)aData; // aData will have pipe handles and size.
329 TRequestStatus stat1;
330 TBuf8<150> cPipeReadData;
332 RTest test(_L("t_pipe_t4"));
333 test.Start(_L("Thread 4"));
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);
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
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);
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);
356 test.Next(_L("PIPE TEST:Thread 4-4 Verify data is correct ?.\n"));
357 test (KErrNone == cPipeReadData.Compare(KTestData1));
359 test.Next(_L("PIPE TEST:Thread 4-5 Read remaining data from the pipe.\n"));
360 ret = data.iReadEnd->Read(cPipeReadData,21);
364 test.Next(_L("PIPE TEST:Thread 4-6 Verify data is correct ?.\n"));
365 test (KErrNone == cPipeReadData.Compare(KTestData3));
367 sem.Signal(); //signalling to the main thread to continue its operation
368 sem.Close(); //closing the handle to the semaphore
376 /****************************************************************************
377 This function is used as thread to test Unnamed pipes.
378 TestWaitMechanismPipes() will use this function.
380 @aData : Used to pass the pipe and handle its size information.
384 ******************************************************************************/
386 TInt TestThread5(TAny* aData) {
388 TData& data = *(TData *)aData; // aData will have pipe handles and size.
389 TRequestStatus stat1;
392 RTest test(_L("t_pipe_t5"));
394 test.Start(_L("Thread 5"));
395 test.Printf(_L("PIPE TEST:Thread 5:Created by TestWaitMechanismPipes.\n"));
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);
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);
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
418 TInt ReaderThread(TAny* aData) {
419 // Read data from Pipe
420 RTest test(KReaderThread);
422 test.Start(_L("Reader Thread"));
424 TData& data = *(TData *)aData;
425 TBuf8<10> pipeReadData;
427 const TInt sizeToRead = data.iReadEnd->MaxSize(); //attempt to read everything from pipe
428 TRequestStatus status(KErrGeneral);
430 //do read in loop in case thread is notified before pipe is full
431 TInt totalDataRead=0;
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());
441 const TInt sizeRead = data.iReadEnd->Read(pipeReadData, sizeToRead);
442 test.Printf(_L("Read %d bytes from pipe\n"), sizeRead);
444 totalDataRead+=sizeRead;
446 while(totalDataRead<sizeToRead);
448 test(totalDataRead==sizeToRead);
455 _LIT8(KTestDataNum1 , "12345");
456 _LIT8(KTestDataNum , "1234567890");
461 Write into pipe to completely fill it.
463 TInt WriterThread(TAny* aData)
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);
480 The FlusherThread waits till the supplied pipe
481 is full before flushing it.
483 TInt FlusherThread(TAny* aData)
485 TData& data = *(TData *)aData; // aData will have pipe handles and size.
487 //wait for pipe to fill, then flush
488 TRequestStatus status;
489 const TInt maxSize=data.iReadEnd->MaxSize();
492 data.iReadEnd->NotifyDataAvailable(status);
493 if(status==KRequestPending)
494 User::WaitForRequest(status);
497 } while(data.iReadEnd->Size()<maxSize);
498 data.iReadEnd->Flush();
502 /****************************************************************************
503 This function is used as thread to test Unnamed pipes.
504 TestWaitMechanismPipes() will use this function.
506 @aData : Used to pass the pipe and handle its size information.
510 ******************************************************************************/
513 TInt TestThread9(TAny* aData) {
515 TData& data = *(TData *)aData; // aData will have pipe handles and size.
518 data.iReadEnd->Close();
520 data.iWriteEnd->Close();
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
531 TInt ReadBlockThenWrite(TAny* aData) {
533 TData& data = *(TData *)aData; // aData will have pipe handles and size.
535 RTest test(_L("Concurrent blocking read"));
536 test.Start(_L("Call blocking read on pipe\n"));
538 TInt ret = data.iReadEnd->ReadBlocking(cReadData,5);
541 test_KErrNone(cReadData.Compare(KTestDataNum1));
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);
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
562 TInt WriteBlockThenRead(TAny* aData) {
564 TData& data = *(TData *)aData; // aData will have pipe handles and size.
566 RTest test(_L("Concurrent blocking write"));
567 test.Start(_L("test writing blocked pipe\n"));
569 TInt ret = data.iWriteEnd->WriteBlocking(KTestDataNum,10);
572 test.Next(_L("The other thread beat us - read from pipe so it may proceed"));
573 TInt read = data.iReadEnd->Read(cReadData,5);
575 test_KErrNone(cReadData.Compare(KTestDataNum1));
584 /****************************************************************************
585 This function is used as thread to test Unnamed pipes.
586 TestWaitMechanismPipes() will use this function.
588 @aData : Used to pass the pipe and handle its size information.
592 ******************************************************************************/
594 TInt TestThread11(TAny* aData) {
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.
600 RTest test(_L("t_pipe_t11"));
602 test.Start(_L("PIPE TEST:Thread 11:Created by TestWaitMechanismPipes.\n"));
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());
609 test.Next(_L("PIPE TEST:Thread 11-2:Open Pipe handle to write.\n"));
610 ret = data.iWriteEnd->Open(cPipeName,RPipe::EOpenToWrite);
618 /****************************************************************************
619 This is a function to test Named/UnNamed pipes Performace.
620 Check the functionality of following library functions
626 ******************************************************************************/
628 - test that WriteBlocking unblocks
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
636 void TestBlockingAndNotify() {
638 TRequestStatus stat1;
639 RPipe aReader,aWriter;
641 TBufC8<10> cPipeTestDataNum(KTestDataNum);
647 ret = RPipe::Create( aSize,
655 TData data( &aReader, &aWriter);
658 TTestThread readerThread(KReaderThread, ReaderThread, &data);
660 test.Start(_L("Test that WriteBlock unblocks as data is read from pipe\n"));
661 ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
663 test(aWriter.Size()==5);
665 test(aWriter.Size()==0);
667 ret = readerThread.WaitForExitL();
672 TTestThread flusherThread(KThread8Name, FlusherThread, &data);
673 test.Next(_L("Test that WriteBlock unblocks as data is flushed from read end of pipe\n"));
675 ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
677 ret = flusherThread.WaitForExitL();
681 test.Next(_L("Test that NotifyDataAvailable request is completed as data is read from pipe\n"));
683 aWriter.NotifySpaceAvailable(aSize,stat1);
684 test(stat1==KRequestPending);
687 TTestThread readerThread2(KReaderThread, ReaderThread, &data);
689 User::WaitForRequest(stat1);
690 test(stat1==KErrNone);
692 ret = readerThread2.WaitForExitL();
698 test.Next(_L("PIPE TEST: Test that ReadBlocking unblocks\n"));
700 TTestThread writeThread(KWriterThread, WriterThread, &data);
702 ret = aReader.ReadBlocking(cReadData,5);
705 ret = writeThread.WaitForExitL();
709 test.Next(_L("PIPE TEST: Test NotifyDataAvailable\n"));
711 aReader.NotifyDataAvailable(stat1);
712 test(stat1==KRequestPending);
715 TTestThread writeThread2(KWriterThread,WriterThread, &data);
717 User::WaitForRequest(stat1);
718 test(stat1==KErrNone);
722 ret = writeThread2.WaitForExitL();
725 test.Next(_L("PIPE TEST: Test reading from pipe closed by the writer\n"));
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);
732 ret = closeThread.WaitForExitL();
735 ret = aReader.ReadBlocking(cReadData,5);
736 test_Equal(KErrNotReady, ret);
741 ret = RPipe::Create( aSize,
749 TData data1(&aReader,&aWriter);
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);
759 ret = closeThread2.WaitForExitL();
769 /****************************************************************************
770 TestPipesPermissionCheck :
771 This function is used to test Permission and Access related
773 APIs tested are Define , Create , Destroy , Read and Write.
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");
786 // Different processes with different capability , VID values.
787 _LIT(KProcessNoCap, "t_pipe3.exe");
788 _LIT(KProcessRCap, "t_pipe5.exe");
791 _LIT_VENDOR_ID(MyVID,0x70000001);
793 void TestPipesPermissionCheck() {
798 // Define TSecurity objects with different capabilities and VID .
799 TSecurityPolicy NoCapVID(MyVID,ECapability_None,ECapability_None,ECapability_None);
800 TSecurityPolicy RWCap(ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
801 TSecurityPolicy ComDDCap(ECapabilityCommDD);
802 TSecurityPolicy RWComDDCap(ECapabilityReadDeviceData,ECapabilityCommDD,ECapabilityWriteDeviceData);
803 TSecurityPolicy RWComDDCapVID(MyVID,ECapabilityCommDD,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
804 TSecurityPolicy RWRUCap(ECapabilityReadUserData,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
806 // Define Named pipes with No Cap , combination of Cap and VID
809 ret = RPipe::Define(KPipeName2, aSize);
810 test (ret == KErrNone);
811 ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
812 test (ret == KErrNone);
813 ret = RPipe::Define(KPipeName4, aSize,RWCap);
814 test (ret == KErrNone);
815 ret = RPipe::Define(KPipeName5, aSize,ComDDCap);
816 test (ret == KErrNone);
817 ret = RPipe::Define(KPipeName6, aSize,RWComDDCap);
818 test (ret == KErrNone);
819 ret = RPipe::Define(KPipeName7, aSize,RWComDDCapVID);
820 test (ret == KErrNone);
821 ret = RPipe::Define(KPipeName8, aSize,RWRUCap);
822 test (ret == KErrNone);
824 //Lets see who can use pipes. Check for Permissions and Access
825 test.Next(_L("PIPE TEST:8.1 Create Process with No Cap t_pipe3.exe\n"));
827 KProcessNoCap, // Launch t_pipe3.exe process
828 KNullDesC // No arguments passed to t_pipe3.exe
833 test.Printf(_L(" ***** t_pipe3.exe could not start ****"));
836 test.Printf(_L("Process Created successfully"));
838 TRequestStatus procLogon;
839 proc.Logon(procLogon);
840 test(procLogon==KRequestPending);
842 User::WaitForRequest(procLogon);
845 // Lets see what happens with Read Capability.
846 test.Next(_L("PIPE TEST:8.2 Create Process with Read-Write-CommDD Cap t_pipe5.exe\n"));
847 ret = RPipe::Define(KPipeName2, aSize);
849 ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
853 KProcessRCap, // Launch t_pipe3.exe process
854 KNullDesC // No arguments passed to t_pipe3.exe
859 test.Printf(_L(" ***** t_pipe5.exe could not start ****"));
862 test.Printf(_L("Process Created successfully"));
863 proc.Logon(procLogon);
864 test(procLogon==KRequestPending);
866 User::WaitForRequest(procLogon);
869 //the t_pipe5.exe process should destroy most of these
870 //but we call destroy again to verify this
871 ret = RPipe::Destroy (KPipeName2);
872 test_Equal(KErrNotFound, ret);
873 ret = RPipe::Destroy (KPipeName3);
874 test_KErrNone(ret); //KPipeName3 is not destroyed by the other process.
875 ret = RPipe::Destroy (KPipeName4);
876 test_Equal(KErrNotFound, ret);
877 ret = RPipe::Destroy (KPipeName5);
878 test_Equal(KErrNotFound, ret);
879 ret = RPipe::Destroy (KPipeName6);
880 test_Equal(KErrNotFound, ret);
881 ret = RPipe::Destroy (KPipeName7);
882 test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
883 ret = RPipe::Destroy (KPipeName8);
884 test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
892 /****************************************************************************
895 This is a function to test Named/UnNamed pipes for all Misc test cases.
898 ******************************************************************************/
900 void TestMiscPipes() {
902 _LIT(KInvalidPipeName,"PipeNotExist");
904 RPipe aReader,aWriter;
905 TBufC<50> cPipeName(KInvalidPipeName); // Descriptor to hold data for Writing.
906 TBufC8<50> cPipeTestData2(KTestData2);
909 // Try to create unnamed pipe with Negative size
910 test.Next(_L("PIPE TEST:9.1 Create Pipe of Negative Size.\n"));
912 ret = RPipe::Create( aSize,
918 test( ret == KErrArgument);
921 // Try to create unnamed pipe with zero size
922 test.Next(_L("PIPE TEST:9.2 Create Pipe with of Zero size.\n"));
924 ret = RPipe::Create( aSize,
930 test( ret == KErrArgument);
933 // Try to define named pipe with Negative size
934 test.Next(_L("PIPE TEST:9.3 Define Pipe of Negative size.\n"));
936 ret = RPipe::Define(cPipeName, aSize);
937 test( ret == KErrArgument);
941 // Try to define named pipe with Zero size
942 test.Next(_L("PIPE TEST:9.4 Define Pipe of Zero size.\n"));
944 ret = RPipe::Define(cPipeName, aSize);
945 test( ret == KErrArgument);
948 // Try to destroy pipe which does not exists
949 test.Next(_L("PIPE TEST:9.5 Try to destroy named pipe which do not exist.\n"));
950 ret = RPipe::Destroy (cPipeName);
951 test (ret == KErrNotFound);
954 // Try to read from pipe with invalid length data to be read
955 RPipe aReaderUN,aWriterUN;
956 TBuf8<150> cPipeReadData;
958 ret = RPipe::Create( aSize,
964 test (ret == KErrNone );
967 test.Next(_L("PIPE TEST:9.6 Try calling ReadBlocking using write handle and WriteBlocking using Read handle.\n"));
968 ret = aWriterUN.ReadBlocking(cPipeReadData, aSize);
969 test (ret == KErrAccessDenied);
970 ret = aReaderUN.WriteBlocking(cPipeTestData2,aSize);
971 test (ret == KErrAccessDenied);
976 test.Next(_L("PIPE TEST:9.7 Read negative size data from un-named pipe.\n"));
978 ret = aReaderUN.Read(cPipeReadData, aSize);
979 test( ret == KErrArgument);
980 ret = aWriterUN.Write(cPipeTestData2,aSize);
981 test( ret == KErrArgument);
985 test.Next(_L("PIPE TEST:9.8 Read/Write zero size data from/to un-named pipe\n"));
987 ret = aReaderUN.Read(cPipeReadData, aSize);
988 test( ret == KErrNone);
990 ret = aWriterUN.Write(cPipeTestData2,aSize);
991 test( ret == KErrNone);
994 test.Next(_L("PIPE TEST:9.9 Call ReadBlocking and WriteBlocking to Read and Write negative size data.\n"));
995 // Try to readblocking from pipe with invalid length data to be read
997 ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
998 test( ret == KErrArgument);
999 ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
1000 test( ret == KErrArgument);
1002 test.Next(_L("PIPE TEST:9.10 ReadBlocking/WriteBlocking to read/write zero size data.\n"));
1004 ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
1005 test( ret == KErrArgument);
1006 ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
1007 test( ret == KErrArgument);
1010 test.Next(_L("PIPE TEST:9.11 Try calling ReadBlocking and WriteBlocking using un opened RPipe handles.\n"));
1011 RPipe aReaderT,aWriterT;
1012 ret = aReaderT.ReadBlocking(cPipeReadData, aSize);
1013 test (ret == KErrBadHandle);
1014 ret = aWriterT.WriteBlocking(cPipeTestData2,aSize);
1015 test (ret == KErrBadHandle);
1023 /****************************************************************************
1024 This is a function to test notify mechanism of pipes.
1025 Check the functionality of following library functions
1029 ******************************************************************************/
1030 void TestWaitMechanismPipes() {
1032 RPipe aReader,aWriter; // Used to pass to thread.
1035 TBufC<50> cPipeName(KPipe3Name); // Descriptor to hold data for Writing.
1037 TRequestStatus stat1;
1039 aSize = 22 * 10; // Sizeof(KTestData) * 10
1041 ret = RPipe::Define( cPipeName,aSize);
1042 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1043 test (ret == KErrNone);
1047 test.Next(_L("PIPE TEST:7.1 Try calling Wait function on BadPipe name.\n"));
1049 _LIT(KBadPipeName , "***R$@#$@#%#$%#^.12-.");
1050 aWriter.Wait(KBadPipeName,stat1);
1051 test(stat1.Int() == KErrBadName);
1052 aWriter.WaitForReader(KBadPipeName,stat1);
1053 test(stat1.Int() == KErrBadName);
1056 _LIT(KBadPipeName2 , "");
1057 aWriter.Wait(KBadPipeName2,stat1);
1058 test(stat1.Int() == KErrBadName);
1059 aWriter.WaitForReader(KBadPipeName2,stat1);
1060 test(stat1.Int() == KErrBadName);
1064 test.Next(_L("PIPE TEST:7.2 Try calling Wait function on non existing Pipe\n"));
1065 _LIT(KInvalidPipe , "NotExistingPipe");
1066 aWriter.Wait(KInvalidPipe,stat1);
1067 test(stat1.Int() == KErrNotFound);
1068 aWriter.WaitForReader(KInvalidPipe,stat1);
1069 test(stat1.Int() == KErrNotFound);
1072 test.Next(_L("PIPE TEST:7.3 Try calling Wait function on Pipe name length more than maxlength.\n"));
1073 aWriter.Wait(KMaxPipeNamePlusOne,stat1);
1074 test(stat1.Int() == KErrBadName);
1075 aWriter.WaitForReader(KMaxPipeNamePlusOne,stat1);
1076 test(stat1.Int() == KErrBadName);
1079 test.Next(_L("PIPE TEST:7.4 Try calling Wait function from unopened handle.\n"));
1080 aWriter2.Wait(cPipeName, stat1);
1081 test (stat1.Int() == KErrInUse);
1082 aWriter2.WaitForReader(cPipeName, stat1);
1083 test (stat1.Int() == KErrInUse);
1086 test.Next(_L("PIPE TEST:7.5 Register a valid Wait Request .\n"));
1087 aWriter.Wait(cPipeName, stat1);
1089 TData data( &aReader, &aWriter);
1092 // Pass TData object with Write and Read handle both
1093 TTestThread thread5(KThread5Name, TestThread5, &data);
1094 User::WaitForRequest(stat1);
1096 ret = thread5.WaitForExitL();
1099 test.Next(_L("PIPE TEST:7.6 After Wait finish check the value of status register.\n"));
1100 test_KErrNone(stat1.Int());
1103 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1105 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1108 test.Next(_L("PIPE TEST:7.7 After Read handle is open , register request to Wait\n"));
1110 aWriter.Wait(cPipeName, stat1);
1111 test (stat1.Int() == KErrNone);
1113 test.Next(_L("PIPE TEST:7.8 Check for CancelWait.\n"));
1116 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1117 TRequestStatus stat2;
1118 aWriter.Wait(cPipeName, stat1);
1119 aWriter.Wait(cPipeName, stat2);
1120 test(stat2.Int() == KErrInUse);
1121 aWriter.CancelWait();
1122 test(stat1.Int() == KErrCancel);
1123 test(stat2.Int() == KErrInUse);
1124 aWriter.Wait(cPipeName, stat1);
1125 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1126 test(stat1.Int() == KErrNone);
1128 test.Next(_L("PIPE TEST:7.9 Check Wait and CancelWait from reader end\n"));
1131 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1132 aReader.Wait(cPipeName, stat1);
1133 test (stat1.Int() == KErrAccessDenied);
1134 aReader.CancelWait();
1139 RPipe::Destroy(cPipeName);
1141 /*****************Newly added tests for CR 1114 - WaitForReader *********/
1143 ret = RPipe::Define( cPipeName,aSize);
1144 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1145 test (ret == KErrNone);
1148 test.Next(_L("PIPE TEST:7.10 Register a valid Wait Request .\n"));
1149 aWriter.WaitForReader(cPipeName, stat1);
1150 test(stat1==KRequestPending);
1153 // Pass TData object with Write and Read handle both
1155 TTestThread thread5_1(KThread5Name, TestThread5, &data);
1156 User::WaitForRequest(stat1);
1158 ret = thread5_1.WaitForExitL();
1162 test.Next(_L("PIPE TEST:7.11 After Wait finish check the value of status register.\n"));
1165 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1166 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1168 aReader.WaitForReader(cPipeName, stat1);
1169 test (stat1.Int() == KErrAccessDenied);
1171 test.Next(_L("PIPE TEST:7.12 After Read handle is open , register request to Wait\n"));
1173 aWriter.WaitForReader(cPipeName, stat1);
1174 test (stat1.Int() == KErrNone);
1176 test.Next(_L("PIPE TEST:7.13 Check for CancelWait.\n"));
1179 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1181 aWriter.WaitForReader(cPipeName, stat1);
1182 aWriter.WaitForReader(cPipeName, stat2);
1183 test(stat2.Int() == KErrInUse);
1184 aWriter.CancelWait();
1185 test(stat1.Int() == KErrCancel);
1186 test(stat2.Int() == KErrInUse);
1187 aWriter.WaitForReader(cPipeName, stat1);
1188 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1189 test(stat1.Int() == KErrNone);
1191 // Release all the resources.
1196 // Pass TData object with Write and Read handle both
1198 test.Next(_L("PIPE TEST:7.14 Register a valid Wait Request .\n"));
1199 aWriter.WaitForReader(cPipeName, stat1);
1202 TTestThread thread5_2(KThread5Name, TestThread5, &data);
1203 User::WaitForRequest(stat1);
1205 ret = thread5_2.WaitForExitL();
1208 test.Next(_L("PIPE TEST:7.15 After Wait finish close the handles.\n"));
1209 test (stat1.Int() == KErrNone);
1212 // Release all the resources.
1213 ret = RPipe::Destroy(cPipeName);
1216 /*****************Newly added tests for CR 1114 - WaitForWriter *********/
1218 ret = RPipe::Define( cPipeName,aSize);
1220 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1221 test (ret == KErrNone);
1225 // Pass TData object with Write and Read handle both
1227 test.Next(_L("PIPE TEST:7.16 Register a valid Wait Request .\n"));
1228 aReader.WaitForWriter(cPipeName, stat1);
1229 test(stat1==KRequestPending);
1232 TTestThread thread11(KThread11Name, TestThread11, &data);
1233 User::WaitForRequest(stat1);
1235 ret = thread11.WaitForExitL();
1239 test.Next(_L("PIPE TEST:7.17 After Wait finish check the value of status register.\n"));
1242 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1244 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1247 aWriter.WaitForWriter(cPipeName, stat1);
1248 test (stat1.Int() == KErrAccessDenied);
1250 test.Next(_L("PIPE TEST:7.18 After Write handle is open , register request to Wait\n"));
1252 aReader.WaitForWriter(cPipeName, stat1);
1253 test (stat1.Int() == KErrNone);
1255 test.Next(_L("PIPE TEST:7.19 Check for CancelWait.\n"));
1258 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1260 aReader.WaitForWriter(cPipeName, stat1);
1261 aReader.WaitForWriter(cPipeName, stat2);
1262 test(stat2.Int() == KErrInUse);
1263 aReader.CancelWait();
1264 test(stat1.Int() == KErrCancel);
1265 test(stat2.Int() == KErrInUse);
1266 aReader.WaitForWriter(cPipeName, stat1);
1267 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1268 test(stat1.Int() == KErrNone);
1270 // Release all the resources.
1275 // Pass TData object with Write and Read handle both
1277 test.Next(_L("PIPE TEST:7.20 Register a valid Wait Request .\n"));
1278 aReader.WaitForWriter(cPipeName, stat1);
1281 TTestThread thread11_2(KThread11Name, TestThread11, &data);
1282 User::WaitForRequest(stat1);
1284 test.Next(_L("PIPE TEST:7.21 After Wait finish , close the hadles.\n"));
1285 test (stat1.Int() == KErrNone);
1286 ret = thread11_2.WaitForExitL();
1289 // Release all the resources.
1294 ret = RPipe::Destroy(cPipeName);
1297 /**********************************************************/
1300 ret = RPipe::Define( cPipeName,aSize);
1301 test(ret == KErrNone);
1304 aReader.WaitForWriter(cPipeName, stat1);
1305 // Try to open read end again. It should not open because WaitForWriter
1306 // will has already opened the Read End of the pipe.
1307 ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
1308 test(ret = KErrInUse );
1309 // Status of the wait request is pending because writer is not opened yet.
1310 test (stat1.Int() == KRequestPending);
1313 aWriter.WaitForReader(cPipeName , stat2);
1314 // Reader was already opened so status is KErrNone.
1315 test ( stat2.Int() == KErrNone);
1317 // Try to open Write end. It should not allow because WaitForReader has
1318 // already opened the write end of the pipe.
1319 ret = aWriter.Open(cPipeName ,RPipe::EOpenToWrite);
1320 test (ret == KErrInUse);
1322 // Check the status of the WaitForWriter request. It should be KErrNone now.
1323 test (stat1.Int() == KErrNone);
1325 // Let's check for pipe attributes.
1326 ret = aReader.MaxSize();
1328 ret = aWriter.MaxSize();
1330 ret = aReader.Size();
1332 ret = aWriter.Size();
1335 // Close the Reade handle.
1338 // Put request to wait for Reader.
1339 aWriter.WaitForReader(cPipeName , stat2);
1340 // It should be pending.
1341 test ( stat2.Int() == KRequestPending);
1342 // Open the reader end of the pipe. It should allow , KErrNone
1343 ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
1344 test ( stat2.Int() == KErrNone);
1345 test (ret == KErrNone);
1349 ret=RPipe::Destroy(cPipeName);
1357 /****************************************************************************
1358 This is a function to test notify mechanism of pipes.
1359 Check the functionality of following library functions
1363 ******************************************************************************/
1364 void TestNotifyMechanismPipes() {
1365 // Test NotifyDataAvailable , NotifySpaceAvailable
1366 RSemaphore globalSem; // Handle to a global semaphore. Semaphore is used to maintain synchronisation between thread4 and the main thread
1367 TInt ret; // Return Value variable.
1368 RPipe aReader,aWriter; // Used to pass to thread.
1369 RPipe aReader2,aWriter2; // Used to pass to thread.
1371 TInt aSize; // Used to pass to thread.
1372 const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
1374 TRequestStatus stat1;
1375 TBuf8<50> cPipeTestData1(KTestData2);
1377 const TBufC<50> cSemaphoreName(KSemaphoreName); // Descriptor conataining the name of the global semaphore.
1380 ret = globalSem.CreateGlobal(cSemaphoreName,0); //create and open a global semaphore with initial count as 0.
1381 test (ret == KErrNone);
1383 aSize = 22; // Size of KTestData * 10
1385 ret = RPipe::Create( aSize,
1392 TData data( &aReader, &aWriter);
1395 // Pass TData object with Write and Read handle both
1396 test.Next(_L("PIPE TEST:6.1 Call CancelDataAvailable/CancelSpaceAvailable using unopened RPipe handles.\n"));
1397 ret = aReader2.CancelDataAvailable();
1398 test ( ret == KErrBadHandle);
1399 ret = aWriter2.CancelSpaceAvailable();
1400 test (ret == KErrBadHandle);
1402 test.Next(_L("PIPE TEST:6.2 Call NotifySpaceAvailable with Negative size \n"));
1403 // Call Notfifyspace
1405 aWriter.NotifySpaceAvailable(tempsize, stat1);
1406 test ( stat1.Int() == KErrArgument);
1408 test.Next(_L("PIPE TEST:6.2a Call NotifySpaceAvailable for space larger than pipe.\n"));
1409 aWriter.NotifySpaceAvailable(aSize+1, stat1);
1410 test_Equal( KErrArgument, stat1.Int());
1415 TTestThread thread4(KThread4Name, TestThread4, &data);
1418 // Call Notifydata available
1419 // Loop for Available
1420 // Read the data and validate
1422 test.Next(_L("PIPE TEST:6.3 Write data into the pipe , verify return value.\n"));
1423 // Write one byte data into the pipe.
1424 globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
1425 ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1426 test (ret == cPipeTestData1.Length());
1429 test.Next(_L("PIPE TEST:6.4 Call NotifySpaceAvailable with valid parameters \n"));
1431 aWriter.NotifySpaceAvailable(tempsize, stat1);
1432 test(stat1==KRequestPending);
1433 globalSem.Signal(); //signal that thread 4 may go ahead and read 1 byte
1436 test.Next(_L("PIPE TEST:6.5 Wait till request says AVAILABLE. Available ?\n"));
1437 User::WaitForRequest(stat1);
1438 test ( stat1.Int() == KErrNone || stat1.Int() == KErrCompletion);
1441 // Notify data available
1442 // Loop for available
1444 // Register two request for Notifydata available
1445 // Register two request for Notifyspace available
1446 // Call Notifydata available using Read handle
1447 // Call Notifydata available using write handle
1451 // Check for Error conditions
1454 globalSem.Wait(); // this is waiting for a signal from thread4
1455 test.Next(_L("PIPE TEST:6.6 Register Notification for space availability. Allows ?\n"));
1456 ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1457 ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1458 // Register two request for Notifyspace available
1460 aWriter.NotifySpaceAvailable(tempsize, stat1);
1461 test_Equal(KRequestPending, stat1.Int() );
1462 test.Next(_L("PIPE TEST:6.7 Register One more Notification for space availability. Allows ?\n"));
1463 TRequestStatus tempstat1;
1464 aWriter.NotifySpaceAvailable(tempsize, tempstat1);
1465 test ( tempstat1.Int() == KErrInUse);
1467 test.Next(_L("PIPE TEST:6.7a Cancellation of non-outstanding requests must not disrupt oustanding requests\n"));
1468 aWriter.CancelWait();
1469 aWriter.NotifySpaceAvailable(tempsize, tempstat1);
1470 test_Equal( KErrInUse, tempstat1.Int());
1472 test.Next(_L("PIPE TEST:6.8 Cancel all the pending Notifications.\n"));
1473 ret = aWriter.CancelSpaceAvailable();
1474 test ( ret == KErrNone);
1475 test_Equal(KErrCancel, stat1.Int() );
1477 test.Next(_L("PIPE TEST:6.9 Try to cancel some more notifications. It should not allow\n"));
1478 ret = aWriter.CancelSpaceAvailable();
1479 test ( ret == KErrNone);
1481 test.Next(_L("PIPE TEST:6.10 Register Notification for Data availability. Allows ?\n"));
1482 // Register two request for Notifydata available
1484 aReader.NotifyDataAvailable(stat1);
1486 test.Next(_L("PIPE TEST:6.11 Register One More Notification for Data availability. Allows ?\n"));
1488 aReader.NotifyDataAvailable(tempstat1);
1489 test ( ( tempstat1.Int() == KErrInUse) || (tempstat1.Int() == KErrCompletion));
1491 test.Next(_L("PIPE TEST:6.12 Cancel all the pending Notifications for Data.\n"));
1492 ret = aReader.CancelDataAvailable();
1493 test ( ( ret == KErrNone) || (ret == KErrNotFound));
1494 test (stat1.Int() == KErrCancel);
1496 test.Next(_L("PIPE TEST:6.13 Try to cancel some more notifications. It should not allow\n"));
1497 ret = aReader.CancelDataAvailable();
1498 test ( ret == KErrNone);
1500 test.Next(_L("PIPE TEST:6.14 Try to register Data available notification using Write handle. Should not allow.\n"));
1501 aWriter.NotifyDataAvailable(stat1);
1502 test ( stat1.Int() == KErrAccessDenied);
1504 test.Next(_L("PIPE TEST:6.15 Try to register Space available notification using Read handle. Should not allow.\n"));
1505 aReader.NotifySpaceAvailable(tempsize, stat1);
1506 test ( stat1.Int() == KErrAccessDenied);
1508 test.Next(_L("PIPE TEST:6.16 Try to Cancel Data available notification using Write handle. Should not allow.\n"));
1509 ret = aWriter.CancelDataAvailable();
1510 test ( ret == KErrAccessDenied);
1512 test.Next(_L("PIPE TEST:6.17 Try to Cancel Space available notification using Write handle. Should not allow.\n"));
1513 ret = aReader.CancelSpaceAvailable();
1514 test ( ret == KErrAccessDenied);
1516 // Stop the thread and Close the Thread
1517 ret = thread4.WaitForExitL();
1520 // Close all the pipe handles.
1526 test.Printf(_L(" TEST NOTIFICATION MECHNISM FOR NAMED PIPES\n"));
1528 aSize = 22; // Size of KTestData
1530 test.Next(_L("PIPE TEST:6.18 Create Named pipe and Open Read/Write Handles.\n"));
1531 ret = RPipe::Define( cPipeName,aSize);
1532 test (ret == KErrNone);
1533 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1534 test (ret == KErrNone);
1535 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1536 test (ret == KErrNone);
1540 TData data2( &aReader, &aWriter);
1543 // Pass TData object with Write and Read handle both
1544 TTestThread thread4a(KThread4Name, TestThread4, &data2);
1547 // Call Notifydata available
1548 // Loop for Available
1549 // Read the data and validate
1551 // Write one byte data into the pipe.
1552 test.Next(_L("PIPE TEST:6.19 Write Data and check for return value.\n"));
1553 globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
1554 ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1555 test (ret == cPipeTestData1.Length());
1557 test.Next(_L("PIPE TEST:6.20 Register Notification for Space Available.\n"));
1558 // Call Notfifyspace
1560 aWriter.NotifySpaceAvailable(tempsize, stat1);
1561 test(stat1==KRequestPending);
1562 globalSem.Signal(); //signal that thread 4 may go ahead and read byte
1564 test.Next(_L("PIPE TEST:6.21 Wait till notified for Space Availanle.\n"));
1565 User::WaitForRequest(stat1);
1566 test ( stat1.Int() == KErrNone);
1569 // Read one byte of data
1571 // Notify data available
1572 // Loop for available
1574 // Register two request for Notifydata available
1575 // Register two request for Notifyspace available
1576 // Call Notifydata available using Read handle
1577 // Call Notifydata available using write handle
1580 globalSem.Wait(); //waiting for a signal from thread4.
1581 test.Next(_L("PIPE TEST:6.22 Notify for Space available.\n"));
1582 // Register two request for Notifydata available
1583 ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1584 aWriter.NotifySpaceAvailable(tempsize, stat1);
1586 test.Next(_L("PIPE TEST:6.23 Notify one more notifier for Space available.\n"));
1587 // Register two request for Notifyspace available
1588 TRequestStatus notifyStatus;
1589 aWriter.NotifySpaceAvailable(tempsize, notifyStatus);
1590 test ( notifyStatus.Int() == KErrInUse);
1593 aWriter.NotifySpaceAvailable(tempsize, stat1);
1594 test ( stat1.Int() == KErrNone);
1596 test.Next(_L("PIPE TEST:6.24 Cancel Notify for Space available.\n"));
1597 ret = aWriter.CancelSpaceAvailable();
1598 test (( ret == KErrNotFound) ||( ret == KErrNone));
1599 test.Next(_L("PIPE TEST:6.25 Cancel one more Notify for Space available.\n"));
1600 ret = aWriter.CancelSpaceAvailable();
1601 test ( ret == KErrNone);
1603 test.Next(_L("PIPE TEST:6.26 Register Notify for Data available.\n"));
1604 // Register two request for Notifydata available
1607 TRequestStatus stat5,stat6;
1608 aReader.NotifyDataAvailable(stat5);
1610 test.Next(_L("PIPE TEST:6.27 Register One more Notify for Data available.\n"));
1611 // Register two request for Notifyspace available
1612 aReader.NotifyDataAvailable(notifyStatus);
1613 test ( notifyStatus.Int() == KErrInUse);
1614 test.Next(_L("PIPE TEST:6.28 Cancel Notify for Data available.\n"));
1615 ret = aReader.CancelDataAvailable();
1616 test ( ret == KErrNone);
1617 test (stat5.Int() == KErrCancel);
1619 test.Next(_L("PIPE TEST:6.29 Cancel One more Notify for Data available.\n"));
1620 ret = aReader.CancelDataAvailable();
1621 test ( ret == KErrNone);
1623 test.Next(_L("PIPE TEST:6.30 Register Notify for Data available using Write handle\n"));
1624 aWriter.NotifyDataAvailable(stat6);
1625 test ( stat6.Int() == KErrAccessDenied);
1627 test.Next(_L("PIPE TEST:6.31 Register Notify for Space available using Read handle\n"));
1628 aReader.NotifySpaceAvailable(tempsize, stat6);
1629 test ( stat6.Int() == KErrAccessDenied);
1631 test.Next(_L("PIPE TEST:6.32 Cancel Notify for Data available using Write handle\n"));
1632 ret = aWriter.CancelDataAvailable();
1633 test ( ret == KErrAccessDenied);
1635 test.Next(_L("PIPE TEST:6.33 Cancel Notify for Space available using Read handle\n"));
1636 ret = aReader.CancelSpaceAvailable();
1637 test ( ret == KErrAccessDenied);
1639 //close the handle to the global semaphore
1642 // Stop the thread and Close the Thread
1643 ret = thread4a.WaitForExitL();
1647 RPipe::Destroy(cPipeName);
1654 } // End TestNotifyMechanismPipes()
1656 /****************************************************************************
1657 This is a function to test Named pipes in Mutli process environment.
1658 Check the functionality of following library functions
1663 ******************************************************************************/
1666 _LIT8(KTestDataIP, "ABCDEFGHIJ");
1668 void TestMultiProcessNamedPipes() {
1670 _LIT(KPipeName5, "InterProcessPipe1");
1671 TInt ret; // Return value variable
1672 RProcess proc; // Process Handle
1674 RPipe aWriterUN,aReaderUN;
1675 const TBufC<150> cPipeName1(KPipeName5);
1677 TBufC8<150> cPipeWriteData1(KTestDataIP);
1679 TRequestStatus stat1;
1680 TBuf8<150> cPipeReadData1;
1684 // Define Pipe with valid size.
1686 test.Next(_L("PIPE TEST:5.1 Define Pipe and Create UnNAmed pipe and pass handle to other process.\n"));
1687 ret = RPipe::Define(cPipeName1, aSize);
1690 KProcessName, // Launch t_pipe2.exe process
1691 KNullDesC // No arguments passed to t_pipe2.exe
1694 if (ret != KErrNone) {
1695 // Check for process successfully launched
1696 test.Printf(_L("Error : Could not start the process t_pipe2.exe \n"));
1699 TRequestStatus procLogon;
1700 proc.Logon(procLogon);
1701 test(procLogon==KRequestPending);
1704 ret = RPipe::Create( aSize,
1707 EOwnerProcess,//TOwnerType aTypeW
1708 EOwnerProcess //TOwnerType aTypeW
1712 ret = aWriterUN.Write(KTestData,22);
1714 ret = aReaderUN.Read(cPipeReadData1,10);
1717 ret = aReaderUN.Read(cPipeReadData1,6);
1719 aReaderUN.NotifyDataAvailable(stat1);
1721 test (ret == KErrNone);
1722 ret = aReaderUN.ReadBlocking(cPipeReadData1,6);
1724 ret = aReaderUN.Read(cPipeReadData1,1);
1725 test ( ret == KErrNotReady);
1726 ret = aReaderUN.ReadBlocking(cPipeReadData1,1);
1727 test ( ret == KErrNotReady);
1730 ret = RPipe::Create( aSize,
1733 EOwnerProcess,//TOwnerType aTypeW
1734 EOwnerProcess //TOwnerType aTypeW
1737 proc.SetParameter(3,aReaderUN);
1739 ret = aWriterUN.Write(KTestData,22);
1745 test.Next(_L("PIPE TEST:5.2 Open Write handle to Pipe. Wait till Read handle Opened\n"));
1746 ret = aWriter.Open(cPipeName1, RPipe::EOpenToWrite);
1748 aWriter.Wait(cPipeName1,stat1);
1749 User::WaitForRequest(stat1);
1750 test (stat1.Int() == KErrNone);
1752 test.Next(_L("PIPE TEST:5.3 Write data to Pipe.\n"));
1753 ret = aWriter.Write(cPipeWriteData1,cPipeWriteData1.Length());
1754 test ( ret == cPipeWriteData1.Length());
1756 test.Next(_L("PIPE TEST:5.4 Wait till Space Available in Pipe.\n"));
1757 aWriter.NotifySpaceAvailable(aSize,stat1);
1758 User::WaitForRequest(stat1);
1760 test.Next(_L("PIPE TEST:5.5 Write the data using WriteBlocking call\n"));
1761 test_Equal(0, aWriter.Size());
1762 ret = aWriter.WriteBlocking(cPipeWriteData1,cPipeWriteData1.Length());
1763 test ( ret ==cPipeWriteData1.Length() );
1765 User::WaitForRequest(procLogon);
1768 ret=RPipe::Destroy(cPipeName1);
1776 } // End TestMultiProcessNamedPipes ()
1777 /****************************************************************************
1778 This is a function to test Named pipes in Multi threaded environment.
1779 Check the functionality of following library functions
1787 ******************************************************************************/
1789 // Test defining and opening both ends of pipe
1790 // Attempt to readblock from pipe closed at far end (should fail)
1791 // Attemp writeblock to pipe closed at far end
1793 // Do some normal reading and writing between threads
1794 // do some blocking read/write between threads
1795 void TestMultiThreadNamedPipes() {
1797 TInt ret; // Return Value variable.
1798 RPipe aReader,aWriter; // Used to pass to thread.
1799 TInt aSize; // Used to pass to thread.
1800 const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
1802 TBuf8<150> cPipeReadData;
1803 TBufC8<50> cTestData(KTestData); // Test Data
1808 ///////////////////////////////////////////////////////////
1810 // Test Read and Write Functionality ///
1811 ///////////////////////////////////////////////////////////
1813 test.Next(_L("PIPE TEST:4.1 Define Pipe , Open Read and Write Handle.\n"));
1815 ret = RPipe::Define( cPipeName,aSize);
1816 test (ret == KErrNone);
1818 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1819 test (ret == KErrNone);
1821 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1822 test (ret == KErrNone);
1826 test.Next(_L("PIPE TEST:4.2 ReadBlocking: Check for KErrNotReady.\n"));
1828 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1829 test (ret == KErrNotReady);
1831 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1832 test (ret == KErrNone);
1836 test.Next(_L("PIPE TEST:4.3 WriteBlocking: Check for KErrNotReady.\n"));
1837 ret = aWriter.WriteBlocking(cTestData,cTestData.Length());
1838 test (ret == KErrNotReady);
1840 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1841 test (ret == KErrNone);
1844 TData data( &aReader, &aWriter);
1849 // Write data to Pipe using valid handle
1850 test.Next(_L("PIPE TEST:4.4 Write into the pipe and verify return value.\n"));
1851 ret = aWriter.Write(cTestData,cTestData.Length());
1852 test (ret == cTestData.Length() );
1855 // Keep writing the data into pipe till it overflows
1857 test.Next(_L("PIPE TEST:4.5 Write into the pipe till it overflows.\n"));
1858 ret = aWriter.Write(cTestData,cTestData.Length());
1859 test (( ret == KErrOverflow)) ;
1861 // Start the thread.
1862 TTestThread thread2(KThread2Name, TestThread2, &data);
1863 // Read 1 byte data from pipe
1865 // Read aByte size data
1868 // Read aByte size data
1869 // User:: After (10000)
1870 // Keep reading data till zero return
1873 // Stop the thread and Close the Thread
1874 ret = thread2.WaitForExitL();
1879 ret = RPipe::Destroy(cPipeName);
1883 ///////////////////////////////////////////////////////////
1885 // Test ReadBlocking and WriteBlocking Functionality ///
1886 ///////////////////////////////////////////////////////////
1888 // Test Read and Write blocking call
1890 test.Next(_L("PIPE TEST:4.6 Create UnNamed Pipe with valid size.\n"));
1893 ret = RPipe::Define( cPipeName,aSize);
1894 test (ret == KErrNone);
1896 ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1897 test (ret == KErrNone);
1899 ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1900 test (ret == KErrNone);
1902 // Create TData object to pass Pipe handles.
1903 TData data2( &aReader, &aWriter);
1906 // Create Thread ( Note : Thread is in pending state now)
1907 // Flush the data if any in pipe to make sure its empty.
1911 TTestThread thread3(KThread3Name, TestThread3, &data2);
1913 // Write one byte of data
1914 // Write one one byte of data using WriteBlocking call
1915 // Write aByte size data using Writblocking call
1918 // Call Readblocking function.Read one byte of data.
1919 test.Next(_L("PIPE TEST:4.7 Flush the buffer and Call ReadBlocking one byte into the pipe.\n"));
1921 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1922 test_Equal(aReadSize, ret);
1924 test.Next(_L("PIPE TEST:4.8 Verify the data received.\n"));
1925 test ( KErrNone == cPipeReadData.Compare(KTestData1));
1928 test.Next(_L("PIPE TEST:4.9 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
1929 // Call Readblocking function.Read aSize bytes of data.
1930 aReadSize = aSize-aReadSize; //read rest of data
1931 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1932 test_Equal(aReadSize, ret);
1933 test ( KErrNone == cPipeReadData.Compare(KTestData3));
1936 // Wait for some time
1937 // Call Readblocking and read 1 byte of data
1938 // Call Readblocking and Read abyte size data
1939 // Call flush buffer
1941 test.Next(_L("PIPE TEST:4.10 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
1942 // Call Readblocking function.Read aSize bytes of data.
1944 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1945 test_Equal(aReadSize, ret);
1946 test ( KErrNone == cPipeReadData.Compare(KTestData2));
1948 // Stop the thread and Close the Thread
1949 ret = thread3.WaitForExitL();
1954 ret=RPipe::Destroy(cPipeName);
1958 } // End TestMultiThreadNamedPipes ()
1961 /****************************************************************************
1962 This is a function to test UnNamed pipes in Multi threaded environment.
1963 Check the functionality of following library functions
1971 ******************************************************************************/
1972 void TestMultiThreadUnNamedPipes() {
1974 TInt ret; // Return Value variable.
1975 RPipe aReader,aWriter; // Used to pass to thread.
1976 TInt aSize; // Used to pass to thread.
1977 TBuf8<250> cPipeReadData;
1979 TBufC8<50> cTestData(KTestData); // Test Data
1982 ///////////////////////////////////////////////////////////
1984 // Test Read and Write Functionality ///
1985 ///////////////////////////////////////////////////////////
1987 test.Next(_L("PIPE TEST: 3.1 Create Pipe : Check for no erros on Pipe Creation \n"));
1989 aSize = 22; // Size of KTestData * 10
1991 ret = RPipe::Create( aSize,
1994 EOwnerProcess ,//TOwnerType aTypeW
1995 EOwnerProcess //TOwnerType aTypeW
1998 test (ret == KErrNone);
2000 // Create TData object to pass Pipe handles.
2001 TData data1( &aReader, &aWriter);
2003 // Create Thread ( Note : Thread is in pending state now)
2005 // Create test data stream.
2006 test.Next(_L("PIPE TEST: 3.2 Write Function test : Write data into the pipe \n"));
2007 ret = aWriter.Write(cTestData,cTestData.Length()); // Write ""Pipe Data To Be Passed"
2008 test (ret == cTestData.Length());
2010 // Keep writing the data into pipe till it overflows
2011 test.Next(_L("PIPE TEST: 3.3 Write Data till the Pipe returns KErrOverFlow\n"));
2012 ret = aWriter.Write(cTestData,cTestData.Length());
2013 test ( ret == KErrOverflow);
2015 TTestThread thread2(KThread2Name, TestThread2, &data1);
2017 // Read 1 byte data from pipe
2019 // Read aByte size data
2022 // Read aByte size data
2023 // User:: After (10000)
2024 // Keep reading data till zero return
2027 // Stop the thread , Close it.
2029 ret = thread2.WaitForExitL();
2036 ///////////////////////////////////////////////////////////
2038 // Test ReadBlocking and WriteBlocking Functionality ///
2039 ///////////////////////////////////////////////////////////
2042 aSize = 22; // Size of KTestData
2044 ret = RPipe::Create( aSize,
2047 EOwnerProcess , //TOwnerType aTypeW
2048 EOwnerProcess //TOwnerType aTypeW
2052 // Create TData object to pass Pipe handles.
2054 TData data2(&aReader, &aWriter);
2056 // Flush the data if any in pipe to make sure its empty.
2060 TTestThread thread3(KThread3Name, TestThread3, &data2);
2062 // Write one byte of data
2063 // Write one one byte of data using WriteBlocking call
2064 // Write aByte size data using Writblocking call
2067 // Call Readblocking function.Read one byte of data.
2070 test.Next(_L("PIPE TEST: 3.4 : Call readblocking and read one byte of data \n"));
2071 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
2072 // Call goes to Thread 3
2073 test_Equal(aReadSize, ret);
2075 test.Next(_L("PIPE TEST: 3.5 : Validate the data \n"));
2076 test_Equal(0, cPipeReadData.Compare(KTestData1));
2079 // Call Readblocking function.Read aSize bytes of data.
2080 test.Next(_L("PIPE TEST: 3.6 : Read remaining data \n"));
2082 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
2083 test_Equal(aReadSize, ret);
2084 test_Equal(0, cPipeReadData.Compare(KTestData3));
2087 test.Next(_L("PIPE TEST: 3.7 : Read complete pipe size data \n"));
2089 ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
2090 test_Equal(aReadSize, ret);
2091 test_Equal(0, cPipeReadData.Compare(KTestData2));
2093 // Wait for thread to end and Close
2094 ret = thread3.WaitForExitL();
2103 }// End TestMultiThreadUnNamedPipes()
2105 /****************************************************************************
2106 This is a function to test Named pipes in Single threaded environment.
2107 Check the functionality of following library functions
2112 ******************************************************************************/
2114 void TestSingleThreadNamedPipes()
2119 const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
2126 const TBufC<100> cPipeNameMax(KMaxPipeName);
2127 const TBufC<100> cPipeNameMaxPlusOne(KMaxPipeNamePlusOne);
2129 _LIT(KBadName , "***?SFSDFWE?*_-");
2130 _LIT(KBadName2 , "");
2132 test.Next(_L("PIPE TEST: 2.1 Define Function test : Check for No Error\n"));
2135 ret = RPipe::Define(cPipeName , aSize);
2136 test (ret == KErrNone);
2138 ret = RPipe::Destroy (cPipeName);
2139 test (ret == KErrNone);
2143 test.Next(_L("PIPE TEST: 2.2 Define Function test : Check for Max length \n"));
2147 ret = RPipe::Define(cPipeNameMax , aSize);
2148 test (ret == KErrNone);
2150 ret = RPipe::Destroy (cPipeNameMax);
2151 test (ret == KErrNone);
2153 test.Next(_L("PIPE TEST: 2.3 Define Function test : Check for Max length \n"));
2156 ret = RPipe::Define(cPipeNameMaxPlusOne , aSize);
2157 test (ret == KErrBadName);
2158 ret = RPipe::Destroy (cPipeNameMaxPlusOne);
2159 test (ret == KErrBadName);
2161 test.Next(_L("PIPE TEST: 2.4 Open Function test : Test Open \n"));
2163 ret = RPipe::Define(cPipeName , aSize);
2166 ret = testPipe1.Open(KBadName,RPipe::EOpenToRead);
2167 test (ret == KErrBadName);
2169 ret = testPipe1.Open(KBadName2,RPipe::EOpenToRead);
2170 test (ret == KErrBadName);
2172 ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
2173 test (ret == KErrNone);
2175 ret = testPipe1.Open(cPipeName,RPipe::EOpenToWrite);
2176 test (ret == KErrInUse);
2180 test.Next(_L("PIPE TEST: 2.5 Destroy Function test : Destroy opened pipe error \n"));
2181 ret = RPipe::Destroy (cPipeName);
2182 test (ret == KErrInUse);
2184 test.Next(_L("PIPE TEST: 2.6 Open Function test : Reopen pipe for reading\n"));
2185 ret = testPipe2.Open(cPipeName,RPipe::EOpenToRead);
2186 test (ret == KErrInUse);
2188 test.Next(_L("PIPE TEST: 2.7 Open Function test : Bad name test \n"));
2189 ret = testPipe2.Open(cPipeNameMaxPlusOne,RPipe::EOpenToRead);
2190 test (ret == KErrBadName);
2193 test.Next(_L("PIPE TEST: 2.8 Open Function test : Write mode test\n"));
2195 ret = testPipe3.Open(cPipeName,RPipe::EOpenToWrite);
2196 test (ret == KErrNone);
2198 ret = testPipe3.Open(cPipeName,RPipe::EOpenToRead);
2199 test (ret == KErrInUse);
2201 test.Next(_L("PIPE TEST: 2.9 Open Function test : Bad name test \n"));
2203 ret = testPipe4.Open(cPipeNameMaxPlusOne,RPipe::EOpenToWrite);
2204 test (ret == KErrBadName);
2207 test.Next(_L("PIPE TEST: 2.10 Open Function test : Reopen for writing \n"));
2208 ret = testPipe4.Open(cPipeName,RPipe::EOpenToWrite);
2209 test (ret == KErrInUse);
2212 // Do we have pipes created ? Close and Destroy them ....!!
2218 ret = RPipe::Destroy (cPipeName);
2223 test.Next(_L("PIPE TEST: 2.11a Open Function test : Write But Fail on no Readers mode before pipe defined\n"));
2224 ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
2225 test_Equal(KErrNotFound,ret);
2227 test.Next(_L("PIPE TEST: 2.11 Open Function test : Write But Fail on no Readers mode Error test\n"));
2228 ret = RPipe::Define(cPipeName , aSize);
2229 test (ret == KErrNone);
2231 ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
2232 test (ret == KErrNotReady);
2235 test.Next(_L("PIPE TEST: 2.12 Open Function test : Write But Fail on no Readers mode Success test\n"));
2236 ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
2238 ret = testPipe2.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
2239 test ( ret == KErrNone);
2242 // Do we have pipes created ? Close and Destroy them ....!!
2248 ret = RPipe::Destroy (cPipeName);
2253 test.Next(_L(" 2.13 Define Function test : Check Incorrect Size\n"));
2255 ret = RPipe::Define(cPipeName , aSize);
2256 test (ret == KErrArgument);
2259 test.Next(_L("PIPE TEST: 2.14 Define Function test : Check Incorrect Size\n"));
2261 ret = RPipe::Define(cPipeName , aSize);
2262 test (ret == KErrNoMemory);
2265 test.Next(_L("PIPE TEST: 2.15 Size Function test : Size\n"));
2267 ret = RPipe::Define(cPipeName , aSize);
2269 ret = testPipe5.MaxSize();
2270 test (ret == KErrBadHandle);
2273 test.Next(_L("PIPE TEST: 2.16 Size Function test : Size\n"));
2275 ret = RPipe::Define(cPipeName , aSize);
2276 testPipe5.Open(cPipeName, RPipe::EOpenToRead);
2277 testPipe4.Open(cPipeName, RPipe::EOpenToWrite);
2278 ret = testPipe5.MaxSize();
2279 test (ret == aSize);
2280 ret = testPipe4.MaxSize();
2281 test (ret == aSize);
2284 /* Close all the pipes and Destroy*/
2290 ret = RPipe::Destroy (cPipeName);
2293 _LIT(KRedefinePipe , "REDEFINEPIPE");
2295 test.Next(_L("PIPE TEST: 2.17 Check for Redefining same pipe name \n"));
2296 ret = RPipe::Define(KRedefinePipe , aSize);
2298 ret = RPipe::Define(KRedefinePipe , aSize);
2299 test (ret == KErrAlreadyExists);
2300 ret = RPipe::Destroy (KRedefinePipe);
2303 test.Next(_L("PIPE TEST: 2.18 Open Function test : Bad Pipe name\n"));
2306 ret = testPipe6.Open(cPipeName, RPipe::EOpenToRead);
2307 test (ret == KErrNotFound);
2310 const TBufC<50> cPipeNameNull;
2311 test.Next(_L("PIPE TEST: 2.19 Define Function test : Null Pipe name and Bad Pipe name\n"));
2313 ret = RPipe::Define(cPipeNameNull , aSize);
2314 test (ret == KErrBadName);
2317 ret = RPipe::Define(KBadName , aSize);
2318 test (ret == KErrBadName);
2319 ret = RPipe::Destroy(KBadName);
2320 test (ret == KErrBadName);
2323 ret = RPipe::Define(KBadName2 , aSize);
2324 test (ret == KErrBadName);
2325 ret = RPipe::Destroy(KBadName2);
2326 test (ret == KErrBadName);
2329 test.Next(_L("PIPE TEST: 2.20 Destroy a pipe while Write end is open\n"));
2330 ret = RPipe::Define(cPipeName , aSize);
2333 ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
2334 test (ret == KErrNone);
2336 ret = testPipe2.Open(cPipeName,RPipe::EOpenToWrite);
2337 test (ret == KErrNone);
2339 ret = RPipe::Destroy (cPipeName);
2340 test (ret == KErrInUse);
2343 ret = RPipe::Destroy (cPipeName);
2344 test (ret == KErrNone);
2353 _LIT(KPipe1Name,"TestPipeA");
2354 _LIT(KPipe2Name,"TestPipeB");
2355 _LIT(KPipe3Name,"TestPipeC");
2356 _LIT(KPipe4Name,"TestPipeD");
2358 test.Next(_L("PIPE TEST: 2.21 Define Four pipes and Destroy in different sequence ( Code Coverage test)\n"));
2359 ret = RPipe::Define(KPipe1Name , aSize);
2360 test (ret == KErrNone);
2361 ret = RPipe::Define(KPipe2Name , aSize);
2362 test (ret == KErrNone);
2363 ret = RPipe::Define(KPipe3Name , aSize);
2364 test (ret == KErrNone);
2365 ret = RPipe::Define(KPipe4Name , aSize);
2366 test (ret == KErrNone);
2367 ret = RPipe::Destroy (KPipe2Name);
2368 test (ret == KErrNone);
2369 ret = RPipe::Destroy (KPipe4Name);
2370 test (ret == KErrNone);
2371 ret = RPipe::Destroy (KPipe1Name);
2372 test (ret == KErrNone);
2373 ret = RPipe::Destroy (KPipe3Name);
2374 test (ret == KErrNone);
2378 } // End TestSingleThreadNamedPipes()
2380 /****************************************************************************
2381 This is a function to test UnNamed pipes in Single threaded environment.
2382 Check the functionality of following library functions
2387 ******************************************************************************/
2389 _LIT8(KTxtDataToSend,"*Test data to send**");
2391 void TestSingleThreadUnNamedPipes() {
2393 TInt ret = 1; // Return value test variable.
2395 TBufC8<40> wData(KTxtDataToSend); // Descriptor to hold data for Writing.
2396 RPipe aReader,aWriter;
2397 RPipe aReader2,aWriter2;
2400 // Following tests will verify all the APIs in single thread
2401 // for all the possible return values.
2402 // This is to verify different paths of API
2403 // not for detail functional verification.
2404 // Create the Pipe and Check for No Errors when Valid parameters are passed.
2406 test.Next(_L("PIPE TEST:1.1 Create Function test : Check for No Error\n"));
2409 ret = RPipe::Create( aSize,
2412 EOwnerProcess,//TOwnerType aTypeW
2413 EOwnerProcess //TOwnerType aTypeW
2416 test (ret == KErrNone);
2418 ret = RPipe::Create( aSize,
2421 EOwnerProcess,//TOwnerType aTypeW
2422 EOwnerProcess //TOwnerType aTypeW
2425 test (ret == KErrInUse);
2431 // How big pipe we can create ?
2433 test.Next(_L("PIPE TEST:1.2 Create Function test : Check for No Memory\n"));
2437 ret = RPipe::Create( aSize,
2440 EOwnerProcess,//TOwnerType aTypeW
2441 EOwnerProcess //TOwnerType aTypeW
2444 test (ret == KErrNoMemory);
2450 test.Next(_L("PIPE TEST:1.3 Create Function test : Check for Reopening pipe\n"));
2453 ret = RPipe::Create( aSize,
2456 EOwnerProcess,//TOwnerType aTypeW
2457 EOwnerProcess//TOwnerType aTypeW
2462 ret = RPipe::Create( aSize,
2465 EOwnerProcess,//TOwnerType aTypeW
2466 EOwnerProcess//TOwnerType aTypeW
2469 test (ret == KErrInUse);
2476 test.Next(_L("PIPE TEST:1.4 Read/Write Function test : Check for Writing to pipe\n"));
2479 ret = RPipe::Create( aSize,
2482 EOwnerProcess,//TOwnerType aTypeW
2483 EOwnerProcess//TOwnerType aTypeW
2487 ret=aWriter.Write(wData , wData.Size());
2488 test (ret == wData.Size() );
2490 ret=aWriter.Write(wData , -1);
2491 test (ret == KErrArgument );
2494 test.Next(_L("PIPE TEST:1.5 Read/Write Function test : Check for Reading from pipe\n"));
2497 TBuf8<100> rData ;// Descriptor for reading data from Pipe.
2499 ret=aReader.Read(rData,wData.Size()); // Length of the data to be read from Pipe
2500 test (ret == wData.Size());// Length of the data read from the Pipe
2503 test.Next(_L("PIPE TEST:1.6 Read/Write Function test : Validate data received\n"));
2505 test (KErrNone == rData.Compare(wData));
2508 test.Next(_L("PIPE TEST:1.7 Read/Write Function test : Check for Reading from pipe\n"));
2510 ret=aReader.Read(rData,1);
2515 RPipe aReaderT, aWriterT;
2517 ret = RPipe::Create( aSize,
2520 EOwnerProcess,//TOwnerType aTypeW
2521 EOwnerProcess//TOwnerType aTypeW
2525 ret=aWriterT.Write(wData ,15);
2526 test_Equal(15, ret);
2527 ret = aReaderT.Read(rData,10);
2528 test_Equal(10, ret);
2529 ret=aWriterT.Write(wData ,10);
2530 test_Equal(10, ret);
2531 ret = aReaderT.Read(rData,20);
2533 ret = aReaderT.Read(rData,5);
2535 ret = aReaderT.Read(rData,25);
2544 test.Next(_L("PIPE TEST:1.8 Read/Write Function test : Check for Wrong RPipe Handle\n"));
2547 ret=aWriter.Read(rData,15 );// Length of the data to be read from Pipe
2548 test (ret == KErrAccessDenied );
2550 test.Next(_L("PIPE TEST:1.9 Read/Write Function test : Check for Wrong RPipe Handle\n"));
2552 ret=aReader.Write(rData,rData.Size());
2553 test (ret == KErrAccessDenied );
2556 test.Next(_L("PIPE TEST:1.10 Read/Write Function test : Check for write overflow\n"));
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 ret=aWriter.Write(wData,wData.Size());
2564 test (ret == KErrOverflow );
2568 test.Next(_L("PIPE TEST:1.11 MaxSize Function test : MaxSize Check \n"));
2570 // Just to be on safer side , close pipes if any.
2574 ret = RPipe::Create( aSize,
2577 EOwnerProcess,//TOwnerType aTypeW
2578 EOwnerProcess//TOwnerType aTypeW
2580 test (ret == KErrNone); // This error condition is not defined yet.
2581 ret =aReader.MaxSize();
2582 test (ret == aSize);
2585 test.Next(_L("PIPE TEST:1.12 Size Function test : Size Check \n"));
2588 ret = aReader.Size();
2591 _LIT8(KSizeTestData1,"123456789");
2593 ret = aWriter.Write(KSizeTestData1,9);
2595 ret = aReader.Size();
2598 ret = aReader.Read(rData,1);
2600 ret = rData.Compare(_L8("1"));
2602 ret = aReader.Size();
2605 _LIT8(KSizeTestData2,"ab");
2606 ret = aWriter.Write(KSizeTestData2,2);
2608 ret = aReader.Size();
2609 test_Equal(10, ret);
2611 ret = aWriter.Write(KSizeTestData2,1);
2612 test_Equal(KErrOverflow, ret);
2613 ret = aReader.Size();
2614 test_Equal(10, ret);
2616 ret = aReader.Read(rData,9);
2618 ret = rData.Compare(_L8("23456789a"));
2620 ret = aReader.Size();
2623 ret = aReader.Read(rData,1);
2625 ret = rData.Compare(_L8("b"));
2627 ret = aReader.Size();
2630 ret = aWriter.Size();
2632 RPipe WrongPipeHandle;
2634 ret = WrongPipeHandle.Size();
2635 test ( ret == KErrBadHandle);
2637 test.Next(_L("PIPE TEST:1.13 Size Function test : Size Function call with Wrong handle \n"));
2641 ret = WrongPipeHandle.MaxSize();
2642 test (ret == KErrBadHandle);
2649 test.Next(_L("PIPE TEST:1.14 Read Function : KErrNotReady \n"));
2651 ret = RPipe::Create( aSize,
2654 EOwnerProcess,//TOwnerType aTypeW
2655 EOwnerProcess//TOwnerType aTypeW
2657 test (ret == KErrNone); // This error condition is not defined yet.
2659 ret = aReader.Read(rData,aSize);
2660 test (ret == KErrNotReady);
2661 ret = aReader.Read(rData,110);
2662 test (ret == KErrArgument);
2665 test.Next(_L("PIPE TEST:1.15 Check Handle Type function \n"));
2669 ret = RPipe::Create( aSize,
2672 EOwnerProcess,//TOwnerType aTypeW
2673 EOwnerProcess//TOwnerType aTypeW
2677 ret = aReader.HandleType();
2678 test (ret == RPipe::EReadChannel);
2680 ret = aWriter.HandleType();
2681 test (ret == RPipe::EWriteChannel);
2685 ret = aReader.HandleType();
2686 test (ret == KErrBadHandle);
2688 test.Next(_L("PIPE TEST:1.16 Write Function : KErrNotReady \n"));
2690 ret = aWriter.Write(wData,aSize);
2691 test (ret == KErrNotReady);
2693 test.Next(_L("PIPE TEST:1.17 Write Function : Write data more than size of Descriptor \n"));
2694 ret = aWriter.Write(wData,110);
2695 test (ret == KErrArgument);
2698 test.Next(_L("PIPE TEST:1.18 Write Function : KErrCompletion \n"));
2700 ret = RPipe::Create( aSize,
2703 EOwnerProcess,//TOwnerType aTypeW
2704 EOwnerProcess//TOwnerType aTypeW
2707 ret = aWriter.Write(wData,wData.Size());
2708 test (ret == KErrOverflow);
2710 test.Next(_L("PIPE TEST:1.19 Create Function : KErrInUse \n"));
2712 ret = RPipe::Create( aSize,
2715 EOwnerProcess,//TOwnerType aTypeW
2716 EOwnerProcess//TOwnerType aTypeW
2718 test (ret == KErrInUse);
2721 ret = RPipe::Create( aSize,
2724 EOwnerProcess,//TOwnerType aTypeW
2725 EOwnerProcess//TOwnerType aTypeW
2727 test (ret == KErrNone);
2729 ret = RPipe::Create( aSize,
2732 EOwnerProcess,//TOwnerType aTypeW
2733 EOwnerProcess//TOwnerType aTypeW
2735 test (ret == KErrInUse);
2739 test.Next(_L("PIPE TEST:1.20 Read / Write using un opened handles \n"));
2740 RPipe aReaderT,aWriterT;
2742 ret = aWriterT.Write(wData,wData.Size());
2743 test (ret == KErrBadHandle);
2744 ret = aReaderT.Read(rData,aSize);
2745 test (ret == KErrBadHandle);
2750 // Close all the pipes and return the resources.
2757 } // End TestSingleThreadUnNamedPipes()
2759 /****************************************************************************
2760 This is a function to test UnNamed pipes and named pipes in Single
2761 threaded environment.
2762 This test ensures that the memory is actually being released when:
2763 RPipe::Close() is called for unnamed pipes and
2764 RPipe::Destroy() is called for named pipes.
2765 ******************************************************************************/
2766 void TestCreateClosePipe()
2770 RPipe readHandle, writeHandle;
2771 const TInt K3MB = 1024*1024*3;
2772 // The loop is run ten times to ensure that if memory allocated while pipe
2773 // creation is not deallocated by close,then creation of pipe will fail with
2774 // KErrNoMemory in the sixth iteration. Default heap size is assumed.
2776 test.Next(_L("PIPE TEST:11.1 Create Function test in a loop : Check for No Error\n"));
2779 TInt r = RPipe::Create(K3MB, readHandle, writeHandle,EOwnerProcess, EOwnerProcess);
2780 test(KErrNone == r);
2782 writeHandle.Close();
2786 _LIT(KPipeName, "testPipe");
2787 // The loop is run ten times to ensure that if memory allocated while pipe
2788 // creation is not deallocated by destroy,then creation of pipe will fail with
2789 // KErrNoMemory in the sixth iteration. Default heap size is assumed.
2790 test.Next(_L("PIPE TEST:11.2 Define Function test in a loop : Check for No Error\n"));
2793 TInt r = RPipe::Define(KPipeName,K3MB);
2794 test(KErrNone == r);
2795 r = RPipe::Destroy(KPipeName);
2796 test(KErrNone == r);
2799 }// End TestCreateClosePipe()
2804 TStressArgs(TInt aIter, TInt aSize)
2805 :iIter(aIter), iSize(aSize)
2812 struct TDefDesArgs: public TStressArgs
2814 TDefDesArgs(TInt aIter, TInt aSize, const TDesC& aName)
2815 :TStressArgs(aIter,aSize), iName(aName)
2821 Repeatedly define and destroy named pipe
2823 TInt DefineDestroy(TAny* aArgs)
2825 const TDefDesArgs args = *static_cast<TDefDesArgs*>(aArgs);
2827 for(TInt i=0; i<args.iIter; i++)
2829 TInt r = RPipe::Define(args.iName, args.iSize);
2830 if(r!=KErrNone && r!=KErrAlreadyExists)
2834 r = RPipe::Destroy(args.iName);
2835 if(r!=KErrNone && r!=KErrInUse && r!=KErrNotFound)
2845 The parent thread will try to repeatedly open and close a named pipe
2846 which is being repeatedly created and destroyed by the child thread.
2847 This attempts to catch race conditions.
2849 void TestRapidDefineDestroy()
2851 const TInt iterations=1000;
2852 TDefDesArgs args(iterations, 16, KPipe1Name);
2856 TTestThread thread(_L("DefineDestroy"), DefineDestroy, &args);
2860 for(TInt i=0; i<args.iIter; i++)
2862 r = pipe.Open(args.iName, RPipe::EOpenToWrite);
2863 if(r!=KErrNone && r !=KErrNotFound)
2870 r = thread.WaitForExitL();
2876 Write the descriptor specified in to the pipe repeating
2877 as many times as specified by TData::iIterations
2879 TInt WriteThread(TAny* aData)
2881 TData& data = *static_cast<TData*>(aData);
2883 const TInt iter = data.iIterations;
2886 for(TInt i=0; i<iter; i++)
2888 write = data.iWriteEnd->WriteBlocking(*data.iPipeData, data.iPipeData->Size());
2899 Fill descriptor with random bytes
2901 void FillRandom(TDes8& aDes)
2905 while(aDes.Size()+4<=aDes.MaxSize())
2908 *(TUint32*)rand = Math::Random();
2910 aDes.Append(rand, 4);
2915 @param aTotalBytes Bytes transfered in period
2916 @param aTicks number of ticks elapsed in period
2917 @return The rate of the transfer on kilobytes per second
2919 TReal KiloBytesPerSecond(TInt aTotalBytes, TInt aTicks)
2921 TInt period=0; //period of nanotick in microseconds
2922 TInt r = HAL::Get(HAL::ENanoTickPeriod, period);
2923 User::LeaveIfError(r);
2925 //we use the definition that a kilobytes is 1000 bytes
2926 TReal result = (aTotalBytes/(aTicks*period/1000));
2932 Create a source data buffer of aTotal bytes and fill with random data.
2933 Create a pipe and thread (WriteThread) to write the source buffer
2935 Read from the pipe into destination buffer
2936 and optionally verify that buffers match
2938 @param aTotal Size of data buffer
2939 @param aPipeData Size of pipe to create
2940 @param aIter number of times to repeat transfer
2941 @param aVerify Confirm that destination buffer matches source buffer
2942 @param aPollRead read pipe by polling instead of using blocking read
2943 @return Total number of ticks elapsed
2945 TInt TestLoopBack(TInt aTotal, TInt aPipeSize, TInt aIter, TBool aVerify=ETrue, TBool aPollRead=EFalse)
2947 const TInt bufferSize = aTotal;
2950 sourceBuffer.CreateL(bufferSize);
2951 FillRandom(sourceBuffer);
2952 test_Equal(bufferSize,sourceBuffer.Size());
2954 const TInt pipeSize=aPipeSize;
2956 RPipe readEnd, writeEnd;
2957 TInt r = RPipe::Create(pipeSize, readEnd, writeEnd ,EOwnerProcess, EOwnerProcess);
2961 const TInt maxIter=aIter;
2962 TData data(NULL, &writeEnd, &sourceBuffer, maxIter);
2966 destBuffer.CreateL(bufferSize);
2969 tempBuffer.CreateL(bufferSize);
2972 TTestThread writer(_L("LoopBack"), WriteThread, &data);
2973 const TUint32 startTicks=User::NTickCount();
2975 for(TInt iter=0; iter<maxIter; iter++)
2977 TInt remainingData = bufferSize;
2980 const TInt toRead = Min(pipeSize,remainingData);
2983 //an inefficient way to read a pipe!
2984 r = readEnd.Read(tempBuffer, toRead);
2985 test_NotNegative(r);
2989 r = readEnd.ReadBlocking(tempBuffer, toRead );
2990 test_Equal(toRead, r);
2992 destBuffer+=tempBuffer;
2996 while(remainingData);
3000 r = sourceBuffer.Compare(destBuffer);
3006 const TUint32 endTicks = User::NTickCount();
3008 r = writer.WaitForExitL();
3009 test_Equal(bufferSize*maxIter, r);
3011 const TUint32 ticksElapsed= endTicks - startTicks;
3013 sourceBuffer.Close();
3020 return ticksElapsed;
3024 Simple test to confirm that data is reproduced after being fed through a pipe
3026 void TestTransferIntegrity()
3029 TestLoopBack(128*1024, 128, 1, ETrue);
3030 TestLoopBack(1024, 1, 1, ETrue);
3032 //read by constantly polling
3033 TestLoopBack(128*1024, 1024, 1, ETrue, ETrue);
3038 Enable Writeblocking and Readblocking notifications
3039 without actual reads and writes
3041 class RTestPipe: public RPipe
3044 void RequestWriteBlocking(TInt aNumByte, TRequestStatus& aStatus)
3046 DoRequest(EWriteBlocking, aStatus, &aNumByte);
3049 void RequestReadBlocking(TRequestStatus& aStatus)
3051 DoRequest(EReadBlocking, aStatus);
3057 A test which will request some type of notification
3059 struct CNotificationTest : public TFunctor
3061 CNotificationTest(RTestPipe& aPipe)
3064 TInt r = iParent.Open(iParent.Id());
3068 virtual ~CNotificationTest()
3076 //set up rendezvous with parent
3077 iParent.Rendezvous(iRendezvousStatus);
3079 //announce we have run test
3080 RThread::Rendezvous(KErrNone);
3082 //wait untill parent has reached rendezvous
3083 User::WaitForRequest(iRendezvousStatus);
3086 virtual CNotificationTest* Clone()=0;
3089 If necessary, gets pipe into correct state for the start of test
3091 virtual void PreparePipe() =0;
3092 virtual void RunTest() =0;
3095 Cancel the notification
3097 virtual void Cancel() =0;
3099 virtual TInt GetReturn()
3101 return iStatus.Int();
3105 TRequestStatus iStatus;
3107 TRequestStatus iRendezvousStatus;
3114 Will request free space notification
3116 struct CSpaceNotificationTest : public CNotificationTest
3118 typedef void (RTestPipe::*TSpaceNotification) (TInt, TRequestStatus&);
3121 @param aPipe Pipe handle to use
3122 @param TSpaceNotification A pointer for the method to test
3123 @param aNumBytes Amount of space to request
3125 CSpaceNotificationTest(RTestPipe& aPipe, TSpaceNotification aFunc, TInt aNumBytes)
3126 :CNotificationTest(aPipe), iFn(aFunc), iNumBytes(aNumBytes)
3129 CNotificationTest* Clone()
3131 return new CSpaceNotificationTest(*this);
3136 (iPipe.*iFn)(iNumBytes, iStatus);
3139 //Make sure space notification won't complete immediately
3142 TInt freeSpace = iPipe.MaxSize() - iPipe.Size();
3143 if(freeSpace >= iNumBytes)
3145 TInt r = iPipe.Write(KTestData, freeSpace);
3146 test_Equal(freeSpace, r);
3152 iPipe.CancelSpaceAvailable();
3155 TSpaceNotification iFn;
3159 struct CDataNotificationTest : public CNotificationTest
3161 typedef void (RTestPipe::*TDataNotification) (TRequestStatus&);
3163 CDataNotificationTest(RTestPipe& aPipe, TDataNotification aFunc)
3164 :CNotificationTest(aPipe), iFn(aFunc)
3167 CNotificationTest* Clone()
3169 return new CDataNotificationTest(*this);
3174 (iPipe.*iFn)(iStatus);
3177 //make sure we start with an empty pipe
3185 iPipe.CancelDataAvailable();
3188 TDataNotification iFn;
3192 void ProcessNotificationTests(RPointerArray<CNotificationTest>& aArray)
3194 const TInt count = aArray.Count();
3195 for(TInt i=0; i < count; i++)
3197 for(TInt j=0; j < count; j++)
3199 //need copies as objects contain request states
3200 CNotificationTest* testA = aArray[i]->Clone();
3201 test_NotNull(testA);
3202 CNotificationTest* testB = aArray[j]->Clone();
3203 test_NotNull(testB);
3205 testA->PreparePipe(); testB->PreparePipe();
3207 TTestThread a(_L("CNotificationTestA"), *testA, EFalse);
3208 TTestThread b(_L("CNotificationTestB"), *testB, EFalse);
3210 TRequestStatus rendezvousA, rendezvousB;
3211 a.Rendezvous(rendezvousA);
3212 b.Rendezvous(rendezvousB);
3214 a.Resume(); b.Resume();
3216 //wait till after threads have made notification request.
3217 User::WaitForRequest(rendezvousA);
3218 User::WaitForRequest(rendezvousB);
3220 TInt retA = testA->GetReturn(); TInt retB = testB->GetReturn();
3222 //announce that we have read status requests, allowing
3223 //child threads to terminate
3224 RThread::Rendezvous(KErrNone);
3229 TBool oneRequestSupported = ((retA == KRequestPending) && (retB == KErrInUse))
3230 || ((retB == KRequestPending) && (retA == KErrInUse));
3231 TBool bothSupported = (retA == KRequestPending) && (retB == KRequestPending);
3233 if(!(oneRequestSupported || bothSupported))
3235 test.Printf(_L("Failure: i=%d, j=%d"), i, j);
3239 testA->Cancel(); testB->Cancel();
3247 Test abillity of pipe channels to handle multiple notification requests
3250 void TestNotifications()
3252 RTestPipe readEnd, writeEnd;
3255 TInt r = RPipe::Create(pipeSize, readEnd, writeEnd, EOwnerProcess, EOwnerProcess);
3258 test.Next(_L("Test write end requests"));
3259 CSpaceNotificationTest writeBlocking(writeEnd, &RTestPipe::RequestWriteBlocking, pipeSize);
3260 CSpaceNotificationTest spaceAvailable(writeEnd, &RTestPipe::NotifySpaceAvailable, pipeSize);
3261 RPointerArray<CNotificationTest> writeEndTests;
3263 writeEndTests.AppendL(&writeBlocking);
3264 writeEndTests.AppendL(&spaceAvailable);
3266 for(TInt i=0; i<10; i++)
3268 ProcessNotificationTests(writeEndTests);
3270 writeEndTests.Close();
3272 test.Next(_L("Test read end requests"));
3273 CDataNotificationTest readBlocking(readEnd, &RTestPipe::RequestReadBlocking);
3274 CDataNotificationTest dataAvailable(readEnd, &RTestPipe::NotifyDataAvailable);
3275 RPointerArray<CNotificationTest> readEndTests;
3277 readEndTests.AppendL(&readBlocking);
3278 readEndTests.AppendL(&dataAvailable);
3280 for(TInt j=0; j<10; j++)
3282 ProcessNotificationTests(readEndTests);
3285 readEndTests.Close();
3291 LOCAL_C void RunTests(void)
3293 // Test UnNamed Pipes in Single Thread
3294 test.Next(_L("PIPE TEST: 1.Un Named pipes in Single Thread\n"));
3295 TestSingleThreadUnNamedPipes();
3297 // Test Named Pipes in Single Thread
3298 test.Next(_L("PIPE TEST: 2.Named pipes in Single Thread\n"));
3299 TestSingleThreadNamedPipes();
3301 // Test UnNamed Pipes in MultiThread
3302 test.Next(_L("PIPE TEST: 3.Un Named pipes in Multi Thread\n"));
3303 TestMultiThreadUnNamedPipes();
3305 // Test Named Pipes in MultiThread
3306 test.Next(_L("PIPE TEST: 4.Named pipes in Multi Thread\n"));
3307 TestMultiThreadNamedPipes();
3309 // Test Named Pipes in Multi Process
3310 test.Next(_L("PIPE TEST: 5.Named pipes in Multi Process\n"));
3311 TestMultiProcessNamedPipes();
3313 // Test Notify mechanism
3314 test.Next(_L("PIPE TEST: 6.Pipes Notify mechanism test\n"));
3315 TestNotifyMechanismPipes();
3317 // Test Wait Mechanism
3318 test.Next(_L("PIPE TEST: 7.Pipes Wait mechanism test\n"));
3319 TestWaitMechanismPipes();
3322 // Test Pipes performance
3323 test.Next(_L("PIPE TEST: 8.Pipes Permission test\n"));
3324 TestPipesPermissionCheck ();
3327 test.Next(_L("PIPE TEST: 9.Misc Pipe tests\n"));
3330 // Blocking and Notify method tests.
3331 test.Next(_L("PIPE TEST: 10.Blocking and Notification calls test\n"));
3332 TestBlockingAndNotify();
3334 //Creation and closure of a large number of Pipes
3335 test.Next(_L("PIPE TEST: 11. Creation and subsequent closure of a large number of pipes\n"));
3336 TestCreateClosePipe();
3338 test.Next(_L("Test concurrent notification requests"));
3339 TestNotifications();
3341 test.Next(_L("Repeatedly open a named pipe whilst it's being created and destroyed"));
3342 TestRapidDefineDestroy();
3344 test.Next(_L("Check integrity of data after transfer\n"));
3345 TestTransferIntegrity();
3347 test.Next(_L("PIPE TEST: Ending test.\n"));
3351 TInt ParseCommandLine()
3354 //TInt r= cmdLine.Create(User::CommandLineLength());
3356 User::CommandLine(cmdLine);
3359 TPtrC token=lex.NextToken();
3360 if(token.Length()>0)
3362 TInt os=token.Match(_L("-n*"));
3365 if(token.Length()>2)
3366 lex.SkipAndMark(2-lex.TokenLength()); //set mark backwards to after the "-n"
3367 token.Set(lex.NextToken());
3368 if(token.Length()==0)
3369 return KErrArgument;
3373 TInt r=valLex.Val(value);
3381 return KErrArgument;
3386 const TInt KDefaultRuns=1;
3387 return KDefaultRuns;
3391 GLDEF_C TInt E32Main()
3392 // Main entry point for the test.
3397 test.Start(_L("PIPE TEST: Testing"));
3398 ret = RPipe::Init();
3399 if ( ret != KErrNone && ret != KErrAlreadyExists)
3401 test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
3404 TName pddName(RPipe::Name());
3405 ret = RPipe::Define (KPipe1Name,10);
3408 User::FreeLogicalDevice(pddName);
3409 ret = RPipe::Define (KPipe1Name,10);
3410 test_Equal(KErrNotFound, ret);
3412 ret = RPipe::Init();
3413 if ( ret != KErrNone && ret != KErrAlreadyExists)
3415 test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
3420 TInt runs=ParseCommandLine();
3423 TBool forever=(runs==0);
3424 for(TInt i=0; forever||(i<runs); ++i)
3427 test.Next(_L("Next iteration"));
3429 test.Start(_L("Starting Run")); //sub nest each test iteration
3431 TRAP(ret, RunTests());
3439 test.Printf(_L("Usage: t_pipe -n N\n N is number of runs to do. If N=0 run forever"));
3442 TName pddName2(RPipe::Name());
3443 ret= User::FreeLogicalDevice(pddName2);