|
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-0010 |
|
15 // New Test CaseID DEVSRVS-SSMA-STARTSAFE-0010 |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 |
|
26 #include "tss_procstartwithfandf.h" |
|
27 #include "ssmtestappsucessfulafterretry.h" |
|
28 #include "ssmtestappslow.h" |
|
29 |
|
30 const TInt KProcStartStopperTimeout = 5000000; |
|
31 const TInt KWaitTimeForTestAppForFAndF = 500; // 500ms is the delay given for the KTestAppForFAndF test app for each retry. |
|
32 |
|
33 TVerdict CSsTestStepProcStartWithFAndF::doTestStepL() |
|
34 { |
|
35 __UHEAP_MARK; |
|
36 |
|
37 TInt threadHandles_Before; |
|
38 TInt processHandles_Before; |
|
39 TInt threadHandles_After; |
|
40 TInt processHandles_After; |
|
41 |
|
42 RThread().HandleCount(processHandles_Before, threadHandles_Before); |
|
43 |
|
44 TRAPD(err, DoTestFAndFWithLessTimeOutAndWithRetriesL()); |
|
45 TEST(err == KErrNone); |
|
46 INFO_PRINTF2(_L("DoTestFAndFWithLessTimeOutAndWithRetriesL completed with err = %d"), err); |
|
47 |
|
48 TRAP(err, DoTestFAndFWithLessTimeOutAndNoRetriesL()); |
|
49 TEST(err == KErrNone); |
|
50 INFO_PRINTF2(_L("DoTestFAndFWithLessTimeOutAndNoRetriesL completed with err = %d"), err); |
|
51 |
|
52 TRAP(err, DoTestFAndFWithMoreTimeOutAndNoRetriesL()); |
|
53 TEST(err == KErrNone); |
|
54 INFO_PRINTF2(_L("DoTestFAndFWithMoreTimeOutAndNoRetriesL completed with err = %d"), err); |
|
55 |
|
56 TRAP(err, DoTestFAndFWithMoreTimeOutAndWithRetriesL()); |
|
57 TEST(err == KErrNone); |
|
58 INFO_PRINTF2(_L("DoTestFAndFWithMoreTimeOutAndWithRetriesL completed with err = %d"), err); |
|
59 |
|
60 TRAP(err, DoTestFAndFWithRetriesForFailureAppL()); |
|
61 TEST(err == KErrNone); |
|
62 INFO_PRINTF2(_L("DoTestFAndFWithRetriesForFailureAppL completed with err = %d"), err); |
|
63 |
|
64 TRAP(err, DoTestFAndFWithLessTimeOutAndMoreRetriesL()); |
|
65 TEST(err == KErrNone); |
|
66 INFO_PRINTF2(_L("DoTestFAndFWithLessTimeOutAndMoreRetriesL completed with err = %d"), err); |
|
67 |
|
68 TRAP(err, DoTestFAndFWithRetriesForSuccessfullAppL()); |
|
69 TEST(err == KErrNone); |
|
70 INFO_PRINTF2(_L("DoTestFAndFWithRetriesForSuccessfullAppL completed with err = %d"), err); |
|
71 |
|
72 RThread().HandleCount(processHandles_After, threadHandles_After); |
|
73 TEST(processHandles_After == processHandles_Before); |
|
74 TEST(threadHandles_After == threadHandles_Before); |
|
75 |
|
76 __UHEAP_MARKEND; |
|
77 return TestStepResult(); |
|
78 } |
|
79 |
|
80 void CSsTestStepProcStartWithFAndF::DoTestAndStopperL(TInt aRetries, TInt aTimeOut, const TDesC& aFileName) |
|
81 { |
|
82 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
83 CleanupStack::PushL(startupProperties); |
|
84 |
|
85 startupProperties->SetFileParamsL(aFileName, KNullDesC); |
|
86 startupProperties->SetCommandTypeL(ESsmCmdStartProcess); |
|
87 startupProperties->SetExecutionBehaviour(ESsmFireAndForget); |
|
88 startupProperties->SetTimeout(aTimeOut); |
|
89 startupProperties->SetRetries(aRetries); |
|
90 |
|
91 RProcess process; |
|
92 CleanupClosePushL(process); |
|
93 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
94 |
|
95 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper(*ss, *startupProperties, process, KProcStartStopperTimeout, this); |
|
96 CleanupStack::PushL(testAndStopper); |
|
97 CActiveScheduler::Start(); |
|
98 |
|
99 CleanupStack::PopAndDestroy(4, startupProperties); |
|
100 } |
|
101 |
|
102 /** |
|
103 Starts an instance of ssmtestappslow.exe synchronously as a process using fire-and-forget. |
|
104 No retries are specified. Timeout is specified, therefore CTimeoutWaiter is not instantiated. |
|
105 */ |
|
106 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithLessTimeOutAndWithRetriesL() |
|
107 { |
|
108 INFO_PRINTF1(_L("Performing Fire-and-forget Timeout test with retries")); |
|
109 |
|
110 const TInt KTestLessTimeOut = KTestAppSlowTimeoutInMilliSeconds-100; |
|
111 DoTestAndStopperL(1, KTestLessTimeOut, KTestAppSlow); |
|
112 |
|
113 // ssmtestappslow.exe would terminated due to timeout. |
|
114 // Since ssmtestappslow application takes more time to start than the timeout specified in the ssmsstartupproperties, |
|
115 // it doesn't start anytime irrespective of no. of retries specified. |
|
116 TEST(0 == FindAndKill(KTestAppSlow)); |
|
117 INFO_PRINTF1( _L("ssmtestappslow.exe would be terminated due to timeout")); |
|
118 } |
|
119 |
|
120 /** |
|
121 Start a ssmtestappslow test application synchronously using fire-and-forget with timeout |
|
122 less than the time required for the application to start and without retries. |
|
123 */ |
|
124 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithLessTimeOutAndNoRetriesL() |
|
125 { |
|
126 INFO_PRINTF1(_L("Performing Fire-and-forget Timeout test with no retries")); |
|
127 |
|
128 const TInt KTestLessTimeOut = KTestAppSlowTimeoutInMilliSeconds-100; |
|
129 DoTestAndStopperL(0, KTestLessTimeOut, KTestAppSlow); |
|
130 |
|
131 // ssmtestappslow.exe would terminated due to timeout. |
|
132 // Since ssmtestappslow application takes more time to start than the timeout specified in the ssmsstartupproperties |
|
133 TEST(0 == FindAndKill(KTestAppSlow)); |
|
134 INFO_PRINTF1( _L("ssmtestappslow.exe would be terminated due to timeout")); |
|
135 } |
|
136 |
|
137 /** |
|
138 Start a ssmtestappslow test application synchronously using fire-and-forget with timeout |
|
139 more than the time required for the application to start and without retries. |
|
140 */ |
|
141 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithMoreTimeOutAndNoRetriesL() |
|
142 { |
|
143 INFO_PRINTF1(_L("Performing Fire-and-forget Timeout test with no retries and..")); |
|
144 INFO_PRINTF1(_L("Timeout specified in ssmstartupproperties is more than timeout required for application startup")); |
|
145 |
|
146 const TInt KTestMoreTimeOut = KTestAppSlowTimeoutInMilliSeconds * 3; |
|
147 DoTestAndStopperL(0, KTestMoreTimeOut, KTestAppSlow); |
|
148 |
|
149 // ssmtestappslow.exe would be started as ssmtestappslow application takes less time to start than |
|
150 // the timeout specified in the ssmsstartupproperties |
|
151 TEST(1 == FindAndKill(KTestAppSlow)); |
|
152 } |
|
153 |
|
154 /** |
|
155 Start a test application synchronously using fire-and-forget with timeout |
|
156 more than the time required for the application to start and which starts after the no. of retries given. |
|
157 */ |
|
158 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithMoreTimeOutAndWithRetriesL() |
|
159 { |
|
160 INFO_PRINTF1(_L("Performing Fire-and-forget test with timeout and retries")); |
|
161 |
|
162 // Write the retry number to a file to be read, updated |
|
163 // and eventually deleted by the test-app. |
|
164 RFs fs; |
|
165 CleanupClosePushL( fs ); |
|
166 |
|
167 RFileWriteStream writeStream; |
|
168 CleanupClosePushL( writeStream ); |
|
169 |
|
170 User::LeaveIfError(fs.Connect()); |
|
171 User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite)); |
|
172 |
|
173 const TInt KSsTestRequiredDelay = 0; |
|
174 const TInt KSsTestFailCount = 1; |
|
175 const TInt KSsTestRetryCount = 0; |
|
176 writeStream.WriteInt8L(KSsTestRetryCount); |
|
177 writeStream.WriteInt8L(KSsTestFailCount); |
|
178 writeStream.WriteInt8L(KSsTestRequiredDelay); |
|
179 writeStream.CommitL(); |
|
180 writeStream.Close(); |
|
181 |
|
182 const TInt KRetries = KSsTestFailCount + 1; |
|
183 DoTestAndStopperL(KRetries, KWaitTimeForTestAppForFAndF * 4, KTestAppForFAndF); |
|
184 |
|
185 RFileReadStream readStream; |
|
186 CleanupClosePushL(readStream); |
|
187 |
|
188 User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead)); |
|
189 TInt retryCount = readStream.ReadInt8L(); |
|
190 readStream.Close(); |
|
191 fs.Delete(KFileForFAndF); |
|
192 |
|
193 CleanupStack::PopAndDestroy(3, &fs); |
|
194 |
|
195 TEST(retryCount == 1); |
|
196 INFO_PRINTF3( _L("ssmtestappsucessfulafterretry.exe is started after %d retries. anticipated retries value %d"),retryCount, 1); |
|
197 TEST(1 == FindAndKill(KTestAppForFAndF)); |
|
198 } |
|
199 |
|
200 /** |
|
201 Start a test application which fails to start synchronously using fire-and-forget |
|
202 without timeout and 1 retry. |
|
203 */ |
|
204 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithRetriesForFailureAppL() |
|
205 { |
|
206 INFO_PRINTF1(_L("Performing Fire-and-forget test for failure app with retries and no timeout")); |
|
207 |
|
208 DoTestAndStopperL(1, 0, KTestAppRvError); |
|
209 |
|
210 // Since ssmtestapprverror application is terminated with KErrGeneral each it is started, so |
|
211 // it doesn't start anytime irrespective of no. of retries specified. |
|
212 INFO_PRINTF1( _L("ssmtestapprverror.exe would not be started even after 1 retry as the app Rendezvous with error")); |
|
213 TEST( 0 == FindAndKill(KTestAppRvError) ); |
|
214 } |
|
215 |
|
216 /** |
|
217 Start a test application which fails to start even with 2 retries remaining due to timeout |
|
218 synchronously using fire-and-forget. |
|
219 */ |
|
220 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithLessTimeOutAndMoreRetriesL() |
|
221 { |
|
222 INFO_PRINTF1(_L("Performing Fire-and-forget test with Less Timeout and more retries")); |
|
223 |
|
224 // Write the retry number to a file to be read, updated |
|
225 // and eventually deleted by the test-app. |
|
226 RFs fs; |
|
227 CleanupClosePushL( fs ); |
|
228 |
|
229 RFileWriteStream writeStream; |
|
230 CleanupClosePushL( writeStream ); |
|
231 |
|
232 User::LeaveIfError(fs.Connect()); |
|
233 User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite)); |
|
234 |
|
235 const TInt KSsTestFailCount = 3; |
|
236 const TInt KSsTestRetryCount = 0; |
|
237 const TInt KSsTestRequiredDelay = 1; |
|
238 writeStream.WriteInt8L(KSsTestRetryCount); |
|
239 writeStream.WriteInt8L(KSsTestFailCount); |
|
240 writeStream.WriteInt8L(KSsTestRequiredDelay); |
|
241 writeStream.CommitL(); |
|
242 writeStream.Close(); |
|
243 |
|
244 const TInt KRetries = KSsTestFailCount + 1; |
|
245 DoTestAndStopperL(KRetries, KWaitTimeForTestAppForFAndF * 2.5, KTestAppForFAndF); |
|
246 |
|
247 RFileReadStream readStream; |
|
248 CleanupClosePushL(readStream); |
|
249 |
|
250 User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead)); |
|
251 TInt retryCount = readStream.ReadInt8L(); |
|
252 readStream.Close(); |
|
253 fs.Delete(KFileForFAndF); |
|
254 |
|
255 CleanupStack::PopAndDestroy(3, &fs); |
|
256 // ssmtestappsucessfulafterretry.exe would terminated due to timeout. |
|
257 TEST(0 == FindAndKill(KTestAppForFAndF)); |
|
258 TInt retriesRemaining = KRetries-retryCount; |
|
259 // remaining retries would differ in case of emulator and h4 due to timeout required is different in each case. |
|
260 // so we are testing if there are any remaining retries rather than the exact number. |
|
261 TEST(retryCount >= 1); |
|
262 TEST(retriesRemaining >= 1); |
|
263 INFO_PRINTF2(_L("ssmtestappsucessfulafterretry.exe is not started even after %d retries. anticipated retries more than or equal to 1"),retryCount); |
|
264 INFO_PRINTF2(_L("Actual remaining retries %d. anticipated remaining retries more than or equal to 1"),retriesRemaining); |
|
265 } |
|
266 |
|
267 /** |
|
268 Start a test application which fails to start twice and starts on the 3rd retry |
|
269 synchronously using fire-and-forget without timeout and 3 retries. |
|
270 */ |
|
271 void CSsTestStepProcStartWithFAndF::DoTestFAndFWithRetriesForSuccessfullAppL() |
|
272 { |
|
273 INFO_PRINTF1(_L("Performing Fire-and-forget test without timeout and with retries")); |
|
274 |
|
275 // Write the retry number to a file to be read, updated |
|
276 // and eventually deleted by the test-app. |
|
277 RFs fs; |
|
278 CleanupClosePushL( fs ); |
|
279 |
|
280 RFileWriteStream writeStream; |
|
281 CleanupClosePushL( writeStream ); |
|
282 |
|
283 User::LeaveIfError(fs.Connect()); |
|
284 User::LeaveIfError(writeStream.Replace(fs, KFileForFAndF, EFileWrite)); |
|
285 |
|
286 const TInt KSsTestRequiredDelay = 0; |
|
287 const TInt KSsTestFailCount = 1; |
|
288 const TInt KSsTestRetryCount = 0; |
|
289 writeStream.WriteInt8L(KSsTestRetryCount); |
|
290 writeStream.WriteInt8L(KSsTestFailCount); |
|
291 writeStream.WriteInt8L(KSsTestRequiredDelay); |
|
292 writeStream.CommitL(); |
|
293 writeStream.Close(); |
|
294 |
|
295 const TInt KRetries = KSsTestFailCount + 1; |
|
296 DoTestAndStopperL(KRetries, 0, KTestAppForFAndF); |
|
297 |
|
298 RFileReadStream readStream; |
|
299 CleanupClosePushL(readStream); |
|
300 |
|
301 User::LeaveIfError(readStream.Open(fs, KFileForFAndF, EFileRead)); |
|
302 TInt retryCount = readStream.ReadInt8L(); |
|
303 readStream.Close(); |
|
304 fs.Delete(KFileForFAndF); |
|
305 |
|
306 CleanupStack::PopAndDestroy(3, &fs); |
|
307 |
|
308 TEST(retryCount == 1); |
|
309 |
|
310 INFO_PRINTF3( _L("ssmtestappsucessfulafterretry.exe is started after %d retries. anticipated retries value %d"),retryCount, 1); |
|
311 TEST(1 == FindAndKill(KTestAppForFAndF)); |
|
312 } |
|
313 |
|
314 TVerdict CSsTestStepProcStartWithFAndF::doTestStepPreambleL() |
|
315 { |
|
316 iActiveScheduler = new(ELeave) CActiveScheduler; |
|
317 CActiveScheduler::Install (iActiveScheduler); |
|
318 |
|
319 return CTestStep::doTestStepPreambleL(); |
|
320 } |
|
321 |
|
322 TVerdict CSsTestStepProcStartWithFAndF::doTestStepPostambleL() |
|
323 { |
|
324 return CTestStep::doTestStepPostambleL(); |
|
325 } |
|
326 |
|
327 CSsTestStepProcStartWithFAndF::CSsTestStepProcStartWithFAndF() |
|
328 { |
|
329 SetTestStepName(KCTestCaseProcStartWithFAndF); |
|
330 } |
|
331 |
|
332 CSsTestStepProcStartWithFAndF::~CSsTestStepProcStartWithFAndF() |
|
333 { |
|
334 delete iActiveScheduler; |
|
335 } |
|
336 |
|
337 |