|
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 "testprocgoodsession.h" |
|
27 #include "tstartsafe_procmonsysrestart.h" |
|
28 #include "tpowerdownclient.h" |
|
29 |
|
30 |
|
31 CAppFwkStartSafeTestStepProcMonSysRestart::CAppFwkStartSafeTestStepProcMonSysRestart() |
|
32 { |
|
33 SetTestStepName(KCTestCaseProcMonSysRestart); |
|
34 } |
|
35 |
|
36 CAppFwkStartSafeTestStepProcMonSysRestart::~CAppFwkStartSafeTestStepProcMonSysRestart() |
|
37 { |
|
38 delete iNotifier; |
|
39 } |
|
40 |
|
41 /** |
|
42 Old Test CaseID APPFWK-STARTSAFE-0014 |
|
43 New Test CaseID DEVSRVS-SYSSTART-STARTSAFE-0014 |
|
44 */ |
|
45 |
|
46 TVerdict CAppFwkStartSafeTestStepProcMonSysRestart::doTestStepL() |
|
47 { |
|
48 |
|
49 #ifdef __WINSCW__ |
|
50 ASSERT(0); |
|
51 #endif |
|
52 |
|
53 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
54 CleanupStack::PushL(sched); |
|
55 CActiveScheduler::Install(sched); |
|
56 |
|
57 iNotifier = CSaveNotifier::NewL(*this); |
|
58 |
|
59 CStartSafe* startSafe = CStartSafe::NewL(); |
|
60 CleanupStack::PushL( startSafe ); |
|
61 |
|
62 CStartupProperties* prop = CStartupProperties::NewLC(); |
|
63 prop->SetFileParamsL(KTestProcGood, KNullDesC); |
|
64 prop->SetStartMethod(EWaitForStart); |
|
65 prop->SetMonitored(ETrue); |
|
66 prop->SetRecoveryParams(ERestartOS, 0); |
|
67 |
|
68 TInt tried; |
|
69 RProcess proc; |
|
70 CleanupClosePushL(proc); |
|
71 TRAPD(err, startSafe->StartAndMonitorL(*prop, proc, tried)); |
|
72 TEST(KErrNone == err); |
|
73 CleanupStack::Pop(&proc); |
|
74 CleanupStack::PopAndDestroy(prop); |
|
75 CleanupStack::PopAndDestroy(startSafe); |
|
76 INFO_PRINTF1(_L("Process monitoring setup with TRecoveryMethod=ERestartOS")); |
|
77 |
|
78 proc.Kill(KErrNone); |
|
79 proc.Close(); |
|
80 |
|
81 TTime init; |
|
82 init.UniversalTime(); |
|
83 INFO_PRINTF4( _L("Process killed at time %d:%d.%d"), init.DateTime().Minute(), init.DateTime().Second(), init.DateTime().MicroSecond()); |
|
84 INFO_PRINTF1(_L("Starting scheduler (expecting an OS restart)")); |
|
85 CActiveScheduler::Start(); //Wait for MSaveObserver callback |
|
86 |
|
87 //resume here after callback has stopped the scheduler |
|
88 TESTE(iCallbackReceived, iCallbackReceived); |
|
89 if(iCallbackReceived) |
|
90 { |
|
91 const TTimeIntervalMicroSeconds elapsedTime = iShutdownPerformed.MicroSecondsFrom(init); |
|
92 const TDateTime dt = iShutdownPerformed.DateTime(); |
|
93 const TInt64 value = elapsedTime.Int64(); |
|
94 INFO_PRINTF5(_L("Shutdown callback received at time %d:%d.%d (after %d microseconds)"), dt.Minute(), dt.Second(), dt.MicroSecond(), value); |
|
95 TESTE((value >= 0) && (value < 1000000), value); // within 1 second |
|
96 } |
|
97 else |
|
98 { |
|
99 INFO_PRINTF1( _L("Restart didn't take place :-(")); |
|
100 TEST(EFalse); |
|
101 } |
|
102 |
|
103 // Now call CPowerdownClient::QueryServerPowerState() which will in turn call the method 'ServerPowerState()' |
|
104 // to stop the shutdown. This function call will cause the shutdown server in syslibs/pwrcli to cancel power off. |
|
105 INFO_PRINTF1(_L("Aborting shutdown.")); |
|
106 TBool powerOff = EFalse; |
|
107 CPowerdownClient* powerdownclient = CPowerdownClient::NewL(); |
|
108 CleanupStack::PushL(powerdownclient); |
|
109 TEST(KErrNone == powerdownclient->QueryServerPowerState(iNotifier,powerOff)); |
|
110 TEST(powerOff); |
|
111 CleanupStack::PopAndDestroy(powerdownclient); |
|
112 |
|
113 CleanupStack::PopAndDestroy(sched); |
|
114 return TestStepResult(); |
|
115 } |
|
116 |
|
117 void CAppFwkStartSafeTestStepProcMonSysRestart::SaveL(TSaveType /*aSaveType*/) |
|
118 { |
|
119 INFO_PRINTF1(_L("Callback arrived")); |
|
120 |
|
121 // Do assertions in the doTestStepL function, just save values for now |
|
122 iCallbackReceived = ETrue; |
|
123 iShutdownPerformed.UniversalTime(); |
|
124 |
|
125 iNotifier->DelayRequeue(); |
|
126 |
|
127 CActiveScheduler::Stop(); //resume doTestStepL |
|
128 } |
|
129 |