Update contrib.
1 // Copyright (c) 2007-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 the License "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.
14 // e32test/defrag/perf/t_perfdll.cpp
18 #define __E32TEST_EXTENSION__
21 #include "..\d_pagemove.h"
23 #include "t_testdll.h"
25 _LIT(KDllbaseName, "t_defragperf");
27 TPtrC TestPlExtNames = _L(".dll");
29 const TInt KIterations = 50;
34 #define MINDLL_PAGES (100 * E_SIZE)
36 typedef TInt (*TCallFunction)(TUint32 funcIndex, TInt param1, TInt param2);
38 TInt DllDefrag::LoadTheLib(TInt aIdx, RTest& test)
43 TLibraryFunction InitFunc;
44 TLibraryFunction FunctionCountFunc;
45 TCallFunction CallFunctionFunc;
46 TLibraryFunction SetCloseFunc;
47 TLibraryFunction Function0AddrFunc, FunctionNAddrFunc;
54 nameBuffer.Format(_L("%S%d%S"), &KDllbaseName, aIdx, &TestPlExtNames);
57 TEST_PRINTF(_L("Loading the DLL (%S) ...\n"), &nameBuffer);
59 retVal = iLib->Load(nameBuffer);
61 if (retVal != KErrNone)
63 test.Printf(_L("Load Failed %S (%d)\n"), &nameBuffer, aIdx);
67 TEST_PRINTF(_L("Loaded %S (%d)\n"), &nameBuffer, aIdx);
69 /* Test that the DLL is loaded correctly */
70 InitFunc = iLib->Lookup(DEFRAGDLL_FUNC_Init);
71 FunctionCountFunc = iLib->Lookup(DEFRAGDLL_FUNC_FunctionCount);
72 CallFunctionFunc = (TCallFunction)iLib->Lookup(DEFRAGDLL_FUNC_CallFunction);
73 SetCloseFunc = iLib->Lookup(DEFRAGDLL_FUNC_SetClose);
74 Function0AddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_func0);
75 FunctionNAddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_funcN);
77 if (InitFunc == NULL ||
78 FunctionCountFunc == NULL ||
79 CallFunctionFunc == NULL ||
85 retVal = (InitFunc)();
86 if (retVal != KErrNone)
89 FuncCount = (FunctionCountFunc)();
93 iFunc0Addr = (TInt8 *)(Function0AddrFunc)();
94 iFuncNAddr = (TInt8 *)(FunctionNAddrFunc)();
96 TEST_PRINTF(_L("%S:Func0 = %x FuncN = %x\n"), &nameBuffer, iFunc0Addr, iFuncNAddr);
98 if (iFunc0Addr == NULL || iFuncNAddr == NULL)
101 if (iFunc0Addr > iFuncNAddr)
107 TInt DllDefrag::TestDLLPerformance(TInt aDummy, RPageMove& aPageMove, RTest& test)
110 TInt size = iFuncNAddr - iFunc0Addr;
111 const TUint8 *end = (TUint8 *)iFunc0Addr + size;
114 TInt r = UserHal::PageSizeInBytes(pageSize);
116 TEST_PRINTF(_L("size %x"), size);
117 TInt pagesToMove = _ALIGN_UP(size, pageSize) / pageSize;
118 // Ensure there is at least one page to move
119 test_Compare(size, >=, 1);
121 timer.CalibrateTimer(test);
124 for (TInt j = 0; j < KIterations; j++)
126 TUint8* base = (TUint8 *)iFunc0Addr;
131 test_KErrNone(aPageMove.TryMovingUserPage(base));
134 timer.StopTimer(test);
137 DTime_t average, max, min, delay;
138 TEST_PRINTF(_L("Finished moving %d dll pages\n"), pagesToMove);
139 average = timer.GetResult(max, min, delay);
140 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);
141 test.Printf(_L("Average of %d ticks to move one page\n\n"), average / pagesToMove);