|
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 // Old Test CaseID APPFWK-SSS-0002 |
|
15 // New Test CaseID DEVSRVS-SSMA-STARTSAFE-0002 |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 |
|
26 |
|
27 #include "tss_procstart.h" |
|
28 |
|
29 |
|
30 const TInt KProcStartStopperTimeout = 5000000; |
|
31 const TInt KWaitForActiveSchedStart = 500000; //0.5s |
|
32 |
|
33 /** |
|
34 From MSsTestAsyncNotifier |
|
35 */ |
|
36 void CSsTestStepProcStart::SsTestNotify( TInt aNotify ) |
|
37 { |
|
38 TEST( KErrNone == aNotify ); |
|
39 |
|
40 INFO_PRINTF2( _L("*** Start supplied code %d"), aNotify ); |
|
41 } |
|
42 |
|
43 |
|
44 |
|
45 TVerdict CSsTestStepProcStart::doTestStepL() |
|
46 { |
|
47 __UHEAP_MARK; |
|
48 TRAPD(err, DoTestFireAndForgetAsyncL()); |
|
49 TEST(err == KErrNone); |
|
50 INFO_PRINTF2(_L("DoTestFireAndForgetAsyncL completed with err = %d"), err); |
|
51 |
|
52 TRAP(err, DoTestWaitForStartAsyncL()); |
|
53 TEST(err == KErrNone); |
|
54 INFO_PRINTF2(_L("DoTestWaitForStartAsyncL completed with err = %d"), err); |
|
55 |
|
56 TRAP(err, DoTestFireAndForgetSyncL()); |
|
57 TEST(err == KErrNone); |
|
58 INFO_PRINTF2(_L("DoTestFireAndForgetSyncL completed with err = %d"), err); |
|
59 |
|
60 TRAP(err, DoTestWaitForStartSyncL()); |
|
61 TEST(err == KErrNone); |
|
62 INFO_PRINTF2(_L("DoTestWaitForStartSyncL completed with err = %d"), err); |
|
63 |
|
64 TRAP(err, DoTestForMonitorAlreadyMonProcL()); |
|
65 TEST(err == KErrNone); |
|
66 INFO_PRINTF2(_L("DoTestForMonitorAlreadyMonProcL completed with err = %d"), err); |
|
67 |
|
68 TRAP(err, DoTestStartTwoServersL()); |
|
69 TEST(err == KErrNone); |
|
70 INFO_PRINTF2(_L("DoTestStartTwoServersL completed with err = %d"), err); |
|
71 |
|
72 __UHEAP_MARKEND; |
|
73 return TestStepResult(); |
|
74 } |
|
75 |
|
76 |
|
77 /** |
|
78 Starts an instance of ssmtestappgood.exe asynchronously as a process using fire-and-forget. |
|
79 No timeout is specified, therefore CTimeoutWaiter is not instantiated. |
|
80 */ |
|
81 void CSsTestStepProcStart::DoTestFireAndForgetAsyncL() |
|
82 { |
|
83 INFO_PRINTF1( _L("\n\nPerforming Fire-and-forget async test") ); |
|
84 |
|
85 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
86 CleanupStack::PushL( startupProperties ); |
|
87 |
|
88 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
89 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
90 startupProperties->SetExecutionBehaviour( ESsmFireAndForget ); |
|
91 |
|
92 RProcess process; |
|
93 CleanupClosePushL( process ); |
|
94 TInt id = 0; |
|
95 |
|
96 CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout ); |
|
97 CleanupStack::PushL( stopper ); |
|
98 |
|
99 TRequestStatus& trs = stopper->Trs(); |
|
100 TInt stopperCompletion = KErrGeneral; |
|
101 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
102 |
|
103 ss->Start(*startupProperties, process, trs, id); |
|
104 //Process are started using fire-and-forget execution behaviour, |
|
105 //Start method always sets TRequestStatus to KRequestPending. |
|
106 if( KErrNone == trs.Int() ) |
|
107 { |
|
108 CActiveScheduler::Start(); |
|
109 |
|
110 stopperCompletion = stopper->CompletionCode(); |
|
111 INFO_PRINTF3( _L("TRS completed with %d. Anticipated value %d"), stopperCompletion, KErrNone ); |
|
112 } |
|
113 |
|
114 INFO_PRINTF3( _L("Start supplied %d. anticipated value %d"), trs.Int(), KErrNone ); |
|
115 |
|
116 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
117 |
|
118 TEST( KErrNone == stopperCompletion ); |
|
119 |
|
120 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
121 } |
|
122 |
|
123 |
|
124 |
|
125 const TInt KSsTestProcStartTimeout = 3000; // ms |
|
126 /** |
|
127 Starts an instance of ssmtestappgood.exe asynchronously as a process using wait-for-start. |
|
128 A timeout is specified, therefore CTimeoutWaiter is instantiated. |
|
129 */ |
|
130 void CSsTestStepProcStart::DoTestWaitForStartAsyncL() |
|
131 { |
|
132 INFO_PRINTF1( _L("\n\nPerforming Wait-for-start async test") ); |
|
133 |
|
134 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
135 CleanupStack::PushL( startupProperties ); |
|
136 |
|
137 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
138 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
139 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
140 startupProperties->SetRetries( 3 ); |
|
141 startupProperties->SetTimeout( KSsTestProcStartTimeout ); |
|
142 |
|
143 RProcess process; |
|
144 CleanupClosePushL( process ); |
|
145 TInt id = 0; |
|
146 |
|
147 CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout ); |
|
148 CleanupStack::PushL( stopper ); |
|
149 |
|
150 TRequestStatus& trs = stopper->Trs(); |
|
151 TInt stopperCompletion = KErrGeneral; |
|
152 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
153 |
|
154 ss->Start(*startupProperties, process, trs, id); |
|
155 //Process are started using Wait for start execution behaviour, |
|
156 //Start method always sets TRequestStatus to KRequestPending. |
|
157 if( KRequestPending == trs.Int() ) |
|
158 { |
|
159 CActiveScheduler::Start(); |
|
160 |
|
161 stopperCompletion = stopper->CompletionCode(); |
|
162 INFO_PRINTF3( _L("TRS completed with %d. Anticipated value %d"), stopperCompletion, KErrNone ); |
|
163 } |
|
164 |
|
165 INFO_PRINTF3( _L("Start supplied %d. anticipated value %d"), trs.Int(), KErrNone ); |
|
166 |
|
167 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
168 |
|
169 TEST( KErrNone == stopperCompletion ); |
|
170 |
|
171 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
172 } |
|
173 |
|
174 |
|
175 /** |
|
176 Starts an instance of ssmtestappgood.exe synchronously as a process using fire-and-forget. |
|
177 No timeout is specified, therefore CTimeoutWaiter is not instantiated. |
|
178 */ |
|
179 void CSsTestStepProcStart::DoTestFireAndForgetSyncL() |
|
180 { |
|
181 INFO_PRINTF1( _L("\n\nPerforming Fire-and-forget sync test") ); |
|
182 |
|
183 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
184 CleanupStack::PushL( startupProperties ); |
|
185 |
|
186 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
187 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
188 startupProperties->SetExecutionBehaviour( ESsmFireAndForget ); |
|
189 |
|
190 RProcess process; |
|
191 CleanupClosePushL( process ); |
|
192 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
193 |
|
194 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper( *ss, *startupProperties, process, KProcStartStopperTimeout, this ); |
|
195 CleanupStack::PushL( testAndStopper ); |
|
196 CActiveScheduler::Start(); |
|
197 |
|
198 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
199 |
|
200 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
201 } |
|
202 |
|
203 |
|
204 /** |
|
205 Starts an instance of ssmtestappgood.exe synchronously as a process using wait-for-start. |
|
206 A timeout is specified, therefore CTimeoutWaiter is instantiated. |
|
207 */ |
|
208 void CSsTestStepProcStart::DoTestWaitForStartSyncL() |
|
209 { |
|
210 INFO_PRINTF1( _L("\n\nPerforming Wait-for-start sync test") ); |
|
211 |
|
212 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
213 CleanupStack::PushL( startupProperties ); |
|
214 |
|
215 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
216 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
217 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
218 startupProperties->SetRetries( 3 ); |
|
219 startupProperties->SetTimeout( KSsTestProcStartTimeout ); |
|
220 |
|
221 RProcess process; |
|
222 CleanupClosePushL( process ); |
|
223 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
224 |
|
225 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper( *ss, *startupProperties, process, KProcStartStopperTimeout, this ); |
|
226 CleanupStack::PushL( testAndStopper ); |
|
227 CActiveScheduler::Start(); |
|
228 |
|
229 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
230 |
|
231 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
232 } |
|
233 |
|
234 |
|
235 |
|
236 /** |
|
237 Start ssmtestprocgood as a server. Attempt to start it a second time. |
|
238 Ensure that only one instance exists and SsmStartSafe has not reported any error. |
|
239 */ |
|
240 void CSsTestStepProcStart::DoTestStartTwoServersL() |
|
241 { |
|
242 INFO_PRINTF1( _L("\n\nPerforming Process-start as server. Ensure only one") ); |
|
243 |
|
244 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
245 CleanupStack::PushL( startupProperties ); |
|
246 |
|
247 // Start testprocess as a server. |
|
248 startupProperties->SetFileParamsL( KTestProcGood, KLaunchServerCommandLineOption ); |
|
249 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
250 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
251 |
|
252 RProcess process_0; |
|
253 CleanupClosePushL( process_0 ); |
|
254 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
255 |
|
256 CTestAndStopper* testAndStopper_0 = new(ELeave) CTestAndStopper( *ss, *startupProperties, process_0, KProcStartStopperTimeout, this ); |
|
257 CleanupStack::PushL( testAndStopper_0 ); |
|
258 CActiveScheduler::Start(); |
|
259 |
|
260 |
|
261 RProcess process_1; |
|
262 CleanupClosePushL( process_1 ); |
|
263 |
|
264 // Attempt to start another |
|
265 CTestAndStopper* testAndStopper_1 = new(ELeave) CTestAndStopper( *ss, *startupProperties, process_1, KProcStartStopperTimeout, this ); |
|
266 CleanupStack::PushL( testAndStopper_1 ); |
|
267 CActiveScheduler::Start(); |
|
268 |
|
269 |
|
270 INFO_PRINTF1( _L("Checking for one instance of the server process") ); |
|
271 TEST( 1 == FindAndKill(KTestProcGood) ); |
|
272 |
|
273 CleanupStack::PopAndDestroy( 6, startupProperties ); |
|
274 } |
|
275 |
|
276 void CSsTestStepProcStart::DoTestForMonitorAlreadyMonProcL() |
|
277 { |
|
278 INFO_PRINTF1( _L("\n\nPerforming Process-monitor test for already started and monitored process") ); |
|
279 |
|
280 RProcess process; |
|
281 CleanupClosePushL(process); |
|
282 |
|
283 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
284 CleanupStack::PushL( startupProperties ); |
|
285 |
|
286 // Need to start testprocess as a server so that we can tell it to stop being monitored. |
|
287 startupProperties->SetFileParamsL(KTestProcGood, KLaunchServerCommandLineOption); |
|
288 startupProperties->SetCommandTypeL(ESsmCmdStartProcess); |
|
289 startupProperties->SetExecutionBehaviour(ESsmWaitForSignal); |
|
290 |
|
291 const TInt KMonitorTimeout = 3000; // milliseconds I presume |
|
292 TSsmMonitorInfo monitorInfo; |
|
293 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
294 monitorInfo.iRestartMode = 0; |
|
295 monitorInfo.iTimeout = KMonitorTimeout; |
|
296 monitorInfo.iRetries = 1; |
|
297 startupProperties->SetMonitorInfoL(monitorInfo); |
|
298 |
|
299 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
300 |
|
301 // Try to start and monitor the process |
|
302 TRAPD(err, ss->StartAndMonitorL(*startupProperties, process)); |
|
303 TEST(err == KErrNone); |
|
304 INFO_PRINTF3( _L("StartAndMonitorL() completed with %d. anticipated value %d"),err, KErrNone ); |
|
305 |
|
306 RTestProcGoodSession testProcServerSession; |
|
307 err = testProcServerSession.Connect(); |
|
308 TEST(KErrNone == err); |
|
309 INFO_PRINTF1( _L("Asserted that server is running")); |
|
310 |
|
311 // Try to start and monitor an already started and monitored process |
|
312 TRAP(err, ss->StartAndMonitorL(*startupProperties, process)); |
|
313 |
|
314 // sysmon returns KErrAlreadyExists, if we try to monitor an already monitored process |
|
315 TEST(err == KErrAlreadyExists); |
|
316 INFO_PRINTF3( _L("StartAndMonitorL() completed with %d. anticipated value %d"),err, KErrAlreadyExists); |
|
317 |
|
318 process.Kill(KErrNone); |
|
319 |
|
320 err = testProcServerSession.Connect(); |
|
321 //Connecting to the test proc server session should fail here with error value as either KErrNotFound(in case session object is cleaned up) or KErrServerTerminated(session object is there but session terminated) |
|
322 TEST(KErrNotFound == err || KErrServerTerminated == err); |
|
323 INFO_PRINTF3( _L("Connect to test proc server session failed with %d. anticipated value %d"),err, KErrNotFound); |
|
324 |
|
325 RSemaphore sem; |
|
326 err = sem.CreateGlobal(KStartProcSignalSemaphore, 0); |
|
327 INFO_PRINTF2(_L("Created semaphore with err %d"),err); |
|
328 TEST(err == KErrNone); |
|
329 CleanupClosePushL(sem); |
|
330 |
|
331 INFO_PRINTF1(_L("Waiting for Start of the test application")); |
|
332 sem.Wait(); |
|
333 //Waiting for 5 seconds as in the ssmtestprocgood application the active scheduler |
|
334 // will be started after signalling the semaphore. And we can connect to the |
|
335 // application only after the active scheduler is started. |
|
336 User::After(KWaitForActiveSchedStart); |
|
337 |
|
338 // Check that the killed process is restarted by SysMon |
|
339 err = testProcServerSession.Connect(); |
|
340 TEST(KErrNone == err); |
|
341 INFO_PRINTF3( _L("process re-started by sysmon with %d, anticipate value %d"),err,KErrNone); |
|
342 |
|
343 // Stop monitoring to stop restarts. |
|
344 if(KErrNone == testProcServerSession.Connect()) |
|
345 { |
|
346 testProcServerSession.CancelMonitor(); |
|
347 testProcServerSession.Close(); |
|
348 } |
|
349 TEST(1 == FindAndKill(KTestProcGood)); |
|
350 CleanupStack::PopAndDestroy(4, &process); |
|
351 } |
|
352 |
|
353 TVerdict CSsTestStepProcStart::doTestStepPreambleL() |
|
354 { |
|
355 iActiveScheduler = new(ELeave) CActiveScheduler; |
|
356 CActiveScheduler::Install ( iActiveScheduler ); |
|
357 |
|
358 return CTestStep::doTestStepPreambleL(); |
|
359 } |
|
360 |
|
361 |
|
362 |
|
363 /** */ |
|
364 TVerdict CSsTestStepProcStart::doTestStepPostambleL() |
|
365 { |
|
366 return CTestStep::doTestStepPostambleL(); |
|
367 } |
|
368 |
|
369 |
|
370 |
|
371 CSsTestStepProcStart::CSsTestStepProcStart() |
|
372 { |
|
373 SetTestStepName( KCTestCaseProcStart ); |
|
374 } |
|
375 |
|
376 |
|
377 |
|
378 CSsTestStepProcStart::~CSsTestStepProcStart() |
|
379 { |
|
380 delete iActiveScheduler; |
|
381 } |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |