sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: #include sl@0: #include sl@0: #include "RegistryData.h" sl@0: #include "Registrar.h" sl@0: #include "RegistrarObserver.h" sl@0: #include "DriveInfo.h" sl@0: #include "TE_EcomGranularityTestStep.h" sl@0: sl@0: _LIT (KMinGranInfUidIndex, "MinGranInfUidIndex"); sl@0: _LIT (KMinGranImplUidIndex, "MinGranImplUidIndex"); sl@0: _LIT (KGranStep, "GranStep"); sl@0: _LIT (KMaxGranInfUidIndex, "MaxGranInfUidIndex"); sl@0: _LIT (KMaxGranImplUidIndex, "MaxGranImplUidIndex"); sl@0: sl@0: sl@0: /** Stub class needed to instantiate CRegistrar object. */ sl@0: class CTestRegistrarObserver : public MRegistrarObserver // codescanner::missingcclass sl@0: { sl@0: public: sl@0: // This is a stub. Hence do nothing in notification. sl@0: void Notification( TInt /*aNotification*/ ) {} sl@0: }; sl@0: sl@0: /** Constructor of CEComImplIndexPerfTest */ sl@0: CEComImplIndexPerfTest::CEComImplIndexPerfTest() sl@0: { sl@0: SetTestStepName(KEComImplIndexPerfTest); sl@0: } sl@0: sl@0: /** destructor of CEComImplIndexPerfTest */ sl@0: CEComImplIndexPerfTest::~CEComImplIndexPerfTest() sl@0: { sl@0: iFs.Close(); sl@0: delete iScheduler; sl@0: } sl@0: sl@0: /** Run the test */ sl@0: TVerdict CEComImplIndexPerfTest::doTestStepL() sl@0: { sl@0: iScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iScheduler); sl@0: User::LeaveIfError(iFs.Connect()); sl@0: sl@0: if (ReadConfigParameters() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt fastCounterFreq; sl@0: HAL::Get(HAL::EFastCounterFrequency, fastCounterFreq); sl@0: TUint numTicksInHalfMilliSec = fastCounterFreq / 2000; sl@0: sl@0: const TInt KNumberOfDataPts = sl@0: (iMaxInfUidIndexGranularity - iMinInfUidIndexGranularity) / iGranStep + 1; sl@0: HBufC* hbufc = HBufC::NewLC(10 * KNumberOfDataPts); sl@0: TPtr buf = hbufc->Des(); sl@0: sl@0: // If a sample has the same granularities as the default values sl@0: // in RegistryData.h, save the result in defaultGranularityTime. sl@0: TUint32 defaultGranularityTime = 0x7fffffff; sl@0: sl@0: TUint32 besttime = 0x7fffffff; sl@0: TUint32 worsttime = 0; sl@0: TInt bestAllImplGranularity = 0; sl@0: TInt bestImplUidGranularity = 0; sl@0: sl@0: TUint32 startTicks, endTicks; sl@0: sl@0: // Print header for table sl@0: _LIT(KTableLegend, "Columns = iInterfaceImplIndex granularity, rows = iImplIndex granularity"); sl@0: Logger().Write(KTableLegend); sl@0: sl@0: _LIT(KCommaNumber, ",%d"); sl@0: _LIT(KCommaNumber3Wide, ",%3d"); sl@0: _LIT(KNumber2Wide, "%2d"); sl@0: sl@0: _LIT(KColumnHeadSpace, "--"); sl@0: buf.Copy(KColumnHeadSpace); sl@0: TInt j; sl@0: for (j = iMinInfUidIndexGranularity; j <= iMaxInfUidIndexGranularity; j += iGranStep) sl@0: { sl@0: buf.AppendFormat(KCommaNumber3Wide, j); sl@0: } sl@0: Logger().Write(buf); sl@0: sl@0: sl@0: CTestRegistrarObserver* registrarObserver = new (ELeave) CTestRegistrarObserver; sl@0: CleanupStack::PushL(registrarObserver); sl@0: sl@0: // The two nexting for loops below generate a 2-D table of sl@0: // discovery time at different combinations of granularities. sl@0: for (TInt implIndexGranularity = iMinIimplUidIndexGranularity; sl@0: implIndexGranularity <= iMaxIimplUidIndexGranularity; sl@0: implIndexGranularity += iGranStep) sl@0: { sl@0: buf.Format(KNumber2Wide, implIndexGranularity); sl@0: sl@0: for (TInt infIndexGranularity = iMinInfUidIndexGranularity; sl@0: infIndexGranularity <= iMaxInfUidIndexGranularity; sl@0: infIndexGranularity += iGranStep) sl@0: { sl@0: CRegistryData* registryData = CRegistryData::NewL(iFs, infIndexGranularity, implIndexGranularity); sl@0: CleanupStack::PushL(registryData); sl@0: sl@0: CRegistrar* registrar = CRegistrar::NewL(*registryData, *registrarObserver, iFs); sl@0: CleanupStack::PushL(registrar); sl@0: sl@0: startTicks = User::FastCounter(); sl@0: registrar->ProcessSSAEventL(EStartupStateCriticalStatic); sl@0: endTicks = User::FastCounter(); sl@0: sl@0: TUint32 elapsedMilliSec = (endTicks - startTicks + numTicksInHalfMilliSec) * 1000 / fastCounterFreq; sl@0: buf.AppendFormat(KCommaNumber, elapsedMilliSec); sl@0: sl@0: // Look for the best, worst and default granularity times. sl@0: if ((KDefaultInterfaceImplIndexGranularity == infIndexGranularity) && sl@0: (KDefaultImplIndexGranularity == implIndexGranularity)) sl@0: { sl@0: defaultGranularityTime = elapsedMilliSec; sl@0: } sl@0: sl@0: if (besttime > elapsedMilliSec) sl@0: { sl@0: bestAllImplGranularity = infIndexGranularity; sl@0: bestImplUidGranularity = implIndexGranularity; sl@0: besttime = elapsedMilliSec; sl@0: } sl@0: else if (elapsedMilliSec > worsttime) sl@0: { sl@0: worsttime = elapsedMilliSec; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(registrar); sl@0: CleanupStack::PopAndDestroy(registryData); sl@0: } // for AllImplementations index granularity sl@0: sl@0: // Show one row of result. sl@0: Logger().Write(buf); sl@0: } // for impl. UID index granularity sl@0: sl@0: CleanupStack::PopAndDestroy(registrarObserver); sl@0: sl@0: _LIT(KBest, "Best time is %d milli sec at interface idx granularity %d, Impl UID index granularity %d"); sl@0: INFO_PRINTF4(KBest, besttime, bestAllImplGranularity, bestImplUidGranularity); sl@0: sl@0: _LIT(KWorst, "Worst time is %d milli sec."); sl@0: INFO_PRINTF2(KWorst, worsttime); sl@0: sl@0: if (0x7fffffff != defaultGranularityTime) sl@0: { sl@0: _LIT(KDefGran, "Default granularities (%d,%d) time is %d."); sl@0: INFO_PRINTF4(KDefGran, KDefaultInterfaceImplIndexGranularity, KDefaultImplIndexGranularity, defaultGranularityTime); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(hbufc); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** Read test configuration from ini file. sl@0: */ sl@0: TVerdict CEComImplIndexPerfTest::ReadConfigParameters() sl@0: { sl@0: _LIT (KMissingParamMsg, "Missing %S in config file"); sl@0: sl@0: if (!GetIntFromConfig(ConfigSection(), KMinGranInfUidIndex, iMinInfUidIndexGranularity)) sl@0: { sl@0: ERR_PRINTF2(KMissingParamMsg, &KMinGranInfUidIndex); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (!GetIntFromConfig(ConfigSection(), KMaxGranInfUidIndex, iMaxInfUidIndexGranularity)) sl@0: { sl@0: ERR_PRINTF2(KMissingParamMsg, &KMaxGranInfUidIndex); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (!GetIntFromConfig(ConfigSection(), KMinGranImplUidIndex, iMinIimplUidIndexGranularity)) sl@0: { sl@0: ERR_PRINTF2(KMissingParamMsg, &KMinGranImplUidIndex); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (!GetIntFromConfig(ConfigSection(), KMaxGranImplUidIndex, iMaxIimplUidIndexGranularity)) sl@0: { sl@0: ERR_PRINTF2(KMissingParamMsg, &KMaxGranImplUidIndex); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (!GetIntFromConfig(ConfigSection(), KGranStep, iGranStep)) sl@0: { sl@0: ERR_PRINTF2(KMissingParamMsg, &KGranStep); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: #if defined(__WINS__) || defined(__WINSCW__) sl@0: // On winscw, each data point in the plot takes 3 to 4 seconds (instead sl@0: // of 0.3 s). A table of 12 columns x 20 rows needs 1000 s. sl@0: // It is not worthwhile to scan the full range because performance results sl@0: // on winscw is meaningless anyway. Hence adjust the range to reduce the sl@0: // stress on over night build. sl@0: sl@0: // reduce number of columns to plot sl@0: iMinInfUidIndexGranularity += (iGranStep * 3); sl@0: iMaxInfUidIndexGranularity -= iGranStep; sl@0: sl@0: iMinIimplUidIndexGranularity += (iGranStep * 4); sl@0: iMaxIimplUidIndexGranularity -= (iGranStep * 2); sl@0: sl@0: INFO_PRINTF1(_L("This test takes too long to run on winscw.")); sl@0: 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: #endif sl@0: sl@0: return TestStepResult(); sl@0: }