1 /* |
|
2 * Copyright (c) 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: Class definition of CDiagExecPlanEntryImplTest |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS DECLARATION |
|
20 #include "diagexecplanentryimpltest.h" |
|
21 |
|
22 // SYSTEM INCLUDE FILES |
|
23 #include <DiagPlugin.h> // MDiagPlugin |
|
24 #include <DiagTestPlugin.h> // MDiagTestPlugin |
|
25 #include <DiagFrameworkDebug.h> // LOGSTRING |
|
26 #include <DiagResultsDbItemBuilder.h> // CDiagResultsDbItemBuilder |
|
27 #include <DiagTestExecParam.h> // TDiagTestExecParam |
|
28 #include <DiagResultsDatabase.h> // RDiagResultsDatabaseRecord |
|
29 |
|
30 // USER INCLUDE FILES |
|
31 #include "diagframework.pan" // Panic Codes |
|
32 #include "diagexecplanentryimplobserver.h" // MDiagExecPlanEntryImplObserver |
|
33 #include "diagengineconfig.h" // TDiagEngineConfig |
|
34 |
|
35 |
|
36 // DATA |
|
37 |
|
38 // MACROS |
|
39 |
|
40 // LOCAL DATA TYPES |
|
41 |
|
42 |
|
43 // ======== LOCAL FUNCTIONS ======== |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CDiagExecPlanEntryImplTest::NewL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CDiagExecPlanEntryImplTest* CDiagExecPlanEntryImplTest::NewL( |
|
52 MDiagEngineCommon& aEngine, |
|
53 const TDiagEngineConfig& aEngineConfig, |
|
54 MDiagExecPlanEntryImplObserver& aObserver, |
|
55 MDiagTestPlugin& aPlugin, |
|
56 TBool aAsDependency, |
|
57 CDiagResultsDatabaseItem::TResult aResult ) |
|
58 { |
|
59 CDiagExecPlanEntryImplTest* self = NewLC( aEngine, |
|
60 aEngineConfig, |
|
61 aObserver, |
|
62 aPlugin, |
|
63 aAsDependency, |
|
64 aResult ); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CDiagExecPlanEntryImplTest::NewLC |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CDiagExecPlanEntryImplTest* CDiagExecPlanEntryImplTest::NewLC( |
|
74 MDiagEngineCommon& aEngine, |
|
75 const TDiagEngineConfig& aEngineConfig, |
|
76 MDiagExecPlanEntryImplObserver& aObserver, |
|
77 MDiagTestPlugin& aPlugin, |
|
78 TBool aAsDependency, |
|
79 CDiagResultsDatabaseItem::TResult aResult ) |
|
80 { |
|
81 CDiagExecPlanEntryImplTest* self = |
|
82 new ( ELeave ) CDiagExecPlanEntryImplTest ( aEngine, |
|
83 aEngineConfig, |
|
84 aObserver, |
|
85 aPlugin, |
|
86 aAsDependency, |
|
87 aResult ); |
|
88 CleanupStack::PushL( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CDiagExecPlanEntryImplTest::CDiagExecPlanEntryImplTest |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 CDiagExecPlanEntryImplTest::CDiagExecPlanEntryImplTest( |
|
98 MDiagEngineCommon& aEngine, |
|
99 const TDiagEngineConfig& aEngineConfig, |
|
100 MDiagExecPlanEntryImplObserver& aObserver, |
|
101 MDiagTestPlugin& aPlugin, |
|
102 TBool aAsDependency, |
|
103 CDiagResultsDatabaseItem::TResult aResult ) |
|
104 : CDiagExecPlanEntryImpl( |
|
105 aEngine, |
|
106 aEngineConfig, |
|
107 aObserver, |
|
108 aPlugin, |
|
109 aAsDependency, |
|
110 ETypeTestExec ), |
|
111 iResult( aResult ) |
|
112 { |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CDiagExecPlanEntryImplTest::~CDiagExecPlanEntryImplTest |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CDiagExecPlanEntryImplTest::~CDiagExecPlanEntryImplTest() |
|
120 { |
|
121 StopAll(); // deletes timer as well. |
|
122 if ( CDiagExecPlanEntryImpl::State() != EStateCompleted ) |
|
123 { |
|
124 // TRAP is needed since this is being called in destructor. |
|
125 TRAP_IGNORE( StopExecutionAndIgnoreResultL() ) |
|
126 } |
|
127 delete iCachedResult; |
|
128 iCachedResult = NULL; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CDiagExecPlanEntryImplTest::Result |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 CDiagResultsDatabaseItem::TResult CDiagExecPlanEntryImplTest::Result() const |
|
136 { |
|
137 return iResult; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CDiagExecPlanEntryImplTest::SetResult |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CDiagExecPlanEntryImplTest::SetResult( CDiagResultsDatabaseItem::TResult aResult ) |
|
145 { |
|
146 iResult = aResult; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CDiagExecPlanEntryImplTest::TestPlugin |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 MDiagTestPlugin& CDiagExecPlanEntryImplTest::TestPlugin() |
|
154 { |
|
155 // It is safe to typecast here, since CDiagExecPlanEntryImplTest::NewL |
|
156 // accepts only MDiagTestPlugin&. |
|
157 return static_cast< MDiagTestPlugin& >( Plugin() ); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // From CDiagExecPlanEntryImpl |
|
162 // CDiagExecPlanEntryImplTest::ExecuteL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CDiagExecPlanEntryImplTest::ExecuteL() |
|
166 { |
|
167 #ifdef _DEBUG |
|
168 HBufC* pluginName = Plugin().GetPluginNameL( |
|
169 MDiagPlugin::ENameLayoutListSingle ); |
|
170 |
|
171 LOGSTRING3( "---- TEST BEGIN ---- [ 0x%08x %S ] ---- TEST BEGIN ---- {", |
|
172 Plugin().Uid().iUid, |
|
173 pluginName ) |
|
174 delete pluginName; |
|
175 pluginName = NULL; |
|
176 #endif // _DEBUG |
|
177 |
|
178 __ASSERT_DEBUG( State() == EStateQueued, |
|
179 Panic( EDiagFrameworkCorruptStateMachine ) ); |
|
180 |
|
181 |
|
182 // Case 1) Item was already executed. (Resume scenario) |
|
183 // Just go straight to EStateCompleted and let engine know that |
|
184 // it was completed. |
|
185 if ( Result() != CDiagResultsDatabaseItem::EQueuedToRun ) |
|
186 { |
|
187 // it was already executed. Report result immediately. |
|
188 ChangeStateL( EStateCompleted ); |
|
189 Observer().ExecPlanEntryExecutedL( *this ); |
|
190 return; |
|
191 } |
|
192 |
|
193 // Notify observer that progress is 0 so that application will know that |
|
194 // plug-in execution has now started. |
|
195 Observer().ExecPlanEntryProgressL( *this, 0, TestPlugin().TotalSteps() ); |
|
196 |
|
197 // Case 2) Initial delay was specified. Start delay timer. |
|
198 if ( EngineConfig().TestPluginInitialDelay().Int() > 0 ) |
|
199 { |
|
200 // timer value is specified. Start timer. |
|
201 ChangeStateL( EStateInitDelay ); |
|
202 StopInitDelayTimer(); |
|
203 iInitDelayTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
204 iInitDelayTimer->Start( EngineConfig().TestPluginInitialDelay(), // initial delay |
|
205 EngineConfig().TestPluginInitialDelay(), // repeat |
|
206 TCallBack( HandleDelayTimerExpiredL, this ) ); |
|
207 |
|
208 return; |
|
209 } |
|
210 |
|
211 // Case 3) Start test immediately. |
|
212 DoExecuteTestPluginL(); |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CDiagExecPlanEntryImplTest::DoExecuteTestPluginL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CDiagExecPlanEntryImplTest::DoExecuteTestPluginL() |
|
222 { |
|
223 #ifdef _DEBUG |
|
224 HBufC* pluginName = Plugin().GetPluginNameL( |
|
225 MDiagPlugin::ENameLayoutListSingle ); |
|
226 |
|
227 LOGSTRING3( "CDiagExecPlanEntryImplTest::DoExecuteTestPluginL() " |
|
228 L"Starting test plugin Uid 0x%x (%S)", |
|
229 Plugin().Uid().iUid, |
|
230 pluginName ) |
|
231 delete pluginName; |
|
232 pluginName = NULL; |
|
233 #endif // _DEBUG |
|
234 |
|
235 // Real test starts now, so reset watchdog timer. |
|
236 if ( TestPlugin().RunMode() == MDiagTestPlugin::EAutomatic ) |
|
237 { |
|
238 ResetWatchdog( EDiagEngineWatchdogTypeAutomatic ); |
|
239 } |
|
240 else |
|
241 { |
|
242 ResetWatchdog( EDiagEngineWatchdogTypeInteractive ); |
|
243 } |
|
244 |
|
245 ChangeStateL( EStateRunning ); |
|
246 |
|
247 |
|
248 // Create a result in case test fails during RunTestL(). |
|
249 // It needs to be created at this point to make sure that |
|
250 // test start time is recorded correctly, since RunTestL() may |
|
251 // take some time to finish. |
|
252 CDiagResultsDbItemBuilder* resultBuilder = |
|
253 CDiagResultsDbItemBuilder::NewLC( Plugin().Uid(), AsDependency() ); |
|
254 |
|
255 TDiagTestExecParam* execParam = |
|
256 new ( ELeave ) TDiagTestExecParam( *this, // aObserver |
|
257 Engine() /* aEngine */ ); |
|
258 |
|
259 // Trap when calling test. This makes sure that if a test fails during |
|
260 // its RunTestL(), it will automatically be marked as failed. |
|
261 TRAPD( err, TestPlugin().RunTestL( execParam, // ownership changed |
|
262 Engine().IsDependencyDisabled(), |
|
263 AsDependency(), |
|
264 Engine().CustomParam() ) ); |
|
265 execParam = NULL; //lint !e423 execParam ownership changed. |
|
266 |
|
267 if ( err != KErrNone ) |
|
268 { |
|
269 // Test failure. Call stop plug-in so that it may have a chance to |
|
270 // clean up, but result is not needed. Discard it and replace it with |
|
271 // CDiagResultsDatabaseItem::EFailed |
|
272 LOGSTRING2( "CDiagExecPlanEntryImplTest::DoExecuteTestPluginL() " |
|
273 L"RunTestL() for 0x%08x failed! Mark it as FAILED and continue", |
|
274 Plugin().Uid().iUid ) |
|
275 |
|
276 StopExecutionAndIgnoreResultL(); |
|
277 resultBuilder->SetTestCompleted( CDiagResultsDatabaseItem::EFailed ); |
|
278 |
|
279 CDiagResultsDatabaseItem* result = resultBuilder->ToResultsDatabaseItemL(); |
|
280 |
|
281 // Call test execution observer as if the real test is completed. |
|
282 TestExecutionCompletedL( TestPlugin(), result ); |
|
283 result = NULL; // ownership transferred above. |
|
284 } |
|
285 |
|
286 CleanupStack::PopAndDestroy( resultBuilder ); |
|
287 resultBuilder = NULL; |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // From MDiagTestObserver |
|
292 // CDiagExecPlanEntryImplTest::TestProgressL |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CDiagExecPlanEntryImplTest::TestProgressL( |
|
296 const MDiagTestPlugin& aSender, |
|
297 TUint aCurrentStep ) |
|
298 { |
|
299 __ASSERT_ALWAYS( aSender.Uid() == Plugin().Uid(), Panic( EDiagFrameworkPlugin ) ); |
|
300 __ASSERT_ALWAYS( aCurrentStep <= TestPlugin().TotalSteps(), Panic( EDiagFrameworkPlugin ) ); |
|
301 |
|
302 // TestExecutionProgressL is accepted only if we were running. |
|
303 if ( State() != EStateRunning ) |
|
304 { |
|
305 __ASSERT_DEBUG( 0, Panic( EDiagFrameworkCorruptStateMachine ) ); |
|
306 return; |
|
307 } |
|
308 |
|
309 ResetWatchdog(); |
|
310 Observer().ExecPlanEntryProgressL( *this, aCurrentStep, TestPlugin().TotalSteps() ); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // From MDiagTestObserver |
|
315 // CDiagExecPlanEntryImplTest::TestExecutionCompletedL |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 void CDiagExecPlanEntryImplTest::TestExecutionCompletedL( |
|
319 const MDiagTestPlugin& aSender, |
|
320 CDiagResultsDatabaseItem* aTestResult ) |
|
321 { |
|
322 __ASSERT_ALWAYS( aSender.Uid() == Plugin().Uid(), Panic( EDiagFrameworkPlugin ) ); |
|
323 __ASSERT_ALWAYS( aTestResult, Panic( EDiagFrameworkNullTestResult ) ); |
|
324 |
|
325 // TestExecutionCompletedL is accepted only if we were running. |
|
326 if ( State() == EStateCompleted ) |
|
327 { |
|
328 __ASSERT_DEBUG( 0, Panic( EDiagFrameworkCorruptStateMachine ) ); |
|
329 return; |
|
330 } |
|
331 |
|
332 // For view-switching plugins, ask the application to switch the view |
|
333 // back. This allows the application to be in a known state. This must |
|
334 // be done before logging the test result, because that may fail. |
|
335 if ( TestPlugin().RunMode() == MDiagTestPlugin::EInteractiveView ) |
|
336 { |
|
337 TRAP_IGNORE( Engine().ExecuteAppCommandL( |
|
338 EDiagAppCommandSwitchToMainView, |
|
339 NULL, |
|
340 NULL ) ) |
|
341 } |
|
342 // Writing to db is a non interactive step. |
|
343 ResetWatchdog( EDiagEngineWatchdogTypeAutomatic ); |
|
344 ChangeStateL( EStateStopped ); |
|
345 |
|
346 |
|
347 // update cache. Cached result will be available until ResultsDbItem() |
|
348 // is called. |
|
349 delete iCachedResult; |
|
350 iCachedResult = aTestResult; |
|
351 aTestResult = NULL; |
|
352 |
|
353 iResult = iCachedResult->TestResult(); |
|
354 |
|
355 Engine().DbRecord().LogTestResult( iStatus, *iCachedResult ); |
|
356 SetActive(); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // From CActive |
|
361 // CDiagExecPlanEntryImplTest::RunL |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void CDiagExecPlanEntryImplTest::RunL() |
|
365 { |
|
366 // Currently, this object only uses one request, which is |
|
367 // Engine().DbRecord().LogTestResult(), which is sent only when state is |
|
368 // EStateStopped |
|
369 User::LeaveIfError( iStatus.Int() ); |
|
370 |
|
371 ChangeStateL( EStateCompleted ); |
|
372 |
|
373 #ifdef _DEBUG |
|
374 HBufC* pluginName = Plugin().GetPluginNameL( |
|
375 MDiagPlugin::ENameLayoutListSingle ); |
|
376 |
|
377 LOGSTRING4( "} ---- TEST END ---- [ 0x%08x %S %S ] ---- TEST END ----", |
|
378 Plugin().Uid().iUid, |
|
379 pluginName, |
|
380 &TestResultString( iResult ) ) |
|
381 |
|
382 delete pluginName; |
|
383 pluginName = NULL; |
|
384 #endif // _DEBUG |
|
385 |
|
386 // Notify engine that test is completed. |
|
387 Observer().ExecPlanEntryExecutedL( *this ); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // From CActive |
|
392 // CDiagExecPlanEntryImplTest::DoCancel |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CDiagExecPlanEntryImplTest::DoCancel() |
|
396 { |
|
397 // Currently, DbRecord().LogTestResult() is the only request this uses. |
|
398 Engine().DbRecord().CancelLogTestResult(); |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // From CActive |
|
403 // CDiagExecPlanEntryImplTest::RunError |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 TInt CDiagExecPlanEntryImplTest::RunError( TInt aError ) |
|
407 { |
|
408 Observer().ExecPlanEntryCriticalError( aError ); |
|
409 return KErrNone; |
|
410 } |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // CDiagExecPlanEntryImplTest::StopExecutionByWatchdogL |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CDiagExecPlanEntryImplTest::StopExecutionByWatchdogL() |
|
417 { |
|
418 CDiagResultsDatabaseItem* result = StopTestPluginL( MDiagTestPlugin::EWatchdog ); |
|
419 |
|
420 if ( result == NULL ) |
|
421 { |
|
422 // It was not originally running, so no real result. Create |
|
423 // a default that makes sense. |
|
424 result = CDiagResultsDbItemBuilder::CreateSimpleDbItemL( |
|
425 Plugin().Uid(), |
|
426 AsDependency(), |
|
427 CDiagResultsDatabaseItem::EWatchdogCancel ); |
|
428 } |
|
429 |
|
430 TestExecutionCompletedL( TestPlugin(), result ); // ownership transferred. |
|
431 result = NULL; |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------------------------- |
|
435 // CDiagExecPlanEntryImplTest::DoStopExecutionByClientL |
|
436 // --------------------------------------------------------------------------- |
|
437 // |
|
438 void CDiagExecPlanEntryImplTest::DoStopExecutionByClientL( |
|
439 MDiagEngineCommon::TCancelMode aCancelMode ) |
|
440 { |
|
441 MDiagTestPlugin::TStopReason stopReason; |
|
442 |
|
443 switch ( aCancelMode ) |
|
444 { |
|
445 case MDiagEngineCommon::ECancelAll: |
|
446 stopReason = MDiagTestPlugin::ECancelAll; |
|
447 break; |
|
448 |
|
449 case MDiagEngineCommon::ESkip: |
|
450 stopReason = MDiagTestPlugin::ESkip; |
|
451 break; |
|
452 |
|
453 default: |
|
454 __ASSERT_DEBUG( 0, Panic( EDiagFrameworkInternal ) ); |
|
455 stopReason = MDiagTestPlugin::ESkip; |
|
456 break; |
|
457 } |
|
458 |
|
459 CDiagResultsDatabaseItem* result = StopTestPluginL( stopReason ); |
|
460 |
|
461 if ( result == NULL ) |
|
462 { |
|
463 // it was not originally running, so no result was given by |
|
464 // the plugin. Create one for them. |
|
465 result = CDiagResultsDbItemBuilder::CreateSimpleDbItemL( |
|
466 Plugin().Uid(), |
|
467 AsDependency(), |
|
468 CDiagResultsDatabaseItem::ESkipped ); |
|
469 } |
|
470 |
|
471 TestExecutionCompletedL( TestPlugin(), result ); // ownership transferred. |
|
472 result = NULL; |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------------------------- |
|
476 // CDiagExecPlanEntryImplTest::StopExecutionAndIgnoreResultL |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 void CDiagExecPlanEntryImplTest::StopExecutionAndIgnoreResultL() |
|
480 { |
|
481 CDiagResultsDatabaseItem* result = StopTestPluginL( MDiagTestPlugin::ESkip ); |
|
482 delete result; |
|
483 } |
|
484 |
|
485 // --------------------------------------------------------------------------- |
|
486 // CDiagExecPlanEntryImplTest::StopTestPluginL |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 CDiagResultsDatabaseItem* CDiagExecPlanEntryImplTest::StopTestPluginL( |
|
490 MDiagTestPlugin::TStopReason aReason ) |
|
491 { |
|
492 StopAll(); |
|
493 |
|
494 CDiagResultsDatabaseItem* result = NULL; |
|
495 |
|
496 switch ( State() ) |
|
497 { |
|
498 case EStateQueued: // fall through |
|
499 case EStateInitDelay: |
|
500 // Test was not actually running in these casese. |
|
501 LOGSTRING3( "CDiagExecPlanEntryImplTest::StopTestPluginL()" |
|
502 L"Plugin 0x%x. State = %d", |
|
503 Plugin().Uid().iUid, |
|
504 State() ) |
|
505 break; |
|
506 |
|
507 case EStateStopped: |
|
508 // Test was already completed. Return last result. |
|
509 LOGSTRING3( "CDiagExecPlanEntryImplTest::StopTestPluginL()" |
|
510 L"Plugin 0x%x. State = %d", |
|
511 Plugin().Uid().iUid, |
|
512 State() ) |
|
513 result = GetLastTestResultL(); |
|
514 break; |
|
515 |
|
516 case EStateRunning: // fall through |
|
517 case EStateSuspended: |
|
518 // Test was actually running in this case. |
|
519 // Need to call execution stop and use result from plug-in. |
|
520 LOGSTRING2( "CDiagEngineImpl::StopTestPluginL: " |
|
521 L"Plugin 0x%x was in ERunning or ESuspended. Call Stop", |
|
522 Plugin().Uid().iUid ) |
|
523 result = TestPlugin().ExecutionStopL( aReason ); |
|
524 __ASSERT_ALWAYS( result, Panic( EDiagFrameworkNullTestResult ) ); |
|
525 break; |
|
526 |
|
527 case EStateCompleted: |
|
528 default: |
|
529 LOGSTRING3( "CDiagEngineImpl::StopTestPluginL: " |
|
530 L"Plugin 0x%x = INVALID STATE! %d", |
|
531 Plugin().Uid().iUid, |
|
532 State() ) |
|
533 __ASSERT_DEBUG( 0, Panic( EDiagFrameworkCorruptStateMachine ) ); |
|
534 |
|
535 // Use result from cache or DB. |
|
536 result = GetLastTestResultL(); |
|
537 break; |
|
538 } |
|
539 |
|
540 return result; |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------------------------- |
|
544 // CDiagExecPlanEntryImplTest::SuspendL |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 void CDiagExecPlanEntryImplTest::SuspendL() |
|
548 { |
|
549 StopAll(); |
|
550 |
|
551 switch ( State() ) |
|
552 { |
|
553 case EStateQueued: // fall through |
|
554 case EStateInitDelay: // fall through |
|
555 // nothing to do. |
|
556 LOGSTRING3( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
557 L"Plugin 0x%08x state = %d. Was not running. Change to EQueued", |
|
558 Plugin().Uid().iUid, |
|
559 State() ) |
|
560 |
|
561 ChangeStateL( EStateQueued ); |
|
562 break; |
|
563 |
|
564 case EStateRunning: |
|
565 { |
|
566 // it is currently running. suspend |
|
567 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
568 L"Plugin 0x%08x = ERunning. Trying to stop", |
|
569 Plugin().Uid().iUid ) |
|
570 TRAPD( err, TestPlugin().SuspendL() ) |
|
571 if ( err == KErrNone ) |
|
572 { |
|
573 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
574 L"Plugin 0x%08x Stop successful. To ESuspended", |
|
575 Plugin().Uid().iUid ) |
|
576 |
|
577 ChangeStateL( EStateSuspended ); |
|
578 } |
|
579 else |
|
580 { |
|
581 // Suspend probably not supported. Try Stop |
|
582 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
583 L"Plugin 0x%x Stop not successful. Try to Stop", |
|
584 Plugin().Uid().iUid ) |
|
585 |
|
586 CDiagResultsDatabaseItem* result = |
|
587 TestPlugin().ExecutionStopL( MDiagTestPlugin::ESkip ); |
|
588 __ASSERT_ALWAYS( result, Panic( EDiagFrameworkNullTestResult ) ); |
|
589 delete result; // not interested in result. |
|
590 // force reset the plugin execution to queued so that |
|
591 // it will be restarted |
|
592 ChangeStateL( EStateQueued ); |
|
593 } |
|
594 } |
|
595 break; |
|
596 |
|
597 case EStateStopped: |
|
598 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
599 L"Plugin 0x%08x = EStateStopped. Do nothing.", |
|
600 Plugin().Uid().iUid ) |
|
601 // do nothing, When resumed, it will store temporary result to db |
|
602 break; |
|
603 |
|
604 case EStateSuspended: |
|
605 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
606 L"Plugin 0x%08x = ESuspended. Already suspended..", |
|
607 Plugin().Uid().iUid ) |
|
608 // do nothing. |
|
609 break; |
|
610 |
|
611 case EStateCompleted: |
|
612 // result already logged. do nothing. |
|
613 LOGSTRING2( "CDiagExecPlanEntryImplTest::SuspendL(): " |
|
614 L"Plugin 0x%08x = ECompleted. Stay completed.", |
|
615 Plugin().Uid().iUid ) |
|
616 break; |
|
617 |
|
618 default: |
|
619 __ASSERT_DEBUG( 0, Panic( EDiagFrameworkCorruptStateMachine ) ); |
|
620 } |
|
621 } |
|
622 |
|
623 // --------------------------------------------------------------------------- |
|
624 // CDiagExecPlanEntryImplTest::ResumeL |
|
625 // --------------------------------------------------------------------------- |
|
626 // |
|
627 void CDiagExecPlanEntryImplTest::ResumeL() |
|
628 { |
|
629 LOGSTRING3( "CDiagExecPlanEntryImplTest::ResumeL(): " |
|
630 L"Plugin 0x%08x, State = %d", Plugin().Uid().iUid, State() ) |
|
631 |
|
632 // resumable states are: EStateQueued, EStateSuspended, EStateStopped |
|
633 |
|
634 switch ( State() ) |
|
635 { |
|
636 case EStateQueued: |
|
637 ExecuteL(); |
|
638 break; |
|
639 |
|
640 case EStateSuspended: |
|
641 { |
|
642 ChangeStateL( EStateRunning ); |
|
643 |
|
644 TestPlugin().ResumeL(); |
|
645 } |
|
646 break; |
|
647 |
|
648 case EStateStopped: |
|
649 { |
|
650 // There was a result not saved in DB yet. |
|
651 // If test was suspended in EStopped state, there MUST BE a |
|
652 // saved test result. |
|
653 __ASSERT_DEBUG( iCachedResult, Panic( EDiagFrameworkInternal ) ); |
|
654 |
|
655 if ( iCachedResult ) //lint !e774 Will be evaluated in non DEBUG build. |
|
656 { |
|
657 // Simulate TestExecutionCompletedL from plug-in. |
|
658 // Unset iCachedResult, since TestExecutionCompletedL() will try |
|
659 // to deallocate iCachedResult. |
|
660 CDiagResultsDatabaseItem* result = iCachedResult; |
|
661 iCachedResult = NULL; |
|
662 TestExecutionCompletedL( TestPlugin(), result ); // ownership passed |
|
663 result = NULL; |
|
664 } |
|
665 } |
|
666 break; |
|
667 |
|
668 default: |
|
669 // already running. ignored. |
|
670 break; |
|
671 } |
|
672 } |
|
673 |
|
674 |
|
675 // --------------------------------------------------------------------------- |
|
676 // CDiagExecPlanEntryImplTest::GetLastTestResultL |
|
677 // --------------------------------------------------------------------------- |
|
678 // |
|
679 CDiagResultsDatabaseItem* CDiagExecPlanEntryImplTest::GetLastTestResultL() |
|
680 { |
|
681 // Currently, cache is implemented such that calling |
|
682 // GetLastTestResultL() once after test is completed will not |
|
683 // require a request to DB. Any subsequent request will have to access |
|
684 // database. |
|
685 // |
|
686 // This should satisfy most common usage of execution plan entry. |
|
687 // It could be expanded to store for longer than that, however, it |
|
688 // may take up too much memory if there are lots of tests in the |
|
689 // execution plan. At this point, this should be sufficient. |
|
690 |
|
691 CDiagResultsDatabaseItem* result = NULL; |
|
692 |
|
693 if ( iCachedResult ) |
|
694 { |
|
695 if ( State() != EStateStopped ) |
|
696 { |
|
697 LOGSTRING2( "CDiagExecPlanEntryImplTest::GetLastTestResultL() " |
|
698 L"Plugin 0x%08x. Cache hit", |
|
699 Plugin().Uid().iUid ) |
|
700 result = iCachedResult; |
|
701 iCachedResult = NULL; |
|
702 } |
|
703 else |
|
704 { |
|
705 LOGSTRING2( "CDiagExecPlanEntryImplTest::GetLastTestResultL() " |
|
706 L"Plugin 0x%08x. Cache hit, but need to duplicate.", |
|
707 Plugin().Uid().iUid ) |
|
708 // If we were in STOPPED state, make a copy, since it |
|
709 // may not been fully written to db yet. |
|
710 // Cached copy should be deleted only after it is written to db. |
|
711 const CBufFlat* detailData = iCachedResult->DetailsData(); |
|
712 CBufFlat* detailDataCopy = NULL; |
|
713 |
|
714 if ( detailData ) |
|
715 { |
|
716 detailDataCopy = CBufFlat::NewL( detailData->Size() ); |
|
717 CleanupStack::PushL( detailDataCopy ); |
|
718 |
|
719 TPtr8 ptr = detailDataCopy->Ptr( 0 ); |
|
720 detailData->Read( 0, ptr ); |
|
721 } |
|
722 |
|
723 result = CDiagResultsDatabaseItem::NewL( |
|
724 iCachedResult->TestUid(), |
|
725 iCachedResult->WasDependency(), |
|
726 iCachedResult->TestResult(), |
|
727 iCachedResult->TimeStarted(), |
|
728 iCachedResult->TimeCompleted(), |
|
729 detailDataCopy ); |
|
730 |
|
731 if ( detailDataCopy ) |
|
732 { |
|
733 CleanupStack::Pop( detailDataCopy ); |
|
734 } |
|
735 } |
|
736 } |
|
737 else |
|
738 { |
|
739 LOGSTRING2( "CDiagExecPlanEntryImplTest::GetLastTestResultL() " |
|
740 L"Plugin 0x%08x. Cache miss", |
|
741 Plugin().Uid().iUid ) |
|
742 // result was not avaiable in cache. Fetch it from database. |
|
743 User::LeaveIfError( Engine().DbRecord().GetTestResult( Plugin().Uid(), result ) ); |
|
744 } |
|
745 |
|
746 return result; |
|
747 } |
|
748 |
|
749 // --------------------------------------------------------------------------- |
|
750 // CDiagExecPlanEntryImplTest::HandleDelayTimerExpiredL |
|
751 // --------------------------------------------------------------------------- |
|
752 // |
|
753 TInt CDiagExecPlanEntryImplTest::HandleDelayTimerExpiredL( TAny* aData ) |
|
754 { |
|
755 CDiagExecPlanEntryImplTest* self = static_cast< CDiagExecPlanEntryImplTest* >( aData ); |
|
756 |
|
757 self->StopInitDelayTimer(); |
|
758 self->DoExecuteTestPluginL(); |
|
759 return 0; |
|
760 } |
|
761 |
|
762 // --------------------------------------------------------------------------- |
|
763 // CDiagExecPlanEntryImplTest::StopAll |
|
764 // --------------------------------------------------------------------------- |
|
765 // |
|
766 void CDiagExecPlanEntryImplTest::StopAll() |
|
767 { |
|
768 Cancel(); |
|
769 StopInitDelayTimer(); |
|
770 StopWatchdogTemporarily(); |
|
771 } |
|
772 |
|
773 // --------------------------------------------------------------------------- |
|
774 // CDiagExecPlanEntryImplTest::StopInitDelayTimer |
|
775 // --------------------------------------------------------------------------- |
|
776 // |
|
777 void CDiagExecPlanEntryImplTest::StopInitDelayTimer() |
|
778 { |
|
779 if ( iInitDelayTimer ) |
|
780 { |
|
781 iInitDelayTimer->Cancel(); |
|
782 delete iInitDelayTimer; |
|
783 iInitDelayTimer = NULL; |
|
784 } |
|
785 } |
|
786 |
|
787 // --------------------------------------------------------------------------- |
|
788 // CDiagExecPlanEntryImplTest::TestResultString |
|
789 // --------------------------------------------------------------------------- |
|
790 // |
|
791 #ifdef _DEBUG |
|
792 const TDesC& CDiagExecPlanEntryImplTest::TestResultString( |
|
793 CDiagResultsDatabaseItem::TResult aResult ) |
|
794 { |
|
795 _LIT( KSuccess, "ESuccess" ); |
|
796 _LIT( KFailed, "EFailed" ); |
|
797 _LIT( KSkipped, "ESkipped" ); |
|
798 _LIT( KCancelled, "ECancelled" ); |
|
799 _LIT( KInterrupted, "EInterrupted" ); |
|
800 _LIT( KNotPerformed, "ENotPerformed" ); |
|
801 _LIT( KDependencyFailed, "EDependencyFailed" ); |
|
802 _LIT( KWatchdogCancel, "EWatchdogCancel" ); |
|
803 _LIT( KSuspended, "ESuspended" ); |
|
804 _LIT( KQueuedToRun, "EQueuedToRun" ); |
|
805 |
|
806 switch( aResult ) |
|
807 { |
|
808 case CDiagResultsDatabaseItem::ESuccess: |
|
809 return KSuccess(); |
|
810 |
|
811 case CDiagResultsDatabaseItem::EFailed: |
|
812 return KFailed(); |
|
813 |
|
814 case CDiagResultsDatabaseItem::ESkipped: |
|
815 return KSkipped(); |
|
816 |
|
817 case CDiagResultsDatabaseItem::ECancelled: |
|
818 return KCancelled(); |
|
819 |
|
820 case CDiagResultsDatabaseItem::EInterrupted: |
|
821 return KInterrupted(); |
|
822 |
|
823 case CDiagResultsDatabaseItem::ENotPerformed: |
|
824 return KNotPerformed(); |
|
825 |
|
826 case CDiagResultsDatabaseItem::EDependencyFailed: |
|
827 return KDependencyFailed(); |
|
828 |
|
829 case CDiagResultsDatabaseItem::EWatchdogCancel: |
|
830 return KWatchdogCancel(); |
|
831 |
|
832 case CDiagResultsDatabaseItem::ESuspended: |
|
833 return KSuspended(); |
|
834 |
|
835 case CDiagResultsDatabaseItem::EQueuedToRun: |
|
836 return KQueuedToRun(); |
|
837 |
|
838 default: |
|
839 _LIT( KUnknown, "* Unknown *" ); |
|
840 return KUnknown(); |
|
841 } |
|
842 } |
|
843 |
|
844 #else // #if _DEBUG |
|
845 |
|
846 // non-debug version. |
|
847 const TDesC& CDiagExecPlanEntryImplTest::TestResultString( |
|
848 CDiagResultsDatabaseItem::TResult /* aResult */ ) |
|
849 { |
|
850 _LIT( KNonDebugResultName, "?" ); |
|
851 return KNonDebugResultName(); |
|
852 } |
|
853 |
|
854 #endif // #else _DEBUG |
|
855 |
|
856 // End of File |
|
857 |
|