realtimenetprots/sipfw/Test/CapTests/ClientResolver/Common/CSuite.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-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 "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 // @file  TS_PARAM_SVR_SUITENAMEServer.cpp
       
    15 // for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started
       
    16 // in the process of the client. The client initialises the server by calling the
       
    17 // one and only ordinal.
       
    18 // 
       
    19 //
       
    20 
       
    21 // EPOC includes
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h>
       
    24 
       
    25 #if (!defined TS_PARAM_SVR_SUITENAME_SERVER_H_)
       
    26 	#include "CSuite.h"
       
    27 #endif
       
    28 
       
    29 
       
    30 //ADD TEST STEP HEADERS HERE
       
    31 PARAM_FOREACH_MESS_BEGIN
       
    32 #include "PARAM_MESS_NAME_CStep.h"
       
    33 PARAM_FOREACH_MESS_END
       
    34 
       
    35 
       
    36 _LIT(KSipClientResolverServerName,"siprsvsrv");
       
    37 _LIT(KSipClientResolverServerFilename, "siprsvsrv");
       
    38 _LIT(KSipClientResolverServerSemaphoreName, "siprsvsrvSemaphore");
       
    39 const TUid KServerUid3 = { 0x1020334f };
       
    40 
       
    41 // __EDIT_ME__ - Substitute the name of your test server
       
    42 _LIT(KServerName,"Cap_PARAM_SVR_SUITENAME_sc");
       
    43 // __EDIT_ME__ - Use your own server class name
       
    44 
       
    45 CTestPARAM_SVR_SUITENAMEServer* CTestPARAM_SVR_SUITENAMEServer::NewL()
       
    46 /**
       
    47  * @return - Instance of the test server
       
    48  * Same code for Secure and non-secure variants
       
    49  * Called inside the MainL() function to create and start the
       
    50  * CTestServer derived server.
       
    51  */
       
    52 	{
       
    53 // __EDIT_ME__ - Use your own server class name
       
    54 	CTestPARAM_SVR_SUITENAMEServer * server = new (ELeave) CTestPARAM_SVR_SUITENAMEServer();
       
    55 	CleanupStack::PushL(server);
       
    56 	// CServer base class call
       
    57 	server->StartL(KServerName);
       
    58 	CleanupStack::Pop(server);
       
    59 	return server;
       
    60 	}
       
    61 
       
    62 CTestStep* CTestPARAM_SVR_SUITENAMEServer::CreateTestStep(const TDesC& aStepName)
       
    63 /**
       
    64  * @return - A CTestStep derived instance
       
    65  * Secure and non-secure variants
       
    66  * Implementation of CTestServer pure virtual
       
    67  */
       
    68 	{
       
    69 	 CTestStep* testStep = NULL;
       
    70 	// add test steps
       
    71 PARAM_FOREACH_MESS_BEGIN
       
    72 		if (aStepName == _L("CPARAM_MESS_NAMEStep"))
       
    73 			{
       
    74 			testStep =  new(ELeave) CPARAM_MESS_NAMEStep  ;
       
    75 			return testStep;
       
    76 			 }
       
    77 
       
    78 PARAM_FOREACH_MESS_END
       
    79 		return testStep;
       
    80 	 }
       
    81 
       
    82 
       
    83 
       
    84 // Secure variants much simpler
       
    85 // Just an E32Main and a MainL()
       
    86 LOCAL_C void MainL()
       
    87 /**
       
    88  * Secure variant
       
    89  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    90  */
       
    91 	{
       
    92 #if (defined __DATA_CAGING__)
       
    93 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    94 	RProcess().DataCaging(RProcess::ESecureApiOn);
       
    95 #endif
       
    96 	CActiveScheduler* sched=NULL;
       
    97 	sched=new(ELeave) CActiveScheduler;
       
    98 	CActiveScheduler::Install(sched);
       
    99 // __EDIT_ME__ - Use your own server class name
       
   100 	CTestPARAM_SVR_SUITENAMEServer* server = NULL;
       
   101 	// Create the CTestServer derived server
       
   102 	TRAPD(err,server = CTestPARAM_SVR_SUITENAMEServer::NewL());
       
   103 	if(!err)
       
   104 		{
       
   105 		// Sync with the client and enter the active scheduler
       
   106 		RProcess::Rendezvous(KErrNone);
       
   107 		sched->Start();
       
   108 		}
       
   109 	delete server;
       
   110 	delete sched;
       
   111 	}
       
   112 
       
   113 
       
   114 GLDEF_C TInt E32Main()
       
   115 /**
       
   116  * @return - Standard Epoc error code on process exit
       
   117  * Secure variant only
       
   118  * Process entry point. Called by client using RProcess API
       
   119  */
       
   120 	{
       
   121 	__UHEAP_MARK;
       
   122 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   123 	if(cleanup == NULL)
       
   124 		{
       
   125 		return KErrNoMemory;
       
   126 		}
       
   127 	TRAPD(err,MainL());
       
   128 	delete cleanup;
       
   129 	__UHEAP_MARKEND;
       
   130 	return KErrNone;
       
   131     }
       
   132 
       
   133 
       
   134 TVerdict CCapabilityTestStep::doTestStepPreambleL( void )
       
   135 	{
       
   136 	//If Preamble is not required just pass a success value
       
   137 	TVerdict testResult = CTestStep::doTestStepPreambleL();
       
   138 
       
   139 
       
   140 	return TestStepResult();
       
   141 
       
   142 	}
       
   143 TVerdict CCapabilityTestStep::doTestStepPostambleL( void )
       
   144 	{
       
   145 	//If Postamble is not required just pass a success value
       
   146 	TVerdict testResult = CTestStep::doTestStepPostambleL();
       
   147 
       
   148 	return TestStepResult();
       
   149 
       
   150 	}
       
   151 
       
   152 
       
   153 // Moved from CStep.cpp
       
   154 
       
   155 enum TVerdict CCapabilityTestStep::doTestStepL()
       
   156 	{
       
   157 	//DEF! INFO_PRINTF2(_L("%S - Starting ..."), &iTestStepName);
       
   158 
       
   159 	//The MainThread()creates a separate thread that executes SendReceive
       
   160 	TVerdict vResult = MainThread();
       
   161 
       
   162 	SetTestStepResult(vResult);
       
   163 	return TestStepResult();
       
   164 	}
       
   165 
       
   166 /*
       
   167 ThreadStartFn:
       
   168 Called by:	The Child thread
       
   169 Function:	Calls the Exec_SendReceive
       
   170 */
       
   171 static TInt ThreadStartFn( TAny * ptr )
       
   172 	{
       
   173 	return(((CCapabilityTestStep *)ptr)->Exec_SendReceive());
       
   174 	}
       
   175 
       
   176 /*
       
   177 TVerdict GetVerdict(TInt aAPIretValue)
       
   178 
       
   179 Called by: "MainThread" for returning verdict
       
   180 
       
   181 Parameters(TInt aRetValue) :	0 if API call gets thru without any rejection
       
   182 								1 if API call is rejected for capability error
       
   183 */
       
   184 enum TVerdict CCapabilityTestStep::GetVerdict(TInt aAPIretValue)
       
   185 	{
       
   186 	TVerdict vVerdict[] = {EPass, EFail};
       
   187 
       
   188 	//please leave the following if/else block as the information printed by INFO_PRINTF1 is used bu CapTestSumm
       
   189 	if(iExpect_Rejection)//[Inverse Test] EPass for 1 while EFail for 0
       
   190 		{
       
   191 		INFO_PRINTF1(_L("Test Expected to Fail due to lack of capabilities"));
       
   192 		return vVerdict[(aAPIretValue)?0:1];
       
   193 
       
   194 		}
       
   195 	else //[Direct Test] EPass for 0 while EFail for 1
       
   196 		{
       
   197 		INFO_PRINTF1(_L("Test Expected to Pass with correct capabilities"));
       
   198 		return vVerdict[(aAPIretValue)?1:0];
       
   199 		}
       
   200 	}
       
   201 
       
   202 
       
   203 /*
       
   204 TVerdict MainThread()
       
   205 
       
   206 Called by: "doTestStepL"
       
   207 
       
   208 Purpose:	Creates the child thread(which calls the respective function with regard
       
   209 			to the server and also implements the Message Call). Then this fn.waits for the
       
   210 			completion of the childthread( doesnt matter how the thread did die!)
       
   211 
       
   212 Return Value(Verdict of the TestStep):
       
   213 
       
   214 			A.Reporting PASS/FAIL
       
   215 				Direct Test:
       
   216 						When a message call gets thru. Please note that in such cases
       
   217 						actually the implementation of the message has started. As we
       
   218 						are passing "0" Parameters, server may panic, though our botheration
       
   219 						stops once the call gets thru.
       
   220 						NOTE:	The style is the same when CONNECTION capabilities
       
   221 								are tested, the only diff is you dont have to expect a
       
   222 								panic from server
       
   223 				Inverse Test:
       
   224 						The call should be either failed or panicked with
       
   225 						"KErrPermissionDenied" flag.
       
   226 
       
   227 				General Case:
       
   228 						If a thread creation failed or if the server couldnt be connected
       
   229 						apart from the above two cases, then a FAIL is reported
       
   230 
       
   231 			B.Reporting INCONCLUSIVE
       
   232 						Any panic say from unexpected source (eg:KERN-EXEC) will be
       
   233 						reported INCONCLUSIVE
       
   234 */
       
   235 TVerdict CCapabilityTestStep::MainThread()
       
   236 	{
       
   237 
       
   238 	TBuf<100>	tExitCategory;
       
   239 	TInt		tExitReason = 0;
       
   240 	TBuf<100>	TestStyle;
       
   241 
       
   242 	iExpect_Rejection?TestStyle = _L("Inverse"):TestStyle = _L("Direct");
       
   243 	TCapabilitySet theCaps =  TSecurityInfo(RProcess()).iCaps ;
       
   244 	const TInt KMaxTestThreadHeapSize = 0x10000;
       
   245 
       
   246 	//Initialize return values
       
   247 	iResult_SR = iResult_Server = KErrNone;
       
   248 
       
   249 
       
   250 	// Create a child thread, with a new heap
       
   251 	TInt nRes_Thread =	tChildThread.Create(
       
   252 						ChildThread_SR,
       
   253 						ThreadStartFn,
       
   254 						KDefaultStackSize,
       
   255 						KMinHeapSize,
       
   256 						KMaxTestThreadHeapSize,
       
   257 						this,
       
   258 						EOwnerProcess);
       
   259 
       
   260 
       
   261 	if(nRes_Thread == KErrNone)//Thread Created
       
   262 		{
       
   263 
       
   264 		//Let me know when the thread is dead
       
   265 		TRequestStatus ThreadStatus;
       
   266 		tChildThread.Logon(ThreadStatus);
       
   267 		tChildThread.Resume();
       
   268 		//Is the thread dead?
       
   269 		User::WaitForRequest( ThreadStatus );
       
   270 
       
   271 		//yes, he is dead. RIP!  Now the Killer's profile
       
   272 		tExitCategory	=	tChildThread.ExitCategory();
       
   273 		tExitReason		=	tChildThread.ExitReason();
       
   274 
       
   275 
       
   276 		//Somebody Please say what are we testing!!
       
   277 		if(iSessionCreated && (SR_MESSAGE_ID >=0))//Flag set by Child thread when connected to Server
       
   278 		{
       
   279 			//DEF INFO_PRINTF5(_L("Connected to Server(%S) for %S Test [MessageID: %d,Req.Cap: 0x%x,Present.Cap: 0x%x]"),&SR_ServerName,&TestStyle,SR_MESSAGE_ID,iStepCap,TSecurityInfo(RProcess()));
       
   280 		}
       
   281 		else if(SR_MESSAGE_ID < 0)
       
   282 		{
       
   283 			//DEF INFO_PRINTF5(_L("Testing Connection capabilities[%S Test] for Server(%S)  [Req.Cap: 0x%x,Present.Cap: 0x%x]"),&TestStyle,
       
   284 			//&SR_ServerName,TSecurityInfo(RProcess()));
       
   285 		}
       
   286 		else if(!iSessionCreated)// NO Connection
       
   287 			{
       
   288 			INFO_PRINTF4(_L("Couldnt connect to the Server(%S) ErrorCode - ServerRet: %d C32ret: %d"),&SR_ServerName,iResult_Server,iResult_C32);
       
   289 			//INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason);
       
   290   			return EFail;
       
   291  			}
       
   292 
       
   293 
       
   294 
       
   295 		switch(tChildThread.ExitType())
       
   296 			{
       
   297 			case EExitPanic:
       
   298 				//1.A Panic from the connected Server
       
   299 				//2.A CServer Panic normally for capability rejection
       
   300 				//3.A kernel Panic (consider yourself doomed!)
       
   301 				if((tExitReason == KErrPermissionDenied) ||
       
   302 					//DEF ? 	it's old version (tExitReason == CServer::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap.
       
   303 					// is it correct ?
       
   304 					(tExitReason == CServer2::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap.
       
   305 					{
       
   306 					INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),tExitReason);
       
   307 					return(GetVerdict(API_RetValue_PermissionDenied));
       
   308 					}
       
   309 				else if(tExitCategory == iServer_Panic) //Panic from Server
       
   310 					{
       
   311 					INFO_PRINTF2(_L("Server(%S) Panic to child thread"),&tExitCategory);
       
   312 					INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason);
       
   313 					return(GetVerdict(API_RetValue_ServerPanic));
       
   314 					}
       
   315 				else//A kernel Panic possibly
       
   316 					{
       
   317 					INFO_PRINTF3(_L("Child Thread: Panic from unexpected source (ExitCategory: %S ExitReason : %d)!"),&tExitCategory,tExitReason);
       
   318 					return EInconclusive;
       
   319 					}
       
   320 
       
   321 					break;
       
   322 			case EExitKill:
       
   323 				if(iResult_SR != KErrPermissionDenied)
       
   324 					{
       
   325 					INFO_PRINTF2(_L("A Successfull call (Return Value : %d)"),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server));
       
   326 					return(GetVerdict(API_RetValue_NoCapError));
       
   327 					}
       
   328 				else
       
   329 					{
       
   330 					INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server));
       
   331 					return(GetVerdict(API_RetValue_PermissionDenied));
       
   332 					}
       
   333 
       
   334 					break;
       
   335 			default:
       
   336 					break;
       
   337 			}
       
   338 		}
       
   339 	else //Our thread couldnt start	:o(
       
   340 		{
       
   341 		INFO_PRINTF2(_L("ERROR: Failed to create Child thread,  ErrorCode:(%d)"),nRes_Thread);
       
   342 		return EFail;
       
   343 		}
       
   344 
       
   345 	return EInconclusive;
       
   346 	}
       
   347 /*
       
   348 TInt CCapabilityTestStep::StartServer()
       
   349 {
       
   350 	TInt err =  KErrNone ;
       
   351 	// EKA2 is simple No path required
       
   352 	TBuf<32> serverFile;
       
   353 	serverFile.Copy(_L("PARAM_SVR_SUITENAME"));
       
   354 	_LIT(KExe,".exe");
       
   355 	serverFile.Append(KExe);
       
   356 	RProcess server;
       
   357 	err = server.Create(serverFile,_L(""));
       
   358 	if(err != KErrNone)
       
   359 		return err;
       
   360 	// Synchronise with the server
       
   361 	TRequestStatus reqStatus;
       
   362 	server.Rendezvous(reqStatus);
       
   363 	server.Resume();
       
   364 	 //Server will call the reciprocal static synchronise call
       
   365 	User::WaitForRequest(reqStatus);
       
   366 	//server.Close();
       
   367 	if(reqStatus.Int() != KErrNone)
       
   368 		return reqStatus.Int();
       
   369 	return err;
       
   370 }
       
   371 
       
   372 */
       
   373 
       
   374 TInt CCapabilityTestStep::StartServer()
       
   375 {
       
   376 	TInt err = KErrNone;
       
   377 
       
   378     TFindServer findServer(KSipClientResolverServerName);
       
   379     TFullName name;
       
   380 	if (findServer.Next(name) == KErrNone)
       
   381         {
       
   382         return KErrNone; // Server already running
       
   383         }
       
   384 
       
   385 	RSemaphore semaphore;
       
   386 	err = semaphore.CreateGlobal(KSipClientResolverServerSemaphoreName,0);
       
   387 	if (err != KErrNone)
       
   388 		{
       
   389 		return err;
       
   390 		}
       
   391 
       
   392 	err = CreateServerProcess(semaphore);
       
   393 	semaphore.Close ();
       
   394 
       
   395     return err;
       
   396 }
       
   397 
       
   398 TInt CCapabilityTestStep::CreateServerProcess(RSemaphore& aSemaphore)
       
   399 {
       
   400 
       
   401 
       
   402 	TInt err = KErrNone;
       
   403 
       
   404 	const TUidType serverUid (KNullUid, KNullUid, KServerUid3);
       
   405 
       
   406 	RProcess server;
       
   407 	err = server.Create(KSipClientResolverServerName,_L(""),serverUid);
       
   408 	if (err)
       
   409     {
       
   410 		return err;
       
   411     }
       
   412 
       
   413 
       
   414 	server.Resume ();
       
   415 	aSemaphore.Wait();
       
   416 	TInt exitReason = server.ExitReason();
       
   417 	server.Close ();
       
   418 
       
   419     return exitReason;
       
   420 }
       
   421 
       
   422 
       
   423  	TInt CCapabilityTestStep::TestDebugHeap(TInt* iDbgIPCNo)
       
   424  	{
       
   425 
       
   426  	//TDbgFns  {MarkHeapStart, MarkHeapEnd, CheckHeap, FailNext, ResetFailNext};
       
   427  	TInt aFnToTest= iDbgIPCNo[5];
       
   428 
       
   429 
       
   430  	TInt iResult_SR [6] ={0};
       
   431  	TInt i = 1;
       
   432  	TInt testedFn = 0;
       
   433 
       
   434  	TInt dbgTestSequence[5][6]	=	{	{MarkHeapStart	,2,0,1,-1,-1},
       
   435  										{MarkHeapEnd	,2,0,1,-1,-1},
       
   436  										{CheckHeap		,3,0,2, 1,-1},
       
   437  										{FailNext		,4,0,3, 4, 1},
       
   438  										{ResetFailNext	,4,0,3, 4, 1}
       
   439 
       
   440  									};
       
   441 
       
   442 
       
   443  	TInt aCount = dbgTestSequence[aFnToTest][i];
       
   444 
       
   445  	while(aCount--  )
       
   446  		{
       
   447  		testedFn =  dbgTestSequence[aFnToTest][(++i)];
       
   448 
       
   449 			iResult_SR[testedFn ]= SendReceive( iDbgIPCNo[testedFn],TIpcArgs(((iDbgIPCNo[testedFn]==3 )?4:0),0,0,0));
       
   450 
       
   451 
       
   452  		if( ((testedFn !=aFnToTest)?iResult_SR[testedFn]:KErrNone) == KErrPermissionDenied)
       
   453 
       
   454 			User::Panic(_L("Failed at Initialization"),iResult_SR[testedFn]);
       
   455 
       
   456 		}
       
   457 
       
   458 	return iResult_SR[aFnToTest];
       
   459 	}
       
   460