systemhealthmanagement/systemhealthmgr/test/tsysmon/src/tsysmon_stepprocrestart.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include "testprocgoodsession.h"
       
    23 #include "tsysmon_stepprocrestart.h"
       
    24 
       
    25 
       
    26 CStepProcRestart::CStepProcRestart()
       
    27 	{
       
    28 	SetTestStepName(KCTestCaseProcRestart);
       
    29 	}
       
    30 
       
    31 TVerdict CStepProcRestart::doTestStepL()
       
    32 	{
       
    33 	TInt err = iProcStartSignalSem.CreateGlobal(KStartShmaTestProcGood,0);
       
    34 	INFO_PRINTF2(_L("Semaphore created with err %d"), err);
       
    35 	TEST(KErrNone == err);
       
    36 	
       
    37 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0003"));
       
    38 	TRAP(err, DoTestProcRestartL());
       
    39 	TEST(err == KErrNone);
       
    40 	
       
    41 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0003b"));	
       
    42 	TRAP(err, DoTestExtendedProcRestartL());
       
    43 	TEST(err == KErrNone);
       
    44 
       
    45 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0055"));
       
    46 	TRAP(err, DoTestProcRestartAferRateOfFailureL());
       
    47 	TEST(err == KErrNone);
       
    48 
       
    49 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0056"));
       
    50 	TRAP(err, DoTestProcRestartForRateOfFailureL());
       
    51 	TEST(err == KErrNone);
       
    52 	
       
    53 	iProcStartSignalSem.Close();
       
    54 
       
    55 	return TestStepResult();
       
    56 	}
       
    57 
       
    58 /**
       
    59 Old Test CaseID 		APPFWK-SYSMON-0003
       
    60 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0003
       
    61 */
       
    62 
       
    63 void CStepProcRestart::DoTestProcRestartL()
       
    64 	{
       
    65 	INFO_PRINTF1(_L("New Test step"));
       
    66 	INFO_PRINTF1(_L("Test System Monitor functionality using startupproperties"));
       
    67 	RProcess process;
       
    68 	
       
    69 	CleanupClosePushL(process);
       
    70 	StartAndMonitorUsingStartupPropL(process, EWaitForStart);
       
    71 
       
    72 	iProcStartSignalSem.Wait();
       
    73 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
    74 	process.Kill(KErrNone);
       
    75 	CleanupStack::Pop(&process);
       
    76 	INFO_PRINTF1(_L("Killed monitored process."));		
       
    77 	TESTL(AssertRestart()); // this is the main test
       
    78 
       
    79 	Cleanup();
       
    80 	
       
    81 	INFO_PRINTF1(_L("Test System Monitor functionality using ssmstartupproperties"));
       
    82 	CleanupClosePushL(process);
       
    83 	StartAndMonitorUsingSsmStartupPropL(process, EWaitForStart);
       
    84 	
       
    85 	iProcStartSignalSem.Wait();
       
    86 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
    87 	process.Kill(KErrNone);
       
    88 	CleanupStack::PopAndDestroy(&process);
       
    89 	INFO_PRINTF1(_L("Killed monitored process."));		
       
    90 	TESTL(AssertRestart()); // this is the main test
       
    91 	
       
    92 	Cleanup();
       
    93 
       
    94 	INFO_PRINTF1(_L("Test step complete"));		
       
    95 	INFO_PRINTF1(_L(""));
       
    96 	}
       
    97 
       
    98 /**
       
    99 Old Test CaseID 		APPFWK-SYSMON-0003b
       
   100 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0003
       
   101 */
       
   102 
       
   103 
       
   104 void CStepProcRestart::DoTestExtendedProcRestartL()
       
   105 	{
       
   106 	INFO_PRINTF1(_L("New Test step"));
       
   107 	INFO_PRINTF1(_L("Test System Monitor functionality using startupproperties"));
       
   108 	RProcess process;
       
   109 	CleanupClosePushL(process);
       
   110 	StartAndMonitorUsingStartupPropL(process, EWaitForStart);
       
   111 	
       
   112 	iProcStartSignalSem.Wait();
       
   113 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
   114 	process.Kill(KErrNone);
       
   115 	CleanupStack::Pop(&process);
       
   116 	INFO_PRINTF1(_L("Killed monitored process."));		
       
   117 	TESTL(AssertRestart()); 
       
   118 	
       
   119 	//Now do the same test for the restarted process, can't use the old processhandle
       
   120 	RTestProcGoodSession server;	
       
   121 	TEST(KErrNone == server.Connect());
       
   122 	server.ShutDown();
       
   123 	server.Close();
       
   124 	INFO_PRINTF1(_L("Killed the restarted process."));		
       
   125 	TESTL(AssertRestart()); // this is the main test
       
   126 	
       
   127 	Cleanup();	
       
   128 	
       
   129 	INFO_PRINTF1(_L("Test System Monitor functionality using ssmstartupproperties"));
       
   130 	CleanupClosePushL(process);
       
   131 	StartAndMonitorUsingSsmStartupPropL(process, EWaitForStart);
       
   132 	
       
   133 	iProcStartSignalSem.Wait();
       
   134 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
   135 	process.Kill(KErrNone);
       
   136 	CleanupStack::PopAndDestroy(&process);
       
   137 	INFO_PRINTF1(_L("Killed monitored process."));		
       
   138 	TESTL(AssertRestart()); 
       
   139 	
       
   140 	//Now do the same test for the restarted process, can't use the old processhandle
       
   141 	TEST(KErrNone == server.Connect());
       
   142 	server.ShutDown();
       
   143 	server.Close();
       
   144 	INFO_PRINTF1(_L("Killed the restarted process."));		
       
   145 	TESTL(AssertRestart()); // this is the main test
       
   146 	
       
   147 	Cleanup();	
       
   148 
       
   149 	INFO_PRINTF1(_L("Test step complete"));		
       
   150 	INFO_PRINTF1(_L(""));
       
   151 	}
       
   152 
       
   153 /**
       
   154 Old Test CaseID 		APPFWK-SYSMON-0055
       
   155 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0003
       
   156 */
       
   157 
       
   158 void CStepProcRestart::DoTestProcRestartAferRateOfFailureL()
       
   159 	{
       
   160 	TRAPD(err, DoTestProcRestartAferRateOfFailureL(EWaitForStart));
       
   161 	TEST(err == KErrNone);
       
   162 	
       
   163 	TRAP(err, DoTestProcRestartAferRateOfFailureL(EFireAndForget));
       
   164 	TEST(err == KErrNone);
       
   165 	}
       
   166 
       
   167 void CStepProcRestart::DoTestProcRestartAferRateOfFailureL(TStartMethod aStartMethod)
       
   168 	{
       
   169 	INFO_PRINTF1(_L("New Test step"));
       
   170 	
       
   171 	// The KIntervalForReLaunchRateOfFailure time interval is 30mins by default, its patched to 25secs on emulator in epoc.ini file
       
   172 	// and for hardware in iby file.
       
   173 	INFO_PRINTF1(_L("For test to pass in Winscw - (patchdata_sysmon_exe_KIntervalForReLaunchRateOfFailure 25) should be added to epoc32\\data\\epoc.ini file"));
       
   174 	RProcess process;
       
   175 	CleanupClosePushL(process);
       
   176 	StartAndMonitorUsingStartupPropL(process, aStartMethod);
       
   177 	
       
   178 	iProcStartSignalSem.Wait();
       
   179 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
   180 	process.Kill(KErrNone);
       
   181 	CleanupStack::PopAndDestroy(&process);
       
   182 	INFO_PRINTF1(_L("Killed monitored process."));		
       
   183 	TESTL(AssertRestart()); 
       
   184 	
       
   185 	//Now do the same test for the restarted process, can't use the old processhandle
       
   186 	RTestProcGoodSession server;	
       
   187 	TEST(KErrNone == server.Connect());
       
   188 	server.ShutDown();
       
   189 	server.Close();
       
   190 	INFO_PRINTF1(_L("Killed the restarted process."));		
       
   191 	TESTL(AssertRestart()); // this is the main test
       
   192 
       
   193 	//Now do the same test for the restarted process, can't use the old processhandle
       
   194 	TEST(KErrNone == server.Connect());
       
   195 	server.ShutDown();
       
   196 	server.Close();
       
   197 	INFO_PRINTF1(_L("Killed the restarted process. - 2"));
       
   198 	TESTL(AssertRestart()); // this is the main test
       
   199 
       
   200 	//Now do the same test for the restarted process, can't use the old processhandle
       
   201 	TEST(KErrNone == server.Connect());
       
   202 	server.ShutDown();
       
   203 	server.Close();
       
   204 	INFO_PRINTF1(_L("Killed the restarted process. - 3"));
       
   205 
       
   206 	//Allow the process to be restarted
       
   207 	INFO_PRINTF1(_L("Going to sleep for KWaitTime + 1 seconds."));		
       
   208 	User::After(KThrottleTime + 1000000);
       
   209 	
       
   210 	//Assert that the server is not running
       
   211 	const TInt err = server.Connect();
       
   212 	TEST(KErrNotFound == err);
       
   213 	if(err)
       
   214 		{
       
   215 		INFO_PRINTF1(_L("Asserted that server is not running - Monitor's Rate of Failure policy would be applied"));
       
   216 		INFO_PRINTF1(_L("System Moniter is cancelled as the failure recovery policy is Ignore on failure"));
       
   217 		}
       
   218 	}
       
   219 
       
   220 
       
   221 
       
   222 /**
       
   223 Old Test CaseID 		APPFWK-SYSMON-0056
       
   224 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0003
       
   225 */
       
   226 
       
   227 
       
   228 void CStepProcRestart::DoTestProcRestartForRateOfFailureL()
       
   229 	{
       
   230 	TRAPD(err, DoTestProcRestartForRateOfFailureL(EWaitForStart));
       
   231 	TEST(err == KErrNone);
       
   232 	
       
   233 	TRAP(err, DoTestProcRestartForRateOfFailureL(EFireAndForget));
       
   234 	TEST(err == KErrNone);
       
   235 	}
       
   236 	
       
   237 void CStepProcRestart::DoTestProcRestartForRateOfFailureL(TStartMethod aStartMethod)
       
   238 	{
       
   239 	INFO_PRINTF1(_L("New Test step"));
       
   240 
       
   241 	// The KIntervalForReLaunchRateOfFailure time interval is 30mins by default, its patched to 25secs on emulator in epoc.ini file
       
   242 	// and for hardware in iby file.
       
   243 	INFO_PRINTF1(_L("For test to pass in Winscw - (patchdata_sysmon_exe_KIntervalForReLaunchRateOfFailure 25) should be added to epoc32\\data\\epoc.ini file"));
       
   244 	RProcess process;
       
   245 	CleanupClosePushL(process);
       
   246 	StartAndMonitorUsingStartupPropL(process, aStartMethod);
       
   247 	
       
   248 	iProcStartSignalSem.Wait();
       
   249 	//Killing the process will cause sysmon to restart after KWaitTime (declared in sysmon_patch.h)
       
   250 	process.Kill(KErrNone);
       
   251 	CleanupStack::PopAndDestroy(&process);
       
   252 	INFO_PRINTF1(_L("Killed monitored process - 1"));		
       
   253 	TESTL(AssertRestart()); 
       
   254 	
       
   255 	//Now do the same test for the restarted process, can't use the old processhandle
       
   256 	RTestProcGoodSession server;	
       
   257 	TEST(KErrNone == server.Connect());
       
   258 	server.ShutDown();
       
   259 	server.Close();
       
   260 	INFO_PRINTF1(_L("Killed the restarted process. - 2"));
       
   261 	TESTL(AssertRestart()); // this is the main test
       
   262 
       
   263 	//Now do the same test for the restarted process, can't use the old processhandle
       
   264 	TEST(KErrNone == server.Connect());
       
   265 	INFO_PRINTF1(_L("Going to sleep for KReLaunchRateofFailure - 25secs."));
       
   266 	User::After(25000000);
       
   267 
       
   268 	//Now do the same test for the restarted process, can't use the old processhandle
       
   269 	server.ShutDown();
       
   270 	server.Close();
       
   271 
       
   272 	//Assert that the server is not running
       
   273 	TInt err = server.Connect();
       
   274 	TEST(KErrNotFound == err);
       
   275 	INFO_PRINTF2(_L("Connect to server with %d"),err);
       
   276 
       
   277 	INFO_PRINTF1(_L("Killed the restarted process after KIntervalForReLaunchRateOfFailure - 3"));
       
   278 	
       
   279 	//Assert that the server is running
       
   280 	TESTL(AssertRestart());
       
   281 
       
   282 	Cleanup();
       
   283 	INFO_PRINTF1(_L("Test step complete"));	
       
   284 	}
       
   285 
       
   286 TBool CStepProcRestart::AssertRestart()
       
   287 	{	
       
   288 	//Allow the process to be restarted
       
   289 	INFO_PRINTF1(_L("Going to sleep using Semaphore."));		
       
   290 
       
   291 	//Wait for the process to restart
       
   292 	iProcStartSignalSem.Wait();
       
   293 	
       
   294 	//Assert that the server is running
       
   295 	INFO_PRINTF1(_L("Woke up, now the server should be restarted (sysmon KWaitTime is 15s)."));	
       
   296 	RTestProcGoodSession server;	
       
   297 	const TInt err = server.Connect();
       
   298 	const TBool assert = (KErrNone == err);
       
   299 	TESTE(assert, err);
       
   300 	if(assert)
       
   301 		{
       
   302 		INFO_PRINTF1(_L("Yes, asserted that server is running."));		
       
   303 		}
       
   304 	server.Close();
       
   305 	return assert;
       
   306 	}
       
   307 	
       
   308 void CStepProcRestart::Cleanup()
       
   309 	{
       
   310 	RTestProcGoodSession server;	
       
   311 	const TInt err = server.Connect();
       
   312 	TESTE(KErrNone == err, err);
       
   313 	if(KErrNone == err)
       
   314 		{
       
   315 		INFO_PRINTF1(_L("Going to cancel monitor and shutdown server."));		
       
   316 		}
       
   317 	server.CancelMonitor();
       
   318 	server.ShutDown();
       
   319 	server.Close();
       
   320 	}