traceservices/tracefw/integ_test/ost/TEF/te_ostv2integsuite_common/src/te_tracecontrolcmds.cpp
changeset 0 08ec8eefde2f
child 29 cce6680bbf1c
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2007-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 // Ost Performance Tests ULogger commands.
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file te_tracecontrolcmds.cpp
       
    21  @internalTechnology
       
    22  @prototype
       
    23 */
       
    24 
       
    25 #include "te_tracecontrolcmds.h"
       
    26 #include "te_dataparameters.h"
       
    27 #include "te_ostv2integsuite_defs.h"
       
    28 
       
    29 using namespace Ulogger; //CA:added so can use old ulogger api
       
    30 
       
    31 CUptULogger::CUptULogger()
       
    32 	{
       
    33 	/*Constructor*/
       
    34 	}
       
    35 
       
    36 CUptULogger::~CUptULogger()
       
    37 	{
       
    38 	/*Destructor*/
       
    39 	}
       
    40 
       
    41 _LIT(KTextvalue, "C:\\logs\\ULoggerStartFileTestLog.utf");
       
    42 /** This user-side method configures the passed ULogger session to log to a default file and with filter settings as specified by the user
       
    43     and starts the session in order to output trace points.
       
    44 @param aLogger is ULogger session being passed to the routine to be configured and started
       
    45 @param aTestUTraceULoggerMatch is the user-defined boolean specifying whether the Ulogger filter settings should match the (test-specific) trace points or not
       
    46 @return KErrNone if command was prepared correctly and a system wide error code otherwise.
       
    47  */
       
    48 TInt CUptULogger::StartFileL(RULogger& aLogger, const TBool& aGroupIdFiltering, const TBool& aComponentIdFiltering, const TBool& aGroupIdFilterMatch, const TBool& aComponentIdFilterMatch)
       
    49 	{
       
    50 	TInt err=0;
       
    51 	//set plugin name as default file
       
    52 	_LIT8(KTextmedia,"uloggerfileplugin");
       
    53 	TPtrC8 pluginPtr(KTextmedia);
       
    54 	//set plugin configuration as default file settings
       
    55 	_LIT(KTextsetting, "output_path");
       
    56 	//_LIT(KTextvalue, "C:\\logs\\UPTApiCallTest.utf");
       
    57 	TPluginConfiguration pluginConfig;
       
    58 	pluginConfig.SetKey(KTextsetting);
       
    59 	pluginConfig.SetValue(KTextvalue);
       
    60 	
       
    61 	//now configure and start ulogger
       
    62 	err = StartGeneralL(aLogger, pluginPtr, pluginConfig, aGroupIdFiltering, aComponentIdFiltering, aGroupIdFilterMatch, aComponentIdFilterMatch);
       
    63 	return err;
       
    64 	}
       
    65 
       
    66 /** This user-side method configures the passed ULogger session to output to the passed plugin (with configurations) and with filter settings as specified by the user
       
    67     and starts the session in order to output trace points.
       
    68 @param aLogger is ULogger session being passed to the routine to be configured and started
       
    69 @param aPluginName is the TPtrC8 passed, identifying which ULogger plugin to output to
       
    70 @param aPluginConfiguration is the TPluginConfiguration passed, indicating the hardware configurations for the specified plugin
       
    71 @param aTestUTraceULoggerMatch is the user-defined boolean specifying whether the Ulogger filter settings should match the (test-specific) trace points or not
       
    72 @return KErrNone if command was prepared correctly and a system wide error code otherwise.
       
    73  */
       
    74 TInt CUptULogger::StartGeneralL(RULogger& aLogger, const TPtrC8& aPluginName, const TPluginConfiguration& aPluginConfiguration, const TBool& aGroupIdFiltering, const TBool& aComponentIdFiltering, const TBool& aGroupIdFilterMatch, const TBool& aComponentIdFilterMatch)
       
    75 	{
       
    76 	TInt err=0;
       
    77 	
       
    78 	//connect to the ULogger session
       
    79 	err=aLogger.Connect();
       
    80 	
       
    81     if (err!=KErrNone)
       
    82         {
       
    83         for (TInt i=2; i<12;i++)
       
    84             {
       
    85             User::After(1000);
       
    86             err = aLogger.Connect();
       
    87             if (err==KErrNone)
       
    88                 {
       
    89                 break;
       
    90                 }
       
    91             }
       
    92         }
       
    93 	
       
    94 	//clear any configurations stored in the ULogger configuration file
       
    95 	CClearConfig configIni;
       
    96 	configIni.Clear(aLogger);
       
    97 	
       
    98 	//prepare arrays for storing the filter settings to configure ULogger (and push any heap objects on the cleanup stack)
       
    99 	CArrayFixFlat<TUint8> *setPrimFilter = new (ELeave)CArrayFixFlat<TUint8>(256);
       
   100 	CleanupStack::PushL(setPrimFilter);
       
   101 	RArray<TUint32> setSecondFilter;
       
   102 	CleanupClosePushL(setSecondFilter);
       
   103 	//now configure the filtering and filter match options according to the passed parameters:
       
   104 	//aGroupIdFiltering aComponentIdFiltering aGroupIdFilterMatch aComponentIdFilterMatch	
       
   105 
       
   106 	if(aGroupIdFiltering==1)
       
   107 	    {
       
   108 	    //We might have previously "disabled" primary filtering by enabling all filter
       
   109 	    //values, we'll disable them all here initially and then enable what we want below
       
   110         TInt i;
       
   111         for (i=0;i<=255;i++)
       
   112             {
       
   113             setPrimFilter->AppendL((TUint8)i);
       
   114             }
       
   115         TInt err=aLogger.SetPrimaryFiltersEnabled(*setPrimFilter,EFalse);
       
   116         setPrimFilter->Delete(0,setPrimFilter->Count());
       
   117 	    }
       
   118 		//C.A. previously this but done by default:err=aLogger.EnableGroupIdFiltering();
       
   119 	else
       
   120 		//C.A. previously:err=aLogger.DisableClassificationFiltering();
       
   121 		//C.A.: just enable all classifications so all is allowed through
       
   122 		{
       
   123 		TInt i;
       
   124 		for (i=0;i<=255;i++)
       
   125 			{
       
   126 			setPrimFilter->AppendL((TUint8)i);
       
   127 			}
       
   128 		TInt err=aLogger.SetPrimaryFiltersEnabled(*setPrimFilter,ETrue);
       
   129 		setPrimFilter->Delete(0,setPrimFilter->Count());
       
   130 		}
       
   131 
       
   132 	err=aLogger.SetSecondaryFilteringEnabled(aComponentIdFiltering);
       
   133 //	C.A. previously	
       
   134 /*	if(aComponentIdFiltering==1)
       
   135 		err=aLogger.EnableModuleUidFiltering();
       
   136 	else
       
   137 		err=aLogger.DisableModuleUidFiltering();*/
       
   138 	
       
   139 	if(aGroupIdFilterMatch==1)
       
   140 		{
       
   141 		//if the user specifies that ULogger should have classifiaction filter settings which match the test trace points, then fill the filter arrays with the test trace point identifiers accordingly
       
   142 		SetFilter(setPrimFilter);		
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		//if the user specifies that ULogger should have classifciation filter settings which dont match the test trace points, then fill the filter arrays with the trace point identifiers which differ from the test trace point identifiers
       
   147 		setPrimFilter->AppendL((TGroupId)(KGroupId+1));
       
   148 		}
       
   149 	
       
   150 	if(aComponentIdFilterMatch==1)
       
   151 			{
       
   152 			//if the user specifies that ULogger should have module id filter settings which match the test trace points, then fill the filter arrays with the test trace point identifiers accordingly
       
   153 			setSecondFilter.Append((TComponentId) KComponentId);
       
   154 			}
       
   155 		else
       
   156 			{
       
   157 			//if the user specifies that ULogger should have module id settings which dont match the test trace points, then fill the filter arrays with the trace point identifiers which differ from the test trace point identifiers
       
   158 			setSecondFilter.Append((TComponentId) (KComponentId+1));
       
   159 			}
       
   160 
       
   161 	//set the filter settings in ULogger according to the above defined filter arrays
       
   162 	err=aLogger.SetPrimaryFiltersEnabled(*setPrimFilter,ETrue);//C.A. previously:err=aLogger.EnableClassifications(*setPrimFilter);
       
   163 	if(err==0)
       
   164 		err=aLogger.SetSecondaryFiltersEnabled(setSecondFilter,ETrue);//C.A. previously:err=aLogger.EnableModuleUids(setSecondFilter);
       
   165 	
       
   166 	
       
   167 	if(err==0)	
       
   168 		{
       
   169 		//now set the ULogger session to output to the specified plugin and configuration
       
   170 		err=aLogger.ActivateOutputPlugin(aPluginName);//C.A. previously:err=aLogger.SetActiveOutputPlugin(aPluginName);
       
   171 	
       
   172 		if((err == KErrNone)/*Added*/||(err == KErrAlreadyExists))//C.A. have to add cuz old api returns -11 if plugin already activated
       
   173 			{
       
   174 			err=aLogger.SetPluginConfigurations(aPluginName, aPluginConfiguration);
       
   175 			if(err==0)
       
   176 				{
       
   177 				//given the ULogger session has successfully been configured to output to the default file, start the session
       
   178 				err=aLogger.Start();//C.A. previously:err=aLogger.StartOutputting();
       
   179 				}
       
   180 			}
       
   181 		}
       
   182 	
       
   183 	//cleanup any heap objects
       
   184 
       
   185 	CleanupStack::PopAndDestroy(&setSecondFilter);	
       
   186 	CleanupStack::PopAndDestroy(setPrimFilter);
       
   187 	
       
   188 	return err;
       
   189 	}
       
   190 	
       
   191 /** This user-side method sets the filter for OSTv2
       
   192  */
       
   193 void CUptULogger::SetFilter(CArrayFixFlat<TUint8>* aSetPrimFilter)
       
   194     {
       
   195     aSetPrimFilter->AppendL(KGroupId);
       
   196     }
       
   197 
       
   198 /** This user-side method stops the passed ULogger session 
       
   199 @param aLogger is ULogger session being passed to the routine to be configured and started
       
   200 @return KErrNone if command was prepared correctly and a system wide error code otherwise.
       
   201  */
       
   202 TInt CUptULogger::Stop(RULogger& aLogger)
       
   203 	{
       
   204 	//stop the passed ULogger session
       
   205 	TInt err=aLogger.Stop();//C.A. previously:TInt err=aLogger.StopOutputting();
       
   206 	return err;
       
   207 	}
       
   208 
       
   209 /** This user-side method stops the passed ULogger file session and deletes the log file to ensure the disk 
       
   210  * space is not maxed out for intensive performance testing.
       
   211 @param aLogger is ULogger session being passed to the routine to be configured and started
       
   212 @return KErrNone if command was prepared correctly and a system wide error code otherwise.
       
   213  */
       
   214 TInt CUptULogger::StopAndDeleteFile(RULogger& aLogger)
       
   215 	{
       
   216 	//stop the passed ULogger session
       
   217 	TInt err=aLogger.Stop();//C.A. previously:TInt err=aLogger.StopOutputting();
       
   218 	
       
   219 	//create handle to the output file and connect to the session
       
   220 	RFs outputFileSession;
       
   221 	RFile outputFile;
       
   222 	err=outputFileSession.Connect();
       
   223 	
       
   224 	//delete the output file (i.e. replace with a zero length file) and close the sessions
       
   225 	err=outputFile.Replace(outputFileSession, KTextvalue ,EFileWrite);
       
   226 	outputFile.Close();
       
   227 	outputFileSession.Close();	
       
   228 	
       
   229 	return err;
       
   230 	}
       
   231 
       
   232 TInt CUptULogger::DeleteFile()
       
   233 	{
       
   234 	RFs outputFileSession;
       
   235 	RFile outputFile;
       
   236 	TInt err = outputFileSession.Connect();	
       
   237 	//delete the output file (i.e. replace with a zero length file) and close the sessions
       
   238 	err=outputFile.Replace(outputFileSession, KTextvalue ,EFileWrite);
       
   239 	outputFile.Close();
       
   240 	outputFileSession.Close();	
       
   241 	
       
   242 	return err;
       
   243 	}
       
   244 
       
   245 TInt CUptULogger::GetDataL(TUint8*& aData, TUint& aSize)
       
   246 	{
       
   247 	RFs fsSession;
       
   248 	CleanupClosePushL(fsSession);
       
   249 	User::LeaveIfError(fsSession.Connect()); 
       
   250 	
       
   251 	RFile file;
       
   252 	TInt error = file.Open(fsSession, KTextvalue, EFileRead);
       
   253 	if(error == KErrNone)
       
   254 		{
       
   255 		TInt size = 0;
       
   256 		file.Size(size);
       
   257 		aSize = size;
       
   258 		aData = new TUint8[aSize];
       
   259 		if(!aData)
       
   260 			error = KErrNoMemory;
       
   261 		if(!error)
       
   262 			{
       
   263 			TPtr8 ptr(aData, aSize);
       
   264 			error = file.Read(ptr);
       
   265 			}
       
   266 		file.Close();//is really called at fsSession.Close(); 
       
   267 		fsSession.Close();
       
   268 		}
       
   269 	CleanupStack::PopAndDestroy();//fsSession
       
   270 	return error;
       
   271 	}
       
   272 
       
   273 
       
   274 /** This sanity test method is executed at the start of the test run to verify that UPT methods in
       
   275 this class are stable before any of the performance tests are carried out 
       
   276 @return KErrNone if command was prepared correctly and system wide error code otherwise.
       
   277  */
       
   278 TInt CUptULogger::Test()
       
   279 	{
       
   280 	return KErrNone;
       
   281 	}
       
   282 
       
   283