stif/inc/TestThreadContainer.h
changeset 0 a03f92240627
child 16 8f8df8006c40
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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     public: // Functions from base classes
       
   249 
       
   250     protected:  // New functions
       
   251 
       
   252     private:  // New functions
       
   253 
       
   254         /**
       
   255         * Function that initialise module in execution thread context.
       
   256         */
       
   257         TInt InitializeModuleInThread( RLibrary& aModule );
       
   258 
       
   259         /**
       
   260         * Function that enumerates test cases in execution thread context.
       
   261         */
       
   262         TInt EnumerateInThread();
       
   263 
       
   264         /**
       
   265         * Function that frees the enumeration data in execution thread context.
       
   266         */
       
   267         void FreeEnumerationDataInThread();
       
   268 
       
   269         /**
       
   270         * Function that executes test case in execution thread context.
       
   271         */
       
   272         TInt ExecuteTestCaseInThread();
       
   273 
       
   274         
       
   275         /**
       
   276         * Complete testcase.
       
   277         */
       
   278         void TestComplete( TInt aCompletionCode );
       
   279         
       
   280         /**
       
   281         * Delete a test module instance
       
   282         */
       
   283         void DeleteTestModule();
       
   284         
       
   285         /**
       
   286         * Store TRequestStatus.
       
   287         */
       
   288         void SetEventReq(  TEventDef::TEventCmdType aType, 
       
   289                            TEventIf& aEvent, 
       
   290                            TRequestStatus* aStatus );
       
   291 
       
   292         /**
       
   293         * Destroys the event queue. 
       
   294         * This function is called from test execution thread.
       
   295         */
       
   296         void DestroyEventQueue();
       
   297         
       
   298         /**
       
   299         * Error print.
       
   300         */
       
   301         void ErrorPrint( const TInt aPriority, TPtrC aError );
       
   302 
       
   303         /**
       
   304         * Panicing function for test thread.
       
   305         */ 
       
   306         static void Panic( TPanicReason aReason );
       
   307      
       
   308         /**
       
   309         * Check that server is alive.
       
   310         */ 
       
   311         void IsServerAlive();
       
   312 
       
   313         /**
       
   314         * Exception handler
       
   315         */
       
   316         static void ExceptionHandler( TExcType );
       
   317 
       
   318          /**
       
   319         * Modifies aRecFile and aRecFunction lenghts if nesessarily.
       
   320         */ 
       
   321         void SetMacroInformation( TInt aFileMaxLength,
       
   322                                   TInt aFuntionMaxLength,
       
   323                                   const TText8* aRecFile,
       
   324                                   const char* aRecFunction,
       
   325                                   TDes& aFile,
       
   326                                   TDes& aFunction );
       
   327         /**
       
   328         * Duplicates mutexes
       
   329         */                                 
       
   330         TInt DuplicateMutexHandles( RThread& aThread );
       
   331         
       
   332         /**
       
   333         * Executes test case using OOM simulation
       
   334         */       
       
   335         TInt ExecuteOOMTestCase( TInt aTestCaseNumber,                
       
   336                                  TInt aFirst, 
       
   337                                  TInt aLast, 
       
   338                                  TInt& aResult, 
       
   339                                  TTestResult& caseResult );
       
   340         /**
       
   341         * Leak checks for test case
       
   342         */       
       
   343 
       
   344         void LeakChecksForTestCase( TBool aReturnLeakCheckFail,
       
   345                             TInt aThreadHandleCountBeforeTest,
       
   346                             TInt aThreadHandleCountAfterTest,
       
   347                             TInt aRequestCountBeforeTest, 
       
   348                             TInt aRequestCountAfterTest );                           
       
   349 
       
   350     protected:  // Functions from base classes
       
   351         // None
       
   352 
       
   353     private:
       
   354         
       
   355         /**
       
   356         * By default Symbian OS constructor is private.
       
   357         */
       
   358         void ConstructL( TThreadId aServerThreadId );
       
   359 
       
   360         /** 
       
   361         * C++ default constructor.
       
   362         */
       
   363         CTestThreadContainer( CTestModuleContainer* aModuleContainer );
       
   364                               
       
   365         /**
       
   366         * Handles to parent.
       
   367         */
       
   368         CTestExecution& TestExecution();
       
   369         CTestModuleContainer& ModuleContainer();
       
   370         
       
   371     public:     // Data
       
   372         
       
   373     protected:  // Data
       
   374         // None
       
   375 
       
   376     private:    // Data     
       
   377         // Pointers to server 
       
   378         CTestModuleContainer*           iModuleContainer;
       
   379         
       
   380         // Pointer to test module
       
   381         CTestModuleBase*                iTestModule;            
       
   382         
       
   383         // Test cases
       
   384         RPointerArray<TTestCaseInfo>*   iCases;    
       
   385         
       
   386         // Resource checking
       
   387         TUint                           iCheckResourceFlags;
       
   388 
       
   389         // Internal if none provoded from testmodule        
       
   390         TRequestStatus                  iReqStatus;
       
   391 
       
   392          // StifLogger used in test module thread
       
   393         CStifLogger* iThreadLogger;             
       
   394         
       
   395         // Handles to server
       
   396         RThread     iServerThread;
       
   397 
       
   398         // Mutexes, duplicated handles
       
   399         RMutex  iPrintMutex;                // For iPrintSem semaphore handling
       
   400         //RMutex  iErrorPrintMutex;         // For iErrorPrintSem semaphore handling
       
   401         RMutex  iEventMutex;                // For iEventSem semaphore handling
       
   402         RMutex  iSndMutex;                  // For iSndSem semaphore handling
       
   403         RMutex  iRcvMutex;                  // For iRcvSem semaphore handling
       
   404         RMutex  iInterferenceMutex;         // For iInterferenceSem semaphore handling
       
   405         RMutex  iMeasurementMutex;          // For iMeasurementSem semaphore handling
       
   406         RMutex  iCommandMutex;              // For iCommandSem semaphore handling
       
   407         
       
   408         // Mutex, duplicated handle. This mutex meaning is to make sure that
       
   409         // test complete and test case cancel operations are not executed at
       
   410         // the same time.
       
   411         RMutex          iTestThreadMutex;                 
       
   412                 
       
   413         // Semaphores, duplicated handles
       
   414         RSemaphore  iPrintSem;          // Signal print request availability
       
   415         RSemaphore  iErrorPrintSem;     // Signal error request availability
       
   416         RSemaphore  iEventSem;          // Signal event request availability
       
   417         RSemaphore  iSndSem;            // Signal Send request availability
       
   418         RSemaphore  iRcvSem;            // Signal Receive request availability
       
   419         RSemaphore  iInterferenceSem;   // Synchronize test interference access
       
   420         RSemaphore  iMeasurementSem;    // Synchronize test measurement access
       
   421         RSemaphore  iCommandSem;        // Signal command request availability
       
   422 
       
   423         // Macro information
       
   424         TTestMacro  iTestMacroInfo;
       
   425 
       
   426     public:     // Friend classes
       
   427 
       
   428     protected:  // Friend classes
       
   429         // None
       
   430 
       
   431     private:    // Friend classes
       
   432     	friend class CTestThreadContainerRunner;
       
   433     };
       
   434 
       
   435 #endif // TEST_THREAD_CONTAINER_H
       
   436     
       
   437 // End of File