author | hgs |
Tue, 26 Oct 2010 12:49:20 +0100 | |
changeset 297 | b2826f67641f |
parent 176 | af6ec97d9189 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-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_ramall.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#define __E32TEST_EXTENSION__ |
|
19 |
||
20 |
#include <e32test.h> |
|
21 |
#include <e32uid.h> |
|
176 | 22 |
#include <hal.h> |
0 | 23 |
#include <e32hal.h> |
132 | 24 |
#include <dptest.h> |
0 | 25 |
#include "d_shadow.h" |
26 |
#include "mmudetect.h" |
|
27 |
#include "freeram.h" |
|
176 | 28 |
#include "d_gobble.h" |
0 | 29 |
|
30 |
LOCAL_D RTest test(_L("T_RAMALL")); |
|
31 |
||
32 |
_LIT(KLddFileName,"D_SHADOW.LDD"); |
|
33 |
||
34 |
TInt PageSize; |
|
35 |
TInt PageShift; |
|
36 |
RShadow Shadow; |
|
176 | 37 |
TInt TotalRam; |
132 | 38 |
RChunk Chunk; |
39 |
TUint ChunkCommitEnd; |
|
40 |
RThread TouchThread; |
|
41 |
TRequestStatus TouchStatus; |
|
42 |
TBool TouchDataStop; |
|
43 |
RThread FragThread; |
|
44 |
TRequestStatus FragStatus; |
|
45 |
TBool FragThreadStop; |
|
46 |
TBool ManualTest; |
|
47 |
TBool CacheSizeAdjustable; |
|
48 |
TUint OrigMinCacheSize; |
|
49 |
TUint OrigMaxCacheSize; |
|
0 | 50 |
|
176 | 51 |
// |
52 |
// Random number generation |
|
53 |
// |
|
54 |
||
55 |
TUint32 RandomSeed; |
|
56 |
||
57 |
TUint32 Random() |
|
58 |
{ |
|
59 |
RandomSeed = RandomSeed*69069+1; |
|
60 |
return RandomSeed; |
|
61 |
} |
|
62 |
||
63 |
TUint32 Random(TUint32 aRange) |
|
64 |
{ |
|
65 |
return (TUint32)((TUint64(Random())*TUint64(aRange))>>32); |
|
66 |
} |
|
67 |
||
68 |
void RandomInit(TUint32 aSeed) |
|
69 |
{ |
|
70 |
RandomSeed = aSeed+(aSeed<<8)+(aSeed<<16)+(aSeed<<24); |
|
71 |
Random(); |
|
72 |
Random(); |
|
73 |
} |
|
74 |
||
0 | 75 |
TInt AllocPhysicalRam(TUint32& aAddr, TInt aSize, TInt aAlign) |
76 |
{ |
|
77 |
return Shadow.AllocPhysicalRam(aAddr,aSize,aAlign); |
|
78 |
} |
|
79 |
||
80 |
TInt FreePhysicalRam(TUint32 aAddr, TInt aSize) |
|
81 |
{ |
|
82 |
return Shadow.FreePhysicalRam(aAddr,aSize); |
|
83 |
} |
|
84 |
||
85 |
TInt ClaimPhysicalRam(TUint32 aAddr, TInt aSize) |
|
86 |
{ |
|
87 |
return Shadow.ClaimPhysicalRam(aAddr,aSize); |
|
88 |
} |
|
89 |
||
90 |
void TestAlignedAllocs() |
|
91 |
{ |
|
92 |
TInt align; |
|
93 |
TInt size; |
|
94 |
for (align=PageShift; align<=20; ++align) |
|
95 |
{ |
|
96 |
for (size=PageSize; size<=0x100000; size+=PageSize) |
|
97 |
{ |
|
98 |
TInt free=FreeRam(); |
|
99 |
TUint32 pa=0; |
|
100 |
TInt r=AllocPhysicalRam(pa,size,align); |
|
101 |
test.Printf(_L("Size %08x Align %d r=%d pa=%08x\n"),size,align,r,pa); |
|
102 |
if (r==KErrNone) |
|
103 |
{ |
|
104 |
TUint32 as=1u<<align; |
|
105 |
TUint32 am=as-1; |
|
106 |
test(FreeRam()==free-size); |
|
107 |
test((pa&am)==0); |
|
108 |
r=FreePhysicalRam(pa,size); |
|
109 |
test(r==KErrNone); |
|
110 |
} |
|
111 |
test(FreeRam()==free); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
void TestClaimPhys() |
|
117 |
{ |
|
118 |
TInt free=FreeRam(); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
|
0 | 120 |
TUint32 pa=0; |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
TInt r=AllocPhysicalRam(pa,4*PageSize,0); |
0 | 122 |
test(r==KErrNone); |
123 |
test(FreeRam()==free-4*PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
|
0 | 125 |
r=FreePhysicalRam(pa,4*PageSize); |
126 |
test(r==KErrNone); |
|
127 |
test(FreeRam()==free); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
r=ClaimPhysicalRam(pa,4*PageSize); |
0 | 130 |
test(r==KErrNone); |
131 |
test(FreeRam()==free-4*PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
|
0 | 133 |
r=FreePhysicalRam(pa,3*PageSize); |
134 |
test(r==KErrNone); |
|
135 |
test(FreeRam()==free-PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
|
0 | 137 |
r=ClaimPhysicalRam(pa,4*PageSize); |
138 |
test(r==KErrInUse); |
|
139 |
test(FreeRam()==free-PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
#ifdef MANUAL_PANIC_TEST |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
//This section of the test should be run as a manual test as it results in |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
// a panic due to attempting to Free an unclaimed page |
0 | 144 |
if (HaveVirtMem()) |
145 |
{ |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
test.Printf(_L("HaveVirtMem() \n")); |
0 | 147 |
r=FreePhysicalRam(pa,4*PageSize); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
test.Printf(_L("FreePhysicalRam() \n")); |
0 | 149 |
test(r==KErrGeneral); |
150 |
test(FreeRam()==free-PageSize); |
|
151 |
} |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
#endif |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
|
0 | 154 |
r=FreePhysicalRam(pa+3*PageSize,PageSize); |
155 |
test(r==KErrNone); |
|
156 |
test(FreeRam()==free); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
|
0 | 158 |
} |
159 |
||
132 | 160 |
|
161 |
struct SPhysAllocData |
|
162 |
{ |
|
163 |
TUint iSize; |
|
164 |
TUint iAlign; |
|
165 |
TBool iCheckMaxAllocs; |
|
166 |
TBool iCheckFreeRam; |
|
167 |
}; |
|
168 |
||
169 |
||
170 |
TInt FillPhysicalRam(TAny* aArgs) |
|
171 |
{ |
|
176 | 172 |
SPhysAllocData allocData = *((SPhysAllocData*)aArgs); |
132 | 173 |
TUint maxAllocs = FreeRam() / allocData.iSize; |
174 |
TUint32* physAddrs = new TUint32[maxAllocs + 1]; |
|
175 |
if (!physAddrs) |
|
176 |
return KErrNoMemory; |
|
177 |
TUint32* pa = physAddrs; |
|
178 |
TUint32 alignMask = (1 << allocData.iAlign) - 1; |
|
179 |
TUint initialFreeRam = FreeRam(); |
|
180 |
TInt r = KErrNone; |
|
181 |
TUint allocations = 0; |
|
182 |
for(; allocations <= maxAllocs; ++allocations) |
|
183 |
{ |
|
184 |
TUint freeRam = FreeRam(); |
|
185 |
r = AllocPhysicalRam(*pa, allocData.iSize, allocData.iAlign); |
|
186 |
if (r != KErrNone) |
|
187 |
break; |
|
188 |
if (*pa++ & alignMask) |
|
189 |
{ |
|
190 |
r = KErrGeneral; |
|
191 |
RDebug::Printf("Error alignment phys addr 0x%08x", *(pa - 1)); |
|
192 |
break; |
|
193 |
} |
|
176 | 194 |
TUint newFreeRam = FreeRam(); |
195 |
if (allocData.iCheckFreeRam && freeRam - allocData.iSize != newFreeRam) |
|
132 | 196 |
{ |
197 |
r = KErrGeneral; |
|
176 | 198 |
RDebug::Printf("Error in free ram 0x%08x orig 0x%08x", newFreeRam, freeRam); |
132 | 199 |
break; |
200 |
} |
|
201 |
} |
|
202 |
||
203 |
TUint32* physEnd = pa; |
|
204 |
TBool failFrees = EFalse; |
|
205 |
for (pa = physAddrs; pa < physEnd; pa++) |
|
206 |
{ |
|
207 |
if (FreePhysicalRam(*pa, allocData.iSize) != KErrNone) |
|
208 |
failFrees = ETrue; |
|
209 |
} |
|
210 |
if (failFrees) |
|
211 |
r = KErrNotFound; |
|
212 |
if (allocData.iCheckMaxAllocs && allocations > maxAllocs) |
|
213 |
{ |
|
214 |
r = KErrOverflow; |
|
215 |
RDebug::Printf("Error able to allocate too many pages"); |
|
216 |
} |
|
176 | 217 |
TUint finalFreeRam = FreeRam(); |
218 |
if (allocData.iCheckFreeRam && initialFreeRam != finalFreeRam) |
|
132 | 219 |
{ |
220 |
r = KErrGeneral; |
|
176 | 221 |
RDebug::Printf("Error in free ram 0x%08x initial 0x%08x", finalFreeRam, initialFreeRam); |
132 | 222 |
} |
223 |
delete[] physAddrs; |
|
224 |
if (r != KErrNone && r != KErrNoMemory) |
|
225 |
return r; |
|
226 |
TUint possibleAllocs = initialFreeRam / allocData.iSize; |
|
227 |
if (allocData.iCheckMaxAllocs && possibleAllocs != allocations) |
|
228 |
{ |
|
229 |
RDebug::Printf("Error in number of allocations possibleAllocs %d allocations %d", possibleAllocs, allocations); |
|
230 |
return KErrGeneral; |
|
231 |
} |
|
232 |
return allocations; |
|
233 |
} |
|
234 |
||
235 |
||
236 |
void TestMultipleContiguousAllocations(TUint aNumThreads, TUint aSize, TUint aAlign) |
|
237 |
{ |
|
238 |
test.Printf(_L("TestMultiContig threads %d size 0x%x, align %d\n"), aNumThreads, aSize, aAlign); |
|
239 |
SPhysAllocData allocData; |
|
240 |
allocData.iSize = aSize; |
|
241 |
allocData.iAlign = aAlign; |
|
242 |
allocData.iCheckMaxAllocs = EFalse; |
|
243 |
allocData.iCheckFreeRam = EFalse; |
|
244 |
// Start several threads all contiguous allocating memory. |
|
245 |
RThread* threads = new RThread[aNumThreads]; |
|
246 |
TRequestStatus* status = new TRequestStatus[aNumThreads]; |
|
247 |
TUint i = 0; |
|
248 |
for (; i < aNumThreads; i++) |
|
249 |
{// Need enough heap to store addr of every possible allocation + 1. |
|
176 | 250 |
TUint requiredHeapMax = Max(PageSize, ((TotalRam / aSize) * sizeof(TUint32)) + sizeof(TUint32)); |
132 | 251 |
TInt r = threads[i].Create(KNullDesC, FillPhysicalRam, KDefaultStackSize, PageSize, requiredHeapMax, (TAny*)&allocData); |
176 | 252 |
if (r != KErrNone) |
253 |
break; |
|
132 | 254 |
threads[i].Logon(status[i]); |
255 |
} |
|
176 | 256 |
TUint totalThreads = i; |
257 |
for (i = 0; i < totalThreads; i++) |
|
132 | 258 |
{ |
259 |
threads[i].Resume(); |
|
260 |
} |
|
176 | 261 |
for (i = 0; i < totalThreads; i++) |
132 | 262 |
{ |
263 |
User::WaitForRequest(status[i]); |
|
264 |
test_Equal(EExitKill, threads[i].ExitType()); |
|
265 |
TInt exitReason = threads[i].ExitReason(); |
|
266 |
test_Value(exitReason, exitReason >= 0 || exitReason == KErrNoMemory); |
|
267 |
threads[i].Close(); |
|
268 |
} |
|
269 |
delete[] status; |
|
270 |
delete[] threads; |
|
271 |
} |
|
272 |
||
273 |
struct STouchData |
|
274 |
{ |
|
275 |
TUint iSize; |
|
276 |
TUint iFrequency; |
|
277 |
}TouchData; |
|
278 |
||
279 |
||
280 |
TInt TouchMemory(TAny*) |
|
281 |
{ |
|
176 | 282 |
RThread::Rendezvous(KErrNone); // Signal that this thread has started running. |
283 |
RandomInit(TouchData.iSize); |
|
132 | 284 |
while (!TouchDataStop) |
285 |
{ |
|
286 |
TUint8* p = Chunk.Base(); |
|
287 |
TUint8* pEnd = p + ChunkCommitEnd; |
|
288 |
TUint8* fragPEnd = p + TouchData.iFrequency; |
|
176 | 289 |
for (TUint8* fragP = p + TouchData.iSize; fragPEnd < pEnd && !TouchDataStop;) |
132 | 290 |
{ |
291 |
TUint8* data = fragP; |
|
176 | 292 |
for (; data < fragPEnd && !TouchDataStop; data += PageSize) |
132 | 293 |
{ |
294 |
*data = (TUint8)(data - fragP); |
|
176 | 295 |
TUint random = Random(); |
296 |
if (random & 0x8484) |
|
297 |
User::After(random & 0xFFFF); |
|
132 | 298 |
} |
176 | 299 |
for (data = fragP; data < fragPEnd && !TouchDataStop; data += PageSize) |
132 | 300 |
{ |
301 |
if (*data != (TUint8)(data - fragP)) |
|
302 |
{ |
|
303 |
RDebug::Printf("Error unexpected data 0x%x read from 0x%08x", *data, data); |
|
304 |
return KErrGeneral; |
|
305 |
} |
|
176 | 306 |
TUint random = Random(); |
307 |
if (random & 0x8484) |
|
308 |
User::After(random & 0xFFFF); |
|
132 | 309 |
} |
310 |
fragP = fragPEnd + TouchData.iSize; |
|
311 |
fragPEnd += TouchData.iFrequency; |
|
312 |
} |
|
313 |
} |
|
314 |
return KErrNone; |
|
315 |
} |
|
316 |
||
317 |
struct SFragData |
|
318 |
{ |
|
319 |
TUint iSize; |
|
320 |
TUint iFrequency; |
|
321 |
TUint iDiscard; |
|
322 |
TBool iFragThread; |
|
323 |
}FragData; |
|
324 |
||
325 |
void FragmentMemoryFunc() |
|
326 |
{ |
|
327 |
ChunkCommitEnd = 0; |
|
328 |
TInt r; |
|
329 |
while(KErrNone == (r = Chunk.Commit(ChunkCommitEnd,PageSize)) && !FragThreadStop) |
|
330 |
{ |
|
331 |
ChunkCommitEnd += PageSize; |
|
332 |
} |
|
333 |
if (FragThreadStop) |
|
334 |
return; |
|
335 |
test_Equal(KErrNoMemory, r); |
|
336 |
TUint freeBlocks = 0; |
|
337 |
for ( TUint offset = 0; |
|
338 |
(offset + FragData.iSize) < ChunkCommitEnd; |
|
339 |
offset += FragData.iFrequency, freeBlocks++) |
|
340 |
{ |
|
341 |
test_KErrNone(Chunk.Decommit(offset, FragData.iSize)); |
|
342 |
} |
|
343 |
||
344 |
if (FragData.iDiscard && CacheSizeAdjustable && !FragThreadStop) |
|
345 |
{ |
|
346 |
TUint minCacheSize = FreeRam(); |
|
347 |
TUint maxCacheSize = minCacheSize; |
|
176 | 348 |
DPTest::SetCacheSize(minCacheSize, maxCacheSize); |
349 |
if (OrigMinCacheSize <= maxCacheSize) |
|
350 |
DPTest::SetCacheSize(OrigMinCacheSize, maxCacheSize); |
|
132 | 351 |
} |
352 |
} |
|
353 |
||
354 |
||
355 |
void UnfragmentMemoryFunc() |
|
356 |
{ |
|
357 |
if (FragData.iDiscard && CacheSizeAdjustable) |
|
176 | 358 |
DPTest::SetCacheSize(OrigMinCacheSize, OrigMaxCacheSize); |
132 | 359 |
Chunk.Decommit(0, Chunk.MaxSize()); |
360 |
} |
|
361 |
||
362 |
||
363 |
TInt FragmentMemoryThreadFunc(TAny*) |
|
364 |
{ |
|
176 | 365 |
RThread::Rendezvous(KErrNone); // Signal that this thread has started running. |
132 | 366 |
while (!FragThreadStop) |
367 |
{ |
|
368 |
FragmentMemoryFunc(); |
|
369 |
UnfragmentMemoryFunc(); |
|
370 |
} |
|
371 |
return KErrNone; |
|
372 |
} |
|
373 |
||
374 |
||
375 |
void FragmentMemory(TUint aSize, TUint aFrequency, TBool aDiscard, TBool aTouchMemory, TBool aFragThread) |
|
376 |
{ |
|
377 |
test_Value(aTouchMemory, !aTouchMemory || !aFragThread); |
|
378 |
test_Value(aSize, aSize < aFrequency); |
|
379 |
FragData.iSize = aSize; |
|
380 |
FragData.iFrequency = aFrequency; |
|
381 |
FragData.iDiscard = aDiscard; |
|
382 |
FragData.iFragThread = aFragThread; |
|
383 |
||
384 |
TChunkCreateInfo chunkInfo; |
|
176 | 385 |
chunkInfo.SetDisconnected(0, 0, TotalRam); |
132 | 386 |
chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged); |
176 | 387 |
chunkInfo.SetClearByte(0x19); |
132 | 388 |
test_KErrNone(Chunk.Create(chunkInfo)); |
389 |
||
390 |
if (aFragThread) |
|
391 |
{ |
|
176 | 392 |
TInt r = FragThread.Create(_L("FragThread"), FragmentMemoryThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL); |
132 | 393 |
test_KErrNone(r); |
394 |
FragThread.Logon(FragStatus); |
|
395 |
FragThreadStop = EFalse; |
|
176 | 396 |
TRequestStatus threadInitialised; |
397 |
FragThread.Rendezvous(threadInitialised); |
|
132 | 398 |
FragThread.Resume(); |
176 | 399 |
User::WaitForRequest(threadInitialised); |
400 |
test_KErrNone(threadInitialised.Int()); |
|
132 | 401 |
} |
402 |
else |
|
403 |
{ |
|
404 |
FragmentMemoryFunc(); |
|
405 |
} |
|
406 |
if (aTouchMemory && !ManualTest) |
|
407 |
{ |
|
408 |
TouchData.iSize = aSize; |
|
409 |
TouchData.iFrequency = aFrequency; |
|
176 | 410 |
TInt r = TouchThread.Create(_L("TouchThread"), TouchMemory, KDefaultStackSize, PageSize, PageSize, NULL); |
132 | 411 |
test_KErrNone(r); |
412 |
TouchThread.Logon(TouchStatus); |
|
413 |
TouchDataStop = EFalse; |
|
176 | 414 |
TRequestStatus threadInitialised; |
415 |
TouchThread.Rendezvous(threadInitialised); |
|
132 | 416 |
TouchThread.Resume(); |
176 | 417 |
User::WaitForRequest(threadInitialised); |
418 |
test_KErrNone(threadInitialised.Int()); |
|
132 | 419 |
} |
420 |
} |
|
421 |
||
422 |
||
423 |
void UnfragmentMemory(TBool aDiscard, TBool aTouchMemory, TBool aFragThread) |
|
424 |
{ |
|
425 |
test_Value(aTouchMemory, !aTouchMemory || !aFragThread); |
|
426 |
if (aTouchMemory && !ManualTest) |
|
427 |
{ |
|
428 |
TouchDataStop = ETrue; |
|
429 |
User::WaitForRequest(TouchStatus); |
|
430 |
test_Equal(EExitKill, TouchThread.ExitType()); |
|
431 |
test_KErrNone(TouchThread.ExitReason()); |
|
432 |
CLOSE_AND_WAIT(TouchThread); |
|
433 |
} |
|
434 |
if (aFragThread) |
|
435 |
{ |
|
436 |
FragThreadStop = ETrue; |
|
437 |
User::WaitForRequest(FragStatus); |
|
438 |
test_Equal(EExitKill, FragThread.ExitType()); |
|
439 |
test_KErrNone(FragThread.ExitReason()); |
|
440 |
CLOSE_AND_WAIT(FragThread); |
|
441 |
} |
|
442 |
else |
|
443 |
UnfragmentMemoryFunc(); |
|
176 | 444 |
if (CacheSizeAdjustable) |
445 |
test_KErrNone(DPTest::SetCacheSize(OrigMinCacheSize, OrigMaxCacheSize)); |
|
132 | 446 |
CLOSE_AND_WAIT(Chunk); |
447 |
} |
|
448 |
||
449 |
||
450 |
void TestFillPhysicalRam(TUint aFragSize, TUint aFragFreq, TUint aAllocSize, TUint aAllocAlign, TBool aDiscard, TBool aTouchMemory) |
|
451 |
{ |
|
452 |
test.Printf(_L("TestFillPhysicalRam aFragSize 0x%x aFragFreq 0x%x aAllocSize 0x%x aAllocAlign %d dis %d touch %d\n"), |
|
453 |
aFragSize, aFragFreq, aAllocSize, aAllocAlign, aDiscard, aTouchMemory); |
|
454 |
FragmentMemory(aFragSize, aFragFreq, aDiscard, aTouchMemory, EFalse); |
|
455 |
SPhysAllocData allocData; |
|
456 |
// Only check free all ram could be allocated in manual tests as fixed pages may be fragmented. |
|
176 | 457 |
allocData.iCheckMaxAllocs = (ManualTest && !aTouchMemory && !aAllocAlign); |
132 | 458 |
allocData.iCheckFreeRam = ETrue; |
459 |
allocData.iSize = aAllocSize; |
|
460 |
allocData.iAlign = aAllocAlign; |
|
176 | 461 |
TInt r = FillPhysicalRam(&allocData); |
462 |
test_Value(r, r >= 0); |
|
132 | 463 |
UnfragmentMemory(aDiscard, aTouchMemory, EFalse); |
464 |
} |
|
465 |
||
466 |
||
467 |
void TestFragmentedAllocation() |
|
468 |
{ |
|
469 |
// Test every other page free. |
|
470 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize, 0, EFalse, EFalse); |
|
471 |
if (ManualTest) |
|
472 |
{ |
|
473 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize * 2, 0, EFalse, EFalse); |
|
474 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize, 0, EFalse, ETrue); |
|
475 |
} |
|
476 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize * 2, 0, EFalse, ETrue); |
|
477 |
// Test every 2 pages free. |
|
478 |
TestFillPhysicalRam(PageSize * 2, PageSize * 4, PageSize * 8, 0, EFalse, EFalse); |
|
479 |
if (ManualTest) |
|
480 |
TestFillPhysicalRam(PageSize * 2, PageSize * 4, PageSize * 8, 0, EFalse, ETrue); |
|
481 |
// Test 10 pages free then 20 pages allocated, allocate 256 pages (1MB in most cases). |
|
482 |
if (ManualTest) |
|
483 |
TestFillPhysicalRam(PageSize * 10, PageSize * 30, PageSize * 256, 0, EFalse, EFalse); |
|
484 |
TestFillPhysicalRam(PageSize * 10, PageSize * 30, PageSize * 256, 0, EFalse, ETrue); |
|
485 |
||
486 |
if (CacheSizeAdjustable) |
|
487 |
{// It is possible to adjust the cache size so test phyiscally contiguous |
|
488 |
// allocations discard and move pages when required. |
|
489 |
test.Next(_L("TestFragmentedAllocations with discardable data no true free memory")); |
|
490 |
// Test every other page free. |
|
491 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize, 0, ETrue, EFalse); |
|
492 |
if (ManualTest) |
|
493 |
{ |
|
494 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize, 0, ETrue, ETrue); |
|
495 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize * 2, 0, ETrue, EFalse); |
|
496 |
} |
|
497 |
TestFillPhysicalRam(PageSize, PageSize * 2, PageSize * 2, 0, ETrue, ETrue); |
|
498 |
// Test every 2 pages free. |
|
499 |
TestFillPhysicalRam(PageSize * 2, PageSize * 4, PageSize * 8, 0, ETrue, EFalse); |
|
500 |
if (ManualTest) |
|
501 |
TestFillPhysicalRam(PageSize * 2, PageSize * 4, PageSize * 8, 0, ETrue, ETrue); |
|
502 |
// Test 10 pages free then 20 pages allocated, allocate 256 pages (1MB in most cases). |
|
503 |
if (ManualTest) |
|
504 |
TestFillPhysicalRam(PageSize * 10, PageSize * 30, PageSize * 256, 0, ETrue, EFalse); |
|
505 |
TestFillPhysicalRam(PageSize * 10, PageSize * 30, PageSize * 256, 0, ETrue, ETrue); |
|
506 |
} |
|
507 |
} |
|
508 |
||
509 |
||
0 | 510 |
GLDEF_C TInt E32Main() |
511 |
// |
|
512 |
// Test RAM allocation |
|
513 |
// |
|
514 |
{ |
|
515 |
test.Title(); |
|
516 |
test.Start(_L("Load test LDD")); |
|
517 |
TInt r=User::LoadLogicalDevice(KLddFileName); |
|
518 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
519 |
||
520 |
r=UserHal::PageSizeInBytes(PageSize); |
|
521 |
test(r==KErrNone); |
|
522 |
||
523 |
TInt psz=PageSize; |
|
524 |
PageShift=-1; |
|
525 |
for (; psz; psz>>=1, ++PageShift); |
|
526 |
||
132 | 527 |
TUint currentCacheSize; |
528 |
CacheSizeAdjustable = DPTest::CacheSize(OrigMinCacheSize, OrigMaxCacheSize, currentCacheSize) == KErrNone; |
|
529 |
||
530 |
TUint memodel = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL) & EMemModelTypeMask; |
|
531 |
||
532 |
TInt cmdLineLen = User::CommandLineLength(); |
|
533 |
if(cmdLineLen) |
|
534 |
{ |
|
535 |
_LIT(KManual, "manual"); |
|
536 |
RBuf cmdLine; |
|
537 |
test_KErrNone(cmdLine.Create(cmdLineLen)); |
|
538 |
User::CommandLine(cmdLine); |
|
539 |
cmdLine.LowerCase(); |
|
540 |
ManualTest = cmdLine.Find(KManual) != KErrNotFound; |
|
541 |
} |
|
542 |
||
176 | 543 |
// Turn off lazy dll unloading and ensure any supervisor clean up has completed |
544 |
// so the free ram checking isn't affected. |
|
132 | 545 |
RLoader l; |
546 |
test(l.Connect()==KErrNone); |
|
547 |
test(l.CancelLazyDllUnload()==KErrNone); |
|
548 |
l.Close(); |
|
176 | 549 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
132 | 550 |
|
176 | 551 |
test_KErrNone(HAL::Get(HAL::EMemoryRAM, TotalRam)); |
552 |
||
553 |
test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),FreeRam(),PageSize,PageShift); |
|
0 | 554 |
|
555 |
test.Next(_L("Open test LDD")); |
|
556 |
r=Shadow.Open(); |
|
557 |
test(r==KErrNone); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
test.Next(_L("TestAlignedAllocs")); |
0 | 560 |
TestAlignedAllocs(); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
test.Next(_L("TestClaimPhys")); |
0 | 563 |
TestClaimPhys(); |
564 |
||
132 | 565 |
if (memodel >= EMemModelTypeFlexible) |
566 |
{ |
|
176 | 567 |
// To stop these tests taking too long leave only 8MB of RAM free. |
568 |
const TUint KFreePages = 2048; |
|
569 |
test.Next(_L("Load gobbler LDD")); |
|
570 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName); |
|
571 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
|
572 |
RGobbler gobbler; |
|
573 |
r = gobbler.Open(); |
|
574 |
test_KErrNone(r); |
|
575 |
TUint32 taken = gobbler.GobbleRAM(KFreePages * PageSize); |
|
576 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024); |
|
577 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam()); |
|
578 |
||
132 | 579 |
test.Next(_L("TestFragmentedAllocation")); |
580 |
TestFragmentedAllocation(); |
|
581 |
||
582 |
test.Next(_L("TestMultipleContiguousAllocations")); |
|
583 |
TestMultipleContiguousAllocations(20, PageSize * 16, 0); |
|
584 |
TestMultipleContiguousAllocations(20, PageSize * 16, PageShift + 1); |
|
585 |
TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2); |
|
586 |
||
587 |
FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, EFalse); |
|
588 |
TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2); |
|
589 |
UnfragmentMemory(EFalse, EFalse, EFalse); |
|
590 |
||
591 |
test.Next(_L("TestMultipleContiguousAllocations while accessing memory")); |
|
592 |
FragmentMemory(PageSize, PageSize * 2, EFalse, ETrue, EFalse); |
|
593 |
TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2); |
|
594 |
UnfragmentMemory(EFalse, ETrue, EFalse); |
|
595 |
FragmentMemory(PageSize, PageSize * 2, ETrue, ETrue, EFalse); |
|
596 |
TestMultipleContiguousAllocations(50, PageSize * 256, PageShift + 5); |
|
597 |
UnfragmentMemory(ETrue, ETrue, EFalse); |
|
598 |
FragmentMemory(PageSize * 16, PageSize * 32, ETrue, ETrue, EFalse); |
|
599 |
TestMultipleContiguousAllocations(10, PageSize * 512, PageShift + 8); |
|
600 |
UnfragmentMemory(ETrue, ETrue, EFalse); |
|
601 |
FragmentMemory(PageSize * 32, PageSize * 64, ETrue, ETrue, EFalse); |
|
602 |
TestMultipleContiguousAllocations(10, PageSize * 1024, PageShift + 10); |
|
603 |
UnfragmentMemory(ETrue, ETrue, EFalse); |
|
604 |
||
605 |
test.Next(_L("TestMultipleContiguousAllocations with repeated movable and discardable allocations")); |
|
606 |
FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, ETrue); |
|
607 |
TestMultipleContiguousAllocations(20, PageSize * 2, PageShift); |
|
608 |
UnfragmentMemory(EFalse, EFalse, ETrue); |
|
609 |
FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, ETrue); |
|
610 |
TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2); |
|
611 |
UnfragmentMemory(EFalse, EFalse, ETrue); |
|
612 |
FragmentMemory(PageSize, PageSize * 2, ETrue, EFalse, ETrue); |
|
613 |
TestMultipleContiguousAllocations(50, PageSize * 256, PageShift + 5); |
|
614 |
UnfragmentMemory(ETrue, EFalse, ETrue); |
|
615 |
FragmentMemory(PageSize * 16, PageSize * 32, ETrue, EFalse, ETrue); |
|
616 |
TestMultipleContiguousAllocations(20, PageSize * 512, PageShift + 8); |
|
617 |
UnfragmentMemory(ETrue, EFalse, ETrue); |
|
618 |
FragmentMemory(PageSize * 32, PageSize * 64, ETrue, EFalse, ETrue); |
|
619 |
TestMultipleContiguousAllocations(20, PageSize * 1024, PageShift + 10); |
|
620 |
UnfragmentMemory(ETrue, EFalse, ETrue); |
|
176 | 621 |
|
622 |
gobbler.Close(); |
|
623 |
r = User::FreeLogicalDevice(KGobblerLddFileName); |
|
624 |
test_KErrNone(r); |
|
132 | 625 |
} |
626 |
||
0 | 627 |
Shadow.Close(); |
176 | 628 |
r = User::FreeLogicalDevice(KLddFileName); |
629 |
test_KErrNone(r); |
|
132 | 630 |
test.Printf(_L("Free RAM=%08x at end of test\n"),FreeRam()); |
0 | 631 |
test.End(); |
632 |
return(KErrNone); |
|
633 |
} |