1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pipe/t_pipe.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,3451 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\pipe\t_pipe.cpp
1.18 +// Overview:
1.19 +// Test pipe mechanism
1.20 +// API Information:
1.21 +// RPipe
1.22 +// Details:
1.23 +// - Create various leagal and illegal pipe and verify that pipe
1.24 +// functionality works as stated in requirements.
1.25 +// - Create Named and UnNamed Pipes and verify.
1.26 +// - Test Pipes communication in multiprocess , multithreaded , single process
1.27 +// single threaded environment.
1.28 +// Platforms/Drives/Compatibility:
1.29 +// All.
1.30 +// Assumptions/Requirement/Pre-requisites:
1.31 +// Refer Pipes design and requirement document.
1.32 +// 1. SGL.GT0314.202 PREQ1460 Design Doc
1.33 +// 2. SGL.GT0314.203 PREQ1460 Pipe Functional Specification
1.34 +// Refer Pipe test specification document.
1.35 +// 1. SGL.GT0314.601 Pipes_Test_Specifications
1.36 +// Failures and causes:
1.37 +// Base Port information:
1.38 +// MMP File:
1.39 +// t_pipe.mmp
1.40 +//
1.41 +//
1.42 +
1.43 +/**
1.44 + @STMTestCaseID KBASE-T_PIPE-0217
1.45 + @SYMPREQ PREQ1460
1.46 + @SYMREQ REQ6141
1.47 + @SYMCR CR0923
1.48 + @SYMTestCaseDesc Pipe functional tests
1.49 + @SYMTestPriority High
1.50 + @SYMTestActions Tests the functionality of the pipe. Success and failure tests are performed.
1.51 + @SYMTestExpectedResults Test should pass
1.52 +*/
1.53 +
1.54 +#define __E32TEST_EXTENSION__
1.55 +#include <e32test.h>
1.56 +#include <e32svr.h>
1.57 +#include <e32des8.h>
1.58 +#include <e32des8_private.h>
1.59 +#include <e32cmn.h>
1.60 +#include <e32cmn_private.h>
1.61 +#include <e32math.h>
1.62 +#include <hal.h>
1.63 +
1.64 +#include "RPipe.h"
1.65 +
1.66 +LOCAL_D RTest test(_L("t_pipe"));
1.67 +
1.68 +
1.69 +//if the test is to run under the debugger, uncomment the following line
1.70 +
1.71 +
1.72 +
1.73 +const TInt KHeapSize=0x2000;
1.74 +
1.75 +
1.76 +
1.77 +// Test Data
1.78 +_LIT8(KTestData,"Pipe Data To Be Passed");
1.79 +_LIT8(KTestData1,"P");
1.80 +_LIT8(KTestData2,"Pipe Data To Be Passed");
1.81 +_LIT8(KTestData3,"ipe Data To Be Passed");
1.82 +
1.83 +
1.84 +// Test Pipe Names
1.85 +_LIT(KPipe1Name,"TestPipe1");
1.86 +_LIT(KPipe3Name,"TestPipe3");
1.87 +
1.88 +//Global semaphore name
1.89 +_LIT(KSemaphoreName,"Semaphore1");
1.90 +
1.91 +// Pipename of max pipe length 80 Charecters.
1.92 +_LIT(KMaxPipeName,"abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrst");
1.93 +// PipeName of max pipe length plus one ,81 charecters
1.94 +_LIT(KMaxPipeNamePlusOne,"abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrst1");
1.95 +
1.96 +// Thread Name Constants
1.97 +_LIT(KThread2Name, "thread2");
1.98 +_LIT(KThread3Name, "thread3");
1.99 +_LIT(KThread4Name, "thread4");
1.100 +_LIT(KThread5Name, "thread5");
1.101 +_LIT(KReaderThread, "ReaderThread");
1.102 +_LIT(KWriterThread, "WriterThread");
1.103 +_LIT(KThread8Name, "thread8");
1.104 +_LIT(KThread9Name, "thread9");
1.105 +_LIT(KThread11Name, "thread11");
1.106 +
1.107 +// Test Process Name Constants
1.108 +_LIT(KProcessName, "t_pipe2.exe");
1.109 +
1.110 +
1.111 +// Following class is used to pass thread handle information to different threads.
1.112 +class TData
1.113 + {
1.114 +public:
1.115 + TData(RPipe* aReadEnd, RPipe *aWriteEnd);
1.116 + TData(RPipe* aReadEnd, RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations=1);
1.117 + RPipe* iReadEnd;
1.118 + RPipe* iWriteEnd;
1.119 + const TDesC8* iPipeData;
1.120 + TInt iIterations;
1.121 + };
1.122 +
1.123 +TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd)
1.124 + :iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(NULL), iIterations(NULL)
1.125 + {}
1.126 +
1.127 +TData::TData(RPipe* aReadEnd , RPipe *aWriteEnd, const TDesC8* aPipeData, TInt aIterations)
1.128 + :iReadEnd(aReadEnd),iWriteEnd(aWriteEnd), iPipeData(aPipeData), iIterations(aIterations)
1.129 + {}
1.130 +
1.131 +/**
1.132 +A utility class for running functions in other threads/processes
1.133 +*/
1.134 +class TTestRemote
1.135 + {
1.136 +public:
1.137 + virtual TInt WaitForExitL()=0;
1.138 + virtual ~TTestRemote()
1.139 + {}
1.140 +
1.141 + virtual void Rendezvous(TRequestStatus& aStatus) =0;
1.142 +
1.143 +protected:
1.144 + TTestRemote()
1.145 + {}
1.146 +
1.147 + static TInt RunFunctor(TAny* aFunctor)
1.148 + {
1.149 + TFunctor& functor = *(TFunctor*)aFunctor;
1.150 + functor();
1.151 + return KErrNone;
1.152 + }
1.153 +
1.154 + TRequestStatus iLogonStatus;
1.155 + static TInt iCount;
1.156 + };
1.157 +TInt TTestRemote::iCount=0;
1.158 +
1.159 +class TTestThread : public TTestRemote
1.160 + {
1.161 +public:
1.162 + TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue)
1.163 + {
1.164 + Init(aName, aFn, aData, aAutoResume);
1.165 + }
1.166 +
1.167 + /**
1.168 + Run aFunctor in another thread
1.169 + */
1.170 + TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue)
1.171 + {
1.172 + Init(aName, RunFunctor, &aFunctor, aAutoResume);
1.173 + }
1.174 +
1.175 + ~TTestThread()
1.176 + {
1.177 + //RTest::CloseHandleAndWaitForDestruction(iThread);
1.178 + iThread.Close();
1.179 + }
1.180 +
1.181 + void Resume()
1.182 + {
1.183 + iThread.Resume();
1.184 + }
1.185 +
1.186 + /**
1.187 + If thread exited normally, return its return code
1.188 + Otherwise, leave with exit reason
1.189 + */
1.190 + virtual TInt WaitForExitL()
1.191 + {
1.192 + User::WaitForRequest(iLogonStatus);
1.193 + const TInt exitType = iThread.ExitType();
1.194 + const TInt exitReason = iThread.ExitReason();
1.195 +
1.196 + __ASSERT_ALWAYS(exitType != EExitPending, User::Panic(_L("TTestThread"),0));
1.197 +
1.198 + if(exitType != EExitKill)
1.199 + User::Leave(exitReason);
1.200 +
1.201 + return exitReason;
1.202 + }
1.203 +
1.204 + virtual void Rendezvous(TRequestStatus& aStatus)
1.205 + {
1.206 + iThread.Rendezvous(aStatus);
1.207 + }
1.208 +
1.209 +private:
1.210 + void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume)
1.211 + {
1.212 + TKName name(aName);
1.213 + name.AppendFormat(_L("-%d"), iCount++);
1.214 + TInt r=iThread.Create(name, aFn, KDefaultStackSize, KHeapSize, KHeapSize, aData);
1.215 + User::LeaveIfError(r);
1.216 +
1.217 + iThread.Logon(iLogonStatus);
1.218 + __ASSERT_ALWAYS(iLogonStatus == KRequestPending, User::Panic(_L("TTestThread"),0));
1.219 +
1.220 + if(aAutoResume)
1.221 + iThread.Resume();
1.222 + }
1.223 +
1.224 +
1.225 +
1.226 + RThread iThread;
1.227 + };
1.228 +
1.229 +
1.230 +/**
1.231 +Non blocking reads, verifying data as expected
1.232 +*/
1.233 +TInt TestThread2(TAny* aData)
1.234 + {
1.235 + RTest test(_L("t_pipe_t2"));
1.236 +
1.237 + test.Start(_L("Thread 2"));
1.238 + test.Printf(_L("THREAD 2 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
1.239 +
1.240 + TBuf8<50> cPipeReadData;
1.241 + TInt ret,readsize;
1.242 +
1.243 +
1.244 +
1.245 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.246 +
1.247 +
1.248 + test.Next(_L("PIPE TEST:Thread 2-1 Read 1 byte of data from the pipe : Test for success\n"));
1.249 + readsize = 1;
1.250 +
1.251 + ret = data.iReadEnd->Read(cPipeReadData ,readsize);
1.252 + test_Equal(readsize, ret);
1.253 +
1.254 +
1.255 + test.Next(_L("PIPE TEST:Thread 2-2 Validate 1 byte received is correct\n"));
1.256 + ret = cPipeReadData.Compare(KTestData1);
1.257 + test_KErrNone(ret);
1.258 +
1.259 +
1.260 + test.Next(_L("PIPE TEST:Thread 2-3 Read remaining data from the pipe\n"));
1.261 + readsize = 21;
1.262 + ret = data.iReadEnd->Read(cPipeReadData , readsize);
1.263 + test_Equal(readsize, ret);
1.264 +
1.265 + test.Next(_L("PIPE TEST:Thread 2-4 Validate received data\n"));
1.266 + ret = cPipeReadData.Compare(KTestData3);
1.267 + test_KErrNone(ret);
1.268 +
1.269 + test.End();
1.270 + test.Close();
1.271 + return KErrNone;
1.272 +
1.273 +
1.274 +}
1.275 +/****************************************************************************
1.276 + This function is used as thread to test Unnamed pipes.
1.277 + TestMultiThreadUnNamedPipes() will use this function.
1.278 + TestMultiThreadNamedPipes() will use this function.
1.279 + @aData : Used to pass the pipe and handle its size information.
1.280 +
1.281 + Return Value : TInt
1.282 +
1.283 +******************************************************************************/
1.284 +TInt TestThread3(TAny* aData) {
1.285 +
1.286 +
1.287 + TInt ret, aWriteSize;
1.288 +
1.289 + TBufC8<50> cTestData3(KTestData2); // Test Data
1.290 +
1.291 +
1.292 +
1.293 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.294 + RTest test(_L("t_pipe_t3"));
1.295 +
1.296 + test.Start(_L("Thread 3"));
1.297 +
1.298 + test.Printf(_L(" THREAD 3 called by TestMultiThreadNamedPipes And TestMultiThreadUnNamedPipes\n"));
1.299 +
1.300 + test.Next(_L("PIPE TEST:Thread 3-1 Call Write blocking and write data\n"));
1.301 +
1.302 + // Call Writeblocking function. Write one byte of data.
1.303 +
1.304 + aWriteSize = cTestData3.Length();
1.305 + ret = data.iWriteEnd->WriteBlocking(cTestData3,aWriteSize);
1.306 + test_Equal(aWriteSize, ret);
1.307 +
1.308 + // Call Writeblocking function. Write aSize bye data.
1.309 +
1.310 + // Write data so that pipe get filled.
1.311 + test.Next(_L("PIPE TEST:Thread 3-2 Write data till pipe is filled up \n"));
1.312 + ret = data.iWriteEnd->WriteBlocking(cTestData3,aWriteSize);
1.313 + test_Equal(aWriteSize, ret);
1.314 +
1.315 + test.End();
1.316 + test.Close();
1.317 + return KErrNone;
1.318 +}
1.319 +/****************************************************************************
1.320 + This function is used as thread to test Unnamed pipes.
1.321 + TestMultiThreadUnNamedPipes() will use this function.
1.322 +
1.323 + @aData : Used to pass the pipe and handle its size information.
1.324 +
1.325 + Return Value : TInt
1.326 +
1.327 +******************************************************************************/
1.328 +//TRequestStatus stat1;
1.329 +TInt TestThread4(TAny* aData) {
1.330 +
1.331 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.332 + TRequestStatus stat1;
1.333 + TBuf8<150> cPipeReadData;
1.334 + TInt ret;
1.335 + RTest test(_L("t_pipe_t4"));
1.336 + test.Start(_L("Thread 4"));
1.337 +
1.338 + RSemaphore sem; // Handle to the global semaphore
1.339 + ret = sem.OpenGlobal(KSemaphoreName); // Access to the global semaphore identified by its name.
1.340 + test(ret == KErrNone);
1.341 +
1.342 +
1.343 +
1.344 + test.Printf(_L("Thread 4:Created by TestNotifyMechanismPipes.\n"));
1.345 + test.Next(_L("PIPE TEST:Thread 4-1 Register Notify Data available request.\n"));
1.346 + data.iReadEnd->NotifyDataAvailable(stat1);
1.347 + test_Equal(KRequestPending, stat1.Int());
1.348 + sem.Signal(); //signal to say that we have issued notification request
1.349 +
1.350 + test.Next(_L("PIPE TEST:Thread 4-2 Wait till notified for data. Check for Available.\n"));
1.351 + User::WaitForRequest(stat1);
1.352 + test ( stat1.Int() == KErrNone);
1.353 +
1.354 + test.Next(_L("PIPE TEST:Thread 4-3 Read One byte of data from the pipe.\n"));
1.355 + sem.Wait(); //wait for signal that 1 byte should be read
1.356 + ret = data.iReadEnd->Read(cPipeReadData,1);
1.357 + test (ret == 1);
1.358 +
1.359 + test.Next(_L("PIPE TEST:Thread 4-4 Verify data is correct ?.\n"));
1.360 + test (KErrNone == cPipeReadData.Compare(KTestData1));
1.361 +
1.362 + test.Next(_L("PIPE TEST:Thread 4-5 Read remaining data from the pipe.\n"));
1.363 + ret = data.iReadEnd->Read(cPipeReadData,21);
1.364 + test (ret == 21);
1.365 +
1.366 +
1.367 + test.Next(_L("PIPE TEST:Thread 4-6 Verify data is correct ?.\n"));
1.368 + test (KErrNone == cPipeReadData.Compare(KTestData3));
1.369 +
1.370 + sem.Signal(); //signalling to the main thread to continue its operation
1.371 + sem.Close(); //closing the handle to the semaphore
1.372 + test.End();
1.373 + test.Close();
1.374 +
1.375 + return KErrNone;
1.376 +
1.377 +}
1.378 +
1.379 +/****************************************************************************
1.380 + This function is used as thread to test Unnamed pipes.
1.381 + TestWaitMechanismPipes() will use this function.
1.382 +
1.383 + @aData : Used to pass the pipe and handle its size information.
1.384 +
1.385 + Return Value : TInt
1.386 +
1.387 +******************************************************************************/
1.388 +
1.389 +TInt TestThread5(TAny* aData) {
1.390 +
1.391 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.392 + TRequestStatus stat1;
1.393 + TInt ret;
1.394 +
1.395 + RTest test(_L("t_pipe_t5"));
1.396 +
1.397 + test.Start(_L("Thread 5"));
1.398 + test.Printf(_L("PIPE TEST:Thread 5:Created by TestWaitMechanismPipes.\n"));
1.399 +
1.400 + test.Next(_L("PIPE TEST:Thread 5-1:Register one more request to wait till open to read. It shall not allow\n"));
1.401 + data.iWriteEnd->Wait(KPipe3Name, stat1);
1.402 + test (stat1.Int() == KErrInUse);
1.403 + data.iWriteEnd->WaitForReader(KPipe3Name, stat1);
1.404 + test (stat1.Int() == KErrInUse);
1.405 +
1.406 +
1.407 + test.Next(_L("PIPE TEST:Thread 5-2:Open Pipe handle to Read.\n"));
1.408 + ret = data.iReadEnd->Open(KPipe3Name,RPipe::EOpenToRead);
1.409 + test(ret == KErrNone);
1.410 +
1.411 + test.End();
1.412 + test.Close();
1.413 + return KErrNone;
1.414 +}
1.415 +
1.416 +/**
1.417 +The reader thread will wait till there is data in the pipe
1.418 +and then continuously read till it has read the total length
1.419 +of the pipe.
1.420 +*/
1.421 +TInt ReaderThread(TAny* aData) {
1.422 +// Read data from Pipe
1.423 + RTest test(KReaderThread);
1.424 + test.Title();
1.425 + test.Start(_L("Reader Thread"));
1.426 +
1.427 + TData& data = *(TData *)aData;
1.428 + TBuf8<10> pipeReadData;
1.429 +
1.430 + const TInt sizeToRead = data.iReadEnd->MaxSize(); //attempt to read everything from pipe
1.431 + TRequestStatus status(KErrGeneral);
1.432 +
1.433 + //do read in loop in case thread is notified before pipe is full
1.434 + TInt totalDataRead=0;
1.435 + do
1.436 + {
1.437 + data.iReadEnd->NotifyDataAvailable(status);
1.438 + test.Printf(_L("notify data request status is %d\n"), status.Int());
1.439 + if(status==KRequestPending)
1.440 + User::WaitForRequest(status);
1.441 + test(status==KErrNone);
1.442 + test.Printf(_L("ready to read data\n"), status.Int());
1.443 +
1.444 + const TInt sizeRead = data.iReadEnd->Read(pipeReadData, sizeToRead);
1.445 + test.Printf(_L("Read %d bytes from pipe\n"), sizeRead);
1.446 + test(sizeRead>0);
1.447 + totalDataRead+=sizeRead;
1.448 + }
1.449 + while(totalDataRead<sizeToRead);
1.450 +
1.451 + test(totalDataRead==sizeToRead);
1.452 + test.End();
1.453 + test.Close();
1.454 +
1.455 + return KErrNone;
1.456 +}
1.457 +
1.458 +_LIT8(KTestDataNum1 , "12345");
1.459 +_LIT8(KTestDataNum , "1234567890");
1.460 +
1.461 +
1.462 +
1.463 +/**
1.464 +Write into pipe to completely fill it.
1.465 +*/
1.466 +TInt WriterThread(TAny* aData)
1.467 + {
1.468 +// Write data to pipe
1.469 + RPipe* writeEnd = static_cast<TData*>(aData)->iWriteEnd;
1.470 + RTest test(_L("WriterThread"));
1.471 + test.Start(_L("WriterThread"));
1.472 + writeEnd->Flush(); //make sure pipe is empty
1.473 + const TInt sizeToWrite = writeEnd->MaxSize();
1.474 + test.Printf(_L("Writing %d bytes in to pipe\n"), sizeToWrite);
1.475 + TInt length=writeEnd->WriteBlocking(KTestDataNum1,sizeToWrite);
1.476 + test(length==sizeToWrite);
1.477 + test.End();
1.478 + test.Close();
1.479 + return KErrNone;
1.480 + }
1.481 +
1.482 +/**
1.483 +The FlusherThread waits till the supplied pipe
1.484 +is full before flushing it.
1.485 +*/
1.486 +TInt FlusherThread(TAny* aData)
1.487 + {
1.488 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.489 +
1.490 + //wait for pipe to fill, then flush
1.491 + TRequestStatus status;
1.492 + const TInt maxSize=data.iReadEnd->MaxSize();
1.493 + do
1.494 + {
1.495 + data.iReadEnd->NotifyDataAvailable(status);
1.496 + if(status==KRequestPending)
1.497 + User::WaitForRequest(status);
1.498 + if(status!=KErrNone)
1.499 + return status.Int();
1.500 + } while(data.iReadEnd->Size()<maxSize);
1.501 + data.iReadEnd->Flush();
1.502 + return KErrNone;
1.503 + }
1.504 +
1.505 +/****************************************************************************
1.506 + This function is used as thread to test Unnamed pipes.
1.507 + TestWaitMechanismPipes() will use this function.
1.508 +
1.509 + @aData : Used to pass the pipe and handle its size information.
1.510 +
1.511 + Return Value : TInt
1.512 +
1.513 +******************************************************************************/
1.514 +TInt CloseFlag;
1.515 +
1.516 +TInt TestThread9(TAny* aData) {
1.517 +
1.518 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.519 +
1.520 + if (CloseFlag == 1)
1.521 + data.iReadEnd->Close();
1.522 + if (CloseFlag == 0)
1.523 + data.iWriteEnd->Close();
1.524 +
1.525 +
1.526 + return 0;
1.527 + }
1.528 +
1.529 +/**
1.530 +The test will create 2 threads running this function. They will
1.531 +race to placing the blocking read request. The first
1.532 +will succeed and wait, the second will write to pipe
1.533 +*/
1.534 +TInt ReadBlockThenWrite(TAny* aData) {
1.535 +
1.536 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.537 + TBuf8<10> cReadData;
1.538 + RTest test(_L("Concurrent blocking read"));
1.539 + test.Start(_L("Call blocking read on pipe\n"));
1.540 +
1.541 + TInt ret = data.iReadEnd->ReadBlocking(cReadData,5);
1.542 + if(ret == KErrNone)
1.543 + {
1.544 + test_KErrNone(cReadData.Compare(KTestDataNum1));
1.545 + }
1.546 +
1.547 + if(ret == KErrInUse)
1.548 + {
1.549 + test.Next(_L("Other thread beat us - write to pipe so it may proceed"));
1.550 + TInt write = data.iWriteEnd->Write(KTestDataNum,5);
1.551 + test_Equal(5, write);
1.552 + }
1.553 +
1.554 + test.End();
1.555 + test.Close();
1.556 +
1.557 + return ret;
1.558 +}
1.559 +
1.560 +/**
1.561 +The test will create 2 threads running this function. They will
1.562 +race to placing the blocking write request. The first
1.563 +will succeed and wait, the second will read from pipe
1.564 +*/
1.565 +TInt WriteBlockThenRead(TAny* aData) {
1.566 +
1.567 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.568 + TBuf8<10> cReadData;
1.569 + RTest test(_L("Concurrent blocking write"));
1.570 + test.Start(_L("test writing blocked pipe\n"));
1.571 +
1.572 + TInt ret = data.iWriteEnd->WriteBlocking(KTestDataNum,10);
1.573 + if(ret == KErrInUse)
1.574 + {
1.575 + test.Next(_L("The other thread beat us - read from pipe so it may proceed"));
1.576 + TInt read = data.iReadEnd->Read(cReadData,5);
1.577 + test_Equal(5, read);
1.578 + test_KErrNone(cReadData.Compare(KTestDataNum1));
1.579 + }
1.580 +
1.581 + test.End();
1.582 + test.Close();
1.583 +
1.584 + return ret;
1.585 +}
1.586 +
1.587 +/****************************************************************************
1.588 + This function is used as thread to test Unnamed pipes.
1.589 + TestWaitMechanismPipes() will use this function.
1.590 +
1.591 + @aData : Used to pass the pipe and handle its size information.
1.592 +
1.593 + Return Value : TInt
1.594 +
1.595 +******************************************************************************/
1.596 +
1.597 +TInt TestThread11(TAny* aData) {
1.598 +
1.599 + TData& data = *(TData *)aData; // aData will have pipe handles and size.
1.600 + TRequestStatus stat1;
1.601 + TBufC<50> cPipeName(KPipe3Name); // Descriptor to hold data for Writing.
1.602 + TInt ret;
1.603 + RTest test(_L("t_pipe_t11"));
1.604 +
1.605 + test.Start(_L("PIPE TEST:Thread 11:Created by TestWaitMechanismPipes.\n"));
1.606 +
1.607 + test.Next(_L("PIPE TEST:Thread 11-1:Register one more request to wait till open to read. It shall not allow\n"));
1.608 + data.iReadEnd->WaitForWriter(cPipeName, stat1);
1.609 + test_Equal(KErrInUse, stat1.Int());
1.610 +
1.611 +
1.612 + test.Next(_L("PIPE TEST:Thread 11-2:Open Pipe handle to write.\n"));
1.613 + ret = data.iWriteEnd->Open(cPipeName,RPipe::EOpenToWrite);
1.614 + test_KErrNone(ret);
1.615 +
1.616 + test.End();
1.617 + test.Close();
1.618 + return KErrNone;
1.619 +}
1.620 +
1.621 +/****************************************************************************
1.622 + This is a function to test Named/UnNamed pipes Performace.
1.623 + Check the functionality of following library functions
1.624 + -
1.625 + -
1.626 +
1.627 +
1.628 +
1.629 +******************************************************************************/
1.630 +/**
1.631 + - test that WriteBlocking unblocks
1.632 + - when data is read
1.633 + - whed date is flushed
1.634 + - test that notify data available request is completed as data is read
1.635 + - test that ReadBlocking unblocks
1.636 + - test that data available notification works
1.637 +
1.638 +*/
1.639 +void TestBlockingAndNotify() {
1.640 +
1.641 + TRequestStatus stat1;
1.642 + RPipe aReader,aWriter;
1.643 + TInt aSize,ret;
1.644 + TBufC8<10> cPipeTestDataNum(KTestDataNum);
1.645 +
1.646 + TBuf8<10> cReadData;
1.647 +
1.648 +
1.649 + aSize = 5;
1.650 + ret = RPipe::Create( aSize,
1.651 + aReader,
1.652 + aWriter,
1.653 + EOwnerProcess, //
1.654 + EOwnerProcess //
1.655 + );
1.656 + test_KErrNone(ret);
1.657 +
1.658 + TData data( &aReader, &aWriter);
1.659 +
1.660 + {
1.661 + TTestThread readerThread(KReaderThread, ReaderThread, &data);
1.662 +
1.663 + test.Start(_L("Test that WriteBlock unblocks as data is read from pipe\n"));
1.664 + ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
1.665 + test(ret == 10);
1.666 + test(aWriter.Size()==5);
1.667 + aWriter.Flush();
1.668 + test(aWriter.Size()==0);
1.669 +
1.670 + ret = readerThread.WaitForExitL();
1.671 + test_KErrNone(ret);
1.672 + }
1.673 +
1.674 + {
1.675 + TTestThread flusherThread(KThread8Name, FlusherThread, &data);
1.676 + test.Next(_L("Test that WriteBlock unblocks as data is flushed from read end of pipe\n"));
1.677 +
1.678 + ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
1.679 + test (ret == 10);
1.680 + ret = flusherThread.WaitForExitL();
1.681 + test_KErrNone(ret);
1.682 + }
1.683 +
1.684 + test.Next(_L("Test that NotifyDataAvailable request is completed as data is read from pipe\n"));
1.685 +
1.686 + aWriter.NotifySpaceAvailable(aSize,stat1);
1.687 + test(stat1==KRequestPending);
1.688 +
1.689 + {
1.690 + TTestThread readerThread2(KReaderThread, ReaderThread, &data);
1.691 +
1.692 + User::WaitForRequest(stat1);
1.693 + test(stat1==KErrNone);
1.694 +
1.695 + ret = readerThread2.WaitForExitL();
1.696 + test_KErrNone(ret);
1.697 + }
1.698 +
1.699 + aReader.Flush();
1.700 +
1.701 + test.Next(_L("PIPE TEST: Test that ReadBlocking unblocks\n"));
1.702 + {
1.703 + TTestThread writeThread(KWriterThread, WriterThread, &data);
1.704 +
1.705 + ret = aReader.ReadBlocking(cReadData,5);
1.706 + test(ret == 5);
1.707 +
1.708 + ret = writeThread.WaitForExitL();
1.709 + test_KErrNone(ret);
1.710 + }
1.711 +
1.712 + test.Next(_L("PIPE TEST: Test NotifyDataAvailable\n"));
1.713 + aReader.Flush();
1.714 + aReader.NotifyDataAvailable(stat1);
1.715 + test(stat1==KRequestPending);
1.716 +
1.717 + {
1.718 + TTestThread writeThread2(KWriterThread,WriterThread, &data);
1.719 +
1.720 + User::WaitForRequest(stat1);
1.721 + test(stat1==KErrNone);
1.722 +
1.723 + aReader.Flush();
1.724 +
1.725 + ret = writeThread2.WaitForExitL();
1.726 + test_KErrNone(ret);
1.727 + }
1.728 + test.Next(_L("PIPE TEST: Test reading from pipe closed by the writer\n"));
1.729 +
1.730 + CloseFlag = 0; // 0 Close Write Handle
1.731 + //CloseFlag = 1; // 1 Close Read Handle
1.732 + test.Next(_L("PIPE TEST: TestBlockingAndNotify 10.6\n"));
1.733 + TTestThread closeThread(KThread9Name, TestThread9, &data);
1.734 +
1.735 + ret = closeThread.WaitForExitL();
1.736 + test_KErrNone(ret);
1.737 +
1.738 + ret = aReader.ReadBlocking(cReadData,5);
1.739 + test_Equal(KErrNotReady, ret);
1.740 +
1.741 + aWriter.Close();
1.742 + aReader.Close();
1.743 + aSize = 5;
1.744 + ret = RPipe::Create( aSize,
1.745 + aReader,
1.746 + aWriter,
1.747 + EOwnerProcess, //
1.748 + EOwnerProcess //
1.749 + );
1.750 + test_KErrNone(ret);
1.751 +
1.752 + TData data1(&aReader,&aWriter);
1.753 +
1.754 +
1.755 + //CloseFlag = 0; // 0 Close Write Handle
1.756 + CloseFlag = 1; // 1 Close Read Handle
1.757 + test.Printf(_L("PIPE TEST: TestBlockingAndNotify 10.7\n"));
1.758 + TTestThread closeThread2(KThread9Name, TestThread9, &data1);
1.759 + ret = aWriter.WriteBlocking(cPipeTestDataNum,10);
1.760 + test_Equal(KErrNotReady, ret);
1.761 +
1.762 + ret = closeThread2.WaitForExitL();
1.763 + test_KErrNone(ret);
1.764 +
1.765 + aWriter.Close();
1.766 + aReader.Close();
1.767 +
1.768 + test.End();
1.769 +}
1.770 +
1.771 +
1.772 +/****************************************************************************
1.773 + TestPipesPermissionCheck :
1.774 + This function is used to test Permission and Access related
1.775 + Errors of Pipes API.
1.776 + APIs tested are Define , Create , Destroy , Read and Write.
1.777 +
1.778 +
1.779 +******************************************************************************/
1.780 +// Different pipes for different capability , VID values.
1.781 +_LIT(KPipeName2, "PipeWithNoCap");
1.782 +_LIT(KPipeName3, "PipeWithNoCapVID");
1.783 +_LIT(KPipeName4, "PipeWithRWCap");
1.784 +_LIT(KPipeName5, "PipeWithComDDCap");
1.785 +_LIT(KPipeName6, "PipeWithRWComDDCap");
1.786 +_LIT(KPipeName7, "PipeWithRWComDDCapVID");
1.787 +_LIT(KPipeName8, "PipeWithRWRUCap");
1.788 +
1.789 +// Different processes with different capability , VID values.
1.790 +_LIT(KProcessNoCap, "t_pipe3.exe");
1.791 +_LIT(KProcessRCap, "t_pipe5.exe");
1.792 +
1.793 +// My VID and SID
1.794 +_LIT_VENDOR_ID(MyVID,0x70000001);
1.795 +
1.796 +void TestPipesPermissionCheck() {
1.797 +
1.798 + RProcess proc;
1.799 + TInt ret;
1.800 +
1.801 + // Define TSecurity objects with different capabilities and VID .
1.802 + TSecurityPolicy NoCapVID(MyVID,ECapability_None,ECapability_None,ECapability_None);
1.803 + TSecurityPolicy RWCap(ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
1.804 + TSecurityPolicy ComDDCap(ECapabilityCommDD);
1.805 + TSecurityPolicy RWComDDCap(ECapabilityReadDeviceData,ECapabilityCommDD,ECapabilityWriteDeviceData);
1.806 + TSecurityPolicy RWComDDCapVID(MyVID,ECapabilityCommDD,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
1.807 + TSecurityPolicy RWRUCap(ECapabilityReadUserData,ECapabilityReadDeviceData,ECapabilityWriteDeviceData);
1.808 +
1.809 + // Define Named pipes with No Cap , combination of Cap and VID
1.810 +
1.811 + TInt aSize = 10;
1.812 + ret = RPipe::Define(KPipeName2, aSize);
1.813 + test (ret == KErrNone);
1.814 + ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
1.815 + test (ret == KErrNone);
1.816 + ret = RPipe::Define(KPipeName4, aSize,RWCap);
1.817 + test (ret == KErrNone);
1.818 + ret = RPipe::Define(KPipeName5, aSize,ComDDCap);
1.819 + test (ret == KErrNone);
1.820 + ret = RPipe::Define(KPipeName6, aSize,RWComDDCap);
1.821 + test (ret == KErrNone);
1.822 + ret = RPipe::Define(KPipeName7, aSize,RWComDDCapVID);
1.823 + test (ret == KErrNone);
1.824 + ret = RPipe::Define(KPipeName8, aSize,RWRUCap);
1.825 + test (ret == KErrNone);
1.826 +
1.827 + //Lets see who can use pipes. Check for Permissions and Access
1.828 + test.Next(_L("PIPE TEST:8.1 Create Process with No Cap t_pipe3.exe\n"));
1.829 + ret = proc.Create (
1.830 + KProcessNoCap, // Launch t_pipe3.exe process
1.831 + KNullDesC // No arguments passed to t_pipe3.exe
1.832 + );
1.833 +
1.834 + if (ret != KErrNone)
1.835 + {
1.836 + test.Printf(_L(" ***** t_pipe3.exe could not start ****"));
1.837 + }
1.838 + test_KErrNone(ret);
1.839 + test.Printf(_L("Process Created successfully"));
1.840 +
1.841 + TRequestStatus procLogon;
1.842 + proc.Logon(procLogon);
1.843 + test(procLogon==KRequestPending);
1.844 + proc.Resume();
1.845 + User::WaitForRequest(procLogon);
1.846 + proc.Close();
1.847 +
1.848 + // Lets see what happens with Read Capability.
1.849 + test.Next(_L("PIPE TEST:8.2 Create Process with Read-Write-CommDD Cap t_pipe5.exe\n"));
1.850 + ret = RPipe::Define(KPipeName2, aSize);
1.851 + test_KErrNone(ret);
1.852 + ret = RPipe::Define(KPipeName3, aSize,NoCapVID);
1.853 + test_KErrNone(ret);
1.854 +
1.855 + ret = proc.Create (
1.856 + KProcessRCap, // Launch t_pipe3.exe process
1.857 + KNullDesC // No arguments passed to t_pipe3.exe
1.858 + );
1.859 +
1.860 + if (ret != KErrNone)
1.861 + {
1.862 + test.Printf(_L(" ***** t_pipe5.exe could not start ****"));
1.863 + }
1.864 + test_KErrNone(ret);
1.865 + test.Printf(_L("Process Created successfully"));
1.866 + proc.Logon(procLogon);
1.867 + test(procLogon==KRequestPending);
1.868 + proc.Resume();
1.869 + User::WaitForRequest(procLogon);
1.870 + proc.Close();
1.871 +
1.872 + //the t_pipe5.exe process should destroy most of these
1.873 + //but we call destroy again to verify this
1.874 + ret = RPipe::Destroy (KPipeName2);
1.875 + test_Equal(KErrNotFound, ret);
1.876 + ret = RPipe::Destroy (KPipeName3);
1.877 + test_KErrNone(ret); //KPipeName3 is not destroyed by the other process.
1.878 + ret = RPipe::Destroy (KPipeName4);
1.879 + test_Equal(KErrNotFound, ret);
1.880 + ret = RPipe::Destroy (KPipeName5);
1.881 + test_Equal(KErrNotFound, ret);
1.882 + ret = RPipe::Destroy (KPipeName6);
1.883 + test_Equal(KErrNotFound, ret);
1.884 + ret = RPipe::Destroy (KPipeName7);
1.885 + test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
1.886 + ret = RPipe::Destroy (KPipeName8);
1.887 + test_KErrNone(ret); //t_pipe5.exe does not have permission to delete
1.888 +
1.889 +
1.890 +
1.891 + return;
1.892 +
1.893 +}
1.894 +
1.895 +/****************************************************************************
1.896 +
1.897 + TestMiscPipes :
1.898 + This is a function to test Named/UnNamed pipes for all Misc test cases.
1.899 +
1.900 +
1.901 +******************************************************************************/
1.902 +
1.903 +void TestMiscPipes() {
1.904 +
1.905 +_LIT(KInvalidPipeName,"PipeNotExist");
1.906 + TInt ret,aSize;
1.907 + RPipe aReader,aWriter;
1.908 + TBufC<50> cPipeName(KInvalidPipeName); // Descriptor to hold data for Writing.
1.909 + TBufC8<50> cPipeTestData2(KTestData2);
1.910 +
1.911 +
1.912 + // Try to create unnamed pipe with Negative size
1.913 + test.Next(_L("PIPE TEST:9.1 Create Pipe of Negative Size.\n"));
1.914 + aSize = -1;
1.915 + ret = RPipe::Create( aSize,
1.916 + aReader,
1.917 + aWriter,
1.918 + EOwnerProcess, //
1.919 + EOwnerProcess //
1.920 + );
1.921 + test( ret == KErrArgument);
1.922 +
1.923 +
1.924 + // Try to create unnamed pipe with zero size
1.925 + test.Next(_L("PIPE TEST:9.2 Create Pipe with of Zero size.\n"));
1.926 + aSize = 0;
1.927 + ret = RPipe::Create( aSize,
1.928 + aReader,
1.929 + aWriter,
1.930 + EOwnerProcess, //
1.931 + EOwnerProcess //
1.932 + );
1.933 + test( ret == KErrArgument);
1.934 +
1.935 +
1.936 + // Try to define named pipe with Negative size
1.937 + test.Next(_L("PIPE TEST:9.3 Define Pipe of Negative size.\n"));
1.938 + aSize = -1;
1.939 + ret = RPipe::Define(cPipeName, aSize);
1.940 + test( ret == KErrArgument);
1.941 +
1.942 +
1.943 +
1.944 + // Try to define named pipe with Zero size
1.945 + test.Next(_L("PIPE TEST:9.4 Define Pipe of Zero size.\n"));
1.946 + aSize = 0;
1.947 + ret = RPipe::Define(cPipeName, aSize);
1.948 + test( ret == KErrArgument);
1.949 +
1.950 +
1.951 + // Try to destroy pipe which does not exists
1.952 + test.Next(_L("PIPE TEST:9.5 Try to destroy named pipe which do not exist.\n"));
1.953 + ret = RPipe::Destroy (cPipeName);
1.954 + test (ret == KErrNotFound);
1.955 +
1.956 +
1.957 + // Try to read from pipe with invalid length data to be read
1.958 + RPipe aReaderUN,aWriterUN;
1.959 + TBuf8<150> cPipeReadData;
1.960 + aSize = 10;
1.961 + ret = RPipe::Create( aSize,
1.962 + aReaderUN,
1.963 + aWriterUN,
1.964 + EOwnerProcess, //
1.965 + EOwnerProcess //
1.966 + );
1.967 + test (ret == KErrNone );
1.968 +
1.969 +
1.970 + test.Next(_L("PIPE TEST:9.6 Try calling ReadBlocking using write handle and WriteBlocking using Read handle.\n"));
1.971 + ret = aWriterUN.ReadBlocking(cPipeReadData, aSize);
1.972 + test (ret == KErrAccessDenied);
1.973 + ret = aReaderUN.WriteBlocking(cPipeTestData2,aSize);
1.974 + test (ret == KErrAccessDenied);
1.975 +
1.976 +
1.977 +
1.978 +
1.979 + test.Next(_L("PIPE TEST:9.7 Read negative size data from un-named pipe.\n"));
1.980 + aSize = -1;
1.981 + ret = aReaderUN.Read(cPipeReadData, aSize);
1.982 + test( ret == KErrArgument);
1.983 + ret = aWriterUN.Write(cPipeTestData2,aSize);
1.984 + test( ret == KErrArgument);
1.985 +
1.986 +
1.987 +
1.988 + test.Next(_L("PIPE TEST:9.8 Read/Write zero size data from/to un-named pipe\n"));
1.989 + aSize = 0;
1.990 + ret = aReaderUN.Read(cPipeReadData, aSize);
1.991 + test( ret == KErrNone);
1.992 +
1.993 + ret = aWriterUN.Write(cPipeTestData2,aSize);
1.994 + test( ret == KErrNone);
1.995 +
1.996 +
1.997 + test.Next(_L("PIPE TEST:9.9 Call ReadBlocking and WriteBlocking to Read and Write negative size data.\n"));
1.998 + // Try to readblocking from pipe with invalid length data to be read
1.999 + aSize = -1;
1.1000 + ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
1.1001 + test( ret == KErrArgument);
1.1002 + ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
1.1003 + test( ret == KErrArgument);
1.1004 +
1.1005 + test.Next(_L("PIPE TEST:9.10 ReadBlocking/WriteBlocking to read/write zero size data.\n"));
1.1006 + aSize = 0;
1.1007 + ret = aReaderUN.ReadBlocking(cPipeReadData, aSize);
1.1008 + test( ret == KErrArgument);
1.1009 + ret = aWriterUN.WriteBlocking(cPipeTestData2,aSize);
1.1010 + test( ret == KErrArgument);
1.1011 +
1.1012 +
1.1013 + test.Next(_L("PIPE TEST:9.11 Try calling ReadBlocking and WriteBlocking using un opened RPipe handles.\n"));
1.1014 + RPipe aReaderT,aWriterT;
1.1015 + ret = aReaderT.ReadBlocking(cPipeReadData, aSize);
1.1016 + test (ret == KErrBadHandle);
1.1017 + ret = aWriterT.WriteBlocking(cPipeTestData2,aSize);
1.1018 + test (ret == KErrBadHandle);
1.1019 + aReaderUN.Close();
1.1020 + aWriterUN.Close();
1.1021 +
1.1022 +
1.1023 + return;
1.1024 +}
1.1025 +
1.1026 +/****************************************************************************
1.1027 + This is a function to test notify mechanism of pipes.
1.1028 + Check the functionality of following library functions
1.1029 + - Notify...()
1.1030 +
1.1031 +
1.1032 +******************************************************************************/
1.1033 +void TestWaitMechanismPipes() {
1.1034 +
1.1035 + RPipe aReader,aWriter; // Used to pass to thread.
1.1036 + RPipe aWriter2;
1.1037 + TInt ret;
1.1038 + TBufC<50> cPipeName(KPipe3Name); // Descriptor to hold data for Writing.
1.1039 + TInt aSize;
1.1040 + TRequestStatus stat1;
1.1041 +
1.1042 + aSize = 22 * 10; // Sizeof(KTestData) * 10
1.1043 +
1.1044 + ret = RPipe::Define( cPipeName,aSize);
1.1045 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1046 + test (ret == KErrNone);
1.1047 +
1.1048 +
1.1049 +
1.1050 + test.Next(_L("PIPE TEST:7.1 Try calling Wait function on BadPipe name.\n"));
1.1051 +
1.1052 + _LIT(KBadPipeName , "***R$@#$@#%#$%#^.12-.");
1.1053 + aWriter.Wait(KBadPipeName,stat1);
1.1054 + test(stat1.Int() == KErrBadName);
1.1055 + aWriter.WaitForReader(KBadPipeName,stat1);
1.1056 + test(stat1.Int() == KErrBadName);
1.1057 +
1.1058 +
1.1059 + _LIT(KBadPipeName2 , "");
1.1060 + aWriter.Wait(KBadPipeName2,stat1);
1.1061 + test(stat1.Int() == KErrBadName);
1.1062 + aWriter.WaitForReader(KBadPipeName2,stat1);
1.1063 + test(stat1.Int() == KErrBadName);
1.1064 +
1.1065 +
1.1066 +
1.1067 + test.Next(_L("PIPE TEST:7.2 Try calling Wait function on non existing Pipe\n"));
1.1068 + _LIT(KInvalidPipe , "NotExistingPipe");
1.1069 + aWriter.Wait(KInvalidPipe,stat1);
1.1070 + test(stat1.Int() == KErrNotFound);
1.1071 + aWriter.WaitForReader(KInvalidPipe,stat1);
1.1072 + test(stat1.Int() == KErrNotFound);
1.1073 +
1.1074 +
1.1075 + test.Next(_L("PIPE TEST:7.3 Try calling Wait function on Pipe name length more than maxlength.\n"));
1.1076 + aWriter.Wait(KMaxPipeNamePlusOne,stat1);
1.1077 + test(stat1.Int() == KErrBadName);
1.1078 + aWriter.WaitForReader(KMaxPipeNamePlusOne,stat1);
1.1079 + test(stat1.Int() == KErrBadName);
1.1080 +
1.1081 +
1.1082 + test.Next(_L("PIPE TEST:7.4 Try calling Wait function from unopened handle.\n"));
1.1083 + aWriter2.Wait(cPipeName, stat1);
1.1084 + test (stat1.Int() == KErrInUse);
1.1085 + aWriter2.WaitForReader(cPipeName, stat1);
1.1086 + test (stat1.Int() == KErrInUse);
1.1087 +
1.1088 +
1.1089 + test.Next(_L("PIPE TEST:7.5 Register a valid Wait Request .\n"));
1.1090 + aWriter.Wait(cPipeName, stat1);
1.1091 +
1.1092 + TData data( &aReader, &aWriter);
1.1093 +
1.1094 + // Create Thread 5
1.1095 + // Pass TData object with Write and Read handle both
1.1096 + TTestThread thread5(KThread5Name, TestThread5, &data);
1.1097 + User::WaitForRequest(stat1);
1.1098 +
1.1099 + ret = thread5.WaitForExitL();
1.1100 + test_KErrNone(ret);
1.1101 +
1.1102 + test.Next(_L("PIPE TEST:7.6 After Wait finish check the value of status register.\n"));
1.1103 + test_KErrNone(stat1.Int());
1.1104 + aWriter.Close();
1.1105 + aReader.Close();
1.1106 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1107 + test_KErrNone(ret);
1.1108 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1109 + test_KErrNone(ret);
1.1110 +
1.1111 + test.Next(_L("PIPE TEST:7.7 After Read handle is open , register request to Wait\n"));
1.1112 +
1.1113 + aWriter.Wait(cPipeName, stat1);
1.1114 + test (stat1.Int() == KErrNone);
1.1115 +
1.1116 + test.Next(_L("PIPE TEST:7.8 Check for CancelWait.\n"));
1.1117 + aWriter.Close();
1.1118 + aReader.Close();
1.1119 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1120 + TRequestStatus stat2;
1.1121 + aWriter.Wait(cPipeName, stat1);
1.1122 + aWriter.Wait(cPipeName, stat2);
1.1123 + test(stat2.Int() == KErrInUse);
1.1124 + aWriter.CancelWait();
1.1125 + test(stat1.Int() == KErrCancel);
1.1126 + test(stat2.Int() == KErrInUse);
1.1127 + aWriter.Wait(cPipeName, stat1);
1.1128 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1129 + test(stat1.Int() == KErrNone);
1.1130 +
1.1131 + test.Next(_L("PIPE TEST:7.9 Check Wait and CancelWait from reader end\n"));
1.1132 + aWriter.Close();
1.1133 + aReader.Close();
1.1134 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1135 + aReader.Wait(cPipeName, stat1);
1.1136 + test (stat1.Int() == KErrAccessDenied);
1.1137 + aReader.CancelWait();
1.1138 +
1.1139 +
1.1140 + aWriter.Close();
1.1141 + aReader.Close();
1.1142 + RPipe::Destroy(cPipeName);
1.1143 +
1.1144 + /*****************Newly added tests for CR 1114 - WaitForReader *********/
1.1145 +
1.1146 + ret = RPipe::Define( cPipeName,aSize);
1.1147 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1148 + test (ret == KErrNone);
1.1149 +
1.1150 +
1.1151 + test.Next(_L("PIPE TEST:7.10 Register a valid Wait Request .\n"));
1.1152 + aWriter.WaitForReader(cPipeName, stat1);
1.1153 + test(stat1==KRequestPending);
1.1154 +
1.1155 + // Create Thread 5
1.1156 + // Pass TData object with Write and Read handle both
1.1157 + {
1.1158 + TTestThread thread5_1(KThread5Name, TestThread5, &data);
1.1159 + User::WaitForRequest(stat1);
1.1160 +
1.1161 + ret = thread5_1.WaitForExitL();
1.1162 + test_KErrNone(ret);
1.1163 + }
1.1164 +
1.1165 + test.Next(_L("PIPE TEST:7.11 After Wait finish check the value of status register.\n"));
1.1166 + aWriter.Close();
1.1167 + aReader.Close();
1.1168 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1169 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1170 +
1.1171 + aReader.WaitForReader(cPipeName, stat1);
1.1172 + test (stat1.Int() == KErrAccessDenied);
1.1173 +
1.1174 + test.Next(_L("PIPE TEST:7.12 After Read handle is open , register request to Wait\n"));
1.1175 +
1.1176 + aWriter.WaitForReader(cPipeName, stat1);
1.1177 + test (stat1.Int() == KErrNone);
1.1178 +
1.1179 + test.Next(_L("PIPE TEST:7.13 Check for CancelWait.\n"));
1.1180 + aWriter.Close();
1.1181 + aReader.Close();
1.1182 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1183 +
1.1184 + aWriter.WaitForReader(cPipeName, stat1);
1.1185 + aWriter.WaitForReader(cPipeName, stat2);
1.1186 + test(stat2.Int() == KErrInUse);
1.1187 + aWriter.CancelWait();
1.1188 + test(stat1.Int() == KErrCancel);
1.1189 + test(stat2.Int() == KErrInUse);
1.1190 + aWriter.WaitForReader(cPipeName, stat1);
1.1191 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1192 + test(stat1.Int() == KErrNone);
1.1193 +
1.1194 + // Release all the resources.
1.1195 + aWriter.Close();
1.1196 + aReader.Close();
1.1197 +
1.1198 + // Create Thread 5
1.1199 + // Pass TData object with Write and Read handle both
1.1200 +
1.1201 + test.Next(_L("PIPE TEST:7.14 Register a valid Wait Request .\n"));
1.1202 + aWriter.WaitForReader(cPipeName, stat1);
1.1203 +
1.1204 + {
1.1205 + TTestThread thread5_2(KThread5Name, TestThread5, &data);
1.1206 + User::WaitForRequest(stat1);
1.1207 +
1.1208 + ret = thread5_2.WaitForExitL();
1.1209 + test_KErrNone(ret);
1.1210 + }
1.1211 + test.Next(_L("PIPE TEST:7.15 After Wait finish close the handles.\n"));
1.1212 + test (stat1.Int() == KErrNone);
1.1213 + aWriter.Close();
1.1214 + aReader.Close();
1.1215 + // Release all the resources.
1.1216 + ret = RPipe::Destroy(cPipeName);
1.1217 + test_KErrNone(ret);
1.1218 +
1.1219 + /*****************Newly added tests for CR 1114 - WaitForWriter *********/
1.1220 +
1.1221 + ret = RPipe::Define( cPipeName,aSize);
1.1222 + test_KErrNone(ret);
1.1223 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1224 + test (ret == KErrNone);
1.1225 +
1.1226 +
1.1227 + // Create Thread 11
1.1228 + // Pass TData object with Write and Read handle both
1.1229 +
1.1230 + test.Next(_L("PIPE TEST:7.16 Register a valid Wait Request .\n"));
1.1231 + aReader.WaitForWriter(cPipeName, stat1);
1.1232 + test(stat1==KRequestPending);
1.1233 +
1.1234 + {
1.1235 + TTestThread thread11(KThread11Name, TestThread11, &data);
1.1236 + User::WaitForRequest(stat1);
1.1237 +
1.1238 + ret = thread11.WaitForExitL();
1.1239 + test_KErrNone(ret);
1.1240 + }
1.1241 +
1.1242 + test.Next(_L("PIPE TEST:7.17 After Wait finish check the value of status register.\n"));
1.1243 + aWriter.Close();
1.1244 + aReader.Close();
1.1245 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1246 + test_KErrNone(ret);
1.1247 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1248 + test_KErrNone(ret);
1.1249 +
1.1250 + aWriter.WaitForWriter(cPipeName, stat1);
1.1251 + test (stat1.Int() == KErrAccessDenied);
1.1252 +
1.1253 + test.Next(_L("PIPE TEST:7.18 After Write handle is open , register request to Wait\n"));
1.1254 +
1.1255 + aReader.WaitForWriter(cPipeName, stat1);
1.1256 + test (stat1.Int() == KErrNone);
1.1257 +
1.1258 + test.Next(_L("PIPE TEST:7.19 Check for CancelWait.\n"));
1.1259 + aWriter.Close();
1.1260 + aReader.Close();
1.1261 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1262 +
1.1263 + aReader.WaitForWriter(cPipeName, stat1);
1.1264 + aReader.WaitForWriter(cPipeName, stat2);
1.1265 + test(stat2.Int() == KErrInUse);
1.1266 + aReader.CancelWait();
1.1267 + test(stat1.Int() == KErrCancel);
1.1268 + test(stat2.Int() == KErrInUse);
1.1269 + aReader.WaitForWriter(cPipeName, stat1);
1.1270 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1271 + test(stat1.Int() == KErrNone);
1.1272 +
1.1273 + // Release all the resources.
1.1274 + aWriter.Close();
1.1275 + aReader.Close();
1.1276 +
1.1277 + // Create Thread 11
1.1278 + // Pass TData object with Write and Read handle both
1.1279 +
1.1280 + test.Next(_L("PIPE TEST:7.20 Register a valid Wait Request .\n"));
1.1281 + aReader.WaitForWriter(cPipeName, stat1);
1.1282 +
1.1283 + {
1.1284 + TTestThread thread11_2(KThread11Name, TestThread11, &data);
1.1285 + User::WaitForRequest(stat1);
1.1286 +
1.1287 + test.Next(_L("PIPE TEST:7.21 After Wait finish , close the hadles.\n"));
1.1288 + test (stat1.Int() == KErrNone);
1.1289 + ret = thread11_2.WaitForExitL();
1.1290 + test_KErrNone(ret);
1.1291 +
1.1292 + // Release all the resources.
1.1293 + aWriter.Close();
1.1294 + aReader.Close();
1.1295 + }
1.1296 +
1.1297 + ret = RPipe::Destroy(cPipeName);
1.1298 + test_KErrNone(ret);
1.1299 +
1.1300 + /**********************************************************/
1.1301 +
1.1302 + // Define the pipe.
1.1303 + ret = RPipe::Define( cPipeName,aSize);
1.1304 + test(ret == KErrNone);
1.1305 +
1.1306 + // Wait for Writer.
1.1307 + aReader.WaitForWriter(cPipeName, stat1);
1.1308 + // Try to open read end again. It should not open because WaitForWriter
1.1309 + // will has already opened the Read End of the pipe.
1.1310 + ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
1.1311 + test(ret = KErrInUse );
1.1312 + // Status of the wait request is pending because writer is not opened yet.
1.1313 + test (stat1.Int() == KRequestPending);
1.1314 +
1.1315 + // Wait on Reader.
1.1316 + aWriter.WaitForReader(cPipeName , stat2);
1.1317 + // Reader was already opened so status is KErrNone.
1.1318 + test ( stat2.Int() == KErrNone);
1.1319 +
1.1320 + // Try to open Write end. It should not allow because WaitForReader has
1.1321 + // already opened the write end of the pipe.
1.1322 + ret = aWriter.Open(cPipeName ,RPipe::EOpenToWrite);
1.1323 + test (ret == KErrInUse);
1.1324 +
1.1325 + // Check the status of the WaitForWriter request. It should be KErrNone now.
1.1326 + test (stat1.Int() == KErrNone);
1.1327 +
1.1328 + // Let's check for pipe attributes.
1.1329 + ret = aReader.MaxSize();
1.1330 + test (ret = aSize);
1.1331 + ret = aWriter.MaxSize();
1.1332 + test (ret = aSize);
1.1333 + ret = aReader.Size();
1.1334 + test (ret = aSize);
1.1335 + ret = aWriter.Size();
1.1336 + test (ret = aSize);
1.1337 +
1.1338 + // Close the Reade handle.
1.1339 + aReader.Close();
1.1340 +
1.1341 + // Put request to wait for Reader.
1.1342 + aWriter.WaitForReader(cPipeName , stat2);
1.1343 + // It should be pending.
1.1344 + test ( stat2.Int() == KRequestPending);
1.1345 + // Open the reader end of the pipe. It should allow , KErrNone
1.1346 + ret = aReader.Open(cPipeName ,RPipe::EOpenToRead );
1.1347 + test ( stat2.Int() == KErrNone);
1.1348 + test (ret == KErrNone);
1.1349 +
1.1350 + aReader.Close();
1.1351 + aWriter.Close();
1.1352 + ret=RPipe::Destroy(cPipeName);
1.1353 + test_KErrNone(ret);
1.1354 +
1.1355 + return;
1.1356 +
1.1357 +
1.1358 +}
1.1359 +
1.1360 +/****************************************************************************
1.1361 + This is a function to test notify mechanism of pipes.
1.1362 + Check the functionality of following library functions
1.1363 + - Notify...()
1.1364 +
1.1365 +
1.1366 +******************************************************************************/
1.1367 +void TestNotifyMechanismPipes() {
1.1368 + // Test NotifyDataAvailable , NotifySpaceAvailable
1.1369 + RSemaphore globalSem; // Handle to a global semaphore. Semaphore is used to maintain synchronisation between thread4 and the main thread
1.1370 + TInt ret; // Return Value variable.
1.1371 + RPipe aReader,aWriter; // Used to pass to thread.
1.1372 + RPipe aReader2,aWriter2; // Used to pass to thread.
1.1373 +
1.1374 + TInt aSize; // Used to pass to thread.
1.1375 + const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
1.1376 +
1.1377 + TRequestStatus stat1;
1.1378 + TBuf8<50> cPipeTestData1(KTestData2);
1.1379 +
1.1380 + const TBufC<50> cSemaphoreName(KSemaphoreName); // Descriptor conataining the name of the global semaphore.
1.1381 +
1.1382 +
1.1383 + ret = globalSem.CreateGlobal(cSemaphoreName,0); //create and open a global semaphore with initial count as 0.
1.1384 + test (ret == KErrNone);
1.1385 +
1.1386 + aSize = 22; // Size of KTestData * 10
1.1387 +
1.1388 + ret = RPipe::Create( aSize,
1.1389 + aReader,
1.1390 + aWriter,
1.1391 + EOwnerProcess, //
1.1392 + EOwnerProcess //
1.1393 + );
1.1394 +
1.1395 + TData data( &aReader, &aWriter);
1.1396 +
1.1397 + // Create Thread 4
1.1398 + // Pass TData object with Write and Read handle both
1.1399 + test.Next(_L("PIPE TEST:6.1 Call CancelDataAvailable/CancelSpaceAvailable using unopened RPipe handles.\n"));
1.1400 + ret = aReader2.CancelDataAvailable();
1.1401 + test ( ret == KErrBadHandle);
1.1402 + ret = aWriter2.CancelSpaceAvailable();
1.1403 + test (ret == KErrBadHandle);
1.1404 +
1.1405 + test.Next(_L("PIPE TEST:6.2 Call NotifySpaceAvailable with Negative size \n"));
1.1406 + // Call Notfifyspace
1.1407 + TInt tempsize = -1;
1.1408 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1409 + test ( stat1.Int() == KErrArgument);
1.1410 +
1.1411 + test.Next(_L("PIPE TEST:6.2a Call NotifySpaceAvailable for space larger than pipe.\n"));
1.1412 + aWriter.NotifySpaceAvailable(aSize+1, stat1);
1.1413 + test_Equal( KErrArgument, stat1.Int());
1.1414 +
1.1415 +
1.1416 + // Start the thread
1.1417 + {
1.1418 + TTestThread thread4(KThread4Name, TestThread4, &data);
1.1419 +
1.1420 + // Thread 4
1.1421 + // Call Notifydata available
1.1422 + // Loop for Available
1.1423 + // Read the data and validate
1.1424 +
1.1425 + test.Next(_L("PIPE TEST:6.3 Write data into the pipe , verify return value.\n"));
1.1426 + // Write one byte data into the pipe.
1.1427 + globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
1.1428 + ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1.1429 + test (ret == cPipeTestData1.Length());
1.1430 +
1.1431 +
1.1432 + test.Next(_L("PIPE TEST:6.4 Call NotifySpaceAvailable with valid parameters \n"));
1.1433 + tempsize = 1;
1.1434 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1435 + test(stat1==KRequestPending);
1.1436 + globalSem.Signal(); //signal that thread 4 may go ahead and read 1 byte
1.1437 +
1.1438 +
1.1439 + test.Next(_L("PIPE TEST:6.5 Wait till request says AVAILABLE. Available ?\n"));
1.1440 + User::WaitForRequest(stat1);
1.1441 + test ( stat1.Int() == KErrNone || stat1.Int() == KErrCompletion);
1.1442 +
1.1443 + // Thread 4
1.1444 + // Notify data available
1.1445 + // Loop for available
1.1446 + // Flush the buffer
1.1447 + // Register two request for Notifydata available
1.1448 + // Register two request for Notifyspace available
1.1449 + // Call Notifydata available using Read handle
1.1450 + // Call Notifydata available using write handle
1.1451 + // return
1.1452 +
1.1453 +
1.1454 + // Check for Error conditions
1.1455 +
1.1456 + // Flush buffer
1.1457 + globalSem.Wait(); // this is waiting for a signal from thread4
1.1458 + test.Next(_L("PIPE TEST:6.6 Register Notification for space availability. Allows ?\n"));
1.1459 + ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1.1460 + ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1.1461 + // Register two request for Notifyspace available
1.1462 +
1.1463 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1464 + test_Equal(KRequestPending, stat1.Int() );
1.1465 + test.Next(_L("PIPE TEST:6.7 Register One more Notification for space availability. Allows ?\n"));
1.1466 + TRequestStatus tempstat1;
1.1467 + aWriter.NotifySpaceAvailable(tempsize, tempstat1);
1.1468 + test ( tempstat1.Int() == KErrInUse);
1.1469 +
1.1470 + test.Next(_L("PIPE TEST:6.7a Cancellation of non-outstanding requests must not disrupt oustanding requests\n"));
1.1471 + aWriter.CancelWait();
1.1472 + aWriter.NotifySpaceAvailable(tempsize, tempstat1);
1.1473 + test_Equal( KErrInUse, tempstat1.Int());
1.1474 +
1.1475 + test.Next(_L("PIPE TEST:6.8 Cancel all the pending Notifications.\n"));
1.1476 + ret = aWriter.CancelSpaceAvailable();
1.1477 + test ( ret == KErrNone);
1.1478 + test_Equal(KErrCancel, stat1.Int() );
1.1479 +
1.1480 + test.Next(_L("PIPE TEST:6.9 Try to cancel some more notifications. It should not allow\n"));
1.1481 + ret = aWriter.CancelSpaceAvailable();
1.1482 + test ( ret == KErrNone);
1.1483 +
1.1484 + test.Next(_L("PIPE TEST:6.10 Register Notification for Data availability. Allows ?\n"));
1.1485 + // Register two request for Notifydata available
1.1486 + aWriter.Flush();
1.1487 + aReader.NotifyDataAvailable(stat1);
1.1488 +
1.1489 + test.Next(_L("PIPE TEST:6.11 Register One More Notification for Data availability. Allows ?\n"));
1.1490 +
1.1491 + aReader.NotifyDataAvailable(tempstat1);
1.1492 + test ( ( tempstat1.Int() == KErrInUse) || (tempstat1.Int() == KErrCompletion));
1.1493 +
1.1494 + test.Next(_L("PIPE TEST:6.12 Cancel all the pending Notifications for Data.\n"));
1.1495 + ret = aReader.CancelDataAvailable();
1.1496 + test ( ( ret == KErrNone) || (ret == KErrNotFound));
1.1497 + test (stat1.Int() == KErrCancel);
1.1498 +
1.1499 + test.Next(_L("PIPE TEST:6.13 Try to cancel some more notifications. It should not allow\n"));
1.1500 + ret = aReader.CancelDataAvailable();
1.1501 + test ( ret == KErrNone);
1.1502 +
1.1503 + test.Next(_L("PIPE TEST:6.14 Try to register Data available notification using Write handle. Should not allow.\n"));
1.1504 + aWriter.NotifyDataAvailable(stat1);
1.1505 + test ( stat1.Int() == KErrAccessDenied);
1.1506 +
1.1507 + test.Next(_L("PIPE TEST:6.15 Try to register Space available notification using Read handle. Should not allow.\n"));
1.1508 + aReader.NotifySpaceAvailable(tempsize, stat1);
1.1509 + test ( stat1.Int() == KErrAccessDenied);
1.1510 +
1.1511 + test.Next(_L("PIPE TEST:6.16 Try to Cancel Data available notification using Write handle. Should not allow.\n"));
1.1512 + ret = aWriter.CancelDataAvailable();
1.1513 + test ( ret == KErrAccessDenied);
1.1514 +
1.1515 + test.Next(_L("PIPE TEST:6.17 Try to Cancel Space available notification using Write handle. Should not allow.\n"));
1.1516 + ret = aReader.CancelSpaceAvailable();
1.1517 + test ( ret == KErrAccessDenied);
1.1518 +
1.1519 + // Stop the thread and Close the Thread
1.1520 + ret = thread4.WaitForExitL();
1.1521 + }
1.1522 + test_KErrNone(ret);
1.1523 + // Close all the pipe handles.
1.1524 + aReader.Close();
1.1525 + aWriter.Close();
1.1526 +
1.1527 +
1.1528 +
1.1529 + test.Printf(_L(" TEST NOTIFICATION MECHNISM FOR NAMED PIPES\n"));
1.1530 +
1.1531 + aSize = 22; // Size of KTestData
1.1532 +
1.1533 + test.Next(_L("PIPE TEST:6.18 Create Named pipe and Open Read/Write Handles.\n"));
1.1534 + ret = RPipe::Define( cPipeName,aSize);
1.1535 + test (ret == KErrNone);
1.1536 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1537 + test (ret == KErrNone);
1.1538 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1539 + test (ret == KErrNone);
1.1540 +
1.1541 +
1.1542 +
1.1543 + TData data2( &aReader, &aWriter);
1.1544 +
1.1545 + // Create Thread 4
1.1546 + // Pass TData object with Write and Read handle both
1.1547 + TTestThread thread4a(KThread4Name, TestThread4, &data2);
1.1548 +
1.1549 + // Thread 4
1.1550 + // Call Notifydata available
1.1551 + // Loop for Available
1.1552 + // Read the data and validate
1.1553 +
1.1554 + // Write one byte data into the pipe.
1.1555 + test.Next(_L("PIPE TEST:6.19 Write Data and check for return value.\n"));
1.1556 + globalSem.Wait(); //wait before writing to ensure that other thread can register Data Available request while pipe is empty.
1.1557 + ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1.1558 + test (ret == cPipeTestData1.Length());
1.1559 +
1.1560 + test.Next(_L("PIPE TEST:6.20 Register Notification for Space Available.\n"));
1.1561 + // Call Notfifyspace
1.1562 + tempsize = 1;
1.1563 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1564 + test(stat1==KRequestPending);
1.1565 + globalSem.Signal(); //signal that thread 4 may go ahead and read byte
1.1566 +
1.1567 + test.Next(_L("PIPE TEST:6.21 Wait till notified for Space Availanle.\n"));
1.1568 + User::WaitForRequest(stat1);
1.1569 + test ( stat1.Int() == KErrNone);
1.1570 +
1.1571 + // Thread 4
1.1572 + // Read one byte of data
1.1573 + // Thread 4
1.1574 + // Notify data available
1.1575 + // Loop for available
1.1576 + // Flush the buffer
1.1577 + // Register two request for Notifydata available
1.1578 + // Register two request for Notifyspace available
1.1579 + // Call Notifydata available using Read handle
1.1580 + // Call Notifydata available using write handle
1.1581 + // return
1.1582 +
1.1583 + globalSem.Wait(); //waiting for a signal from thread4.
1.1584 + test.Next(_L("PIPE TEST:6.22 Notify for Space available.\n"));
1.1585 + // Register two request for Notifydata available
1.1586 + ret = aWriter.Write(cPipeTestData1,cPipeTestData1.Length());
1.1587 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1588 +
1.1589 + test.Next(_L("PIPE TEST:6.23 Notify one more notifier for Space available.\n"));
1.1590 + // Register two request for Notifyspace available
1.1591 + TRequestStatus notifyStatus;
1.1592 + aWriter.NotifySpaceAvailable(tempsize, notifyStatus);
1.1593 + test ( notifyStatus.Int() == KErrInUse);
1.1594 +
1.1595 + aWriter.Flush();
1.1596 + aWriter.NotifySpaceAvailable(tempsize, stat1);
1.1597 + test ( stat1.Int() == KErrNone);
1.1598 +
1.1599 + test.Next(_L("PIPE TEST:6.24 Cancel Notify for Space available.\n"));
1.1600 + ret = aWriter.CancelSpaceAvailable();
1.1601 + test (( ret == KErrNotFound) ||( ret == KErrNone));
1.1602 + test.Next(_L("PIPE TEST:6.25 Cancel one more Notify for Space available.\n"));
1.1603 + ret = aWriter.CancelSpaceAvailable();
1.1604 + test ( ret == KErrNone);
1.1605 +
1.1606 + test.Next(_L("PIPE TEST:6.26 Register Notify for Data available.\n"));
1.1607 + // Register two request for Notifydata available
1.1608 +
1.1609 + aWriter.Flush();
1.1610 + TRequestStatus stat5,stat6;
1.1611 + aReader.NotifyDataAvailable(stat5);
1.1612 +
1.1613 + test.Next(_L("PIPE TEST:6.27 Register One more Notify for Data available.\n"));
1.1614 + // Register two request for Notifyspace available
1.1615 + aReader.NotifyDataAvailable(notifyStatus);
1.1616 + test ( notifyStatus.Int() == KErrInUse);
1.1617 + test.Next(_L("PIPE TEST:6.28 Cancel Notify for Data available.\n"));
1.1618 + ret = aReader.CancelDataAvailable();
1.1619 + test ( ret == KErrNone);
1.1620 + test (stat5.Int() == KErrCancel);
1.1621 +
1.1622 + test.Next(_L("PIPE TEST:6.29 Cancel One more Notify for Data available.\n"));
1.1623 + ret = aReader.CancelDataAvailable();
1.1624 + test ( ret == KErrNone);
1.1625 +
1.1626 + test.Next(_L("PIPE TEST:6.30 Register Notify for Data available using Write handle\n"));
1.1627 + aWriter.NotifyDataAvailable(stat6);
1.1628 + test ( stat6.Int() == KErrAccessDenied);
1.1629 +
1.1630 + test.Next(_L("PIPE TEST:6.31 Register Notify for Space available using Read handle\n"));
1.1631 + aReader.NotifySpaceAvailable(tempsize, stat6);
1.1632 + test ( stat6.Int() == KErrAccessDenied);
1.1633 +
1.1634 + test.Next(_L("PIPE TEST:6.32 Cancel Notify for Data available using Write handle\n"));
1.1635 + ret = aWriter.CancelDataAvailable();
1.1636 + test ( ret == KErrAccessDenied);
1.1637 +
1.1638 + test.Next(_L("PIPE TEST:6.33 Cancel Notify for Space available using Read handle\n"));
1.1639 + ret = aReader.CancelSpaceAvailable();
1.1640 + test ( ret == KErrAccessDenied);
1.1641 +
1.1642 + //close the handle to the global semaphore
1.1643 +
1.1644 + globalSem.Close();
1.1645 + // Stop the thread and Close the Thread
1.1646 + ret = thread4a.WaitForExitL();
1.1647 + test_KErrNone(ret);
1.1648 + aReader.Close();
1.1649 + aWriter.Close();
1.1650 + RPipe::Destroy(cPipeName);
1.1651 +
1.1652 +
1.1653 + return;
1.1654 +
1.1655 +
1.1656 +
1.1657 +} // End TestNotifyMechanismPipes()
1.1658 +
1.1659 +/****************************************************************************
1.1660 + This is a function to test Named pipes in Mutli process environment.
1.1661 + Check the functionality of following library functions
1.1662 + - Define ()
1.1663 + -
1.1664 +
1.1665 +
1.1666 +******************************************************************************/
1.1667 +
1.1668 +
1.1669 +_LIT8(KTestDataIP, "ABCDEFGHIJ");
1.1670 +
1.1671 +void TestMultiProcessNamedPipes() {
1.1672 +
1.1673 +_LIT(KPipeName5, "InterProcessPipe1");
1.1674 + TInt ret; // Return value variable
1.1675 + RProcess proc; // Process Handle
1.1676 + RPipe aWriter;
1.1677 + RPipe aWriterUN,aReaderUN;
1.1678 + const TBufC<150> cPipeName1(KPipeName5);
1.1679 +
1.1680 + TBufC8<150> cPipeWriteData1(KTestDataIP);
1.1681 + TInt aSize;
1.1682 + TRequestStatus stat1;
1.1683 + TBuf8<150> cPipeReadData1;
1.1684 +
1.1685 + aSize = 10;
1.1686 +
1.1687 + // Define Pipe with valid size.
1.1688 +
1.1689 + test.Next(_L("PIPE TEST:5.1 Define Pipe and Create UnNAmed pipe and pass handle to other process.\n"));
1.1690 + ret = RPipe::Define(cPipeName1, aSize);
1.1691 + test_KErrNone(ret);
1.1692 + ret = proc.Create(
1.1693 + KProcessName, // Launch t_pipe2.exe process
1.1694 + KNullDesC // No arguments passed to t_pipe2.exe
1.1695 + );
1.1696 +
1.1697 + if (ret != KErrNone) {
1.1698 + // Check for process successfully launched
1.1699 + test.Printf(_L("Error : Could not start the process t_pipe2.exe \n"));
1.1700 + }
1.1701 + test_KErrNone(ret);
1.1702 + TRequestStatus procLogon;
1.1703 + proc.Logon(procLogon);
1.1704 + test(procLogon==KRequestPending);
1.1705 +
1.1706 + aSize = 512;
1.1707 + ret = RPipe::Create( aSize,
1.1708 + aReaderUN,
1.1709 + aWriterUN,
1.1710 + EOwnerProcess,//TOwnerType aTypeW
1.1711 + EOwnerProcess //TOwnerType aTypeW
1.1712 + );
1.1713 + test_KErrNone(ret);
1.1714 +
1.1715 + ret = aWriterUN.Write(KTestData,22);
1.1716 + test (ret == 22);
1.1717 + ret = aReaderUN.Read(cPipeReadData1,10);
1.1718 + test ( ret == 10);
1.1719 + aWriterUN.Close();
1.1720 + ret = aReaderUN.Read(cPipeReadData1,6);
1.1721 + test (ret == 6);
1.1722 + aReaderUN.NotifyDataAvailable(stat1);
1.1723 + ret = stat1.Int();
1.1724 + test (ret == KErrNone);
1.1725 + ret = aReaderUN.ReadBlocking(cPipeReadData1,6);
1.1726 + test (ret == 6);
1.1727 + ret = aReaderUN.Read(cPipeReadData1,1);
1.1728 + test ( ret == KErrNotReady);
1.1729 + ret = aReaderUN.ReadBlocking(cPipeReadData1,1);
1.1730 + test ( ret == KErrNotReady);
1.1731 + aReaderUN.Close();
1.1732 +
1.1733 + ret = RPipe::Create( aSize,
1.1734 + aReaderUN,
1.1735 + aWriterUN,
1.1736 + EOwnerProcess,//TOwnerType aTypeW
1.1737 + EOwnerProcess //TOwnerType aTypeW
1.1738 + );
1.1739 + test_KErrNone(ret);
1.1740 + proc.SetParameter(3,aReaderUN);
1.1741 + aReaderUN.Close();
1.1742 + ret = aWriterUN.Write(KTestData,22);
1.1743 + test (ret == 22 );
1.1744 +
1.1745 + proc.Resume();
1.1746 +
1.1747 + aSize = 10;
1.1748 + test.Next(_L("PIPE TEST:5.2 Open Write handle to Pipe. Wait till Read handle Opened\n"));
1.1749 + ret = aWriter.Open(cPipeName1, RPipe::EOpenToWrite);
1.1750 + test_KErrNone(ret);
1.1751 + aWriter.Wait(cPipeName1,stat1);
1.1752 + User::WaitForRequest(stat1);
1.1753 + test (stat1.Int() == KErrNone);
1.1754 +
1.1755 + test.Next(_L("PIPE TEST:5.3 Write data to Pipe.\n"));
1.1756 + ret = aWriter.Write(cPipeWriteData1,cPipeWriteData1.Length());
1.1757 + test ( ret == cPipeWriteData1.Length());
1.1758 +
1.1759 + test.Next(_L("PIPE TEST:5.4 Wait till Space Available in Pipe.\n"));
1.1760 + aWriter.NotifySpaceAvailable(aSize,stat1);
1.1761 + User::WaitForRequest(stat1);
1.1762 +
1.1763 + test.Next(_L("PIPE TEST:5.5 Write the data using WriteBlocking call\n"));
1.1764 + test_Equal(0, aWriter.Size());
1.1765 + ret = aWriter.WriteBlocking(cPipeWriteData1,cPipeWriteData1.Length());
1.1766 + test ( ret ==cPipeWriteData1.Length() );
1.1767 +
1.1768 + User::WaitForRequest(procLogon);
1.1769 +
1.1770 + aWriter.Close();
1.1771 + ret=RPipe::Destroy(cPipeName1);
1.1772 + test_KErrNone(ret);
1.1773 +
1.1774 + proc.Close();
1.1775 + aWriterUN.Close();
1.1776 + aReaderUN.Close();
1.1777 + return;
1.1778 +
1.1779 +} // End TestMultiProcessNamedPipes ()
1.1780 +/****************************************************************************
1.1781 + This is a function to test Named pipes in Multi threaded environment.
1.1782 + Check the functionality of following library functions
1.1783 + - Define ()
1.1784 + - Read()
1.1785 + - Write()
1.1786 + - ReadBlocking()
1.1787 + - WriteBlocking()
1.1788 +
1.1789 +
1.1790 +******************************************************************************/
1.1791 +//
1.1792 +// Test defining and opening both ends of pipe
1.1793 +// Attempt to readblock from pipe closed at far end (should fail)
1.1794 +// Attemp writeblock to pipe closed at far end
1.1795 +//
1.1796 +// Do some normal reading and writing between threads
1.1797 +// do some blocking read/write between threads
1.1798 +void TestMultiThreadNamedPipes() {
1.1799 +
1.1800 + TInt ret; // Return Value variable.
1.1801 + RPipe aReader,aWriter; // Used to pass to thread.
1.1802 + TInt aSize; // Used to pass to thread.
1.1803 + const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
1.1804 + TInt aReadSize;
1.1805 + TBuf8<150> cPipeReadData;
1.1806 + TBufC8<50> cTestData(KTestData); // Test Data
1.1807 +
1.1808 +
1.1809 +
1.1810 +
1.1811 +///////////////////////////////////////////////////////////
1.1812 +// PART : 1 ///
1.1813 +// Test Read and Write Functionality ///
1.1814 +///////////////////////////////////////////////////////////
1.1815 +
1.1816 + test.Next(_L("PIPE TEST:4.1 Define Pipe , Open Read and Write Handle.\n"));
1.1817 + aSize = 22;
1.1818 + ret = RPipe::Define( cPipeName,aSize);
1.1819 + test (ret == KErrNone);
1.1820 +
1.1821 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1822 + test (ret == KErrNone);
1.1823 +
1.1824 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1825 + test (ret == KErrNone);
1.1826 +
1.1827 + aWriter.Close();
1.1828 +
1.1829 + test.Next(_L("PIPE TEST:4.2 ReadBlocking: Check for KErrNotReady.\n"));
1.1830 + aReadSize = 1;
1.1831 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.1832 + test (ret == KErrNotReady);
1.1833 +
1.1834 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1835 + test (ret == KErrNone);
1.1836 +
1.1837 +
1.1838 + aReader.Close();
1.1839 + test.Next(_L("PIPE TEST:4.3 WriteBlocking: Check for KErrNotReady.\n"));
1.1840 + ret = aWriter.WriteBlocking(cTestData,cTestData.Length());
1.1841 + test (ret == KErrNotReady);
1.1842 +
1.1843 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1844 + test (ret == KErrNone);
1.1845 +
1.1846 +
1.1847 + TData data( &aReader, &aWriter);
1.1848 +
1.1849 +
1.1850 +
1.1851 +
1.1852 + // Write data to Pipe using valid handle
1.1853 + test.Next(_L("PIPE TEST:4.4 Write into the pipe and verify return value.\n"));
1.1854 + ret = aWriter.Write(cTestData,cTestData.Length());
1.1855 + test (ret == cTestData.Length() );
1.1856 +
1.1857 +
1.1858 + // Keep writing the data into pipe till it overflows
1.1859 +
1.1860 + test.Next(_L("PIPE TEST:4.5 Write into the pipe till it overflows.\n"));
1.1861 + ret = aWriter.Write(cTestData,cTestData.Length());
1.1862 + test (( ret == KErrOverflow)) ;
1.1863 +
1.1864 + // Start the thread.
1.1865 + TTestThread thread2(KThread2Name, TestThread2, &data);
1.1866 + // Read 1 byte data from pipe
1.1867 + // Validate data
1.1868 + // Read aByte size data
1.1869 + // Validate data
1.1870 + // Thread 2
1.1871 + // Read aByte size data
1.1872 + // User:: After (10000)
1.1873 + // Keep reading data till zero return
1.1874 + // return
1.1875 +
1.1876 + // Stop the thread and Close the Thread
1.1877 + ret = thread2.WaitForExitL();
1.1878 + test_KErrNone(ret);
1.1879 +
1.1880 + aReader.Close();
1.1881 + aWriter.Close();
1.1882 + ret = RPipe::Destroy(cPipeName);
1.1883 + test_KErrNone(ret);
1.1884 +
1.1885 +
1.1886 +///////////////////////////////////////////////////////////
1.1887 +// PART : 2 ///
1.1888 +// Test ReadBlocking and WriteBlocking Functionality ///
1.1889 +///////////////////////////////////////////////////////////
1.1890 +
1.1891 + // Test Read and Write blocking call
1.1892 +
1.1893 + test.Next(_L("PIPE TEST:4.6 Create UnNamed Pipe with valid size.\n"));
1.1894 +
1.1895 + aSize = 22;
1.1896 + ret = RPipe::Define( cPipeName,aSize);
1.1897 + test (ret == KErrNone);
1.1898 +
1.1899 + ret = aReader.Open(cPipeName,RPipe::EOpenToRead);
1.1900 + test (ret == KErrNone);
1.1901 +
1.1902 + ret = aWriter.Open(cPipeName,RPipe::EOpenToWrite);
1.1903 + test (ret == KErrNone);
1.1904 +
1.1905 + // Create TData object to pass Pipe handles.
1.1906 + TData data2( &aReader, &aWriter);
1.1907 +
1.1908 +
1.1909 + // Create Thread ( Note : Thread is in pending state now)
1.1910 + // Flush the data if any in pipe to make sure its empty.
1.1911 + aWriter.Flush();
1.1912 +
1.1913 + // Start the thread
1.1914 + TTestThread thread3(KThread3Name, TestThread3, &data2);
1.1915 + // Thread 3
1.1916 + // Write one byte of data
1.1917 + // Write one one byte of data using WriteBlocking call
1.1918 + // Write aByte size data using Writblocking call
1.1919 +
1.1920 +
1.1921 + // Call Readblocking function.Read one byte of data.
1.1922 + test.Next(_L("PIPE TEST:4.7 Flush the buffer and Call ReadBlocking one byte into the pipe.\n"));
1.1923 + aReadSize = 1;
1.1924 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.1925 + test_Equal(aReadSize, ret);
1.1926 +
1.1927 + test.Next(_L("PIPE TEST:4.8 Verify the data received.\n"));
1.1928 + test ( KErrNone == cPipeReadData.Compare(KTestData1));
1.1929 +
1.1930 +
1.1931 + test.Next(_L("PIPE TEST:4.9 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
1.1932 + // Call Readblocking function.Read aSize bytes of data.
1.1933 + aReadSize = aSize-aReadSize; //read rest of data
1.1934 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.1935 + test_Equal(aReadSize, ret);
1.1936 + test ( KErrNone == cPipeReadData.Compare(KTestData3));
1.1937 +
1.1938 + // Thread 3
1.1939 + // Wait for some time
1.1940 + // Call Readblocking and read 1 byte of data
1.1941 + // Call Readblocking and Read abyte size data
1.1942 + // Call flush buffer
1.1943 + // return
1.1944 + test.Next(_L("PIPE TEST:4.10 Call ReadBlocking and read complete data from Pipe. As big as Pipe Size\n"));
1.1945 + // Call Readblocking function.Read aSize bytes of data.
1.1946 + aReadSize = aSize;
1.1947 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.1948 + test_Equal(aReadSize, ret);
1.1949 + test ( KErrNone == cPipeReadData.Compare(KTestData2));
1.1950 +
1.1951 + // Stop the thread and Close the Thread
1.1952 + ret = thread3.WaitForExitL();
1.1953 + test_KErrNone(ret);
1.1954 +
1.1955 + aReader.Close();
1.1956 + aWriter.Close();
1.1957 + ret=RPipe::Destroy(cPipeName);
1.1958 + test_KErrNone(ret);
1.1959 + return ;
1.1960 +
1.1961 +} // End TestMultiThreadNamedPipes ()
1.1962 +
1.1963 +
1.1964 +/****************************************************************************
1.1965 + This is a function to test UnNamed pipes in Multi threaded environment.
1.1966 + Check the functionality of following library functions
1.1967 + - Create()
1.1968 + - Read()
1.1969 + - Write()
1.1970 + - ReadBlocking()
1.1971 + - WriteBlocking()
1.1972 +
1.1973 +
1.1974 +******************************************************************************/
1.1975 +void TestMultiThreadUnNamedPipes() {
1.1976 +
1.1977 + TInt ret; // Return Value variable.
1.1978 + RPipe aReader,aWriter; // Used to pass to thread.
1.1979 + TInt aSize; // Used to pass to thread.
1.1980 + TBuf8<250> cPipeReadData;
1.1981 + TInt aReadSize;
1.1982 + TBufC8<50> cTestData(KTestData); // Test Data
1.1983 +
1.1984 +
1.1985 +///////////////////////////////////////////////////////////
1.1986 +// PART : 1 ///
1.1987 +// Test Read and Write Functionality ///
1.1988 +///////////////////////////////////////////////////////////
1.1989 +
1.1990 + test.Next(_L("PIPE TEST: 3.1 Create Pipe : Check for no erros on Pipe Creation \n"));
1.1991 + ret = 100;
1.1992 + aSize = 22; // Size of KTestData * 10
1.1993 +
1.1994 + ret = RPipe::Create( aSize,
1.1995 + aReader,
1.1996 + aWriter,
1.1997 + EOwnerProcess ,//TOwnerType aTypeW
1.1998 + EOwnerProcess //TOwnerType aTypeW
1.1999 + );
1.2000 +
1.2001 + test (ret == KErrNone);
1.2002 +
1.2003 + // Create TData object to pass Pipe handles.
1.2004 + TData data1( &aReader, &aWriter);
1.2005 +
1.2006 + // Create Thread ( Note : Thread is in pending state now)
1.2007 +
1.2008 + // Create test data stream.
1.2009 + test.Next(_L("PIPE TEST: 3.2 Write Function test : Write data into the pipe \n"));
1.2010 + ret = aWriter.Write(cTestData,cTestData.Length()); // Write ""Pipe Data To Be Passed"
1.2011 + test (ret == cTestData.Length());
1.2012 +
1.2013 + // Keep writing the data into pipe till it overflows
1.2014 + test.Next(_L("PIPE TEST: 3.3 Write Data till the Pipe returns KErrOverFlow\n"));
1.2015 + ret = aWriter.Write(cTestData,cTestData.Length());
1.2016 + test ( ret == KErrOverflow);
1.2017 +
1.2018 + TTestThread thread2(KThread2Name, TestThread2, &data1);
1.2019 + // Thread2
1.2020 + // Read 1 byte data from pipe
1.2021 + // Validate data
1.2022 + // Read aByte size data
1.2023 + // Validate data
1.2024 + // Thread 2
1.2025 + // Read aByte size data
1.2026 + // User:: After (10000)
1.2027 + // Keep reading data till zero return
1.2028 + // return
1.2029 +
1.2030 + // Stop the thread , Close it.
1.2031 +
1.2032 + ret = thread2.WaitForExitL();
1.2033 + test_KErrNone(ret);
1.2034 +
1.2035 + aReader.Close();
1.2036 + aWriter.Close();
1.2037 +
1.2038 +
1.2039 +///////////////////////////////////////////////////////////
1.2040 +// PART : 2 ///
1.2041 +// Test ReadBlocking and WriteBlocking Functionality ///
1.2042 +///////////////////////////////////////////////////////////
1.2043 +
1.2044 +
1.2045 + aSize = 22; // Size of KTestData
1.2046 +
1.2047 + ret = RPipe::Create( aSize,
1.2048 + aReader,
1.2049 + aWriter,
1.2050 + EOwnerProcess , //TOwnerType aTypeW
1.2051 + EOwnerProcess //TOwnerType aTypeW
1.2052 + );
1.2053 + test_KErrNone(ret);
1.2054 +
1.2055 + // Create TData object to pass Pipe handles.
1.2056 +
1.2057 + TData data2(&aReader, &aWriter);
1.2058 +
1.2059 + // Flush the data if any in pipe to make sure its empty.
1.2060 + aWriter.Flush();
1.2061 +
1.2062 + // Start the thread
1.2063 + TTestThread thread3(KThread3Name, TestThread3, &data2);
1.2064 + // Thread 3
1.2065 + // Write one byte of data
1.2066 + // Write one one byte of data using WriteBlocking call
1.2067 + // Write aByte size data using Writblocking call
1.2068 +
1.2069 +
1.2070 + // Call Readblocking function.Read one byte of data.
1.2071 +
1.2072 + aReadSize = 1;
1.2073 + test.Next(_L("PIPE TEST: 3.4 : Call readblocking and read one byte of data \n"));
1.2074 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.2075 + // Call goes to Thread 3
1.2076 + test_Equal(aReadSize, ret);
1.2077 +
1.2078 + test.Next(_L("PIPE TEST: 3.5 : Validate the data \n"));
1.2079 + test_Equal(0, cPipeReadData.Compare(KTestData1));
1.2080 +
1.2081 +
1.2082 + // Call Readblocking function.Read aSize bytes of data.
1.2083 + test.Next(_L("PIPE TEST: 3.6 : Read remaining data \n"));
1.2084 + aReadSize = 21;
1.2085 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.2086 + test_Equal(aReadSize, ret);
1.2087 + test_Equal(0, cPipeReadData.Compare(KTestData3));
1.2088 +
1.2089 +
1.2090 + test.Next(_L("PIPE TEST: 3.7 : Read complete pipe size data \n"));
1.2091 + aReadSize = 22;
1.2092 + ret = aReader.ReadBlocking(cPipeReadData,aReadSize);
1.2093 + test_Equal(aReadSize, ret);
1.2094 + test_Equal(0, cPipeReadData.Compare(KTestData2));
1.2095 +
1.2096 + // Wait for thread to end and Close
1.2097 + ret = thread3.WaitForExitL();
1.2098 + test_KErrNone(ret);
1.2099 +
1.2100 + aReader.Close();
1.2101 + aWriter.Close();
1.2102 +
1.2103 + return ;
1.2104 +
1.2105 +
1.2106 +}// End TestMultiThreadUnNamedPipes()
1.2107 +
1.2108 +/****************************************************************************
1.2109 + This is a function to test Named pipes in Single threaded environment.
1.2110 + Check the functionality of following library functions
1.2111 + - Define ()
1.2112 + -
1.2113 +
1.2114 +
1.2115 +******************************************************************************/
1.2116 +
1.2117 +void TestSingleThreadNamedPipes()
1.2118 +
1.2119 +{
1.2120 +
1.2121 +
1.2122 + const TBufC<50> cPipeName(KPipe1Name); // Descriptor to hold data for Writing.
1.2123 + TInt aSize, ret;
1.2124 + RPipe testPipe1;
1.2125 + RPipe testPipe2;
1.2126 + RPipe testPipe3;
1.2127 + RPipe testPipe4;
1.2128 + RPipe testPipe5;
1.2129 + const TBufC<100> cPipeNameMax(KMaxPipeName);
1.2130 + const TBufC<100> cPipeNameMaxPlusOne(KMaxPipeNamePlusOne);
1.2131 +
1.2132 + _LIT(KBadName , "***?SFSDFWE?*_-");
1.2133 + _LIT(KBadName2 , "");
1.2134 +
1.2135 + test.Next(_L("PIPE TEST: 2.1 Define Function test : Check for No Error\n"));
1.2136 + aSize = 10;
1.2137 +
1.2138 + ret = RPipe::Define(cPipeName , aSize);
1.2139 + test (ret == KErrNone);
1.2140 +
1.2141 + ret = RPipe::Destroy (cPipeName);
1.2142 + test (ret == KErrNone);
1.2143 +
1.2144 +
1.2145 +
1.2146 + test.Next(_L("PIPE TEST: 2.2 Define Function test : Check for Max length \n"));
1.2147 +
1.2148 + aSize = 10;
1.2149 +
1.2150 + ret = RPipe::Define(cPipeNameMax , aSize);
1.2151 + test (ret == KErrNone);
1.2152 +
1.2153 + ret = RPipe::Destroy (cPipeNameMax);
1.2154 + test (ret == KErrNone);
1.2155 +
1.2156 + test.Next(_L("PIPE TEST: 2.3 Define Function test : Check for Max length \n"));
1.2157 +
1.2158 + aSize = 10;
1.2159 + ret = RPipe::Define(cPipeNameMaxPlusOne , aSize);
1.2160 + test (ret == KErrBadName);
1.2161 + ret = RPipe::Destroy (cPipeNameMaxPlusOne);
1.2162 + test (ret == KErrBadName);
1.2163 +
1.2164 + test.Next(_L("PIPE TEST: 2.4 Open Function test : Test Open \n"));
1.2165 + aSize = 10;
1.2166 + ret = RPipe::Define(cPipeName , aSize);
1.2167 + test_KErrNone(ret);
1.2168 +
1.2169 + ret = testPipe1.Open(KBadName,RPipe::EOpenToRead);
1.2170 + test (ret == KErrBadName);
1.2171 +
1.2172 + ret = testPipe1.Open(KBadName2,RPipe::EOpenToRead);
1.2173 + test (ret == KErrBadName);
1.2174 +
1.2175 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
1.2176 + test (ret == KErrNone);
1.2177 +
1.2178 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToWrite);
1.2179 + test (ret == KErrInUse);
1.2180 +
1.2181 +
1.2182 +
1.2183 + test.Next(_L("PIPE TEST: 2.5 Destroy Function test : Destroy opened pipe error \n"));
1.2184 + ret = RPipe::Destroy (cPipeName);
1.2185 + test (ret == KErrInUse);
1.2186 +
1.2187 + test.Next(_L("PIPE TEST: 2.6 Open Function test : Reopen pipe for reading\n"));
1.2188 + ret = testPipe2.Open(cPipeName,RPipe::EOpenToRead);
1.2189 + test (ret == KErrInUse);
1.2190 +
1.2191 + test.Next(_L("PIPE TEST: 2.7 Open Function test : Bad name test \n"));
1.2192 + ret = testPipe2.Open(cPipeNameMaxPlusOne,RPipe::EOpenToRead);
1.2193 + test (ret == KErrBadName);
1.2194 +
1.2195 +
1.2196 + test.Next(_L("PIPE TEST: 2.8 Open Function test : Write mode test\n"));
1.2197 +
1.2198 + ret = testPipe3.Open(cPipeName,RPipe::EOpenToWrite);
1.2199 + test (ret == KErrNone);
1.2200 +
1.2201 + ret = testPipe3.Open(cPipeName,RPipe::EOpenToRead);
1.2202 + test (ret == KErrInUse);
1.2203 +
1.2204 + test.Next(_L("PIPE TEST: 2.9 Open Function test : Bad name test \n"));
1.2205 +
1.2206 + ret = testPipe4.Open(cPipeNameMaxPlusOne,RPipe::EOpenToWrite);
1.2207 + test (ret == KErrBadName);
1.2208 +
1.2209 +
1.2210 + test.Next(_L("PIPE TEST: 2.10 Open Function test : Reopen for writing \n"));
1.2211 + ret = testPipe4.Open(cPipeName,RPipe::EOpenToWrite);
1.2212 + test (ret == KErrInUse);
1.2213 +
1.2214 +
1.2215 + // Do we have pipes created ? Close and Destroy them ....!!
1.2216 +
1.2217 + testPipe1.Close();
1.2218 + testPipe2.Close();
1.2219 + testPipe3.Close();
1.2220 + testPipe4.Close();
1.2221 + ret = RPipe::Destroy (cPipeName);
1.2222 + test_KErrNone(ret);
1.2223 +
1.2224 +
1.2225 +
1.2226 + test.Next(_L("PIPE TEST: 2.11a Open Function test : Write But Fail on no Readers mode before pipe defined\n"));
1.2227 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
1.2228 + test_Equal(KErrNotFound,ret);
1.2229 +
1.2230 + test.Next(_L("PIPE TEST: 2.11 Open Function test : Write But Fail on no Readers mode Error test\n"));
1.2231 + ret = RPipe::Define(cPipeName , aSize);
1.2232 + test (ret == KErrNone);
1.2233 +
1.2234 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
1.2235 + test (ret == KErrNotReady);
1.2236 +
1.2237 +
1.2238 + test.Next(_L("PIPE TEST: 2.12 Open Function test : Write But Fail on no Readers mode Success test\n"));
1.2239 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
1.2240 + test_KErrNone(ret);
1.2241 + ret = testPipe2.Open(cPipeName,RPipe::EOpenToWriteNamedPipeButFailOnNoReaders);
1.2242 + test ( ret == KErrNone);
1.2243 +
1.2244 +
1.2245 + // Do we have pipes created ? Close and Destroy them ....!!
1.2246 +
1.2247 + testPipe1.Close();
1.2248 + testPipe2.Close();
1.2249 + testPipe3.Close();
1.2250 + testPipe4.Close();
1.2251 + ret = RPipe::Destroy (cPipeName);
1.2252 + test_KErrNone(ret);
1.2253 +
1.2254 +
1.2255 +
1.2256 + test.Next(_L(" 2.13 Define Function test : Check Incorrect Size\n"));
1.2257 + aSize = -1;
1.2258 + ret = RPipe::Define(cPipeName , aSize);
1.2259 + test (ret == KErrArgument);
1.2260 +
1.2261 +
1.2262 + test.Next(_L("PIPE TEST: 2.14 Define Function test : Check Incorrect Size\n"));
1.2263 + aSize = 0x1fffffff;
1.2264 + ret = RPipe::Define(cPipeName , aSize);
1.2265 + test (ret == KErrNoMemory);
1.2266 +
1.2267 +
1.2268 + test.Next(_L("PIPE TEST: 2.15 Size Function test : Size\n"));
1.2269 + aSize = 10;
1.2270 + ret = RPipe::Define(cPipeName , aSize);
1.2271 +
1.2272 + ret = testPipe5.MaxSize();
1.2273 + test (ret == KErrBadHandle);
1.2274 +
1.2275 +
1.2276 + test.Next(_L("PIPE TEST: 2.16 Size Function test : Size\n"));
1.2277 + aSize = 10;
1.2278 + ret = RPipe::Define(cPipeName , aSize);
1.2279 + testPipe5.Open(cPipeName, RPipe::EOpenToRead);
1.2280 + testPipe4.Open(cPipeName, RPipe::EOpenToWrite);
1.2281 + ret = testPipe5.MaxSize();
1.2282 + test (ret == aSize);
1.2283 + ret = testPipe4.MaxSize();
1.2284 + test (ret == aSize);
1.2285 +
1.2286 +
1.2287 + /* Close all the pipes and Destroy*/
1.2288 + testPipe1.Close();
1.2289 + testPipe2.Close();
1.2290 + testPipe3.Close();
1.2291 + testPipe4.Close();
1.2292 + testPipe5.Close();
1.2293 + ret = RPipe::Destroy (cPipeName);
1.2294 + test_KErrNone(ret);
1.2295 +
1.2296 + _LIT(KRedefinePipe , "REDEFINEPIPE");
1.2297 +
1.2298 + test.Next(_L("PIPE TEST: 2.17 Check for Redefining same pipe name \n"));
1.2299 + ret = RPipe::Define(KRedefinePipe , aSize);
1.2300 + test_KErrNone(ret);
1.2301 + ret = RPipe::Define(KRedefinePipe , aSize);
1.2302 + test (ret == KErrAlreadyExists);
1.2303 + ret = RPipe::Destroy (KRedefinePipe);
1.2304 + test_KErrNone(ret);
1.2305 +
1.2306 + test.Next(_L("PIPE TEST: 2.18 Open Function test : Bad Pipe name\n"));
1.2307 + aSize = 10;
1.2308 + RPipe testPipe6;
1.2309 + ret = testPipe6.Open(cPipeName, RPipe::EOpenToRead);
1.2310 + test (ret == KErrNotFound);
1.2311 +
1.2312 +
1.2313 + const TBufC<50> cPipeNameNull;
1.2314 + test.Next(_L("PIPE TEST: 2.19 Define Function test : Null Pipe name and Bad Pipe name\n"));
1.2315 + aSize = 10;
1.2316 + ret = RPipe::Define(cPipeNameNull , aSize);
1.2317 + test (ret == KErrBadName);
1.2318 +
1.2319 +
1.2320 + ret = RPipe::Define(KBadName , aSize);
1.2321 + test (ret == KErrBadName);
1.2322 + ret = RPipe::Destroy(KBadName);
1.2323 + test (ret == KErrBadName);
1.2324 +
1.2325 +
1.2326 + ret = RPipe::Define(KBadName2 , aSize);
1.2327 + test (ret == KErrBadName);
1.2328 + ret = RPipe::Destroy(KBadName2);
1.2329 + test (ret == KErrBadName);
1.2330 +
1.2331 +
1.2332 + test.Next(_L("PIPE TEST: 2.20 Destroy a pipe while Write end is open\n"));
1.2333 + ret = RPipe::Define(cPipeName , aSize);
1.2334 +
1.2335 + testPipe1.Close();
1.2336 + ret = testPipe1.Open(cPipeName,RPipe::EOpenToRead);
1.2337 + test (ret == KErrNone);
1.2338 + testPipe2.Close();
1.2339 + ret = testPipe2.Open(cPipeName,RPipe::EOpenToWrite);
1.2340 + test (ret == KErrNone);
1.2341 + testPipe1.Close();
1.2342 + ret = RPipe::Destroy (cPipeName);
1.2343 + test (ret == KErrInUse);
1.2344 +
1.2345 + testPipe2.Close();
1.2346 + ret = RPipe::Destroy (cPipeName);
1.2347 + test (ret == KErrNone);
1.2348 +
1.2349 + testPipe1.Close();
1.2350 + testPipe2.Close();
1.2351 + testPipe3.Close();
1.2352 + testPipe4.Close();
1.2353 + testPipe5.Close();
1.2354 +
1.2355 +
1.2356 + _LIT(KPipe1Name,"TestPipeA");
1.2357 + _LIT(KPipe2Name,"TestPipeB");
1.2358 + _LIT(KPipe3Name,"TestPipeC");
1.2359 + _LIT(KPipe4Name,"TestPipeD");
1.2360 +
1.2361 + test.Next(_L("PIPE TEST: 2.21 Define Four pipes and Destroy in different sequence ( Code Coverage test)\n"));
1.2362 + ret = RPipe::Define(KPipe1Name , aSize);
1.2363 + test (ret == KErrNone);
1.2364 + ret = RPipe::Define(KPipe2Name , aSize);
1.2365 + test (ret == KErrNone);
1.2366 + ret = RPipe::Define(KPipe3Name , aSize);
1.2367 + test (ret == KErrNone);
1.2368 + ret = RPipe::Define(KPipe4Name , aSize);
1.2369 + test (ret == KErrNone);
1.2370 + ret = RPipe::Destroy (KPipe2Name);
1.2371 + test (ret == KErrNone);
1.2372 + ret = RPipe::Destroy (KPipe4Name);
1.2373 + test (ret == KErrNone);
1.2374 + ret = RPipe::Destroy (KPipe1Name);
1.2375 + test (ret == KErrNone);
1.2376 + ret = RPipe::Destroy (KPipe3Name);
1.2377 + test (ret == KErrNone);
1.2378 +
1.2379 + return;
1.2380 +
1.2381 +} // End TestSingleThreadNamedPipes()
1.2382 +
1.2383 +/****************************************************************************
1.2384 + This is a function to test UnNamed pipes in Single threaded environment.
1.2385 + Check the functionality of following library functions
1.2386 + - Create ()
1.2387 + -
1.2388 +
1.2389 +
1.2390 +******************************************************************************/
1.2391 +
1.2392 +_LIT8(KTxtDataToSend,"*Test data to send**");
1.2393 +
1.2394 +void TestSingleThreadUnNamedPipes() {
1.2395 +
1.2396 + TInt ret = 1; // Return value test variable.
1.2397 + TInt aSize;
1.2398 + TBufC8<40> wData(KTxtDataToSend); // Descriptor to hold data for Writing.
1.2399 + RPipe aReader,aWriter;
1.2400 + RPipe aReader2,aWriter2;
1.2401 +
1.2402 +
1.2403 + // Following tests will verify all the APIs in single thread
1.2404 + // for all the possible return values.
1.2405 + // This is to verify different paths of API
1.2406 + // not for detail functional verification.
1.2407 + // Create the Pipe and Check for No Errors when Valid parameters are passed.
1.2408 +
1.2409 + test.Next(_L("PIPE TEST:1.1 Create Function test : Check for No Error\n"));
1.2410 + aSize = 10;
1.2411 +
1.2412 + ret = RPipe::Create( aSize,
1.2413 + aReader,
1.2414 + aWriter,
1.2415 + EOwnerProcess,//TOwnerType aTypeW
1.2416 + EOwnerProcess //TOwnerType aTypeW
1.2417 + );
1.2418 +
1.2419 + test (ret == KErrNone);
1.2420 +
1.2421 + ret = RPipe::Create( aSize,
1.2422 + aReader,
1.2423 + aWriter,
1.2424 + EOwnerProcess,//TOwnerType aTypeW
1.2425 + EOwnerProcess //TOwnerType aTypeW
1.2426 + );
1.2427 +
1.2428 + test (ret == KErrInUse);
1.2429 +
1.2430 + aWriter.Close();
1.2431 + aReader.Close();
1.2432 +
1.2433 +
1.2434 + // How big pipe we can create ?
1.2435 +
1.2436 + test.Next(_L("PIPE TEST:1.2 Create Function test : Check for No Memory\n"));
1.2437 +
1.2438 + aSize = 0x1BCDEFFF;
1.2439 +
1.2440 + ret = RPipe::Create( aSize,
1.2441 + aReader2,
1.2442 + aWriter2,
1.2443 + EOwnerProcess,//TOwnerType aTypeW
1.2444 + EOwnerProcess //TOwnerType aTypeW
1.2445 + );
1.2446 +
1.2447 + test (ret == KErrNoMemory);
1.2448 +
1.2449 + aReader2.Close();
1.2450 + aWriter2.Close();
1.2451 +
1.2452 +
1.2453 + test.Next(_L("PIPE TEST:1.3 Create Function test : Check for Reopening pipe\n"));
1.2454 + aSize = 10;
1.2455 +
1.2456 + ret = RPipe::Create( aSize,
1.2457 + aReader,
1.2458 + aWriter,
1.2459 + EOwnerProcess,//TOwnerType aTypeW
1.2460 + EOwnerProcess//TOwnerType aTypeW
1.2461 + );
1.2462 + test_KErrNone(ret);
1.2463 +
1.2464 +
1.2465 + ret = RPipe::Create( aSize,
1.2466 + aReader,
1.2467 + aWriter,
1.2468 + EOwnerProcess,//TOwnerType aTypeW
1.2469 + EOwnerProcess//TOwnerType aTypeW
1.2470 + );
1.2471 +
1.2472 + test (ret == KErrInUse);
1.2473 +
1.2474 + aReader.Close();
1.2475 + aWriter.Close();
1.2476 +
1.2477 +
1.2478 +
1.2479 + test.Next(_L("PIPE TEST:1.4 Read/Write Function test : Check for Writing to pipe\n"));
1.2480 +
1.2481 + aSize = 100;
1.2482 + ret = RPipe::Create( aSize,
1.2483 + aReader,
1.2484 + aWriter,
1.2485 + EOwnerProcess,//TOwnerType aTypeW
1.2486 + EOwnerProcess//TOwnerType aTypeW
1.2487 + );
1.2488 + test_KErrNone(ret);
1.2489 +
1.2490 + ret=aWriter.Write(wData , wData.Size());
1.2491 + test (ret == wData.Size() );
1.2492 +
1.2493 + ret=aWriter.Write(wData , -1);
1.2494 + test (ret == KErrArgument );
1.2495 +
1.2496 +
1.2497 + test.Next(_L("PIPE TEST:1.5 Read/Write Function test : Check for Reading from pipe\n"));
1.2498 +
1.2499 +
1.2500 + TBuf8<100> rData ;// Descriptor for reading data from Pipe.
1.2501 +
1.2502 + ret=aReader.Read(rData,wData.Size()); // Length of the data to be read from Pipe
1.2503 + test (ret == wData.Size());// Length of the data read from the Pipe
1.2504 +
1.2505 +
1.2506 + test.Next(_L("PIPE TEST:1.6 Read/Write Function test : Validate data received\n"));
1.2507 +
1.2508 + test (KErrNone == rData.Compare(wData));
1.2509 +
1.2510 +
1.2511 + test.Next(_L("PIPE TEST:1.7 Read/Write Function test : Check for Reading from pipe\n"));
1.2512 +
1.2513 + ret=aReader.Read(rData,1);
1.2514 + test (ret == 0);
1.2515 + {
1.2516 +
1.2517 +
1.2518 + RPipe aReaderT, aWriterT;
1.2519 + aSize = 20;
1.2520 + ret = RPipe::Create( aSize,
1.2521 + aReaderT,
1.2522 + aWriterT,
1.2523 + EOwnerProcess,//TOwnerType aTypeW
1.2524 + EOwnerProcess//TOwnerType aTypeW
1.2525 + );
1.2526 + test_KErrNone(ret);
1.2527 +
1.2528 + ret=aWriterT.Write(wData ,15);
1.2529 + test_Equal(15, ret);
1.2530 + ret = aReaderT.Read(rData,10);
1.2531 + test_Equal(10, ret);
1.2532 + ret=aWriterT.Write(wData ,10);
1.2533 + test_Equal(10, ret);
1.2534 + ret = aReaderT.Read(rData,20);
1.2535 + test (ret ==15);
1.2536 + ret = aReaderT.Read(rData,5);
1.2537 + test_Equal(0, ret);
1.2538 + ret = aReaderT.Read(rData,25);
1.2539 + test_Equal(0, ret);
1.2540 +
1.2541 + aReaderT.Close();
1.2542 + aWriterT.Close();
1.2543 +
1.2544 + }
1.2545 +
1.2546 +
1.2547 + test.Next(_L("PIPE TEST:1.8 Read/Write Function test : Check for Wrong RPipe Handle\n"));
1.2548 +
1.2549 +
1.2550 + ret=aWriter.Read(rData,15 );// Length of the data to be read from Pipe
1.2551 + test (ret == KErrAccessDenied );
1.2552 +
1.2553 + test.Next(_L("PIPE TEST:1.9 Read/Write Function test : Check for Wrong RPipe Handle\n"));
1.2554 +
1.2555 + ret=aReader.Write(rData,rData.Size());
1.2556 + test (ret == KErrAccessDenied );
1.2557 +
1.2558 +
1.2559 + test.Next(_L("PIPE TEST:1.10 Read/Write Function test : Check for write overflow\n"));
1.2560 +
1.2561 + ret=aWriter.Write(wData,wData.Size());
1.2562 + ret=aWriter.Write(wData,wData.Size());
1.2563 + ret=aWriter.Write(wData,wData.Size());
1.2564 + ret=aWriter.Write(wData,wData.Size());
1.2565 + ret=aWriter.Write(wData,wData.Size());
1.2566 + ret=aWriter.Write(wData,wData.Size());
1.2567 + test (ret == KErrOverflow );
1.2568 +
1.2569 +
1.2570 +
1.2571 + test.Next(_L("PIPE TEST:1.11 MaxSize Function test : MaxSize Check \n"));
1.2572 + aSize = 10;
1.2573 + // Just to be on safer side , close pipes if any.
1.2574 + aReader.Close();
1.2575 + aWriter.Close();
1.2576 +
1.2577 + ret = RPipe::Create( aSize,
1.2578 + aReader,
1.2579 + aWriter,
1.2580 + EOwnerProcess,//TOwnerType aTypeW
1.2581 + EOwnerProcess//TOwnerType aTypeW
1.2582 + );
1.2583 + test (ret == KErrNone); // This error condition is not defined yet.
1.2584 + ret =aReader.MaxSize();
1.2585 + test (ret == aSize);
1.2586 +
1.2587 +
1.2588 + test.Next(_L("PIPE TEST:1.12 Size Function test : Size Check \n"));
1.2589 + rData.Zero();
1.2590 +
1.2591 + ret = aReader.Size();
1.2592 + test_Equal(0, ret);
1.2593 +
1.2594 + _LIT8(KSizeTestData1,"123456789");
1.2595 +
1.2596 + ret = aWriter.Write(KSizeTestData1,9);
1.2597 + test_Equal(9, ret);
1.2598 + ret = aReader.Size();
1.2599 + test_Equal(9, ret);
1.2600 +
1.2601 + ret = aReader.Read(rData,1);
1.2602 + test_Equal(1, ret);
1.2603 + ret = rData.Compare(_L8("1"));
1.2604 + test_KErrNone(ret);
1.2605 + ret = aReader.Size();
1.2606 + test_Equal(8, ret);
1.2607 +
1.2608 + _LIT8(KSizeTestData2,"ab");
1.2609 + ret = aWriter.Write(KSizeTestData2,2);
1.2610 + test_Equal(2, ret);
1.2611 + ret = aReader.Size();
1.2612 + test_Equal(10, ret);
1.2613 +
1.2614 + ret = aWriter.Write(KSizeTestData2,1);
1.2615 + test_Equal(KErrOverflow, ret);
1.2616 + ret = aReader.Size();
1.2617 + test_Equal(10, ret);
1.2618 +
1.2619 + ret = aReader.Read(rData,9);
1.2620 + test_Equal(9, ret);
1.2621 + ret = rData.Compare(_L8("23456789a"));
1.2622 + test_KErrNone(ret);
1.2623 + ret = aReader.Size();
1.2624 + test_Equal(1, ret);
1.2625 +
1.2626 + ret = aReader.Read(rData,1);
1.2627 + test_Equal(1, ret);
1.2628 + ret = rData.Compare(_L8("b"));
1.2629 + test_KErrNone(ret);
1.2630 + ret = aReader.Size();
1.2631 + test_Equal(0, ret);
1.2632 +
1.2633 + ret = aWriter.Size();
1.2634 + test_Equal(0, ret);
1.2635 + RPipe WrongPipeHandle;
1.2636 +
1.2637 + ret = WrongPipeHandle.Size();
1.2638 + test ( ret == KErrBadHandle);
1.2639 +
1.2640 + test.Next(_L("PIPE TEST:1.13 Size Function test : Size Function call with Wrong handle \n"));
1.2641 +
1.2642 +
1.2643 +
1.2644 + ret = WrongPipeHandle.MaxSize();
1.2645 + test (ret == KErrBadHandle);
1.2646 +
1.2647 + aReader.Close();
1.2648 + aWriter.Close();
1.2649 + aReader2.Close();
1.2650 + aWriter2.Close();
1.2651 +
1.2652 + test.Next(_L("PIPE TEST:1.14 Read Function : KErrNotReady \n"));
1.2653 + aSize = 10;
1.2654 + ret = RPipe::Create( aSize,
1.2655 + aReader,
1.2656 + aWriter,
1.2657 + EOwnerProcess,//TOwnerType aTypeW
1.2658 + EOwnerProcess//TOwnerType aTypeW
1.2659 + );
1.2660 + test (ret == KErrNone); // This error condition is not defined yet.
1.2661 + aWriter.Close();
1.2662 + ret = aReader.Read(rData,aSize);
1.2663 + test (ret == KErrNotReady);
1.2664 + ret = aReader.Read(rData,110);
1.2665 + test (ret == KErrArgument);
1.2666 +
1.2667 +
1.2668 + test.Next(_L("PIPE TEST:1.15 Check Handle Type function \n"));
1.2669 + aReader.Close();
1.2670 + aWriter.Close();
1.2671 + aSize = 10;
1.2672 + ret = RPipe::Create( aSize,
1.2673 + aReader,
1.2674 + aWriter,
1.2675 + EOwnerProcess,//TOwnerType aTypeW
1.2676 + EOwnerProcess//TOwnerType aTypeW
1.2677 + );
1.2678 + test_KErrNone(ret);
1.2679 +
1.2680 + ret = aReader.HandleType();
1.2681 + test (ret == RPipe::EReadChannel);
1.2682 +
1.2683 + ret = aWriter.HandleType();
1.2684 + test (ret == RPipe::EWriteChannel);
1.2685 +
1.2686 +
1.2687 + aReader.Close();
1.2688 + ret = aReader.HandleType();
1.2689 + test (ret == KErrBadHandle);
1.2690 +
1.2691 + test.Next(_L("PIPE TEST:1.16 Write Function : KErrNotReady \n"));
1.2692 + aSize = 1;
1.2693 + ret = aWriter.Write(wData,aSize);
1.2694 + test (ret == KErrNotReady);
1.2695 +
1.2696 + test.Next(_L("PIPE TEST:1.17 Write Function : Write data more than size of Descriptor \n"));
1.2697 + ret = aWriter.Write(wData,110);
1.2698 + test (ret == KErrArgument);
1.2699 +
1.2700 +
1.2701 + test.Next(_L("PIPE TEST:1.18 Write Function : KErrCompletion \n"));
1.2702 + aWriter.Close();
1.2703 + ret = RPipe::Create( aSize,
1.2704 + aReader,
1.2705 + aWriter,
1.2706 + EOwnerProcess,//TOwnerType aTypeW
1.2707 + EOwnerProcess//TOwnerType aTypeW
1.2708 + );
1.2709 + test_KErrNone(ret);
1.2710 + ret = aWriter.Write(wData,wData.Size());
1.2711 + test (ret == KErrOverflow);
1.2712 +
1.2713 + test.Next(_L("PIPE TEST:1.19 Create Function : KErrInUse \n"));
1.2714 + aReader.Close();
1.2715 + ret = RPipe::Create( aSize,
1.2716 + aReader,
1.2717 + aWriter,
1.2718 + EOwnerProcess,//TOwnerType aTypeW
1.2719 + EOwnerProcess//TOwnerType aTypeW
1.2720 + );
1.2721 + test (ret == KErrInUse);
1.2722 +
1.2723 + aWriter.Close();
1.2724 + ret = RPipe::Create( aSize,
1.2725 + aReader,
1.2726 + aWriter,
1.2727 + EOwnerProcess,//TOwnerType aTypeW
1.2728 + EOwnerProcess//TOwnerType aTypeW
1.2729 + );
1.2730 + test (ret == KErrNone);
1.2731 + aWriter.Close();
1.2732 + ret = RPipe::Create( aSize,
1.2733 + aReader,
1.2734 + aWriter,
1.2735 + EOwnerProcess,//TOwnerType aTypeW
1.2736 + EOwnerProcess//TOwnerType aTypeW
1.2737 + );
1.2738 + test (ret == KErrInUse);
1.2739 +
1.2740 +
1.2741 +
1.2742 + test.Next(_L("PIPE TEST:1.20 Read / Write using un opened handles \n"));
1.2743 + RPipe aReaderT,aWriterT;
1.2744 +
1.2745 + ret = aWriterT.Write(wData,wData.Size());
1.2746 + test (ret == KErrBadHandle);
1.2747 + ret = aReaderT.Read(rData,aSize);
1.2748 + test (ret == KErrBadHandle);
1.2749 +
1.2750 +
1.2751 +
1.2752 +
1.2753 + // Close all the pipes and return the resources.
1.2754 + aReader.Close();
1.2755 + aWriter.Close();
1.2756 + aReader2.Close();
1.2757 + aWriter2.Close();
1.2758 + return;
1.2759 +
1.2760 +} // End TestSingleThreadUnNamedPipes()
1.2761 +
1.2762 +/****************************************************************************
1.2763 + This is a function to test UnNamed pipes and named pipes in Single
1.2764 + threaded environment.
1.2765 + This test ensures that the memory is actually being released when:
1.2766 + RPipe::Close() is called for unnamed pipes and
1.2767 + RPipe::Destroy() is called for named pipes.
1.2768 +******************************************************************************/
1.2769 +void TestCreateClosePipe()
1.2770 + {
1.2771 +
1.2772 + //unnamed pipes
1.2773 + RPipe readHandle, writeHandle;
1.2774 + const TInt K3MB = 1024*1024*3;
1.2775 + // The loop is run ten times to ensure that if memory allocated while pipe
1.2776 + // creation is not deallocated by close,then creation of pipe will fail with
1.2777 + // KErrNoMemory in the sixth iteration. Default heap size is assumed.
1.2778 + TInt i;
1.2779 + test.Next(_L("PIPE TEST:11.1 Create Function test in a loop : Check for No Error\n"));
1.2780 + for(i=1; i<10; i++)
1.2781 + {
1.2782 + TInt r = RPipe::Create(K3MB, readHandle, writeHandle,EOwnerProcess, EOwnerProcess);
1.2783 + test(KErrNone == r);
1.2784 + readHandle.Close();
1.2785 + writeHandle.Close();
1.2786 + }
1.2787 +
1.2788 + //named pipes
1.2789 + _LIT(KPipeName, "testPipe");
1.2790 + // The loop is run ten times to ensure that if memory allocated while pipe
1.2791 + // creation is not deallocated by destroy,then creation of pipe will fail with
1.2792 + // KErrNoMemory in the sixth iteration. Default heap size is assumed.
1.2793 + test.Next(_L("PIPE TEST:11.2 Define Function test in a loop : Check for No Error\n"));
1.2794 + for(i=1; i<10; i++)
1.2795 + {
1.2796 + TInt r = RPipe::Define(KPipeName,K3MB);
1.2797 + test(KErrNone == r);
1.2798 + r = RPipe::Destroy(KPipeName);
1.2799 + test(KErrNone == r);
1.2800 + }
1.2801 +
1.2802 + }// End TestCreateClosePipe()
1.2803 +
1.2804 +
1.2805 +struct TStressArgs
1.2806 + {
1.2807 + TStressArgs(TInt aIter, TInt aSize)
1.2808 + :iIter(aIter), iSize(aSize)
1.2809 + {}
1.2810 +
1.2811 + const TInt iIter;
1.2812 + const TInt iSize;
1.2813 + };
1.2814 +
1.2815 +struct TDefDesArgs: public TStressArgs
1.2816 + {
1.2817 + TDefDesArgs(TInt aIter, TInt aSize, const TDesC& aName)
1.2818 + :TStressArgs(aIter,aSize), iName(aName)
1.2819 + {}
1.2820 + const TDesC& iName;
1.2821 + };
1.2822 +
1.2823 +/**
1.2824 +Repeatedly define and destroy named pipe
1.2825 +*/
1.2826 +TInt DefineDestroy(TAny* aArgs)
1.2827 + {
1.2828 + const TDefDesArgs args = *static_cast<TDefDesArgs*>(aArgs);
1.2829 +
1.2830 + for(TInt i=0; i<args.iIter; i++)
1.2831 + {
1.2832 + TInt r = RPipe::Define(args.iName, args.iSize);
1.2833 + if(r!=KErrNone && r!=KErrAlreadyExists)
1.2834 + {
1.2835 + return r;
1.2836 + }
1.2837 + r = RPipe::Destroy(args.iName);
1.2838 + if(r!=KErrNone && r!=KErrInUse && r!=KErrNotFound)
1.2839 + {
1.2840 + return r;
1.2841 + }
1.2842 + }
1.2843 + return KErrNone;
1.2844 + }
1.2845 +
1.2846 +
1.2847 +/**
1.2848 +The parent thread will try to repeatedly open and close a named pipe
1.2849 +which is being repeatedly created and destroyed by the child thread.
1.2850 +This attempts to catch race conditions.
1.2851 +*/
1.2852 +void TestRapidDefineDestroy()
1.2853 + {
1.2854 + const TInt iterations=1000;
1.2855 + TDefDesArgs args(iterations, 16, KPipe1Name);
1.2856 +
1.2857 + RPipe pipe;
1.2858 +
1.2859 + TTestThread thread(_L("DefineDestroy"), DefineDestroy, &args);
1.2860 +
1.2861 + TInt r=KErrNone;
1.2862 +
1.2863 + for(TInt i=0; i<args.iIter; i++)
1.2864 + {
1.2865 + r = pipe.Open(args.iName, RPipe::EOpenToWrite);
1.2866 + if(r!=KErrNone && r !=KErrNotFound)
1.2867 + {
1.2868 + test_KErrNone(r);
1.2869 + }
1.2870 +
1.2871 + pipe.Close();
1.2872 + }
1.2873 + r = thread.WaitForExitL();
1.2874 + test_KErrNone(r);
1.2875 + }
1.2876 +
1.2877 +
1.2878 +/**
1.2879 +Write the descriptor specified in to the pipe repeating
1.2880 +as many times as specified by TData::iIterations
1.2881 +*/
1.2882 +TInt WriteThread(TAny* aData)
1.2883 + {
1.2884 + TData& data = *static_cast<TData*>(aData);
1.2885 +
1.2886 + const TInt iter = data.iIterations;
1.2887 +
1.2888 + TInt write=0;
1.2889 + for(TInt i=0; i<iter; i++)
1.2890 + {
1.2891 + write = data.iWriteEnd->WriteBlocking(*data.iPipeData, data.iPipeData->Size());
1.2892 + if(write <KErrNone)
1.2893 + {
1.2894 + return write;
1.2895 + }
1.2896 + }
1.2897 +
1.2898 + return write*iter;
1.2899 + }
1.2900 +
1.2901 +/**
1.2902 +Fill descriptor with random bytes
1.2903 +*/
1.2904 +void FillRandom(TDes8& aDes)
1.2905 + {
1.2906 + aDes.Zero();
1.2907 +
1.2908 + while(aDes.Size()+4<=aDes.MaxSize())
1.2909 + {
1.2910 + TUint8 rand[4];
1.2911 + *(TUint32*)rand = Math::Random();
1.2912 +
1.2913 + aDes.Append(rand, 4);
1.2914 + }
1.2915 + }
1.2916 +
1.2917 +/**
1.2918 +@param aTotalBytes Bytes transfered in period
1.2919 +@param aTicks number of ticks elapsed in period
1.2920 +@return The rate of the transfer on kilobytes per second
1.2921 +*/
1.2922 +TReal KiloBytesPerSecond(TInt aTotalBytes, TInt aTicks)
1.2923 + {
1.2924 + TInt period=0; //period of nanotick in microseconds
1.2925 + TInt r = HAL::Get(HAL::ENanoTickPeriod, period);
1.2926 + User::LeaveIfError(r);
1.2927 +
1.2928 + //we use the definition that a kilobytes is 1000 bytes
1.2929 + TReal result = (aTotalBytes/(aTicks*period/1000));
1.2930 + return result;
1.2931 + }
1.2932 +
1.2933 +
1.2934 +/**
1.2935 +Create a source data buffer of aTotal bytes and fill with random data.
1.2936 +Create a pipe and thread (WriteThread) to write the source buffer
1.2937 +into the pipe.
1.2938 +Read from the pipe into destination buffer
1.2939 +and optionally verify that buffers match
1.2940 +
1.2941 +@param aTotal Size of data buffer
1.2942 +@param aPipeData Size of pipe to create
1.2943 +@param aIter number of times to repeat transfer
1.2944 +@param aVerify Confirm that destination buffer matches source buffer
1.2945 +@param aPollRead read pipe by polling instead of using blocking read
1.2946 +@return Total number of ticks elapsed
1.2947 +*/
1.2948 +TInt TestLoopBack(TInt aTotal, TInt aPipeSize, TInt aIter, TBool aVerify=ETrue, TBool aPollRead=EFalse)
1.2949 + {
1.2950 + const TInt bufferSize = aTotal;
1.2951 +
1.2952 + RBuf8 sourceBuffer;
1.2953 + sourceBuffer.CreateL(bufferSize);
1.2954 + FillRandom(sourceBuffer);
1.2955 + test_Equal(bufferSize,sourceBuffer.Size());
1.2956 +
1.2957 + const TInt pipeSize=aPipeSize;
1.2958 +
1.2959 + RPipe readEnd, writeEnd;
1.2960 + TInt r = RPipe::Create(pipeSize, readEnd, writeEnd ,EOwnerProcess, EOwnerProcess);
1.2961 + test_KErrNone(r);
1.2962 +
1.2963 +
1.2964 + const TInt maxIter=aIter;
1.2965 + TData data(NULL, &writeEnd, &sourceBuffer, maxIter);
1.2966 +
1.2967 +
1.2968 + RBuf8 destBuffer;
1.2969 + destBuffer.CreateL(bufferSize);
1.2970 +
1.2971 + RBuf8 tempBuffer;
1.2972 + tempBuffer.CreateL(bufferSize);
1.2973 +
1.2974 +
1.2975 + TTestThread writer(_L("LoopBack"), WriteThread, &data);
1.2976 + const TUint32 startTicks=User::NTickCount();
1.2977 +
1.2978 + for(TInt iter=0; iter<maxIter; iter++)
1.2979 + {
1.2980 + TInt remainingData = bufferSize;
1.2981 + do
1.2982 + {
1.2983 + const TInt toRead = Min(pipeSize,remainingData);
1.2984 + if(aPollRead)
1.2985 + {
1.2986 + //an inefficient way to read a pipe!
1.2987 + r = readEnd.Read(tempBuffer, toRead);
1.2988 + test_NotNegative(r);
1.2989 + }
1.2990 + else
1.2991 + {
1.2992 + r = readEnd.ReadBlocking(tempBuffer, toRead );
1.2993 + test_Equal(toRead, r);
1.2994 + }
1.2995 + destBuffer+=tempBuffer;
1.2996 + tempBuffer.Zero();
1.2997 + remainingData-=r;
1.2998 + }
1.2999 + while(remainingData);
1.3000 +
1.3001 + if(aVerify)
1.3002 + {
1.3003 + r = sourceBuffer.Compare(destBuffer);
1.3004 + test_KErrNone(r);
1.3005 + }
1.3006 +
1.3007 + destBuffer.Zero();
1.3008 + }
1.3009 + const TUint32 endTicks = User::NTickCount();
1.3010 +
1.3011 + r = writer.WaitForExitL();
1.3012 + test_Equal(bufferSize*maxIter, r);
1.3013 +
1.3014 + const TUint32 ticksElapsed= endTicks - startTicks;
1.3015 +
1.3016 + sourceBuffer.Close();
1.3017 + tempBuffer.Close();
1.3018 + destBuffer.Close();
1.3019 +
1.3020 + readEnd.Close();
1.3021 + writeEnd.Close();
1.3022 +
1.3023 + return ticksElapsed;
1.3024 + }
1.3025 +
1.3026 +/**
1.3027 +Simple test to confirm that data is reproduced after being fed through a pipe
1.3028 +*/
1.3029 +void TestTransferIntegrity()
1.3030 + {
1.3031 +
1.3032 + TestLoopBack(128*1024, 128, 1, ETrue);
1.3033 + TestLoopBack(1024, 1, 1, ETrue);
1.3034 +
1.3035 + //read by constantly polling
1.3036 + TestLoopBack(128*1024, 1024, 1, ETrue, ETrue);
1.3037 + }
1.3038 +
1.3039 +
1.3040 +/**
1.3041 +Enable Writeblocking and Readblocking notifications
1.3042 +without actual reads and writes
1.3043 +*/
1.3044 +class RTestPipe: public RPipe
1.3045 + {
1.3046 +public:
1.3047 + void RequestWriteBlocking(TInt aNumByte, TRequestStatus& aStatus)
1.3048 + {
1.3049 + DoRequest(EWriteBlocking, aStatus, &aNumByte);
1.3050 + }
1.3051 +
1.3052 + void RequestReadBlocking(TRequestStatus& aStatus)
1.3053 + {
1.3054 + DoRequest(EReadBlocking, aStatus);
1.3055 + }
1.3056 + };
1.3057 +
1.3058 +
1.3059 +/**
1.3060 +A test which will request some type of notification
1.3061 +*/
1.3062 +struct CNotificationTest : public TFunctor
1.3063 + {
1.3064 + CNotificationTest(RTestPipe& aPipe)
1.3065 + :iPipe(aPipe)
1.3066 + {
1.3067 + TInt r = iParent.Open(iParent.Id());
1.3068 + test_KErrNone(r);
1.3069 + }
1.3070 +
1.3071 + virtual ~CNotificationTest()
1.3072 + {
1.3073 + }
1.3074 +
1.3075 + void operator()()
1.3076 + {
1.3077 + RunTest();
1.3078 +
1.3079 + //set up rendezvous with parent
1.3080 + iParent.Rendezvous(iRendezvousStatus);
1.3081 +
1.3082 + //announce we have run test
1.3083 + RThread::Rendezvous(KErrNone);
1.3084 +
1.3085 + //wait untill parent has reached rendezvous
1.3086 + User::WaitForRequest(iRendezvousStatus);
1.3087 + }
1.3088 +
1.3089 + virtual CNotificationTest* Clone()=0;
1.3090 +
1.3091 + /**
1.3092 + If necessary, gets pipe into correct state for the start of test
1.3093 + */
1.3094 + virtual void PreparePipe() =0;
1.3095 + virtual void RunTest() =0;
1.3096 +
1.3097 + /**
1.3098 + Cancel the notification
1.3099 + */
1.3100 + virtual void Cancel() =0;
1.3101 +
1.3102 + virtual TInt GetReturn()
1.3103 + {
1.3104 + return iStatus.Int();
1.3105 + }
1.3106 +
1.3107 + RTestPipe& iPipe;
1.3108 + TRequestStatus iStatus;
1.3109 +
1.3110 + TRequestStatus iRendezvousStatus;
1.3111 + RThread iParent;
1.3112 + };
1.3113 +
1.3114 +
1.3115 +
1.3116 +/**
1.3117 +Will request free space notification
1.3118 +*/
1.3119 +struct CSpaceNotificationTest : public CNotificationTest
1.3120 + {
1.3121 + typedef void (RTestPipe::*TSpaceNotification) (TInt, TRequestStatus&);
1.3122 +
1.3123 + /**
1.3124 + @param aPipe Pipe handle to use
1.3125 + @param TSpaceNotification A pointer for the method to test
1.3126 + @param aNumBytes Amount of space to request
1.3127 + */
1.3128 + CSpaceNotificationTest(RTestPipe& aPipe, TSpaceNotification aFunc, TInt aNumBytes)
1.3129 + :CNotificationTest(aPipe), iFn(aFunc), iNumBytes(aNumBytes)
1.3130 + {}
1.3131 +
1.3132 + CNotificationTest* Clone()
1.3133 + {
1.3134 + return new CSpaceNotificationTest(*this);
1.3135 + }
1.3136 +
1.3137 + void RunTest()
1.3138 + {
1.3139 + (iPipe.*iFn)(iNumBytes, iStatus);
1.3140 + }
1.3141 +
1.3142 + //Make sure space notification won't complete immediately
1.3143 + void PreparePipe()
1.3144 + {
1.3145 + TInt freeSpace = iPipe.MaxSize() - iPipe.Size();
1.3146 + if(freeSpace >= iNumBytes)
1.3147 + {
1.3148 + TInt r = iPipe.Write(KTestData, freeSpace);
1.3149 + test_Equal(freeSpace, r);
1.3150 + }
1.3151 + }
1.3152 +
1.3153 + void Cancel()
1.3154 + {
1.3155 + iPipe.CancelSpaceAvailable();
1.3156 + };
1.3157 +
1.3158 + TSpaceNotification iFn;
1.3159 + TInt iNumBytes;
1.3160 + };
1.3161 +
1.3162 +struct CDataNotificationTest : public CNotificationTest
1.3163 + {
1.3164 + typedef void (RTestPipe::*TDataNotification) (TRequestStatus&);
1.3165 +
1.3166 + CDataNotificationTest(RTestPipe& aPipe, TDataNotification aFunc)
1.3167 + :CNotificationTest(aPipe), iFn(aFunc)
1.3168 + {}
1.3169 +
1.3170 + CNotificationTest* Clone()
1.3171 + {
1.3172 + return new CDataNotificationTest(*this);
1.3173 + }
1.3174 +
1.3175 + void RunTest()
1.3176 + {
1.3177 + (iPipe.*iFn)(iStatus);
1.3178 + }
1.3179 +
1.3180 + //make sure we start with an empty pipe
1.3181 + void PreparePipe()
1.3182 + {
1.3183 + iPipe.Flush();
1.3184 + }
1.3185 +
1.3186 + void Cancel()
1.3187 + {
1.3188 + iPipe.CancelDataAvailable();
1.3189 + };
1.3190 +
1.3191 + TDataNotification iFn;
1.3192 + };
1.3193 +
1.3194 +
1.3195 +void ProcessNotificationTests(RPointerArray<CNotificationTest>& aArray)
1.3196 + {
1.3197 + const TInt count = aArray.Count();
1.3198 + for(TInt i=0; i < count; i++)
1.3199 + {
1.3200 + for(TInt j=0; j < count; j++)
1.3201 + {
1.3202 + //need copies as objects contain request states
1.3203 + CNotificationTest* testA = aArray[i]->Clone();
1.3204 + test_NotNull(testA);
1.3205 + CNotificationTest* testB = aArray[j]->Clone();
1.3206 + test_NotNull(testB);
1.3207 +
1.3208 + testA->PreparePipe(); testB->PreparePipe();
1.3209 +
1.3210 + TTestThread a(_L("CNotificationTestA"), *testA, EFalse);
1.3211 + TTestThread b(_L("CNotificationTestB"), *testB, EFalse);
1.3212 +
1.3213 + TRequestStatus rendezvousA, rendezvousB;
1.3214 + a.Rendezvous(rendezvousA);
1.3215 + b.Rendezvous(rendezvousB);
1.3216 +
1.3217 + a.Resume(); b.Resume();
1.3218 +
1.3219 + //wait till after threads have made notification request.
1.3220 + User::WaitForRequest(rendezvousA);
1.3221 + User::WaitForRequest(rendezvousB);
1.3222 +
1.3223 + TInt retA = testA->GetReturn(); TInt retB = testB->GetReturn();
1.3224 +
1.3225 + //announce that we have read status requests, allowing
1.3226 + //child threads to terminate
1.3227 + RThread::Rendezvous(KErrNone);
1.3228 +
1.3229 + a.WaitForExitL();
1.3230 + b.WaitForExitL();
1.3231 +
1.3232 + TBool oneRequestSupported = ((retA == KRequestPending) && (retB == KErrInUse))
1.3233 + || ((retB == KRequestPending) && (retA == KErrInUse));
1.3234 + TBool bothSupported = (retA == KRequestPending) && (retB == KRequestPending);
1.3235 +
1.3236 + if(!(oneRequestSupported || bothSupported))
1.3237 + {
1.3238 + test.Printf(_L("Failure: i=%d, j=%d"), i, j);
1.3239 + test(EFalse);
1.3240 + }
1.3241 +
1.3242 + testA->Cancel(); testB->Cancel();
1.3243 + delete testA;
1.3244 + delete testB;
1.3245 + }
1.3246 + }
1.3247 + }
1.3248 +
1.3249 +/**
1.3250 +Test abillity of pipe channels to handle multiple notification requests
1.3251 +simultaneously.
1.3252 +*/
1.3253 +void TestNotifications()
1.3254 + {
1.3255 + RTestPipe readEnd, writeEnd;
1.3256 +
1.3257 + TInt pipeSize = 5;
1.3258 + TInt r = RPipe::Create(pipeSize, readEnd, writeEnd, EOwnerProcess, EOwnerProcess);
1.3259 + test_KErrNone(r);
1.3260 +
1.3261 + test.Next(_L("Test write end requests"));
1.3262 + CSpaceNotificationTest writeBlocking(writeEnd, &RTestPipe::RequestWriteBlocking, pipeSize);
1.3263 + CSpaceNotificationTest spaceAvailable(writeEnd, &RTestPipe::NotifySpaceAvailable, pipeSize);
1.3264 + RPointerArray<CNotificationTest> writeEndTests;
1.3265 +
1.3266 + writeEndTests.AppendL(&writeBlocking);
1.3267 + writeEndTests.AppendL(&spaceAvailable);
1.3268 +
1.3269 + for(TInt i=0; i<10; i++)
1.3270 + {
1.3271 + ProcessNotificationTests(writeEndTests);
1.3272 + }
1.3273 + writeEndTests.Close();
1.3274 +
1.3275 + test.Next(_L("Test read end requests"));
1.3276 + CDataNotificationTest readBlocking(readEnd, &RTestPipe::RequestReadBlocking);
1.3277 + CDataNotificationTest dataAvailable(readEnd, &RTestPipe::NotifyDataAvailable);
1.3278 + RPointerArray<CNotificationTest> readEndTests;
1.3279 +
1.3280 + readEndTests.AppendL(&readBlocking);
1.3281 + readEndTests.AppendL(&dataAvailable);
1.3282 +
1.3283 + for(TInt j=0; j<10; j++)
1.3284 + {
1.3285 + ProcessNotificationTests(readEndTests);
1.3286 + }
1.3287 +
1.3288 + readEndTests.Close();
1.3289 +
1.3290 + readEnd.Close();
1.3291 + writeEnd.Close();
1.3292 + }
1.3293 +
1.3294 +LOCAL_C void RunTests(void)
1.3295 + {
1.3296 + // Test UnNamed Pipes in Single Thread
1.3297 + test.Next(_L("PIPE TEST: 1.Un Named pipes in Single Thread\n"));
1.3298 + TestSingleThreadUnNamedPipes();
1.3299 +
1.3300 + // Test Named Pipes in Single Thread
1.3301 + test.Next(_L("PIPE TEST: 2.Named pipes in Single Thread\n"));
1.3302 + TestSingleThreadNamedPipes();
1.3303 +
1.3304 + // Test UnNamed Pipes in MultiThread
1.3305 + test.Next(_L("PIPE TEST: 3.Un Named pipes in Multi Thread\n"));
1.3306 + TestMultiThreadUnNamedPipes();
1.3307 +
1.3308 + // Test Named Pipes in MultiThread
1.3309 + test.Next(_L("PIPE TEST: 4.Named pipes in Multi Thread\n"));
1.3310 + TestMultiThreadNamedPipes();
1.3311 +
1.3312 + // Test Named Pipes in Multi Process
1.3313 + test.Next(_L("PIPE TEST: 5.Named pipes in Multi Process\n"));
1.3314 + TestMultiProcessNamedPipes();
1.3315 +
1.3316 + // Test Notify mechanism
1.3317 + test.Next(_L("PIPE TEST: 6.Pipes Notify mechanism test\n"));
1.3318 + TestNotifyMechanismPipes();
1.3319 +
1.3320 + // Test Wait Mechanism
1.3321 + test.Next(_L("PIPE TEST: 7.Pipes Wait mechanism test\n"));
1.3322 + TestWaitMechanismPipes();
1.3323 +
1.3324 +
1.3325 + // Test Pipes performance
1.3326 + test.Next(_L("PIPE TEST: 8.Pipes Permission test\n"));
1.3327 + TestPipesPermissionCheck ();
1.3328 +
1.3329 + // Misc Pipe tests
1.3330 + test.Next(_L("PIPE TEST: 9.Misc Pipe tests\n"));
1.3331 + TestMiscPipes();
1.3332 +
1.3333 + // Blocking and Notify method tests.
1.3334 + test.Next(_L("PIPE TEST: 10.Blocking and Notification calls test\n"));
1.3335 + TestBlockingAndNotify();
1.3336 +
1.3337 + //Creation and closure of a large number of Pipes
1.3338 + test.Next(_L("PIPE TEST: 11. Creation and subsequent closure of a large number of pipes\n"));
1.3339 + TestCreateClosePipe();
1.3340 +
1.3341 + test.Next(_L("Test concurrent notification requests"));
1.3342 + TestNotifications();
1.3343 +
1.3344 + test.Next(_L("Repeatedly open a named pipe whilst it's being created and destroyed"));
1.3345 + TestRapidDefineDestroy();
1.3346 +
1.3347 + test.Next(_L("Check integrity of data after transfer\n"));
1.3348 + TestTransferIntegrity();
1.3349 +
1.3350 + test.Next(_L("PIPE TEST: Ending test.\n"));
1.3351 + return;
1.3352 + }
1.3353 +
1.3354 +TInt ParseCommandLine()
1.3355 + {
1.3356 + TBuf<20> cmdLine;
1.3357 + //TInt r= cmdLine.Create(User::CommandLineLength());
1.3358 + //test_KErrNone(r);
1.3359 + User::CommandLine(cmdLine);
1.3360 + TLex lex(cmdLine);
1.3361 +
1.3362 + TPtrC token=lex.NextToken();
1.3363 + if(token.Length()>0)
1.3364 + {
1.3365 + TInt os=token.Match(_L("-n*"));
1.3366 + if(os==0)
1.3367 + {
1.3368 + if(token.Length()>2)
1.3369 + lex.SkipAndMark(2-lex.TokenLength()); //set mark backwards to after the "-n"
1.3370 + token.Set(lex.NextToken());
1.3371 + if(token.Length()==0)
1.3372 + return KErrArgument;
1.3373 +
1.3374 + TLex valLex(token);
1.3375 + TInt value;
1.3376 + TInt r=valLex.Val(value);
1.3377 + if(r<0)
1.3378 + return r;
1.3379 + else
1.3380 + return value;
1.3381 + }
1.3382 + else
1.3383 + {
1.3384 + return KErrArgument;
1.3385 + }
1.3386 + }
1.3387 + else
1.3388 + {
1.3389 + const TInt KDefaultRuns=1;
1.3390 + return KDefaultRuns;
1.3391 + }
1.3392 + }
1.3393 +
1.3394 +GLDEF_C TInt E32Main()
1.3395 +// Main entry point for the test.
1.3396 + {
1.3397 + __UHEAP_MARK;
1.3398 + TInt ret = 0;
1.3399 +
1.3400 + test.Start(_L("PIPE TEST: Testing"));
1.3401 + ret = RPipe::Init();
1.3402 + if ( ret != KErrNone && ret != KErrAlreadyExists)
1.3403 + {
1.3404 + test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
1.3405 + return KErrNone;
1.3406 + }
1.3407 + TName pddName(RPipe::Name());
1.3408 + ret = RPipe::Define (KPipe1Name,10);
1.3409 + test_KErrNone(ret);
1.3410 +
1.3411 + User::FreeLogicalDevice(pddName);
1.3412 + ret = RPipe::Define (KPipe1Name,10);
1.3413 + test_Equal(KErrNotFound, ret);
1.3414 +
1.3415 + ret = RPipe::Init();
1.3416 + if ( ret != KErrNone && ret != KErrAlreadyExists)
1.3417 + {
1.3418 + test.Printf(_L("Fail to load RPIPE driver %d\n"),ret);
1.3419 + return KErrNone;
1.3420 + }
1.3421 +
1.3422 +
1.3423 + TInt runs=ParseCommandLine();
1.3424 + if(runs>=0)
1.3425 + {
1.3426 + TBool forever=(runs==0);
1.3427 + for(TInt i=0; forever||(i<runs); ++i)
1.3428 + {
1.3429 + if(i!=0)
1.3430 + test.Next(_L("Next iteration"));
1.3431 +
1.3432 + test.Start(_L("Starting Run")); //sub nest each test iteration
1.3433 + __UHEAP_MARK;
1.3434 + TRAP(ret, RunTests());
1.3435 + test_KErrNone(ret);
1.3436 + __UHEAP_MARKEND;
1.3437 + test.End();
1.3438 + }
1.3439 + }
1.3440 + else
1.3441 + {
1.3442 + test.Printf(_L("Usage: t_pipe -n N\n N is number of runs to do. If N=0 run forever"));
1.3443 + }
1.3444 +
1.3445 + TName pddName2(RPipe::Name());
1.3446 + ret= User::FreeLogicalDevice(pddName2);
1.3447 + test_KErrNone(ret);
1.3448 + test.End();
1.3449 + test.Close();
1.3450 + __UHEAP_MARKEND;
1.3451 + return KErrNone;
1.3452 + }
1.3453 +
1.3454 +