sl@0: // Copyright (c) 2007-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 the License "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: // e32test/defrag/perf/t_perfdll.cpp sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include sl@0: #include "..\d_pagemove.h" sl@0: #include "t_perf.h" sl@0: #include "t_testdll.h" sl@0: sl@0: _LIT(KDllbaseName, "t_defragperf"); sl@0: sl@0: TPtrC TestPlExtNames = _L(".dll"); sl@0: sl@0: const TInt KIterations = 50; sl@0: sl@0: #define MAXDLLS 1 sl@0: sl@0: sl@0: #define MINDLL_PAGES (100 * E_SIZE) sl@0: sl@0: typedef TInt (*TCallFunction)(TUint32 funcIndex, TInt param1, TInt param2); sl@0: sl@0: TInt DllDefrag::LoadTheLib(TInt aIdx, RTest& test) sl@0: { sl@0: sl@0: TBuf<128> nameBuffer; sl@0: TUint32 FuncCount; sl@0: TLibraryFunction InitFunc; sl@0: TLibraryFunction FunctionCountFunc; sl@0: TCallFunction CallFunctionFunc; sl@0: TLibraryFunction SetCloseFunc; sl@0: TLibraryFunction Function0AddrFunc, FunctionNAddrFunc; sl@0: TInt retVal; sl@0: sl@0: if (iLib == NULL) sl@0: return KErrNoMemory; sl@0: sl@0: sl@0: nameBuffer.Format(_L("%S%d%S"), &KDllbaseName, aIdx, &TestPlExtNames); sl@0: sl@0: /* Load the DLL */ sl@0: TEST_PRINTF(_L("Loading the DLL (%S) ...\n"), &nameBuffer); sl@0: sl@0: retVal = iLib->Load(nameBuffer); sl@0: sl@0: if (retVal != KErrNone) sl@0: { sl@0: test.Printf(_L("Load Failed %S (%d)\n"), &nameBuffer, aIdx); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: TEST_PRINTF(_L("Loaded %S (%d)\n"), &nameBuffer, aIdx); sl@0: sl@0: /* Test that the DLL is loaded correctly */ sl@0: InitFunc = iLib->Lookup(DEFRAGDLL_FUNC_Init); sl@0: FunctionCountFunc = iLib->Lookup(DEFRAGDLL_FUNC_FunctionCount); sl@0: CallFunctionFunc = (TCallFunction)iLib->Lookup(DEFRAGDLL_FUNC_CallFunction); sl@0: SetCloseFunc = iLib->Lookup(DEFRAGDLL_FUNC_SetClose); sl@0: Function0AddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_func0); sl@0: FunctionNAddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_funcN); sl@0: sl@0: if (InitFunc == NULL || sl@0: FunctionCountFunc == NULL || sl@0: CallFunctionFunc == NULL || sl@0: SetCloseFunc == NULL) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: retVal = (InitFunc)(); sl@0: if (retVal != KErrNone) sl@0: return KErrGeneral; sl@0: sl@0: FuncCount = (FunctionCountFunc)(); sl@0: if (FuncCount == 0) sl@0: return KErrGeneral; sl@0: sl@0: iFunc0Addr = (TInt8 *)(Function0AddrFunc)(); sl@0: iFuncNAddr = (TInt8 *)(FunctionNAddrFunc)(); sl@0: sl@0: TEST_PRINTF(_L("%S:Func0 = %x FuncN = %x\n"), &nameBuffer, iFunc0Addr, iFuncNAddr); sl@0: sl@0: if (iFunc0Addr == NULL || iFuncNAddr == NULL) sl@0: return KErrGeneral; sl@0: sl@0: if (iFunc0Addr > iFuncNAddr) sl@0: return KErrGeneral; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DllDefrag::TestDLLPerformance(TInt aDummy, RPageMove& aPageMove, RTest& test) sl@0: { sl@0: DefragLatency timer; sl@0: TInt size = iFuncNAddr - iFunc0Addr; sl@0: const TUint8 *end = (TUint8 *)iFunc0Addr + size; sl@0: sl@0: TInt pageSize; sl@0: TInt r = UserHal::PageSizeInBytes(pageSize); sl@0: test_KErrNone(r); sl@0: TEST_PRINTF(_L("size %x"), size); sl@0: TInt pagesToMove = _ALIGN_UP(size, pageSize) / pageSize; sl@0: // Ensure there is at least one page to move sl@0: test_Compare(size, >=, 1); sl@0: sl@0: timer.CalibrateTimer(test); sl@0: sl@0: sl@0: for (TInt j = 0; j < KIterations; j++) sl@0: { sl@0: TUint8* base = (TUint8 *)iFunc0Addr; sl@0: sl@0: timer.StartTimer(); sl@0: while (base < end) sl@0: { sl@0: test_KErrNone(aPageMove.TryMovingUserPage(base)); sl@0: base += pageSize; sl@0: } sl@0: timer.StopTimer(test); sl@0: } sl@0: sl@0: DTime_t average, max, min, delay; sl@0: TEST_PRINTF(_L("Finished moving %d dll pages\n"), pagesToMove); sl@0: average = timer.GetResult(max, min, delay); sl@0: test.Printf(_L("Fast counter ticks to move %d dll pages: Av %d Min %d Max %d (Overhead %d)\n"), pagesToMove, average, min, max, delay); sl@0: test.Printf(_L("Average of %d ticks to move one page\n\n"), average / pagesToMove); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: