author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 17:13:29 +0300 | |
changeset 109 | b3a1d9898418 |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\mmu\t_mmubm.cpp |
|
15 |
// Overview: |
|
16 |
// Time MMU allocation & deallocation |
|
17 |
// API Information: |
|
18 |
// RChunk |
|
19 |
// Details: |
|
20 |
// - Allocate and release a 1 MB chunk 100 times and time how long it takes. |
|
21 |
// - Allocate and release a 2 MB chunk 100 times and time how long it takes. |
|
22 |
// - Allocate and release a 7 MB chunk 100 times and time how long it takes. |
|
23 |
// - Allocate a 7 MB chunk once and time how long it takes. |
|
24 |
// - Deallocate a 7 MB chunk once and time how long it takes. |
|
25 |
// Platforms/Drives/Compatibility: |
|
26 |
// All. |
|
27 |
// Assumptions/Requirement/Pre-requisites: |
|
28 |
// Failures and causes: |
|
29 |
// Base Port information: |
|
30 |
// |
|
31 |
// |
|
32 |
||
33 |
#define __E32TEST_EXTENSION__ |
|
34 |
||
35 |
#include <e32test.h> |
|
36 |
#include "mmudetect.h" |
|
37 |
#include "d_gobble.h" |
|
38 |
#include "d_memorytest.h" |
|
39 |
#include "freeram.h" |
|
40 |
||
41 |
RTest test(_L("T_MMUBM")); |
|
42 |
||
43 |
typedef TInt (*TestFunction)(TUint32 aIters, TUint32 aSize); |
|
44 |
||
45 |
RMemoryTestLdd MemoryTest; |
|
46 |
RChunk TheChunk; |
|
47 |
||
48 |
LOCAL_C TInt AllocPhysical(TUint32 aIters, TUint32 aSize) |
|
49 |
{ |
|
50 |
return MemoryTest.AllocPhysTest(aIters, aSize * 0x00100000); |
|
51 |
} |
|
52 |
||
53 |
LOCAL_C TInt AllocPhysical1(TUint32 aIters, TUint32 aSize) |
|
54 |
{ |
|
55 |
return MemoryTest.AllocPhysTest1(aIters, aSize * 0x00100000); |
|
56 |
} |
|
57 |
||
58 |
LOCAL_C TInt AdjustChunk(TUint32 aIters, TUint32 aSize) |
|
59 |
{ |
|
60 |
TUint32 i; |
|
61 |
for (i=0; i<aIters; i++) |
|
62 |
{ |
|
63 |
TInt r=TheChunk.Adjust(aSize * 0x00100000); |
|
64 |
if (r!=KErrNone) |
|
65 |
return r; |
|
66 |
r=TheChunk.Adjust(0); |
|
67 |
if (r!=KErrNone) |
|
68 |
return r; |
|
69 |
} |
|
70 |
return KErrNone; |
|
71 |
} |
|
72 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
LOCAL_C TInt AllocateChunk(TUint32 /*aIters*/, TUint32 aSize) |
0 | 74 |
{ |
75 |
return TheChunk.Adjust(aSize * 0x00100000); |
|
76 |
} |
|
77 |
||
78 |
LOCAL_C TInt DeallocateChunk(TUint32 , TUint32 ) |
|
79 |
{ |
|
80 |
return TheChunk.Adjust(0); |
|
81 |
} |
|
82 |
||
83 |
LOCAL_C TInt TimedCall(TestFunction aFunction, TUint32& aTime, TUint32 aIters, TUint32 aSize) |
|
84 |
{ |
|
85 |
TUint32 before=User::NTickCount(); |
|
86 |
TInt r=(*aFunction)(aIters, aSize); |
|
87 |
TUint32 after=User::NTickCount(); |
|
88 |
aTime=after-before; |
|
89 |
return r; |
|
90 |
} |
|
91 |
||
92 |
#define DO_TEST(__ret, __func, __time, __iters, __size)\ |
|
93 |
tempSize = __size;\ |
|
94 |
__ret=TimedCall(__func, __time, __iters, __size);\ |
|
95 |
if (__ret==KErrNone)\ |
|
96 |
{\ |
|
97 |
test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\ |
|
98 |
}\ |
|
99 |
else if (tempSize < 7)\ |
|
100 |
{\ |
|
101 |
test(__ret==KErrNone);\ |
|
102 |
} |
|
103 |
||
104 |
#define DO_TEST_GOB(__ret, __func, __time, __iters, __size, __rem,__taken)\ |
|
105 |
tempSize = __size;\ |
|
106 |
__ret = gobbler.Open();\ |
|
107 |
test(__ret==KErrNone);\ |
|
108 |
/* gobble leaving x+1MB then test adjusting to x...*/\ |
|
109 |
__taken = gobbler.GobbleRAM(__rem*1024*1024);\ |
|
110 |
test.Printf(_L("Gobbled: %dK freeRam %dK\n"), __taken/1024, FreeRam()/1024);\ |
|
111 |
/* adjust to 1MB*/\ |
|
112 |
__ret=TimedCall(__func, __time, __iters, __size);\ |
|
113 |
if (__ret==KErrNone)\ |
|
114 |
{\ |
|
115 |
test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\ |
|
116 |
}\ |
|
117 |
else if (tempSize < 7)\ |
|
118 |
{\ |
|
119 |
test(__ret==KErrNone);\ |
|
120 |
}\ |
|
121 |
gobbler.Close(); |
|
122 |
||
123 |
||
124 |
GLDEF_C TInt E32Main() |
|
125 |
{ |
|
126 |
||
127 |
test.Title(); |
|
128 |
if (!HaveVirtMem()) |
|
129 |
{ |
|
130 |
test.Printf(_L("This test requires an MMU\n")); |
|
131 |
return KErrNone; |
|
132 |
} |
|
133 |
test.Start(_L("Timing MMU allocation/deallocation...")); |
|
134 |
||
135 |
test(KErrNone==MemoryTest.Open()); |
|
136 |
||
137 |
TInt r; |
|
138 |
TUint32 t; |
|
139 |
TUint32 tempSize; |
|
140 |
r=TheChunk.CreateLocal(0,0x01000000); |
|
141 |
test(r==KErrNone); |
|
142 |
||
143 |
test.Printf(_L("Adjusting Chunks\n")); |
|
144 |
DO_TEST(r, AdjustChunk, t, 100, 1); |
|
145 |
DO_TEST(r, AdjustChunk, t, 100, 2); |
|
146 |
DO_TEST(r, AdjustChunk, t, 100, 7); |
|
147 |
r=TimedCall(AllocateChunk,t,1,7); |
|
148 |
if (r==KErrNone) |
|
149 |
{ |
|
150 |
test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t); |
|
151 |
r=TimedCall(DeallocateChunk,t, 1, 0); |
|
152 |
test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t); |
|
153 |
} |
|
154 |
else |
|
155 |
{ |
|
156 |
test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r); |
|
157 |
} |
|
158 |
||
159 |
test.Next(_L("Test physical memory allocations....")); |
|
160 |
||
161 |
DO_TEST(r, AllocPhysical, t, 100, 1); |
|
162 |
DO_TEST(r, AllocPhysical1, t, 100, 1); |
|
163 |
DO_TEST(r, AllocPhysical, t, 100, 2); |
|
164 |
DO_TEST(r, AllocPhysical1, t, 100, 2); |
|
165 |
DO_TEST(r, AllocPhysical, t, 100, 7); |
|
166 |
DO_TEST(r, AllocPhysical1, t, 100, 7); |
|
167 |
||
168 |
test.Next(_L("Now the test with low memory....")); |
|
169 |
||
170 |
r = User::LoadLogicalDevice(KGobblerLddFileName); |
|
171 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
172 |
||
173 |
RGobbler gobbler; |
|
174 |
TUint32 taken = 0; |
|
175 |
||
176 |
DO_TEST_GOB(r, AdjustChunk, t, 100, 1, 2, taken); |
|
177 |
DO_TEST_GOB(r, AdjustChunk, t, 100, 2, 3, taken); |
|
178 |
DO_TEST_GOB(r, AdjustChunk, t, 100, 7, 8, taken); |
|
179 |
||
180 |
r=TimedCall(AllocateChunk,t,1,7); |
|
181 |
if (r==KErrNone) |
|
182 |
{ |
|
183 |
test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t); |
|
184 |
r=TimedCall(DeallocateChunk,t, 1, 0); |
|
185 |
test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t); |
|
186 |
} |
|
187 |
||
188 |
// gobble leaving 8MB then test allocing 7... |
|
189 |
r = gobbler.Open(); |
|
190 |
test(r==KErrNone); |
|
191 |
taken = gobbler.GobbleRAM(8*1024*1024); |
|
192 |
test.Printf(_L("Gobbled: %dK freeRam %dK\n"), taken/1024, FreeRam()/1024); |
|
193 |
// allocate 7mb |
|
194 |
r=TimedCall(AllocateChunk,t,1,7); |
|
195 |
if (r==KErrNone) |
|
196 |
{ |
|
197 |
test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t); |
|
198 |
r=TimedCall(DeallocateChunk,t, 1, 0); |
|
199 |
test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t); |
|
200 |
} |
|
201 |
else |
|
202 |
test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r); |
|
203 |
gobbler.Close(); |
|
204 |
||
205 |
test.Next(_L("Test physical memory allocations with low memory....")); |
|
206 |
DO_TEST_GOB(r, AllocPhysical, t, 100, 1, 2, taken); |
|
207 |
DO_TEST_GOB(r, AllocPhysical1, t, 100, 1, 2, taken); |
|
208 |
DO_TEST_GOB(r, AllocPhysical, t, 100, 2, 3, taken); |
|
209 |
DO_TEST_GOB(r, AllocPhysical1, t, 100, 2, 3, taken); |
|
210 |
DO_TEST_GOB(r, AllocPhysical, t, 100, 7, 8, taken); |
|
211 |
DO_TEST_GOB(r, AllocPhysical1, t, 100, 7, 8, taken); |
|
212 |
||
213 |
test.End(); |
|
214 |
return 0; |
|
215 |
} |