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