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