os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComPerfTest/src/TE_EcomGranularityTestStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2006-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 //
    15 
    16 /**
    17  @file
    18  @internalComponent
    19 */
    20 #include <startup.hrh>
    21 #include <hal.h>
    22 #include "RegistryData.h"
    23 #include "Registrar.h"
    24 #include "RegistrarObserver.h"
    25 #include "DriveInfo.h"
    26 #include "TE_EcomGranularityTestStep.h"
    27 
    28 _LIT (KMinGranInfUidIndex, "MinGranInfUidIndex");
    29 _LIT (KMinGranImplUidIndex, "MinGranImplUidIndex");
    30 _LIT (KGranStep, "GranStep");
    31 _LIT (KMaxGranInfUidIndex, "MaxGranInfUidIndex");
    32 _LIT (KMaxGranImplUidIndex, "MaxGranImplUidIndex");
    33 
    34 
    35 /** Stub class needed to instantiate CRegistrar object. */
    36 class CTestRegistrarObserver : public MRegistrarObserver // codescanner::missingcclass
    37 	{
    38 public:
    39 	// This is a stub. Hence do nothing in notification.
    40 	void Notification( TInt /*aNotification*/ ) {}
    41 	};
    42 
    43 /** Constructor of CEComImplIndexPerfTest */
    44 CEComImplIndexPerfTest::CEComImplIndexPerfTest()
    45 	{
    46 	SetTestStepName(KEComImplIndexPerfTest);
    47 	}
    48 
    49 /** destructor of CEComImplIndexPerfTest */
    50 CEComImplIndexPerfTest::~CEComImplIndexPerfTest()
    51 	{
    52 	iFs.Close();
    53 	delete iScheduler;
    54 	}
    55 
    56 /** Run the test */
    57 TVerdict CEComImplIndexPerfTest::doTestStepL()
    58 	{
    59 	iScheduler = new(ELeave) CActiveScheduler;
    60 	CActiveScheduler::Install(iScheduler);
    61 	User::LeaveIfError(iFs.Connect());
    62 
    63 	if (ReadConfigParameters() != EPass)
    64 		{
    65 		return TestStepResult();
    66 		}
    67 
    68 	TInt fastCounterFreq;
    69 	HAL::Get(HAL::EFastCounterFrequency, fastCounterFreq);
    70 	TUint numTicksInHalfMilliSec = fastCounterFreq / 2000;
    71 
    72 	const TInt KNumberOfDataPts = 
    73 		(iMaxInfUidIndexGranularity - iMinInfUidIndexGranularity) / iGranStep + 1;
    74 	HBufC* hbufc = HBufC::NewLC(10 * KNumberOfDataPts);
    75 	TPtr   buf = hbufc->Des();
    76 
    77 	// If a sample has the same granularities as the default values
    78 	// in RegistryData.h, save the result in defaultGranularityTime.
    79 	TUint32 defaultGranularityTime = 0x7fffffff;
    80 
    81 	TUint32 besttime = 0x7fffffff;
    82 	TUint32 worsttime = 0;
    83 	TInt bestAllImplGranularity = 0;
    84 	TInt bestImplUidGranularity = 0;
    85 
    86 	TUint32 startTicks, endTicks;
    87 
    88 	// Print header for table
    89 	_LIT(KTableLegend, "Columns = iInterfaceImplIndex granularity, rows = iImplIndex granularity");
    90 	Logger().Write(KTableLegend);
    91 
    92 	_LIT(KCommaNumber, ",%d");
    93 	_LIT(KCommaNumber3Wide, ",%3d");
    94 	_LIT(KNumber2Wide, "%2d");
    95 
    96 	_LIT(KColumnHeadSpace, "--");
    97 	buf.Copy(KColumnHeadSpace);
    98 	TInt j;
    99 	for (j = iMinInfUidIndexGranularity; j <= iMaxInfUidIndexGranularity; j += iGranStep)
   100 		{
   101 		buf.AppendFormat(KCommaNumber3Wide, j);
   102 		}
   103 	Logger().Write(buf);
   104 
   105 
   106 	CTestRegistrarObserver* registrarObserver = new (ELeave) CTestRegistrarObserver; 
   107 	CleanupStack::PushL(registrarObserver);
   108 
   109 	// The two nexting for loops below generate a 2-D table of
   110 	// discovery time at different combinations of granularities.
   111 	for (TInt implIndexGranularity = iMinIimplUidIndexGranularity;
   112 		 implIndexGranularity <= iMaxIimplUidIndexGranularity;
   113 		 implIndexGranularity += iGranStep)
   114 		{
   115 		buf.Format(KNumber2Wide, implIndexGranularity);
   116 
   117 		for (TInt infIndexGranularity = iMinInfUidIndexGranularity;
   118 			infIndexGranularity <= iMaxInfUidIndexGranularity; 
   119 			infIndexGranularity += iGranStep)
   120 			{
   121 			CRegistryData* registryData = CRegistryData::NewL(iFs, infIndexGranularity, implIndexGranularity); 
   122 			CleanupStack::PushL(registryData);
   123 
   124 			CRegistrar* registrar = CRegistrar::NewL(*registryData, *registrarObserver, iFs); 
   125 			CleanupStack::PushL(registrar);
   126 
   127 			startTicks = User::FastCounter();
   128 			registrar->ProcessSSAEventL(EStartupStateCriticalStatic);
   129 			endTicks = User::FastCounter();
   130 
   131 			TUint32 elapsedMilliSec = (endTicks - startTicks + numTicksInHalfMilliSec) * 1000 / fastCounterFreq;
   132 			buf.AppendFormat(KCommaNumber, elapsedMilliSec);
   133 
   134 			// Look for the best, worst and default granularity times.
   135 			if ((KDefaultInterfaceImplIndexGranularity == infIndexGranularity) &&
   136 			 	(KDefaultImplIndexGranularity == implIndexGranularity))
   137 				{
   138 				defaultGranularityTime = elapsedMilliSec;
   139 				}
   140 
   141 			if (besttime > elapsedMilliSec)
   142 				{
   143 				bestAllImplGranularity = infIndexGranularity;
   144 				bestImplUidGranularity = implIndexGranularity;
   145 				besttime = elapsedMilliSec;
   146 				}
   147 			else if (elapsedMilliSec > worsttime)
   148 				{
   149 				worsttime = elapsedMilliSec;
   150 				}
   151 
   152 			CleanupStack::PopAndDestroy(registrar);
   153 			CleanupStack::PopAndDestroy(registryData);
   154 			} // for AllImplementations index granularity
   155 
   156 		// Show one row of result.
   157 		Logger().Write(buf);
   158 		} // for impl. UID index granularity
   159 
   160 	CleanupStack::PopAndDestroy(registrarObserver);
   161 
   162 	_LIT(KBest, "Best time is %d milli sec at interface idx granularity %d, Impl UID index granularity %d");
   163 	INFO_PRINTF4(KBest, besttime, bestAllImplGranularity, bestImplUidGranularity);
   164 
   165 	_LIT(KWorst, "Worst time is %d milli sec.");
   166 	INFO_PRINTF2(KWorst, worsttime);
   167 
   168 	if (0x7fffffff != defaultGranularityTime)
   169 		{
   170 		_LIT(KDefGran, "Default granularities (%d,%d) time is %d.");
   171 		INFO_PRINTF4(KDefGran, KDefaultInterfaceImplIndexGranularity, KDefaultImplIndexGranularity, defaultGranularityTime);
   172 		}
   173 
   174 	CleanupStack::PopAndDestroy(hbufc);
   175 	return TestStepResult();
   176 	}
   177 
   178 /** Read test configuration from ini file.
   179 */
   180 TVerdict CEComImplIndexPerfTest::ReadConfigParameters()
   181 	{
   182 	_LIT (KMissingParamMsg, "Missing %S in config file");
   183 
   184 	if (!GetIntFromConfig(ConfigSection(), KMinGranInfUidIndex, iMinInfUidIndexGranularity))
   185 		{
   186 		ERR_PRINTF2(KMissingParamMsg, &KMinGranInfUidIndex);
   187 		SetTestStepResult(EFail);
   188 		}
   189 
   190 	if (!GetIntFromConfig(ConfigSection(), KMaxGranInfUidIndex, iMaxInfUidIndexGranularity))
   191 		{
   192 		ERR_PRINTF2(KMissingParamMsg, &KMaxGranInfUidIndex);
   193 		SetTestStepResult(EFail);
   194 		}
   195 
   196 	if (!GetIntFromConfig(ConfigSection(), KMinGranImplUidIndex, iMinIimplUidIndexGranularity))
   197 		{
   198 		ERR_PRINTF2(KMissingParamMsg, &KMinGranImplUidIndex);
   199 		SetTestStepResult(EFail);
   200 		}
   201 
   202 	if (!GetIntFromConfig(ConfigSection(), KMaxGranImplUidIndex, iMaxIimplUidIndexGranularity))
   203 		{
   204 		ERR_PRINTF2(KMissingParamMsg, &KMaxGranImplUidIndex);
   205 		SetTestStepResult(EFail);
   206 		}
   207 
   208 	if (!GetIntFromConfig(ConfigSection(), KGranStep, iGranStep))
   209 		{
   210 		ERR_PRINTF2(KMissingParamMsg, &KGranStep);
   211 		SetTestStepResult(EFail);
   212 		}
   213 
   214 #if defined(__WINS__) || defined(__WINSCW__)
   215 	// On winscw, each data point in the plot takes 3 to 4 seconds (instead
   216 	// of 0.3 s).  A table of 12 columns x 20 rows needs 1000 s.
   217 	// It is not worthwhile to scan the full range because performance results
   218 	// on winscw is meaningless anyway. Hence adjust the range to reduce the
   219 	// stress on over night build.
   220 
   221 	// reduce number of columns to plot
   222 	iMinInfUidIndexGranularity += (iGranStep * 3);
   223 	iMaxInfUidIndexGranularity -= iGranStep;
   224 
   225 	iMinIimplUidIndexGranularity += (iGranStep * 4);
   226 	iMaxIimplUidIndexGranularity -= (iGranStep * 2);
   227 
   228 	INFO_PRINTF1(_L("This test takes too long to run on winscw."));
   229 	INFO_PRINTF5(_L("Range of I/F idx granularities narrowed to %d,%d, Impl. idx granularity narrowed to %d,%d"), iMinInfUidIndexGranularity, iMaxInfUidIndexGranularity, iMinIimplUidIndexGranularity, iMaxIimplUidIndexGranularity);
   230 #endif
   231 
   232 	return TestStepResult();
   233 	}