sysstatemgmt/systemstarter/test/tstartsafe/src/tstartsafe_appretry.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 <startupproperties.h>
       
    23 #include <s32file.h>
       
    24 #include <hal.h>
       
    25 
       
    26 #include "testapps.h"
       
    27 #include "startsafe.h"
       
    28 #include "tstartsafe_appretry.h"
       
    29 #include "testapprvafterretry.h"
       
    30 
       
    31 
       
    32 // KDontRvCount is defined in testapprvafterretry.h
       
    33 // the application will fail to rendezvous KDontRvCount times
       
    34 // but will then acquiesce and rendezvous with KErrNone
       
    35 const TInt KTries = KDontRvCount;
       
    36 const TInt KStartSafeRetryTestTimeout = 600; //400;
       
    37 
       
    38 /**
       
    39 Old Test CaseID 		APPFWK-STARTSAFE-0008
       
    40 New Test CaseID 		DEVSRVS-SYSSTART-STARTSAFE-0008
       
    41  */
       
    42 
       
    43 TVerdict CAppFwkStartSafeTestStepAppRetry::doTestStepL( void )
       
    44 	{
       
    45 	TInt threadHandles_Before;
       
    46 	TInt processHandles_Before;
       
    47 	TInt threadHandles_After;
       
    48 	TInt processHandles_After;
       
    49 		
       
    50 	RThread().HandleCount(processHandles_Before, threadHandles_Before);
       
    51 	
       
    52 	CStartSafe *startSafe = CStartSafe::NewL();	
       
    53 	CleanupStack::PushL( startSafe );
       
    54 	
       
    55 	CStartupProperties *prop = CStartupProperties::NewL();
       
    56 	CleanupStack::PushL( prop );
       
    57 	
       
    58 
       
    59 	// Write the retry number to a file to be read, updated 
       
    60 	// and eventually deleted by the test-app.
       
    61 	RFs fs;	
       
    62 	CleanupClosePushL( fs );
       
    63 	
       
    64 	RFileWriteStream writeStream;
       
    65 	CleanupClosePushL( writeStream );
       
    66 	
       
    67 	if( KErrNone != fs.Connect()
       
    68 	 || KErrNone != writeStream.Replace(fs, KDontRvCountFile, EFileWrite) )
       
    69 		{
       
    70 		User::Leave( KErrCouldNotConnect );	
       
    71 		}	
       
    72 					
       
    73 	writeStream.WriteInt8L( KDontRvCount );
       
    74 	writeStream.CommitL();		
       
    75 	
       
    76 	CleanupStack::PopAndDestroy( 2, &fs );
       
    77 	
       
    78 	prop->SetFileParamsL( KTestAppRvAfterRetry, KNullDesC );
       
    79 	prop->SetStartupType( EStartApp );	
       
    80 	prop->SetStartMethod( EWaitForStart );
       
    81 	prop->SetNoOfRetries( KDontRvCount ); 
       
    82 	prop->SetTimeout( KStartSafeRetryTestTimeout );
       
    83 	
       
    84 	RProcess proc;
       
    85 	CleanupClosePushL( proc );
       
    86 	
       
    87 	TInt tried = 0;
       
    88 	TInt nTicksInMicroseconds = 0;
       
    89 	HAL::Get( HAL::ENanoTickPeriod, nTicksInMicroseconds );
       
    90 	INFO_PRINTF2( _L("System nano-ticks in uSec = %d"), nTicksInMicroseconds );
       
    91 	
       
    92 	TUint nTicks = User::NTickCount();	
       
    93 	
       
    94 	INFO_PRINTF2( _L("Invoke StartSafe on %S"), &KTestAppRvAfterRetry() );
       
    95 	TRAPD( err, startSafe->StartL(*prop, proc, tried) );
       
    96 	
       
    97 	nTicks = ( User::NTickCount() - nTicks );
       
    98 	INFO_PRINTF2( _L("milliseconds after = %d"), nTicks * (nTicksInMicroseconds / 1000) );
       
    99 	
       
   100 
       
   101 	TPtrC procNamePtr = proc.FileName().Right( KTestAppRvAfterRetry().Length() );
       
   102 	TInt nameComparison = procNamePtr.Compare( KTestAppRvAfterRetry() );
       
   103 		
       
   104 	if ( (KTries !=tried) || (KErrNone != err) || (0 != nameComparison) )
       
   105 		{
       
   106 		SetTestStepResult( EFail );	
       
   107 		ERR_PRINTF3( _L("Test failed. Retries %d. StartL error code %d "), tried, err );
       
   108 		}
       
   109 	else
       
   110 		{
       
   111 		SetTestStepResult( EPass );	
       
   112 		INFO_PRINTF2( _L("Test passed. App launched after %d unsuccessful tries"), tried );
       
   113 		}
       
   114 
       
   115 	// Dispose of the test-app.	
       
   116 	if( 0 == nameComparison )
       
   117 		{
       
   118 		proc.Kill( KErrNone );			
       
   119 		}
       
   120 		
       
   121 					
       
   122 	CleanupStack::PopAndDestroy( 3, startSafe ); // proc, prop, startSafe
       
   123 	
       
   124 	RThread().HandleCount(processHandles_After, threadHandles_After);
       
   125 	TEST(processHandles_After == processHandles_Before);
       
   126 	TEST(threadHandles_After == threadHandles_Before);
       
   127 	
       
   128 	return TestStepResult();	
       
   129 	}
       
   130 
       
   131 
       
   132 
       
   133 CAppFwkStartSafeTestStepAppRetry::CAppFwkStartSafeTestStepAppRetry()
       
   134 	{
       
   135 	SetTestStepName( KCTestCaseAppRetry );
       
   136 	}