os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComPerfTest/src/TE_EcomGranularityTestStep.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include <startup.hrh>
22 #include "RegistryData.h"
23 #include "Registrar.h"
24 #include "RegistrarObserver.h"
25 #include "DriveInfo.h"
26 #include "TE_EcomGranularityTestStep.h"
28 _LIT (KMinGranInfUidIndex, "MinGranInfUidIndex");
29 _LIT (KMinGranImplUidIndex, "MinGranImplUidIndex");
30 _LIT (KGranStep, "GranStep");
31 _LIT (KMaxGranInfUidIndex, "MaxGranInfUidIndex");
32 _LIT (KMaxGranImplUidIndex, "MaxGranImplUidIndex");
35 /** Stub class needed to instantiate CRegistrar object. */
36 class CTestRegistrarObserver : public MRegistrarObserver // codescanner::missingcclass
39 // This is a stub. Hence do nothing in notification.
40 void Notification( TInt /*aNotification*/ ) {}
43 /** Constructor of CEComImplIndexPerfTest */
44 CEComImplIndexPerfTest::CEComImplIndexPerfTest()
46 SetTestStepName(KEComImplIndexPerfTest);
49 /** destructor of CEComImplIndexPerfTest */
50 CEComImplIndexPerfTest::~CEComImplIndexPerfTest()
57 TVerdict CEComImplIndexPerfTest::doTestStepL()
59 iScheduler = new(ELeave) CActiveScheduler;
60 CActiveScheduler::Install(iScheduler);
61 User::LeaveIfError(iFs.Connect());
63 if (ReadConfigParameters() != EPass)
65 return TestStepResult();
69 HAL::Get(HAL::EFastCounterFrequency, fastCounterFreq);
70 TUint numTicksInHalfMilliSec = fastCounterFreq / 2000;
72 const TInt KNumberOfDataPts =
73 (iMaxInfUidIndexGranularity - iMinInfUidIndexGranularity) / iGranStep + 1;
74 HBufC* hbufc = HBufC::NewLC(10 * KNumberOfDataPts);
75 TPtr buf = hbufc->Des();
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;
81 TUint32 besttime = 0x7fffffff;
82 TUint32 worsttime = 0;
83 TInt bestAllImplGranularity = 0;
84 TInt bestImplUidGranularity = 0;
86 TUint32 startTicks, endTicks;
88 // Print header for table
89 _LIT(KTableLegend, "Columns = iInterfaceImplIndex granularity, rows = iImplIndex granularity");
90 Logger().Write(KTableLegend);
92 _LIT(KCommaNumber, ",%d");
93 _LIT(KCommaNumber3Wide, ",%3d");
94 _LIT(KNumber2Wide, "%2d");
96 _LIT(KColumnHeadSpace, "--");
97 buf.Copy(KColumnHeadSpace);
99 for (j = iMinInfUidIndexGranularity; j <= iMaxInfUidIndexGranularity; j += iGranStep)
101 buf.AppendFormat(KCommaNumber3Wide, j);
106 CTestRegistrarObserver* registrarObserver = new (ELeave) CTestRegistrarObserver;
107 CleanupStack::PushL(registrarObserver);
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)
115 buf.Format(KNumber2Wide, implIndexGranularity);
117 for (TInt infIndexGranularity = iMinInfUidIndexGranularity;
118 infIndexGranularity <= iMaxInfUidIndexGranularity;
119 infIndexGranularity += iGranStep)
121 CRegistryData* registryData = CRegistryData::NewL(iFs, infIndexGranularity, implIndexGranularity);
122 CleanupStack::PushL(registryData);
124 CRegistrar* registrar = CRegistrar::NewL(*registryData, *registrarObserver, iFs);
125 CleanupStack::PushL(registrar);
127 startTicks = User::FastCounter();
128 registrar->ProcessSSAEventL(EStartupStateCriticalStatic);
129 endTicks = User::FastCounter();
131 TUint32 elapsedMilliSec = (endTicks - startTicks + numTicksInHalfMilliSec) * 1000 / fastCounterFreq;
132 buf.AppendFormat(KCommaNumber, elapsedMilliSec);
134 // Look for the best, worst and default granularity times.
135 if ((KDefaultInterfaceImplIndexGranularity == infIndexGranularity) &&
136 (KDefaultImplIndexGranularity == implIndexGranularity))
138 defaultGranularityTime = elapsedMilliSec;
141 if (besttime > elapsedMilliSec)
143 bestAllImplGranularity = infIndexGranularity;
144 bestImplUidGranularity = implIndexGranularity;
145 besttime = elapsedMilliSec;
147 else if (elapsedMilliSec > worsttime)
149 worsttime = elapsedMilliSec;
152 CleanupStack::PopAndDestroy(registrar);
153 CleanupStack::PopAndDestroy(registryData);
154 } // for AllImplementations index granularity
156 // Show one row of result.
158 } // for impl. UID index granularity
160 CleanupStack::PopAndDestroy(registrarObserver);
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);
165 _LIT(KWorst, "Worst time is %d milli sec.");
166 INFO_PRINTF2(KWorst, worsttime);
168 if (0x7fffffff != defaultGranularityTime)
170 _LIT(KDefGran, "Default granularities (%d,%d) time is %d.");
171 INFO_PRINTF4(KDefGran, KDefaultInterfaceImplIndexGranularity, KDefaultImplIndexGranularity, defaultGranularityTime);
174 CleanupStack::PopAndDestroy(hbufc);
175 return TestStepResult();
178 /** Read test configuration from ini file.
180 TVerdict CEComImplIndexPerfTest::ReadConfigParameters()
182 _LIT (KMissingParamMsg, "Missing %S in config file");
184 if (!GetIntFromConfig(ConfigSection(), KMinGranInfUidIndex, iMinInfUidIndexGranularity))
186 ERR_PRINTF2(KMissingParamMsg, &KMinGranInfUidIndex);
187 SetTestStepResult(EFail);
190 if (!GetIntFromConfig(ConfigSection(), KMaxGranInfUidIndex, iMaxInfUidIndexGranularity))
192 ERR_PRINTF2(KMissingParamMsg, &KMaxGranInfUidIndex);
193 SetTestStepResult(EFail);
196 if (!GetIntFromConfig(ConfigSection(), KMinGranImplUidIndex, iMinIimplUidIndexGranularity))
198 ERR_PRINTF2(KMissingParamMsg, &KMinGranImplUidIndex);
199 SetTestStepResult(EFail);
202 if (!GetIntFromConfig(ConfigSection(), KMaxGranImplUidIndex, iMaxIimplUidIndexGranularity))
204 ERR_PRINTF2(KMissingParamMsg, &KMaxGranImplUidIndex);
205 SetTestStepResult(EFail);
208 if (!GetIntFromConfig(ConfigSection(), KGranStep, iGranStep))
210 ERR_PRINTF2(KMissingParamMsg, &KGranStep);
211 SetTestStepResult(EFail);
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.
221 // reduce number of columns to plot
222 iMinInfUidIndexGranularity += (iGranStep * 3);
223 iMaxInfUidIndexGranularity -= iGranStep;
225 iMinIimplUidIndexGranularity += (iGranStep * 4);
226 iMaxIimplUidIndexGranularity -= (iGranStep * 2);
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);
232 return TestStepResult();