kerneltest/e32test/active/t_messge.cpp
branchRCL_3
changeset 39 2bb754abd467
parent 6 0173bcd7697c
child 43 c1f20ce4abcf
equal deleted inserted replaced
36:bbf8bed59bcb 39:2bb754abd467
    76 
    76 
    77 
    77 
    78 class CTestSession : public CSession2
    78 class CTestSession : public CSession2
    79 	{
    79 	{
    80 public:
    80 public:
    81 	enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter,ETestMessageConstruction, ETestRMessagePtr2LeavingInterface};
    81 	enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter,ETestMessageConstruction, 
       
    82 		ETestRMessagePtr2LeavingInterface, ETestKillCompletePanic};
    82 //Override pure virtual
    83 //Override pure virtual
    83 	IMPORT_C virtual void ServiceL(const RMessage2& aMessage);
    84 	IMPORT_C virtual void ServiceL(const RMessage2& aMessage);
    84 private:
    85 private:
    85 	void TestInt(const RMessage2& aMessage);
    86 	void TestInt(const RMessage2& aMessage);
    86 	void TestPtr(const RMessage2& aMessage);
    87 	void TestPtr(const RMessage2& aMessage);
   321 			r=TestMessageConstruction(aMessage);
   322 			r=TestMessageConstruction(aMessage);
   322 			break;
   323 			break;
   323 		case ETestRMessagePtr2LeavingInterface:
   324 		case ETestRMessagePtr2LeavingInterface:
   324 			r=TestRMessagePtr2LeavingInterface(aMessage);
   325 			r=TestRMessagePtr2LeavingInterface(aMessage);
   325 			break;
   326 			break;
       
   327 		case ETestKillCompletePanic:
       
   328 			aMessage.Complete(KErrNone);
       
   329 			aMessage.Panic(_L("Testing Panic"),0xFF); //This will panic the server!
       
   330 			break;
   326 		default:
   331 		default:
   327 			r=KErrNotSupported;
   332 			r=KErrNotSupported;
   328 
   333 
   329 		}						  
   334 		}						  
   330  	aMessage.Complete(r);
   335  	aMessage.Complete(r);
   478 		User::Panic(_L("StartServr failure"),r);
   483 		User::Panic(_L("StartServr failure"),r);
   479 		}
   484 		}
   480 
   485 
   481 
   486 
   482 	test.Next(_L("Start ActiveScheduler and signal to client"));
   487 	test.Next(_L("Start ActiveScheduler and signal to client"));
   483 	test.Printf(_L("        There might be something going on beneath this window"));
   488 	test.Printf(_L("        There might be something going on beneath this window\n"));
   484 	sem.Signal();
   489 	sem.Signal();
   485 	CActiveScheduler::Start();
   490 	CActiveScheduler::Start();
   486 	test.Next(_L("Destroy ActiveScheduler"));
   491 	test.Next(_L("Destroy ActiveScheduler"));
   487 	delete pScheduler;
   492 	delete pScheduler;
   488 	delete pServer;
   493 	delete pServer;
   515 	
   520 	
   516 	TInt r=session.PublicCreateSession(_L("CTestServer"),1);
   521 	TInt r=session.PublicCreateSession(_L("CTestServer"),1);
   517 	test(r==KErrNone);
   522 	test(r==KErrNone);
   518 
   523 
   519 	r=session.PublicSendReceive(CTestSession::ETestCompletePanic, TIpcArgs());
   524 	r=session.PublicSendReceive(CTestSession::ETestCompletePanic, TIpcArgs());
       
   525 	test(r==KErrNone);
       
   526 
       
   527 	session.PublicSendReceive(CTestSession::EStop, TIpcArgs());//panic should occur before this is serviced 
       
   528 	return(KErrNone);
       
   529 	}
       
   530 	
       
   531 TInt KillCompletePanicClientThread (TAny*)
       
   532 //
       
   533 //  A client thread entry - signals to server to kill client after completing the message
       
   534 //
       
   535 	{
       
   536 	sem.Wait();
       
   537 	
       
   538 	TInt r=session.PublicCreateSession(_L("CTestServer"),1);
       
   539 	test(r==KErrNone);
       
   540 
       
   541 	r=session.PublicSendReceive(CTestSession::ETestKillCompletePanic, TIpcArgs());
   520 	test(r==KErrNone);
   542 	test(r==KErrNone);
   521 
   543 
   522 	session.PublicSendReceive(CTestSession::EStop, TIpcArgs());//panic should occur before this is serviced 
   544 	session.PublicSendReceive(CTestSession::EStop, TIpcArgs());//panic should occur before this is serviced 
   523 	return(KErrNone);
   545 	return(KErrNone);
   524 	}
   546 	}
   573 	test.Next(_L("Assignment operator"));
   595 	test.Next(_L("Assignment operator"));
   574 	messagePtr1=messagePtr2;
   596 	messagePtr1=messagePtr2;
   575 
   597 
   576 	test.End();
   598 	test.End();
   577 	}
   599 	}
   578 
   600 	
   579 
   601 void TestServerCompleteTwicePanic(void)
   580 GLDEF_C TInt E32Main()
   602 	{
   581 	{
   603 	TRequestStatus clientStat,serverStat;
   582 	test.Title();
   604 	
   583 	
       
   584 	test.Start(_L("Simple RMessage2 tests"));
       
   585 	SimpleRMessage();
       
   586 
       
   587 	test.Next(_L("Simple RMessagePtr2 tests"));
       
   588 	SimpleRMessagePtr();
       
   589 
       
   590 	test.Next(_L("Sending messages between two threads"));
       
   591 	test.Start(_L("Create client and server threads"));
       
   592 	clientThread.Create(_L("Client Thread"),ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   593 	serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   594 	
       
   595 	test.Next(_L("Logon to the threads"));
       
   596 	TRequestStatus clientStat,serverStat;	
       
   597 	clientThread.Logon(clientStat);
       
   598 	serverThread.Logon(serverStat);
       
   599 
       
   600 	test.Next(_L("Start the threads"));
       
   601 	sem.CreateLocal(0);
       
   602 	clientThread.Resume();
       
   603 	serverThread.Resume();
       
   604 	
       
   605 	test.Next(_L("Wait for the threads to stop"));
       
   606 	if(clientStat==KRequestPending)
       
   607 		User::WaitForRequest(clientStat);
       
   608 	if(serverStat==KRequestPending)
       
   609 		User::WaitForRequest(serverStat);
       
   610 	switch (clientThread.ExitType())
       
   611 		{
       
   612 		case EExitKill:
       
   613 			test.Printf(_L("  Client thread killed\n")); 
       
   614 			break;
       
   615 		case EExitTerminate:
       
   616 			test.Printf(_L("!!Client thread terminated:"));
       
   617 			test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
       
   618 		case EExitPanic:
       
   619 			test.Panic(_L("!!Client thread panicked:"));
       
   620 			test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
       
   621 		default:
       
   622 			test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason());
       
   623 		}
       
   624 	switch (serverThread.ExitType())
       
   625 		{
       
   626 		case EExitKill:
       
   627 			test.Printf(_L("  Server thread killed\n")); 
       
   628 			break;
       
   629 		case EExitTerminate:
       
   630 			test.Printf(_L("!!Server thread terminated:"));
       
   631 			test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
       
   632 		case EExitPanic:
       
   633 			test.Printf(_L("!!Server thread panicked:"));
       
   634 			test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
       
   635 			//
       
   636 			// To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP).
       
   637 			//
       
   638 		default:
       
   639 			test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason());
       
   640 		}
       
   641 
       
   642 	test.Next(_L("Close the threads"));
       
   643 	CLOSE_AND_WAIT(serverThread);
       
   644 	CLOSE_AND_WAIT(clientThread);
       
   645 	test.End();
       
   646 
       
   647 	TBool justInTime=User::JustInTime();
   605 	TBool justInTime=User::JustInTime();
   648 	
   606 	
   649  	test.Next(_L("Check it Panics if you try to Complete a message twice"));
   607  	test.Next(_L("Check server panics if you try to complete a message twice"));
   650 	test.Start(_L("Create client and server threads"));
   608 	test.Start(_L("Create client and server threads"));
   651 	clientThread.Create(_L("Client Thread1"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
   609 	clientThread.Create(_L("Client Thread1"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
   652 	serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
   610 	serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
   653 	
   611 	
   654 	test.Next(_L("Logon to the threads"));
   612 	test.Next(_L("Logon to the threads"));
   676 
   634 
   677 	test.Next(_L("Close the threads"));
   635 	test.Next(_L("Close the threads"));
   678 	CLOSE_AND_WAIT(serverThread);
   636 	CLOSE_AND_WAIT(serverThread);
   679 	CLOSE_AND_WAIT(clientThread);
   637 	CLOSE_AND_WAIT(clientThread);
   680 	test.End();	  
   638 	test.End();	  
       
   639 	}
       
   640 	
       
   641 void TestServerKillCompletePanic(void)
       
   642 	{
       
   643 	TRequestStatus clientStat,serverStat;
       
   644 	
       
   645 	TBool justInTime=User::JustInTime();
       
   646 	
       
   647 	test.Next(_L("Check Server panics if you try to panic a client using a completed message"));
       
   648 	test.Start(_L("Create client and server threads"));
       
   649 	clientThread.Create(_L("Client Thread2"),KillCompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   650 	serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   651 	
       
   652 	test.Next(_L("Logon to the threads"));
       
   653 	clientThread.Logon(clientStat);
       
   654 	serverThread.Logon(serverStat);
       
   655 
       
   656 	test.Next(_L("Start the threads"));
       
   657 	sem.CreateLocal(0);
       
   658 	User::SetJustInTime(EFalse); 
       
   659 	clientThread.Resume();
       
   660 	serverThread.Resume();
       
   661 	
       
   662 	test.Next(_L("Wait for the threads to stop"));
       
   663 	User::WaitForRequest(clientStat); 
       
   664 	User::WaitForRequest(serverStat);
       
   665 	User::SetJustInTime(justInTime); 
       
   666 	test.Next(_L("Check the exit categories"));
       
   667 	test(clientThread.ExitType()==EExitKill);
       
   668 	test(clientThread.ExitCategory().Compare(_L("Kill"))==0);
       
   669 	test(clientThread.ExitReason()==KErrNone);
       
   670 		
       
   671 	test(serverThread.ExitType()==EExitPanic);
       
   672 	test(serverThread.ExitCategory().Compare(_L("KERN-EXEC"))==0);
       
   673 	test(serverThread.ExitReason()==EBadMessageHandle);
       
   674 	
       
   675 	test.Next(_L("Close the threads"));
       
   676 	CLOSE_AND_WAIT(serverThread);
       
   677 	CLOSE_AND_WAIT(clientThread);
       
   678 	test.End();	 
       
   679 	}	
       
   680 
       
   681 GLDEF_C TInt E32Main()
       
   682 	{
       
   683 	test.Title();
       
   684 	
       
   685 	test.Start(_L("Simple RMessage2 tests"));
       
   686 	SimpleRMessage();
       
   687 
       
   688 	test.Next(_L("Simple RMessagePtr2 tests"));
       
   689 	SimpleRMessagePtr();
       
   690 
       
   691 	test.Next(_L("Sending messages between two threads"));
       
   692 	test.Start(_L("Create client and server threads"));
       
   693 	clientThread.Create(_L("Client Thread"),ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   694 	serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL);
       
   695 	
       
   696 	test.Next(_L("Logon to the threads"));
       
   697 	TRequestStatus clientStat,serverStat;	
       
   698 	clientThread.Logon(clientStat);
       
   699 	serverThread.Logon(serverStat);
       
   700 
       
   701 	test.Next(_L("Start the threads"));
       
   702 	sem.CreateLocal(0);
       
   703 	clientThread.Resume();
       
   704 	serverThread.Resume();
       
   705 	
       
   706 	test.Next(_L("Wait for the threads to stop"));
       
   707 	if(clientStat==KRequestPending)
       
   708 		User::WaitForRequest(clientStat);
       
   709 	if(serverStat==KRequestPending)
       
   710 		User::WaitForRequest(serverStat);
       
   711 	switch (clientThread.ExitType())
       
   712 		{
       
   713 		case EExitKill:
       
   714 			test.Printf(_L("  Client thread killed\n")); 
       
   715 			break;
       
   716 		case EExitTerminate:
       
   717 			test.Printf(_L("!!Client thread terminated:"));
       
   718 			test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
       
   719 		case EExitPanic:
       
   720 			test.Panic(_L("!!Client thread panicked:"));
       
   721 			test.Panic(clientThread.ExitCategory(), clientThread.ExitReason());
       
   722 		default:
       
   723 			test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason());
       
   724 		}
       
   725 	switch (serverThread.ExitType())
       
   726 		{
       
   727 		case EExitKill:
       
   728 			test.Printf(_L("  Server thread killed\n")); 
       
   729 			break;
       
   730 		case EExitTerminate:
       
   731 			test.Printf(_L("!!Server thread terminated:"));
       
   732 			test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
       
   733 		case EExitPanic:
       
   734 			test.Printf(_L("!!Server thread panicked:"));
       
   735 			test.Panic(serverThread.ExitCategory(), serverThread.ExitReason());
       
   736 			//
       
   737 			// To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP).
       
   738 			//
       
   739 		default:
       
   740 			test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason());
       
   741 		}
       
   742 
       
   743 	test.Next(_L("Close the threads"));
       
   744 	CLOSE_AND_WAIT(serverThread);
       
   745 	CLOSE_AND_WAIT(clientThread);
       
   746 	test.End();
       
   747 	
       
   748 	TestServerCompleteTwicePanic();
       
   749 	
       
   750 	TestServerKillCompletePanic();
   681   	
   751   	
   682 	test.End();
   752 	test.End();
   683   
   753   
   684 	return (KErrNone);
   754 	return (KErrNone);
   685 	}
   755 	}