author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 15 Jul 2010 20:11:42 +0300 | |
branch | RCL_3 |
changeset 248 | 0ffb4e86fcc9 |
parent 198 | 2bb754abd467 |
child 229 | 07a685bbdd3d |
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" |
|
198
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
90 |
#include "..\demandpaging\t_dpcmn.h" |
0 | 91 |
|
198
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
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; |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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")); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
// Get orignal page cache size |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
TUint minCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
TUint maxCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
TUint oldCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
TUint newCache = 0; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
{ |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
r = DPTest::CacheSize(minCache, maxCache, oldCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
} |
0 | 322 |
r = TestChunk.Unlock(aOffset,PageSize*4); |
323 |
test_KErrNone(r); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
TUint spareCache = maxCache - oldCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
if (gFmm && spareCache) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
{// 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
|
328 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
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
|
331 |
test_Equal(oldCache + extraCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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()); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
{// 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
|
342 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
test_Equal(oldCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
} |
0 | 346 |
// Restore chunk back to original state |
347 |
r = TestChunk.Commit(aOffset, PageSize*4); |
|
348 |
test_KErrNone(r); |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
||
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
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
|
382 |
// Get orignal page cache size |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
{ |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
r = DPTest::CacheSize(minCache, maxCache, oldCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
r = TestChunk.Unlock(aOffset,PageSize); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
r = TestChunk.Unlock(aOffset + PageSize*2, PageSize); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
spareCache = maxCache - oldCache; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
if (gFmm && spareCache) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
{// 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
|
396 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
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
|
399 |
test_Equal(oldCache + extraCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
test(FreeRam() >= NoFreeRam+PageSize*2); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
r=TestChunk.Decommit(aOffset, PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
freeRam = FreeRam(); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
test_Compare(freeRam, >=, NoFreeRam+PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
test_Equal(origChunkSize - PageSize*4, TestChunk.Size()); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
|
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
if (gFmm) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
{// 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
|
410 |
r = DPTest::CacheSize(minCache, maxCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
test_Equal(oldCache, newCache); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
// Restore chunk back to original state |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
r = TestChunk.Commit(aOffset, PageSize*4); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
test_KErrNone(r); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
test_Equal(NoFreeRam, FreeRam()); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
||
198
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
508 |
TBool StopCacheThreads; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
509 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
510 |
TInt CacheThreadFunc(TAny* aMax) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
511 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
512 |
RThread::Rendezvous(KErrNone); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
513 |
while (!StopCacheThreads) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
514 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
515 |
TInt maxSize = (TInt)aMax; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
516 |
TInt minSize; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
517 |
TInt r = KErrNone; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
518 |
for (minSize = PageSize << 4; r == KErrNone && !StopCacheThreads; minSize += PageSize) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
519 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
520 |
r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
521 |
User::After(minSize/PageSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
522 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
523 |
for (minSize -= PageSize; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
524 |
minSize > PageSize << 4 && r == KErrNone && !StopCacheThreads; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
525 |
minSize -= PageSize) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
526 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
527 |
r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
528 |
User::After(minSize/PageSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
529 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
530 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
531 |
return KErrNone; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
532 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
533 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
534 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
535 |
TInt DonateThreadFunc(TAny*) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
536 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
537 |
TChunkCreateInfo createInfo; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
538 |
createInfo.SetCache(100 * PageSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
539 |
RChunk chunk; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
540 |
TInt r = chunk.Create(createInfo); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
541 |
if (r != KErrNone) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
542 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
543 |
RDebug::Printf("DonateThreadFunc: Failed to create cache chunk %d", r); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
544 |
return r; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
545 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
546 |
TUint chunkEnd = 0; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
547 |
while (chunk.Commit(chunkEnd, PageSize) == KErrNone) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
548 |
chunkEnd += PageSize; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
549 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
550 |
RThread::Rendezvous(KErrNone); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
551 |
while (!StopCacheThreads) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
552 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
553 |
for (TUint i = PageSize; i <= chunkEnd && !StopCacheThreads; i += PageSize) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
554 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
555 |
chunk.Unlock(0, i); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
556 |
if (chunk.Lock(0, i) != KErrNone) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
557 |
{// Recommit as many pages as possible. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
558 |
while (chunk.Commit(0, chunkEnd) != KErrNone && !StopCacheThreads) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
559 |
chunkEnd -= PageSize; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
560 |
i = 0; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
561 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
562 |
User::After(i/PageSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
563 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
564 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
565 |
CLOSE_AND_WAIT(chunk); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
566 |
return KErrNone; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
567 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
568 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
569 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
570 |
TInt DirtyThreadFunc(TAny*) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
571 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
572 |
RThread::Rendezvous(KErrNone); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
573 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
574 |
RChunk chunk; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
575 |
TChunkCreateInfo createInfo; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
576 |
createInfo.SetNormal(PageSize * 100, PageSize *100); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
577 |
createInfo.SetPaging(TChunkCreateInfo::EPaged); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
578 |
TInt r = chunk.Create(createInfo); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
579 |
if (r != KErrNone) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
580 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
581 |
RDebug::Printf("Failed to create a cache chunk %d", r); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
582 |
return r; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
583 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
584 |
TUint8* base = chunk.Base(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
585 |
// Dirty each page in the chunk so that there are dirty pages in the live |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
586 |
// list while it is being resized and pages are being unlocked. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
587 |
while (!StopCacheThreads) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
588 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
589 |
TUint8* p = base; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
590 |
TUint8* pEnd = base + chunk.Size(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
591 |
for (; p < pEnd && !StopCacheThreads; p += PageSize) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
592 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
593 |
*p = (TUint8)(pEnd - p); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
594 |
User::After((TUint8)(pEnd - p)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
595 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
596 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
597 |
CLOSE_AND_WAIT(chunk); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
598 |
return KErrNone; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
599 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
600 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
601 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
602 |
void TestResizeExcess() |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
603 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
604 |
test.Printf(_L("Commit all of memory again leaving 100 free pages\n")); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
605 |
CommitEnd = 0; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
606 |
TInt r; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
607 |
while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize))) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
608 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
609 |
CommitEnd += PageSize; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
610 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
611 |
test(r==KErrNoMemory); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
612 |
test_KErrNone(TestChunk.Unlock(0, 100 * PageSize)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
613 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
614 |
SVMCacheInfo info; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
615 |
test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalGetCacheSize, &info, 0)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
616 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
617 |
StopCacheThreads = EFalse; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
618 |
RThread cacheThread; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
619 |
r = cacheThread.Create( KNullDesC, CacheThreadFunc, KDefaultStackSize, PageSize, |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
620 |
PageSize, (TAny*)info.iMaxSize); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
621 |
test_KErrNone(r); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
622 |
TRequestStatus threadStarted; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
623 |
cacheThread.Rendezvous(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
624 |
TRequestStatus cacheStatus; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
625 |
cacheThread.Logon(cacheStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
626 |
cacheThread.Resume(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
627 |
User::WaitForRequest(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
628 |
test_KErrNone(threadStarted.Int()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
629 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
630 |
// Create the dirty thread before the donate thread as the donate thread may |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
631 |
// consume all the free ram periodically. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
632 |
RThread dirtyThread; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
633 |
r = dirtyThread.Create(KNullDesC, DirtyThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
634 |
test_KErrNone(r); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
635 |
dirtyThread.Rendezvous(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
636 |
TRequestStatus dirtyStatus; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
637 |
dirtyThread.Logon(dirtyStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
638 |
dirtyThread.Resume(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
639 |
User::WaitForRequest(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
640 |
test_KErrNone(threadStarted.Int()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
641 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
642 |
RThread donateThread; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
643 |
r = donateThread.Create(KNullDesC, DonateThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
644 |
test_KErrNone(r); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
645 |
donateThread.Rendezvous(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
646 |
TRequestStatus donateStatus; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
647 |
donateThread.Logon(donateStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
648 |
donateThread.Resume(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
649 |
User::WaitForRequest(threadStarted); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
650 |
test_KErrNone(threadStarted.Int()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
651 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
652 |
// Run test for 10 secs. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
653 |
User::After(10000000); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
654 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
655 |
// End the test. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
656 |
StopCacheThreads = ETrue; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
657 |
User::WaitForRequest(donateStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
658 |
test_Equal(EExitKill, donateThread.ExitType()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
659 |
test_KErrNone(donateThread.ExitReason()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
660 |
User::WaitForRequest(dirtyStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
661 |
test_Equal(EExitKill, dirtyThread.ExitType()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
662 |
test_KErrNone(dirtyThread.ExitReason()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
663 |
User::WaitForRequest(cacheStatus); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
664 |
test_Equal(EExitKill, cacheThread.ExitType()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
665 |
test_KErrNone(cacheThread.ExitReason()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
666 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
667 |
CLOSE_AND_WAIT(donateThread); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
668 |
CLOSE_AND_WAIT(cacheThread); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
669 |
CLOSE_AND_WAIT(dirtyThread); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
670 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
671 |
test_KErrNone(UserSvr::HalFunction( EHalGroupVM, |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
672 |
EVMHalSetCacheSize, |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
673 |
(TAny*)info.iMinSize, |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
674 |
(TAny*)info.iMaxSize)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
675 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
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 |
} |
|
97
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
// 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
|
688 |
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
|
689 |
gFmm = (memModelAttrib & EMemModelTypeMask) >= EMemModelTypeFlexible; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
||
198
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
809 |
test_KErrNone(GetGlobalPolicies()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
810 |
if (gDataPagingSupported) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
811 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
812 |
test.Next(_L("Test interactions of chunk unlocking and page cache resizing")); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
813 |
// Do this after the live list limit is restored. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
814 |
test_KErrNone(TestChunk.Create(createInfo)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
815 |
TestResizeExcess(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
816 |
TestChunk.Close(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
817 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
97
diff
changeset
|
818 |
|
0 | 819 |
// end... |
820 |
test.End(); |
|
821 |
MemoryTest.Close(); |
|
822 |
gobbler.Close(); |
|
823 |
test.Close(); |
|
824 |
||
825 |
return KErrNone; |
|
826 |
} |