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"
|
176
|
90 |
#include "..\demandpaging\t_dpcmn.h"
|
0
|
91 |
|
176
|
92 |
RTest test(_L("T_CACHECHUNK"));
|
0
|
93 |
|
|
94 |
RMemoryTestLdd MemoryTest;
|
|
95 |
|
|
96 |
RChunk TestChunk;
|
|
97 |
TUint8* TestChunkBase;
|
|
98 |
TInt CommitEnd;
|
|
99 |
TInt PageSize;
|
|
100 |
TInt NoFreeRam;
|
|
101 |
RTimer Timer;
|
132
|
102 |
TBool gFmm;
|
0
|
103 |
|
|
104 |
|
|
105 |
void FillPage(TUint aOffset)
|
|
106 |
{
|
|
107 |
TUint8* ptr = TestChunkBase+aOffset;
|
|
108 |
TUint8* ptrEnd = ptr+PageSize;
|
|
109 |
do *((TUint32*&)ptr)++ = aOffset+=4;
|
|
110 |
while(ptr<ptrEnd);
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
TBool CheckPage(TUint aOffset)
|
|
115 |
{
|
|
116 |
TUint8* ptr = TestChunkBase+aOffset;
|
|
117 |
TUint8* ptrEnd = ptr+PageSize;
|
|
118 |
do if(*((TUint32*&)ptr)++ != (aOffset+=4)) break;
|
|
119 |
while(ptr<ptrEnd);
|
|
120 |
return ptr==ptrEnd;
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
TBool CheckPages(TUint aOffset, TInt aNumPages)
|
|
125 |
{
|
|
126 |
while(aNumPages--)
|
|
127 |
if(!CheckPage(aOffset+=PageSize))
|
|
128 |
return EFalse;
|
|
129 |
return ETrue;
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
TBool IsPageMapped(TUint aOffset)
|
|
134 |
{
|
|
135 |
TUint32 value;
|
|
136 |
TInt r=MemoryTest.ReadMemory(TestChunkBase+aOffset,value);
|
|
137 |
return r==KErrNone;
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
void Tests(TInt aOffset)
|
|
142 |
{
|
|
143 |
if(aOffset+5*PageSize>=CommitEnd)
|
|
144 |
{
|
|
145 |
test.Start(_L("TEST NOT RUN - Not enough system RAM"));
|
|
146 |
test.End();
|
|
147 |
return;
|
|
148 |
}
|
|
149 |
TInt r;
|
|
150 |
TInt freeRam;
|
|
151 |
|
|
152 |
TUint origChunkSize = TestChunk.Size();
|
|
153 |
|
|
154 |
test.Start(_L("Check Unlock is idempotent"));
|
|
155 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize);
|
|
156 |
test_KErrNone(r);
|
|
157 |
freeRam = FreeRam();
|
|
158 |
test(freeRam==NoFreeRam+PageSize);
|
|
159 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize);
|
|
160 |
test_KErrNone(r);
|
|
161 |
test_Equal(FreeRam(), freeRam);
|
|
162 |
// Ensure unlock on reclaimed pages is idempotent
|
|
163 |
TInt flushSupported = UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
|
|
164 |
r = TestChunk.Unlock(aOffset+PageSize,PageSize);
|
|
165 |
test_KErrNone(r);
|
|
166 |
test_Equal(FreeRam(), freeRam);
|
|
167 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
168 |
|
|
169 |
if (flushSupported == KErrNotSupported)
|
|
170 |
{// Flush cache not supported so lock won't fail so no need to recommit the pages.
|
|
171 |
test_KErrNone(TestChunk.Lock(aOffset+PageSize,PageSize));
|
|
172 |
}
|
|
173 |
else
|
|
174 |
{// Recommit the reclaimed pages.
|
|
175 |
test_KErrNone(flushSupported);
|
|
176 |
test_Equal(KErrNotFound, TestChunk.Lock(aOffset+PageSize,PageSize));
|
|
177 |
test_KErrNone(TestChunk.Commit(aOffset+PageSize,PageSize));
|
|
178 |
}
|
|
179 |
|
|
180 |
test.Next(_L("Check Lock is idempotent"));
|
|
181 |
r = TestChunk.Lock(aOffset,3*PageSize);
|
|
182 |
test_KErrNone(r);
|
|
183 |
freeRam = FreeRam();
|
|
184 |
test(freeRam==NoFreeRam);
|
|
185 |
CheckPages(aOffset,3);
|
|
186 |
r = TestChunk.Lock(aOffset,3*PageSize);
|
|
187 |
test_KErrNone(r);
|
|
188 |
CheckPages(aOffset,3);
|
|
189 |
freeRam = FreeRam();
|
|
190 |
test(freeRam==NoFreeRam);
|
|
191 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
192 |
|
|
193 |
test.Next(_L("Check non page aligned Unlock/Lock"));
|
|
194 |
r = TestChunk.Unlock(aOffset+PageSize-1,1);
|
|
195 |
test_KErrNone(r);
|
|
196 |
freeRam = FreeRam();
|
|
197 |
test(freeRam==NoFreeRam+PageSize);
|
|
198 |
r = TestChunk.Lock(aOffset+PageSize-1,1);
|
|
199 |
test_KErrNone(r);
|
|
200 |
freeRam = FreeRam();
|
|
201 |
test(freeRam==NoFreeRam);
|
|
202 |
r = TestChunk.Unlock(aOffset+PageSize-1,2);
|
|
203 |
test_KErrNone(r);
|
|
204 |
freeRam = FreeRam();
|
|
205 |
test(freeRam==NoFreeRam+PageSize*2);
|
|
206 |
r = TestChunk.Lock(aOffset+PageSize-1,2);
|
|
207 |
test_KErrNone(r);
|
|
208 |
freeRam = FreeRam();
|
|
209 |
test(freeRam==NoFreeRam);
|
|
210 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
211 |
|
|
212 |
test.Next(_L("Check unlocked pages get reclaimed for new memory allocation"));
|
|
213 |
r=TestChunk.Commit(CommitEnd,PageSize);
|
|
214 |
test(r==KErrNoMemory);
|
|
215 |
r = TestChunk.Unlock(aOffset,4*PageSize);
|
|
216 |
test_KErrNone(r);
|
|
217 |
freeRam = FreeRam();
|
|
218 |
test(freeRam==NoFreeRam+PageSize*4);
|
|
219 |
r=TestChunk.Commit(CommitEnd,PageSize);
|
|
220 |
test_KErrNone(r);
|
|
221 |
freeRam = FreeRam();
|
|
222 |
test(freeRam<NoFreeRam+PageSize*4);
|
|
223 |
r=TestChunk.Decommit(CommitEnd,PageSize);
|
|
224 |
test_KErrNone(r);
|
|
225 |
freeRam = FreeRam();
|
|
226 |
test(freeRam==NoFreeRam+PageSize*4);
|
|
227 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
|
|
228 |
freeRam = FreeRam();
|
|
229 |
test(freeRam==NoFreeRam+PageSize*4);
|
|
230 |
|
|
231 |
#ifndef __WINS__ // wins fakery doesn't actually do this
|
|
232 |
test.Next(_L("Check reclaimed memory is unmapped and decommitted from original location"));
|
|
233 |
TInt mappedPages = IsPageMapped(aOffset+PageSize*0);
|
|
234 |
mappedPages += IsPageMapped(aOffset+PageSize*1);
|
|
235 |
mappedPages += IsPageMapped(aOffset+PageSize*2);
|
|
236 |
mappedPages += IsPageMapped(aOffset+PageSize*3);
|
|
237 |
test(mappedPages<4);
|
|
238 |
#endif
|
|
239 |
if(aOffset>PageSize)
|
|
240 |
{
|
|
241 |
test(CheckPage(aOffset+PageSize*-1)); // should be left mapped
|
|
242 |
}
|
|
243 |
test(CheckPage(aOffset+PageSize*4)); // should be left mapped
|
|
244 |
|
|
245 |
test.Next(_L("Check Lock fails when memory is reclaimed"));
|
|
246 |
r = TestChunk.Lock(aOffset,4*PageSize);
|
|
247 |
test(r==KErrNotFound);
|
|
248 |
freeRam = FreeRam();
|
|
249 |
test(freeRam==NoFreeRam+PageSize*4);
|
|
250 |
|
|
251 |
test.Next(_L("Check Lock failure Decommits memory"));
|
|
252 |
test(!IsPageMapped(aOffset+PageSize*0));
|
|
253 |
test(!IsPageMapped(aOffset+PageSize*1));
|
|
254 |
test(!IsPageMapped(aOffset+PageSize*2));
|
|
255 |
test(!IsPageMapped(aOffset+PageSize*3));
|
|
256 |
test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
|
|
257 |
|
|
258 |
test.Next(_L("Recommit memory to chunk"));
|
|
259 |
TInt offset;
|
|
260 |
for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
|
|
261 |
{
|
|
262 |
r=TestChunk.Commit(offset,PageSize);
|
|
263 |
test_KErrNone(r);
|
|
264 |
FillPage(offset);
|
|
265 |
}
|
|
266 |
freeRam = FreeRam();
|
|
267 |
test(freeRam==NoFreeRam);
|
|
268 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
269 |
|
|
270 |
test.Next(_L("Check Commit on unlocked pages"));
|
|
271 |
r = TestChunk.Unlock(aOffset,4*PageSize);
|
|
272 |
test_KErrNone(r);
|
|
273 |
freeRam = FreeRam();
|
|
274 |
test(freeRam>=NoFreeRam+PageSize*4);
|
|
275 |
r=TestChunk.Commit(aOffset,4*PageSize);
|
|
276 |
test(r==KErrAlreadyExists);
|
|
277 |
freeRam = FreeRam();
|
|
278 |
test(freeRam>=NoFreeRam+PageSize*4);
|
|
279 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
280 |
|
|
281 |
test.Next(_L("Check Commit on unlocked and reclaimed pages"));
|
|
282 |
// unlock and force a page to be reclaimed...
|
|
283 |
r=TestChunk.Commit(CommitEnd,PageSize);
|
|
284 |
test_KErrNone(r);
|
|
285 |
r=TestChunk.Decommit(CommitEnd,PageSize);
|
|
286 |
test_KErrNone(r);
|
|
287 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
|
|
288 |
freeRam = FreeRam();
|
|
289 |
test(freeRam>=NoFreeRam+PageSize*4);
|
|
290 |
// check can't commit any pages (because they are unlocked, not decommitted)...
|
|
291 |
r=TestChunk.Commit(aOffset+PageSize*0,PageSize);
|
|
292 |
test(r==KErrAlreadyExists);
|
|
293 |
r=TestChunk.Commit(aOffset+PageSize*1,PageSize);
|
|
294 |
test(r==KErrAlreadyExists);
|
|
295 |
r=TestChunk.Commit(aOffset+PageSize*2,PageSize);
|
|
296 |
test(r==KErrAlreadyExists);
|
|
297 |
r=TestChunk.Commit(aOffset+PageSize*3,PageSize);
|
|
298 |
test(r==KErrAlreadyExists);
|
|
299 |
freeRam = FreeRam();
|
|
300 |
test(freeRam>=NoFreeRam+PageSize*4);
|
|
301 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
302 |
// Restore the chunk to original size.
|
|
303 |
r = TestChunk.Lock(aOffset,4*PageSize);
|
|
304 |
test_Equal(r, KErrNotFound);
|
|
305 |
freeRam = FreeRam();
|
|
306 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
307 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
|
|
308 |
r = TestChunk.Commit(aOffset, PageSize*4);
|
|
309 |
test_KErrNone(r);
|
|
310 |
|
|
311 |
test.Next(_L("Check Decommit on unlocked pages"));
|
132
|
312 |
// Get orignal page cache size
|
|
313 |
TUint minCache = 0;
|
|
314 |
TUint maxCache = 0;
|
|
315 |
TUint oldCache = 0;
|
|
316 |
TUint newCache = 0;
|
|
317 |
if (gFmm)
|
|
318 |
{
|
|
319 |
r = DPTest::CacheSize(minCache, maxCache, oldCache);
|
|
320 |
test_KErrNone(r);
|
|
321 |
}
|
0
|
322 |
r = TestChunk.Unlock(aOffset,PageSize*4);
|
|
323 |
test_KErrNone(r);
|
132
|
324 |
|
|
325 |
TUint spareCache = maxCache - oldCache;
|
|
326 |
if (gFmm && spareCache)
|
|
327 |
{// Cache wasn't at maximum so should have grown when unlocked pages were added.
|
|
328 |
r = DPTest::CacheSize(minCache, maxCache, newCache);
|
|
329 |
test_KErrNone(r);
|
|
330 |
TUint extraCache = (spareCache > (TUint)PageSize*4)? PageSize*4 : spareCache;
|
|
331 |
test_Equal(oldCache + extraCache, newCache);
|
|
332 |
}
|
0
|
333 |
test(FreeRam() >= NoFreeRam+PageSize*4);
|
|
334 |
r=TestChunk.Decommit(aOffset, PageSize*4);
|
|
335 |
test_KErrNone(r);
|
|
336 |
freeRam = FreeRam();
|
|
337 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
338 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
|
132
|
339 |
|
|
340 |
if (gFmm)
|
|
341 |
{// Cache should have shrunk after pages were decommited.
|
|
342 |
r = DPTest::CacheSize(minCache, maxCache, newCache);
|
|
343 |
test_KErrNone(r);
|
|
344 |
test_Equal(oldCache, newCache);
|
|
345 |
}
|
0
|
346 |
// Restore chunk back to original state
|
|
347 |
r = TestChunk.Commit(aOffset, PageSize*4);
|
|
348 |
test_KErrNone(r);
|
132
|
349 |
test_Equal(NoFreeRam, FreeRam());
|
0
|
350 |
|
|
351 |
test.Next(_L("Check Decommit on unlocked and reclaimed pages"));
|
|
352 |
r = TestChunk.Unlock(aOffset,PageSize*4);
|
|
353 |
test_KErrNone(r);
|
|
354 |
freeRam = FreeRam();
|
|
355 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
356 |
r=TestChunk.Commit(CommitEnd,PageSize);
|
|
357 |
test_KErrNone(r);
|
|
358 |
r=TestChunk.Decommit(CommitEnd,PageSize);
|
|
359 |
test_KErrNone(r);
|
|
360 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
|
|
361 |
freeRam = FreeRam();
|
|
362 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
363 |
r=TestChunk.Decommit(aOffset, PageSize*4);
|
|
364 |
test_KErrNone(r);
|
|
365 |
freeRam = FreeRam();
|
|
366 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
367 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
|
|
368 |
|
|
369 |
test.Next(_L("Restore chunk"));
|
|
370 |
test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
|
|
371 |
for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
|
|
372 |
{
|
|
373 |
r=TestChunk.Commit(offset,PageSize);
|
|
374 |
test_KErrNone(r);
|
|
375 |
FillPage(offset);
|
|
376 |
}
|
|
377 |
freeRam = FreeRam();
|
|
378 |
test(freeRam==NoFreeRam);
|
|
379 |
test_Equal(origChunkSize, TestChunk.Size());
|
|
380 |
|
132
|
381 |
test.Next(_L("Check Decommit on a mixture of locked and unlocked pages"));
|
|
382 |
// Get orignal page cache size
|
|
383 |
if (gFmm)
|
|
384 |
{
|
|
385 |
r = DPTest::CacheSize(minCache, maxCache, oldCache);
|
|
386 |
test_KErrNone(r);
|
|
387 |
}
|
|
388 |
r = TestChunk.Unlock(aOffset,PageSize);
|
|
389 |
test_KErrNone(r);
|
|
390 |
r = TestChunk.Unlock(aOffset + PageSize*2, PageSize);
|
|
391 |
test_KErrNone(r);
|
|
392 |
|
|
393 |
spareCache = maxCache - oldCache;
|
|
394 |
if (gFmm && spareCache)
|
|
395 |
{// Cache wasn't at maximum so should have grown when unlocked pages were added.
|
|
396 |
r = DPTest::CacheSize(minCache, maxCache, newCache);
|
|
397 |
test_KErrNone(r);
|
|
398 |
TUint extraCache = (spareCache > (TUint)PageSize*2)? PageSize*2 : spareCache;
|
|
399 |
test_Equal(oldCache + extraCache, newCache);
|
|
400 |
}
|
|
401 |
test(FreeRam() >= NoFreeRam+PageSize*2);
|
|
402 |
r=TestChunk.Decommit(aOffset, PageSize*4);
|
|
403 |
test_KErrNone(r);
|
|
404 |
freeRam = FreeRam();
|
|
405 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
|
|
406 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
|
|
407 |
|
|
408 |
if (gFmm)
|
|
409 |
{// Cache should have shrunk after pages were decommited.
|
|
410 |
r = DPTest::CacheSize(minCache, maxCache, newCache);
|
|
411 |
test_KErrNone(r);
|
|
412 |
test_Equal(oldCache, newCache);
|
|
413 |
}
|
|
414 |
// Restore chunk back to original state
|
|
415 |
r = TestChunk.Commit(aOffset, PageSize*4);
|
|
416 |
test_KErrNone(r);
|
|
417 |
test_Equal(NoFreeRam, FreeRam());
|
|
418 |
|
0
|
419 |
test.End();
|
|
420 |
}
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
void TestBenchmarks()
|
|
425 |
{
|
|
426 |
TInt r = TestChunk.Unlock(0,CommitEnd); // start with everthing unlocked
|
|
427 |
test_KErrNone(r);
|
|
428 |
TInt testSizes[] = { PageSize,1<<16,1<<20,0 };
|
|
429 |
TInt* sizes = testSizes;
|
|
430 |
TInt size;
|
|
431 |
while((size=*sizes++)!=0)
|
|
432 |
{
|
|
433 |
TRequestStatus status;
|
|
434 |
Timer.After(status,1);
|
|
435 |
User::WaitForRequest(status);
|
|
436 |
TInt KRunTime = 1*1000*1000;
|
|
437 |
Timer.After(status,KRunTime);
|
|
438 |
TInt count = 0;
|
|
439 |
while(status==KRequestPending)
|
|
440 |
{
|
|
441 |
r = TestChunk.Lock(0,size);
|
|
442 |
test_KErrNone(r);
|
|
443 |
r = TestChunk.Unlock(0,size);
|
|
444 |
test_KErrNone(r);
|
|
445 |
++count;
|
|
446 |
}
|
|
447 |
User::WaitForRequest(status);
|
|
448 |
test.Printf(_L("Unlock/Lock of %d kB takes %d us\n"),size>>10,KRunTime/count);
|
|
449 |
}
|
|
450 |
}
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
void TestUnlockOld()
|
|
455 |
{
|
|
456 |
// we start with TestChunk being locked and no or little free RAM
|
|
457 |
// (hence live list should be close to minimum size.)
|
|
458 |
|
|
459 |
// get sizes...
|
|
460 |
TUint min = 0;
|
|
461 |
TUint max = 0;
|
|
462 |
TUint cur = 0;
|
|
463 |
TInt r = DPTest::CacheSize(min,max,cur);
|
|
464 |
|
|
465 |
// manipulate demand paging live list so we end up with zero old pages...
|
|
466 |
|
|
467 |
r = TestChunk.Unlock(0,min*2); // dump 2*min bytes at start of live list
|
|
468 |
test_KErrNone(r);
|
|
469 |
// live list now cur+2*min bytes
|
|
470 |
|
|
471 |
r = TestChunk.Commit(CommitEnd,cur); // use up 'cur' bytes of RAM from end of live list
|
|
472 |
test_KErrNone(r);
|
|
473 |
// live list now 2*min bytes of pages which were unlocked from our test chunk
|
|
474 |
|
|
475 |
// lock pages until free RAM is <= 2 pages.
|
|
476 |
// this should remove all of the 'old' pages
|
|
477 |
TUint i = 0;
|
|
478 |
while(FreeRam()>2*PageSize)
|
|
479 |
{
|
|
480 |
TestChunk.Lock(i,PageSize);
|
|
481 |
i += PageSize;
|
|
482 |
test(i<=min);
|
|
483 |
}
|
|
484 |
// live list now min+2*PageSize bytes, with no old pages
|
|
485 |
|
|
486 |
// now commit memory, which forces allocation from the demand paging live list
|
|
487 |
// which doesn't have any old pages (the purpose of this test)...
|
|
488 |
TUint extra = 0;
|
|
489 |
for(;;)
|
|
490 |
{
|
|
491 |
r = TestChunk.Commit(CommitEnd+min+extra,PageSize);
|
|
492 |
if(r==KErrNoMemory)
|
|
493 |
break;
|
|
494 |
extra += PageSize;
|
|
495 |
}
|
|
496 |
test(extra>0);
|
|
497 |
|
|
498 |
// restore commit state...
|
|
499 |
r = TestChunk.Decommit(CommitEnd,min+extra);
|
|
500 |
test_KErrNone(r);
|
|
501 |
r = TestChunk.Decommit(0,min*2);
|
|
502 |
test_KErrNone(r);
|
|
503 |
r = TestChunk.Commit(0,min*2);
|
|
504 |
test_KErrNone(r);
|
|
505 |
}
|
|
506 |
|
|
507 |
|
176
|
508 |
TBool StopCacheThreads;
|
|
509 |
|
|
510 |
TInt CacheThreadFunc(TAny* aMax)
|
|
511 |
{
|
|
512 |
RThread::Rendezvous(KErrNone);
|
|
513 |
while (!StopCacheThreads)
|
|
514 |
{
|
|
515 |
TInt maxSize = (TInt)aMax;
|
|
516 |
TInt minSize;
|
|
517 |
TInt r = KErrNone;
|
|
518 |
for (minSize = PageSize << 4; r == KErrNone && !StopCacheThreads; minSize += PageSize)
|
|
519 |
{
|
|
520 |
r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize);
|
|
521 |
User::After(minSize/PageSize);
|
|
522 |
}
|
|
523 |
for (minSize -= PageSize;
|
|
524 |
minSize > PageSize << 4 && r == KErrNone && !StopCacheThreads;
|
|
525 |
minSize -= PageSize)
|
|
526 |
{
|
|
527 |
r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize);
|
|
528 |
User::After(minSize/PageSize);
|
|
529 |
}
|
|
530 |
}
|
|
531 |
return KErrNone;
|
|
532 |
}
|
|
533 |
|
|
534 |
|
|
535 |
TInt DonateThreadFunc(TAny*)
|
|
536 |
{
|
|
537 |
TChunkCreateInfo createInfo;
|
|
538 |
createInfo.SetCache(100 * PageSize);
|
|
539 |
RChunk chunk;
|
|
540 |
TInt r = chunk.Create(createInfo);
|
|
541 |
if (r != KErrNone)
|
|
542 |
{
|
|
543 |
RDebug::Printf("DonateThreadFunc: Failed to create cache chunk %d", r);
|
|
544 |
return r;
|
|
545 |
}
|
|
546 |
TUint chunkEnd = 0;
|
|
547 |
while (chunk.Commit(chunkEnd, PageSize) == KErrNone)
|
|
548 |
chunkEnd += PageSize;
|
|
549 |
|
|
550 |
RThread::Rendezvous(KErrNone);
|
|
551 |
while (!StopCacheThreads)
|
|
552 |
{
|
|
553 |
for (TUint i = PageSize; i <= chunkEnd && !StopCacheThreads; i += PageSize)
|
|
554 |
{
|
|
555 |
chunk.Unlock(0, i);
|
|
556 |
if (chunk.Lock(0, i) != KErrNone)
|
|
557 |
{// Recommit as many pages as possible.
|
|
558 |
while (chunk.Commit(0, chunkEnd) != KErrNone && !StopCacheThreads)
|
|
559 |
chunkEnd -= PageSize;
|
|
560 |
i = 0;
|
|
561 |
}
|
|
562 |
User::After(i/PageSize);
|
|
563 |
}
|
|
564 |
}
|
|
565 |
CLOSE_AND_WAIT(chunk);
|
|
566 |
return KErrNone;
|
|
567 |
}
|
|
568 |
|
|
569 |
|
|
570 |
TInt DirtyThreadFunc(TAny*)
|
|
571 |
{
|
|
572 |
RThread::Rendezvous(KErrNone);
|
|
573 |
|
|
574 |
RChunk chunk;
|
|
575 |
TChunkCreateInfo createInfo;
|
|
576 |
createInfo.SetNormal(PageSize * 100, PageSize *100);
|
|
577 |
createInfo.SetPaging(TChunkCreateInfo::EPaged);
|
|
578 |
TInt r = chunk.Create(createInfo);
|
|
579 |
if (r != KErrNone)
|
|
580 |
{
|
|
581 |
RDebug::Printf("Failed to create a cache chunk %d", r);
|
|
582 |
return r;
|
|
583 |
}
|
|
584 |
TUint8* base = chunk.Base();
|
|
585 |
// Dirty each page in the chunk so that there are dirty pages in the live
|
|
586 |
// list while it is being resized and pages are being unlocked.
|
|
587 |
while (!StopCacheThreads)
|
|
588 |
{
|
|
589 |
TUint8* p = base;
|
|
590 |
TUint8* pEnd = base + chunk.Size();
|
|
591 |
for (; p < pEnd && !StopCacheThreads; p += PageSize)
|
|
592 |
{
|
|
593 |
*p = (TUint8)(pEnd - p);
|
|
594 |
User::After((TUint8)(pEnd - p));
|
|
595 |
}
|
|
596 |
}
|
|
597 |
CLOSE_AND_WAIT(chunk);
|
|
598 |
return KErrNone;
|
|
599 |
}
|
|
600 |
|
|
601 |
|
|
602 |
void TestResizeExcess()
|
|
603 |
{
|
|
604 |
test.Printf(_L("Commit all of memory again leaving 100 free pages\n"));
|
|
605 |
CommitEnd = 0;
|
|
606 |
TInt r;
|
|
607 |
while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize)))
|
|
608 |
{
|
|
609 |
CommitEnd += PageSize;
|
|
610 |
}
|
|
611 |
test(r==KErrNoMemory);
|
|
612 |
test_KErrNone(TestChunk.Unlock(0, 100 * PageSize));
|
|
613 |
|
|
614 |
SVMCacheInfo info;
|
|
615 |
test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalGetCacheSize, &info, 0));
|
|
616 |
|
|
617 |
StopCacheThreads = EFalse;
|
|
618 |
RThread cacheThread;
|
|
619 |
r = cacheThread.Create( KNullDesC, CacheThreadFunc, KDefaultStackSize, PageSize,
|
|
620 |
PageSize, (TAny*)info.iMaxSize);
|
|
621 |
test_KErrNone(r);
|
|
622 |
TRequestStatus threadStarted;
|
|
623 |
cacheThread.Rendezvous(threadStarted);
|
|
624 |
TRequestStatus cacheStatus;
|
|
625 |
cacheThread.Logon(cacheStatus);
|
|
626 |
cacheThread.Resume();
|
|
627 |
User::WaitForRequest(threadStarted);
|
|
628 |
test_KErrNone(threadStarted.Int());
|
|
629 |
|
|
630 |
// Create the dirty thread before the donate thread as the donate thread may
|
|
631 |
// consume all the free ram periodically.
|
|
632 |
RThread dirtyThread;
|
|
633 |
r = dirtyThread.Create(KNullDesC, DirtyThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL);
|
|
634 |
test_KErrNone(r);
|
|
635 |
dirtyThread.Rendezvous(threadStarted);
|
|
636 |
TRequestStatus dirtyStatus;
|
|
637 |
dirtyThread.Logon(dirtyStatus);
|
|
638 |
dirtyThread.Resume();
|
|
639 |
User::WaitForRequest(threadStarted);
|
|
640 |
test_KErrNone(threadStarted.Int());
|
|
641 |
|
|
642 |
RThread donateThread;
|
|
643 |
r = donateThread.Create(KNullDesC, DonateThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL);
|
|
644 |
test_KErrNone(r);
|
|
645 |
donateThread.Rendezvous(threadStarted);
|
|
646 |
TRequestStatus donateStatus;
|
|
647 |
donateThread.Logon(donateStatus);
|
|
648 |
donateThread.Resume();
|
|
649 |
User::WaitForRequest(threadStarted);
|
|
650 |
test_KErrNone(threadStarted.Int());
|
|
651 |
|
|
652 |
// Run test for 10 secs.
|
|
653 |
User::After(10000000);
|
|
654 |
|
|
655 |
// End the test.
|
|
656 |
StopCacheThreads = ETrue;
|
|
657 |
User::WaitForRequest(donateStatus);
|
|
658 |
test_Equal(EExitKill, donateThread.ExitType());
|
|
659 |
test_KErrNone(donateThread.ExitReason());
|
|
660 |
User::WaitForRequest(dirtyStatus);
|
|
661 |
test_Equal(EExitKill, dirtyThread.ExitType());
|
|
662 |
test_KErrNone(dirtyThread.ExitReason());
|
|
663 |
User::WaitForRequest(cacheStatus);
|
|
664 |
test_Equal(EExitKill, cacheThread.ExitType());
|
|
665 |
test_KErrNone(cacheThread.ExitReason());
|
|
666 |
|
|
667 |
CLOSE_AND_WAIT(donateThread);
|
|
668 |
CLOSE_AND_WAIT(cacheThread);
|
|
669 |
CLOSE_AND_WAIT(dirtyThread);
|
|
670 |
|
|
671 |
test_KErrNone(UserSvr::HalFunction( EHalGroupVM,
|
|
672 |
EVMHalSetCacheSize,
|
|
673 |
(TAny*)info.iMinSize,
|
|
674 |
(TAny*)info.iMaxSize));
|
|
675 |
}
|
|
676 |
|
0
|
677 |
|
|
678 |
TInt E32Main()
|
|
679 |
{
|
|
680 |
test.Title();
|
|
681 |
|
|
682 |
if (!HaveVirtMem())
|
|
683 |
{
|
|
684 |
test.Printf(_L("This test requires an MMU\n"));
|
|
685 |
return KErrNone;
|
|
686 |
}
|
132
|
687 |
// See if were running on the Flexible Memory Model or newer.
|
|
688 |
TUint32 memModelAttrib = (TUint32)UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL);
|
|
689 |
gFmm = (memModelAttrib & EMemModelTypeMask) >= EMemModelTypeFlexible;
|
|
690 |
|
0
|
691 |
test.Start(_L("Initialise test"));
|
|
692 |
test.Next(_L("Load gobbler LDD"));
|
|
693 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
|
|
694 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
695 |
RGobbler gobbler;
|
|
696 |
r = gobbler.Open();
|
|
697 |
test(r==KErrNone);
|
|
698 |
TUint32 taken = gobbler.GobbleRAM(496*1024*1024);
|
|
699 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024);
|
|
700 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());
|
|
701 |
|
|
702 |
test_KErrNone(HAL::Get(HAL::EMemoryPageSize,PageSize));
|
|
703 |
TInt totalRAM;
|
|
704 |
test_KErrNone(HAL::Get(HAL::EMemoryRAM, totalRAM));
|
|
705 |
totalRAM -= taken;
|
|
706 |
test.Printf(_L("totalRAM=%dK\n"), totalRAM/1024);
|
|
707 |
|
|
708 |
test(KErrNone==MemoryTest.Open());
|
|
709 |
// Create the test chunk. It must not be paged otherwise
|
|
710 |
// unlocking its pages will have no effect.
|
|
711 |
TChunkCreateInfo createInfo;
|
|
712 |
createInfo.SetCache(totalRAM);
|
|
713 |
test_KErrNone(TestChunk.Create(createInfo));
|
|
714 |
TestChunkBase = TestChunk.Base();
|
|
715 |
|
|
716 |
test(KErrNone==Timer.CreateLocal());
|
|
717 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
|
|
718 |
|
|
719 |
test.Next(_L("Commit all of memory"));
|
|
720 |
CommitEnd = 0;
|
|
721 |
while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize)))
|
|
722 |
{
|
|
723 |
FillPage(CommitEnd);
|
|
724 |
CommitEnd += PageSize;
|
|
725 |
}
|
|
726 |
test(r==KErrNoMemory);
|
|
727 |
NoFreeRam = FreeRam();
|
|
728 |
test(NoFreeRam<=PageSize);
|
|
729 |
|
|
730 |
test.Next(_L("Check Unlocked page gets counted as free memory"));
|
|
731 |
r = TestChunk.Unlock(0,PageSize);
|
|
732 |
test_KErrNone(r);
|
|
733 |
TInt freeRam = FreeRam();
|
|
734 |
test(freeRam==NoFreeRam+PageSize);
|
|
735 |
r = TestChunk.Lock(0,PageSize);
|
|
736 |
test_KErrNone(r);
|
|
737 |
freeRam = FreeRam();
|
|
738 |
test(freeRam==NoFreeRam);
|
|
739 |
|
|
740 |
test.Next(_L("Check Unlock/Lock preserves page contents"));
|
|
741 |
TInt offset;
|
|
742 |
for(offset=0; offset<CommitEnd; offset+=PageSize)
|
|
743 |
{
|
|
744 |
test(CheckPage(offset));
|
|
745 |
r = TestChunk.Unlock(offset,PageSize);
|
|
746 |
test_KErrNone(r);
|
|
747 |
r = TestChunk.Lock(offset,PageSize);
|
|
748 |
test_KErrNone(r);
|
|
749 |
test(CheckPage(offset));
|
|
750 |
freeRam = FreeRam();
|
|
751 |
test(freeRam==NoFreeRam);
|
|
752 |
}
|
|
753 |
|
|
754 |
test.Next(_L("Tests at chunk offset '0'"));
|
|
755 |
Tests(0);
|
|
756 |
test.Next(_L("Tests at chunk offset 'PageSize'"));
|
|
757 |
Tests(PageSize);
|
|
758 |
test.Next(_L("Tests at chunk offset '0x100000-PageSize'"));
|
|
759 |
Tests(0x100000-PageSize);
|
|
760 |
test.Next(_L("Tests at chunk offset '0x400000-PageSize'"));
|
|
761 |
Tests(0x400000-PageSize);
|
|
762 |
|
|
763 |
// Remove limit on max size of live list
|
|
764 |
TUint originalMin = 0;
|
|
765 |
TUint originalMax = 0;
|
|
766 |
TUint currentSize = 0;
|
|
767 |
r = DPTest::CacheSize(originalMin, originalMax, currentSize);
|
|
768 |
test(r == KErrNone || r == KErrNotSupported);
|
|
769 |
TBool resizeCache = r == KErrNone;
|
|
770 |
if (resizeCache)
|
|
771 |
test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint));
|
|
772 |
|
|
773 |
test.Next(_L("Big Unlock/Lock"));
|
|
774 |
r = TestChunk.Unlock(0,CommitEnd);
|
|
775 |
test_KErrNone(r);
|
|
776 |
freeRam = FreeRam();
|
|
777 |
test(freeRam>=NoFreeRam+CommitEnd);
|
|
778 |
r = TestChunk.Lock(0,CommitEnd);
|
|
779 |
test_KErrNone(r);
|
|
780 |
freeRam = FreeRam();
|
|
781 |
test_Equal(NoFreeRam, freeRam);
|
|
782 |
|
|
783 |
if (resizeCache)
|
|
784 |
{
|
|
785 |
test.Next(_L("Check Unlock of old pages doesn't cause problems"));
|
|
786 |
TestUnlockOld();
|
|
787 |
}
|
|
788 |
|
|
789 |
test.Next(_L("Benchmarks..."));
|
|
790 |
TestBenchmarks();
|
|
791 |
|
|
792 |
test.Next(_L("Close chunk with unlocked pages which have been flushed"));
|
|
793 |
r = TestChunk.Unlock(0,CommitEnd);
|
|
794 |
test_KErrNone(r);
|
|
795 |
UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
|
|
796 |
TestChunk.Close();
|
|
797 |
|
|
798 |
test.Next(_L("Check can't lock/unlock non-cache chunks"));
|
|
799 |
RChunk chunk;
|
|
800 |
test_KErrNone(chunk.CreateDisconnectedLocal(0,PageSize,2*PageSize));
|
|
801 |
test_Equal(KErrGeneral,chunk.Lock(PageSize,PageSize));
|
|
802 |
test_Equal(KErrGeneral,chunk.Unlock(0,PageSize));
|
|
803 |
chunk.Close();
|
|
804 |
|
|
805 |
// Restore original settings for live list size
|
|
806 |
if (resizeCache)
|
|
807 |
test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax));
|
|
808 |
|
176
|
809 |
test_KErrNone(GetGlobalPolicies());
|
|
810 |
if (gDataPagingSupported)
|
|
811 |
{
|
|
812 |
test.Next(_L("Test interactions of chunk unlocking and page cache resizing"));
|
|
813 |
// Do this after the live list limit is restored.
|
|
814 |
test_KErrNone(TestChunk.Create(createInfo));
|
|
815 |
TestResizeExcess();
|
|
816 |
TestChunk.Close();
|
|
817 |
}
|
|
818 |
|
0
|
819 |
// end...
|
|
820 |
test.End();
|
|
821 |
MemoryTest.Close();
|
|
822 |
gobbler.Close();
|
|
823 |
test.Close();
|
|
824 |
|
|
825 |
return KErrNone;
|
|
826 |
}
|