xml/xmlfw/test/rtest/tsrc/tp_perftestbase.h
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Generic performance test framework
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef TP_FRAMEWORK_H
       
    24 #define TP_FRAMEWORK_H
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <f32file.h>
       
    28 
       
    29 /**
       
    30 Typedef for method pointer
       
    31 */
       
    32 typedef TAny (*TFuncPtr)();
       
    33 
       
    34 /** 
       
    35 The class purpose is to store all necessary details of API method to call. 
       
    36 */
       
    37 class TApiRecord
       
    38 	{
       
    39 	public:
       
    40 		TApiRecord(const TDesC8& aAPIName, TFuncPtr aAPIPtr, TUint64 aMaxDuration);
       
    41 		
       
    42 
       
    43 	public:
       
    44 		void SetAPIPtr(TFuncPtr aAPIPtr);
       
    45 		const TDesC8& APIName();
       
    46 		
       
    47 		void SetAPIName(TDesC8& aAPIName);
       
    48 		TFuncPtr APIPtr();
       
    49 		
       
    50 		void SetMaxDuration(TUint64 aMaxDuration);
       
    51 		TUint64 MaxDuration();
       
    52 		
       
    53 	private:
       
    54 		/**
       
    55 		API method name
       
    56 		*/
       
    57 		TBuf8<100> iAPIName;
       
    58 		
       
    59 		/**
       
    60 		API method pointer
       
    61 		*/
       
    62 		TFuncPtr iAPIPtr;
       
    63 		
       
    64 		/**
       
    65 		The maximum duration of the performance test for that API method
       
    66 		*/
       
    67 		TUint64 iMaxDuration;
       
    68 	};
       
    69 	
       
    70 /**
       
    71 Typedef to simplify usage of the Api record list.
       
    72 */
       
    73 typedef RPointerArray<TApiRecord> RApiList;
       
    74 
       
    75 /** 
       
    76 The base clase for API performance testing. 
       
    77 The class users should inherit from this class to use the performance test functionality. 
       
    78 
       
    79 The user needs to provide a number of test methods, which should be a friend to the class. 
       
    80 Each of this method should have a call to ApiTestStart and ApiTestEnd methods, which 
       
    81 should enclose particular functionality (API method) for performance testing. It allows to 
       
    82 performance test only requried functionality leaving out of test scope the test preparation 
       
    83 and post test activity.
       
    84 
       
    85 Here is the test method prototype:
       
    86 void TestAPIMethod()
       
    87 	{
       
    88 		// test preparation here
       
    89 	apiTest->ApiTestStart();
       
    90 		// call to the API method
       
    91 	apiTest->ApiTestEnd();
       
    92 		// post test activity
       
    93 	}
       
    94 
       
    95 The framework will call all test methods required number of times for perfromance testing. 
       
    96 The test results will be shown on the console and logged into result file in "C:\Log" directory. 
       
    97 */
       
    98 class CPerformanceTests : public CBase
       
    99 	{
       
   100 
       
   101 public:
       
   102 	void RunTestsL();
       
   103 	~CPerformanceTests();
       
   104 
       
   105 public: 
       
   106 	/**
       
   107 	User should implement GetMethodList to create full list of require API method to test
       
   108 	*/
       
   109 	virtual void GetMethodListL(RApiList& aApiList) = 0;
       
   110 	
       
   111 	/**
       
   112 	User should implement GetNumberOfRepetition to inform the framework about the number
       
   113 	of repetitions for performance testing. 
       
   114 	*/
       
   115 	virtual TInt GetNumberOfRepetition() = 0;
       
   116 	
       
   117 	/**
       
   118 	User should implement this method for some general purpose test preparation. 
       
   119 	*/
       
   120 	virtual void PrepareTestsL() = 0;
       
   121 	
       
   122 private:
       
   123 	void TestApi(TApiRecord& aApi);
       
   124 
       
   125 protected:
       
   126 	void ConstructL(const TDesC& aTestName);
       
   127 	CPerformanceTests();
       
   128 	void ApiTestStart();
       
   129 	void ApiTestEnd();
       
   130 	void ParserComandLineL();
       
   131 			
       
   132 private:
       
   133 	/** The list of methods to perform the test on */
       
   134 	RApiList list; 		
       
   135 
       
   136 	/** Output log file handle */
       
   137 	RFile output; 		
       
   138 	
       
   139 	/** RF session for logging */
       
   140 	RFs session;	
       
   141 	
       
   142 	/** Start time of API call */
       
   143 	TUint64 iStartTime; 
       
   144 
       
   145 	/** End time of API call */
       
   146 	TUint64 iEndTime;    
       
   147 
       
   148 	/** Number of required repetition */
       
   149 	TInt iRepNum;
       
   150 
       
   151 	/** Name of outpu file */
       
   152 	HBufC* iOutputFile;
       
   153 	};
       
   154 
       
   155 #endif // TP_FRAMEWORK_H