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