sysstatemgmt/systemstatemgr/test/tss/src/tss_apptimeout.cpp
changeset 0 4e1aa6a622a0
child 41 c87e5f80c17d
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 // Old Test CaseID 		APPFWK-SSS-0005
       
    15 // New Test CaseID 		DEVSRVS-SSMA-STARTSAFE-0005
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test
       
    22  @internalComponent - Internal Symbian test code
       
    23 */
       
    24 
       
    25 
       
    26 
       
    27 #include "tss_apptimeout.h"
       
    28 #include "ssmtestapps.h"
       
    29 #include "ssmtestappsucessfulafterretry.h"
       
    30 #include "ssmtestappslow.h"
       
    31 
       
    32 const TInt KWaitTime = 300;
       
    33 const TInt KWaitTimeForTestAppForFAndF = 500;	// 500ms is the delay given for the KTestAppForFAndF test app for each retry.
       
    34 	 
       
    35 TVerdict CSsTestStepAppTimeout::doTestStepL()
       
    36 	{
       
    37 	__UHEAP_MARK;
       
    38 	
       
    39 	TRAPD(err, DoTestAppTimeoutAsAppL());
       
    40 	TEST(err == KErrNone);
       
    41 	INFO_PRINTF2(_L("DoTestAppTimeoutAsAppL completed with err = %d"), err);
       
    42 	
       
    43 	TRAP(err, DoTestAppTimeoutAsProcL());
       
    44 	TEST(err == KErrNone);
       
    45 	INFO_PRINTF2(_L("DoTestAppTimeoutAsProcL completed with err = %d"), err);
       
    46 	
       
    47 	TRAP(err, DoTestWaitForSignalWithLessTimeOutAndWithRetriesL());
       
    48 	TEST(err == KErrNone);
       
    49 	INFO_PRINTF2(_L("DoTestWaitForSignalWithLessTimeOutAndWithRetriesL completed with err = %d"), err);
       
    50 	
       
    51 	TRAP(err, DoTestWaitForSignalWithLessTimeOutAndNoRetriesL());
       
    52 	TEST(err == KErrNone);
       
    53 	INFO_PRINTF2(_L("DoTestWaitForSignalWithLessTimeOutAndNoRetriesL completed with err = %d"), err);
       
    54 	
       
    55 	TRAP(err, DoTestWaitForSignalWithMoreTimeOutAndNoRetriesL());
       
    56 	TEST(err == KErrNone);
       
    57 	INFO_PRINTF2(_L("DoTestWaitForSignalWithMoreTimeOutAndNoRetriesL completed with err = %d"), err);
       
    58 	
       
    59 	TRAP(err, DoTestWaitForSignalWithMoreTimeOutAndWithRetriesL());
       
    60 	TEST(err == KErrNone);
       
    61 	INFO_PRINTF2(_L("DoTestWaitForSignalWithMoreTimeOutAndWithRetriesL completed with err = %d"), err);
       
    62 	
       
    63 	TRAP(err, DoTestWaitForSignalWithRetriesForFailureAppL());
       
    64 	TEST(err == KErrNone);
       
    65 	INFO_PRINTF2(_L("DoTestWaitForSignalWithRetriesForFailureAppL completed with err = %d"), err);
       
    66 	
       
    67 	TRAP(err, DoTestWaitForSignalWithRetriesForSuccessfullAppL());
       
    68 	TEST(err == KErrNone);
       
    69 	INFO_PRINTF2(_L("DoTestWaitForSignalWithRetriesForSuccessfullAppL completed with err = %d"), err);
       
    70 
       
    71 	__UHEAP_MARKEND;
       
    72 	return TestStepResult();	
       
    73 	}
       
    74 
       
    75 TInt CSsTestStepAppTimeout::DoTestAndStopperL(TInt aRetries, TInt aTimeOut, const TDesC& aFileName)
       
    76 	{
       
    77 	CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL();
       
    78 	CleanupStack::PushL(startupProperties);
       
    79 	
       
    80 	startupProperties->SetFileParamsL(aFileName, KNullDesC);
       
    81 	startupProperties->SetCommandTypeL(ESsmCmdStartProcess);
       
    82 	startupProperties->SetExecutionBehaviour(ESsmWaitForSignal);
       
    83 	startupProperties->SetTimeout(aTimeOut);
       
    84 	startupProperties->SetRetries(aRetries);
       
    85 	
       
    86 	RProcess process;
       
    87 	CleanupClosePushL(process);
       
    88 	CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout );
       
    89 	CleanupStack::PushL( stopper );
       
    90 	
       
    91 	TRequestStatus& trs = stopper->Trs();
       
    92 	CSsmStartSafe* ss  = CSsmStartSafe::NewLC();
       
    93 
       
    94 	TInt id = 0;
       
    95 	ss->Start(*startupProperties, process, trs, id);
       
    96 	//Process are started using Wait for signal execution behaviour, 
       
    97 	//Start method always sets TRequestStatus to KRequestPending.		
       
    98 	if( KRequestPending == trs.Int() )
       
    99 		{
       
   100 		CActiveScheduler::Start();
       
   101 		}
       
   102 
       
   103 	TInt completionCode = stopper->CompletionCode();	
       
   104 	
       
   105 	CleanupStack::PopAndDestroy(4, startupProperties);
       
   106 	return completionCode;
       
   107 	}
       
   108 
       
   109 /**
       
   110  Starts an instance of ssmtestappslow.exe synchronously as a process using Wait-for-Signal.
       
   111  No retries are specified. Timeout is specified, therefore CTimeoutWaiter is not instantiated.
       
   112 */
       
   113 void CSsTestStepAppTimeout::DoTestWaitForSignalWithLessTimeOutAndWithRetriesL()
       
   114 	{	
       
   115 	INFO_PRINTF1(_L("Performing Wait-for-Signal Timeout test with retries"));
       
   116 	
       
   117 	const TInt KTestLessTimeOut = KTestAppSlowTimeoutInMilliSeconds-100;
       
   118 	TInt completionCode = DoTestAndStopperL(1, KTestLessTimeOut, KTestAppSlow);
       
   119 
       
   120 	TEST(completionCode == -33);
       
   121 	INFO_PRINTF2( _L("Anticipated completion code -33. Supplied completion code %d"),completionCode);
       
   122 	// ssmtestappslow.exe would terminated due to timeout. 
       
   123 	// Since ssmtestappslow application takes more time to start than the timeout specified in the ssmsstartupproperties,
       
   124 	// it doesn't start anytime irrespective of no. of retries specified.
       
   125 	TEST(0 == FindAndKill(KTestAppSlow));
       
   126 	INFO_PRINTF1( _L("ssmtestappslow.exe would be terminated due to timeout"));
       
   127 	}
       
   128 
       
   129 /**
       
   130  Start a ssmtestappslow test application synchronously using Wait-for-Signal with timeout
       
   131  less than the time required for the application to start and without retries.
       
   132 */
       
   133 void CSsTestStepAppTimeout::DoTestWaitForSignalWithLessTimeOutAndNoRetriesL()
       
   134 	{	
       
   135 	INFO_PRINTF1(_L("Performing Wait-for-Signal Timeout test with no retries"));
       
   136 	
       
   137 	const TInt KTestLessTimeOut = KTestAppSlowTimeoutInMilliSeconds-100;
       
   138 	TInt completionCode = DoTestAndStopperL(0, KTestLessTimeOut, KTestAppSlow);
       
   139 
       
   140 	TEST(completionCode == -33);
       
   141 	INFO_PRINTF2( _L("Anticipated completion code -33. Supplied completion code %d"),completionCode);
       
   142 	// ssmtestappslow.exe would terminated due to timeout. 
       
   143 	// Since ssmtestappslow application takes more time to start than the timeout specified in the ssmsstartupproperties
       
   144 	TEST(0 == FindAndKill(KTestAppSlow));
       
   145 	INFO_PRINTF1( _L("ssmtestappslow.exe would be terminated due to timeout"));
       
   146 	}
       
   147 
       
   148 /**
       
   149  Start a ssmtestappslow test application synchronously using Wait-for-Signal with timeout
       
   150  more than the time required for the application to start and without retries.
       
   151 */
       
   152 void CSsTestStepAppTimeout::DoTestWaitForSignalWithMoreTimeOutAndNoRetriesL()
       
   153 	{	
       
   154 	INFO_PRINTF1(_L("Performing Wait-for-Signal Timeout test with no retries and.."));
       
   155 	INFO_PRINTF1(_L("Timeout specified in ssmstartupproperties is more than timeout required for application startup"));
       
   156 	
       
   157 	const TInt KTestMoreTimeOut = KTestAppSlowTimeoutInMilliSeconds * 2;
       
   158 	TInt completionCode = DoTestAndStopperL(0, KTestMoreTimeOut, KTestAppSlow);
       
   159 
       
   160 	TEST(completionCode == 0);
       
   161 	INFO_PRINTF2( _L("Anticipated completion code 0. Supplied completion code %d"),completionCode);
       
   162 	// ssmtestappslow.exe would be started as ssmtestappslow application takes less time to start than 
       
   163 	// the timeout specified in the ssmsstartupproperties
       
   164 	TEST(1 == FindAndKill(KTestAppSlow));
       
   165 	}
       
   166 
       
   167 /**
       
   168  Start a test application synchronously using Wait-for-Signal with timeout
       
   169  more than the time required for the application to start and which starts after the no. of retries given.
       
   170 */
       
   171 void CSsTestStepAppTimeout::DoTestWaitForSignalWithMoreTimeOutAndWithRetriesL()
       
   172 	{	
       
   173 	INFO_PRINTF1(_L("Performing Wait-for-Signal test with timeout and retries"));
       
   174 
       
   175 	// Write the retry number to a file to be read, updated 
       
   176 	// and eventually deleted by the test-app.
       
   177 	RFs fs;	
       
   178 	CleanupClosePushL( fs );
       
   179 	
       
   180 	RFileWriteStream writeStream;
       
   181 	CleanupClosePushL( writeStream );
       
   182 
       
   183 	User::LeaveIfError(fs.Connect());
       
   184 	User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite));
       
   185 
       
   186 	const TInt KSsTestRequiredDelay = 0;
       
   187 	const TInt KSsTestFailCount = 1;
       
   188 	const TInt KSsTestRetryCount = 0;
       
   189 	writeStream.WriteInt8L(KSsTestRetryCount);
       
   190 	writeStream.WriteInt8L(KSsTestFailCount);
       
   191 	writeStream.WriteInt8L(KSsTestRequiredDelay);
       
   192 	writeStream.CommitL();
       
   193 	writeStream.Close();
       
   194 	
       
   195 	const TInt KRetries = KSsTestFailCount + 1;
       
   196 	TInt completionCode = DoTestAndStopperL(KRetries, KWaitTimeForTestAppForFAndF * 3, KTestAppForFAndF);
       
   197 	TEST(completionCode == 0);
       
   198 	
       
   199 	INFO_PRINTF2( _L("Anticipated completion code 0. Supplied completion code %d"),completionCode);
       
   200 	RFileReadStream readStream;
       
   201 	CleanupClosePushL(readStream);
       
   202 
       
   203 	User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead));
       
   204 	TInt retryCount = readStream.ReadInt8L();
       
   205 	readStream.Close();	
       
   206 	fs.Delete(KFileForFAndF);
       
   207 
       
   208 	CleanupStack::PopAndDestroy(3, &fs);
       
   209 
       
   210 	TEST(1 == FindAndKill(KTestAppForFAndF));
       
   211 	TEST(retryCount == 1);
       
   212 
       
   213 	INFO_PRINTF3( _L("ssmtestappsucessfulafterretry.exe is started after %d retries. anticipated retries value %d"),retryCount, 1);
       
   214 	}
       
   215 
       
   216 /**
       
   217  Start a test application which fails to start synchronously using Wait-for-Signal 
       
   218  without timeout and 1 retry.
       
   219 */
       
   220 void CSsTestStepAppTimeout::DoTestWaitForSignalWithRetriesForFailureAppL()
       
   221 	{	
       
   222 	INFO_PRINTF1(_L("Performing Wait-for-Signal test for failure app with retries and no timeout"));
       
   223 
       
   224 	TInt completionCode = DoTestAndStopperL(1, 0, KTestAppRvError);
       
   225 
       
   226 	TEST(completionCode == -2012);
       
   227 	INFO_PRINTF2( _L("Anticipated completion code -2012. Supplied completion code %d"),completionCode);
       
   228 	// Since ssmtestapprverror application is terminated with KErrGeneral each it is started, so
       
   229 	// it doesn't start anytime irrespective of no. of retries specified.
       
   230 	INFO_PRINTF1( _L("ssmtestapprverror.exe would not be started even after 1 retry as the app Rendezvous with error"));
       
   231 	TEST( 0 == FindAndKill(KTestAppRvError) );
       
   232 	}
       
   233 
       
   234 /**
       
   235  Start a test application which fails to start twice and starts on the 3rd retry 
       
   236  synchronously using Wait-for-Signal without timeout and 3 retries.
       
   237 */
       
   238 void CSsTestStepAppTimeout::DoTestWaitForSignalWithRetriesForSuccessfullAppL()
       
   239 	{	
       
   240 	INFO_PRINTF1(_L("Performing Wait-for-Signal test without timeout and with retries"));
       
   241 
       
   242 	// Write the retry number to a file to be read, updated 
       
   243 	// and eventually deleted by the test-app.
       
   244 	RFs fs;	
       
   245 	CleanupClosePushL( fs );
       
   246 	
       
   247 	RFileWriteStream writeStream;
       
   248 	CleanupClosePushL( writeStream );
       
   249 
       
   250 	User::LeaveIfError(fs.Connect());
       
   251 	User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite));
       
   252 
       
   253 	const TInt KSsTestRequiredDelay = 0;
       
   254 	const TInt KSsTestFailCount = 1;
       
   255 	const TInt KSsTestRetryCount = 0;
       
   256 	writeStream.WriteInt8L(KSsTestRetryCount);
       
   257 	writeStream.WriteInt8L(KSsTestFailCount);
       
   258 	writeStream.WriteInt8L(KSsTestRequiredDelay);
       
   259 	writeStream.CommitL();
       
   260 	writeStream.Close();
       
   261 
       
   262 	const TInt KRetries = KSsTestFailCount + 1;
       
   263 	TInt completionCode = DoTestAndStopperL(KRetries, 0, KTestAppForFAndF);
       
   264 	TEST(completionCode == 0);
       
   265 	INFO_PRINTF2( _L("Anticipated completion code 0. Supplied completion code %d"),completionCode);
       
   266 	RFileReadStream readStream;
       
   267 	CleanupClosePushL(readStream);
       
   268 
       
   269 	User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead));
       
   270 	TInt retryCount = readStream.ReadInt8L();
       
   271 	readStream.Close();	
       
   272 	fs.Delete(KFileForFAndF);
       
   273 
       
   274 	CleanupStack::PopAndDestroy(3, &fs);
       
   275 
       
   276 	TEST(retryCount == 1);
       
   277 
       
   278 	INFO_PRINTF3( _L("ssmtestappsucessfulafterretry.exe is started after %d retries. anticipated retries value %d"),retryCount, 1);
       
   279 	TEST(1 == FindAndKill(KTestAppForFAndF));
       
   280 	}
       
   281 
       
   282 /**
       
   283  Starts an instance of ssmtestappslow.exe asynchronously, allowing an insufficient period for it to rv.
       
   284 */
       
   285 void CSsTestStepAppTimeout::DoTestAppTimeoutAsAppL()
       
   286 	{
       
   287 	INFO_PRINTF1( _L("\n\nPerforming App-timeout as app test") );
       
   288 	
       
   289 	CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL();
       
   290 	CleanupStack::PushL( startupProperties );
       
   291 
       
   292 	startupProperties->SetFileParamsL( KTestAppSlow, KNullDesC );
       
   293 	startupProperties->SetCommandTypeL( ESsmCmdStartApp );
       
   294 	startupProperties->SetExecutionBehaviour( ESsmWaitForSignal );
       
   295 	startupProperties->SetTimeout( KWaitTime );
       
   296 
       
   297 	RProcess process;
       
   298 	CleanupClosePushL( process );
       
   299 	TInt id = 0;
       
   300 	
       
   301 	CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout );
       
   302 	CleanupStack::PushL( stopper );
       
   303 	
       
   304 	TRequestStatus& trs = stopper->Trs();
       
   305 	CSsmStartSafe* ss  = CSsmStartSafe::NewLC();
       
   306 	
       
   307 	ss->Start(*startupProperties, process, trs, id);
       
   308 	//Process are started using Wait for start execution behaviour, 
       
   309 	//Start method always sets TRequestStatus to KRequestPending.		
       
   310 	if( KRequestPending == trs.Int() )
       
   311 		{
       
   312 		CActiveScheduler::Start();
       
   313 		}
       
   314 
       
   315 	
       
   316 	TInt completionCode = stopper->CompletionCode();
       
   317 	INFO_PRINTF3( _L("Anticipated completion code %d. Supplied completion code %d"), KErrTimedOut, completionCode );
       
   318 	
       
   319 	TEST(  KErrTimedOut == completionCode );
       
   320 	
       
   321 	CleanupStack::PopAndDestroy( 4, startupProperties );
       
   322 	TEST( 0 == FindAndKill(KTestAppSlow) );	
       
   323 	}
       
   324 
       
   325 
       
   326 /**
       
   327   Starts an instance of ssmtestappslow.exe as a process asynchronously, 
       
   328   allowing an insufficient period for it to rv.
       
   329 */
       
   330 void CSsTestStepAppTimeout::DoTestAppTimeoutAsProcL()
       
   331 	{
       
   332 	INFO_PRINTF1( _L("\n\nPerforming App-timeout as process test") );
       
   333 	
       
   334 	CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL();
       
   335 	CleanupStack::PushL( startupProperties );
       
   336 
       
   337 	startupProperties->SetFileParamsL( KTestAppSlow, KNullDesC );
       
   338 	startupProperties->SetCommandTypeL( ESsmCmdStartProcess );
       
   339 	startupProperties->SetExecutionBehaviour( ESsmWaitForSignal );
       
   340 	startupProperties->SetRetries( 3 );
       
   341 	startupProperties->SetTimeout( KWaitTime );
       
   342 
       
   343 	RProcess process;
       
   344 	CleanupClosePushL( process );
       
   345 	TInt id = 0;
       
   346 	
       
   347 	CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout );
       
   348 	CleanupStack::PushL( stopper );
       
   349 	
       
   350 	TRequestStatus& trs = stopper->Trs();
       
   351 	
       
   352 	CSsmStartSafe* ss  = CSsmStartSafe::NewLC();
       
   353 	ss->Start(*startupProperties, process, trs, id);
       
   354 	//Process is started using Wait for signal execution behaviour, 
       
   355 	//Start method always sets TRequestStatus to KRequestPending.
       
   356 	if( KRequestPending == trs.Int() )
       
   357 		{
       
   358 		CActiveScheduler::Start();
       
   359 		}
       
   360 
       
   361 	
       
   362 	TInt completionCode = stopper->CompletionCode();
       
   363 	INFO_PRINTF3( _L("Anticipated completion code %d. Supplied completion code %d"), KErrTimedOut, completionCode );
       
   364 	
       
   365 	TEST(  KErrTimedOut == completionCode );
       
   366 	
       
   367 	CleanupStack::PopAndDestroy( 4, startupProperties );
       
   368 	TEST( 0 == FindAndKill(KTestAppSlow) );
       
   369 	}
       
   370 
       
   371 
       
   372 
       
   373 TVerdict CSsTestStepAppTimeout::doTestStepPreambleL()
       
   374 	{
       
   375 	iActiveScheduler = new(ELeave) CActiveScheduler;
       
   376 	CActiveScheduler::Install( iActiveScheduler );
       
   377 
       
   378 	return CTestStep::doTestStepPreambleL();	
       
   379 	}
       
   380 
       
   381 
       
   382 
       
   383 TVerdict CSsTestStepAppTimeout::doTestStepPostambleL()
       
   384 	{
       
   385 	return CTestStep::doTestStepPostambleL();
       
   386 	}
       
   387 
       
   388 
       
   389 
       
   390 CSsTestStepAppTimeout::CSsTestStepAppTimeout()
       
   391 	{
       
   392 	SetTestStepName(KCTestCaseAppTimeout);
       
   393 	}
       
   394 
       
   395 
       
   396 
       
   397 CSsTestStepAppTimeout::~CSsTestStepAppTimeout()
       
   398 	{
       
   399 	delete iActiveScheduler;
       
   400 	}
       
   401