author | Mike Kinghan <mikek@symbian.org> |
Wed, 21 Jul 2010 12:04:49 +0100 | |
branch | GCC_SURGE |
changeset 215 | 8096a832df02 |
parent 102 | ef2a444a7410 |
child 152 | 657f875b013e |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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\defrag\t_ramdefrag.cpp |
|
15 |
// RAM Defragmentation Functional Tests |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
//#define RUN_ALL_TESTS // Uncomment to ensure that all tests are run regardless of test failures |
|
20 |
//#define DEBUG_VER // Uncomment for information output from tests |
|
21 |
||
22 |
||
23 |
||
24 |
#define __E32TEST_EXTENSION__ |
|
25 |
#include <e32test.h> |
|
26 |
RTest test(_L("T_RAMDEFRAG")); |
|
27 |
#include <e32rom.h> |
|
28 |
#include <u32hal.h> |
|
29 |
#include <f32file.h> |
|
30 |
#include <f32dbg.h> |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
#include <e32svr.h> |
0 | 32 |
#include <e32msgqueue.h> |
33 |
#include <e32math.h> |
|
34 |
#include <hal.h> |
|
35 |
#include "testdefs.h" |
|
36 |
||
37 |
||
38 |
#include <dptest.h> |
|
39 |
||
40 |
#include "t_ramdefrag.h" |
|
41 |
||
42 |
#define READ(a) ReadByte((volatile TUint8*)(a)) |
|
43 |
||
44 |
||
45 |
#ifdef RUN_ALL_TESTS |
|
46 |
#define TEST_FAIL {gTestStepFailed++;} |
|
47 |
#define CLEANUP(a) {} |
|
48 |
#else |
|
49 |
#define TEST_FAIL {TestCleanup(); test(EFalse);} |
|
50 |
#define CLEANUP(a) {if (!gFailPrintPageInfo) \ |
|
51 |
{ \ |
|
52 |
PrintPageInfo(); \ |
|
53 |
gFailPrintPageInfo = ETrue; \ |
|
54 |
} \ |
|
55 |
a;} |
|
56 |
#endif |
|
57 |
||
58 |
||
59 |
||
60 |
#define TEST_DRIVER_OPEN 1 |
|
61 |
#define TEST_DRIVER_CLOSE 0 |
|
62 |
||
63 |
#define BEST_MOVABLE 1 |
|
64 |
#define BEST_DISCARDABLE 2 |
|
65 |
#define BEST_FIXED 3 |
|
66 |
||
67 |
#define Z_ALLOC_CONTIG 1 |
|
68 |
#define Z_ALLOC_DISC 2 |
|
69 |
||
70 |
LOCAL_D TUint gTestStarted = EFalse; // Used to ensure matching TestStart() and TestEnd(). |
|
71 |
LOCAL_D TBool gPagedRom = ETrue; // Stores whether or not is a paged ROM |
|
72 |
LOCAL_D TInt gTestStepFailed = 0; // Stores the number of test steps failed |
|
73 |
LOCAL_D TBool gFailPrintPageInfo = EFalse; // Set to ETrue once CLEANUP has been invoked once. |
|
74 |
LOCAL_D TBool gFileCacheRun = EFalse; // Set to ETrue whe FSCaching tests have been run |
|
75 |
||
76 |
LOCAL_D TInt gRamSize; // The total RAM size in bytes |
|
77 |
LOCAL_D TInt gFreeRam; // The amount of free RAM available in bytes |
|
78 |
LOCAL_D TInt gPageSize; // The number of bytes per page |
|
79 |
LOCAL_D TUint gPageShift; |
|
80 |
#ifdef DEBUG_VER |
|
81 |
LOCAL_D TInt gRamUsed; // The amount of RAM used in bytes |
|
82 |
#endif |
|
83 |
LOCAL_D TInt gInitialRam; // The initial free RAM before a test starts |
|
84 |
LOCAL_D TInt gEndRam; // The end free RAM when a test finishes |
|
85 |
LOCAL_D TUint gOriginalMinCacheSize; // The original DP minSize |
|
86 |
LOCAL_D TUint gOriginalMaxCacheSize; // The original DP maxSize |
|
87 |
LOCAL_D TInt gTotalRamLost; // The total amount of RAM lost during the test |
|
88 |
||
89 |
LOCAL_D TUint gZoneCount = 0; // Number of zones |
|
90 |
LOCAL_D const TUint KInvalidZoneID = 0xffffffff; // Invalid value for a zone ID |
|
91 |
LOCAL_D STestPageCount gTotalPageCount; |
|
92 |
||
93 |
||
94 |
LOCAL_D struct SRamZoneConfig* gZoneConfigArray; // Contains the configurations of all the zones |
|
95 |
LOCAL_D struct SRamZoneUtilisation* gZoneUtilArray; // Contains the utilisations of all the zones |
|
96 |
LOCAL_D struct SRamZoneUtilisation* gOriginalPageCountArray; // Contains the original utilisations of the zones |
|
97 |
LOCAL_D TInt* gPrefArray; // Contains the preference order of the zones |
|
98 |
LOCAL_D TUint8* gOrigFlagArray; // Contains the orignal values for the zone flags |
|
99 |
||
100 |
LOCAL_D TInt gDefragMaxPages = 0; |
|
101 |
||
102 |
const TInt KFillAllMovable = -1; |
|
103 |
||
104 |
LOCAL_D RChunk* gChunkArray1 = NULL; // Stores reference to all the chunks that have been created |
|
105 |
LOCAL_D RChunk* gChunkArray2 = NULL; // Stores reference to all the chunks that have been created |
|
106 |
LOCAL_D TUint gChunkArraySize1 = 0; // The size of the array gChunkArray |
|
107 |
LOCAL_D TUint gChunkArraySize2 = 0; // The size of the array gChunkArray |
|
108 |
const TUint KChunkDefaultSize = 0x300000; |
|
109 |
const TUint KMaxChunks = 14; |
|
110 |
LOCAL_D const TUint KNumAllocChunks = 10; // The number of chunks to be allocd for some tests. |
|
111 |
||
112 |
LOCAL_D RRamDefragFuncTestLdd Ldd; // Main Ldd used to call into device driver |
|
113 |
||
114 |
LOCAL_D TBuf<20> gTestThreadName =_L("TestThread"); |
|
115 |
LOCAL_D RThread gTestThread; |
|
116 |
LOCAL_D TRequestStatus status; |
|
117 |
||
118 |
LOCAL_D TInt gDrive; // The removable media drive |
|
119 |
LOCAL_D RFs gTheFs; |
|
120 |
LOCAL_D TFileName gSessionPath; |
|
121 |
||
122 |
const TInt KNoRemovableDrive = -1; // gDrive is set to this when no suitable drive can be found. |
|
123 |
const TInt KDefaultCacheSize = (128 + 12) * 1024; // The default file system cache size |
|
124 |
const TUint KNumFilesOrig = (32 * 1024 * 1024) / KDefaultCacheSize; // The number of files that are needed to fill the file system cache |
|
125 |
LOCAL_D TInt gFilesNeededToFillCache = KNumFilesOrig ; // Not constant as can change depending on the size of the disk |
|
126 |
LOCAL_D RFile gFile[KNumFilesOrig]; |
|
127 |
||
128 |
LOCAL_D TInt* gCandList1; // Array of zones that have the same preference and the same |
|
129 |
LOCAL_D TInt* gCandList2; // amount of free pages |
|
130 |
const TInt KInvalidCandIndex = -1; |
|
131 |
||
132 |
// |
|
133 |
// GetDrive |
|
134 |
// |
|
135 |
// Gets the removable drive number |
|
136 |
// |
|
137 |
TInt GetDrive() |
|
138 |
{ |
|
139 |
RFs theFs; |
|
140 |
TInt r = theFs.Connect(); |
|
141 |
test_KErrNone(r); |
|
142 |
||
143 |
TInt driveLet = KNoRemovableDrive; |
|
144 |
||
145 |
TInt i = EDriveA; |
|
146 |
for (; i <= EDriveZ; i++) |
|
147 |
{ |
|
148 |
TVolumeInfo volInfo; |
|
149 |
r = theFs.Volume(volInfo, i); |
|
150 |
if (r == KErrNone) |
|
151 |
{// This drive no. exists so determine if it is removable and |
|
152 |
// formattable media. |
|
153 |
if ((volInfo.iDrive.iDriveAtt & KDriveAttRemovable) && |
|
154 |
(volInfo.iDrive.iMediaAtt & KMediaAttFormattable)) |
|
155 |
{ |
|
156 |
driveLet = i; |
|
157 |
break; |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
theFs.Close(); |
|
162 |
return driveLet; |
|
163 |
} |
|
164 |
||
165 |
||
166 |
// |
|
167 |
// DeviceDriver |
|
168 |
// |
|
169 |
// Opens or closes the device driver used |
|
170 |
// |
|
171 |
TInt DeviceDriver(TInt aFunctionNum) |
|
172 |
{ |
|
173 |
TInt r = 0; |
|
174 |
switch (aFunctionNum) |
|
175 |
{ |
|
176 |
case TEST_DRIVER_OPEN: |
|
177 |
{ |
|
178 |
r = User::LoadLogicalDevice(KRamDefragFuncTestLddName); |
|
179 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
180 |
r = Ldd.Open(); |
|
181 |
test_KErrNone(r); |
|
182 |
} |
|
183 |
break; |
|
184 |
||
185 |
case TEST_DRIVER_CLOSE: |
|
186 |
{ |
|
187 |
Ldd.Close(); |
|
188 |
r = User::FreeLogicalDevice(KRamDefragFuncTestLddName); |
|
189 |
test_KErrNone(r); |
|
190 |
} |
|
191 |
break; |
|
192 |
||
193 |
default: |
|
194 |
break; |
|
195 |
||
196 |
} |
|
197 |
return r; |
|
198 |
} |
|
199 |
||
200 |
||
201 |
// |
|
202 |
// GetOriginalPageCount |
|
203 |
// |
|
204 |
// Obtains the orginal types of pages in each of the zones |
|
205 |
// |
|
206 |
void GetOriginalPageCount() |
|
207 |
{ |
|
208 |
TUint index; |
|
209 |
TInt ret = 0; |
|
210 |
TESTDEBUG(test.Printf(_L("ram defrag : Get info about the zones\n"))); |
|
211 |
for (index = 0; index < gZoneCount; index ++) |
|
212 |
{ |
|
213 |
ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gOriginalPageCountArray[index]); |
|
214 |
test(ret == KErrNone); |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
||
219 |
// |
|
220 |
// PrintPageInfo |
|
221 |
// |
|
222 |
// Prints various page information to the screen |
|
223 |
// |
|
224 |
void PrintPageInfo() |
|
225 |
{ |
|
226 |
test.Printf(_L("\nZONE CONFIGURATIONS:\n")); |
|
227 |
for (TUint index = 0; index < gZoneCount; index ++) |
|
228 |
{ |
|
229 |
TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)index, (TAny*)&gZoneConfigArray[index]); |
|
230 |
test(ret == KErrNone); |
|
231 |
test.Printf(_L("config : id=0x%08x index=%-2d base=0x%08x end=0x%08x pages=0x%08x pref=%-2d flags=0x%x\n"), |
|
232 |
gZoneConfigArray[index].iZoneId,gZoneConfigArray[index].iZoneIndex, |
|
233 |
gZoneConfigArray[index].iPhysBase,gZoneConfigArray[index].iPhysEnd, |
|
234 |
gZoneConfigArray[index].iPhysPages,gZoneConfigArray[index].iPref,gZoneConfigArray[index].iFlags); |
|
235 |
} |
|
236 |
test.Printf(_L("\nZONE UTILISATIONS:\n")); |
|
237 |
for (TUint index = 0; index < gZoneCount; index ++) |
|
238 |
{ |
|
239 |
TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gZoneUtilArray[index]); |
|
240 |
test(ret == KErrNone); |
|
241 |
test.Printf(_L("usage : id=0x%08x index=%-2d pref=%d pages=0x%08x free=0x%08x unknown=0x%08x fixed=0x%08x move=0x%08x discard=0x%08x other=0x%08x\n"), |
|
242 |
gZoneUtilArray[index].iZoneId,gZoneUtilArray[index].iZoneIndex,gZoneConfigArray[index].iPref, |
|
243 |
gZoneUtilArray[index].iPhysPages,gZoneUtilArray[index].iFreePages, |
|
244 |
gZoneUtilArray[index].iAllocUnknown,gZoneUtilArray[index].iAllocFixed,gZoneUtilArray[index].iAllocMovable, |
|
245 |
gZoneUtilArray[index].iAllocDiscardable,gZoneUtilArray[index].iAllocOther); |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
||
250 |
// |
|
251 |
// GetAllPageInfo |
|
252 |
// |
|
253 |
// Get various different page information for all zones |
|
254 |
// Also updates the total page count |
|
255 |
// |
|
256 |
void GetAllPageInfo() |
|
257 |
{ |
|
258 |
TInt ret = 0; |
|
259 |
gTotalPageCount.iFreePages = 0; |
|
260 |
gTotalPageCount.iUnknownPages = 0; |
|
261 |
gTotalPageCount.iFixedPages = 0; |
|
262 |
gTotalPageCount.iMovablePages = 0; |
|
263 |
gTotalPageCount.iDiscardablePages = 0; |
|
264 |
gTotalPageCount.iOtherPages = 0; |
|
265 |
||
266 |
// now get the config of each of the zones. |
|
267 |
TUint index; |
|
268 |
TESTDEBUG(test.Printf(_L("ram defrag : Get info about the zones\n"))); |
|
269 |
for (index = 0; index < gZoneCount; index ++) |
|
270 |
{ |
|
271 |
ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)index, (TAny*)&gZoneConfigArray[index]); |
|
272 |
test(ret == KErrNone); |
|
273 |
||
274 |
ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gZoneUtilArray[index]); |
|
275 |
test(ret == KErrNone); |
|
276 |
||
277 |
gTotalPageCount.iFreePages += gZoneUtilArray[index].iFreePages; |
|
278 |
gTotalPageCount.iUnknownPages += gZoneUtilArray[index].iAllocUnknown; |
|
279 |
gTotalPageCount.iFixedPages += gZoneUtilArray[index].iAllocFixed; |
|
280 |
gTotalPageCount.iMovablePages += gZoneUtilArray[index].iAllocMovable; |
|
281 |
gTotalPageCount.iDiscardablePages += gZoneUtilArray[index].iAllocDiscardable; |
|
282 |
gTotalPageCount.iOtherPages += gZoneUtilArray[index].iAllocOther; |
|
283 |
} |
|
284 |
TESTDEBUG(test.Printf(_L("free=0x%x unknown=0x%x fixed=0x%x move=0x%x discard=0x%x other=0x%x\n"), |
|
285 |
gTotalPageCount.iFreePages, gTotalPageCount.iUnknownPages, gTotalPageCount.iFixedPages, |
|
286 |
gTotalPageCount.iMovablePages, gTotalPageCount.iDiscardablePages,gTotalPageCount.iOtherPages)); |
|
287 |
||
288 |
TESTDEBUG(PrintPageInfo()); |
|
289 |
} |
|
290 |
||
291 |
void RestoreRamZoneFlags() |
|
292 |
{ |
|
293 |
GetAllPageInfo(); // Update the current set of RAM zone flag data. |
|
294 |
for (TUint index=0; index < gZoneCount; index++) |
|
295 |
{ |
|
296 |
TUint zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
297 |
Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ORIG_FLAG, gOrigFlagArray[index]); |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
void ResetRamZoneFlags() |
|
302 |
{ |
|
303 |
GetAllPageInfo(); // Update the current set of RAM zone flag data. |
|
304 |
for (TUint index=0; index < gZoneCount; index++) |
|
305 |
{ |
|
306 |
TUint zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
307 |
Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, RESET_FLAG); |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize); |
|
312 |
void ResetDPCache(); |
|
313 |
||
314 |
void FSCachCleanUp() |
|
315 |
{ |
|
316 |
// If the File System Caching tests have been run, |
|
317 |
// ensure that they are cleaned up |
|
318 |
if (gFileCacheRun) |
|
319 |
{ |
|
320 |
TUint i = 0; |
|
321 |
// First close all the open handles to the RFile objects open |
|
322 |
for (i = 0; i < KNumFilesOrig; i++) |
|
323 |
{ |
|
324 |
gFile[i].Close(); |
|
325 |
} |
|
326 |
||
327 |
// Now call EmptyRamZone on every zone to ensure that |
|
328 |
// discardable pages are cleaned up |
|
329 |
||
330 |
GetAllPageInfo(); |
|
331 |
for (i = 0; i < gZoneCount; i++) |
|
332 |
{ |
|
333 |
TUint zoneID = gZoneConfigArray[i].iZoneId; |
|
334 |
Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); |
|
335 |
} |
|
336 |
gFileCacheRun = EFalse; |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
// |
|
341 |
// TestCleanup |
|
342 |
// |
|
343 |
// Cleans up all the allocations made at the beginning of the test |
|
344 |
// |
|
345 |
void TestCleanup() |
|
346 |
{ |
|
347 |
||
348 |
Ldd.ResetDriver(); |
|
349 |
||
350 |
// Revert the cleared flags to their original values before the tests were carried out |
|
351 |
RestoreRamZoneFlags(); |
|
352 |
||
353 |
// Reset the DP cache and remove any allocated chunks and fixed pages. |
|
354 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
355 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
356 |
ResetDPCache(); |
|
357 |
Ldd.FreeAllFixedPages(); |
|
358 |
Ldd.FreeFromAllZones(); |
|
359 |
FSCachCleanUp(); |
|
360 |
||
361 |
User::Free(gPrefArray); |
|
362 |
gPrefArray = NULL; |
|
363 |
||
364 |
User::Free(gOrigFlagArray); |
|
365 |
gOrigFlagArray = NULL; |
|
366 |
||
367 |
User::Free(gCandList1); |
|
368 |
gCandList1 = NULL; |
|
369 |
||
370 |
User::Free(gCandList2); |
|
371 |
gCandList2 = NULL; |
|
372 |
||
373 |
User::Free(gOriginalPageCountArray); |
|
374 |
gOriginalPageCountArray = NULL; |
|
375 |
||
376 |
// Output the last possible state of memory |
|
377 |
if (!gFailPrintPageInfo) |
|
378 |
PrintPageInfo(); |
|
379 |
||
380 |
User::Free(gZoneConfigArray); |
|
381 |
gZoneConfigArray = NULL; |
|
382 |
||
383 |
User::Free(gZoneUtilArray); |
|
384 |
gZoneUtilArray = NULL; |
|
385 |
||
386 |
} |
|
387 |
||
388 |
||
389 |
// TestSetup |
|
390 |
// |
|
391 |
// Get the necessary information needed to carry out the tests |
|
392 |
// |
|
393 |
TInt TestSetup() |
|
394 |
{ |
|
395 |
// Get the MMC drive |
|
396 |
gDrive = GetDrive(); |
|
397 |
||
398 |
// first get the number of zones |
|
399 |
TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneCount,&gZoneCount,0); |
|
400 |
if (ret != KErrNone) |
|
401 |
{ |
|
402 |
test.Printf(_L("Cannot obtain the number of zones\n")); |
|
403 |
return ret; |
|
404 |
} |
|
405 |
test.Printf(_L("RAM Zones (count=%u)\n"),gZoneCount); |
|
406 |
||
407 |
// Obtain the size of the RAM and the size of a page |
|
408 |
ret = HAL::Get(HAL::EMemoryRAM, gRamSize); |
|
409 |
if (ret != KErrNone) |
|
410 |
{ |
|
411 |
test.Printf(_L("Cannot obtain the size of RAM\n")); |
|
412 |
return ret; |
|
413 |
} |
|
414 |
||
415 |
// Retrieve the page size and use it to detemine the page shift (assumes 32-bit system). |
|
416 |
ret = HAL::Get(HAL::EMemoryPageSize, gPageSize); |
|
417 |
if (ret != KErrNone) |
|
418 |
{ |
|
419 |
test.Printf(_L("Cannot obtain the page size\n")); |
|
420 |
return ret; |
|
421 |
} |
|
422 |
||
423 |
TUint32 pageMask = gPageSize; |
|
424 |
TUint i = 0; |
|
425 |
for (; i < 32; i++) |
|
426 |
{ |
|
427 |
if (pageMask & 1) |
|
428 |
{ |
|
429 |
if (pageMask & ~1u) |
|
430 |
{ |
|
431 |
test.Printf(_L("ERROR - page size not a power of 2")); |
|
432 |
return KErrNotSupported; |
|
433 |
} |
|
434 |
gPageShift = i; |
|
435 |
break; |
|
436 |
} |
|
437 |
pageMask >>= 1; |
|
438 |
} |
|
439 |
||
440 |
gZoneConfigArray = (SRamZoneConfig *)User::AllocZ(sizeof(SRamZoneConfig) * gZoneCount); |
|
441 |
if (gZoneConfigArray == NULL) |
|
442 |
return KErrNoMemory; |
|
443 |
gZoneUtilArray = (SRamZoneUtilisation *)User::AllocZ(sizeof(SRamZoneUtilisation) * gZoneCount); |
|
444 |
if (gZoneUtilArray == NULL) |
|
445 |
return KErrNoMemory; |
|
446 |
gPrefArray = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); |
|
447 |
if (gPrefArray == NULL) |
|
448 |
return KErrNoMemory; |
|
449 |
gOrigFlagArray = (TUint8 *)User::AllocZ(sizeof(TUint8) * gZoneCount); |
|
450 |
if (gOrigFlagArray == NULL) |
|
451 |
return KErrNoMemory; |
|
452 |
gOriginalPageCountArray = (SRamZoneUtilisation *)User::AllocZ(sizeof(SRamZoneUtilisation) * gZoneCount); |
|
453 |
if (gOriginalPageCountArray == NULL) |
|
454 |
return KErrNoMemory; |
|
455 |
||
456 |
gCandList1 = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); |
|
457 |
if (gCandList1 == NULL) |
|
458 |
return KErrNoMemory; |
|
459 |
gCandList2 = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); |
|
460 |
if (gCandList2 == NULL) |
|
461 |
return KErrNoMemory; |
|
462 |
||
463 |
GetAllPageInfo(); |
|
464 |
PrintPageInfo(); |
|
465 |
||
466 |
// Store the original flags |
|
467 |
for (i=0; i < gZoneCount; i++) |
|
468 |
gOrigFlagArray[i] = gZoneConfigArray[i].iFlags; |
|
469 |
||
470 |
// Now clear the flags for carrying out tests |
|
471 |
Ldd.ResetDriver(); |
|
472 |
ResetRamZoneFlags(); |
|
473 |
||
474 |
||
475 |
// Check whether the ROM is paged or not |
|
476 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
477 |
if(!romHeader->iPageableRomStart) |
|
478 |
{ |
|
479 |
test.Printf(_L("Not a Paged ROM - Skipping all discardable page tests.\n")); |
|
480 |
gPagedRom = EFalse; |
|
481 |
} |
|
482 |
else |
|
483 |
{// Save the current state of the DP cache so it can be restored when required and |
|
484 |
// after the test has finished. |
|
485 |
TUint currentCacheSize; |
|
486 |
DPTest::CacheSize(gOriginalMinCacheSize, gOriginalMaxCacheSize, currentCacheSize); |
|
487 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
488 |
gOriginalMinCacheSize >> gPageShift, gOriginalMaxCacheSize >> gPageShift, |
|
489 |
currentCacheSize >> gPageShift)); |
|
490 |
} |
|
491 |
||
492 |
return KErrNone; |
|
493 |
} |
|
494 |
||
495 |
||
496 |
// |
|
497 |
// UpdateRamInfo |
|
498 |
// |
|
499 |
// Updating the various RAM information |
|
500 |
// |
|
501 |
void UpdateRamInfo() |
|
502 |
{ |
|
503 |
HAL::Get(HAL::EMemoryRAMFree, gFreeRam); |
|
504 |
TESTDEBUG(gRamUsed = gRamSize - gFreeRam); |
|
505 |
} |
|
506 |
||
507 |
||
508 |
// |
|
509 |
// CheckRamDifference |
|
510 |
// |
|
511 |
// Checks the difference between the initial free RAM and the end free RAM |
|
512 |
// |
|
513 |
void CheckRamDifference() |
|
514 |
{ |
|
515 |
if (gInitialRam == gEndRam) |
|
516 |
{ |
|
517 |
TESTDEBUG(test.Printf(_L("No RAM was lost during this test\n"))); |
|
518 |
} |
|
519 |
else |
|
520 |
{ |
|
521 |
TInt diff = gInitialRam - gEndRam; |
|
522 |
||
523 |
||
524 |
gTotalRamLost = gTotalRamLost + diff; |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
TInt VerifyMovDisAlloc(); |
|
529 |
// |
|
530 |
// TestStart |
|
531 |
// |
|
532 |
// Updates the RAM information at the beginning of a test step |
|
533 |
// |
|
534 |
void TestStart() |
|
535 |
{ |
|
536 |
test(!gTestStarted); |
|
537 |
gTestStarted = ETrue; |
|
538 |
||
539 |
Ldd.ResetDriver(); |
|
540 |
||
541 |
Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
542 |
if (VerifyMovDisAlloc() != KErrNone) |
|
543 |
{ |
|
544 |
CLEANUP(;); |
|
545 |
TEST_FAIL; |
|
546 |
} |
|
547 |
||
548 |
UpdateRamInfo(); |
|
549 |
gInitialRam = gFreeRam; |
|
550 |
TESTDEBUG(test.Printf(_L("Initial Free RAM = 0x%x, Initial RAM Used = 0x%x\n"), gFreeRam, gRamUsed)); |
|
551 |
} |
|
552 |
||
553 |
||
554 |
void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize); |
|
555 |
// |
|
556 |
// TestEnd |
|
557 |
// |
|
558 |
// Updates RAM information at end of test step and checks the RAM delta |
|
559 |
// |
|
560 |
void TestEnd() |
|
561 |
{ |
|
562 |
test(gTestStarted); |
|
563 |
gTestStarted = EFalse; |
|
564 |
||
565 |
gDefragMaxPages = 0; |
|
566 |
||
567 |
// Clean up anything that may need to be cleaned. |
|
568 |
ResetRamZoneFlags(); |
|
569 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
570 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
571 |
ResetDPCache(); |
|
572 |
Ldd.FreeAllFixedPages(); |
|
573 |
FSCachCleanUp(); |
|
574 |
||
575 |
UpdateRamInfo(); |
|
576 |
gEndRam = gFreeRam; |
|
577 |
TESTDEBUG(test.Printf(_L("End RAM Free = 0x%x, End RAM Used = 0x%x\n"), gEndRam, gRamUsed)); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
578 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
579 |
// Ensure any asynchronous clean up operations complete before we move on |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
580 |
// to the next test. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
581 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
0 | 582 |
CheckRamDifference(); |
583 |
test.Printf(_L(" \n")); |
|
584 |
} |
|
585 |
||
586 |
// |
|
587 |
// CheckZonesSwitchedOff |
|
588 |
// |
|
589 |
// Checks that zones have been switched off |
|
590 |
// |
|
591 |
TBool CheckZonesSwitchedOff() |
|
592 |
{ |
|
593 |
GetAllPageInfo(); |
|
594 |
for (TUint i = 0; i < gZoneCount; i++) |
|
595 |
{ |
|
596 |
if (gOriginalPageCountArray[i].iFreePages != gOriginalPageCountArray[i].iPhysPages && |
|
597 |
gZoneUtilArray[i].iFreePages == gZoneUtilArray[i].iPhysPages) |
|
598 |
{ |
|
599 |
return ETrue; |
|
600 |
} |
|
601 |
} |
|
602 |
return EFalse; |
|
603 |
} |
|
604 |
||
605 |
||
606 |
// |
|
607 |
// CheckZoneIsOff |
|
608 |
// |
|
609 |
// Checks if a particular zone is empty |
|
610 |
// |
|
611 |
TBool CheckZoneIsOff(TUint aZoneIndex) |
|
612 |
{ |
|
613 |
GetAllPageInfo(); |
|
614 |
if (gZoneUtilArray[aZoneIndex].iFreePages == gZoneUtilArray[aZoneIndex].iPhysPages) |
|
615 |
{ |
|
616 |
TESTDEBUG(test.Printf(_L("Zone index %d is Empty\n"), aZoneIndex)); |
|
617 |
return ETrue; |
|
618 |
} |
|
619 |
else |
|
620 |
{ |
|
621 |
TESTDEBUG(test.Printf(_L("Zone index %d is Not empty\n"), aZoneIndex)); |
|
622 |
return EFalse; |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
||
627 |
// |
|
628 |
// GetPrefOrder |
|
629 |
// |
|
630 |
// Go through each zone ordering them in preference order |
|
631 |
// |
|
632 |
void GetPrefOrder() |
|
633 |
{ |
|
634 |
GetAllPageInfo(); |
|
635 |
TESTDEBUG(PrintPageInfo()); |
|
636 |
||
637 |
for (TUint i=0; i < (TUint)gZoneCount; i++) |
|
638 |
gPrefArray[i] = KErrNotFound; |
|
639 |
||
640 |
for (TUint curIndex = 0; curIndex < gZoneCount; curIndex++) |
|
641 |
{ |
|
642 |
TBool currentEmpty = gZoneUtilArray[curIndex].iPhysPages == gZoneUtilArray[curIndex].iFreePages; |
|
643 |
TUint currentPref = gZoneConfigArray[curIndex].iPref; |
|
644 |
TUint currentImmovPages = gZoneUtilArray[curIndex].iAllocFixed + |
|
645 |
gZoneUtilArray[curIndex].iAllocUnknown; |
|
646 |
TUint morePrefCnt = 0; |
|
647 |
for (TUint index = 0; index < gZoneCount; index++) |
|
648 |
{// A RAM zone with the same iPref is more preferable if it has |
|
649 |
// more immovable pages. |
|
650 |
if (gZoneConfigArray[index].iPref < currentPref || |
|
651 |
(gZoneConfigArray[index].iPref == currentPref && |
|
652 |
(currentImmovPages < gZoneUtilArray[index].iAllocFixed + gZoneUtilArray[index].iAllocUnknown || |
|
653 |
(currentEmpty && |
|
654 |
gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages)))) |
|
655 |
{ |
|
656 |
morePrefCnt++; |
|
657 |
} |
|
658 |
} |
|
659 |
||
660 |
while (gPrefArray[morePrefCnt] != KErrNotFound) |
|
661 |
{// Zone(s) of this preference and size already exist so |
|
662 |
// place this one after it/them |
|
663 |
morePrefCnt++; |
|
664 |
} |
|
665 |
gPrefArray[morePrefCnt] = curIndex; |
|
666 |
} |
|
667 |
} |
|
668 |
||
669 |
// |
|
670 |
// ZonesSamePref |
|
671 |
// |
|
672 |
// Return ETrue if the RAM zones are of the same preference. |
|
673 |
// |
|
674 |
// NOTE - This requires GetAllPageInfo() to have already been called. |
|
675 |
// |
|
676 |
TBool ZonesSamePref(TUint aZoneIndex1, TUint aZoneIndex2) |
|
677 |
{ |
|
678 |
TBool zoneEmpty1 = gZoneUtilArray[aZoneIndex1].iFreePages == gZoneUtilArray[aZoneIndex1].iPhysPages; |
|
679 |
TBool zoneEmpty2 = gZoneUtilArray[aZoneIndex2].iFreePages == gZoneUtilArray[aZoneIndex2].iPhysPages; |
|
680 |
if (gZoneConfigArray[aZoneIndex1].iPref == gZoneConfigArray[aZoneIndex2].iPref && |
|
681 |
(gZoneUtilArray[aZoneIndex1].iAllocFixed + gZoneUtilArray[aZoneIndex1].iAllocUnknown == |
|
682 |
gZoneUtilArray[aZoneIndex2].iAllocFixed + gZoneUtilArray[aZoneIndex2].iAllocUnknown && |
|
683 |
(zoneEmpty1 == zoneEmpty2))) |
|
684 |
{ |
|
685 |
return ETrue; |
|
686 |
} |
|
687 |
||
688 |
return EFalse; |
|
689 |
} |
|
690 |
||
691 |
// |
|
692 |
// FindMostPrefEmpty |
|
693 |
// |
|
694 |
// Checks all zones and returns the most preferable RAM zone which |
|
695 |
// is completely emtpy |
|
696 |
// |
|
697 |
// @param aZoneIndex On return this will contain the index into gZoneUtilArray of the most preferable empty RAM zone. |
|
698 |
// @param aPrefIndex On return this will contain the index into gPrefArray of the most preferable empty RAM zone. |
|
699 |
// |
|
700 |
// @return KErrNotFound if a zone cannot be found, else KErrNone |
|
701 |
// |
|
702 |
TInt FindMostPrefEmpty(TUint& aZoneIndex, TUint* aPrefIndex = NULL) |
|
703 |
{ |
|
704 |
// Get the most pref zone which is completely free to use as a test zone |
|
705 |
GetPrefOrder(); |
|
706 |
TUint prefIndex = 0; |
|
707 |
for (; prefIndex < gZoneCount; prefIndex++) |
|
708 |
{ |
|
709 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
710 |
if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages) |
|
711 |
{ |
|
712 |
aZoneIndex = zoneIndex; |
|
713 |
if (aPrefIndex) |
|
714 |
{ |
|
715 |
*aPrefIndex = prefIndex; |
|
716 |
} |
|
717 |
return KErrNone; |
|
718 |
} |
|
719 |
} |
|
720 |
return KErrNotFound; |
|
721 |
} |
|
722 |
||
723 |
// |
|
724 |
// FindLeastPrefEmpty |
|
725 |
// |
|
726 |
// Checks all zones and returns the least preferable RAM zone which |
|
727 |
// is completely emtpy |
|
728 |
// |
|
729 |
// @param aZoneIndex On return this will contain the index into gZoneUtilArray of the least preferable empty RAM zone. |
|
730 |
// @param aPrefIndex On return this will contain the index into gPrefArray of the least preferable empty RAM zone. |
|
731 |
// |
|
732 |
// @return KErrNotFound if a zone cannot be found, else KErrNone |
|
733 |
// |
|
734 |
TInt FindLeastPrefEmpty(TUint& aZoneIndex, TUint* aPrefIndex = NULL) |
|
735 |
{ |
|
736 |
// Get the most pref zone which is completely free to use as a test zone |
|
737 |
GetPrefOrder(); |
|
738 |
TInt prefIndex = gZoneCount - 1; |
|
739 |
for (; prefIndex >= 0; prefIndex--) |
|
740 |
{ |
|
741 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
742 |
if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages) |
|
743 |
{ |
|
744 |
aZoneIndex = zoneIndex; |
|
745 |
if (aPrefIndex) |
|
746 |
{ |
|
747 |
*aPrefIndex = (TUint)prefIndex; |
|
748 |
} |
|
749 |
return KErrNone; |
|
750 |
} |
|
751 |
} |
|
752 |
return KErrNotFound; |
|
753 |
} |
|
754 |
||
755 |
// |
|
756 |
// FindMostPrefWithFree |
|
757 |
// |
|
758 |
// Checks all zones and returns the most preferable RAM zone which |
|
759 |
// has at least 1 free page |
|
760 |
// |
|
761 |
// @param aZoneIndex On return this will contain the index into gZoneUtilArray of the most preferable RAM zone with free pages. |
|
762 |
// @param aPrefIndex On return this will contain the index into gPrefArray of the most preferable RAM zone with free pages. |
|
763 |
// |
|
764 |
// @return KErrNotFound if a zone cannot be found, else KErrNone |
|
765 |
// |
|
766 |
TInt FindMostPrefWithFree(TUint& aZoneIndex, TUint* aPrefIndex = NULL) |
|
767 |
{ |
|
768 |
// Get the most pref zone which has free pages |
|
769 |
GetPrefOrder(); |
|
770 |
TUint prefIndex = 0; |
|
771 |
for (; prefIndex < gZoneCount; prefIndex++) |
|
772 |
{ |
|
773 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
774 |
if (gZoneUtilArray[zoneIndex].iFreePages) |
|
775 |
{ |
|
776 |
aZoneIndex = zoneIndex; |
|
777 |
if (aPrefIndex) |
|
778 |
{ |
|
779 |
*aPrefIndex = prefIndex; |
|
780 |
} |
|
781 |
return KErrNone; |
|
782 |
} |
|
783 |
} |
|
784 |
return KErrNotFound; |
|
785 |
} |
|
786 |
// |
|
787 |
// CanGenSucceed |
|
788 |
// |
|
789 |
// Check whether a call to TRamDefragRequest::DefragRam() would be able to |
|
790 |
// succeed or not. |
|
791 |
// |
|
792 |
TBool CanGenSucceed() |
|
793 |
{ |
|
794 |
GetPrefOrder(); |
|
795 |
TBool genSucceed = EFalse; |
|
796 |
// Work out if general has anything to do |
|
797 |
for(TInt prefIndex = (TInt)gZoneCount-1; prefIndex >= 0; prefIndex--) |
|
798 |
{ |
|
799 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
800 |
TESTDEBUG(test.Printf(_L("prefIndex = %d zoneIndex = 0x%x\n"), prefIndex, zoneIndex)); |
|
801 |
||
802 |
TUint samePrefCount = 1; |
|
803 |
TUint samePrefSucceed = 0; |
|
804 |
// The number of zones of this preference that will be skipped by the general defrag |
|
805 |
TUint samePrefEmptyImmovable = 0; |
|
806 |
||
807 |
// Determine how many zones have the same preference as this one |
|
808 |
TInt prevPrefIndex = (prefIndex != 0)? (prefIndex - 1) : -1; |
|
809 |
for (; prevPrefIndex >= 0; prevPrefIndex--) |
|
810 |
{ |
|
811 |
TUint prevIndex = gPrefArray[prevPrefIndex]; |
|
812 |
if (ZonesSamePref(zoneIndex, prevIndex)) |
|
813 |
{ |
|
814 |
samePrefCount++; |
|
815 |
} |
|
816 |
else // no more zones with this preference |
|
817 |
break; |
|
818 |
} |
|
819 |
TESTDEBUG(test.Printf(_L("samePrefCount = %d\n"), samePrefCount)); |
|
820 |
||
821 |
for (TInt l = prefIndex - (samePrefCount-1); l <= prefIndex; l++) |
|
822 |
{ |
|
823 |
TUint curPrefIndex = gPrefArray[l]; |
|
824 |
TESTDEBUG(test.Printf(_L("curPrefIndex = %d\n"), curPrefIndex)); |
|
825 |
if (gZoneUtilArray[curPrefIndex].iFreePages != gZoneConfigArray[curPrefIndex].iPhysPages) |
|
826 |
{ |
|
827 |
TBool clearMovable = EFalse; |
|
828 |
TBool clearDiscardable = EFalse; |
|
829 |
||
830 |
if (gZoneUtilArray[curPrefIndex].iAllocUnknown || gZoneUtilArray[curPrefIndex].iAllocFixed) |
|
831 |
{ |
|
832 |
TESTDEBUG(test.Printf(_L("unknown or fixed\n"))); |
|
833 |
samePrefEmptyImmovable++; |
|
834 |
continue; |
|
835 |
} |
|
836 |
if (gZoneUtilArray[curPrefIndex].iAllocMovable) |
|
837 |
{// determine if movable can potentially be cleared from this zone |
|
838 |
TUint freeInLower = 0; |
|
839 |
for (TInt j=0; j <= prefIndex; j++) |
|
840 |
{ |
|
841 |
TUint idx = gPrefArray[j]; |
|
842 |
if (idx == curPrefIndex) |
|
843 |
continue; |
|
844 |
freeInLower += gZoneUtilArray[idx].iFreePages; |
|
845 |
} |
|
846 |
if (gZoneUtilArray[curPrefIndex].iAllocMovable <= freeInLower) |
|
847 |
{ |
|
848 |
clearMovable = ETrue; |
|
849 |
TESTDEBUG(test.Printf(_L("Can clear movable, curPrefIndex = %d\n"), curPrefIndex)); |
|
850 |
} |
|
851 |
} |
|
852 |
else |
|
853 |
{ |
|
854 |
TESTDEBUG(test.Printf(_L("Can clear movable, curPrefIndex = %d\n"), curPrefIndex)); |
|
855 |
clearMovable = ETrue; |
|
856 |
} |
|
857 |
if (gZoneUtilArray[curPrefIndex].iAllocDiscardable) |
|
858 |
{ |
|
859 |
if (gPagedRom) |
|
860 |
{ |
|
861 |
TUint minCacheSize = 0; |
|
862 |
TUint maxCacheSize = 0; |
|
863 |
TUint currentCacheSize = 0; |
|
864 |
||
865 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
866 |
TUint spareCache = currentCacheSize - minCacheSize; |
|
867 |
if (spareCache >= gZoneUtilArray[curPrefIndex].iAllocDiscardable ) |
|
868 |
{ |
|
869 |
clearDiscardable = ETrue; |
|
870 |
TESTDEBUG(test.Printf(_L("Paged: Can clear discardable\n"))); |
|
871 |
} |
|
872 |
else |
|
873 |
{// determine space for discardable in more preferable zones |
|
874 |
TUint freeInLower = 0; |
|
875 |
for (TInt j=0; j <= prefIndex; j++) |
|
876 |
{ |
|
877 |
TUint idx = gPrefArray[j]; |
|
878 |
if (idx == curPrefIndex) |
|
879 |
continue; |
|
880 |
freeInLower += gZoneUtilArray[idx].iFreePages; |
|
881 |
} |
|
882 |
if (gZoneUtilArray[curPrefIndex].iAllocDiscardable - spareCache <= freeInLower) |
|
883 |
{ |
|
884 |
clearDiscardable = ETrue; |
|
885 |
TESTDEBUG(test.Printf(_L("Paged: Can clear discardable curPrefIndex = %d\n"), curPrefIndex)); |
|
886 |
} |
|
887 |
} |
|
888 |
} |
|
889 |
else |
|
890 |
{//Should always be OK to discard as no min cache size on non-paged ROMS |
|
891 |
clearDiscardable = ETrue; |
|
892 |
test.Printf(_L("Can clear discardable curPrefIndex = %d\n"), curPrefIndex); |
|
893 |
} |
|
894 |
} |
|
895 |
else |
|
896 |
{ |
|
897 |
clearDiscardable = ETrue; |
|
898 |
} |
|
899 |
||
900 |
if (clearDiscardable && clearMovable) |
|
901 |
{ |
|
902 |
samePrefSucceed++; |
|
903 |
TESTDEBUG(test.Printf(_L("General should succeed ID=%x\n"), gZoneConfigArray[curPrefIndex].iZoneId)); |
|
904 |
} |
|
905 |
} |
|
906 |
else |
|
907 |
{//zone already empty |
|
908 |
samePrefEmptyImmovable++; |
|
909 |
} |
|
910 |
} |
|
911 |
if (samePrefSucceed == 0 && samePrefEmptyImmovable == 0) |
|
912 |
{// no zones can be defragged and none are already empty/have immovable. |
|
913 |
break; |
|
914 |
} |
|
915 |
if (samePrefEmptyImmovable != samePrefCount) |
|
916 |
{// Have reached some zones with allocated pages in them. |
|
917 |
if (samePrefSucceed + samePrefEmptyImmovable == samePrefCount) |
|
918 |
{// general should definitely succeed as each of the zones of this preference |
|
919 |
// can be emptied or are already empty/have immovable pages allocated. |
|
920 |
TESTDEBUG(test.Printf(_L("General should succeed \n"))); |
|
921 |
genSucceed = ETrue; |
|
922 |
} |
|
923 |
break; |
|
924 |
} |
|
925 |
prefIndex -= samePrefCount - 1; |
|
926 |
} |
|
927 |
return genSucceed; |
|
928 |
} |
|
929 |
||
930 |
||
931 |
// |
|
932 |
// ReadByte |
|
933 |
// |
|
934 |
// Read a particular byte |
|
935 |
// |
|
936 |
TUint8 ReadByte(volatile TUint8* aPtr) |
|
937 |
{ |
|
938 |
return *aPtr; |
|
939 |
} |
|
940 |
||
941 |
||
942 |
// |
|
943 |
// AllocDiscardable |
|
944 |
// |
|
945 |
// Allocate Discardable pages in the form of demand paged pages |
|
946 |
// |
|
947 |
// @param aNumDiscardableBytes On return this will contain the number of discardable bytes above the min cache size. |
|
948 |
// @param aMaxBytes The new limit for maximum number of bytes in the DP cache, set to KMaxTUInt64 to fill RAM. |
|
949 |
// @param aMinOffsetBytes When not set to KMaxTUint64, this sets the min cache size to be the max cache size - aMinOffsetBytes. |
|
950 |
// |
|
951 |
TInt AllocDiscardable(TInt& aNumDiscardableBytes, TUint64 aMaxBytes = KMaxTUint64, TUint64 aMinOffsetBytes = KMaxTUint64) |
|
952 |
{ |
|
953 |
TUint minCacheSize = 0; |
|
954 |
TUint maxCacheSize = 0; |
|
955 |
TUint currentCacheSize = 0; |
|
956 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
957 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
958 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
959 |
||
960 |
TESTDEBUG(test.Printf(_L("SetCacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x\n"), minCacheSize >> gPageShift, aMaxBytes >> gPageShift)); |
|
961 |
||
962 |
if (aMaxBytes == KMaxTUint64) |
|
963 |
{// Need to fill all of free memory with discardable pages |
|
964 |
UpdateRamInfo(); |
|
965 |
maxCacheSize = minCacheSize + gFreeRam; |
|
966 |
if (aMinOffsetBytes != KMaxTUint64) |
|
967 |
{// Set the min cache size relative to the max cache size. |
|
968 |
minCacheSize = maxCacheSize - aMinOffsetBytes; |
|
969 |
} |
|
970 |
TESTDEBUG(test.Printf(_L("free 0x%x max 0x%x min 0x%x\n"), gFreeRam, maxCacheSize, minCacheSize)); |
|
971 |
} |
|
972 |
else |
|
973 |
{ |
|
974 |
maxCacheSize = aMaxBytes; |
|
975 |
} |
|
976 |
||
977 |
TInt r = DPTest::SetCacheSize(maxCacheSize, maxCacheSize); |
|
978 |
if (r != KErrNone) |
|
979 |
return r; |
|
980 |
r = DPTest::SetCacheSize(minCacheSize, maxCacheSize); |
|
981 |
if (r != KErrNone) |
|
982 |
return r; |
|
983 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
984 |
TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
985 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
986 |
||
987 |
aNumDiscardableBytes = currentCacheSize - minCacheSize; |
|
988 |
TESTDEBUG(test.Printf(_L("Number of discardable bytes 0x%x\n"), aNumDiscardableBytes)); |
|
989 |
||
990 |
if (aMaxBytes == KMaxTUint64) |
|
991 |
{ |
|
992 |
UpdateRamInfo(); |
|
993 |
if (gFreeRam != aNumDiscardableBytes) |
|
994 |
{// The only free RAM should be that of the DP cache. |
|
995 |
test.Printf(_L("gFreeRam 0x%x aNumDiscardableBytes 0x%x\n"), gFreeRam, aNumDiscardableBytes); |
|
996 |
return KErrGeneral; |
|
997 |
} |
|
998 |
} |
|
999 |
return KErrNone; |
|
1000 |
} |
|
1001 |
||
1002 |
||
1003 |
// |
|
1004 |
// ResetDPCache |
|
1005 |
// |
|
1006 |
// Flush the cache and set the boundaries back to their original values |
|
1007 |
// |
|
1008 |
void ResetDPCache() |
|
1009 |
{ |
|
1010 |
if (gPagedRom) |
|
1011 |
{ |
|
1012 |
TUint minCacheSize = 0; |
|
1013 |
TUint maxCacheSize = 0; |
|
1014 |
TUint currentCacheSize = 0; |
|
1015 |
||
1016 |
TESTDEBUG(test.Printf(_L("FlushCache\n"))); |
|
1017 |
TInt r = DPTest::FlushCache(); |
|
1018 |
||
1019 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
1020 |
TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
1021 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
1022 |
||
1023 |
||
1024 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
1025 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMaxCacheSize); |
|
1026 |
TESTDEBUG(test.Printf(_L("SetCacheSize returns r = %d\n"), r)); |
|
1027 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
1028 |
TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
1029 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
1030 |
} |
|
1031 |
} |
|
1032 |
||
1033 |
// |
|
1034 |
// WriteToChunk |
|
1035 |
// |
|
1036 |
// Write to a number of chunks |
|
1037 |
// |
|
1038 |
TInt WriteToChunk(RChunk* aChunkArray, TUint aChunkArraySize, TInt aChunk, TUint8 aStart=0) |
|
1039 |
{ |
|
1040 |
for (TUint i=0; i<10; i++) // Write to all chunks 10 times |
|
1041 |
{ |
|
1042 |
for (TUint j=0; j < aChunkArraySize; j++) //Write to all open chunks except aChunk. |
|
1043 |
{ |
|
1044 |
if (aChunkArray[j].Handle() != NULL) |
|
1045 |
{ |
|
1046 |
if ((TInt)j == aChunk) // Don't write to specified chunk |
|
1047 |
{ |
|
1048 |
continue; |
|
1049 |
} |
|
1050 |
TUint8* base = aChunkArray[j].Base(); |
|
1051 |
for (TUint8 k = aStart; k < aStart + 10; k++) |
|
1052 |
{ |
|
1053 |
*base++ = k; // write 0 - 9 to the chunk |
|
1054 |
} |
|
1055 |
} |
|
1056 |
} |
|
1057 |
} |
|
1058 |
return KErrNone; |
|
1059 |
} |
|
1060 |
||
1061 |
||
1062 |
// |
|
1063 |
// ReadChunk |
|
1064 |
// |
|
1065 |
// Read chunks - If a chunk is specified, that particular chunk is not read |
|
1066 |
// |
|
1067 |
TInt ReadChunk(RChunk* aChunkArray, TUint aChunkArraySize, TInt aChunk=-1) |
|
1068 |
{ |
|
1069 |
for (TUint j=0; j < aChunkArraySize; j++) //Read all open chunks |
|
1070 |
{ |
|
1071 |
if (aChunkArray[j].Handle() != NULL) |
|
1072 |
{ |
|
1073 |
if ((TInt)j == aChunk) // Don't read specified chunk |
|
1074 |
{ |
|
1075 |
continue; |
|
1076 |
} |
|
1077 |
TUint8* base = aChunkArray[j].Base(); |
|
1078 |
while ((aChunkArray[j].Base() + aChunkArray[j].Size()) != base) |
|
1079 |
{ |
|
1080 |
READ(base++); |
|
1081 |
} |
|
1082 |
} |
|
1083 |
} |
|
1084 |
return KErrNone; |
|
1085 |
} |
|
1086 |
||
1087 |
||
1088 |
// |
|
1089 |
// RemoveChunkAlloc |
|
1090 |
// |
|
1091 |
// Remove ALL chunks allocated |
|
1092 |
// |
|
1093 |
// @param aChunkArray The array that stores a reference to the chunks created. |
|
1094 |
// @param aChunkArraySize The size of aChunkArray. |
|
1095 |
// |
|
1096 |
void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize) |
|
1097 |
{ |
|
1098 |
TInt closedChunks = 0; |
|
1099 |
||
1100 |
if (aChunkArray == NULL) |
|
1101 |
{// The chunk array has already been deleted. |
|
1102 |
return; |
|
1103 |
} |
|
1104 |
||
1105 |
for (TUint i = 0; i < aChunkArraySize; i++) |
|
1106 |
{ |
|
1107 |
if (aChunkArray[i].Handle() != NULL) |
|
1108 |
{ |
|
1109 |
aChunkArray[i].Close(); |
|
1110 |
closedChunks ++; |
|
1111 |
} |
|
1112 |
} |
|
1113 |
delete[] aChunkArray; |
|
1114 |
aChunkArray = NULL; |
|
1115 |
aChunkArraySize = 0; |
|
1116 |
UpdateRamInfo(); |
|
1117 |
test.Printf(_L("Free RAM after closing %d chunks = 0x%x\n"),closedChunks,gFreeRam); |
|
1118 |
} |
|
1119 |
||
1120 |
||
1121 |
TBool SpaceAvailForPageTables(TUint aZoneIndex, TInt aNumPages) |
|
1122 |
{ |
|
1123 |
// Every 1MB allocated needs a new page table |
|
1124 |
const TUint KDataBytesPerPageTable = 1024 * 1024; |
|
1125 |
||
1126 |
// 1 Page can fit 4 page tables |
|
1127 |
const TUint KPageTablesPerPage = 4; |
|
1128 |
||
1129 |
||
1130 |
GetAllPageInfo(); |
|
1131 |
if (aNumPages == KFillAllMovable) |
|
1132 |
{ |
|
1133 |
aNumPages = gTotalPageCount.iFreePages; |
|
1134 |
} |
|
1135 |
||
1136 |
TUint allocBytes = aNumPages << gPageShift; |
|
1137 |
||
1138 |
// Add 1 as you always require at least 1 page table |
|
1139 |
TUint pageTablesRequired = (allocBytes / KDataBytesPerPageTable) + 1; |
|
1140 |
// Add 1 as the first 1-3 page tables may require a new page. |
|
1141 |
TUint pageTablePagesRequired = (pageTablesRequired / KPageTablesPerPage) + 1; |
|
1142 |
||
1143 |
// Determine the number of free pages in the other zones |
|
1144 |
TUint freeInOther = 0; |
|
1145 |
for (TUint index = 0; index < gZoneCount; index++) |
|
1146 |
{ |
|
1147 |
if (index != aZoneIndex) |
|
1148 |
{ |
|
1149 |
freeInOther += gZoneUtilArray[index].iFreePages; |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
1153 |
// Need an overhead for the heap to grow (5 pages) |
|
1154 |
const TUint KOverhead = 5; |
|
1155 |
if (freeInOther < pageTablePagesRequired + KOverhead) |
|
1156 |
{// Not enough space in other zones to fit all page tables |
|
1157 |
test.Printf(_L("No space in other zones for page table pages\n")); |
|
1158 |
return EFalse; |
|
1159 |
} |
|
1160 |
// There is space available in the other zones to fit all the page tables |
|
1161 |
return ETrue; |
|
1162 |
} |
|
1163 |
// |
|
1164 |
// AllocMovable |
|
1165 |
// |
|
1166 |
// Allocate movable memory in the form of chunks |
|
1167 |
// |
|
1168 |
// @param aChunkArray The array to store a reference to the chunks created. |
|
1169 |
// @param aChunkArraySize The size of aChunkArray. |
|
1170 |
// @param aNumChunks The number of chunks to create. |
|
1171 |
// @param aNumPages The size of each chunk. |
|
1172 |
// |
|
1173 |
TInt AllocMovable(RChunk*& aChunkArray, TUint& aChunkArraySize, TInt aNumChunks, TUint aChunkSize=KChunkDefaultSize, TBool aForceFill = ETrue) |
|
1174 |
{ |
|
1175 |
TUint i = 0; |
|
1176 |
TInt r = 0; |
|
1177 |
TUint chunksAllocd = 0; |
|
1178 |
TBool fillAll = EFalse; |
|
1179 |
||
1180 |
TInt numChunks = aNumChunks; |
|
1181 |
UpdateRamInfo(); |
|
1182 |
// Allocate chunks to take up all of memory with the maximum number of chunks |
|
1183 |
if (aNumChunks == KFillAllMovable) |
|
1184 |
{ |
|
1185 |
fillAll = ETrue; |
|
1186 |
if (aChunkSize == KChunkDefaultSize) |
|
1187 |
{ |
|
1188 |
numChunks = KMaxChunks; |
|
1189 |
aChunkSize = gFreeRam / numChunks; |
|
1190 |
} |
|
1191 |
else |
|
1192 |
{ |
|
1193 |
numChunks = gFreeRam / aChunkSize; |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
test.Printf(_L("gFreeRam = 0x%x, aChunkSize = 0x%x, numChunks = %d\n"), gFreeRam, aChunkSize, numChunks); |
|
1198 |
||
1199 |
// Allocate as many chunks as is specified, either with the default chunk size or a specified chunk size |
|
1200 |
if (aChunkArray == NULL) |
|
1201 |
{ |
|
1202 |
aChunkArraySize = numChunks; |
|
1203 |
aChunkArray = new RChunk[aChunkArraySize]; |
|
1204 |
if (aChunkArray == NULL) |
|
1205 |
return KErrNoMemory; |
|
1206 |
} |
|
1207 |
||
1208 |
// Create chunks for each RChunk with a NULL handle. |
|
1209 |
for (i = 0; i < aChunkArraySize; i++) |
|
1210 |
{ |
|
1211 |
if (aChunkArray[i].Handle() == NULL) |
|
1212 |
{ |
|
1213 |
// Keep going even if a chunk creation fails as the flag tests rely |
|
1214 |
// on this. |
|
1215 |
r = aChunkArray[i].CreateLocal(aChunkSize, aChunkSize); |
|
1216 |
if (r != KErrNone && fillAll && aForceFill) |
|
1217 |
{ |
|
1218 |
while (aChunkArray[i].CreateLocal(aChunkSize, aChunkSize) != KErrNone) |
|
1219 |
{ |
|
1220 |
aChunkSize -= gPageSize; |
|
1221 |
} |
|
1222 |
} |
|
1223 |
if (r == KErrNone) |
|
1224 |
{ |
|
1225 |
chunksAllocd++; |
|
1226 |
} |
|
1227 |
} |
|
1228 |
User::After(10); // Wait so that the next chunk gets allocated in the next time slice |
|
1229 |
} |
|
1230 |
test.Printf(_L("Number of chunks allocd = %d\n"),chunksAllocd); |
|
1231 |
return r; |
|
1232 |
} |
|
1233 |
||
1234 |
// |
|
1235 |
// ZoneAllocMovable |
|
1236 |
// |
|
1237 |
// Allocate the specified number of movable pages to a specific zone |
|
1238 |
// If the number of pages is not specified, then fill the specified zone with |
|
1239 |
// movable pages |
|
1240 |
// |
|
1241 |
// @param aChunkArray The array to store a reference to the chunks created. |
|
1242 |
// @param aChunkArraySize The size of aChunkArray. |
|
1243 |
// @param aZoneIndex The zone index to allocate movable pages to. |
|
1244 |
// @param aNumPages The number of movable pages to allocate. |
|
1245 |
// |
|
1246 |
TInt ZoneAllocMovable(RChunk*& aChunkArray, TUint& aChunkArraySize, TUint aZoneIndex, TUint aNumPages = KMaxTUint) |
|
1247 |
{ |
|
1248 |
ResetRamZoneFlags(); |
|
1249 |
TInt r = KErrNone; |
|
1250 |
TUint allocBytes = 0; |
|
1251 |
||
1252 |
if (aNumPages == KMaxTUint) |
|
1253 |
{ |
|
1254 |
aNumPages = gZoneUtilArray[aZoneIndex].iFreePages; |
|
1255 |
} |
|
1256 |
||
1257 |
allocBytes = aNumPages << gPageShift; |
|
1258 |
||
1259 |
if (!SpaceAvailForPageTables(aZoneIndex, aNumPages)) |
|
1260 |
{ |
|
1261 |
return KErrGeneral; |
|
1262 |
} |
|
1263 |
||
1264 |
// Block all other zones from allocation |
|
1265 |
for(TUint index = 0; index < gZoneCount; index++) |
|
1266 |
{ |
|
1267 |
if (index == aZoneIndex) |
|
1268 |
{ |
|
1269 |
r = Ldd.SetZoneFlag(gZoneConfigArray[index].iZoneId, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
1270 |
} |
|
1271 |
else |
|
1272 |
{ |
|
1273 |
r = Ldd.SetZoneFlag(gZoneConfigArray[index].iZoneId, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); |
|
1274 |
} |
|
1275 |
if (r != KErrNone) |
|
1276 |
{ |
|
1277 |
test.Printf(_L("Failed to set RAM zone flag on zone %d r = %d\n"), index, r); |
|
1278 |
return r; |
|
1279 |
} |
|
1280 |
} |
|
1281 |
||
1282 |
// Allocate the movable pages |
|
1283 |
r = AllocMovable(aChunkArray, aChunkArraySize, 1, allocBytes); |
|
1284 |
||
1285 |
ResetRamZoneFlags(); |
|
1286 |
return r; |
|
1287 |
} |
|
1288 |
||
1289 |
// |
|
1290 |
// ZoneAllocDiscard |
|
1291 |
// |
|
1292 |
// Allocate the specified number of discardable pages to a specific zone |
|
1293 |
// |
|
1294 |
// @param aZoneIndex The zone index to allocate discardable pages to. |
|
1295 |
// @param aNumPages The number of discardable pages to allocate. |
|
1296 |
// @param aDisPages On return this will contain the number of discardable pages allocated |
|
1297 |
// |
|
1298 |
TInt ZoneAllocDiscard(TUint aZoneIndex, TUint aNumPages, TInt& aDisPages) |
|
1299 |
{ |
|
1300 |
TInt r = KErrNone; |
|
1301 |
ResetRamZoneFlags(); |
|
1302 |
||
1303 |
for (TUint index = 0; index < gZoneCount; index++) |
|
1304 |
{ |
|
1305 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
1306 |
if (index == aZoneIndex) |
|
1307 |
{ |
|
1308 |
r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
1309 |
} |
|
1310 |
else |
|
1311 |
{ |
|
1312 |
r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); |
|
1313 |
} |
|
1314 |
||
1315 |
if (r != KErrNone) |
|
1316 |
{ |
|
1317 |
test.Printf(_L("Failed to set flag r = %d\n"), r); |
|
1318 |
return r; |
|
1319 |
} |
|
1320 |
} |
|
1321 |
||
1322 |
TUint disBytes = gTotalPageCount.iDiscardablePages + aNumPages << gPageShift; |
|
1323 |
r = AllocDiscardable(aDisPages, disBytes); |
|
1324 |
aDisPages = aDisPages >> gPageShift; |
|
1325 |
if (r != KErrNone) |
|
1326 |
{ |
|
1327 |
test.Printf(_L("Discardable pages not allocated r = %d\n"), r); |
|
1328 |
} |
|
1329 |
ResetRamZoneFlags(); |
|
1330 |
return r; |
|
1331 |
} |
|
1332 |
||
1333 |
// |
|
1334 |
// FreeMovable |
|
1335 |
// |
|
1336 |
// Free movable pages by closing chunks. |
|
1337 |
// The function will close every other chunk so that the movable pages are scattered in every zone |
|
1338 |
// |
|
1339 |
// @param aChunkArray The array that stores reference to the chunks created. |
|
1340 |
// @param aChunkArraySize The size of aChunkArray. |
|
1341 |
// |
|
1342 |
TInt FreeMovable(RChunk* aChunkArray, TUint aChunkArraySize) |
|
1343 |
{ |
|
1344 |
TUint i; |
|
1345 |
TInt closedChunks = 0; |
|
1346 |
||
1347 |
for (i=0; i < aChunkArraySize; i+=2) // Close every other chunk |
|
1348 |
{ |
|
1349 |
if (aChunkArray[i].Handle() != NULL) |
|
1350 |
{ |
|
1351 |
aChunkArray[i].Close(); |
|
1352 |
closedChunks ++; |
|
1353 |
} |
|
1354 |
} |
|
1355 |
UpdateRamInfo(); |
|
1356 |
test.Printf(_L("Free RAM after closing %d chunks = 0x%x\n"),closedChunks,gFreeRam); |
|
1357 |
return KErrNone; |
|
1358 |
} |
|
1359 |
||
1360 |
// |
|
1361 |
// GetBestZone |
|
1362 |
// |
|
1363 |
// Obtains the most preferable zone for allocating a specific type of page |
|
1364 |
// |
|
1365 |
// @param aPageType The page type that we are interested in |
|
1366 |
// @param aBestPrefIndex The index into the preference array for the zone. |
|
1367 |
// |
|
1368 |
// @return KErrNotFound if a zone cannot be found, else the zone index into gZoneUtilArray |
|
1369 |
// |
|
1370 |
TInt GetBestZone(TInt aPageType, TUint* aBestPrefIndex = NULL) |
|
1371 |
{ |
|
1372 |
GetPrefOrder(); |
|
1373 |
||
1374 |
||
1375 |
switch (aPageType) |
|
1376 |
{ |
|
1377 |
case BEST_MOVABLE: |
|
1378 |
case BEST_DISCARDABLE: |
|
1379 |
{ |
|
1380 |
TInt bestIndex = KErrNotFound; |
|
1381 |
TUint bestPrefIndex = 0; |
|
1382 |
TUint curIndex = 0; |
|
1383 |
TInt startIndex = KErrNotFound; |
|
1384 |
TBool zoneFound = EFalse; |
|
1385 |
// Find the least preferable zone that has movable or discardable pages |
|
1386 |
for (TInt prefIndex = gZoneCount - 1; prefIndex >= 0; prefIndex--) |
|
1387 |
{ |
|
1388 |
curIndex = gPrefArray[prefIndex]; |
|
1389 |
if (gZoneUtilArray[curIndex].iAllocMovable || gZoneUtilArray[curIndex].iAllocDiscardable) |
|
1390 |
{ |
|
1391 |
startIndex = prefIndex; |
|
1392 |
break; |
|
1393 |
} |
|
1394 |
} |
|
1395 |
if (startIndex == KErrNotFound) |
|
1396 |
return startIndex; |
|
1397 |
||
1398 |
// Work up the preference list to look for the best zone |
|
1399 |
for (TInt prefIndex = startIndex; prefIndex >= 0; prefIndex--) |
|
1400 |
{ |
|
1401 |
curIndex = gPrefArray[prefIndex]; |
|
1402 |
if (gZoneUtilArray[curIndex].iFreePages) |
|
1403 |
{ |
|
1404 |
bestIndex = curIndex; |
|
1405 |
bestPrefIndex = prefIndex; |
|
1406 |
zoneFound = ETrue; |
|
1407 |
break; |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
// If the zone still isn't found, look down the preference list |
|
1412 |
if (!zoneFound) |
|
1413 |
{ |
|
1414 |
for (TUint prefIndex = startIndex; prefIndex < gZoneCount; prefIndex++) |
|
1415 |
{ |
|
1416 |
curIndex = gPrefArray[prefIndex]; |
|
1417 |
if (gZoneUtilArray[curIndex].iFreePages) |
|
1418 |
{ |
|
1419 |
bestIndex = curIndex; |
|
1420 |
bestPrefIndex = prefIndex; |
|
1421 |
zoneFound = ETrue; |
|
1422 |
break; |
|
1423 |
} |
|
1424 |
} |
|
1425 |
} |
|
1426 |
||
1427 |
test.Printf(_L("leastPref = %d\n"), bestIndex); |
|
1428 |
if (aBestPrefIndex) |
|
1429 |
*aBestPrefIndex = bestPrefIndex; |
|
1430 |
return bestIndex; |
|
1431 |
} |
|
1432 |
||
1433 |
case BEST_FIXED: |
|
1434 |
for (TUint prefIndex = 0; prefIndex < gZoneCount; prefIndex++) |
|
1435 |
{ |
|
1436 |
TUint mostPref = gPrefArray[prefIndex]; |
|
1437 |
if (gZoneUtilArray[mostPref].iFreePages != 0 || |
|
1438 |
gZoneUtilArray[mostPref].iAllocMovable != 0 || |
|
1439 |
gZoneUtilArray[mostPref].iAllocDiscardable != 0) |
|
1440 |
{ |
|
1441 |
test.Printf(_L("mostPref = %d\n"), mostPref); |
|
1442 |
if (aBestPrefIndex) |
|
1443 |
*aBestPrefIndex = prefIndex; |
|
1444 |
return mostPref; |
|
1445 |
} |
|
1446 |
} |
|
1447 |
break; |
|
1448 |
} |
|
1449 |
||
1450 |
test.Printf(_L("Cannot find zone\n")); |
|
1451 |
return KErrNotFound; |
|
1452 |
} |
|
1453 |
||
1454 |
void GetCandList1(TInt aIndex); |
|
1455 |
// |
|
1456 |
// VerifyMovDisAlloc |
|
1457 |
// |
|
1458 |
// Checks that all movable and discardable pages are in the correct RAM zones. |
|
1459 |
// Should only be invoked after a general defragmentation or a general |
|
1460 |
// defragmentation followed by an allocation. |
|
1461 |
// |
|
1462 |
// NOTE - This shouldn't be used to verify RAM if a RAM specific allocation or |
|
1463 |
// zone claim operation has been performed. |
|
1464 |
// |
|
1465 |
// @return KErrNone if RAM layout is good, KErrGeneral if not, KErrNotFound if no |
|
1466 |
// movable or discardable pages are allocated. |
|
1467 |
// |
|
1468 |
TInt VerifyMovDisAlloc() |
|
1469 |
{ |
|
1470 |
GetPrefOrder(); |
|
1471 |
TInt leastInUse = KErrNotFound; |
|
1472 |
TUint requiredMovDis = 0; |
|
1473 |
TUint totalMorePrefInUse = 0; |
|
1474 |
TBool verifySpread = ETrue; |
|
1475 |
TBool prevZoneNotFull = EFalse; |
|
1476 |
||
1477 |
// Determine which is the least prefable RAM zone in use and how many pages |
|
1478 |
// are allocated of each type. |
|
1479 |
for (TInt prefIndex = gZoneCount - 1; prefIndex >= 0; prefIndex--) |
|
1480 |
{ |
|
1481 |
TUint index = gPrefArray[prefIndex]; |
|
1482 |
TUint allocMov = gZoneUtilArray[index].iAllocMovable; |
|
1483 |
TUint allocDis = gZoneUtilArray[index].iAllocDiscardable; |
|
1484 |
TUint allocFixed = gZoneUtilArray[index].iAllocFixed; |
|
1485 |
TESTDEBUG(test.Printf(_L("pref ID 0x%x\n"), gZoneConfigArray[index].iZoneId)); |
|
1486 |
if (allocMov || allocDis || allocFixed) |
|
1487 |
{ |
|
1488 |
TBool zoneNotFull = EFalse; |
|
1489 |
GetCandList1(index); |
|
1490 |
TUint candIndex = 0; |
|
1491 |
for (; candIndex < gZoneCount; candIndex++) |
|
1492 |
{ |
|
1493 |
TInt zoneIndexCand = gCandList1[candIndex]; |
|
1494 |
if (zoneIndexCand == KInvalidCandIndex) |
|
1495 |
{ |
|
1496 |
break; |
|
1497 |
} |
|
1498 |
allocMov += gZoneUtilArray[zoneIndexCand].iAllocMovable; |
|
1499 |
allocDis += gZoneUtilArray[zoneIndexCand].iAllocDiscardable; |
|
1500 |
if (gZoneUtilArray[zoneIndexCand].iFreePages) |
|
1501 |
{ |
|
1502 |
zoneNotFull = ETrue; |
|
1503 |
} |
|
1504 |
} |
|
1505 |
prefIndex -= candIndex - 1; |
|
1506 |
if (leastInUse == KErrNotFound) |
|
1507 |
{// Have found least preferable RAM zone that is in use. |
|
1508 |
leastInUse = index; |
|
1509 |
if (allocFixed) |
|
1510 |
{// The least preferable RAM zone has fixed pages in it so |
|
1511 |
// RAM may be more spread out than is necessary. |
|
1512 |
verifySpread = EFalse; |
|
1513 |
} |
|
1514 |
} |
|
1515 |
else |
|
1516 |
{ |
|
1517 |
if ((allocMov || allocDis) && prevZoneNotFull) |
|
1518 |
{// The previous least preferable RAM zones were not full so shouldn't |
|
1519 |
// be any movable or discardable pages in the RAM zones of this preference. |
|
1520 |
test.Printf(_L("Movable or discardable pages in more preferable RAM zones unnecessarily\n")); |
|
1521 |
return KErrGeneral; |
|
1522 |
} |
|
1523 |
prevZoneNotFull = zoneNotFull; |
|
1524 |
||
1525 |
// Not the least preferable RAM zone so add to total allocatable. |
|
1526 |
totalMorePrefInUse += allocMov + allocDis + gZoneUtilArray[index].iFreePages; |
|
1527 |
} |
|
1528 |
requiredMovDis += allocMov + allocDis; |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
1532 |
if (leastInUse == KErrNotFound) |
|
1533 |
{// No movable or discardable pages are allocated. |
|
1534 |
test.Printf(_L("No in use RAM zones found????\n")); |
|
1535 |
return KErrNotFound; |
|
1536 |
} |
|
1537 |
||
1538 |
if (totalMorePrefInUse > requiredMovDis) |
|
1539 |
{// There enough allocatable pages in the RAM zones below the currently |
|
1540 |
// least preferable RAM in use. |
|
1541 |
test.Printf(_L("Memory is spread out totalMorePref 0x%x required 0x%x\n"), totalMorePrefInUse, requiredMovDis); |
|
1542 |
if (verifySpread) |
|
1543 |
return KErrGeneral; |
|
1544 |
} |
|
1545 |
return KErrNone; |
|
1546 |
} |
|
1547 |
||
1548 |
||
1549 |
// |
|
1550 |
// GetCandList1 |
|
1551 |
// |
|
1552 |
// Populates a list of all zones that have the same preference and the same amount |
|
1553 |
// of immovable pages |
|
1554 |
// |
|
1555 |
void GetCandList1(TInt aIndex) |
|
1556 |
{ |
|
1557 |
for (TUint i=0; i<gZoneCount; i++) |
|
1558 |
{ |
|
1559 |
gCandList1[i] = KInvalidCandIndex; |
|
1560 |
} |
|
1561 |
||
1562 |
TInt candListIndex = 0; |
|
1563 |
GetAllPageInfo(); |
|
1564 |
for (TUint i=0; i<gZoneCount; i++) |
|
1565 |
{ |
|
1566 |
if (ZonesSamePref(aIndex, i)) |
|
1567 |
{ |
|
1568 |
gCandList1[candListIndex] = i; |
|
1569 |
candListIndex ++; |
|
1570 |
} |
|
1571 |
} |
|
1572 |
} |
|
1573 |
||
1574 |
// |
|
1575 |
// GetCandList2 |
|
1576 |
// |
|
1577 |
// Populates a list of all zones that have the same preference and the same amount |
|
1578 |
// of immovable pages |
|
1579 |
// |
|
1580 |
void GetCandList2(TInt aIndex) |
|
1581 |
{ |
|
1582 |
for (TUint i=0; i<gZoneCount; i++) |
|
1583 |
{ |
|
1584 |
gCandList2[i] = KInvalidCandIndex; |
|
1585 |
} |
|
1586 |
||
1587 |
TInt candListIndex = 0; |
|
1588 |
GetAllPageInfo(); |
|
1589 |
for (TUint i=0; i<gZoneCount; i++) |
|
1590 |
{ |
|
1591 |
if (ZonesSamePref(aIndex, i)) |
|
1592 |
{ |
|
1593 |
gCandList2[candListIndex] = i; |
|
1594 |
candListIndex ++; |
|
1595 |
} |
|
1596 |
} |
|
1597 |
} |
|
1598 |
||
1599 |
// |
|
1600 |
// GetCandListFixed1 |
|
1601 |
// |
|
1602 |
// Populates a list of all zones that have the same preference and the same |
|
1603 |
// amount of immovable pages, it will ignore RAM zones that are full of |
|
1604 |
// immovable pages as these are the only RAM zones that fixed pages can't be |
|
1605 |
// allocated into. |
|
1606 |
// |
|
1607 |
void GetCandListFixed1(TInt aIndex) |
|
1608 |
{ |
|
1609 |
for (TUint i=0; i<gZoneCount; i++) |
|
1610 |
{ |
|
1611 |
gCandList1[i] = KInvalidCandIndex; |
|
1612 |
} |
|
1613 |
||
1614 |
TInt candListIndex = 0; |
|
1615 |
GetAllPageInfo(); |
|
1616 |
for (TUint i=0; i<gZoneCount; i++) |
|
1617 |
{ |
|
1618 |
if (ZonesSamePref(aIndex, i) && |
|
1619 |
gZoneUtilArray[i].iAllocFixed + gZoneUtilArray[i].iAllocUnknown != |
|
1620 |
gZoneConfigArray[i].iPhysPages) |
|
1621 |
{ |
|
1622 |
gCandList1[candListIndex] = i; |
|
1623 |
candListIndex ++; |
|
1624 |
} |
|
1625 |
} |
|
1626 |
} |
|
1627 |
||
1628 |
// |
|
1629 |
// MultiGenDefragThreadFunc |
|
1630 |
// |
|
1631 |
// Called when a general defrag is called to run at the same time as another operation |
|
1632 |
// |
|
1633 |
TInt MultiGenDefragThreadFunc(TAny* /*aPtr*/) |
|
1634 |
{ |
|
1635 |
RRamDefragFuncTestLdd Ldd2; |
|
1636 |
TInt r = Ldd2.Open(); |
|
1637 |
if (r != KErrNone) |
|
1638 |
{ |
|
1639 |
RDebug::Printf("Unable to open Ldd2 in MultiGenDefragThreadFunc, r = %d\n", r); |
|
1640 |
return r; |
|
1641 |
} |
|
1642 |
||
1643 |
RThread thisThread = RThread(); |
|
1644 |
thisThread.SetPriority(EPriorityLess); |
|
1645 |
r = Ldd2.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
1646 |
Ldd2.Close(); |
|
1647 |
thisThread.Close(); |
|
1648 |
return r; |
|
1649 |
} |
|
1650 |
||
1651 |
TBool gTestLoop = EFalse; |
|
1652 |
// |
|
1653 |
// MultiLoopGenDefragThreadFunc |
|
1654 |
// |
|
1655 |
// Called when a general defrag is called to run at the same time as another operation |
|
1656 |
// |
|
1657 |
TInt MultiLoopGenDefragThreadFunc(TAny* /*aPtr*/) |
|
1658 |
{ |
|
1659 |
RRamDefragFuncTestLdd Ldd2; |
|
1660 |
TInt r = Ldd2.Open(); |
|
1661 |
if (r != KErrNone) |
|
1662 |
{ |
|
1663 |
RDebug::Printf("Unable to open Ldd2 in MultiLoopGenDefragThreadFunc, r = %d\n", r); |
|
1664 |
return r; |
|
1665 |
} |
|
1666 |
||
1667 |
RThread thisThread = RThread(); |
|
1668 |
thisThread.SetPriority(EPriorityLess); |
|
1669 |
while (gTestLoop) |
|
1670 |
{ |
|
1671 |
r = Ldd2.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
1672 |
if (r != KErrNone) |
|
1673 |
goto threadExit; |
|
1674 |
} |
|
1675 |
threadExit: |
|
1676 |
Ldd2.Close(); |
|
1677 |
thisThread.Close(); |
|
1678 |
return r; |
|
1679 |
} |
|
1680 |
||
1681 |
// |
|
1682 |
// MultiEmptyZoneThreadFunc |
|
1683 |
// |
|
1684 |
// Called when a zone defrag is called to run at the same time as another operation |
|
1685 |
// |
|
1686 |
TInt MultiEmptyZoneThreadFunc(TAny* zoneID) |
|
1687 |
{ |
|
1688 |
RRamDefragFuncTestLdd Ldd2; |
|
1689 |
TInt r = Ldd2.Open(); |
|
1690 |
if (r != KErrNone) |
|
1691 |
{ |
|
1692 |
RDebug::Printf("Unable to open Ldd2 in MultiEmptyZoneThreadFunc, r = %d\n", r); |
|
1693 |
return r; |
|
1694 |
} |
|
1695 |
||
1696 |
RThread thisThread = RThread(); |
|
1697 |
thisThread.SetPriority(EPriorityLess); |
|
1698 |
r = Ldd2.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, (TUint)zoneID); |
|
1699 |
Ldd2.Close(); |
|
1700 |
thisThread.Close(); |
|
1701 |
return r; |
|
1702 |
} |
|
1703 |
||
1704 |
||
1705 |
// |
|
1706 |
// MultiClaimZoneThreadFunc |
|
1707 |
// |
|
1708 |
// Called when a ClaimRamZone is called to run at the same time as another operation |
|
1709 |
// |
|
1710 |
TInt MultiClaimZoneThreadFunc(TAny* zoneID) |
|
1711 |
{ |
|
1712 |
RRamDefragFuncTestLdd Ldd2; |
|
1713 |
TInt r = Ldd2.Open(); |
|
1714 |
if (r != KErrNone) |
|
1715 |
{ |
|
1716 |
RDebug::Printf("Unable to open Ldd2 in MultiClaimZoneThreadFunc, r = %d\n", r); |
|
1717 |
return r; |
|
1718 |
} |
|
1719 |
||
1720 |
RThread thisThread = RThread(); |
|
1721 |
thisThread.SetPriority(EPriorityLess); |
|
1722 |
r = Ldd2.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, (TUint)zoneID); |
|
1723 |
Ldd2.Close(); |
|
1724 |
thisThread.Close(); |
|
1725 |
return r; |
|
1726 |
} |
|
1727 |
||
1728 |
||
1729 |
// |
|
1730 |
// TestAllocStrategies |
|
1731 |
// |
|
1732 |
// Verifying that pages are allocated correctly. All tests rely on a general defragmentation occuring |
|
1733 |
// in TestStart() so that memory is in a defragmented state before the allocations. |
|
1734 |
// |
|
1735 |
//--------------------------------------------------------------------------------------------------------------------- |
|
1736 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0525 |
|
1737 |
//! @SYMTestCaseDesc Verifying that pages are allocated correctly |
|
1738 |
//! @SYMTestType CIT |
|
1739 |
//! @SYMPREQ PREQ308 |
|
1740 |
//! @SYMTestPriority High |
|
1741 |
//! @SYMTestActions |
|
1742 |
//! 1. Allocate one chunk to memory. |
|
1743 |
//! Check which zone the chunk has been allocated to by checking the |
|
1744 |
//! number of movable pages before and after the allocation has taken place. |
|
1745 |
//! 2. Allocate one chunk to memory that is large enough to cause an empty RAM |
|
1746 |
//! zone to be used. |
|
1747 |
//! 3. Allocate a certain number of fixed pages to memory. |
|
1748 |
//! Check which zone the chunk has been allocated to by checking the |
|
1749 |
//! number of fixed pages before and after the allocation has taken place. |
|
1750 |
//! 4. Allocate fixed pages when it is known that discardable pages will need |
|
1751 |
//! to be discarded for the allocation to succeed. |
|
1752 |
//! 5. Allocate fixed pages when it is known that movable pages will need |
|
1753 |
//! to be moved for the allocation to succeed. |
|
1754 |
//! 6. Allocate fixed pages when it is known that movable pages will need |
|
1755 |
//! to be moved for the allocation to succeed, Determine the "best" zone for fixed pages and allocate 1 more |
|
1756 |
//! than that. |
|
1757 |
//! 7. Allocate discardable pages by loading pages that are demand paged. |
|
1758 |
//! Check which zone the memory has been allocated to by checking the number of |
|
1759 |
//! discardable pages before and after the allocation has taken place. |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1760 |
//! 8. Allocate a contiguous fixed page into a zone which is full of movable or discardable pages. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1761 |
//! 9. Allocate a large 1MB aligned chunk with as few pages as possible availiable for page tables, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1762 |
//! then clear to every page in the chunk. This is attempting to ensure that the chunk pages |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1763 |
//! that have page tables associated to them are remapped correctly if the chunk pages have to be |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1764 |
//! moved so page table pages to map other pages in the chunk are allocated in the most preferable |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1765 |
//! ram zones. |
0 | 1766 |
//! |
1767 |
//! @SYMTestExpectedResults |
|
1768 |
//! 1. The memory has been allocated to the most preferred zone with the least amount of |
|
1769 |
//! space accounting for the zone threshold for movable pages. |
|
1770 |
//! 2. The new RAM zone is used and the movable page are allocated into it first then the other |
|
1771 |
//! more preferable RAM zones. |
|
1772 |
//! 3. The fixed pages are allocated to the most preferred zone |
|
1773 |
//! 4. The fixed pages are allocatted to the most preferred zone with free, movable or discardable pages in it. |
|
1774 |
//! 5. The fixed pages are allocatted to the most preferred zone with free, movable or discardable pages in it. |
|
1775 |
//! 6. Extra page is placed in the next preferable to the "best"zone |
|
1776 |
//! 7. Memory is allocated to the most preferred zone with the least amount of |
|
1777 |
//! space accounting for the zone threshold for discardable pages. |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1778 |
//! 8. The fixed page is allocated as it has moved or discarded a page. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1779 |
//! 9. The chunk is cleared succesfully. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1780 |
//! |
0 | 1781 |
//--------------------------------------------------------------------------------------------------------------------- |
1782 |
TInt TestAllocStrategies() |
|
1783 |
{ |
|
1784 |
||
1785 |
test.Start(_L("Test1: Check which zone a movable page has been allocated to ")); |
|
1786 |
TestStart(); //This will perform a general defrag which should tidy up RAM for us |
|
1787 |
gChunkArray1 = new RChunk; |
|
1788 |
gChunkArraySize1 = 1; |
|
1789 |
TBool zoneFound = EFalse; |
|
1790 |
||
1791 |
// Determine if suitable RAM zone exists for testing |
|
1792 |
TInt best = GetBestZone(BEST_MOVABLE); |
|
1793 |
if (best == KErrNotFound) |
|
1794 |
{ |
|
1795 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
1796 |
} |
|
1797 |
else |
|
1798 |
{ |
|
1799 |
test.Printf(_L("best = %d\n"), best); |
|
1800 |
// Populate the candidate list |
|
1801 |
GetCandList2(best); |
|
1802 |
// Allocate 1 movable page |
|
1803 |
GetOriginalPageCount(); |
|
1804 |
if (AllocMovable(gChunkArray1, gChunkArraySize1, 1, gPageSize) != KErrNone) |
|
1805 |
{ |
|
1806 |
test.Printf(_L("Not enough free RAM for test - Skipping...\n")); |
|
1807 |
} |
|
1808 |
else |
|
1809 |
{ |
|
1810 |
GetAllPageInfo(); |
|
1811 |
TInt r = VerifyMovDisAlloc(); |
|
1812 |
// Need to check all candidates to see if page has gone into any one of them |
|
1813 |
for (TUint i=0; i < gZoneCount; i++) |
|
1814 |
{ |
|
1815 |
if (gCandList2[i] == KInvalidCandIndex) |
|
1816 |
{ |
|
1817 |
break; |
|
1818 |
} |
|
1819 |
TUint zoneIndex = gCandList2[i]; |
|
1820 |
if (gOriginalPageCountArray[zoneIndex].iAllocMovable < gZoneUtilArray[zoneIndex].iAllocMovable) |
|
1821 |
{ |
|
1822 |
zoneFound = ETrue; |
|
1823 |
break; |
|
1824 |
} |
|
1825 |
} |
|
1826 |
||
1827 |
if (r == KErrNone && zoneFound) |
|
1828 |
{ |
|
1829 |
test.Printf(_L("Pass: Movable allocated to the zone expected\n")); |
|
1830 |
} |
|
1831 |
else |
|
1832 |
{ |
|
1833 |
test.Printf(_L("Fail: Movable allocated to a zone that was not expected, r %d\n"), r); |
|
1834 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
1835 |
TEST_FAIL; |
|
1836 |
} |
|
1837 |
} |
|
1838 |
} |
|
1839 |
TestEnd(); |
|
1840 |
||
1841 |
test.Next(_L("Test2: Check that movable pages allocated from least preferable RAM zone to be used\n")); |
|
1842 |
TestStart(); |
|
1843 |
gChunkArray1 = new RChunk; |
|
1844 |
gChunkArraySize1 = 1; |
|
1845 |
// Determine if suitable RAM zone exists for testing. |
|
1846 |
TUint bestPrefIndex; |
|
1847 |
best = GetBestZone(BEST_MOVABLE, &bestPrefIndex); |
|
1848 |
TUint morePrefIndex = bestPrefIndex - 1; |
|
1849 |
TUint nextLeastPrefIndex = bestPrefIndex + 1; |
|
1850 |
||
1851 |
||
1852 |
// Check number of free pages in the more preferable zones |
|
1853 |
TUint freeInMorePref = 0; |
|
1854 |
for (TUint i = 0; i < bestPrefIndex; i++) |
|
1855 |
{ |
|
1856 |
freeInMorePref += gZoneUtilArray[gPrefArray[i]].iFreePages; |
|
1857 |
} |
|
1858 |
||
1859 |
test.Printf(_L("freeInMorePref = 0x%x\n"), freeInMorePref); |
|
1860 |
const TUint KHeapOverhead = 5; // Room for kernel heap allocations so they don't affect the page count |
|
1861 |
if (best == KErrNotFound || nextLeastPrefIndex >= gZoneCount || |
|
1862 |
(gZoneUtilArray[gPrefArray[nextLeastPrefIndex]].iFreePages < KHeapOverhead && |
|
1863 |
freeInMorePref < KHeapOverhead)|| |
|
1864 |
gZoneConfigArray[gPrefArray[nextLeastPrefIndex]].iPref == gZoneConfigArray[best].iPref || |
|
1865 |
gZoneConfigArray[gPrefArray[morePrefIndex]].iPref == gZoneConfigArray[best].iPref) |
|
1866 |
{// No less preferable RAM zone or there are more or less preferable of |
|
1867 |
// same preference so re-ordering potential makes verification too complex. |
|
1868 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
1869 |
} |
|
1870 |
else |
|
1871 |
{ |
|
1872 |
// Ensure the zone is almost full as chunks will get allocated in blocks |
|
1873 |
// by almost filling the best zone with fixed pages, leaving a space (e.g. 20 pages) |
|
1874 |
const TUint KSpaceNeeded = 20; |
|
1875 |
if (gZoneUtilArray[best].iFreePages > KSpaceNeeded) |
|
1876 |
{ |
|
1877 |
TUint zoneID = gZoneUtilArray[best].iZoneId; |
|
1878 |
TUint diffAlloc = gZoneUtilArray[best].iFreePages - KSpaceNeeded; |
|
1879 |
TInt r = Ldd.ZoneAllocDiscontiguous(zoneID, diffAlloc); |
|
1880 |
if (r != KErrNone) |
|
1881 |
{ |
|
1882 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
1883 |
TEST_FAIL; |
|
1884 |
} |
|
1885 |
} |
|
1886 |
||
1887 |
||
1888 |
||
1889 |
GetAllPageInfo(); |
|
1890 |
// Update the number of free pages in the more preferable zones |
|
1891 |
freeInMorePref = 0; |
|
1892 |
for (TUint i = 0; i < bestPrefIndex; i++) |
|
1893 |
{ |
|
1894 |
freeInMorePref += gZoneUtilArray[gPrefArray[i]].iFreePages; |
|
1895 |
} |
|
1896 |
TUint origFixed = gTotalPageCount.iFixedPages; |
|
1897 |
||
1898 |
GetOriginalPageCount(); |
|
1899 |
||
1900 |
// Allocate enough movable pages that the next least preferable RAM zone |
|
1901 |
// will need to be used. |
|
1902 |
TUint movPages = gZoneUtilArray[best].iFreePages + 1; |
|
1903 |
TUint movBytes = movPages << gPageShift; |
|
1904 |
TInt r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes); |
|
1905 |
if (r != KErrNone) |
|
1906 |
{ |
|
1907 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
1908 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
1909 |
TEST_FAIL; |
|
1910 |
} |
|
1911 |
||
1912 |
GetAllPageInfo(); |
|
1913 |
TUint curFixed = gTotalPageCount.iFixedPages; |
|
1914 |
TInt difFixed = curFixed - origFixed; |
|
1915 |
||
1916 |
// If there is space in the more preferable zones then they should be allocated starting from |
|
1917 |
// the "best" zone to the more preferable zones, else from the next least preferable zone to the more preferable zones |
|
1918 |
TUint prefIndex; |
|
1919 |
if ((TInt)freeInMorePref > difFixed) |
|
1920 |
{//No new zones should be turned on, allocation should have gone into bestPrefIndex then down towards most preferred zones |
|
1921 |
TUint nextIndex = gPrefArray[nextLeastPrefIndex]; |
|
1922 |
if (gOriginalPageCountArray[best].iAllocMovable >= gZoneUtilArray[best].iAllocMovable || |
|
1923 |
gOriginalPageCountArray[nextIndex].iAllocMovable < gZoneUtilArray[nextIndex].iAllocMovable) |
|
1924 |
{ |
|
1925 |
test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), |
|
1926 |
gOriginalPageCountArray[best].iFreePages, gZoneUtilArray[best].iFreePages, |
|
1927 |
gZoneUtilArray[nextLeastPrefIndex].iFreePages); |
|
1928 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
1929 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
1930 |
TEST_FAIL; |
|
1931 |
} |
|
1932 |
prefIndex = morePrefIndex; |
|
1933 |
} |
|
1934 |
else |
|
1935 |
{// If there are enough free pages in "nextIndex" to fit all movable pages allocated then the movable |
|
1936 |
// page count in "best" should stay the same, else they should be allocated between "nextIndex" and "best". |
|
1937 |
TUint nextIndex = gPrefArray[nextLeastPrefIndex]; |
|
1938 |
test.Printf(_L("nextIndex = %d\n"), nextIndex); |
|
1939 |
if (gOriginalPageCountArray[nextIndex].iAllocMovable >= gZoneUtilArray[nextIndex].iAllocMovable || |
|
1940 |
(gOriginalPageCountArray[nextIndex].iFreePages >= movPages && |
|
1941 |
gOriginalPageCountArray[best].iAllocMovable != gZoneUtilArray[best].iAllocMovable) || |
|
1942 |
(gOriginalPageCountArray[nextIndex].iFreePages < movPages && |
|
1943 |
gOriginalPageCountArray[best].iAllocMovable == gZoneUtilArray[best].iAllocMovable)) |
|
1944 |
{ |
|
1945 |
test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), |
|
1946 |
gOriginalPageCountArray[nextIndex].iFreePages, gZoneUtilArray[nextIndex].iFreePages, |
|
1947 |
gZoneUtilArray[nextIndex].iFreePages); |
|
1948 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
1949 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
1950 |
TEST_FAIL; |
|
1951 |
} |
|
1952 |
prefIndex = bestPrefIndex; |
|
1953 |
} |
|
1954 |
||
1955 |
// Check that movable pages have only been allocated into the more |
|
1956 |
// preferable RAM zones if the less preferable ram zones in use are full. |
|
1957 |
prefIndex++; |
|
1958 |
do |
|
1959 |
{ |
|
1960 |
prefIndex--; |
|
1961 |
TUint indexCurrent = gPrefArray[prefIndex]; |
|
1962 |
TUint indexLessPref = gPrefArray[prefIndex+1]; |
|
1963 |
||
1964 |
if (gOriginalPageCountArray[indexCurrent].iAllocMovable < gZoneUtilArray[indexCurrent].iAllocMovable && |
|
1965 |
gZoneUtilArray[indexLessPref].iFreePages) |
|
1966 |
{// Current in use zone or less preferable than current has free pages so fail |
|
1967 |
test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), |
|
1968 |
gOriginalPageCountArray[best].iFreePages, gZoneUtilArray[best].iFreePages, |
|
1969 |
gZoneUtilArray[nextLeastPrefIndex].iFreePages); |
|
1970 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
1971 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
1972 |
TEST_FAIL; |
|
1973 |
} |
|
1974 |
} |
|
1975 |
while(prefIndex); |
|
1976 |
test.Printf(_L("Pass: Pages allocated to the zone expected\n")); |
|
1977 |
} |
|
1978 |
TestEnd(); |
|
1979 |
||
1980 |
test.Next(_L("Test3: Check which zone a fixed page has been allocated to ")); |
|
1981 |
for (TUint testStep = 0; testStep < 2; testStep++) |
|
1982 |
{ |
|
1983 |
switch (testStep) |
|
1984 |
{ |
|
1985 |
case 0: |
|
1986 |
test.Printf(_L("Testing discontiguous allocations\n")); |
|
1987 |
break; |
|
1988 |
||
1989 |
case 1: |
|
1990 |
test.Printf(_L("Testing contiguous allocations\n")); |
|
1991 |
break; |
|
1992 |
} |
|
1993 |
TestStart(); |
|
1994 |
zoneFound = EFalse; |
|
1995 |
GetOriginalPageCount(); |
|
1996 |
||
1997 |
best = GetBestZone(BEST_FIXED); |
|
1998 |
TESTDEBUG(test.Printf(_L("best = %d\n"), best)); |
|
1999 |
if (best == KErrNotFound) |
|
2000 |
{ |
|
2001 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
2002 |
} |
|
2003 |
else |
|
2004 |
{ |
|
2005 |
GetCandList1(best); |
|
2006 |
TInt allocFixedPages = 1; // Try and allocate just 1 fixed page |
|
2007 |
switch (testStep) |
|
2008 |
{ |
|
2009 |
case 0: |
|
2010 |
Ldd.AllocateFixed(allocFixedPages); |
|
2011 |
break; |
|
2012 |
||
2013 |
case 1: |
|
2014 |
TUint allocFixedBytes = allocFixedPages << gPageShift; |
|
2015 |
Ldd.AllocContiguous(allocFixedBytes); |
|
2016 |
break; |
|
2017 |
} |
|
2018 |
||
2019 |
||
2020 |
GetAllPageInfo(); |
|
2021 |
for (TUint i=0; i<gZoneCount; i++) |
|
2022 |
{ |
|
2023 |
if (gCandList1[i] == KInvalidCandIndex) |
|
2024 |
{ |
|
2025 |
break; |
|
2026 |
} |
|
2027 |
TUint zoneIndex = gCandList1[i]; |
|
2028 |
if (gOriginalPageCountArray[zoneIndex].iAllocFixed + allocFixedPages <= gZoneUtilArray[zoneIndex].iAllocFixed) |
|
2029 |
{ |
|
2030 |
zoneFound = ETrue; |
|
2031 |
break; |
|
2032 |
} |
|
2033 |
} |
|
2034 |
||
2035 |
if (zoneFound) |
|
2036 |
{ |
|
2037 |
test.Printf(_L("Pass: Chunk has been allocated to the zone expected\n")); |
|
2038 |
} |
|
2039 |
else |
|
2040 |
{ |
|
2041 |
test.Printf(_L("Fail: Fixed been allocated to a zone that was not expected\n")); |
|
2042 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
2043 |
TEST_FAIL; |
|
2044 |
} |
|
2045 |
||
2046 |
Ldd.FreeAllFixedPages(); |
|
2047 |
} |
|
2048 |
TestEnd(); |
|
2049 |
} |
|
2050 |
||
2051 |
test.Next(_L("Test4: Check fixed page allocations will discard pages")); |
|
2052 |
for (TUint testStep = 0; testStep < 2; testStep++) |
|
2053 |
{ |
|
2054 |
switch (testStep) |
|
2055 |
{ |
|
2056 |
case 0: |
|
2057 |
test.Printf(_L("Testing discontiguous allocations\n")); |
|
2058 |
break; |
|
2059 |
||
2060 |
case 1: |
|
2061 |
test.Printf(_L("Testing contiguous allocations\n")); |
|
2062 |
break; |
|
2063 |
} |
|
2064 |
TestStart(); |
|
2065 |
TInt discardBytes; |
|
2066 |
TInt r; |
|
2067 |
||
2068 |
if (!gPagedRom) |
|
2069 |
{ |
|
2070 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
2071 |
goto SkipTest4; |
|
2072 |
} |
|
2073 |
||
2074 |
best = GetBestZone(BEST_FIXED); |
|
2075 |
TESTDEBUG(test.Printf(_L("best = %d\n"), best)); |
|
2076 |
if (best == KErrNotFound) |
|
2077 |
{ |
|
2078 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
2079 |
goto SkipTest4; |
|
2080 |
} |
|
2081 |
// Ensure discardable pages in the preferred RAM zone. |
|
2082 |
r = AllocDiscardable(discardBytes); |
|
2083 |
if (r != KErrNone) |
|
2084 |
{ |
|
2085 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2086 |
TEST_FAIL; |
|
2087 |
} |
|
2088 |
if (discardBytes < gPageSize) |
|
2089 |
{// Can't discard any pages so test can't run. |
|
2090 |
test.Printf(_L("Memory too full to perform test - Skipping...\n")); |
|
2091 |
goto SkipTest4; |
|
2092 |
} |
|
2093 |
||
2094 |
// Make sure all RAM zones that the fixed page allocation could potentially |
|
2095 |
// go to have discardable pages allocated in it. |
|
2096 |
GetOriginalPageCount(); |
|
2097 |
GetCandListFixed1(best); |
|
2098 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2099 |
{ |
|
2100 |
if (gCandList1[i] == KInvalidCandIndex) |
|
2101 |
{ |
|
2102 |
break; |
|
2103 |
} |
|
2104 |
TUint zoneIndex = gCandList1[i]; |
|
2105 |
if (gOriginalPageCountArray[zoneIndex].iAllocDiscardable == 0) |
|
2106 |
{ |
|
2107 |
test.Printf(_L("No dicardable pages in one of the candidates RAM zones - Skipping...\n")); |
|
2108 |
goto SkipTest4; |
|
2109 |
} |
|
2110 |
if (gOriginalPageCountArray[zoneIndex].iFreePages != 0) |
|
2111 |
{ |
|
2112 |
test.Printf(_L("Some free pages in candidate RAM zone ID%x\n"), |
|
2113 |
gZoneConfigArray[zoneIndex].iZoneId); |
|
2114 |
CLEANUP(ResetDPCache()); |
|
2115 |
TEST_FAIL; |
|
2116 |
} |
|
2117 |
} |
|
2118 |
||
2119 |
// Allocate 1 fixed page and ensure that it discards a page. |
|
2120 |
switch (testStep) |
|
2121 |
{ |
|
2122 |
case 0: |
|
2123 |
r = Ldd.AllocateFixed(1); |
|
2124 |
break; |
|
2125 |
||
2126 |
case 1: |
|
2127 |
r = Ldd.AllocContiguous(gPageSize); |
|
2128 |
break; |
|
2129 |
} |
|
2130 |
||
2131 |
// Find RAM zone the fixed page was allocated into. |
|
2132 |
GetAllPageInfo(); |
|
2133 |
zoneFound = EFalse; |
|
2134 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2135 |
{ |
|
2136 |
if (gCandList1[i] == KInvalidCandIndex) |
|
2137 |
{ |
|
2138 |
break; |
|
2139 |
} |
|
2140 |
TUint zoneIndex = gCandList1[i]; |
|
2141 |
if (gOriginalPageCountArray[zoneIndex].iAllocFixed < gZoneUtilArray[zoneIndex].iAllocFixed) |
|
2142 |
{ |
|
2143 |
zoneFound = ETrue; |
|
2144 |
if (gOriginalPageCountArray[zoneIndex].iAllocDiscardable <= gZoneUtilArray[zoneIndex].iAllocDiscardable && |
|
2145 |
gOriginalPageCountArray[zoneIndex].iAllocMovable <= gZoneUtilArray[zoneIndex].iAllocMovable) |
|
2146 |
{ |
|
2147 |
test.Printf(_L("Fixed pages allocated but no pages discarded in RAM zone ID 0x%x\n"), |
|
2148 |
gZoneConfigArray[zoneIndex].iZoneId); |
|
2149 |
CLEANUP(ResetDPCache()); |
|
2150 |
TEST_FAIL; |
|
2151 |
} |
|
2152 |
} |
|
2153 |
} |
|
2154 |
||
2155 |
if (!zoneFound || r != KErrNone) |
|
2156 |
{ |
|
2157 |
test.Printf(_L("No fixed pages were allocated r = %d\n"), r); |
|
2158 |
CLEANUP(ResetDPCache()); |
|
2159 |
TEST_FAIL; |
|
2160 |
} |
|
2161 |
else |
|
2162 |
{ |
|
2163 |
test.Printf(_L("Pass: Pages been allocated to the zone expected\n")); |
|
2164 |
} |
|
2165 |
SkipTest4 : |
|
2166 |
// This will free any DP cache pages and fixed pages allocated. |
|
2167 |
TestEnd(); |
|
2168 |
} |
|
2169 |
||
2170 |
||
2171 |
for (TUint testIndex = 0; testIndex < 2; testIndex++) |
|
2172 |
{ |
|
2173 |
switch (testIndex) |
|
2174 |
{ |
|
2175 |
case 0: |
|
2176 |
test.Next(_L("Test5: Check fixed page allocations (discontiguous) will move pages")); |
|
2177 |
break; |
|
2178 |
||
2179 |
case 1: |
|
2180 |
test.Next(_L("Test6: Check fixed page will only go into a new zone if all other fix page zones are full of fix")); |
|
2181 |
break; |
|
2182 |
} |
|
2183 |
||
2184 |
TestStart(); |
|
2185 |
gChunkArray1 = new RChunk; |
|
2186 |
gChunkArraySize1 = 1; |
|
2187 |
TInt r = KErrNone; |
|
2188 |
TUint freeInOtherZones = 0; |
|
2189 |
TUint allocatablePages; |
|
2190 |
TUint allocImmovPages; |
|
2191 |
TUint bestPrefIndex; |
|
2192 |
TUint nextBestIndex = 0; |
|
2193 |
const TUint KMovAllocOverhead = 5; // need pages for page tables and kernel heap expansion. |
|
2194 |
||
2195 |
best = GetBestZone(BEST_FIXED, &bestPrefIndex); |
|
2196 |
TESTDEBUG(test.Printf(_L("best = %d\n"), best)); |
|
2197 |
GetCandListFixed1(best); |
|
2198 |
TUint candidates = 0; |
|
2199 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2200 |
{ |
|
2201 |
if (gCandList1[i] == KInvalidCandIndex) |
|
2202 |
{ |
|
2203 |
break; |
|
2204 |
} |
|
2205 |
candidates++; |
|
2206 |
} |
|
2207 |
if (best == KErrNotFound || |
|
2208 |
(gZoneUtilArray[best].iAllocMovable == 0 && gZoneUtilArray[best].iFreePages < KMovAllocOverhead) || |
|
2209 |
candidates != 1) |
|
2210 |
{ |
|
2211 |
test.Printf(_L("Cannot find zone or too many equal pref zones to perform test - Skipping...\n")); |
|
2212 |
goto SkipTest5; |
|
2213 |
} |
|
2214 |
||
2215 |
if (testIndex == 1) |
|
2216 |
{// need to work out what the next best zone would be |
|
2217 |
GetPrefOrder(); |
|
2218 |
if (bestPrefIndex + 1 >= gZoneCount) |
|
2219 |
{ |
|
2220 |
test.Printf(_L("Cannot find next best zone - Skipping...\n")); |
|
2221 |
goto SkipTest5; |
|
2222 |
} |
|
2223 |
nextBestIndex = gPrefArray[bestPrefIndex + 1]; |
|
2224 |
test.Printf(_L("nextBestIndex= %d\n"), nextBestIndex); |
|
2225 |
GetCandListFixed1(nextBestIndex); |
|
2226 |
candidates = 0; |
|
2227 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2228 |
{ |
|
2229 |
if (gCandList1[i] == KInvalidCandIndex) |
|
2230 |
{ |
|
2231 |
break; |
|
2232 |
} |
|
2233 |
candidates++; |
|
2234 |
} |
|
2235 |
if (gZoneUtilArray[nextBestIndex].iPhysPages == gZoneUtilArray[nextBestIndex].iAllocFixed + |
|
2236 |
gZoneUtilArray[nextBestIndex].iAllocUnknown || |
|
2237 |
candidates != 1) |
|
2238 |
{ |
|
2239 |
test.Printf(_L("Cannot find zone or too many equal pref zones to perform test - Skipping...\n")); |
|
2240 |
goto SkipTest5; |
|
2241 |
} |
|
2242 |
} |
|
2243 |
||
2244 |
||
2245 |
||
2246 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2247 |
{ |
|
2248 |
if (i != (TUint)best) |
|
2249 |
{ |
|
2250 |
freeInOtherZones += gZoneUtilArray[i].iFreePages; |
|
2251 |
} |
|
2252 |
} |
|
2253 |
allocatablePages = gZoneUtilArray[best].iFreePages + |
|
2254 |
gZoneUtilArray[best].iAllocMovable + |
|
2255 |
gZoneUtilArray[best].iAllocDiscardable; |
|
2256 |
||
2257 |
if (allocatablePages > freeInOtherZones) |
|
2258 |
{ |
|
2259 |
test.Printf(_L("Not enough free RAM for test - Skipping...\n")); |
|
2260 |
goto SkipTest5; |
|
2261 |
} |
|
2262 |
||
2263 |
// Allocate the fixed array before getting any page counts |
|
2264 |
r = Ldd.AllocFixedArray(allocatablePages + 1); |
|
2265 |
if (r != KErrNone) |
|
2266 |
{ |
|
2267 |
test.Printf(_L("Failed to allocate fixed array r = %d - Skipping...\n"), r); |
|
2268 |
goto SkipTest5; |
|
2269 |
} |
|
2270 |
||
2271 |
// Fill the RAM zone with movable pages if none already in it. |
|
2272 |
GetAllPageInfo(); |
|
2273 |
if (gZoneUtilArray[best].iAllocMovable == 0) |
|
2274 |
{ |
|
2275 |
if (!gZoneUtilArray[best].iFreePages) |
|
2276 |
{ |
|
2277 |
test.Printf(_L("RAM zone ID %x too full for test - Skipping...\n"), gZoneConfigArray[best].iZoneId); |
|
2278 |
goto SkipTest5; |
|
2279 |
} |
|
2280 |
// Fill the zone with movable pages |
|
2281 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, best); |
|
2282 |
if (r != KErrNone) |
|
2283 |
{ |
|
2284 |
test.Printf(_L("Failed to fill zone index %d with movable r = %d\n"), best, r); |
|
2285 |
CLEANUP(ResetRamZoneFlags()); |
|
2286 |
TEST_FAIL; |
|
2287 |
} |
|
2288 |
||
2289 |
if (GetBestZone(BEST_FIXED) != best) |
|
2290 |
{ |
|
2291 |
test.Printf(_L("Unable to complete test; RAM zone reordering - Skipping...\n")); |
|
2292 |
goto SkipTest5; |
|
2293 |
} |
|
2294 |
} |
|
2295 |
// Allocate fixed pages after reseting the allocation flags. |
|
2296 |
GetAllPageInfo(); |
|
2297 |
ResetRamZoneFlags(); |
|
2298 |
allocatablePages = gZoneUtilArray[best].iFreePages + |
|
2299 |
gZoneUtilArray[best].iAllocMovable + |
|
2300 |
gZoneUtilArray[best].iAllocDiscardable; |
|
2301 |
switch (testIndex) |
|
2302 |
{ |
|
2303 |
case 0: |
|
2304 |
r = Ldd.AllocateFixed2(allocatablePages); |
|
2305 |
GetAllPageInfo(); |
|
2306 |
allocImmovPages = gZoneUtilArray[best].iAllocFixed + gZoneUtilArray[best].iAllocUnknown; |
|
2307 |
if (r != KErrNone || gZoneConfigArray[best].iPhysPages != allocImmovPages) |
|
2308 |
{ |
|
2309 |
test.Printf(_L("RAM zone ID 0x%x not full of immovable pages\n"), gZoneConfigArray[best].iZoneId); |
|
2310 |
CLEANUP(ResetRamZoneFlags()); |
|
2311 |
TEST_FAIL; |
|
2312 |
} |
|
2313 |
else |
|
2314 |
{ |
|
2315 |
test.Printf(_L("Pass: Pages allocated to the zone expected\n")); |
|
2316 |
} |
|
2317 |
break; |
|
2318 |
||
2319 |
case 1: |
|
2320 |
GetOriginalPageCount(); |
|
2321 |
r = Ldd.AllocateFixed2(allocatablePages + 1); |
|
2322 |
GetAllPageInfo(); |
|
2323 |
allocImmovPages = gZoneUtilArray[best].iAllocFixed + gZoneUtilArray[best].iAllocUnknown; |
|
2324 |
if (r != KErrNone || gZoneUtilArray[best].iPhysPages != allocImmovPages || |
|
2325 |
gZoneUtilArray[nextBestIndex].iAllocFixed <= gOriginalPageCountArray[nextBestIndex].iAllocFixed) |
|
2326 |
{ |
|
2327 |
test.Printf(_L("RAM zone ID 0x%x not full of immovable pages or next best ID 0x%x no fix pages\n"), |
|
2328 |
gZoneConfigArray[best].iZoneId, gZoneConfigArray[nextBestIndex].iZoneId); |
|
2329 |
test.Printf(_L("nextBest %d origFix 0x%x curFix 0x%x\n"), |
|
2330 |
nextBestIndex, gOriginalPageCountArray[nextBestIndex].iAllocFixed, |
|
2331 |
gZoneUtilArray[nextBestIndex].iAllocFixed); |
|
2332 |
CLEANUP(ResetRamZoneFlags()); |
|
2333 |
TEST_FAIL; |
|
2334 |
} |
|
2335 |
// Go through every other zone and check that fixed pages haven't increased |
|
2336 |
for (TUint i = 0; i < gZoneCount; i++) |
|
2337 |
{ |
|
2338 |
if (i != (TUint)best && i != (TUint)nextBestIndex && |
|
2339 |
gZoneUtilArray[i].iAllocFixed > gOriginalPageCountArray[i].iAllocFixed) |
|
2340 |
{ |
|
2341 |
test.Printf(_L("FAIL: Fix page count increased zoneIndex %d orig 0x%x current 0x%x\n"), |
|
2342 |
i, gOriginalPageCountArray[i].iAllocFixed, gZoneUtilArray[i].iAllocFixed); |
|
2343 |
CLEANUP(ResetRamZoneFlags()); |
|
2344 |
TEST_FAIL; |
|
2345 |
} |
|
2346 |
} |
|
2347 |
||
2348 |
test.Printf(_L("Pass: Pages allocated to the zone expected\n")); |
|
2349 |
break; |
|
2350 |
} |
|
2351 |
SkipTest5 : |
|
2352 |
// This will perform any required clean up. |
|
2353 |
ResetRamZoneFlags(); |
|
2354 |
TestEnd(); |
|
2355 |
} |
|
2356 |
||
2357 |
test.Next(_L("Test7: Check which zone a discardable page has been allocated to")); |
|
2358 |
TestStart(); |
|
2359 |
if (gPagedRom) |
|
2360 |
{ |
|
2361 |
GetAllPageInfo(); |
|
2362 |
||
2363 |
// Try to allocate just one more discardable page |
|
2364 |
TUint allocBytes = (gTotalPageCount.iDiscardablePages + 1) << gPageShift; |
|
2365 |
TInt discardablePages; |
|
2366 |
||
2367 |
best = GetBestZone(BEST_DISCARDABLE); |
|
2368 |
if (best == KErrNotFound) |
|
2369 |
{ |
|
2370 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
2371 |
} |
|
2372 |
else |
|
2373 |
{ |
|
2374 |
// Populate the candidate list |
|
2375 |
GetCandList2(best); |
|
2376 |
zoneFound = EFalse; |
|
2377 |
GetOriginalPageCount(); |
|
2378 |
TInt r = AllocDiscardable(discardablePages, allocBytes); |
|
2379 |
if (r != KErrNone) |
|
2380 |
{ |
|
2381 |
test.Printf(_L("Fail: r %d\n"), r); |
|
2382 |
CLEANUP(ResetDPCache()); |
|
2383 |
TEST_FAIL; |
|
2384 |
} |
|
2385 |
||
2386 |
r = VerifyMovDisAlloc(); |
|
2387 |
// Need to check all candidates to see if page has gone into any one of them |
|
2388 |
for (TUint i=0; i < gZoneCount; i++) |
|
2389 |
{ |
|
2390 |
if (gCandList2[i] == KInvalidCandIndex) |
|
2391 |
{ |
|
2392 |
break; |
|
2393 |
} |
|
2394 |
TUint zoneIndex = gCandList2[i]; |
|
2395 |
if (gOriginalPageCountArray[zoneIndex].iAllocDiscardable < gZoneUtilArray[zoneIndex].iAllocDiscardable) |
|
2396 |
{ |
|
2397 |
zoneFound = ETrue; |
|
2398 |
break; |
|
2399 |
} |
|
2400 |
} |
|
2401 |
||
2402 |
if (r == KErrNone && zoneFound) |
|
2403 |
{ |
|
2404 |
test.Printf(_L("Pass: Discardable allocated to the zone expected\n")); |
|
2405 |
} |
|
2406 |
else |
|
2407 |
{ |
|
2408 |
test.Printf(_L("Fail: Discardable been allocated to a zone that was not expected r %d\n"), r); |
|
2409 |
CLEANUP(ResetDPCache()); |
|
2410 |
TEST_FAIL; |
|
2411 |
} |
|
2412 |
} |
|
2413 |
} |
|
2414 |
else |
|
2415 |
{ |
|
2416 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
2417 |
} |
|
2418 |
TestEnd(); |
|
2419 |
||
2420 |
test.Next(_L("Test8: Check fixed page allocations (contiguous) will move pages")); |
|
2421 |
TestStart(); |
|
2422 |
gChunkArray1 = new RChunk; |
|
2423 |
gChunkArraySize1 = 1; |
|
2424 |
||
2425 |
TInt r = KErrNone; |
|
2426 |
TUint testZoneIndex = 0; |
|
2427 |
||
2428 |
// Get the most pref zone which is completely free to use as a test zone |
|
2429 |
r = FindMostPrefEmpty(testZoneIndex); |
|
2430 |
if (r != KErrNone) |
|
2431 |
{ |
|
2432 |
test.Printf(_L("Cannot find empty zone - Skipping...\n")); |
|
2433 |
goto skipTest8; |
|
2434 |
} |
|
2435 |
||
2436 |
||
2437 |
// fill the test zone with movable pages |
|
2438 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, testZoneIndex); |
|
2439 |
GetAllPageInfo(); |
|
2440 |
if (r != KErrNone || |
|
2441 |
gZoneUtilArray[testZoneIndex].iAllocMovable != gZoneUtilArray[testZoneIndex].iPhysPages) |
|
2442 |
{ |
|
2443 |
test.Printf(_L("Failed to allocate movable r = %d - Skipping...\n"), r); |
|
2444 |
goto skipTest8; |
|
2445 |
} |
|
2446 |
||
2447 |
if (gTotalPageCount.iFreePages < 1) |
|
2448 |
{ |
|
2449 |
test.Printf(_L("Insufficient memory - totalFreePages = 0x%x - Skipping...\n"), gTotalPageCount.iFreePages); |
|
2450 |
goto skipTest8; |
|
2451 |
} |
|
2452 |
||
2453 |
for (TUint zoneIndex = 0; zoneIndex < gZoneCount; zoneIndex++) |
|
2454 |
{ |
|
2455 |
TUint zoneId = gZoneConfigArray[zoneIndex].iZoneId; |
|
2456 |
if (zoneIndex != testZoneIndex) |
|
2457 |
{ |
|
2458 |
r = Ldd.SetZoneFlag(zoneId, gZoneConfigArray[zoneIndex].iFlags, NO_FIXED_FLAG); |
|
2459 |
if (r != KErrNone) |
|
2460 |
{ |
|
2461 |
test.Printf(_L("Failed to set flag on zone index %d r = %d- Skipping...\n"), zoneIndex, r); |
|
2462 |
goto skipTest8; |
|
2463 |
} |
|
2464 |
} |
|
2465 |
} |
|
2466 |
||
2467 |
//attempt to alloc 1 contiguous fixed page |
|
2468 |
r = Ldd.AllocContiguous(gPageSize); |
|
2469 |
GetAllPageInfo(); |
|
2470 |
if (r != KErrNone || |
|
2471 |
!gZoneUtilArray[testZoneIndex].iAllocFixed) |
|
2472 |
{ |
|
2473 |
test.Printf(_L("FAIL: no fixed pages in testZoneIndex(%d) r = %d\n"), testZoneIndex, r); |
|
2474 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
2475 |
TEST_FAIL; |
|
2476 |
} |
|
2477 |
else |
|
2478 |
{ |
|
2479 |
test.Printf(_L("Passed...\n")); |
|
2480 |
} |
|
2481 |
||
2482 |
skipTest8: |
|
2483 |
TestEnd(); |
|
2484 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2485 |
test.Next(_L("Test9: Allocate a large 1MB aligned chunk and touch all its pages")); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2486 |
TestStart(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2487 |
gChunkArray1 = new RChunk; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2488 |
gChunkArraySize1 = 1; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2489 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2490 |
GetAllPageInfo(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2491 |
const TUint KChunkBytes = 0x100000; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2492 |
const TUint KChunkMask = KChunkBytes - 1; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2493 |
TUint freeBytes = gTotalPageCount.iFreePages << gPageShift; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2494 |
TUint chunkSize = freeBytes & ~KChunkMask; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2495 |
// Fill as much memory as possible with fixed pages while still allowing the movable allocation to succeed. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2496 |
// This should help force the page table allocation for the chunk to need to move pages. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2497 |
TUint fixedSize = freeBytes - chunkSize; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2498 |
r = KErrNoMemory; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2499 |
while (r != KErrNone && fixedSize) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2500 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2501 |
Ldd.FreeAllFixedPages(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2502 |
fixedSize -= gPageSize; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2503 |
test.Printf(_L("fixedSize 0x%x\n"), fixedSize); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2504 |
r = Ldd.AllocateFixed(fixedSize >> gPageShift); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2505 |
if (r != KErrNone) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2506 |
break; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2507 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, gChunkArraySize1, chunkSize); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2508 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2509 |
if (r == KErrNone) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2510 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2511 |
// Touch every page in the chunk. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2512 |
memclr(gChunkArray1->Base(), chunkSize); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2513 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2514 |
TestEnd(); // This will free any chunk and fixed pages. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
2515 |
|
0 | 2516 |
test.End(); |
2517 |
return KErrNone; |
|
2518 |
} |
|
2519 |
||
2520 |
||
2521 |
// |
|
2522 |
// TestMovingPages |
|
2523 |
// |
|
2524 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2525 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0526 |
|
2526 |
//! @SYMTestType CIT |
|
2527 |
//! @SYMTestCaseDesc Verifying that pages are moved correctly |
|
2528 |
//! @SYMPREQ PREQ308 |
|
2529 |
//! @SYMTestPriority High |
|
2530 |
//! @SYMTestActions |
|
2531 |
//! 1. Fragment the memory. Write to all chunks apart from chunk 9. |
|
2532 |
//! Following this start a RAM defrag and whilst defrag is running write to chunk 9. |
|
2533 |
//! 2. Fragment the memory. Start a RAM defrag and whilst defrag is running |
|
2534 |
//! continuously write different values to the chunks. |
|
2535 |
//! 3. Fragment the memory. Following this start a RAM defrag and whilst this |
|
2536 |
//! is happening, continuously read from all chunks. |
|
2537 |
//! 4. Allocate some movable pages. Call a device driver that will allocate fixed |
|
2538 |
//! pages and write values to these fixed pages. |
|
2539 |
//! Close every other chunk so that only 5 chunks are now still open. |
|
2540 |
//! Following this perform a RAM defrag. |
|
2541 |
//! Read from the fixed pages that were originally written to, ensuring |
|
2542 |
//! that they have not changed. |
|
2543 |
//! 5. Without starting any processes, allocate discardable pages by loading |
|
2544 |
//! pages that are demand paged. |
|
2545 |
//! Read each of the constants from beginning to end. |
|
2546 |
//! Following this perform a RAM defrag. |
|
2547 |
//! |
|
2548 |
//! @SYMTestExpectedResults |
|
2549 |
//! 1. Zones are emptied |
|
2550 |
//! 2. Zones are emptied |
|
2551 |
//! 3. Zones are emptied |
|
2552 |
//! 4. The values written to the fixed pages have not changed. |
|
2553 |
//! 5. Zones are emptied |
|
2554 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2555 |
TInt TestMovingPages() |
|
2556 |
{ |
|
2557 |
const TInt KAllChunks = -1; // Specifies that all chunks should be written to |
|
2558 |
||
2559 |
test.Start(_L("Test1: Whilst moving page, change the usage ")); |
|
2560 |
TestStart(); |
|
2561 |
||
2562 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); |
|
2563 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2564 |
||
2565 |
// Find a chunk that exists |
|
2566 |
TInt chunkIndex = gChunkArraySize1 - 1; |
|
2567 |
for (; chunkIndex >= 0 && gChunkArray1[chunkIndex].Handle() == NULL; chunkIndex--); |
|
2568 |
if (chunkIndex < 0) |
|
2569 |
{ |
|
2570 |
test.Printf(_L("No chunks were allocated\n")); |
|
2571 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2572 |
TEST_FAIL; |
|
2573 |
} |
|
2574 |
||
2575 |
WriteToChunk(gChunkArray1, gChunkArraySize1, chunkIndex); |
|
2576 |
||
2577 |
TInt r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
2578 |
if (r != KErrNone) |
|
2579 |
{ |
|
2580 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2581 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2582 |
TEST_FAIL; |
|
2583 |
} |
|
2584 |
gTestThread.Logon(status); |
|
2585 |
gTestThread.Resume(); |
|
2586 |
||
2587 |
TUint8* base = gChunkArray1[chunkIndex].Base(); |
|
2588 |
while (status.Int() == KRequestPending) |
|
2589 |
{ |
|
2590 |
User::After(10000); |
|
2591 |
for (TInt8 k = 0; k < 10; k ++) |
|
2592 |
{ |
|
2593 |
if (base == gChunkArray1[chunkIndex].Base() + gChunkArray1[chunkIndex].Size()) |
|
2594 |
{ |
|
2595 |
base = gChunkArray1[chunkIndex].Base(); |
|
2596 |
} |
|
2597 |
*base++ = k; // write 0 - 9 to the chunk |
|
2598 |
} |
|
2599 |
} |
|
2600 |
||
2601 |
User::WaitForRequest(status); |
|
2602 |
r = status.Int(); |
|
2603 |
TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); |
|
2604 |
||
2605 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2606 |
||
2607 |
if (r == KErrNone) |
|
2608 |
{ |
|
2609 |
test.Printf(_L("Correct return value\n")); |
|
2610 |
test.Printf(_L("Passed...\n")); |
|
2611 |
} |
|
2612 |
else |
|
2613 |
{ |
|
2614 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
2615 |
TEST_FAIL; |
|
2616 |
} |
|
2617 |
||
2618 |
gTestThread.Close(); |
|
2619 |
TestEnd(); |
|
2620 |
||
2621 |
||
2622 |
test.Next(_L("Test2: Whilst moving page, change the contents of the page")); |
|
2623 |
TestStart(); |
|
2624 |
||
2625 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); |
|
2626 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2627 |
WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks); |
|
2628 |
||
2629 |
r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
2630 |
if (r != KErrNone) |
|
2631 |
{ |
|
2632 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2633 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2634 |
TEST_FAIL; |
|
2635 |
} |
|
2636 |
gTestThread.Logon(status); |
|
2637 |
gTestThread.Resume(); |
|
2638 |
||
2639 |
TUint8 startValue = 0; |
|
2640 |
while (status.Int() == KRequestPending) |
|
2641 |
{ |
|
2642 |
User::After(10000); |
|
2643 |
WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks, startValue); |
|
2644 |
if (++startValue > 245) |
|
2645 |
{ |
|
2646 |
startValue = 0; |
|
2647 |
} |
|
2648 |
} |
|
2649 |
||
2650 |
User::WaitForRequest(status); |
|
2651 |
r = status.Int(); |
|
2652 |
TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); |
|
2653 |
||
2654 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2655 |
||
2656 |
if (r == KErrNone) |
|
2657 |
{ |
|
2658 |
test.Printf(_L("Correct return value\n")); |
|
2659 |
test.Printf(_L("Passed...\n")); |
|
2660 |
} |
|
2661 |
else |
|
2662 |
{ |
|
2663 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
2664 |
TEST_FAIL; |
|
2665 |
} |
|
2666 |
||
2667 |
gTestThread.Close(); |
|
2668 |
TestEnd(); |
|
2669 |
||
2670 |
||
2671 |
test.Next(_L("Test3: Whilst moving page, read pages")); |
|
2672 |
TestStart(); |
|
2673 |
||
2674 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); |
|
2675 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2676 |
WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks); |
|
2677 |
||
2678 |
r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
2679 |
if (r != KErrNone) |
|
2680 |
{ |
|
2681 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2682 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2683 |
TEST_FAIL; |
|
2684 |
} |
|
2685 |
gTestThread.Logon(status); |
|
2686 |
gTestThread.Resume(); |
|
2687 |
||
2688 |
while (status.Int() == KRequestPending) |
|
2689 |
{ |
|
2690 |
User::After(100000000); |
|
2691 |
ReadChunk(gChunkArray1, gChunkArraySize1); |
|
2692 |
} |
|
2693 |
||
2694 |
User::WaitForRequest(status); |
|
2695 |
r = status.Int(); |
|
2696 |
TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); |
|
2697 |
||
2698 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2699 |
||
2700 |
if (r == KErrNone) |
|
2701 |
{ |
|
2702 |
test.Printf(_L("Correct return value\n")); |
|
2703 |
test.Printf(_L("Passed...\n")); |
|
2704 |
} |
|
2705 |
else |
|
2706 |
{ |
|
2707 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2708 |
TEST_FAIL; |
|
2709 |
} |
|
2710 |
||
2711 |
gTestThread.Close(); |
|
2712 |
TestEnd(); |
|
2713 |
||
2714 |
test.Next(_L("Test4: Allocate fixed pages and then perform a defrag")); |
|
2715 |
TestStart(); |
|
2716 |
||
2717 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
2718 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2719 |
||
2720 |
Ldd.AllocateFixedWrite(FILL_ALL_FIXED); |
|
2721 |
||
2722 |
GetOriginalPageCount(); |
|
2723 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
2724 |
test.Printf(_L("defrag returns %d\n"), r); |
|
2725 |
||
2726 |
if (CheckZonesSwitchedOff() != EFalse) |
|
2727 |
{ |
|
2728 |
test.Printf(_L("Fail: Zones were switched off when they shouldn't have been\n")); |
|
2729 |
CLEANUP(r = Ldd.FreeAllFixedPagesRead()); |
|
2730 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2731 |
TEST_FAIL; |
|
2732 |
} |
|
2733 |
else |
|
2734 |
{ |
|
2735 |
test.Printf(_L("Passed...\n")); |
|
2736 |
} |
|
2737 |
r = Ldd.FreeAllFixedPagesRead(); |
|
2738 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2739 |
TestEnd(); |
|
2740 |
||
2741 |
test.Next(_L("Test5: Allocate discardable pages and then perform a defrag")); |
|
2742 |
TestStart(); |
|
2743 |
if (gPagedRom) |
|
2744 |
{ |
|
2745 |
TInt discardablePages; |
|
2746 |
||
2747 |
UpdateRamInfo(); |
|
2748 |
r = AllocDiscardable(discardablePages); |
|
2749 |
if (r != KErrNone) |
|
2750 |
{ |
|
2751 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2752 |
TEST_FAIL; |
|
2753 |
} |
|
2754 |
TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); |
|
2755 |
||
2756 |
GetOriginalPageCount(); |
|
2757 |
TBool genSucceed = CanGenSucceed(); |
|
2758 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
2759 |
||
2760 |
TESTDEBUG(test.Printf(_L("defrag returns %d\n"), r)); |
|
2761 |
||
2762 |
if (genSucceed && CheckZonesSwitchedOff() == EFalse) |
|
2763 |
{ |
|
2764 |
test.Printf(_L("Fail: Zones were not switched off when they should have been\n")); |
|
2765 |
CLEANUP(ResetDPCache()); |
|
2766 |
TEST_FAIL; |
|
2767 |
} |
|
2768 |
else |
|
2769 |
{ |
|
2770 |
test.Printf(_L("Passed...\n")); |
|
2771 |
} |
|
2772 |
ResetDPCache(); |
|
2773 |
||
2774 |
} |
|
2775 |
else |
|
2776 |
{ |
|
2777 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
2778 |
} |
|
2779 |
TestEnd(); |
|
2780 |
||
2781 |
test.End(); |
|
2782 |
return 0; |
|
2783 |
} |
|
2784 |
||
2785 |
||
2786 |
// |
|
2787 |
// TestMovPgsDefrag |
|
2788 |
// |
|
2789 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2790 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0527 |
|
2791 |
//! @SYMTestType CIT |
|
2792 |
//! @SYMTestCaseDesc Verifying the moving of pages in the defrag implmentation |
|
2793 |
//! @SYMPREQ PREQ308 |
|
2794 |
//! @SYMTestPriority High |
|
2795 |
//! @SYMTestActions |
|
2796 |
//! 1. Fragment the memory. Following this perform a RAM defrag. |
|
2797 |
//! Now that all movable memory has now been moved and the relevant source |
|
2798 |
//! zones have been switched off, again attempt to perform a RAM defrag. |
|
2799 |
//! 2. Fragment the memory. Following this perform a RAM defrag and whilst |
|
2800 |
//! this is happening, continuously create more chunks. |
|
2801 |
//! 3. Set up memory so that there are a mix of movable and free pages in a low preference zone, with there |
|
2802 |
//! being movable pages in the higher preference zones. Following this call a general defrag |
|
2803 |
//! 4. Set up memory so that there are a mix of movable and free pages and a couple of free pages |
|
2804 |
//! in a low preference zone, with there being enough free pages in the higher preference zones for the |
|
2805 |
//! pages to be moved to. Following this call a general defrag |
|
2806 |
//! 5. Set up memory so that there is a fixed page and a movable page in an empty zone (testZone). Also ensure that |
|
2807 |
//! there are movable and free pages in more preferable zones than the test zone. Following this call a general |
|
2808 |
//! defrag |
|
2809 |
//! 6. Set up memory so that the mostPrefZone contains movable and free pages. Allocate 1 movable and 1 fixed |
|
2810 |
//! page into an empty zone (testZone). Following this call a general defrag. |
|
2811 |
//! |
|
2812 |
//! @SYMTestExpectedResults |
|
2813 |
//! 1. Second defrag does not empty any zones |
|
2814 |
//! 2. No zones have been emptied |
|
2815 |
//! 3. Zones are emptied if the general defrag can succeed |
|
2816 |
//! 4. Defrag fills up the less preferable zones first |
|
2817 |
//! 5. movable pages are moved from the testZone |
|
2818 |
//! 6. testZone is not emptied |
|
2819 |
//--------------------------------------------------------------------------------------------------------------------- |
|
2820 |
TInt TestMovPgsDefrag() |
|
2821 |
{ |
|
2822 |
TInt r = KErrNone; |
|
2823 |
||
2824 |
test.Start(_L("Test1: Performing a defrag twice")); |
|
2825 |
TestStart(); |
|
2826 |
||
2827 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
2828 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2829 |
||
2830 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
2831 |
TESTDEBUG(test.Printf(_L("After calling general defrag r = %d\n"), r)); |
|
2832 |
||
2833 |
r = VerifyMovDisAlloc(); |
|
2834 |
// The first defrag should empty zones if the general can succeed |
|
2835 |
if (r != KErrNone) |
|
2836 |
{ |
|
2837 |
test.Printf(_L("Fail: r = %d, memory is not laid out as expected\n"), r); |
|
2838 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2839 |
TEST_FAIL; |
|
2840 |
} |
|
2841 |
||
2842 |
GetOriginalPageCount(); |
|
2843 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
2844 |
||
2845 |
TESTDEBUG(test.Printf(_L("After calling general defrag again r = %d\n"), r)); |
|
2846 |
||
2847 |
// The second call to general defrag should have nothing further to do |
|
2848 |
if (r != KErrNone || CheckZonesSwitchedOff() != EFalse) |
|
2849 |
{ |
|
2850 |
test.Printf(_L("Fail: r = %d, expected = %d, or zones have been switched off \n"), |
|
2851 |
r, KErrNone); |
|
2852 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2853 |
TEST_FAIL; |
|
2854 |
} |
|
2855 |
else |
|
2856 |
{ |
|
2857 |
test.Printf(_L("Passed...\n")); |
|
2858 |
} |
|
2859 |
||
2860 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2861 |
TestEnd(); |
|
2862 |
||
2863 |
||
2864 |
||
2865 |
test.Next(_L("Test2: Ensure new memory allocations can occur successfully during a general defrag")); |
|
2866 |
TestStart(); |
|
2867 |
||
2868 |
// Create a thread to call Defrag continuously and resume it |
|
2869 |
r = gTestThread.Create(gTestThreadName,MultiLoopGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
2870 |
if (r != KErrNone) |
|
2871 |
{ |
|
2872 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
2873 |
TEST_FAIL; |
|
2874 |
} |
|
2875 |
gTestThread.Logon(status); |
|
2876 |
gTestLoop = ETrue; |
|
2877 |
gTestThread.Resume(); |
|
2878 |
||
2879 |
// Whilst the defrag loop is taking place, continuously allocate and free memory |
|
2880 |
for (TInt i = 0; i < 100; i++) |
|
2881 |
{ |
|
2882 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
2883 |
if (r != KErrNone) |
|
2884 |
break; |
|
2885 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2886 |
} |
|
2887 |
gTestLoop = EFalse; |
|
2888 |
User::WaitForRequest(status); |
|
2889 |
TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); |
|
2890 |
||
2891 |
if (r != KErrNone || status.Int() != KErrNone) |
|
2892 |
{ |
|
2893 |
test.Printf(_L("Fail: r = %d, status.Int() = %d\n"), r, status.Int()); |
|
2894 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2895 |
TEST_FAIL; |
|
2896 |
} |
|
2897 |
else |
|
2898 |
{ |
|
2899 |
test.Printf(_L("Passed...\n")); |
|
2900 |
} |
|
2901 |
||
2902 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2903 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
2904 |
gTestThread.Close(); |
|
2905 |
TestEnd(); |
|
2906 |
||
2907 |
||
2908 |
test.Next(_L("Test3: Check whether RAM defrag switches off any zones")); |
|
2909 |
TestStart(); |
|
2910 |
||
2911 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
2912 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
2913 |
||
2914 |
GetOriginalPageCount(); |
|
2915 |
TBool genSucceed = CanGenSucceed(); |
|
2916 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
2917 |
||
2918 |
TESTDEBUG(test.Printf(_L("After calling zone defrag r = %d\n"), r)); |
|
2919 |
||
2920 |
if (r != KErrNone || (genSucceed && CheckZonesSwitchedOff() == EFalse)) |
|
2921 |
{ |
|
2922 |
test.Printf(_L("Fail: No zones were switched off or r = %d, expected = %d\n"), r, KErrNone); |
|
2923 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
2924 |
TEST_FAIL; |
|
2925 |
} |
|
2926 |
else |
|
2927 |
{ |
|
2928 |
test.Printf(_L("Passed...\n")); |
|
2929 |
} |
|
2930 |
||
2931 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
2932 |
TestEnd(); |
|
2933 |
||
2934 |
||
2935 |
test.Next(_L("Test4: Verify that a general defrag moves pages to the least preferable RAM zone in use")); |
|
2936 |
TestStart(); |
|
2937 |
gChunkArray1 = new RChunk; |
|
2938 |
gChunkArraySize1 = 1; |
|
2939 |
// Get the preference order |
|
2940 |
GetPrefOrder(); |
|
2941 |
||
2942 |
TUint mostPrefIndex = 0; |
|
2943 |
TUint mostPrefArrayIndex = 0; |
|
2944 |
TUint totMov = 0; |
|
2945 |
TUint lastPrefIndex = 0; |
|
2946 |
TUint lastPrefArrayIndex = 0; |
|
2947 |
TUint movPages = 0; |
|
2948 |
TUint movBytes = 0; |
|
2949 |
TUint totFreeInTestZones = 0; |
|
2950 |
TBool zoneNotEmptyOrFull = EFalse; |
|
2951 |
||
2952 |
||
2953 |
// Find the first most pref zone that has free pages in it |
|
2954 |
r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); |
|
2955 |
if (r != KErrNone) |
|
2956 |
{ |
|
2957 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
2958 |
goto skipTest4; |
|
2959 |
} |
|
2960 |
||
2961 |
// Find the next most preferable free zone |
|
2962 |
lastPrefArrayIndex = mostPrefArrayIndex + 1; |
|
2963 |
||
2964 |
while (lastPrefArrayIndex < gZoneCount && |
|
2965 |
gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iFreePages != gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iPhysPages) |
|
2966 |
{ |
|
2967 |
lastPrefArrayIndex++; |
|
2968 |
} |
|
2969 |
||
2970 |
if (lastPrefArrayIndex >= gZoneCount) |
|
2971 |
{ |
|
2972 |
test.Printf(_L("Skipping...\n")); |
|
2973 |
goto skipTest4; |
|
2974 |
} |
|
2975 |
||
2976 |
// Block all other zones |
|
2977 |
for (TUint prefIndex = lastPrefArrayIndex + 1; prefIndex < gZoneCount; prefIndex++) |
|
2978 |
{ |
|
2979 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
2980 |
Ldd.SetZoneFlag(gZoneConfigArray[zoneIndex].iZoneId, gZoneConfigArray[zoneIndex].iFlags, NO_ALLOC_FLAG); |
|
2981 |
} |
|
2982 |
||
2983 |
||
2984 |
// Zone alloc to fill half of the last zone under test |
|
2985 |
GetAllPageInfo(); |
|
2986 |
lastPrefIndex = gPrefArray[lastPrefArrayIndex]; |
|
2987 |
r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[lastPrefIndex].iZoneId, gZoneUtilArray[lastPrefIndex].iFreePages >> 1); |
|
2988 |
if (r != KErrNone) |
|
2989 |
{ |
|
2990 |
test.Printf(_L("Failed to allocate fixed pages r = %d - Skipping...\n"), r); |
|
2991 |
goto skipTest4; |
|
2992 |
} |
|
2993 |
||
2994 |
||
2995 |
// Go through the zones under test and determine the number of free pages |
|
2996 |
GetAllPageInfo(); |
|
2997 |
for(TUint prefIndex = mostPrefArrayIndex; prefIndex <= lastPrefArrayIndex; prefIndex++) |
|
2998 |
{ |
|
2999 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
3000 |
totFreeInTestZones += gZoneUtilArray[zoneIndex].iFreePages; |
|
3001 |
} |
|
3002 |
||
3003 |
// Allocate movable pages to almost fill zones under test |
|
3004 |
movPages = totFreeInTestZones; |
|
3005 |
movBytes = movPages << gPageShift; |
|
3006 |
while (movBytes && AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes) != KErrNone) |
|
3007 |
{ |
|
3008 |
movBytes -= gPageSize; |
|
3009 |
movPages--; |
|
3010 |
} |
|
3011 |
if (!movBytes) |
|
3012 |
{ |
|
3013 |
test.Printf(_L("Failed to allocate 0x%x movable pages - Skipping...\n"), movPages); |
|
3014 |
goto skipTest4; |
|
3015 |
} |
|
3016 |
||
3017 |
||
3018 |
// Free the allocated fixed pages |
|
3019 |
Ldd.FreeAllFixedPages(); |
|
3020 |
||
3021 |
// Reset all the flags |
|
3022 |
ResetRamZoneFlags(); |
|
3023 |
||
3024 |
// Check that the most preferable zone still has movable pages in it |
|
3025 |
// and also check that the last zone under test has free pages in it |
|
3026 |
GetAllPageInfo(); |
|
3027 |
if (gTotalPageCount.iMovablePages < movPages || |
|
3028 |
gZoneUtilArray[mostPrefIndex].iAllocMovable == 0 || |
|
3029 |
gZoneUtilArray[lastPrefIndex].iFreePages == 0) |
|
3030 |
{ |
|
3031 |
test.Printf(_L("Setup failed - Skipping...\n")); |
|
3032 |
goto skipTest4; |
|
3033 |
} |
|
3034 |
||
3035 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3036 |
// Check that defrag allocated the movable from the less preferable to the more preferable |
|
3037 |
GetPrefOrder(); |
|
3038 |
totMov = gTotalPageCount.iMovablePages; |
|
3039 |
for(TInt prefIndex = gZoneCount - 1; prefIndex >= 0 ; prefIndex--) |
|
3040 |
{ |
|
3041 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
3042 |
GetCandList1(zoneIndex); |
|
3043 |
TUint candIndex = 0; |
|
3044 |
for (; candIndex < gZoneCount; candIndex++) |
|
3045 |
{// Check all the zones of this preference |
|
3046 |
TInt zoneIndexCand = gCandList1[candIndex]; |
|
3047 |
if (zoneIndexCand == KInvalidCandIndex) |
|
3048 |
{ |
|
3049 |
break; |
|
3050 |
} |
|
3051 |
totMov -= gZoneUtilArray[zoneIndexCand].iAllocMovable; |
|
3052 |
if (gZoneUtilArray[zoneIndexCand].iFreePages != gZoneUtilArray[zoneIndexCand].iPhysPages && |
|
3053 |
gZoneUtilArray[zoneIndexCand].iFreePages != 0) |
|
3054 |
{ |
|
3055 |
zoneNotEmptyOrFull = ETrue; |
|
3056 |
} |
|
3057 |
} |
|
3058 |
prefIndex -= candIndex - 1 ; |
|
3059 |
||
3060 |
if (zoneNotEmptyOrFull && totMov != 0) |
|
3061 |
{ |
|
3062 |
test.Printf(_L("FAIL: index = %d free = 0x%x totMov = 0x%x\n"), |
|
3063 |
zoneIndex, gZoneUtilArray[zoneIndex].iFreePages, totMov); |
|
3064 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3065 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
3066 |
TEST_FAIL; |
|
3067 |
} |
|
3068 |
} |
|
3069 |
||
3070 |
skipTest4: |
|
3071 |
TestEnd(); |
|
3072 |
||
3073 |
||
3074 |
test.Next(_L("Test5: Verify that a general defrag tidies up if RAM zone to be emptied contains fixed pages")); |
|
3075 |
TestStart(); |
|
3076 |
gChunkArray1 = new RChunk; |
|
3077 |
gChunkArraySize1 = 1; |
|
3078 |
gChunkArray2 = new RChunk; |
|
3079 |
gChunkArraySize2 = 1; |
|
3080 |
||
3081 |
// find 2 empty zones - put 1 movable in 1 of them and 1 movable and 1 fixed in the other |
|
3082 |
TUint testZoneIndex1; |
|
3083 |
TUint testZoneIndex2; |
|
3084 |
TUint testZoneID2; |
|
3085 |
TUint numFreeInUse = 0; |
|
3086 |
||
3087 |
r = FindMostPrefEmpty(testZoneIndex1); |
|
3088 |
if (r != KErrNone) |
|
3089 |
{ |
|
3090 |
test.Printf(_L("Skipping...\n")); |
|
3091 |
goto skipTest5; |
|
3092 |
} |
|
3093 |
// Allocate 1 movable page to the test zone |
|
3094 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, testZoneIndex1, 1); |
|
3095 |
if (r != KErrNone) |
|
3096 |
{ |
|
3097 |
test.Printf(_L("Failed to allocate 1 movable page to zone index %d, r = %d - Skipping...\n"), testZoneIndex1, r); |
|
3098 |
goto skipTest5; |
|
3099 |
} |
|
3100 |
||
3101 |
r = FindMostPrefEmpty(testZoneIndex2); |
|
3102 |
if (r != KErrNone) |
|
3103 |
{ |
|
3104 |
test.Printf(_L("Skipping...\n")); |
|
3105 |
goto skipTest5; |
|
3106 |
} |
|
3107 |
// Allocate 1 movable page to the test zone |
|
3108 |
r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, testZoneIndex2, 1); |
|
3109 |
if (r != KErrNone) |
|
3110 |
{ |
|
3111 |
test.Printf(_L("Failed to allocate 1 movable page to zone index %d, r = %d - Skipping...\n"), testZoneIndex2, r); |
|
3112 |
goto skipTest5; |
|
3113 |
} |
|
3114 |
||
3115 |
// Zone alloc to put 1 fixed page last zone under test |
|
3116 |
testZoneID2 = gZoneConfigArray[testZoneIndex2].iZoneId; |
|
3117 |
r = Ldd.ZoneAllocContiguous(testZoneID2, gPageSize); |
|
3118 |
if (r != KErrNone) |
|
3119 |
{ |
|
3120 |
test.Printf(_L("Failed to allocate 1 fixed page to zone %d index, r = %d - Skipping...\n"), testZoneIndex2, r); |
|
3121 |
goto skipTest5; |
|
3122 |
} |
|
3123 |
||
3124 |
// Allocate 2 fixed (as there is 1 in our test zone) to prevent reordering |
|
3125 |
GetAllPageInfo(); |
|
3126 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3127 |
{ |
|
3128 |
TUint totImmovable = gZoneUtilArray[index].iAllocFixed + gZoneUtilArray[index].iAllocUnknown ; |
|
3129 |
if (index != testZoneIndex1 && |
|
3130 |
index != testZoneIndex2 && |
|
3131 |
gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && |
|
3132 |
totImmovable < 2) |
|
3133 |
{ |
|
3134 |
r = Ldd.ZoneAllocToMany(index, 2 - totImmovable); |
|
3135 |
if (r != KErrNone) |
|
3136 |
{ |
|
3137 |
test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Skipping...\n"), |
|
3138 |
2, index, r); |
|
3139 |
goto skipTest5; |
|
3140 |
} |
|
3141 |
} |
|
3142 |
} |
|
3143 |
||
3144 |
// Check that the number of free pages in the other in-use zones >= movable pages in test zone |
|
3145 |
GetAllPageInfo(); |
|
3146 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3147 |
{ |
|
3148 |
if (index != testZoneIndex1 && |
|
3149 |
index != testZoneIndex2 && |
|
3150 |
gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages) |
|
3151 |
{ |
|
3152 |
numFreeInUse += gZoneUtilArray[index].iFreePages; |
|
3153 |
} |
|
3154 |
} |
|
3155 |
if (gZoneUtilArray[testZoneIndex1].iAllocMovable + gZoneUtilArray[testZoneIndex1].iAllocDiscardable + |
|
3156 |
gZoneUtilArray[testZoneIndex2].iAllocMovable + gZoneUtilArray[testZoneIndex2].iAllocDiscardable > numFreeInUse || |
|
3157 |
gZoneUtilArray[testZoneIndex2].iAllocFixed == 0) |
|
3158 |
{ |
|
3159 |
test.Printf(_L("Setup failed - Skipping...\n")); |
|
3160 |
goto skipTest5; |
|
3161 |
} |
|
3162 |
||
3163 |
// Added extra tracing to debug random failures |
|
3164 |
PrintPageInfo(); |
|
3165 |
||
3166 |
// Call a general defrag |
|
3167 |
GetOriginalPageCount(); |
|
3168 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3169 |
||
3170 |
// Check that the defrag tidies up |
|
3171 |
GetAllPageInfo(); |
|
3172 |
if(gZoneUtilArray[testZoneIndex1].iAllocMovable || |
|
3173 |
gZoneUtilArray[testZoneIndex2].iAllocMovable) |
|
3174 |
{ |
|
3175 |
test.Printf(_L("FAIL: testZoneIndex1(%d): mov orig 0x%x cur 0x%x, testZoneIndex2(%d) mov orig 0x%x cur 0x%x \n"), |
|
3176 |
testZoneIndex1, gOriginalPageCountArray[testZoneIndex1].iAllocMovable, gZoneUtilArray[testZoneIndex1].iAllocMovable, |
|
3177 |
testZoneIndex2, gOriginalPageCountArray[testZoneIndex2].iAllocMovable, gZoneUtilArray[testZoneIndex2].iAllocMovable); |
|
3178 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3179 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
3180 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3181 |
TEST_FAIL; |
|
3182 |
} |
|
3183 |
||
3184 |
skipTest5: |
|
3185 |
TestEnd(); |
|
3186 |
||
3187 |
||
3188 |
test.Next(_L("Test6: Verify that a general defrag will not move pages if RAM zone to be emptied contains fixed pages")); |
|
3189 |
TestStart(); |
|
3190 |
gChunkArray1 = new RChunk; |
|
3191 |
gChunkArraySize1 = 1; |
|
3192 |
// Find the first most pref zone that has free pages in it |
|
3193 |
r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); |
|
3194 |
if (r != KErrNone) |
|
3195 |
{ |
|
3196 |
test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); |
|
3197 |
goto skipTest6; |
|
3198 |
} |
|
3199 |
||
3200 |
// Find the next most preferable free zone |
|
3201 |
lastPrefArrayIndex = mostPrefArrayIndex + 1; |
|
3202 |
while (lastPrefArrayIndex < gZoneCount && |
|
3203 |
gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iFreePages != gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iPhysPages) |
|
3204 |
{ |
|
3205 |
lastPrefArrayIndex++; |
|
3206 |
} |
|
3207 |
if (lastPrefArrayIndex >= gZoneCount) |
|
3208 |
{ |
|
3209 |
test.Printf(_L("Skipping...\n")); |
|
3210 |
goto skipTest6; |
|
3211 |
} |
|
3212 |
||
3213 |
||
3214 |
// Zone alloc to put 1 fixed page last zone under test |
|
3215 |
lastPrefIndex = gPrefArray[lastPrefArrayIndex]; |
|
3216 |
r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[lastPrefIndex].iZoneId, 1); |
|
3217 |
if (r != KErrNone) |
|
3218 |
{ |
|
3219 |
test.Printf(_L("Failed to allocate 1 fixed page to zone index %d r = %d - Skipping...\n"), lastPrefIndex, r); |
|
3220 |
goto skipTest6; |
|
3221 |
} |
|
3222 |
||
3223 |
GetAllPageInfo(); |
|
3224 |
if (!gZoneUtilArray[mostPrefIndex].iFreePages) |
|
3225 |
{ |
|
3226 |
test.Printf(_L("Not enough space in zone under test mostPrefIndex = %d - Skipping...\n"), mostPrefIndex); |
|
3227 |
goto skipTest6; |
|
3228 |
} |
|
3229 |
||
3230 |
// Block all zones apart from the last zone under test from allocation |
|
3231 |
for (TUint prefIndex = 0; prefIndex < gZoneCount; prefIndex++) |
|
3232 |
{ |
|
3233 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
3234 |
if (zoneIndex != lastPrefIndex) |
|
3235 |
{ |
|
3236 |
Ldd.SetZoneFlag(gZoneConfigArray[zoneIndex].iZoneId, gZoneConfigArray[zoneIndex].iFlags, NO_ALLOC_FLAG); |
|
3237 |
} |
|
3238 |
} |
|
3239 |
||
3240 |
TESTDEBUG(test.Printf(_L("mostPrefIndex = %d lastPrefIndex = %d\n"), mostPrefIndex, lastPrefIndex)); |
|
3241 |
||
3242 |
// Allocate movable pages to the lastPrefZone that will fit into the most pref zone |
|
3243 |
movPages = gZoneUtilArray[mostPrefIndex].iFreePages; |
|
3244 |
movBytes = movPages << gPageShift; |
|
3245 |
while (movBytes && AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes) != KErrNone) |
|
3246 |
{ |
|
3247 |
movBytes -= gPageSize; |
|
3248 |
} |
|
3249 |
if (!movBytes) |
|
3250 |
{ |
|
3251 |
test.Printf(_L("Failed to allocate 0x%x movable pages r = %d - Skipping...\n"), movPages, r); |
|
3252 |
goto skipTest6; |
|
3253 |
} |
|
3254 |
||
3255 |
// Reset all the flags |
|
3256 |
ResetRamZoneFlags(); |
|
3257 |
||
3258 |
||
3259 |
// Check that the number of movable pages in the least pref will fit |
|
3260 |
// into the most preferable zone |
|
3261 |
GetAllPageInfo(); |
|
3262 |
if (gZoneUtilArray[lastPrefIndex].iAllocMovable > gZoneUtilArray[mostPrefIndex].iFreePages) |
|
3263 |
{ |
|
3264 |
test.Printf(_L("Setup failed - Skipping...\n")); |
|
3265 |
PrintPageInfo(); |
|
3266 |
goto skipTest6; |
|
3267 |
} |
|
3268 |
||
3269 |
// Added extra tracing to debug random failures |
|
3270 |
PrintPageInfo(); |
|
3271 |
||
3272 |
// Call a general defrag |
|
3273 |
GetOriginalPageCount(); |
|
3274 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3275 |
||
3276 |
// Check that the defrag didn't move any pages from the least pref zone |
|
3277 |
GetAllPageInfo(); |
|
3278 |
if(gOriginalPageCountArray[lastPrefIndex].iAllocMovable > gZoneUtilArray[lastPrefIndex].iAllocMovable) |
|
3279 |
{ |
|
3280 |
test.Printf(_L("FAIL: mostPref(index %d): origMov = 0x%x curMov = 0x%x, lastPref(index %d): origMov = 0x%x curMov = 0x%x \n"), |
|
3281 |
mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, |
|
3282 |
lastPrefIndex, gOriginalPageCountArray[lastPrefIndex].iAllocMovable, gZoneUtilArray[lastPrefIndex].iAllocMovable); |
|
3283 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3284 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
3285 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3286 |
TEST_FAIL; |
|
3287 |
} |
|
3288 |
||
3289 |
skipTest6: |
|
3290 |
TestEnd(); |
|
3291 |
||
3292 |
test.End(); |
|
3293 |
return KErrNone; |
|
3294 |
} |
|
3295 |
||
3296 |
// |
|
3297 |
// GenDefragTest123Setup |
|
3298 |
// |
|
3299 |
// Used to set up the memory ready for testing in TestGenDefrag, Test Steps 1, 2, 3 and 4 |
|
3300 |
// |
|
3301 |
// @param aMovAlloc The number of movable pages to allocate. |
|
3302 |
// @param aFixAlloc The number of fixed pages to allocate. |
|
3303 |
// @param aDisAlloc The number of discardable pages to allocate. |
|
3304 |
// @param aMovIndex On return contains the test zone index. |
|
3305 |
// @param aNumFreeInUse On return contains the number of free pages in the inuse zones. |
|
3306 |
// @param aTestNo The test number that is using this setup. |
|
3307 |
// |
|
3308 |
TInt GenDefragTest123Setup(TUint aMovAlloc, TUint aFixAlloc, TUint aDisAlloc, TUint& aMovIndex, TUint& aNumFreeInUse, TUint aTestNo) |
|
3309 |
{ |
|
3310 |
TInt r = KErrNone; |
|
3311 |
aNumFreeInUse = 0; |
|
3312 |
const TUint KFillUpTo = 5; // Rough estimate of how full the in-use zones should be |
|
3313 |
const TUint KSpaceNeeded = 2; |
|
3314 |
TUint movPrefIndex = 0; |
|
3315 |
if (aTestNo == 4) |
|
3316 |
{// Test 4 we need to look for the LEAST preferable RAM zone which is empty |
|
3317 |
TUint mostPrefIndex; |
|
3318 |
r = FindLeastPrefEmpty(aMovIndex, &movPrefIndex); |
|
3319 |
TInt r2 = FindMostPrefEmpty(mostPrefIndex); |
|
3320 |
if (r != KErrNone || r2 != KErrNone || !gPagedRom || |
|
3321 |
gZoneConfigArray[aMovIndex].iPref == gZoneConfigArray[mostPrefIndex].iPref) |
|
3322 |
{ |
|
3323 |
test.Printf(_L("r %d r2 %d or not a paged ROM or Equal zone preferences- Skipping test step...\n"), |
|
3324 |
r, r2); |
|
3325 |
return KErrGeneral; |
|
3326 |
} |
|
3327 |
} |
|
3328 |
else |
|
3329 |
{// All other tests look the MOST preferable RAM zone which is empty |
|
3330 |
r = FindMostPrefEmpty(aMovIndex, &movPrefIndex); |
|
3331 |
if (r != KErrNone || !gPagedRom) |
|
3332 |
{ |
|
3333 |
test.Printf(_L("No suitable RAM zone found or not a paged ROM - Skipping test step...\n")); |
|
3334 |
return KErrGeneral; |
|
3335 |
} |
|
3336 |
} |
|
3337 |
||
3338 |
// Go through all the in-use zones and check how many free pages there are |
|
3339 |
// Allocate fixed so there is only KFillUpTo pages in each in-use zone to |
|
3340 |
// ensure that the total number of free pages in the in-use zones can fit into |
|
3341 |
// the zone under test |
|
3342 |
GetAllPageInfo(); |
|
3343 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3344 |
{ |
|
3345 |
if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && |
|
3346 |
gZoneUtilArray[index].iFreePages > KFillUpTo) |
|
3347 |
{ |
|
3348 |
r = Ldd.ZoneAllocToMany(index, gZoneUtilArray[index].iFreePages - KFillUpTo); |
|
3349 |
if (r != KErrNone) |
|
3350 |
{ |
|
3351 |
test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Ending setup...\n"), |
|
3352 |
gZoneUtilArray[index].iFreePages - KFillUpTo, index, r); |
|
3353 |
return KErrGeneral; |
|
3354 |
} |
|
3355 |
} |
|
3356 |
} |
|
3357 |
||
3358 |
GetAllPageInfo(); |
|
3359 |
// If any of the in-use zones doesn't contain any fixed and unknown pages allocate one fixed |
|
3360 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3361 |
{ |
|
3362 |
if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && |
|
3363 |
!gZoneUtilArray[index].iAllocFixed && !gZoneUtilArray[index].iAllocUnknown) |
|
3364 |
{ |
|
3365 |
r = Ldd.ZoneAllocToMany(index, 1); |
|
3366 |
if (r != KErrNone) |
|
3367 |
{ |
|
3368 |
test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Ending setup...\n"), |
|
3369 |
1, index, r); |
|
3370 |
return KErrGeneral; |
|
3371 |
} |
|
3372 |
} |
|
3373 |
} |
|
3374 |
||
3375 |
GetAllPageInfo(); |
|
3376 |
// Check the total number of free pages in the in-use zones |
|
3377 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3378 |
{ |
|
3379 |
if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages) |
|
3380 |
{ |
|
3381 |
aNumFreeInUse += gZoneUtilArray[index].iFreePages; |
|
3382 |
} |
|
3383 |
} |
|
3384 |
TESTDEBUG(test.Printf(_L("aNumFreeInUse = 0x%x\n"), aNumFreeInUse)); |
|
3385 |
||
3386 |
test.Printf(_L("aMovIndex = %d\n"), aMovIndex); |
|
3387 |
if (aNumFreeInUse < KSpaceNeeded) |
|
3388 |
{ |
|
3389 |
test.Printf(_L("RAM zone to be tested is too full - Skipping test step...\n")); |
|
3390 |
return KErrGeneral; |
|
3391 |
} |
|
3392 |
||
3393 |
||
3394 |
// Ensure that there are movable pages in the zone under test |
|
3395 |
// ensuring that there is also room for discardable pages |
|
3396 |
GetAllPageInfo(); |
|
3397 |
if (aMovAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocMovable == 0) |
|
3398 |
{ |
|
3399 |
// Allocate just aMovAlloc movable pages |
|
3400 |
TUint movPagesAlloc = aMovAlloc; |
|
3401 |
if (aTestNo == 2 || aTestNo == 4) |
|
3402 |
{// Tests 2 and 4 require that movable pages can't be moved from zone |
|
3403 |
movPagesAlloc = aNumFreeInUse + 1; |
|
3404 |
if (movPagesAlloc > gZoneUtilArray[aMovIndex].iFreePages) |
|
3405 |
{ |
|
3406 |
test.Printf(_L("Insufficiant space in zone %d to allocate 0x%x pages - Ending setup...\n"), |
|
3407 |
aMovIndex, movPagesAlloc); |
|
3408 |
return KErrGeneral; |
|
3409 |
} |
|
3410 |
} |
|
3411 |
||
3412 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, aMovIndex, movPagesAlloc); |
|
3413 |
if (gZoneUtilArray[aMovIndex].iAllocMovable != movPagesAlloc || |
|
3414 |
gZoneUtilArray[aMovIndex].iFreePages == 0 || |
|
3415 |
r != KErrNone) |
|
3416 |
{// Movable page didn't go into RAM, or RAM zone is full. |
|
3417 |
test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); |
|
3418 |
test.Printf(_L("zone mov 0x%x free 0x%x r=%d\n"), |
|
3419 |
gZoneUtilArray[aMovIndex].iAllocMovable, |
|
3420 |
gZoneUtilArray[aMovIndex].iFreePages, r); |
|
3421 |
return KErrGeneral; |
|
3422 |
} |
|
3423 |
} |
|
3424 |
||
3425 |
// Block all other zones from allocation |
|
3426 |
for(TUint i = 0; i < gZoneCount; i++) |
|
3427 |
{ |
|
3428 |
if (i != aMovIndex) |
|
3429 |
{ |
|
3430 |
r = Ldd.SetZoneFlag(gZoneConfigArray[i].iZoneId, gZoneConfigArray[i].iFlags, NO_ALLOC_FLAG); |
|
3431 |
if (r != KErrNone) |
|
3432 |
{ |
|
3433 |
test.Printf(_L("Failed to set flag on zone index %d r = %d- Ending setup...\n"), i, r); |
|
3434 |
return KErrGeneral; |
|
3435 |
} |
|
3436 |
} |
|
3437 |
} |
|
3438 |
||
3439 |
// Now ensure that there are fixed pages in the zone under test |
|
3440 |
// ensuring that there is also room for discardable pages |
|
3441 |
GetAllPageInfo(); |
|
3442 |
if (aFixAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocFixed == 0) |
|
3443 |
{//Allocate just aFixAlloc fixed pages |
|
3444 |
r = Ldd.ZoneAllocToMany(aMovIndex, aFixAlloc); |
|
3445 |
GetAllPageInfo(); |
|
3446 |
if (gZoneUtilArray[aMovIndex].iAllocMovable == 0 || |
|
3447 |
gZoneUtilArray[aMovIndex].iFreePages == 0 || |
|
3448 |
gZoneUtilArray[aMovIndex].iAllocFixed == 0 || |
|
3449 |
r != KErrNone) |
|
3450 |
{// Fixed page didn't go into RAM or RAM zone is full. |
|
3451 |
test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); |
|
3452 |
test.Printf(_L("zone mov 0x%x fixed 0x%x free 0x%x r=%d\n"), |
|
3453 |
gZoneUtilArray[aMovIndex].iAllocMovable, |
|
3454 |
gZoneUtilArray[aMovIndex].iAllocFixed, |
|
3455 |
gZoneUtilArray[aMovIndex].iFreePages, r); |
|
3456 |
return KErrGeneral; |
|
3457 |
} |
|
3458 |
} |
|
3459 |
||
3460 |
||
3461 |
||
3462 |
// Allocate aDisAlloc number of discardable pages |
|
3463 |
if (aDisAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocDiscardable == 0) |
|
3464 |
{//Allocate just aDisAlloc discardable pages |
|
3465 |
TInt discard; |
|
3466 |
r = ZoneAllocDiscard(aMovIndex, aDisAlloc, discard); |
|
3467 |
GetAllPageInfo(); |
|
3468 |
if (r != KErrNone || gZoneUtilArray[aMovIndex].iAllocDiscardable == 0) |
|
3469 |
{// Discardable page didn't go into RAM or RAM zone is full. |
|
3470 |
test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); |
|
3471 |
test.Printf(_L("zone mov 0x%x discardable 0x%x free 0x%x r=%d\n"), |
|
3472 |
gZoneUtilArray[aMovIndex].iAllocDiscardable, |
|
3473 |
gZoneUtilArray[aMovIndex].iAllocFixed, |
|
3474 |
gZoneUtilArray[aMovIndex].iFreePages, r); |
|
3475 |
return KErrGeneral; |
|
3476 |
} |
|
3477 |
} |
|
3478 |
||
3479 |
// Update the total number of free pages in the in-use zones |
|
3480 |
aNumFreeInUse = 0; |
|
3481 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3482 |
{ |
|
3483 |
if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && |
|
3484 |
index != aMovIndex) |
|
3485 |
{ |
|
3486 |
aNumFreeInUse += gZoneUtilArray[index].iFreePages; |
|
3487 |
} |
|
3488 |
} |
|
3489 |
TESTDEBUG(test.Printf(_L("aNumFreeInUse = 0x%x\n"), aNumFreeInUse)); |
|
3490 |
||
3491 |
// now reset all the flags |
|
3492 |
ResetRamZoneFlags(); |
|
3493 |
||
3494 |
return KErrNone; |
|
3495 |
} |
|
3496 |
// |
|
3497 |
// TestGenDefrag |
|
3498 |
// |
|
3499 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3500 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0528 |
|
3501 |
//! @SYMTestType CIT |
|
3502 |
//! @SYMTestCaseDesc Verifying general scenarios when RAM defrag would take place |
|
3503 |
//! @SYMPREQ PREQ308 |
|
3504 |
//! @SYMTestPriority High |
|
3505 |
//! @SYMTestActions |
|
3506 |
//! 1. Allocate 1 movable, 1 fixed and 1 discardable pages into the most preferable empty RAM zone |
|
3507 |
//! ensuring that there is enough free space in the more preferable RAM zones for the |
|
3508 |
//! movable pages in the RAM zone under test. Following this call a general defrag. |
|
3509 |
//! 2. Allocate 1 movable and 1 discardable page into into the most preferable empty RAM zone |
|
3510 |
//! ensuring that there is not enough free space in the more preferable RAM zones for the |
|
3511 |
//! movable pages in the RAM zone under test. Following this call a general defrag. |
|
3512 |
//! 3. Allocate 1 movable and 1 discardable and 1 fixed page into the most preferable empty RAM zone(a). |
|
3513 |
//! Following this, place 1 movable page in an empty zone(b) ensuring that there is enough free space in |
|
3514 |
//! the more preferable RAM zones for the movable pages in both zones (a) and (b). |
|
3515 |
//! Following this call a general defrag. |
|
3516 |
//! 4. Allocate 1 movable and 1 discardable page into the least preferable empty RAM zone |
|
3517 |
//! ensuring that there is not enough free space in the more preferable RAM zones for the |
|
3518 |
//! movable pages in the RAM zone under test. Following this call a general defrag. |
|
3519 |
//! 5. Fragment the memory. |
|
3520 |
//! Following this allocate discardable pages by loading pages that are demand paged. |
|
3521 |
//! Read each of the constants from beginning to end. |
|
3522 |
//! Following this perform a RAM defrag. |
|
3523 |
//! 6. Call a device driver that will continuously allocate fixed pages to the |
|
3524 |
//! memory until it reports out of memory. Following this perform a RAM defrag. |
|
3525 |
//! 7. Defrag memory filled with discardable pages when the min cache size is reached |
|
3526 |
//! 8. Fragment the memory. Following this, continuously call a general defrag, each time |
|
3527 |
//! reducing the size of the chunks that are allocated |
|
3528 |
//! |
|
3529 |
//! @SYMTestExpectedResults |
|
3530 |
//! 1. The RAM zone under test is not emptied and all the discardable pages contained in it |
|
3531 |
//! have not been discarded. |
|
3532 |
//! 2. The RAM zone under test is not emptied and all the discardable pages contained in it |
|
3533 |
//! have not been discarded. |
|
3534 |
//! 3. RAM zones (a) and (b) have been emptied and all the discardable pages contained in them |
|
3535 |
//! have not been discarded. |
|
3536 |
//! 4. The RAM zone under test is emptied |
|
3537 |
//! 5. Pages are discarded |
|
3538 |
//! 6. No zones are emptied |
|
3539 |
//! 7. The least preferable zone is skipped but the other zones are defragmented as required. |
|
3540 |
//! 8. Zones are emptied if the general defrag can succeed |
|
3541 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3542 |
TInt TestGenDefrag() |
|
3543 |
{ |
|
3544 |
TInt r = KErrNone; |
|
3545 |
||
3546 |
test.Start(_L("Test1: Test General Defrag doesn't discard pages when fixed page in zone to be emptied")); |
|
3547 |
TestStart(); |
|
3548 |
gChunkArray1 = new RChunk; |
|
3549 |
gChunkArraySize1 = 1; |
|
3550 |
TUint numFreeInUse = 0; |
|
3551 |
TUint testNo = 1; |
|
3552 |
||
3553 |
// We just need 1 movable, 1 discardable and 1 fixed in the zone to ensure it cannot be emptied |
|
3554 |
// as the fixed should block the defrag |
|
3555 |
TInt movAllocPages = 1; |
|
3556 |
TInt fixAllocPages = 1; |
|
3557 |
TInt disAllocPages = 1; |
|
3558 |
TUint zoneIndex; |
|
3559 |
||
3560 |
if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) |
|
3561 |
{ |
|
3562 |
test.Printf(_L("Setup failed - Skipping..\n")); |
|
3563 |
goto skipTest1; |
|
3564 |
} |
|
3565 |
||
3566 |
// Call a general defrag and check that no discardable pages were freed. |
|
3567 |
GetOriginalPageCount(); |
|
3568 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3569 |
GetAllPageInfo(); |
|
3570 |
if (r != KErrNone || |
|
3571 |
gZoneUtilArray[zoneIndex].iAllocMovable < gOriginalPageCountArray[zoneIndex].iAllocMovable || |
|
3572 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable > gZoneUtilArray[zoneIndex].iAllocDiscardable) |
|
3573 |
{ |
|
3574 |
test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, |
|
3575 |
gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, |
|
3576 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); |
|
3577 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3578 |
TEST_FAIL; |
|
3579 |
} |
|
3580 |
else |
|
3581 |
{ |
|
3582 |
test.Printf(_L("Passed...\n")); |
|
3583 |
} |
|
3584 |
||
3585 |
skipTest1: |
|
3586 |
// TestEnd() will perform any required clean up. |
|
3587 |
TestEnd(); |
|
3588 |
||
3589 |
test.Next(_L("Test2: Test General Defrag doesn't discard pages when zone can't be emptied")); |
|
3590 |
TestStart(); |
|
3591 |
gChunkArray1 = new RChunk; |
|
3592 |
gChunkArraySize1 = 1; |
|
3593 |
testNo++; |
|
3594 |
// No fixed, but there should be no space for the movable to go to |
|
3595 |
// GenDefragTest123Setup(), will ensure that this is the case |
|
3596 |
// by allocating 1 more movable page than there is free in the in-use zones |
|
3597 |
movAllocPages = 1; |
|
3598 |
fixAllocPages = 0; |
|
3599 |
disAllocPages = 1; |
|
3600 |
||
3601 |
if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) |
|
3602 |
{ |
|
3603 |
test.Printf(_L("Setup failed - Skipping..\n")); |
|
3604 |
goto skipTest2; |
|
3605 |
} |
|
3606 |
||
3607 |
// Call a general defrag and check that no discardable pages were freed. |
|
3608 |
GetOriginalPageCount(); |
|
3609 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3610 |
||
3611 |
GetAllPageInfo(); |
|
3612 |
if (r != KErrNone || |
|
3613 |
gZoneUtilArray[zoneIndex].iAllocMovable < gOriginalPageCountArray[zoneIndex].iAllocMovable || |
|
3614 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable > gZoneUtilArray[zoneIndex].iAllocDiscardable) |
|
3615 |
{ |
|
3616 |
test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, |
|
3617 |
gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, |
|
3618 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); |
|
3619 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3620 |
TEST_FAIL; |
|
3621 |
} |
|
3622 |
else |
|
3623 |
{ |
|
3624 |
test.Printf(_L("Passed...\n")); |
|
3625 |
} |
|
3626 |
||
3627 |
skipTest2: |
|
3628 |
// TestEnd() will perform any required clean up. |
|
3629 |
TestEnd(); |
|
3630 |
||
3631 |
test.Next(_L("Test3: Test General Defrag tidies when fixed page in zone to be emptied but other can be emptied")); |
|
3632 |
TestStart(); |
|
3633 |
gChunkArray1 = new RChunk; |
|
3634 |
gChunkArraySize1 = 1; |
|
3635 |
gChunkArray2 = new RChunk; |
|
3636 |
gChunkArraySize2 = 1; |
|
3637 |
TUint totalToMove; |
|
3638 |
testNo++; |
|
3639 |
||
3640 |
// First use GenDefragTest123Setup() to ensure we place 1 fixed, 1 movable and 1 discardable |
|
3641 |
// in the least preferable zone |
|
3642 |
movAllocPages = 1; |
|
3643 |
fixAllocPages = 1; |
|
3644 |
disAllocPages = 1; |
|
3645 |
TBool zoneFound = EFalse; |
|
3646 |
TUint emptyZoneIndex = 0; |
|
3647 |
||
3648 |
if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) |
|
3649 |
{ |
|
3650 |
test.Printf(_L("Setup failed - Skipping..\n")); |
|
3651 |
goto skipTest3; |
|
3652 |
} |
|
3653 |
||
3654 |
// Find an empty zone and place a movable page in it |
|
3655 |
GetAllPageInfo(); |
|
3656 |
for (TUint i = 0; i < gZoneCount; i++) |
|
3657 |
{ |
|
3658 |
if (gZoneUtilArray[i].iFreePages == gZoneUtilArray[i].iPhysPages) |
|
3659 |
{ |
|
3660 |
zoneFound = ETrue; |
|
3661 |
emptyZoneIndex = i; |
|
3662 |
break; |
|
3663 |
} |
|
3664 |
} |
|
3665 |
if (!zoneFound) |
|
3666 |
{ |
|
3667 |
test.Printf(_L("Can't find empty zone - Skipping..\n")); |
|
3668 |
goto skipTest3; |
|
3669 |
} |
|
3670 |
||
3671 |
// Allocate 1 movable page into the empty zone |
|
3672 |
r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, emptyZoneIndex, 1); |
|
3673 |
GetAllPageInfo(); |
|
3674 |
if (r != KErrNone || |
|
3675 |
gZoneUtilArray[emptyZoneIndex].iAllocMovable == 0 || |
|
3676 |
gZoneUtilArray[emptyZoneIndex].iAllocFixed != 0) |
|
3677 |
{ |
|
3678 |
test.Printf(_L("Movable pages not allocated or fixed pages allocated. - Skipping...\n")); |
|
3679 |
test.Printf(_L("zone mov 0x%x free 0x%x r =% d\n"), |
|
3680 |
gZoneUtilArray[emptyZoneIndex].iAllocMovable, |
|
3681 |
gZoneUtilArray[emptyZoneIndex].iFreePages, r); |
|
3682 |
goto skipTest3; |
|
3683 |
} |
|
3684 |
||
3685 |
// Check that the amount we are allocating can actually be moved into the in-use zones |
|
3686 |
totalToMove = gZoneUtilArray[zoneIndex].iAllocMovable + gZoneUtilArray[zoneIndex].iAllocDiscardable + |
|
3687 |
gZoneUtilArray[emptyZoneIndex].iAllocMovable + gZoneUtilArray[emptyZoneIndex].iAllocDiscardable; |
|
3688 |
||
3689 |
// Check the total number of free pages in the in-use zones |
|
3690 |
numFreeInUse = 0; |
|
3691 |
for (TUint index = 0; index < gZoneCount; index++) |
|
3692 |
{ |
|
3693 |
if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && |
|
3694 |
index != zoneIndex && index != emptyZoneIndex) |
|
3695 |
{ |
|
3696 |
numFreeInUse += gZoneUtilArray[index].iFreePages; |
|
3697 |
} |
|
3698 |
} |
|
3699 |
if(numFreeInUse < totalToMove) |
|
3700 |
{ |
|
3701 |
test.Printf(_L("No space to move pages numFreeInUse = 0x%x totalToMove = 0x%x - Skipping..\n"), |
|
3702 |
numFreeInUse, totalToMove); |
|
3703 |
goto skipTest3; |
|
3704 |
} |
|
3705 |
||
3706 |
// Call a general defrag and check that zone is emptied. |
|
3707 |
GetOriginalPageCount(); |
|
3708 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3709 |
||
3710 |
GetAllPageInfo(); |
|
3711 |
if (r != KErrNone || |
|
3712 |
gZoneUtilArray[zoneIndex].iAllocMovable || |
|
3713 |
gZoneUtilArray[zoneIndex].iAllocDiscardable || |
|
3714 |
gZoneUtilArray[emptyZoneIndex].iAllocMovable) |
|
3715 |
{ |
|
3716 |
test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, |
|
3717 |
gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, |
|
3718 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); |
|
3719 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3720 |
TEST_FAIL; |
|
3721 |
} |
|
3722 |
else |
|
3723 |
{ |
|
3724 |
test.Printf(_L("Passed...\n")); |
|
3725 |
} |
|
3726 |
||
3727 |
skipTest3: |
|
3728 |
// TestEnd() will perform any required clean up. |
|
3729 |
TestEnd(); |
|
3730 |
||
3731 |
test.Next(_L("Test4: Test General Defrag moves pages into the next most pref if they don't fit into the most pref")); |
|
3732 |
TestStart(); |
|
3733 |
gChunkArray1 = new RChunk; |
|
3734 |
gChunkArraySize1 = 1; |
|
3735 |
testNo++; |
|
3736 |
||
3737 |
// No fixed, but there should be no space for the movable to go to |
|
3738 |
// GenDefragTest123Setup(), will ensure that this is the case |
|
3739 |
// by allocating 1 more movable page than there is free in the in-use zones |
|
3740 |
movAllocPages = 1; |
|
3741 |
fixAllocPages = 0; |
|
3742 |
disAllocPages = 1; |
|
3743 |
||
3744 |
if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) |
|
3745 |
{ |
|
3746 |
test.Printf(_L("Setup failed - Skipping..\n")); |
|
3747 |
goto skipTest4; |
|
3748 |
} |
|
3749 |
||
3750 |
// Call a general defrag and check that the test zone is emptied. |
|
3751 |
GetOriginalPageCount(); |
|
3752 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3753 |
||
3754 |
GetAllPageInfo(); |
|
3755 |
if (r != KErrNone || |
|
3756 |
gZoneUtilArray[zoneIndex].iFreePages != gZoneUtilArray[zoneIndex].iPhysPages) |
|
3757 |
{ |
|
3758 |
test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, |
|
3759 |
gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, |
|
3760 |
gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); |
|
3761 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3762 |
TEST_FAIL; |
|
3763 |
} |
|
3764 |
else |
|
3765 |
{ |
|
3766 |
test.Printf(_L("Passed...\n")); |
|
3767 |
} |
|
3768 |
||
3769 |
skipTest4: |
|
3770 |
// TestEnd() will perform any required clean up. |
|
3771 |
TestEnd(); |
|
3772 |
||
3773 |
test.Next(_L("Test5: Defrag memory filled with discardable pages\n")); |
|
3774 |
TestStart(); |
|
3775 |
if (gPagedRom) |
|
3776 |
{ |
|
3777 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
3778 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
3779 |
||
3780 |
GetAllPageInfo(); |
|
3781 |
TInt discardablePages; |
|
3782 |
UpdateRamInfo(); |
|
3783 |
||
3784 |
r = AllocDiscardable(discardablePages); |
|
3785 |
if (r != KErrNone) |
|
3786 |
{ |
|
3787 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
3788 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3789 |
TEST_FAIL; |
|
3790 |
} |
|
3791 |
TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); |
|
3792 |
||
3793 |
GetOriginalPageCount(); |
|
3794 |
TBool genSucceed = CanGenSucceed(); |
|
3795 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3796 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
3797 |
||
3798 |
if (r != KErrNone) |
|
3799 |
{ |
|
3800 |
test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); |
|
3801 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3802 |
TEST_FAIL; |
|
3803 |
} |
|
3804 |
else if (genSucceed && CheckZonesSwitchedOff() == EFalse) |
|
3805 |
{ |
|
3806 |
test.Printf(_L("No Zones Switched off and should have been\n")); |
|
3807 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3808 |
TEST_FAIL; |
|
3809 |
} |
|
3810 |
else |
|
3811 |
{ |
|
3812 |
test.Printf(_L("Passed...\n")); |
|
3813 |
} |
|
3814 |
||
3815 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
3816 |
ResetDPCache(); |
|
3817 |
} |
|
3818 |
else |
|
3819 |
{ |
|
3820 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
3821 |
} |
|
3822 |
TestEnd(); |
|
3823 |
||
3824 |
||
3825 |
test.Next(_L("Test6: Defrag memory filled with fixed pages")); |
|
3826 |
TestStart(); |
|
3827 |
||
3828 |
TESTDEBUG(test.Printf(_L("Filling memory with fixed pages, r = %d\n"))); |
|
3829 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
3830 |
||
3831 |
GetOriginalPageCount(); |
|
3832 |
TBool genSucceed = CanGenSucceed(); |
|
3833 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3834 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
3835 |
||
3836 |
// The zones should be full of fixed pages so the general should do nothing. |
|
3837 |
if (r != KErrNone || |
|
3838 |
genSucceed || |
|
3839 |
CheckZonesSwitchedOff()) |
|
3840 |
{ |
|
3841 |
test.Printf(_L("Fail: r = %d, expected = %d, or zone have been emptied\n"), r, KErrNone); |
|
3842 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
3843 |
TEST_FAIL; |
|
3844 |
} |
|
3845 |
else |
|
3846 |
{ |
|
3847 |
test.Printf(_L("Passed...\n")); |
|
3848 |
} |
|
3849 |
Ldd.FreeAllFixedPages(); |
|
3850 |
TestEnd(); |
|
3851 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
3852 |
PrintPageInfo(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
3853 |
|
0 | 3854 |
test.Next(_L("Test7: Defrag memory filled with discardable pages when the min cache size is reached\n")); |
3855 |
TestStart(); |
|
3856 |
if (gPagedRom) |
|
3857 |
{ |
|
3858 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
3859 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
3860 |
||
3861 |
GetAllPageInfo(); |
|
3862 |
TInt discardablePages; |
|
3863 |
UpdateRamInfo(); |
|
3864 |
||
3865 |
r = AllocDiscardable(discardablePages); |
|
3866 |
if (r != KErrNone) |
|
3867 |
{ |
|
3868 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
3869 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3870 |
TEST_FAIL; |
|
3871 |
} |
|
3872 |
TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); |
|
3873 |
||
3874 |
TUint minCacheSize = 0; |
|
3875 |
TUint maxCacheSize = 0; |
|
3876 |
TUint currentCacheSize = 0; |
|
3877 |
||
3878 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
3879 |
||
3880 |
TUint setMin = maxCacheSize; |
|
3881 |
TUint64 setMax = maxCacheSize; |
|
3882 |
TInt r = DPTest::SetCacheSize(setMin, setMax); |
|
3883 |
if (r != KErrNone) |
|
3884 |
{ |
|
3885 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
3886 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3887 |
CLEANUP(ResetDPCache()); |
|
3888 |
TEST_FAIL; |
|
3889 |
} |
|
3890 |
TESTDEBUG(test.Printf(_L("After SetCacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x\n"), |
|
3891 |
setMin >> gPageShift, setMax >> gPageShift)); |
|
3892 |
||
3893 |
GetOriginalPageCount(); |
|
3894 |
genSucceed = CanGenSucceed(); |
|
3895 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3896 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
3897 |
||
3898 |
if (r != KErrNone) |
|
3899 |
{ |
|
3900 |
test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); |
|
3901 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3902 |
CLEANUP(ResetDPCache()); |
|
3903 |
TEST_FAIL; |
|
3904 |
} |
|
3905 |
else if (genSucceed && CheckZonesSwitchedOff() == EFalse) |
|
3906 |
{ |
|
3907 |
test.Printf(_L("No Zones Switched off and should have been\n")); |
|
3908 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3909 |
CLEANUP(ResetDPCache()); |
|
3910 |
TEST_FAIL; |
|
3911 |
} |
|
3912 |
else |
|
3913 |
{ |
|
3914 |
test.Printf(_L("Passed...\n")); |
|
3915 |
} |
|
3916 |
||
3917 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
3918 |
ResetDPCache(); |
|
3919 |
||
3920 |
||
3921 |
} |
|
3922 |
else |
|
3923 |
{ |
|
3924 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
3925 |
} |
|
3926 |
TestEnd(); |
|
3927 |
||
3928 |
test.Next(_L("Test8: Defrag fragmented memory for various smaller chunk sizes")); |
|
3929 |
TInt chunkSize = 0x80000; |
|
3930 |
while (chunkSize >= 0x4000) |
|
3931 |
{ |
|
3932 |
test.Printf(_L("chunkSize = %dKB\n"), chunkSize/1024); |
|
3933 |
TestStart(); |
|
3934 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, chunkSize, EFalse); |
|
3935 |
r = FreeMovable(gChunkArray1, gChunkArraySize1); |
|
3936 |
||
3937 |
GetOriginalPageCount(); |
|
3938 |
TBool genSucceed = CanGenSucceed(); |
|
3939 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3940 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
3941 |
||
3942 |
if (r != KErrNone) |
|
3943 |
{ |
|
3944 |
test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); |
|
3945 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3946 |
TEST_FAIL; |
|
3947 |
} |
|
3948 |
else if (genSucceed && CheckZonesSwitchedOff() == EFalse) |
|
3949 |
{ |
|
3950 |
test.Printf(_L("No Zones Switched off and should have been\n")); |
|
3951 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3952 |
TEST_FAIL; |
|
3953 |
} |
|
3954 |
else |
|
3955 |
{ |
|
3956 |
test.Printf(_L("Passed...\n")); |
|
3957 |
} |
|
3958 |
||
3959 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
3960 |
TestEnd(); |
|
3961 |
chunkSize = chunkSize>>1; |
|
3962 |
} |
|
3963 |
||
3964 |
test.Next(_L("Test9: Defrag fragmented memory ")); |
|
3965 |
TestStart(); |
|
3966 |
||
3967 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); |
|
3968 |
r = FreeMovable(gChunkArray1, gChunkArraySize1); |
|
3969 |
||
3970 |
GetOriginalPageCount(); |
|
3971 |
genSucceed = CanGenSucceed(); |
|
3972 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
3973 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
3974 |
||
3975 |
if (r != KErrNone) |
|
3976 |
{ |
|
3977 |
test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); |
|
3978 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3979 |
TEST_FAIL; |
|
3980 |
} |
|
3981 |
else if (genSucceed && CheckZonesSwitchedOff() == EFalse) |
|
3982 |
{ |
|
3983 |
test.Printf(_L("No Zones Switched off and should have been\n")); |
|
3984 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
3985 |
TEST_FAIL; |
|
3986 |
} |
|
3987 |
else |
|
3988 |
{ |
|
3989 |
test.Printf(_L("Passed...\n")); |
|
3990 |
} |
|
3991 |
||
3992 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
3993 |
TestEnd(); |
|
3994 |
||
3995 |
test.End(); |
|
3996 |
return KErrNone; |
|
3997 |
} |
|
3998 |
||
3999 |
||
4000 |
// |
|
4001 |
// TestGetRamZonePageCount |
|
4002 |
// |
|
4003 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4004 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0529 |
|
4005 |
//! @SYMTestType CIT |
|
4006 |
//! @SYMTestCaseDesc Verifying the implementation of the function GetRamZonePageCount() |
|
4007 |
//! @SYMPREQ PREQ308 |
|
4008 |
//! @SYMTestPriority High |
|
4009 |
//! @SYMTestActions |
|
4010 |
//! 1. Fragment the memory. Following this, call GetRamZonePageCount() on every zone and verify |
|
4011 |
//! the values with the test HAL functions. |
|
4012 |
//! 2. Fragment the memory. Following this, call function with an valid aID |
|
4013 |
//! |
|
4014 |
//! @SYMTestExpectedResults |
|
4015 |
//! 1. KErrNone |
|
4016 |
//! 2. KErrArgument |
|
4017 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4018 |
TInt TestGetRamZonePageCount() |
|
4019 |
{ |
|
4020 |
test.Start(_L("Test1: Call GetRamZonePageCount() on every zone one after the other")); |
|
4021 |
TestStart(); |
|
4022 |
||
4023 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4024 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4025 |
||
4026 |
for (TUint index = 0; index < gZoneCount; index++) |
|
4027 |
{ |
|
4028 |
GetAllPageInfo(); |
|
4029 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
4030 |
||
4031 |
STestUserSidePageCount pageData; |
|
4032 |
TInt r = Ldd.PageCount(zoneID, &pageData); |
|
4033 |
TESTDEBUG(test.Printf(_L("Page count function r = %d\n"), r)); |
|
4034 |
if (r != KErrNone) |
|
4035 |
{ |
|
4036 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
4037 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4038 |
TEST_FAIL; |
|
4039 |
} |
|
4040 |
||
4041 |
if (pageData.iFreePages != gZoneUtilArray[index].iFreePages || |
|
4042 |
pageData.iFixedPages != gZoneUtilArray[index].iAllocFixed || |
|
4043 |
pageData.iMovablePages != gZoneUtilArray[index].iAllocMovable || |
|
4044 |
pageData.iDiscardablePages != gZoneUtilArray[index].iAllocDiscardable) |
|
4045 |
{ |
|
4046 |
test.Printf(_L("RAM zone page count does not match test HAL page count, Zone %d\n"), zoneID); |
|
4047 |
test.Printf(_L("PgCnt: free = 0x%x, fixed = 0x%x, movable= 0x%x, discard = 0x%x\n"), |
|
4048 |
pageData.iFreePages, pageData.iFixedPages, pageData.iMovablePages, pageData.iDiscardablePages); |
|
4049 |
test.Printf(_L("HalFunc: free = 0x%x, fixed = 0x%x, movable= 0x%x, discard = 0x%x\n"), |
|
4050 |
gZoneUtilArray[index].iFreePages, gZoneUtilArray[index].iAllocFixed, |
|
4051 |
gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable); |
|
4052 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4053 |
TEST_FAIL; |
|
4054 |
} |
|
4055 |
else |
|
4056 |
{ |
|
4057 |
test.Printf(_L("Zone %d Passed...\n"), zoneID); |
|
4058 |
} |
|
4059 |
TESTDEBUG(test.Printf(_L("iFreePages = 0x%x, iFixedPages = 0x%x, iMovablePages = 0x%x, iDiscardablePages = 0x%x\n"), |
|
4060 |
pageData.iFreePages, pageData.iFixedPages, pageData.iMovablePages, pageData.iDiscardablePages)); |
|
4061 |
} |
|
4062 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4063 |
TestEnd(); |
|
4064 |
||
4065 |
test.Next(_L("Test2: Call GetRamZonePageCount() with an invalid aID ")); |
|
4066 |
TestStart(); |
|
4067 |
||
4068 |
TUint zoneID = KInvalidZoneID; |
|
4069 |
STestUserSidePageCount pageData; |
|
4070 |
TInt r = Ldd.PageCount(zoneID, &pageData); |
|
4071 |
TESTDEBUG(test.Printf(_L("Page count function r = %d\n"), r)); |
|
4072 |
if (r != KErrArgument) |
|
4073 |
{ |
|
4074 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
4075 |
TEST_FAIL; |
|
4076 |
} |
|
4077 |
else |
|
4078 |
{ |
|
4079 |
test.Printf(_L("Passed...\n")); |
|
4080 |
} |
|
4081 |
TestEnd(); |
|
4082 |
||
4083 |
test.End(); |
|
4084 |
return 0; |
|
4085 |
} |
|
4086 |
||
4087 |
const TUint KIndex2Alloc = 10; |
|
4088 |
const TUint KTestMaxPages = 6; |
|
4089 |
||
4090 |
// |
|
4091 |
// DefragMaxPagesSetup |
|
4092 |
// |
|
4093 |
// Arranges the memory layout in preparation for TestDefragRamMaxPages() |
|
4094 |
// |
|
4095 |
// WARNING THIS WILL BE UNRELIABLE IF aMaxPages > KIndex2Alloc |
|
4096 |
// |
|
4097 |
TInt DefragMaxPagesSetup(TInt aPageType, TUint aMaxPages, TUint& aIndex, TUint& aIndex2) |
|
4098 |
{ |
|
4099 |
TInt r = KErrNoMemory; |
|
4100 |
||
4101 |
// Get the preference order and determine the 2 most preferable zones |
|
4102 |
// that are currently not in use. |
|
4103 |
GetPrefOrder(); |
|
4104 |
TUint freeInUsePages = 0; |
|
4105 |
TBool zonesFound = EFalse; |
|
4106 |
for (TUint i = 1; i < gZoneCount; i++) |
|
4107 |
{ |
|
4108 |
aIndex = gPrefArray[i]; |
|
4109 |
aIndex2 = gPrefArray[i-1]; |
|
4110 |
TUint indexFree = gZoneUtilArray[aIndex].iFreePages; |
|
4111 |
TUint index2Free = gZoneUtilArray[aIndex2].iFreePages; |
|
4112 |
if (indexFree == gZoneUtilArray[aIndex].iPhysPages && |
|
4113 |
index2Free == gZoneUtilArray[aIndex2].iPhysPages && |
|
4114 |
indexFree >= aMaxPages && index2Free >= KIndex2Alloc && |
|
4115 |
freeInUsePages >= KIndex2Alloc + aMaxPages) |
|
4116 |
{ |
|
4117 |
zonesFound = ETrue; |
|
4118 |
break; |
|
4119 |
} |
|
4120 |
freeInUsePages += index2Free; |
|
4121 |
} |
|
4122 |
||
4123 |
// Could suitable RAM zones be found. |
|
4124 |
if (!zonesFound) |
|
4125 |
{ |
|
4126 |
test.Printf(_L("Insufficient memory - Skipping test...\n")); |
|
4127 |
return KErrNoMemory; |
|
4128 |
} |
|
4129 |
||
4130 |
if (aPageType == BEST_MOVABLE) |
|
4131 |
{ |
|
4132 |
// Allocate KIndex2Alloc movable pages to aIndex2 |
|
4133 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, aIndex2, KIndex2Alloc); |
|
4134 |
if (r != KErrNone) |
|
4135 |
{ |
|
4136 |
test.Printf(_L("Insufficient memory - Skipping test...\n")); |
|
4137 |
r = KErrNoMemory; |
|
4138 |
goto error; |
|
4139 |
} |
|
4140 |
||
4141 |
||
4142 |
||
4143 |
// Now allow movable pages to be allocated into the least preferable RAM zone under test only. |
|
4144 |
GetAllPageInfo(); |
|
4145 |
if (aMaxPages >= gZoneUtilArray[aIndex].iFreePages) |
|
4146 |
{ |
|
4147 |
test.Printf(_L("Insufficient memory available - Skipping test...\n")); |
|
4148 |
r = KErrNoMemory; |
|
4149 |
goto error; |
|
4150 |
} |
|
4151 |
// Allocate aMaxPages movable pages to aIndex |
|
4152 |
r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, aIndex, aMaxPages); |
|
4153 |
if (r != KErrNone) |
|
4154 |
{ |
|
4155 |
test.Printf(_L("Insufficient memory - Skipping test...\n")); |
|
4156 |
r = KErrNoMemory; |
|
4157 |
goto error; |
|
4158 |
} |
|
4159 |
||
4160 |
// Determine how many free pages there are in the RAM zones more preferable |
|
4161 |
// than the RAM zones under test. |
|
4162 |
GetPrefOrder(); |
|
4163 |
freeInUsePages = 0; |
|
4164 |
for (TUint i = 0; i < gZoneCount; i++) |
|
4165 |
{ |
|
4166 |
TUint tmpIndex = gPrefArray[i]; |
|
4167 |
if (tmpIndex == aIndex2) |
|
4168 |
break; |
|
4169 |
freeInUsePages += gZoneUtilArray[tmpIndex].iFreePages; |
|
4170 |
} |
|
4171 |
// Verify that the RAM layout is still suitable for the test. |
|
4172 |
if (gZoneUtilArray[aIndex].iAllocMovable != aMaxPages || |
|
4173 |
gZoneUtilArray[aIndex2].iAllocMovable != KIndex2Alloc || |
|
4174 |
gZoneUtilArray[aIndex].iAllocDiscardable || gZoneUtilArray[aIndex].iAllocFixed || |
|
4175 |
gZoneUtilArray[aIndex2].iAllocDiscardable || gZoneUtilArray[aIndex2].iAllocFixed || |
|
4176 |
freeInUsePages < KIndex2Alloc + aMaxPages) |
|
4177 |
{ |
|
4178 |
test.Printf(_L("Insufficient memory - Skipping test...\n")); |
|
4179 |
r = KErrNoMemory; |
|
4180 |
goto error; |
|
4181 |
} |
|
4182 |
||
4183 |
// now reset all the flags |
|
4184 |
ResetRamZoneFlags(); |
|
4185 |
||
4186 |
// Perform a general defrag |
|
4187 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, KTestMaxPages); |
|
4188 |
goto exit; |
|
4189 |
} |
|
4190 |
||
4191 |
if (aPageType == BEST_DISCARDABLE) |
|
4192 |
{ |
|
4193 |
||
4194 |
TUint minCacheSize = 0; |
|
4195 |
TUint maxCacheSize = 0; |
|
4196 |
TUint currentCacheSize = 0; |
|
4197 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
4198 |
test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
4199 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift); |
|
4200 |
||
4201 |
||
4202 |
||
4203 |
// Allocate a number of discardable pages to the 2nd least preferable zone under test |
|
4204 |
TInt disPages; |
|
4205 |
r = ZoneAllocDiscard(aIndex2, KIndex2Alloc, disPages); |
|
4206 |
if (r != KErrNone) |
|
4207 |
{ |
|
4208 |
test.Printf(_L("ZoneAllocDiscard() r = %d KIndex2Alloc = 0x%x disPages = 0x%x aIndex2 = %d - Skipping test...\n"), |
|
4209 |
r, KIndex2Alloc, disPages, aIndex2); |
|
4210 |
GetAllPageInfo(); |
|
4211 |
PrintPageInfo(); |
|
4212 |
r = KErrNoMemory; |
|
4213 |
goto error; |
|
4214 |
} |
|
4215 |
TUint discFillBytes = KIndex2Alloc << gPageShift; |
|
4216 |
r = DPTest::SetCacheSize(currentCacheSize + discFillBytes, currentCacheSize + discFillBytes); |
|
4217 |
if (r != KErrNone) |
|
4218 |
{ |
|
4219 |
test.Printf(_L("SetCacheSize r = 0x%x currentCacheSize + discFillBytes = 0x%x - Skipping test...\n"), |
|
4220 |
r, currentCacheSize + discFillBytes); |
|
4221 |
GetAllPageInfo(); |
|
4222 |
PrintPageInfo(); |
|
4223 |
r = KErrNoMemory; |
|
4224 |
goto error; |
|
4225 |
} |
|
4226 |
||
4227 |
||
4228 |
// Allocate a discardable pages equal to aMaxPages to the least preferable zone under test |
|
4229 |
GetAllPageInfo(); |
|
4230 |
if(aMaxPages >= gTotalPageCount.iFreePages) |
|
4231 |
{ |
|
4232 |
test.Printf(_L("Insufficient memory available - Skipping test...\n")); |
|
4233 |
r = KErrNoMemory; |
|
4234 |
goto error; |
|
4235 |
} |
|
4236 |
TUint allocPages = aMaxPages + KIndex2Alloc; |
|
4237 |
r = ZoneAllocDiscard(aIndex, aMaxPages, disPages); |
|
4238 |
if (r != KErrNone) |
|
4239 |
{ |
|
4240 |
test.Printf(_L("ZoneAllocDiscard() r = %d aMaxPages = 0x%x disPages = 0x%x aIndex = %d - Skipping test...\n"), |
|
4241 |
r, aMaxPages, disPages, aIndex); |
|
4242 |
GetAllPageInfo(); |
|
4243 |
PrintPageInfo(); |
|
4244 |
r = KErrNoMemory; |
|
4245 |
goto error; |
|
4246 |
} |
|
4247 |
discFillBytes = allocPages << gPageShift; |
|
4248 |
r = DPTest::SetCacheSize(currentCacheSize + discFillBytes, currentCacheSize + discFillBytes); |
|
4249 |
if (r != KErrNone) |
|
4250 |
{ |
|
4251 |
test.Printf(_L("SetCacheSize r = %d currentCacheSize + discFillBytes = 0x%x - Skipping test...\n"), |
|
4252 |
r, currentCacheSize + discFillBytes); |
|
4253 |
GetAllPageInfo(); |
|
4254 |
PrintPageInfo(); |
|
4255 |
r = KErrNoMemory; |
|
4256 |
goto error; |
|
4257 |
} |
|
4258 |
||
4259 |
||
4260 |
// Determine how many free pages there are in the RAM zones more preferable |
|
4261 |
// than the RAM zones under test. |
|
4262 |
GetPrefOrder(); |
|
4263 |
freeInUsePages = 0; |
|
4264 |
for (TUint i = 0; i < gZoneCount; i++) |
|
4265 |
{ |
|
4266 |
TUint tmpIndex = gPrefArray[i]; |
|
4267 |
if (tmpIndex == aIndex2) |
|
4268 |
break; |
|
4269 |
freeInUsePages += gZoneUtilArray[tmpIndex].iFreePages; |
|
4270 |
} |
|
4271 |
// Verify that the RAM layout is still suitable for the test. |
|
4272 |
if (r != KErrNone || gZoneUtilArray[aIndex].iAllocDiscardable != aMaxPages || |
|
4273 |
gZoneUtilArray[aIndex2].iAllocDiscardable != KIndex2Alloc || |
|
4274 |
gZoneUtilArray[aIndex].iAllocMovable || gZoneUtilArray[aIndex].iAllocFixed || |
|
4275 |
gZoneUtilArray[aIndex2].iAllocMovable || gZoneUtilArray[aIndex2].iAllocFixed || |
|
4276 |
freeInUsePages < KIndex2Alloc + aMaxPages) |
|
4277 |
{ |
|
4278 |
test.Printf(_L("Insufficient memory - Skipping test...\n")); |
|
4279 |
r = KErrNoMemory; |
|
4280 |
goto error; |
|
4281 |
} |
|
4282 |
||
4283 |
// now reset all the flags |
|
4284 |
ResetRamZoneFlags(); |
|
4285 |
||
4286 |
// Perform a general defrag with maxPages = KTestMaxPages |
|
4287 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, KTestMaxPages); |
|
4288 |
goto exit; |
|
4289 |
||
4290 |
} |
|
4291 |
error: |
|
4292 |
// Reset all the flags |
|
4293 |
ResetRamZoneFlags(); |
|
4294 |
exit: |
|
4295 |
return r; |
|
4296 |
} |
|
4297 |
||
4298 |
// |
|
4299 |
// TestDefragRamMaxPages |
|
4300 |
// |
|
4301 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4302 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0530 |
|
4303 |
//! @SYMTestType CIT |
|
4304 |
//! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::DefragRam() |
|
4305 |
//! @SYMPREQ PREQ308 |
|
4306 |
//! @SYMTestPriority High |
|
4307 |
//! @SYMTestActions |
|
4308 |
//! 1. Call function with invalid aMaxPages |
|
4309 |
//! 2. Call DefragRam when aMaxPages < number of movable pages in least preferable zone |
|
4310 |
//! 3. Call DefragRam when aMaxPages > number of movable pages in least preferable zone |
|
4311 |
//! 4. Call DefragRam when aMaxPages = number of movable pages in least preferable zone |
|
4312 |
//! 5. Call DefragRam when aMaxPages < number of discardable pages in least preferable zone |
|
4313 |
//! 6. Call DefragRam when aMaxPages > number of discardable pages in least preferable zone |
|
4314 |
//! 7. Call DefragRam when aMaxPages = number of discardable pages in least preferable zone |
|
4315 |
//! |
|
4316 |
//! @SYMTestExpectedResults |
|
4317 |
//! 1. KErrArgument |
|
4318 |
//! 2. Least preferable zone and 2nd least preferable zone have not been emptied |
|
4319 |
//! 3. Least preferable zone has been emptied and 2nd least preferable zone has not been emptied |
|
4320 |
//! 4. Least preferable zone has been emptied and 2nd least preferable zone not not been emptied |
|
4321 |
//! 5. Least preferable zone and 2nd least preferable zone have not been emptied |
|
4322 |
//! 6. Least preferable zone has been emptied and 2nd least preferable zone has not been emptied |
|
4323 |
//! 7. Least preferable zone has been emptied and 2nd least preferable zone not not been emptied |
|
4324 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4325 |
TInt TestDefragRamMaxPages() |
|
4326 |
{ |
|
4327 |
test.Start(_L("Test1: Call DefragRam with invalid aMaxPages ")); |
|
4328 |
TestStart(); |
|
4329 |
||
4330 |
gDefragMaxPages = -1; |
|
4331 |
||
4332 |
TInt r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4333 |
TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); |
|
4334 |
if (r != KErrArgument) |
|
4335 |
{ |
|
4336 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
4337 |
TEST_FAIL; |
|
4338 |
} |
|
4339 |
else |
|
4340 |
{ |
|
4341 |
test.Printf(_L("Passed...\n")); |
|
4342 |
} |
|
4343 |
TestEnd(); |
|
4344 |
||
4345 |
test.Next(_L("Test2: Call DefragRam aMaxPages < number of movable pages in least preferable zone ")); |
|
4346 |
TestStart(); |
|
4347 |
gChunkArray1 = new RChunk; |
|
4348 |
gChunkArraySize1 = 1; |
|
4349 |
gChunkArray2 = new RChunk; |
|
4350 |
gChunkArraySize2 = 1; |
|
4351 |
TUint index = 0; |
|
4352 |
TUint index2 = 0; |
|
4353 |
r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages + 1, index, index2); |
|
4354 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4355 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4356 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4357 |
} |
|
4358 |
else |
|
4359 |
{ |
|
4360 |
if (r == KErrNone) |
|
4361 |
{ |
|
4362 |
GetAllPageInfo(); |
|
4363 |
if (gZoneUtilArray[index].iAllocMovable < KTestMaxPages + 1 || |
|
4364 |
gZoneUtilArray[index2].iAllocMovable < KIndex2Alloc) |
|
4365 |
{ |
|
4366 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4367 |
index, KTestMaxPages + 1, index2, KIndex2Alloc); |
|
4368 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4369 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4370 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4371 |
TEST_FAIL; |
|
4372 |
} |
|
4373 |
||
4374 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4375 |
// if there is free space elsewhere |
|
4376 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4377 |
GetAllPageInfo(); |
|
4378 |
if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages + 1 && |
|
4379 |
(gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) |
|
4380 |
{ |
|
4381 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4382 |
index, 0, index2, 0); |
|
4383 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4384 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4385 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4386 |
TEST_FAIL; |
|
4387 |
} |
|
4388 |
else |
|
4389 |
{ |
|
4390 |
test.Printf(_L("Passed...\n")); |
|
4391 |
} |
|
4392 |
} |
|
4393 |
else |
|
4394 |
{ |
|
4395 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4396 |
} |
|
4397 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4398 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
4399 |
} |
|
4400 |
Ldd.FreeFromAllZones(); |
|
4401 |
TestEnd(); |
|
4402 |
||
4403 |
||
4404 |
test.Next(_L("Test3: Call DefragRam aMaxPages > number of movable pages in least preferable zone ")); |
|
4405 |
TestStart(); |
|
4406 |
gChunkArray1 = new RChunk; |
|
4407 |
gChunkArraySize1 = 1; |
|
4408 |
gChunkArray2 = new RChunk; |
|
4409 |
gChunkArraySize2 = 1; |
|
4410 |
r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages - 1, index, index2); |
|
4411 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4412 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4413 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4414 |
} |
|
4415 |
else |
|
4416 |
{ |
|
4417 |
if (r == KErrNone) |
|
4418 |
{ |
|
4419 |
GetAllPageInfo(); |
|
4420 |
if (gZoneUtilArray[index].iAllocMovable != 0) |
|
4421 |
{ |
|
4422 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4423 |
index, 0, index2, KIndex2Alloc); |
|
4424 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4425 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4426 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4427 |
TEST_FAIL; |
|
4428 |
} |
|
4429 |
||
4430 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4431 |
// if there is free space elsewhere |
|
4432 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4433 |
||
4434 |
GetAllPageInfo(); |
|
4435 |
if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages - 1 && |
|
4436 |
(gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) |
|
4437 |
{ |
|
4438 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4439 |
index, 0, index2, 0); |
|
4440 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4441 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4442 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4443 |
TEST_FAIL; |
|
4444 |
} |
|
4445 |
else |
|
4446 |
{ |
|
4447 |
test.Printf(_L("Passed...\n")); |
|
4448 |
} |
|
4449 |
} |
|
4450 |
else |
|
4451 |
{ |
|
4452 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4453 |
} |
|
4454 |
||
4455 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4456 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
4457 |
} |
|
4458 |
Ldd.FreeFromAllZones(); |
|
4459 |
TestEnd(); |
|
4460 |
||
4461 |
||
4462 |
test.Next(_L("Test4: Call DefragRam aMaxPages = number of movable pages in least preferable zone ")); |
|
4463 |
TestStart(); |
|
4464 |
gChunkArray1 = new RChunk; |
|
4465 |
gChunkArraySize1 = 1; |
|
4466 |
gChunkArray2 = new RChunk; |
|
4467 |
gChunkArraySize2 = 1; |
|
4468 |
r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages, index, index2); |
|
4469 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4470 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4471 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4472 |
} |
|
4473 |
else |
|
4474 |
{ |
|
4475 |
if (r == KErrNone) |
|
4476 |
{ |
|
4477 |
GetAllPageInfo(); |
|
4478 |
if (gZoneUtilArray[index].iAllocMovable != 0) |
|
4479 |
{ |
|
4480 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4481 |
index, 0, index2, KIndex2Alloc); |
|
4482 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4483 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4484 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4485 |
TEST_FAIL; |
|
4486 |
} |
|
4487 |
||
4488 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4489 |
// if there is free space elsewhere |
|
4490 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4491 |
||
4492 |
GetAllPageInfo(); |
|
4493 |
if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages && |
|
4494 |
(gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) |
|
4495 |
{ |
|
4496 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4497 |
index, 0, index2, 0); |
|
4498 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4499 |
CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); |
|
4500 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4501 |
TEST_FAIL; |
|
4502 |
} |
|
4503 |
else |
|
4504 |
{ |
|
4505 |
test.Printf(_L("Passed...\n")); |
|
4506 |
} |
|
4507 |
} |
|
4508 |
else |
|
4509 |
{ |
|
4510 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4511 |
} |
|
4512 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4513 |
RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); |
|
4514 |
} |
|
4515 |
Ldd.FreeFromAllZones(); |
|
4516 |
TestEnd(); |
|
4517 |
||
4518 |
test.Next(_L("Test5: Call DefragRam aMaxPages < number of discardable pages in least preferable zone ")); |
|
4519 |
TestStart(); |
|
4520 |
if (gPagedRom) |
|
4521 |
{ |
|
4522 |
r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages + 1, index, index2); |
|
4523 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4524 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4525 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4526 |
} |
|
4527 |
else |
|
4528 |
{ |
|
4529 |
if (r == KErrNone) |
|
4530 |
{ |
|
4531 |
GetAllPageInfo(); |
|
4532 |
if (gZoneUtilArray[index].iAllocDiscardable < KTestMaxPages + 1 || |
|
4533 |
gZoneUtilArray[index2].iAllocDiscardable < KIndex2Alloc) |
|
4534 |
{ |
|
4535 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4536 |
index, KTestMaxPages + 1, index2, KIndex2Alloc); |
|
4537 |
CLEANUP(ResetDPCache()); |
|
4538 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4539 |
TEST_FAIL; |
|
4540 |
} |
|
4541 |
||
4542 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4543 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4544 |
||
4545 |
GetAllPageInfo(); |
|
4546 |
if (gZoneUtilArray[index].iAllocDiscardable != 0 || |
|
4547 |
gZoneUtilArray[index2].iAllocDiscardable != 0) |
|
4548 |
{ |
|
4549 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4550 |
index, 0, index2, 0); |
|
4551 |
CLEANUP(ResetDPCache()); |
|
4552 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4553 |
TEST_FAIL; |
|
4554 |
} |
|
4555 |
else |
|
4556 |
{ |
|
4557 |
test.Printf(_L("Passed...\n")); |
|
4558 |
} |
|
4559 |
} |
|
4560 |
else |
|
4561 |
{ |
|
4562 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4563 |
} |
|
4564 |
ResetDPCache(); |
|
4565 |
} |
|
4566 |
Ldd.FreeFromAllZones(); |
|
4567 |
} |
|
4568 |
else |
|
4569 |
{ |
|
4570 |
test.Printf(_L("Not a Paged Rom - Skipping...\n")); |
|
4571 |
} |
|
4572 |
TestEnd(); |
|
4573 |
||
4574 |
test.Next(_L("Test6: Call DefragRam aMaxPages > number of discardable pages in least preferable zone ")); |
|
4575 |
TestStart(); |
|
4576 |
||
4577 |
if (gPagedRom) |
|
4578 |
{ |
|
4579 |
r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages - 1, index, index2); |
|
4580 |
||
4581 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4582 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4583 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4584 |
} |
|
4585 |
else |
|
4586 |
{ |
|
4587 |
if (r == KErrNone) |
|
4588 |
{ |
|
4589 |
GetAllPageInfo(); |
|
4590 |
if (gZoneUtilArray[index].iAllocDiscardable != 0|| |
|
4591 |
gZoneUtilArray[index2].iAllocDiscardable != KIndex2Alloc) |
|
4592 |
{ |
|
4593 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4594 |
index, 0, index2, KIndex2Alloc); |
|
4595 |
CLEANUP(ResetDPCache()); |
|
4596 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4597 |
TEST_FAIL; |
|
4598 |
} |
|
4599 |
||
4600 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4601 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4602 |
GetAllPageInfo(); |
|
4603 |
if (gZoneUtilArray[index].iAllocDiscardable != 0|| |
|
4604 |
gZoneUtilArray[index2].iAllocDiscardable != 0) |
|
4605 |
{ |
|
4606 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4607 |
index, 0, index2, 0); |
|
4608 |
CLEANUP(ResetDPCache()); |
|
4609 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4610 |
TEST_FAIL; |
|
4611 |
} |
|
4612 |
else |
|
4613 |
{ |
|
4614 |
test.Printf(_L("Passed...\n")); |
|
4615 |
} |
|
4616 |
} |
|
4617 |
else |
|
4618 |
{ |
|
4619 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4620 |
} |
|
4621 |
ResetDPCache(); |
|
4622 |
} |
|
4623 |
Ldd.FreeFromAllZones(); |
|
4624 |
} |
|
4625 |
else |
|
4626 |
{ |
|
4627 |
test.Printf(_L("Not a Paged Rom - Skipping...\n")); |
|
4628 |
} |
|
4629 |
TestEnd(); |
|
4630 |
||
4631 |
||
4632 |
test.Next(_L("Test4: Call DefragRam aMaxPages = number of discardable pages in least preferable zone ")); |
|
4633 |
TestStart(); |
|
4634 |
||
4635 |
if(gPagedRom) |
|
4636 |
{ |
|
4637 |
r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages, index, index2); |
|
4638 |
||
4639 |
if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) |
|
4640 |
{// Cannot perform test with fixed pages in least preferable zones |
|
4641 |
test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); |
|
4642 |
} |
|
4643 |
else |
|
4644 |
{ |
|
4645 |
if (r == KErrNone) |
|
4646 |
{ |
|
4647 |
GetAllPageInfo(); |
|
4648 |
if (gZoneUtilArray[index].iAllocDiscardable != 0|| |
|
4649 |
gZoneUtilArray[index2].iAllocDiscardable != KIndex2Alloc) |
|
4650 |
{ |
|
4651 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4652 |
index, 0, index2, KIndex2Alloc); |
|
4653 |
CLEANUP(ResetDPCache()); |
|
4654 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4655 |
TEST_FAIL; |
|
4656 |
} |
|
4657 |
||
4658 |
// Double check that if DefragRam is called with maxPages = 0, these zones are emptied |
|
4659 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4660 |
GetAllPageInfo(); |
|
4661 |
if (gZoneUtilArray[index].iAllocDiscardable != 0|| |
|
4662 |
gZoneUtilArray[index2].iAllocDiscardable != 0) |
|
4663 |
{ |
|
4664 |
test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), |
|
4665 |
index, 0, index2, 0); |
|
4666 |
CLEANUP(ResetDPCache()); |
|
4667 |
CLEANUP(Ldd.FreeFromAllZones()); |
|
4668 |
TEST_FAIL; |
|
4669 |
} |
|
4670 |
else |
|
4671 |
{ |
|
4672 |
test.Printf(_L("Passed...\n")); |
|
4673 |
} |
|
4674 |
} |
|
4675 |
else |
|
4676 |
{ |
|
4677 |
test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); |
|
4678 |
} |
|
4679 |
ResetDPCache(); |
|
4680 |
} |
|
4681 |
Ldd.FreeFromAllZones(); |
|
4682 |
} |
|
4683 |
else |
|
4684 |
{ |
|
4685 |
test.Printf(_L("Not a Paged Rom - Skipping...\n")); |
|
4686 |
} |
|
4687 |
TestEnd(); |
|
4688 |
||
4689 |
test.End(); |
|
4690 |
return KErrNone; |
|
4691 |
} |
|
4692 |
||
4693 |
||
4694 |
// |
|
4695 |
// TestEmptyRamZone |
|
4696 |
// |
|
4697 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4698 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0531 |
|
4699 |
//! @SYMTestType CIT |
|
4700 |
//! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::EmptyRamZone() |
|
4701 |
//! @SYMPREQ PREQ308 |
|
4702 |
//! @SYMTestPriority High |
|
4703 |
//! @SYMTestActions |
|
4704 |
//! 1. Fragment the memory. Call function with a valid aID, |
|
4705 |
//! i.e. a zone which lies within the range of zones. |
|
4706 |
//! 2. Fragment the memory. Call function with an invalid aID |
|
4707 |
//! i.e. a zone which does not exist within the range of zones. |
|
4708 |
//! 3. Fragment the memory. Following this, call a zone specific defrag on a particular zone. |
|
4709 |
//! Call the zone specific defrag again on the same zone whilst the other defrag is still |
|
4710 |
//! running on that zone. |
|
4711 |
//! 4. Fragment the memory. Following this, call the TRamDefragRequest::DefragRam() to perform general defrag. |
|
4712 |
//! Following this call zone specific defrag whilst the general defrag is still running. |
|
4713 |
//! 5. Fragment the memory. Following this, call a zone specific defrag on a particular zone. |
|
4714 |
//! Whilst the zone defrag is running, call a general defrag |
|
4715 |
//! 6: Fragment the memory. Following this, call the function on specifc zone and |
|
4716 |
//! at the same time allocate pages to the zone |
|
4717 |
//! 7. Fragment the memory. Call EmptyRamZone() on every zone one after the other. |
|
4718 |
//! 8. Fragment the memory. Allocate a couple of fixed pages to a zone that contains movable pages. |
|
4719 |
//! Following this, Call EmptyRamZone() on that zone. |
|
4720 |
//! |
|
4721 |
//! @SYMTestExpectedResults |
|
4722 |
//! 1. KErrNone |
|
4723 |
//! 2. KErrArgument |
|
4724 |
//! 3. KErrNone and the zone has been emptied |
|
4725 |
//! 4. Zone has not been emptied, as the general defrag has already placed pages in the zone |
|
4726 |
//! 5. Zone has been emptied |
|
4727 |
//! 6. KErrNone and pages have been allocated in the zone |
|
4728 |
//! 7. One of the following scenarios should occur: |
|
4729 |
//! a. If the cache has not reached its minimum size, then all the movable pages should |
|
4730 |
//! be moved from the zone if there are enough free pages in the other zones. |
|
4731 |
//! However, when demand paging is off, all movable pages should be moved from the zone, again if there |
|
4732 |
//! are enough free pages in the other zones. |
|
4733 |
//! b. If the current size of the cache minus the number of discardable pages in the zone being emptied is |
|
4734 |
//! not less than the minimum cache size, then all the discardable pages should be discarded of. |
|
4735 |
//! However, when demand paging is off, all discardable pages should be removed from |
|
4736 |
//! the zone. |
|
4737 |
//! 8. KErrNoMemory, however all movable and discardable pages have been moved from the zone |
|
4738 |
//--------------------------------------------------------------------------------------------------------------------- |
|
4739 |
TInt TestEmptyRamZone() |
|
4740 |
{ |
|
4741 |
TInt r = KErrNone; |
|
4742 |
TInt r2 = KErrNone; |
|
4743 |
||
4744 |
test.Start(_L("Test1: Call EmptyRamZone with valid aID ")); |
|
4745 |
TestStart(); |
|
4746 |
||
4747 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4748 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4749 |
||
4750 |
GetAllPageInfo(); |
|
4751 |
TUint index = gZoneCount - 1; |
|
4752 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4753 |
{ |
|
4754 |
-- index; |
|
4755 |
} |
|
4756 |
TUint defragZoneID = gZoneConfigArray[index].iZoneId; |
|
4757 |
test.Printf(_L("Zone ID = %d\n"), defragZoneID); |
|
4758 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4759 |
{ |
|
4760 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
4761 |
} |
|
4762 |
else |
|
4763 |
{ |
|
4764 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); |
|
4765 |
GetAllPageInfo(); |
|
4766 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
4767 |
if (freeInOthers && (r != KErrNone || !CheckZoneIsOff(index))) |
|
4768 |
{ |
|
4769 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
4770 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4771 |
TEST_FAIL; |
|
4772 |
} |
|
4773 |
else |
|
4774 |
{ |
|
4775 |
test.Printf(_L("Passed...\n")); |
|
4776 |
} |
|
4777 |
} |
|
4778 |
||
4779 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4780 |
TestEnd(); |
|
4781 |
||
4782 |
||
4783 |
test.Next(_L("Test2: Call EmptyRamZone with invalid aID ")); |
|
4784 |
TestStart(); |
|
4785 |
gChunkArray1 = new RChunk; |
|
4786 |
gChunkArraySize1 = 1; |
|
4787 |
defragZoneID = KInvalidZoneID; |
|
4788 |
||
4789 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); |
|
4790 |
||
4791 |
if (r != KErrArgument) |
|
4792 |
{ |
|
4793 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
4794 |
TEST_FAIL; |
|
4795 |
} |
|
4796 |
else |
|
4797 |
{ |
|
4798 |
test.Printf(_L("Passed...\n")); |
|
4799 |
} |
|
4800 |
||
4801 |
TestEnd(); |
|
4802 |
||
4803 |
||
4804 |
test.Next(_L("Test3: Call EmptyRamZone twice at the same time ")); |
|
4805 |
TestStart(); |
|
4806 |
||
4807 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4808 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4809 |
||
4810 |
GetAllPageInfo(); |
|
4811 |
index = gZoneCount - 1; |
|
4812 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4813 |
{ |
|
4814 |
-- index; |
|
4815 |
} |
|
4816 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
4817 |
||
4818 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4819 |
{ |
|
4820 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
4821 |
} |
|
4822 |
else |
|
4823 |
{ |
|
4824 |
r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny *)defragZoneID); |
|
4825 |
if (r != KErrNone) |
|
4826 |
{ |
|
4827 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
4828 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4829 |
TEST_FAIL; |
|
4830 |
} |
|
4831 |
||
4832 |
gTestThread.Logon(status); |
|
4833 |
gTestThread.Resume(); |
|
4834 |
||
4835 |
User::After(10); |
|
4836 |
||
4837 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); |
|
4838 |
||
4839 |
User::WaitForRequest(status); |
|
4840 |
r2 = status.Int(); |
|
4841 |
||
4842 |
GetAllPageInfo(); |
|
4843 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
4844 |
if (r != r2 || |
|
4845 |
(freeInOthers && (r != KErrNone || r2 != KErrNone || !CheckZoneIsOff(index)))) |
|
4846 |
{ |
|
4847 |
test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone %d has not been emptied\n"), |
|
4848 |
r, r2, KErrNone, defragZoneID); |
|
4849 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4850 |
TEST_FAIL; |
|
4851 |
} |
|
4852 |
else |
|
4853 |
{ |
|
4854 |
test.Printf(_L("Passed...\n")); |
|
4855 |
} |
|
4856 |
||
4857 |
gTestThread.Close(); |
|
4858 |
} |
|
4859 |
||
4860 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4861 |
TestEnd(); |
|
4862 |
||
4863 |
||
4864 |
test.Next(_L("Test4: Call general defrag and zone defrag at the same time ")); |
|
4865 |
TestStart(); |
|
4866 |
||
4867 |
TInt waitTime = 10000; |
|
4868 |
||
4869 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4870 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4871 |
||
4872 |
GetAllPageInfo(); |
|
4873 |
index = gZoneCount - 1; |
|
4874 |
while (index > 0 && gZoneUtilArray[index].iAllocFixed > 0) |
|
4875 |
{ |
|
4876 |
index--; |
|
4877 |
} |
|
4878 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
4879 |
||
4880 |
if (index == 0 && gZoneUtilArray[index].iAllocFixed > 0) |
|
4881 |
{ |
|
4882 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
4883 |
} |
|
4884 |
else |
|
4885 |
{ |
|
4886 |
r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
4887 |
if (r != KErrNone) |
|
4888 |
{ |
|
4889 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
4890 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4891 |
TEST_FAIL; |
|
4892 |
} |
|
4893 |
gTestThread.Logon(status); |
|
4894 |
||
4895 |
gTestThread.Resume(); |
|
4896 |
User::After(waitTime); |
|
4897 |
||
4898 |
TESTDEBUG(test.Printf(_L("Zone defrag running on main thread\n"))); |
|
4899 |
||
4900 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); |
|
4901 |
||
4902 |
User::WaitForRequest(status); |
|
4903 |
r2 = status.Int(); |
|
4904 |
||
4905 |
GetAllPageInfo(); |
|
4906 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
4907 |
if (r2 != KErrNone || |
|
4908 |
(freeInOthers && (r != KErrNone || !CheckZoneIsOff(index)))) |
|
4909 |
{ |
|
4910 |
test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone %d is on unexpectedly\n"), |
|
4911 |
r, r2, KErrNone, defragZoneID); |
|
4912 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4913 |
TEST_FAIL; |
|
4914 |
} |
|
4915 |
else |
|
4916 |
{ |
|
4917 |
test.Printf(_L("Passed...\n")); |
|
4918 |
} |
|
4919 |
||
4920 |
gTestThread.Close(); |
|
4921 |
} |
|
4922 |
||
4923 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4924 |
TestEnd(); |
|
4925 |
||
4926 |
||
4927 |
test.Next(_L("Test5: Call zone defrag and general defrag at the same time ")); |
|
4928 |
TestStart(); |
|
4929 |
||
4930 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4931 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4932 |
||
4933 |
GetAllPageInfo(); |
|
4934 |
index = gZoneCount - 1; |
|
4935 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4936 |
{ |
|
4937 |
-- index; |
|
4938 |
} |
|
4939 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
4940 |
||
4941 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4942 |
{ |
|
4943 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
4944 |
} |
|
4945 |
else |
|
4946 |
{ |
|
4947 |
r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); |
|
4948 |
if (r != KErrNone) |
|
4949 |
{ |
|
4950 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
4951 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4952 |
TEST_FAIL; |
|
4953 |
} |
|
4954 |
gTestThread.Logon(status); |
|
4955 |
||
4956 |
gTestThread.Resume(); |
|
4957 |
User::After(0); |
|
4958 |
||
4959 |
TESTDEBUG(test.Printf(_L("Zone defrag running on main thread\n"))); |
|
4960 |
||
4961 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); |
|
4962 |
||
4963 |
User::WaitForRequest(status); |
|
4964 |
r2 = status.Int(); |
|
4965 |
||
4966 |
GetAllPageInfo(); |
|
4967 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
4968 |
if (r != KErrNone || |
|
4969 |
(freeInOthers && (r2 != KErrNone || !CheckZoneIsOff(index)))) |
|
4970 |
{ |
|
4971 |
test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone 0x%x is on unexpectedly\n"), |
|
4972 |
r, r2, KErrNone, defragZoneID); |
|
4973 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
4974 |
TEST_FAIL; |
|
4975 |
} |
|
4976 |
else |
|
4977 |
{ |
|
4978 |
test.Printf(_L("Passed...\n")); |
|
4979 |
} |
|
4980 |
||
4981 |
gTestThread.Close(); |
|
4982 |
} |
|
4983 |
||
4984 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
4985 |
TestEnd(); |
|
4986 |
||
4987 |
||
4988 |
test.Next(_L("Test6: Call function TRamDefragRequest::EmptyRamZone on specifc zone and at the same time allocate pages to the zone")); |
|
4989 |
TestStart(); |
|
4990 |
||
4991 |
TInt pagesAlloc = 1; // Try and allocate just one page whilst trying to empty the zone. |
|
4992 |
||
4993 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
4994 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
4995 |
||
4996 |
GetAllPageInfo(); |
|
4997 |
index = gZoneCount - 1; |
|
4998 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
4999 |
{ |
|
5000 |
-- index; |
|
5001 |
} |
|
5002 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5003 |
||
5004 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5005 |
{ |
|
5006 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5007 |
} |
|
5008 |
else |
|
5009 |
{ |
|
5010 |
TInt numPassed = 0; |
|
5011 |
for (waitTime = 1000; waitTime > 0; waitTime-=10) |
|
5012 |
{ |
|
5013 |
r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); |
|
5014 |
if (r != KErrNone) |
|
5015 |
{ |
|
5016 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5017 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5018 |
TEST_FAIL; |
|
5019 |
} |
|
5020 |
gTestThread.Logon(status); |
|
5021 |
||
5022 |
gTestThread.Resume(); |
|
5023 |
User::After(waitTime); |
|
5024 |
||
5025 |
r = Ldd.ZoneAllocDiscontiguous(defragZoneID, pagesAlloc); |
|
5026 |
||
5027 |
User::WaitForRequest(status); |
|
5028 |
r2 = status.Int(); |
|
5029 |
||
5030 |
if (r2 != KErrNone) |
|
5031 |
{ |
|
5032 |
test.Printf(_L("Empty was unsuccsessful: r2 = %d, expected = %d\n"), r2, KErrNone); |
|
5033 |
} |
|
5034 |
else if (r != KErrNone) |
|
5035 |
{ |
|
5036 |
test.Printf(_L("Fail: r = %d, expected = %d, r2 = %d, expected = %d, zone = 0x%x\n"), |
|
5037 |
r, KErrNone, r2, KErrNone, defragZoneID); |
|
5038 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5039 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
5040 |
TEST_FAIL; |
|
5041 |
} |
|
5042 |
else |
|
5043 |
{ |
|
5044 |
numPassed ++; |
|
5045 |
} |
|
5046 |
||
5047 |
Ldd.FreeAllFixedPages(); |
|
5048 |
||
5049 |
gTestThread.Close(); |
|
5050 |
} |
|
5051 |
if (numPassed > 0) |
|
5052 |
{ |
|
5053 |
test.Printf(_L("Passed...\n")); |
|
5054 |
} |
|
5055 |
} |
|
5056 |
||
5057 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5058 |
TestEnd(); |
|
5059 |
||
5060 |
||
5061 |
test.Next(_L("Test7: Call function TRamDefragRequest::EmptyRamZone on every zone one after the other")); |
|
5062 |
TestStart(); |
|
5063 |
||
5064 |
Ldd.ResetDriver(); |
|
5065 |
||
5066 |
for (index = 0; index < gZoneCount; index ++) |
|
5067 |
{ |
|
5068 |
// Variables for DP ROM cache sizes |
|
5069 |
TUint minCacheSize = 0; |
|
5070 |
TUint maxCacheSize = 0; |
|
5071 |
TUint currentCacheSize = 0; |
|
5072 |
||
5073 |
if (gPagedRom) |
|
5074 |
{ |
|
5075 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
5076 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5077 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5078 |
// Calculate the maximum size available for the DP cache. |
|
5079 |
TUint minZoneFree = KMaxTUint; |
|
5080 |
TUint maxDisFillBytes = 0; |
|
5081 |
GetAllPageInfo(); |
|
5082 |
for (TUint i = 0; i < gZoneCount; i++) |
|
5083 |
{ |
|
5084 |
maxDisFillBytes += gZoneUtilArray[i].iFreePages; |
|
5085 |
maxDisFillBytes += gZoneUtilArray[i].iAllocDiscardable; |
|
5086 |
if (minZoneFree > gZoneUtilArray[i].iFreePages) |
|
5087 |
minZoneFree = gZoneUtilArray[i].iFreePages; |
|
5088 |
} |
|
5089 |
test.Printf(_L("Free pages 0x%x maxDisFillBytes 0x%x\n"), gTotalPageCount.iFreePages, maxDisFillBytes); |
|
5090 |
maxDisFillBytes <<= gPageShift; |
|
5091 |
||
5092 |
r = DPTest::SetCacheSize(maxDisFillBytes, maxDisFillBytes); |
|
5093 |
if (r != KErrNone) |
|
5094 |
{ |
|
5095 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5096 |
CLEANUP(ResetDPCache()); |
|
5097 |
TEST_FAIL; |
|
5098 |
} |
|
5099 |
||
5100 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
5101 |
TESTDEBUG(test.Printf(_L("CacheSize2: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5102 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5103 |
if (currentCacheSize != maxDisFillBytes) |
|
5104 |
{ |
|
5105 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5106 |
CLEANUP(ResetDPCache()); |
|
5107 |
TEST_FAIL; |
|
5108 |
} |
|
5109 |
||
5110 |
GetAllPageInfo(); |
|
5111 |
test.Printf(_L("Free pages after alloc discardable1 = 0x%x\n"), gTotalPageCount.iFreePages); |
|
5112 |
||
5113 |
r = DPTest::SetCacheSize(minZoneFree << gPageShift, maxDisFillBytes); |
|
5114 |
if (r != KErrNone) |
|
5115 |
{ |
|
5116 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5117 |
CLEANUP(ResetDPCache()); |
|
5118 |
TEST_FAIL; |
|
5119 |
} |
|
5120 |
||
5121 |
// Check all zones have no free pages. |
|
5122 |
GetAllPageInfo(); |
|
5123 |
for (TUint i = 0; i < gZoneCount; i++) |
|
5124 |
{ |
|
5125 |
if (gZoneUtilArray[i].iFreePages != 0) |
|
5126 |
{ |
|
5127 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5128 |
CLEANUP(ResetDPCache()); |
|
5129 |
TEST_FAIL; |
|
5130 |
} |
|
5131 |
} |
|
5132 |
} |
|
5133 |
else |
|
5134 |
{ |
|
5135 |
// Fragment the RAM with some movable pages |
|
5136 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); |
|
5137 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5138 |
} |
|
5139 |
||
5140 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
5141 |
||
5142 |
GetAllPageInfo(); |
|
5143 |
TUint origUnknownInZone = gZoneUtilArray[index].iAllocUnknown; |
|
5144 |
TUint origMovInZone = gZoneUtilArray[index].iAllocMovable; |
|
5145 |
TUint origFreeInZone = gZoneUtilArray[index].iFreePages; |
|
5146 |
||
5147 |
test.Printf(_L("Zone ID 0x%x - fixedPages = 0x%x, unknownPages = 0x%x, discardablePages = 0x%x movable = 0x%x free = 0x%x\n"), |
|
5148 |
zoneID, gZoneUtilArray[index].iAllocFixed, origUnknownInZone, gZoneUtilArray[index].iAllocDiscardable, |
|
5149 |
origMovInZone, origFreeInZone); |
|
5150 |
||
5151 |
||
5152 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); |
|
5153 |
||
5154 |
GetAllPageInfo(); |
|
5155 |
TUint unknownPages = gZoneUtilArray[index].iAllocUnknown; |
|
5156 |
TUint discPages = gZoneUtilArray[index].iAllocDiscardable; |
|
5157 |
TUint movablePages = gZoneUtilArray[index].iAllocMovable; |
|
5158 |
||
5159 |
TUint freeInOtherZones = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5160 |
if(movablePages && freeInOtherZones) |
|
5161 |
{ |
|
5162 |
test.Printf(_L("Fail: Zone ID %x all the movable pages haven't been moved\n"), zoneID); |
|
5163 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5164 |
CLEANUP(ResetDPCache()); |
|
5165 |
TEST_FAIL; |
|
5166 |
} |
|
5167 |
||
5168 |
if (origUnknownInZone != unknownPages) |
|
5169 |
{ |
|
5170 |
test.Printf(_L("Fail: Zone ID %x unknown pages before and after are not equal\n"), zoneID); |
|
5171 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5172 |
CLEANUP(ResetDPCache()); |
|
5173 |
TEST_FAIL; |
|
5174 |
} |
|
5175 |
||
5176 |
if (!gPagedRom) |
|
5177 |
{ |
|
5178 |
if (discPages && freeInOtherZones) |
|
5179 |
{ |
|
5180 |
test.Printf(_L("Fail: Zone ID %x all the discardable pages haven't been moved\n"), zoneID); |
|
5181 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5182 |
CLEANUP(ResetDPCache()); |
|
5183 |
TEST_FAIL; |
|
5184 |
} |
|
5185 |
} |
|
5186 |
else |
|
5187 |
{ |
|
5188 |
DPTest::CacheSize(minCacheSize, maxCacheSize, currentCacheSize); |
|
5189 |
TESTDEBUG(test.Printf(_L("CacheSize3: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5190 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5191 |
// The the discardable pages should have been discarded or moved unless |
|
5192 |
// there is no room in the other zones and the cache size is already at its minimum |
|
5193 |
if (discPages && (freeInOtherZones || currentCacheSize != minCacheSize)) |
|
5194 |
{ |
|
5195 |
test.Printf(_L("Fail: Zone 0x%x all the discardable pages haven't been moved\n"), zoneID); |
|
5196 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5197 |
CLEANUP(ResetDPCache()); |
|
5198 |
TEST_FAIL; |
|
5199 |
} |
|
5200 |
} |
|
5201 |
test.Printf(_L("Passed...\n")); |
|
5202 |
} |
|
5203 |
// TestEnd() willl cleanup what's required |
|
5204 |
TestEnd(); |
|
5205 |
||
5206 |
test.Next(_L("Test8: Call function TRamDefragRequest::EmptyRamZone on a zone that contains fixed and movable pages")); |
|
5207 |
TestStart(); |
|
5208 |
||
5209 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5210 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5211 |
||
5212 |
GetAllPageInfo(); |
|
5213 |
index = gZoneCount - 1; |
|
5214 |
while (index > 0 && (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) |
|
5215 |
{ |
|
5216 |
-- index; |
|
5217 |
} |
|
5218 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5219 |
||
5220 |
if (index == 0 && (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) |
|
5221 |
{ |
|
5222 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5223 |
} |
|
5224 |
else |
|
5225 |
{ |
|
5226 |
test.Printf(_L("defragZoneID = 0x%x\n"), defragZoneID); |
|
5227 |
test.Printf(_L("movable = 0x%x discardable = 0x%x\n"), |
|
5228 |
gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable); |
|
5229 |
||
5230 |
||
5231 |
Ldd.ZoneAllocDiscontiguous(defragZoneID, 2); // Allocated 2 fixed pages to ensure that zone cannot be emptied |
|
5232 |
||
5233 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); |
|
5234 |
||
5235 |
GetAllPageInfo(); |
|
5236 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5237 |
if (r != KErrNoMemory || |
|
5238 |
(freeInOthers && |
|
5239 |
(gZoneUtilArray[index].iAllocMovable || |
|
5240 |
gZoneUtilArray[index].iAllocDiscardable))) |
|
5241 |
{ |
|
5242 |
test.Printf(_L("r = %d, expected = %d, or all movable/discardable pages have not been moved"), |
|
5243 |
r, KErrNoMemory); |
|
5244 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
5245 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5246 |
TEST_FAIL; |
|
5247 |
} |
|
5248 |
else |
|
5249 |
{ |
|
5250 |
test.Printf(_L("Passed...")); |
|
5251 |
} |
|
5252 |
||
5253 |
Ldd.FreeAllFixedPages(); |
|
5254 |
} |
|
5255 |
||
5256 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5257 |
TestEnd(); |
|
5258 |
||
5259 |
test.End(); |
|
5260 |
return r; |
|
5261 |
} |
|
5262 |
||
5263 |
||
5264 |
// |
|
5265 |
// TestClaimRamZone |
|
5266 |
// |
|
5267 |
//--------------------------------------------------------------------------------------------------------------------- |
|
5268 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0532 |
|
5269 |
//! @SYMTestType CIT |
|
5270 |
//! @SYMTestCaseDesc Verifying the implemntation of the function TRamDefragRequest::ClaimRamZone() |
|
5271 |
//! @SYMPREQ PREQ308 |
|
5272 |
//! @SYMTestPriority High |
|
5273 |
//! @SYMTestActions |
|
5274 |
//! 1. Fragment the memory. Following this, call function with a valid aID |
|
5275 |
//! 2. Fragment the memory. Following this, call function with an invalid aID |
|
5276 |
//! 3. Fragment the memory. Following this, start a zone defrag and whilst this |
|
5277 |
//! is running, call function on the same zone. |
|
5278 |
//! 4. Fragment the memory. Following this, start a general defrag and whilst this |
|
5279 |
//! is running, call function on the same zone. |
|
5280 |
//! 5. Fragment the memory. Following this, call ClaimRamZone() on a specific zone, whilst at the |
|
5281 |
//! same time calling ClaimRamZone() on another zone. |
|
5282 |
//! 6: Fragment the memory. Call function TRamDefragRequest::ClaimRamZone on specifc zone and at the |
|
5283 |
//! same time allocate pages to the zone |
|
5284 |
//! 7. Fragment the memory. Following this allocate fixed pages to a zone and attempt to claim |
|
5285 |
//! the zone. |
|
5286 |
//! 8. Fragment the memory. Following this call ClaimRamZone() on every zone, one after the other |
|
5287 |
//! |
|
5288 |
//! @SYMTestExpectedResults |
|
5289 |
//! 1. KErrNone |
|
5290 |
//! 2. KErrArgument |
|
5291 |
//! 3. KErrNone and the zone has been claimed |
|
5292 |
//! 4. KErrNone and the zone has been claimed |
|
5293 |
//! 5. KErrNone and both zones have been claimed |
|
5294 |
//! 6. KErrNoMemory |
|
5295 |
//! 7. KErrNoMemory, all movable and discardable pages have been moved |
|
5296 |
//! 8. One of the following scenarios should occur: |
|
5297 |
//! a. If the cache has not reached its minimum size and there are no unknown pages in |
|
5298 |
//! the zone, then all the movable pages should be moved from the zone if there are enough free pages |
|
5299 |
//! in the other zones. |
|
5300 |
//! However, when demand paging is off, all movable pages should be moved from the zone, again if there |
|
5301 |
//! are enough free pages in the other zones and if there are no unknown pages in the zone. |
|
5302 |
//! b. If the current size of the cache minus the number of discardable pages in the zone being emptied is not |
|
5303 |
//! less than the minimum cache size and there are no unknown pages in the zone, |
|
5304 |
//! then all the discardable pages should be discarded of. |
|
5305 |
//! However, when demand paging is off, all discardable pages should be removed from |
|
5306 |
//! the zone if there are no unknown pages in the zone. |
|
5307 |
//--------------------------------------------------------------------------------------------------------------------- |
|
5308 |
TInt TestClaimRamZone() |
|
5309 |
{ |
|
5310 |
TInt r = 0; |
|
5311 |
TInt r2 = 0; |
|
5312 |
TUint32 addr = 0; |
|
5313 |
TInt waitTime = 1000; |
|
5314 |
||
5315 |
test.Start(_L("Test1: Call function TRamDefragRequest::ClaimRamZone with a valid aID")); |
|
5316 |
TestStart(); |
|
5317 |
||
5318 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5319 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5320 |
||
5321 |
GetAllPageInfo(); |
|
5322 |
TUint index = gZoneCount - 1; |
|
5323 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5324 |
{ |
|
5325 |
-- index; |
|
5326 |
} |
|
5327 |
TUint defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5328 |
||
5329 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5330 |
{ |
|
5331 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5332 |
} |
|
5333 |
else |
|
5334 |
{ |
|
5335 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5336 |
GetAllPageInfo(); |
|
5337 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5338 |
if (freeInOthers && r != KErrNone && |
|
5339 |
gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) |
|
5340 |
{ |
|
5341 |
test.Printf(_L("Fail: Zone 0x%x has not been claimed r %d expected %d\n"), defragZoneID, r, KErrNone); |
|
5342 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5343 |
TEST_FAIL; |
|
5344 |
} |
|
5345 |
else |
|
5346 |
{ |
|
5347 |
test.Printf(_L("Passed...\n")); |
|
5348 |
} |
|
5349 |
||
5350 |
addr = gZoneConfigArray[index].iPhysBase; |
|
5351 |
if (r == KErrNone) |
|
5352 |
{ |
|
5353 |
r = Ldd.FreeAllFixedPages(); |
|
5354 |
} |
|
5355 |
} |
|
5356 |
||
5357 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5358 |
TestEnd(); |
|
5359 |
||
5360 |
||
5361 |
test.Next(_L("Test2: Call function TRamDefragRequest::ClaimRamZone with an invalid aID")); |
|
5362 |
TestStart(); |
|
5363 |
gChunkArray1 = new RChunk; |
|
5364 |
gChunkArraySize1 = 1; |
|
5365 |
defragZoneID = KInvalidZoneID; |
|
5366 |
||
5367 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5368 |
if (r != KErrArgument) |
|
5369 |
{ |
|
5370 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
5371 |
TEST_FAIL; |
|
5372 |
} |
|
5373 |
else |
|
5374 |
{ |
|
5375 |
test.Printf(_L("Passed...\n")); |
|
5376 |
} |
|
5377 |
||
5378 |
TestEnd(); |
|
5379 |
||
5380 |
||
5381 |
test.Next(_L("Test3: Call function TRamDefragRequest::ClaimRamZone when a EmptyRamZone is already running")); |
|
5382 |
TestStart(); |
|
5383 |
||
5384 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5385 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5386 |
||
5387 |
GetAllPageInfo(); |
|
5388 |
index = gZoneCount - 1; |
|
5389 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5390 |
{ |
|
5391 |
-- index; |
|
5392 |
} |
|
5393 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5394 |
||
5395 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5396 |
{ |
|
5397 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5398 |
} |
|
5399 |
else |
|
5400 |
{ |
|
5401 |
TInt numPassed = 0; |
|
5402 |
for (waitTime = 1000; waitTime > 0; waitTime-=10) |
|
5403 |
{ |
|
5404 |
r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); |
|
5405 |
if (r != KErrNone) |
|
5406 |
{ |
|
5407 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5408 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5409 |
TEST_FAIL; |
|
5410 |
} |
|
5411 |
||
5412 |
gTestThread.Logon(status); |
|
5413 |
gTestThread.Resume(); |
|
5414 |
User::After(waitTime); |
|
5415 |
||
5416 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5417 |
||
5418 |
User::WaitForRequest(status); |
|
5419 |
r2 = status.Int(); |
|
5420 |
||
5421 |
GetAllPageInfo(); |
|
5422 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5423 |
if (freeInOthers && r != KErrNone && r2 != KErrNone) |
|
5424 |
{ |
|
5425 |
test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone ID 0x%x has not been claimed\n"), |
|
5426 |
r, r2, KErrNone, defragZoneID); |
|
5427 |
if (r == KErrNone) |
|
5428 |
{ |
|
5429 |
CLEANUP(r = Ldd.FreeAllFixedPages()); |
|
5430 |
} |
|
5431 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5432 |
TEST_FAIL; |
|
5433 |
} |
|
5434 |
else |
|
5435 |
{ |
|
5436 |
numPassed ++; |
|
5437 |
} |
|
5438 |
||
5439 |
if (r == KErrNone) |
|
5440 |
{ |
|
5441 |
r = Ldd.FreeAllFixedPages(); |
|
5442 |
} |
|
5443 |
||
5444 |
gTestThread.Close(); |
|
5445 |
} |
|
5446 |
if (numPassed > 0) |
|
5447 |
{ |
|
5448 |
test.Printf(_L("Passed...\n")); |
|
5449 |
} |
|
5450 |
} |
|
5451 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5452 |
TestEnd(); |
|
5453 |
||
5454 |
||
5455 |
test.Next(_L("Test4: Call function TRamDefragRequest::ClaimRamZone when a general defrag is already running")); |
|
5456 |
TestStart(); |
|
5457 |
||
5458 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5459 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5460 |
||
5461 |
GetAllPageInfo(); |
|
5462 |
index = gZoneCount - 1; |
|
5463 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5464 |
{ |
|
5465 |
-- index; |
|
5466 |
} |
|
5467 |
||
5468 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5469 |
{ |
|
5470 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5471 |
} |
|
5472 |
else |
|
5473 |
{ |
|
5474 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5475 |
||
5476 |
r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); |
|
5477 |
if (r != KErrNone) |
|
5478 |
{ |
|
5479 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5480 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5481 |
TEST_FAIL; |
|
5482 |
} |
|
5483 |
||
5484 |
gTestThread.Logon(status); |
|
5485 |
gTestThread.Resume(); |
|
5486 |
User::After(waitTime); |
|
5487 |
||
5488 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5489 |
||
5490 |
User::WaitForRequest(status); |
|
5491 |
r2 = status.Int(); |
|
5492 |
||
5493 |
if (r != KErrNone) |
|
5494 |
{ |
|
5495 |
test.Printf(_L("ClaimZone: r = %d, expected = %d\n"), r, KErrNone); |
|
5496 |
} |
|
5497 |
||
5498 |
if (r2 != KErrNone) |
|
5499 |
{ |
|
5500 |
test.Printf(_L("General: r2 = %d, expected = %d\n"), r, KErrNone); |
|
5501 |
} |
|
5502 |
||
5503 |
GetAllPageInfo(); |
|
5504 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5505 |
if (freeInOthers && gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) |
|
5506 |
{ |
|
5507 |
test.Printf(_L("Fail: Zone ID 0x%x has not been claimed, r = %d, r2 = %d, expected = %d\n"), |
|
5508 |
defragZoneID, r, r2, KErrNone); |
|
5509 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5510 |
TEST_FAIL; |
|
5511 |
} |
|
5512 |
else |
|
5513 |
{ |
|
5514 |
test.Printf(_L("Passed...\n")); |
|
5515 |
} |
|
5516 |
||
5517 |
if (r == KErrNone) |
|
5518 |
{ |
|
5519 |
r = Ldd.FreeAllFixedPages(); |
|
5520 |
} |
|
5521 |
||
5522 |
gTestThread.Close(); |
|
5523 |
} |
|
5524 |
||
5525 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5526 |
TestEnd(); |
|
5527 |
||
5528 |
||
5529 |
||
5530 |
test.Next(_L("Test5: Call function TRamDefragRequest::ClaimRamZone on specifc zone at the same time as calling on another zone")); |
|
5531 |
TestStart(); |
|
5532 |
||
5533 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5534 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5535 |
||
5536 |
GetAllPageInfo(); |
|
5537 |
index = gZoneCount - 1; |
|
5538 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5539 |
{ |
|
5540 |
-- index; |
|
5541 |
} |
|
5542 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5543 |
test.Printf(_L("index = 0x%x "), index); |
|
5544 |
||
5545 |
TUint index2 = gZoneCount - 1; |
|
5546 |
while ( index2 > 0 && |
|
5547 |
(index == index2 || gZoneUtilArray[index2].iAllocFixed != 0 || gZoneUtilArray[index2].iAllocUnknown != 0)) |
|
5548 |
{ |
|
5549 |
-- index2; |
|
5550 |
} |
|
5551 |
TUint defragZoneID2 = gZoneConfigArray[index2].iZoneId; |
|
5552 |
test.Printf(_L("index2 = %d\n"), index2); |
|
5553 |
||
5554 |
if ((index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) || |
|
5555 |
(index2 == 0 && (index == index2 || gZoneUtilArray[index2].iAllocFixed != 0 || gZoneUtilArray[index2].iAllocUnknown != 0))) |
|
5556 |
{ |
|
5557 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5558 |
} |
|
5559 |
else |
|
5560 |
{ |
|
5561 |
r = gTestThread.Create(gTestThreadName,MultiClaimZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)(defragZoneID2)); |
|
5562 |
if (r != KErrNone) |
|
5563 |
{ |
|
5564 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5565 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5566 |
TEST_FAIL; |
|
5567 |
} |
|
5568 |
||
5569 |
gTestThread.Logon(status); |
|
5570 |
gTestThread.Resume(); |
|
5571 |
User::After(waitTime); |
|
5572 |
||
5573 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5574 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
5575 |
||
5576 |
User::WaitForRequest(status); |
|
5577 |
r2 = status.Int(); |
|
5578 |
||
5579 |
GetAllPageInfo(); |
|
5580 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5581 |
TUint freeInOthers2 = gTotalPageCount.iFreePages - gZoneUtilArray[index2].iFreePages; |
|
5582 |
if ((freeInOthers && r != KErrNone && |
|
5583 |
gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) || |
|
5584 |
(freeInOthers2 && r != KErrNone && |
|
5585 |
gZoneUtilArray[index2].iAllocFixed != gZoneUtilArray[index2].iPhysPages)) |
|
5586 |
{ |
|
5587 |
test.Printf(_L("Fail: Zone ID 0x%x or Zone ID 0x%x has not been claimed, r = %d, r2 = %d, expected = %d\n"), |
|
5588 |
defragZoneID, defragZoneID2, r, r2, KErrNone); |
|
5589 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5590 |
TEST_FAIL; |
|
5591 |
} |
|
5592 |
else |
|
5593 |
{ |
|
5594 |
test.Printf(_L("Passed...\n")); |
|
5595 |
} |
|
5596 |
||
5597 |
if (r == KErrNone) |
|
5598 |
{ |
|
5599 |
r = Ldd.FreeAllFixedPages(); |
|
5600 |
} |
|
5601 |
||
5602 |
if (r2 == KErrNone) |
|
5603 |
{// Have to free from specific address as RAM zone claimed by other channel. |
|
5604 |
addr = gZoneConfigArray[index2].iPhysBase; |
|
5605 |
r = Ldd.FreeFromAddr(gZoneUtilArray[index2].iAllocFixed, addr); |
|
5606 |
} |
|
5607 |
||
5608 |
gTestThread.Close(); |
|
5609 |
} |
|
5610 |
||
5611 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5612 |
TestEnd(); |
|
5613 |
||
5614 |
||
5615 |
test.Next(_L("Test6: Call function TRamDefragRequest::ClaimRamZone on specifc zone and at the same time allocate pages to the zone")); |
|
5616 |
TestStart(); |
|
5617 |
||
5618 |
TInt pagesAlloc = 1; // Try and allocate just one page whilst attempting to claim the zone |
|
5619 |
||
5620 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5621 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5622 |
||
5623 |
GetAllPageInfo(); |
|
5624 |
index = gZoneCount - 1; |
|
5625 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5626 |
{ |
|
5627 |
-- index; |
|
5628 |
} |
|
5629 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
5630 |
{ |
|
5631 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5632 |
} |
|
5633 |
else |
|
5634 |
{ |
|
5635 |
GetAllPageInfo(); |
|
5636 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5637 |
TInt numPassed = 0; |
|
5638 |
for (waitTime = 1000; waitTime > 0; waitTime-=10) |
|
5639 |
{ |
|
5640 |
r = gTestThread.Create(gTestThreadName,MultiClaimZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); |
|
5641 |
if (r != KErrNone) |
|
5642 |
{ |
|
5643 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5644 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5645 |
TEST_FAIL; |
|
5646 |
} |
|
5647 |
||
5648 |
gTestThread.Logon(status); |
|
5649 |
gTestThread.Resume(); |
|
5650 |
test(status.Int() == KRequestPending); |
|
5651 |
User::After(waitTime); |
|
5652 |
||
5653 |
r = Ldd.ZoneAllocDiscontiguous(defragZoneID, pagesAlloc); |
|
5654 |
||
5655 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
5656 |
||
5657 |
User::WaitForRequest(status); |
|
5658 |
r2 = status.Int(); |
|
5659 |
||
5660 |
GetAllPageInfo(); |
|
5661 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5662 |
if (freeInOthers && r2 != KErrNone) |
|
5663 |
{ |
|
5664 |
test.Printf(_L("Claim was unsuccsessful: r2 = %d, expected = %d\n"), r2, KErrNone); |
|
5665 |
} |
|
5666 |
else if (r2 == KErrNone && r != KErrNoMemory) |
|
5667 |
{ |
|
5668 |
test.Printf(_L("Fail: r = %d, expected = %d, r2 = %d, expected = %d, zone ID = 0x%x\n"), |
|
5669 |
r, KErrNoMemory, r2, KErrNone, defragZoneID); |
|
5670 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5671 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
5672 |
// Free from address as a different channel claimed the RAM zone. |
|
5673 |
addr = gZoneConfigArray[index].iPhysBase; |
|
5674 |
CLEANUP(Ldd.FreeFromAddr(gZoneUtilArray[index].iAllocFixed, addr)); |
|
5675 |
TEST_FAIL; |
|
5676 |
} |
|
5677 |
else |
|
5678 |
{ |
|
5679 |
numPassed ++; |
|
5680 |
} |
|
5681 |
||
5682 |
Ldd.FreeAllFixedPages(); |
|
5683 |
||
5684 |
GetAllPageInfo(); |
|
5685 |
if (r2 == KErrNone) |
|
5686 |
{// Free from address as a different channel claimed the RAM zone. |
|
5687 |
addr = gZoneConfigArray[index].iPhysBase; |
|
5688 |
r = Ldd.FreeFromAddr(gZoneUtilArray[index].iAllocFixed, addr); |
|
5689 |
} |
|
5690 |
gTestThread.Close(); |
|
5691 |
} |
|
5692 |
if (numPassed > 0) |
|
5693 |
{ |
|
5694 |
test.Printf(_L("Passed...\n")); |
|
5695 |
} |
|
5696 |
} |
|
5697 |
||
5698 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5699 |
TestEnd(); |
|
5700 |
||
5701 |
||
5702 |
||
5703 |
test.Next(_L("Test7: Call function TRamDefragRequest::ClaimRamZone on a zone that contains fixed and movable pages")); |
|
5704 |
TestStart(); |
|
5705 |
||
5706 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5707 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5708 |
||
5709 |
GetAllPageInfo(); |
|
5710 |
index = gZoneCount - 1; |
|
5711 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0) && |
|
5712 |
(gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) |
|
5713 |
{ |
|
5714 |
-- index; |
|
5715 |
} |
|
5716 |
||
5717 |
if (index == 0 && ((gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0) && |
|
5718 |
(gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3))) |
|
5719 |
{ |
|
5720 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5721 |
} |
|
5722 |
else |
|
5723 |
{ |
|
5724 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5725 |
TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"), defragZoneID)); |
|
5726 |
TESTDEBUG(test.Printf(_L("movable = 0x%x discardable = 0x%x\n"), |
|
5727 |
gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable)); |
|
5728 |
||
5729 |
||
5730 |
Ldd.ZoneAllocDiscontiguous(defragZoneID, 2); // Allocated 2 fixed pages to ensure that zone cannot be emptied |
|
5731 |
||
5732 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); |
|
5733 |
GetAllPageInfo(); |
|
5734 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5735 |
if (r != KErrNoMemory || |
|
5736 |
(freeInOthers && |
|
5737 |
(gZoneUtilArray[index].iAllocMovable || |
|
5738 |
gZoneUtilArray[index].iAllocDiscardable))) |
|
5739 |
{ |
|
5740 |
test.Printf(_L("r = %d, expected = %d, or all movable/discardable pages have not been moved"), |
|
5741 |
r, KErrNoMemory); |
|
5742 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
5743 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5744 |
TEST_FAIL; |
|
5745 |
} |
|
5746 |
else |
|
5747 |
{ |
|
5748 |
test.Printf(_L("Passed...\n")); |
|
5749 |
} |
|
5750 |
||
5751 |
Ldd.FreeAllFixedPages(); |
|
5752 |
} |
|
5753 |
||
5754 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5755 |
TestEnd(); |
|
5756 |
||
5757 |
test.Next(_L("Test8: Call function TRamDefragRequest::ClaimRamZone on every zone one after the other")); |
|
5758 |
TestStart(); |
|
5759 |
||
5760 |
Ldd.ResetDriver(); |
|
5761 |
||
5762 |
for (index = 0; index < gZoneCount; index ++) |
|
5763 |
{ |
|
5764 |
// Variables for DP ROM cache sizes |
|
5765 |
TUint minCacheSize = 0; |
|
5766 |
TUint maxCacheSize = 0; |
|
5767 |
TUint currentCacheSize = 0; |
|
5768 |
||
5769 |
if (gPagedRom) |
|
5770 |
{ |
|
5771 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
5772 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5773 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5774 |
// Calculate the maximum size of the DP cache |
|
5775 |
TUint minZoneFree = KMaxTUint; |
|
5776 |
TUint maxDisFillBytes = 0; |
|
5777 |
GetAllPageInfo(); |
|
5778 |
for (TUint i = 0; i < gZoneCount; i++) |
|
5779 |
{ |
|
5780 |
maxDisFillBytes += gZoneUtilArray[i].iFreePages; |
|
5781 |
maxDisFillBytes += gZoneUtilArray[i].iAllocDiscardable; |
|
5782 |
if (minZoneFree > gZoneUtilArray[i].iFreePages) |
|
5783 |
minZoneFree = gZoneUtilArray[i].iFreePages; |
|
5784 |
} |
|
5785 |
test.Printf(_L("Free pages 0x%x maxDisFillBytes 0x%x\n"), gTotalPageCount.iFreePages, maxDisFillBytes); |
|
5786 |
maxDisFillBytes <<= gPageShift; |
|
5787 |
||
5788 |
r = DPTest::SetCacheSize(maxDisFillBytes, maxDisFillBytes); |
|
5789 |
if (r != KErrNone) |
|
5790 |
{ |
|
5791 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5792 |
CLEANUP(ResetDPCache()); |
|
5793 |
TEST_FAIL; |
|
5794 |
} |
|
5795 |
||
5796 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
5797 |
TESTDEBUG(test.Printf(_L("CacheSize2: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5798 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5799 |
if (currentCacheSize != maxDisFillBytes) |
|
5800 |
{ |
|
5801 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5802 |
CLEANUP(ResetDPCache()); |
|
5803 |
TEST_FAIL; |
|
5804 |
} |
|
5805 |
||
5806 |
GetAllPageInfo(); |
|
5807 |
test.Printf(_L("Free pages after alloc discardable1 = 0x%x\n"), gTotalPageCount.iFreePages); |
|
5808 |
||
5809 |
r = DPTest::SetCacheSize(minZoneFree << gPageShift, maxDisFillBytes); |
|
5810 |
if (r != KErrNone) |
|
5811 |
{ |
|
5812 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5813 |
CLEANUP(ResetDPCache()); |
|
5814 |
TEST_FAIL; |
|
5815 |
} |
|
5816 |
||
5817 |
// Check all zones have no free pages. |
|
5818 |
GetAllPageInfo(); |
|
5819 |
for (TUint i = 0; i < gZoneCount; i++) |
|
5820 |
{ |
|
5821 |
if (gZoneUtilArray[i].iFreePages != 0) |
|
5822 |
{ |
|
5823 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
5824 |
CLEANUP(ResetDPCache()); |
|
5825 |
TEST_FAIL; |
|
5826 |
} |
|
5827 |
} |
|
5828 |
} |
|
5829 |
else |
|
5830 |
{ |
|
5831 |
// Fragment the RAM with some movable pages |
|
5832 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); |
|
5833 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5834 |
} |
|
5835 |
||
5836 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
5837 |
||
5838 |
GetAllPageInfo(); |
|
5839 |
TUint origUnknownInZone = gZoneUtilArray[index].iAllocUnknown; |
|
5840 |
TUint origMovInZone = gZoneUtilArray[index].iAllocMovable; |
|
5841 |
TUint origFreeInZone = gZoneUtilArray[index].iFreePages; |
|
5842 |
||
5843 |
test.Printf(_L("Zone ID 0x%x - fixedPages = 0x%x, unknownPages = 0x%x, discardablePages = 0x%x movable = 0x%x free = 0x%x\n"), |
|
5844 |
zoneID, gZoneUtilArray[index].iAllocFixed, origUnknownInZone, gZoneUtilArray[index].iAllocDiscardable, |
|
5845 |
origMovInZone, origFreeInZone); |
|
5846 |
||
5847 |
||
5848 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID); |
|
5849 |
||
5850 |
GetAllPageInfo(); |
|
5851 |
TUint unknownPages = gZoneUtilArray[index].iAllocUnknown; |
|
5852 |
TUint discPages = gZoneUtilArray[index].iAllocDiscardable; |
|
5853 |
TUint movablePages = gZoneUtilArray[index].iAllocMovable; |
|
5854 |
||
5855 |
if (r == KErrNone) |
|
5856 |
{ |
|
5857 |
r = Ldd.FreeAllFixedPages(); |
|
5858 |
} |
|
5859 |
TUint freeInOtherZones = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
5860 |
if (!unknownPages && movablePages && freeInOtherZones) |
|
5861 |
{ |
|
5862 |
test.Printf(_L("Fail: Zone ID %x all the movable pages haven't been moved\n"), zoneID); |
|
5863 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5864 |
CLEANUP(ResetDPCache()); |
|
5865 |
TEST_FAIL; |
|
5866 |
} |
|
5867 |
||
5868 |
if (origUnknownInZone != unknownPages) |
|
5869 |
{ |
|
5870 |
test.Printf(_L("Fail: Zone ID %x unknown pages before and after are not equal\n"), zoneID); |
|
5871 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5872 |
CLEANUP(ResetDPCache()); |
|
5873 |
TEST_FAIL; |
|
5874 |
} |
|
5875 |
||
5876 |
if (!gPagedRom) |
|
5877 |
{ |
|
5878 |
if (!unknownPages && freeInOtherZones && discPages) |
|
5879 |
{ |
|
5880 |
test.Printf(_L("Fail: Zone ID %x all the discardable pages haven't been moved\n"), zoneID); |
|
5881 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5882 |
CLEANUP(ResetDPCache()); |
|
5883 |
TEST_FAIL; |
|
5884 |
} |
|
5885 |
} |
|
5886 |
else |
|
5887 |
{ |
|
5888 |
DPTest::CacheSize(minCacheSize, maxCacheSize, currentCacheSize); |
|
5889 |
TESTDEBUG(test.Printf(_L("CacheSize3: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
5890 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
5891 |
// The the discardable pages should have been discarded or moved unless |
|
5892 |
// there is no room in the other zones and the cache size is already at its minimum |
|
5893 |
if (!unknownPages && discPages && (freeInOtherZones || currentCacheSize != minCacheSize)) |
|
5894 |
{ |
|
5895 |
test.Printf(_L("Fail: Zone ID 0x%x all the discardable pages haven't been moved\n"), zoneID); |
|
5896 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5897 |
CLEANUP(ResetDPCache()); |
|
5898 |
TEST_FAIL; |
|
5899 |
} |
|
5900 |
} |
|
5901 |
test.Printf(_L("Passed...\n")); |
|
5902 |
} |
|
5903 |
// TestEnd() will cleanup what's required. |
|
5904 |
TestEnd(); |
|
5905 |
test.End(); |
|
5906 |
return 0; |
|
5907 |
} |
|
5908 |
||
5909 |
||
5910 |
// |
|
5911 |
// TestCancelDefrag |
|
5912 |
// |
|
5913 |
//----------------------------------------------------------------------------------------------------------------------------------------- |
|
5914 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0533 |
|
5915 |
//! @SYMTestType CIT |
|
5916 |
//! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::CancelDefrag() |
|
5917 |
//! @SYMPREQ PREQ308 |
|
5918 |
//! @SYMTestPriority High |
|
5919 |
//! @SYMTestActions |
|
5920 |
//! 1. Fragment the memory. Following this, start a general defrag and cancel it |
|
5921 |
//! 2. Fragment the memory. Following this, start a zone defrag and cancel it |
|
5922 |
//! 3. Fragment the memory. Following this, start a claim zone and cancel it |
|
5923 |
//! |
|
5924 |
//! @SYMTestExpectedResults |
|
5925 |
//! 1. KErrCancel |
|
5926 |
//! 2. KErrCancel |
|
5927 |
//! 3. KErrCancel |
|
5928 |
//----------------------------------------------------------------------------------------------------------------------------------------- |
|
5929 |
TInt TestCancelDefrag() |
|
5930 |
{ |
|
5931 |
TInt r = 0; |
|
5932 |
TUint defragZoneID = 0; |
|
5933 |
||
5934 |
test.Start(_L("Test1: Call general defrag and cancel it")); |
|
5935 |
TestStart(); |
|
5936 |
||
5937 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5938 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5939 |
||
5940 |
r = Ldd.CheckCancel(DEFRAG_TYPE_GEN); |
|
5941 |
||
5942 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
5943 |
if (r != KErrCancel) |
|
5944 |
{ |
|
5945 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); |
|
5946 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5947 |
TEST_FAIL; |
|
5948 |
} |
|
5949 |
else |
|
5950 |
{ |
|
5951 |
test.Printf(_L("Passed...\n")); |
|
5952 |
} |
|
5953 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
5954 |
TestEnd(); |
|
5955 |
||
5956 |
||
5957 |
test.Next(_L("Test2: Call zone defrag and cancel it")); |
|
5958 |
TestStart(); |
|
5959 |
||
5960 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
5961 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
5962 |
||
5963 |
GetAllPageInfo(); |
|
5964 |
TUint index = gZoneCount - 1; |
|
5965 |
while (index > 0 && |
|
5966 |
(gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || |
|
5967 |
gZoneUtilArray[index].iAllocFixed !=0 || |
|
5968 |
gZoneUtilArray[index].iAllocUnknown !=0)) |
|
5969 |
{ |
|
5970 |
-- index; |
|
5971 |
} |
|
5972 |
if (index == 0 && |
|
5973 |
(gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || |
|
5974 |
gZoneUtilArray[index].iAllocFixed !=0 || |
|
5975 |
gZoneUtilArray[index].iAllocUnknown !=0)) |
|
5976 |
{ |
|
5977 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
5978 |
} |
|
5979 |
else |
|
5980 |
{ |
|
5981 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
5982 |
TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"),defragZoneID)); |
|
5983 |
||
5984 |
r = Ldd.CheckCancel(DEFRAG_TYPE_EMPTY, defragZoneID); |
|
5985 |
||
5986 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
5987 |
if (r != KErrCancel) |
|
5988 |
{ |
|
5989 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); |
|
5990 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
5991 |
TEST_FAIL; |
|
5992 |
} |
|
5993 |
else |
|
5994 |
{ |
|
5995 |
test.Printf(_L("Passed...\n")); |
|
5996 |
} |
|
5997 |
} |
|
5998 |
||
5999 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
6000 |
TestEnd(); |
|
6001 |
||
6002 |
||
6003 |
test.Next(_L("Test3: Call Claim RAM Zone and cancel it")); |
|
6004 |
TestStart(); |
|
6005 |
||
6006 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
6007 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
6008 |
||
6009 |
GetAllPageInfo(); |
|
6010 |
index = gZoneCount - 1; |
|
6011 |
while (index > 0 && |
|
6012 |
(gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || |
|
6013 |
gZoneUtilArray[index].iAllocFixed !=0 || |
|
6014 |
gZoneUtilArray[index].iAllocUnknown !=0)) |
|
6015 |
{ |
|
6016 |
-- index; |
|
6017 |
} |
|
6018 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
6019 |
TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"),defragZoneID)); |
|
6020 |
||
6021 |
if (index == 0 && |
|
6022 |
(gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || |
|
6023 |
gZoneUtilArray[index].iAllocFixed !=0 || |
|
6024 |
gZoneUtilArray[index].iAllocUnknown !=0)) |
|
6025 |
{ |
|
6026 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
6027 |
} |
|
6028 |
else |
|
6029 |
{ |
|
6030 |
r = Ldd.CheckCancel(DEFRAG_TYPE_CLAIM, defragZoneID); |
|
6031 |
||
6032 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
6033 |
if (r != KErrCancel) |
|
6034 |
{ |
|
6035 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); |
|
6036 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
6037 |
TEST_FAIL; |
|
6038 |
} |
|
6039 |
else |
|
6040 |
{ |
|
6041 |
test.Printf(_L("Passed...\n")); |
|
6042 |
} |
|
6043 |
} |
|
6044 |
||
6045 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
6046 |
TestEnd(); |
|
6047 |
||
6048 |
test.End(); |
|
6049 |
return 0; |
|
6050 |
} |
|
6051 |
||
6052 |
// |
|
6053 |
// TestZoneAllocNoAffect |
|
6054 |
// |
|
6055 |
// Ensures that fixed page allocations do not affect the movable |
|
6056 |
// or discardable page allocations |
|
6057 |
// |
|
6058 |
TInt TestZoneAllocNoAffect(TInt aZoneAllocType, TInt aPageType) |
|
6059 |
{ |
|
6060 |
TInt retVal = KErrNone; |
|
6061 |
TInt r = KErrNone; |
|
6062 |
TInt mostPrefIndex = 0; |
|
6063 |
TUint leastPrefIndex = 0; |
|
6064 |
TUint leastPrefZoneID = 0; |
|
6065 |
||
6066 |
TestStart(); |
|
6067 |
gChunkArray1 = new RChunk; |
|
6068 |
gChunkArraySize1 = 1; |
|
6069 |
switch(aPageType) |
|
6070 |
{ |
|
6071 |
case BEST_MOVABLE: |
|
6072 |
test.Printf(_L("Test Epoc::ZoneAllocPhysicalRam() doesn't affect the allocation of movable pages\n")); |
|
6073 |
break; |
|
6074 |
||
6075 |
case BEST_DISCARDABLE: |
|
6076 |
test.Printf(_L("Test Epoc::ZoneAllocPhysicalRam() doesn't affect the allocation of discardable pages\n")); |
|
6077 |
if (!gPagedRom) |
|
6078 |
{ |
|
6079 |
test.Printf(_L("Not a paged ROM - Skipping...\n")); |
|
6080 |
goto skipSetup; |
|
6081 |
} |
|
6082 |
break; |
|
6083 |
} |
|
6084 |
// Fist find the zone that movable page allocations should go into |
|
6085 |
// Getting the best movable will be the same for discardable as well |
|
6086 |
mostPrefIndex = GetBestZone(aPageType); |
|
6087 |
if (mostPrefIndex == KErrNotFound) |
|
6088 |
{ |
|
6089 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
6090 |
goto skipSetup; |
|
6091 |
} |
|
6092 |
||
6093 |
// Get the least pref zone to zone alloc into and ensure it has free pages |
|
6094 |
GetPrefOrder(); |
|
6095 |
leastPrefIndex = gPrefArray[gZoneCount - 1]; |
|
6096 |
if (gZoneConfigArray[mostPrefIndex].iPref == gZoneConfigArray[leastPrefIndex].iPref) |
|
6097 |
{ |
|
6098 |
test.Printf(_L("Zones with same preference - Skipping...\n")); |
|
6099 |
goto skipSetup; |
|
6100 |
} |
|
6101 |
if (leastPrefIndex == (TUint)mostPrefIndex || |
|
6102 |
gZoneUtilArray[leastPrefIndex].iFreePages == 0) |
|
6103 |
{ |
|
6104 |
test.Printf(_L("leastPrefIndex = mostPrefIndex or leastPrefIndex(%d) / mostPrefIndex(%d) has 0 free - Skipping test step...\n"), |
|
6105 |
leastPrefIndex, mostPrefIndex); |
|
6106 |
goto skipSetup; |
|
6107 |
} |
|
6108 |
||
6109 |
||
6110 |
// Zone alloc 1 fixed page into the least preferable zone |
|
6111 |
leastPrefZoneID = gZoneConfigArray[leastPrefIndex].iZoneId; |
|
6112 |
GetOriginalPageCount(); |
|
6113 |
switch(aZoneAllocType) |
|
6114 |
{ |
|
6115 |
case Z_ALLOC_DISC: |
|
6116 |
{ |
|
6117 |
r = Ldd.ZoneAllocDiscontiguous(leastPrefZoneID, 1); |
|
6118 |
break; |
|
6119 |
} |
|
6120 |
||
6121 |
case Z_ALLOC_CONTIG: |
|
6122 |
{ |
|
6123 |
r = Ldd.ZoneAllocContiguous(leastPrefZoneID, gPageSize); |
|
6124 |
break; |
|
6125 |
} |
|
6126 |
} |
|
6127 |
GetAllPageInfo(); |
|
6128 |
if (r != KErrNone || |
|
6129 |
gZoneUtilArray[leastPrefIndex].iAllocFixed <= gOriginalPageCountArray[leastPrefIndex].iAllocFixed) |
|
6130 |
{ |
|
6131 |
test.Printf(_L("Failed to allocate 1 fixed page to zone index %d r = %d\n"), leastPrefIndex, r); |
|
6132 |
goto skipSetup; |
|
6133 |
} |
|
6134 |
test.Printf(_L("leastPrefIndex = %d mostPrefIndex = %d\n"), leastPrefIndex, mostPrefIndex); |
|
6135 |
switch(aPageType) |
|
6136 |
{ |
|
6137 |
case BEST_MOVABLE: |
|
6138 |
// now allocate 1 movable page |
|
6139 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, gPageSize); |
|
6140 |
if (r != KErrNone) |
|
6141 |
{ |
|
6142 |
test.Printf(_L("Failed to allocate 1 movable page r = %d\n"), r); |
|
6143 |
goto skipSetup; |
|
6144 |
} |
|
6145 |
break; |
|
6146 |
||
6147 |
case BEST_DISCARDABLE: |
|
6148 |
// now allocate 1 discardable page |
|
6149 |
TInt disPages; |
|
6150 |
TUint disBytes = (gTotalPageCount.iDiscardablePages + 1) << gPageShift; |
|
6151 |
r = AllocDiscardable(disPages, disBytes); |
|
6152 |
if (r != KErrNone) |
|
6153 |
{ |
|
6154 |
test.Printf(_L("Failed to allocate 1 discardable page r = %d\n"), r); |
|
6155 |
goto skipSetup; |
|
6156 |
} |
|
6157 |
break; |
|
6158 |
} |
|
6159 |
||
6160 |
GetAllPageInfo(); |
|
6161 |
switch(aPageType) |
|
6162 |
{ |
|
6163 |
case BEST_MOVABLE: |
|
6164 |
if (gOriginalPageCountArray[mostPrefIndex].iAllocMovable >= gZoneUtilArray[mostPrefIndex].iAllocMovable || |
|
6165 |
gOriginalPageCountArray[leastPrefIndex].iAllocMovable < gZoneUtilArray[leastPrefIndex].iAllocMovable) |
|
6166 |
{ |
|
6167 |
test.Printf(_L("FAIL: mostPrefIndex(%d) origMov 0x%x curMov 0x%x leastPrefIndex(%d) origMov 0x%x curMov 0x%x\n"), |
|
6168 |
mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, |
|
6169 |
leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable); |
|
6170 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6171 |
retVal = KErrGeneral; |
|
6172 |
} |
|
6173 |
else |
|
6174 |
{ |
|
6175 |
test.Printf(_L("Passed...\n")); |
|
6176 |
} |
|
6177 |
break; |
|
6178 |
||
6179 |
||
6180 |
case BEST_DISCARDABLE: |
|
6181 |
if (gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable >= gZoneUtilArray[mostPrefIndex].iAllocDiscardable || |
|
6182 |
gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable < gZoneUtilArray[leastPrefIndex].iAllocDiscardable) |
|
6183 |
{ |
|
6184 |
test.Printf(_L("FAIL: mostPrefIndex(%d) origDis 0x%x curDis 0x%x leastPrefIndex(%d) origDis 0x%x curDis 0x%x\n"), |
|
6185 |
mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable, gZoneUtilArray[mostPrefIndex].iAllocDiscardable, |
|
6186 |
leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); |
|
6187 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6188 |
retVal = KErrGeneral; |
|
6189 |
} |
|
6190 |
else |
|
6191 |
{ |
|
6192 |
test.Printf(_L("Passed...\n")); |
|
6193 |
} |
|
6194 |
break; |
|
6195 |
} |
|
6196 |
||
6197 |
// This will clean up any fixed pages allocated. |
|
6198 |
skipSetup: |
|
6199 |
TestEnd(); |
|
6200 |
return retVal; |
|
6201 |
} |
|
6202 |
||
6203 |
// |
|
6204 |
// TestZoneAllocContiguous |
|
6205 |
// |
|
6206 |
//--------------------------------------------------------------------------------------------------------------------- |
|
6207 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0535 |
|
6208 |
//! @SYMTestType CIT |
|
6209 |
//! @SYMTestCaseDesc Verifying the contiguous overload of Epoc::ZoneAllocPhysicalRam(). |
|
6210 |
//! @SYMPREQ PREQ308 |
|
6211 |
//! @SYMTestPriority High |
|
6212 |
//! @SYMTestActions |
|
6213 |
//! 1. Call function with a valid aZoneID. |
|
6214 |
//! 2. Call function with an invalid aZoneID |
|
6215 |
//! 3. Call function with aSize > zone size |
|
6216 |
//! 4. Call multiple RAM zone overload of the function with a mix of valid and invalid IDs. |
|
6217 |
//! 5. Call multiple RAM zone overload of the function with contiguous RAM zones and attempt |
|
6218 |
//! to allocate over both RAM zones. |
|
6219 |
//! 6. Call function on a RAM zone that has some non-DP pages allocated into it and ask |
|
6220 |
//! for the whole RAM zone to be filled with fixed pages. |
|
6221 |
//! 7. Get the most preferable zone for movable page allocations (mostPref). Allocate 1 contiguous fixed page |
|
6222 |
//! in the least preferable zone. Following this allocate 1 movable page |
|
6223 |
//! 8. Get the most preferable zone for discardable page allocations (mostPref). Allocate 1 contiguous fixed |
|
6224 |
//! page in the least preferable zone. Following this allocate 1 discardable page |
|
6225 |
//! |
|
6226 |
//! @SYMTestExpectedResults |
|
6227 |
//! 1. KErrNone |
|
6228 |
//! 2. KErrArgument |
|
6229 |
//! 3. KErrArgument |
|
6230 |
//! 4. KErrArgument |
|
6231 |
//! 5. KErrNone |
|
6232 |
//! 6. KErrNoMemory |
|
6233 |
//! 7. Movable pages are allocated into zone mostPref. |
|
6234 |
//! 8. Discardable pages are allocated into zone mostPref |
|
6235 |
//--------------------------------------------------------------------------------------------------------------------- |
|
6236 |
TInt TestZoneAllocContiguous() |
|
6237 |
{ |
|
6238 |
TInt r = 0; |
|
6239 |
test.Start(_L("Test1: Call function Epoc::ZoneAllocPhysicalRam() with a valid aZoneID")); |
|
6240 |
TestStart(); |
|
6241 |
||
6242 |
const TUint KAllocPages = 2; |
|
6243 |
||
6244 |
GetOriginalPageCount(); |
|
6245 |
GetAllPageInfo(); |
|
6246 |
TUint index = gZoneCount - 1; |
|
6247 |
while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) |
|
6248 |
{ |
|
6249 |
-- index; |
|
6250 |
} |
|
6251 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
6252 |
if (index == 0 && gZoneUtilArray[index].iFreePages < KAllocPages) |
|
6253 |
{ |
|
6254 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
6255 |
} |
|
6256 |
else |
|
6257 |
{ |
|
6258 |
TUint allocBytes = KAllocPages << gPageShift; |
|
6259 |
r = Ldd.ZoneAllocContiguous(zoneID, allocBytes); |
|
6260 |
GetAllPageInfo(); |
|
6261 |
if (r == KErrNone && |
|
6262 |
gZoneUtilArray[index].iAllocFixed - gOriginalPageCountArray[index].iAllocFixed == KAllocPages) |
|
6263 |
{ |
|
6264 |
test.Printf(_L("Pass: Correct number of fixed pages allocated to zone ID 0x%x\n"),zoneID); |
|
6265 |
} |
|
6266 |
else |
|
6267 |
{ |
|
6268 |
test.Printf(_L("Fail: r = %d, expected = %d, or number of pages allocated is not expected\n"), |
|
6269 |
r, KErrNone); |
|
6270 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6271 |
TEST_FAIL; |
|
6272 |
} |
|
6273 |
||
6274 |
Ldd.FreeAllFixedPages(); |
|
6275 |
} |
|
6276 |
TestEnd(); |
|
6277 |
||
6278 |
||
6279 |
test.Next(_L("Test2: Call function Epoc::ZoneAllocPhysicalRam() with an invalid aZoneID")); |
|
6280 |
TestStart(); |
|
6281 |
||
6282 |
zoneID = KInvalidZoneID; |
|
6283 |
||
6284 |
TESTDEBUG(test.Printf(_L("zoneID = 0x%x\n"), zoneID)); |
|
6285 |
||
6286 |
r = Ldd.ZoneAllocContiguous(zoneID, gPageSize); |
|
6287 |
GetAllPageInfo(); |
|
6288 |
if (r == KErrArgument) |
|
6289 |
{ |
|
6290 |
test.Printf(_L("Pass: Correct return value\n")); |
|
6291 |
} |
|
6292 |
else |
|
6293 |
{ |
|
6294 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
6295 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6296 |
TEST_FAIL; |
|
6297 |
} |
|
6298 |
Ldd.FreeAllFixedPages(); |
|
6299 |
TestEnd(); |
|
6300 |
||
6301 |
||
6302 |
test.Next(_L("Test3: Call function Epoc::ZoneAllocPhysicalRam() with aSize > zone size")); |
|
6303 |
TestStart(); |
|
6304 |
||
6305 |
index = gZoneCount - 1; |
|
6306 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
6307 |
||
6308 |
TUint allocBytes = (gZoneUtilArray[index].iPhysPages + 5) << gPageShift; |
|
6309 |
||
6310 |
r = Ldd.ZoneAllocContiguous(zoneID, allocBytes); |
|
6311 |
GetAllPageInfo(); |
|
6312 |
if (r == KErrArgument) |
|
6313 |
{ |
|
6314 |
test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); |
|
6315 |
} |
|
6316 |
else |
|
6317 |
{ |
|
6318 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
6319 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6320 |
TEST_FAIL; |
|
6321 |
} |
|
6322 |
Ldd.FreeAllFixedPages(); |
|
6323 |
TestEnd(); |
|
6324 |
||
6325 |
const TUint KMultiZoneIds = 10; |
|
6326 |
TUint* zoneIdArray = new TUint[KMultiZoneIds]; |
|
6327 |
test_NotNull(zoneIdArray); |
|
6328 |
||
6329 |
test.Next(_L("Test4: Test Epoc::ZoneAllocPhysicaRam() always fails when at least one ID is invalid")); |
|
6330 |
TestStart(); |
|
6331 |
||
6332 |
index = gZoneCount - 1; |
|
6333 |
while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) |
|
6334 |
{ |
|
6335 |
-- index; |
|
6336 |
} |
|
6337 |
if (index == 0 && gZoneUtilArray[index].iFreePages < KAllocPages) |
|
6338 |
{ |
|
6339 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
6340 |
} |
|
6341 |
else |
|
6342 |
{ |
|
6343 |
TUint zoneIdSize = 2; |
|
6344 |
zoneIdArray[0] = gZoneConfigArray[index].iZoneId; |
|
6345 |
zoneIdArray[1] = KInvalidZoneID; |
|
6346 |
TUint allocBytes = KAllocPages << gPageShift; |
|
6347 |
r = Ldd.MultiZoneAllocContiguous(zoneIdArray, zoneIdSize, allocBytes); |
|
6348 |
if (r != KErrArgument) |
|
6349 |
{ |
|
6350 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6351 |
TEST_FAIL; |
|
6352 |
} |
|
6353 |
else |
|
6354 |
{ |
|
6355 |
test.Printf(_L("Pass: Correct return value\n")); |
|
6356 |
} |
|
6357 |
} |
|
6358 |
||
6359 |
TestEnd(); |
|
6360 |
||
6361 |
test.Next(_L("Test5: Test Epoc::ZoneAllocPhysicalRam() can span multiple RAM zones")); |
|
6362 |
TestStart(); |
|
6363 |
// Attempt to find to physically contiguous RAM zones where higher addressed |
|
6364 |
// one is empty, relies on RAM zones are returned by HAL functions in |
|
6365 |
// ascending physical address order. |
|
6366 |
GetAllPageInfo(); |
|
6367 |
TBool zonesFound = EFalse; |
|
6368 |
index = gZoneCount - 1; |
|
6369 |
for (; index > 1; index--) |
|
6370 |
{ |
|
6371 |
if (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages && |
|
6372 |
gZoneUtilArray[index-1].iFreePages == gZoneUtilArray[index-1].iPhysPages && |
|
6373 |
gZoneConfigArray[index].iPhysBase - 1 == gZoneConfigArray[index-1].iPhysEnd) |
|
6374 |
{ |
|
6375 |
zonesFound = ETrue; |
|
6376 |
break; |
|
6377 |
} |
|
6378 |
} |
|
6379 |
||
6380 |
if (!zonesFound) |
|
6381 |
{ |
|
6382 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6383 |
} |
|
6384 |
else |
|
6385 |
{ |
|
6386 |
// Allocate one page more than the first RAM zone to force the allocation |
|
6387 |
// to spread over both RAM zones. |
|
6388 |
TUint allocPages = gZoneUtilArray[index-1].iPhysPages + 1; |
|
6389 |
TUint allocBytes = allocPages << gPageShift; |
|
6390 |
||
6391 |
// Attempt to find a zone that has less free pages than the allocation |
|
6392 |
// size so we can test that the method continues past too full RAM zones. |
|
6393 |
zonesFound = EFalse; |
|
6394 |
TUint noAllocZone = 0; |
|
6395 |
for (; noAllocZone < gZoneCount; noAllocZone++) |
|
6396 |
{ |
|
6397 |
if (allocPages > gZoneUtilArray[noAllocZone].iFreePages && |
|
6398 |
noAllocZone != index && noAllocZone != index-1) |
|
6399 |
{ |
|
6400 |
zonesFound = ETrue; |
|
6401 |
break; |
|
6402 |
} |
|
6403 |
} |
|
6404 |
TUint zoneIds = 2; |
|
6405 |
if (!zonesFound) |
|
6406 |
{ |
|
6407 |
zoneIdArray[0] = gZoneConfigArray[index-1].iZoneId; |
|
6408 |
zoneIdArray[1] = gZoneConfigArray[index].iZoneId; |
|
6409 |
} |
|
6410 |
else |
|
6411 |
{// Have a zone that won't meet the allocation so use it |
|
6412 |
TESTDEBUG(test.Printf(_L("noAllocZone ID %x\n"), gZoneConfigArray[noAllocZone].iZoneId)); |
|
6413 |
zoneIds++; |
|
6414 |
zoneIdArray[0] = gZoneConfigArray[noAllocZone].iZoneId; |
|
6415 |
zoneIdArray[1] = gZoneConfigArray[index-1].iZoneId; |
|
6416 |
zoneIdArray[2] = gZoneConfigArray[index].iZoneId; |
|
6417 |
} |
|
6418 |
||
6419 |
r = Ldd.MultiZoneAllocContiguous(zoneIdArray, zoneIds, allocBytes); |
|
6420 |
||
6421 |
GetAllPageInfo(); |
|
6422 |
if (r != KErrNone || |
|
6423 |
gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || |
|
6424 |
gZoneUtilArray[index-1].iFreePages == gZoneUtilArray[index-1].iPhysPages) |
|
6425 |
{// The allocation failed. |
|
6426 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6427 |
TEST_FAIL; |
|
6428 |
} |
|
6429 |
else |
|
6430 |
{ |
|
6431 |
test.Printf(_L("Passed...\n")); |
|
6432 |
} |
|
6433 |
} |
|
6434 |
// TestEnd() will free the allocation of fixed pages. |
|
6435 |
TestEnd(); |
|
6436 |
||
6437 |
test.Next(_L("Test6: Test Epoc::ZoneAllocPhysicalRam() returns KErrNoMemory when appropriate")); |
|
6438 |
TestStart(); |
|
6439 |
// Attempt to find a RAM zone with some non-discarable pages allocated into it. |
|
6440 |
// (At time of writing discardable pages wouldn't be discarded on demand by |
|
6441 |
// this function but this may be changed in the future as discontiguous case does that). |
|
6442 |
GetAllPageInfo(); |
|
6443 |
zonesFound = EFalse; |
|
6444 |
index = gZoneCount - 1; |
|
6445 |
for (; index > 0; index--) |
|
6446 |
{ |
|
6447 |
if (gZoneUtilArray[index].iFreePages && |
|
6448 |
(gZoneUtilArray[index].iAllocMovable || gZoneUtilArray[index].iAllocFixed)) |
|
6449 |
{ |
|
6450 |
zonesFound = ETrue; |
|
6451 |
break; |
|
6452 |
} |
|
6453 |
} |
|
6454 |
||
6455 |
if (!zonesFound) |
|
6456 |
{ |
|
6457 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6458 |
} |
|
6459 |
else |
|
6460 |
{ |
|
6461 |
// Attempt to allocate the whole of the RAM zone. |
|
6462 |
GetOriginalPageCount(); |
|
6463 |
TUint allocBytes = gZoneConfigArray[index].iPhysPages << gPageShift; |
|
6464 |
r = Ldd.ZoneAllocContiguous(gZoneConfigArray[index].iZoneId, allocBytes); |
|
6465 |
||
6466 |
// The allocation should have failed and no pages should have |
|
6467 |
// been allocated. |
|
6468 |
GetAllPageInfo(); |
|
6469 |
if (r != KErrNoMemory || |
|
6470 |
gOriginalPageCountArray[index].iFreePages > gZoneUtilArray[index].iFreePages) |
|
6471 |
{ |
|
6472 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6473 |
TEST_FAIL; |
|
6474 |
} |
|
6475 |
else |
|
6476 |
{ |
|
6477 |
test.Printf(_L("Pass: Correct return value\n")); |
|
6478 |
} |
|
6479 |
} |
|
6480 |
// TestEnd() will free the allocation of fixed pages. |
|
6481 |
TestEnd(); |
|
6482 |
delete[] zoneIdArray; |
|
6483 |
||
6484 |
||
6485 |
test.Next(_L("Test7: Test Epoc::ZoneAllocPhysicalRam() (Contiguous) doesn't affect the allocation of movable pages")); |
|
6486 |
r = TestZoneAllocNoAffect(Z_ALLOC_CONTIG, BEST_MOVABLE); |
|
6487 |
if (r != KErrNone) |
|
6488 |
{ |
|
6489 |
TEST_FAIL; |
|
6490 |
} |
|
6491 |
||
6492 |
test.Next(_L("Test8: Test Epoc::ZoneAllocPhysicalRam() (Contiguous) doesn't affect the allocation of discardable pages")); |
|
6493 |
r = TestZoneAllocNoAffect(Z_ALLOC_CONTIG, BEST_DISCARDABLE); |
|
6494 |
if (r != KErrNone) |
|
6495 |
{ |
|
6496 |
TEST_FAIL; |
|
6497 |
} |
|
6498 |
||
6499 |
test.End(); |
|
6500 |
return KErrNone; |
|
6501 |
} |
|
6502 |
||
6503 |
||
6504 |
// |
|
6505 |
// TestZoneAllocDiscontiguous |
|
6506 |
// |
|
6507 |
//--------------------------------------------------------------------------------------------------------------------- |
|
6508 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0536 |
|
6509 |
//! @SYMTestType CIT |
|
6510 |
//! @SYMTestCaseDesc Verifying the discontiguous overload of Epoc::ZoneAllocPhysicalRam(). |
|
6511 |
//! @SYMPREQ PREQ308 |
|
6512 |
//! @SYMTestPriority High |
|
6513 |
//! @SYMTestActions |
|
6514 |
//! 1. Call function with a valid aZoneID. |
|
6515 |
//! 2. Call function with an invalid aZoneID |
|
6516 |
//! 3. Call function with aNumPages > zone size |
|
6517 |
//! 4. Call multiple RAM zone overload of function with a mix of valid and invalid IDs |
|
6518 |
//! 5. Call multiple RAM zone overload of function so that the allocation will have to |
|
6519 |
//! span multiple RAM zones. |
|
6520 |
//! 6. Call function with memory full with DP cache that has reached it's |
|
6521 |
//! minimum cache size. |
|
6522 |
//! 7. Call function with memory not quite full with DP cache that has reached it's |
|
6523 |
//! minimum cache size and with the specified RAM zone full. |
|
6524 |
//! 8. Call function to allocate a whole RAM zone on a RAM zone that has non-discardable |
|
6525 |
//! pages already allocated into it. |
|
6526 |
//! 9. Call function to allocate one less than the whole RAM zone on a RAM zone that has movable |
|
6527 |
//! pages allocated. |
|
6528 |
//! 10. Get the most preferable zone for movable page allocations (mostPref). Allocate 1 discontiguous fixed page |
|
6529 |
//! in the least preferable zone. Following this allocate 1 movable page |
|
6530 |
//! 11. Get the most preferable zone for discardable page allocations (mostPref). Allocate 1 discontiguous fixed |
|
6531 |
//! page in the least preferable zone. Following this allocate 1 discardable page |
|
6532 |
//! |
|
6533 |
//! @SYMTestExpectedResults |
|
6534 |
//! 1. KErrNone |
|
6535 |
//! 2. KErrArgument |
|
6536 |
//! 3. KErrArgument |
|
6537 |
//! 4. KErrArgument |
|
6538 |
//! 5. KErrNone |
|
6539 |
//! 6. KErrNoMemory |
|
6540 |
//! 7. KErrNone |
|
6541 |
//! 8. KErrNoMemory |
|
6542 |
//! 9. KErrNone (i.e. the movable pages are shifted out of the way but only those that need to be moved). |
|
6543 |
//! 10. Movable pages are allocated into zone mostPref. |
|
6544 |
//! 11. Discardable pages are allocated into zone mostPref |
|
6545 |
//--------------------------------------------------------------------------------------------------------------------- |
|
6546 |
TInt TestZoneAllocDiscontiguous() |
|
6547 |
{ |
|
6548 |
TInt r = KErrNone; |
|
6549 |
test.Start(_L("Test1: Call function Epoc::ZoneAllocPhysicalRam() with a valid aZoneID")); |
|
6550 |
TestStart(); |
|
6551 |
||
6552 |
const TUint KAllocPages = 5; |
|
6553 |
// Detemine how many extra pages the kernel heap may grow by |
|
6554 |
// as these may need to be accounted for. |
|
6555 |
TUint fixedOverhead = Ldd.GetAllocDiff(KAllocPages); |
|
6556 |
||
6557 |
GetOriginalPageCount(); |
|
6558 |
GetAllPageInfo(); |
|
6559 |
TUint index = gZoneCount - 1; |
|
6560 |
while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) |
|
6561 |
{ |
|
6562 |
-- index; |
|
6563 |
} |
|
6564 |
||
6565 |
if (gZoneUtilArray[index].iFreePages < KAllocPages || gTotalPageCount.iFreePages < KAllocPages + fixedOverhead) |
|
6566 |
{ |
|
6567 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
6568 |
} |
|
6569 |
else |
|
6570 |
{ |
|
6571 |
// Allocate KAllocPages discontiguous fixed pages into RAM zone zoneID |
|
6572 |
// and verfiy that the pages were allocated to the correct zone, allow for |
|
6573 |
// extra fixed pages to be allocated as the kernel heap may grow. |
|
6574 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
6575 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, KAllocPages); |
|
6576 |
||
6577 |
GetAllPageInfo(); |
|
6578 |
if ((r == KErrNone) && |
|
6579 |
(gZoneUtilArray[index].iAllocFixed >= gOriginalPageCountArray[index].iAllocFixed + KAllocPages)) |
|
6580 |
{ |
|
6581 |
test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); |
|
6582 |
} |
|
6583 |
else |
|
6584 |
{ |
|
6585 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
6586 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6587 |
TEST_FAIL; |
|
6588 |
} |
|
6589 |
Ldd.FreeAllFixedPages(); |
|
6590 |
} |
|
6591 |
TestEnd(); |
|
6592 |
||
6593 |
||
6594 |
test.Next(_L("Test2: Call function Epoc::ZoneAllocPhysicalRam() with an invalid aZoneID")); |
|
6595 |
TestStart(); |
|
6596 |
||
6597 |
TUint zoneID = KInvalidZoneID; |
|
6598 |
||
6599 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, KAllocPages); |
|
6600 |
GetAllPageInfo(); |
|
6601 |
if (r == KErrArgument) |
|
6602 |
{ |
|
6603 |
test.Printf(_L("Pass: Correct return value\n")); |
|
6604 |
} |
|
6605 |
else |
|
6606 |
{ |
|
6607 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
6608 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6609 |
TEST_FAIL; |
|
6610 |
} |
|
6611 |
Ldd.FreeAllFixedPages(); |
|
6612 |
TestEnd(); |
|
6613 |
||
6614 |
test.Next(_L("Test3: Call function Epoc::ZoneAllocPhysicalRam() when aNumPages > zone size")); |
|
6615 |
TestStart(); |
|
6616 |
||
6617 |
GetAllPageInfo(); |
|
6618 |
index = gZoneCount - 1; |
|
6619 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
6620 |
||
6621 |
TUint allocPages = gZoneUtilArray[index].iPhysPages + 1; |
|
6622 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, allocPages); |
|
6623 |
||
6624 |
GetAllPageInfo(); |
|
6625 |
if (r == KErrArgument) |
|
6626 |
{ |
|
6627 |
test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); |
|
6628 |
} |
|
6629 |
else |
|
6630 |
{ |
|
6631 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); |
|
6632 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6633 |
TEST_FAIL; |
|
6634 |
} |
|
6635 |
Ldd.FreeAllFixedPages(); |
|
6636 |
TestEnd(); |
|
6637 |
||
6638 |
const TUint KMultiZoneIds = 10; |
|
6639 |
TUint* zoneIdArray = new TUint[KMultiZoneIds]; |
|
6640 |
test_NotNull(zoneIdArray); |
|
6641 |
||
6642 |
test.Next(_L("Test4: Test Epoc::ZoneAllocPhysicaRam() always fails when at least one ID is invalid")); |
|
6643 |
TestStart(); |
|
6644 |
||
6645 |
TBool zonesFound = EFalse; |
|
6646 |
index = gZoneCount - 1; |
|
6647 |
for (; index > 0; index--) |
|
6648 |
{ |
|
6649 |
if (gZoneUtilArray[index].iFreePages >= KAllocPages) |
|
6650 |
{ |
|
6651 |
zonesFound = ETrue; |
|
6652 |
break; |
|
6653 |
} |
|
6654 |
} |
|
6655 |
if (!zonesFound) |
|
6656 |
{ |
|
6657 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
6658 |
} |
|
6659 |
else |
|
6660 |
{ |
|
6661 |
TUint zoneIdSize = 2; |
|
6662 |
zoneIdArray[0] = gZoneConfigArray[index].iZoneId; |
|
6663 |
zoneIdArray[1] = KInvalidZoneID; |
|
6664 |
r = Ldd.MultiZoneAllocDiscontiguous(zoneIdArray, zoneIdSize, KAllocPages); |
|
6665 |
if (r != KErrArgument) |
|
6666 |
{// Make sure we cleanup. |
|
6667 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6668 |
TEST_FAIL; |
|
6669 |
} |
|
6670 |
else |
|
6671 |
{ |
|
6672 |
test.Printf(_L("Passed...\n")); |
|
6673 |
} |
|
6674 |
} |
|
6675 |
||
6676 |
TestEnd(); |
|
6677 |
||
6678 |
test.Next(_L("Test5: Test Epoc::ZoneAllocPhysicalRam() can span multiple RAM zones")); |
|
6679 |
TestStart(); |
|
6680 |
zonesFound = EFalse; |
|
6681 |
TUint zonesCount = 0; |
|
6682 |
const TUint KTest5Zones = 2; |
|
6683 |
TUint zoneIndices[KTest5Zones]; |
|
6684 |
allocPages = 0; |
|
6685 |
||
6686 |
// Attempt to find KTest5Zones RAM zones with some free pages, |
|
6687 |
// search in reverse preference order to reduce chances of kernel heap pages |
|
6688 |
// being allocated into the RAM zones under test. |
|
6689 |
GetPrefOrder(); |
|
6690 |
index = gZoneCount - 1; |
|
6691 |
for (; index > 0; index--) |
|
6692 |
{ |
|
6693 |
TUint prefIndex = gPrefArray[index]; |
|
6694 |
if (gZoneUtilArray[prefIndex].iFreePages != 0) |
|
6695 |
{ |
|
6696 |
allocPages += gZoneUtilArray[prefIndex].iFreePages; |
|
6697 |
zoneIndices[zonesCount++] = prefIndex; |
|
6698 |
if (zonesCount == KTest5Zones) |
|
6699 |
{ |
|
6700 |
zonesFound = ETrue; |
|
6701 |
break; |
|
6702 |
} |
|
6703 |
} |
|
6704 |
} |
|
6705 |
||
6706 |
if (!zonesFound) |
|
6707 |
{ |
|
6708 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6709 |
} |
|
6710 |
else |
|
6711 |
{ |
|
6712 |
// Attempt to find a zone that has less free pages than the allocation |
|
6713 |
// size so we can test that the method continues past too full RAM zones. |
|
6714 |
zonesFound = EFalse; |
|
6715 |
TUint noAllocZone = 0; |
|
6716 |
for (; noAllocZone < gZoneCount; noAllocZone++) |
|
6717 |
{ |
|
6718 |
if (allocPages > gZoneUtilArray[noAllocZone].iFreePages && |
|
6719 |
noAllocZone != zoneIndices[0] && noAllocZone != zoneIndices[1]) |
|
6720 |
{ |
|
6721 |
zonesFound = ETrue; |
|
6722 |
break; |
|
6723 |
} |
|
6724 |
} |
|
6725 |
||
6726 |
if (gPagedRom) |
|
6727 |
{// Fill memory with DP pages to test the allocation will discard |
|
6728 |
// pages when necessary. |
|
6729 |
TInt discard; |
|
6730 |
r = AllocDiscardable(discard); |
|
6731 |
GetAllPageInfo(); |
|
6732 |
if (r != KErrNone || |
|
6733 |
gZoneUtilArray[zoneIndices[0]].iFreePages != 0 || |
|
6734 |
gZoneUtilArray[zoneIndices[1]].iFreePages != 0) |
|
6735 |
{ |
|
6736 |
test.Printf(_L("r %d\n"), r); |
|
6737 |
CLEANUP(ResetDPCache()); |
|
6738 |
TEST_FAIL; |
|
6739 |
} |
|
6740 |
} |
|
6741 |
||
6742 |
TUint zoneIds = KTest5Zones; |
|
6743 |
if (!zonesFound) |
|
6744 |
{ |
|
6745 |
zoneIdArray[0] = gZoneConfigArray[zoneIndices[0]].iZoneId; |
|
6746 |
zoneIdArray[1] = gZoneConfigArray[zoneIndices[1]].iZoneId; |
|
6747 |
} |
|
6748 |
else |
|
6749 |
{// Have a zone that won't meet the allocation so use it |
|
6750 |
TESTDEBUG(test.Printf(_L("noAllocZone ID %x\n"), gZoneConfigArray[noAllocZone].iZoneId)); |
|
6751 |
zoneIds++; |
|
6752 |
zoneIdArray[0] = gZoneConfigArray[noAllocZone].iZoneId; |
|
6753 |
zoneIdArray[1] = gZoneConfigArray[zoneIndices[0]].iZoneId; |
|
6754 |
zoneIdArray[2] = gZoneConfigArray[zoneIndices[1]].iZoneId; |
|
6755 |
} |
|
6756 |
||
6757 |
// Adjust the allocation size for any kernel heap pages that may be |
|
6758 |
// required as they may get allocated into the RAM zones under test. |
|
6759 |
allocPages -= Ldd.GetAllocDiff(allocPages); |
|
6760 |
||
6761 |
GetOriginalPageCount(); |
|
6762 |
r = Ldd.MultiZoneAllocDiscontiguous(zoneIdArray, zoneIds, allocPages); |
|
6763 |
||
6764 |
GetAllPageInfo(); |
|
6765 |
if (r != KErrNone || |
|
6766 |
gZoneUtilArray[zoneIndices[0]].iAllocFixed <= gOriginalPageCountArray[zoneIndices[0]].iAllocFixed || |
|
6767 |
gZoneUtilArray[zoneIndices[1]].iAllocFixed <= gOriginalPageCountArray[zoneIndices[1]].iAllocFixed) |
|
6768 |
{// The allocation failed. |
|
6769 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6770 |
TEST_FAIL; |
|
6771 |
} |
|
6772 |
else |
|
6773 |
{ |
|
6774 |
test.Printf(_L("Passed...\n")); |
|
6775 |
} |
|
6776 |
} |
|
6777 |
// TestEnd() will free the allocation of fixed pages. |
|
6778 |
TestEnd(); |
|
6779 |
||
6780 |
||
6781 |
if (gPagedRom) |
|
6782 |
{ |
|
6783 |
test.Next(_L("Test6: Test Epoc::ZoneAllocPhysicalRam() returns KErrNoMemory when DP minimum cache size is hit")); |
|
6784 |
TestStart(); |
|
6785 |
GetPrefOrder(); |
|
6786 |
TUint zoneFreePages = 0; |
|
6787 |
index = gZoneCount - 1; |
|
6788 |
for (; index > 0; index--) |
|
6789 |
{ |
|
6790 |
TUint prefIndex = gPrefArray[index]; |
|
6791 |
zoneFreePages = gZoneUtilArray[prefIndex].iFreePages; |
|
6792 |
if (zoneFreePages > 2) |
|
6793 |
{ |
|
6794 |
index = prefIndex; |
|
6795 |
zonesFound = ETrue; |
|
6796 |
break; |
|
6797 |
} |
|
6798 |
} |
|
6799 |
||
6800 |
if (!zonesFound) |
|
6801 |
{ |
|
6802 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6803 |
} |
|
6804 |
else |
|
6805 |
{ |
|
6806 |
// Fill the RAM with DP cache pages and up the minimum cache size so |
|
6807 |
// that the allocation will fail. |
|
6808 |
TInt discardBytes; |
|
6809 |
TInt r = AllocDiscardable(discardBytes, KMaxTUint64, (zoneFreePages - 1) << gPageShift); |
|
6810 |
test_KErrNone(r); |
|
6811 |
||
6812 |
// Ensure that the RAM zone under test is full. |
|
6813 |
GetAllPageInfo(); |
|
6814 |
if (gZoneUtilArray[index].iFreePages != 0) |
|
6815 |
{ |
|
6816 |
CLEANUP(ResetDPCache()); |
|
6817 |
TEST_FAIL; |
|
6818 |
} |
|
6819 |
||
6820 |
r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[index].iZoneId, zoneFreePages); |
|
6821 |
||
6822 |
if (r != KErrNoMemory) |
|
6823 |
{ |
|
6824 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6825 |
TEST_FAIL; |
|
6826 |
} |
|
6827 |
else |
|
6828 |
{ |
|
6829 |
test.Printf(_L("Passed...\n")); |
|
6830 |
} |
|
6831 |
} |
|
6832 |
TestEnd(); |
|
6833 |
||
6834 |
test.Next(_L("Test7: Test Epoc::ZoneAllocPhysicalRam() replaces DP cache when DP minimum cache size is hit")); |
|
6835 |
TestStart(); |
|
6836 |
gChunkArray1 = new RChunk; |
|
6837 |
gChunkArraySize1 = 1; |
|
6838 |
GetPrefOrder(); |
|
6839 |
zonesFound = EFalse; |
|
6840 |
for (index = gZoneCount - 1; index > 0 && !zonesFound; index--) |
|
6841 |
{ |
|
6842 |
TUint prefIndex = gPrefArray[index]; |
|
6843 |
zoneFreePages = gZoneUtilArray[prefIndex].iFreePages; |
|
6844 |
if (zoneFreePages > 1) |
|
6845 |
{ |
|
6846 |
// Check there is at least one free page in the other RAM zones. |
|
6847 |
TUint i = 0; |
|
6848 |
for (; i < gZoneCount; i++) |
|
6849 |
{ |
|
6850 |
if (i != prefIndex && gZoneUtilArray[i].iFreePages != 0) |
|
6851 |
{ |
|
6852 |
index = prefIndex; |
|
6853 |
zonesFound = ETrue; |
|
6854 |
break; |
|
6855 |
} |
|
6856 |
} |
|
6857 |
} |
|
6858 |
} |
|
6859 |
if (!zonesFound) |
|
6860 |
{ |
|
6861 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6862 |
} |
|
6863 |
else |
|
6864 |
{ |
|
6865 |
index++; |
|
6866 |
// Attempt to allocate a movable page to create a gap for the DP cache |
|
6867 |
// page to be replaced with. |
|
6868 |
GetOriginalPageCount(); |
|
6869 |
r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, gPageSize); |
|
6870 |
||
6871 |
GetAllPageInfo(); |
|
6872 |
TESTDEBUG(test.Printf(_L("index %d prev free 0x%x cur free 0x%x\n"), |
|
6873 |
index, gOriginalPageCountArray[index].iFreePages, gZoneUtilArray[index].iFreePages)); |
|
6874 |
||
6875 |
if (r != KErrNone || |
|
6876 |
gOriginalPageCountArray[index].iFreePages != gZoneUtilArray[index].iFreePages) |
|
6877 |
{// The gap was allocated into the RAM zone under test so can't continue as |
|
6878 |
// the DP cache will attempt to be reallocated into the same RAM zone. |
|
6879 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6880 |
} |
|
6881 |
else |
|
6882 |
{ |
|
6883 |
// Get the ldd to create the array for the fixed page addresses here |
|
6884 |
// so that any kernel heap allocations have already occurred before |
|
6885 |
// memory is filled etc. Make allocation really large so it will always be enough. |
|
6886 |
r = Ldd.AllocFixedArray(50); |
|
6887 |
||
6888 |
// Fill RAM with DP cache pages and free the gap. |
|
6889 |
TInt discardBytes; |
|
6890 |
r = AllocDiscardable(discardBytes, KMaxTUint64, 0); |
|
6891 |
if (r != KErrNone) |
|
6892 |
{ |
|
6893 |
CLEANUP(ResetDPCache()); |
|
6894 |
TEST_FAIL; |
|
6895 |
} |
|
6896 |
UpdateRamInfo(); |
|
6897 |
TInt prevFreeBytes = gFreeRam; |
|
6898 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
6899 |
UpdateRamInfo(); |
|
6900 |
TInt freedPages = (gFreeRam - prevFreeBytes) >> gPageShift; |
|
6901 |
if (freedPages < 1) |
|
6902 |
{// Something went wrong as should have freed at least one page |
|
6903 |
CLEANUP(ResetDPCache()); |
|
6904 |
TEST_FAIL; |
|
6905 |
} |
|
6906 |
TUint extraFreePages = freedPages - 1; |
|
6907 |
||
6908 |
// Ensure that the RAM zone under test is full. |
|
6909 |
GetAllPageInfo(); |
|
6910 |
if (gZoneUtilArray[index].iFreePages != 0) |
|
6911 |
{ |
|
6912 |
CLEANUP(ResetDPCache()); |
|
6913 |
TEST_FAIL; |
|
6914 |
} |
|
6915 |
||
6916 |
// Allocate from the RAM zone which should force a DP cache |
|
6917 |
// page to be allocated. |
|
6918 |
GetOriginalPageCount(); |
|
6919 |
TUint fixedAllocPages = 1 + extraFreePages; |
|
6920 |
r = Ldd.ZoneAllocDiscontiguous2(gZoneConfigArray[index].iZoneId, fixedAllocPages); |
|
6921 |
||
6922 |
GetAllPageInfo(); |
|
6923 |
if (r != KErrNone || |
|
6924 |
gOriginalPageCountArray[index].iAllocFixed + fixedAllocPages != gZoneUtilArray[index].iAllocFixed) |
|
6925 |
{ |
|
6926 |
test.Printf(_L("r %d index %d alloc 0x%x prevFixed 0x%x curFixed 0x%x\n"), r, index, fixedAllocPages, |
|
6927 |
gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocFixed); |
|
6928 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6929 |
TEST_FAIL; |
|
6930 |
} |
|
6931 |
else |
|
6932 |
{ |
|
6933 |
test.Printf(_L("Passed...\n")); |
|
6934 |
} |
|
6935 |
} |
|
6936 |
} |
|
6937 |
// This should cleanup any fixed pages allocated. |
|
6938 |
TestEnd(); |
|
6939 |
} |
|
6940 |
||
6941 |
test.Next(_L("Test8: Test Epoc::ZoneAllocPhysicalRam() return KErrNoMemory when appropriate")); |
|
6942 |
TestStart(); |
|
6943 |
// Search for a RAM zone that has some immovable pages allocated into |
|
6944 |
// it but isn't totally full. |
|
6945 |
GetAllPageInfo(); |
|
6946 |
zonesFound = EFalse; |
|
6947 |
for (index = 0; index < gZoneCount; index++) |
|
6948 |
{ |
|
6949 |
if (gZoneUtilArray[index].iFreePages && |
|
6950 |
(gZoneUtilArray[index].iAllocUnknown || gZoneUtilArray[index].iAllocFixed)) |
|
6951 |
{ |
|
6952 |
zonesFound = ETrue; |
|
6953 |
break; |
|
6954 |
} |
|
6955 |
} |
|
6956 |
if (!zonesFound) |
|
6957 |
{ |
|
6958 |
test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); |
|
6959 |
} |
|
6960 |
else |
|
6961 |
{ |
|
6962 |
// Attempt to allocate the whole RAM zone. |
|
6963 |
r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[index].iZoneId, gZoneUtilArray[index].iPhysPages); |
|
6964 |
||
6965 |
if (r != KErrNoMemory) |
|
6966 |
{ |
|
6967 |
test.Printf(_L("FAIL: r %d index %d\n"), r, index); |
|
6968 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
6969 |
TEST_FAIL; |
|
6970 |
} |
|
6971 |
else |
|
6972 |
{ |
|
6973 |
test.Printf(_L("Passed...\n")); |
|
6974 |
} |
|
6975 |
} |
|
6976 |
TestEnd(); |
|
6977 |
||
6978 |
test.Next(_L("Test9: Test Epoc::ZoneAllocPhysicalRam() moves the required number of movable pages")); |
|
6979 |
TestStart(); |
|
6980 |
TUint allocFixedPages; |
|
6981 |
// Search for a RAM zone that has at least 2 movable pages allocated into it. |
|
6982 |
// Need 2 so that we can move one and leave one. |
|
6983 |
GetAllPageInfo(); |
|
6984 |
zonesFound = EFalse; |
|
6985 |
for (index = 0; index < gZoneCount; index++) |
|
6986 |
{ |
|
6987 |
if (gZoneUtilArray[index].iAllocMovable > 1) |
|
6988 |
{ |
|
6989 |
// Only use this zone if the other RAM zones have enough free space for |
|
6990 |
// the movable page in this zone to be moved to. |
|
6991 |
TUint freeInOther = 0; |
|
6992 |
for (TUint i = 0; i < gZoneCount && !zonesFound; i++) |
|
6993 |
{ |
|
6994 |
if (i != index) |
|
6995 |
{ |
|
6996 |
freeInOther += gZoneUtilArray[i].iFreePages; |
|
6997 |
} |
|
6998 |
} |
|
6999 |
if (freeInOther >= gZoneUtilArray[index].iAllocMovable) |
|
7000 |
{ |
|
7001 |
zonesFound = ETrue; |
|
7002 |
break; |
|
7003 |
} |
|
7004 |
} |
|
7005 |
} |
|
7006 |
||
7007 |
if (!zonesFound) |
|
7008 |
{ |
|
7009 |
test.Printf(_L("No suitable RAM zone could be found - Skipping...\n")); |
|
7010 |
goto skipTest9; |
|
7011 |
} |
|
7012 |
||
7013 |
// Allocate up to one less than the RAM zone size. Do 2 stage fixed allocation |
|
7014 |
// to avoid kernel heap allocations spoiling test setup. |
|
7015 |
r = Ldd.AllocFixedArray(gZoneConfigArray[index].iPhysPages); |
|
7016 |
if (r != KErrNone) |
|
7017 |
{ |
|
7018 |
test.Printf(_L("Not enough free RAM to perform test - Skipping...\n")); |
|
7019 |
goto skipTest9; |
|
7020 |
} |
|
7021 |
||
7022 |
GetAllPageInfo(); |
|
7023 |
if (gZoneUtilArray[index].iAllocMovable < 2) |
|
7024 |
{ |
|
7025 |
test.Printf(_L("Expanding kernel heap for phys address array spoiled RAM zone - Skipping...\n")); |
|
7026 |
goto skipTest9; |
|
7027 |
} |
|
7028 |
allocFixedPages = gZoneUtilArray[index].iAllocMovable + |
|
7029 |
gZoneUtilArray[index].iAllocDiscardable + |
|
7030 |
gZoneUtilArray[index].iFreePages - 1; |
|
7031 |
r = Ldd.ZoneAllocDiscontiguous2(gZoneConfigArray[index].iZoneId, allocFixedPages); |
|
7032 |
||
7033 |
if (r != KErrNone || !gZoneUtilArray[index].iAllocMovable) |
|
7034 |
{ |
|
7035 |
test.Printf(_L("Fixed not allocated or too many movable moved RAM zone ID%x\n"), |
|
7036 |
gZoneConfigArray[index].iZoneId); |
|
7037 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
7038 |
TEST_FAIL; |
|
7039 |
} |
|
7040 |
||
7041 |
skipTest9 : |
|
7042 |
// This will clean up any fixed pages allocated. |
|
7043 |
TestEnd(); |
|
7044 |
||
7045 |
delete[] zoneIdArray; |
|
7046 |
||
7047 |
test.Next(_L("Test10: Test Epoc::ZoneAllocPhysicalRam() (Discontiguous) doesn't affect the allocation of movable pages")); |
|
7048 |
r = TestZoneAllocNoAffect(Z_ALLOC_DISC, BEST_MOVABLE); |
|
7049 |
if (r != KErrNone) |
|
7050 |
{ |
|
7051 |
TEST_FAIL; |
|
7052 |
} |
|
7053 |
||
7054 |
test.Next(_L("Test11: Test Epoc::ZoneAllocPhysicalRam() (Discontiguous) doesn't affect the allocation of discardable pages")); |
|
7055 |
r = TestZoneAllocNoAffect(Z_ALLOC_DISC, BEST_DISCARDABLE); |
|
7056 |
if (r != KErrNone) |
|
7057 |
{ |
|
7058 |
TEST_FAIL; |
|
7059 |
} |
|
7060 |
||
7061 |
test.End(); |
|
7062 |
return KErrNone; |
|
7063 |
} |
|
7064 |
||
7065 |
||
7066 |
// |
|
7067 |
// TestFreeZone |
|
7068 |
// |
|
7069 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7070 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0537 |
|
7071 |
//! @SYMTestType CIT |
|
7072 |
//! @SYMTestCaseDesc Verifying the function Epoc::FreePhysicalRam() |
|
7073 |
//! @SYMPREQ PREQ308 |
|
7074 |
//! @SYMTestPriority High |
|
7075 |
//! @SYMTestActions |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7076 |
//! 1. Allocate fixed pages and call function to free all fixed pages allocated. |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7077 |
//! 2. Claim a RAM zone and then free it via Epoc::FreeRamZone(). |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7078 |
//! 3. Invoke Epoc::FreeRamZone() with an invalid RAM zone ID. |
0 | 7079 |
//! |
7080 |
//! @SYMTestExpectedResults |
|
7081 |
//! 1. KErrNone |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7082 |
//! 2. KErrNone |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7083 |
//! 3. KErrArgument |
0 | 7084 |
//--------------------------------------------------------------------------------------------------------------------- |
7085 |
TInt TestFreeZone() |
|
7086 |
{ |
|
7087 |
TInt r = 0; |
|
7088 |
TUint zoneID = 0; |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7089 |
test.Start(_L("Test1: Freeing allocated pages")); |
0 | 7090 |
TestStart(); |
7091 |
||
7092 |
TInt pages = 50; |
|
7093 |
||
7094 |
GetAllPageInfo(); |
|
7095 |
TUint index = gZoneCount - 1; |
|
7096 |
while (index > 0 && |
|
7097 |
(gZoneUtilArray[index].iAllocFixed != 0 || |
|
7098 |
gZoneUtilArray[index].iAllocUnknown != 0 || |
|
7099 |
(TInt)gZoneUtilArray[index].iFreePages < pages)) |
|
7100 |
{ |
|
7101 |
-- index; |
|
7102 |
} |
|
7103 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
7104 |
||
7105 |
if (index == 0 && |
|
7106 |
(gZoneUtilArray[index].iAllocFixed != 0 || |
|
7107 |
gZoneUtilArray[index].iAllocUnknown != 0 || |
|
7108 |
(TInt)gZoneUtilArray[index].iFreePages < pages)) |
|
7109 |
{ |
|
7110 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
7111 |
} |
|
7112 |
else |
|
7113 |
{ |
|
7114 |
TESTDEBUG(test.Printf(_L("Allocating 0x%x pages to zone ID 0x%x\n"), pages, zoneID)); |
|
7115 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, pages); |
|
7116 |
GetAllPageInfo(); |
|
7117 |
||
7118 |
TESTDEBUG(test.Printf(_L("Freeing 0x%x fixed pages\n"), pages)); |
|
7119 |
if (r == KErrNone) |
|
7120 |
{ |
|
7121 |
r = Ldd.FreeZone(pages); |
|
7122 |
} |
|
7123 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
7124 |
if (r == KErrNone) |
|
7125 |
{ |
|
7126 |
test.Printf(_L("Pass: Correct return value\n")); |
|
7127 |
} |
|
7128 |
else |
|
7129 |
{ |
|
7130 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
|
7131 |
TEST_FAIL; |
|
7132 |
} |
|
7133 |
} |
|
7134 |
TestEnd(); |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7135 |
test.End(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7136 |
|
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7137 |
test.Start(_L("Test2: Epoc::FreeRamZone() on a claimed RAM zone")); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7138 |
TestStart(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7139 |
GetAllPageInfo(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7140 |
TUint zoneIndex = 0; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7141 |
while (zoneIndex < gZoneCount) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7142 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7143 |
if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7144 |
break; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7145 |
zoneIndex++; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7146 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7147 |
if (zoneIndex >= gZoneCount) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7148 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7149 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7150 |
goto Test2End; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7151 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7152 |
zoneID = gZoneConfigArray[zoneIndex].iZoneId; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7153 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7154 |
if (r != KErrNone) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7155 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7156 |
test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7157 |
TEST_FAIL; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7158 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7159 |
GetAllPageInfo(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7160 |
if (gZoneUtilArray[zoneIndex].iPhysPages != gZoneUtilArray[zoneIndex].iAllocFixed) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7161 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7162 |
test.Printf(_L("Fail: RAM zone ID %d not claimed successfully"), zoneID); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7163 |
TEST_FAIL; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7164 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7165 |
r = Ldd.FreeZoneId(zoneID); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7166 |
GetAllPageInfo(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7167 |
if (r != KErrNone || |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7168 |
gZoneUtilArray[zoneIndex].iPhysPages != gZoneUtilArray[zoneIndex].iFreePages) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7169 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7170 |
test.Printf(_L("Fail: RAM zone ID %d not freed successfully r=%d"), zoneID, r); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7171 |
TEST_FAIL; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7172 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7173 |
Test2End: |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7174 |
TestEnd(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7175 |
test.End(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7176 |
|
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7177 |
test.Start(_L("Test2: Epoc::FreeRamZone() on an invalid RAM zone")); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7178 |
TestStart(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7179 |
r = Ldd.FreeZoneId(KInvalidZoneID); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7180 |
if (r != KErrArgument) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7181 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7182 |
test.Printf(_L("Fail: Error RAM zone ID %d r=%d"), KInvalidZoneID, r); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7183 |
TEST_FAIL; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7184 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7185 |
|
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
7186 |
TestEnd(); |
0 | 7187 |
test.End(); |
7188 |
return KErrNone; |
|
7189 |
} |
|
7190 |
||
7191 |
||
7192 |
// |
|
7193 |
// TestDefragSemMethod |
|
7194 |
// |
|
7195 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7196 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0538 |
|
7197 |
//! @SYMTestType CIT |
|
7198 |
//! @SYMTestCaseDesc Verifying the semaphore versions of the various defrag methods |
|
7199 |
//! @SYMPREQ PREQ308 |
|
7200 |
//! @SYMTestPriority High |
|
7201 |
//! @SYMTestActions |
|
7202 |
//! 1. Fragment the memory. Following this, call the semaphore variation of DefragRam. |
|
7203 |
//! 2. Fragment the memory. Following this, call the semaphore variation of EmptyRamZone |
|
7204 |
//! 3. Fragment the memory. Following this, call the semaphore variation of ClaimRamZone |
|
7205 |
//! |
|
7206 |
//! @SYMTestExpectedResults |
|
7207 |
//! 1. 1 or more zones have been emptied |
|
7208 |
//! 2. Zone specified has been emptied |
|
7209 |
//! 3. Zone has been claimed |
|
7210 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7211 |
TInt TestDefragSemMethod() |
|
7212 |
{ |
|
7213 |
TInt r = 0; |
|
7214 |
||
7215 |
test.Start(_L("Test1: Call semaphore method of DefragRam")); |
|
7216 |
TestStart(); |
|
7217 |
||
7218 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7219 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7220 |
||
7221 |
GetOriginalPageCount(); |
|
7222 |
TBool genSucceed = CanGenSucceed(); |
|
7223 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SEM); |
|
7224 |
||
7225 |
||
7226 |
if (r != KErrNone ||(genSucceed && CheckZonesSwitchedOff() == EFalse)) |
|
7227 |
{ |
|
7228 |
test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); |
|
7229 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7230 |
TEST_FAIL; |
|
7231 |
} |
|
7232 |
else |
|
7233 |
{ |
|
7234 |
test.Printf(_L("Passed...\n")); |
|
7235 |
} |
|
7236 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
7237 |
TestEnd(); |
|
7238 |
||
7239 |
||
7240 |
test.Next(_L("Test2: Call semaphore method of EmptyRamZone")); |
|
7241 |
TestStart(); |
|
7242 |
||
7243 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7244 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7245 |
||
7246 |
GetAllPageInfo(); |
|
7247 |
TUint index = gZoneCount - 1; |
|
7248 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7249 |
{ |
|
7250 |
-- index; |
|
7251 |
} |
|
7252 |
TUint defragZoneID = gZoneConfigArray[index].iZoneId; |
|
7253 |
||
7254 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7255 |
{ |
|
7256 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
7257 |
} |
|
7258 |
else |
|
7259 |
{ |
|
7260 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SEM, defragZoneID); |
|
7261 |
||
7262 |
GetAllPageInfo(); |
|
7263 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
7264 |
if (freeInOthers && (r != KErrNone || !CheckZoneIsOff(index))) |
|
7265 |
{ |
|
7266 |
test.Printf(_L("Fail: r = %d, or zones has not been swtiched off\n"), r); |
|
7267 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7268 |
TEST_FAIL; |
|
7269 |
} |
|
7270 |
else |
|
7271 |
{ |
|
7272 |
test.Printf(_L("Passed...\n")); |
|
7273 |
} |
|
7274 |
} |
|
7275 |
// This will free any allocated memory. |
|
7276 |
TestEnd(); |
|
7277 |
||
7278 |
test.Next(_L("Test3: Call semaphore method of ClaimRamZone")); |
|
7279 |
TestStart(); |
|
7280 |
||
7281 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7282 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7283 |
||
7284 |
GetAllPageInfo(); |
|
7285 |
index = gZoneCount - 2; |
|
7286 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7287 |
{ |
|
7288 |
-- index; |
|
7289 |
} |
|
7290 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
7291 |
||
7292 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7293 |
{ |
|
7294 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
7295 |
} |
|
7296 |
else |
|
7297 |
{ |
|
7298 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SEM, defragZoneID); |
|
7299 |
||
7300 |
GetAllPageInfo(); |
|
7301 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
7302 |
if (CheckZoneIsOff(index) || |
|
7303 |
(freeInOthers && ( r != KErrNone || |
|
7304 |
gZoneUtilArray[index].iAllocFixed != gZoneConfigArray[index].iPhysPages))) |
|
7305 |
{ |
|
7306 |
test.Printf(_L("Fail: r = %d, or zone ID 0x%x has not been claimed\n"), r, defragZoneID); |
|
7307 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7308 |
TEST_FAIL; |
|
7309 |
} |
|
7310 |
else |
|
7311 |
{ |
|
7312 |
test.Printf(_L("Passed...\n")); |
|
7313 |
} |
|
7314 |
||
7315 |
r = Ldd.FreeAllFixedPages(); |
|
7316 |
} |
|
7317 |
||
7318 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
7319 |
TestEnd(); |
|
7320 |
||
7321 |
test.End(); |
|
7322 |
return KErrNone; |
|
7323 |
||
7324 |
} |
|
7325 |
||
7326 |
||
7327 |
// |
|
7328 |
// TestDefragDfcMethod |
|
7329 |
// |
|
7330 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7331 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0539 |
|
7332 |
//! @SYMTestType CIT |
|
7333 |
//! @SYMTestCaseDesc Verifying the Dfc versions of the various defrag methods |
|
7334 |
//! @SYMPREQ PREQ308 |
|
7335 |
//! @SYMTestPriority High |
|
7336 |
//! @SYMTestActions |
|
7337 |
//! 1. Fragment the memory. Following this, call the Dfc variation of DefragRam. |
|
7338 |
//! 2. Fragment the memory. Following this, call the Dfc variation of EmptyRamZone |
|
7339 |
//! 3. Fragment the memory. Following this, call the Dfc variation of ClaimRamZone |
|
7340 |
//! |
|
7341 |
//! @SYMTestExpectedResults |
|
7342 |
//! 1. 1 or more zones have been emptied |
|
7343 |
//! 2. Zone specified has been emptied |
|
7344 |
//! 3. Zone has been claimed |
|
7345 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7346 |
TInt TestDefragDfcMethod() |
|
7347 |
{ |
|
7348 |
TInt r = 0; |
|
7349 |
TRequestStatus req; |
|
7350 |
test.Start(_L("Test1: Call Dfc method of DefragRam")); |
|
7351 |
TestStart(); |
|
7352 |
||
7353 |
GetAllPageInfo(); |
|
7354 |
||
7355 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7356 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7357 |
||
7358 |
GetOriginalPageCount(); |
|
7359 |
TBool genSucceed = CanGenSucceed(); |
|
7360 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_DFC, 0, 0, -1, &req); |
|
7361 |
TESTDEBUG(test.Printf(_L("After queueing defrag r = %d\n"), r)); |
|
7362 |
User::WaitForRequest(req); |
|
7363 |
r = req.Int(); |
|
7364 |
||
7365 |
if (r != KErrNone || (genSucceed && CheckZonesSwitchedOff() == EFalse)) |
|
7366 |
{ |
|
7367 |
test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); |
|
7368 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7369 |
TEST_FAIL; |
|
7370 |
} |
|
7371 |
else |
|
7372 |
{ |
|
7373 |
test.Printf(_L("Passed...\n")); |
|
7374 |
} |
|
7375 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
7376 |
TestEnd(); |
|
7377 |
||
7378 |
||
7379 |
test.Next(_L("Test2: Call Dfc method of EmptyRamZone")); |
|
7380 |
TestStart(); |
|
7381 |
||
7382 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7383 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7384 |
||
7385 |
GetAllPageInfo(); |
|
7386 |
TUint index = gZoneCount - 1; |
|
7387 |
while (index > 0 && |
|
7388 |
(gZoneUtilArray[index].iAllocMovable < 10 || |
|
7389 |
gZoneUtilArray[index].iAllocFixed != 0 || |
|
7390 |
gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7391 |
{ |
|
7392 |
-- index; |
|
7393 |
} |
|
7394 |
||
7395 |
TUint defragZoneID = gZoneConfigArray[index].iZoneId; |
|
7396 |
test.Printf(_L("zone ID = 0x%x\n"), defragZoneID); |
|
7397 |
if (index == 0 && |
|
7398 |
(gZoneUtilArray[index].iAllocMovable < 10 || |
|
7399 |
gZoneUtilArray[index].iAllocFixed != 0 || |
|
7400 |
gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7401 |
{ |
|
7402 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
7403 |
} |
|
7404 |
else |
|
7405 |
{ |
|
7406 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_DFC, defragZoneID, 0, -1, &req); |
|
7407 |
||
7408 |
User::WaitForRequest(req); |
|
7409 |
r = req.Int(); |
|
7410 |
||
7411 |
GetAllPageInfo(); |
|
7412 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
7413 |
if (freeInOthers && (r != KErrNone || CheckZoneIsOff(index) == EFalse)) |
|
7414 |
{ |
|
7415 |
test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); |
|
7416 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7417 |
TEST_FAIL; |
|
7418 |
} |
|
7419 |
else |
|
7420 |
{ |
|
7421 |
test.Printf(_L("Passed...\n")); |
|
7422 |
} |
|
7423 |
} |
|
7424 |
// This will free any allocated memory |
|
7425 |
TestEnd(); |
|
7426 |
||
7427 |
||
7428 |
test.Next(_L("Test3: Call Dfc method of ClaimRamZone")); |
|
7429 |
TestStart(); |
|
7430 |
||
7431 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7432 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7433 |
||
7434 |
GetAllPageInfo(); |
|
7435 |
index = gZoneCount - 1; |
|
7436 |
while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7437 |
{ |
|
7438 |
-- index; |
|
7439 |
} |
|
7440 |
defragZoneID = gZoneConfigArray[index].iZoneId; |
|
7441 |
||
7442 |
if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7443 |
{ |
|
7444 |
test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); |
|
7445 |
} |
|
7446 |
else |
|
7447 |
{ |
|
7448 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_DFC, defragZoneID, 0, -1, &req); |
|
7449 |
User::WaitForRequest(req); |
|
7450 |
r = req.Int(); |
|
7451 |
||
7452 |
GetAllPageInfo(); |
|
7453 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
7454 |
if (CheckZoneIsOff(index) || |
|
7455 |
(freeInOthers && (r != KErrNone || |
|
7456 |
gZoneUtilArray[index].iAllocFixed != gZoneConfigArray[index].iPhysPages))) |
|
7457 |
{ |
|
7458 |
test.Printf(_L("Fail: r = %d, or zone ID 0x%x has not been claimed\n"), r, defragZoneID); |
|
7459 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7460 |
if (r == KErrNone) |
|
7461 |
{ |
|
7462 |
CLEANUP(Ldd.FreeFromAddr( gZoneUtilArray[index].iAllocFixed, |
|
7463 |
gZoneConfigArray[index].iPhysBase)); |
|
7464 |
} |
|
7465 |
TEST_FAIL; |
|
7466 |
} |
|
7467 |
else |
|
7468 |
{ |
|
7469 |
test.Printf(_L("Passed...\n")); |
|
7470 |
} |
|
7471 |
||
7472 |
if (r == KErrNone) |
|
7473 |
{ |
|
7474 |
Ldd.FreeFromAddr( gZoneUtilArray[index].iAllocFixed, |
|
7475 |
gZoneConfigArray[index].iPhysBase); |
|
7476 |
} |
|
7477 |
} |
|
7478 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
7479 |
TestEnd(); |
|
7480 |
||
7481 |
test.End(); |
|
7482 |
return KErrNone; |
|
7483 |
} |
|
7484 |
||
7485 |
||
7486 |
// |
|
7487 |
// TestPriorities |
|
7488 |
// |
|
7489 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7490 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0540 |
|
7491 |
//! @SYMTestType CIT |
|
7492 |
//! @SYMTestCaseDesc Verifying the priorities of the defrag methods |
|
7493 |
//! @SYMPREQ PREQ308 |
|
7494 |
//! @SYMTestPriority High |
|
7495 |
//! @SYMTestActions |
|
7496 |
//! 1. Call DefragRam with a lower invalid priority value, e.g. -2 |
|
7497 |
//! 2. Call DefragRam with a lower invalid priority value, e.g. 100 |
|
7498 |
//! 3. Queue three asynchronous defrags using the Dfc method: |
|
7499 |
//! a. First one with the lowest priority, this will start the straight away |
|
7500 |
//! and will busy the defrag method, causing any other defrag requests to |
|
7501 |
//! be queued. |
|
7502 |
//! b. Queue a defrag with a relatively low priority |
|
7503 |
//! c. Queue a defrag with a higher priority than the one queued in (b) |
|
7504 |
//! Record the order in which the defrags are completed |
|
7505 |
//! |
|
7506 |
//! @SYMTestExpectedResults |
|
7507 |
//! 1. KErrArgument |
|
7508 |
//! 2. KErrArgument |
|
7509 |
//! 3. (a) will complete first as it started straight away. |
|
7510 |
//! (b) and (c) were both queued whilst (a) was running, |
|
7511 |
//! however as (c) has a higher priority, it will complete first - |
|
7512 |
//! therefore the order returned would be "a,c,b" |
|
7513 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7514 |
TInt TestPriorities() |
|
7515 |
{ |
|
7516 |
test.Start(_L("Test1: Call defrag with an invalid lower priority")); |
|
7517 |
TestStart(); |
|
7518 |
||
7519 |
TInt r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, 0, -2); |
|
7520 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
7521 |
if (r != KErrArgument) |
|
7522 |
{ |
|
7523 |
test.Printf(_L("Fail: r = %d, not expected\n"), r); |
|
7524 |
TEST_FAIL; |
|
7525 |
} |
|
7526 |
else |
|
7527 |
{ |
|
7528 |
test.Printf(_L("Passed...\n")); |
|
7529 |
} |
|
7530 |
||
7531 |
TestEnd(); |
|
7532 |
||
7533 |
test.Next(_L("Test2: Call defrag with an invalid higher priority")); |
|
7534 |
TestStart(); |
|
7535 |
||
7536 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, 0, 100); |
|
7537 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
7538 |
if (r != KErrArgument) |
|
7539 |
{ |
|
7540 |
test.Printf(_L("Fail: r = %d, not expected\n"), r); |
|
7541 |
TEST_FAIL; |
|
7542 |
} |
|
7543 |
else |
|
7544 |
{ |
|
7545 |
test.Printf(_L("Passed...\n")); |
|
7546 |
} |
|
7547 |
TestEnd(); |
|
7548 |
||
7549 |
if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0) == 1) |
|
7550 |
{// Only test priorities on single core system as this test is not smp safe. |
|
7551 |
test.Next(_L("Test3: Call Dfc method of EmptyRamZone to test priorities")); |
|
7552 |
TestStart(); |
|
7553 |
||
7554 |
||
7555 |
TRequestStatus req; |
|
7556 |
TRequestStatus req2; |
|
7557 |
TRequestStatus req3; |
|
7558 |
TInt expectedOrder = 132; // Priorities set in Device driver |
|
7559 |
||
7560 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
7561 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
7562 |
||
7563 |
TUint index = (gZoneCount + 1) / 2; |
|
7564 |
TUint defragZoneID = gZoneConfigArray[index].iZoneId; |
|
7565 |
||
7566 |
r = Ldd.CheckPriorities(DEFRAG_TYPE_EMPTY, defragZoneID, &req, &req2, &req3); |
|
7567 |
||
7568 |
User::WaitForRequest(req); |
|
7569 |
User::WaitForRequest(req2); |
|
7570 |
User::WaitForRequest(req3); |
|
7571 |
||
7572 |
TInt order = Ldd.GetDefragOrder(); |
|
7573 |
if (order != expectedOrder) |
|
7574 |
{ |
|
7575 |
test.Printf(_L("Fail: order = %d. expected = %d\n"), order, expectedOrder); |
|
7576 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7577 |
TEST_FAIL; |
|
7578 |
} |
|
7579 |
else |
|
7580 |
{ |
|
7581 |
test.Printf(_L("Passed...\n")); |
|
7582 |
} |
|
7583 |
// This will free any allocated memory |
|
7584 |
TestEnd(); |
|
7585 |
} |
|
7586 |
||
7587 |
test.End(); |
|
7588 |
return KErrNone; |
|
7589 |
} |
|
7590 |
||
7591 |
||
7592 |
// |
|
7593 |
// TestFlags |
|
7594 |
// |
|
7595 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7596 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0541 |
|
7597 |
//! @SYMTestType CIT |
|
7598 |
//! @SYMTestCaseDesc Verifying that when certain flags are set, |
|
7599 |
//! only certain types of pages can be allocated to the zone. |
|
7600 |
//! @SYMPREQ PREQ308 |
|
7601 |
//! @SYMTestPriority High |
|
7602 |
//! @SYMTestActions |
|
7603 |
//! 1. Set the NoFixed flag in a zone and allocate movable pages |
|
7604 |
//! 2. Set the NoFixed flag in a zone and allocate fixed pages |
|
7605 |
//! 3. Set the NoFixed flag in a zone and allocate discardable pages |
|
7606 |
//! 4. Set the NoFixed flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() |
|
7607 |
//! 5. Set the NoFixed flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() |
|
7608 |
//! 6. Set the NoMovable flag in a zone and allocate movable pages |
|
7609 |
//! 7. Set the NoMovable flag in a zone and allocate fixed pages |
|
7610 |
//! 8. Set the NoMovable flag in a zone and allocate discardable pages |
|
7611 |
//! 9. Set the NoDiscardable flag in a zone and allocate movable pages |
|
7612 |
//! 10. Set the NoDiscardable flag in a zone and allocate fixed pages |
|
7613 |
//! 11. Set the NoDiscardable flag in a zone and allocate discardable pages |
|
7614 |
//! 12. Set the OnlyDiscardable flag in a zone and allocate movable pages |
|
7615 |
//! 13. Set the OnlyDiscardable flag in a zone and allocate fixed pages |
|
7616 |
//! 14. Set the OnlyDiscardable flag in a zone and allocate discardable pages |
|
7617 |
//! 15. Set the OnlyDiscardable flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() |
|
7618 |
//! 16. Set the OnlyDiscardable flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() |
|
7619 |
//! 17. Set the NoFurtherAlloc flag in a zone and allocate movable pages |
|
7620 |
//! 18. Set the NoFurtherAlloc flag in a zone and allocate fixed pages |
|
7621 |
//! 19. Set the NoFurtherAlloc flag in a zone and allocate discardable pages |
|
7622 |
//! 20. Set the NoFurtherAlloc flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() |
|
7623 |
//! 21. Set the NoFurtherAlloc flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() |
|
7624 |
//! 22. Set up memory so that the least preferable RAM zone has movable pages + discardable pages > free pages in the most |
|
7625 |
//! preferable zone. Ensure that the discardable pages cannot be discarded and so must be moved. Now set the flag on |
|
7626 |
//! all zones barring the most preferable zone to KRamZoneFlagNoMovable, ensuring that most pref has no flags set. |
|
7627 |
//! Following this call a general defrag. |
|
7628 |
//! 23. Set up memory so that the least preferable RAM zone has movable pages + discardable pages > free pages in the most |
|
7629 |
//! preferable RAM zone. Ensure that the discardable pages cannot be discarded and so must be moved. |
|
7630 |
//! Now set the flag on all zones barring the most preferable zone to KRamZoneFlagNoDiscard, ensuring that |
|
7631 |
//! most preferable RAM zone has no flags set. Following this call a general defrag. |
|
7632 |
//! 24. Set up memory so that the least preferable RAM zone has movable pages and discardable pages. Set all the zone |
|
7633 |
//! flags to KRamZoneFlagNoMovable. Following this call a general defrag. |
|
7634 |
//! |
|
7635 |
//! @SYMTestExpectedResults |
|
7636 |
//! 1. Movable pages are allocated and no fixed pages allocated |
|
7637 |
//! 2. No fixed pages have been allocated |
|
7638 |
//! 3. Discardable pages are allocated and no fixed pages allocated |
|
7639 |
//! 4. KErrNone, flag is ignored with zone specific allocation |
|
7640 |
//! 5. KErrNone, flag is ignored when claiming a zone |
|
7641 |
//! 6. No movable pages have been allocated |
|
7642 |
//! 7. Fixed pages allocated, no movable allocated |
|
7643 |
//! 8. Discardable pages allocated, no movable pages allocated |
|
7644 |
//! 9. Movable pages allocated, no discardable pages allocated |
|
7645 |
//! 10. Fixed pages allocated, no discardable allocated |
|
7646 |
//! 11. No discardable pages allocated |
|
7647 |
//! 12. No movable pages allocated |
|
7648 |
//! 13. No fixed pages allocated |
|
7649 |
//! 14. Discardable pages allocated, no movable or fixed allocated |
|
7650 |
//! 15. KErrNone, flag is ignored with zone specific allocation |
|
7651 |
//! 16. KErrNone, flag is ignored when claiming a zone |
|
7652 |
//! 17. No moving, fixed or discardable pages allocated |
|
7653 |
//! 18. No moving, fixed or discardable pages allocated |
|
7654 |
//! 19. No moving, fixed or discardable pages allocated |
|
7655 |
//! 20. KErrNoMemory, flag is obeyed with zone specific allocation |
|
7656 |
//! 21. KErrNone, flag is ignored when claiming a zone |
|
7657 |
//! 22. Movable pages moved to the most preferable zone, discardable pages moved to next most preferable zone |
|
7658 |
//! 23. Discardable pages moved to most preferable zone, movable pages moved to next next most preferable zone |
|
7659 |
//! 24. No pages are moved from the least preferable zone zone |
|
7660 |
//--------------------------------------------------------------------------------------------------------------------- |
|
7661 |
TInt TestFlags() |
|
7662 |
{ |
|
7663 |
TInt r = 0; |
|
7664 |
TUint zoneDefragID = 0; |
|
7665 |
||
7666 |
test.Start(_L("Test1: No Fixed Flag, Alloc Movable")); |
|
7667 |
TestStart(); |
|
7668 |
||
7669 |
TInt index = GetBestZone(BEST_MOVABLE); |
|
7670 |
||
7671 |
if (index == KErrNotFound) |
|
7672 |
{ |
|
7673 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7674 |
} |
|
7675 |
else |
|
7676 |
{ |
|
7677 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7678 |
if (SpaceAvailForPageTables(index, KFillAllMovable)) |
|
7679 |
{ |
|
7680 |
GetOriginalPageCount(); |
|
7681 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
7682 |
test_KErrNone(r); |
|
7683 |
||
7684 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); |
|
7685 |
GetAllPageInfo(); |
|
7686 |
if (gZoneUtilArray[index].iAllocMovable == gOriginalPageCountArray[index].iAllocMovable || |
|
7687 |
gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
7688 |
{ |
|
7689 |
test.Printf(_L("Fail: Either fixed pages have been allocated or movable pages have not been allocated to zone ID %x\n"), gZoneConfigArray[index].iZoneId); |
|
7690 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7691 |
TEST_FAIL; |
|
7692 |
} |
|
7693 |
else |
|
7694 |
{ |
|
7695 |
test.Printf(_L("Passed...\n")); |
|
7696 |
} |
|
7697 |
} |
|
7698 |
else |
|
7699 |
{ |
|
7700 |
test.Printf(_L("Skipping...\n")); |
|
7701 |
} |
|
7702 |
} |
|
7703 |
TestEnd(); |
|
7704 |
||
7705 |
||
7706 |
test.Next(_L("Test2: No Fixed Flag, Alloc Fixed")); |
|
7707 |
TestStart(); |
|
7708 |
||
7709 |
if(gPagedRom) |
|
7710 |
{ |
|
7711 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
7712 |
test_KErrNone(r); |
|
7713 |
} |
|
7714 |
||
7715 |
// find a zone that has free pages in it to block it |
|
7716 |
GetAllPageInfo(); |
|
7717 |
TUint i = 0; |
|
7718 |
for (; i < gZoneCount; i++) |
|
7719 |
{ |
|
7720 |
if (gZoneUtilArray[i].iFreePages > 0) |
|
7721 |
{ |
|
7722 |
index = i; |
|
7723 |
break; |
|
7724 |
} |
|
7725 |
} |
|
7726 |
||
7727 |
if (i == gZoneCount) |
|
7728 |
{ |
|
7729 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7730 |
} |
|
7731 |
else |
|
7732 |
{ |
|
7733 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7734 |
||
7735 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
7736 |
test_KErrNone(r); |
|
7737 |
||
7738 |
GetOriginalPageCount(); |
|
7739 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
7740 |
||
7741 |
GetAllPageInfo(); |
|
7742 |
// Ensure that either zone does not contain extra fixed pages |
|
7743 |
if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
7744 |
{ |
|
7745 |
test.Printf(_L("Fail: Fixed pages have been allocated into the zone ID 0x%x r = %d\n"), zoneDefragID, r); |
|
7746 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
7747 |
TEST_FAIL; |
|
7748 |
} |
|
7749 |
else |
|
7750 |
{ |
|
7751 |
test.Printf(_L("Passed...\n")); |
|
7752 |
} |
|
7753 |
} |
|
7754 |
TestEnd(); |
|
7755 |
||
7756 |
||
7757 |
test.Next(_L("Test3: No Fixed Flag, Alloc Discardable")); |
|
7758 |
TestStart(); |
|
7759 |
if (gPagedRom) |
|
7760 |
{ |
|
7761 |
index = GetBestZone(BEST_DISCARDABLE); |
|
7762 |
||
7763 |
if (index == KErrNotFound) |
|
7764 |
{ |
|
7765 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7766 |
} |
|
7767 |
else |
|
7768 |
{ |
|
7769 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7770 |
GetOriginalPageCount(); |
|
7771 |
||
7772 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
7773 |
test_KErrNone(r); |
|
7774 |
||
7775 |
UpdateRamInfo(); |
|
7776 |
TInt discardablePages; |
|
7777 |
r = AllocDiscardable(discardablePages); |
|
7778 |
if (r != KErrNone) |
|
7779 |
{ |
|
7780 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
7781 |
TEST_FAIL; |
|
7782 |
} |
|
7783 |
||
7784 |
GetAllPageInfo(); |
|
7785 |
if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
7786 |
{ |
|
7787 |
test.Printf(_L("Fail: Fixed pages have been allocated\n")); |
|
7788 |
CLEANUP(ResetDPCache()); |
|
7789 |
TEST_FAIL; |
|
7790 |
} |
|
7791 |
else |
|
7792 |
{ |
|
7793 |
test.Printf(_L("Passed...\n")); |
|
7794 |
} |
|
7795 |
} |
|
7796 |
} |
|
7797 |
else |
|
7798 |
{ |
|
7799 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
7800 |
} |
|
7801 |
TestEnd(); |
|
7802 |
||
7803 |
test.Next(_L("Test4: No Fixed Flag, Alloc Fixed using ZoneAllocPhyicalRam")); |
|
7804 |
TestStart(); |
|
7805 |
||
7806 |
index = GetBestZone(BEST_FIXED); |
|
7807 |
||
7808 |
if (index == KErrNotFound) |
|
7809 |
{ |
|
7810 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7811 |
} |
|
7812 |
else |
|
7813 |
{ |
|
7814 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7815 |
||
7816 |
GetOriginalPageCount(); |
|
7817 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
7818 |
test_KErrNone(r); |
|
7819 |
||
7820 |
// Just need to try and allocate one page |
|
7821 |
r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); |
|
7822 |
||
7823 |
GetAllPageInfo(); |
|
7824 |
if (r != KErrNone) |
|
7825 |
{ |
|
7826 |
test.Printf(_L("Fail: Fixed pages have not been allocated into the zone\n")); |
|
7827 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
7828 |
TEST_FAIL; |
|
7829 |
} |
|
7830 |
else |
|
7831 |
{ |
|
7832 |
test.Printf(_L("Passed...\n")); |
|
7833 |
} |
|
7834 |
} |
|
7835 |
TestEnd(); |
|
7836 |
||
7837 |
test.Next(_L("Test5: No Fixed Flag, Alloc Fixed by attempting to claim zone")); |
|
7838 |
TestStart(); |
|
7839 |
||
7840 |
GetAllPageInfo(); |
|
7841 |
index = 0; |
|
7842 |
while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
7843 |
{ |
|
7844 |
index++; |
|
7845 |
} |
|
7846 |
||
7847 |
if ((TUint)index == gZoneCount) |
|
7848 |
{ |
|
7849 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7850 |
} |
|
7851 |
else |
|
7852 |
{ |
|
7853 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7854 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); |
|
7855 |
test_KErrNone(r); |
|
7856 |
||
7857 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); |
|
7858 |
GetAllPageInfo(); |
|
7859 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
7860 |
if (freeInOthers && r != KErrNone) |
|
7861 |
{ |
|
7862 |
test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); |
|
7863 |
TEST_FAIL; |
|
7864 |
} |
|
7865 |
else |
|
7866 |
{ |
|
7867 |
test.Printf(_L("Passed...\n")); |
|
7868 |
} |
|
7869 |
} |
|
7870 |
TestEnd(); |
|
7871 |
||
7872 |
||
7873 |
||
7874 |
//------------------------------------------------------------ |
|
7875 |
test.Next(_L("Test6: No Movable Flag, Alloc Movable")); |
|
7876 |
TestStart(); |
|
7877 |
||
7878 |
index = GetBestZone(BEST_MOVABLE); |
|
7879 |
||
7880 |
if (index == KErrNotFound) |
|
7881 |
{ |
|
7882 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7883 |
} |
|
7884 |
else |
|
7885 |
{ |
|
7886 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7887 |
||
7888 |
GetOriginalPageCount(); |
|
7889 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); |
|
7890 |
test_KErrNone(r); |
|
7891 |
||
7892 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); |
|
7893 |
||
7894 |
GetAllPageInfo(); |
|
7895 |
if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) |
|
7896 |
{ |
|
7897 |
test.Printf(_L("Fail: Movable pages have been allocated in the zone\n")); |
|
7898 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
7899 |
TEST_FAIL; |
|
7900 |
} |
|
7901 |
else |
|
7902 |
{ |
|
7903 |
test.Printf(_L("Passed...\n")); |
|
7904 |
} |
|
7905 |
} |
|
7906 |
TestEnd(); |
|
7907 |
||
7908 |
||
7909 |
test.Next(_L("Test7: No Movable Flag, Alloc Fixed")); |
|
7910 |
TestStart(); |
|
7911 |
||
7912 |
if(gPagedRom) |
|
7913 |
{ |
|
7914 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
7915 |
test_KErrNone(r); |
|
7916 |
} |
|
7917 |
||
7918 |
index = GetBestZone(BEST_FIXED); |
|
7919 |
||
7920 |
if (index == KErrNotFound) |
|
7921 |
{ |
|
7922 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7923 |
} |
|
7924 |
else |
|
7925 |
{ |
|
7926 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7927 |
||
7928 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); |
|
7929 |
test_KErrNone(r); |
|
7930 |
||
7931 |
GetOriginalPageCount(); |
|
7932 |
// Fill up all of RAM with fixed pages. |
|
7933 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
7934 |
test.Printf(_L("r = %d\n"), r); |
|
7935 |
||
7936 |
GetAllPageInfo(); |
|
7937 |
if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || |
|
7938 |
gZoneUtilArray[index].iAllocFixed <= gOriginalPageCountArray[index].iAllocFixed) |
|
7939 |
{ |
|
7940 |
test.Printf(_L("Fail: orig mov 0x%x fix 0x%x current mov 0x%x fix 0x%x\n"), gOriginalPageCountArray[index].iAllocMovable, |
|
7941 |
gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocFixed); |
|
7942 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
7943 |
TEST_FAIL; |
|
7944 |
} |
|
7945 |
else |
|
7946 |
{ |
|
7947 |
test.Printf(_L("Passed...\n")); |
|
7948 |
} |
|
7949 |
} |
|
7950 |
TestEnd(); |
|
7951 |
||
7952 |
||
7953 |
test.Next(_L("Test8: No Movable Flag, Alloc Discardable")); |
|
7954 |
TestStart(); |
|
7955 |
if (gPagedRom) |
|
7956 |
{ |
|
7957 |
index = GetBestZone(BEST_DISCARDABLE); |
|
7958 |
||
7959 |
if (index == KErrNotFound) |
|
7960 |
{ |
|
7961 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
7962 |
} |
|
7963 |
else |
|
7964 |
{ |
|
7965 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
7966 |
||
7967 |
GetOriginalPageCount(); |
|
7968 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); |
|
7969 |
test_KErrNone(r) |
|
7970 |
UpdateRamInfo(); |
|
7971 |
TInt discardablePages; |
|
7972 |
r = AllocDiscardable(discardablePages); |
|
7973 |
if (r != KErrNone) |
|
7974 |
{ |
|
7975 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
7976 |
TEST_FAIL; |
|
7977 |
} |
|
7978 |
||
7979 |
GetAllPageInfo(); |
|
7980 |
if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) |
|
7981 |
{ |
|
7982 |
test.Printf(_L("Fail: Movable pages have been allocated into the zone \n")); |
|
7983 |
CLEANUP(ResetDPCache()); |
|
7984 |
TEST_FAIL; |
|
7985 |
} |
|
7986 |
else |
|
7987 |
{ |
|
7988 |
test.Printf(_L("Passed...\n")); |
|
7989 |
} |
|
7990 |
} |
|
7991 |
} |
|
7992 |
else |
|
7993 |
{ |
|
7994 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
7995 |
} |
|
7996 |
TestEnd(); |
|
7997 |
||
7998 |
//----------------------------------------------------------------------------------------------- |
|
7999 |
||
8000 |
test.Next(_L("Test9: No Discardable Flag, Alloc Movable")); |
|
8001 |
TestStart(); |
|
8002 |
||
8003 |
index = GetBestZone(BEST_MOVABLE); |
|
8004 |
||
8005 |
if (index == KErrNotFound) |
|
8006 |
{ |
|
8007 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8008 |
} |
|
8009 |
else |
|
8010 |
{ |
|
8011 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8012 |
||
8013 |
GetOriginalPageCount(); |
|
8014 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); |
|
8015 |
test_KErrNone(r); |
|
8016 |
||
8017 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); |
|
8018 |
GetAllPageInfo(); |
|
8019 |
||
8020 |
if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || |
|
8021 |
(gZoneUtilArray[index].iAllocMovable <= gOriginalPageCountArray[index].iAllocMovable && |
|
8022 |
gZoneUtilArray[index].iAllocFixed == gOriginalPageCountArray[index].iAllocFixed)) |
|
8023 |
{ |
|
8024 |
test.Printf(_L("Fail: Either discardable pages have been allocated or movable pages have not been allocated\n")); |
|
8025 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
8026 |
TEST_FAIL; |
|
8027 |
} |
|
8028 |
else |
|
8029 |
{ |
|
8030 |
test.Printf(_L("Passed...\n")); |
|
8031 |
} |
|
8032 |
} |
|
8033 |
TestEnd(); |
|
8034 |
||
8035 |
||
8036 |
test.Next(_L("Test10: No Discardable Flag, Alloc Fixed")); |
|
8037 |
TestStart(); |
|
8038 |
||
8039 |
if(gPagedRom) |
|
8040 |
{ |
|
8041 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
8042 |
test_KErrNone(r); |
|
8043 |
} |
|
8044 |
||
8045 |
index = GetBestZone(BEST_FIXED); |
|
8046 |
||
8047 |
if (index == KErrNotFound) |
|
8048 |
{ |
|
8049 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8050 |
} |
|
8051 |
else |
|
8052 |
{ |
|
8053 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8054 |
||
8055 |
GetOriginalPageCount(); |
|
8056 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); |
|
8057 |
test_KErrNone(r); |
|
8058 |
// Fill up all of RAM with fixed pages. |
|
8059 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
8060 |
||
8061 |
GetAllPageInfo(); |
|
8062 |
if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || |
|
8063 |
gZoneUtilArray[index].iAllocFixed <= gOriginalPageCountArray[index].iAllocFixed) |
|
8064 |
{ |
|
8065 |
test.Printf(_L("Fail: Discardable pages have been allocated or fixed pages have not been allocated\n")); |
|
8066 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8067 |
TEST_FAIL; |
|
8068 |
} |
|
8069 |
else |
|
8070 |
{ |
|
8071 |
test.Printf(_L("Passed...\n")); |
|
8072 |
} |
|
8073 |
} |
|
8074 |
TestEnd(); |
|
8075 |
||
8076 |
||
8077 |
test.Next(_L("Test11: No Discardable Flag, Alloc Discardable")); |
|
8078 |
TestStart(); |
|
8079 |
if (gPagedRom) |
|
8080 |
{ |
|
8081 |
index = GetBestZone(BEST_DISCARDABLE); |
|
8082 |
||
8083 |
if (index == KErrNotFound) |
|
8084 |
{ |
|
8085 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8086 |
} |
|
8087 |
else |
|
8088 |
{ |
|
8089 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8090 |
GetOriginalPageCount(); |
|
8091 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); |
|
8092 |
test_KErrNone(r); |
|
8093 |
UpdateRamInfo(); |
|
8094 |
||
8095 |
TInt discardablePages; |
|
8096 |
r = AllocDiscardable(discardablePages); |
|
8097 |
if (r != KErrNoMemory) |
|
8098 |
{// Allocation should fail as no dis flag is set |
|
8099 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
8100 |
TEST_FAIL; |
|
8101 |
} |
|
8102 |
GetAllPageInfo(); |
|
8103 |
||
8104 |
if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable) |
|
8105 |
{ |
|
8106 |
test.Printf(_L("Fail: Discardable pages have been allocated into the zone\n")); |
|
8107 |
CLEANUP(ResetDPCache()); |
|
8108 |
TEST_FAIL; |
|
8109 |
} |
|
8110 |
else |
|
8111 |
{ |
|
8112 |
test.Printf(_L("Passed...\n")); |
|
8113 |
} |
|
8114 |
} |
|
8115 |
} |
|
8116 |
else |
|
8117 |
{ |
|
8118 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
8119 |
} |
|
8120 |
TestEnd(); |
|
8121 |
||
8122 |
//----------------------------------------------------------------------------------------------- |
|
8123 |
||
8124 |
test.Next(_L("Test12: Only Discardable Flag, Alloc Movable")); |
|
8125 |
TestStart(); |
|
8126 |
||
8127 |
index = GetBestZone(BEST_MOVABLE); |
|
8128 |
||
8129 |
if (index == KErrNotFound) |
|
8130 |
{ |
|
8131 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8132 |
} |
|
8133 |
else |
|
8134 |
{ |
|
8135 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8136 |
||
8137 |
GetOriginalPageCount(); |
|
8138 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
8139 |
test_KErrNone(r); |
|
8140 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); |
|
8141 |
GetAllPageInfo(); |
|
8142 |
||
8143 |
if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) |
|
8144 |
{ |
|
8145 |
test.Printf(_L("Fail: Movable pages have been allocated\n")); |
|
8146 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
8147 |
TEST_FAIL; |
|
8148 |
} |
|
8149 |
else |
|
8150 |
{ |
|
8151 |
test.Printf(_L("Passed...\n")); |
|
8152 |
} |
|
8153 |
} |
|
8154 |
TestEnd(); |
|
8155 |
||
8156 |
||
8157 |
test.Next(_L("Test13: Only Discardable Flag, Alloc Fixed")); |
|
8158 |
TestStart(); |
|
8159 |
||
8160 |
if(gPagedRom) |
|
8161 |
{ |
|
8162 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
8163 |
test_KErrNone(r); |
|
8164 |
} |
|
8165 |
||
8166 |
index = GetBestZone(BEST_FIXED); |
|
8167 |
||
8168 |
if (index == KErrNotFound) |
|
8169 |
{ |
|
8170 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8171 |
} |
|
8172 |
else |
|
8173 |
{ |
|
8174 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8175 |
||
8176 |
GetOriginalPageCount(); |
|
8177 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
8178 |
test_KErrNone(r); |
|
8179 |
||
8180 |
// Fill up all of RAM with fixed pages. |
|
8181 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
8182 |
||
8183 |
GetAllPageInfo(); |
|
8184 |
if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
8185 |
{ |
|
8186 |
test.Printf(_L("Fail: Fixed pages have been allocated\n")); |
|
8187 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8188 |
TEST_FAIL; |
|
8189 |
} |
|
8190 |
else |
|
8191 |
{ |
|
8192 |
test.Printf(_L("Passed...\n")); |
|
8193 |
} |
|
8194 |
} |
|
8195 |
TestEnd(); |
|
8196 |
||
8197 |
||
8198 |
test.Next(_L("Test14: Only Discardable Flag, Alloc Discardable")); |
|
8199 |
TestStart(); |
|
8200 |
if (gPagedRom) |
|
8201 |
{ |
|
8202 |
index = GetBestZone(BEST_DISCARDABLE); |
|
8203 |
||
8204 |
if (index == KErrNotFound) |
|
8205 |
{ |
|
8206 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8207 |
} |
|
8208 |
else |
|
8209 |
{ |
|
8210 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8211 |
||
8212 |
GetOriginalPageCount(); |
|
8213 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
8214 |
test_KErrNone(r); |
|
8215 |
UpdateRamInfo(); |
|
8216 |
||
8217 |
TInt discardablePages; |
|
8218 |
r = AllocDiscardable(discardablePages); |
|
8219 |
if (r != KErrNone) |
|
8220 |
{ |
|
8221 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
8222 |
TEST_FAIL; |
|
8223 |
} |
|
8224 |
GetAllPageInfo(); |
|
8225 |
||
8226 |
if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || |
|
8227 |
gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
8228 |
{ |
|
8229 |
test.Printf(_L("Fail: Pages other than discardable have been allocated\n")); |
|
8230 |
CLEANUP(ResetDPCache()); |
|
8231 |
TEST_FAIL; |
|
8232 |
} |
|
8233 |
else |
|
8234 |
{ |
|
8235 |
test.Printf(_L("Passed...\n")); |
|
8236 |
} |
|
8237 |
} |
|
8238 |
} |
|
8239 |
else |
|
8240 |
{ |
|
8241 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
8242 |
} |
|
8243 |
TestEnd(); |
|
8244 |
||
8245 |
test.Next(_L("Test15: Only Discardable Flag, Alloc Fixed using ZoneAllocPhyicalRam")); |
|
8246 |
TestStart(); |
|
8247 |
||
8248 |
index = GetBestZone(BEST_FIXED); |
|
8249 |
||
8250 |
if (index == KErrNotFound) |
|
8251 |
{ |
|
8252 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8253 |
} |
|
8254 |
else |
|
8255 |
{ |
|
8256 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8257 |
||
8258 |
GetOriginalPageCount(); |
|
8259 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
8260 |
test_KErrNone(r); |
|
8261 |
||
8262 |
// Just need to try and allocate one page |
|
8263 |
r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); |
|
8264 |
||
8265 |
GetAllPageInfo(); |
|
8266 |
if (r != KErrNone) |
|
8267 |
{ |
|
8268 |
test.Printf(_L("Fail: Fixed pages have not been allocated into zone ID 0x%x\n"), zoneDefragID); |
|
8269 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8270 |
TEST_FAIL; |
|
8271 |
} |
|
8272 |
else |
|
8273 |
{ |
|
8274 |
test.Printf(_L("Passed...\n")); |
|
8275 |
} |
|
8276 |
} |
|
8277 |
TestEnd(); |
|
8278 |
||
8279 |
test.Next(_L("Test16: Only Discardable Flag, Alloc Fixed by attempting to claim zone")); |
|
8280 |
TestStart(); |
|
8281 |
||
8282 |
GetAllPageInfo(); |
|
8283 |
index = 0; |
|
8284 |
while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
8285 |
{ |
|
8286 |
index++; |
|
8287 |
} |
|
8288 |
||
8289 |
if ((TUint)index == gZoneCount) |
|
8290 |
{ |
|
8291 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8292 |
} |
|
8293 |
else |
|
8294 |
{ |
|
8295 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8296 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); |
|
8297 |
test_KErrNone(r); |
|
8298 |
||
8299 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); |
|
8300 |
GetAllPageInfo(); |
|
8301 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
8302 |
if (freeInOthers && r != KErrNone) |
|
8303 |
{ |
|
8304 |
test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); |
|
8305 |
TEST_FAIL; |
|
8306 |
} |
|
8307 |
else |
|
8308 |
{ |
|
8309 |
test.Printf(_L("Passed...\n")); |
|
8310 |
} |
|
8311 |
} |
|
8312 |
TestEnd(); |
|
8313 |
//----------------------------------------------------------------------------------------------- |
|
8314 |
||
8315 |
test.Next(_L("Test17: No further alloc Flag, Alloc Movable")); |
|
8316 |
TestStart(); |
|
8317 |
||
8318 |
index = GetBestZone(BEST_MOVABLE); |
|
8319 |
||
8320 |
||
8321 |
if (index == KErrNotFound) |
|
8322 |
{ |
|
8323 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8324 |
} |
|
8325 |
else |
|
8326 |
{ |
|
8327 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8328 |
||
8329 |
GetOriginalPageCount(); |
|
8330 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); |
|
8331 |
test_KErrNone(r); |
|
8332 |
AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); |
|
8333 |
GetAllPageInfo(); |
|
8334 |
||
8335 |
if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || |
|
8336 |
gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || |
|
8337 |
gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
8338 |
{ |
|
8339 |
test.Printf(_L("Fail: Pages been allocated\n")); |
|
8340 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
8341 |
TEST_FAIL; |
|
8342 |
} |
|
8343 |
else |
|
8344 |
{ |
|
8345 |
test.Printf(_L("Passed...\n")); |
|
8346 |
} |
|
8347 |
} |
|
8348 |
TestEnd(); |
|
8349 |
||
8350 |
||
8351 |
test.Next(_L("Test18: No further alloc Flag, Alloc Fixed")); |
|
8352 |
TestStart(); |
|
8353 |
||
8354 |
if(gPagedRom) |
|
8355 |
{ |
|
8356 |
r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); |
|
8357 |
test_KErrNone(r); |
|
8358 |
} |
|
8359 |
||
8360 |
// Find a zone with free pages and set the flag on this zone |
|
8361 |
// as it will ensure that you cannot fill all of free RAM with fixed pages |
|
8362 |
index = KErrNotFound; |
|
8363 |
GetAllPageInfo(); |
|
8364 |
for (TUint i = 0; i < gZoneCount; i++) |
|
8365 |
{ |
|
8366 |
if (gZoneUtilArray[i].iFreePages != 0) |
|
8367 |
{ |
|
8368 |
index = i; |
|
8369 |
break; |
|
8370 |
} |
|
8371 |
} |
|
8372 |
if (index == KErrNotFound) |
|
8373 |
{ |
|
8374 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8375 |
} |
|
8376 |
else |
|
8377 |
{ |
|
8378 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8379 |
||
8380 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); |
|
8381 |
test_KErrNone(r); |
|
8382 |
||
8383 |
GetOriginalPageCount(); |
|
8384 |
r = Ldd.AllocateFixed(FILL_ALL_FIXED); |
|
8385 |
||
8386 |
// Ensure memory wasn't filled as it should have hit the blocked zone. |
|
8387 |
GetAllPageInfo(); |
|
8388 |
if (r != KErrNoMemory || gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
8389 |
{ |
|
8390 |
test.Printf(_L("Fail: orig fix 0x%x current fix 0x%x\n"), gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocFixed); |
|
8391 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8392 |
TEST_FAIL; |
|
8393 |
} |
|
8394 |
else |
|
8395 |
{ |
|
8396 |
test.Printf(_L("Passed...\n")); |
|
8397 |
} |
|
8398 |
} |
|
8399 |
TestEnd(); |
|
8400 |
||
8401 |
||
8402 |
test.Next(_L("Test19: No further alloc Flag, Alloc Discardable")); |
|
8403 |
TestStart(); |
|
8404 |
if (gPagedRom) |
|
8405 |
{ |
|
8406 |
index = GetBestZone(BEST_DISCARDABLE); |
|
8407 |
||
8408 |
if (index == KErrNotFound) |
|
8409 |
{ |
|
8410 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8411 |
} |
|
8412 |
else |
|
8413 |
{ |
|
8414 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8415 |
||
8416 |
GetOriginalPageCount(); |
|
8417 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); |
|
8418 |
test_KErrNone(r); |
|
8419 |
UpdateRamInfo(); |
|
8420 |
TInt discardablePages; |
|
8421 |
r = AllocDiscardable(discardablePages); |
|
8422 |
if (r != KErrNoMemory) |
|
8423 |
{// Allocation should fail as no alloc flag is set |
|
8424 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
8425 |
TEST_FAIL; |
|
8426 |
} |
|
8427 |
GetAllPageInfo(); |
|
8428 |
||
8429 |
if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || |
|
8430 |
gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || |
|
8431 |
gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) |
|
8432 |
{ |
|
8433 |
test.Printf(_L("Fail: Pages have been allocated into the zone\n")); |
|
8434 |
CLEANUP(ResetDPCache()); |
|
8435 |
TEST_FAIL; |
|
8436 |
} |
|
8437 |
else |
|
8438 |
{ |
|
8439 |
test.Printf(_L("Passed...\n")); |
|
8440 |
} |
|
8441 |
} |
|
8442 |
} |
|
8443 |
else |
|
8444 |
{ |
|
8445 |
test.Printf(_L("Not a paged ROM - Skipping test step\n")); |
|
8446 |
} |
|
8447 |
TestEnd(); |
|
8448 |
||
8449 |
||
8450 |
test.Next(_L("Test20: No Further Alloc Flag, Alloc Fixed using ZoneAllocPhyicalRam")); |
|
8451 |
TestStart(); |
|
8452 |
||
8453 |
GetAllPageInfo(); |
|
8454 |
index = 0; |
|
8455 |
while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iFreePages == 0 || |
|
8456 |
gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
8457 |
{ |
|
8458 |
index++; |
|
8459 |
} |
|
8460 |
||
8461 |
if ((TUint)index == gZoneCount) |
|
8462 |
{ |
|
8463 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8464 |
} |
|
8465 |
else |
|
8466 |
{ |
|
8467 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8468 |
||
8469 |
GetOriginalPageCount(); |
|
8470 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); |
|
8471 |
test_KErrNone(r); |
|
8472 |
||
8473 |
// Just need to try and allocate one page |
|
8474 |
r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); |
|
8475 |
||
8476 |
GetAllPageInfo(); |
|
8477 |
if (r != KErrNoMemory) |
|
8478 |
{ |
|
8479 |
test.Printf(_L("Fail: Fixed pages have been allocated into zone ID 0x%x\n"), zoneDefragID); |
|
8480 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8481 |
TEST_FAIL; |
|
8482 |
} |
|
8483 |
else |
|
8484 |
{ |
|
8485 |
test.Printf(_L("Passed...\n")); |
|
8486 |
} |
|
8487 |
} |
|
8488 |
TestEnd(); |
|
8489 |
||
8490 |
test.Next(_L("Test21: No Further Alloc Flag, Alloc Fixed by attempting to claim zone")); |
|
8491 |
TestStart(); |
|
8492 |
||
8493 |
GetAllPageInfo(); |
|
8494 |
index = 0; |
|
8495 |
while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) |
|
8496 |
{ |
|
8497 |
index++; |
|
8498 |
} |
|
8499 |
||
8500 |
if ((TUint)index == gZoneCount) |
|
8501 |
{ |
|
8502 |
test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); |
|
8503 |
} |
|
8504 |
else |
|
8505 |
{ |
|
8506 |
zoneDefragID = gZoneConfigArray[index].iZoneId; |
|
8507 |
r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); |
|
8508 |
test_KErrNone(r); |
|
8509 |
||
8510 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); |
|
8511 |
GetAllPageInfo(); |
|
8512 |
TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; |
|
8513 |
if (freeInOthers && r != KErrNone) |
|
8514 |
{ |
|
8515 |
test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); |
|
8516 |
CLEANUP(ResetRamZoneFlags()); |
|
8517 |
TEST_FAIL; |
|
8518 |
} |
|
8519 |
else |
|
8520 |
{ |
|
8521 |
test.Printf(_L("Passed...\n")); |
|
8522 |
} |
|
8523 |
} |
|
8524 |
TestEnd(); |
|
8525 |
||
8526 |
TUint mostPrefArrayIndex = 0; |
|
8527 |
TUint mostPrefIndex = 0; |
|
8528 |
TUint leastPrefIndex = 0; |
|
8529 |
const TUint KFreeMostPref = 10; |
|
8530 |
TUint flag = 0; |
|
8531 |
TUint prefIndex; |
|
8532 |
TUint totalFree; |
|
8533 |
||
8534 |
||
8535 |
for (TUint testStep = 0; testStep < 2; testStep++) |
|
8536 |
{ |
|
8537 |
switch(testStep) |
|
8538 |
{ |
|
8539 |
case 0: |
|
8540 |
test.Next(_L("Test22: Ensure that the General Defrag looks at the flags 1")); |
|
8541 |
break; |
|
8542 |
||
8543 |
case 1: |
|
8544 |
test.Next(_L("Test23: Ensure that the General Defrag looks at the flags 2")); |
|
8545 |
break; |
|
8546 |
} |
|
8547 |
||
8548 |
TestStart(); |
|
8549 |
gChunkArray1 = new RChunk; |
|
8550 |
gChunkArraySize1 = 1; |
|
8551 |
TUint minCacheSize = 0; |
|
8552 |
TUint maxCacheSize = 0; |
|
8553 |
TUint currentCacheSize = 0; |
|
8554 |
TUint freeNeededInMostPref = 0; |
|
8555 |
if (!gPagedRom) |
|
8556 |
{ |
|
8557 |
test.Printf(_L("Not a paged ROM - Skipping...\n")); |
|
8558 |
goto skipTest22; |
|
8559 |
} |
|
8560 |
||
8561 |
// Find the most pref zone with free pages |
|
8562 |
r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); |
|
8563 |
if (r != KErrNone) |
|
8564 |
{ |
|
8565 |
test.Printf(_L("Cannot find zone with free pages - Skipping...\n")); |
|
8566 |
goto skipTest22; |
|
8567 |
} |
|
8568 |
||
8569 |
// Ensure that the least pref zone is empty |
|
8570 |
leastPrefIndex = gPrefArray[gZoneCount - 1]; |
|
8571 |
if (gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) |
|
8572 |
{ |
|
8573 |
test.Printf(_L("Least pref zone is not empty - Skipping...\n")); |
|
8574 |
goto skipTest22; |
|
8575 |
} |
|
8576 |
||
8577 |
// Allocate 1 movable page to the least preferable zone |
|
8578 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, leastPrefIndex, 1); |
|
8579 |
if (r != KErrNone) |
|
8580 |
{ |
|
8581 |
test.Printf(_L("Failed to allocate movable r = %d - Skipping...\n"), r); |
|
8582 |
goto skipTest22; |
|
8583 |
} |
|
8584 |
||
8585 |
// Allocate 1 discardable page to the least preferable zone |
|
8586 |
if (gZoneUtilArray[leastPrefIndex].iFreePages != 0) |
|
8587 |
{ |
|
8588 |
TInt disPages; |
|
8589 |
r = ZoneAllocDiscard(leastPrefIndex, 1, disPages); |
|
8590 |
if (r != KErrNone) |
|
8591 |
{ |
|
8592 |
test.Printf(_L("Failed to allocate discardable pages r = %d - Skipping...\n"), r); |
|
8593 |
goto skipTest22; |
|
8594 |
} |
|
8595 |
||
8596 |
// up the minimum cache size so that the pages have to be moved - not discarded |
|
8597 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
8598 |
r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); |
|
8599 |
if (r != KErrNone) |
|
8600 |
{ |
|
8601 |
test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); |
|
8602 |
goto skipTest22; |
|
8603 |
} |
|
8604 |
} |
|
8605 |
else |
|
8606 |
{ |
|
8607 |
test.Printf(_L("Least pref zone has no free pages - Skipping...\n")); |
|
8608 |
goto skipTest22; |
|
8609 |
} |
|
8610 |
||
8611 |
// Check that the least pref zone has movable and discardable pages in it |
|
8612 |
GetAllPageInfo(); |
|
8613 |
if (gZoneUtilArray[leastPrefIndex].iAllocMovable == 0 || |
|
8614 |
gZoneUtilArray[leastPrefIndex].iAllocDiscardable == 0) |
|
8615 |
{ |
|
8616 |
test.Printf(_L("No movable or discardable in least pref zone\n")); |
|
8617 |
PrintPageInfo(); |
|
8618 |
goto skipTest22; |
|
8619 |
} |
|
8620 |
||
8621 |
ResetRamZoneFlags(); |
|
8622 |
// if most pref zone has too many free pages fill up with fixed |
|
8623 |
if (gZoneUtilArray[mostPrefIndex].iFreePages > KFreeMostPref) |
|
8624 |
{ |
|
8625 |
TUint allocPages = gZoneUtilArray[mostPrefIndex].iFreePages - KFreeMostPref; |
|
8626 |
r = Ldd.ZoneAllocToMany(mostPrefIndex, allocPages); |
|
8627 |
if (r != KErrNone) |
|
8628 |
{ |
|
8629 |
test.Printf(_L("Failed allocate 0x%x fixed to index %d r = %d - Skipping...\n"), |
|
8630 |
allocPages, mostPrefIndex,r); |
|
8631 |
PrintPageInfo(); |
|
8632 |
goto skipTest22; |
|
8633 |
} |
|
8634 |
} |
|
8635 |
||
8636 |
||
8637 |
// if the no. of discardable pages is less than free in most pref increase the min cache size |
|
8638 |
GetAllPageInfo(); |
|
8639 |
if (gZoneUtilArray[leastPrefIndex].iAllocDiscardable < gZoneUtilArray[mostPrefIndex].iFreePages) |
|
8640 |
{ |
|
8641 |
TUint discDiff = gZoneUtilArray[mostPrefIndex].iFreePages - gZoneUtilArray[leastPrefIndex].iAllocDiscardable; |
|
8642 |
test.Printf(_L("discDiff = 0x%x\n"), discDiff); |
|
8643 |
TInt disPages; |
|
8644 |
if (ZoneAllocDiscard(leastPrefIndex, discDiff, disPages) != KErrNone) |
|
8645 |
{ |
|
8646 |
test.Printf(_L("Failed allocate discardable to zone index %d- Skipping...\n"), leastPrefIndex); |
|
8647 |
goto skipTest22; |
|
8648 |
} |
|
8649 |
// up the minimum cache size by the difference as we don't want these pages to be discarded |
|
8650 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
8651 |
r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); |
|
8652 |
test.Printf(_L("r = %d\n"), r); |
|
8653 |
if (r != KErrNone) |
|
8654 |
{ |
|
8655 |
test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); |
|
8656 |
goto skipTest22; |
|
8657 |
} |
|
8658 |
} |
|
8659 |
ResetRamZoneFlags(); |
|
8660 |
||
8661 |
// if the rest of the zones are either full or empty put a fixed page into the next most pref empty zone |
|
8662 |
GetPrefOrder(); |
|
8663 |
prefIndex = 0; |
|
8664 |
totalFree = 0; |
|
8665 |
for (; prefIndex < gZoneCount && totalFree < gZoneUtilArray[leastPrefIndex].iAllocDiscardable; prefIndex++) |
|
8666 |
{// Look for zone that has enough free pages to fit all the discardable |
|
8667 |
TUint zoneIndex = gPrefArray[prefIndex]; |
|
8668 |
if (zoneIndex != mostPrefIndex && zoneIndex != leastPrefIndex) |
|
8669 |
{ |
|
8670 |
if (gZoneUtilArray[zoneIndex].iFreePages != gZoneUtilArray[zoneIndex].iPhysPages) |
|
8671 |
{ |
|
8672 |
totalFree += gZoneUtilArray[zoneIndex].iFreePages; |
|
8673 |
} |
|
8674 |
else |
|
8675 |
{ |
|
8676 |
r = Ldd.ZoneAllocToMany(zoneIndex, 1); |
|
8677 |
if (r != KErrNone) |
|
8678 |
{ |
|
8679 |
test.Printf(_L("Couldn't alloc fixed to zone index %d - r = %d\n"), zoneIndex, r); |
|
8680 |
goto skipTest22; |
|
8681 |
} |
|
8682 |
GetAllPageInfo(); |
|
8683 |
totalFree += gZoneUtilArray[zoneIndex].iFreePages; |
|
8684 |
} |
|
8685 |
} |
|
8686 |
} |
|
8687 |
||
8688 |
if (prefIndex >= gZoneCount) |
|
8689 |
{ |
|
8690 |
test.Printf(_L("Couldn't find zone\n")); |
|
8691 |
goto skipTest22; |
|
8692 |
} |
|
8693 |
||
8694 |
||
8695 |
||
8696 |
// If the most preferable zone does not have enough free pages, skip |
|
8697 |
freeNeededInMostPref = (testStep == 0) ? gZoneUtilArray[leastPrefIndex].iAllocMovable : gZoneUtilArray[leastPrefIndex].iAllocDiscardable; |
|
8698 |
if (gZoneUtilArray[mostPrefIndex].iFreePages < freeNeededInMostPref) |
|
8699 |
{ |
|
8700 |
test.Printf(_L("Free needed in mostPref(%d) = %d, Free available in mostPref = %d - skipping...\n"), |
|
8701 |
mostPrefIndex,freeNeededInMostPref,gZoneUtilArray[mostPrefIndex].iFreePages); |
|
8702 |
goto skipTest22; |
|
8703 |
} |
|
8704 |
||
8705 |
GetAllPageInfo(); |
|
8706 |
// Set up the RAM zone flags for the test |
|
8707 |
flag = (testStep == 0)? NO_MOVE_FLAG: NO_DISCARD_FLAG; |
|
8708 |
// Set all zones except most pref to KRamZoneFlagNoMovable or KRamZoneFlagNoDiscard |
|
8709 |
for (TUint index = 0; index < gZoneCount; index++) |
|
8710 |
{ |
|
8711 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
8712 |
if (index != mostPrefIndex) |
|
8713 |
{ |
|
8714 |
r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, flag); |
|
8715 |
if (r != KErrNone) |
|
8716 |
{ |
|
8717 |
test.Printf(_L("Failed to set flag r = %d - Skipping...\n"), r); |
|
8718 |
goto skipTest22; |
|
8719 |
} |
|
8720 |
} |
|
8721 |
} |
|
8722 |
||
8723 |
GetOriginalPageCount(); |
|
8724 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
8725 |
||
8726 |
GetAllPageInfo(); |
|
8727 |
switch(testStep) |
|
8728 |
{ |
|
8729 |
case 0: |
|
8730 |
if (r != KErrNone || |
|
8731 |
gOriginalPageCountArray[mostPrefIndex].iAllocMovable >= gZoneUtilArray[mostPrefIndex].iAllocMovable || |
|
8732 |
gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) |
|
8733 |
{ |
|
8734 |
test.Printf(_L("FAIL:r=%d MostPref(%d): origMov 0x%x curMov 0x%x LeastPref(%d): origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), |
|
8735 |
r, mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, |
|
8736 |
leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, |
|
8737 |
gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); |
|
8738 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8739 |
TEST_FAIL; |
|
8740 |
} |
|
8741 |
else |
|
8742 |
{ |
|
8743 |
test.Printf(_L("Passed...\n")); |
|
8744 |
} |
|
8745 |
break; |
|
8746 |
||
8747 |
case 1: |
|
8748 |
if (r != KErrNone || |
|
8749 |
gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable >= gZoneUtilArray[mostPrefIndex].iAllocDiscardable || |
|
8750 |
gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) |
|
8751 |
{ |
|
8752 |
test.Printf(_L("FAIL:r=%d MostPref(%d): origMov 0x%x curMov 0x%x LeastPref(%d): origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), |
|
8753 |
r, mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, |
|
8754 |
leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, |
|
8755 |
gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); |
|
8756 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
8757 |
TEST_FAIL; |
|
8758 |
} |
|
8759 |
else |
|
8760 |
{ |
|
8761 |
test.Printf(_L("Passed...\n")); |
|
8762 |
} |
|
8763 |
break; |
|
8764 |
} |
|
8765 |
||
8766 |
skipTest22: |
|
8767 |
TestEnd(); |
|
8768 |
} |
|
8769 |
||
8770 |
test.Next(_L("Test24: Ensure that the General Defrag doesnt move or discard pages if KRamZoneFlagNoMovable set on all zones ")); |
|
8771 |
TestStart(); |
|
8772 |
gChunkArray1 = new RChunk; |
|
8773 |
gChunkArraySize1 = 1; |
|
8774 |
// Find the most pref zone with free pages |
|
8775 |
GetPrefOrder(); |
|
8776 |
TInt disPages = 0; |
|
8777 |
if (FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex) != KErrNone) |
|
8778 |
{ |
|
8779 |
test.Printf(_L("Cannot find zone with free pages - Skipping...\n")); |
|
8780 |
goto skipTest24; |
|
8781 |
} |
|
8782 |
||
8783 |
// Ensure that the least pref zone has free pages in it |
|
8784 |
leastPrefIndex = gPrefArray[gZoneCount-1]; |
|
8785 |
if (gZoneUtilArray[leastPrefIndex].iFreePages == 0) |
|
8786 |
{ |
|
8787 |
test.Printf(_L("Least pref zone has no free pages - Skipping...\n")); |
|
8788 |
goto skipTest24; |
|
8789 |
} |
|
8790 |
||
8791 |
// Allocate 1 movable page to the least preferable zone |
|
8792 |
r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, leastPrefIndex, 1); |
|
8793 |
if (r != KErrNone) |
|
8794 |
{ |
|
8795 |
test.Printf(_L("Failed to allocate movable page r = %d - Skipping...\n"), r); |
|
8796 |
goto skipTest24; |
|
8797 |
} |
|
8798 |
||
8799 |
if (gPagedRom) |
|
8800 |
{ |
|
8801 |
||
8802 |
TUint minCacheSize = 0; |
|
8803 |
TUint maxCacheSize = 0; |
|
8804 |
TUint currentCacheSize = 0; |
|
8805 |
||
8806 |
// Allocate 1 discardable page to the least preferable zone |
|
8807 |
if (gZoneUtilArray[leastPrefIndex].iFreePages != 0) |
|
8808 |
{ |
|
8809 |
r = ZoneAllocDiscard(leastPrefIndex, 1, disPages); |
|
8810 |
if (r != KErrNone) |
|
8811 |
{ |
|
8812 |
test.Printf(_L("Discardable pages not allocated r= %d\n"), r); |
|
8813 |
} |
|
8814 |
||
8815 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
8816 |
r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); |
|
8817 |
if (r != KErrNone) |
|
8818 |
{ |
|
8819 |
test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); |
|
8820 |
goto skipTest24; |
|
8821 |
} |
|
8822 |
} |
|
8823 |
} |
|
8824 |
||
8825 |
||
8826 |
// Check that the least pref zone has movable and discardable (if allocated) pages in it |
|
8827 |
GetAllPageInfo(); |
|
8828 |
if (gZoneUtilArray[leastPrefIndex].iAllocMovable == 0 || |
|
8829 |
gZoneUtilArray[leastPrefIndex].iAllocDiscardable < (TUint)disPages || |
|
8830 |
gZoneUtilArray[leastPrefIndex].iAllocMovable > gTotalPageCount.iFreePages - gZoneUtilArray[leastPrefIndex].iFreePages) |
|
8831 |
{ |
|
8832 |
test.Printf(_L("No movable in least pref zone or no space for moveable pages to be moved to\n")); |
|
8833 |
PrintPageInfo(); |
|
8834 |
goto skipTest24; |
|
8835 |
} |
|
8836 |
||
8837 |
ResetRamZoneFlags(); |
|
8838 |
GetAllPageInfo(); |
|
8839 |
// Now set all zones to KRamZoneFlagNoMovable |
|
8840 |
for (TUint index = 0; index < gZoneCount; index++) |
|
8841 |
{ |
|
8842 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
8843 |
r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); |
|
8844 |
if (r != KErrNone) |
|
8845 |
{ |
|
8846 |
test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); |
|
8847 |
goto skipTest24; |
|
8848 |
} |
|
8849 |
} |
|
8850 |
||
8851 |
GetOriginalPageCount(); |
|
8852 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
8853 |
GetAllPageInfo(); |
|
8854 |
if (r != KErrNone || |
|
8855 |
gOriginalPageCountArray[leastPrefIndex].iAllocMovable != gZoneUtilArray[leastPrefIndex].iAllocMovable || |
|
8856 |
gZoneUtilArray[leastPrefIndex].iAllocDiscardable < gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable) |
|
8857 |
{ |
|
8858 |
test.Printf(_L("FAIL:r=%d LeastPref(%d): origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), |
|
8859 |
r,leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, |
|
8860 |
gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); |
|
8861 |
CLEANUP(ResetRamZoneFlags()); |
|
8862 |
TEST_FAIL; |
|
8863 |
} |
|
8864 |
else |
|
8865 |
{ |
|
8866 |
test.Printf(_L("Passed...\n")); |
|
8867 |
} |
|
8868 |
skipTest24: |
|
8869 |
TestEnd(); |
|
8870 |
||
8871 |
test.End(); |
|
8872 |
return KErrNone; |
|
8873 |
} |
|
8874 |
||
8875 |
||
8876 |
// |
|
8877 |
// Template functions encapsulating ControlIo magic |
|
8878 |
// |
|
8879 |
template <class C> |
|
8880 |
TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c) |
|
8881 |
{ |
|
8882 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C)); |
|
8883 |
||
8884 |
TInt r = fs.ControlIo(drv, fkn, ptrC); |
|
8885 |
||
8886 |
return r; |
|
8887 |
} |
|
8888 |
||
8889 |
// |
|
8890 |
// FormatMMC |
|
8891 |
// |
|
8892 |
// Formats the MMC card |
|
8893 |
// |
|
8894 |
void FormatMMC() |
|
8895 |
{ |
|
8896 |
test.Printf(_L("Formatting MMC...\n")); |
|
8897 |
||
8898 |
RFs theFs; |
|
8899 |
TBuf<4> driveBuf = _L("D:\\"); |
|
8900 |
RFormat format; |
|
8901 |
TInt count; |
|
8902 |
TChar driveLet; |
|
8903 |
||
8904 |
TInt r = theFs.Connect(); |
|
8905 |
test_KErrNone(r); |
|
8906 |
||
8907 |
r = theFs.DriveToChar(gDrive, driveLet); |
|
8908 |
test_KErrNone(r); |
|
8909 |
||
8910 |
driveBuf[0] = driveLet; |
|
8911 |
test.Printf(_L("Formatting Drive: %C\n"),(TInt)driveLet); |
|
8912 |
||
8913 |
r = format.Open(theFs,driveBuf,EFullFormat,count); |
|
8914 |
test_KErrNone(r); |
|
8915 |
||
8916 |
while(count) |
|
8917 |
{ |
|
8918 |
TInt r = format.Next(count); |
|
8919 |
test_KErrNone(r); |
|
8920 |
} |
|
8921 |
format.Close(); |
|
8922 |
theFs.Close(); |
|
8923 |
} |
|
8924 |
||
8925 |
||
8926 |
// |
|
8927 |
// FileNameGen |
|
8928 |
// |
|
8929 |
// Generates file names to create the files |
|
8930 |
// |
|
8931 |
void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos) |
|
8932 |
{ |
|
8933 |
TInt padding; |
|
8934 |
TInt i = 0; |
|
8935 |
TBuf16<10> tempbuf; |
|
8936 |
||
8937 |
_LIT(KNumber,"%d"); |
|
8938 |
tempbuf.Format(KNumber,aPos); |
|
8939 |
||
8940 |
padding = aLong-tempbuf.Size()/2; |
|
8941 |
aBuffer = _L(""); |
|
8942 |
||
8943 |
while(i < padding) |
|
8944 |
{ |
|
8945 |
aBuffer.Append('F'); |
|
8946 |
i++; |
|
8947 |
} |
|
8948 |
aBuffer.Append(tempbuf); |
|
8949 |
||
8950 |
_LIT(KExtension1, ".TXT"); |
|
8951 |
aBuffer.Append(KExtension1); |
|
8952 |
} |
|
8953 |
||
8954 |
||
8955 |
// |
|
8956 |
// CreateFiles |
|
8957 |
// |
|
8958 |
// Creates the files to fill part of the read cache |
|
8959 |
// |
|
8960 |
void CreateFiles(TInt aFiles, TInt aFileSize) |
|
8961 |
{ |
|
8962 |
TInt i = 0, r = 0; |
|
8963 |
RFile file; |
|
8964 |
TBuf16<50> directory; |
|
8965 |
||
8966 |
TBuf16<50> path; |
|
8967 |
TBuf16<50> buffer(50); |
|
8968 |
||
8969 |
directory = gSessionPath; |
|
8970 |
||
8971 |
test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), aFiles, aFileSize); |
|
8972 |
||
8973 |
// create a big buffer to speed things up |
|
8974 |
HBufC8* bigBuf = NULL; |
|
8975 |
const TInt KBigBufferSize = 32 * 1024; |
|
8976 |
TRAPD(res,bigBuf = HBufC8::NewL(KBigBufferSize)); |
|
8977 |
test(res == KErrNone && bigBuf != NULL); |
|
8978 |
||
8979 |
TPtr8 bigBufWritePtr(NULL, 0); |
|
8980 |
bigBufWritePtr.Set(bigBuf->Des()); |
|
8981 |
||
8982 |
// Fill the buffer |
|
8983 |
TChar aC = 'A'; |
|
8984 |
for(i = 0; i < KBigBufferSize; i++) |
|
8985 |
{ |
|
8986 |
bigBufWritePtr.Append((i%32) + aC); |
|
8987 |
} |
|
8988 |
||
8989 |
||
8990 |
i = 0; |
|
8991 |
while(i < aFiles) |
|
8992 |
{ |
|
8993 |
if (i % 10 == 0) |
|
8994 |
test.Printf(_L("Creating file %d of %d...\r"), i, aFiles); |
|
8995 |
FileNameGen(buffer, 8, i+3) ; |
|
8996 |
path = directory; |
|
8997 |
path.Append(buffer); |
|
8998 |
||
8999 |
// delete file first to ensure it's contents are not in the cache (file may be on the closed file queue) |
|
9000 |
r = gTheFs.Delete(path); |
|
9001 |
test(r == KErrNone || r == KErrNotFound); |
|
9002 |
||
9003 |
r = file.Create(gTheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
|
9004 |
if(r == KErrAlreadyExists) |
|
9005 |
r = file.Open(gTheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
|
9006 |
TInt j = 0; |
|
9007 |
i++; |
|
9008 |
while(j < aFileSize) |
|
9009 |
{ |
|
9010 |
bigBufWritePtr.SetLength(Min(KBigBufferSize, aFileSize - j)); |
|
9011 |
r = file.Write(bigBufWritePtr); |
|
9012 |
// Running out of disk space is expected for the last file. |
|
9013 |
// Premature "disk full" conditions need to abort. |
|
9014 |
if (r == KErrDiskFull) |
|
9015 |
{ |
|
9016 |
test(i == aFiles); |
|
9017 |
break; |
|
9018 |
} |
|
9019 |
test_KErrNone(r); |
|
9020 |
j += bigBufWritePtr.Length(); |
|
9021 |
} |
|
9022 |
||
9023 |
file.Close(); |
|
9024 |
} |
|
9025 |
test.Printf(_L("\nFiles created\n")); |
|
9026 |
delete bigBuf; |
|
9027 |
} |
|
9028 |
||
9029 |
||
9030 |
// |
|
9031 |
// FillCache |
|
9032 |
// |
|
9033 |
// Allocate discardable pages using file system caching |
|
9034 |
// |
|
9035 |
TInt FillCache(TInt aFiles, TInt aFileSize) |
|
9036 |
{ |
|
9037 |
// Fail if files already open |
|
9038 |
test(!gFileCacheRun); |
|
9039 |
||
9040 |
||
9041 |
TInt i = 0, r = 0; |
|
9042 |
TBuf16<50> directory; |
|
9043 |
||
9044 |
TBuf16<50> path; |
|
9045 |
TBuf16<50> buffer(50); |
|
9046 |
HBufC8* buf = NULL; |
|
9047 |
TPtr8 bufPtr(NULL, 0); |
|
9048 |
||
9049 |
TRAPD(res,buf = HBufC8::NewL(2)); |
|
9050 |
test(res == KErrNone && buf != NULL); |
|
9051 |
bufPtr.Set(buf->Des()); |
|
9052 |
||
9053 |
TESTDEBUG(test.Printf(_L("Filling the cache\n"))); |
|
9054 |
||
9055 |
directory = gSessionPath; |
|
9056 |
||
9057 |
i = 0; |
|
9058 |
||
9059 |
GetAllPageInfo(); |
|
9060 |
TESTDEBUG(test.Printf(_L("total disc pages = %d\n"), gTotalPageCount.iDiscardablePages)); |
|
9061 |
||
9062 |
||
9063 |
while(i < aFiles) |
|
9064 |
{ |
|
9065 |
FileNameGen(buffer, 8, i+3) ; |
|
9066 |
path = directory; |
|
9067 |
path.Append(buffer); |
|
9068 |
r = gFile[i].Open(gTheFs,path,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
|
9069 |
test_KErrNone(r); |
|
9070 |
||
9071 |
TInt j = 0; |
|
9072 |
while(j < aFileSize) |
|
9073 |
{ |
|
9074 |
r = gFile[i].Read(j,bufPtr); |
|
9075 |
test_KErrNone(r); |
|
9076 |
j += 4 * 1024; |
|
9077 |
} |
|
9078 |
i++; |
|
9079 |
} |
|
9080 |
gFileCacheRun = ETrue; |
|
9081 |
GetAllPageInfo(); |
|
9082 |
TESTDEBUG(test.Printf(_L("after - total disc pages = %d\n"), gTotalPageCount.iDiscardablePages)); |
|
9083 |
delete buf; |
|
9084 |
TESTDEBUG(test.Printf(_L("Cache filled\n"))); |
|
9085 |
||
9086 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
9087 |
// get number of items on Page Cache |
|
9088 |
TFileCacheStats startPageCacheStats; |
|
9089 |
||
9090 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
9091 |
test.Printf(_L("control stats r= %d\n"), r); |
|
9092 |
test(r==KErrNone || r == KErrNotSupported); |
|
9093 |
||
9094 |
TESTDEBUG(test.Printf(_L("Allocated segment count=%d\n"),startPageCacheStats.iAllocatedSegmentCount)); |
|
9095 |
#endif |
|
9096 |
// if we do not have any discardable pages then something went |
|
9097 |
// wrong with file caching |
|
9098 |
if (gTotalPageCount.iDiscardablePages == 0) |
|
9099 |
return KErrNotSupported; |
|
9100 |
||
9101 |
return KErrNone; |
|
9102 |
} |
|
9103 |
||
9104 |
||
9105 |
||
9106 |
// |
|
9107 |
// SetUpMMC |
|
9108 |
// |
|
9109 |
// Sets up the MMC to be used by the test by creating files on the MMC |
|
9110 |
// |
|
9111 |
void SetUpMMC() |
|
9112 |
{ |
|
9113 |
FormatMMC(); |
|
9114 |
||
9115 |
TInt r = 0; |
|
9116 |
||
9117 |
TChar driveToTest; |
|
9118 |
||
9119 |
TVolumeInfo volInfo; |
|
9120 |
||
9121 |
r = gTheFs.DriveToChar(gDrive, driveToTest); |
|
9122 |
test_KErrNone(r); |
|
9123 |
||
9124 |
r = gTheFs.CharToDrive(driveToTest,gDrive); |
|
9125 |
test_KErrNone(r); |
|
9126 |
||
9127 |
gSessionPath = _L("?:\\F32-TST\\"); |
|
9128 |
gSessionPath[0] = (TUint16) driveToTest; |
|
9129 |
test.Printf(_L("Drive Letter=%C\n"),(TInt)driveToTest); |
|
9130 |
||
9131 |
TDriveInfo info; |
|
9132 |
r = gTheFs.Drive(info,gDrive); |
|
9133 |
test_KErrNone(r); |
|
9134 |
r = gTheFs.SetSessionPath(gSessionPath); |
|
9135 |
test_KErrNone(r); |
|
9136 |
r = gTheFs.MkDirAll(gSessionPath); |
|
9137 |
if (r != KErrNone && r != KErrAlreadyExists) |
|
9138 |
{ |
|
9139 |
test_KErrNone(r); |
|
9140 |
} |
|
9141 |
||
9142 |
r = gTheFs.Volume(volInfo, gDrive); |
|
9143 |
test_KErrNone(r); |
|
9144 |
TInt64 gMediaSize = volInfo.iSize; |
|
9145 |
||
9146 |
// This calculation is approximate because the client cannot know |
|
9147 |
// internal allocation mechanisms of the filesystem, i.e. how much |
|
9148 |
// metadata is associated with a file of name X / size Y, whether |
|
9149 |
// space used by such metadata is reflected in TDriveInfo::iSize and |
|
9150 |
// what block/clustersize the filesystem will round filesizes to. |
|
9151 |
// The last file that fills up the drive may therefore be partial |
|
9152 |
// (smaller than this calculation predicts). |
|
9153 |
TInt maxPossibleFiles = gFilesNeededToFillCache; |
|
9154 |
test.Printf(_L("Original files needed = %d\n"), maxPossibleFiles); |
|
9155 |
if(gMediaSize < (KDefaultCacheSize * maxPossibleFiles)) |
|
9156 |
{ |
|
9157 |
maxPossibleFiles = (gMediaSize - 10) / KDefaultCacheSize; |
|
9158 |
test.Printf(_L("Disk size is smaller - files needed = %d\n"), maxPossibleFiles); |
|
9159 |
} |
|
9160 |
gFilesNeededToFillCache = maxPossibleFiles; |
|
9161 |
CreateFiles(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9162 |
} |
|
9163 |
||
9164 |
||
9165 |
// |
|
9166 |
// TestFileCaching |
|
9167 |
// |
|
9168 |
//--------------------------------------------------------------------------------------------------------------------- |
|
9169 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0599 |
|
9170 |
//! @SYMTestType CIT |
|
9171 |
//! @SYMTestCaseDesc Verifying that when File System Caching allocates dicardable pages, |
|
9172 |
//! Defrag and allocation of fixed pages happens correctly. |
|
9173 |
//! @SYMPREQ PREQ308 |
|
9174 |
//! @SYMTestPriority High |
|
9175 |
//! @SYMTestActions |
|
9176 |
//! 1. Fill the file system cache to allocate discardable pages |
|
9177 |
//! following this call EmptyRamZone() in a zone with discardable pages. |
|
9178 |
//! 2. Fill the file system cache to allocate discardable pages |
|
9179 |
//! folling this allocate discontiguous fixed pages to a zone |
|
9180 |
//! 3. Fill the file system cache to allocate discardable pages |
|
9181 |
//! . following this allocate discontuguous fixed pages |
|
9182 |
//! 4. Fill the file system cache to allocate discardable pages |
|
9183 |
//! following this allocate less than 16 contiguous fixed pages |
|
9184 |
//! 5. Fill the file system cache to allocate discardable pages |
|
9185 |
//! following this allocate more than 16 contiguous fixed pages |
|
9186 |
//! |
|
9187 |
//! @SYMTestExpectedResults |
|
9188 |
//! 1. Discardable pages are removed |
|
9189 |
//! 2. KErrNone |
|
9190 |
//! 3. KErrNone |
|
9191 |
//! 4. KErrNone and numDiscardablePages != 0 |
|
9192 |
//! 5. KErrNone and numDiscardablePages = 0 |
|
9193 |
//--------------------------------------------------------------------------------------------------------------------- |
|
9194 |
TInt TestFileCaching() |
|
9195 |
{ |
|
9196 |
const TUint KDisPagesReq = 1; |
|
9197 |
TInt r = KErrNone; |
|
9198 |
TInt allocSize = 0; |
|
9199 |
TUint zoneID = 0; |
|
9200 |
TUint index = 0; |
|
9201 |
TUint minDiscardPages = 0; |
|
9202 |
if (gDrive == KNoRemovableDrive) |
|
9203 |
{ |
|
9204 |
test.Start(_L("Cannot find drive to write files to - Skipping FS Caching Tests\n")); |
|
9205 |
test.End(); |
|
9206 |
return 0; |
|
9207 |
} |
|
9208 |
||
9209 |
r = gTheFs.Connect(); |
|
9210 |
test_KErrNone(r); |
|
9211 |
||
9212 |
SetUpMMC(); |
|
9213 |
||
9214 |
RRamDefragFuncTestLdd Ldd2; |
|
9215 |
r = Ldd2.Open(); |
|
9216 |
test_KErrNone(r); |
|
9217 |
||
9218 |
test.Start(_L("Test1: Test EmptyRamZone() clears file server cache pages")); |
|
9219 |
TestStart(); |
|
9220 |
||
9221 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9222 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9223 |
||
9224 |
r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9225 |
if (r != KErrNone) |
|
9226 |
{ |
|
9227 |
test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); |
|
9228 |
goto skipFileCacheTests; |
|
9229 |
} |
|
9230 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
9231 |
||
9232 |
GetAllPageInfo(); |
|
9233 |
while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) |
|
9234 |
{ |
|
9235 |
++ index; |
|
9236 |
} |
|
9237 |
||
9238 |
if (index == gZoneCount) |
|
9239 |
{ |
|
9240 |
test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); |
|
9241 |
} |
|
9242 |
else |
|
9243 |
{ |
|
9244 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
9245 |
||
9246 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); |
|
9247 |
||
9248 |
GetAllPageInfo(); |
|
9249 |
if (gZoneUtilArray[index].iAllocDiscardable != 0) |
|
9250 |
{ |
|
9251 |
test.Printf(_L("Fail: Zone ID 0x%x has 0x%x discardable pages\n"), zoneID, gZoneUtilArray[index].iAllocDiscardable); |
|
9252 |
TEST_FAIL; |
|
9253 |
} |
|
9254 |
else |
|
9255 |
{ |
|
9256 |
test.Printf(_L("Passed...\n")); |
|
9257 |
} |
|
9258 |
} |
|
9259 |
TestEnd(); |
|
9260 |
||
9261 |
test.Next(_L("Test2: Filling the FS Cache and allocating fixed pages to a zone")); |
|
9262 |
TestStart(); |
|
9263 |
||
9264 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9265 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9266 |
||
9267 |
r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9268 |
if (r != KErrNone) |
|
9269 |
{ |
|
9270 |
test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); |
|
9271 |
goto skipFileCacheTests; |
|
9272 |
} |
|
9273 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
9274 |
||
9275 |
GetAllPageInfo(); |
|
9276 |
index = 0; |
|
9277 |
while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) |
|
9278 |
{ |
|
9279 |
++ index; |
|
9280 |
} |
|
9281 |
||
9282 |
if (index == gZoneCount) |
|
9283 |
{ |
|
9284 |
test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); |
|
9285 |
} |
|
9286 |
else |
|
9287 |
{ |
|
9288 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
9289 |
||
9290 |
// Just need to attempt to allocate one more page than there is free in the zone |
|
9291 |
allocSize = gZoneUtilArray[index].iFreePages + 1; |
|
9292 |
||
9293 |
test.Printf(_L("Allocating 0x%x fixed pages to zone ID 0x%x.....\n"), allocSize, zoneID); |
|
9294 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, allocSize); |
|
9295 |
test.Printf(_L("r = %d\n"), r); |
|
9296 |
||
9297 |
GetAllPageInfo(); |
|
9298 |
if (r != KErrNone) |
|
9299 |
{ |
|
9300 |
test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); |
|
9301 |
TEST_FAIL; |
|
9302 |
} |
|
9303 |
else |
|
9304 |
{ |
|
9305 |
test.Printf(_L("Passed...\n")); |
|
9306 |
} |
|
9307 |
TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); |
|
9308 |
Ldd.FreeAllFixedPages(); |
|
9309 |
} |
|
9310 |
TestEnd(); |
|
9311 |
||
9312 |
||
9313 |
test.Next(_L("Test3: Filling the FS Cache and allocating fixed pages")); |
|
9314 |
TestStart(); |
|
9315 |
r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9316 |
if (r != KErrNone) |
|
9317 |
{ |
|
9318 |
test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); |
|
9319 |
goto skipFileCacheTests; |
|
9320 |
} |
|
9321 |
||
9322 |
GetAllPageInfo(); |
|
9323 |
index = 0; |
|
9324 |
while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) |
|
9325 |
{ |
|
9326 |
++ index; |
|
9327 |
} |
|
9328 |
||
9329 |
if (index == gZoneCount) |
|
9330 |
{ |
|
9331 |
test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); |
|
9332 |
} |
|
9333 |
else |
|
9334 |
{ |
|
9335 |
zoneID = gZoneConfigArray[index].iZoneId; |
|
9336 |
||
9337 |
allocSize = 14; |
|
9338 |
||
9339 |
TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); |
|
9340 |
Ldd.AllocateFixed(gTotalPageCount.iFreePages); |
|
9341 |
||
9342 |
test.Printf(_L("Allocating 0x%x fixed pages to zone ID 0x%x.....\n"), allocSize, zoneID); |
|
9343 |
r = Ldd2.AllocateFixed(allocSize); |
|
9344 |
||
9345 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
9346 |
||
9347 |
GetAllPageInfo(); |
|
9348 |
if (r != KErrNone) |
|
9349 |
{ |
|
9350 |
test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); |
|
9351 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
9352 |
CLEANUP(Ldd2.FreeAllFixedPages()); |
|
9353 |
TEST_FAIL; |
|
9354 |
} |
|
9355 |
else |
|
9356 |
{ |
|
9357 |
test.Printf(_L("Passed...\n")); |
|
9358 |
} |
|
9359 |
TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); |
|
9360 |
Ldd2.FreeAllFixedPages(); |
|
9361 |
} |
|
9362 |
TestEnd(); |
|
9363 |
||
9364 |
test.Next(_L("Test4: Filling the FS Cache and allocating less than 16 contiguous fixed pages")); |
|
9365 |
TestStart(); |
|
9366 |
||
9367 |
r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9368 |
if (r != KErrNone) |
|
9369 |
{ |
|
9370 |
test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); |
|
9371 |
goto skipFileCacheTests; |
|
9372 |
} |
|
9373 |
allocSize = 14 << gPageShift; |
|
9374 |
||
9375 |
TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); |
|
9376 |
GetAllPageInfo(); |
|
9377 |
// Allocate the fixed array before getting any page counts |
|
9378 |
for (TUint index = 0; index < gZoneCount; index++) |
|
9379 |
{ |
|
9380 |
GetAllPageInfo(); |
|
9381 |
if (gZoneUtilArray[index].iFreePages) |
|
9382 |
{ |
|
9383 |
r = Ldd.ZoneAllocToManyArray(index, gZoneUtilArray[index].iFreePages); |
|
9384 |
if (r != KErrNone) |
|
9385 |
{ |
|
9386 |
test.Printf(_L("Failed to allocate fixed array Zone %d r = %d - Skipping...\n"), index, r); |
|
9387 |
goto SkipTest4; |
|
9388 |
} |
|
9389 |
} |
|
9390 |
} |
|
9391 |
||
9392 |
// Now fill all zones with fixed pages, 1 zone at a time |
|
9393 |
// to avoid the discardable pages being disturbed |
|
9394 |
for (TUint index = 0; index < gZoneCount; index++) |
|
9395 |
{ |
|
9396 |
GetAllPageInfo(); |
|
9397 |
if (gZoneUtilArray[index].iFreePages) |
|
9398 |
{ |
|
9399 |
r = Ldd.ZoneAllocToMany2(index, gZoneUtilArray[index].iFreePages); |
|
9400 |
if (r != KErrNone) |
|
9401 |
{ |
|
9402 |
test.Printf(_L("Failed to allocate %d fixed to Zone %d r = %d - Skipping...\n"), |
|
9403 |
gZoneUtilArray[index].iFreePages, index, r); |
|
9404 |
goto SkipTest4; |
|
9405 |
} |
|
9406 |
} |
|
9407 |
} |
|
9408 |
||
9409 |
GetAllPageInfo(); |
|
9410 |
test.Printf(_L("number of free pages = 0x%x\n"), gTotalPageCount.iFreePages); |
|
9411 |
if (gTotalPageCount.iFreePages || |
|
9412 |
gTotalPageCount.iDiscardablePages <= (TUint)(allocSize >> gPageShift)) |
|
9413 |
{ |
|
9414 |
test.Printf(_L("Setup failed - Skipping...\n")); |
|
9415 |
goto SkipTest4; |
|
9416 |
} |
|
9417 |
||
9418 |
test.Printf(_L("Allocating 0x%x fixed pages.....\n"), allocSize >> gPageShift); |
|
9419 |
r = Ldd2.AllocContiguous(allocSize); |
|
9420 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
9421 |
||
9422 |
GetAllPageInfo(); |
|
9423 |
if (r != KErrNone || !gTotalPageCount.iDiscardablePages) |
|
9424 |
{ |
|
9425 |
test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); |
|
9426 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
9427 |
CLEANUP(Ldd2.FreeAllFixedPages()); |
|
9428 |
TEST_FAIL; |
|
9429 |
} |
|
9430 |
else |
|
9431 |
{ |
|
9432 |
test.Printf(_L("Passed...\n")); |
|
9433 |
} |
|
9434 |
||
9435 |
SkipTest4: |
|
9436 |
TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); |
|
9437 |
Ldd2.FreeAllFixedPages(); |
|
9438 |
TestEnd(); |
|
9439 |
||
9440 |
test.Next(_L("Test5: Filling the FS Cache and allocating more than 16 contiguous fixed pages")); |
|
9441 |
TestStart(); |
|
9442 |
// TestEnd() will have reduced any cache pages to minimum so just get current |
|
9443 |
// count of discardable pages. |
|
9444 |
GetAllPageInfo(); |
|
9445 |
minDiscardPages = gTotalPageCount.iDiscardablePages; |
|
9446 |
||
9447 |
r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9448 |
if (r != KErrNone) |
|
9449 |
{ |
|
9450 |
test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); |
|
9451 |
goto skipFileCacheTests; |
|
9452 |
} |
|
9453 |
||
9454 |
allocSize = 18 << gPageShift; |
|
9455 |
||
9456 |
TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); |
|
9457 |
GetAllPageInfo(); |
|
9458 |
||
9459 |
// Allocate the fixed array before getting any page counts |
|
9460 |
for (TUint index = 0; index < gZoneCount; index++) |
|
9461 |
{ |
|
9462 |
GetAllPageInfo(); |
|
9463 |
if (gZoneUtilArray[index].iFreePages) |
|
9464 |
{ |
|
9465 |
r = Ldd.ZoneAllocToManyArray(index, gZoneUtilArray[index].iFreePages); |
|
9466 |
if (r != KErrNone) |
|
9467 |
{ |
|
9468 |
test.Printf(_L("Failed to allocate fixed array Zone %d r = %d - Skipping...\n"), index, r); |
|
9469 |
goto SkipTest5; |
|
9470 |
} |
|
9471 |
} |
|
9472 |
} |
|
9473 |
||
9474 |
// Now fill all zones with fixed pages, 1 zone at a time |
|
9475 |
// to avoid the discardable pages being disturbed |
|
9476 |
for (TUint index = 0; index < gZoneCount; index++) |
|
9477 |
{ |
|
9478 |
GetAllPageInfo(); |
|
9479 |
if (gZoneUtilArray[index].iFreePages) |
|
9480 |
{ |
|
9481 |
r = Ldd.ZoneAllocToMany2(index, gZoneUtilArray[index].iFreePages); |
|
9482 |
if (r != KErrNone) |
|
9483 |
{ |
|
9484 |
test.Printf(_L("Failed to allocate %d fixed to Zone %d r = %d - Skipping...\n"), |
|
9485 |
gZoneUtilArray[index].iFreePages, index, r); |
|
9486 |
goto SkipTest5; |
|
9487 |
} |
|
9488 |
} |
|
9489 |
} |
|
9490 |
||
9491 |
GetAllPageInfo(); |
|
9492 |
test.Printf(_L("number of free pages = 0x%x\n"), gTotalPageCount.iFreePages); |
|
9493 |
if (gTotalPageCount.iFreePages) |
|
9494 |
{ |
|
9495 |
test.Printf(_L("Setup failed - Skipping...\n")); |
|
9496 |
goto SkipTest5; |
|
9497 |
} |
|
9498 |
||
9499 |
test.Printf(_L("Allocating 0x%x fixed pages.....\n"), allocSize >> gPageShift); |
|
9500 |
r = Ldd2.AllocContiguous(allocSize); |
|
9501 |
TESTDEBUG(test.Printf(_L("r = %d\n"), r)); |
|
9502 |
||
9503 |
GetAllPageInfo(); |
|
9504 |
if (r != KErrNone || gTotalPageCount.iDiscardablePages != minDiscardPages) |
|
9505 |
{ |
|
9506 |
test.Printf(_L("Fail: r = %d, expected = %d - Discardable Pages = 0x%x, expected = %d\n"), |
|
9507 |
r, KErrNone, gTotalPageCount.iDiscardablePages, minDiscardPages); |
|
9508 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
9509 |
CLEANUP(Ldd2.FreeAllFixedPages()); |
|
9510 |
TEST_FAIL; |
|
9511 |
} |
|
9512 |
else |
|
9513 |
{ |
|
9514 |
test.Printf(_L("Passed...\n")); |
|
9515 |
} |
|
9516 |
SkipTest5: |
|
9517 |
||
9518 |
skipFileCacheTests: |
|
9519 |
TestEnd(); |
|
9520 |
TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); |
|
9521 |
Ldd2.FreeAllFixedPages(); |
|
9522 |
Ldd2.Close(); |
|
9523 |
gTheFs.Close(); |
|
9524 |
FormatMMC(); |
|
9525 |
test.End(); |
|
9526 |
return KErrNone; |
|
9527 |
||
9528 |
} |
|
9529 |
||
9530 |
||
9531 |
// |
|
9532 |
// TestOneZoneConfig |
|
9533 |
// |
|
9534 |
//--------------------------------------------------------------------------------------------------------------------- |
|
9535 |
//! @SYMTestCaseID KBASE-t_ramdefrag-0600 |
|
9536 |
//! @SYMTestType CIT |
|
9537 |
//! @SYMTestCaseDesc Verifying that when only 1 zone is cofigured in the variant, that |
|
9538 |
//! the defrag and allocation of fixed pages happend correctly |
|
9539 |
//! @SYMPREQ PREQ308 |
|
9540 |
//! @SYMTestPriority High |
|
9541 |
//! @SYMTestActions |
|
9542 |
//! 1. Fragment the memory and perform a DefragRam |
|
9543 |
//! 2. Fragment the memory and perform an EmptyZone |
|
9544 |
//! 3. Fragment the memory and perform a ClaimZone |
|
9545 |
//! 4. Call ZoneAllocPhysicalRam to allocate discontiguous fixed pages |
|
9546 |
//! 5. Call ZoneAllocPhysicalRam to allocate contiguous fixed pages |
|
9547 |
//! |
|
9548 |
//! @SYMTestExpectedResults |
|
9549 |
//! 1. Number of pages does not differ from the original |
|
9550 |
//! 2. KErrNoMemroy and discardable pages are discarded of |
|
9551 |
//! 3. KErrNoMemory |
|
9552 |
//! 4. KErrNone |
|
9553 |
//! 5. KErrNone |
|
9554 |
//--------------------------------------------------------------------------------------------------------------------- |
|
9555 |
TInt TestOneZoneConfig() |
|
9556 |
{ |
|
9557 |
TInt r = gTheFs.Connect(); |
|
9558 |
test_KErrNone(r); |
|
9559 |
||
9560 |
if (gDrive != KNoRemovableDrive) |
|
9561 |
{ |
|
9562 |
SetUpMMC(); |
|
9563 |
} |
|
9564 |
||
9565 |
TUint index = 0; |
|
9566 |
GetAllPageInfo(); |
|
9567 |
TUint zoneID = gZoneConfigArray[index].iZoneId; |
|
9568 |
test.Printf(_L("Zone ID = 0x%x\n"), zoneID); |
|
9569 |
TUint minCacheSize = 0; |
|
9570 |
TUint maxCacheSize = 0; |
|
9571 |
TUint currentCacheSize = 0; |
|
9572 |
||
9573 |
||
9574 |
TUint origFree = 0; |
|
9575 |
TUint origUnknown = 0; |
|
9576 |
TUint origFixed = 0; |
|
9577 |
TUint origMovable = 0; |
|
9578 |
TUint origDiscard = 0; |
|
9579 |
TUint origOther = 0; |
|
9580 |
||
9581 |
if (gPagedRom) |
|
9582 |
{ |
|
9583 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
9584 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
9585 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
9586 |
||
9587 |
TUint setMin = 60 << gPageShift; |
|
9588 |
TInt setMax = -1; |
|
9589 |
TInt r = DPTest::SetCacheSize(setMin, setMax); |
|
9590 |
if (r != KErrNone) |
|
9591 |
{ |
|
9592 |
test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); |
|
9593 |
CLEANUP(ResetDPCache()); |
|
9594 |
TEST_FAIL; |
|
9595 |
} |
|
9596 |
DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); |
|
9597 |
TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), |
|
9598 |
minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); |
|
9599 |
} |
|
9600 |
||
9601 |
test.Start(_L("Test1: Fragmenting the memory and performing a general defrag")); |
|
9602 |
TestStart(); |
|
9603 |
||
9604 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9605 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9606 |
||
9607 |
if (gDrive != KNoRemovableDrive) |
|
9608 |
{ |
|
9609 |
FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9610 |
} |
|
9611 |
else |
|
9612 |
{ |
|
9613 |
test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); |
|
9614 |
} |
|
9615 |
||
9616 |
GetAllPageInfo(); |
|
9617 |
origFree = gTotalPageCount.iFreePages; |
|
9618 |
origUnknown = gTotalPageCount.iUnknownPages; |
|
9619 |
origFixed = gTotalPageCount.iFixedPages; |
|
9620 |
origMovable = gTotalPageCount.iMovablePages; |
|
9621 |
origDiscard = gTotalPageCount.iDiscardablePages; |
|
9622 |
origOther = gTotalPageCount.iOtherPages; |
|
9623 |
||
9624 |
r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
9625 |
||
9626 |
GetAllPageInfo(); |
|
9627 |
||
9628 |
if ((origUnknown != gTotalPageCount.iUnknownPages) || |
|
9629 |
(origFixed != gTotalPageCount.iFixedPages) || |
|
9630 |
(origMovable != gTotalPageCount.iMovablePages) || |
|
9631 |
(origDiscard != gTotalPageCount.iDiscardablePages) || |
|
9632 |
(origOther != gTotalPageCount.iOtherPages)) |
|
9633 |
{ |
|
9634 |
test.Printf(_L("Fail: Pages after defrag are not equal to those before")); |
|
9635 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
9636 |
TEST_FAIL; |
|
9637 |
} |
|
9638 |
else |
|
9639 |
{ |
|
9640 |
test.Printf(_L("Passed...")); |
|
9641 |
} |
|
9642 |
// This will free any allocated memory |
|
9643 |
TestEnd(); |
|
9644 |
||
9645 |
||
9646 |
test.Next(_L("Test2: Fragmenting the memory and performing an EmptyZone")); |
|
9647 |
TestStart(); |
|
9648 |
||
9649 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9650 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9651 |
||
9652 |
if (gDrive != KNoRemovableDrive) |
|
9653 |
{ |
|
9654 |
FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9655 |
} |
|
9656 |
else |
|
9657 |
{ |
|
9658 |
test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); |
|
9659 |
} |
|
9660 |
r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); |
|
9661 |
||
9662 |
if (r != KErrNoMemory || CheckZoneIsOff(index)) |
|
9663 |
{ |
|
9664 |
test.Printf(_L("Fail: r = %d, expected = -4"), r); |
|
9665 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
9666 |
TEST_FAIL; |
|
9667 |
} |
|
9668 |
else |
|
9669 |
{ |
|
9670 |
test.Printf(_L("Passed...")); |
|
9671 |
} |
|
9672 |
// This will free any allocated memory |
|
9673 |
TestEnd(); |
|
9674 |
||
9675 |
test.Next(_L("Test3: Fragmenting the memory and performing a ClaimZone")); |
|
9676 |
TestStart(); |
|
9677 |
||
9678 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9679 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9680 |
||
9681 |
if (gDrive != KNoRemovableDrive) |
|
9682 |
{ |
|
9683 |
FillCache(gFilesNeededToFillCache, KDefaultCacheSize); |
|
9684 |
} |
|
9685 |
else |
|
9686 |
{ |
|
9687 |
test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); |
|
9688 |
} |
|
9689 |
||
9690 |
GetAllPageInfo(); |
|
9691 |
origMovable = gTotalPageCount.iMovablePages; |
|
9692 |
||
9693 |
r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID); |
|
9694 |
||
9695 |
GetAllPageInfo(); |
|
9696 |
if (r != KErrNoMemory || origMovable != gTotalPageCount.iMovablePages) |
|
9697 |
{ |
|
9698 |
test.Printf(_L("Fail: r = %d, expected = -4"), r); |
|
9699 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
9700 |
TEST_FAIL; |
|
9701 |
} |
|
9702 |
else |
|
9703 |
{ |
|
9704 |
test.Printf(_L("Passed...")); |
|
9705 |
} |
|
9706 |
// This will free any allocated memory. |
|
9707 |
TestEnd(); |
|
9708 |
||
9709 |
test.Next(_L("Test4: Calling ZoneAllocPhysicalRam to allocate discontiguous fixed pages")); |
|
9710 |
TestStart(); |
|
9711 |
||
9712 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9713 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9714 |
||
9715 |
GetAllPageInfo(); |
|
9716 |
origFree = gTotalPageCount.iFreePages; |
|
9717 |
origUnknown = gTotalPageCount.iUnknownPages; |
|
9718 |
origFixed = gTotalPageCount.iFixedPages; |
|
9719 |
origMovable = gTotalPageCount.iMovablePages; |
|
9720 |
origDiscard = gTotalPageCount.iDiscardablePages; |
|
9721 |
origOther = gTotalPageCount.iOtherPages; |
|
9722 |
||
9723 |
r = Ldd.ZoneAllocDiscontiguous(zoneID, (TInt)(origFree / 2)); |
|
9724 |
||
9725 |
GetAllPageInfo(); |
|
9726 |
if (gTotalPageCount.iFixedPages < (origFixed + (origFree / 2))) |
|
9727 |
{ |
|
9728 |
test.Printf(_L("Fail: fixed pages = 0x%x, expected >= 0x%x\n"), |
|
9729 |
gTotalPageCount.iFixedPages, (origFixed + (origFree / 2))); |
|
9730 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
9731 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
9732 |
TEST_FAIL; |
|
9733 |
} |
|
9734 |
else |
|
9735 |
{ |
|
9736 |
test.Printf(_L("Passed...")); |
|
9737 |
} |
|
9738 |
Ldd.FreeAllFixedPages(); |
|
9739 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
9740 |
TestEnd(); |
|
9741 |
||
9742 |
||
9743 |
test.Next(_L("Test5: Calling ZoneAllocPhysicalRam to allocate contiguous fixed pages")); |
|
9744 |
TestStart(); |
|
9745 |
||
9746 |
AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); |
|
9747 |
FreeMovable(gChunkArray1, gChunkArraySize1); |
|
9748 |
||
9749 |
GetAllPageInfo(); |
|
9750 |
origFree = gTotalPageCount.iFreePages; |
|
9751 |
origUnknown = gTotalPageCount.iUnknownPages; |
|
9752 |
origFixed = gTotalPageCount.iFixedPages; |
|
9753 |
origMovable = gTotalPageCount.iMovablePages; |
|
9754 |
origDiscard = gTotalPageCount.iDiscardablePages; |
|
9755 |
origOther = gTotalPageCount.iOtherPages; |
|
9756 |
||
9757 |
TInt allocSize = 50 << gPageShift; |
|
9758 |
||
9759 |
r = Ldd.ZoneAllocContiguous(zoneID, allocSize); |
|
9760 |
||
9761 |
GetAllPageInfo(); |
|
9762 |
if (gTotalPageCount.iFixedPages < (origFixed + (allocSize >> gPageShift))) |
|
9763 |
{ |
|
9764 |
test.Printf(_L("Fail: fixed pages = 0x%x, expected >= 0x%x\n"), |
|
9765 |
gTotalPageCount.iFixedPages, (origFixed + (allocSize >> gPageShift))); |
|
9766 |
CLEANUP(Ldd.FreeAllFixedPages()); |
|
9767 |
CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); |
|
9768 |
TEST_FAIL; |
|
9769 |
} |
|
9770 |
else |
|
9771 |
{ |
|
9772 |
test.Printf(_L("Passed...")); |
|
9773 |
} |
|
9774 |
Ldd.FreeAllFixedPages(); |
|
9775 |
RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); |
|
9776 |
TestEnd(); |
|
9777 |
||
9778 |
if (gPagedRom) |
|
9779 |
{ |
|
9780 |
test_KErrNone(DPTest::FlushCache()); |
|
9781 |
ResetDPCache(); |
|
9782 |
} |
|
9783 |
||
9784 |
gTheFs.Close(); |
|
9785 |
if (gDrive != KNoRemovableDrive) |
|
9786 |
{ |
|
9787 |
FormatMMC(); |
|
9788 |
} |
|
9789 |
||
9790 |
test.End(); |
|
9791 |
return KErrNone; |
|
9792 |
} |
|
9793 |
||
9794 |
||
9795 |
// |
|
9796 |
// RunDefragTests |
|
9797 |
// |
|
9798 |
// List of defrag tests to be run |
|
9799 |
// |
|
9800 |
void RunDefragTests() |
|
9801 |
{ |
|
9802 |
test.Start(_L("Testing the moving of pages in a defrag")); |
|
9803 |
TestMovPgsDefrag(); |
|
9804 |
||
9805 |
test.Next(_L("Verifying the implementation of the function TRamDefragRequest::DefragRam() arg aMaxPages")); |
|
9806 |
TestDefragRamMaxPages(); |
|
9807 |
||
9808 |
test.Next(_L("Verifying the implementation of the function TRamDefragRequest::EmptyRamZone()")); |
|
9809 |
TestEmptyRamZone(); |
|
9810 |
||
9811 |
test.Next(_L("Verifying the implementation of the function Epoc::GetRamZonePageCount()")); |
|
9812 |
TestGetRamZonePageCount(); |
|
9813 |
||
9814 |
test.Next(_L("Verifying the implementation of the function TRamDefragRequest::ClaimRamZone()")); |
|
9815 |
TestClaimRamZone(); |
|
9816 |
||
9817 |
test.Next(_L("Verifying the implementation of the function TRamDefragRequest::Cancel()")); |
|
9818 |
TestCancelDefrag(); |
|
9819 |
||
9820 |
test.Next(_L("Verifying that pages are moved correctly")); |
|
9821 |
TestMovingPages(); |
|
9822 |
||
9823 |
test.Next(_L("Verifying Semaphore Methods of the Defrag")); |
|
9824 |
TestDefragSemMethod(); |
|
9825 |
||
9826 |
test.Next(_L("Verifying Dfc Methods of the Defrag")); |
|
9827 |
TestDefragDfcMethod(); |
|
9828 |
||
9829 |
test.Next(_L("Testing priorities")); |
|
9830 |
TestPriorities(); |
|
9831 |
||
9832 |
test.Next(_L("Testing File System Caching")); |
|
9833 |
if (!gPagedRom) |
|
9834 |
{ |
|
9835 |
TestFileCaching(); |
|
9836 |
} |
|
9837 |
else |
|
9838 |
{ |
|
9839 |
test.Printf(_L("Skipping... \n")); |
|
9840 |
} |
|
9841 |
||
9842 |
test.Next(_L("Testing general RAM defrag implementation")); |
|
9843 |
TestGenDefrag(); |
|
9844 |
||
9845 |
test.End(); |
|
9846 |
} |
|
9847 |
||
9848 |
||
9849 |
// |
|
9850 |
// RunAllocTests |
|
9851 |
// |
|
9852 |
// List of allocating tests to be run |
|
9853 |
// These tests only need to be executed once |
|
9854 |
// |
|
9855 |
void RunAllocTests() |
|
9856 |
{ |
|
9857 |
test.Start(_L("Verifying the allocating strategies")); |
|
9858 |
TestAllocStrategies(); |
|
9859 |
||
9860 |
test.Next(_L("Verifying the contiguous overload of Epoc::ZoneAllocPhysicalRam()")); |
|
9861 |
TestZoneAllocContiguous(); |
|
9862 |
||
9863 |
test.Next(_L("Verifying the discontiguous overload of Epoc::ZoneAllocPhysicalRam()")); |
|
9864 |
TestZoneAllocDiscontiguous(); |
|
9865 |
||
9866 |
test.Next(_L("Test Free Zone")); |
|
9867 |
TestFreeZone(); |
|
9868 |
||
9869 |
test.Next(_L("Testing zone flags")); |
|
9870 |
TestFlags(); |
|
9871 |
||
9872 |
test.End(); |
|
9873 |
} |
|
9874 |
||
9875 |
||
9876 |
// |
|
9877 |
// E32Main |
|
9878 |
// |
|
9879 |
// Main entry point. |
|
9880 |
// |
|
9881 |
TInt E32Main() |
|
9882 |
{ |
|
9883 |
test.Title(); |
|
9884 |
DeviceDriver(TEST_DRIVER_OPEN); |
|
9885 |
gTotalRamLost = 0; |
|
9886 |
||
9887 |
TInt r = TestSetup(); |
|
9888 |
if (r != KErrNone) |
|
9889 |
{ |
|
9890 |
test.Printf(_L("Test Setup failed, r = %d\n"), r); |
|
9891 |
TestCleanup(); |
|
9892 |
return r; |
|
9893 |
} |
|
9894 |
||
9895 |
if (gZoneCount == 1) |
|
9896 |
{ |
|
9897 |
GetAllPageInfo(); |
|
9898 |
||
9899 |
test.Start(_L("Zone Count 1...")); |
|
9900 |
TestOneZoneConfig(); |
|
9901 |
} |
|
9902 |
else |
|
9903 |
{ |
|
9904 |
test.Start(_L("Running Alloc tests")); |
|
9905 |
RunAllocTests(); |
|
9906 |
||
9907 |
Ldd.ResetDriver(); |
|
9908 |
Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
9909 |
||
9910 |
||
9911 |
test.Next(_L("Running Defrag tests")); |
|
9912 |
RunDefragTests(); |
|
9913 |
||
9914 |
Ldd.ResetDriver(); |
|
9915 |
Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); |
|
9916 |
} |
|
9917 |
||
9918 |
||
9919 |
test.Printf(_L("The total number of test steps failed = %d\n"), gTestStepFailed); |
|
9920 |
test_Equal(KErrNone, gTestStepFailed); |
|
9921 |
||
9922 |
TestCleanup(); |
|
9923 |
||
9924 |
DeviceDriver(TEST_DRIVER_CLOSE); |
|
9925 |
test.End(); |
|
9926 |
test.Close(); |
|
9927 |
||
9928 |
return 0; |
|
9929 |
} |