testexecfw/stf/inc/TestThreadContainer.h
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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 file contains the header file of the CTestServer.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef TEST_THREAD_CONTAINER_H
       
    19 #define TEST_THREAD_CONTAINER_H
       
    20 
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <StifLogger.h>
       
    26 #include <StifTestModule.h>
       
    27 #include <StifTestInterface.h>
       
    28 #include "TestServerModuleIf.h"
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KStifMacroMax = 128;         // Maximum description length for
       
    32                                         // STIF TF's macro cases
       
    33 const TInt KStifMacroMaxFile = 50;      // Maximum test result description
       
    34                                         // length for STIF TF's macro cases
       
    35 const TInt KStifMacroMaxFunction = 30;  // Maximum test result description
       
    36                                         // length for STIF TF's macro cases
       
    37 
       
    38 typedef TBuf<KStifMacroMax> TStifMacroDes;
       
    39 
       
    40 // MACROS
       
    41 
       
    42 // DATA TYPES
       
    43 
       
    44 // FUNCTION PROTOTYPES
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 class CUiEnvProxy;
       
    48 
       
    49 // CLASS DECLARATION
       
    50 
       
    51 // DESCRIPTION
       
    52 // CTestThreadContainer is a class, which contains the test execution thread
       
    53 // and interface functions to do operations in that thread context.
       
    54 class CTestThreadContainer 
       
    55        :public CBase 
       
    56     {
       
    57 
       
    58     public: // Enumerations
       
    59 
       
    60     private: // Enumerations
       
    61         enum TPanicReason
       
    62             {
       
    63             EUnknownEventCmd,
       
    64             EInvalidCTestThreadContainer,
       
    65             ECreateTrapCleanup,
       
    66             ENullTestThreadContainer,
       
    67             EReInitializingTestModule,
       
    68             ETestModuleNotInitialized,
       
    69             EInvalidTestModuleOperation,
       
    70             ENullRequest,            
       
    71             EDuplicateFail,
       
    72             EServerDied,
       
    73             ENullExecution,
       
    74             EThreadHandleOpenFail,
       
    75             };
       
    76 
       
    77     public: // Structured classes
       
    78 
       
    79         /**
       
    80         * For STIF TF's macro information
       
    81         */
       
    82         struct TTestMacro
       
    83             {
       
    84             TBool   iIndication;
       
    85             TName   iFileDes;
       
    86             TName   iFunctionDes;
       
    87             TInt    iLine;
       
    88             TInt    iReceivedError;
       
    89             };
       
    90 
       
    91 
       
    92     public:  // Constructors and destructor
       
    93 
       
    94         /**
       
    95         * NewL is first phase of two-phased constructor.
       
    96         */
       
    97         static CTestThreadContainer* NewL( 
       
    98             CTestModuleContainer* aModuleContainer,
       
    99             TThreadId aServerThreadId );
       
   100 
       
   101         /**
       
   102         * Destructor of CTestThreadContainer.
       
   103         */
       
   104         virtual ~CTestThreadContainer();
       
   105 
       
   106 
       
   107     public: // New functions
       
   108     
       
   109         /**
       
   110         * Test case execution thread thread function
       
   111         */
       
   112         static TInt ExecutionThread( TAny* aParams );        
       
   113 
       
   114         /**
       
   115          * UI Test case execution thread thread function
       
   116          */
       
   117          static TInt UIExecutionThread( TAny* aParams );        
       
   118         
       
   119         /**
       
   120         * Returns pointer to test cases
       
   121         */
       
   122         const RPointerArray<TTestCaseInfo>* TestCases() const;
       
   123         
       
   124         /**
       
   125         * Completes a print request. 
       
   126         * This function is called from test execution thread.
       
   127         */
       
   128         virtual void DoNotifyPrint( const TInt aPriority, 
       
   129                                     const TStifInfoName& aDes, 
       
   130                                     const TName& aBuffer
       
   131                                     );
       
   132 
       
   133         /**
       
   134         * Enables remote command receiving. 
       
   135         * This function is called from test execution thread.
       
   136         */
       
   137         virtual void DoRemoteReceive( TStifCommand aRemoteCommand,
       
   138                                       TParams aParams,
       
   139                                       TInt aLen,
       
   140                                       TRequestStatus& aStatus );
       
   141         
       
   142         /**
       
   143         * Cancel remote command receiving. 
       
   144         * This function is called from test execution thread.
       
   145         */
       
   146         virtual TInt DoRemoteReceiveCancel();
       
   147 
       
   148         /**
       
   149         * Completes a event request. 
       
   150         * This function is called from test execution thread.
       
   151         */
       
   152         virtual TInt DoNotifyEvent( TEventIf& aEvent,
       
   153                                     TRequestStatus* aStatus = NULL );
       
   154                                     
       
   155         /**
       
   156         * Cancels pending asynchronous event request. 
       
   157         * This function is called from test execution thread.
       
   158         */
       
   159         virtual void CancelEvent( TEventIf& aEvent, 
       
   160                                   TRequestStatus* aStatus );
       
   161                           
       
   162         /**
       
   163         * Set exit reason.
       
   164         */
       
   165         virtual void SetExitReason( const CTestModuleIf::TExitReason aExitReason, 
       
   166                                     const TInt aExitCode );
       
   167                                     
       
   168         /**
       
   169         * Set test behavior.
       
   170         */
       
   171         virtual TInt SetBehavior( const CTestModuleIf::TTestBehavior aType, 
       
   172                                   TAny* aPtr );
       
   173 
       
   174         /**
       
   175         * Get exit reason.
       
   176         */
       
   177         virtual void ExitReason (  CTestModuleIf::TExitReason& aExitReason, 
       
   178                                    TInt& aExitCode );
       
   179 
       
   180         /**
       
   181         * STIF TF's macro. Initialized TTestMacro.
       
   182         */
       
   183         virtual void StifMacroErrorInit();
       
   184 
       
   185         /**
       
   186         * STIF TF's(TL, T1L, T2L, etc )macro. Saves information for later use.
       
   187         */ 
       
   188         virtual TInt StifMacroError( TInt aMacroType,
       
   189                                      const TText8* aFile,
       
   190                                      const char* aFunction,
       
   191                                      TInt aLine,
       
   192                                      TInt aResult,
       
   193                                      TInt aExpected1,
       
   194                                      TInt aExpected2,
       
   195                                      TInt aExpected3,
       
   196                                      TInt aExpected4,
       
   197                                      TInt aExpected5 );
       
   198 
       
   199         /**
       
   200         * With this can be store information about test interference
       
   201         * thread to client space.
       
   202         */ 
       
   203         virtual TInt AddInterferenceThread( RThread aSTIFTestInterference );
       
   204 
       
   205         /**
       
   206         * With this can be remove information about test interference
       
   207         * thread from client space.
       
   208         */ 
       
   209         virtual TInt RemoveInterferenceThread( RThread aSTIFTestInterference );
       
   210 
       
   211         /**
       
   212         * With this can be stored information about test measurement
       
   213         * to TestServer space.
       
   214         */ 
       
   215         virtual TInt HandleMeasurementProcess(
       
   216                     CSTIFTestMeasurement::TStifMeasurementStruct aSTIFMeasurementInfo );
       
   217 
       
   218         /**
       
   219         * Completes a command request.
       
   220         * This function is called from test execution thread.
       
   221         */
       
   222         virtual void DoNotifyCommand(TCommand aCommand, const TDesC8& aParamsPckg);
       
   223 
       
   224         /**
       
   225         * Obtain title of currently running test case.
       
   226         */
       
   227         virtual void GetTestCaseTitleL(TDes& aTestCaseTitle);
       
   228 
       
   229         /**
       
   230          * Sets thread logger.
       
   231          */
       
   232         void SetThreadLogger( CStifLogger* aThreadLogger );
       
   233         
       
   234         /**
       
   235          * Gets thread logger.
       
   236          */
       
   237         CStifLogger* GetThreadLogger();
       
   238         
       
   239         /**
       
   240          * Gets information if testserver supports UI testing.
       
   241          */
       
   242         IMPORT_C TBool UITesting();
       
   243                 
       
   244         /**
       
   245          * Gets UIEnvProxy.
       
   246          */
       
   247         IMPORT_C CUiEnvProxy* GetUiEnvProxy();
       
   248         
       
   249         IMPORT_C TBool SeperateProcesses();
       
   250 
       
   251     public: // Functions from base classes
       
   252 
       
   253     protected:  // New functions
       
   254 
       
   255     private:  // New functions
       
   256 
       
   257         /**
       
   258         * Function that initialise module in execution thread context.
       
   259         */
       
   260         TInt InitializeModuleInThread( RLibrary& aModule );
       
   261 
       
   262         /**
       
   263         * Function that enumerates test cases in execution thread context.
       
   264         */
       
   265         TInt EnumerateInThread();
       
   266 
       
   267         /**
       
   268         * Function that frees the enumeration data in execution thread context.
       
   269         */
       
   270         void FreeEnumerationDataInThread();
       
   271 
       
   272         /**
       
   273         * Function that executes test case in execution thread context.
       
   274         */
       
   275         TInt ExecuteTestCaseInThread();
       
   276 
       
   277         
       
   278         /**
       
   279         * Complete testcase.
       
   280         */
       
   281         void TestComplete( TInt aCompletionCode );
       
   282         
       
   283         /**
       
   284         * Delete a test module instance
       
   285         */
       
   286         void DeleteTestModule();
       
   287         
       
   288         /**
       
   289         * Store TRequestStatus.
       
   290         */
       
   291         void SetEventReq(  TEventDef::TEventCmdType aType, 
       
   292                            TEventIf& aEvent, 
       
   293                            TRequestStatus* aStatus );
       
   294 
       
   295         /**
       
   296         * Destroys the event queue. 
       
   297         * This function is called from test execution thread.
       
   298         */
       
   299         void DestroyEventQueue();
       
   300         
       
   301         /**
       
   302         * Error print.
       
   303         */
       
   304         void ErrorPrint( const TInt aPriority, TPtrC aError );
       
   305 
       
   306         /**
       
   307         * Panicing function for test thread.
       
   308         */ 
       
   309         static void Panic( TPanicReason aReason );
       
   310      
       
   311         /**
       
   312         * Check that server is alive.
       
   313         */ 
       
   314         void IsServerAlive();
       
   315 
       
   316         /**
       
   317         * Exception handler
       
   318         */
       
   319         static void ExceptionHandler( TExcType );
       
   320 
       
   321          /**
       
   322         * Modifies aRecFile and aRecFunction lenghts if nesessarily.
       
   323         */ 
       
   324         void SetMacroInformation( TInt aFileMaxLength,
       
   325                                   TInt aFuntionMaxLength,
       
   326                                   const TText8* aRecFile,
       
   327                                   const char* aRecFunction,
       
   328                                   TDes& aFile,
       
   329                                   TDes& aFunction );
       
   330         /**
       
   331         * Duplicates mutexes
       
   332         */                                 
       
   333         TInt DuplicateMutexHandles( RThread& aThread );
       
   334         
       
   335         /**
       
   336         * Executes test case using OOM simulation
       
   337         */       
       
   338         TInt ExecuteOOMTestCase( TInt aTestCaseNumber,                
       
   339                                  TInt aFirst, 
       
   340                                  TInt aLast, 
       
   341                                  TInt& aResult, 
       
   342                                  TTestResult& caseResult );
       
   343         /**
       
   344         * Leak checks for test case
       
   345         */       
       
   346 
       
   347         void LeakChecksForTestCase( TBool aReturnLeakCheckFail,
       
   348                             TInt aThreadHandleCountBeforeTest,
       
   349                             TInt aThreadHandleCountAfterTest,
       
   350                             TInt aRequestCountBeforeTest, 
       
   351                             TInt aRequestCountAfterTest );                           
       
   352 
       
   353     protected:  // Functions from base classes
       
   354         // None
       
   355 
       
   356     private:
       
   357         
       
   358         /**
       
   359         * By default Symbian OS constructor is private.
       
   360         */
       
   361         void ConstructL( TThreadId aServerThreadId );
       
   362 
       
   363         /** 
       
   364         * C++ default constructor.
       
   365         */
       
   366         CTestThreadContainer( CTestModuleContainer* aModuleContainer );
       
   367                               
       
   368         /**
       
   369         * Handles to parent.
       
   370         */
       
   371         CTestExecution& TestExecution();
       
   372         CTestModuleContainer& ModuleContainer();
       
   373         
       
   374     public:     // Data
       
   375         
       
   376     protected:  // Data
       
   377         // None
       
   378 
       
   379     private:    // Data     
       
   380         // Pointers to server 
       
   381         CTestModuleContainer*           iModuleContainer;
       
   382         
       
   383         // Pointer to test module
       
   384         CTestModuleBase*                iTestModule;            
       
   385         
       
   386         // Test cases
       
   387         RPointerArray<TTestCaseInfo>*   iCases;    
       
   388         
       
   389         // Resource checking
       
   390         TUint                           iCheckResourceFlags;
       
   391 
       
   392         // Internal if none provoded from testmodule        
       
   393         TRequestStatus                  iReqStatus;
       
   394 
       
   395          // StifLogger used in test module thread
       
   396         CStifLogger* iThreadLogger;             
       
   397         
       
   398         // Handles to server
       
   399         RThread     iServerThread;
       
   400 
       
   401         // Mutexes, duplicated handles
       
   402         RMutex  iPrintMutex;                // For iPrintSem semaphore handling
       
   403         //RMutex  iErrorPrintMutex;         // For iErrorPrintSem semaphore handling
       
   404         RMutex  iEventMutex;                // For iEventSem semaphore handling
       
   405         RMutex  iSndMutex;                  // For iSndSem semaphore handling
       
   406         RMutex  iRcvMutex;                  // For iRcvSem semaphore handling
       
   407         RMutex  iInterferenceMutex;         // For iInterferenceSem semaphore handling
       
   408         RMutex  iMeasurementMutex;          // For iMeasurementSem semaphore handling
       
   409         RMutex  iCommandMutex;              // For iCommandSem semaphore handling
       
   410         
       
   411         // Mutex, duplicated handle. This mutex meaning is to make sure that
       
   412         // test complete and test case cancel operations are not executed at
       
   413         // the same time.
       
   414         RMutex          iTestThreadMutex;                 
       
   415                 
       
   416         // Semaphores, duplicated handles
       
   417         RSemaphore  iPrintSem;          // Signal print request availability
       
   418         RSemaphore  iErrorPrintSem;     // Signal error request availability
       
   419         RSemaphore  iEventSem;          // Signal event request availability
       
   420         RSemaphore  iSndSem;            // Signal Send request availability
       
   421         RSemaphore  iRcvSem;            // Signal Receive request availability
       
   422         RSemaphore  iInterferenceSem;   // Synchronize test interference access
       
   423         RSemaphore  iMeasurementSem;    // Synchronize test measurement access
       
   424         RSemaphore  iCommandSem;        // Signal command request availability
       
   425 
       
   426         // Macro information
       
   427         TTestMacro  iTestMacroInfo;
       
   428 
       
   429     public:     // Friend classes
       
   430 
       
   431     protected:  // Friend classes
       
   432         // None
       
   433 
       
   434     private:    // Friend classes
       
   435     	friend class CTestThreadContainerRunner;
       
   436     };
       
   437 
       
   438 #endif // TEST_THREAD_CONTAINER_H
       
   439     
       
   440 // End of File