|
1 // Copyright (c) 2010 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_steposrestarttest.h" |
|
24 #include <ssm/ssmstate.h> |
|
25 #include <ssm/ssmdomaindefs.h> |
|
26 #include <ssm/ssmstateawaresession.h> |
|
27 #include <sysmonclisess.h> |
|
28 #include <startupproperties.h> |
|
29 #include <e32cmn.h> |
|
30 #include <f32file.h> |
|
31 |
|
32 _LIT(KSysMonDontRendezvousRunCountFile, "C:\\testdata\\runcounts\\tsysmon_app_dontrendezvous.exe"); |
|
33 |
|
34 CStepOSRestart::CStepOSRestart(const TDesC& aTestName): iTestName(aTestName) |
|
35 { |
|
36 if (aTestName == KCTestCaseCriticalNoRetries) |
|
37 SetTestStepName(KCTestCaseCriticalNoRetriesStep); |
|
38 else if (aTestName == KCTestCaseRestartOS) |
|
39 SetTestStepName(KCTestCaseRestartOSStep); |
|
40 else |
|
41 { |
|
42 // If the test script is none of the above then we would fail the test |
|
43 TEST(KErrArgument); |
|
44 } |
|
45 } |
|
46 |
|
47 CStepOSRestart::~CStepOSRestart() |
|
48 { |
|
49 iSsmStateAwareSess.Close(); |
|
50 if (iAsyncCallbackForStartTest) |
|
51 delete iAsyncCallbackForStartTest; |
|
52 if(iAsyncCallbackForStopScheduler) |
|
53 delete iAsyncCallbackForStopScheduler; |
|
54 } |
|
55 |
|
56 void CStepOSRestart::StateChanged(TSsmState aSsmState) |
|
57 { |
|
58 |
|
59 } |
|
60 void CStepOSRestart::CallStopSchedulerL() |
|
61 { |
|
62 TSsmState currenState; |
|
63 currenState = iSsmStateAwareSess.State(); |
|
64 |
|
65 TUint16 currentMainState = currenState.MainState(); |
|
66 // Active scheduler is stopped once the system goes into shutdown state, else it issues a request for callback again |
|
67 // Once the system gets into normal state start the state transition test |
|
68 if (currentMainState == ESsmFail || currentMainState == ESsmShutdown) |
|
69 { |
|
70 RDebug::Print(_L("\nStateTran Test: Stop Active Scheduler\n")); |
|
71 TInt runCount = CSysMonTestHelper::ReadRunCountL(KSysMonDontRendezvousRunCountFile); |
|
72 if((iTestName == KCTestCaseCriticalNoRetries) && (1 != runCount)) |
|
73 SetTestStepResult(EFail); |
|
74 else if((iTestName == KCTestCaseRestartOS) && (2 != runCount)) |
|
75 SetTestStepResult(EFail); |
|
76 CActiveScheduler::Stop(); |
|
77 } |
|
78 else |
|
79 { |
|
80 iAsyncCallbackForStopScheduler->CallBack(); |
|
81 } |
|
82 } |
|
83 |
|
84 static TInt StopScheduler(TAny* aStateTranFromNormal) |
|
85 { |
|
86 CStepOSRestart* stateTran = reinterpret_cast<CStepOSRestart*>(aStateTranFromNormal); |
|
87 TRAPD(err,stateTran->CallStopSchedulerL()); |
|
88 return err; |
|
89 } |
|
90 |
|
91 |
|
92 TVerdict CStepOSRestart::doTestStepL() |
|
93 { |
|
94 TInt err =0; |
|
95 if (iTestName == KCTestCaseCriticalNoRetries) |
|
96 { |
|
97 TRAP(err, TestCriticalNoRetriesL()); |
|
98 } |
|
99 else if (iTestName == KCTestCaseRestartOS) |
|
100 { |
|
101 TRAP(err, TestRestartOSL()); |
|
102 } |
|
103 TEST(KErrNone == err); |
|
104 return TestStepResult(); |
|
105 } |
|
106 |
|
107 void CStepOSRestart::TestCriticalNoRetriesL() |
|
108 { |
|
109 CActiveScheduler* sched=new(ELeave) CActiveScheduler; |
|
110 CleanupStack::PushL(sched); |
|
111 CActiveScheduler::Install(sched); |
|
112 |
|
113 RSysMonSession sysmon; |
|
114 sysmon.OpenL(); |
|
115 CleanupClosePushL(sysmon); |
|
116 |
|
117 CStartupProperties* props = CStartupProperties::NewLC(_L("tsysmon_app_dontrendezvous.exe"), KNullDesC); |
|
118 props->SetMonitored(ETrue); |
|
119 props->SetStartupType(EStartProcess); |
|
120 props->SetStartMethod(EWaitForStart); |
|
121 props->SetNoOfRetries(1); |
|
122 props->SetTimeout(0); |
|
123 props->SetRecoveryParams(ECriticalNoRetries, 0); |
|
124 |
|
125 RProcess slave1; |
|
126 slave1.Create(_L("tsysmon_app_dontrendezvous.exe"), _L("5000")); |
|
127 CleanupClosePushL(slave1); |
|
128 |
|
129 TSsmState currenState; |
|
130 // Connects to RSsmStateAwareSession in order to enquire about the current system state |
|
131 TInt err = iSsmStateAwareSess.Connect(KSM2UiServicesDomain3); |
|
132 TEST(err == KErrNone); |
|
133 if (err == KErrNone) |
|
134 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect %d\n"), err); |
|
135 else |
|
136 { |
|
137 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect Failed\n")); |
|
138 User::Leave(err); |
|
139 } |
|
140 |
|
141 currenState = iSsmStateAwareSess.State(); |
|
142 |
|
143 RDebug::Print(_L("\nStateTran Test: Current System State is %d\n"), currenState.MainState()); |
|
144 TEST(currenState.MainState() == ESsmNormal); |
|
145 |
|
146 iAsyncCallbackForStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle); |
|
147 TCallBack stopSchedulerCallback(StopScheduler, this); |
|
148 iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback); |
|
149 |
|
150 // call the callback function which keeps looping until the system state gets into fail state. |
|
151 iAsyncCallbackForStopScheduler->CallBack(); |
|
152 |
|
153 // Notifier used to get the notification when system gets to fail state |
|
154 CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3); |
|
155 notif_for_failstate->AddSubscriberL(*this); |
|
156 |
|
157 TRequestStatus status; |
|
158 slave1.Rendezvous(status); |
|
159 slave1.Resume(); |
|
160 User::WaitForRequest(status); |
|
161 // Register with SysMon |
|
162 sysmon.MonitorL(*props, slave1); |
|
163 slave1.Terminate(KErrNone); |
|
164 |
|
165 sched->Start(); |
|
166 |
|
167 CleanupStack::PopAndDestroy(5); |
|
168 } |
|
169 |
|
170 void CStepOSRestart::TestRestartOSL() |
|
171 { |
|
172 CActiveScheduler* sched=new(ELeave) CActiveScheduler; |
|
173 CleanupStack::PushL(sched); |
|
174 CActiveScheduler::Install(sched); |
|
175 |
|
176 RSysMonSession sysmon; |
|
177 sysmon.OpenL(); |
|
178 CleanupClosePushL(sysmon); |
|
179 |
|
180 CStartupProperties* props = CStartupProperties::NewLC(_L("tsysmon_app_dontrendezvous.exe"), KNullDesC); |
|
181 props->SetMonitored(ETrue); |
|
182 props->SetStartupType(EStartProcess); |
|
183 props->SetStartMethod(EWaitForStart); |
|
184 props->SetNoOfRetries(1); |
|
185 props->SetTimeout(0); |
|
186 props->SetRecoveryParams(ERestartOS, 0); |
|
187 |
|
188 RProcess slave1; |
|
189 slave1.Create(_L("tsysmon_app_dontrendezvous.exe"), _L("5000")); |
|
190 CleanupClosePushL(slave1); |
|
191 |
|
192 TSsmState currenState; |
|
193 // Connects to RSsmStateAwareSession in order to enquire about the current system state |
|
194 TInt err = iSsmStateAwareSess.Connect(KSM2UiServicesDomain3); |
|
195 TEST(err == KErrNone); |
|
196 if (err == KErrNone) |
|
197 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect %d\n"), err); |
|
198 else |
|
199 { |
|
200 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect Failed\n")); |
|
201 User::Leave(err); |
|
202 } |
|
203 |
|
204 currenState = iSsmStateAwareSess.State(); |
|
205 |
|
206 RDebug::Print(_L("\nStateTran Test: Current System State is %d\n"), currenState.MainState()); |
|
207 TEST(currenState.MainState() == ESsmNormal); |
|
208 |
|
209 iAsyncCallbackForStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle); |
|
210 TCallBack stopSchedulerCallback(StopScheduler, this); |
|
211 iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback); |
|
212 |
|
213 // call the callback function which keeps looping until the system state gets into fail state. |
|
214 iAsyncCallbackForStopScheduler->CallBack(); |
|
215 |
|
216 // Notifier used to get the notification when system gets to fail state |
|
217 CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3); |
|
218 notif_for_failstate->AddSubscriberL(*this); |
|
219 |
|
220 TRequestStatus status; |
|
221 slave1.Rendezvous(status); |
|
222 slave1.Resume(); |
|
223 User::WaitForRequest(status); |
|
224 // Register with SysMon |
|
225 sysmon.MonitorL(*props, slave1); |
|
226 slave1.Terminate(KErrNone); |
|
227 |
|
228 sched->Start(); |
|
229 |
|
230 CleanupStack::PopAndDestroy(5); |
|
231 } |
|
232 |