sysstatemgmt/systemstarter/test/tstartsafe/src/tstartsafe_procfailsysrestart.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 
       
    24 #include "startsafe.h"
       
    25 #include "testapps.h"
       
    26 #include "tstartsafe_procfailsysrestart.h"
       
    27 #include "tpowerdownclient.h"
       
    28 
       
    29 CAppFwkStartSafeTestStepProcFailSysRestart::CAppFwkStartSafeTestStepProcFailSysRestart()
       
    30 	{
       
    31 	SetTestStepName(KCTestCaseProcFailSysRestart);
       
    32 	}
       
    33 
       
    34 CAppFwkStartSafeTestStepProcFailSysRestart::~CAppFwkStartSafeTestStepProcFailSysRestart()
       
    35 	{
       
    36 	delete iNotifier;
       
    37 	}	
       
    38 
       
    39 static TInt StartApplication(TAny* aSelf)
       
    40 	{
       
    41 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    42 	TInt r=KErrNoMemory;
       
    43 	if (cleanup)
       
    44 		{
       
    45 		CAppFwkStartSafeTestStepProcFailSysRestart* self = (CAppFwkStartSafeTestStepProcFailSysRestart*)aSelf;
       
    46 		TRAP(r, self->DoStartApplicationL());
       
    47 		delete cleanup;
       
    48 		}
       
    49 	return r;
       
    50 	}
       
    51 
       
    52 /**
       
    53 Old Test CaseID 		APPFWK-STARTSAFE-0013
       
    54 New Test CaseID 		DEVSRVS-SYSSTART-STARTSAFE-0013
       
    55  */	
       
    56 
       
    57 TVerdict CAppFwkStartSafeTestStepProcFailSysRestart::doTestStepL()
       
    58 	{
       
    59 
       
    60 #ifdef __WINSCW__
       
    61 	ASSERT(0);
       
    62 #endif	
       
    63 
       
    64 	//create scheduler
       
    65 	//create savenotifier
       
    66 	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
       
    67 	CleanupStack::PushL(sched);
       
    68 	CActiveScheduler::Install(sched);
       
    69 	iNotifier = CSaveNotifier::NewL(*this);
       
    70 
       
    71 	//Create a new thread and resume it
       
    72 	RThread thread;
       
    73 	CleanupClosePushL(thread);
       
    74 	User::LeaveIfError(thread.Create(_L("StarterThread"), StartApplication, KDefaultStackSize, NULL, this));
       
    75 	TRequestStatus stat;	
       
    76 	thread.Rendezvous(stat);
       
    77 	if (stat!=KRequestPending)
       
    78 		{
       
    79 		thread.Kill(0);	// abort startup
       
    80 		TEST(EFalse);	// fail test
       
    81 		return TestStepResult();
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		thread.Resume();	// logon OK - run DoStartApplicationL	
       
    86 		}
       
    87 	User::WaitForRequest(stat);	// wait for rendevouz
       
    88 	//Some sanity checks to verify our new thread is healthy
       
    89 	TInt r=(thread.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    90 	CleanupStack::PopAndDestroy(&thread); //only this handle
       
    91 	User::LeaveIfError(r);
       
    92 
       
    93 	iShutdownInitiated.UniversalTime();
       
    94 	INFO_PRINTF1( _L("Attempt to start the failing Test Application will cause an OS Restart") );
       
    95 	INFO_PRINTF4( _L("StartL called at time %d:%d.%d"), iShutdownInitiated.DateTime().Minute(), iShutdownInitiated.DateTime().Second(), iShutdownInitiated.DateTime().MicroSecond());
       
    96 	INFO_PRINTF1(_L("Starting scheduler"));
       
    97 	CActiveScheduler::Start(); //Wait for MSaveObserver callback
       
    98 		
       
    99 	//resume here after callback has stopped the scheduler
       
   100 	INFO_PRINTF2( _L("Asserting that the shutdown was at all initiated: %d"), iCallbackReceived );
       
   101 	TESTE(iCallbackReceived, iCallbackReceived);
       
   102 	
       
   103 	//assert the thread calling StartL is still blocked
       
   104 	TESTE(KErrNone == iStartSafeError, iStartSafeError);
       
   105 	
       
   106 	if(iCallbackReceived)
       
   107 		{
       
   108 		const TTimeIntervalMicroSeconds elapsedTime = iShutdownPerformed.MicroSecondsFrom(iShutdownInitiated);
       
   109 		const TDateTime dt = iShutdownPerformed.DateTime();
       
   110 		const TInt64 value = elapsedTime.Int64();
       
   111 		INFO_PRINTF5(_L("Shutdown callback received at time %d:%d.%d (after %d microseconds)"), dt.Minute(), dt.Second(), dt.MicroSecond(), value);
       
   112 		TESTE((value >= 0) && (value < 1000000), value); // within 1 second	
       
   113 		
       
   114 		// Now call CPowerdownClient::QueryServerPowerState() which will in turn call the method 'ServerPowerState()'
       
   115 		// to stop the shutdown. This function call will cause the shutdown server in syslibs/pwrcli to cancel power off.
       
   116 		INFO_PRINTF1(_L("Aborting shutdown sequence"));
       
   117 		TBool powerOff = EFalse;
       
   118 		CPowerdownClient* powerdownclient = CPowerdownClient::NewL();
       
   119 		CleanupStack::PushL(powerdownclient);
       
   120 		TEST(KErrNone == powerdownclient->QueryServerPowerState(iNotifier,powerOff));
       
   121 		TEST(powerOff);
       
   122 		CleanupStack::PopAndDestroy(powerdownclient);
       
   123 		CleanupStack::PopAndDestroy(sched);	
       
   124 		}
       
   125 	else
       
   126 		{
       
   127 		TEST(EFalse);	
       
   128 		}
       
   129 	
       
   130 	return TestStepResult();	
       
   131 	}
       
   132 
       
   133 
       
   134 
       
   135 void CAppFwkStartSafeTestStepProcFailSysRestart::DoStartApplicationL()
       
   136 	{	
       
   137 	// warning: the Tef framework can't do logging from this thread
       
   138 	CStartSafe* startSafe = CStartSafe::NewL();	
       
   139 	CleanupStack::PushL( startSafe );
       
   140 	
       
   141 	CStartupProperties* prop = CStartupProperties::NewLC(KTestAppNoRv, KNullDesC);
       
   142 	prop->SetStartupType( EStartApp );
       
   143 	prop->SetStartMethod( EWaitForStart );
       
   144 	prop->SetTimeout( 1 );
       
   145 	prop->SetNoOfRetries( 0 );
       
   146 	prop->SetRecoveryParams( ERestartOS, 0 );
       
   147 	
       
   148 	TInt tried = 0;
       
   149 	RProcess proc;
       
   150 	// We are expecting StartL to leave because KTestAppNoRv will fail to start, so any items 
       
   151 	// on the CleanupStack would be deleted/closed on this call. 
       
   152 	CleanupStack::Pop(2, startSafe);
       
   153 	RThread::Rendezvous(KErrNone);
       
   154 	TRAP( iStartSafeError, startSafe->StartL(*prop, proc, tried) ); // Will initiate ERestartOS and then freeze this thread for 5 seconds	
       
   155 	
       
   156 	proc.Close();
       
   157 	delete prop;
       
   158 	delete startSafe;
       
   159 	}
       
   160 	
       
   161 /**
       
   162 Called by the shutdown server in syslib/pwrcli when device is initiating a shut down.
       
   163 */
       
   164 void CAppFwkStartSafeTestStepProcFailSysRestart::SaveL(TSaveType /*aSaveType*/)
       
   165 	{
       
   166 	// Do assertions in the doTestStepL function, just save values for now
       
   167 	iCallbackReceived = ETrue;
       
   168 	iShutdownPerformed.UniversalTime();	
       
   169 
       
   170 	iNotifier->DelayRequeue();
       
   171 	CActiveScheduler::Stop();
       
   172 	}