|
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-0001 |
|
15 // New Test CaseID DEVSRVS-SSMA-STARTSAFE-0001 |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 |
|
26 |
|
27 #include "tss_appstart.h" |
|
28 |
|
29 |
|
30 const TInt KFireAndForgetTimeout = 5000000; |
|
31 |
|
32 |
|
33 |
|
34 TVerdict CSsTestStepAppStart::doTestStepL() |
|
35 { |
|
36 __UHEAP_MARK; |
|
37 |
|
38 TRAPD(err, DoTestFireAndForgetAsyncL()); |
|
39 TEST(err == KErrNone); |
|
40 INFO_PRINTF2(_L("DoTestFireAndForgetAsyncL completed with err = %d"), err); |
|
41 |
|
42 TRAP(err, DoTestWaitForStartAsyncL()); |
|
43 TEST(err == KErrNone); |
|
44 INFO_PRINTF2(_L("DoTestWaitForStartAsyncL completed with err = %d"), err); |
|
45 |
|
46 TRAP(err, DoTestFireAndForgetSyncL()); |
|
47 TEST(err == KErrNone); |
|
48 INFO_PRINTF2(_L("DoTestFireAndForgetSyncL completed with err = %d"), err); |
|
49 |
|
50 TRAP(err, DoTestWaitForStartSyncL()); |
|
51 TEST(err == KErrNone); |
|
52 INFO_PRINTF2(_L("DoTestWaitForStartSyncL completed with err = %d"), err); |
|
53 |
|
54 TRAP(err, DoTestWaitForStartSuccessiveSyncL()); |
|
55 TEST(err == KErrNone); |
|
56 INFO_PRINTF2(_L("DoTestWaitForStartSuccessiveSyncL completed with err = %d"), err); |
|
57 |
|
58 TRAP(err, DoTestAppStartWithRetriesL()); |
|
59 TEST(err == KErrNone); |
|
60 INFO_PRINTF2(_L("DoTestAppStartWithRetriesL completed with err = %d"), err); |
|
61 |
|
62 __UHEAP_MARKEND; |
|
63 return TestStepResult(); |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Start a test application asynchronously using fire-and-forget |
|
69 */ |
|
70 void CSsTestStepAppStart::DoTestFireAndForgetAsyncL() |
|
71 { |
|
72 INFO_PRINTF1( _L("\n\nPerforming App-Start Fire-and-forget Async test") ); |
|
73 |
|
74 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
75 CleanupStack::PushL( startupProperties ); |
|
76 |
|
77 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
78 startupProperties->SetCommandTypeL( ESsmCmdStartApp ); |
|
79 startupProperties->SetExecutionBehaviour( ESsmFireAndForget ); |
|
80 |
|
81 RProcess process; |
|
82 CleanupClosePushL( process ); |
|
83 TInt id = 0; |
|
84 |
|
85 CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout ); |
|
86 CleanupStack::PushL( stopper ); |
|
87 |
|
88 TRequestStatus& trs = stopper->Trs(); |
|
89 |
|
90 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
91 ss->Start(*startupProperties, process, trs, id); |
|
92 //Application is started using fire-and-forget execution behaviour, |
|
93 //Start method always sets TRequestStatus to KErrNone. |
|
94 if( KErrNone == trs.Int() ) |
|
95 { |
|
96 CActiveScheduler::Start(); |
|
97 INFO_PRINTF3( _L("TRS completed with %d. anticipated value %d"), stopper->CompletionCode(), KErrNone ); |
|
98 } |
|
99 |
|
100 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
101 |
|
102 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
103 } |
|
104 |
|
105 |
|
106 |
|
107 const TInt KSsTestAppStartTimeout = 3000; // ms |
|
108 /** |
|
109 Start a test application asynchronously using wait-for-start. |
|
110 A timeout is specified in order to instantiate the CTimeoutWaiter class |
|
111 */ |
|
112 void CSsTestStepAppStart::DoTestWaitForStartAsyncL() |
|
113 { |
|
114 INFO_PRINTF1( _L("\n\nPerforming App-Start Wait-for-start Async test") ); |
|
115 |
|
116 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
117 CleanupStack::PushL( startupProperties ); |
|
118 |
|
119 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
120 startupProperties->SetCommandTypeL( ESsmCmdStartApp ); |
|
121 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
122 startupProperties->SetRetries( 3 ); |
|
123 startupProperties->SetTimeout( KSsTestAppStartTimeout ); |
|
124 |
|
125 RProcess process; |
|
126 TInt id = 0; |
|
127 |
|
128 CAsStopper* stopper = new(ELeave) CAsStopper( KSsAsStopperNominalTimeout ); |
|
129 CleanupStack::PushL( stopper ); |
|
130 |
|
131 TRequestStatus& trs = stopper->Trs(); |
|
132 |
|
133 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
134 ss->Start(*startupProperties, process, trs, id); |
|
135 CActiveScheduler::Start(); |
|
136 process.Close(); |
|
137 |
|
138 INFO_PRINTF3( _L("TRS completed with %d. anticipated value %d"), stopper->CompletionCode(), KErrNone ); |
|
139 |
|
140 CleanupStack::PopAndDestroy( 3, startupProperties ); |
|
141 |
|
142 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
143 } |
|
144 |
|
145 |
|
146 |
|
147 /** |
|
148 Start a test application synchronously using fire-and-forget |
|
149 */ |
|
150 void CSsTestStepAppStart::DoTestFireAndForgetSyncL() |
|
151 { |
|
152 INFO_PRINTF1( _L("\n\nPerforming App-start Fire-and-forget sync test") ); |
|
153 |
|
154 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
155 CleanupStack::PushL( startupProperties ); |
|
156 |
|
157 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
158 startupProperties->SetCommandTypeL( ESsmCmdStartApp ); |
|
159 startupProperties->SetExecutionBehaviour( ESsmFireAndForget ); |
|
160 |
|
161 RProcess process; |
|
162 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
163 |
|
164 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper( *ss, *startupProperties, process, KFireAndForgetTimeout, this ); |
|
165 CleanupStack::PushL( testAndStopper ); |
|
166 CActiveScheduler::Start(); |
|
167 |
|
168 process.Close(); |
|
169 |
|
170 CleanupStack::PopAndDestroy( 3, startupProperties ); |
|
171 |
|
172 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
173 } |
|
174 |
|
175 |
|
176 |
|
177 /** |
|
178 Start a test application asynchronously using wait-for-start. |
|
179 A timeout is specified in order to instantiate the CTimeoutWaiter class |
|
180 */ |
|
181 void CSsTestStepAppStart::DoTestWaitForStartSyncL() |
|
182 { |
|
183 INFO_PRINTF1( _L("\n\nPerforming App-start Wait-for-start sync test") ); |
|
184 |
|
185 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
186 CleanupStack::PushL( startupProperties ); |
|
187 |
|
188 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
189 startupProperties->SetCommandTypeL( ESsmCmdStartApp ); |
|
190 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
191 startupProperties->SetRetries( 3 ); |
|
192 startupProperties->SetTimeout( KSsTestAppStartTimeout ); |
|
193 |
|
194 RProcess process; |
|
195 |
|
196 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
197 |
|
198 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper( *ss, *startupProperties, process, KFireAndForgetTimeout, this ); |
|
199 CleanupStack::PushL( testAndStopper ); |
|
200 CActiveScheduler::Start(); |
|
201 |
|
202 process.Close(); |
|
203 |
|
204 CleanupStack::PopAndDestroy( 3, startupProperties ); |
|
205 |
|
206 TEST( 1 == FindAndKill(KTestAppGood) ); |
|
207 } |
|
208 |
|
209 |
|
210 /** |
|
211 This test makes two synchronous calls to StartL and checks for two instances of the test-app. |
|
212 A timeout is specified in order to instantiate the CTimeoutWaiter class. |
|
213 some retries are specified, although they will not be used |
|
214 */ |
|
215 void CSsTestStepAppStart::DoTestWaitForStartSuccessiveSyncL() |
|
216 { |
|
217 INFO_PRINTF1( _L("\n\nPerforming App-start Wait-for-start sync test") ); |
|
218 |
|
219 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
220 CleanupStack::PushL( startupProperties ); |
|
221 |
|
222 startupProperties->SetFileParamsL( KTestAppGood, KNullDesC ); |
|
223 startupProperties->SetCommandTypeL( ESsmCmdStartApp ); |
|
224 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
225 startupProperties->SetRetries( 3 ); |
|
226 startupProperties->SetTimeout( KSsTestAppStartTimeout ); |
|
227 |
|
228 RProcess process_0; |
|
229 RProcess process_1; |
|
230 |
|
231 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
232 |
|
233 CTestTwoAndStopper* testTwoAndStopper_0 = new(ELeave) CTestTwoAndStopper( *ss, *startupProperties, process_0, process_1, KFireAndForgetTimeout, this ); |
|
234 CleanupStack::PushL( testTwoAndStopper_0 ); |
|
235 |
|
236 CActiveScheduler::Start(); |
|
237 |
|
238 process_0.Close(); |
|
239 process_1.Close(); |
|
240 CleanupStack::PopAndDestroy( 3, startupProperties ); |
|
241 |
|
242 TEST( 2 == FindAndKill(KTestAppGood) ); |
|
243 } |
|
244 |
|
245 |
|
246 |
|
247 /** |
|
248 ssmtestapprvafterretry.exe is eventually invoked successfully. SsmStartSafe is configured to |
|
249 make 1 + retries attempts to start the recalcitrant app. The app is configured to start |
|
250 after retries attempts |
|
251 */ |
|
252 void CSsTestStepAppStart::DoTestAppStartWithRetriesL() |
|
253 { |
|
254 INFO_PRINTF1( _L("\nStart recalcitrant app with retries") ); |
|
255 |
|
256 // |
|
257 // Write the retry number to a file to be read, updated |
|
258 // and eventually deleted by the test-app. |
|
259 RFs fs; |
|
260 CleanupClosePushL( fs ); |
|
261 |
|
262 RFileWriteStream writeStream; |
|
263 CleanupClosePushL( writeStream ); |
|
264 |
|
265 if( KErrNone != fs.Connect() |
|
266 || KErrNone != writeStream.Replace(fs, KDontRvCountFile, EFileWrite) ) |
|
267 { |
|
268 User::Leave( KErrCouldNotConnect ); |
|
269 } |
|
270 const TInt KSsTestDontRvCount = 4; |
|
271 writeStream.WriteInt8L( KSsTestDontRvCount ); |
|
272 writeStream.CommitL(); |
|
273 |
|
274 CleanupStack::PopAndDestroy( 2, &fs ); |
|
275 // |
|
276 |
|
277 |
|
278 const TInt KRetries = KSsTestDontRvCount + 1; |
|
279 CSsmStartupProperties* startupProperties_0 = CSsmStartupProperties::NewL(); |
|
280 CleanupStack::PushL( startupProperties_0 ); |
|
281 |
|
282 startupProperties_0->SetFileParamsL( KTestAppRvAfterRetry, KNullDesC ); |
|
283 startupProperties_0->SetCommandTypeL( ESsmCmdStartApp ); |
|
284 startupProperties_0->SetExecutionBehaviour( ESsmWaitForSignal ); |
|
285 startupProperties_0->SetRetries( KRetries ); |
|
286 // For each retry KTestAppRvAfterRetry takes 2secs |
|
287 startupProperties_0->SetTimeout( KSsTestAppStartTimeout*1.5 ); |
|
288 |
|
289 RProcess process; |
|
290 TInt id_0 = 0; |
|
291 |
|
292 CStartAcknowledge* ack_0 = new(ELeave) CStartAcknowledge( this ); |
|
293 CleanupStack::PushL( ack_0 ); |
|
294 |
|
295 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
296 ss->Start(*startupProperties_0, process, ack_0->iStatus, id_0); |
|
297 |
|
298 |
|
299 CAsPauseStopper* pauseStopper = new(ELeave) CAsPauseStopper( KSsAsStopperNominalTimeout * 10 ); |
|
300 CleanupStack::PushL( pauseStopper ); |
|
301 CActiveScheduler::Start(); |
|
302 process.Close(); |
|
303 |
|
304 TEST( ack_0->iStatus == KErrNone ); |
|
305 |
|
306 CleanupStack::PopAndDestroy( 4, startupProperties_0 ); |
|
307 |
|
308 TEST( 1 == FindAndKill(KTestAppRvAfterRetry) ); |
|
309 } |
|
310 |
|
311 |
|
312 |
|
313 TVerdict CSsTestStepAppStart::doTestStepPreambleL() |
|
314 { |
|
315 iActiveScheduler = new(ELeave) CActiveScheduler; |
|
316 CActiveScheduler::Install( iActiveScheduler ); |
|
317 |
|
318 return CTestStep::doTestStepPreambleL(); |
|
319 } |
|
320 |
|
321 |
|
322 |
|
323 /** */ |
|
324 TVerdict CSsTestStepAppStart::doTestStepPostambleL() |
|
325 { |
|
326 return CTestStep::doTestStepPostambleL(); |
|
327 } |
|
328 |
|
329 |
|
330 /** |
|
331 From MSsTestAsyncNotifier |
|
332 */ |
|
333 void CSsTestStepAppStart::SsTestNotify( TInt aNotify ) |
|
334 { |
|
335 TEST( KErrNone == aNotify ); |
|
336 |
|
337 INFO_PRINTF3( _L("StartL supplied leave code %d. Anticipated value %d"), aNotify, KErrNone ); |
|
338 } |
|
339 |
|
340 |
|
341 |
|
342 CSsTestStepAppStart::CSsTestStepAppStart() |
|
343 { |
|
344 SetTestStepName( KCTestCaseAppStart ); |
|
345 } |
|
346 |
|
347 |
|
348 |
|
349 CSsTestStepAppStart::~CSsTestStepAppStart() |
|
350 { |
|
351 delete iActiveScheduler; |
|
352 } |
|
353 |