perfsrv/piprofiler/tsrc/PIEngineTest/src/PIEngineTestBlocks.cpp
changeset 62 1c2bb2fc7c87
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
       
     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 testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <bautils.h>
       
    21 #include <StifParser.h>
       
    22 #include <StifTestInterface.h>
       
    23 #include "PIEngineTest.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 //extern  ?external_data;
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 //extern ?external_function( ?arg_type,?arg_type );
       
    30 
       
    31 // CONSTANTS
       
    32 //const ?type ?constant_var = ?constant;
       
    33 
       
    34 // MACROS
       
    35 //#define ?macro ?macro_def
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 //const ?type ?constant_var = ?constant;
       
    39 //#define ?macro_name ?macro_def
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 //enum ?declaration
       
    43 //typedef ?declaration
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 //?type ?function_name( ?arg_type, ?arg_type );
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 //class ?FORWARD_CLASSNAME;
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // ?function_name ?description.
       
    55 // ?description
       
    56 // Returns: ?value_1: ?description
       
    57 //          ?value_n: ?description_line1
       
    58 //                    ?description_line2
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 /*
       
    62 ?type ?function_name(
       
    63     ?arg_type arg,  // ?description
       
    64     ?arg_type arg)  // ?description
       
    65     {
       
    66 
       
    67     ?code  // ?comment
       
    68 
       
    69     // ?comment
       
    70     ?code
       
    71     }
       
    72 */
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CPIEngineTest::Delete
       
    78 // Delete here all resources allocated and opened from test methods. 
       
    79 // Called from destructor. 
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CPIEngineTest::Delete() 
       
    83     {
       
    84 
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CPIEngineTest::RunMethodL
       
    89 // Run specified method. Contains also table of test mothods and their names.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TInt CPIEngineTest::RunMethodL( 
       
    93     CStifItemParser& aItem ) 
       
    94     {
       
    95 
       
    96     static TStifFunctionInfo const KFunctions[] =
       
    97         {  
       
    98         // Copy this line for every implemented function.
       
    99         // First string is the function name used in TestScripter script file.
       
   100         // Second is the actual implementation member function. 
       
   101         ENTRY( "StartEngineAndSample10Sec", CPIEngineTest::StartEngineAndSample10SecL ),
       
   102         //ADD NEW ENTRY HERE
       
   103         // [test cases entries] - Do not remove
       
   104 
       
   105         };
       
   106 
       
   107     const TInt count = sizeof( KFunctions ) / 
       
   108                         sizeof( TStifFunctionInfo );
       
   109 
       
   110     return RunInternalL( KFunctions, count, aItem );
       
   111 
       
   112     }
       
   113 
       
   114 TInt CPIEngineTest::CPIEngineTest::StartEngineAndSample10SecL( CStifItemParser& aItem )
       
   115     {
       
   116     // Print to UI
       
   117     _LIT( KPIEngineTest, "PIEngineTest" );
       
   118     _LIT( KPIEngineExeFile,"Z:\\sys\\bin\\PIProfiler.exe" );
       
   119     _LIT( KPIEngineExeParameters,"timed Z:\\data\\PIProfilerSettings.txt 10" );
       
   120     _LIT( KLogFileName, "C:\\data\\PIProfilerTest_1.dat" );
       
   121     
       
   122     TestModuleIf().Printf( 0, KPIEngineTest, _L("Check for existing data log files") );  
       
   123     iLog->Log( _L("Check for existing data log files") );
       
   124 
       
   125     // Remove existing test data log file if it any. 
       
   126     RFs fsSession;
       
   127     User::LeaveIfError(fsSession.Connect());
       
   128     if ( BaflUtils::FileExists(fsSession, KLogFileName) )
       
   129         {
       
   130         TestModuleIf().Printf( 0, KPIEngineTest, _L("Removing existing file") );  
       
   131         iLog->Log( _L("Removing existing file") );
       
   132                 
       
   133         User::LeaveIfError(fsSession.Delete(KLogFileName));
       
   134         }
       
   135 
       
   136     fsSession.Close();
       
   137 
       
   138     TestModuleIf().Printf( 0, KPIEngineTest, _L("Start profiling for 10 seconds") );
       
   139     iLog->Log(_L("Start profiling for 10 seconds"));
       
   140 
       
   141     // Create engine process with timed profiling parameter and setting file.
       
   142     RProcess proc;
       
   143     TInt status = proc.Create(KPIEngineExeFile, KPIEngineExeParameters);
       
   144 
       
   145     // Check if creating process failed
       
   146     if(status != KErrNone) 
       
   147         {
       
   148         TestModuleIf().Printf( 0, KPIEngineTest, _L("Failed to start profiling") );
       
   149         iLog->Log( _L("Failed to start profiling") );
       
   150                 
       
   151         return status;
       
   152         }
       
   153 
       
   154     TestModuleIf().Printf( 0, KPIEngineTest, _L("profiling...") );
       
   155     iLog->Log( _L("profiling...") );
       
   156             
       
   157     proc.Resume();
       
   158 
       
   159     // Wait for process to finish
       
   160     User::After(15000000);
       
   161 
       
   162     if (proc.ExitReason() != KErrNone)
       
   163         {
       
   164         TestModuleIf().Printf( 0, KPIEngineTest, _L("Process exited with reason: %d"), proc.ExitReason());
       
   165         iLog->Log( _L("Process exited with reason: %d"), proc.ExitReason() );
       
   166 
       
   167         proc.Close();
       
   168 
       
   169         return proc.ExitReason();
       
   170         }
       
   171 
       
   172     proc.Close();
       
   173 
       
   174     TInt err = KErrNone;
       
   175     User::LeaveIfError(fsSession.Connect());
       
   176     
       
   177     // Check if data log file was succesfully created and remove it
       
   178     if ( BaflUtils::FileExists(fsSession, KLogFileName) )
       
   179         {
       
   180         TestModuleIf().Printf( 0, KPIEngineTest, _L("Data log file was succesfully created") );
       
   181         iLog->Log( _L("Data log file was succesfully created") );
       
   182         
       
   183         fsSession.Delete(KLogFileName);
       
   184         }
       
   185     else
       
   186         {
       
   187         TestModuleIf().Printf( 0, KPIEngineTest, _L("Data log file was not created") );
       
   188         iLog->Log( _L("Data log file was not created") );
       
   189                 
       
   190         err = KErrPathNotFound;
       
   191         }
       
   192     
       
   193     fsSession.Close();
       
   194     return err;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CPIEngineTest::?member_function
       
   199 // ?implementation_description
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 /*
       
   204 TInt CPIEngineTest::?member_function(
       
   205    CItemParser& aItem )
       
   206    {
       
   207 
       
   208    ?code
       
   209 
       
   210    }
       
   211 */
       
   212 
       
   213 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   214 // None
       
   215 
       
   216 //  [End of File] - Do not remove
       
   217 
       
   218 // End of File