author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 27 Apr 2010 18:02:57 +0300 | |
branch | RCL_3 |
changeset 97 | 41f0cfe18c80 |
parent 0 | a41df078684a |
child 176 | af6ec97d9189 |
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_chunk.cpp |
|
15 |
// Tests on RChunk objects in connection with demand paging. |
|
16 |
// Tests exercise the locking, unlocking, commiting and decommiting of |
|
17 |
// pages to chunk objects. |
|
18 |
// 1 Check Unlocked page gets counted as free memory |
|
19 |
// 2 Check Unlock/Lock preserves page contents |
|
20 |
// 3 Tests at chunk offset '0' |
|
21 |
// 4 Check Lock is idempotent |
|
22 |
// 5 Check non page aligned Unlock/Lock |
|
23 |
// 6 Check unlocked pages get reclaimed for new memory allocation |
|
24 |
// 7 Check reclaimed memory is unmapped from original location |
|
25 |
// 8 Check Lock fails when memory is reclaimed |
|
26 |
// 9 Check Lock failure Decommits memory |
|
27 |
// 10 Recommit memory to chunk |
|
28 |
// 11 Check Commit on unlocked pages |
|
29 |
// 12 Check Commit on unlocked and reclaimed pages |
|
30 |
// 13 Restore chunk |
|
31 |
// 14 Tests at chunk offset 'PageSize' |
|
32 |
// 15 Check Lock is idempotent |
|
33 |
// 16 Check non page aligned Unlock/Lock |
|
34 |
// 17 Check unlocked pages get reclaimed for new memory allocation |
|
35 |
// 18 Check reclaimed memory is unmapped from original location |
|
36 |
// 19 Check Lock fails when memory is reclaimed |
|
37 |
// 20 Check Lock failure Decommits memory |
|
38 |
// 21 Recommit memory to chunk |
|
39 |
// 22 Check Commit on unlocked pages |
|
40 |
// 23 Check Commit on unlocked and reclaimed pages |
|
41 |
// 24 Restore chunk |
|
42 |
// 25 Tests at chunk offset '0x100000-PageSize' |
|
43 |
// 26 Check Lock is idempotent |
|
44 |
// 27 Check non page aligned Unlock/Lock |
|
45 |
// 28 Check unlocked pages get reclaimed for new memory allocation |
|
46 |
// 29 Check reclaimed memory is unmapped from original location |
|
47 |
// 30 Check Lock fails when memory is reclaimed |
|
48 |
// 31 Check Lock failure Decommits memory |
|
49 |
// 32 Recommit memory to chunk |
|
50 |
// 33 Check Commit on unlocked pages |
|
51 |
// 34 Check Commit on unlocked and reclaimed pages |
|
52 |
// 35 Restore chunk |
|
53 |
// 36 Tests at chunk offset '0x400000-PageSize' |
|
54 |
// 37 Check Lock is idempotent |
|
55 |
// 38 Check non page aligned Unlock/Lock |
|
56 |
// 39 Check unlocked pages get reclaimed for new memory allocation |
|
57 |
// 40 Check reclaimed memory is unmapped from original location |
|
58 |
// 41 Check Lock fails when memory is reclaimed |
|
59 |
// 42 Check Lock failure Decommits memory |
|
60 |
// 43 Recommit memory to chunk |
|
61 |
// 44 Check Commit on unlocked pages |
|
62 |
// 45 Check Commit on unlocked and reclaimed pages |
|
63 |
// 46 Restore chunk |
|
64 |
// 47 Big Unlock/Lock |
|
65 |
// 48 Benchmarks... |
|
66 |
// 49 Close chunk with unlocked pages which have been flushed |
|
67 |
// |
|
68 |
// |
|
69 |
||
70 |
//! @SYMTestCaseID KBASE-T_CACHECHUNK-0336 |
|
71 |
//! @SYMTestType UT |
|
72 |
//! @SYMPREQ PREQ1110 |
|
73 |
//! @SYMTestCaseDesc Demand Paging Loader Stress Tests |
|
74 |
//! @SYMTestActions 0 Commit all of memory |
|
75 |
//! @SYMTestExpectedResults All tests should pass. |
|
76 |
//! @SYMTestPriority High |
|
77 |
//! @SYMTestStatus Implemented |
|
78 |
||
79 |
#define __E32TEST_EXTENSION__ |
|
80 |
||
81 |
#include <e32test.h> |
|
82 |
#include <e32panic.h> |
|
83 |
#include <e32svr.h> |
|
84 |
#include <hal.h> |
|
85 |
#include "mmudetect.h" |
|
86 |
#include "d_memorytest.h" |
|
87 |
#include "d_gobble.h" |
|
88 |
#include <dptest.h> |
|
89 |
#include "freeram.h" |
|
90 |
||
91 |
LOCAL_D RTest test(_L("T_CACHECHUNK")); |
|
92 |
||
93 |
RMemoryTestLdd MemoryTest; |
|
94 |
||
95 |
RChunk TestChunk; |
|
96 |
TUint8* TestChunkBase; |
|
97 |
TInt CommitEnd; |
|
98 |
TInt PageSize; |
|
99 |
TInt NoFreeRam; |
|
100 |
RTimer Timer; |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
TBool gFmm; |
0 | 102 |
|
103 |
||
104 |
void FillPage(TUint aOffset) |
|
105 |
{ |
|
106 |
TUint8* ptr = TestChunkBase+aOffset; |
|
107 |
TUint8* ptrEnd = ptr+PageSize; |
|
108 |
do *((TUint32*&)ptr)++ = aOffset+=4; |
|
109 |
while(ptr<ptrEnd); |
|
110 |
} |
|
111 |
||
112 |
||
113 |
TBool CheckPage(TUint aOffset) |
|
114 |
{ |
|
115 |
TUint8* ptr = TestChunkBase+aOffset; |
|
116 |
TUint8* ptrEnd = ptr+PageSize; |
|
117 |
do if(*((TUint32*&)ptr)++ != (aOffset+=4)) break; |
|
118 |
while(ptr<ptrEnd); |
|
119 |
return ptr==ptrEnd; |
|
120 |
} |
|
121 |
||
122 |
||
123 |
TBool CheckPages(TUint aOffset, TInt aNumPages) |
|
124 |
{ |
|
125 |
while(aNumPages--) |
|
126 |
if(!CheckPage(aOffset+=PageSize)) |
|
127 |
return EFalse; |
|
128 |
return ETrue; |
|
129 |
} |
|
130 |
||
131 |
||
132 |
TBool IsPageMapped(TUint aOffset) |
|
133 |
{ |
|
134 |
TUint32 value; |
|
135 |
TInt r=MemoryTest.ReadMemory(TestChunkBase+aOffset,value); |
|
136 |
return r==KErrNone; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
void Tests(TInt aOffset) |
|
141 |
{ |
|
142 |
if(aOffset+5*PageSize>=CommitEnd) |
|
143 |
{ |
|
144 |
test.Start(_L("TEST NOT RUN - Not enough system RAM")); |
|
145 |
test.End(); |
|
146 |
return; |
|
147 |
} |
|
148 |
TInt r; |
|
149 |
TInt freeRam; |
|
150 |
||
151 |
TUint origChunkSize = TestChunk.Size(); |
|
152 |
||
153 |
test.Start(_L("Check Unlock is idempotent")); |
|
154 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize); |
|
155 |
test_KErrNone(r); |
|
156 |
freeRam = FreeRam(); |
|
157 |
test(freeRam==NoFreeRam+PageSize); |
|
158 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize); |
|
159 |
test_KErrNone(r); |
|
160 |
test_Equal(FreeRam(), freeRam); |
|
161 |
// Ensure unlock on reclaimed pages is idempotent |
|
162 |
TInt flushSupported = UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); |
|
163 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize); |
|
164 |
test_KErrNone(r); |
|
165 |
test_Equal(FreeRam(), freeRam); |
|
166 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
167 |
||
168 |
if (flushSupported == KErrNotSupported) |
|
169 |
{// Flush cache not supported so lock won't fail so no need to recommit the pages. |
|
170 |
test_KErrNone(TestChunk.Lock(aOffset+PageSize,PageSize)); |
|
171 |
} |
|
172 |
else |
|
173 |
{// Recommit the reclaimed pages. |
|
174 |
test_KErrNone(flushSupported); |
|
175 |
test_Equal(KErrNotFound, TestChunk.Lock(aOffset+PageSize,PageSize)); |
|
176 |
test_KErrNone(TestChunk.Commit(aOffset+PageSize,PageSize)); |
|
177 |
} |
|
178 |
||
179 |
test.Next(_L("Check Lock is idempotent")); |
|
180 |
r = TestChunk.Lock(aOffset,3*PageSize); |
|
181 |
test_KErrNone(r); |
|
182 |
freeRam = FreeRam(); |
|
183 |
test(freeRam==NoFreeRam); |
|
184 |
CheckPages(aOffset,3); |
|
185 |
r = TestChunk.Lock(aOffset,3*PageSize); |
|
186 |
test_KErrNone(r); |
|
187 |
CheckPages(aOffset,3); |
|
188 |
freeRam = FreeRam(); |
|
189 |
test(freeRam==NoFreeRam); |
|
190 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
191 |
||
192 |
test.Next(_L("Check non page aligned Unlock/Lock")); |
|
193 |
r = TestChunk.Unlock(aOffset+PageSize-1,1); |
|
194 |
test_KErrNone(r); |
|
195 |
freeRam = FreeRam(); |
|
196 |
test(freeRam==NoFreeRam+PageSize); |
|
197 |
r = TestChunk.Lock(aOffset+PageSize-1,1); |
|
198 |
test_KErrNone(r); |
|
199 |
freeRam = FreeRam(); |
|
200 |
test(freeRam==NoFreeRam); |
|
201 |
r = TestChunk.Unlock(aOffset+PageSize-1,2); |
|
202 |
test_KErrNone(r); |
|
203 |
freeRam = FreeRam(); |
|
204 |
test(freeRam==NoFreeRam+PageSize*2); |
|
205 |
r = TestChunk.Lock(aOffset+PageSize-1,2); |
|
206 |
test_KErrNone(r); |
|
207 |
freeRam = FreeRam(); |
|
208 |
test(freeRam==NoFreeRam); |
|
209 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
210 |
||
211 |
test.Next(_L("Check unlocked pages get reclaimed for new memory allocation")); |
|
212 |
r=TestChunk.Commit(CommitEnd,PageSize); |
|
213 |
test(r==KErrNoMemory); |
|
214 |
r = TestChunk.Unlock(aOffset,4*PageSize); |
|
215 |
test_KErrNone(r); |
|
216 |
freeRam = FreeRam(); |
|
217 |
test(freeRam==NoFreeRam+PageSize*4); |
|
218 |
r=TestChunk.Commit(CommitEnd,PageSize); |
|
219 |
test_KErrNone(r); |
|
220 |
freeRam = FreeRam(); |
|
221 |
test(freeRam<NoFreeRam+PageSize*4); |
|
222 |
r=TestChunk.Decommit(CommitEnd,PageSize); |
|
223 |
test_KErrNone(r); |
|
224 |
freeRam = FreeRam(); |
|
225 |
test(freeRam==NoFreeRam+PageSize*4); |
|
226 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone |
|
227 |
freeRam = FreeRam(); |
|
228 |
test(freeRam==NoFreeRam+PageSize*4); |
|
229 |
||
230 |
#ifndef __WINS__ // wins fakery doesn't actually do this |
|
231 |
test.Next(_L("Check reclaimed memory is unmapped and decommitted from original location")); |
|
232 |
TInt mappedPages = IsPageMapped(aOffset+PageSize*0); |
|
233 |
mappedPages += IsPageMapped(aOffset+PageSize*1); |
|
234 |
mappedPages += IsPageMapped(aOffset+PageSize*2); |
|
235 |
mappedPages += IsPageMapped(aOffset+PageSize*3); |
|
236 |
test(mappedPages<4); |
|
237 |
#endif |
|
238 |
if(aOffset>PageSize) |
|
239 |
{ |
|
240 |
test(CheckPage(aOffset+PageSize*-1)); // should be left mapped |
|
241 |
} |
|
242 |
test(CheckPage(aOffset+PageSize*4)); // should be left mapped |
|
243 |
||
244 |
test.Next(_L("Check Lock fails when memory is reclaimed")); |
|
245 |
r = TestChunk.Lock(aOffset,4*PageSize); |
|
246 |
test(r==KErrNotFound); |
|
247 |
freeRam = FreeRam(); |
|
248 |
test(freeRam==NoFreeRam+PageSize*4); |
|
249 |
||
250 |
test.Next(_L("Check Lock failure Decommits memory")); |
|
251 |
test(!IsPageMapped(aOffset+PageSize*0)); |
|
252 |
test(!IsPageMapped(aOffset+PageSize*1)); |
|
253 |
test(!IsPageMapped(aOffset+PageSize*2)); |
|
254 |
test(!IsPageMapped(aOffset+PageSize*3)); |
|
255 |
test_Equal(origChunkSize-PageSize*4, TestChunk.Size()); |
|
256 |
||
257 |
test.Next(_L("Recommit memory to chunk")); |
|
258 |
TInt offset; |
|
259 |
for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize) |
|
260 |
{ |
|
261 |
r=TestChunk.Commit(offset,PageSize); |
|
262 |
test_KErrNone(r); |
|
263 |
FillPage(offset); |
|
264 |
} |
|
265 |
freeRam = FreeRam(); |
|
266 |
test(freeRam==NoFreeRam); |
|
267 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
268 |
||
269 |
test.Next(_L("Check Commit on unlocked pages")); |
|
270 |
r = TestChunk.Unlock(aOffset,4*PageSize); |
|
271 |
test_KErrNone(r); |
|
272 |
freeRam = FreeRam(); |
|
273 |
test(freeRam>=NoFreeRam+PageSize*4); |
|
274 |
r=TestChunk.Commit(aOffset,4*PageSize); |
|
275 |
test(r==KErrAlreadyExists); |
|
276 |
freeRam = FreeRam(); |
|
277 |
test(freeRam>=NoFreeRam+PageSize*4); |
|
278 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
279 |
||
280 |
test.Next(_L("Check Commit on unlocked and reclaimed pages")); |
|
281 |
// unlock and force a page to be reclaimed... |
|
282 |
r=TestChunk.Commit(CommitEnd,PageSize); |
|
283 |
test_KErrNone(r); |
|
284 |
r=TestChunk.Decommit(CommitEnd,PageSize); |
|
285 |
test_KErrNone(r); |
|
286 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone |
|
287 |
freeRam = FreeRam(); |
|
288 |
test(freeRam>=NoFreeRam+PageSize*4); |
|
289 |
// check can't commit any pages (because they are unlocked, not decommitted)... |
|
290 |
r=TestChunk.Commit(aOffset+PageSize*0,PageSize); |
|
291 |
test(r==KErrAlreadyExists); |
|
292 |
r=TestChunk.Commit(aOffset+PageSize*1,PageSize); |
|
293 |
test(r==KErrAlreadyExists); |
|
294 |
r=TestChunk.Commit(aOffset+PageSize*2,PageSize); |
|
295 |
test(r==KErrAlreadyExists); |
|
296 |
r=TestChunk.Commit(aOffset+PageSize*3,PageSize); |
|
297 |
test(r==KErrAlreadyExists); |
|
298 |
freeRam = FreeRam(); |
|
299 |
test(freeRam>=NoFreeRam+PageSize*4); |
|
300 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
301 |
// Restore the chunk to original size. |
|
302 |
r = TestChunk.Lock(aOffset,4*PageSize); |
|
303 |
test_Equal(r, KErrNotFound); |
|
304 |
freeRam = FreeRam(); |
|
305 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
|
306 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size()); |
|
307 |
r = TestChunk.Commit(aOffset, PageSize*4); |
|
308 |
test_KErrNone(r); |
|
309 |
||
310 |
test.Next(_L("Check Decommit on unlocked pages")); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
// Get orignal page cache size |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
TUint minCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
TUint maxCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
TUint oldCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
TUint newCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
{ |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
r = DPTest::CacheSize(minCache, maxCache, oldCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
} |
0 | 321 |
r = TestChunk.Unlock(aOffset,PageSize*4); |
322 |
test_KErrNone(r); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
TUint spareCache = maxCache - oldCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
if (gFmm && spareCache) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
{// Cache wasn't at maximum so should have grown when unlocked pages were added. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
TUint extraCache = (spareCache > (TUint)PageSize*4)? PageSize*4 : spareCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
test_Equal(oldCache + extraCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
} |
0 | 332 |
test(FreeRam() >= NoFreeRam+PageSize*4); |
333 |
r=TestChunk.Decommit(aOffset, PageSize*4); |
|
334 |
test_KErrNone(r); |
|
335 |
freeRam = FreeRam(); |
|
336 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
|
337 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size()); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
{// Cache should have shrunk after pages were decommited. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
test_Equal(oldCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
} |
0 | 345 |
// Restore chunk back to original state |
346 |
r = TestChunk.Commit(aOffset, PageSize*4); |
|
347 |
test_KErrNone(r); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
test_Equal(NoFreeRam, FreeRam()); |
0 | 349 |
|
350 |
test.Next(_L("Check Decommit on unlocked and reclaimed pages")); |
|
351 |
r = TestChunk.Unlock(aOffset,PageSize*4); |
|
352 |
test_KErrNone(r); |
|
353 |
freeRam = FreeRam(); |
|
354 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
|
355 |
r=TestChunk.Commit(CommitEnd,PageSize); |
|
356 |
test_KErrNone(r); |
|
357 |
r=TestChunk.Decommit(CommitEnd,PageSize); |
|
358 |
test_KErrNone(r); |
|
359 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone |
|
360 |
freeRam = FreeRam(); |
|
361 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
|
362 |
r=TestChunk.Decommit(aOffset, PageSize*4); |
|
363 |
test_KErrNone(r); |
|
364 |
freeRam = FreeRam(); |
|
365 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
|
366 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size()); |
|
367 |
||
368 |
test.Next(_L("Restore chunk")); |
|
369 |
test_Equal(origChunkSize-PageSize*4, TestChunk.Size()); |
|
370 |
for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize) |
|
371 |
{ |
|
372 |
r=TestChunk.Commit(offset,PageSize); |
|
373 |
test_KErrNone(r); |
|
374 |
FillPage(offset); |
|
375 |
} |
|
376 |
freeRam = FreeRam(); |
|
377 |
test(freeRam==NoFreeRam); |
|
378 |
test_Equal(origChunkSize, TestChunk.Size()); |
|
379 |
||
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
test.Next(_L("Check Decommit on a mixture of locked and unlocked pages")); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
// Get orignal page cache size |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
{ |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
r = DPTest::CacheSize(minCache, maxCache, oldCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
r = TestChunk.Unlock(aOffset,PageSize); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
r = TestChunk.Unlock(aOffset + PageSize*2, PageSize); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
spareCache = maxCache - oldCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
if (gFmm && spareCache) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
{// Cache wasn't at maximum so should have grown when unlocked pages were added. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
TUint extraCache = (spareCache > (TUint)PageSize*2)? PageSize*2 : spareCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
test_Equal(oldCache + extraCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
test(FreeRam() >= NoFreeRam+PageSize*2); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
r=TestChunk.Decommit(aOffset, PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
freeRam = FreeRam(); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size()); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
{// Cache should have shrunk after pages were decommited. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
test_Equal(oldCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
// Restore chunk back to original state |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
r = TestChunk.Commit(aOffset, PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
test_Equal(NoFreeRam, FreeRam()); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
|
0 | 418 |
test.End(); |
419 |
} |
|
420 |
||
421 |
||
422 |
||
423 |
void TestBenchmarks() |
|
424 |
{ |
|
425 |
TInt r = TestChunk.Unlock(0,CommitEnd); // start with everthing unlocked |
|
426 |
test_KErrNone(r); |
|
427 |
TInt testSizes[] = { PageSize,1<<16,1<<20,0 }; |
|
428 |
TInt* sizes = testSizes; |
|
429 |
TInt size; |
|
430 |
while((size=*sizes++)!=0) |
|
431 |
{ |
|
432 |
TRequestStatus status; |
|
433 |
Timer.After(status,1); |
|
434 |
User::WaitForRequest(status); |
|
435 |
TInt KRunTime = 1*1000*1000; |
|
436 |
Timer.After(status,KRunTime); |
|
437 |
TInt count = 0; |
|
438 |
while(status==KRequestPending) |
|
439 |
{ |
|
440 |
r = TestChunk.Lock(0,size); |
|
441 |
test_KErrNone(r); |
|
442 |
r = TestChunk.Unlock(0,size); |
|
443 |
test_KErrNone(r); |
|
444 |
++count; |
|
445 |
} |
|
446 |
User::WaitForRequest(status); |
|
447 |
test.Printf(_L("Unlock/Lock of %d kB takes %d us\n"),size>>10,KRunTime/count); |
|
448 |
} |
|
449 |
} |
|
450 |
||
451 |
||
452 |
||
453 |
void TestUnlockOld() |
|
454 |
{ |
|
455 |
// we start with TestChunk being locked and no or little free RAM |
|
456 |
// (hence live list should be close to minimum size.) |
|
457 |
||
458 |
// get sizes... |
|
459 |
TUint min = 0; |
|
460 |
TUint max = 0; |
|
461 |
TUint cur = 0; |
|
462 |
TInt r = DPTest::CacheSize(min,max,cur); |
|
463 |
||
464 |
// manipulate demand paging live list so we end up with zero old pages... |
|
465 |
||
466 |
r = TestChunk.Unlock(0,min*2); // dump 2*min bytes at start of live list |
|
467 |
test_KErrNone(r); |
|
468 |
// live list now cur+2*min bytes |
|
469 |
||
470 |
r = TestChunk.Commit(CommitEnd,cur); // use up 'cur' bytes of RAM from end of live list |
|
471 |
test_KErrNone(r); |
|
472 |
// live list now 2*min bytes of pages which were unlocked from our test chunk |
|
473 |
||
474 |
// lock pages until free RAM is <= 2 pages. |
|
475 |
// this should remove all of the 'old' pages |
|
476 |
TUint i = 0; |
|
477 |
while(FreeRam()>2*PageSize) |
|
478 |
{ |
|
479 |
TestChunk.Lock(i,PageSize); |
|
480 |
i += PageSize; |
|
481 |
test(i<=min); |
|
482 |
} |
|
483 |
// live list now min+2*PageSize bytes, with no old pages |
|
484 |
||
485 |
// now commit memory, which forces allocation from the demand paging live list |
|
486 |
// which doesn't have any old pages (the purpose of this test)... |
|
487 |
TUint extra = 0; |
|
488 |
for(;;) |
|
489 |
{ |
|
490 |
r = TestChunk.Commit(CommitEnd+min+extra,PageSize); |
|
491 |
if(r==KErrNoMemory) |
|
492 |
break; |
|
493 |
extra += PageSize; |
|
494 |
} |
|
495 |
test(extra>0); |
|
496 |
||
497 |
// restore commit state... |
|
498 |
r = TestChunk.Decommit(CommitEnd,min+extra); |
|
499 |
test_KErrNone(r); |
|
500 |
r = TestChunk.Decommit(0,min*2); |
|
501 |
test_KErrNone(r); |
|
502 |
r = TestChunk.Commit(0,min*2); |
|
503 |
test_KErrNone(r); |
|
504 |
} |
|
505 |
||
506 |
||
507 |
||
508 |
TInt E32Main() |
|
509 |
{ |
|
510 |
test.Title(); |
|
511 |
||
512 |
if (!HaveVirtMem()) |
|
513 |
{ |
|
514 |
test.Printf(_L("This test requires an MMU\n")); |
|
515 |
return KErrNone; |
|
516 |
} |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
// See if were running on the Flexible Memory Model or newer. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
TUint32 memModelAttrib = (TUint32)UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
gFmm = (memModelAttrib & EMemModelTypeMask) >= EMemModelTypeFlexible; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
|
0 | 521 |
test.Start(_L("Initialise test")); |
522 |
test.Next(_L("Load gobbler LDD")); |
|
523 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName); |
|
524 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
525 |
RGobbler gobbler; |
|
526 |
r = gobbler.Open(); |
|
527 |
test(r==KErrNone); |
|
528 |
TUint32 taken = gobbler.GobbleRAM(496*1024*1024); |
|
529 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024); |
|
530 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam()); |
|
531 |
||
532 |
test_KErrNone(HAL::Get(HAL::EMemoryPageSize,PageSize)); |
|
533 |
TInt totalRAM; |
|
534 |
test_KErrNone(HAL::Get(HAL::EMemoryRAM, totalRAM)); |
|
535 |
totalRAM -= taken; |
|
536 |
test.Printf(_L("totalRAM=%dK\n"), totalRAM/1024); |
|
537 |
||
538 |
test(KErrNone==MemoryTest.Open()); |
|
539 |
// Create the test chunk. It must not be paged otherwise |
|
540 |
// unlocking its pages will have no effect. |
|
541 |
TChunkCreateInfo createInfo; |
|
542 |
createInfo.SetCache(totalRAM); |
|
543 |
test_KErrNone(TestChunk.Create(createInfo)); |
|
544 |
TestChunkBase = TestChunk.Base(); |
|
545 |
||
546 |
test(KErrNone==Timer.CreateLocal()); |
|
547 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); |
|
548 |
||
549 |
test.Next(_L("Commit all of memory")); |
|
550 |
CommitEnd = 0; |
|
551 |
while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize))) |
|
552 |
{ |
|
553 |
FillPage(CommitEnd); |
|
554 |
CommitEnd += PageSize; |
|
555 |
} |
|
556 |
test(r==KErrNoMemory); |
|
557 |
NoFreeRam = FreeRam(); |
|
558 |
test(NoFreeRam<=PageSize); |
|
559 |
||
560 |
test.Next(_L("Check Unlocked page gets counted as free memory")); |
|
561 |
r = TestChunk.Unlock(0,PageSize); |
|
562 |
test_KErrNone(r); |
|
563 |
TInt freeRam = FreeRam(); |
|
564 |
test(freeRam==NoFreeRam+PageSize); |
|
565 |
r = TestChunk.Lock(0,PageSize); |
|
566 |
test_KErrNone(r); |
|
567 |
freeRam = FreeRam(); |
|
568 |
test(freeRam==NoFreeRam); |
|
569 |
||
570 |
test.Next(_L("Check Unlock/Lock preserves page contents")); |
|
571 |
TInt offset; |
|
572 |
for(offset=0; offset<CommitEnd; offset+=PageSize) |
|
573 |
{ |
|
574 |
test(CheckPage(offset)); |
|
575 |
r = TestChunk.Unlock(offset,PageSize); |
|
576 |
test_KErrNone(r); |
|
577 |
r = TestChunk.Lock(offset,PageSize); |
|
578 |
test_KErrNone(r); |
|
579 |
test(CheckPage(offset)); |
|
580 |
freeRam = FreeRam(); |
|
581 |
test(freeRam==NoFreeRam); |
|
582 |
} |
|
583 |
||
584 |
test.Next(_L("Tests at chunk offset '0'")); |
|
585 |
Tests(0); |
|
586 |
test.Next(_L("Tests at chunk offset 'PageSize'")); |
|
587 |
Tests(PageSize); |
|
588 |
test.Next(_L("Tests at chunk offset '0x100000-PageSize'")); |
|
589 |
Tests(0x100000-PageSize); |
|
590 |
test.Next(_L("Tests at chunk offset '0x400000-PageSize'")); |
|
591 |
Tests(0x400000-PageSize); |
|
592 |
||
593 |
// Remove limit on max size of live list |
|
594 |
TUint originalMin = 0; |
|
595 |
TUint originalMax = 0; |
|
596 |
TUint currentSize = 0; |
|
597 |
r = DPTest::CacheSize(originalMin, originalMax, currentSize); |
|
598 |
test(r == KErrNone || r == KErrNotSupported); |
|
599 |
TBool resizeCache = r == KErrNone; |
|
600 |
if (resizeCache) |
|
601 |
test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint)); |
|
602 |
||
603 |
test.Next(_L("Big Unlock/Lock")); |
|
604 |
r = TestChunk.Unlock(0,CommitEnd); |
|
605 |
test_KErrNone(r); |
|
606 |
freeRam = FreeRam(); |
|
607 |
test(freeRam>=NoFreeRam+CommitEnd); |
|
608 |
r = TestChunk.Lock(0,CommitEnd); |
|
609 |
test_KErrNone(r); |
|
610 |
freeRam = FreeRam(); |
|
611 |
test_Equal(NoFreeRam, freeRam); |
|
612 |
||
613 |
if (resizeCache) |
|
614 |
{ |
|
615 |
test.Next(_L("Check Unlock of old pages doesn't cause problems")); |
|
616 |
TestUnlockOld(); |
|
617 |
} |
|
618 |
||
619 |
test.Next(_L("Benchmarks...")); |
|
620 |
TestBenchmarks(); |
|
621 |
||
622 |
test.Next(_L("Close chunk with unlocked pages which have been flushed")); |
|
623 |
r = TestChunk.Unlock(0,CommitEnd); |
|
624 |
test_KErrNone(r); |
|
625 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); |
|
626 |
TestChunk.Close(); |
|
627 |
||
628 |
test.Next(_L("Check can't lock/unlock non-cache chunks")); |
|
629 |
RChunk chunk; |
|
630 |
test_KErrNone(chunk.CreateDisconnectedLocal(0,PageSize,2*PageSize)); |
|
631 |
test_Equal(KErrGeneral,chunk.Lock(PageSize,PageSize)); |
|
632 |
test_Equal(KErrGeneral,chunk.Unlock(0,PageSize)); |
|
633 |
chunk.Close(); |
|
634 |
||
635 |
// Restore original settings for live list size |
|
636 |
if (resizeCache) |
|
637 |
test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax)); |
|
638 |
||
639 |
// end... |
|
640 |
test.End(); |
|
641 |
MemoryTest.Close(); |
|
642 |
gobbler.Close(); |
|
643 |
test.Close(); |
|
644 |
||
645 |
return KErrNone; |
|
646 |
} |