stif/SUEvent/src/SUEvent.cpp
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 SUEvent implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <StifTestInterface.h>
       
    20 #include "SUEvent.h"
       
    21 #include <e32svr.h>
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 //extern  ?external_data;
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 //extern ?external_function( ?arg_type,?arg_type );
       
    28 
       
    29 // CONSTANTS
       
    30 //const ?type ?constant_var = ?constant;
       
    31 
       
    32 // MACROS
       
    33 //#define ?macro ?macro_def
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 //#define ?macro_name ?macro_def
       
    38 
       
    39 // MODULE DATA STRUCTURES
       
    40 //enum ?declaration
       
    41 //typedef ?declaration
       
    42 
       
    43 // LOCAL FUNCTION PROTOTYPES
       
    44 //?type ?function_name( ?arg_type, ?arg_type );
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 //class ?FORWARD_CLASSNAME;
       
    48 
       
    49 // ============================= LOCAL FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // ?function_name ?description.
       
    53 // ?description
       
    54 // Returns: ?value_1: ?description
       
    55 //          ?value_n: ?description_line1
       
    56 //                    ?description_line2
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 /*
       
    60 ?type ?function_name(
       
    61     ?arg_type arg,  // ?description
       
    62     ?arg_type arg)  // ?description
       
    63     {
       
    64 
       
    65     ?code  // ?comment
       
    66 
       
    67     // ?comment
       
    68     ?code
       
    69     }
       
    70 */
       
    71 
       
    72 // ============================ MEMBER FUNCTIONS ===============================
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CSUEvent::CSUEvent
       
    76 // C++ default constructor can NOT contain any code, that
       
    77 // might leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CSUEvent::CSUEvent()
       
    81     {
       
    82 
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSUEvent::ConstructL
       
    87 // Symbian 2nd phase constructor can leave.
       
    88 //
       
    89 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
       
    90 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger 
       
    91 // allocates memory from heap and therefore causes error situations with OOM 
       
    92 // testing. For more information about STIF Logger construction, see STIF Users 
       
    93 // Guide.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CSUEvent::ConstructL()
       
    97     {
       
    98     iLog = CStifLogger::NewL( KSUEventLogPath, 
       
    99                           KSUEventLogFile);
       
   100 
       
   101     // Sample how to use logging
       
   102     _LIT( KLogStart, "SUEvent logging starts!" );
       
   103     iLog->Log( KLogStart );
       
   104 
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSUEvent::NewL
       
   109 // Two-phased constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CSUEvent* CSUEvent::NewL()
       
   113     {
       
   114     CSUEvent* self = new (ELeave) CSUEvent;
       
   115 
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118     CleanupStack::Pop();
       
   119 
       
   120     return self;
       
   121 
       
   122     }
       
   123 
       
   124 // Destructor
       
   125 CSUEvent::~CSUEvent()
       
   126     {
       
   127     delete iLog;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSUEvent::InitL
       
   132 // InitL is used to initialize the Test Module.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CSUEvent::InitL( 
       
   136     TFileName& /*aIniFile*/, 
       
   137     TBool /*aFirstTime*/ )
       
   138     {
       
   139     return KErrNone;
       
   140 
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSUEvent::GetTestCasesL
       
   145 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   146 // cases are stored to array of test cases. The Test Framework will be
       
   147 // the owner of the data in the RPointerArray after GetTestCases return
       
   148 // and it does the memory deallocation.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 TInt CSUEvent::GetTestCasesL(
       
   152     const TFileName& /*aConfig*/,
       
   153     RPointerArray<TTestCaseInfo>& aTestCases )
       
   154     {
       
   155 
       
   156     // Loop through all test cases and create new
       
   157     // TTestCaseInfo items and append items to aTestCase array
       
   158     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   159         {
       
   160 
       
   161         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   162         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   163 
       
   164         // PushL TTestCaseInfo to CleanupStack.
       
   165         CleanupStack::PushL( newCase );
       
   166 
       
   167         // Set number for the testcase.
       
   168         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   169         newCase->iCaseNumber = i;
       
   170 
       
   171         // Set title for the test case. This is shown in UI to user.
       
   172         newCase->iTitle.Copy( Case(i).iCaseName );
       
   173 
       
   174         // Append TTestCaseInfo to the testcase array. After appended 
       
   175         // successfully the TTestCaseInfo object is owned (and freed) 
       
   176         // by the TestServer. 
       
   177         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   178 
       
   179         // Pop TTestCaseInfo from the CleanupStack.
       
   180         CleanupStack::Pop( newCase );
       
   181 
       
   182         }
       
   183 
       
   184     return KErrNone;
       
   185 
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSUEvent::RunTestCaseL
       
   190 // RunTestCaseL is used to run an individual test case specified 
       
   191 // by aTestCase. Test cases that can be run may be requested from 
       
   192 // Test Module by GetTestCases method before calling RunTestCase.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CSUEvent::RunTestCaseL( 
       
   196     const TInt aCaseNumber,
       
   197     const TFileName& aConfig,
       
   198     TTestResult& aResult )
       
   199     {
       
   200 
       
   201     // Return value
       
   202     TInt execStatus = KErrNone;
       
   203 
       
   204     // Get the pointer to test case function
       
   205     TCaseInfo tmp = Case ( aCaseNumber );
       
   206 
       
   207     _LIT( KLogStartTC, "Starting testcase [%S]" );
       
   208     iLog->Log( KLogStartTC, &tmp.iCaseName);
       
   209 
       
   210     // Check that case number was valid
       
   211     if ( tmp.iMethod != NULL )
       
   212         {
       
   213         // Valid case was found, call it via function pointer
       
   214         iMethod = tmp.iMethod;
       
   215         execStatus  = ( this->*iMethod )( aResult, aConfig );
       
   216         }
       
   217     else
       
   218         {
       
   219         // Valid case was not found, return error.
       
   220         execStatus = KErrNotFound;
       
   221         }
       
   222 
       
   223 	RDebug::Print(_L(" CSUEvent::RunTestCaseL waiting"));
       
   224 
       
   225 	User::After(500000);
       
   226 	RDebug::Print(_L(" CSUEvent::RunTestCaseL running"));
       
   227     // Return case execution status (not the result of the case execution)
       
   228     return execStatus;
       
   229 
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSUEvent::OOMTestQueryL
       
   234 // Used to check if a particular test case should be run in OOM conditions and 
       
   235 // which memory allocations should fail.    
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TBool CSUEvent::OOMTestQueryL( 
       
   239                                 const TFileName& /* aTestCaseFile */, 
       
   240                                 const TInt aCaseNumber, 
       
   241                                 TOOMFailureType& /* aFailureType */, 
       
   242                                 TInt& aFirstMemFailure, 
       
   243                                 TInt& aLastMemFailure ) 
       
   244     {
       
   245     _LIT( KLogOOMTestQueryL, "CSUEvent::OOMTestQueryL" );
       
   246     iLog->Log( KLogOOMTestQueryL );     
       
   247 
       
   248     aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
       
   249     aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
       
   250 
       
   251     return Case( aCaseNumber ).iIsOOMTest;
       
   252 
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CSUEvent::OOMTestInitializeL
       
   257 // Used to perform the test environment setup for a particular OOM test case. 
       
   258 // Test Modules may use the initialization file to read parameters for Test 
       
   259 // Module initialization but they can also have their own configure file or 
       
   260 // some other routine to initialize themselves.  
       
   261 //
       
   262 // NOTE: User may add implementation for OOM test environment initialization.
       
   263 // Usually no implementation is required.
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CSUEvent::OOMTestInitializeL( 
       
   267                                 const TFileName& /* aTestCaseFile */, 
       
   268                                 const TInt /* aCaseNumber */ )
       
   269     {
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CSUEvent::OOMHandleWarningL
       
   274 // In some cases the heap memory allocation should be skipped, either due to
       
   275 // problems in the OS code or components used by the code being tested, or even 
       
   276 // inside the tested components which are implemented this way on purpose (by 
       
   277 // design), so it is important to give the tester a way to bypass allocation 
       
   278 // failures.
       
   279 //
       
   280 // NOTE: User may add implementation for OOM test warning handling. Usually no
       
   281 // implementation is required.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 void CSUEvent::OOMHandleWarningL( 
       
   285                                 const TFileName& /* aTestCaseFile */,
       
   286                                 const TInt /* aCaseNumber */, 
       
   287                                 TInt& /* aFailNextValue */ )
       
   288     {
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CSUEvent::OOMTestFinalizeL
       
   293 // Used to perform the test environment cleanup for a particular OOM test case.
       
   294 //
       
   295 // NOTE: User may add implementation for OOM test environment finalization.
       
   296 // Usually no implementation is required.
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CSUEvent::OOMTestFinalizeL( 
       
   300                                 const TFileName& /* aTestCaseFile */, 
       
   301                                 const TInt /* aCaseNumber */ )
       
   302     {
       
   303     }
       
   304 
       
   305 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // LibEntryL is a polymorphic Dll entry point
       
   309 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 EXPORT_C CTestModuleBase* LibEntryL()
       
   313     {
       
   314     return CSUEvent::NewL();
       
   315 
       
   316     }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // SetRequirements handles test module parameters(implements evolution
       
   320 // version 1 for test module's heap and stack sizes configuring).
       
   321 // Returns: TInt: Symbian error code.
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   325                                 TUint32& /*aParameterValid*/ )
       
   326     {
       
   327 
       
   328     /* --------------------------------- NOTE ---------------------------------
       
   329     USER PANICS occurs in test thread creation when:
       
   330     1) "The panic occurs when the value of the stack size is negative."
       
   331     2) "The panic occurs if the minimum heap size specified is less
       
   332        than KMinHeapSize".
       
   333        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   334        either panic, or will reset the required heap size to this value if
       
   335        a smaller heap size is specified".
       
   336     3) "The panic occurs if the minimum heap size specified is greater than
       
   337        the maximum size to which the heap can grow".
       
   338     Other:
       
   339     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   340        e.g. Hardware might support only sizes that are divisible by four.
       
   341     ------------------------------- NOTE end ------------------------------- */
       
   342 
       
   343     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   344     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   345     // If needed heap and stack sizes can be configured here by user. Remove
       
   346     // comments and define sizes.
       
   347 
       
   348 /*
       
   349     aParameterValid = KStifTestModuleParameterChanged;
       
   350 
       
   351     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   352     // Stack size
       
   353     param->iTestThreadStackSize= 16384; // 16K stack
       
   354     // Heap sizes
       
   355     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   356     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   357 
       
   358     aTestModuleParam = param;
       
   359 */
       
   360     return KErrNone;
       
   361 
       
   362     }
       
   363 
       
   364 // End of File