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