|
1 /* |
|
2 * Copyright (c) 2009 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: This module contains the implementation of |
|
15 * CTestThreadContainerRunner class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "TestThreadContainerRunner.h" |
|
21 #include "ThreadLogging.h" |
|
22 #include "TestThreadContainer.h" |
|
23 #include "TestServer.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 // None |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // None |
|
30 |
|
31 // CONSTANTS |
|
32 // None |
|
33 |
|
34 // MACROS |
|
35 // None |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 // None |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 // None |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 // None |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 // None |
|
48 |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ========================================= |
|
51 |
|
52 /* |
|
53 ------------------------------------------------------------------------------- |
|
54 |
|
55 Class: CTestThreadContainerRunner |
|
56 |
|
57 Method: NewL |
|
58 |
|
59 Description: NewL is first phase of two-phased constructor. |
|
60 |
|
61 NewL is first phase of two-phased constructor. |
|
62 |
|
63 Parameters: TThreadId aMainThreadId: in: Main thread id. |
|
64 CActiveScheduler* aMainThreadActiveScheduler: in: Pointer to main thread active scheduler. |
|
65 |
|
66 Return Values: Pointer to new CTestThreadContainerRunner object. |
|
67 |
|
68 Errors/Exceptions: None |
|
69 |
|
70 Status: Draft |
|
71 |
|
72 ------------------------------------------------------------------------------- |
|
73 */ |
|
74 EXPORT_C CTestThreadContainerRunner* CTestThreadContainerRunner::NewL( TThreadId aMainThreadId, |
|
75 CActiveScheduler* aMainThreadActiveScheduler ) |
|
76 { |
|
77 CTestThreadContainerRunner* self = new(ELeave) CTestThreadContainerRunner(); |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL( aMainThreadId, aMainThreadActiveScheduler ); |
|
80 CleanupStack::Pop( self ); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 /* |
|
86 ------------------------------------------------------------------------------- |
|
87 |
|
88 Class: CTestThreadContainerRunner |
|
89 |
|
90 Method: CTestThreadContainerRunner |
|
91 |
|
92 Description: Default constructor. |
|
93 |
|
94 Default constructor. |
|
95 |
|
96 Parameters: None. |
|
97 |
|
98 Return Values: None. |
|
99 |
|
100 Errors/Exceptions: None. |
|
101 |
|
102 Status: Draft |
|
103 |
|
104 ------------------------------------------------------------------------------- |
|
105 */ |
|
106 CTestThreadContainerRunner::CTestThreadContainerRunner() |
|
107 :CActive( EPriorityNormal ) |
|
108 { |
|
109 } |
|
110 |
|
111 /* |
|
112 ------------------------------------------------------------------------------- |
|
113 |
|
114 Class: CTestThreadContainerRunner |
|
115 |
|
116 Method: ~CTestThreadContainerRunner |
|
117 |
|
118 Description: Default destructor. |
|
119 |
|
120 Default destructor. |
|
121 |
|
122 Parameters: None. |
|
123 |
|
124 Return Values: None. |
|
125 |
|
126 Errors/Exceptions: None. |
|
127 |
|
128 Status: Draft |
|
129 |
|
130 ------------------------------------------------------------------------------- |
|
131 */ |
|
132 CTestThreadContainerRunner::~CTestThreadContainerRunner() |
|
133 { |
|
134 Cancel(); |
|
135 } |
|
136 |
|
137 /* |
|
138 ------------------------------------------------------------------------------- |
|
139 |
|
140 Class: CTestThreadContainerRunner |
|
141 |
|
142 Method: ConstructL |
|
143 |
|
144 Description: Second phase of two-phased constructor. |
|
145 |
|
146 Second phase of two-phased constructor. |
|
147 |
|
148 Parameters: TThreadId aMainThreadId: in: Main thread id. |
|
149 CActiveScheduler* aMainThreadActiveScheduler: in: Pointer to main thread active scheduler. |
|
150 |
|
151 Return Values: None. |
|
152 |
|
153 Errors/Exceptions: None. |
|
154 |
|
155 Status: Draft |
|
156 |
|
157 ------------------------------------------------------------------------------- |
|
158 */ |
|
159 void CTestThreadContainerRunner::ConstructL( TThreadId aMainThreadId, |
|
160 CActiveScheduler* aMainThreadActiveScheduler ) |
|
161 { |
|
162 User::LeaveIfNull( aMainThreadActiveScheduler ); |
|
163 |
|
164 iMainThreadId = aMainThreadId; |
|
165 |
|
166 iMainThreadActiveScheduler = aMainThreadActiveScheduler; |
|
167 aMainThreadActiveScheduler->Add( this ); |
|
168 |
|
169 iOperationOngoing.CreateLocal( 0 ); |
|
170 |
|
171 iTestThreadContainer = NULL; |
|
172 iCurrentOperation = ENone; |
|
173 } |
|
174 |
|
175 /* |
|
176 ------------------------------------------------------------------------------- |
|
177 |
|
178 Class: CTestThreadContainerRunner |
|
179 |
|
180 Method: Setup |
|
181 |
|
182 Description: Emulates setup part of CTestThreadContainer::ExecutionThread method |
|
183 |
|
184 Setup is performed in main thread. |
|
185 |
|
186 Parameters: CTestModuleContainer* aTestModuleContainer: in: Pointer to test CTestModuleContainer |
|
187 |
|
188 Return Values: None. |
|
189 |
|
190 Errors/Exceptions: None. |
|
191 |
|
192 Status: Draft |
|
193 |
|
194 ------------------------------------------------------------------------------- |
|
195 */ |
|
196 void CTestThreadContainerRunner::Setup( CTestModuleContainer* aTestModuleContainer ) |
|
197 { |
|
198 iTestModuleContainer = aTestModuleContainer; |
|
199 iCurrentOperation = ESetup; |
|
200 SetActive(); |
|
201 CompleteRequest(); |
|
202 iOperationOngoing.Wait(); |
|
203 } |
|
204 |
|
205 /* |
|
206 ------------------------------------------------------------------------------- |
|
207 |
|
208 Class: CTestThreadContainerRunner |
|
209 |
|
210 Method: RunOneIteration |
|
211 |
|
212 Description: Emulates one iteration of while loop from CTestThreadContainer::ExecutionThread method |
|
213 |
|
214 Iterations is performed in main thread. |
|
215 |
|
216 Parameters: None |
|
217 |
|
218 Return Values: None. |
|
219 |
|
220 Errors/Exceptions: None. |
|
221 |
|
222 Status: Draft |
|
223 |
|
224 ------------------------------------------------------------------------------- |
|
225 */ |
|
226 void CTestThreadContainerRunner::RunOneIteration() |
|
227 { |
|
228 iCurrentOperation = ERunOneIteration; |
|
229 SetActive(); |
|
230 CompleteRequest(); |
|
231 iOperationOngoing.Wait(); |
|
232 } |
|
233 |
|
234 /* |
|
235 ------------------------------------------------------------------------------- |
|
236 |
|
237 Class: CTestThreadContainerRunner |
|
238 |
|
239 Method: TeareDown |
|
240 |
|
241 Description: Emulates teare down part of CTestThreadContainer::ExecutionThread method |
|
242 |
|
243 Teare down is performed in main thread. |
|
244 |
|
245 Parameters: None |
|
246 |
|
247 Return Values: None |
|
248 |
|
249 Errors/Exceptions: None |
|
250 |
|
251 Status: Draft |
|
252 |
|
253 ------------------------------------------------------------------------------- |
|
254 */ |
|
255 void CTestThreadContainerRunner::TeareDown() |
|
256 { |
|
257 iCurrentOperation = ETearDown; |
|
258 SetActive(); |
|
259 CompleteRequest(); |
|
260 iOperationOngoing.Wait(); |
|
261 } |
|
262 |
|
263 /* |
|
264 ------------------------------------------------------------------------------- |
|
265 |
|
266 Class: CTestThreadContainerRunner |
|
267 |
|
268 Method: CheckSignalFromSuspend |
|
269 |
|
270 Description: Checks if operation change signal was signaled from suspend state. |
|
271 |
|
272 Main part of code is executed in main thread. |
|
273 |
|
274 Parameters: None |
|
275 |
|
276 Return Values: None |
|
277 |
|
278 Errors/Exceptions: None |
|
279 |
|
280 Status: Draft |
|
281 |
|
282 ------------------------------------------------------------------------------- |
|
283 */ |
|
284 void CTestThreadContainerRunner::CheckSignalFromSuspend() |
|
285 { |
|
286 if ( iSignalFromSuspend ) |
|
287 { |
|
288 iSignalFromSuspend = EFalse; |
|
289 iTestThreadContainer->TestComplete( iReturnCode ); |
|
290 } |
|
291 } |
|
292 |
|
293 /* |
|
294 ------------------------------------------------------------------------------- |
|
295 |
|
296 Class: CTestThreadContainerRunner |
|
297 |
|
298 Method: IsReusable |
|
299 |
|
300 Description: Checks if test thread is reusable. |
|
301 |
|
302 Checks if test thread is reusable. |
|
303 |
|
304 Parameters: None |
|
305 |
|
306 Return Values: True if TestThreadContainer is reusable. |
|
307 |
|
308 Errors/Exceptions: None |
|
309 |
|
310 Status: Draft |
|
311 |
|
312 ------------------------------------------------------------------------------- |
|
313 */ |
|
314 TBool CTestThreadContainerRunner::IsReusable() |
|
315 { |
|
316 return iReusable; |
|
317 } |
|
318 |
|
319 /* |
|
320 ------------------------------------------------------------------------------- |
|
321 |
|
322 Class: CTestThreadContainerRunner |
|
323 |
|
324 Method: ExceptionHandler |
|
325 |
|
326 Description: Test thread exception handler. |
|
327 |
|
328 Test thread exception handler. |
|
329 |
|
330 Parameters: TExcType aType: in: Exception type. |
|
331 |
|
332 Return Values: None |
|
333 |
|
334 Errors/Exceptions: None |
|
335 |
|
336 Status: Draft |
|
337 |
|
338 ------------------------------------------------------------------------------- |
|
339 */ |
|
340 void CTestThreadContainerRunner::ExceptionHandler ( TExcType aType ) |
|
341 { |
|
342 // Kill the current thread, undertaker handles rest |
|
343 RThread current; |
|
344 current.Kill( aType ); |
|
345 |
|
346 // This line is never executed, because thread has been killed. |
|
347 } |
|
348 |
|
349 /* |
|
350 ------------------------------------------------------------------------------- |
|
351 |
|
352 Class: CTestThreadContainerRunner |
|
353 |
|
354 Method: RunL |
|
355 |
|
356 Description: RunL derived from CActive handles the completed requests. |
|
357 |
|
358 RunL derived from CActive handles the completed requests. |
|
359 |
|
360 Parameters: None. |
|
361 |
|
362 Return Values: None. |
|
363 |
|
364 Errors/Exceptions: Leaves if one of the called method leavs. |
|
365 |
|
366 Status: Draft |
|
367 |
|
368 ------------------------------------------------------------------------------- |
|
369 */ |
|
370 void CTestThreadContainerRunner::RunL() |
|
371 { |
|
372 switch( iCurrentOperation ) |
|
373 { |
|
374 case ESetup: |
|
375 { |
|
376 TInt error( KErrNone ); |
|
377 |
|
378 const TUint32 KAll = 0xFFFFFFFF; |
|
379 #ifndef __HIDE_IPC_V1__ // e.g. 7.0s, 8.0a |
|
380 RThread currentThread; |
|
381 currentThread.SetExceptionHandler( ExceptionHandler, KAll ); |
|
382 #else // PlatSec used. Thread exception management is part of the User class. |
|
383 User::SetExceptionHandler( ExceptionHandler, KAll ); |
|
384 #endif // __HIDE_IPC_V1__ |
|
385 |
|
386 // Create cleanup stack |
|
387 // CTrapCleanup* tc = CTrapCleanup::New(); |
|
388 // __ASSERT_ALWAYS( tc, Panic( ECreateTrapCleanup ) ); |
|
389 |
|
390 iTestThreadContainer = NULL; |
|
391 TRAPD( err, |
|
392 iTestThreadContainer = CTestThreadContainer::NewL( iTestModuleContainer, |
|
393 iTestModuleContainer->ServerThreadId() ); |
|
394 ); |
|
395 if( err != KErrNone ) |
|
396 { |
|
397 Panic( ENullTestThreadContainer ); |
|
398 } |
|
399 |
|
400 // Construct the logger |
|
401 TName path = _L("C:\\logs\\testframework\\testserver\\"); |
|
402 TFileName name = _L("testserver_thread_"); |
|
403 name.Append( iTestModuleContainer->TestModuleName() ); |
|
404 |
|
405 // Create logger, in Wins use HTML in HW default logger |
|
406 TLoggerSettings loggerSettings; |
|
407 |
|
408 // Directory must create by hand if test server log wanted |
|
409 loggerSettings.iCreateLogDirectories = EFalse; |
|
410 |
|
411 loggerSettings.iOverwrite = ETrue; |
|
412 loggerSettings.iTimeStamp = ETrue; |
|
413 loggerSettings.iLineBreak = ETrue; |
|
414 loggerSettings.iEventRanking = EFalse; |
|
415 loggerSettings.iThreadId = EFalse; |
|
416 loggerSettings.iHardwareFormat = CStifLogger::ETxt; |
|
417 #ifndef FORCE_STIF_INTERNAL_LOGGING_TO_RDEBUG |
|
418 loggerSettings.iEmulatorFormat = CStifLogger::EHtml; |
|
419 loggerSettings.iHardwareOutput = CStifLogger::EFile; |
|
420 loggerSettings.iEmulatorOutput = CStifLogger::EFile; |
|
421 #else |
|
422 RDebug::Print( _L( "STIF Test Server's thread logging forced to RDebug" ) ); |
|
423 loggerSettings.iEmulatorFormat = CStifLogger::ETxt; |
|
424 loggerSettings.iHardwareOutput = CStifLogger::ERDebug; |
|
425 loggerSettings.iEmulatorOutput = CStifLogger::ERDebug; |
|
426 #endif |
|
427 loggerSettings.iUnicode = EFalse; |
|
428 loggerSettings.iAddTestCaseTitle = EFalse; |
|
429 |
|
430 TRAP ( error, iTestThreadContainer->SetThreadLogger( CStifLogger::NewL( path, name, |
|
431 loggerSettings ) ) ); |
|
432 |
|
433 iReusable = ETrue; // Is test module reusable? |
|
434 iInitialized = EFalse; // Is module initialized? |
|
435 iSignalFromSuspend = EFalse; // Send signal from suspend state? |
|
436 |
|
437 iReturnCode = KErrNone; |
|
438 } |
|
439 break; |
|
440 case ERunOneIteration: |
|
441 { |
|
442 iReturnCode = KErrNone; |
|
443 |
|
444 switch ( iTestModuleContainer->OperationType() ) |
|
445 { |
|
446 // Test module initialisation |
|
447 case CTestModuleContainer::EInitializeModule: |
|
448 { |
|
449 __ASSERT_ALWAYS ( !iInitialized, |
|
450 Panic( EReInitializingTestModule ) ); |
|
451 |
|
452 // Initialize module |
|
453 if ( iTestThreadContainer->InitializeModuleInThread( iModule ) == KErrNone ) |
|
454 { |
|
455 iInitialized = ETrue; |
|
456 } |
|
457 |
|
458 iSignalFromSuspend = ETrue; |
|
459 break; |
|
460 } |
|
461 |
|
462 // Test case enumeration |
|
463 case CTestModuleContainer::EEnumerateInThread: |
|
464 { |
|
465 __ASSERT_ALWAYS ( iInitialized, |
|
466 Panic( ETestModuleNotInitialized ) ); |
|
467 iReturnCode = iTestThreadContainer->EnumerateInThread(); |
|
468 |
|
469 iSignalFromSuspend = ETrue; |
|
470 break; |
|
471 } |
|
472 |
|
473 // Free test case enumeration data |
|
474 case CTestModuleContainer::EFreeEnumerationData: |
|
475 { |
|
476 __ASSERT_ALWAYS ( iInitialized, |
|
477 Panic( ETestModuleNotInitialized ) ); |
|
478 iTestThreadContainer->FreeEnumerationDataInThread (); |
|
479 |
|
480 iSignalFromSuspend = ETrue; |
|
481 break; |
|
482 } |
|
483 |
|
484 // Execute test case |
|
485 case CTestModuleContainer::EExecuteTestInThread: |
|
486 { |
|
487 __ASSERT_ALWAYS ( iInitialized, |
|
488 Panic( ETestModuleNotInitialized ) ); |
|
489 iReturnCode = iTestThreadContainer->ExecuteTestCaseInThread (); |
|
490 |
|
491 iSignalFromSuspend = ETrue; |
|
492 break; |
|
493 } |
|
494 |
|
495 // Exiting (i.e test server is unloading) |
|
496 case CTestModuleContainer::EExit: |
|
497 { |
|
498 iReusable = EFalse; |
|
499 break; |
|
500 } |
|
501 |
|
502 // Illegal state |
|
503 default: |
|
504 { |
|
505 Panic( EInvalidTestModuleOperation ); |
|
506 } |
|
507 } |
|
508 } |
|
509 break; |
|
510 case ETearDown: |
|
511 { |
|
512 iTestThreadContainer->DeleteTestModule(); |
|
513 |
|
514 // Close handle to module. No function calls to test |
|
515 // module are possible after this line. |
|
516 iModule.Close(); |
|
517 |
|
518 // Delete logger |
|
519 CStifLogger* threadLogger = iTestThreadContainer->GetThreadLogger(); |
|
520 iTestThreadContainer->SetThreadLogger( NULL ); |
|
521 delete threadLogger; |
|
522 threadLogger = NULL; |
|
523 |
|
524 // Delete clean-up stack. |
|
525 // delete tc; |
|
526 // tc = NULL; |
|
527 |
|
528 // Operation completed ( = Exit completed ) |
|
529 iTestThreadContainer->TestComplete( KErrNone ); |
|
530 |
|
531 delete iTestThreadContainer; |
|
532 } |
|
533 break; |
|
534 } |
|
535 |
|
536 iCurrentOperation = ENone; |
|
537 iOperationOngoing.Signal(); |
|
538 } |
|
539 |
|
540 /* |
|
541 ------------------------------------------------------------------------------- |
|
542 |
|
543 Class: CTestThreadContainerRunner |
|
544 |
|
545 Method: Panic |
|
546 |
|
547 Description: Raises panic. |
|
548 |
|
549 Raises panic. |
|
550 |
|
551 Parameters: TInt aReason: in: Panic reason. |
|
552 |
|
553 Return Values: None. |
|
554 |
|
555 Errors/Exceptions: None. |
|
556 |
|
557 Status: Draft |
|
558 |
|
559 ------------------------------------------------------------------------------- |
|
560 */ |
|
561 void CTestThreadContainerRunner::Panic( TInt aReason ) |
|
562 { |
|
563 RDebug::Print( _L("CTestThreadContainer::Panic %d"), aReason ); |
|
564 User::Panic( _L("CTestThreadContainer::Panic"), aReason ); |
|
565 } |
|
566 |
|
567 /* |
|
568 ------------------------------------------------------------------------------- |
|
569 |
|
570 Class: CTestThreadContainerRunner |
|
571 |
|
572 Method: DoCancel |
|
573 |
|
574 Description: DoCancel derived from CActive handles the Cancel. |
|
575 |
|
576 DoCancel derived from CActive handles the Cancel. |
|
577 |
|
578 Parameters: None. |
|
579 |
|
580 Return Values: None. |
|
581 |
|
582 Errors/Exceptions: None. |
|
583 |
|
584 Status: Draft |
|
585 |
|
586 ------------------------------------------------------------------------------- |
|
587 */ |
|
588 void CTestThreadContainerRunner::DoCancel() |
|
589 { |
|
590 } |
|
591 |
|
592 /* |
|
593 ------------------------------------------------------------------------------- |
|
594 |
|
595 Class: CTestThreadContainerRunner |
|
596 |
|
597 Method: CompleteRequest |
|
598 |
|
599 Description: Complets current operation request. |
|
600 |
|
601 Complets current operation request, what causes execution of RunL method |
|
602 in main thread of UITestServerStarter. |
|
603 |
|
604 |
|
605 Parameters: None. |
|
606 |
|
607 Return Values: None. |
|
608 |
|
609 Errors/Exceptions: None. |
|
610 |
|
611 Status: Draft |
|
612 |
|
613 ------------------------------------------------------------------------------- |
|
614 */ |
|
615 void CTestThreadContainerRunner::CompleteRequest() |
|
616 { |
|
617 iStatus = KRequestPending; |
|
618 TRequestStatus* statusPtr = &iStatus; |
|
619 RThread mainThread; |
|
620 User::LeaveIfError( mainThread.Open( iMainThreadId ) ); |
|
621 mainThread.RequestComplete( statusPtr, KErrNone ); |
|
622 mainThread.Close(); |
|
623 } |
|
624 |
|
625 // End of File |