commsprocess/commsrootserverconfig/ts_rootserver/TestSuiteRootServer.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 main DLL entry point for the TS_RootServer.dll
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 // EPOC includes
       
    20 #include <e32base.h>
       
    21 
       
    22 // RootServer includes
       
    23 #include <rsshared.h>
       
    24 
       
    25 // Test system includes
       
    26 #include <comms-infras/commsdebugutility.h>
       
    27 #include <networking/teststep.h>
       
    28 #include "TestStepRootServer.h"
       
    29 #include "TestSuiteRootServer.h"
       
    30 #include "TestAsynchHandler.h"
       
    31 #include "RootServerTestSection1.h"
       
    32 #include "RootServerTestSection2.h"
       
    33 #include "RootServerTestSection3.h"
       
    34 #include "RootServerTestSection4.h"
       
    35 #include "RootServerTestSection5.h"
       
    36 #include "RootServerTestSection6.h"
       
    37 #include "RootServerTestSection7.h"
       
    38 #include "RootServerTestSection8.h"
       
    39 
       
    40 _LIT(KRootServerExe, "c32exe.exe");
       
    41 _LIT(KRootServerProcessPattern, "c32exe*");
       
    42 
       
    43 EXPORT_C CTestSuiteRootServer* NewTestSuiteRootServer( void ) 
       
    44     {
       
    45 	return new (ELeave) CTestSuiteRootServer;
       
    46     }
       
    47 
       
    48 CTestSuiteRootServer::CTestSuiteRootServer()
       
    49 	{
       
    50 	}
       
    51 
       
    52 // destructor
       
    53 CTestSuiteRootServer::~CTestSuiteRootServer()
       
    54 	{
       
    55 	}
       
    56 
       
    57 
       
    58 // Add a test step into the suite
       
    59 void CTestSuiteRootServer::AddTestStepL( CTestStepRootServer * ptrTestStep )
       
    60 {
       
    61 	// test steps contain a pointer back to the suite which owns them
       
    62 	ptrTestStep->iRootServerSuite = this; 
       
    63 
       
    64 	// add the step using the base class method
       
    65 	CTestSuite::AddTestStepL(ptrTestStep);
       
    66 }
       
    67 
       
    68 // make a version string available for test system 
       
    69 TPtrC CTestSuiteRootServer::GetVersion( void )
       
    70 	{
       
    71 
       
    72 #ifdef _DEBUG
       
    73 	_LIT(KTxtVersion,"1.00 (udeb)");
       
    74 #else
       
    75 	_LIT(KTxtVersion,"1.00");
       
    76 #endif
       
    77 
       
    78 	return KTxtVersion();
       
    79 	}
       
    80 
       
    81 
       
    82 // second phase constructor for RootServer test suite
       
    83 // this creates all the ESOCK test steps and
       
    84 // stores them inside CTestSuiteRootServer
       
    85 void CTestSuiteRootServer::InitialiseL( void )
       
    86 	{
       
    87 	// add test steps
       
    88 	AddTestStepL( new(ELeave) CRootServerTest1_1 );
       
    89 	AddTestStepL( new(ELeave) CRootServerTest1_2 );
       
    90 	AddTestStepL( new(ELeave) CRootServerTest2_1 );
       
    91 	AddTestStepL( new(ELeave) CRootServerTest2_2 );
       
    92 	AddTestStepL( new(ELeave) CRootServerTest2_3 );	
       
    93 //	AddTestStepL( new(ELeave) CRootServerTest3_1 );
       
    94 	AddTestStepL( new(ELeave) CRootServerTest3_2 );
       
    95 	AddTestStepL( new(ELeave) CRootServerTest3_3 );
       
    96 	AddTestStepL( new(ELeave) CRootServerTest3_4 );
       
    97 	AddTestStepL( new(ELeave) CRootServerTest3_5 );
       
    98 	AddTestStepL( new(ELeave) CRootServerTest3_6 );
       
    99 	AddTestStepL( new(ELeave) CRootServerTest3_7 );
       
   100 	AddTestStepL( new(ELeave) CRootServerTest3_8 );
       
   101 	AddTestStepL( new(ELeave) CRootServerTest3_9 );
       
   102 	AddTestStepL( new(ELeave) CRootServerTest3_10 );
       
   103 	AddTestStepL( new(ELeave) CRootServerTest3_11 );
       
   104 	AddTestStepL( new(ELeave) CRootServerTest3_12 );
       
   105 	AddTestStepL( new(ELeave) CRootServerTest3_13 );
       
   106 	AddTestStepL( new(ELeave) CRootServerTest3_14 );
       
   107 	AddTestStepL( new(ELeave) CRootServerTest3_15 );
       
   108 	AddTestStepL( new(ELeave) CRootServerTest3_16 );
       
   109 	AddTestStepL( new(ELeave) CRootServerTest3_17 );
       
   110 	AddTestStepL( new(ELeave) CRootServerTest3_18 );
       
   111 	AddTestStepL( new(ELeave) CRootServerTest4_1 );
       
   112 	AddTestStepL( new(ELeave) CRootServerTest5_1 );
       
   113 	AddTestStepL( new(ELeave) CRootServerTest5_2 );
       
   114 	AddTestStepL( new(ELeave) CRootServerTest5_3 );
       
   115 	AddTestStepL( new(ELeave) CRootServerTest5_4 );
       
   116 	AddTestStepL( new(ELeave) CRootServerTest5_5 );
       
   117 	AddTestStepL( new(ELeave) CRootServerTest5_6 );
       
   118 	AddTestStepL( new(ELeave) CRootServerTest5_7 );
       
   119 	AddTestStepL( new(ELeave) CRootServerTest5_8 );
       
   120 	AddTestStepL( new(ELeave) CRootServerTest6_1 );
       
   121 	AddTestStepL( new(ELeave) CRootServerTest6_2 );
       
   122 	AddTestStepL( new(ELeave) CRootServerTest6_3 );
       
   123 	AddTestStepL( new(ELeave) CRootServerTest6_4 );
       
   124 	AddTestStepL( new(ELeave) CRootServerTest6_5 );
       
   125 	AddTestStepL( new(ELeave) CRootServerTest6_6 );
       
   126 	AddTestStepL( new(ELeave) CRootServerTest6_7 );
       
   127 	AddTestStepL( new(ELeave) CRootServerTest6_8 );
       
   128 	AddTestStepL( new(ELeave) CRootServerTest6_9 );
       
   129 	AddTestStepL( new(ELeave) CRootServerTest6_10 );
       
   130 	AddTestStepL( new(ELeave) CRootServerTest6_11 );
       
   131 	AddTestStepL( new(ELeave) CRootServerTest6_12 );
       
   132 	AddTestStepL( new(ELeave) CRootServerTest6_13 );
       
   133 	AddTestStepL( new(ELeave) CRootServerTest6_14 );
       
   134 	AddTestStepL( new(ELeave) CRootServerTest6_15 );
       
   135 	AddTestStepL( new(ELeave) CRootServerTest6_16 );
       
   136 	AddTestStepL( new(ELeave) CRootServerTest7_1 );
       
   137 	AddTestStepL( new(ELeave) CRootServerTest7_2 );
       
   138 	AddTestStepL( new(ELeave) CRootServerTest7_3 );
       
   139 	AddTestStepL( new(ELeave) CRootServerTest7_4 );
       
   140 	AddTestStepL( new(ELeave) CRootServerTest8_1 );
       
   141 
       
   142 	iNextServerNumber = 0;
       
   143 	}
       
   144 
       
   145 TInt CTestSuiteRootServer::StartRootServer()
       
   146 /**
       
   147  * Start the Root Server and connect the standard session to it
       
   148  *
       
   149  * @return TInt - An error code
       
   150  */
       
   151     {    
       
   152     TInt err = KErrNone;
       
   153     TFindServer findCS(KRootServerName);
       
   154     TFullName name;
       
   155     RProcess rootServer;
       
   156 
       
   157     if (findCS.Next(name) == KErrNone)
       
   158 		{
       
   159 		Log(_L("Shutting down existing RootServer"));
       
   160 
       
   161 		// Try to shutdown any existing instance of the rootserver so we can
       
   162 		// safely change the MBuf pool size before any modules are loaded.
       
   163 		// A sticky module such as ETel may prevent complete shutdown so we
       
   164 		// kill the process if necessary.
       
   165 		if(!ShutdownRootServer())
       
   166 			{
       
   167 			Log(_L("Killing existing RootServer"));
       
   168 
       
   169 			// Kill the rootserver process if normal shutdown fails.
       
   170 			TFindProcess findPS(KRootServerProcessPattern);
       
   171 			err = findPS.Next(name);
       
   172 			if(err == KErrNone)
       
   173 				{
       
   174 	 			err = rootServer.Open(findPS);
       
   175 	 			if(err == KErrNone)
       
   176 	 				{
       
   177 		 			TRequestStatus status;
       
   178 					rootServer.Logon(status);
       
   179 					rootServer.Kill(KErrNone);
       
   180 					User::WaitForRequest(status);
       
   181 					
       
   182 					// Create a timer in case some other entity holds an open handle on the
       
   183 					// configurator which prevents the kernel from destroying it.  We timeout
       
   184 					// after one second.
       
   185 					TAutoClose<RTimer> timer;
       
   186 					if(timer.iObj.CreateLocal() == KErrNone)
       
   187 						{
       
   188 						// Request destruction notification so we know when it is safe to start
       
   189 						// the process again.
       
   190 						TRequestStatus destructionStatus;
       
   191 						rootServer.NotifyDestruction(destructionStatus);
       
   192 						rootServer.Close();
       
   193 					
       
   194 						enum{ KProcessDestructionTimeout = 1000000 };
       
   195 				  					
       
   196 						TRequestStatus timerStatus;
       
   197 						timer.iObj.After(timerStatus, KProcessDestructionTimeout);
       
   198 						
       
   199 						// Wait for the process to be destroyed or for the timeout.
       
   200 						User::WaitForRequest(destructionStatus, timerStatus);
       
   201 						if(timerStatus.Int() == KRequestPending)
       
   202 							{
       
   203 							timer.iObj.Cancel();
       
   204 							User::WaitForRequest(timerStatus);
       
   205 							}
       
   206 						else
       
   207 							{
       
   208 							User::CancelMiscNotifier(destructionStatus);
       
   209 							User::WaitForRequest(destructionStatus);
       
   210 							
       
   211 							Log(_L("CTestSuiteRootServer::StartRootServer - existing RootServer process has still not been destroyed after %f.0s"), KProcessDestructionTimeout / 1000000.0);
       
   212 							}
       
   213 						}
       
   214 	 				}
       
   215 				}
       
   216 			}
       
   217 		}
       
   218 	else
       
   219 		{
       
   220 	    err = rootServer.Create(KRootServerExe, KNullDesC);
       
   221 		TRequestStatus status;
       
   222 	    if (err == KErrNone)
       
   223 			{
       
   224 			rootServer.Rendezvous(status);
       
   225 			rootServer.Resume();
       
   226 			User::WaitForRequest(status);
       
   227 			rootServer.Close();
       
   228 			err = status.Int();
       
   229 			}
       
   230 		if(err == KErrNone)
       
   231 			{
       
   232 			err = RootSess().Connect();
       
   233 			}
       
   234 		}
       
   235 
       
   236     return err;
       
   237     }
       
   238 
       
   239 
       
   240 TBool CTestSuiteRootServer::ShutdownRootServer()
       
   241 /**
       
   242  * Tell the Root Server to shutdown via its standard session, and validate that it did so.
       
   243  *
       
   244  * @return TBool - True if shutdown was successful
       
   245  */
       
   246     {
       
   247 	TInt err;
       
   248 	// Some tests close the session
       
   249 	if(RootSess().Handle() == 0)
       
   250 		{
       
   251 		err = RootSess().Connect();
       
   252 		if(err != KErrNone)
       
   253 			{
       
   254 			Log(_L("Failed to reconnect session (err %d) - maybe dead already?"), err);
       
   255 			return EFalse;
       
   256 			}
       
   257 		}
       
   258 
       
   259 	TRSIter position;
       
   260 	while((err = RootSess().Shutdown()) == KErrRSModulesStillRunning)
       
   261 		{
       
   262 		TCFModuleName moduleName;
       
   263 		err = RootSess().EnumerateModules(position, moduleName);
       
   264 		if(err == KErrEof)
       
   265 			{
       
   266 			Log(_L("RRootServ::Shutdown could not be completed, probably due to the presence of sticky modules"));
       
   267 			return EFalse;
       
   268 			}
       
   269 		TRSModuleInfo moduleInfo;
       
   270 		err = RootSess().GetModuleInfo(moduleName, moduleInfo);
       
   271 		if(err == KErrRSModuleUnknown)
       
   272 			continue;	// an unload probably just completed
       
   273 		else if(err != KErrNone)
       
   274 			{
       
   275 			Log(_L("RRootServ::GetModuleInfo failed during shutdown"));
       
   276 			return EFalse;
       
   277 			}
       
   278 		TBuf<KCFMaxModuleName> wideModuleName;
       
   279 		wideModuleName.Copy(moduleName);
       
   280 		Log(_L("RRootServ::Shutdown in progress; need to unload %S (state %d)"), &wideModuleName, moduleInfo().iState);
       
   281 		TRequestStatus status;
       
   282 		switch(moduleInfo().iState)
       
   283 			{
       
   284 			case EStarting:		// treat a starting module as a zombie coz we're in a hurry, and who knows how long that rendezvous could take?
       
   285 			case EZombie:
       
   286 				{
       
   287 				RootSess().UnloadCpm(status, moduleName, EUnGraceful);
       
   288 				User::WaitForRequest(status);
       
   289 				if(status != KErrNone && status != KErrRSSuddenDeath && status != KErrRSModuleUnknown)
       
   290 					{
       
   291 					Log(_L("RRootServ::Shutdown failed, zombie could not be killed"));
       
   292 					return EFalse;
       
   293 					}
       
   294 				break;
       
   295 				}
       
   296 			case ERunning:
       
   297 				{
       
   298 				RootSess().UnloadCpm(status, moduleName, EGraceful);
       
   299 				User::WaitForRequest(status);
       
   300 				if(status.Int() == KErrLocked)
       
   301 					{
       
   302 					Log(_L("Module is sticky and cannot be unloaded"));
       
   303 					
       
   304 					// Move to the next module.
       
   305 					continue;
       
   306 					}
       
   307 				else
       
   308 					{
       
   309 					Log(_L("UnloadCPM returned %d"), status.Int());
       
   310 					}
       
   311 				break;	// either it worked or it should have become a zombie
       
   312 				}
       
   313 			case EStopping:
       
   314 				{
       
   315 				// transition states; snooze and try again
       
   316 				User::After(1000000);
       
   317 				break;
       
   318 				}
       
   319 			default:
       
   320 				{
       
   321 				Log(_L("RRootServ::Shutdown failed, module in improper states"));
       
   322 				return EFalse;
       
   323 				}
       
   324 			}
       
   325 			
       
   326 			// Try to unload this module again.
       
   327 			position.Reset();
       
   328 		}
       
   329 	RootSess().Close();
       
   330 	RRootServ probeSess;
       
   331 	TBool res = (probeSess.Connect() != KErrNone);
       
   332 	if(!res)
       
   333 		{
       
   334 		probeSess.Close();
       
   335 		}
       
   336 
       
   337     return res;
       
   338     }
       
   339 
       
   340 
       
   341 
       
   342 CSelfPopScheduler* CSelfPopScheduler::CreateLC()
       
   343 	{
       
   344 	CSelfPopScheduler* self = new(ELeave)CSelfPopScheduler;
       
   345 	CleanupStack::PushL(self);
       
   346 	CActiveScheduler::Install(self);
       
   347 	return self;
       
   348 	}
       
   349 
       
   350 CSelfPopScheduler::operator TCleanupItem()
       
   351 	{
       
   352 	return TCleanupItem(Cleanup, this);
       
   353 	}
       
   354 
       
   355 void CSelfPopScheduler::Cleanup(TAny* aItem)
       
   356 	{
       
   357 	CActiveScheduler::Install(NULL);
       
   358 	delete reinterpret_cast<CSelfPopScheduler*>(aItem);
       
   359 	}
       
   360 
       
   361