commsprocess/commsrootserverconfig/TE_rootserver/src/RootServerTestSection7.cpp
changeset 72 ae47d0499bee
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 8
       
    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 "TestAsynchHandler.h"
       
    29 #include "RootServerTestSection7.h"
       
    30 #include "RootServerTest.h"
       
    31 
       
    32 // Test step 7.1 - OOM loop Test1 - Load, Enumerate, GetInfo
       
    33 CRootServerTest7_1::CRootServerTest7_1(CTE_RootServerServer *aSuite) : CTestStepRootServer(aSuite)
       
    34 {
       
    35 	// store the name of this test case
       
    36 	SetTestStepName(_L("Test7.1"));
       
    37 }
       
    38 
       
    39 TVerdict CRootServerTest7_1::doTestStepL( void )
       
    40 	{
       
    41 	INFO_PRINTF1(_L("Test Purpose: OOM loop test 1: Load, Enumerate, GetInfo"));
       
    42 										SetTestStepResult(EPass);
       
    43 
       
    44 	// Create scheduler/active object framework 
       
    45 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
    46     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
    47 
       
    48 
       
    49 	TInt failure = 1000;
       
    50 							
       
    51 		while(TestStepResult() == EPass)
       
    52 		{
       
    53 		iRootServerSuite->RootSess().__DbgFailNext(failure);
       
    54 		failure++;
       
    55 
       
    56 		TRSStartModuleParams startParams;
       
    57 		TTestModuleIniData iniData;
       
    58 		DefaultStartParams(startParams, iniData);
       
    59 		startParams.iParams.iName = KModule1;
       
    60 		
       
    61 		asynchHandler->TryLoad(startParams, iniData);
       
    62     	CActiveScheduler::Start();
       
    63 
       
    64 		if (asynchHandler->iStatus != KErrNone)
       
    65 			{
       
    66 			INFO_PRINTF3(_L("TryLoad: %d with FailNext(%d)"), asynchHandler->iStatus.Int(), failure);
       
    67 if(asynchHandler->iStatus == KErrRSModuleAlreadyExist)
       
    68 	User::Leave(KErrRSModuleAlreadyExist);
       
    69 			continue;
       
    70 			}
       
    71 
       
    72 		TCFModuleName moduleName;
       
    73 		TRSIter position;
       
    74 		TInt ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
    75 		if(ret != KErrNone)
       
    76 			{
       
    77 			INFO_PRINTF3(_L("EnumerateModules: %d with FailNext(%d)"), asynchHandler->iStatus.Int(), failure);
       
    78 			continue;
       
    79 			}
       
    80 
       
    81 		if(moduleName != KModule1)
       
    82 			{
       
    83 			INFO_PRINTF2(_L("EnumerateModules() returned KErrNone but wrong name: %S"), &moduleName);
       
    84 			SetTestStepResult(EFail);
       
    85 
       
    86 			break;
       
    87 			}
       
    88 
       
    89 		TRSModuleInfo info;
       
    90 		ret = iRootServerSuite->RootSess().GetModuleInfo(KModule1(), info);
       
    91 		if(ret != KErrNone)
       
    92 			{
       
    93 			INFO_PRINTF3(_L("GetModuleInfo: %d with FailNext(%d)"), asynchHandler->iStatus.Int(), failure);
       
    94 			continue;
       
    95 			}
       
    96 
       
    97 		if(info.iParams.iState != ERunning)
       
    98 			{
       
    99 			INFO_PRINTF2(_L("GetModuleInfo() returned KErrNone but wrong state: %d"), info.iParams.iState);
       
   100 			SetTestStepResult(EFail);
       
   101 
       
   102 			}
       
   103 		// everything worked;
       
   104 		INFO_PRINTF1(_L("OOM loop complete"));
       
   105 		break;
       
   106 		}
       
   107 
       
   108 
       
   109 	INFO_PRINTF1(_L("Resetting heap"));
       
   110 	iRootServerSuite->RootSess().__DbgFailNext(-1);
       
   111 	// uninstall and destroy active scheduler
       
   112 	CleanupStack::PopAndDestroy(asynchHandler);
       
   113 	CleanupStack::PopAndDestroy(scheduler);
       
   114 	return TestStepResult();
       
   115 	}
       
   116 
       
   117 // Test step 7.2 - OOM loop Test2 - Unload, GetInfo
       
   118 CRootServerTest7_2::CRootServerTest7_2(CTE_RootServerServer *aSuite) : CTestStepRootServer(aSuite)
       
   119 {
       
   120 	// store the name of this test case
       
   121 	SetTestStepName(_L("Test7.2"));
       
   122 }
       
   123 
       
   124 TVerdict CRootServerTest7_2::doTestStepL( void )
       
   125 	{
       
   126 	INFO_PRINTF1(_L("Test Purpose: Heap loop Test2 - Unload, GetInfo"));
       
   127 										SetTestStepResult(EPass);
       
   128 
       
   129 	// Create scheduler/active object framework 
       
   130 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   131     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   132 
       
   133 	INFO_PRINTF2(_L("01 Loading cpm: %S"), &KModule1());
       
   134 	LoadNormalModuleL(asynchHandler, KModule1);
       
   135 
       
   136 	TInt failure = 1;
       
   137 						
       
   138 	while(TestStepResult() == EPass)
       
   139 		{
       
   140 		iRootServerSuite->RootSess().__DbgFailNext(failure);
       
   141 		failure++;
       
   142 
       
   143 		asynchHandler->TryUnLoad(KModule1(), EUnGraceful);
       
   144     	CActiveScheduler::Start();
       
   145 
       
   146 		if (asynchHandler->iStatus != KErrNone)
       
   147 			{
       
   148 			INFO_PRINTF3(_L("TryUnload: %d with FailNext(%d)"), asynchHandler->iStatus.Int(), failure);
       
   149 			if(asynchHandler->iStatus != KErrRSModuleNotLoaded)
       
   150 				{
       
   151 				continue;
       
   152 				}
       
   153 			}
       
   154 
       
   155 		TRSModuleInfo info;
       
   156 		TInt ret = iRootServerSuite->RootSess().GetModuleInfo(KModule1(), info);
       
   157 		if(ret == KErrRSModuleUnknown)
       
   158 			{
       
   159 			// everything worked;
       
   160 			INFO_PRINTF1(_L("OOM loop complete"));
       
   161 			break;
       
   162 			}
       
   163 		else if(ret == KErrNone)
       
   164 			{
       
   165 			INFO_PRINTF1(_L("GetModuleInfo() returned KErrNone for unloaded module"));
       
   166 			SetTestStepResult(EFail);
       
   167 
       
   168 			}
       
   169 		else 
       
   170 			{
       
   171 			INFO_PRINTF3(_L("GetModuleInfo: %d with FailNext(%d)"), ret, failure);
       
   172 			continue;
       
   173 			}
       
   174 		}
       
   175 
       
   176 	INFO_PRINTF1(_L("Resetting heap"));
       
   177 	iRootServerSuite->RootSess().__DbgFailNext(-1);
       
   178 	// uninstall and destroy active scheduler
       
   179 	CleanupStack::PopAndDestroy(asynchHandler);
       
   180 	CleanupStack::PopAndDestroy(scheduler);
       
   181 	return TestStepResult();
       
   182 	}
       
   183 	
       
   184 
       
   185 // Test step 7.3 - OOM loop Test 3 - Bind
       
   186 CRootServerTest7_3::CRootServerTest7_3(CTE_RootServerServer *aSuite) : CTestStepRootServer(aSuite)
       
   187 {
       
   188 	// store the name of this test case
       
   189 	SetTestStepName(_L("Test7.3"));
       
   190 }
       
   191 
       
   192 TVerdict CRootServerTest7_3::doTestStepL( void )
       
   193 	{
       
   194 	INFO_PRINTF1(_L("Test Purpose: Heap loop Test3 - Bind, EnumerateBindings"));
       
   195 										SetTestStepResult(EPass);
       
   196 
       
   197 	// Create scheduler/active object framework 
       
   198 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   199     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   200 
       
   201 	INFO_PRINTF2(_L("01 Loading cpm: %S"), &KModule1());
       
   202 	LoadNormalModuleL(asynchHandler, KModule1);
       
   203 
       
   204 	TCFSubModuleAddress fullName1;
       
   205 	fullName1.SetModule(KModule1());
       
   206 	fullName1.SetSubModule(KSubModule1());
       
   207 	TInt failure = 1;
       
   208 						
       
   209 	while(TestStepResult() == EPass)
       
   210 		{
       
   211 		INFO_PRINTF2(_L("Failing after %d Allocs"), failure);
       
   212 		iRootServerSuite->RootSess().__DbgFailNext(failure);
       
   213 		failure++;
       
   214 
       
   215 		TInt ret = TryHierachicalBind(asynchHandler, KModule1, KSubModule1, KModule1, KSubModule2);
       
   216 		if(ret != KErrNone)
       
   217 			continue;
       
   218 
       
   219 		INFO_PRINTF1(_L("02 Enumerate bindings"));
       
   220 		TRSBindingInfo bindInfo;
       
   221 		TRSIter position;
       
   222 		ret = iRootServerSuite->RootSess().EnumerateBindings(fullName1, position, bindInfo);
       
   223 		if(ret != KErrNone)
       
   224 			continue;
       
   225 
       
   226 		// everything worked;
       
   227 		INFO_PRINTF1(_L("OOM loop complete"));
       
   228 		break;
       
   229 		}		
       
   230 
       
   231 	CleanupStack::PopAndDestroy(asynchHandler);
       
   232 	CleanupStack::PopAndDestroy(scheduler);
       
   233 	return TestStepResult();
       
   234 	}
       
   235 
       
   236 // Test step 7.4 - OOM loop Test 4 - Unbind
       
   237 CRootServerTest7_4::CRootServerTest7_4(CTE_RootServerServer *aSuite) : CTestStepRootServer(aSuite)
       
   238 {
       
   239 	// store the name of this test case
       
   240 	SetTestStepName(_L("Test7.4"));
       
   241 }
       
   242 
       
   243 TVerdict CRootServerTest7_4::doTestStepL( void )
       
   244 	{
       
   245 	INFO_PRINTF1(_L("Test Purpose: Heap loop Test4 - Unbind, EnumerateBindings"));
       
   246 										SetTestStepResult(EPass);
       
   247 
       
   248 	// Create scheduler/active object framework 
       
   249 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   250     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   251 
       
   252 	INFO_PRINTF2(_L("01 Loading and binding cpm: %S"), &KModule1());
       
   253 	LoadNormalModuleL(asynchHandler, KModule1);
       
   254 	TInt ret = TryHierachicalBind(asynchHandler, KModule1, KSubModule1, KModule1, KSubModule2);
       
   255 	if(ret != KErrNone)
       
   256 		{
       
   257 		INFO_PRINTF2(_L("Binding CPM failed with %d"), ret);
       
   258 		User::Leave(ret);
       
   259 		}
       
   260 
       
   261 	TCFSubModuleAddress fullName1;
       
   262 	fullName1.SetModule(KModule1());
       
   263 	fullName1.SetSubModule(KSubModule1());
       
   264 	TInt failure = 1;
       
   265 							
       
   266 	while(TestStepResult() == EPass)
       
   267 		{
       
   268 		iRootServerSuite->RootSess().__DbgFailNext(failure);
       
   269 		failure++;
       
   270 
       
   271 		TRSUnBindingInfo unbindInfo;
       
   272 		unbindInfo.iParams.iAddress1.SetModule(KModule1());
       
   273 		unbindInfo.iParams.iAddress1.SetSubModule(KSubModule1());
       
   274 		unbindInfo.iParams.iAddress2.SetModule(KModule1());
       
   275 		unbindInfo.iParams.iAddress2.SetSubModule(KSubModule2());
       
   276 		asynchHandler->TryUnBind( unbindInfo );
       
   277 		
       
   278 		CActiveScheduler::Start();
       
   279 
       
   280 		if (asynchHandler->iStatus != KErrNone)
       
   281 			{
       
   282 			INFO_PRINTF3(_L("TryUnload: %d with FailNext(%d)"), asynchHandler->iStatus.Int(), failure);
       
   283 			continue;
       
   284 			}
       
   285 
       
   286 		INFO_PRINTF1(_L("03 Enumerate bindings"));
       
   287 		TRSBindingInfo bindInfo;
       
   288 		TRSIter position;
       
   289 		ret = iRootServerSuite->RootSess().EnumerateBindings(fullName1, position, bindInfo);
       
   290 		if(ret == KErrEof)
       
   291 			{
       
   292 			INFO_PRINTF1(_L("OOM loop complete"));
       
   293 			break;
       
   294 			}
       
   295 		else if(ret == KErrNone)
       
   296 			{
       
   297 			INFO_PRINTF1(_L("EnumerateBindings returned KErrNone for unbound submodules"));
       
   298 			SetTestStepResult(EFail);
       
   299 
       
   300 			}
       
   301 		else 
       
   302 			{
       
   303 			INFO_PRINTF3(_L("EnumerateBindings: %d with FailNext(%d)"), ret, failure);
       
   304 			continue;
       
   305 			}
       
   306 		}		
       
   307 
       
   308 	CleanupStack::PopAndDestroy(asynchHandler);
       
   309 	CleanupStack::PopAndDestroy(scheduler);
       
   310 	return TestStepResult();
       
   311 	}
       
   312 	
       
   313