os/kernelhwsrv/kerneltest/e32test/pipe/t_pipe4.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\pipe\t_pipe4.cpp
    15 // This is very similar to User::WaitForRequest() but allows the User
    16 // to specify multiple TRequestStatus objects to wait on. The function
    17 // will return when the first TRequestStatus object completes.
    18 // / Header Files////////
    19 // 
    20 //
    21 
    22 /**
    23  @STMTestCaseID			KBASE-T_PIPE4-0218
    24  @SYMPREQ				PREQ1460
    25  @SYMREQ					REQ6142
    26  @SYMCR					CR0923
    27  @SYMTestCaseDesc		User::WaitForNRequests functional test
    28  @SYMTestPriority		High
    29  @SYMTestActions			Tests the operation of the API User::WaitForNRequests().
    30  @SYMTestExpectedResults	Test should pass
    31 */
    32 
    33 #define __E32TEST_EXTENSION__
    34 
    35 #include <e32test.h>
    36 #include <e32svr.h>
    37 #include <e32des8.h>
    38 #include <e32des8_private.h>
    39 #include <e32cmn.h>
    40 #include <e32cmn_private.h>
    41 #include <e32std.h>
    42 #include <e32std_private.h>
    43 
    44 #include "rpipe.h"
    45 
    46 //// Test Objects for All threads////
    47 
    48 LOCAL_D RTest test(_L("t_pipe4"));
    49 LOCAL_D RTest test2(_L("t_pipe_t2"));
    50 LOCAL_D RTest test3(_L("t_pipe_t3"));
    51 LOCAL_D RTest test4(_L("t_pipe_t4"));
    52 LOCAL_D RTest test5(_L("t_pipe_t5"));
    53 
    54 //// Thread Name Constants //////
    55 _LIT(KThread2Name, "WaitThread");
    56 _LIT(KThread3Name, "NotifyDataThread");
    57 _LIT(KThread4Name, "NotifySpaceThread");
    58 _LIT(KThread5Name, "CancelNotifyThread");
    59 
    60 _LIT(KPipe1Name,"TestPipeP");
    61 _LIT(KPipe2Name,"TestPipeQ");
    62 _LIT(KPipe3Name,"TestPipeR");
    63 _LIT(KPipe4Name,"TestPipeS");
    64 _LIT(KPipe5Name,"TestPipeT");
    65 
    66 
    67 _LIT8(KTestDataNum,"1234567890");
    68 
    69 
    70 
    71 const TInt KHeapSize=0x2000;
    72 
    73 
    74 // Following class is used to pass thread handle information to different threads.
    75 class TData
    76 	{
    77 public:
    78 	TData(RPipe* aPipe, RPipe *bPipe, TInt aSize);
    79 	RPipe* rPipe;								// Pipe Read handle
    80 	RPipe* wPipe;								// Pipe Write handle
    81 	TInt iSize;
    82 
    83 
    84 	};
    85 
    86 TData::TData(RPipe * aPipe , RPipe *bPipe, TInt aSize) {
    87 	rPipe = aPipe;
    88 	wPipe = bPipe;
    89 	iSize = aSize;
    90 
    91 }
    92 
    93 ////////////////////////////////////////////////////
    94 //// WaitThread : Function opens the Read handle
    95 ////			for the pipe passed to it.
    96 ////
    97 ////			CPipeName --> Pipe Name
    98 ////			aData 	  --> Read Write Handle
    99 ////
   100 ////////////////////////////////////////////////////
   101 TBufC<100> 		cPipeName;
   102 
   103 TInt WaitThread(TAny* aData) {
   104 
   105 	test2.Start(_L("PIPE TEST:WaitThread Entry"));
   106 	TInt 		ret;
   107 
   108 	TData& data = *(TData *)aData; 					// aData will have pipe handles and size.
   109 
   110 	ret = data.rPipe->Open(cPipeName,RPipe::EOpenToRead);
   111 	test2 (ret == KErrNone);
   112 
   113 	test2.Printf(_L("PIPE TEST:WaitThread Exit\n"));
   114 	test2.End();
   115 	test2.Close();
   116 	return KErrNone;
   117 }
   118 
   119 ////////////////////////////////////////////////////
   120 //// NotifyDataThread :
   121 ////			Function writes data into the pipe.
   122 ////
   123 ////			aData 	  --> Read Write Handle
   124 ////
   125 ////////////////////////////////////////////////////
   126 
   127 TInt NotifyDataThread(TAny* aData) {
   128 
   129 	TBufC8<50> 			cTestData(KTestDataNum); 	// Test Data
   130 	TInt 				ret;
   131 
   132 	test3.Start(_L("PIPE TEST:NotifyDataThread Entry"));
   133 
   134 	TData& data = *(TData *)aData; 					// aData will have pipe handles and size.
   135 
   136 	User::After(10000);
   137 
   138 	ret = data.wPipe->Write(cTestData,cTestData.Length());
   139 	test3(ret == cTestData.Length());
   140 
   141 	test3.Printf(_L("PIPE TEST:NotifyDataThread Exit\n"));
   142 	test3.End();
   143 	test3.Close();
   144 	return KErrNone;
   145 }
   146 
   147 ////////////////////////////////////////////////////
   148 //// NotifySpaceThread :
   149 ////			Function flush the pipe and makes
   150 ////			it free.
   151 ////
   152 ////			aData 	  --> Read Write Handle
   153 ////
   154 ////////////////////////////////////////////////////
   155 
   156 TInt NotifySpaceThread(TAny* aData) {
   157 
   158 
   159 	test4.Start(_L("PIPE TEST:NotifySpaceThread Entry"));
   160 
   161 	TData& data = *(TData *)aData; 					// aData will have pipe handles and size.
   162 
   163 //	User::After(10000000);
   164 
   165 	data.rPipe->Flush();
   166 
   167 	test4.Printf(_L("PIPE TEST:NotifySpaceThread Exit\n"));
   168 	test4.End();
   169 	test4.Close();
   170 	return KErrNone;
   171 }
   172 
   173 
   174 ////////////////////////////////////////////////////
   175 //// CancelNotifyThread :
   176 ////			Function cancels Space available request
   177 ////			or Cancels Data available request.
   178 ////
   179 ////			CancelFlag  --> 1 CancelSpaceAvailable
   180 ////							0 for CancelDataAvailable
   181 ////
   182 ////			aData 	  --> Read Write Handle
   183 ////
   184 ////////////////////////////////////////////////////
   185 
   186 TInt		CancelFlag; // 1 CancelSpaceAvailable ; 0 for CancelDataAvailable
   187 TInt CancelNotifyThread(TAny* aData) {
   188 
   189 	test5.Start(_L("PIPE TEST:CancelNotifyThread Entry"));
   190 
   191 	TData& data = *(TData *)aData; 					// aData will have pipe handles and size.
   192 
   193 	if ( CancelFlag == 1)
   194 		data.wPipe->CancelSpaceAvailable();
   195 	else if ( CancelFlag == 0)
   196 		data.rPipe->CancelDataAvailable();
   197 	else
   198 		test5.Printf(_L("PIPE TEST: *** Illegal Cancel\n"));
   199 
   200 	test5.Printf(_L("PIPE TEST:CancelNotifyThread Exit\n"));
   201 	test5.End();
   202 	test5.Close();
   203 	return KErrNone;
   204 }
   205 
   206 ////////////////////////////////////////////////////
   207 //// Main Thread
   208 ////
   209 ////
   210 ////////////////////////////////////////////////////
   211 /*
   212 
   213 
   214 1. Create 5 (UN)Pipes.
   215 2. Register NotifyData AVailable on 5 pipes.
   216 3. Create Thread 1
   217 4. Wait for n request.
   218 5. In thread 1 write data into any one pipe. Exit
   219 6. Main should show 1 stat variable updated.
   220 
   221 7. Again call Wait for n request.
   222 8. It shall come out as one stat is Available.
   223 
   224 9. Close all the pipes. Repeat same for NotifySpace available.
   225 
   226 10. Define 5 N-Pipes
   227 11. Open write end and call wait till read end open.
   228 12. Create thread 2
   229 12. Wait for n request
   230 13. In thread 2 , open read end of one of the pipe.
   231 14. Main should show 1 stat variable updated.
   232 
   233 15. Again call Wait for n request.
   234 16. It shall come out as one stat is Available.
   235 
   236 17. Close all the pipes. Destroy pipes.
   237 
   238 18. Create 3 N pipe and 2 UN pipes.
   239 19. Register 2 NDA , 2 NSA , 2 Read end wait.
   240 20. Create thread 3 make any request successful.
   241 
   242 
   243 */
   244 
   245 LOCAL_C void test_MainThread()
   246 {
   247 
   248 		RPipe			aReader1,aWriter1;			// Used to pass to thread.
   249 		RPipe			aReader2,aWriter2;			// Used to pass to thread.
   250 		RPipe			aReader3,aWriter3;			// Used to pass to thread.
   251 		RPipe			aReader4,aWriter4;			// Used to pass to thread.
   252 		RPipe			aReader5,aWriter5;			// Used to pass to thread.
   253 
   254 		TInt			ret,aSize;
   255 		RThread			thread2;
   256 		RThread			thread3;
   257 		RThread			thread4;
   258 		RThread			thread5;
   259 
   260 		TRequestStatus	stat1;
   261 		TRequestStatus	stat2;
   262 		TRequestStatus	stat3;
   263 		TRequestStatus	stat4;
   264 		TRequestStatus	stat5;
   265 
   266 		TRequestStatus	s;
   267 
   268 		TRequestStatus	*ReqArray[] =
   269 		{
   270 			&stat1,&stat2,&stat3,&stat4,&stat5
   271 		};
   272 		const TBufC<100> 		cPipeName1(KPipe1Name);
   273 		TBufC8<50> 				cTestData(KTestDataNum); 	// Test Data
   274 
   275 
   276 
   277 		test.Printf(_L("PIPE TEST:Main Thread Entry\n"));
   278 
   279 //Test	1:
   280 
   281 		aSize = 10;
   282 		// Create 5 Pipes.
   283 		ret = RPipe::Create( aSize,	aReader1,aWriter1,EOwnerProcess, EOwnerProcess);
   284 		test_KErrNone(ret);
   285 		ret = RPipe::Create( aSize,	aReader2,aWriter2,EOwnerProcess, EOwnerProcess);
   286 		test_KErrNone(ret);
   287 		ret = RPipe::Create( aSize,	aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
   288 		test_KErrNone(ret);
   289 		ret = RPipe::Create( aSize,	aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
   290 		test_KErrNone(ret);
   291 		ret = RPipe::Create( aSize,	aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
   292 		test_KErrNone(ret);
   293 		// Register Notification for Data Available for all 5 pipes.
   294 		aReader1.NotifyDataAvailable(stat1);
   295 		aReader2.NotifyDataAvailable(stat2);
   296 		aReader3.NotifyDataAvailable(stat3);
   297 		aReader4.NotifyDataAvailable(stat4);
   298 		aReader5.NotifyDataAvailable(stat5);
   299 
   300 
   301 		// Pass handles for Pipe# 3
   302 		TData data1(&aReader3,&aWriter3,aSize);
   303 
   304 		// Create thread for Writing data into pipe.
   305 		// This will make status variable of respective pipe as AVAILABLE
   306 		ret = thread3.Create(
   307 								KThread3Name, 		// Thread name
   308 								NotifyDataThread,			// Function to be called
   309 								KDefaultStackSize,
   310 								KHeapSize,
   311 								KHeapSize,
   312 								(TAny *)&data1		// Data object containing Pipe information.
   313 							);
   314 		test_KErrNone(ret);
   315 		thread3.Logon(s);
   316 		test_Equal(KRequestPending, s.Int());
   317 
   318 		// Start the Thread
   319 		thread3.Resume();
   320 
   321 		// Wait till any of the request status is Avaialble
   322 		User::WaitForNRequest(ReqArray,5);
   323 
   324 		// As WaitForNRequest returned. This proves test pass.
   325 		test.Printf(_L("PIPE TEST:Test 1: Pass\n"));
   326 
   327 		// Cancel all pending requests for other tests.
   328 		aReader1.CancelDataAvailable();
   329 		aReader2.CancelDataAvailable();
   330 		aReader3.CancelDataAvailable();
   331 		aReader4.CancelDataAvailable();
   332 		aReader5.CancelDataAvailable();
   333 
   334 		// Close thread.
   335 		User::WaitForRequest(s);
   336 		CLOSE_AND_WAIT(thread3);
   337 
   338 
   339 //Test	2:
   340 
   341 		// Pipes created in Test 1.
   342 		// Write data into all the pipes and Fill it.
   343 		aWriter1.Write(cTestData,cTestData.Length());
   344 		aWriter2.Write(cTestData,cTestData.Length());
   345 		aWriter3.Write(cTestData,cTestData.Length());
   346 		aWriter4.Write(cTestData,cTestData.Length());
   347 		aWriter5.Write(cTestData,cTestData.Length());
   348 
   349 		// Register notification for Space availability for all pipes.
   350 			
   351 		aWriter1.NotifySpaceAvailable(aSize,stat1);
   352 		aWriter2.NotifySpaceAvailable(aSize,stat2);
   353 		aWriter3.NotifySpaceAvailable(aSize,stat3);
   354 		aWriter4.NotifySpaceAvailable(aSize,stat4);
   355 		aWriter5.NotifySpaceAvailable(aSize,stat5);
   356 
   357 
   358 		// Create data object for Pipe# 5.
   359 		TData data2(&aReader5,&aWriter5,aSize);
   360 
   361 		// Create thread which will make space available in Pipe.
   362 		//
   363 		ret = thread4.Create(
   364 								KThread4Name, 		// Thread name
   365 								NotifySpaceThread,			// Function to be called
   366 								KDefaultStackSize,
   367 								KHeapSize,
   368 								KHeapSize,
   369 								(TAny *)&data2		// Data object containing Pipe information.
   370 							);
   371 		test_KErrNone(ret);
   372 		thread4.Logon(s);
   373 		test_Equal(KRequestPending, s.Int());
   374 
   375 		// Start the thread.
   376 		thread4.Resume();
   377 
   378 		// Wait till any of the status variable status change to Avaialble
   379 		User::WaitForNRequest(ReqArray,5);
   380 
   381 		test.Printf(_L("PIPE TEST:Test 2: Pass\n"));
   382 
   383 		// Cancel all pending requests.
   384 		aWriter1.CancelSpaceAvailable();
   385 		aWriter2.CancelSpaceAvailable();
   386 		aWriter3.CancelSpaceAvailable();
   387 		aWriter4.CancelSpaceAvailable();
   388 		aWriter5.CancelSpaceAvailable();
   389 
   390 		// Close the thread.
   391 		User::WaitForRequest(s);
   392 		CLOSE_AND_WAIT(thread4);
   393 
   394 //Test	3:
   395 		// Flush all the Pipes.
   396 		// This is needed for NotifyDataAvailable request.
   397 		aReader1.Flush();
   398 		aReader2.Flush();
   399 		aReader3.Flush();
   400 		aReader4.Flush();
   401 		aReader5.Flush();
   402 
   403 		// Register NotifyDataAvailable request for all the pipes.
   404 		
   405 		CancelFlag = 0;	// 0 = CanceldataAvailable()
   406 		aReader1.NotifyDataAvailable(stat1);
   407 		aReader2.NotifyDataAvailable(stat2);
   408 		aReader3.NotifyDataAvailable(stat3);
   409 		aReader4.NotifyDataAvailable(stat4);
   410 		aReader5.NotifyDataAvailable(stat5);
   411 
   412 		TData data3(&aReader2,&aWriter2,aSize);
   413 
   414 		ret = thread5.Create(
   415 								KThread5Name, 		// Thread name
   416 								CancelNotifyThread,			// Function to be called
   417 								KDefaultStackSize,
   418 								KHeapSize,
   419 								KHeapSize,
   420 								(TAny *)&data3		// Data object containing Pipe information.
   421 							);
   422 		test_KErrNone(ret);
   423 		thread5.Logon(s);
   424 		test_Equal(KRequestPending, s.Int());
   425 		thread5.Resume();
   426 
   427 		User::WaitForNRequest(ReqArray,5);
   428 
   429 		test.Printf(_L("PIPE TEST:Test 3: Pass\n"));
   430 		aReader1.CancelDataAvailable();
   431 		aReader2.CancelDataAvailable();
   432 		aReader3.CancelDataAvailable();
   433 		aReader4.CancelDataAvailable();
   434 		aReader5.CancelDataAvailable();
   435 		User::WaitForRequest(s);
   436 		CLOSE_AND_WAIT(thread5);
   437 
   438 
   439 //Test	4:
   440 		aReader1.Close();
   441 		aWriter1.Close();
   442 		aReader2.Close();
   443 		aWriter2.Close();
   444 		aReader3.Close();
   445 		aWriter3.Close();
   446 		aReader4.Close();
   447 		aWriter4.Close();
   448 		aReader5.Close();
   449 		aWriter5.Close();
   450 
   451 		ret = RPipe::Define(KPipe1Name,aSize);
   452 		test_KErrNone(ret);
   453 		ret = RPipe::Define(KPipe2Name,aSize);
   454 		test_KErrNone(ret);
   455 		ret = RPipe::Define(KPipe3Name,aSize);
   456 		test_KErrNone(ret);
   457 		ret = RPipe::Define(KPipe4Name,aSize);
   458 		test_KErrNone(ret);
   459 		ret = RPipe::Define(KPipe5Name,aSize);
   460 		test_KErrNone(ret);
   461 
   462 		aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
   463 		aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
   464 		aWriter3.Open(KPipe3Name,RPipe::EOpenToWrite);
   465 		aWriter4.Open(KPipe4Name,RPipe::EOpenToWrite);
   466 		aWriter5.Open(KPipe5Name,RPipe::EOpenToWrite);
   467 
   468 		aWriter1.Wait(KPipe1Name,stat1);
   469 		aWriter2.Wait(KPipe2Name,stat2);
   470 		aWriter3.Wait(KPipe3Name,stat3);
   471 		aWriter4.Wait(KPipe4Name,stat4);
   472 		aWriter5.Wait(KPipe5Name,stat5);
   473 
   474 		const TBufC<100> 		cPipeName2(KPipe2Name);
   475 
   476 		TData data4(&aReader2,&aWriter2,aSize);
   477 		cPipeName = cPipeName2;
   478 
   479 		ret = thread2.Create(
   480 								KThread2Name, 		// Thread name
   481 								WaitThread,			// Function to be called
   482 								KDefaultStackSize,
   483 								KHeapSize,
   484 								KHeapSize,
   485 								(TAny *)&data4		// Data object containing Pipe information.
   486 							);
   487 		test_KErrNone(ret);
   488 		thread2.Logon(s);
   489 		test_Equal(KRequestPending, s.Int());
   490 		thread2.Resume();
   491 		User::WaitForNRequest(ReqArray,5);
   492 		test.Printf(_L("PIPE TEST:Test 4: Pass\n"));
   493 		aWriter1.CancelWait();
   494 		aWriter2.CancelWait();
   495 		aWriter3.CancelWait();
   496 		aWriter4.CancelWait();
   497 		aWriter5.CancelWait();
   498 
   499 		aReader1.Close();		aWriter1.Close();
   500 		aReader2.Close();		aWriter2.Close();
   501 		aReader3.Close();		aWriter3.Close();
   502 		aReader4.Close();		aWriter4.Close();
   503 		aReader5.Close();		aWriter5.Close();
   504 
   505 		User::WaitForRequest(s);
   506 		CLOSE_AND_WAIT(thread2);
   507 
   508 //Test	5:
   509 
   510 		ret =aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
   511 		test_KErrNone(ret);
   512 		aReader1.Close();
   513 		//ret =aWriter1.Wait(KPipe1Name,stat1);
   514 		aWriter1.Wait(KPipe1Name,stat1);
   515 
   516 		ret =aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
   517 		test_KErrNone(ret);
   518 		ret =aReader2.Open(KPipe2Name,RPipe::EOpenToRead);
   519 		test_KErrNone(ret);
   520 		ret =aWriter2.Write(cTestData,cTestData.Length());
   521 		//ret =aWriter2.NotifySpaceAvailable(aSize,stat2);
   522 		aWriter2.NotifySpaceAvailable(aSize,stat2);
   523 
   524 		ret = RPipe::Create( aSize,	aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
   525 		test_KErrNone(ret);
   526 		aReader3.Flush();
   527 		//ret =aReader3.NotifyDataAvailable(stat3);
   528 		aReader3.NotifyDataAvailable(stat3);
   529 
   530 		ret = RPipe::Create( aSize,	aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
   531 		test_KErrNone(ret);
   532 		ret =aWriter4.Write(cTestData,cTestData.Length());
   533 		//ret =aWriter4.NotifySpaceAvailable(aSize,stat4);
   534 		aWriter4.NotifySpaceAvailable(aSize,stat4);
   535 
   536 		ret = RPipe::Create( aSize,	aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
   537 		test_KErrNone(ret);
   538 		aReader5.Flush();
   539 		//ret =aReader5.NotifyDataAvailable(stat5);
   540 		aReader5.NotifyDataAvailable(stat5);
   541 
   542 		TData data5(&aReader3,&aWriter3,aSize);
   543 		cPipeName = cPipeName2;
   544 
   545 		RThread thread6;
   546 
   547 		ret = thread6.Create(
   548 								KThread3Name, 		// Thread name
   549 								NotifyDataThread,			// Function to be called
   550 								KDefaultStackSize,
   551 								KHeapSize,
   552 								KHeapSize,
   553 								(TAny *)&data5		// Data object containing Pipe information.
   554 							);
   555 		test_KErrNone(ret);
   556 		thread6.Logon(s);
   557 		test_Equal(KRequestPending, s.Int());
   558 		thread6.Resume();
   559 		User::WaitForNRequest(ReqArray,5);
   560 		test.Printf(_L("PIPE TEST:Test 5: Pass\n"));
   561 
   562 		User::WaitForRequest(s);
   563 		CLOSE_AND_WAIT(thread6);
   564 //Test	6:
   565 
   566 		TData data6(&aReader2,&aWriter2,aSize);
   567 		cPipeName = cPipeName2;
   568 
   569 		RThread thread7;
   570 
   571 		ret = thread7.Create(
   572 								KThread3Name, 		// Thread name
   573 								NotifySpaceThread,			// Function to be called
   574 								KDefaultStackSize,
   575 								KHeapSize,
   576 								KHeapSize,
   577 								(TAny *)&data6		// Data object containing Pipe information.
   578 							);
   579 		test_KErrNone(ret);
   580 		thread7.Logon(s);
   581 		test_Equal(KRequestPending, s.Int());
   582 		thread7.Resume();
   583 
   584 		User::WaitForNRequest(ReqArray,5);
   585 		test.Printf(_L("PIPE TEST:Test 6: Pass\n"));
   586 
   587 
   588 		User::WaitForRequest(s);
   589 		CLOSE_AND_WAIT(thread7);
   590 
   591 //Test	7:
   592 		TData data7(&aReader1,&aWriter1,aSize);
   593 		cPipeName = cPipeName1;
   594 
   595 		RThread thread8;
   596 
   597 		ret = thread8.Create(
   598 								KThread2Name, 		// Thread name
   599 								WaitThread,			// Function to be called
   600 								KDefaultStackSize,
   601 								KHeapSize,
   602 								KHeapSize,
   603 								(TAny *)&data7		// Data object containing Pipe information.
   604 							);
   605 		test_KErrNone(ret);
   606 		thread8.Logon(s);
   607 		test_Equal(KRequestPending, s.Int());
   608 		thread8.Resume();
   609 
   610 		User::WaitForNRequest(ReqArray,5);
   611 		test.Printf(_L("PIPE TEST:Test 7: Pass\n"));
   612 
   613 
   614 		User::WaitForRequest(s);
   615 //		CLOSE_AND_WAIT(thread8);	DOESN'T WORK SINCE PIPE DRIVER KEEPS THE THREAD OPEN
   616 		thread8.Close();
   617 
   618 //Test	8:
   619 		TData data8(&aReader4,&aWriter4,aSize);
   620 
   621 		RThread thread9;
   622 		
   623 		CancelFlag = 1;	// 1 = CancelSpaceAvailable()
   624 
   625 		ret = thread9.Create(
   626 								KThread4Name, 		// Thread name
   627 								CancelNotifyThread,			// Function to be called
   628 								KDefaultStackSize,
   629 								KHeapSize,
   630 								KHeapSize,
   631 								(TAny *)&data8		// Data object containing Pipe information.
   632 							);
   633 		test_KErrNone(ret);
   634 		thread9.Logon(s);
   635 		test_Equal(KRequestPending, s.Int());
   636 		thread9.Resume();
   637 
   638 		User::WaitForNRequest(ReqArray,5);
   639 		test.Printf(_L("PIPE TEST:Test 8: Pass\n"));
   640 
   641 		User::WaitForRequest(s);
   642 		CLOSE_AND_WAIT(thread9);
   643 
   644 //Test	9:
   645 		TData data9(&aReader5,&aWriter5,aSize);
   646 
   647 		RThread thread10;
   648 
   649 		CancelFlag = 0;	// 0 = CancelDataAvailable()
   650 
   651 		ret = thread10.Create(
   652 								KThread5Name, 		// Thread name
   653 								CancelNotifyThread,			// Function to be called
   654 								KDefaultStackSize,
   655 								KHeapSize,
   656 								KHeapSize,
   657 								(TAny *)&data9		// Data object containing Pipe information.
   658 							);
   659 		test_KErrNone(ret);
   660 		thread10.Logon(s);
   661 		test_Equal(KRequestPending, s.Int());
   662 		thread10.Resume();
   663 
   664 		
   665 		User::WaitForNRequest(ReqArray,5);
   666 		test.Printf(_L("PIPE TEST:Test 9: Pass\n"));
   667 
   668 		User::WaitForRequest(s);
   669 		CLOSE_AND_WAIT(thread10);
   670 
   671 
   672 		aReader1.Close();		aWriter1.Close();
   673 		aReader2.Close();		aWriter2.Close();
   674 		aReader3.Close();		aWriter3.Close();
   675 		aReader4.Close();		aWriter4.Close();
   676 		aReader5.Close();		aWriter5.Close();
   677 		ret = RPipe::Destroy(KPipe1Name);
   678 		test_KErrNone(ret);
   679 		ret = RPipe::Destroy(KPipe2Name);
   680 		test_KErrNone(ret);
   681 		ret = RPipe::Destroy(KPipe3Name);
   682 		test_KErrNone(ret);
   683 		ret = RPipe::Destroy(KPipe4Name);
   684 		test_KErrNone(ret);
   685 		ret = RPipe::Destroy(KPipe5Name);
   686 		test_KErrNone(ret);
   687 		
   688 		
   689 		test.Printf(_L("PIPE TEST:Main Thread Exit\n"));
   690 		return;
   691 
   692 
   693 
   694 }
   695 
   696 ////////////////////////////////////////////////////
   697 //// RunTests:
   698 ////
   699 ////
   700 ////////////////////////////////////////////////////
   701 LOCAL_C void RunTests(void)
   702 {
   703 
   704 	test.Start(_L("PIPE TEST: Testing WaitForNRequest"));
   705 
   706 	test_MainThread();
   707 
   708 	test.Printf(_L("PIPE TEST: Ending test.\n"));
   709 
   710 	test.End();
   711 	test.Close();
   712 	return;
   713 }
   714 
   715 
   716 ////////////////////////////////////////////////////
   717 //// E32Main : Main entry point to test.
   718 ////
   719 ////
   720 ////////////////////////////////////////////////////
   721 
   722 
   723 GLDEF_C TInt E32Main()
   724 
   725 {
   726 	TInt		ret = 0;
   727 
   728 	ret = RPipe::Init();
   729 	
   730 	if (ret != KErrNone && ret != KErrAlreadyExists)
   731 	{
   732 	test.Printf(_L(" t_pipe4.exe PIPE TEST: Error loading driver %d\n"),ret);
   733 	test.Printf(_L(" Exiting t_pipe4.exe\n"));
   734 
   735 	return KErrNone;
   736 
   737 	}
   738 	RunTests();
   739 
   740 	TName pddName1(RPipe::Name());
   741 	
   742 	ret= User::FreeLogicalDevice(pddName1);
   743 	
   744 	return KErrNone;
   745 	
   746 }