sl@0
|
1 |
// Copyright (c) 2007-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 the License "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 |
// e32test/defrag/perf/t_perfdll.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#define __E32TEST_EXTENSION__
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <e32hal.h>
|
sl@0
|
21 |
#include "..\d_pagemove.h"
|
sl@0
|
22 |
#include "t_perf.h"
|
sl@0
|
23 |
#include "t_testdll.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT(KDllbaseName, "t_defragperf");
|
sl@0
|
26 |
|
sl@0
|
27 |
TPtrC TestPlExtNames = _L(".dll");
|
sl@0
|
28 |
|
sl@0
|
29 |
const TInt KIterations = 50;
|
sl@0
|
30 |
|
sl@0
|
31 |
#define MAXDLLS 1
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
#define MINDLL_PAGES (100 * E_SIZE)
|
sl@0
|
35 |
|
sl@0
|
36 |
typedef TInt (*TCallFunction)(TUint32 funcIndex, TInt param1, TInt param2);
|
sl@0
|
37 |
|
sl@0
|
38 |
TInt DllDefrag::LoadTheLib(TInt aIdx, RTest& test)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
|
sl@0
|
41 |
TBuf<128> nameBuffer;
|
sl@0
|
42 |
TUint32 FuncCount;
|
sl@0
|
43 |
TLibraryFunction InitFunc;
|
sl@0
|
44 |
TLibraryFunction FunctionCountFunc;
|
sl@0
|
45 |
TCallFunction CallFunctionFunc;
|
sl@0
|
46 |
TLibraryFunction SetCloseFunc;
|
sl@0
|
47 |
TLibraryFunction Function0AddrFunc, FunctionNAddrFunc;
|
sl@0
|
48 |
TInt retVal;
|
sl@0
|
49 |
|
sl@0
|
50 |
if (iLib == NULL)
|
sl@0
|
51 |
return KErrNoMemory;
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
nameBuffer.Format(_L("%S%d%S"), &KDllbaseName, aIdx, &TestPlExtNames);
|
sl@0
|
55 |
|
sl@0
|
56 |
/* Load the DLL */
|
sl@0
|
57 |
TEST_PRINTF(_L("Loading the DLL (%S) ...\n"), &nameBuffer);
|
sl@0
|
58 |
|
sl@0
|
59 |
retVal = iLib->Load(nameBuffer);
|
sl@0
|
60 |
|
sl@0
|
61 |
if (retVal != KErrNone)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
test.Printf(_L("Load Failed %S (%d)\n"), &nameBuffer, aIdx);
|
sl@0
|
64 |
return KErrGeneral;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
TEST_PRINTF(_L("Loaded %S (%d)\n"), &nameBuffer, aIdx);
|
sl@0
|
68 |
|
sl@0
|
69 |
/* Test that the DLL is loaded correctly */
|
sl@0
|
70 |
InitFunc = iLib->Lookup(DEFRAGDLL_FUNC_Init);
|
sl@0
|
71 |
FunctionCountFunc = iLib->Lookup(DEFRAGDLL_FUNC_FunctionCount);
|
sl@0
|
72 |
CallFunctionFunc = (TCallFunction)iLib->Lookup(DEFRAGDLL_FUNC_CallFunction);
|
sl@0
|
73 |
SetCloseFunc = iLib->Lookup(DEFRAGDLL_FUNC_SetClose);
|
sl@0
|
74 |
Function0AddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_func0);
|
sl@0
|
75 |
FunctionNAddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_funcN);
|
sl@0
|
76 |
|
sl@0
|
77 |
if (InitFunc == NULL ||
|
sl@0
|
78 |
FunctionCountFunc == NULL ||
|
sl@0
|
79 |
CallFunctionFunc == NULL ||
|
sl@0
|
80 |
SetCloseFunc == NULL)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
return KErrGeneral;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
retVal = (InitFunc)();
|
sl@0
|
86 |
if (retVal != KErrNone)
|
sl@0
|
87 |
return KErrGeneral;
|
sl@0
|
88 |
|
sl@0
|
89 |
FuncCount = (FunctionCountFunc)();
|
sl@0
|
90 |
if (FuncCount == 0)
|
sl@0
|
91 |
return KErrGeneral;
|
sl@0
|
92 |
|
sl@0
|
93 |
iFunc0Addr = (TInt8 *)(Function0AddrFunc)();
|
sl@0
|
94 |
iFuncNAddr = (TInt8 *)(FunctionNAddrFunc)();
|
sl@0
|
95 |
|
sl@0
|
96 |
TEST_PRINTF(_L("%S:Func0 = %x FuncN = %x\n"), &nameBuffer, iFunc0Addr, iFuncNAddr);
|
sl@0
|
97 |
|
sl@0
|
98 |
if (iFunc0Addr == NULL || iFuncNAddr == NULL)
|
sl@0
|
99 |
return KErrGeneral;
|
sl@0
|
100 |
|
sl@0
|
101 |
if (iFunc0Addr > iFuncNAddr)
|
sl@0
|
102 |
return KErrGeneral;
|
sl@0
|
103 |
|
sl@0
|
104 |
return KErrNone;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt DllDefrag::TestDLLPerformance(TInt aDummy, RPageMove& aPageMove, RTest& test)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
DefragLatency timer;
|
sl@0
|
110 |
TInt size = iFuncNAddr - iFunc0Addr;
|
sl@0
|
111 |
const TUint8 *end = (TUint8 *)iFunc0Addr + size;
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt pageSize;
|
sl@0
|
114 |
TInt r = UserHal::PageSizeInBytes(pageSize);
|
sl@0
|
115 |
test_KErrNone(r);
|
sl@0
|
116 |
TEST_PRINTF(_L("size %x"), size);
|
sl@0
|
117 |
TInt pagesToMove = _ALIGN_UP(size, pageSize) / pageSize;
|
sl@0
|
118 |
// Ensure there is at least one page to move
|
sl@0
|
119 |
test_Compare(size, >=, 1);
|
sl@0
|
120 |
|
sl@0
|
121 |
timer.CalibrateTimer(test);
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
for (TInt j = 0; j < KIterations; j++)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TUint8* base = (TUint8 *)iFunc0Addr;
|
sl@0
|
127 |
|
sl@0
|
128 |
timer.StartTimer();
|
sl@0
|
129 |
while (base < end)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
test_KErrNone(aPageMove.TryMovingUserPage(base));
|
sl@0
|
132 |
base += pageSize;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
timer.StopTimer(test);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
DTime_t average, max, min, delay;
|
sl@0
|
138 |
TEST_PRINTF(_L("Finished moving %d dll pages\n"), pagesToMove);
|
sl@0
|
139 |
average = timer.GetResult(max, min, delay);
|
sl@0
|
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);
|
sl@0
|
141 |
test.Printf(_L("Average of %d ticks to move one page\n\n"), average / pagesToMove);
|
sl@0
|
142 |
|
sl@0
|
143 |
return KErrNone;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
|