|
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_stepprocmoninit.h" |
|
27 |
|
28 |
|
29 CStepProcMonInit::CStepProcMonInit() |
|
30 { |
|
31 SetTestStepName(KCTestCaseProcMonInit); |
|
32 } |
|
33 |
|
34 TVerdict CStepProcMonInit::doTestStepL() |
|
35 { |
|
36 DoTestProcL(); |
|
37 DoTestAppL(); |
|
38 DoTestErrArgumentL(); |
|
39 return TestStepResult(); |
|
40 } |
|
41 |
|
42 /** |
|
43 Old Test CaseID APPFWK-SYSMON-0001 |
|
44 New Test CaseID DEVSRVS-SHMA-SYSMON-0001 |
|
45 */ |
|
46 |
|
47 void CStepProcMonInit::DoTestProcL() |
|
48 { |
|
49 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001A")); |
|
50 INFO_PRINTF1(_L("Going to set a process running")); |
|
51 |
|
52 RProcess process; |
|
53 CleanupClosePushL(process); |
|
54 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
55 ResumeL(process); |
|
56 |
|
57 INFO_PRINTF1(_L("Going to request process monitoring using startupproperties")); |
|
58 DoTestMonitorL(process, KTestProcGood, 0); // The test using startupproperties |
|
59 |
|
60 process.Kill(KErrNone); |
|
61 CleanupStack::Pop(&process); |
|
62 |
|
63 CleanupClosePushL(process); |
|
64 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
65 ResumeL(process); |
|
66 |
|
67 INFO_PRINTF1(_L("Going to request process monitoring using ssmstartupproperties")); |
|
68 DoTestMonitorL(process, KTestProcGood, 1); // The test using ssmstartupproperties |
|
69 |
|
70 process.Kill(KErrNone); |
|
71 CleanupStack::PopAndDestroy(&process); |
|
72 } |
|
73 |
|
74 /** |
|
75 Bonus-test APPFWK-SYSMON-0001b using an application instead of a process |
|
76 */ |
|
77 void CStepProcMonInit::DoTestAppL() |
|
78 { |
|
79 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001B")); |
|
80 |
|
81 // Launch native application using an unconnected RApaLsSession |
|
82 INFO_PRINTF1(_L("Going to set a native application running")); |
|
83 TThreadId threadId; |
|
84 TRequestStatus requestStatus; |
|
85 StartViewlessBgApplicationL(KTestAppGood, threadId, requestStatus); |
|
86 |
|
87 // Test that the application was created, then wait for it to resume |
|
88 RThread thread; |
|
89 RProcess process; |
|
90 CleanupClosePushL(thread); |
|
91 CleanupClosePushL(process); |
|
92 TEST(KErrNone == thread.Open(threadId)); |
|
93 TEST(KErrNone == thread.Process(process)); |
|
94 User::WaitForRequest(requestStatus); |
|
95 |
|
96 INFO_PRINTF1(_L("Going to request process monitoring using startupproperties")); |
|
97 // Do the actual testing |
|
98 DoTestMonitorL(process, KTestAppGood, 0); // test using startupproperties |
|
99 |
|
100 // Cleanup |
|
101 process.Kill(KErrNone); |
|
102 |
|
103 StartViewlessBgApplicationL(KTestAppGood, threadId, requestStatus); |
|
104 CleanupStack::Pop(&process); |
|
105 CleanupStack::Pop(&thread); |
|
106 |
|
107 CleanupClosePushL(thread); |
|
108 CleanupClosePushL(process); |
|
109 TEST(KErrNone == thread.Open(threadId)); |
|
110 TEST(KErrNone == thread.Process(process)); |
|
111 User::WaitForRequest(requestStatus); |
|
112 |
|
113 INFO_PRINTF1(_L("Going to request process monitoring using ssmstartupproperties")); |
|
114 // Do the actual testing |
|
115 DoTestMonitorL(process, KTestAppGood, 1); // test using ssmstartupproperties |
|
116 |
|
117 // Cleanup |
|
118 process.Kill(KErrNone); |
|
119 CleanupStack::PopAndDestroy(&process); |
|
120 CleanupStack::PopAndDestroy(&thread); |
|
121 } |
|
122 |
|
123 /** |
|
124 * Calls RSysMonSession::MonitorL twice. the first call is expected to succeed and the second call |
|
125 * returns KErrNone in release builds, whereas panics in debug builds |
|
126 */ |
|
127 void CStepProcMonInit::DoTestMonitorL(const RProcess& aProcess, const TDesC& aFilename, const TInt aStartUpPropType) |
|
128 { |
|
129 RSysMonSession sess; |
|
130 sess.OpenL(); |
|
131 CleanupClosePushL(sess); |
|
132 |
|
133 if (aStartUpPropType) |
|
134 { |
|
135 CSsmStartupProperties* prop = CSsmStartupProperties::NewLC(aFilename, KNullDesC); |
|
136 // Testing consistency assertion of aStartupProperties in RSysMonSession::MonitorL |
|
137 TRAPD(err, sess.MonitorL(*prop, aProcess)); |
|
138 TESTE(err == KErrArgument, err); |
|
139 if(err == KErrArgument) |
|
140 { |
|
141 INFO_PRINTF1(_L("Monitor request with invalid args was refused properly by RSysMonSession::MonitorL using ssmstartupproperties")); |
|
142 } |
|
143 |
|
144 prop->SetExecutionBehaviour(ESsmWaitForSignal); |
|
145 TSsmMonitorInfo monitorInfo; |
|
146 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
147 monitorInfo.iRestartMode = 0; |
|
148 monitorInfo.iTimeout = 0; |
|
149 monitorInfo.iRetries = 0; |
|
150 prop->SetMonitorInfoL(monitorInfo); // SysMon will not do any restart attempts |
|
151 |
|
152 // monitoring first time should succeed |
|
153 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
154 TESTEL(err == KErrNone, err); |
|
155 INFO_PRINTF1(_L("First monitor request succeeded")); |
|
156 |
|
157 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
158 TESTE(err == KErrAlreadyExists, err); |
|
159 if(err == KErrAlreadyExists) |
|
160 { |
|
161 INFO_PRINTF1(_L("Second monitor request returned KErrAlreadyExists as expected")); |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy(prop); |
|
165 } |
|
166 else |
|
167 { |
|
168 CStartupProperties* prop = CStartupProperties::NewLC(aFilename, KNullDesC); |
|
169 // Testing consistency assertion of aStartupProperties in RSysMonSession::MonitorL |
|
170 TRAPD(err, sess.MonitorL(*prop, aProcess)); |
|
171 TESTE(err == KErrArgument, err); |
|
172 if(err == KErrArgument) |
|
173 { |
|
174 INFO_PRINTF1(_L("Monitor request with invalid args was refused properly by RSysMonSession::MonitorL using startupproperties")); |
|
175 } |
|
176 |
|
177 prop->SetMonitored(ETrue); |
|
178 prop->SetNoOfRetries(0); // SysMon will not do any restart attempts |
|
179 |
|
180 // monitoring first time should succeed |
|
181 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
182 TESTEL(err == KErrNone, err); |
|
183 INFO_PRINTF1(_L("First monitor request succeeded")); |
|
184 |
|
185 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
186 TESTE(err == KErrAlreadyExists, err); |
|
187 if(err == KErrAlreadyExists) |
|
188 { |
|
189 INFO_PRINTF1(_L("Second monitor request returned KErrAlreadyExists as expected")); |
|
190 } |
|
191 |
|
192 CleanupStack::PopAndDestroy(prop); |
|
193 } |
|
194 CleanupStack::PopAndDestroy(&sess); |
|
195 } |
|
196 |
|
197 |
|
198 /* |
|
199 Bonus-test APPFWK-SYSMON-0001C |
|
200 Testing consistency of assertions in RSysMonSession::MonitorL |
|
201 */ |
|
202 void CStepProcMonInit::DoTestErrArgumentL() |
|
203 { |
|
204 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001C - validade that sysmon refuse invalid requests")); |
|
205 |
|
206 RProcess process; |
|
207 CleanupClosePushL(process); |
|
208 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
209 ResumeL(process); |
|
210 |
|
211 RSysMonSession sess; |
|
212 sess.OpenL(); |
|
213 CleanupClosePushL(sess); |
|
214 CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
215 CSsmStartupProperties* ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
216 |
|
217 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::Monitor()==EFalse using startupproperties")); |
|
218 TRAPD(err, sess.MonitorL(*prop, process)); |
|
219 TESTE(err == KErrArgument, err); |
|
220 |
|
221 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::Monitor()==EFalse using ssmstartupproperties")); |
|
222 TRAP(err, sess.MonitorL(*ssmProp, process)); |
|
223 TESTE(err == KErrArgument, err); |
|
224 |
|
225 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::StartMethod==EDeferredWaitForStart using startupproperties")); |
|
226 prop->SetStartMethod(EDeferredWaitForStart); |
|
227 prop->SetNoOfRetries(0); |
|
228 TRAP(err, sess.MonitorL(*prop, process)); |
|
229 TESTE(err == KErrArgument, err); |
|
230 |
|
231 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::StartMethod==ESsmDeferredWaitForSignal using ssmstartupproperties")); |
|
232 ssmProp->SetExecutionBehaviour(ESsmDeferredWaitForSignal); |
|
233 TSsmMonitorInfo monitorInfo; |
|
234 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
235 monitorInfo.iRestartMode = 0; |
|
236 monitorInfo.iTimeout = 0; |
|
237 monitorInfo.iRetries = 0; |
|
238 ssmProp->SetMonitorInfoL(monitorInfo); |
|
239 TRAP(err, sess.MonitorL(*ssmProp, process)); |
|
240 TESTE(err == KErrArgument, err); |
|
241 |
|
242 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to restart another exe image than the one it monitors using startupproperties.")); |
|
243 prop->SetStartMethod(EWaitForStart); |
|
244 prop->SetNoOfRetries(1); |
|
245 prop->SetFileParamsL(_L("sdkjfhsdk"), KNullDesC); |
|
246 TRAP(err, sess.MonitorL(*prop, process)); |
|
247 TESTE(err == KErrArgument, err); |
|
248 |
|
249 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to restart another exe image than the one it monitors using ssmsstartupproperties.")); |
|
250 ssmProp->SetExecutionBehaviour(ESsmWaitForSignal); |
|
251 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
252 monitorInfo.iRestartMode = 0; |
|
253 monitorInfo.iTimeout = 0; |
|
254 monitorInfo.iRetries = 1; |
|
255 ssmProp->SetMonitorInfoL(monitorInfo); |
|
256 ssmProp->SetFileParamsL(_L("sdkjfhsdk"), KNullDesC); |
|
257 TRAP(err, sess.MonitorL(*ssmProp, process)); |
|
258 TESTE(err == KErrArgument, err); |
|
259 |
|
260 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to monitor a dead process using startupproperties.")); |
|
261 prop->SetFileParamsL(KTestProcGood, KNullDesC); |
|
262 prop->SetStartMethod(EWaitForStart); |
|
263 prop->SetMonitored(ETrue); |
|
264 prop->SetNoOfRetries(1); |
|
265 process.Kill(KErrNone); |
|
266 TRAP(err, sess.MonitorL(*prop, process)); |
|
267 TESTE(err == KErrDied, err); |
|
268 |
|
269 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to monitor a dead process using ssmstartupproperties.")); |
|
270 ssmProp->SetFileParamsL(KTestProcGood, KNullDesC); |
|
271 TRAP(err, sess.MonitorL(*ssmProp, process)); |
|
272 TESTE(err == KErrDied, err); |
|
273 |
|
274 CleanupStack::PopAndDestroy(ssmProp); |
|
275 CleanupStack::PopAndDestroy(prop); |
|
276 CleanupStack::PopAndDestroy(&sess); |
|
277 CleanupStack::PopAndDestroy(&process); |
|
278 } |