commsprocess/commsrootserverconfig/ts_rootserver/RootServerTestSection5.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     1 // Copyright (c) 2003-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 // This contains RootServer Test cases from section 6
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <es_mbman.h>
       
    21 
       
    22 // Test system includes
       
    23 #include <networking/log.h>
       
    24 #include <networking/teststep.h>
       
    25 #include <networking/testsuite.h>
       
    26 
       
    27 #include "TestStepRootServer.h"
       
    28 #include "TestSuiteRootServer.h"
       
    29 #include "TestAsynchHandler.h"
       
    30 #include "RootServerTestSection5.h"
       
    31 #include "RootServerTest.h"
       
    32 
       
    33 
       
    34 TVerdict CRootServerTest_GracefulUnload::UnloadGracefullyL(TThreadPriority aPriority)
       
    35 	{
       
    36 	TVerdict verdict = EFail;
       
    37 
       
    38 	// Create scheduler/active object framework 
       
    39 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
    40     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
    41 
       
    42     //*****************step 2************************
       
    43 	Log(_L("02 Load test module"));
       
    44 
       
    45 	TRSStartModuleParams startParams;
       
    46 	TTestModuleIniData iniData;
       
    47 	DefaultStartParams(startParams, iniData);
       
    48 	startParams.iParams.iName = KModule1;
       
    49 	startParams.iParams.iPriority = aPriority;
       
    50 
       
    51 	asynchHandler->TryLoad(startParams, iniData);
       
    52     CActiveScheduler::Start();
       
    53    	if (asynchHandler->iStatus != KErrNone)
       
    54 		{
       
    55 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
    56 		verdict = EInconclusive;
       
    57 		}
       
    58 	else
       
    59 		{
       
    60 		//*****************step 4***********************
       
    61 		Log(_L("04 Unload Test Module"));
       
    62 
       
    63 		asynchHandler->TryUnLoad(startParams.iParams.iName, EGraceful);
       
    64 		
       
    65 		CActiveScheduler::Start();
       
    66 
       
    67    		if (asynchHandler->iStatus != KErrNone)
       
    68 			{
       
    69 			Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
    70 			verdict = EInconclusive;
       
    71 			}
       
    72 		else
       
    73 			{
       
    74 			verdict = EPass;			
       
    75 			}
       
    76 		}
       
    77 
       
    78 	// uninstall and destroy active scheduler
       
    79 	CleanupStack::PopAndDestroy(asynchHandler);
       
    80 	CleanupStack::PopAndDestroy(scheduler);
       
    81 	return verdict;
       
    82 	}
       
    83 
       
    84 
       
    85 // Test step 5.1 - UnLoad Gracefully (normal priority)
       
    86 CRootServerTest5_1::CRootServerTest5_1()
       
    87 {
       
    88 	// store the name of this test case
       
    89 	iTestStepName = _L("Test5.1");
       
    90 }
       
    91 
       
    92 TVerdict CRootServerTest5_1::doTestStepL( void )
       
    93 	{
       
    94 	Log(_L("Test Purpose: UnLoad Comms Provider Module gracefully (normal priority)"));
       
    95 	return UnloadGracefullyL(EPriorityNormal);
       
    96 	}
       
    97 
       
    98 
       
    99 // Test step 5.2 - UnLoad Gracefully (elevated priority)
       
   100 CRootServerTest5_2::CRootServerTest5_2()
       
   101 {
       
   102 	// store the name of this test case
       
   103 	iTestStepName = _L("Test5.2");
       
   104 }
       
   105 
       
   106 TVerdict CRootServerTest5_2::doTestStepL( void )
       
   107 	{
       
   108 	Log(_L("Test Purpose: UnLoad Comms Provider Module gracefully (elevated priority)"));
       
   109 	return UnloadGracefullyL(EPriorityRealTime);
       
   110 	}
       
   111 
       
   112 
       
   113 // Test step 5.3 -  Cancel UnLoad Gracefully
       
   114 CRootServerTest5_3::CRootServerTest5_3()
       
   115 {
       
   116 	// store the name of this test case
       
   117 	iTestStepName = _L("Test5.3");
       
   118 }
       
   119 
       
   120 TVerdict CRootServerTest5_3::doTestStepL( void )
       
   121 	{
       
   122 	Log(_L("Test Purpose: Cancel UnLoad Comms Provider Module gracefully"));
       
   123 	TVerdict verdict = EPass;
       
   124 
       
   125 	// Create scheduler/active object framework 
       
   126 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   127     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   128 
       
   129 	//*****************step 2************************
       
   130 	Log(_L("02 Load Test Module"));
       
   131 	TRSStartModuleParams startParams;
       
   132 	TTestModuleIniData iniData;
       
   133 	DefaultStartParams(startParams, iniData);
       
   134 	startParams.iParams.iName = KModule1;
       
   135 
       
   136 	asynchHandler->TryLoad(startParams, iniData);
       
   137     CActiveScheduler::Start();
       
   138    	if (asynchHandler->iStatus != KErrNone)
       
   139 		{
       
   140 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
   141 		verdict = EInconclusive;
       
   142 		}
       
   143 	else
       
   144 		{
       
   145 		//*****************step 3***********************
       
   146 		Log(_L("03 Unload Test Module"));
       
   147 		asynchHandler->TryUnLoad(startParams.iParams.iName, EGraceful);
       
   148 		
       
   149 		//*****************step 4***********************
       
   150 		Log(_L8("04 Cancelling UnLoad: %S"), &startParams.iParams.iName);
       
   151 		iRootServerSuite->RootSess().CancelUnloadCpm(startParams.iParams.iName);
       
   152 		
       
   153 		CActiveScheduler::Start();
       
   154 
       
   155    		if ((asynchHandler->iStatus != KErrNone) && (asynchHandler->iStatus != KErrCancel))
       
   156 			{
       
   157 			Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
   158 			verdict = EFail;
       
   159 			}
       
   160 
       
   161 		}
       
   162 
       
   163 	// uninstall and destroy active scheduler
       
   164 	CleanupStack::PopAndDestroy(asynchHandler);
       
   165 	CleanupStack::PopAndDestroy(scheduler);
       
   166 	return verdict;
       
   167 	}
       
   168 
       
   169 
       
   170 TVerdict CRootServerTest_UngracefulUnload::UnloadNonGracefullyL(TThreadPriority aPriority)
       
   171 	{
       
   172 	TVerdict verdict = EFail;
       
   173 
       
   174 	// Create scheduler/active object framework 
       
   175 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   176     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   177 
       
   178 	//*****************step 3************************
       
   179 	Log(_L("03 Load Test Module"));
       
   180 	TRSStartModuleParams startParams;
       
   181 	TTestModuleIniData iniData;
       
   182 	DefaultStartParams(startParams, iniData);
       
   183 	startParams.iParams.iName = KModule1;
       
   184 	startParams.iParams.iPriority = aPriority;
       
   185 
       
   186 	asynchHandler->TryLoad(startParams, iniData);
       
   187     CActiveScheduler::Start();
       
   188    	if (asynchHandler->iStatus != KErrNone)
       
   189 		{
       
   190 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
   191 		verdict = EInconclusive;
       
   192 		}
       
   193 	else
       
   194 		{
       
   195 		//*****************step 4***********************
       
   196 		Log(_L("04 Unload Test Module"));
       
   197 		asynchHandler->TryUnLoad(startParams.iParams.iName, EUnGraceful);
       
   198 		
       
   199 		CActiveScheduler::Start();
       
   200 
       
   201    		if (asynchHandler->iStatus != KErrNone)
       
   202 			{
       
   203 			Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
   204 			verdict = EInconclusive;
       
   205 			}
       
   206 		else
       
   207 			{
       
   208 			verdict = EPass;			
       
   209 			}
       
   210 		}
       
   211 
       
   212 	// uninstall and destroy active scheduler
       
   213 	CleanupStack::PopAndDestroy(asynchHandler);
       
   214 	CleanupStack::PopAndDestroy(scheduler);
       
   215 	return verdict;
       
   216 	}
       
   217 	
       
   218 
       
   219 // Test step 5.4 - UnLoad Ungracefully - normal priority
       
   220 CRootServerTest5_4::CRootServerTest5_4()
       
   221 {
       
   222 	// store the name of this test case
       
   223 	iTestStepName = _L("Test5.4");
       
   224 }
       
   225 
       
   226 TVerdict CRootServerTest5_4::doTestStepL( void )
       
   227 	{
       
   228 	Log(_L("Test Purpose: UnLoad Comms Provider Module Ungracefully (normal priority)"));
       
   229 	return UnloadNonGracefullyL(EPriorityNormal);
       
   230 	}
       
   231 
       
   232 // Test step 5.5 - UnLoad Ungracefully - elevated priority
       
   233 CRootServerTest5_5::CRootServerTest5_5()
       
   234 {
       
   235 	// store the name of this test case
       
   236 	iTestStepName = _L("Test5.5");
       
   237 }
       
   238 
       
   239 TVerdict CRootServerTest5_5::doTestStepL( void )
       
   240 	{
       
   241 	Log(_L("Test Purpose: UnLoad Comms Provider Module Ungracefully (elevated priority)"));
       
   242 	return UnloadNonGracefullyL(EPriorityRealTime);
       
   243 	}
       
   244 
       
   245 
       
   246 // Test step 5.6 - Cancel UnLoad Ungracefully
       
   247 CRootServerTest5_6::CRootServerTest5_6()
       
   248 {
       
   249 	// store the name of this test case
       
   250 	iTestStepName = _L("Test5.6");
       
   251 }
       
   252 
       
   253 TVerdict CRootServerTest5_6::doTestStepL( void )
       
   254 	{
       
   255 	Log(_L("Test Purpose: Cancel UnLoad Comms Provider Module Ungracefully"));
       
   256 	TVerdict verdict = EPass;
       
   257 
       
   258 	// Create scheduler/active object framework 
       
   259 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   260     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   261 
       
   262 	//*****************step 2************************
       
   263 	Log(_L("02 Load Test Module"));
       
   264 	TRSStartModuleParams startParams;
       
   265 	TTestModuleIniData iniData;
       
   266 	DefaultStartParams(startParams, iniData);
       
   267 	startParams.iParams.iName = KModule1;
       
   268 
       
   269 	asynchHandler->TryLoad(startParams, iniData);
       
   270     CActiveScheduler::Start();
       
   271    	if (asynchHandler->iStatus != KErrNone)
       
   272 		{
       
   273 		Log(_L("Load returned error: <%d> "), asynchHandler->iStatus.Int());
       
   274 		verdict = EInconclusive;
       
   275 		}
       
   276 	else
       
   277 		{
       
   278 		//*****************step 3***********************
       
   279 		Log(_L("03 Unload Test Module"));
       
   280 		asynchHandler->TryUnLoad(startParams.iParams.iName, EUnGraceful);
       
   281 		
       
   282 		//*****************step 4***********************
       
   283 		Log(_L8("04 Cancelling UnLoad: %S"), &startParams.iParams.iName);
       
   284 		iRootServerSuite->RootSess().CancelUnloadCpm(startParams.iParams.iName);
       
   285 		
       
   286 		CActiveScheduler::Start();
       
   287     
       
   288 	    // Unload the CPM anyway in case we were too late to cancel the load.
       
   289 	    TRequestStatus status;
       
   290 	    iRootServerSuite->RootSess().UnloadCpm(status, startParams.iParams.iName, EImmediate);
       
   291 	    User::WaitForRequest(status);
       
   292 
       
   293    		if (asynchHandler->iStatus != KErrNone)
       
   294 			{
       
   295 			Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
   296 			verdict = EFail;
       
   297 			}
       
   298 
       
   299 		}
       
   300 
       
   301 	// uninstall and destroy active scheduler
       
   302 	CleanupStack::PopAndDestroy(asynchHandler);
       
   303 	CleanupStack::PopAndDestroy(scheduler);
       
   304 	return verdict;
       
   305 	}
       
   306 	
       
   307 	
       
   308 // Test step 5.7 - UnLoad 2 modules sharing the same heap
       
   309 CRootServerTest5_7::CRootServerTest5_7()
       
   310 {
       
   311 	// store the name of this test case
       
   312 	iTestStepName = _L("Test5.7");
       
   313 }
       
   314 
       
   315 TVerdict CRootServerTest5_7::doTestStepL( void )
       
   316 	{
       
   317 	Log(_L("Test Purpose: UnLoad 2 modules sharing the same heap"));
       
   318 	TVerdict verdict = EFail;
       
   319 
       
   320 	// Create scheduler/active object framework 
       
   321 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   322     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   323     
       
   324 	//*****************step 3************************
       
   325 	Log(_L("03 Load Test Module_Share1"));
       
   326 	TRSStartModuleParams startParams;
       
   327 	TTestModuleIniData iniData;
       
   328 	DefaultStartParams(startParams, iniData);
       
   329 	_LIT8(KShareModule1, "Test ModuleShare1");
       
   330 	_LIT8(KShareModule2, "Test ModuleShare2");
       
   331 	startParams.iParams.iName = KShareModule1;
       
   332 
       
   333 	asynchHandler->TryLoad(startParams, iniData);
       
   334     CActiveScheduler::Start();
       
   335    	if (asynchHandler->iStatus != KErrNone)
       
   336 		{
       
   337 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
   338 		User::Leave(asynchHandler->iStatus.Int());
       
   339 		}
       
   340 
       
   341 	//*****************step 3************************
       
   342 	Log(_L("03 Load Test Module"));
       
   343 	startParams.iParams.iName = KShareModule2;
       
   344 	startParams.iParams.iHeapType = EShareHeap;
       
   345 	startParams.iParams.iShareHeapWith = KShareModule1;
       
   346 
       
   347 	asynchHandler->TryLoad(startParams, iniData);
       
   348 	CActiveScheduler::Start();
       
   349 
       
   350 	if (asynchHandler->iStatus != KErrNone)
       
   351 		{
       
   352 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
   353 		User::Leave(asynchHandler->iStatus.Int());
       
   354 		}
       
   355 
       
   356     //*****************step 5***********************
       
   357 	Log(_L("05 Unload Test Module_Share1"));
       
   358 	startParams.iParams.iName = KShareModule1;
       
   359 	asynchHandler->TryUnLoad(startParams.iParams.iName, EGraceful);
       
   360 	CActiveScheduler::Start();
       
   361 
       
   362 	if (asynchHandler->iStatus != KErrNone)
       
   363 		{
       
   364 		Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
   365 		User::Leave(asynchHandler->iStatus.Int());
       
   366 		}
       
   367 
       
   368 	//*****************step 6***********************
       
   369 	Log(_L("06 Unload Test Module_Share2"));
       
   370 	startParams.iParams.iName = KShareModule2;
       
   371 	asynchHandler->TryUnLoad(startParams.iParams.iName, EGraceful);
       
   372 	
       
   373 	CActiveScheduler::Start();
       
   374 
       
   375 	if (asynchHandler->iStatus != KErrNone)
       
   376 		{
       
   377 		Log(_L("Unload returned error: <%d> "), asynchHandler->iStatus.Int());
       
   378 		verdict = EInconclusive;
       
   379 		}
       
   380 	else
       
   381 		{
       
   382 		verdict = EPass;			
       
   383 		}
       
   384 
       
   385 	// uninstall and destroy active scheduler
       
   386 	CleanupStack::PopAndDestroy(asynchHandler);
       
   387 	CleanupStack::PopAndDestroy(scheduler);
       
   388 	return verdict;
       
   389 	}
       
   390     
       
   391     
       
   392 // Test step 5.8 - Unload Sluggish CPM Gracefully with intervening Close of Session
       
   393 CRootServerTest5_8::CRootServerTest5_8()
       
   394 {
       
   395 	// store the name of this test case
       
   396 	iTestStepName = _L("Test5.8");
       
   397 }
       
   398 
       
   399 TVerdict CRootServerTest5_8::doTestStepL( void )
       
   400 	{
       
   401 	Log(_L("Test Purpose: Unload Sluggish CPM Gracefully with intervening Close of Session"));
       
   402 	TVerdict verdict = EPass;
       
   403 
       
   404 	// Create scheduler/active object framework 
       
   405 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   406     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   407     
       
   408 	TRSStartModuleParams startParams;
       
   409 	TTestModuleIniData iniData;
       
   410 	DefaultStartParams(startParams, iniData);
       
   411 	startParams.iParams.iName = KModule1;
       
   412 	iniData.iParams.iShutdownDelay = isTestServerLifeTime;
       
   413 	Log(_L8("01 Loading sluggish module: %S"), &startParams.iParams.iName);
       
   414 	asynchHandler->TryLoad(startParams, iniData);
       
   415 
       
   416 	CActiveScheduler::Start();
       
   417     if (asynchHandler->iStatus != KErrNone)
       
   418 		{
       
   419 		Log(_L("LoadServer returned error: <%d> "), asynchHandler->iStatus.Int());
       
   420 		User::Leave(asynchHandler->iStatus.Int());
       
   421 		}
       
   422 
       
   423 	Log(_L("02 Unload sluggish Module"));
       
   424 	asynchHandler->TryUnLoad(startParams.iParams.iName, EGraceful);
       
   425 
       
   426 	// Brief wait to give unload chance to start
       
   427 	User::After(250 * 1000);
       
   428 
       
   429 	// Close the session
       
   430 	Log(_L("03 Closing RRootServ"));
       
   431 	iRootServerSuite->RootSess().Close();
       
   432 	// Brief wait for any fireworks
       
   433 	User::After(250 * 1000);
       
   434 	
       
   435 	// Let the request complete
       
   436 	CActiveScheduler::Start();
       
   437 
       
   438 	// Reconnect the session
       
   439 	Log(_L("04 Reconnecting RRootServ"));
       
   440 	TInt ret = iRootServerSuite->RootSess().Connect();
       
   441 	if (ret != KErrNone)
       
   442 		{
       
   443 		Log(_L("Reconnect of RRootServ failed with error: <%d> "), ret);
       
   444 		User::Leave(ret);
       
   445 		}
       
   446 	// Brief wait for any fireworks
       
   447 	User::After(250 * 1000);
       
   448 
       
   449 	// now try to retrieve information about the module; should be ERunning after session close
       
   450 	// causes unload handler to be canceled
       
   451 	Log(_L("05 Getting module information"));
       
   452 	TRSModuleInfo info;
       
   453 	TCFModuleName moduleName = startParams.iParams.iName;
       
   454 	ret = iRootServerSuite->RootSess().GetModuleInfo(moduleName, info);
       
   455 	Log(_L8("GetModuleInfo for %S returned %d, state %c= ERunning"), &moduleName, ret, info.iParams.iState == ERunning ? '=': '!');
       
   456 	
       
   457 	if(KErrNone != ret || info.iParams.iState != ERunning)
       
   458 		{
       
   459 		CleanupStack::PopAndDestroy(asynchHandler);
       
   460 		CleanupStack::PopAndDestroy(scheduler);
       
   461 		return EFail;
       
   462 		}
       
   463 
       
   464 	// Wait for it to finish stopping when its thread terminates, query again
       
   465 	Log(_L("06 Getting module information after waiting for stop"));
       
   466 	User::After((iniData.iParams.iShutdownDelay + 500) * 1000);
       
   467 	moduleName = startParams.iParams.iName;
       
   468 	ret = iRootServerSuite->RootSess().GetModuleInfo(moduleName, info);
       
   469 	Log(_L8("GetModuleInfo for %S returned %d"), &moduleName, ret);
       
   470 	
       
   471 	if(KErrRSModuleUnknown != ret)
       
   472 		{
       
   473 		CleanupStack::PopAndDestroy(asynchHandler);
       
   474 		CleanupStack::PopAndDestroy(scheduler);
       
   475 		return EFail;
       
   476 		}
       
   477 
       
   478 	CleanupStack::PopAndDestroy(asynchHandler);
       
   479 	CleanupStack::PopAndDestroy(scheduler);
       
   480 	return verdict;
       
   481 	}
       
   482     
       
   483     
       
   484