|
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 <sysmonclisess.h> |
|
23 #include <startupproperties.h> |
|
24 #include <ssm/ssmstartupproperties.h> |
|
25 #include "testapps.h" |
|
26 #include "tsysmon_stepnoprocmon.h" |
|
27 |
|
28 |
|
29 CStepNoProcMon::CStepNoProcMon() |
|
30 { |
|
31 SetTestStepName(KCTestCaseNoProcMon); |
|
32 } |
|
33 |
|
34 TVerdict CStepNoProcMon::doTestStepL() |
|
35 { |
|
36 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0007")); |
|
37 |
|
38 TRAPD(err, DoTestNullHandleL()); |
|
39 TEST(err == KErrNone); |
|
40 |
|
41 TRAP(err, DoTestKilledHandleL()); |
|
42 TEST(err == KErrNone); |
|
43 |
|
44 TRAP(err, DoTestWrongHandleL()); |
|
45 TEST(err == KErrNone); |
|
46 |
|
47 TRAP(err, DoTestProcMonErrorsL()); |
|
48 TEST(err == KErrNone); |
|
49 |
|
50 return TestStepResult(); |
|
51 } |
|
52 /** |
|
53 Old Test CaseID APPFWK-SYSMON-0007 |
|
54 New Test CaseID DEVSRVS-SHMA-SYSMON-0007 |
|
55 */ |
|
56 |
|
57 void CStepNoProcMon::DoTestNullHandleL() |
|
58 { |
|
59 INFO_PRINTF1(_L("Requesting SysMon to monitor a process NULL handle using startupproperties")); |
|
60 |
|
61 RProcess process; |
|
62 process.Close(); |
|
63 |
|
64 RSysMonSession sess; |
|
65 sess.OpenL(); |
|
66 CleanupClosePushL(sess); |
|
67 |
|
68 CStartupProperties *prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
69 prop->SetMonitored(ETrue); |
|
70 prop->SetStartMethod(EWaitForStart); |
|
71 prop->SetRecoveryParams(EIgnoreOnFailure, 0); |
|
72 prop->SetNoOfRetries(1); |
|
73 prop->SetTimeout(0); |
|
74 |
|
75 TRAPD(err, sess.MonitorL(*prop, process)); // check that passing in a null handle would return KErrArugment |
|
76 |
|
77 // check that the initiation of monitoring failed |
|
78 TESTE(KErrArgument == err, err); |
|
79 if(KErrArgument == err) |
|
80 { |
|
81 INFO_PRINTF1(_L("Request refused with KErrArgument")); |
|
82 } |
|
83 CleanupStack::PopAndDestroy(prop); |
|
84 |
|
85 INFO_PRINTF1(_L("Requesting SysMon to monitor a process NULL handle using ssmstartupproperties")); |
|
86 CSsmStartupProperties *ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
87 ssmProp->SetExecutionBehaviour(ESsmWaitForSignal); |
|
88 TSsmMonitorInfo monitorInfo; |
|
89 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
90 monitorInfo.iRestartMode = 0; |
|
91 monitorInfo.iTimeout = 0; |
|
92 monitorInfo.iRetries = 1; |
|
93 |
|
94 ssmProp->SetMonitorInfoL(monitorInfo);// SysMon will not do any restart attempts |
|
95 |
|
96 TRAP(err, sess.MonitorL(*ssmProp, process)); // check that passing in a null handle would return KErrArugment |
|
97 |
|
98 // check that the initiation of monitoring failed |
|
99 TESTE(KErrArgument == err, err); |
|
100 if(KErrArgument == err) |
|
101 { |
|
102 INFO_PRINTF1(_L("Request refused with KErrArgument")); |
|
103 } |
|
104 |
|
105 CleanupStack::PopAndDestroy(ssmProp); |
|
106 CleanupStack::PopAndDestroy(&sess); |
|
107 } |
|
108 |
|
109 /** |
|
110 Check that passing in a handle to a killed process will return KErrArugment |
|
111 */ |
|
112 void CStepNoProcMon::DoTestKilledHandleL() |
|
113 { |
|
114 INFO_PRINTF1(_L("Requesting SysMon to monitor a handle to a killed process using startupproperties")); |
|
115 |
|
116 RSysMonSession sess; |
|
117 sess.OpenL(); |
|
118 CleanupClosePushL(sess); |
|
119 |
|
120 RProcess process; |
|
121 CleanupClosePushL(process); |
|
122 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
123 ResumeL(process); |
|
124 |
|
125 process.Kill(KErrNone); |
|
126 INFO_PRINTF1(_L("Process killed.")); |
|
127 |
|
128 CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
129 prop->SetMonitored(ETrue); |
|
130 prop->SetStartMethod(EWaitForStart); |
|
131 prop->SetRecoveryParams(EIgnoreOnFailure, 0); |
|
132 prop->SetNoOfRetries(1); |
|
133 prop->SetTimeout(0); |
|
134 |
|
135 TRAPD(err, sess.MonitorL(*prop, process)); |
|
136 |
|
137 // check that the initiation of monitoring failed |
|
138 TESTE(KErrDied == err, err); |
|
139 if(KErrDied == err) |
|
140 { |
|
141 INFO_PRINTF1(_L("Request refused with KErrDied")); |
|
142 } |
|
143 |
|
144 CleanupStack::PopAndDestroy(prop); |
|
145 CleanupStack::Pop(&process); |
|
146 |
|
147 INFO_PRINTF1(_L("Requesting SysMon to monitor a handle to a killed process using ssmstartupproperties")); |
|
148 CleanupClosePushL(process); |
|
149 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
150 ResumeL(process); |
|
151 |
|
152 process.Kill(KErrNone); |
|
153 INFO_PRINTF1(_L("Process killed.")); |
|
154 |
|
155 CSsmStartupProperties *ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
156 ssmProp->SetExecutionBehaviour(ESsmWaitForSignal); |
|
157 TSsmMonitorInfo monitorInfo; |
|
158 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
159 monitorInfo.iRestartMode = 0; |
|
160 monitorInfo.iTimeout = 0; |
|
161 monitorInfo.iRetries = 1; |
|
162 |
|
163 ssmProp->SetMonitorInfoL(monitorInfo); // SysMon will not do any restart attempts |
|
164 |
|
165 TRAP(err, sess.MonitorL(*ssmProp, process)); |
|
166 |
|
167 // check that the initiation of monitoring failed |
|
168 TESTE(KErrDied == err, err); |
|
169 if(KErrDied == err) |
|
170 { |
|
171 INFO_PRINTF1(_L("Request refused with KErrDied")); |
|
172 } |
|
173 |
|
174 CleanupStack::PopAndDestroy(ssmProp); |
|
175 CleanupStack::PopAndDestroy(&process); |
|
176 CleanupStack::PopAndDestroy(&sess); |
|
177 } |
|
178 |
|
179 void CStepNoProcMon::DoTestWrongHandleL() |
|
180 { |
|
181 INFO_PRINTF1(_L("Requesting SysMon to monitor wrong process handle using startupproperties")); |
|
182 |
|
183 RProcess process; // initiated with handle to current process |
|
184 |
|
185 RSysMonSession sess; |
|
186 sess.OpenL(); |
|
187 CleanupClosePushL(sess); |
|
188 |
|
189 CStartupProperties *prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
190 prop->SetMonitored(ETrue); |
|
191 prop->SetStartMethod(EWaitForStart); |
|
192 prop->SetRecoveryParams(EIgnoreOnFailure, 0); |
|
193 prop->SetNoOfRetries(1); |
|
194 prop->SetTimeout(0); |
|
195 |
|
196 TRAPD(err, sess.MonitorL(*prop, process)); // check that passing in a null handle would return KErrArugment |
|
197 |
|
198 // check that the initiation of monitoring failed |
|
199 TESTE(KErrArgument == err, err); |
|
200 if(KErrArgument == err) |
|
201 { |
|
202 INFO_PRINTF1(_L("Request refused with KErrArgument")); |
|
203 } |
|
204 |
|
205 CleanupStack::PopAndDestroy(prop); |
|
206 |
|
207 INFO_PRINTF1(_L("Requesting SysMon to monitor wrong process handle using ssmstartupproperties")); |
|
208 CSsmStartupProperties *ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
209 ssmProp->SetExecutionBehaviour(ESsmWaitForSignal); |
|
210 TSsmMonitorInfo monitorInfo; |
|
211 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
212 monitorInfo.iRestartMode = 0; |
|
213 monitorInfo.iTimeout = 0; |
|
214 monitorInfo.iRetries = 1; |
|
215 |
|
216 ssmProp->SetMonitorInfoL(monitorInfo);// SysMon will not do any restart attempts |
|
217 |
|
218 TRAP(err, sess.MonitorL(*ssmProp, process)); // check that passing in a null handle would return KErrArugment |
|
219 |
|
220 // check that the initiation of monitoring failed |
|
221 TESTE(KErrArgument == err, err); |
|
222 if(KErrArgument == err) |
|
223 { |
|
224 INFO_PRINTF1(_L("Request refused with KErrArgument")); |
|
225 } |
|
226 |
|
227 CleanupStack::PopAndDestroy(ssmProp); |
|
228 CleanupStack::PopAndDestroy(&sess); |
|
229 } |
|
230 |
|
231 void CStepNoProcMon::DoTestProcMonErrorsL() |
|
232 { |
|
233 INFO_PRINTF1(_L("Testin SysMon in different error conditions")); |
|
234 RProcess process; |
|
235 CleanupClosePushL(process); |
|
236 |
|
237 INFO_PRINTF1(_L("Going start a process")); |
|
238 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
239 ResumeL(process); |
|
240 |
|
241 //Setup monitoring |
|
242 INFO_PRINTF1(_L("Going to request process monitoring")); |
|
243 RSysMonSession sess; |
|
244 sess.OpenL(); |
|
245 CleanupClosePushL(sess); |
|
246 |
|
247 CSsmStartupProperties* prop = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
248 TSsmMonitorInfo monitorInfo; |
|
249 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
250 monitorInfo.iRestartMode = 0; |
|
251 monitorInfo.iTimeout = 0; |
|
252 monitorInfo.iRetries = 1; |
|
253 prop->SetMonitorInfoL(monitorInfo); |
|
254 prop->SetFileParamsL(KNullDesC,KNullDesC); |
|
255 prop->SetCommandTypeL(ESsmCmdStartApp); |
|
256 |
|
257 INFO_PRINTF1(_L("Going to request process monitoring with NULL filename type")); |
|
258 TRAPD(err, sess.MonitorL(*prop, process)); |
|
259 TEST(err == KErrArgument); |
|
260 INFO_PRINTF3(_L("Actual return value for NULL filename %d, Expected return value %d"), err, KErrArgument); |
|
261 |
|
262 prop->Reset(); |
|
263 prop->SetFileParamsL(KNullDesC,KNullDesC); |
|
264 prop->SetCommandTypeL(ESsmCmdStartApp); |
|
265 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
266 monitorInfo.iRestartMode = 0; |
|
267 monitorInfo.iTimeout = 0; |
|
268 monitorInfo.iRetries = -12; |
|
269 prop->SetMonitorInfoL(monitorInfo); |
|
270 |
|
271 CleanupStack::Pop(prop); |
|
272 CleanupStack::PushL(prop); |
|
273 |
|
274 INFO_PRINTF1(_L("Going to request process monitoring with -ve retries for WaitForStart execution behaviour")); |
|
275 TRAP(err, sess.MonitorL(*prop, process)); |
|
276 TEST(err == KErrArgument); |
|
277 INFO_PRINTF3(_L("Actual return value for -ve retries for WaitForStart execution behaviour %d, Expected return value %d"), err, KErrArgument); |
|
278 |
|
279 prop->Reset(); |
|
280 prop->SetFileParamsL(KNullDesC,KNullDesC); |
|
281 prop->SetCommandTypeL(ESsmCmdStartProcess); |
|
282 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
283 monitorInfo.iRestartMode = 0; |
|
284 monitorInfo.iTimeout = -100; |
|
285 monitorInfo.iRetries = 1; |
|
286 prop->SetMonitorInfoL(monitorInfo); |
|
287 |
|
288 CleanupStack::Pop(prop); |
|
289 CleanupStack::PushL(prop); |
|
290 |
|
291 INFO_PRINTF1(_L("Going to request process monitoring with -ve timeout for WaitForStart execution behaviour")); |
|
292 TRAP(err, sess.MonitorL(*prop, process)); |
|
293 TEST(err == KErrArgument); |
|
294 INFO_PRINTF3(_L("Actual return value for -ve timeout for WaitForStart execution behaviour %d, Expected return value %d"), err, KErrArgument); |
|
295 |
|
296 prop->Reset(); |
|
297 prop->SetFileParamsL(KNullDesC,KNullDesC); |
|
298 prop->SetCommandTypeL(ESsmCmdStartProcess); |
|
299 monitorInfo.iRestartPolicy = (static_cast <TSsmRecoveryMethod>(100)); |
|
300 monitorInfo.iRestartMode = 0; |
|
301 monitorInfo.iTimeout = -100; |
|
302 monitorInfo.iRetries = 1; |
|
303 prop->SetMonitorInfoL(monitorInfo); |
|
304 |
|
305 CleanupStack::Pop(prop); |
|
306 CleanupStack::PushL(prop); |
|
307 |
|
308 INFO_PRINTF1(_L("Going to request process monitoring with invalid recoverymethod for WaitForStart execution behaviour")); |
|
309 TRAP(err, sess.MonitorL(*prop, process)); |
|
310 TEST(err == KErrArgument); |
|
311 INFO_PRINTF3(_L("Actual return value for invalid recoverymethod for WaitForStart execution behaviour %d, Expected return value %d"), err, KErrArgument); |
|
312 |
|
313 CStartupProperties* prop1 = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
314 prop1->SetStartupType(static_cast<TStartupType>(10)); |
|
315 prop1->SetMonitored(ETrue); |
|
316 prop1->SetStartMethod(EWaitForStart); |
|
317 prop1->SetRecoveryParams(EIgnoreOnFailure, 0); |
|
318 prop1->SetNoOfRetries(1); |
|
319 prop1->SetTimeout(0); |
|
320 |
|
321 INFO_PRINTF1(_L("Going to request process monitoring with invalid startuptype")); |
|
322 TRAP(err, sess.MonitorL(*prop, process)); |
|
323 TEST(err == KErrArgument); |
|
324 INFO_PRINTF3(_L("Actual return value for invalid startuptype %d, Expected return value %d"), err, KErrArgument); |
|
325 |
|
326 process.Kill(KErrNone); |
|
327 CleanupStack::PopAndDestroy(4, &process); |
|
328 INFO_PRINTF1(_L("Test step complete")); |
|
329 } |
|
330 |
|
331 |