|
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 implementation of |
|
15 * CTestModuleContainer class member functions. CTestModuleContainer |
|
16 * class contains interface * to execute various functions in context |
|
17 * of test execution thread. |
|
18 * |
|
19 * CTestModuleContainer is the owner of the test execution thread |
|
20 * object and the owner of the test module instance. |
|
21 * |
|
22 */ |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <e32std.h> |
|
26 #include <e32svr.h> |
|
27 #include <e32uid.h> |
|
28 #include "TestEngineClient.h" |
|
29 #include <StifTestModule.h> |
|
30 #include <stifinternal/TestServerClient.h> |
|
31 #include "TestServer.h" |
|
32 #include "TestServerModuleIf.h" |
|
33 #include "TestServerCommon.h" |
|
34 #include "PrintQueue.h" |
|
35 #include "TestThreadContainer.h" |
|
36 //--PYTHON-- begin |
|
37 #include "StifPython.h" |
|
38 //--PYTHON-- end |
|
39 |
|
40 // EXTERNAL DATA STRUCTURES |
|
41 |
|
42 // EXTERNAL FUNCTION PROTOTYPES |
|
43 |
|
44 // The test module execution thread function |
|
45 TInt ExecutionThread( TAny* aParams ); |
|
46 |
|
47 // CONSTANTS |
|
48 |
|
49 // MACROS |
|
50 |
|
51 // LOCAL CONSTANTS AND MACROS |
|
52 |
|
53 // MODULE DATA STRUCTURES |
|
54 |
|
55 // LOCAL FUNCTION PROTOTYPES |
|
56 typedef TInt( *CTestInterfaceFactoryTestModule )( CTestModuleParam*&, TUint32& ); |
|
57 |
|
58 // FORWARD DECLARATIONS |
|
59 |
|
60 // ==================== LOCAL FUNCTIONS ======================================= |
|
61 |
|
62 // ================= MEMBER FUNCTIONS ========================================= |
|
63 |
|
64 |
|
65 /* |
|
66 ------------------------------------------------------------------------------- |
|
67 |
|
68 Class: CTestModuleContainer |
|
69 |
|
70 Method: NewL |
|
71 |
|
72 Description: Returns new CTestModuleContainer instance. |
|
73 |
|
74 Parameters: const TDesC& aName: in: Module name |
|
75 CTestModule* aSession: in: "Parent" |
|
76 const TDesC& aConfig: in: Test case (config) file name. |
|
77 |
|
78 Return Values: CTestModuleContainer* New instance |
|
79 |
|
80 Errors/Exceptions: Function leaves if memory allocation fails or |
|
81 CTestModuleContainer ConstructL leaves. |
|
82 Panics if aSession is NULL. |
|
83 |
|
84 Status: Proposal |
|
85 |
|
86 ------------------------------------------------------------------------------- |
|
87 */ |
|
88 CTestModuleContainer* CTestModuleContainer::NewL( const TDesC& aName, |
|
89 CTestModule* aSession, |
|
90 const TDesC& aConfig ) |
|
91 { |
|
92 |
|
93 __ASSERT_ALWAYS ( aSession, |
|
94 CTestServer::PanicServer( ENullTestModule ) ); |
|
95 |
|
96 CTestModuleContainer* self = new ( ELeave ) CTestModuleContainer(); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aName, aSession, aConfig ); |
|
99 CleanupStack::Pop( self ); |
|
100 return self; |
|
101 |
|
102 } |
|
103 |
|
104 /* |
|
105 ------------------------------------------------------------------------------- |
|
106 |
|
107 Class: CTestModuleContainer |
|
108 |
|
109 Method: ConstructL |
|
110 |
|
111 Description: Second level constructor. |
|
112 |
|
113 Function creates the execution thread, creates exception |
|
114 handler and the thread undertaker for it and then resumes the thread. |
|
115 |
|
116 Parameters: const TDesC& aName: in: Module name |
|
117 CTestModule* aSession: in: "Parent" |
|
118 const TDesC& aConfig: in: Test case (config) file name. |
|
119 |
|
120 Return Values: CTestModuleContainer* New instance |
|
121 |
|
122 Errors/Exceptions: Function leaves if thread creation fails, |
|
123 memory allocation fails or undertaker creation leaves. |
|
124 |
|
125 Status: Proposal |
|
126 |
|
127 ------------------------------------------------------------------------------- |
|
128 */ |
|
129 void CTestModuleContainer::ConstructL( const TDesC& aName, |
|
130 CTestModule* aSession, |
|
131 const TDesC& aConfig ) |
|
132 { |
|
133 |
|
134 RDebug::Print( aName ); |
|
135 |
|
136 iNestedActiveScheduler = new (ELeave) CActiveSchedulerWait; |
|
137 |
|
138 iCTestModule = aSession; |
|
139 |
|
140 // Create error print handler |
|
141 iErrorPrintHandler = CErrorPrintHandler::NewL( *this ); |
|
142 User::LeaveIfError( iErrorPrintSem.CreateLocal( 0 ) ); |
|
143 |
|
144 // Construct unique thread name |
|
145 const TInt KAddressLen = 8; |
|
146 const TInt KMaxName = 50; // Something smaller than max thread name |
|
147 TInt len = aName.Length(); |
|
148 if ( KAddressLen + len > KMaxName ) |
|
149 { |
|
150 len = KMaxName - KAddressLen; |
|
151 } |
|
152 |
|
153 // Default heap and stack sizes that may configure by user. |
|
154 TInt heapMinSize( KTestThreadMinHeap ); |
|
155 TInt heapMaxSize( KTestThreadMaxHeap ); |
|
156 TInt stackSize( KStackSize ); |
|
157 |
|
158 // Check is user give heap or stack sizes and verify sizes. |
|
159 GetTestModuleParams( aName, aConfig, stackSize, heapMinSize, heapMaxSize ); |
|
160 |
|
161 // Create a new thread |
|
162 TInt ret = KErrAlreadyExists; |
|
163 for( TInt i = 0; ret == KErrAlreadyExists; i++ ) |
|
164 { |
|
165 TName threadName = aName.Left( len ); |
|
166 threadName.AppendFormat( _L( "%x" ), ( TUint32 ) this ); |
|
167 threadName.AppendFormat( _L( "%x" ), i ); |
|
168 //RDebug::Print( threadName ); |
|
169 |
|
170 RDebug::Print(_L("CTestModuleContainer::ConstructL create thread=[%S] stackSize=(%d)"), &threadName, stackSize); |
|
171 |
|
172 if ( iCTestModule->GetTestServer()->UiTesting() == false ) |
|
173 { |
|
174 ret = iThread.Create( |
|
175 threadName, // name of thread |
|
176 CTestThreadContainer::ExecutionThread,// thread function |
|
177 stackSize, // Stack size |
|
178 heapMinSize, // Heap sizes |
|
179 heapMaxSize, |
|
180 this // Parameter to thread function |
|
181 ); |
|
182 } |
|
183 else |
|
184 { |
|
185 ret = iThread.Create( |
|
186 threadName, // name of thread |
|
187 CTestThreadContainer::UIExecutionThread,// thread function |
|
188 stackSize, // Stack size |
|
189 heapMinSize, // Heap sizes |
|
190 heapMaxSize, |
|
191 this // Parameter to thread function |
|
192 ); |
|
193 } |
|
194 |
|
195 // If test execution thread exist try to create new one |
|
196 if( ret == KErrAlreadyExists ) |
|
197 { |
|
198 RDebug::Print( _L( "Thread[%S] allready exist, creating new one" ), &threadName ); |
|
199 __TRACE ( KInit, ( CStifLogger::ERed, _L( "Thread[%S] allready exist, creating new one" ), &threadName ) ); |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 // If thread creation fails, leave here. |
|
205 if( ret != KErrNone ) |
|
206 { |
|
207 RDebug::Print( _L( "Execution thread creation fails with: [%d]" ), ret ); |
|
208 __TRACE ( KError, ( CStifLogger::ERed, _L( "Execution thread creation fails with: [%d]" ), ret ) ); |
|
209 User::Leave( ret ); |
|
210 } |
|
211 |
|
212 // Doing nothing |
|
213 // ChangeOperationNoError ( ESuspend, 0 ); |
|
214 // Thread suspends always first by default |
|
215 |
|
216 // Construct the undertaker to get notifications about the |
|
217 // thread death. |
|
218 // This must be trapped to allow to kill just created thread |
|
219 // nicely without a mess in destructor. |
|
220 TRAPD ( r, |
|
221 iUnderTaker = CUnderTaker::NewL ( this ); |
|
222 CActiveScheduler::Add( iUnderTaker ); |
|
223 iUnderTaker->StartL(); |
|
224 ); |
|
225 |
|
226 // Can't create or start the undertaker. Kill the thread. |
|
227 // Undertaker will be deleted in destructor if needed. |
|
228 if ( r != KErrNone ) |
|
229 { |
|
230 iThread.Kill ( r ); |
|
231 iThread.Close(); |
|
232 User::Leave( r ); |
|
233 } |
|
234 |
|
235 // Get server thread id ( i.e current thread id ) |
|
236 RThread tmpThread; |
|
237 iServerThreadId = tmpThread.Id(); |
|
238 |
|
239 // Resume the thread |
|
240 iThread.Resume(); // Start the thread |
|
241 iUpAndRunning = ETrue; // Thread is created |
|
242 |
|
243 // Add "this" container to active scheduler |
|
244 CActiveScheduler::Add ( this ); |
|
245 |
|
246 // Start error print handler |
|
247 iErrorPrintHandler->StartL(); |
|
248 |
|
249 } |
|
250 |
|
251 /* |
|
252 ------------------------------------------------------------------------------- |
|
253 |
|
254 Class: CTestModuleContainer |
|
255 |
|
256 Method: CTestModuleContainer |
|
257 |
|
258 Description: Constructor. |
|
259 |
|
260 Initialise semaphores. |
|
261 |
|
262 Parameters: None |
|
263 |
|
264 Return Values: None |
|
265 |
|
266 Errors/Exceptions: None |
|
267 |
|
268 Status: Proposal |
|
269 |
|
270 ------------------------------------------------------------------------------- |
|
271 */ |
|
272 CTestModuleContainer::CTestModuleContainer() : |
|
273 CActive( CActive::EPriorityStandard ), |
|
274 iOperationName ( 0, 0 ), |
|
275 iIsPaused( EFalse ) |
|
276 { |
|
277 |
|
278 // Create operation start semaphore |
|
279 iOperationStartSemaphore.CreateLocal( 0 ); |
|
280 |
|
281 // Operation can be changed without first waiting. |
|
282 iOperationChangeSemaphore.CreateLocal( 1 ); |
|
283 |
|
284 } |
|
285 |
|
286 /* |
|
287 ------------------------------------------------------------------------------- |
|
288 |
|
289 Class: CTestModuleContainer |
|
290 |
|
291 Method: ~CTestModuleContainer |
|
292 |
|
293 Description: Destructor |
|
294 |
|
295 Delete the test execution thread, if it is up and running. Delete |
|
296 undertaker and close handles. |
|
297 |
|
298 Parameters: None |
|
299 |
|
300 Return Values: None |
|
301 |
|
302 Errors/Exceptions: None |
|
303 |
|
304 Status: Proposal |
|
305 |
|
306 ------------------------------------------------------------------------------- |
|
307 */ |
|
308 CTestModuleContainer::~CTestModuleContainer() |
|
309 { |
|
310 |
|
311 __TRACE ( KThreadOperation, ( _L( "CTestModuleContainer::~CTestModuleContainer in" ) ) ); |
|
312 |
|
313 if ( iUpAndRunning ) |
|
314 { |
|
315 if( iUnderTaker != NULL ) |
|
316 { |
|
317 iUnderTaker->Cancel(); |
|
318 } |
|
319 |
|
320 // Set the operation |
|
321 ChangeOperationNoError ( EExit, 0 ); |
|
322 |
|
323 // Do operation |
|
324 StartAndWaitOperation(); |
|
325 |
|
326 } |
|
327 |
|
328 delete iErrorPrintHandler; |
|
329 iErrorPrintHandler = NULL; |
|
330 |
|
331 // Delete heap descriptor |
|
332 delete iModuleNameBuffer; |
|
333 iModuleNameBuffer = NULL; |
|
334 |
|
335 // Delete undertaker |
|
336 delete iUnderTaker; |
|
337 iUnderTaker = NULL; |
|
338 |
|
339 // Close error semaphore |
|
340 if ( iErrorPrintSem.Handle() != 0 ) iErrorPrintSem.Close(); |
|
341 |
|
342 // Close the semaphores |
|
343 iOperationStartSemaphore.Close(); |
|
344 iOperationChangeSemaphore.Close(); |
|
345 |
|
346 // Close handle to thread |
|
347 iThread.Close(); |
|
348 |
|
349 Cancel(); |
|
350 |
|
351 delete iNestedActiveScheduler; |
|
352 iNestedActiveScheduler = NULL; |
|
353 |
|
354 __TRACE ( KThreadOperation, ( _L( "CTestModuleContainer::~CTestModuleContainer out" ) ) ); |
|
355 |
|
356 } |
|
357 |
|
358 /* |
|
359 ------------------------------------------------------------------------------- |
|
360 |
|
361 Class: CTestModuleContainer |
|
362 |
|
363 Method: StartAndWaitOperation |
|
364 |
|
365 Description: Signals operation and waits until operation is completed. |
|
366 |
|
367 Function executes active scheduler locally to handle both request |
|
368 completion from execution thread and thread undertaker operations. |
|
369 |
|
370 Parameters: None |
|
371 |
|
372 Return Values: None |
|
373 |
|
374 Errors/Exceptions: None |
|
375 |
|
376 Status: Proposal |
|
377 |
|
378 ------------------------------------------------------------------------------- |
|
379 */ |
|
380 TInt CTestModuleContainer::StartAndWaitOperation() |
|
381 { |
|
382 |
|
383 // Change undertaker mode to synchronous |
|
384 iUnderTaker->SetSynchronousMode( ETrue ); |
|
385 |
|
386 iStatus = KRequestPending; |
|
387 // Get ready to handle operation completion |
|
388 SetActive(); |
|
389 |
|
390 // Start operation |
|
391 iOperationStartSemaphore.Signal(); |
|
392 |
|
393 // Start "nested" active scheduler "locally" |
|
394 //CActiveScheduler::Start(); |
|
395 iNestedActiveScheduler->Start(); |
|
396 |
|
397 // Request completed or operation crashed, everything |
|
398 // is done in ModuleContainer's RunL function or in UnderTaker's RunL. |
|
399 |
|
400 // Cancel the original request in case than it was the undertaker |
|
401 // that stopped the active scheduler. Does not do anything if original |
|
402 // request is already finished. |
|
403 Cancel(); |
|
404 |
|
405 // Undertaker back to "normal" mode |
|
406 iUnderTaker->SetSynchronousMode ( EFalse ); |
|
407 |
|
408 return iModuleResult; |
|
409 |
|
410 } |
|
411 |
|
412 |
|
413 |
|
414 /* |
|
415 ------------------------------------------------------------------------------- |
|
416 |
|
417 Class: CTestModuleContainer |
|
418 |
|
419 Method: Initialise |
|
420 |
|
421 Description: Initialise the test module |
|
422 |
|
423 Initialisation is done in context of test execution thread. |
|
424 |
|
425 Parameters: const TDesC& aName :in: Module name |
|
426 TBool aFirstTime :in: First init? |
|
427 |
|
428 |
|
429 Return Values: TInt Result from init |
|
430 |
|
431 Errors/Exceptions: None |
|
432 |
|
433 Status: Proposal |
|
434 |
|
435 ------------------------------------------------------------------------------- |
|
436 */ |
|
437 TInt CTestModuleContainer::Initialize( const TFileName& aName, |
|
438 TBool aFirstTime |
|
439 ) |
|
440 { |
|
441 |
|
442 __TRACE ( KInit, ( _L( "Initializing test module" ) ) ); |
|
443 |
|
444 // Set the operation |
|
445 iErrorResult = ChangeOperation ( EInitializeModule, aName, aFirstTime ); |
|
446 iModuleResult = KErrNone; |
|
447 |
|
448 if ( iErrorResult == KErrNone ) |
|
449 { |
|
450 // Wait until operation is completed |
|
451 StartAndWaitOperation(); |
|
452 } |
|
453 |
|
454 if ( iErrorResult ) |
|
455 { |
|
456 __TRACE ( KError, ( CStifLogger::ERed, _L( "Initializing test module failed %d" ), iErrorResult ) ); |
|
457 } |
|
458 else if ( iModuleResult ) |
|
459 { |
|
460 __TRACE ( KError, ( CStifLogger::ERed, _L( "Initializing test module failed code from module = %d" ), iModuleResult ) ); |
|
461 } |
|
462 else |
|
463 { |
|
464 __TRACE ( KInit, ( CStifLogger::EBold, _L( "Test module initialization done" ) ) ); |
|
465 } |
|
466 |
|
467 // Return result |
|
468 return iModuleResult; |
|
469 |
|
470 } |
|
471 |
|
472 /* |
|
473 ------------------------------------------------------------------------------- |
|
474 |
|
475 Class: CTestModuleContainer |
|
476 |
|
477 Method: EnumerateTestCases |
|
478 |
|
479 Description: Enumerate test cases of the test module |
|
480 |
|
481 Enumeration is done in context of test execution thread. |
|
482 |
|
483 Parameters: const TDesC& aName :in: Configuration file |
|
484 |
|
485 Return Values: TInt Result from enumeration |
|
486 |
|
487 Errors/Exceptions: None |
|
488 |
|
489 Status: Proposal |
|
490 |
|
491 ------------------------------------------------------------------------------- |
|
492 */ |
|
493 TInt CTestModuleContainer::EnumerateTestCases( const TFileName& aName ) |
|
494 { |
|
495 |
|
496 __TRACE ( KInit, ( CStifLogger::EBold, _L( "Enumerating test cases from [%S] (might be empty)" ), &aName ) ); |
|
497 |
|
498 // Set the operation |
|
499 iErrorResult = ChangeOperation( EEnumerateInThread, aName, 0 ); |
|
500 iModuleResult = KErrNone; |
|
501 |
|
502 if ( iErrorResult == KErrNone ) |
|
503 { |
|
504 // Wait until operation is completed |
|
505 StartAndWaitOperation(); |
|
506 } |
|
507 |
|
508 if ( iErrorResult ) |
|
509 { |
|
510 __TRACE ( KError, ( CStifLogger::ERed, _L( "Enumerating test cases failed %d" ), iErrorResult ) ); |
|
511 } |
|
512 else if ( iModuleResult ) |
|
513 { |
|
514 __TRACE ( KError, ( CStifLogger::ERed, _L( "Enumerating test cases failed, code from module = %d" ), iModuleResult ) ); |
|
515 } |
|
516 else |
|
517 { |
|
518 __TRACE ( KInit, ( _L( "Enumerating test cases done" ) ) ); |
|
519 } |
|
520 |
|
521 // Return result |
|
522 return iModuleResult; |
|
523 |
|
524 } |
|
525 |
|
526 |
|
527 |
|
528 /* |
|
529 ------------------------------------------------------------------------------- |
|
530 |
|
531 Class: CTestModuleContainer |
|
532 |
|
533 Method: FreeEnumerationData |
|
534 |
|
535 Description: Frees the enumeration data |
|
536 |
|
537 Memory deallocation is done in context of test execution thread. |
|
538 |
|
539 Parameters: None |
|
540 |
|
541 Return Values: TInt Result from operation |
|
542 |
|
543 Errors/Exceptions: None |
|
544 |
|
545 Status: Proposal |
|
546 |
|
547 ------------------------------------------------------------------------------- |
|
548 */ |
|
549 |
|
550 TInt CTestModuleContainer::FreeEnumerationData() |
|
551 { |
|
552 |
|
553 // Set the operation |
|
554 ChangeOperationNoError( EFreeEnumerationData, 0 ); |
|
555 |
|
556 // Do the operation |
|
557 StartAndWaitOperation(); |
|
558 |
|
559 // Return result |
|
560 return iModuleResult; |
|
561 |
|
562 } |
|
563 |
|
564 /* |
|
565 ------------------------------------------------------------------------------- |
|
566 |
|
567 Class: CTestModuleContainer |
|
568 |
|
569 Method: RunTestCase |
|
570 |
|
571 Description: Run a test case |
|
572 |
|
573 Running a test case is done in context of test execution thread. This |
|
574 function is asynchronous ( i.e test is not finished when this function |
|
575 returns ). |
|
576 |
|
577 Parameters: const TFileName& aName :in: Configuration file |
|
578 TInt aCaseNumber :in: Case number |
|
579 const RMessage :in: Handle to test msg. |
|
580 |
|
581 Return Values: None |
|
582 |
|
583 Errors/Exceptions: None |
|
584 |
|
585 Status: Proposal |
|
586 |
|
587 ------------------------------------------------------------------------------- |
|
588 */ |
|
589 void CTestModuleContainer::RunTestCase ( const TFileName& aName, |
|
590 const TInt aCaseNumber, |
|
591 const RMessage2& aMessage |
|
592 ) |
|
593 { |
|
594 |
|
595 __TRACE ( KInit, ( CStifLogger::EBold, _L( "Running test case [%S], case [%d]" ), &aName, aCaseNumber ) ); |
|
596 |
|
597 // Set the operation |
|
598 iErrorResult = ChangeOperation( EExecuteTestInThread, aName, aCaseNumber ); |
|
599 |
|
600 if ( iErrorResult != KErrNone ) |
|
601 { |
|
602 aMessage.Complete ( iErrorResult ); |
|
603 return; |
|
604 } |
|
605 |
|
606 // Set data |
|
607 iMessage = aMessage; |
|
608 |
|
609 iStatus = KRequestPending; |
|
610 // Get ready to handle operation completion |
|
611 SetActive(); |
|
612 |
|
613 // Do operation |
|
614 iOperationStartSemaphore.Signal(); |
|
615 |
|
616 // This is asynchronous operation, |
|
617 // do not wait until completed. |
|
618 |
|
619 } |
|
620 |
|
621 /* |
|
622 ------------------------------------------------------------------------------- |
|
623 |
|
624 Class: CTestModuleContainer |
|
625 |
|
626 Method: SetExecutionSubSession |
|
627 |
|
628 Description: Set execution subsession |
|
629 |
|
630 Sets module container test execution subsession. Execution subsession |
|
631 is changed when a module container is reused to run another |
|
632 test case. |
|
633 |
|
634 Parameters: CTestExecution* aExecution :in: Subsession pointer |
|
635 |
|
636 Return Values: None |
|
637 |
|
638 Errors/Exceptions: None |
|
639 |
|
640 Status: Proposal |
|
641 |
|
642 ------------------------------------------------------------------------------- |
|
643 */ |
|
644 void CTestModuleContainer::SetExecutionSubSession( CTestExecution* aExecution ) |
|
645 { |
|
646 |
|
647 iCTestExecution = aExecution; |
|
648 |
|
649 } |
|
650 |
|
651 /* |
|
652 ------------------------------------------------------------------------------- |
|
653 |
|
654 Class: CTestModuleContainer |
|
655 |
|
656 Method: PauseThread |
|
657 |
|
658 Description: Pauses the thread |
|
659 |
|
660 Parameters: None |
|
661 |
|
662 Return Values: None |
|
663 |
|
664 Errors/Exceptions: None |
|
665 |
|
666 Status: Proposal |
|
667 |
|
668 ------------------------------------------------------------------------------- |
|
669 */ |
|
670 TInt CTestModuleContainer::PauseThread() |
|
671 { |
|
672 |
|
673 if( iThread.ExitType() != EExitPending ) |
|
674 { |
|
675 // Thread is not alive anymore |
|
676 return KErrDied; |
|
677 } |
|
678 |
|
679 if(iCTestExecution != NULL) |
|
680 { |
|
681 RMutex printMutex; |
|
682 printMutex.SetHandle( iCTestExecution->PrintMutexHandle() ); |
|
683 RMutex eventMutex; |
|
684 eventMutex.SetHandle( iCTestExecution->EventMutexHandle() ); |
|
685 RMutex sndMutex; |
|
686 sndMutex.SetHandle( iCTestExecution->SndMutexHandle() ); |
|
687 RMutex rcvMutex; |
|
688 rcvMutex.SetHandle( iCTestExecution->RcvMutexHandle() ); |
|
689 |
|
690 printMutex.Wait(); // wait that print operation is done |
|
691 eventMutex.Wait(); // wait that event operation is done |
|
692 sndMutex.Wait(); // wait that and operation is done |
|
693 rcvMutex.Wait(); // wait that event operation is done |
|
694 |
|
695 iThread.Suspend(); |
|
696 |
|
697 printMutex.Signal(); |
|
698 eventMutex.Signal(); |
|
699 sndMutex.Signal(); |
|
700 rcvMutex.Signal(); |
|
701 } |
|
702 else |
|
703 { |
|
704 __TRACE( KError,( _L( "STIF internal error - iCTestExecution is NULL in CTestModuleContainer::PauseThread" ) ) ); |
|
705 User::Panic(_L("NULL pointer exception"), KErrGeneral); |
|
706 } |
|
707 |
|
708 iIsPaused = ETrue; |
|
709 |
|
710 return KErrNone; |
|
711 |
|
712 } |
|
713 |
|
714 /* |
|
715 ------------------------------------------------------------------------------- |
|
716 |
|
717 Class: CTestModuleContainer |
|
718 |
|
719 Method: ResumeThread |
|
720 |
|
721 Description: Resumes the thread |
|
722 |
|
723 Parameters: None |
|
724 |
|
725 Return Values: None |
|
726 |
|
727 Errors/Exceptions: None |
|
728 |
|
729 Status: Proposal |
|
730 |
|
731 ------------------------------------------------------------------------------- |
|
732 */ |
|
733 TInt CTestModuleContainer::ResumeThread() |
|
734 { |
|
735 |
|
736 if( iThread.ExitType() != EExitPending ) |
|
737 { |
|
738 // Thread is not alive anymore |
|
739 return KErrDied; |
|
740 } |
|
741 |
|
742 iThread.Resume(); |
|
743 |
|
744 // Pause() - Resume() operations done successfully. |
|
745 iIsPaused = EFalse; |
|
746 |
|
747 return KErrNone; |
|
748 |
|
749 } |
|
750 |
|
751 /* |
|
752 ------------------------------------------------------------------------------- |
|
753 |
|
754 Class: CTestModuleContainer |
|
755 |
|
756 Method: KillThread |
|
757 |
|
758 Description: Kills the thread |
|
759 |
|
760 Parameters: const TInt aCode :in: Kill code |
|
761 |
|
762 Return Values: None |
|
763 |
|
764 Errors/Exceptions: None |
|
765 |
|
766 Status: Proposal |
|
767 |
|
768 ------------------------------------------------------------------------------- |
|
769 */ |
|
770 void CTestModuleContainer::KillThread( const TInt aCode ) |
|
771 { |
|
772 |
|
773 iUpAndRunning = EFalse; |
|
774 iUnderTaker->Cancel(); |
|
775 |
|
776 if(iCTestExecution != NULL) |
|
777 { |
|
778 RMutex printMutex; |
|
779 printMutex.SetHandle( iCTestExecution->PrintMutexHandle() ); |
|
780 RMutex eventMutex; |
|
781 eventMutex.SetHandle( iCTestExecution->EventMutexHandle() ); |
|
782 RMutex sndMutex; |
|
783 sndMutex.SetHandle( iCTestExecution->SndMutexHandle() ); |
|
784 RMutex rcvMutex; |
|
785 rcvMutex.SetHandle( iCTestExecution->RcvMutexHandle() ); |
|
786 |
|
787 printMutex.Wait(); // wait that print operation is done |
|
788 eventMutex.Wait(); // wait that event operation is done |
|
789 sndMutex.Wait(); // wait that snd operation is done |
|
790 rcvMutex.Wait(); // wait that event operation is done |
|
791 |
|
792 iThread.Kill ( aCode ); |
|
793 |
|
794 printMutex.Signal(); |
|
795 eventMutex.Signal(); |
|
796 sndMutex.Signal(); |
|
797 rcvMutex.Signal(); |
|
798 } |
|
799 else |
|
800 { |
|
801 __TRACE( KError,( _L( "STIF internal error - iCTestExecution is NULL in CTestModuleContainer::KillThread" ) ) ); |
|
802 User::Panic(_L("NULL pointer exception"), KErrGeneral); |
|
803 } |
|
804 |
|
805 } |
|
806 |
|
807 /* |
|
808 ------------------------------------------------------------------------------- |
|
809 |
|
810 Class: CTestModuleContainer |
|
811 |
|
812 Method: ChangeOperation |
|
813 |
|
814 Description: Multithread safe way to change operation |
|
815 |
|
816 Parameters: const TOperation aOperation :in: Operation type |
|
817 const TFileName* aNameBuffer :in: Filename ( or NULL ) |
|
818 const TInt aInt :in: Operation specific int |
|
819 |
|
820 Return Values: TInt Error code |
|
821 |
|
822 Errors/Exceptions: None |
|
823 |
|
824 Status: Proposal |
|
825 |
|
826 ------------------------------------------------------------------------------- |
|
827 */ |
|
828 TInt CTestModuleContainer::ChangeOperation( const TOperation aOperation, |
|
829 const TFileName& aNameBuffer, |
|
830 const TInt aInt ) |
|
831 { |
|
832 |
|
833 TInt ret = KErrNone; |
|
834 |
|
835 iOperationChangeSemaphore.Wait(); |
|
836 |
|
837 iErrorResult = KErrNone; |
|
838 iModuleResult = KErrNone; |
|
839 |
|
840 TFileName newNameBuffer; |
|
841 // Check is TestScripter |
|
842 TInt check = CheckModuleName( aNameBuffer, newNameBuffer ); |
|
843 delete iModuleNameBuffer; |
|
844 iModuleNameBuffer = NULL; |
|
845 if( check == KErrNone ) |
|
846 { |
|
847 // Construct heap buffer for configuration file |
|
848 TRAP( ret, iModuleNameBuffer = HBufC::NewL( newNameBuffer.Length() ) ); |
|
849 |
|
850 if( ret == KErrNone ) |
|
851 { |
|
852 iOperationName.Set ( iModuleNameBuffer->Des() ); |
|
853 iOperationName.Copy ( newNameBuffer ); |
|
854 |
|
855 iOperationIntBuffer = aInt; |
|
856 iOperationType = aOperation; |
|
857 } |
|
858 else |
|
859 { |
|
860 __TRACE ( KError, ( CStifLogger::ERed, _L( "CTestModuleContainer::ChangeOperation NoMemory" ) ) ); |
|
861 } |
|
862 } |
|
863 else |
|
864 { |
|
865 // Construct heap buffer for configuration file |
|
866 TRAP( ret, iModuleNameBuffer = HBufC::NewL( aNameBuffer.Length() ) ); |
|
867 |
|
868 if( ret == KErrNone ) |
|
869 { |
|
870 iOperationName.Set ( iModuleNameBuffer->Des() ); |
|
871 iOperationName.Copy ( aNameBuffer ); |
|
872 |
|
873 iOperationIntBuffer = aInt; |
|
874 iOperationType = aOperation; |
|
875 } |
|
876 else |
|
877 { |
|
878 __TRACE ( KError, ( CStifLogger::ERed, _L( "CTestModuleContainer::ChangeOperation NoMemory" ) ) ); |
|
879 } |
|
880 } |
|
881 |
|
882 iOperationChangeSemaphore.Signal(); |
|
883 |
|
884 return ret; |
|
885 |
|
886 } |
|
887 |
|
888 /* |
|
889 ------------------------------------------------------------------------------- |
|
890 |
|
891 Class: CTestModuleContainer |
|
892 |
|
893 Method: ChangeOperationNoError |
|
894 |
|
895 Description: Multithread safe way to change operation. This version |
|
896 of function can't fail. |
|
897 |
|
898 Parameters: const TOperation aOperation :in: Operation type |
|
899 const TInt aInt :in: Operation specific int |
|
900 |
|
901 Return Values: None |
|
902 |
|
903 Errors/Exceptions: None |
|
904 |
|
905 Status: Proposal |
|
906 |
|
907 ------------------------------------------------------------------------------- |
|
908 */ |
|
909 void CTestModuleContainer::ChangeOperationNoError( const TOperation aOperation, |
|
910 const TInt aInt |
|
911 ) |
|
912 { |
|
913 |
|
914 iOperationChangeSemaphore.Wait(); |
|
915 |
|
916 iErrorResult = KErrNone; |
|
917 iModuleResult = KErrNone; |
|
918 iOperationIntBuffer = aInt; |
|
919 iOperationType = aOperation; |
|
920 |
|
921 iOperationChangeSemaphore.Signal(); |
|
922 |
|
923 } |
|
924 |
|
925 /* |
|
926 ------------------------------------------------------------------------------- |
|
927 |
|
928 Class: CTestModuleContainer |
|
929 |
|
930 Method: Operation |
|
931 |
|
932 Description: Multithread safe way to obtain current operation. |
|
933 |
|
934 Parameters: None |
|
935 |
|
936 Return Values: TBool Operation |
|
937 |
|
938 Errors/Exceptions: None |
|
939 |
|
940 Status: Proposal |
|
941 |
|
942 ------------------------------------------------------------------------------- |
|
943 */ |
|
944 //@spe const CTestModuleContainer::TOperation CTestModuleContainer::Operation() |
|
945 CTestModuleContainer::TOperation CTestModuleContainer::Operation() |
|
946 { |
|
947 TOperation operation; |
|
948 iOperationChangeSemaphore.Wait(); |
|
949 operation = iOperationType; |
|
950 iOperationChangeSemaphore.Signal(); |
|
951 |
|
952 return operation; |
|
953 |
|
954 } |
|
955 |
|
956 /* |
|
957 ------------------------------------------------------------------------------- |
|
958 |
|
959 Class: CTestModuleContainer |
|
960 |
|
961 Method: ModuleResult |
|
962 |
|
963 Description: Returns error code from test module |
|
964 |
|
965 Parameters: None |
|
966 |
|
967 Return Values: TInt Result code from module |
|
968 |
|
969 Errors/Exceptions: None |
|
970 |
|
971 Status: Proposal |
|
972 |
|
973 ------------------------------------------------------------------------------- |
|
974 */ |
|
975 TInt& CTestModuleContainer::ModuleResult() |
|
976 { |
|
977 |
|
978 return iModuleResult; |
|
979 |
|
980 } |
|
981 |
|
982 /* |
|
983 ------------------------------------------------------------------------------- |
|
984 |
|
985 Class: CTestModuleContainer |
|
986 |
|
987 Method: OperationErrorResult |
|
988 |
|
989 Description: Returns error code from test module |
|
990 |
|
991 Parameters: None |
|
992 |
|
993 Return Values: TInt Result code from module |
|
994 |
|
995 Errors/Exceptions: None |
|
996 |
|
997 Status: Proposal |
|
998 |
|
999 ------------------------------------------------------------------------------- |
|
1000 */ |
|
1001 TInt& CTestModuleContainer::OperationErrorResult() |
|
1002 { |
|
1003 |
|
1004 return iModuleResult; |
|
1005 |
|
1006 } |
|
1007 |
|
1008 /* |
|
1009 ------------------------------------------------------------------------------- |
|
1010 |
|
1011 Class: CTestModuleContainer |
|
1012 |
|
1013 Method: TestModuleName |
|
1014 |
|
1015 Description: Returns test module name. |
|
1016 |
|
1017 Parameters: None |
|
1018 |
|
1019 Return Values: const TDesC&: test module name |
|
1020 |
|
1021 Errors/Exceptions: None |
|
1022 |
|
1023 Status: Proposal |
|
1024 |
|
1025 ------------------------------------------------------------------------------- |
|
1026 */ |
|
1027 const TDesC& CTestModuleContainer::TestModuleName() |
|
1028 { |
|
1029 |
|
1030 return iCTestModule->Name(); |
|
1031 |
|
1032 } |
|
1033 |
|
1034 /* |
|
1035 ------------------------------------------------------------------------------- |
|
1036 |
|
1037 Class: CTestModuleContainer |
|
1038 |
|
1039 Method: TestModuleName |
|
1040 |
|
1041 Description: Returns test module name. |
|
1042 |
|
1043 Parameters: None |
|
1044 |
|
1045 Return Values: const TDesC&: test module name |
|
1046 |
|
1047 Errors/Exceptions: None |
|
1048 |
|
1049 Status: Proposal |
|
1050 |
|
1051 ------------------------------------------------------------------------------- |
|
1052 */ |
|
1053 const TDesC& CTestModuleContainer::TestModuleIniFile() |
|
1054 { |
|
1055 |
|
1056 return iCTestModule->IniName(); |
|
1057 |
|
1058 } |
|
1059 |
|
1060 /* |
|
1061 ------------------------------------------------------------------------------- |
|
1062 |
|
1063 Class: CTestModuleContainer |
|
1064 |
|
1065 Method: ModuleResult |
|
1066 |
|
1067 Description: Returns constant pointer to test case array |
|
1068 |
|
1069 Parameters: None |
|
1070 |
|
1071 Return Values: const RPointerArray<TTestCaseInfo>* Test cases |
|
1072 |
|
1073 Errors/Exceptions: None |
|
1074 |
|
1075 Status: Proposal |
|
1076 |
|
1077 ------------------------------------------------------------------------------- |
|
1078 */ |
|
1079 const RPointerArray<TTestCaseInfo>* CTestModuleContainer::TestCases() const |
|
1080 { |
|
1081 |
|
1082 if( !iUpAndRunning ) |
|
1083 { |
|
1084 return NULL; |
|
1085 } |
|
1086 |
|
1087 if( iThreadContainer == NULL ) |
|
1088 { |
|
1089 CTestServer::PanicServer( ENullTestThreadContainer ); |
|
1090 } |
|
1091 return iThreadContainer->TestCases(); |
|
1092 |
|
1093 } |
|
1094 |
|
1095 /* |
|
1096 ------------------------------------------------------------------------------- |
|
1097 |
|
1098 Class: CTestModuleContainer |
|
1099 |
|
1100 Method: Complete |
|
1101 |
|
1102 Description: Completes operation from any thread |
|
1103 |
|
1104 Parameters: const TInt aCompletionCode :in: Completion code |
|
1105 |
|
1106 Return Values: None |
|
1107 |
|
1108 Errors/Exceptions: Function panics if server's thread can't be opened. |
|
1109 |
|
1110 Status: Proposal |
|
1111 |
|
1112 ------------------------------------------------------------------------------- |
|
1113 */ |
|
1114 void CTestModuleContainer::Complete( const TInt aCompletionCode ) |
|
1115 { |
|
1116 |
|
1117 TRequestStatus* req = &iStatus; |
|
1118 User::RequestComplete( req, aCompletionCode ); |
|
1119 |
|
1120 } |
|
1121 |
|
1122 /* |
|
1123 ------------------------------------------------------------------------------- |
|
1124 |
|
1125 Class: CTestModuleContainer |
|
1126 |
|
1127 Method: DoErrorPrint |
|
1128 |
|
1129 Description: Handle error prints. |
|
1130 |
|
1131 Parameters: None |
|
1132 |
|
1133 Return Values: None |
|
1134 |
|
1135 Errors/Exceptions: None |
|
1136 |
|
1137 Status: Proposal |
|
1138 |
|
1139 ------------------------------------------------------------------------------- |
|
1140 */ |
|
1141 void CTestModuleContainer::DoErrorPrint() |
|
1142 { |
|
1143 |
|
1144 iCTestModule->ErrorPrint( iErrorPrint.iPriority, iErrorPrint.iText ); |
|
1145 |
|
1146 } |
|
1147 |
|
1148 /* |
|
1149 ------------------------------------------------------------------------------- |
|
1150 |
|
1151 Class: CTestModuleContainer |
|
1152 |
|
1153 Method: KillTestinterferenceThread |
|
1154 |
|
1155 Description: Make sure that any of the test interference thread's won't |
|
1156 stay to run if test case is crashed of test interference |
|
1157 object is not deleted. |
|
1158 |
|
1159 Parameters: None |
|
1160 |
|
1161 Return Values: None |
|
1162 |
|
1163 Errors/Exceptions: None |
|
1164 |
|
1165 Status: Proposal |
|
1166 |
|
1167 ------------------------------------------------------------------------------- |
|
1168 */ |
|
1169 void CTestModuleContainer::KillTestinterferenceThread() |
|
1170 { |
|
1171 if (iCTestExecution != NULL) |
|
1172 { |
|
1173 iCTestExecution->KillTestinterferenceThread(); |
|
1174 } |
|
1175 else |
|
1176 { |
|
1177 __TRACE( KError,( _L( "STIF internal error - iCTestExecution is NULL in CTestModuleContainer::KillTestinterferenceThread" ) ) ); |
|
1178 User::Panic(_L("NULL pointer exception"), KErrGeneral); |
|
1179 } |
|
1180 } |
|
1181 |
|
1182 /* |
|
1183 ------------------------------------------------------------------------------- |
|
1184 |
|
1185 Class: CTestModuleContainer |
|
1186 |
|
1187 Method: KillTestMeasurement |
|
1188 |
|
1189 Description: Make sure that any of the test measurement process's won't |
|
1190 stay to run if test case is crashed of test measurement object |
|
1191 is not deleted. |
|
1192 |
|
1193 Parameters: None |
|
1194 |
|
1195 Return Values: None |
|
1196 |
|
1197 Errors/Exceptions: None |
|
1198 |
|
1199 Status: Approved |
|
1200 |
|
1201 ------------------------------------------------------------------------------- |
|
1202 */ |
|
1203 void CTestModuleContainer::KillTestMeasurement() |
|
1204 { |
|
1205 if (iCTestExecution != NULL) |
|
1206 { |
|
1207 iCTestExecution->KillTestMeasurement(); |
|
1208 } |
|
1209 else |
|
1210 { |
|
1211 __TRACE( KError,( _L( "STIF internal error - iCTestExecution is NULL in CTestModuleContainer::KillTestMeasurement" ) ) ); |
|
1212 User::Panic(_L("NULL pointer exception"), KErrGeneral); |
|
1213 } |
|
1214 } |
|
1215 |
|
1216 /* |
|
1217 ------------------------------------------------------------------------------- |
|
1218 |
|
1219 Class: CTestModuleContainer |
|
1220 |
|
1221 Method: GetRequest |
|
1222 |
|
1223 Description: Return status flags. |
|
1224 |
|
1225 Parameters: TRequestType aType: in: request type |
|
1226 |
|
1227 Return Values: TRequestStatus*: pointer to TRequestStatus |
|
1228 |
|
1229 Errors/Exceptions: None |
|
1230 |
|
1231 Status: Proposal |
|
1232 |
|
1233 ------------------------------------------------------------------------------- |
|
1234 */ |
|
1235 TRequestStatus* CTestModuleContainer::GetRequest( TRequestType aType ) |
|
1236 { |
|
1237 |
|
1238 TRequestStatus* status = NULL; |
|
1239 |
|
1240 switch( aType ) |
|
1241 { |
|
1242 case ERqTestCase: |
|
1243 status = &iStatus; |
|
1244 break; |
|
1245 case ERqErrorPrint: |
|
1246 status = &iErrorPrintHandler->iStatus; |
|
1247 break; |
|
1248 default: |
|
1249 break; |
|
1250 } |
|
1251 |
|
1252 return status; |
|
1253 |
|
1254 } |
|
1255 |
|
1256 /* |
|
1257 ------------------------------------------------------------------------------- |
|
1258 |
|
1259 Class: CTestModuleContainer |
|
1260 |
|
1261 Method: RunL |
|
1262 |
|
1263 Description: Stops active scheduler when operation in another thread |
|
1264 is completed. |
|
1265 |
|
1266 Parameters: None |
|
1267 |
|
1268 Return Values: None |
|
1269 |
|
1270 Errors/Exceptions: None |
|
1271 |
|
1272 Status: Proposal |
|
1273 |
|
1274 ------------------------------------------------------------------------------- |
|
1275 */ |
|
1276 void CTestModuleContainer::RunL() |
|
1277 { |
|
1278 |
|
1279 if( iOperationType == CTestModuleContainer::EExecuteTestInThread ) |
|
1280 { |
|
1281 // Make sure that any of the test interference thread's won't stay |
|
1282 // to run. |
|
1283 KillTestinterferenceThread(); |
|
1284 |
|
1285 // Make sure that any of the test measurement process's won't stay |
|
1286 // to run. |
|
1287 KillTestMeasurement(); |
|
1288 |
|
1289 if(iCTestExecution == NULL) |
|
1290 { |
|
1291 __TRACE( KError,( _L( "STIF internal error - iCTestExecution is NULL in CTestModuleContainer::RunL" ) ) ); |
|
1292 User::Leave(KErrGeneral); |
|
1293 } |
|
1294 else |
|
1295 { |
|
1296 // Set the thread state |
|
1297 iCTestExecution->SetThreadState( CTestExecution::EFinished ); |
|
1298 |
|
1299 // If test print queue is empty, then complete request with KEof. If Queue |
|
1300 // is not empty, then do not complete. Queue will be emptied by UI. |
|
1301 iCTestExecution->CompletePrintRequestIfQueueEmpty(); |
|
1302 |
|
1303 // Event queue clean-up |
|
1304 iCTestExecution->CleanupEvents(); |
|
1305 |
|
1306 // Complete the test request |
|
1307 iCTestExecution->CompleteTestExecution( iStatus.Int() ); |
|
1308 |
|
1309 // Test case execution OK and test module thread's pause operation |
|
1310 // is not ongoing. Re-use old test module execution thread |
|
1311 if( iCTestExecution->TestThreadFailure() == CTestExecution::ETestThreadOk && !iIsPaused ) |
|
1312 { |
|
1313 // Return this module to pool |
|
1314 __TRACE( KInit, ( _L("Freeing test module container at 0x%x"), |
|
1315 (TUint32) this ) ); |
|
1316 iCTestModule->FreeTestModule( this ); |
|
1317 } |
|
1318 // Problems in test case execution. Delete this test module thread and |
|
1319 // start next test case in new test module thread. |
|
1320 else |
|
1321 { |
|
1322 if( iIsPaused ) |
|
1323 { |
|
1324 // Test case is paused by user and this RunL is executed also. |
|
1325 // This RunL will make Resume() operation to fail because test |
|
1326 // case is finished. Next test case cannot complete and that is |
|
1327 // why next test case will start at the "clean table". |
|
1328 __TRACE( KInit, ( _L( "Delete test module container at 0x%x because test module thread is paused while test case is finished(Cannot Resume())" ), (TUint32) this ) ); |
|
1329 } |
|
1330 else |
|
1331 { |
|
1332 // delete test module thread if some thread problem has occurred |
|
1333 __TRACE( KInit, ( _L("Delete test module container at 0x%x because of thread leak (0x%x)"), |
|
1334 (TUint32) this, iCTestExecution->TestThreadFailure() ) ); |
|
1335 } |
|
1336 delete this; |
|
1337 } |
|
1338 } |
|
1339 } |
|
1340 else |
|
1341 { |
|
1342 // Synchronous operation is completed, stop "nested" active scheduler. |
|
1343 //CActiveScheduler::Stop(); |
|
1344 iNestedActiveScheduler->AsyncStop(); |
|
1345 // Execution continues from CTestModuleContainer::WaitOperation(). |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 |
|
1350 /* |
|
1351 ------------------------------------------------------------------------------- |
|
1352 |
|
1353 Class: CTestModuleContainer |
|
1354 |
|
1355 Method: DoCancel |
|
1356 |
|
1357 Description: Cancel asyncronous request. |
|
1358 |
|
1359 Parameters: None |
|
1360 |
|
1361 Return Values: None |
|
1362 |
|
1363 Errors/Exceptions: None |
|
1364 |
|
1365 Status: Proposal |
|
1366 |
|
1367 ------------------------------------------------------------------------------- |
|
1368 */ |
|
1369 void CTestModuleContainer::DoCancel() |
|
1370 { |
|
1371 |
|
1372 if ( iUpAndRunning == EFalse ) |
|
1373 { |
|
1374 |
|
1375 // Before the completion check if the status was not already completed |
|
1376 // from other thread in CTestThreadContainer::TestComplete(). |
|
1377 // For details see Jira STIF-564 |
|
1378 if(iStatus == KRequestPending) |
|
1379 Complete ( KErrCancel ); |
|
1380 |
|
1381 } |
|
1382 |
|
1383 } |
|
1384 |
|
1385 |
|
1386 |
|
1387 /* |
|
1388 ------------------------------------------------------------------------------- |
|
1389 |
|
1390 Class: CTestModuleContainer |
|
1391 |
|
1392 Method: RunError |
|
1393 |
|
1394 Description: Handle errors. |
|
1395 |
|
1396 Because RunL does not leave, one should never come here. Just forward |
|
1397 error code and let framework panic the server in case of error. |
|
1398 |
|
1399 Parameters: TInt aError: :in: Error code |
|
1400 |
|
1401 Return Values: TInt Error code |
|
1402 |
|
1403 Errors/Exceptions: None |
|
1404 |
|
1405 Status: Proposal |
|
1406 |
|
1407 ------------------------------------------------------------------------------- |
|
1408 */ |
|
1409 TInt CTestModuleContainer::RunError( TInt aError ) |
|
1410 { |
|
1411 |
|
1412 __TRACE( KError,( _L( "CTestModuleContainer::RunError %d" ), aError ) ); |
|
1413 |
|
1414 return aError; |
|
1415 |
|
1416 } |
|
1417 |
|
1418 /* |
|
1419 ------------------------------------------------------------------------------- |
|
1420 |
|
1421 Class: CTestModuleContainer |
|
1422 |
|
1423 Method: ReadParametersFromScriptFileL |
|
1424 |
|
1425 Description: Read test class parameters from script file if parameter(s) |
|
1426 are/is set(TestScripter and TestCombiner). |
|
1427 |
|
1428 Parameters: const TDesC& aConfig: in: Test case (config) file name. |
|
1429 TUint32& aStackSize: inout: Stack size. |
|
1430 TUint32& aHeapMinSize: inout: Heap's minimum size. |
|
1431 TUint32& aHeapMaxSize: inout: Heap's maximum size. |
|
1432 |
|
1433 Return Values: Symbian error code. |
|
1434 |
|
1435 Errors/Exceptions: Leaves if User::LeaveIfError() leaves |
|
1436 Leaves if User::LeaveIfNull() leaves |
|
1437 |
|
1438 Status: Approved |
|
1439 |
|
1440 ------------------------------------------------------------------------------- |
|
1441 */ |
|
1442 TInt CTestModuleContainer::ReadParametersFromScriptFileL( |
|
1443 const TDesC& aConfig, |
|
1444 TInt& aStackSize, |
|
1445 TInt& aHeapMinSize, |
|
1446 TInt& aHeapMaxSize ) |
|
1447 { |
|
1448 // __UHEAP_MARK; |
|
1449 |
|
1450 RFs fileServer; |
|
1451 RFile file; |
|
1452 TInt ret( KErrNone ); |
|
1453 |
|
1454 User::LeaveIfError( fileServer.Connect() ); |
|
1455 CleanupClosePushL( fileServer ); |
|
1456 |
|
1457 __TRACE( KInit, ( _L( "ReadParametersFromScriptFile(): Open configfile [%S]" ), &aConfig ) ); |
|
1458 |
|
1459 TParse parse; |
|
1460 parse.Set( aConfig, NULL, NULL ); |
|
1461 |
|
1462 User::LeaveIfError( fileServer.SetSessionPath( parse.DriveAndPath() ) ); |
|
1463 |
|
1464 User::LeaveIfError( file.Open( fileServer, aConfig, EFileRead | EFileShareAny ) ); |
|
1465 CleanupClosePushL( file ); |
|
1466 |
|
1467 TInt size( 0 ); |
|
1468 User::LeaveIfError( file.Size( size ) ); |
|
1469 |
|
1470 const TInt tmpSize = KMaxName; // 128 |
|
1471 TInt offset( 0 ); // Offset value to parts reading |
|
1472 |
|
1473 // Indications for tags |
|
1474 TBool start_tag_found( EFalse ); |
|
1475 TBool end_tag_found( EFalse ); |
|
1476 // Offset values for start and end position parsing |
|
1477 TInt offset_start( 0 ); |
|
1478 TInt offset_end( 0 ); |
|
1479 |
|
1480 /* Search is combined to section that include tags. After this create new |
|
1481 combined section that include second buffer data and new buffer data. |
|
1482 Section: 1) 1+2 |
|
1483 2) 2+1 |
|
1484 2) 1+2 etc. This should ensure that all data is search. |
|
1485 */ |
|
1486 |
|
1487 // Construct modifiable heap-based descriptor. tmp1 to CleanupStack |
|
1488 // This for first data buffer |
|
1489 HBufC8* tmp1 = HBufC8::NewLC( tmpSize ); // 128 |
|
1490 TPtr8 buf1 = tmp1->Des(); |
|
1491 |
|
1492 // Construct modifiable heap-based descriptor. tmp2 to CleanupStack |
|
1493 // This for second data buffer |
|
1494 HBufC8* tmp2 = HBufC8::NewLC( tmpSize ); // 128 |
|
1495 TPtr8 buf2 = tmp2->Des(); |
|
1496 |
|
1497 // Construct modifiable heap-based descriptor. tmp3 to CleanupStack |
|
1498 // This includes both first and second data buffers |
|
1499 HBufC* tmp3 = HBufC::NewLC( tmpSize + tmpSize ); // 256 |
|
1500 TPtr currentSection = tmp3->Des(); |
|
1501 |
|
1502 // Construct modifiable heap-based descriptor. tmp4 to CleanupStack |
|
1503 // This is for changing 8 bit to 16 bit |
|
1504 HBufC* tmp4 = HBufC::NewLC( tmpSize ); // 128 |
|
1505 TPtr to16bit = tmp4->Des(); |
|
1506 |
|
1507 ret = KErrNone; |
|
1508 |
|
1509 // Read data to buffer 1 |
|
1510 // tmp4, tmp3, tmp2 and tmp1 are in CleanupStack => Leave OK |
|
1511 // CleanupClosePushL is used to fileServer and file => Leave OK |
|
1512 User::LeaveIfError( file.Read( offset, buf1, tmpSize ) ); |
|
1513 |
|
1514 // For next buffer reading |
|
1515 offset += tmpSize; |
|
1516 |
|
1517 // Read data to buffer 2 |
|
1518 // tmp4, tmp3, tmp2 and tmp1 are in CleanupStack => Leave OK |
|
1519 // CleanupClosePushL is used to fileServer and file => Leave OK |
|
1520 User::LeaveIfError( file.Read( offset, buf2, tmpSize ) ); |
|
1521 |
|
1522 // 8 bit to 16. Create first combined buffer 1 and buffer 2 that |
|
1523 // is used for searching. |
|
1524 to16bit.Copy( buf1 ); |
|
1525 currentSection.Copy( to16bit ); |
|
1526 to16bit.Copy( buf2 ); |
|
1527 currentSection.Append( to16bit ); |
|
1528 |
|
1529 // Check if small files to be parsed(e.g. settings + one short case). |
|
1530 TInt bigsize( 0 ); |
|
1531 // Check if parsed section is smaller than 256 |
|
1532 if( size < ( tmpSize + tmpSize ) ) |
|
1533 { |
|
1534 bigsize = size; |
|
1535 } |
|
1536 else |
|
1537 { |
|
1538 bigsize = tmpSize + tmpSize; // 256 |
|
1539 } |
|
1540 |
|
1541 do |
|
1542 { |
|
1543 // Start the next buffer reading |
|
1544 offset += tmpSize; |
|
1545 |
|
1546 // Search the start tag |
|
1547 ret = currentSection.Find( KStifSettingsStartTag ); |
|
1548 if( ret != KErrNotFound ) |
|
1549 { |
|
1550 // Succesfully search, take the start offset |
|
1551 ret = file.Seek( ESeekCurrent, offset_start ); |
|
1552 if( ret == KErrNone ) |
|
1553 { |
|
1554 start_tag_found = ETrue; |
|
1555 // Current section is end so offset to beging of the |
|
1556 // combined section. |
|
1557 offset_start = ( offset_start - ( bigsize ) ); |
|
1558 } |
|
1559 } |
|
1560 // Search the end tag |
|
1561 ret = currentSection.Find( KStifSettingsEndTag ); |
|
1562 if( ret != KErrNotFound ) |
|
1563 { |
|
1564 // Succesfully search, take the end offset |
|
1565 ret = file.Seek( ESeekCurrent, offset_end ); |
|
1566 if( ret == KErrNone ) |
|
1567 { |
|
1568 end_tag_found = ETrue; |
|
1569 } |
|
1570 } |
|
1571 |
|
1572 // Both start and end tags are founded, start parsing sizes. |
|
1573 if( start_tag_found && end_tag_found ) |
|
1574 { |
|
1575 TInt length = ( offset_end - offset_start ); |
|
1576 |
|
1577 // Construct modifiable heap-based descriptor. |
|
1578 // setting_buf to CleanupStack |
|
1579 HBufC8* setting_buf = HBufC8::NewLC( length );// 8 bit for reading |
|
1580 TPtr8 setting8 = setting_buf->Des(); |
|
1581 |
|
1582 // Construct modifiable heap-based descriptor. |
|
1583 // setting_buf2 to CleanupStack |
|
1584 HBufC* setting_buf2 = HBufC::NewLC( length );// 16 bit for parsing |
|
1585 TPtr setting16 = setting_buf2->Des(); |
|
1586 |
|
1587 // Read data from the founded STIF settings sections |
|
1588 ret = KErrNone; |
|
1589 // HBufCs are in CleanupStack => Leave OK |
|
1590 // CleanupClosePushL is used to fileServer and file => Leave OK |
|
1591 User::LeaveIfError( file.Read( offset_start, setting8, length ) ); |
|
1592 |
|
1593 // Section 8 bit to 16. |
|
1594 setting16.Copy( setting8 ); |
|
1595 |
|
1596 // Start create parser for parsing heap and stack sizes. |
|
1597 // NOTE: Comments are parsed away from the section. |
|
1598 CStifParser* parser = NULL; |
|
1599 User::LeaveIfNull( parser = CStifParser::NewL( setting16, |
|
1600 CStifParser::ECStyleComments ) ); |
|
1601 CleanupStack::PushL(parser); |
|
1602 |
|
1603 CStifSectionParser* section = NULL; |
|
1604 User::LeaveIfNull( section = parser->SectionL( KStifSettingsStartTag, |
|
1605 KStifSettingsEndTag ) ); |
|
1606 CleanupStack::PushL(section); |
|
1607 TInt lineRet( KErrNone ); |
|
1608 TInt integer( 0 ); |
|
1609 |
|
1610 // Try to get stack size |
|
1611 CStifItemParser* itemLine = NULL; |
|
1612 TRAPD( parse_ret, itemLine = section->GetItemLineL( |
|
1613 KUserDefStackSize ) ); |
|
1614 if ( parse_ret == KErrNone && itemLine != NULL ) |
|
1615 { |
|
1616 lineRet = itemLine->GetInt( KUserDefStackSize, integer ); |
|
1617 if ( lineRet == KErrNone ) |
|
1618 { |
|
1619 aStackSize = integer; |
|
1620 } |
|
1621 } |
|
1622 delete itemLine; |
|
1623 itemLine = NULL; |
|
1624 |
|
1625 // Try to get minimum heap size |
|
1626 TRAP( parse_ret, itemLine = section->GetItemLineL( |
|
1627 KUserDefMinHeap ) ); |
|
1628 if ( parse_ret == KErrNone && itemLine != NULL ) |
|
1629 { |
|
1630 lineRet = itemLine->GetInt( KUserDefMinHeap, integer ); |
|
1631 if ( lineRet == KErrNone ) |
|
1632 { |
|
1633 aHeapMinSize = integer; |
|
1634 } |
|
1635 } |
|
1636 delete itemLine; |
|
1637 itemLine = NULL; |
|
1638 |
|
1639 // Try to get maximum heap size |
|
1640 TRAP( parse_ret, itemLine = section->GetItemLineL( |
|
1641 KUserDefMaxHeap ) ); |
|
1642 if ( parse_ret == KErrNone && itemLine != NULL ) |
|
1643 { |
|
1644 lineRet = itemLine->GetInt( KUserDefMaxHeap, integer ); |
|
1645 if ( lineRet == KErrNone ) |
|
1646 { |
|
1647 aHeapMaxSize = integer; |
|
1648 } |
|
1649 } |
|
1650 delete itemLine; |
|
1651 |
|
1652 CleanupStack::Pop(section); |
|
1653 CleanupStack::Pop(parser); |
|
1654 |
|
1655 CleanupStack::PopAndDestroy( setting_buf2 ); |
|
1656 CleanupStack::PopAndDestroy( setting_buf ); |
|
1657 |
|
1658 delete section; |
|
1659 delete parser; |
|
1660 |
|
1661 break; // Stop the do branch |
|
1662 } |
|
1663 |
|
1664 // Start to create new section for search |
|
1665 |
|
1666 // 8 bit to 16. Last buffer to first |
|
1667 to16bit.Copy( buf2 ); |
|
1668 currentSection.Copy( to16bit ); |
|
1669 |
|
1670 // Read new data to buffer 1 |
|
1671 ret = KErrNone; |
|
1672 User::LeaveIfError( file.Read( offset, buf1, tmpSize ) ); |
|
1673 |
|
1674 // 8 bit to 16. Append |
|
1675 to16bit.Copy( buf1 ); |
|
1676 currentSection.Append( to16bit ); |
|
1677 |
|
1678 // Copy first buffer data to buffer 2. This is added to first |
|
1679 // in section in next run |
|
1680 buf2.Copy( buf1 ); |
|
1681 |
|
1682 } while( offset < size ); |
|
1683 |
|
1684 CleanupStack::PopAndDestroy( tmp4 ); |
|
1685 CleanupStack::PopAndDestroy( tmp3 ); |
|
1686 CleanupStack::PopAndDestroy( tmp2 ); |
|
1687 CleanupStack::PopAndDestroy( tmp1 ); |
|
1688 |
|
1689 CleanupStack::PopAndDestroy( &file ); |
|
1690 CleanupStack::PopAndDestroy( &fileServer ); |
|
1691 file.Close(); |
|
1692 fileServer.Close(); |
|
1693 |
|
1694 //__UHEAP_MARKEND; |
|
1695 |
|
1696 return KErrNone; |
|
1697 |
|
1698 } |
|
1699 |
|
1700 /* |
|
1701 ------------------------------------------------------------------------------- |
|
1702 |
|
1703 Class: CTestModuleContainer |
|
1704 |
|
1705 Method: ReadParametersFromTestModule |
|
1706 |
|
1707 Description: Loads dynamically testmodule and calls SetRequirements()- |
|
1708 method for test module parameter handling. |
|
1709 |
|
1710 Parameters: const TDesC& aModuleName: in: Test module name |
|
1711 CTestModuleParam*& aTestModuleParam: inout: Object for handling |
|
1712 test module parameters. |
|
1713 |
|
1714 Return Values: TInt: Symbian error code. |
|
1715 |
|
1716 Errors/Exceptions: None. |
|
1717 |
|
1718 Status: Proposal |
|
1719 |
|
1720 ------------------------------------------------------------------------------- |
|
1721 */ |
|
1722 TInt CTestModuleContainer::ReadParametersFromTestModule( |
|
1723 const TDesC& aModuleName, |
|
1724 CTestModuleParam*& aTestModuleParam ) |
|
1725 { |
|
1726 __TRACE( KInit, ( _L( "ReadParametersFromTestModule() [%S]" ), &aModuleName ) ); |
|
1727 RLibrary testModule; |
|
1728 // Load the module |
|
1729 TPtrC dllName; |
|
1730 |
|
1731 // Remove optional index appended to module name |
|
1732 TFileName validModuleName; |
|
1733 RemoveOptionalIndex(aModuleName, validModuleName); |
|
1734 __TRACE(KInit, (_L( "Valid module name is [%S] (extracted from [%S])"), &validModuleName, &aModuleName)); |
|
1735 dllName.Set(validModuleName); |
|
1736 |
|
1737 // Loading should work with and without '.dll' extension. |
|
1738 TInt r = testModule.Load( dllName ); |
|
1739 if ( r != KErrNone ) |
|
1740 { |
|
1741 __TRACE( KError, ( CStifLogger::EError, _L("Can't initialize test module[%S], code = %d"), &dllName, r ) ); |
|
1742 return KErrNotFound; |
|
1743 } |
|
1744 else |
|
1745 { |
|
1746 // Print reset module name |
|
1747 __TRACE( KInit, ( _L("Loaded test module[%S]"), &dllName ) ); |
|
1748 } |
|
1749 |
|
1750 // Verify the UID |
|
1751 TUid KUidTestModule = TUid::Uid ( 0x101FB3E7 ); |
|
1752 TUidType requiredUID( KDynamicLibraryUid, KSharedLibraryUid, KUidTestModule ); |
|
1753 |
|
1754 TUidType moduleUID = testModule.Type(); |
|
1755 if ( moduleUID != requiredUID ) |
|
1756 { |
|
1757 // New instance can't be created |
|
1758 RDebug::Print( ( _L("STIF TF: Test module has invalid UID. Aborting loading!") ) ); |
|
1759 __TRACE ( KError, ( CStifLogger::EError, _L("Test module has invalid UID. Aborting loading!" ) ) ); |
|
1760 testModule.Close(); |
|
1761 return KErrNotSupported; |
|
1762 } |
|
1763 |
|
1764 CTestInterfaceFactoryTestModule libEntry = NULL; |
|
1765 |
|
1766 #if defined( __ARMCC__ ) |
|
1767 { |
|
1768 // In this environment the heap and stack feature may crash if |
|
1769 // test module not include a workaround for ARM RVCT(ARMv5) compiler |
|
1770 // error. For more information see STIF user guide. |
|
1771 __TRACE ( KInit, ( _L( "Workaround for ARM RVCT(ARMv5) compiler error should be included to TestModule." ) ) ); |
|
1772 } |
|
1773 #endif // #if defined(__ARMCC__) |
|
1774 |
|
1775 // Get pointer to second exported function |
|
1776 // Verify that there is function |
|
1777 //CTestInterfaceFactoryTestModule libEntry; |
|
1778 libEntry = (CTestInterfaceFactoryTestModule) testModule.Lookup( 2 ); |
|
1779 if ( libEntry == NULL ) |
|
1780 { |
|
1781 // New instance can't be created |
|
1782 __TRACE( KInit, (_L( "Test module is old version and has not SetRequirements() feature." ) ) ); |
|
1783 testModule.Close(); |
|
1784 return KErrNotSupported; |
|
1785 } |
|
1786 else |
|
1787 { |
|
1788 __TRACE ( KInit, ( _L("Pointer to 2st exported received"))); |
|
1789 } |
|
1790 |
|
1791 // Calls dynamically loaded module's second method. |
|
1792 __TRACE ( KVerbose, (_L("Calling 2st exported at 0x%x"), (TUint32) libEntry )); |
|
1793 TUint32 check = 0; |
|
1794 TInt ret = (*libEntry)( aTestModuleParam, check ); |
|
1795 if( check != KStifTestModuleParameterChanged ) |
|
1796 { |
|
1797 // Problems in def-file definitions. Test module is old wersion |
|
1798 // and has not SetRequirements feature. |
|
1799 RDebug::Print( ( _L( "STIF TF: Test module is old version and has not SetRequirements() feature." ) ) ); |
|
1800 __TRACE( KInit, (_L( "Test module is old version and has not SetRequirements() feature." ) ) ); |
|
1801 testModule.Close(); |
|
1802 return KErrNotSupported; |
|
1803 } |
|
1804 if( ret != KErrNone ) |
|
1805 { |
|
1806 __TRACE (KInit, (_L("ReadParametersFromTestModule; SetRequirements fails with error: %d"), ret ) ); |
|
1807 testModule.Close(); |
|
1808 return ret; |
|
1809 } |
|
1810 |
|
1811 libEntry = NULL; |
|
1812 testModule.Close(); // After close test module's pointer is not |
|
1813 // valid anymore. |
|
1814 |
|
1815 return KErrNone; |
|
1816 |
|
1817 } |
|
1818 |
|
1819 /* |
|
1820 ------------------------------------------------------------------------------- |
|
1821 |
|
1822 Class: CTestModuleContainer |
|
1823 |
|
1824 Method: GetTestModuleParams |
|
1825 |
|
1826 Description: Load test module dynamically. If loading is done succesfully |
|
1827 then set test module's parameters according to version. |
|
1828 Verify received parameters. |
|
1829 |
|
1830 Parameters: const TDesC& aModuleName: in: Test module name. |
|
1831 const TDesC& aConfig: in: Test case (config) file name. |
|
1832 TInt& aStackSize: inout: Stack size. |
|
1833 TInt& aHeapMinSize: inout: Heap's minimum size. |
|
1834 TInt& aHeapMaxSize: inout: Heap's maximum size. |
|
1835 |
|
1836 Return Values: TInt: Symbian error code. |
|
1837 |
|
1838 Errors/Exceptions: None |
|
1839 |
|
1840 Status: Proposal |
|
1841 |
|
1842 ------------------------------------------------------------------------------- |
|
1843 */ |
|
1844 TInt CTestModuleContainer::GetTestModuleParams( const TDesC& aModuleName, |
|
1845 const TDesC& aConfig, |
|
1846 TInt& aStackSize, |
|
1847 TInt& aHeapMinSize, |
|
1848 TInt& aHeapMaxSize ) |
|
1849 { |
|
1850 TInt r( KErrNone ); |
|
1851 |
|
1852 // There is lower case despite what is initialization file given. |
|
1853 // Module name is without dll extension. |
|
1854 // Check is TestScripter or TestCombiner and test case (config) file |
|
1855 // name is given. |
|
1856 if( ( aModuleName.Find( KTestScripterName ) != KErrNotFound || |
|
1857 aModuleName == _L( "testcombiner" ) ) && aConfig != KNullDesC ) |
|
1858 { |
|
1859 TRAPD( ret, r = ReadParametersFromScriptFileL( aConfig, aStackSize, |
|
1860 aHeapMinSize, aHeapMaxSize ) ); |
|
1861 if( r != KErrNone ) |
|
1862 { |
|
1863 __TRACE( KInit, ( CStifLogger::ERed, _L( "Cannot set Test Class's stack or heap sizes, fail with error: %d" ), r ) ); |
|
1864 __TRACE( KInit, ( _L( "Default sizes will be use(See KTestThreadMinHeap, KTestThreadMinHeap and KStackSize)" ) ) ); |
|
1865 return r; |
|
1866 } |
|
1867 if( ret != KErrNone ) |
|
1868 { |
|
1869 __TRACE( KInit, ( CStifLogger::ERed, _L( "Cannot set Test Class's stack or heap sizes, leaves with error: %d" ), r ) ); |
|
1870 __TRACE( KInit, ( _L( "Default sizes will be use(See KTestThreadMinHeap, KTestThreadMinHeap and KStackSize)" ) ) ); |
|
1871 return ret; |
|
1872 } |
|
1873 } |
|
1874 else |
|
1875 { |
|
1876 CTestModuleParam* testModuleParam = NULL; |
|
1877 //--PYTHON-- begin |
|
1878 if(aModuleName.Find(KPythonScripter) != KErrNotFound) |
|
1879 { |
|
1880 RDebug::Print(_L("CTestModuleContainer::GetTestModuleParams reading params for PythonScripter, aModuleName=[%S]"), &aModuleName); |
|
1881 TName n; |
|
1882 n.Copy(KPythonScripter); |
|
1883 r = ReadParametersFromTestModule( n, testModuleParam ); |
|
1884 } |
|
1885 else |
|
1886 //--PYTHON-- end |
|
1887 r = ReadParametersFromTestModule( aModuleName, testModuleParam ); |
|
1888 |
|
1889 if( r != KErrNone ) |
|
1890 { |
|
1891 __TRACE( KInit, ( _L( "Cannot set Test Module's stack or heap sizes, fails with: %d" ), r ) ); |
|
1892 __TRACE( KInit, ( _L( "Default sizes will be use(See KTestThreadMinHeap, KTestThreadMinHeap and KStackSize)" ) ) ); |
|
1893 delete testModuleParam; |
|
1894 return r; |
|
1895 } |
|
1896 |
|
1897 if ( testModuleParam->Version() == 1 ) |
|
1898 { |
|
1899 // Casting |
|
1900 CTestModuleParamVer01* paramVer01 = ( CTestModuleParamVer01* ) testModuleParam; |
|
1901 aStackSize = paramVer01->iTestThreadStackSize; |
|
1902 aHeapMinSize = paramVer01->iTestThreadMinHeap; |
|
1903 aHeapMaxSize = paramVer01->iTestThreadMaxHeap; |
|
1904 } |
|
1905 |
|
1906 delete testModuleParam; |
|
1907 } |
|
1908 |
|
1909 // Verify that sizes are valid. If problems are notices then use default |
|
1910 // value |
|
1911 |
|
1912 // 1) "The panic occurs when the value of the stack size is negative." |
|
1913 if( aStackSize < 0 ) |
|
1914 { |
|
1915 RDebug::Print( ( _L("STIF TF: GetTestModuleParams() fails because value of the stack size is negative, default value is taken into use") ) ); |
|
1916 __TRACE( KInit, ( CStifLogger::ERed, _L("STIF TF: GetTestModuleParams() fails because value of the stack size is negative, default value is taken into use" ) ) ); |
|
1917 // Use default value |
|
1918 aStackSize = KStackSize; |
|
1919 } |
|
1920 |
|
1921 // 2) "The panic occurs if the minimum heap size specified is less |
|
1922 // than KMinHeapSize". |
|
1923 // KMinHeapSize: "Functions that require a new heap to be allocated will |
|
1924 // either panic, or will reset the required heap size to this value if a |
|
1925 // smaller heap size is specified". |
|
1926 if( aHeapMinSize < KMinHeapSize ) |
|
1927 { |
|
1928 RDebug::Print( _L( "STIF TF: GetTestModuleParams() fails because test module minimum heap size is less than KMinHeapSize:[%d], default value is taken into use" ), KMinHeapSize ); |
|
1929 __TRACE( KInit, ( CStifLogger::ERed, _L("STIF TF: GetTestModuleParams() fails because test module minimum heap size is less than KMinHeapSize:[%d], default value is taken into use"), KMinHeapSize ) ); |
|
1930 // Use default value(Note: This is used for now on) |
|
1931 aHeapMinSize = KTestThreadMinHeap; |
|
1932 } |
|
1933 |
|
1934 // 3) "The panic occurs if the minimum heap size specified is greater than |
|
1935 // the maximum size to which the heap can grow". |
|
1936 // Check this last ! |
|
1937 if( aHeapMinSize > aHeapMaxSize ) |
|
1938 { |
|
1939 RDebug::Print( ( _L("STIF TF: GetTestModuleParams() fails because the maximum heap size is specified less than minimum heap size, default values is taken into use" ) ) ); |
|
1940 __TRACE( KInit, ( CStifLogger::ERed, _L( "STIF TF: GetTestModuleParams() fails because the maximum heap size is specified less than minimum heap size, default values is taken into use" ) ) ); |
|
1941 // Use default values |
|
1942 aHeapMinSize = KTestThreadMinHeap; |
|
1943 aHeapMaxSize = KTestThreadMaxHeap; |
|
1944 } |
|
1945 |
|
1946 __TRACE( KInit, ( _L( "[%S] uses:" ), &aModuleName ) ); |
|
1947 __TRACE( KInit, ( _L( "Stack size: [%d]" ), aStackSize ) ); |
|
1948 __TRACE( KInit, ( _L( "Minimum heap size: [%d]" ), aHeapMinSize ) ); |
|
1949 __TRACE( KInit, ( _L( "Maximum heap size: [%d]" ), aHeapMaxSize ) ); |
|
1950 |
|
1951 return KErrNone; |
|
1952 |
|
1953 } |
|
1954 |
|
1955 /* |
|
1956 ------------------------------------------------------------------------------- |
|
1957 |
|
1958 Class: CTestModuleContainer |
|
1959 |
|
1960 Method: GetTestCaseTitleL |
|
1961 |
|
1962 Description: Gets title of currently running test case. |
|
1963 |
|
1964 Parameters: TDes& aTestCaseTitle: out: Test case title. |
|
1965 |
|
1966 Return Values: None |
|
1967 |
|
1968 Errors/Exceptions: None |
|
1969 |
|
1970 Status: Proposal |
|
1971 |
|
1972 ------------------------------------------------------------------------------- |
|
1973 */ |
|
1974 void CTestModuleContainer::GetTestCaseTitleL(TDes& aTestCaseTitle) |
|
1975 { |
|
1976 iCTestModule->GetTestCaseTitleL(iOperationIntBuffer, aTestCaseTitle); //currently run test case stored in the iOperationIntBuffer variable |
|
1977 } |
|
1978 |
|
1979 |
|
1980 /* |
|
1981 ------------------------------------------------------------------------------- |
|
1982 |
|
1983 Class: CTestModuleContainer |
|
1984 |
|
1985 Method: GetTestModule |
|
1986 |
|
1987 Description: Gets pointer to test module |
|
1988 |
|
1989 Parameters: none |
|
1990 |
|
1991 Return Values: CTestModule* : Pointer to test module |
|
1992 |
|
1993 Errors/Exceptions: None |
|
1994 |
|
1995 Status: Proposal |
|
1996 |
|
1997 ------------------------------------------------------------------------------- |
|
1998 */ |
|
1999 CTestModule* CTestModuleContainer::GetTestModule() |
|
2000 { |
|
2001 |
|
2002 return iCTestModule; |
|
2003 } |
|
2004 |
|
2005 |
|
2006 /* |
|
2007 ------------------------------------------------------------------------------- |
|
2008 |
|
2009 DESCRIPTION |
|
2010 |
|
2011 This module contains implementation of CPrintHandler class member functions. |
|
2012 CErrorPrintHandler listens print notifications from test thread. |
|
2013 |
|
2014 ------------------------------------------------------------------------------- |
|
2015 */ |
|
2016 |
|
2017 // ================= MEMBER FUNCTIONS ========================================= |
|
2018 |
|
2019 |
|
2020 /* |
|
2021 ------------------------------------------------------------------------------- |
|
2022 |
|
2023 Class: CErrorPrintHandler |
|
2024 |
|
2025 Method: NewL |
|
2026 |
|
2027 Description: Constructs a new CErrorPrintHandler object. |
|
2028 |
|
2029 Parameters: CTestExecution& aExecution: in: "Parent" |
|
2030 |
|
2031 Return Values: CErrorPrintHandler*: New undertaker |
|
2032 |
|
2033 Errors/Exceptions: Leaves if memory allocation or ConstructL leaves. |
|
2034 |
|
2035 Status: Proposal |
|
2036 |
|
2037 ------------------------------------------------------------------------------- |
|
2038 */ |
|
2039 CErrorPrintHandler* CErrorPrintHandler::NewL( CTestModuleContainer& aContainer ) |
|
2040 { |
|
2041 |
|
2042 CErrorPrintHandler* self = new( ELeave ) CErrorPrintHandler( aContainer ); |
|
2043 CleanupStack::PushL( self ); |
|
2044 self->ConstructL(); |
|
2045 CleanupStack::Pop( self ); |
|
2046 return self; |
|
2047 |
|
2048 } |
|
2049 |
|
2050 /* |
|
2051 ------------------------------------------------------------------------------- |
|
2052 |
|
2053 Class: CErrorPrintHandler |
|
2054 |
|
2055 Method: ConstructL |
|
2056 |
|
2057 Description: Second level constructor. |
|
2058 |
|
2059 Parameters: None |
|
2060 |
|
2061 Return Values: None |
|
2062 |
|
2063 Errors/Exceptions: None |
|
2064 |
|
2065 Status: Proposal |
|
2066 |
|
2067 ------------------------------------------------------------------------------- |
|
2068 */ |
|
2069 void CErrorPrintHandler::ConstructL() |
|
2070 { |
|
2071 |
|
2072 } |
|
2073 |
|
2074 /* |
|
2075 ------------------------------------------------------------------------------- |
|
2076 |
|
2077 Class: CErrorPrintHandler |
|
2078 |
|
2079 Method: CErrorPrintHandler |
|
2080 |
|
2081 Description: Constructor |
|
2082 |
|
2083 Parameters: CTestModuleContainer& aExecution :in: "Parent" |
|
2084 |
|
2085 Return Values: None |
|
2086 |
|
2087 Errors/Exceptions: None |
|
2088 |
|
2089 Status: Proposal |
|
2090 |
|
2091 ------------------------------------------------------------------------------- |
|
2092 */ |
|
2093 CErrorPrintHandler::CErrorPrintHandler( CTestModuleContainer& aContainer ) : |
|
2094 CActive( CActive::EPriorityStandard ), |
|
2095 iContainer( aContainer ) |
|
2096 { |
|
2097 |
|
2098 CActiveScheduler::Add ( this ); |
|
2099 |
|
2100 } |
|
2101 |
|
2102 /* |
|
2103 ------------------------------------------------------------------------------- |
|
2104 |
|
2105 Class: CErrorPrintHandler |
|
2106 |
|
2107 Method: ~CErrorPrintHandler |
|
2108 |
|
2109 Description: Destructor. |
|
2110 Cancels active request. |
|
2111 |
|
2112 Parameters: None |
|
2113 |
|
2114 Return Values: None |
|
2115 |
|
2116 Errors/Exceptions: None |
|
2117 |
|
2118 Status: Proposal |
|
2119 |
|
2120 ------------------------------------------------------------------------------- |
|
2121 */ |
|
2122 CErrorPrintHandler::~CErrorPrintHandler() |
|
2123 { |
|
2124 |
|
2125 Cancel(); |
|
2126 |
|
2127 } |
|
2128 |
|
2129 /* |
|
2130 ------------------------------------------------------------------------------- |
|
2131 |
|
2132 Class: CErrorPrintHandler |
|
2133 |
|
2134 Method: StartL |
|
2135 |
|
2136 Description: Starts to monitor thread. |
|
2137 |
|
2138 Parameters: None |
|
2139 |
|
2140 Return Values: TInt Always KErrNone |
|
2141 |
|
2142 Errors/Exceptions: None |
|
2143 |
|
2144 Status: Proposal |
|
2145 |
|
2146 ------------------------------------------------------------------------------- |
|
2147 */ |
|
2148 void CErrorPrintHandler::StartL() |
|
2149 { |
|
2150 |
|
2151 __TRACE( KPrint, ( _L( "CErrorPrintHandler::StartL" ) ) ); |
|
2152 |
|
2153 iStatus = KRequestPending; |
|
2154 SetActive(); |
|
2155 |
|
2156 // Signal test thread |
|
2157 iContainer.iErrorPrintSem.Signal(); |
|
2158 |
|
2159 } |
|
2160 |
|
2161 /* |
|
2162 ------------------------------------------------------------------------------- |
|
2163 |
|
2164 Class: CErrorPrintHandler |
|
2165 |
|
2166 Method: RunL |
|
2167 |
|
2168 Description: Handles thread death. |
|
2169 Function does: |
|
2170 1 ) Stops monitoring thread |
|
2171 1 ) Marks thread death |
|
2172 2 ) Completes ongoing requests |
|
2173 3 ) Cleans the memory |
|
2174 |
|
2175 Parameters: None |
|
2176 |
|
2177 Return Values: None |
|
2178 |
|
2179 Errors/Exceptions: None |
|
2180 |
|
2181 Status: Proposal |
|
2182 |
|
2183 ------------------------------------------------------------------------------- |
|
2184 */ |
|
2185 void CErrorPrintHandler::RunL() |
|
2186 { |
|
2187 |
|
2188 __TRACE( KPrint, ( _L( "CErrorPrintHandler::RunL [%d]" ), iStatus.Int() ) ); |
|
2189 |
|
2190 iContainer.DoErrorPrint(); |
|
2191 |
|
2192 // enable error print request |
|
2193 iContainer.iErrorPrintHandler->StartL(); |
|
2194 |
|
2195 } |
|
2196 |
|
2197 /* |
|
2198 ------------------------------------------------------------------------------- |
|
2199 |
|
2200 Class: CErrorPrintHandler |
|
2201 |
|
2202 Method: DoCancel |
|
2203 |
|
2204 Description: Stops print notification listening. |
|
2205 |
|
2206 Parameters: None |
|
2207 |
|
2208 Return Values: None |
|
2209 |
|
2210 Errors/Exceptions: None |
|
2211 |
|
2212 Status: Proposal |
|
2213 |
|
2214 ------------------------------------------------------------------------------- |
|
2215 */ |
|
2216 |
|
2217 void CErrorPrintHandler::DoCancel() |
|
2218 { |
|
2219 |
|
2220 __TRACE( KPrint, ( _L( "CErrorPrintHandler::DoCancel" ) ) ); |
|
2221 |
|
2222 // Signal test thread |
|
2223 iContainer.iErrorPrintSem.Wait(); |
|
2224 |
|
2225 TRequestStatus* status = &iStatus; |
|
2226 User::RequestComplete( status, KErrCancel ); |
|
2227 |
|
2228 } |
|
2229 |
|
2230 /* |
|
2231 ------------------------------------------------------------------------------- |
|
2232 |
|
2233 Class: CErrorPrintHandler |
|
2234 |
|
2235 Method: RunError |
|
2236 |
|
2237 Description: Handle errors. RunL function does not leave, so one should |
|
2238 never come here. |
|
2239 |
|
2240 Print trace and let framework handle error( i.e to do Panic ) |
|
2241 |
|
2242 Parameters: TInt aError: :in: Error code |
|
2243 |
|
2244 Return Values: TInt Error code |
|
2245 |
|
2246 Errors/Exceptions: None |
|
2247 |
|
2248 Status: Proposal |
|
2249 |
|
2250 ------------------------------------------------------------------------------- |
|
2251 */ |
|
2252 TInt CErrorPrintHandler::RunError( TInt aError ) |
|
2253 { |
|
2254 |
|
2255 __TRACE( KError,( _L( "CErrorPrintHandler::RunError" ) ) ); |
|
2256 |
|
2257 return aError; |
|
2258 |
|
2259 } |
|
2260 |
|
2261 /* |
|
2262 ------------------------------------------------------------------------------- |
|
2263 |
|
2264 Class: - |
|
2265 |
|
2266 Method: CheckModuleName |
|
2267 |
|
2268 Description: Check is module TestScripter. Does parsing and returns new |
|
2269 module name and error codes(Needed operations when creating |
|
2270 server sessions to TestScripter). |
|
2271 |
|
2272 Parameters: TFileName aModuleName: in: Module name for checking. |
|
2273 TFileName& aNewModuleName: inout: Parsed module name. |
|
2274 |
|
2275 Return Values: KErrNone if TestScripter releated module. |
|
2276 KErrNotFound if not TestScripter releated module. |
|
2277 |
|
2278 Errors/Exceptions: None |
|
2279 |
|
2280 Status: Proposal |
|
2281 |
|
2282 ------------------------------------------------------------------------------- |
|
2283 */ |
|
2284 TInt CheckModuleName( TFileName aModuleName, TFileName& aNewModuleName ) |
|
2285 { |
|
2286 //--PYTHON-- old code has been replaced with the new one |
|
2287 /* |
|
2288 // Check that length is greated than KTestScripterNameLength |
|
2289 if( aModuleName.Length() < KTestScripterNameLength ) |
|
2290 { |
|
2291 return KErrNotFound; |
|
2292 } |
|
2293 // Check is TestScripter |
|
2294 TPtrC check( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
2295 TInt ret = check.Compare( KTestScripterName ); |
|
2296 if( ret == KErrNone ) |
|
2297 { |
|
2298 aNewModuleName.Copy( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
2299 } |
|
2300 else |
|
2301 { |
|
2302 return KErrNotFound; |
|
2303 } |
|
2304 |
|
2305 return KErrNone; |
|
2306 */ |
|
2307 |
|
2308 // Check that length is greated than KTestScripterNameLength |
|
2309 if( aModuleName.Length() >= KTestScripterNameLength ) |
|
2310 { |
|
2311 TPtrC check( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
2312 TInt ret = check.Compare( KTestScripterName ); |
|
2313 if( ret == KErrNone ) |
|
2314 { |
|
2315 aNewModuleName.Copy( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
2316 return KErrNone; |
|
2317 } |
|
2318 } |
|
2319 |
|
2320 // Check that length is greated than KTestScripterNameLength |
|
2321 if( aModuleName.Length() >= KPythonScripterLength ) |
|
2322 { |
|
2323 TPtrC check( aModuleName.Mid( 0, KPythonScripterLength ) ); |
|
2324 TInt ret = check.Compare( KPythonScripter ); |
|
2325 if( ret == KErrNone ) |
|
2326 { |
|
2327 aNewModuleName.Copy( aModuleName.Mid( 0, KPythonScripterLength ) ); |
|
2328 return KErrNone; |
|
2329 } |
|
2330 } |
|
2331 |
|
2332 return KErrNotFound; |
|
2333 } |
|
2334 |
|
2335 /* |
|
2336 ------------------------------------------------------------------------------- |
|
2337 |
|
2338 Class: - |
|
2339 |
|
2340 Method: RemoveOptionalIndex |
|
2341 |
|
2342 Description: Remove optional index appended to module name. |
|
2343 If it is found (@ char) then set new module name without it. |
|
2344 This feature is used when iSeparateProcesses is set in |
|
2345 TestEngine. |
|
2346 |
|
2347 Parameters: TFileName aModuleName: in: Module name for checking. |
|
2348 TFileName& aNewModuleName: inout: Parsed module name. |
|
2349 |
|
2350 Return Values: None |
|
2351 |
|
2352 Errors/Exceptions: None |
|
2353 |
|
2354 Status: Proposal |
|
2355 |
|
2356 ------------------------------------------------------------------------------- |
|
2357 */ |
|
2358 void RemoveOptionalIndex(const TDesC& aModuleName, TDes& aNewModuleName) |
|
2359 { |
|
2360 //Copy module name to destination buffer |
|
2361 aNewModuleName.Copy(aModuleName); |
|
2362 |
|
2363 //Search for @ char (it means that some index has been appended) |
|
2364 TInt index = aNewModuleName.Find(_L("@")); |
|
2365 |
|
2366 //Remove index form name (if found) |
|
2367 if(index != KErrNotFound) |
|
2368 { |
|
2369 aNewModuleName.Delete(index, aNewModuleName.Length() - index); |
|
2370 } |
|
2371 } |
|
2372 |
|
2373 // End of File |