|
1 /* |
|
2 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CamAppPerfTest test cases |
|
15 * |
|
16 */ |
|
17 |
|
18 // [INCLUDE FILES] - do not remove |
|
19 #include <e32math.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include <apgtask.h> |
|
23 #include <apgcli.h> |
|
24 #include <EIKENV.H> // for UI components |
|
25 |
|
26 #include "CamAppPerfTest.h" |
|
27 |
|
28 #define EProductKeyCapture EStdKeyDevice7 |
|
29 |
|
30 |
|
31 // CONSTANTS |
|
32 _LIT( KCamAppName, "Z:\\sys\\bin\\cameraapp.exe" ); |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CCamAppPerfTest::Case |
|
38 // Returns a test case by number. |
|
39 // |
|
40 // This function contains an array of all available test cases |
|
41 // i.e pair of case name and test function. If case specified by parameter |
|
42 // aCaseNumber is found from array, then that item is returned. |
|
43 // |
|
44 // The reason for this rather complicated function is to specify all the |
|
45 // test cases only in one place. It is not necessary to understand how |
|
46 // function pointers to class member functions works when adding new test |
|
47 // cases. See function body for instructions how to add new test case. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 const TCaseInfo CCamAppPerfTest::Case ( |
|
51 const TInt aCaseNumber ) const |
|
52 { |
|
53 |
|
54 /** |
|
55 * To add new test cases, implement new test case function and add new |
|
56 * line to KCases array specify the name of the case and the function |
|
57 * doing the test case |
|
58 * In practice, do following |
|
59 * 1) Make copy of existing test case function and change its name |
|
60 * and functionality. Note that the function must be added to |
|
61 * CamAppPerfTest.cpp file and to CamAppPerfTest.h |
|
62 * header file. |
|
63 * |
|
64 * 2) Add entry to following KCases array either by using: |
|
65 * |
|
66 * 2.1: FUNCENTRY or ENTRY macro |
|
67 * ENTRY macro takes two parameters: test case name and test case |
|
68 * function name. |
|
69 * |
|
70 * FUNCENTRY macro takes only test case function name as a parameter and |
|
71 * uses that as a test case name and test case function name. |
|
72 * |
|
73 * Or |
|
74 * |
|
75 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
76 * only with OOM (Out-Of-Memory) testing! |
|
77 * |
|
78 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
79 * function name, TBool which specifies is method supposed to be run using |
|
80 * OOM conditions, TInt value for first heap memory allocation failure and |
|
81 * TInt value for last heap memory allocation failure. |
|
82 * |
|
83 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
84 * that as a test case name, TBool which specifies is method supposed to be |
|
85 * run using OOM conditions, TInt value for first heap memory allocation |
|
86 * failure and TInt value for last heap memory allocation failure. |
|
87 */ |
|
88 |
|
89 static TCaseInfoInternal const KCases[] = |
|
90 { |
|
91 // [test cases entries] - do not remove |
|
92 |
|
93 // NOTE: When compiled to GCCE, there must be Classname:: |
|
94 // declaration in front of the method name, e.g. |
|
95 // CCamAppPerfTest::PrintTest. Otherwise the compiler |
|
96 // gives errors. |
|
97 |
|
98 FUNCENTRY( CCamAppPerfTest::PerfTest ) |
|
99 |
|
100 //FUNCENTRY( CCamAppPerfTest::PrintTest ) |
|
101 //ENTRY( "Loop testzzz", CCamAppPerfTest::LoopTest ), |
|
102 // Example how to use OOM functionality |
|
103 //OOM_ENTRY( "Loop test with OOM", CCamAppPerfTest::LoopTest, ETrue, 2, 3), |
|
104 //OOM_FUNCENTRY( CCamAppPerfTest::PrintTest, ETrue, 1, 3 ), |
|
105 }; |
|
106 |
|
107 // Verify that case number is valid |
|
108 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
109 sizeof( TCaseInfoInternal ) ) |
|
110 { |
|
111 // Invalid case, construct empty object |
|
112 TCaseInfo null( (const TText*) L"" ); |
|
113 null.iMethod = NULL; |
|
114 null.iIsOOMTest = EFalse; |
|
115 null.iFirstMemoryAllocation = 0; |
|
116 null.iLastMemoryAllocation = 0; |
|
117 return null; |
|
118 } |
|
119 |
|
120 // Construct TCaseInfo object and return it |
|
121 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
122 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
123 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
124 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
125 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
126 return tmp; |
|
127 |
|
128 } |
|
129 |
|
130 |
|
131 ////////////////////////////WORKSPACE START///////////////////////////////////// |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CCamAppPerfTest::PerfTest |
|
136 // CameraApp Performance Test. |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CCamAppPerfTest::PerfTest( |
|
140 TTestResult& aResult ) |
|
141 { |
|
142 // The purpose of this performance test is just to launch the cameraapp and get |
|
143 // the related RD_SYMBIAN_TRACES. This test should never fail. |
|
144 |
|
145 /* Simple print test */ |
|
146 _LIT( KPerfTest, "PerfTest" ); |
|
147 _LIT( KEnter, "Enter" ); |
|
148 _LIT( KOnGoing, "On-going" ); |
|
149 _LIT( KExit, "Exit" ); |
|
150 |
|
151 TestModuleIf().Printf( 0, KPerfTest, KEnter ); |
|
152 TestModuleIf().Printf( 1, KPerfTest, KOnGoing ); |
|
153 |
|
154 //////////////////////////////////////////////////////////////////////// |
|
155 |
|
156 // Start test |
|
157 RDebug::Print( _L( "[cam launcher] in" ) ); |
|
158 |
|
159 |
|
160 RDebug::Print( _L( "[cam launcher] ECPCloseCheck" )); |
|
161 // make sure camera app is closed |
|
162 KillIfAlive(); |
|
163 // announce that we are sure camera is closed, |
|
164 // and now we can start testing |
|
165 StartWaiting( 5000000 ); // 5 seconds |
|
166 |
|
167 |
|
168 RDebug::Print( _L( "[cam launcher] ECPTestStart" )); |
|
169 // launch first instance of camera app |
|
170 RProcess process; |
|
171 process.Create(_L("cameraapp.exe"), _L("PerformanceTest")); |
|
172 RDebug::Print( _L( "[cam launcher] resuming" ) ); |
|
173 process.Resume(); |
|
174 RDebug::Print( _L( "[cam launcher] resumed" ) ); |
|
175 // announce that we are waiting for the first startup to finish |
|
176 StartWaiting( 15000000 ); // 15 seconds |
|
177 |
|
178 |
|
179 RDebug::Print( _L( "[cam launcher] ECPTestWaitFirstStartupFinished" )); |
|
180 // fake the capture key event |
|
181 SendCaptureKeyEventToCamApp(); |
|
182 // announce that we are waiting for the first capture to finish |
|
183 StartWaiting( 10000000 ); // 10 seconds |
|
184 |
|
185 |
|
186 RDebug::Print( _L( "[cam launcher] ECPTestWaitFirstCaptureFinished" )); |
|
187 // fake the red end key event |
|
188 SendExitKeyEventToCamApp(); |
|
189 // announce that we are waiting for the first close to finish |
|
190 StartWaiting( 15000000 ); // 15 seconds |
|
191 |
|
192 |
|
193 RDebug::Print( _L( "[cam launcher] ECPTestSecondStartup" )); |
|
194 // launch second instance of camera app |
|
195 RProcess process2; |
|
196 process2.Create(_L("cameraapp.exe"), _L("CameraPerformanceTest")); |
|
197 RDebug::Print( _L( "[cam launcher] resuming" ) ); |
|
198 process2.Resume(); |
|
199 RDebug::Print( _L( "[cam launcher] resumed" ) ); |
|
200 // announce that we are waiting for the second startup to finish |
|
201 StartWaiting( 15000000 ); // 15 seconds |
|
202 |
|
203 |
|
204 RDebug::Print( _L( "[cam launcher] ECPTestWaitSecondStartupFinished" )); |
|
205 // fake the capture key event |
|
206 SendCaptureKeyEventToCamApp(); |
|
207 // announce that we are waiting for the second capture to finish |
|
208 StartWaiting( 10000000 ); // 10 seconds |
|
209 |
|
210 |
|
211 RDebug::Print( _L( "[cam launcher] ECPTestWaitFirstCaptureFinished" )); |
|
212 // fake the red end key event |
|
213 SendExitKeyEventToCamApp(); |
|
214 // announce that we are waiting for the second close to finish |
|
215 StartWaiting( 15000000 ); // 15 seconds |
|
216 |
|
217 |
|
218 // Test done |
|
219 RDebug::Print( _L( "[cam launcher] close process" ) ); |
|
220 process.Close(); |
|
221 RDebug::Print( _L( "[cam launcher] close process2" ) ); |
|
222 process2.Close(); |
|
223 RDebug::Print( _L( "[cam launcher] out" ) ); |
|
224 |
|
225 |
|
226 //////////////////////////////////////////////////////////////////////// |
|
227 |
|
228 TestModuleIf().Printf( 0, KPerfTest, KExit ); |
|
229 |
|
230 RDebug::Print( _L( "[cam launcher] final" ) ); |
|
231 |
|
232 // Test case passed |
|
233 // This test should never fail. |
|
234 |
|
235 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
236 _LIT( KDescription, "PerfTest passed" ); |
|
237 aResult.SetResult( KErrNone, KDescription ); |
|
238 |
|
239 // Case was executed |
|
240 return KErrNone; |
|
241 |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CCamAppPerfTest::StartWaiting( TInt period ) |
|
250 { |
|
251 RDebug::Print( _L( "[cam launcher]::StartWaiting in" ) ); |
|
252 User::After( period ); |
|
253 RDebug::Print( _L( "[cam launcher]::StartWaiting out" ) ); |
|
254 } |
|
255 |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CCamAppPerfTest::KillIfAlive() |
|
262 { |
|
263 RDebug::Print( _L( "[cam launcher]::KillIfAlive in" ) ); |
|
264 |
|
265 RApaLsSession RSession; |
|
266 TInt AAppCount = 0;//get the number of applications |
|
267 RSession.Connect(); |
|
268 RSession.AppCount(AAppCount);//number of tasks |
|
269 RSession.GetAllApps();//get all the tasks in the RApaLsSession obj |
|
270 |
|
271 RDebug::Print( _L( "[cam launcher]::KillIfAlive test-> KCamAppName=%S" ), |
|
272 &KCamAppName ); |
|
273 |
|
274 |
|
275 if(AAppCount > 0) |
|
276 { |
|
277 RDebug::Print( _L( "[cam launcher]::KillIfAlive there are apps, count=%d" ),AAppCount ); |
|
278 //if the task is present get info about it in AppInfo |
|
279 TApaAppInfo AppInfo; |
|
280 |
|
281 RDebug::Print( _L( "[cam launcher]::KillIfAlive making CCoeEnv" ) ); |
|
282 CCoeEnv* coeEnv = new (ELeave) CCoeEnv(); |
|
283 RDebug::Print( _L( "[cam launcher]::KillIfAlive made CCoeEnv" ) ); |
|
284 |
|
285 TRAPD(coeEnvErr, |
|
286 { |
|
287 RDebug::Print( _L( "[cam launcher]::KillIfAlive constructing CCoeEnv" ) ); |
|
288 coeEnv->ConstructL(); |
|
289 RDebug::Print( _L( "[cam launcher]::KillIfAlive getting WsSession from CCoeEnv" ) ); |
|
290 TApaTaskList aList(coeEnv->WsSession()); |
|
291 RDebug::Print( _L( "[cam launcher]::KillIfAlive got WsSession from CCoeEnv" ) ); |
|
292 |
|
293 for(TInt i=0;i<AAppCount;i++) |
|
294 { |
|
295 RSession.GetNextApp(AppInfo); |
|
296 TApaTask ATask3 = aList.FindApp(AppInfo.iUid); |
|
297 |
|
298 if ( AppInfo.iFullName.Compare( KCamAppName ) == 0 ) |
|
299 { |
|
300 RDebug::Print( _L( "[cam launcher]::KillIfAlive KCamAppName MATCH" ) ); |
|
301 |
|
302 if(ATask3.Exists()) |
|
303 { |
|
304 // if the camera is in standby mode, then... |
|
305 // the task exists, so now we try to close it |
|
306 RDebug::Print( _L( "[cam launcher]::KillIfAlive task exists.. uid=%d name=%S" ), |
|
307 AppInfo.iUid, |
|
308 &(AppInfo.iFullName) ); |
|
309 |
|
310 // kill the task |
|
311 ATask3.KillTask(); |
|
312 RDebug::Print( _L( "[cam launcher]::KillIfAlive task killed" ) ); |
|
313 } |
|
314 } |
|
315 } // for |
|
316 }); // TRAPD |
|
317 RDebug::Print( _L( "[cam launcher]::KillIfAlive coeEnvErr=%d" ),coeEnvErr ); |
|
318 coeEnv->DestroyEnvironment(); |
|
319 RDebug::Print( _L( "[cam launcher]::KillIfAlive coeEnv destroyed" ) ); |
|
320 |
|
321 } // if |
|
322 |
|
323 RSession.Close(); |
|
324 |
|
325 RDebug::Print( _L( "[cam launcher]::KillIfAlive out" ) ); |
|
326 } |
|
327 |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CCamAppPerfTest::SendCaptureKeyEventToCamApp() |
|
334 { |
|
335 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp in" ) ); |
|
336 |
|
337 TKeyEvent keyEvent; |
|
338 keyEvent.iCode = 0; |
|
339 keyEvent.iScanCode = EProductKeyCapture; |
|
340 keyEvent.iModifiers = 0; |
|
341 keyEvent.iRepeats = 0; |
|
342 TWsEvent wsEvent; |
|
343 *(wsEvent.Key()) = keyEvent; |
|
344 wsEvent.SetType(EEventKeyDown); |
|
345 wsEvent.SetTimeNow(); |
|
346 |
|
347 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp making CCoeEnv" ) ); |
|
348 CCoeEnv* coeEnv = new (ELeave) CCoeEnv(); |
|
349 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp made CCoeEnv" ) ); |
|
350 |
|
351 TRAPD(coeEnvErr, |
|
352 { |
|
353 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp constructing CCoeEnv" ) ); |
|
354 coeEnv->ConstructL(); |
|
355 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp getting WsSession from CCoeEnv" ) ); |
|
356 coeEnv->WsSession().SendEventToWindowGroup(coeEnv->WsSession().GetFocusWindowGroup(), wsEvent); |
|
357 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp got WsSession from CCoeEnv" ) ); |
|
358 }); // TRAPD |
|
359 |
|
360 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp coeEnvErr=%d" ),coeEnvErr ); |
|
361 coeEnv->DestroyEnvironment(); |
|
362 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp coeEnv destroyed" ) ); |
|
363 |
|
364 RDebug::Print( _L( "[cam launcher]::SendCaptureKeyEventToCamApp out" ) ); |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CCamAppPerfTest::SendExitKeyEventToCamApp() |
|
373 { |
|
374 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp in" ) ); |
|
375 |
|
376 TKeyEvent keyEvent; |
|
377 keyEvent.iCode = 0; |
|
378 keyEvent.iScanCode = EStdKeyNo; |
|
379 keyEvent.iModifiers = 0; |
|
380 keyEvent.iRepeats = 0; |
|
381 TWsEvent wsEvent; |
|
382 *(wsEvent.Key()) = keyEvent; |
|
383 wsEvent.SetType(EEventKeyDown); |
|
384 wsEvent.SetTimeNow(); |
|
385 |
|
386 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp making CCoeEnv" ) ); |
|
387 CCoeEnv* coeEnv = new (ELeave) CCoeEnv(); |
|
388 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp made CCoeEnv" ) ); |
|
389 |
|
390 TRAPD(coeEnvErr, |
|
391 { |
|
392 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp constructing CCoeEnv" ) ); |
|
393 coeEnv->ConstructL(); |
|
394 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp getting WsSession from CCoeEnv" ) ); |
|
395 coeEnv->WsSession().SendEventToWindowGroup(coeEnv->WsSession().GetFocusWindowGroup(), wsEvent); |
|
396 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp got WsSession from CCoeEnv" ) ); |
|
397 }); // TRAPD |
|
398 |
|
399 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp coeEnvErr=%d" ),coeEnvErr ); |
|
400 coeEnv->DestroyEnvironment(); |
|
401 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp coeEnv destroyed" ) ); |
|
402 |
|
403 RDebug::Print( _L( "[cam launcher]::SendExitKeyEventToCamApp out" ) ); |
|
404 } |
|
405 |
|
406 |
|
407 ////////////////////////////WORKSPACE END/////////////////////////////////////// |
|
408 |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CCamAppPerfTest::PrintTest |
|
412 // Simple printing to UI test. |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 TInt CCamAppPerfTest::PrintTest( |
|
416 TTestResult& aResult ) |
|
417 { |
|
418 /* Simple print test */ |
|
419 _LIT( KPrintTest, "PrintTest" ); |
|
420 _LIT( KEnter, "Enter" ); |
|
421 _LIT( KOnGoing, "On-going" ); |
|
422 _LIT( KExit, "Exit" ); |
|
423 |
|
424 TestModuleIf().Printf( 0, KPrintTest, KEnter ); |
|
425 |
|
426 TestModuleIf().Printf( 1, KPrintTest, KOnGoing ); |
|
427 |
|
428 TestModuleIf().Printf( 0, KPrintTest, KExit ); |
|
429 |
|
430 // Test case passed |
|
431 |
|
432 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
433 _LIT( KDescription, "PrintTest passed" ); |
|
434 aResult.SetResult( KErrNone, KDescription ); |
|
435 |
|
436 // Case was executed |
|
437 return KErrNone; |
|
438 |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CCamAppPerfTest::LoopTest |
|
443 // Another printing to UI test. |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 TInt CCamAppPerfTest::LoopTest( TTestResult& aResult ) |
|
447 { |
|
448 |
|
449 /* Simple print and wait loop */ |
|
450 _LIT( KState, "State" ); |
|
451 _LIT( KLooping, "Looping" ); |
|
452 |
|
453 TestModuleIf().Printf( 0, KState, KLooping ); |
|
454 |
|
455 _LIT( KRunning, "Running" ); |
|
456 _LIT( KLoop, "%d" ); |
|
457 for( TInt i=0; i<10; i++) |
|
458 { |
|
459 TestModuleIf().Printf( 1, KRunning, KLoop, i); |
|
460 User::After( 1000000 ); |
|
461 } |
|
462 |
|
463 _LIT( KFinished, "Finished" ); |
|
464 TestModuleIf().Printf( 0, KState, KFinished ); |
|
465 |
|
466 // Test case passed |
|
467 |
|
468 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
469 _LIT( KDescription, "LoopTest passed" ); |
|
470 aResult.SetResult( KErrNone, KDescription ); |
|
471 |
|
472 // Case was executed |
|
473 return KErrNone; |
|
474 |
|
475 } |
|
476 |
|
477 // [End of File] - do not remove |