sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\defrag\t_ramdefrag.cpp sl@0: // RAM Defragmentation Functional Tests sl@0: // sl@0: // sl@0: sl@0: //#define RUN_ALL_TESTS // Uncomment to ensure that all tests are run regardless of test failures sl@0: //#define DEBUG_VER // Uncomment for information output from tests sl@0: sl@0: sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: RTest test(_L("T_RAMDEFRAG")); sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "testdefs.h" sl@0: sl@0: sl@0: #include sl@0: sl@0: #include "t_ramdefrag.h" sl@0: sl@0: #define READ(a) ReadByte((volatile TUint8*)(a)) sl@0: sl@0: sl@0: #ifdef RUN_ALL_TESTS sl@0: #define TEST_FAIL {gTestStepFailed++;} sl@0: #define CLEANUP(a) {} sl@0: #else sl@0: #define TEST_FAIL {TestCleanup(); test(EFalse);} sl@0: #define CLEANUP(a) {if (!gFailPrintPageInfo) \ sl@0: { \ sl@0: PrintPageInfo(); \ sl@0: gFailPrintPageInfo = ETrue; \ sl@0: } \ sl@0: a;} sl@0: #endif sl@0: sl@0: sl@0: sl@0: #define TEST_DRIVER_OPEN 1 sl@0: #define TEST_DRIVER_CLOSE 0 sl@0: sl@0: #define BEST_MOVABLE 1 sl@0: #define BEST_DISCARDABLE 2 sl@0: #define BEST_FIXED 3 sl@0: sl@0: #define Z_ALLOC_CONTIG 1 sl@0: #define Z_ALLOC_DISC 2 sl@0: sl@0: LOCAL_D TUint gTestStarted = EFalse; // Used to ensure matching TestStart() and TestEnd(). sl@0: LOCAL_D TBool gPagedRom = ETrue; // Stores whether or not is a paged ROM sl@0: LOCAL_D TInt gTestStepFailed = 0; // Stores the number of test steps failed sl@0: LOCAL_D TBool gFailPrintPageInfo = EFalse; // Set to ETrue once CLEANUP has been invoked once. sl@0: LOCAL_D TBool gFileCacheRun = EFalse; // Set to ETrue whe FSCaching tests have been run sl@0: sl@0: LOCAL_D TInt gRamSize; // The total RAM size in bytes sl@0: LOCAL_D TInt gFreeRam; // The amount of free RAM available in bytes sl@0: LOCAL_D TInt gPageSize; // The number of bytes per page sl@0: LOCAL_D TUint gPageShift; sl@0: #ifdef DEBUG_VER sl@0: LOCAL_D TInt gRamUsed; // The amount of RAM used in bytes sl@0: #endif sl@0: LOCAL_D TInt gInitialRam; // The initial free RAM before a test starts sl@0: LOCAL_D TInt gEndRam; // The end free RAM when a test finishes sl@0: LOCAL_D TUint gOriginalMinCacheSize; // The original DP minSize sl@0: LOCAL_D TUint gOriginalMaxCacheSize; // The original DP maxSize sl@0: LOCAL_D TInt gTotalRamLost; // The total amount of RAM lost during the test sl@0: sl@0: LOCAL_D TUint gZoneCount = 0; // Number of zones sl@0: LOCAL_D const TUint KInvalidZoneID = 0xffffffff; // Invalid value for a zone ID sl@0: LOCAL_D STestPageCount gTotalPageCount; sl@0: sl@0: sl@0: LOCAL_D struct SRamZoneConfig* gZoneConfigArray; // Contains the configurations of all the zones sl@0: LOCAL_D struct SRamZoneUtilisation* gZoneUtilArray; // Contains the utilisations of all the zones sl@0: LOCAL_D struct SRamZoneUtilisation* gOriginalPageCountArray; // Contains the original utilisations of the zones sl@0: LOCAL_D TInt* gPrefArray; // Contains the preference order of the zones sl@0: LOCAL_D TUint8* gOrigFlagArray; // Contains the orignal values for the zone flags sl@0: sl@0: LOCAL_D TInt gDefragMaxPages = 0; sl@0: sl@0: const TInt KFillAllMovable = -1; sl@0: sl@0: LOCAL_D RChunk* gChunkArray1 = NULL; // Stores reference to all the chunks that have been created sl@0: LOCAL_D RChunk* gChunkArray2 = NULL; // Stores reference to all the chunks that have been created sl@0: LOCAL_D TUint gChunkArraySize1 = 0; // The size of the array gChunkArray sl@0: LOCAL_D TUint gChunkArraySize2 = 0; // The size of the array gChunkArray sl@0: const TUint KChunkDefaultSize = 0x300000; sl@0: const TUint KMaxChunks = 14; sl@0: LOCAL_D const TUint KNumAllocChunks = 10; // The number of chunks to be allocd for some tests. sl@0: sl@0: LOCAL_D RRamDefragFuncTestLdd Ldd; // Main Ldd used to call into device driver sl@0: sl@0: LOCAL_D TBuf<20> gTestThreadName =_L("TestThread"); sl@0: LOCAL_D RThread gTestThread; sl@0: LOCAL_D TRequestStatus status; sl@0: sl@0: LOCAL_D TInt gDrive; // The removable media drive sl@0: LOCAL_D RFs gTheFs; sl@0: LOCAL_D TFileName gSessionPath; sl@0: sl@0: const TInt KNoRemovableDrive = -1; // gDrive is set to this when no suitable drive can be found. sl@0: const TInt KDefaultCacheSize = (128 + 12) * 1024; // The default file system cache size sl@0: const TUint KNumFilesOrig = (32 * 1024 * 1024) / KDefaultCacheSize; // The number of files that are needed to fill the file system cache sl@0: LOCAL_D TInt gFilesNeededToFillCache = KNumFilesOrig ; // Not constant as can change depending on the size of the disk sl@0: LOCAL_D RFile gFile[KNumFilesOrig]; sl@0: sl@0: LOCAL_D TInt* gCandList1; // Array of zones that have the same preference and the same sl@0: LOCAL_D TInt* gCandList2; // amount of free pages sl@0: const TInt KInvalidCandIndex = -1; sl@0: sl@0: // sl@0: // GetDrive sl@0: // sl@0: // Gets the removable drive number sl@0: // sl@0: TInt GetDrive() sl@0: { sl@0: RFs theFs; sl@0: TInt r = theFs.Connect(); sl@0: test_KErrNone(r); sl@0: sl@0: TInt driveLet = KNoRemovableDrive; sl@0: sl@0: TInt i = EDriveA; sl@0: for (; i <= EDriveZ; i++) sl@0: { sl@0: TVolumeInfo volInfo; sl@0: r = theFs.Volume(volInfo, i); sl@0: if (r == KErrNone) sl@0: {// This drive no. exists so determine if it is removable and sl@0: // formattable media. sl@0: if ((volInfo.iDrive.iDriveAtt & KDriveAttRemovable) && sl@0: (volInfo.iDrive.iMediaAtt & KMediaAttFormattable)) sl@0: { sl@0: driveLet = i; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: theFs.Close(); sl@0: return driveLet; sl@0: } sl@0: sl@0: sl@0: // sl@0: // DeviceDriver sl@0: // sl@0: // Opens or closes the device driver used sl@0: // sl@0: TInt DeviceDriver(TInt aFunctionNum) sl@0: { sl@0: TInt r = 0; sl@0: switch (aFunctionNum) sl@0: { sl@0: case TEST_DRIVER_OPEN: sl@0: { sl@0: r = User::LoadLogicalDevice(KRamDefragFuncTestLddName); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r = Ldd.Open(); sl@0: test_KErrNone(r); sl@0: } sl@0: break; sl@0: sl@0: case TEST_DRIVER_CLOSE: sl@0: { sl@0: Ldd.Close(); sl@0: r = User::FreeLogicalDevice(KRamDefragFuncTestLddName); sl@0: test_KErrNone(r); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: sl@0: // sl@0: // GetOriginalPageCount sl@0: // sl@0: // Obtains the orginal types of pages in each of the zones sl@0: // sl@0: void GetOriginalPageCount() sl@0: { sl@0: TUint index; sl@0: TInt ret = 0; sl@0: TESTDEBUG(test.Printf(_L("ram defrag : Get info about the zones\n"))); sl@0: for (index = 0; index < gZoneCount; index ++) sl@0: { sl@0: ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gOriginalPageCountArray[index]); sl@0: test(ret == KErrNone); sl@0: } sl@0: } sl@0: sl@0: sl@0: // sl@0: // PrintPageInfo sl@0: // sl@0: // Prints various page information to the screen sl@0: // sl@0: void PrintPageInfo() sl@0: { sl@0: test.Printf(_L("\nZONE CONFIGURATIONS:\n")); sl@0: for (TUint index = 0; index < gZoneCount; index ++) sl@0: { sl@0: TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)index, (TAny*)&gZoneConfigArray[index]); sl@0: test(ret == KErrNone); sl@0: test.Printf(_L("config : id=0x%08x index=%-2d base=0x%08x end=0x%08x pages=0x%08x pref=%-2d flags=0x%x\n"), sl@0: gZoneConfigArray[index].iZoneId,gZoneConfigArray[index].iZoneIndex, sl@0: gZoneConfigArray[index].iPhysBase,gZoneConfigArray[index].iPhysEnd, sl@0: gZoneConfigArray[index].iPhysPages,gZoneConfigArray[index].iPref,gZoneConfigArray[index].iFlags); sl@0: } sl@0: test.Printf(_L("\nZONE UTILISATIONS:\n")); sl@0: for (TUint index = 0; index < gZoneCount; index ++) sl@0: { sl@0: TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gZoneUtilArray[index]); sl@0: test(ret == KErrNone); sl@0: 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"), sl@0: gZoneUtilArray[index].iZoneId,gZoneUtilArray[index].iZoneIndex,gZoneConfigArray[index].iPref, sl@0: gZoneUtilArray[index].iPhysPages,gZoneUtilArray[index].iFreePages, sl@0: gZoneUtilArray[index].iAllocUnknown,gZoneUtilArray[index].iAllocFixed,gZoneUtilArray[index].iAllocMovable, sl@0: gZoneUtilArray[index].iAllocDiscardable,gZoneUtilArray[index].iAllocOther); sl@0: } sl@0: } sl@0: sl@0: sl@0: // sl@0: // GetAllPageInfo sl@0: // sl@0: // Get various different page information for all zones sl@0: // Also updates the total page count sl@0: // sl@0: void GetAllPageInfo() sl@0: { sl@0: TInt ret = 0; sl@0: gTotalPageCount.iFreePages = 0; sl@0: gTotalPageCount.iUnknownPages = 0; sl@0: gTotalPageCount.iFixedPages = 0; sl@0: gTotalPageCount.iMovablePages = 0; sl@0: gTotalPageCount.iDiscardablePages = 0; sl@0: gTotalPageCount.iOtherPages = 0; sl@0: sl@0: // now get the config of each of the zones. sl@0: TUint index; sl@0: TESTDEBUG(test.Printf(_L("ram defrag : Get info about the zones\n"))); sl@0: for (index = 0; index < gZoneCount; index ++) sl@0: { sl@0: ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)index, (TAny*)&gZoneConfigArray[index]); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneUtilisation,(TAny*)index, (TAny*)&gZoneUtilArray[index]); sl@0: test(ret == KErrNone); sl@0: sl@0: gTotalPageCount.iFreePages += gZoneUtilArray[index].iFreePages; sl@0: gTotalPageCount.iUnknownPages += gZoneUtilArray[index].iAllocUnknown; sl@0: gTotalPageCount.iFixedPages += gZoneUtilArray[index].iAllocFixed; sl@0: gTotalPageCount.iMovablePages += gZoneUtilArray[index].iAllocMovable; sl@0: gTotalPageCount.iDiscardablePages += gZoneUtilArray[index].iAllocDiscardable; sl@0: gTotalPageCount.iOtherPages += gZoneUtilArray[index].iAllocOther; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("free=0x%x unknown=0x%x fixed=0x%x move=0x%x discard=0x%x other=0x%x\n"), sl@0: gTotalPageCount.iFreePages, gTotalPageCount.iUnknownPages, gTotalPageCount.iFixedPages, sl@0: gTotalPageCount.iMovablePages, gTotalPageCount.iDiscardablePages,gTotalPageCount.iOtherPages)); sl@0: sl@0: TESTDEBUG(PrintPageInfo()); sl@0: } sl@0: sl@0: void RestoreRamZoneFlags() sl@0: { sl@0: GetAllPageInfo(); // Update the current set of RAM zone flag data. sl@0: for (TUint index=0; index < gZoneCount; index++) sl@0: { sl@0: TUint zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ORIG_FLAG, gOrigFlagArray[index]); sl@0: } sl@0: } sl@0: sl@0: void ResetRamZoneFlags() sl@0: { sl@0: GetAllPageInfo(); // Update the current set of RAM zone flag data. sl@0: for (TUint index=0; index < gZoneCount; index++) sl@0: { sl@0: TUint zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, RESET_FLAG); sl@0: } sl@0: } sl@0: sl@0: void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize); sl@0: void ResetDPCache(); sl@0: sl@0: void FSCachCleanUp() sl@0: { sl@0: // If the File System Caching tests have been run, sl@0: // ensure that they are cleaned up sl@0: if (gFileCacheRun) sl@0: { sl@0: TUint i = 0; sl@0: // First close all the open handles to the RFile objects open sl@0: for (i = 0; i < KNumFilesOrig; i++) sl@0: { sl@0: gFile[i].Close(); sl@0: } sl@0: sl@0: // Now call EmptyRamZone on every zone to ensure that sl@0: // discardable pages are cleaned up sl@0: sl@0: GetAllPageInfo(); sl@0: for (i = 0; i < gZoneCount; i++) sl@0: { sl@0: TUint zoneID = gZoneConfigArray[i].iZoneId; sl@0: Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); sl@0: } sl@0: gFileCacheRun = EFalse; sl@0: } sl@0: } sl@0: sl@0: // sl@0: // TestCleanup sl@0: // sl@0: // Cleans up all the allocations made at the beginning of the test sl@0: // sl@0: void TestCleanup() sl@0: { sl@0: sl@0: Ldd.ResetDriver(); sl@0: sl@0: // Revert the cleared flags to their original values before the tests were carried out sl@0: RestoreRamZoneFlags(); sl@0: sl@0: // Reset the DP cache and remove any allocated chunks and fixed pages. sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: ResetDPCache(); sl@0: Ldd.FreeAllFixedPages(); sl@0: Ldd.FreeFromAllZones(); sl@0: FSCachCleanUp(); sl@0: sl@0: User::Free(gPrefArray); sl@0: gPrefArray = NULL; sl@0: sl@0: User::Free(gOrigFlagArray); sl@0: gOrigFlagArray = NULL; sl@0: sl@0: User::Free(gCandList1); sl@0: gCandList1 = NULL; sl@0: sl@0: User::Free(gCandList2); sl@0: gCandList2 = NULL; sl@0: sl@0: User::Free(gOriginalPageCountArray); sl@0: gOriginalPageCountArray = NULL; sl@0: sl@0: // Output the last possible state of memory sl@0: if (!gFailPrintPageInfo) sl@0: PrintPageInfo(); sl@0: sl@0: User::Free(gZoneConfigArray); sl@0: gZoneConfigArray = NULL; sl@0: sl@0: User::Free(gZoneUtilArray); sl@0: gZoneUtilArray = NULL; sl@0: sl@0: } sl@0: sl@0: sl@0: // TestSetup sl@0: // sl@0: // Get the necessary information needed to carry out the tests sl@0: // sl@0: TInt TestSetup() sl@0: { sl@0: // Get the MMC drive sl@0: gDrive = GetDrive(); sl@0: sl@0: // first get the number of zones sl@0: TInt ret = UserSvr::HalFunction(EHalGroupRam,ERamHalGetZoneCount,&gZoneCount,0); sl@0: if (ret != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot obtain the number of zones\n")); sl@0: return ret; sl@0: } sl@0: test.Printf(_L("RAM Zones (count=%u)\n"),gZoneCount); sl@0: sl@0: // Obtain the size of the RAM and the size of a page sl@0: ret = HAL::Get(HAL::EMemoryRAM, gRamSize); sl@0: if (ret != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot obtain the size of RAM\n")); sl@0: return ret; sl@0: } sl@0: sl@0: // Retrieve the page size and use it to detemine the page shift (assumes 32-bit system). sl@0: ret = HAL::Get(HAL::EMemoryPageSize, gPageSize); sl@0: if (ret != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot obtain the page size\n")); sl@0: return ret; sl@0: } sl@0: sl@0: TUint32 pageMask = gPageSize; sl@0: TUint i = 0; sl@0: for (; i < 32; i++) sl@0: { sl@0: if (pageMask & 1) sl@0: { sl@0: if (pageMask & ~1u) sl@0: { sl@0: test.Printf(_L("ERROR - page size not a power of 2")); sl@0: return KErrNotSupported; sl@0: } sl@0: gPageShift = i; sl@0: break; sl@0: } sl@0: pageMask >>= 1; sl@0: } sl@0: sl@0: gZoneConfigArray = (SRamZoneConfig *)User::AllocZ(sizeof(SRamZoneConfig) * gZoneCount); sl@0: if (gZoneConfigArray == NULL) sl@0: return KErrNoMemory; sl@0: gZoneUtilArray = (SRamZoneUtilisation *)User::AllocZ(sizeof(SRamZoneUtilisation) * gZoneCount); sl@0: if (gZoneUtilArray == NULL) sl@0: return KErrNoMemory; sl@0: gPrefArray = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); sl@0: if (gPrefArray == NULL) sl@0: return KErrNoMemory; sl@0: gOrigFlagArray = (TUint8 *)User::AllocZ(sizeof(TUint8) * gZoneCount); sl@0: if (gOrigFlagArray == NULL) sl@0: return KErrNoMemory; sl@0: gOriginalPageCountArray = (SRamZoneUtilisation *)User::AllocZ(sizeof(SRamZoneUtilisation) * gZoneCount); sl@0: if (gOriginalPageCountArray == NULL) sl@0: return KErrNoMemory; sl@0: sl@0: gCandList1 = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); sl@0: if (gCandList1 == NULL) sl@0: return KErrNoMemory; sl@0: gCandList2 = (TInt *)User::AllocZ(sizeof(TInt) * gZoneCount); sl@0: if (gCandList2 == NULL) sl@0: return KErrNoMemory; sl@0: sl@0: GetAllPageInfo(); sl@0: PrintPageInfo(); sl@0: sl@0: // Store the original flags sl@0: for (i=0; i < gZoneCount; i++) sl@0: gOrigFlagArray[i] = gZoneConfigArray[i].iFlags; sl@0: sl@0: // Now clear the flags for carrying out tests sl@0: Ldd.ResetDriver(); sl@0: ResetRamZoneFlags(); sl@0: sl@0: sl@0: // Check whether the ROM is paged or not sl@0: TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); sl@0: if(!romHeader->iPageableRomStart) sl@0: { sl@0: test.Printf(_L("Not a Paged ROM - Skipping all discardable page tests.\n")); sl@0: gPagedRom = EFalse; sl@0: } sl@0: else sl@0: {// Save the current state of the DP cache so it can be restored when required and sl@0: // after the test has finished. sl@0: TUint currentCacheSize; sl@0: DPTest::CacheSize(gOriginalMinCacheSize, gOriginalMaxCacheSize, currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: gOriginalMinCacheSize >> gPageShift, gOriginalMaxCacheSize >> gPageShift, sl@0: currentCacheSize >> gPageShift)); sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // UpdateRamInfo sl@0: // sl@0: // Updating the various RAM information sl@0: // sl@0: void UpdateRamInfo() sl@0: { sl@0: HAL::Get(HAL::EMemoryRAMFree, gFreeRam); sl@0: TESTDEBUG(gRamUsed = gRamSize - gFreeRam); sl@0: } sl@0: sl@0: sl@0: // sl@0: // CheckRamDifference sl@0: // sl@0: // Checks the difference between the initial free RAM and the end free RAM sl@0: // sl@0: void CheckRamDifference() sl@0: { sl@0: if (gInitialRam == gEndRam) sl@0: { sl@0: TESTDEBUG(test.Printf(_L("No RAM was lost during this test\n"))); sl@0: } sl@0: else sl@0: { sl@0: TInt diff = gInitialRam - gEndRam; sl@0: sl@0: sl@0: gTotalRamLost = gTotalRamLost + diff; sl@0: } sl@0: } sl@0: sl@0: TInt VerifyMovDisAlloc(); sl@0: // sl@0: // TestStart sl@0: // sl@0: // Updates the RAM information at the beginning of a test step sl@0: // sl@0: void TestStart() sl@0: { sl@0: test(!gTestStarted); sl@0: gTestStarted = ETrue; sl@0: sl@0: Ldd.ResetDriver(); sl@0: sl@0: Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: if (VerifyMovDisAlloc() != KErrNone) sl@0: { sl@0: CLEANUP(;); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: UpdateRamInfo(); sl@0: gInitialRam = gFreeRam; sl@0: TESTDEBUG(test.Printf(_L("Initial Free RAM = 0x%x, Initial RAM Used = 0x%x\n"), gFreeRam, gRamUsed)); sl@0: } sl@0: sl@0: sl@0: void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize); sl@0: // sl@0: // TestEnd sl@0: // sl@0: // Updates RAM information at end of test step and checks the RAM delta sl@0: // sl@0: void TestEnd() sl@0: { sl@0: test(gTestStarted); sl@0: gTestStarted = EFalse; sl@0: sl@0: gDefragMaxPages = 0; sl@0: sl@0: // Clean up anything that may need to be cleaned. sl@0: ResetRamZoneFlags(); sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: ResetDPCache(); sl@0: Ldd.FreeAllFixedPages(); sl@0: FSCachCleanUp(); sl@0: sl@0: UpdateRamInfo(); sl@0: gEndRam = gFreeRam; sl@0: TESTDEBUG(test.Printf(_L("End RAM Free = 0x%x, End RAM Used = 0x%x\n"), gEndRam, gRamUsed)); sl@0: CheckRamDifference(); sl@0: test.Printf(_L(" \n")); sl@0: } sl@0: sl@0: // sl@0: // CheckZonesSwitchedOff sl@0: // sl@0: // Checks that zones have been switched off sl@0: // sl@0: TBool CheckZonesSwitchedOff() sl@0: { sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gOriginalPageCountArray[i].iFreePages != gOriginalPageCountArray[i].iPhysPages && sl@0: gZoneUtilArray[i].iFreePages == gZoneUtilArray[i].iPhysPages) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: sl@0: // sl@0: // CheckZoneIsOff sl@0: // sl@0: // Checks if a particular zone is empty sl@0: // sl@0: TBool CheckZoneIsOff(TUint aZoneIndex) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[aZoneIndex].iFreePages == gZoneUtilArray[aZoneIndex].iPhysPages) sl@0: { sl@0: TESTDEBUG(test.Printf(_L("Zone index %d is Empty\n"), aZoneIndex)); sl@0: return ETrue; sl@0: } sl@0: else sl@0: { sl@0: TESTDEBUG(test.Printf(_L("Zone index %d is Not empty\n"), aZoneIndex)); sl@0: return EFalse; sl@0: } sl@0: } sl@0: sl@0: sl@0: // sl@0: // GetPrefOrder sl@0: // sl@0: // Go through each zone ordering them in preference order sl@0: // sl@0: void GetPrefOrder() sl@0: { sl@0: GetAllPageInfo(); sl@0: TESTDEBUG(PrintPageInfo()); sl@0: sl@0: for (TUint i=0; i < (TUint)gZoneCount; i++) sl@0: gPrefArray[i] = KErrNotFound; sl@0: sl@0: for (TUint curIndex = 0; curIndex < gZoneCount; curIndex++) sl@0: { sl@0: TBool currentEmpty = gZoneUtilArray[curIndex].iPhysPages == gZoneUtilArray[curIndex].iFreePages; sl@0: TUint currentPref = gZoneConfigArray[curIndex].iPref; sl@0: TUint currentImmovPages = gZoneUtilArray[curIndex].iAllocFixed + sl@0: gZoneUtilArray[curIndex].iAllocUnknown; sl@0: TUint morePrefCnt = 0; sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: {// A RAM zone with the same iPref is more preferable if it has sl@0: // more immovable pages. sl@0: if (gZoneConfigArray[index].iPref < currentPref || sl@0: (gZoneConfigArray[index].iPref == currentPref && sl@0: (currentImmovPages < gZoneUtilArray[index].iAllocFixed + gZoneUtilArray[index].iAllocUnknown || sl@0: (currentEmpty && sl@0: gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages)))) sl@0: { sl@0: morePrefCnt++; sl@0: } sl@0: } sl@0: sl@0: while (gPrefArray[morePrefCnt] != KErrNotFound) sl@0: {// Zone(s) of this preference and size already exist so sl@0: // place this one after it/them sl@0: morePrefCnt++; sl@0: } sl@0: gPrefArray[morePrefCnt] = curIndex; sl@0: } sl@0: } sl@0: sl@0: // sl@0: // ZonesSamePref sl@0: // sl@0: // Return ETrue if the RAM zones are of the same preference. sl@0: // sl@0: // NOTE - This requires GetAllPageInfo() to have already been called. sl@0: // sl@0: TBool ZonesSamePref(TUint aZoneIndex1, TUint aZoneIndex2) sl@0: { sl@0: TBool zoneEmpty1 = gZoneUtilArray[aZoneIndex1].iFreePages == gZoneUtilArray[aZoneIndex1].iPhysPages; sl@0: TBool zoneEmpty2 = gZoneUtilArray[aZoneIndex2].iFreePages == gZoneUtilArray[aZoneIndex2].iPhysPages; sl@0: if (gZoneConfigArray[aZoneIndex1].iPref == gZoneConfigArray[aZoneIndex2].iPref && sl@0: (gZoneUtilArray[aZoneIndex1].iAllocFixed + gZoneUtilArray[aZoneIndex1].iAllocUnknown == sl@0: gZoneUtilArray[aZoneIndex2].iAllocFixed + gZoneUtilArray[aZoneIndex2].iAllocUnknown && sl@0: (zoneEmpty1 == zoneEmpty2))) sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: return EFalse; sl@0: } sl@0: sl@0: // sl@0: // FindMostPrefEmpty sl@0: // sl@0: // Checks all zones and returns the most preferable RAM zone which sl@0: // is completely emtpy sl@0: // sl@0: // @param aZoneIndex On return this will contain the index into gZoneUtilArray of the most preferable empty RAM zone. sl@0: // @param aPrefIndex On return this will contain the index into gPrefArray of the most preferable empty RAM zone. sl@0: // sl@0: // @return KErrNotFound if a zone cannot be found, else KErrNone sl@0: // sl@0: TInt FindMostPrefEmpty(TUint& aZoneIndex, TUint* aPrefIndex = NULL) sl@0: { sl@0: // Get the most pref zone which is completely free to use as a test zone sl@0: GetPrefOrder(); sl@0: TUint prefIndex = 0; sl@0: for (; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages) sl@0: { sl@0: aZoneIndex = zoneIndex; sl@0: if (aPrefIndex) sl@0: { sl@0: *aPrefIndex = prefIndex; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: // sl@0: // FindLeastPrefEmpty sl@0: // sl@0: // Checks all zones and returns the least preferable RAM zone which sl@0: // is completely emtpy sl@0: // sl@0: // @param aZoneIndex On return this will contain the index into gZoneUtilArray of the least preferable empty RAM zone. sl@0: // @param aPrefIndex On return this will contain the index into gPrefArray of the least preferable empty RAM zone. sl@0: // sl@0: // @return KErrNotFound if a zone cannot be found, else KErrNone sl@0: // sl@0: TInt FindLeastPrefEmpty(TUint& aZoneIndex, TUint* aPrefIndex = NULL) sl@0: { sl@0: // Get the most pref zone which is completely free to use as a test zone sl@0: GetPrefOrder(); sl@0: TInt prefIndex = gZoneCount - 1; sl@0: for (; prefIndex >= 0; prefIndex--) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages) sl@0: { sl@0: aZoneIndex = zoneIndex; sl@0: if (aPrefIndex) sl@0: { sl@0: *aPrefIndex = (TUint)prefIndex; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: // sl@0: // FindMostPrefWithFree sl@0: // sl@0: // Checks all zones and returns the most preferable RAM zone which sl@0: // has at least 1 free page sl@0: // sl@0: // @param aZoneIndex On return this will contain the index into gZoneUtilArray of the most preferable RAM zone with free pages. sl@0: // @param aPrefIndex On return this will contain the index into gPrefArray of the most preferable RAM zone with free pages. sl@0: // sl@0: // @return KErrNotFound if a zone cannot be found, else KErrNone sl@0: // sl@0: TInt FindMostPrefWithFree(TUint& aZoneIndex, TUint* aPrefIndex = NULL) sl@0: { sl@0: // Get the most pref zone which has free pages sl@0: GetPrefOrder(); sl@0: TUint prefIndex = 0; sl@0: for (; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[zoneIndex].iFreePages) sl@0: { sl@0: aZoneIndex = zoneIndex; sl@0: if (aPrefIndex) sl@0: { sl@0: *aPrefIndex = prefIndex; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: // sl@0: // CanGenSucceed sl@0: // sl@0: // Check whether a call to TRamDefragRequest::DefragRam() would be able to sl@0: // succeed or not. sl@0: // sl@0: TBool CanGenSucceed() sl@0: { sl@0: GetPrefOrder(); sl@0: TBool genSucceed = EFalse; sl@0: // Work out if general has anything to do sl@0: for(TInt prefIndex = (TInt)gZoneCount-1; prefIndex >= 0; prefIndex--) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: TESTDEBUG(test.Printf(_L("prefIndex = %d zoneIndex = 0x%x\n"), prefIndex, zoneIndex)); sl@0: sl@0: TUint samePrefCount = 1; sl@0: TUint samePrefSucceed = 0; sl@0: // The number of zones of this preference that will be skipped by the general defrag sl@0: TUint samePrefEmptyImmovable = 0; sl@0: sl@0: // Determine how many zones have the same preference as this one sl@0: TInt prevPrefIndex = (prefIndex != 0)? (prefIndex - 1) : -1; sl@0: for (; prevPrefIndex >= 0; prevPrefIndex--) sl@0: { sl@0: TUint prevIndex = gPrefArray[prevPrefIndex]; sl@0: if (ZonesSamePref(zoneIndex, prevIndex)) sl@0: { sl@0: samePrefCount++; sl@0: } sl@0: else // no more zones with this preference sl@0: break; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("samePrefCount = %d\n"), samePrefCount)); sl@0: sl@0: for (TInt l = prefIndex - (samePrefCount-1); l <= prefIndex; l++) sl@0: { sl@0: TUint curPrefIndex = gPrefArray[l]; sl@0: TESTDEBUG(test.Printf(_L("curPrefIndex = %d\n"), curPrefIndex)); sl@0: if (gZoneUtilArray[curPrefIndex].iFreePages != gZoneConfigArray[curPrefIndex].iPhysPages) sl@0: { sl@0: TBool clearMovable = EFalse; sl@0: TBool clearDiscardable = EFalse; sl@0: sl@0: if (gZoneUtilArray[curPrefIndex].iAllocUnknown || gZoneUtilArray[curPrefIndex].iAllocFixed) sl@0: { sl@0: TESTDEBUG(test.Printf(_L("unknown or fixed\n"))); sl@0: samePrefEmptyImmovable++; sl@0: continue; sl@0: } sl@0: if (gZoneUtilArray[curPrefIndex].iAllocMovable) sl@0: {// determine if movable can potentially be cleared from this zone sl@0: TUint freeInLower = 0; sl@0: for (TInt j=0; j <= prefIndex; j++) sl@0: { sl@0: TUint idx = gPrefArray[j]; sl@0: if (idx == curPrefIndex) sl@0: continue; sl@0: freeInLower += gZoneUtilArray[idx].iFreePages; sl@0: } sl@0: if (gZoneUtilArray[curPrefIndex].iAllocMovable <= freeInLower) sl@0: { sl@0: clearMovable = ETrue; sl@0: TESTDEBUG(test.Printf(_L("Can clear movable, curPrefIndex = %d\n"), curPrefIndex)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TESTDEBUG(test.Printf(_L("Can clear movable, curPrefIndex = %d\n"), curPrefIndex)); sl@0: clearMovable = ETrue; sl@0: } sl@0: if (gZoneUtilArray[curPrefIndex].iAllocDiscardable) sl@0: { sl@0: if (gPagedRom) sl@0: { sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TUint spareCache = currentCacheSize - minCacheSize; sl@0: if (spareCache >= gZoneUtilArray[curPrefIndex].iAllocDiscardable ) sl@0: { sl@0: clearDiscardable = ETrue; sl@0: TESTDEBUG(test.Printf(_L("Paged: Can clear discardable\n"))); sl@0: } sl@0: else sl@0: {// determine space for discardable in more preferable zones sl@0: TUint freeInLower = 0; sl@0: for (TInt j=0; j <= prefIndex; j++) sl@0: { sl@0: TUint idx = gPrefArray[j]; sl@0: if (idx == curPrefIndex) sl@0: continue; sl@0: freeInLower += gZoneUtilArray[idx].iFreePages; sl@0: } sl@0: if (gZoneUtilArray[curPrefIndex].iAllocDiscardable - spareCache <= freeInLower) sl@0: { sl@0: clearDiscardable = ETrue; sl@0: TESTDEBUG(test.Printf(_L("Paged: Can clear discardable curPrefIndex = %d\n"), curPrefIndex)); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: {//Should always be OK to discard as no min cache size on non-paged ROMS sl@0: clearDiscardable = ETrue; sl@0: test.Printf(_L("Can clear discardable curPrefIndex = %d\n"), curPrefIndex); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: clearDiscardable = ETrue; sl@0: } sl@0: sl@0: if (clearDiscardable && clearMovable) sl@0: { sl@0: samePrefSucceed++; sl@0: TESTDEBUG(test.Printf(_L("General should succeed ID=%x\n"), gZoneConfigArray[curPrefIndex].iZoneId)); sl@0: } sl@0: } sl@0: else sl@0: {//zone already empty sl@0: samePrefEmptyImmovable++; sl@0: } sl@0: } sl@0: if (samePrefSucceed == 0 && samePrefEmptyImmovable == 0) sl@0: {// no zones can be defragged and none are already empty/have immovable. sl@0: break; sl@0: } sl@0: if (samePrefEmptyImmovable != samePrefCount) sl@0: {// Have reached some zones with allocated pages in them. sl@0: if (samePrefSucceed + samePrefEmptyImmovable == samePrefCount) sl@0: {// general should definitely succeed as each of the zones of this preference sl@0: // can be emptied or are already empty/have immovable pages allocated. sl@0: TESTDEBUG(test.Printf(_L("General should succeed \n"))); sl@0: genSucceed = ETrue; sl@0: } sl@0: break; sl@0: } sl@0: prefIndex -= samePrefCount - 1; sl@0: } sl@0: return genSucceed; sl@0: } sl@0: sl@0: sl@0: // sl@0: // ReadByte sl@0: // sl@0: // Read a particular byte sl@0: // sl@0: TUint8 ReadByte(volatile TUint8* aPtr) sl@0: { sl@0: return *aPtr; sl@0: } sl@0: sl@0: sl@0: // sl@0: // AllocDiscardable sl@0: // sl@0: // Allocate Discardable pages in the form of demand paged pages sl@0: // sl@0: // @param aNumDiscardableBytes On return this will contain the number of discardable bytes above the min cache size. sl@0: // @param aMaxBytes The new limit for maximum number of bytes in the DP cache, set to KMaxTUInt64 to fill RAM. sl@0: // @param aMinOffsetBytes When not set to KMaxTUint64, this sets the min cache size to be the max cache size - aMinOffsetBytes. sl@0: // sl@0: TInt AllocDiscardable(TInt& aNumDiscardableBytes, TUint64 aMaxBytes = KMaxTUint64, TUint64 aMinOffsetBytes = KMaxTUint64) sl@0: { sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: sl@0: TESTDEBUG(test.Printf(_L("SetCacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x\n"), minCacheSize >> gPageShift, aMaxBytes >> gPageShift)); sl@0: sl@0: if (aMaxBytes == KMaxTUint64) sl@0: {// Need to fill all of free memory with discardable pages sl@0: UpdateRamInfo(); sl@0: maxCacheSize = minCacheSize + gFreeRam; sl@0: if (aMinOffsetBytes != KMaxTUint64) sl@0: {// Set the min cache size relative to the max cache size. sl@0: minCacheSize = maxCacheSize - aMinOffsetBytes; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("free 0x%x max 0x%x min 0x%x\n"), gFreeRam, maxCacheSize, minCacheSize)); sl@0: } sl@0: else sl@0: { sl@0: maxCacheSize = aMaxBytes; sl@0: } sl@0: sl@0: TInt r = DPTest::SetCacheSize(maxCacheSize, maxCacheSize); sl@0: if (r != KErrNone) sl@0: return r; sl@0: r = DPTest::SetCacheSize(minCacheSize, maxCacheSize); sl@0: if (r != KErrNone) sl@0: return r; sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: sl@0: aNumDiscardableBytes = currentCacheSize - minCacheSize; sl@0: TESTDEBUG(test.Printf(_L("Number of discardable bytes 0x%x\n"), aNumDiscardableBytes)); sl@0: sl@0: if (aMaxBytes == KMaxTUint64) sl@0: { sl@0: UpdateRamInfo(); sl@0: if (gFreeRam != aNumDiscardableBytes) sl@0: {// The only free RAM should be that of the DP cache. sl@0: test.Printf(_L("gFreeRam 0x%x aNumDiscardableBytes 0x%x\n"), gFreeRam, aNumDiscardableBytes); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // ResetDPCache sl@0: // sl@0: // Flush the cache and set the boundaries back to their original values sl@0: // sl@0: void ResetDPCache() sl@0: { sl@0: if (gPagedRom) sl@0: { sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: TESTDEBUG(test.Printf(_L("FlushCache\n"))); sl@0: TInt r = DPTest::FlushCache(); sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: sl@0: sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMaxCacheSize); sl@0: TESTDEBUG(test.Printf(_L("SetCacheSize returns r = %d\n"), r)); sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("After CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // WriteToChunk sl@0: // sl@0: // Write to a number of chunks sl@0: // sl@0: TInt WriteToChunk(RChunk* aChunkArray, TUint aChunkArraySize, TInt aChunk, TUint8 aStart=0) sl@0: { sl@0: for (TUint i=0; i<10; i++) // Write to all chunks 10 times sl@0: { sl@0: for (TUint j=0; j < aChunkArraySize; j++) //Write to all open chunks except aChunk. sl@0: { sl@0: if (aChunkArray[j].Handle() != NULL) sl@0: { sl@0: if ((TInt)j == aChunk) // Don't write to specified chunk sl@0: { sl@0: continue; sl@0: } sl@0: TUint8* base = aChunkArray[j].Base(); sl@0: for (TUint8 k = aStart; k < aStart + 10; k++) sl@0: { sl@0: *base++ = k; // write 0 - 9 to the chunk sl@0: } sl@0: } sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // ReadChunk sl@0: // sl@0: // Read chunks - If a chunk is specified, that particular chunk is not read sl@0: // sl@0: TInt ReadChunk(RChunk* aChunkArray, TUint aChunkArraySize, TInt aChunk=-1) sl@0: { sl@0: for (TUint j=0; j < aChunkArraySize; j++) //Read all open chunks sl@0: { sl@0: if (aChunkArray[j].Handle() != NULL) sl@0: { sl@0: if ((TInt)j == aChunk) // Don't read specified chunk sl@0: { sl@0: continue; sl@0: } sl@0: TUint8* base = aChunkArray[j].Base(); sl@0: while ((aChunkArray[j].Base() + aChunkArray[j].Size()) != base) sl@0: { sl@0: READ(base++); sl@0: } sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // RemoveChunkAlloc sl@0: // sl@0: // Remove ALL chunks allocated sl@0: // sl@0: // @param aChunkArray The array that stores a reference to the chunks created. sl@0: // @param aChunkArraySize The size of aChunkArray. sl@0: // sl@0: void RemoveChunkAlloc(RChunk*& aChunkArray, TUint& aChunkArraySize) sl@0: { sl@0: TInt closedChunks = 0; sl@0: sl@0: if (aChunkArray == NULL) sl@0: {// The chunk array has already been deleted. sl@0: return; sl@0: } sl@0: sl@0: for (TUint i = 0; i < aChunkArraySize; i++) sl@0: { sl@0: if (aChunkArray[i].Handle() != NULL) sl@0: { sl@0: aChunkArray[i].Close(); sl@0: closedChunks ++; sl@0: } sl@0: } sl@0: delete[] aChunkArray; sl@0: aChunkArray = NULL; sl@0: aChunkArraySize = 0; sl@0: UpdateRamInfo(); sl@0: test.Printf(_L("Free RAM after closing %d chunks = 0x%x\n"),closedChunks,gFreeRam); sl@0: } sl@0: sl@0: sl@0: TBool SpaceAvailForPageTables(TUint aZoneIndex, TInt aNumPages) sl@0: { sl@0: // Every 1MB allocated needs a new page table sl@0: const TUint KDataBytesPerPageTable = 1024 * 1024; sl@0: sl@0: // 1 Page can fit 4 page tables sl@0: const TUint KPageTablesPerPage = 4; sl@0: sl@0: sl@0: GetAllPageInfo(); sl@0: if (aNumPages == KFillAllMovable) sl@0: { sl@0: aNumPages = gTotalPageCount.iFreePages; sl@0: } sl@0: sl@0: TUint allocBytes = aNumPages << gPageShift; sl@0: sl@0: // Add 1 as you always require at least 1 page table sl@0: TUint pageTablesRequired = (allocBytes / KDataBytesPerPageTable) + 1; sl@0: // Add 1 as the first 1-3 page tables may require a new page. sl@0: TUint pageTablePagesRequired = (pageTablesRequired / KPageTablesPerPage) + 1; sl@0: sl@0: // Determine the number of free pages in the other zones sl@0: TUint freeInOther = 0; sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (index != aZoneIndex) sl@0: { sl@0: freeInOther += gZoneUtilArray[index].iFreePages; sl@0: } sl@0: } sl@0: sl@0: // Need an overhead for the heap to grow (5 pages) sl@0: const TUint KOverhead = 5; sl@0: if (freeInOther < pageTablePagesRequired + KOverhead) sl@0: {// Not enough space in other zones to fit all page tables sl@0: test.Printf(_L("No space in other zones for page table pages\n")); sl@0: return EFalse; sl@0: } sl@0: // There is space available in the other zones to fit all the page tables sl@0: return ETrue; sl@0: } sl@0: // sl@0: // AllocMovable sl@0: // sl@0: // Allocate movable memory in the form of chunks sl@0: // sl@0: // @param aChunkArray The array to store a reference to the chunks created. sl@0: // @param aChunkArraySize The size of aChunkArray. sl@0: // @param aNumChunks The number of chunks to create. sl@0: // @param aNumPages The size of each chunk. sl@0: // sl@0: TInt AllocMovable(RChunk*& aChunkArray, TUint& aChunkArraySize, TInt aNumChunks, TUint aChunkSize=KChunkDefaultSize, TBool aForceFill = ETrue) sl@0: { sl@0: TUint i = 0; sl@0: TInt r = 0; sl@0: TUint chunksAllocd = 0; sl@0: TBool fillAll = EFalse; sl@0: sl@0: TInt numChunks = aNumChunks; sl@0: UpdateRamInfo(); sl@0: // Allocate chunks to take up all of memory with the maximum number of chunks sl@0: if (aNumChunks == KFillAllMovable) sl@0: { sl@0: fillAll = ETrue; sl@0: if (aChunkSize == KChunkDefaultSize) sl@0: { sl@0: numChunks = KMaxChunks; sl@0: aChunkSize = gFreeRam / numChunks; sl@0: } sl@0: else sl@0: { sl@0: numChunks = gFreeRam / aChunkSize; sl@0: } sl@0: } sl@0: sl@0: test.Printf(_L("gFreeRam = 0x%x, aChunkSize = 0x%x, numChunks = %d\n"), gFreeRam, aChunkSize, numChunks); sl@0: sl@0: // Allocate as many chunks as is specified, either with the default chunk size or a specified chunk size sl@0: if (aChunkArray == NULL) sl@0: { sl@0: aChunkArraySize = numChunks; sl@0: aChunkArray = new RChunk[aChunkArraySize]; sl@0: if (aChunkArray == NULL) sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: // Create chunks for each RChunk with a NULL handle. sl@0: for (i = 0; i < aChunkArraySize; i++) sl@0: { sl@0: if (aChunkArray[i].Handle() == NULL) sl@0: { sl@0: // Keep going even if a chunk creation fails as the flag tests rely sl@0: // on this. sl@0: r = aChunkArray[i].CreateLocal(aChunkSize, aChunkSize); sl@0: if (r != KErrNone && fillAll && aForceFill) sl@0: { sl@0: while (aChunkArray[i].CreateLocal(aChunkSize, aChunkSize) != KErrNone) sl@0: { sl@0: aChunkSize -= gPageSize; sl@0: } sl@0: } sl@0: if (r == KErrNone) sl@0: { sl@0: chunksAllocd++; sl@0: } sl@0: } sl@0: User::After(10); // Wait so that the next chunk gets allocated in the next time slice sl@0: } sl@0: test.Printf(_L("Number of chunks allocd = %d\n"),chunksAllocd); sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // ZoneAllocMovable sl@0: // sl@0: // Allocate the specified number of movable pages to a specific zone sl@0: // If the number of pages is not specified, then fill the specified zone with sl@0: // movable pages sl@0: // sl@0: // @param aChunkArray The array to store a reference to the chunks created. sl@0: // @param aChunkArraySize The size of aChunkArray. sl@0: // @param aZoneIndex The zone index to allocate movable pages to. sl@0: // @param aNumPages The number of movable pages to allocate. sl@0: // sl@0: TInt ZoneAllocMovable(RChunk*& aChunkArray, TUint& aChunkArraySize, TUint aZoneIndex, TUint aNumPages = KMaxTUint) sl@0: { sl@0: ResetRamZoneFlags(); sl@0: TInt r = KErrNone; sl@0: TUint allocBytes = 0; sl@0: sl@0: if (aNumPages == KMaxTUint) sl@0: { sl@0: aNumPages = gZoneUtilArray[aZoneIndex].iFreePages; sl@0: } sl@0: sl@0: allocBytes = aNumPages << gPageShift; sl@0: sl@0: if (!SpaceAvailForPageTables(aZoneIndex, aNumPages)) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: // Block all other zones from allocation sl@0: for(TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (index == aZoneIndex) sl@0: { sl@0: r = Ldd.SetZoneFlag(gZoneConfigArray[index].iZoneId, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.SetZoneFlag(gZoneConfigArray[index].iZoneId, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); sl@0: } sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set RAM zone flag on zone %d r = %d\n"), index, r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: // Allocate the movable pages sl@0: r = AllocMovable(aChunkArray, aChunkArraySize, 1, allocBytes); sl@0: sl@0: ResetRamZoneFlags(); sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // ZoneAllocDiscard sl@0: // sl@0: // Allocate the specified number of discardable pages to a specific zone sl@0: // sl@0: // @param aZoneIndex The zone index to allocate discardable pages to. sl@0: // @param aNumPages The number of discardable pages to allocate. sl@0: // @param aDisPages On return this will contain the number of discardable pages allocated sl@0: // sl@0: TInt ZoneAllocDiscard(TUint aZoneIndex, TUint aNumPages, TInt& aDisPages) sl@0: { sl@0: TInt r = KErrNone; sl@0: ResetRamZoneFlags(); sl@0: sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: if (index == aZoneIndex) sl@0: { sl@0: r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); sl@0: } sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set flag r = %d\n"), r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: TUint disBytes = gTotalPageCount.iDiscardablePages + aNumPages << gPageShift; sl@0: r = AllocDiscardable(aDisPages, disBytes); sl@0: aDisPages = aDisPages >> gPageShift; sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Discardable pages not allocated r = %d\n"), r); sl@0: } sl@0: ResetRamZoneFlags(); sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // FreeMovable sl@0: // sl@0: // Free movable pages by closing chunks. sl@0: // The function will close every other chunk so that the movable pages are scattered in every zone sl@0: // sl@0: // @param aChunkArray The array that stores reference to the chunks created. sl@0: // @param aChunkArraySize The size of aChunkArray. sl@0: // sl@0: TInt FreeMovable(RChunk* aChunkArray, TUint aChunkArraySize) sl@0: { sl@0: TUint i; sl@0: TInt closedChunks = 0; sl@0: sl@0: for (i=0; i < aChunkArraySize; i+=2) // Close every other chunk sl@0: { sl@0: if (aChunkArray[i].Handle() != NULL) sl@0: { sl@0: aChunkArray[i].Close(); sl@0: closedChunks ++; sl@0: } sl@0: } sl@0: UpdateRamInfo(); sl@0: test.Printf(_L("Free RAM after closing %d chunks = 0x%x\n"),closedChunks,gFreeRam); sl@0: return KErrNone; sl@0: } sl@0: sl@0: // sl@0: // GetBestZone sl@0: // sl@0: // Obtains the most preferable zone for allocating a specific type of page sl@0: // sl@0: // @param aPageType The page type that we are interested in sl@0: // @param aBestPrefIndex The index into the preference array for the zone. sl@0: // sl@0: // @return KErrNotFound if a zone cannot be found, else the zone index into gZoneUtilArray sl@0: // sl@0: TInt GetBestZone(TInt aPageType, TUint* aBestPrefIndex = NULL) sl@0: { sl@0: GetPrefOrder(); sl@0: sl@0: sl@0: switch (aPageType) sl@0: { sl@0: case BEST_MOVABLE: sl@0: case BEST_DISCARDABLE: sl@0: { sl@0: TInt bestIndex = KErrNotFound; sl@0: TUint bestPrefIndex = 0; sl@0: TUint curIndex = 0; sl@0: TInt startIndex = KErrNotFound; sl@0: TBool zoneFound = EFalse; sl@0: // Find the least preferable zone that has movable or discardable pages sl@0: for (TInt prefIndex = gZoneCount - 1; prefIndex >= 0; prefIndex--) sl@0: { sl@0: curIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[curIndex].iAllocMovable || gZoneUtilArray[curIndex].iAllocDiscardable) sl@0: { sl@0: startIndex = prefIndex; sl@0: break; sl@0: } sl@0: } sl@0: if (startIndex == KErrNotFound) sl@0: return startIndex; sl@0: sl@0: // Work up the preference list to look for the best zone sl@0: for (TInt prefIndex = startIndex; prefIndex >= 0; prefIndex--) sl@0: { sl@0: curIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[curIndex].iFreePages) sl@0: { sl@0: bestIndex = curIndex; sl@0: bestPrefIndex = prefIndex; sl@0: zoneFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // If the zone still isn't found, look down the preference list sl@0: if (!zoneFound) sl@0: { sl@0: for (TUint prefIndex = startIndex; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: curIndex = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[curIndex].iFreePages) sl@0: { sl@0: bestIndex = curIndex; sl@0: bestPrefIndex = prefIndex; sl@0: zoneFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: test.Printf(_L("leastPref = %d\n"), bestIndex); sl@0: if (aBestPrefIndex) sl@0: *aBestPrefIndex = bestPrefIndex; sl@0: return bestIndex; sl@0: } sl@0: sl@0: case BEST_FIXED: sl@0: for (TUint prefIndex = 0; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: TUint mostPref = gPrefArray[prefIndex]; sl@0: if (gZoneUtilArray[mostPref].iFreePages != 0 || sl@0: gZoneUtilArray[mostPref].iAllocMovable != 0 || sl@0: gZoneUtilArray[mostPref].iAllocDiscardable != 0) sl@0: { sl@0: test.Printf(_L("mostPref = %d\n"), mostPref); sl@0: if (aBestPrefIndex) sl@0: *aBestPrefIndex = prefIndex; sl@0: return mostPref; sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: sl@0: test.Printf(_L("Cannot find zone\n")); sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: void GetCandList1(TInt aIndex); sl@0: // sl@0: // VerifyMovDisAlloc sl@0: // sl@0: // Checks that all movable and discardable pages are in the correct RAM zones. sl@0: // Should only be invoked after a general defragmentation or a general sl@0: // defragmentation followed by an allocation. sl@0: // sl@0: // NOTE - This shouldn't be used to verify RAM if a RAM specific allocation or sl@0: // zone claim operation has been performed. sl@0: // sl@0: // @return KErrNone if RAM layout is good, KErrGeneral if not, KErrNotFound if no sl@0: // movable or discardable pages are allocated. sl@0: // sl@0: TInt VerifyMovDisAlloc() sl@0: { sl@0: GetPrefOrder(); sl@0: TInt leastInUse = KErrNotFound; sl@0: TUint requiredMovDis = 0; sl@0: TUint totalMorePrefInUse = 0; sl@0: TBool verifySpread = ETrue; sl@0: TBool prevZoneNotFull = EFalse; sl@0: sl@0: // Determine which is the least prefable RAM zone in use and how many pages sl@0: // are allocated of each type. sl@0: for (TInt prefIndex = gZoneCount - 1; prefIndex >= 0; prefIndex--) sl@0: { sl@0: TUint index = gPrefArray[prefIndex]; sl@0: TUint allocMov = gZoneUtilArray[index].iAllocMovable; sl@0: TUint allocDis = gZoneUtilArray[index].iAllocDiscardable; sl@0: TUint allocFixed = gZoneUtilArray[index].iAllocFixed; sl@0: TESTDEBUG(test.Printf(_L("pref ID 0x%x\n"), gZoneConfigArray[index].iZoneId)); sl@0: if (allocMov || allocDis || allocFixed) sl@0: { sl@0: TBool zoneNotFull = EFalse; sl@0: GetCandList1(index); sl@0: TUint candIndex = 0; sl@0: for (; candIndex < gZoneCount; candIndex++) sl@0: { sl@0: TInt zoneIndexCand = gCandList1[candIndex]; sl@0: if (zoneIndexCand == KInvalidCandIndex) sl@0: { sl@0: break; sl@0: } sl@0: allocMov += gZoneUtilArray[zoneIndexCand].iAllocMovable; sl@0: allocDis += gZoneUtilArray[zoneIndexCand].iAllocDiscardable; sl@0: if (gZoneUtilArray[zoneIndexCand].iFreePages) sl@0: { sl@0: zoneNotFull = ETrue; sl@0: } sl@0: } sl@0: prefIndex -= candIndex - 1; sl@0: if (leastInUse == KErrNotFound) sl@0: {// Have found least preferable RAM zone that is in use. sl@0: leastInUse = index; sl@0: if (allocFixed) sl@0: {// The least preferable RAM zone has fixed pages in it so sl@0: // RAM may be more spread out than is necessary. sl@0: verifySpread = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if ((allocMov || allocDis) && prevZoneNotFull) sl@0: {// The previous least preferable RAM zones were not full so shouldn't sl@0: // be any movable or discardable pages in the RAM zones of this preference. sl@0: test.Printf(_L("Movable or discardable pages in more preferable RAM zones unnecessarily\n")); sl@0: return KErrGeneral; sl@0: } sl@0: prevZoneNotFull = zoneNotFull; sl@0: sl@0: // Not the least preferable RAM zone so add to total allocatable. sl@0: totalMorePrefInUse += allocMov + allocDis + gZoneUtilArray[index].iFreePages; sl@0: } sl@0: requiredMovDis += allocMov + allocDis; sl@0: } sl@0: } sl@0: sl@0: if (leastInUse == KErrNotFound) sl@0: {// No movable or discardable pages are allocated. sl@0: test.Printf(_L("No in use RAM zones found????\n")); sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: if (totalMorePrefInUse > requiredMovDis) sl@0: {// There enough allocatable pages in the RAM zones below the currently sl@0: // least preferable RAM in use. sl@0: test.Printf(_L("Memory is spread out totalMorePref 0x%x required 0x%x\n"), totalMorePrefInUse, requiredMovDis); sl@0: if (verifySpread) sl@0: return KErrGeneral; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // GetCandList1 sl@0: // sl@0: // Populates a list of all zones that have the same preference and the same amount sl@0: // of immovable pages sl@0: // sl@0: void GetCandList1(TInt aIndex) sl@0: { sl@0: for (TUint i=0; i= gZoneCount || sl@0: (gZoneUtilArray[gPrefArray[nextLeastPrefIndex]].iFreePages < KHeapOverhead && sl@0: freeInMorePref < KHeapOverhead)|| sl@0: gZoneConfigArray[gPrefArray[nextLeastPrefIndex]].iPref == gZoneConfigArray[best].iPref || sl@0: gZoneConfigArray[gPrefArray[morePrefIndex]].iPref == gZoneConfigArray[best].iPref) sl@0: {// No less preferable RAM zone or there are more or less preferable of sl@0: // same preference so re-ordering potential makes verification too complex. sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Ensure the zone is almost full as chunks will get allocated in blocks sl@0: // by almost filling the best zone with fixed pages, leaving a space (e.g. 20 pages) sl@0: const TUint KSpaceNeeded = 20; sl@0: if (gZoneUtilArray[best].iFreePages > KSpaceNeeded) sl@0: { sl@0: TUint zoneID = gZoneUtilArray[best].iZoneId; sl@0: TUint diffAlloc = gZoneUtilArray[best].iFreePages - KSpaceNeeded; sl@0: TInt r = Ldd.ZoneAllocDiscontiguous(zoneID, diffAlloc); sl@0: if (r != KErrNone) sl@0: { sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: GetAllPageInfo(); sl@0: // Update the number of free pages in the more preferable zones sl@0: freeInMorePref = 0; sl@0: for (TUint i = 0; i < bestPrefIndex; i++) sl@0: { sl@0: freeInMorePref += gZoneUtilArray[gPrefArray[i]].iFreePages; sl@0: } sl@0: TUint origFixed = gTotalPageCount.iFixedPages; sl@0: sl@0: GetOriginalPageCount(); sl@0: sl@0: // Allocate enough movable pages that the next least preferable RAM zone sl@0: // will need to be used. sl@0: TUint movPages = gZoneUtilArray[best].iFreePages + 1; sl@0: TUint movBytes = movPages << gPageShift; sl@0: TInt r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: TUint curFixed = gTotalPageCount.iFixedPages; sl@0: TInt difFixed = curFixed - origFixed; sl@0: sl@0: // If there is space in the more preferable zones then they should be allocated starting from sl@0: // the "best" zone to the more preferable zones, else from the next least preferable zone to the more preferable zones sl@0: TUint prefIndex; sl@0: if ((TInt)freeInMorePref > difFixed) sl@0: {//No new zones should be turned on, allocation should have gone into bestPrefIndex then down towards most preferred zones sl@0: TUint nextIndex = gPrefArray[nextLeastPrefIndex]; sl@0: if (gOriginalPageCountArray[best].iAllocMovable >= gZoneUtilArray[best].iAllocMovable || sl@0: gOriginalPageCountArray[nextIndex].iAllocMovable < gZoneUtilArray[nextIndex].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), sl@0: gOriginalPageCountArray[best].iFreePages, gZoneUtilArray[best].iFreePages, sl@0: gZoneUtilArray[nextLeastPrefIndex].iFreePages); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: prefIndex = morePrefIndex; sl@0: } sl@0: else sl@0: {// If there are enough free pages in "nextIndex" to fit all movable pages allocated then the movable sl@0: // page count in "best" should stay the same, else they should be allocated between "nextIndex" and "best". sl@0: TUint nextIndex = gPrefArray[nextLeastPrefIndex]; sl@0: test.Printf(_L("nextIndex = %d\n"), nextIndex); sl@0: if (gOriginalPageCountArray[nextIndex].iAllocMovable >= gZoneUtilArray[nextIndex].iAllocMovable || sl@0: (gOriginalPageCountArray[nextIndex].iFreePages >= movPages && sl@0: gOriginalPageCountArray[best].iAllocMovable != gZoneUtilArray[best].iAllocMovable) || sl@0: (gOriginalPageCountArray[nextIndex].iFreePages < movPages && sl@0: gOriginalPageCountArray[best].iAllocMovable == gZoneUtilArray[best].iAllocMovable)) sl@0: { sl@0: test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), sl@0: gOriginalPageCountArray[nextIndex].iFreePages, gZoneUtilArray[nextIndex].iFreePages, sl@0: gZoneUtilArray[nextIndex].iFreePages); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: prefIndex = bestPrefIndex; sl@0: } sl@0: sl@0: // Check that movable pages have only been allocated into the more sl@0: // preferable RAM zones if the less preferable ram zones in use are full. sl@0: prefIndex++; sl@0: do sl@0: { sl@0: prefIndex--; sl@0: TUint indexCurrent = gPrefArray[prefIndex]; sl@0: TUint indexLessPref = gPrefArray[prefIndex+1]; sl@0: sl@0: if (gOriginalPageCountArray[indexCurrent].iAllocMovable < gZoneUtilArray[indexCurrent].iAllocMovable && sl@0: gZoneUtilArray[indexLessPref].iFreePages) sl@0: {// Current in use zone or less preferable than current has free pages so fail sl@0: test.Printf(_L("Movable page allocated incorrectly origFree 0x%x curFree 0x%x nxtPrefFree 0x%x\n"), sl@0: gOriginalPageCountArray[best].iFreePages, gZoneUtilArray[best].iFreePages, sl@0: gZoneUtilArray[nextLeastPrefIndex].iFreePages); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: while(prefIndex); sl@0: test.Printf(_L("Pass: Pages allocated to the zone expected\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test3: Check which zone a fixed page has been allocated to ")); sl@0: for (TUint testStep = 0; testStep < 2; testStep++) sl@0: { sl@0: switch (testStep) sl@0: { sl@0: case 0: sl@0: test.Printf(_L("Testing discontiguous allocations\n")); sl@0: break; sl@0: sl@0: case 1: sl@0: test.Printf(_L("Testing contiguous allocations\n")); sl@0: break; sl@0: } sl@0: TestStart(); sl@0: zoneFound = EFalse; sl@0: GetOriginalPageCount(); sl@0: sl@0: best = GetBestZone(BEST_FIXED); sl@0: TESTDEBUG(test.Printf(_L("best = %d\n"), best)); sl@0: if (best == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: GetCandList1(best); sl@0: TInt allocFixedPages = 1; // Try and allocate just 1 fixed page sl@0: switch (testStep) sl@0: { sl@0: case 0: sl@0: Ldd.AllocateFixed(allocFixedPages); sl@0: break; sl@0: sl@0: case 1: sl@0: TUint allocFixedBytes = allocFixedPages << gPageShift; sl@0: Ldd.AllocContiguous(allocFixedBytes); sl@0: break; sl@0: } sl@0: sl@0: sl@0: GetAllPageInfo(); sl@0: for (TUint i=0; i= gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find next best zone - Skipping...\n")); sl@0: goto SkipTest5; sl@0: } sl@0: nextBestIndex = gPrefArray[bestPrefIndex + 1]; sl@0: test.Printf(_L("nextBestIndex= %d\n"), nextBestIndex); sl@0: GetCandListFixed1(nextBestIndex); sl@0: candidates = 0; sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gCandList1[i] == KInvalidCandIndex) sl@0: { sl@0: break; sl@0: } sl@0: candidates++; sl@0: } sl@0: if (gZoneUtilArray[nextBestIndex].iPhysPages == gZoneUtilArray[nextBestIndex].iAllocFixed + sl@0: gZoneUtilArray[nextBestIndex].iAllocUnknown || sl@0: candidates != 1) sl@0: { sl@0: test.Printf(_L("Cannot find zone or too many equal pref zones to perform test - Skipping...\n")); sl@0: goto SkipTest5; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (i != (TUint)best) sl@0: { sl@0: freeInOtherZones += gZoneUtilArray[i].iFreePages; sl@0: } sl@0: } sl@0: allocatablePages = gZoneUtilArray[best].iFreePages + sl@0: gZoneUtilArray[best].iAllocMovable + sl@0: gZoneUtilArray[best].iAllocDiscardable; sl@0: sl@0: if (allocatablePages > freeInOtherZones) sl@0: { sl@0: test.Printf(_L("Not enough free RAM for test - Skipping...\n")); sl@0: goto SkipTest5; sl@0: } sl@0: sl@0: // Allocate the fixed array before getting any page counts sl@0: r = Ldd.AllocFixedArray(allocatablePages + 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate fixed array r = %d - Skipping...\n"), r); sl@0: goto SkipTest5; sl@0: } sl@0: sl@0: // Fill the RAM zone with movable pages if none already in it. sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[best].iAllocMovable == 0) sl@0: { sl@0: if (!gZoneUtilArray[best].iFreePages) sl@0: { sl@0: test.Printf(_L("RAM zone ID %x too full for test - Skipping...\n"), gZoneConfigArray[best].iZoneId); sl@0: goto SkipTest5; sl@0: } sl@0: // Fill the zone with movable pages sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, best); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to fill zone index %d with movable r = %d\n"), best, r); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (GetBestZone(BEST_FIXED) != best) sl@0: { sl@0: test.Printf(_L("Unable to complete test; RAM zone reordering - Skipping...\n")); sl@0: goto SkipTest5; sl@0: } sl@0: } sl@0: // Allocate fixed pages after reseting the allocation flags. sl@0: GetAllPageInfo(); sl@0: ResetRamZoneFlags(); sl@0: allocatablePages = gZoneUtilArray[best].iFreePages + sl@0: gZoneUtilArray[best].iAllocMovable + sl@0: gZoneUtilArray[best].iAllocDiscardable; sl@0: switch (testIndex) sl@0: { sl@0: case 0: sl@0: r = Ldd.AllocateFixed2(allocatablePages); sl@0: GetAllPageInfo(); sl@0: allocImmovPages = gZoneUtilArray[best].iAllocFixed + gZoneUtilArray[best].iAllocUnknown; sl@0: if (r != KErrNone || gZoneConfigArray[best].iPhysPages != allocImmovPages) sl@0: { sl@0: test.Printf(_L("RAM zone ID 0x%x not full of immovable pages\n"), gZoneConfigArray[best].iZoneId); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Pass: Pages allocated to the zone expected\n")); sl@0: } sl@0: break; sl@0: sl@0: case 1: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.AllocateFixed2(allocatablePages + 1); sl@0: GetAllPageInfo(); sl@0: allocImmovPages = gZoneUtilArray[best].iAllocFixed + gZoneUtilArray[best].iAllocUnknown; sl@0: if (r != KErrNone || gZoneUtilArray[best].iPhysPages != allocImmovPages || sl@0: gZoneUtilArray[nextBestIndex].iAllocFixed <= gOriginalPageCountArray[nextBestIndex].iAllocFixed) sl@0: { sl@0: test.Printf(_L("RAM zone ID 0x%x not full of immovable pages or next best ID 0x%x no fix pages\n"), sl@0: gZoneConfigArray[best].iZoneId, gZoneConfigArray[nextBestIndex].iZoneId); sl@0: test.Printf(_L("nextBest %d origFix 0x%x curFix 0x%x\n"), sl@0: nextBestIndex, gOriginalPageCountArray[nextBestIndex].iAllocFixed, sl@0: gZoneUtilArray[nextBestIndex].iAllocFixed); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: // Go through every other zone and check that fixed pages haven't increased sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (i != (TUint)best && i != (TUint)nextBestIndex && sl@0: gZoneUtilArray[i].iAllocFixed > gOriginalPageCountArray[i].iAllocFixed) sl@0: { sl@0: test.Printf(_L("FAIL: Fix page count increased zoneIndex %d orig 0x%x current 0x%x\n"), sl@0: i, gOriginalPageCountArray[i].iAllocFixed, gZoneUtilArray[i].iAllocFixed); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: sl@0: test.Printf(_L("Pass: Pages allocated to the zone expected\n")); sl@0: break; sl@0: } sl@0: SkipTest5 : sl@0: // This will perform any required clean up. sl@0: ResetRamZoneFlags(); sl@0: TestEnd(); sl@0: } sl@0: sl@0: test.Next(_L("Test7: Check which zone a discardable page has been allocated to")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: GetAllPageInfo(); sl@0: sl@0: // Try to allocate just one more discardable page sl@0: TUint allocBytes = (gTotalPageCount.iDiscardablePages + 1) << gPageShift; sl@0: TInt discardablePages; sl@0: sl@0: best = GetBestZone(BEST_DISCARDABLE); sl@0: if (best == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Populate the candidate list sl@0: GetCandList2(best); sl@0: zoneFound = EFalse; sl@0: GetOriginalPageCount(); sl@0: TInt r = AllocDiscardable(discardablePages, allocBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r %d\n"), r); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: r = VerifyMovDisAlloc(); sl@0: // Need to check all candidates to see if page has gone into any one of them sl@0: for (TUint i=0; i < gZoneCount; i++) sl@0: { sl@0: if (gCandList2[i] == KInvalidCandIndex) sl@0: { sl@0: break; sl@0: } sl@0: TUint zoneIndex = gCandList2[i]; sl@0: if (gOriginalPageCountArray[zoneIndex].iAllocDiscardable < gZoneUtilArray[zoneIndex].iAllocDiscardable) sl@0: { sl@0: zoneFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (r == KErrNone && zoneFound) sl@0: { sl@0: test.Printf(_L("Pass: Discardable allocated to the zone expected\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: Discardable been allocated to a zone that was not expected r %d\n"), r); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test8: Check fixed page allocations (contiguous) will move pages")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: sl@0: TInt r = KErrNone; sl@0: TUint testZoneIndex = 0; sl@0: sl@0: // Get the most pref zone which is completely free to use as a test zone sl@0: r = FindMostPrefEmpty(testZoneIndex); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot find empty zone - Skipping...\n")); sl@0: goto skipTest8; sl@0: } sl@0: sl@0: sl@0: // fill the test zone with movable pages sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, testZoneIndex); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[testZoneIndex].iAllocMovable != gZoneUtilArray[testZoneIndex].iPhysPages) sl@0: { sl@0: test.Printf(_L("Failed to allocate movable r = %d - Skipping...\n"), r); sl@0: goto skipTest8; sl@0: } sl@0: sl@0: if (gTotalPageCount.iFreePages < 1) sl@0: { sl@0: test.Printf(_L("Insufficient memory - totalFreePages = 0x%x - Skipping...\n"), gTotalPageCount.iFreePages); sl@0: goto skipTest8; sl@0: } sl@0: sl@0: for (TUint zoneIndex = 0; zoneIndex < gZoneCount; zoneIndex++) sl@0: { sl@0: TUint zoneId = gZoneConfigArray[zoneIndex].iZoneId; sl@0: if (zoneIndex != testZoneIndex) sl@0: { sl@0: r = Ldd.SetZoneFlag(zoneId, gZoneConfigArray[zoneIndex].iFlags, NO_FIXED_FLAG); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set flag on zone index %d r = %d- Skipping...\n"), zoneIndex, r); sl@0: goto skipTest8; sl@0: } sl@0: } sl@0: } sl@0: sl@0: //attempt to alloc 1 contiguous fixed page sl@0: r = Ldd.AllocContiguous(gPageSize); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: !gZoneUtilArray[testZoneIndex].iAllocFixed) sl@0: { sl@0: test.Printf(_L("FAIL: no fixed pages in testZoneIndex(%d) r = %d\n"), testZoneIndex, r); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: skipTest8: sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestMovingPages sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0526 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying that pages are moved correctly sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Write to all chunks apart from chunk 9. sl@0: //! Following this start a RAM defrag and whilst defrag is running write to chunk 9. sl@0: //! 2. Fragment the memory. Start a RAM defrag and whilst defrag is running sl@0: //! continuously write different values to the chunks. sl@0: //! 3. Fragment the memory. Following this start a RAM defrag and whilst this sl@0: //! is happening, continuously read from all chunks. sl@0: //! 4. Allocate some movable pages. Call a device driver that will allocate fixed sl@0: //! pages and write values to these fixed pages. sl@0: //! Close every other chunk so that only 5 chunks are now still open. sl@0: //! Following this perform a RAM defrag. sl@0: //! Read from the fixed pages that were originally written to, ensuring sl@0: //! that they have not changed. sl@0: //! 5. Without starting any processes, allocate discardable pages by loading sl@0: //! pages that are demand paged. sl@0: //! Read each of the constants from beginning to end. sl@0: //! Following this perform a RAM defrag. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Zones are emptied sl@0: //! 2. Zones are emptied sl@0: //! 3. Zones are emptied sl@0: //! 4. The values written to the fixed pages have not changed. sl@0: //! 5. Zones are emptied sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestMovingPages() sl@0: { sl@0: const TInt KAllChunks = -1; // Specifies that all chunks should be written to sl@0: sl@0: test.Start(_L("Test1: Whilst moving page, change the usage ")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: // Find a chunk that exists sl@0: TInt chunkIndex = gChunkArraySize1 - 1; sl@0: for (; chunkIndex >= 0 && gChunkArray1[chunkIndex].Handle() == NULL; chunkIndex--); sl@0: if (chunkIndex < 0) sl@0: { sl@0: test.Printf(_L("No chunks were allocated\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: WriteToChunk(gChunkArray1, gChunkArraySize1, chunkIndex); sl@0: sl@0: TInt r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: sl@0: TUint8* base = gChunkArray1[chunkIndex].Base(); sl@0: while (status.Int() == KRequestPending) sl@0: { sl@0: User::After(10000); sl@0: for (TInt8 k = 0; k < 10; k ++) sl@0: { sl@0: if (base == gChunkArray1[chunkIndex].Base() + gChunkArray1[chunkIndex].Size()) sl@0: { sl@0: base = gChunkArray1[chunkIndex].Base(); sl@0: } sl@0: *base++ = k; // write 0 - 9 to the chunk sl@0: } sl@0: } sl@0: sl@0: User::WaitForRequest(status); sl@0: r = status.Int(); sl@0: TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: test.Printf(_L("Correct return value\n")); sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Whilst moving page, change the contents of the page")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks); sl@0: sl@0: r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: sl@0: TUint8 startValue = 0; sl@0: while (status.Int() == KRequestPending) sl@0: { sl@0: User::After(10000); sl@0: WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks, startValue); sl@0: if (++startValue > 245) sl@0: { sl@0: startValue = 0; sl@0: } sl@0: } sl@0: sl@0: User::WaitForRequest(status); sl@0: r = status.Int(); sl@0: TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: test.Printf(_L("Correct return value\n")); sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Whilst moving page, read pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks, KChunkDefaultSize); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: WriteToChunk(gChunkArray1, gChunkArraySize1, KAllChunks); sl@0: sl@0: r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: sl@0: while (status.Int() == KRequestPending) sl@0: { sl@0: User::After(100000000); sl@0: ReadChunk(gChunkArray1, gChunkArraySize1); sl@0: } sl@0: sl@0: User::WaitForRequest(status); sl@0: r = status.Int(); sl@0: TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: test.Printf(_L("Correct return value\n")); sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test4: Allocate fixed pages and then perform a defrag")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: Ldd.AllocateFixedWrite(FILL_ALL_FIXED); sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: test.Printf(_L("defrag returns %d\n"), r); sl@0: sl@0: if (CheckZonesSwitchedOff() != EFalse) sl@0: { sl@0: test.Printf(_L("Fail: Zones were switched off when they shouldn't have been\n")); sl@0: CLEANUP(r = Ldd.FreeAllFixedPagesRead()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: r = Ldd.FreeAllFixedPagesRead(); sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Allocate discardable pages and then perform a defrag")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: TInt discardablePages; sl@0: sl@0: UpdateRamInfo(); sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: TESTDEBUG(test.Printf(_L("defrag returns %d\n"), r)); sl@0: sl@0: if (genSucceed && CheckZonesSwitchedOff() == EFalse) sl@0: { sl@0: test.Printf(_L("Fail: Zones were not switched off when they should have been\n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: ResetDPCache(); sl@0: sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestMovPgsDefrag sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0527 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the moving of pages in the defrag implmentation sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this perform a RAM defrag. sl@0: //! Now that all movable memory has now been moved and the relevant source sl@0: //! zones have been switched off, again attempt to perform a RAM defrag. sl@0: //! 2. Fragment the memory. Following this perform a RAM defrag and whilst sl@0: //! this is happening, continuously create more chunks. sl@0: //! 3. Set up memory so that there are a mix of movable and free pages in a low preference zone, with there sl@0: //! being movable pages in the higher preference zones. Following this call a general defrag sl@0: //! 4. Set up memory so that there are a mix of movable and free pages and a couple of free pages sl@0: //! in a low preference zone, with there being enough free pages in the higher preference zones for the sl@0: //! pages to be moved to. Following this call a general defrag sl@0: //! 5. Set up memory so that there is a fixed page and a movable page in an empty zone (testZone). Also ensure that sl@0: //! there are movable and free pages in more preferable zones than the test zone. Following this call a general sl@0: //! defrag sl@0: //! 6. Set up memory so that the mostPrefZone contains movable and free pages. Allocate 1 movable and 1 fixed sl@0: //! page into an empty zone (testZone). Following this call a general defrag. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Second defrag does not empty any zones sl@0: //! 2. No zones have been emptied sl@0: //! 3. Zones are emptied if the general defrag can succeed sl@0: //! 4. Defrag fills up the less preferable zones first sl@0: //! 5. movable pages are moved from the testZone sl@0: //! 6. testZone is not emptied sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestMovPgsDefrag() sl@0: { sl@0: TInt r = KErrNone; sl@0: sl@0: test.Start(_L("Test1: Performing a defrag twice")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling general defrag r = %d\n"), r)); sl@0: sl@0: r = VerifyMovDisAlloc(); sl@0: // The first defrag should empty zones if the general can succeed sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, memory is not laid out as expected\n"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: TESTDEBUG(test.Printf(_L("After calling general defrag again r = %d\n"), r)); sl@0: sl@0: // The second call to general defrag should have nothing further to do sl@0: if (r != KErrNone || CheckZonesSwitchedOff() != EFalse) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d, or zones have been switched off \n"), sl@0: r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: sl@0: test.Next(_L("Test2: Ensure new memory allocations can occur successfully during a general defrag")); sl@0: TestStart(); sl@0: sl@0: // Create a thread to call Defrag continuously and resume it sl@0: r = gTestThread.Create(gTestThreadName,MultiLoopGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: gTestLoop = ETrue; sl@0: gTestThread.Resume(); sl@0: sl@0: // Whilst the defrag loop is taking place, continuously allocate and free memory sl@0: for (TInt i = 0; i < 100; i++) sl@0: { sl@0: r = AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: if (r != KErrNone) sl@0: break; sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: } sl@0: gTestLoop = EFalse; sl@0: User::WaitForRequest(status); sl@0: TESTDEBUG(test.Printf(_L("defrag running on another thread returns %d\n"), r)); sl@0: sl@0: if (r != KErrNone || status.Int() != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, status.Int() = %d\n"), r, status.Int()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: gTestThread.Close(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Check whether RAM defrag switches off any zones")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: TESTDEBUG(test.Printf(_L("After calling zone defrag r = %d\n"), r)); sl@0: sl@0: if (r != KErrNone || (genSucceed && CheckZonesSwitchedOff() == EFalse)) sl@0: { sl@0: test.Printf(_L("Fail: No zones were switched off or r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test4: Verify that a general defrag moves pages to the least preferable RAM zone in use")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: // Get the preference order sl@0: GetPrefOrder(); sl@0: sl@0: TUint mostPrefIndex = 0; sl@0: TUint mostPrefArrayIndex = 0; sl@0: TUint totMov = 0; sl@0: TUint lastPrefIndex = 0; sl@0: TUint lastPrefArrayIndex = 0; sl@0: TUint movPages = 0; sl@0: TUint movBytes = 0; sl@0: TUint totFreeInTestZones = 0; sl@0: TBool zoneNotEmptyOrFull = EFalse; sl@0: sl@0: sl@0: // Find the first most pref zone that has free pages in it sl@0: r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: // Find the next most preferable free zone sl@0: lastPrefArrayIndex = mostPrefArrayIndex + 1; sl@0: sl@0: while (lastPrefArrayIndex < gZoneCount && sl@0: gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iFreePages != gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iPhysPages) sl@0: { sl@0: lastPrefArrayIndex++; sl@0: } sl@0: sl@0: if (lastPrefArrayIndex >= gZoneCount) sl@0: { sl@0: test.Printf(_L("Skipping...\n")); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: // Block all other zones sl@0: for (TUint prefIndex = lastPrefArrayIndex + 1; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: Ldd.SetZoneFlag(gZoneConfigArray[zoneIndex].iZoneId, gZoneConfigArray[zoneIndex].iFlags, NO_ALLOC_FLAG); sl@0: } sl@0: sl@0: sl@0: // Zone alloc to fill half of the last zone under test sl@0: GetAllPageInfo(); sl@0: lastPrefIndex = gPrefArray[lastPrefArrayIndex]; sl@0: r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[lastPrefIndex].iZoneId, gZoneUtilArray[lastPrefIndex].iFreePages >> 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate fixed pages r = %d - Skipping...\n"), r); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: sl@0: // Go through the zones under test and determine the number of free pages sl@0: GetAllPageInfo(); sl@0: for(TUint prefIndex = mostPrefArrayIndex; prefIndex <= lastPrefArrayIndex; prefIndex++) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: totFreeInTestZones += gZoneUtilArray[zoneIndex].iFreePages; sl@0: } sl@0: sl@0: // Allocate movable pages to almost fill zones under test sl@0: movPages = totFreeInTestZones; sl@0: movBytes = movPages << gPageShift; sl@0: while (movBytes && AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes) != KErrNone) sl@0: { sl@0: movBytes -= gPageSize; sl@0: movPages--; sl@0: } sl@0: if (!movBytes) sl@0: { sl@0: test.Printf(_L("Failed to allocate 0x%x movable pages - Skipping...\n"), movPages); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: sl@0: // Free the allocated fixed pages sl@0: Ldd.FreeAllFixedPages(); sl@0: sl@0: // Reset all the flags sl@0: ResetRamZoneFlags(); sl@0: sl@0: // Check that the most preferable zone still has movable pages in it sl@0: // and also check that the last zone under test has free pages in it sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iMovablePages < movPages || sl@0: gZoneUtilArray[mostPrefIndex].iAllocMovable == 0 || sl@0: gZoneUtilArray[lastPrefIndex].iFreePages == 0) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping...\n")); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: // Check that defrag allocated the movable from the less preferable to the more preferable sl@0: GetPrefOrder(); sl@0: totMov = gTotalPageCount.iMovablePages; sl@0: for(TInt prefIndex = gZoneCount - 1; prefIndex >= 0 ; prefIndex--) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: GetCandList1(zoneIndex); sl@0: TUint candIndex = 0; sl@0: for (; candIndex < gZoneCount; candIndex++) sl@0: {// Check all the zones of this preference sl@0: TInt zoneIndexCand = gCandList1[candIndex]; sl@0: if (zoneIndexCand == KInvalidCandIndex) sl@0: { sl@0: break; sl@0: } sl@0: totMov -= gZoneUtilArray[zoneIndexCand].iAllocMovable; sl@0: if (gZoneUtilArray[zoneIndexCand].iFreePages != gZoneUtilArray[zoneIndexCand].iPhysPages && sl@0: gZoneUtilArray[zoneIndexCand].iFreePages != 0) sl@0: { sl@0: zoneNotEmptyOrFull = ETrue; sl@0: } sl@0: } sl@0: prefIndex -= candIndex - 1 ; sl@0: sl@0: if (zoneNotEmptyOrFull && totMov != 0) sl@0: { sl@0: test.Printf(_L("FAIL: index = %d free = 0x%x totMov = 0x%x\n"), sl@0: zoneIndex, gZoneUtilArray[zoneIndex].iFreePages, totMov); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: sl@0: skipTest4: sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test5: Verify that a general defrag tidies up if RAM zone to be emptied contains fixed pages")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: gChunkArray2 = new RChunk; sl@0: gChunkArraySize2 = 1; sl@0: sl@0: // find 2 empty zones - put 1 movable in 1 of them and 1 movable and 1 fixed in the other sl@0: TUint testZoneIndex1; sl@0: TUint testZoneIndex2; sl@0: TUint testZoneID2; sl@0: TUint numFreeInUse = 0; sl@0: sl@0: r = FindMostPrefEmpty(testZoneIndex1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Skipping...\n")); sl@0: goto skipTest5; sl@0: } sl@0: // Allocate 1 movable page to the test zone sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, testZoneIndex1, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 movable page to zone index %d, r = %d - Skipping...\n"), testZoneIndex1, r); sl@0: goto skipTest5; sl@0: } sl@0: sl@0: r = FindMostPrefEmpty(testZoneIndex2); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Skipping...\n")); sl@0: goto skipTest5; sl@0: } sl@0: // Allocate 1 movable page to the test zone sl@0: r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, testZoneIndex2, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 movable page to zone index %d, r = %d - Skipping...\n"), testZoneIndex2, r); sl@0: goto skipTest5; sl@0: } sl@0: sl@0: // Zone alloc to put 1 fixed page last zone under test sl@0: testZoneID2 = gZoneConfigArray[testZoneIndex2].iZoneId; sl@0: r = Ldd.ZoneAllocContiguous(testZoneID2, gPageSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 fixed page to zone %d index, r = %d - Skipping...\n"), testZoneIndex2, r); sl@0: goto skipTest5; sl@0: } sl@0: sl@0: // Allocate 2 fixed (as there is 1 in our test zone) to prevent reordering sl@0: GetAllPageInfo(); sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: TUint totImmovable = gZoneUtilArray[index].iAllocFixed + gZoneUtilArray[index].iAllocUnknown ; sl@0: if (index != testZoneIndex1 && sl@0: index != testZoneIndex2 && sl@0: gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && sl@0: totImmovable < 2) sl@0: { sl@0: r = Ldd.ZoneAllocToMany(index, 2 - totImmovable); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Skipping...\n"), sl@0: 2, index, r); sl@0: goto skipTest5; sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Check that the number of free pages in the other in-use zones >= movable pages in test zone sl@0: GetAllPageInfo(); sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (index != testZoneIndex1 && sl@0: index != testZoneIndex2 && sl@0: gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages) sl@0: { sl@0: numFreeInUse += gZoneUtilArray[index].iFreePages; sl@0: } sl@0: } sl@0: if (gZoneUtilArray[testZoneIndex1].iAllocMovable + gZoneUtilArray[testZoneIndex1].iAllocDiscardable + sl@0: gZoneUtilArray[testZoneIndex2].iAllocMovable + gZoneUtilArray[testZoneIndex2].iAllocDiscardable > numFreeInUse || sl@0: gZoneUtilArray[testZoneIndex2].iAllocFixed == 0) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping...\n")); sl@0: goto skipTest5; sl@0: } sl@0: sl@0: // Added extra tracing to debug random failures sl@0: PrintPageInfo(); sl@0: sl@0: // Call a general defrag sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: // Check that the defrag tidies up sl@0: GetAllPageInfo(); sl@0: if(gZoneUtilArray[testZoneIndex1].iAllocMovable || sl@0: gZoneUtilArray[testZoneIndex2].iAllocMovable) sl@0: { sl@0: test.Printf(_L("FAIL: testZoneIndex1(%d): mov orig 0x%x cur 0x%x, testZoneIndex2(%d) mov orig 0x%x cur 0x%x \n"), sl@0: testZoneIndex1, gOriginalPageCountArray[testZoneIndex1].iAllocMovable, gZoneUtilArray[testZoneIndex1].iAllocMovable, sl@0: testZoneIndex2, gOriginalPageCountArray[testZoneIndex2].iAllocMovable, gZoneUtilArray[testZoneIndex2].iAllocMovable); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: skipTest5: sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test6: Verify that a general defrag will not move pages if RAM zone to be emptied contains fixed pages")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: // Find the first most pref zone that has free pages in it sl@0: r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping...\n")); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: // Find the next most preferable free zone sl@0: lastPrefArrayIndex = mostPrefArrayIndex + 1; sl@0: while (lastPrefArrayIndex < gZoneCount && sl@0: gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iFreePages != gZoneUtilArray[gPrefArray[lastPrefArrayIndex]].iPhysPages) sl@0: { sl@0: lastPrefArrayIndex++; sl@0: } sl@0: if (lastPrefArrayIndex >= gZoneCount) sl@0: { sl@0: test.Printf(_L("Skipping...\n")); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: sl@0: // Zone alloc to put 1 fixed page last zone under test sl@0: lastPrefIndex = gPrefArray[lastPrefArrayIndex]; sl@0: r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[lastPrefIndex].iZoneId, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 fixed page to zone index %d r = %d - Skipping...\n"), lastPrefIndex, r); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: if (!gZoneUtilArray[mostPrefIndex].iFreePages) sl@0: { sl@0: test.Printf(_L("Not enough space in zone under test mostPrefIndex = %d - Skipping...\n"), mostPrefIndex); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: // Block all zones apart from the last zone under test from allocation sl@0: for (TUint prefIndex = 0; prefIndex < gZoneCount; prefIndex++) sl@0: { sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: if (zoneIndex != lastPrefIndex) sl@0: { sl@0: Ldd.SetZoneFlag(gZoneConfigArray[zoneIndex].iZoneId, gZoneConfigArray[zoneIndex].iFlags, NO_ALLOC_FLAG); sl@0: } sl@0: } sl@0: sl@0: TESTDEBUG(test.Printf(_L("mostPrefIndex = %d lastPrefIndex = %d\n"), mostPrefIndex, lastPrefIndex)); sl@0: sl@0: // Allocate movable pages to the lastPrefZone that will fit into the most pref zone sl@0: movPages = gZoneUtilArray[mostPrefIndex].iFreePages; sl@0: movBytes = movPages << gPageShift; sl@0: while (movBytes && AllocMovable(gChunkArray1, gChunkArraySize1, 1, movBytes) != KErrNone) sl@0: { sl@0: movBytes -= gPageSize; sl@0: } sl@0: if (!movBytes) sl@0: { sl@0: test.Printf(_L("Failed to allocate 0x%x movable pages r = %d - Skipping...\n"), movPages, r); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: // Reset all the flags sl@0: ResetRamZoneFlags(); sl@0: sl@0: sl@0: // Check that the number of movable pages in the least pref will fit sl@0: // into the most preferable zone sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[lastPrefIndex].iAllocMovable > gZoneUtilArray[mostPrefIndex].iFreePages) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping...\n")); sl@0: PrintPageInfo(); sl@0: goto skipTest6; sl@0: } sl@0: sl@0: // Added extra tracing to debug random failures sl@0: PrintPageInfo(); sl@0: sl@0: // Call a general defrag sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: // Check that the defrag didn't move any pages from the least pref zone sl@0: GetAllPageInfo(); sl@0: if(gOriginalPageCountArray[lastPrefIndex].iAllocMovable > gZoneUtilArray[lastPrefIndex].iAllocMovable) sl@0: { sl@0: test.Printf(_L("FAIL: mostPref(index %d): origMov = 0x%x curMov = 0x%x, lastPref(index %d): origMov = 0x%x curMov = 0x%x \n"), sl@0: mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, sl@0: lastPrefIndex, gOriginalPageCountArray[lastPrefIndex].iAllocMovable, gZoneUtilArray[lastPrefIndex].iAllocMovable); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: skipTest6: sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: // sl@0: // GenDefragTest123Setup sl@0: // sl@0: // Used to set up the memory ready for testing in TestGenDefrag, Test Steps 1, 2, 3 and 4 sl@0: // sl@0: // @param aMovAlloc The number of movable pages to allocate. sl@0: // @param aFixAlloc The number of fixed pages to allocate. sl@0: // @param aDisAlloc The number of discardable pages to allocate. sl@0: // @param aMovIndex On return contains the test zone index. sl@0: // @param aNumFreeInUse On return contains the number of free pages in the inuse zones. sl@0: // @param aTestNo The test number that is using this setup. sl@0: // sl@0: TInt GenDefragTest123Setup(TUint aMovAlloc, TUint aFixAlloc, TUint aDisAlloc, TUint& aMovIndex, TUint& aNumFreeInUse, TUint aTestNo) sl@0: { sl@0: TInt r = KErrNone; sl@0: aNumFreeInUse = 0; sl@0: const TUint KFillUpTo = 5; // Rough estimate of how full the in-use zones should be sl@0: const TUint KSpaceNeeded = 2; sl@0: TUint movPrefIndex = 0; sl@0: if (aTestNo == 4) sl@0: {// Test 4 we need to look for the LEAST preferable RAM zone which is empty sl@0: TUint mostPrefIndex; sl@0: r = FindLeastPrefEmpty(aMovIndex, &movPrefIndex); sl@0: TInt r2 = FindMostPrefEmpty(mostPrefIndex); sl@0: if (r != KErrNone || r2 != KErrNone || !gPagedRom || sl@0: gZoneConfigArray[aMovIndex].iPref == gZoneConfigArray[mostPrefIndex].iPref) sl@0: { sl@0: test.Printf(_L("r %d r2 %d or not a paged ROM or Equal zone preferences- Skipping test step...\n"), sl@0: r, r2); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: else sl@0: {// All other tests look the MOST preferable RAM zone which is empty sl@0: r = FindMostPrefEmpty(aMovIndex, &movPrefIndex); sl@0: if (r != KErrNone || !gPagedRom) sl@0: { sl@0: test.Printf(_L("No suitable RAM zone found or not a paged ROM - Skipping test step...\n")); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: // Go through all the in-use zones and check how many free pages there are sl@0: // Allocate fixed so there is only KFillUpTo pages in each in-use zone to sl@0: // ensure that the total number of free pages in the in-use zones can fit into sl@0: // the zone under test sl@0: GetAllPageInfo(); sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && sl@0: gZoneUtilArray[index].iFreePages > KFillUpTo) sl@0: { sl@0: r = Ldd.ZoneAllocToMany(index, gZoneUtilArray[index].iFreePages - KFillUpTo); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Ending setup...\n"), sl@0: gZoneUtilArray[index].iFreePages - KFillUpTo, index, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: // If any of the in-use zones doesn't contain any fixed and unknown pages allocate one fixed sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && sl@0: !gZoneUtilArray[index].iAllocFixed && !gZoneUtilArray[index].iAllocUnknown) sl@0: { sl@0: r = Ldd.ZoneAllocToMany(index, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to alloc 0x%x fixed to zone index %d r = %d - Ending setup...\n"), sl@0: 1, index, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: // Check the total number of free pages in the in-use zones sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages) sl@0: { sl@0: aNumFreeInUse += gZoneUtilArray[index].iFreePages; sl@0: } sl@0: } sl@0: TESTDEBUG(test.Printf(_L("aNumFreeInUse = 0x%x\n"), aNumFreeInUse)); sl@0: sl@0: test.Printf(_L("aMovIndex = %d\n"), aMovIndex); sl@0: if (aNumFreeInUse < KSpaceNeeded) sl@0: { sl@0: test.Printf(_L("RAM zone to be tested is too full - Skipping test step...\n")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: sl@0: // Ensure that there are movable pages in the zone under test sl@0: // ensuring that there is also room for discardable pages sl@0: GetAllPageInfo(); sl@0: if (aMovAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocMovable == 0) sl@0: { sl@0: // Allocate just aMovAlloc movable pages sl@0: TUint movPagesAlloc = aMovAlloc; sl@0: if (aTestNo == 2 || aTestNo == 4) sl@0: {// Tests 2 and 4 require that movable pages can't be moved from zone sl@0: movPagesAlloc = aNumFreeInUse + 1; sl@0: if (movPagesAlloc > gZoneUtilArray[aMovIndex].iFreePages) sl@0: { sl@0: test.Printf(_L("Insufficiant space in zone %d to allocate 0x%x pages - Ending setup...\n"), sl@0: aMovIndex, movPagesAlloc); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, aMovIndex, movPagesAlloc); sl@0: if (gZoneUtilArray[aMovIndex].iAllocMovable != movPagesAlloc || sl@0: gZoneUtilArray[aMovIndex].iFreePages == 0 || sl@0: r != KErrNone) sl@0: {// Movable page didn't go into RAM, or RAM zone is full. sl@0: test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); sl@0: test.Printf(_L("zone mov 0x%x free 0x%x r=%d\n"), sl@0: gZoneUtilArray[aMovIndex].iAllocMovable, sl@0: gZoneUtilArray[aMovIndex].iFreePages, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: // Block all other zones from allocation sl@0: for(TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (i != aMovIndex) sl@0: { sl@0: r = Ldd.SetZoneFlag(gZoneConfigArray[i].iZoneId, gZoneConfigArray[i].iFlags, NO_ALLOC_FLAG); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set flag on zone index %d r = %d- Ending setup...\n"), i, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Now ensure that there are fixed pages in the zone under test sl@0: // ensuring that there is also room for discardable pages sl@0: GetAllPageInfo(); sl@0: if (aFixAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocFixed == 0) sl@0: {//Allocate just aFixAlloc fixed pages sl@0: r = Ldd.ZoneAllocToMany(aMovIndex, aFixAlloc); sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[aMovIndex].iAllocMovable == 0 || sl@0: gZoneUtilArray[aMovIndex].iFreePages == 0 || sl@0: gZoneUtilArray[aMovIndex].iAllocFixed == 0 || sl@0: r != KErrNone) sl@0: {// Fixed page didn't go into RAM or RAM zone is full. sl@0: test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); sl@0: test.Printf(_L("zone mov 0x%x fixed 0x%x free 0x%x r=%d\n"), sl@0: gZoneUtilArray[aMovIndex].iAllocMovable, sl@0: gZoneUtilArray[aMovIndex].iAllocFixed, sl@0: gZoneUtilArray[aMovIndex].iFreePages, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: // Allocate aDisAlloc number of discardable pages sl@0: if (aDisAlloc != 0 && gZoneUtilArray[aMovIndex].iAllocDiscardable == 0) sl@0: {//Allocate just aDisAlloc discardable pages sl@0: TInt discard; sl@0: r = ZoneAllocDiscard(aMovIndex, aDisAlloc, discard); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || gZoneUtilArray[aMovIndex].iAllocDiscardable == 0) sl@0: {// Discardable page didn't go into RAM or RAM zone is full. sl@0: test.Printf(_L("Can't complete test with current RAM layout. - Skipping...\n")); sl@0: test.Printf(_L("zone mov 0x%x discardable 0x%x free 0x%x r=%d\n"), sl@0: gZoneUtilArray[aMovIndex].iAllocDiscardable, sl@0: gZoneUtilArray[aMovIndex].iAllocFixed, sl@0: gZoneUtilArray[aMovIndex].iFreePages, r); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: // Update the total number of free pages in the in-use zones sl@0: aNumFreeInUse = 0; sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && sl@0: index != aMovIndex) sl@0: { sl@0: aNumFreeInUse += gZoneUtilArray[index].iFreePages; sl@0: } sl@0: } sl@0: TESTDEBUG(test.Printf(_L("aNumFreeInUse = 0x%x\n"), aNumFreeInUse)); sl@0: sl@0: // now reset all the flags sl@0: ResetRamZoneFlags(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: // sl@0: // TestGenDefrag sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0528 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying general scenarios when RAM defrag would take place sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Allocate 1 movable, 1 fixed and 1 discardable pages into the most preferable empty RAM zone sl@0: //! ensuring that there is enough free space in the more preferable RAM zones for the sl@0: //! movable pages in the RAM zone under test. Following this call a general defrag. sl@0: //! 2. Allocate 1 movable and 1 discardable page into into the most preferable empty RAM zone sl@0: //! ensuring that there is not enough free space in the more preferable RAM zones for the sl@0: //! movable pages in the RAM zone under test. Following this call a general defrag. sl@0: //! 3. Allocate 1 movable and 1 discardable and 1 fixed page into the most preferable empty RAM zone(a). sl@0: //! Following this, place 1 movable page in an empty zone(b) ensuring that there is enough free space in sl@0: //! the more preferable RAM zones for the movable pages in both zones (a) and (b). sl@0: //! Following this call a general defrag. sl@0: //! 4. Allocate 1 movable and 1 discardable page into the least preferable empty RAM zone sl@0: //! ensuring that there is not enough free space in the more preferable RAM zones for the sl@0: //! movable pages in the RAM zone under test. Following this call a general defrag. sl@0: //! 5. Fragment the memory. sl@0: //! Following this allocate discardable pages by loading pages that are demand paged. sl@0: //! Read each of the constants from beginning to end. sl@0: //! Following this perform a RAM defrag. sl@0: //! 6. Call a device driver that will continuously allocate fixed pages to the sl@0: //! memory until it reports out of memory. Following this perform a RAM defrag. sl@0: //! 7. Defrag memory filled with discardable pages when the min cache size is reached sl@0: //! 8. Fragment the memory. Following this, continuously call a general defrag, each time sl@0: //! reducing the size of the chunks that are allocated sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The RAM zone under test is not emptied and all the discardable pages contained in it sl@0: //! have not been discarded. sl@0: //! 2. The RAM zone under test is not emptied and all the discardable pages contained in it sl@0: //! have not been discarded. sl@0: //! 3. RAM zones (a) and (b) have been emptied and all the discardable pages contained in them sl@0: //! have not been discarded. sl@0: //! 4. The RAM zone under test is emptied sl@0: //! 5. Pages are discarded sl@0: //! 6. No zones are emptied sl@0: //! 7. The least preferable zone is skipped but the other zones are defragmented as required. sl@0: //! 8. Zones are emptied if the general defrag can succeed sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestGenDefrag() sl@0: { sl@0: TInt r = KErrNone; sl@0: sl@0: test.Start(_L("Test1: Test General Defrag doesn't discard pages when fixed page in zone to be emptied")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: TUint numFreeInUse = 0; sl@0: TUint testNo = 1; sl@0: sl@0: // We just need 1 movable, 1 discardable and 1 fixed in the zone to ensure it cannot be emptied sl@0: // as the fixed should block the defrag sl@0: TInt movAllocPages = 1; sl@0: TInt fixAllocPages = 1; sl@0: TInt disAllocPages = 1; sl@0: TUint zoneIndex; sl@0: sl@0: if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping..\n")); sl@0: goto skipTest1; sl@0: } sl@0: sl@0: // Call a general defrag and check that no discardable pages were freed. sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndex].iAllocMovable < gOriginalPageCountArray[zoneIndex].iAllocMovable || sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable > gZoneUtilArray[zoneIndex].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, sl@0: gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: skipTest1: sl@0: // TestEnd() will perform any required clean up. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test2: Test General Defrag doesn't discard pages when zone can't be emptied")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: testNo++; sl@0: // No fixed, but there should be no space for the movable to go to sl@0: // GenDefragTest123Setup(), will ensure that this is the case sl@0: // by allocating 1 more movable page than there is free in the in-use zones sl@0: movAllocPages = 1; sl@0: fixAllocPages = 0; sl@0: disAllocPages = 1; sl@0: sl@0: if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping..\n")); sl@0: goto skipTest2; sl@0: } sl@0: sl@0: // Call a general defrag and check that no discardable pages were freed. sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndex].iAllocMovable < gOriginalPageCountArray[zoneIndex].iAllocMovable || sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable > gZoneUtilArray[zoneIndex].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, sl@0: gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: skipTest2: sl@0: // TestEnd() will perform any required clean up. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test3: Test General Defrag tidies when fixed page in zone to be emptied but other can be emptied")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: gChunkArray2 = new RChunk; sl@0: gChunkArraySize2 = 1; sl@0: TUint totalToMove; sl@0: testNo++; sl@0: sl@0: // First use GenDefragTest123Setup() to ensure we place 1 fixed, 1 movable and 1 discardable sl@0: // in the least preferable zone sl@0: movAllocPages = 1; sl@0: fixAllocPages = 1; sl@0: disAllocPages = 1; sl@0: TBool zoneFound = EFalse; sl@0: TUint emptyZoneIndex = 0; sl@0: sl@0: if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping..\n")); sl@0: goto skipTest3; sl@0: } sl@0: sl@0: // Find an empty zone and place a movable page in it sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gZoneUtilArray[i].iFreePages == gZoneUtilArray[i].iPhysPages) sl@0: { sl@0: zoneFound = ETrue; sl@0: emptyZoneIndex = i; sl@0: break; sl@0: } sl@0: } sl@0: if (!zoneFound) sl@0: { sl@0: test.Printf(_L("Can't find empty zone - Skipping..\n")); sl@0: goto skipTest3; sl@0: } sl@0: sl@0: // Allocate 1 movable page into the empty zone sl@0: r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, emptyZoneIndex, 1); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[emptyZoneIndex].iAllocMovable == 0 || sl@0: gZoneUtilArray[emptyZoneIndex].iAllocFixed != 0) sl@0: { sl@0: test.Printf(_L("Movable pages not allocated or fixed pages allocated. - Skipping...\n")); sl@0: test.Printf(_L("zone mov 0x%x free 0x%x r =% d\n"), sl@0: gZoneUtilArray[emptyZoneIndex].iAllocMovable, sl@0: gZoneUtilArray[emptyZoneIndex].iFreePages, r); sl@0: goto skipTest3; sl@0: } sl@0: sl@0: // Check that the amount we are allocating can actually be moved into the in-use zones sl@0: totalToMove = gZoneUtilArray[zoneIndex].iAllocMovable + gZoneUtilArray[zoneIndex].iAllocDiscardable + sl@0: gZoneUtilArray[emptyZoneIndex].iAllocMovable + gZoneUtilArray[emptyZoneIndex].iAllocDiscardable; sl@0: sl@0: // Check the total number of free pages in the in-use zones sl@0: numFreeInUse = 0; sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages != gZoneUtilArray[index].iPhysPages && sl@0: index != zoneIndex && index != emptyZoneIndex) sl@0: { sl@0: numFreeInUse += gZoneUtilArray[index].iFreePages; sl@0: } sl@0: } sl@0: if(numFreeInUse < totalToMove) sl@0: { sl@0: test.Printf(_L("No space to move pages numFreeInUse = 0x%x totalToMove = 0x%x - Skipping..\n"), sl@0: numFreeInUse, totalToMove); sl@0: goto skipTest3; sl@0: } sl@0: sl@0: // Call a general defrag and check that zone is emptied. sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndex].iAllocMovable || sl@0: gZoneUtilArray[zoneIndex].iAllocDiscardable || sl@0: gZoneUtilArray[emptyZoneIndex].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, sl@0: gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: skipTest3: sl@0: // TestEnd() will perform any required clean up. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test4: Test General Defrag moves pages into the next most pref if they don't fit into the most pref")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: testNo++; sl@0: sl@0: // No fixed, but there should be no space for the movable to go to sl@0: // GenDefragTest123Setup(), will ensure that this is the case sl@0: // by allocating 1 more movable page than there is free in the in-use zones sl@0: movAllocPages = 1; sl@0: fixAllocPages = 0; sl@0: disAllocPages = 1; sl@0: sl@0: if (GenDefragTest123Setup(movAllocPages, fixAllocPages, disAllocPages, zoneIndex, numFreeInUse, testNo) != KErrNone) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping..\n")); sl@0: goto skipTest4; sl@0: } sl@0: sl@0: // Call a general defrag and check that the test zone is emptied. sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndex].iFreePages != gZoneUtilArray[zoneIndex].iPhysPages) sl@0: { sl@0: test.Printf(_L("Fail: r = %d zoneIndex %d origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), r, zoneIndex, sl@0: gOriginalPageCountArray[zoneIndex].iAllocMovable, gZoneUtilArray[zoneIndex].iAllocMovable, sl@0: gOriginalPageCountArray[zoneIndex].iAllocDiscardable, gZoneUtilArray[zoneIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: skipTest4: sl@0: // TestEnd() will perform any required clean up. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Defrag memory filled with discardable pages\n")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TInt discardablePages; sl@0: UpdateRamInfo(); sl@0: sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else if (genSucceed && CheckZonesSwitchedOff() == EFalse) sl@0: { sl@0: test.Printf(_L("No Zones Switched off and should have been\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: ResetDPCache(); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test6: Defrag memory filled with fixed pages")); sl@0: TestStart(); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Filling memory with fixed pages, r = %d\n"))); sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: sl@0: // The zones should be full of fixed pages so the general should do nothing. sl@0: if (r != KErrNone || sl@0: genSucceed || sl@0: CheckZonesSwitchedOff()) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d, or zone have been emptied\n"), r, KErrNone); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test7: Defrag memory filled with discardable pages when the min cache size is reached\n")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TInt discardablePages; sl@0: UpdateRamInfo(); sl@0: sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("Number of discardable pages = 0x%x\n"), discardablePages >> gPageShift)); sl@0: sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: sl@0: TUint setMin = maxCacheSize; sl@0: TUint64 setMax = maxCacheSize; sl@0: TInt r = DPTest::SetCacheSize(setMin, setMax); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: TESTDEBUG(test.Printf(_L("After SetCacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x\n"), sl@0: setMin >> gPageShift, setMax >> gPageShift)); sl@0: sl@0: GetOriginalPageCount(); sl@0: genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else if (genSucceed && CheckZonesSwitchedOff() == EFalse) sl@0: { sl@0: test.Printf(_L("No Zones Switched off and should have been\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: ResetDPCache(); sl@0: sl@0: sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test8: Defrag fragmented memory for various smaller chunk sizes")); sl@0: TInt chunkSize = 0x80000; sl@0: while (chunkSize >= 0x4000) sl@0: { sl@0: test.Printf(_L("chunkSize = %dKB\n"), chunkSize/1024); sl@0: TestStart(); sl@0: r = AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, chunkSize, EFalse); sl@0: r = FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else if (genSucceed && CheckZonesSwitchedOff() == EFalse) sl@0: { sl@0: test.Printf(_L("No Zones Switched off and should have been\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: chunkSize = chunkSize>>1; sl@0: } sl@0: sl@0: test.Next(_L("Test9: Defrag fragmented memory ")); sl@0: TestStart(); sl@0: sl@0: r = AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); sl@0: r = FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetOriginalPageCount(); sl@0: genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"),r,KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else if (genSucceed && CheckZonesSwitchedOff() == EFalse) sl@0: { sl@0: test.Printf(_L("No Zones Switched off and should have been\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestGetRamZonePageCount sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0529 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the implementation of the function GetRamZonePageCount() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this, call GetRamZonePageCount() on every zone and verify sl@0: //! the values with the test HAL functions. sl@0: //! 2. Fragment the memory. Following this, call function with an valid aID sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //! 2. KErrArgument sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestGetRamZonePageCount() sl@0: { sl@0: test.Start(_L("Test1: Call GetRamZonePageCount() on every zone one after the other")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: GetAllPageInfo(); sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: STestUserSidePageCount pageData; sl@0: TInt r = Ldd.PageCount(zoneID, &pageData); sl@0: TESTDEBUG(test.Printf(_L("Page count function r = %d\n"), r)); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (pageData.iFreePages != gZoneUtilArray[index].iFreePages || sl@0: pageData.iFixedPages != gZoneUtilArray[index].iAllocFixed || sl@0: pageData.iMovablePages != gZoneUtilArray[index].iAllocMovable || sl@0: pageData.iDiscardablePages != gZoneUtilArray[index].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("RAM zone page count does not match test HAL page count, Zone %d\n"), zoneID); sl@0: test.Printf(_L("PgCnt: free = 0x%x, fixed = 0x%x, movable= 0x%x, discard = 0x%x\n"), sl@0: pageData.iFreePages, pageData.iFixedPages, pageData.iMovablePages, pageData.iDiscardablePages); sl@0: test.Printf(_L("HalFunc: free = 0x%x, fixed = 0x%x, movable= 0x%x, discard = 0x%x\n"), sl@0: gZoneUtilArray[index].iFreePages, gZoneUtilArray[index].iAllocFixed, sl@0: gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Zone %d Passed...\n"), zoneID); sl@0: } sl@0: TESTDEBUG(test.Printf(_L("iFreePages = 0x%x, iFixedPages = 0x%x, iMovablePages = 0x%x, iDiscardablePages = 0x%x\n"), sl@0: pageData.iFreePages, pageData.iFixedPages, pageData.iMovablePages, pageData.iDiscardablePages)); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test2: Call GetRamZonePageCount() with an invalid aID ")); sl@0: TestStart(); sl@0: sl@0: TUint zoneID = KInvalidZoneID; sl@0: STestUserSidePageCount pageData; sl@0: TInt r = Ldd.PageCount(zoneID, &pageData); sl@0: TESTDEBUG(test.Printf(_L("Page count function r = %d\n"), r)); sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: const TUint KIndex2Alloc = 10; sl@0: const TUint KTestMaxPages = 6; sl@0: sl@0: // sl@0: // DefragMaxPagesSetup sl@0: // sl@0: // Arranges the memory layout in preparation for TestDefragRamMaxPages() sl@0: // sl@0: // WARNING THIS WILL BE UNRELIABLE IF aMaxPages > KIndex2Alloc sl@0: // sl@0: TInt DefragMaxPagesSetup(TInt aPageType, TUint aMaxPages, TUint& aIndex, TUint& aIndex2) sl@0: { sl@0: TInt r = KErrNoMemory; sl@0: sl@0: // Get the preference order and determine the 2 most preferable zones sl@0: // that are currently not in use. sl@0: GetPrefOrder(); sl@0: TUint freeInUsePages = 0; sl@0: TBool zonesFound = EFalse; sl@0: for (TUint i = 1; i < gZoneCount; i++) sl@0: { sl@0: aIndex = gPrefArray[i]; sl@0: aIndex2 = gPrefArray[i-1]; sl@0: TUint indexFree = gZoneUtilArray[aIndex].iFreePages; sl@0: TUint index2Free = gZoneUtilArray[aIndex2].iFreePages; sl@0: if (indexFree == gZoneUtilArray[aIndex].iPhysPages && sl@0: index2Free == gZoneUtilArray[aIndex2].iPhysPages && sl@0: indexFree >= aMaxPages && index2Free >= KIndex2Alloc && sl@0: freeInUsePages >= KIndex2Alloc + aMaxPages) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: freeInUsePages += index2Free; sl@0: } sl@0: sl@0: // Could suitable RAM zones be found. sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Insufficient memory - Skipping test...\n")); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: if (aPageType == BEST_MOVABLE) sl@0: { sl@0: // Allocate KIndex2Alloc movable pages to aIndex2 sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, aIndex2, KIndex2Alloc); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Insufficient memory - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: sl@0: sl@0: // Now allow movable pages to be allocated into the least preferable RAM zone under test only. sl@0: GetAllPageInfo(); sl@0: if (aMaxPages >= gZoneUtilArray[aIndex].iFreePages) sl@0: { sl@0: test.Printf(_L("Insufficient memory available - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: // Allocate aMaxPages movable pages to aIndex sl@0: r = ZoneAllocMovable(gChunkArray2, gChunkArraySize2, aIndex, aMaxPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Insufficient memory - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: // Determine how many free pages there are in the RAM zones more preferable sl@0: // than the RAM zones under test. sl@0: GetPrefOrder(); sl@0: freeInUsePages = 0; sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: TUint tmpIndex = gPrefArray[i]; sl@0: if (tmpIndex == aIndex2) sl@0: break; sl@0: freeInUsePages += gZoneUtilArray[tmpIndex].iFreePages; sl@0: } sl@0: // Verify that the RAM layout is still suitable for the test. sl@0: if (gZoneUtilArray[aIndex].iAllocMovable != aMaxPages || sl@0: gZoneUtilArray[aIndex2].iAllocMovable != KIndex2Alloc || sl@0: gZoneUtilArray[aIndex].iAllocDiscardable || gZoneUtilArray[aIndex].iAllocFixed || sl@0: gZoneUtilArray[aIndex2].iAllocDiscardable || gZoneUtilArray[aIndex2].iAllocFixed || sl@0: freeInUsePages < KIndex2Alloc + aMaxPages) sl@0: { sl@0: test.Printf(_L("Insufficient memory - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: // now reset all the flags sl@0: ResetRamZoneFlags(); sl@0: sl@0: // Perform a general defrag sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, KTestMaxPages); sl@0: goto exit; sl@0: } sl@0: sl@0: if (aPageType == BEST_DISCARDABLE) sl@0: { sl@0: sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift); sl@0: sl@0: sl@0: sl@0: // Allocate a number of discardable pages to the 2nd least preferable zone under test sl@0: TInt disPages; sl@0: r = ZoneAllocDiscard(aIndex2, KIndex2Alloc, disPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("ZoneAllocDiscard() r = %d KIndex2Alloc = 0x%x disPages = 0x%x aIndex2 = %d - Skipping test...\n"), sl@0: r, KIndex2Alloc, disPages, aIndex2); sl@0: GetAllPageInfo(); sl@0: PrintPageInfo(); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: TUint discFillBytes = KIndex2Alloc << gPageShift; sl@0: r = DPTest::SetCacheSize(currentCacheSize + discFillBytes, currentCacheSize + discFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("SetCacheSize r = 0x%x currentCacheSize + discFillBytes = 0x%x - Skipping test...\n"), sl@0: r, currentCacheSize + discFillBytes); sl@0: GetAllPageInfo(); sl@0: PrintPageInfo(); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: sl@0: // Allocate a discardable pages equal to aMaxPages to the least preferable zone under test sl@0: GetAllPageInfo(); sl@0: if(aMaxPages >= gTotalPageCount.iFreePages) sl@0: { sl@0: test.Printf(_L("Insufficient memory available - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: TUint allocPages = aMaxPages + KIndex2Alloc; sl@0: r = ZoneAllocDiscard(aIndex, aMaxPages, disPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("ZoneAllocDiscard() r = %d aMaxPages = 0x%x disPages = 0x%x aIndex = %d - Skipping test...\n"), sl@0: r, aMaxPages, disPages, aIndex); sl@0: GetAllPageInfo(); sl@0: PrintPageInfo(); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: discFillBytes = allocPages << gPageShift; sl@0: r = DPTest::SetCacheSize(currentCacheSize + discFillBytes, currentCacheSize + discFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("SetCacheSize r = %d currentCacheSize + discFillBytes = 0x%x - Skipping test...\n"), sl@0: r, currentCacheSize + discFillBytes); sl@0: GetAllPageInfo(); sl@0: PrintPageInfo(); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: sl@0: // Determine how many free pages there are in the RAM zones more preferable sl@0: // than the RAM zones under test. sl@0: GetPrefOrder(); sl@0: freeInUsePages = 0; sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: TUint tmpIndex = gPrefArray[i]; sl@0: if (tmpIndex == aIndex2) sl@0: break; sl@0: freeInUsePages += gZoneUtilArray[tmpIndex].iFreePages; sl@0: } sl@0: // Verify that the RAM layout is still suitable for the test. sl@0: if (r != KErrNone || gZoneUtilArray[aIndex].iAllocDiscardable != aMaxPages || sl@0: gZoneUtilArray[aIndex2].iAllocDiscardable != KIndex2Alloc || sl@0: gZoneUtilArray[aIndex].iAllocMovable || gZoneUtilArray[aIndex].iAllocFixed || sl@0: gZoneUtilArray[aIndex2].iAllocMovable || gZoneUtilArray[aIndex2].iAllocFixed || sl@0: freeInUsePages < KIndex2Alloc + aMaxPages) sl@0: { sl@0: test.Printf(_L("Insufficient memory - Skipping test...\n")); sl@0: r = KErrNoMemory; sl@0: goto error; sl@0: } sl@0: sl@0: // now reset all the flags sl@0: ResetRamZoneFlags(); sl@0: sl@0: // Perform a general defrag with maxPages = KTestMaxPages sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, KTestMaxPages); sl@0: goto exit; sl@0: sl@0: } sl@0: error: sl@0: // Reset all the flags sl@0: ResetRamZoneFlags(); sl@0: exit: sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // TestDefragRamMaxPages sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0530 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::DefragRam() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Call function with invalid aMaxPages sl@0: //! 2. Call DefragRam when aMaxPages < number of movable pages in least preferable zone sl@0: //! 3. Call DefragRam when aMaxPages > number of movable pages in least preferable zone sl@0: //! 4. Call DefragRam when aMaxPages = number of movable pages in least preferable zone sl@0: //! 5. Call DefragRam when aMaxPages < number of discardable pages in least preferable zone sl@0: //! 6. Call DefragRam when aMaxPages > number of discardable pages in least preferable zone sl@0: //! 7. Call DefragRam when aMaxPages = number of discardable pages in least preferable zone sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrArgument sl@0: //! 2. Least preferable zone and 2nd least preferable zone have not been emptied sl@0: //! 3. Least preferable zone has been emptied and 2nd least preferable zone has not been emptied sl@0: //! 4. Least preferable zone has been emptied and 2nd least preferable zone not not been emptied sl@0: //! 5. Least preferable zone and 2nd least preferable zone have not been emptied sl@0: //! 6. Least preferable zone has been emptied and 2nd least preferable zone has not been emptied sl@0: //! 7. Least preferable zone has been emptied and 2nd least preferable zone not not been emptied sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestDefragRamMaxPages() sl@0: { sl@0: test.Start(_L("Test1: Call DefragRam with invalid aMaxPages ")); sl@0: TestStart(); sl@0: sl@0: gDefragMaxPages = -1; sl@0: sl@0: TInt r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: TESTDEBUG(test.Printf(_L("After calling defrag r = %d\n"), r)); sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test2: Call DefragRam aMaxPages < number of movable pages in least preferable zone ")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: gChunkArray2 = new RChunk; sl@0: gChunkArraySize2 = 1; sl@0: TUint index = 0; sl@0: TUint index2 = 0; sl@0: r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages + 1, index, index2); sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable < KTestMaxPages + 1 || sl@0: gZoneUtilArray[index2].iAllocMovable < KIndex2Alloc) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, KTestMaxPages + 1, index2, KIndex2Alloc); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: // if there is free space elsewhere sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages + 1 && sl@0: (gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call DefragRam aMaxPages > number of movable pages in least preferable zone ")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: gChunkArray2 = new RChunk; sl@0: gChunkArraySize2 = 1; sl@0: r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages - 1, index, index2); sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable != 0) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, KIndex2Alloc); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: // if there is free space elsewhere sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages - 1 && sl@0: (gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test4: Call DefragRam aMaxPages = number of movable pages in least preferable zone ")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: gChunkArray2 = new RChunk; sl@0: gChunkArraySize2 = 1; sl@0: r = DefragMaxPagesSetup(BEST_MOVABLE, KTestMaxPages, index, index2); sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable != 0) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, KIndex2Alloc); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: // if there is free space elsewhere sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iFreePages > KIndex2Alloc + KTestMaxPages && sl@0: (gZoneUtilArray[index].iAllocMovable != 0 || gZoneUtilArray[index2].iAllocMovable != 0)) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray2, gChunkArraySize2)); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: RemoveChunkAlloc(gChunkArray2, gChunkArraySize2); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Call DefragRam aMaxPages < number of discardable pages in least preferable zone ")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages + 1, index, index2); sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable < KTestMaxPages + 1 || sl@0: gZoneUtilArray[index2].iAllocDiscardable < KIndex2Alloc) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, KTestMaxPages + 1, index2, KIndex2Alloc); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0 || sl@0: gZoneUtilArray[index2].iAllocDiscardable != 0) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: ResetDPCache(); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a Paged Rom - Skipping...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test6: Call DefragRam aMaxPages > number of discardable pages in least preferable zone ")); sl@0: TestStart(); sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages - 1, index, index2); sl@0: sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0|| sl@0: gZoneUtilArray[index2].iAllocDiscardable != KIndex2Alloc) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, KIndex2Alloc); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0|| sl@0: gZoneUtilArray[index2].iAllocDiscardable != 0) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: ResetDPCache(); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a Paged Rom - Skipping...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test4: Call DefragRam aMaxPages = number of discardable pages in least preferable zone ")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DefragMaxPagesSetup(BEST_DISCARDABLE, KTestMaxPages, index, index2); sl@0: sl@0: if (gZoneUtilArray[index].iAllocFixed > 0 || gZoneUtilArray[index2].iAllocFixed > 0) sl@0: {// Cannot perform test with fixed pages in least preferable zones sl@0: test.Printf(_L("Fixed pages in least preferable zone - Skipping...\n")); sl@0: } sl@0: else sl@0: { sl@0: if (r == KErrNone) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0|| sl@0: gZoneUtilArray[index2].iAllocDiscardable != KIndex2Alloc) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, KIndex2Alloc); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Double check that if DefragRam is called with maxPages = 0, these zones are emptied sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0|| sl@0: gZoneUtilArray[index2].iAllocDiscardable != 0) sl@0: { sl@0: test.Printf(_L("Fail: index = %d, expected = 0x%x, index2 = %d, expected = 0x%x\n"), sl@0: index, 0, index2, 0); sl@0: CLEANUP(ResetDPCache()); sl@0: CLEANUP(Ldd.FreeFromAllZones()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("DefragMaxPagesSetup failed r = %d\n"), r); sl@0: } sl@0: ResetDPCache(); sl@0: } sl@0: Ldd.FreeFromAllZones(); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a Paged Rom - Skipping...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestEmptyRamZone sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0531 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::EmptyRamZone() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Call function with a valid aID, sl@0: //! i.e. a zone which lies within the range of zones. sl@0: //! 2. Fragment the memory. Call function with an invalid aID sl@0: //! i.e. a zone which does not exist within the range of zones. sl@0: //! 3. Fragment the memory. Following this, call a zone specific defrag on a particular zone. sl@0: //! Call the zone specific defrag again on the same zone whilst the other defrag is still sl@0: //! running on that zone. sl@0: //! 4. Fragment the memory. Following this, call the TRamDefragRequest::DefragRam() to perform general defrag. sl@0: //! Following this call zone specific defrag whilst the general defrag is still running. sl@0: //! 5. Fragment the memory. Following this, call a zone specific defrag on a particular zone. sl@0: //! Whilst the zone defrag is running, call a general defrag sl@0: //! 6: Fragment the memory. Following this, call the function on specifc zone and sl@0: //! at the same time allocate pages to the zone sl@0: //! 7. Fragment the memory. Call EmptyRamZone() on every zone one after the other. sl@0: //! 8. Fragment the memory. Allocate a couple of fixed pages to a zone that contains movable pages. sl@0: //! Following this, Call EmptyRamZone() on that zone. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //! 2. KErrArgument sl@0: //! 3. KErrNone and the zone has been emptied sl@0: //! 4. Zone has not been emptied, as the general defrag has already placed pages in the zone sl@0: //! 5. Zone has been emptied sl@0: //! 6. KErrNone and pages have been allocated in the zone sl@0: //! 7. One of the following scenarios should occur: sl@0: //! a. If the cache has not reached its minimum size, then all the movable pages should sl@0: //! be moved from the zone if there are enough free pages in the other zones. sl@0: //! However, when demand paging is off, all movable pages should be moved from the zone, again if there sl@0: //! are enough free pages in the other zones. sl@0: //! b. If the current size of the cache minus the number of discardable pages in the zone being emptied is sl@0: //! not less than the minimum cache size, then all the discardable pages should be discarded of. sl@0: //! However, when demand paging is off, all discardable pages should be removed from sl@0: //! the zone. sl@0: //! 8. KErrNoMemory, however all movable and discardable pages have been moved from the zone sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestEmptyRamZone() sl@0: { sl@0: TInt r = KErrNone; sl@0: TInt r2 = KErrNone; sl@0: sl@0: test.Start(_L("Test1: Call EmptyRamZone with valid aID ")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: TUint defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: test.Printf(_L("Zone ID = %d\n"), defragZoneID); sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && (r != KErrNone || !CheckZoneIsOff(index))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call EmptyRamZone with invalid aID ")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: defragZoneID = KInvalidZoneID; sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call EmptyRamZone twice at the same time ")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny *)defragZoneID); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: sl@0: User::After(10); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (r != r2 || sl@0: (freeInOthers && (r != KErrNone || r2 != KErrNone || !CheckZoneIsOff(index)))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone %d has not been emptied\n"), sl@0: r, r2, KErrNone, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test4: Call general defrag and zone defrag at the same time ")); sl@0: TestStart(); sl@0: sl@0: TInt waitTime = 10000; sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && gZoneUtilArray[index].iAllocFixed > 0) sl@0: { sl@0: index--; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && gZoneUtilArray[index].iAllocFixed > 0) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: sl@0: gTestThread.Resume(); sl@0: User::After(waitTime); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Zone defrag running on main thread\n"))); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (r2 != KErrNone || sl@0: (freeInOthers && (r != KErrNone || !CheckZoneIsOff(index)))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone %d is on unexpectedly\n"), sl@0: r, r2, KErrNone, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test5: Call zone defrag and general defrag at the same time ")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: sl@0: gTestThread.Resume(); sl@0: User::After(0); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Zone defrag running on main thread\n"))); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, gDefragMaxPages); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (r != KErrNone || sl@0: (freeInOthers && (r2 != KErrNone || !CheckZoneIsOff(index)))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone 0x%x is on unexpectedly\n"), sl@0: r, r2, KErrNone, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test6: Call function TRamDefragRequest::EmptyRamZone on specifc zone and at the same time allocate pages to the zone")); sl@0: TestStart(); sl@0: sl@0: TInt pagesAlloc = 1; // Try and allocate just one page whilst trying to empty the zone. sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TInt numPassed = 0; sl@0: for (waitTime = 1000; waitTime > 0; waitTime-=10) sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: gTestThread.Logon(status); sl@0: sl@0: gTestThread.Resume(); sl@0: User::After(waitTime); sl@0: sl@0: r = Ldd.ZoneAllocDiscontiguous(defragZoneID, pagesAlloc); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: if (r2 != KErrNone) sl@0: { sl@0: test.Printf(_L("Empty was unsuccsessful: r2 = %d, expected = %d\n"), r2, KErrNone); sl@0: } sl@0: else if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d, r2 = %d, expected = %d, zone = 0x%x\n"), sl@0: r, KErrNone, r2, KErrNone, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: numPassed ++; sl@0: } sl@0: sl@0: Ldd.FreeAllFixedPages(); sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: if (numPassed > 0) sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test7: Call function TRamDefragRequest::EmptyRamZone on every zone one after the other")); sl@0: TestStart(); sl@0: sl@0: Ldd.ResetDriver(); sl@0: sl@0: for (index = 0; index < gZoneCount; index ++) sl@0: { sl@0: // Variables for DP ROM cache sizes sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: // Calculate the maximum size available for the DP cache. sl@0: TUint minZoneFree = KMaxTUint; sl@0: TUint maxDisFillBytes = 0; sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: maxDisFillBytes += gZoneUtilArray[i].iFreePages; sl@0: maxDisFillBytes += gZoneUtilArray[i].iAllocDiscardable; sl@0: if (minZoneFree > gZoneUtilArray[i].iFreePages) sl@0: minZoneFree = gZoneUtilArray[i].iFreePages; sl@0: } sl@0: test.Printf(_L("Free pages 0x%x maxDisFillBytes 0x%x\n"), gTotalPageCount.iFreePages, maxDisFillBytes); sl@0: maxDisFillBytes <<= gPageShift; sl@0: sl@0: r = DPTest::SetCacheSize(maxDisFillBytes, maxDisFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("CacheSize2: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: if (currentCacheSize != maxDisFillBytes) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: test.Printf(_L("Free pages after alloc discardable1 = 0x%x\n"), gTotalPageCount.iFreePages); sl@0: sl@0: r = DPTest::SetCacheSize(minZoneFree << gPageShift, maxDisFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Check all zones have no free pages. sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gZoneUtilArray[i].iFreePages != 0) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Fragment the RAM with some movable pages sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: } sl@0: sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetAllPageInfo(); sl@0: TUint origUnknownInZone = gZoneUtilArray[index].iAllocUnknown; sl@0: TUint origMovInZone = gZoneUtilArray[index].iAllocMovable; sl@0: TUint origFreeInZone = gZoneUtilArray[index].iFreePages; sl@0: sl@0: test.Printf(_L("Zone ID 0x%x - fixedPages = 0x%x, unknownPages = 0x%x, discardablePages = 0x%x movable = 0x%x free = 0x%x\n"), sl@0: zoneID, gZoneUtilArray[index].iAllocFixed, origUnknownInZone, gZoneUtilArray[index].iAllocDiscardable, sl@0: origMovInZone, origFreeInZone); sl@0: sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint unknownPages = gZoneUtilArray[index].iAllocUnknown; sl@0: TUint discPages = gZoneUtilArray[index].iAllocDiscardable; sl@0: TUint movablePages = gZoneUtilArray[index].iAllocMovable; sl@0: sl@0: TUint freeInOtherZones = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if(movablePages && freeInOtherZones) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x all the movable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (origUnknownInZone != unknownPages) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x unknown pages before and after are not equal\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (!gPagedRom) sl@0: { sl@0: if (discPages && freeInOtherZones) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x all the discardable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: DPTest::CacheSize(minCacheSize, maxCacheSize, currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("CacheSize3: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: // The the discardable pages should have been discarded or moved unless sl@0: // there is no room in the other zones and the cache size is already at its minimum sl@0: if (discPages && (freeInOtherZones || currentCacheSize != minCacheSize)) sl@0: { sl@0: test.Printf(_L("Fail: Zone 0x%x all the discardable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: // TestEnd() willl cleanup what's required sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test8: Call function TRamDefragRequest::EmptyRamZone on a zone that contains fixed and movable pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("defragZoneID = 0x%x\n"), defragZoneID); sl@0: test.Printf(_L("movable = 0x%x discardable = 0x%x\n"), sl@0: gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable); sl@0: sl@0: sl@0: Ldd.ZoneAllocDiscontiguous(defragZoneID, 2); // Allocated 2 fixed pages to ensure that zone cannot be emptied sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (r != KErrNoMemory || sl@0: (freeInOthers && sl@0: (gZoneUtilArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocDiscardable))) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d, or all movable/discardable pages have not been moved"), sl@0: r, KErrNoMemory); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: sl@0: Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestClaimRamZone sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0532 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the implemntation of the function TRamDefragRequest::ClaimRamZone() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this, call function with a valid aID sl@0: //! 2. Fragment the memory. Following this, call function with an invalid aID sl@0: //! 3. Fragment the memory. Following this, start a zone defrag and whilst this sl@0: //! is running, call function on the same zone. sl@0: //! 4. Fragment the memory. Following this, start a general defrag and whilst this sl@0: //! is running, call function on the same zone. sl@0: //! 5. Fragment the memory. Following this, call ClaimRamZone() on a specific zone, whilst at the sl@0: //! same time calling ClaimRamZone() on another zone. sl@0: //! 6: Fragment the memory. Call function TRamDefragRequest::ClaimRamZone on specifc zone and at the sl@0: //! same time allocate pages to the zone sl@0: //! 7. Fragment the memory. Following this allocate fixed pages to a zone and attempt to claim sl@0: //! the zone. sl@0: //! 8. Fragment the memory. Following this call ClaimRamZone() on every zone, one after the other sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //! 2. KErrArgument sl@0: //! 3. KErrNone and the zone has been claimed sl@0: //! 4. KErrNone and the zone has been claimed sl@0: //! 5. KErrNone and both zones have been claimed sl@0: //! 6. KErrNoMemory sl@0: //! 7. KErrNoMemory, all movable and discardable pages have been moved sl@0: //! 8. One of the following scenarios should occur: sl@0: //! a. If the cache has not reached its minimum size and there are no unknown pages in sl@0: //! the zone, then all the movable pages should be moved from the zone if there are enough free pages sl@0: //! in the other zones. sl@0: //! However, when demand paging is off, all movable pages should be moved from the zone, again if there sl@0: //! are enough free pages in the other zones and if there are no unknown pages in the zone. sl@0: //! b. If the current size of the cache minus the number of discardable pages in the zone being emptied is not sl@0: //! less than the minimum cache size and there are no unknown pages in the zone, sl@0: //! then all the discardable pages should be discarded of. sl@0: //! However, when demand paging is off, all discardable pages should be removed from sl@0: //! the zone if there are no unknown pages in the zone. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestClaimRamZone() sl@0: { sl@0: TInt r = 0; sl@0: TInt r2 = 0; sl@0: TUint32 addr = 0; sl@0: TInt waitTime = 1000; sl@0: sl@0: test.Start(_L("Test1: Call function TRamDefragRequest::ClaimRamZone with a valid aID")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: TUint defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r != KErrNone && sl@0: gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) sl@0: { sl@0: test.Printf(_L("Fail: Zone 0x%x has not been claimed r %d expected %d\n"), defragZoneID, r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: addr = gZoneConfigArray[index].iPhysBase; sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call function TRamDefragRequest::ClaimRamZone with an invalid aID")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: defragZoneID = KInvalidZoneID; sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call function TRamDefragRequest::ClaimRamZone when a EmptyRamZone is already running")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TInt numPassed = 0; sl@0: for (waitTime = 1000; waitTime > 0; waitTime-=10) sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiEmptyZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: User::After(waitTime); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r != KErrNone && r2 != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, r2 = %d, expected = %d, or zone ID 0x%x has not been claimed\n"), sl@0: r, r2, KErrNone, defragZoneID); sl@0: if (r == KErrNone) sl@0: { sl@0: CLEANUP(r = Ldd.FreeAllFixedPages()); sl@0: } sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: numPassed ++; sl@0: } sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: if (numPassed > 0) sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test4: Call function TRamDefragRequest::ClaimRamZone when a general defrag is already running")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = gTestThread.Create(gTestThreadName,MultiGenDefragThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: User::After(waitTime); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("ClaimZone: r = %d, expected = %d\n"), r, KErrNone); sl@0: } sl@0: sl@0: if (r2 != KErrNone) sl@0: { sl@0: test.Printf(_L("General: r2 = %d, expected = %d\n"), r, KErrNone); sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID 0x%x has not been claimed, r = %d, r2 = %d, expected = %d\n"), sl@0: defragZoneID, r, r2, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: sl@0: test.Next(_L("Test5: Call function TRamDefragRequest::ClaimRamZone on specifc zone at the same time as calling on another zone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: test.Printf(_L("index = 0x%x "), index); sl@0: sl@0: TUint index2 = gZoneCount - 1; sl@0: while ( index2 > 0 && sl@0: (index == index2 || gZoneUtilArray[index2].iAllocFixed != 0 || gZoneUtilArray[index2].iAllocUnknown != 0)) sl@0: { sl@0: -- index2; sl@0: } sl@0: TUint defragZoneID2 = gZoneConfigArray[index2].iZoneId; sl@0: test.Printf(_L("index2 = %d\n"), index2); sl@0: sl@0: if ((index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) || sl@0: (index2 == 0 && (index == index2 || gZoneUtilArray[index2].iAllocFixed != 0 || gZoneUtilArray[index2].iAllocUnknown != 0))) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiClaimZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)(defragZoneID2)); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: User::After(waitTime); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: TUint freeInOthers2 = gTotalPageCount.iFreePages - gZoneUtilArray[index2].iFreePages; sl@0: if ((freeInOthers && r != KErrNone && sl@0: gZoneUtilArray[index].iAllocFixed != gZoneUtilArray[index].iPhysPages) || sl@0: (freeInOthers2 && r != KErrNone && sl@0: gZoneUtilArray[index2].iAllocFixed != gZoneUtilArray[index2].iPhysPages)) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID 0x%x or Zone ID 0x%x has not been claimed, r = %d, r2 = %d, expected = %d\n"), sl@0: defragZoneID, defragZoneID2, r, r2, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: if (r2 == KErrNone) sl@0: {// Have to free from specific address as RAM zone claimed by other channel. sl@0: addr = gZoneConfigArray[index2].iPhysBase; sl@0: r = Ldd.FreeFromAddr(gZoneUtilArray[index2].iAllocFixed, addr); sl@0: } sl@0: sl@0: gTestThread.Close(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test6: Call function TRamDefragRequest::ClaimRamZone on specifc zone and at the same time allocate pages to the zone")); sl@0: TestStart(); sl@0: sl@0: TInt pagesAlloc = 1; // Try and allocate just one page whilst attempting to claim the zone sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: GetAllPageInfo(); sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: TInt numPassed = 0; sl@0: for (waitTime = 1000; waitTime > 0; waitTime-=10) sl@0: { sl@0: r = gTestThread.Create(gTestThreadName,MultiClaimZoneThreadFunc,KDefaultStackSize,0x1000,0x1000,(TAny*)defragZoneID); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: gTestThread.Logon(status); sl@0: gTestThread.Resume(); sl@0: test(status.Int() == KRequestPending); sl@0: User::After(waitTime); sl@0: sl@0: r = Ldd.ZoneAllocDiscontiguous(defragZoneID, pagesAlloc); sl@0: sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: sl@0: User::WaitForRequest(status); sl@0: r2 = status.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r2 != KErrNone) sl@0: { sl@0: test.Printf(_L("Claim was unsuccsessful: r2 = %d, expected = %d\n"), r2, KErrNone); sl@0: } sl@0: else if (r2 == KErrNone && r != KErrNoMemory) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d, r2 = %d, expected = %d, zone ID = 0x%x\n"), sl@0: r, KErrNoMemory, r2, KErrNone, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: // Free from address as a different channel claimed the RAM zone. sl@0: addr = gZoneConfigArray[index].iPhysBase; sl@0: CLEANUP(Ldd.FreeFromAddr(gZoneUtilArray[index].iAllocFixed, addr)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: numPassed ++; sl@0: } sl@0: sl@0: Ldd.FreeAllFixedPages(); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r2 == KErrNone) sl@0: {// Free from address as a different channel claimed the RAM zone. sl@0: addr = gZoneConfigArray[index].iPhysBase; sl@0: r = Ldd.FreeFromAddr(gZoneUtilArray[index].iAllocFixed, addr); sl@0: } sl@0: gTestThread.Close(); sl@0: } sl@0: if (numPassed > 0) sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: sl@0: test.Next(_L("Test7: Call function TRamDefragRequest::ClaimRamZone on a zone that contains fixed and movable pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0) && sl@0: (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3)) sl@0: { sl@0: -- index; sl@0: } sl@0: sl@0: if (index == 0 && ((gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0) && sl@0: (gZoneUtilArray[index].iAllocMovable < 10 || gZoneUtilArray[index].iFreePages < 3))) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"), defragZoneID)); sl@0: TESTDEBUG(test.Printf(_L("movable = 0x%x discardable = 0x%x\n"), sl@0: gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocDiscardable)); sl@0: sl@0: sl@0: Ldd.ZoneAllocDiscontiguous(defragZoneID, 2); // Allocated 2 fixed pages to ensure that zone cannot be emptied sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, defragZoneID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (r != KErrNoMemory || sl@0: (freeInOthers && sl@0: (gZoneUtilArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocDiscardable))) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d, or all movable/discardable pages have not been moved"), sl@0: r, KErrNoMemory); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test8: Call function TRamDefragRequest::ClaimRamZone on every zone one after the other")); sl@0: TestStart(); sl@0: sl@0: Ldd.ResetDriver(); sl@0: sl@0: for (index = 0; index < gZoneCount; index ++) sl@0: { sl@0: // Variables for DP ROM cache sizes sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: // Calculate the maximum size of the DP cache sl@0: TUint minZoneFree = KMaxTUint; sl@0: TUint maxDisFillBytes = 0; sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: maxDisFillBytes += gZoneUtilArray[i].iFreePages; sl@0: maxDisFillBytes += gZoneUtilArray[i].iAllocDiscardable; sl@0: if (minZoneFree > gZoneUtilArray[i].iFreePages) sl@0: minZoneFree = gZoneUtilArray[i].iFreePages; sl@0: } sl@0: test.Printf(_L("Free pages 0x%x maxDisFillBytes 0x%x\n"), gTotalPageCount.iFreePages, maxDisFillBytes); sl@0: maxDisFillBytes <<= gPageShift; sl@0: sl@0: r = DPTest::SetCacheSize(maxDisFillBytes, maxDisFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("CacheSize2: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: if (currentCacheSize != maxDisFillBytes) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: test.Printf(_L("Free pages after alloc discardable1 = 0x%x\n"), gTotalPageCount.iFreePages); sl@0: sl@0: r = DPTest::SetCacheSize(minZoneFree << gPageShift, maxDisFillBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Check all zones have no free pages. sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gZoneUtilArray[i].iFreePages != 0) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Fragment the RAM with some movable pages sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: } sl@0: sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetAllPageInfo(); sl@0: TUint origUnknownInZone = gZoneUtilArray[index].iAllocUnknown; sl@0: TUint origMovInZone = gZoneUtilArray[index].iAllocMovable; sl@0: TUint origFreeInZone = gZoneUtilArray[index].iFreePages; sl@0: sl@0: test.Printf(_L("Zone ID 0x%x - fixedPages = 0x%x, unknownPages = 0x%x, discardablePages = 0x%x movable = 0x%x free = 0x%x\n"), sl@0: zoneID, gZoneUtilArray[index].iAllocFixed, origUnknownInZone, gZoneUtilArray[index].iAllocDiscardable, sl@0: origMovInZone, origFreeInZone); sl@0: sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint unknownPages = gZoneUtilArray[index].iAllocUnknown; sl@0: TUint discPages = gZoneUtilArray[index].iAllocDiscardable; sl@0: TUint movablePages = gZoneUtilArray[index].iAllocMovable; sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: TUint freeInOtherZones = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (!unknownPages && movablePages && freeInOtherZones) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x all the movable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (origUnknownInZone != unknownPages) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x unknown pages before and after are not equal\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: if (!gPagedRom) sl@0: { sl@0: if (!unknownPages && freeInOtherZones && discPages) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID %x all the discardable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: DPTest::CacheSize(minCacheSize, maxCacheSize, currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("CacheSize3: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: // The the discardable pages should have been discarded or moved unless sl@0: // there is no room in the other zones and the cache size is already at its minimum sl@0: if (!unknownPages && discPages && (freeInOtherZones || currentCacheSize != minCacheSize)) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID 0x%x all the discardable pages haven't been moved\n"), zoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: // TestEnd() will cleanup what's required. sl@0: TestEnd(); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestCancelDefrag sl@0: // sl@0: //----------------------------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0533 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the implementation of the function TRamDefragRequest::CancelDefrag() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this, start a general defrag and cancel it sl@0: //! 2. Fragment the memory. Following this, start a zone defrag and cancel it sl@0: //! 3. Fragment the memory. Following this, start a claim zone and cancel it sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrCancel sl@0: //! 2. KErrCancel sl@0: //! 3. KErrCancel sl@0: //----------------------------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestCancelDefrag() sl@0: { sl@0: TInt r = 0; sl@0: TUint defragZoneID = 0; sl@0: sl@0: test.Start(_L("Test1: Call general defrag and cancel it")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: r = Ldd.CheckCancel(DEFRAG_TYPE_GEN); sl@0: sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r != KErrCancel) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call zone defrag and cancel it")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && sl@0: (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || sl@0: gZoneUtilArray[index].iAllocFixed !=0 || sl@0: gZoneUtilArray[index].iAllocUnknown !=0)) sl@0: { sl@0: -- index; sl@0: } sl@0: if (index == 0 && sl@0: (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || sl@0: gZoneUtilArray[index].iAllocFixed !=0 || sl@0: gZoneUtilArray[index].iAllocUnknown !=0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"),defragZoneID)); sl@0: sl@0: r = Ldd.CheckCancel(DEFRAG_TYPE_EMPTY, defragZoneID); sl@0: sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r != KErrCancel) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call Claim RAM Zone and cancel it")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && sl@0: (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || sl@0: gZoneUtilArray[index].iAllocFixed !=0 || sl@0: gZoneUtilArray[index].iAllocUnknown !=0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: TESTDEBUG(test.Printf(_L("defragZoneID = 0x%x\n"),defragZoneID)); sl@0: sl@0: if (index == 0 && sl@0: (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || sl@0: gZoneUtilArray[index].iAllocFixed !=0 || sl@0: gZoneUtilArray[index].iAllocUnknown !=0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CheckCancel(DEFRAG_TYPE_CLAIM, defragZoneID); sl@0: sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r != KErrCancel) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrCancel); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: // sl@0: // TestZoneAllocNoAffect sl@0: // sl@0: // Ensures that fixed page allocations do not affect the movable sl@0: // or discardable page allocations sl@0: // sl@0: TInt TestZoneAllocNoAffect(TInt aZoneAllocType, TInt aPageType) sl@0: { sl@0: TInt retVal = KErrNone; sl@0: TInt r = KErrNone; sl@0: TInt mostPrefIndex = 0; sl@0: TUint leastPrefIndex = 0; sl@0: TUint leastPrefZoneID = 0; sl@0: sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: switch(aPageType) sl@0: { sl@0: case BEST_MOVABLE: sl@0: test.Printf(_L("Test Epoc::ZoneAllocPhysicalRam() doesn't affect the allocation of movable pages\n")); sl@0: break; sl@0: sl@0: case BEST_DISCARDABLE: sl@0: test.Printf(_L("Test Epoc::ZoneAllocPhysicalRam() doesn't affect the allocation of discardable pages\n")); sl@0: if (!gPagedRom) sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping...\n")); sl@0: goto skipSetup; sl@0: } sl@0: break; sl@0: } sl@0: // Fist find the zone that movable page allocations should go into sl@0: // Getting the best movable will be the same for discardable as well sl@0: mostPrefIndex = GetBestZone(aPageType); sl@0: if (mostPrefIndex == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: goto skipSetup; sl@0: } sl@0: sl@0: // Get the least pref zone to zone alloc into and ensure it has free pages sl@0: GetPrefOrder(); sl@0: leastPrefIndex = gPrefArray[gZoneCount - 1]; sl@0: if (gZoneConfigArray[mostPrefIndex].iPref == gZoneConfigArray[leastPrefIndex].iPref) sl@0: { sl@0: test.Printf(_L("Zones with same preference - Skipping...\n")); sl@0: goto skipSetup; sl@0: } sl@0: if (leastPrefIndex == (TUint)mostPrefIndex || sl@0: gZoneUtilArray[leastPrefIndex].iFreePages == 0) sl@0: { sl@0: test.Printf(_L("leastPrefIndex = mostPrefIndex or leastPrefIndex(%d) / mostPrefIndex(%d) has 0 free - Skipping test step...\n"), sl@0: leastPrefIndex, mostPrefIndex); sl@0: goto skipSetup; sl@0: } sl@0: sl@0: sl@0: // Zone alloc 1 fixed page into the least preferable zone sl@0: leastPrefZoneID = gZoneConfigArray[leastPrefIndex].iZoneId; sl@0: GetOriginalPageCount(); sl@0: switch(aZoneAllocType) sl@0: { sl@0: case Z_ALLOC_DISC: sl@0: { sl@0: r = Ldd.ZoneAllocDiscontiguous(leastPrefZoneID, 1); sl@0: break; sl@0: } sl@0: sl@0: case Z_ALLOC_CONTIG: sl@0: { sl@0: r = Ldd.ZoneAllocContiguous(leastPrefZoneID, gPageSize); sl@0: break; sl@0: } sl@0: } sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[leastPrefIndex].iAllocFixed <= gOriginalPageCountArray[leastPrefIndex].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 fixed page to zone index %d r = %d\n"), leastPrefIndex, r); sl@0: goto skipSetup; sl@0: } sl@0: test.Printf(_L("leastPrefIndex = %d mostPrefIndex = %d\n"), leastPrefIndex, mostPrefIndex); sl@0: switch(aPageType) sl@0: { sl@0: case BEST_MOVABLE: sl@0: // now allocate 1 movable page sl@0: r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, gPageSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 movable page r = %d\n"), r); sl@0: goto skipSetup; sl@0: } sl@0: break; sl@0: sl@0: case BEST_DISCARDABLE: sl@0: // now allocate 1 discardable page sl@0: TInt disPages; sl@0: TUint disBytes = (gTotalPageCount.iDiscardablePages + 1) << gPageShift; sl@0: r = AllocDiscardable(disPages, disBytes); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate 1 discardable page r = %d\n"), r); sl@0: goto skipSetup; sl@0: } sl@0: break; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: switch(aPageType) sl@0: { sl@0: case BEST_MOVABLE: sl@0: if (gOriginalPageCountArray[mostPrefIndex].iAllocMovable >= gZoneUtilArray[mostPrefIndex].iAllocMovable || sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocMovable < gZoneUtilArray[leastPrefIndex].iAllocMovable) sl@0: { sl@0: test.Printf(_L("FAIL: mostPrefIndex(%d) origMov 0x%x curMov 0x%x leastPrefIndex(%d) origMov 0x%x curMov 0x%x\n"), sl@0: mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, sl@0: leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: retVal = KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: break; sl@0: sl@0: sl@0: case BEST_DISCARDABLE: sl@0: if (gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable >= gZoneUtilArray[mostPrefIndex].iAllocDiscardable || sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable < gZoneUtilArray[leastPrefIndex].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("FAIL: mostPrefIndex(%d) origDis 0x%x curDis 0x%x leastPrefIndex(%d) origDis 0x%x curDis 0x%x\n"), sl@0: mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable, gZoneUtilArray[mostPrefIndex].iAllocDiscardable, sl@0: leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: retVal = KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: break; sl@0: } sl@0: sl@0: // This will clean up any fixed pages allocated. sl@0: skipSetup: sl@0: TestEnd(); sl@0: return retVal; sl@0: } sl@0: sl@0: // sl@0: // TestZoneAllocContiguous sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0535 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the contiguous overload of Epoc::ZoneAllocPhysicalRam(). sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Call function with a valid aZoneID. sl@0: //! 2. Call function with an invalid aZoneID sl@0: //! 3. Call function with aSize > zone size sl@0: //! 4. Call multiple RAM zone overload of the function with a mix of valid and invalid IDs. sl@0: //! 5. Call multiple RAM zone overload of the function with contiguous RAM zones and attempt sl@0: //! to allocate over both RAM zones. sl@0: //! 6. Call function on a RAM zone that has some non-DP pages allocated into it and ask sl@0: //! for the whole RAM zone to be filled with fixed pages. sl@0: //! 7. Get the most preferable zone for movable page allocations (mostPref). Allocate 1 contiguous fixed page sl@0: //! in the least preferable zone. Following this allocate 1 movable page sl@0: //! 8. Get the most preferable zone for discardable page allocations (mostPref). Allocate 1 contiguous fixed sl@0: //! page in the least preferable zone. Following this allocate 1 discardable page sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //! 2. KErrArgument sl@0: //! 3. KErrArgument sl@0: //! 4. KErrArgument sl@0: //! 5. KErrNone sl@0: //! 6. KErrNoMemory sl@0: //! 7. Movable pages are allocated into zone mostPref. sl@0: //! 8. Discardable pages are allocated into zone mostPref sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestZoneAllocContiguous() sl@0: { sl@0: TInt r = 0; sl@0: test.Start(_L("Test1: Call function Epoc::ZoneAllocPhysicalRam() with a valid aZoneID")); sl@0: TestStart(); sl@0: sl@0: const TUint KAllocPages = 2; sl@0: sl@0: GetOriginalPageCount(); sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) sl@0: { sl@0: -- index; sl@0: } sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: if (index == 0 && gZoneUtilArray[index].iFreePages < KAllocPages) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TUint allocBytes = KAllocPages << gPageShift; sl@0: r = Ldd.ZoneAllocContiguous(zoneID, allocBytes); sl@0: GetAllPageInfo(); sl@0: if (r == KErrNone && sl@0: gZoneUtilArray[index].iAllocFixed - gOriginalPageCountArray[index].iAllocFixed == KAllocPages) sl@0: { sl@0: test.Printf(_L("Pass: Correct number of fixed pages allocated to zone ID 0x%x\n"),zoneID); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d, or number of pages allocated is not expected\n"), sl@0: r, KErrNone); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: Ldd.FreeAllFixedPages(); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call function Epoc::ZoneAllocPhysicalRam() with an invalid aZoneID")); sl@0: TestStart(); sl@0: sl@0: zoneID = KInvalidZoneID; sl@0: sl@0: TESTDEBUG(test.Printf(_L("zoneID = 0x%x\n"), zoneID)); sl@0: sl@0: r = Ldd.ZoneAllocContiguous(zoneID, gPageSize); sl@0: GetAllPageInfo(); sl@0: if (r == KErrArgument) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call function Epoc::ZoneAllocPhysicalRam() with aSize > zone size")); sl@0: TestStart(); sl@0: sl@0: index = gZoneCount - 1; sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: TUint allocBytes = (gZoneUtilArray[index].iPhysPages + 5) << gPageShift; sl@0: sl@0: r = Ldd.ZoneAllocContiguous(zoneID, allocBytes); sl@0: GetAllPageInfo(); sl@0: if (r == KErrArgument) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: const TUint KMultiZoneIds = 10; sl@0: TUint* zoneIdArray = new TUint[KMultiZoneIds]; sl@0: test_NotNull(zoneIdArray); sl@0: sl@0: test.Next(_L("Test4: Test Epoc::ZoneAllocPhysicaRam() always fails when at least one ID is invalid")); sl@0: TestStart(); sl@0: sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) sl@0: { sl@0: -- index; sl@0: } sl@0: if (index == 0 && gZoneUtilArray[index].iFreePages < KAllocPages) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TUint zoneIdSize = 2; sl@0: zoneIdArray[0] = gZoneConfigArray[index].iZoneId; sl@0: zoneIdArray[1] = KInvalidZoneID; sl@0: TUint allocBytes = KAllocPages << gPageShift; sl@0: r = Ldd.MultiZoneAllocContiguous(zoneIdArray, zoneIdSize, allocBytes); sl@0: if (r != KErrArgument) sl@0: { sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Pass: Correct return value\n")); sl@0: } sl@0: } sl@0: sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Test Epoc::ZoneAllocPhysicalRam() can span multiple RAM zones")); sl@0: TestStart(); sl@0: // Attempt to find to physically contiguous RAM zones where higher addressed sl@0: // one is empty, relies on RAM zones are returned by HAL functions in sl@0: // ascending physical address order. sl@0: GetAllPageInfo(); sl@0: TBool zonesFound = EFalse; sl@0: index = gZoneCount - 1; sl@0: for (; index > 1; index--) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages && sl@0: gZoneUtilArray[index-1].iFreePages == gZoneUtilArray[index-1].iPhysPages && sl@0: gZoneConfigArray[index].iPhysBase - 1 == gZoneConfigArray[index-1].iPhysEnd) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Allocate one page more than the first RAM zone to force the allocation sl@0: // to spread over both RAM zones. sl@0: TUint allocPages = gZoneUtilArray[index-1].iPhysPages + 1; sl@0: TUint allocBytes = allocPages << gPageShift; sl@0: sl@0: // Attempt to find a zone that has less free pages than the allocation sl@0: // size so we can test that the method continues past too full RAM zones. sl@0: zonesFound = EFalse; sl@0: TUint noAllocZone = 0; sl@0: for (; noAllocZone < gZoneCount; noAllocZone++) sl@0: { sl@0: if (allocPages > gZoneUtilArray[noAllocZone].iFreePages && sl@0: noAllocZone != index && noAllocZone != index-1) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: TUint zoneIds = 2; sl@0: if (!zonesFound) sl@0: { sl@0: zoneIdArray[0] = gZoneConfigArray[index-1].iZoneId; sl@0: zoneIdArray[1] = gZoneConfigArray[index].iZoneId; sl@0: } sl@0: else sl@0: {// Have a zone that won't meet the allocation so use it sl@0: TESTDEBUG(test.Printf(_L("noAllocZone ID %x\n"), gZoneConfigArray[noAllocZone].iZoneId)); sl@0: zoneIds++; sl@0: zoneIdArray[0] = gZoneConfigArray[noAllocZone].iZoneId; sl@0: zoneIdArray[1] = gZoneConfigArray[index-1].iZoneId; sl@0: zoneIdArray[2] = gZoneConfigArray[index].iZoneId; sl@0: } sl@0: sl@0: r = Ldd.MultiZoneAllocContiguous(zoneIdArray, zoneIds, allocBytes); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[index].iFreePages == gZoneUtilArray[index].iPhysPages || sl@0: gZoneUtilArray[index-1].iFreePages == gZoneUtilArray[index-1].iPhysPages) sl@0: {// The allocation failed. sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: // TestEnd() will free the allocation of fixed pages. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test6: Test Epoc::ZoneAllocPhysicalRam() returns KErrNoMemory when appropriate")); sl@0: TestStart(); sl@0: // Attempt to find a RAM zone with some non-discarable pages allocated into it. sl@0: // (At time of writing discardable pages wouldn't be discarded on demand by sl@0: // this function but this may be changed in the future as discontiguous case does that). sl@0: GetAllPageInfo(); sl@0: zonesFound = EFalse; sl@0: index = gZoneCount - 1; sl@0: for (; index > 0; index--) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages && sl@0: (gZoneUtilArray[index].iAllocMovable || gZoneUtilArray[index].iAllocFixed)) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Attempt to allocate the whole of the RAM zone. sl@0: GetOriginalPageCount(); sl@0: TUint allocBytes = gZoneConfigArray[index].iPhysPages << gPageShift; sl@0: r = Ldd.ZoneAllocContiguous(gZoneConfigArray[index].iZoneId, allocBytes); sl@0: sl@0: // The allocation should have failed and no pages should have sl@0: // been allocated. sl@0: GetAllPageInfo(); sl@0: if (r != KErrNoMemory || sl@0: gOriginalPageCountArray[index].iFreePages > gZoneUtilArray[index].iFreePages) sl@0: { sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Pass: Correct return value\n")); sl@0: } sl@0: } sl@0: // TestEnd() will free the allocation of fixed pages. sl@0: TestEnd(); sl@0: delete[] zoneIdArray; sl@0: sl@0: sl@0: test.Next(_L("Test7: Test Epoc::ZoneAllocPhysicalRam() (Contiguous) doesn't affect the allocation of movable pages")); sl@0: r = TestZoneAllocNoAffect(Z_ALLOC_CONTIG, BEST_MOVABLE); sl@0: if (r != KErrNone) sl@0: { sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: test.Next(_L("Test8: Test Epoc::ZoneAllocPhysicalRam() (Contiguous) doesn't affect the allocation of discardable pages")); sl@0: r = TestZoneAllocNoAffect(Z_ALLOC_CONTIG, BEST_DISCARDABLE); sl@0: if (r != KErrNone) sl@0: { sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestZoneAllocDiscontiguous sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0536 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the discontiguous overload of Epoc::ZoneAllocPhysicalRam(). sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Call function with a valid aZoneID. sl@0: //! 2. Call function with an invalid aZoneID sl@0: //! 3. Call function with aNumPages > zone size sl@0: //! 4. Call multiple RAM zone overload of function with a mix of valid and invalid IDs sl@0: //! 5. Call multiple RAM zone overload of function so that the allocation will have to sl@0: //! span multiple RAM zones. sl@0: //! 6. Call function with memory full with DP cache that has reached it's sl@0: //! minimum cache size. sl@0: //! 7. Call function with memory not quite full with DP cache that has reached it's sl@0: //! minimum cache size and with the specified RAM zone full. sl@0: //! 8. Call function to allocate a whole RAM zone on a RAM zone that has non-discardable sl@0: //! pages already allocated into it. sl@0: //! 9. Call function to allocate one less than the whole RAM zone on a RAM zone that has movable sl@0: //! pages allocated. sl@0: //! 10. Get the most preferable zone for movable page allocations (mostPref). Allocate 1 discontiguous fixed page sl@0: //! in the least preferable zone. Following this allocate 1 movable page sl@0: //! 11. Get the most preferable zone for discardable page allocations (mostPref). Allocate 1 discontiguous fixed sl@0: //! page in the least preferable zone. Following this allocate 1 discardable page sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //! 2. KErrArgument sl@0: //! 3. KErrArgument sl@0: //! 4. KErrArgument sl@0: //! 5. KErrNone sl@0: //! 6. KErrNoMemory sl@0: //! 7. KErrNone sl@0: //! 8. KErrNoMemory sl@0: //! 9. KErrNone (i.e. the movable pages are shifted out of the way but only those that need to be moved). sl@0: //! 10. Movable pages are allocated into zone mostPref. sl@0: //! 11. Discardable pages are allocated into zone mostPref sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestZoneAllocDiscontiguous() sl@0: { sl@0: TInt r = KErrNone; sl@0: test.Start(_L("Test1: Call function Epoc::ZoneAllocPhysicalRam() with a valid aZoneID")); sl@0: TestStart(); sl@0: sl@0: const TUint KAllocPages = 5; sl@0: // Detemine how many extra pages the kernel heap may grow by sl@0: // as these may need to be accounted for. sl@0: TUint fixedOverhead = Ldd.GetAllocDiff(KAllocPages); sl@0: sl@0: GetOriginalPageCount(); sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && gZoneUtilArray[index].iFreePages < KAllocPages) sl@0: { sl@0: -- index; sl@0: } sl@0: sl@0: if (gZoneUtilArray[index].iFreePages < KAllocPages || gTotalPageCount.iFreePages < KAllocPages + fixedOverhead) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Allocate KAllocPages discontiguous fixed pages into RAM zone zoneID sl@0: // and verfiy that the pages were allocated to the correct zone, allow for sl@0: // extra fixed pages to be allocated as the kernel heap may grow. sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, KAllocPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if ((r == KErrNone) && sl@0: (gZoneUtilArray[index].iAllocFixed >= gOriginalPageCountArray[index].iAllocFixed + KAllocPages)) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call function Epoc::ZoneAllocPhysicalRam() with an invalid aZoneID")); sl@0: TestStart(); sl@0: sl@0: TUint zoneID = KInvalidZoneID; sl@0: sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, KAllocPages); sl@0: GetAllPageInfo(); sl@0: if (r == KErrArgument) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test3: Call function Epoc::ZoneAllocPhysicalRam() when aNumPages > zone size")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: TUint allocPages = gZoneUtilArray[index].iPhysPages + 1; sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, allocPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r == KErrArgument) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value and number of pages allocated is correct\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrArgument); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: const TUint KMultiZoneIds = 10; sl@0: TUint* zoneIdArray = new TUint[KMultiZoneIds]; sl@0: test_NotNull(zoneIdArray); sl@0: sl@0: test.Next(_L("Test4: Test Epoc::ZoneAllocPhysicaRam() always fails when at least one ID is invalid")); sl@0: TestStart(); sl@0: sl@0: TBool zonesFound = EFalse; sl@0: index = gZoneCount - 1; sl@0: for (; index > 0; index--) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages >= KAllocPages) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TUint zoneIdSize = 2; sl@0: zoneIdArray[0] = gZoneConfigArray[index].iZoneId; sl@0: zoneIdArray[1] = KInvalidZoneID; sl@0: r = Ldd.MultiZoneAllocDiscontiguous(zoneIdArray, zoneIdSize, KAllocPages); sl@0: if (r != KErrArgument) sl@0: {// Make sure we cleanup. sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Test Epoc::ZoneAllocPhysicalRam() can span multiple RAM zones")); sl@0: TestStart(); sl@0: zonesFound = EFalse; sl@0: TUint zonesCount = 0; sl@0: const TUint KTest5Zones = 2; sl@0: TUint zoneIndices[KTest5Zones]; sl@0: allocPages = 0; sl@0: sl@0: // Attempt to find KTest5Zones RAM zones with some free pages, sl@0: // search in reverse preference order to reduce chances of kernel heap pages sl@0: // being allocated into the RAM zones under test. sl@0: GetPrefOrder(); sl@0: index = gZoneCount - 1; sl@0: for (; index > 0; index--) sl@0: { sl@0: TUint prefIndex = gPrefArray[index]; sl@0: if (gZoneUtilArray[prefIndex].iFreePages != 0) sl@0: { sl@0: allocPages += gZoneUtilArray[prefIndex].iFreePages; sl@0: zoneIndices[zonesCount++] = prefIndex; sl@0: if (zonesCount == KTest5Zones) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Attempt to find a zone that has less free pages than the allocation sl@0: // size so we can test that the method continues past too full RAM zones. sl@0: zonesFound = EFalse; sl@0: TUint noAllocZone = 0; sl@0: for (; noAllocZone < gZoneCount; noAllocZone++) sl@0: { sl@0: if (allocPages > gZoneUtilArray[noAllocZone].iFreePages && sl@0: noAllocZone != zoneIndices[0] && noAllocZone != zoneIndices[1]) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (gPagedRom) sl@0: {// Fill memory with DP pages to test the allocation will discard sl@0: // pages when necessary. sl@0: TInt discard; sl@0: r = AllocDiscardable(discard); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndices[0]].iFreePages != 0 || sl@0: gZoneUtilArray[zoneIndices[1]].iFreePages != 0) sl@0: { sl@0: test.Printf(_L("r %d\n"), r); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: sl@0: TUint zoneIds = KTest5Zones; sl@0: if (!zonesFound) sl@0: { sl@0: zoneIdArray[0] = gZoneConfigArray[zoneIndices[0]].iZoneId; sl@0: zoneIdArray[1] = gZoneConfigArray[zoneIndices[1]].iZoneId; sl@0: } sl@0: else sl@0: {// Have a zone that won't meet the allocation so use it sl@0: TESTDEBUG(test.Printf(_L("noAllocZone ID %x\n"), gZoneConfigArray[noAllocZone].iZoneId)); sl@0: zoneIds++; sl@0: zoneIdArray[0] = gZoneConfigArray[noAllocZone].iZoneId; sl@0: zoneIdArray[1] = gZoneConfigArray[zoneIndices[0]].iZoneId; sl@0: zoneIdArray[2] = gZoneConfigArray[zoneIndices[1]].iZoneId; sl@0: } sl@0: sl@0: // Adjust the allocation size for any kernel heap pages that may be sl@0: // required as they may get allocated into the RAM zones under test. sl@0: allocPages -= Ldd.GetAllocDiff(allocPages); sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.MultiZoneAllocDiscontiguous(zoneIdArray, zoneIds, allocPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gZoneUtilArray[zoneIndices[0]].iAllocFixed <= gOriginalPageCountArray[zoneIndices[0]].iAllocFixed || sl@0: gZoneUtilArray[zoneIndices[1]].iAllocFixed <= gOriginalPageCountArray[zoneIndices[1]].iAllocFixed) sl@0: {// The allocation failed. sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: // TestEnd() will free the allocation of fixed pages. sl@0: TestEnd(); sl@0: sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: test.Next(_L("Test6: Test Epoc::ZoneAllocPhysicalRam() returns KErrNoMemory when DP minimum cache size is hit")); sl@0: TestStart(); sl@0: GetPrefOrder(); sl@0: TUint zoneFreePages = 0; sl@0: index = gZoneCount - 1; sl@0: for (; index > 0; index--) sl@0: { sl@0: TUint prefIndex = gPrefArray[index]; sl@0: zoneFreePages = gZoneUtilArray[prefIndex].iFreePages; sl@0: if (zoneFreePages > 2) sl@0: { sl@0: index = prefIndex; sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Fill the RAM with DP cache pages and up the minimum cache size so sl@0: // that the allocation will fail. sl@0: TInt discardBytes; sl@0: TInt r = AllocDiscardable(discardBytes, KMaxTUint64, (zoneFreePages - 1) << gPageShift); sl@0: test_KErrNone(r); sl@0: sl@0: // Ensure that the RAM zone under test is full. sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages != 0) sl@0: { sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[index].iZoneId, zoneFreePages); sl@0: sl@0: if (r != KErrNoMemory) sl@0: { sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test7: Test Epoc::ZoneAllocPhysicalRam() replaces DP cache when DP minimum cache size is hit")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: GetPrefOrder(); sl@0: zonesFound = EFalse; sl@0: for (index = gZoneCount - 1; index > 0 && !zonesFound; index--) sl@0: { sl@0: TUint prefIndex = gPrefArray[index]; sl@0: zoneFreePages = gZoneUtilArray[prefIndex].iFreePages; sl@0: if (zoneFreePages > 1) sl@0: { sl@0: // Check there is at least one free page in the other RAM zones. sl@0: TUint i = 0; sl@0: for (; i < gZoneCount; i++) sl@0: { sl@0: if (i != prefIndex && gZoneUtilArray[i].iFreePages != 0) sl@0: { sl@0: index = prefIndex; sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: index++; sl@0: // Attempt to allocate a movable page to create a gap for the DP cache sl@0: // page to be replaced with. sl@0: GetOriginalPageCount(); sl@0: r = AllocMovable(gChunkArray1, gChunkArraySize1, 1, gPageSize); sl@0: sl@0: GetAllPageInfo(); sl@0: TESTDEBUG(test.Printf(_L("index %d prev free 0x%x cur free 0x%x\n"), sl@0: index, gOriginalPageCountArray[index].iFreePages, gZoneUtilArray[index].iFreePages)); sl@0: sl@0: if (r != KErrNone || sl@0: gOriginalPageCountArray[index].iFreePages != gZoneUtilArray[index].iFreePages) sl@0: {// The gap was allocated into the RAM zone under test so can't continue as sl@0: // the DP cache will attempt to be reallocated into the same RAM zone. sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Get the ldd to create the array for the fixed page addresses here sl@0: // so that any kernel heap allocations have already occurred before sl@0: // memory is filled etc. Make allocation really large so it will always be enough. sl@0: r = Ldd.AllocFixedArray(50); sl@0: sl@0: // Fill RAM with DP cache pages and free the gap. sl@0: TInt discardBytes; sl@0: r = AllocDiscardable(discardBytes, KMaxTUint64, 0); sl@0: if (r != KErrNone) sl@0: { sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: UpdateRamInfo(); sl@0: TInt prevFreeBytes = gFreeRam; sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: UpdateRamInfo(); sl@0: TInt freedPages = (gFreeRam - prevFreeBytes) >> gPageShift; sl@0: if (freedPages < 1) sl@0: {// Something went wrong as should have freed at least one page sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: TUint extraFreePages = freedPages - 1; sl@0: sl@0: // Ensure that the RAM zone under test is full. sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages != 0) sl@0: { sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: // Allocate from the RAM zone which should force a DP cache sl@0: // page to be allocated. sl@0: GetOriginalPageCount(); sl@0: TUint fixedAllocPages = 1 + extraFreePages; sl@0: r = Ldd.ZoneAllocDiscontiguous2(gZoneConfigArray[index].iZoneId, fixedAllocPages); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gOriginalPageCountArray[index].iAllocFixed + fixedAllocPages != gZoneUtilArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("r %d index %d alloc 0x%x prevFixed 0x%x curFixed 0x%x\n"), r, index, fixedAllocPages, sl@0: gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocFixed); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: // This should cleanup any fixed pages allocated. sl@0: TestEnd(); sl@0: } sl@0: sl@0: test.Next(_L("Test8: Test Epoc::ZoneAllocPhysicalRam() return KErrNoMemory when appropriate")); sl@0: TestStart(); sl@0: // Search for a RAM zone that has some immovable pages allocated into sl@0: // it but isn't totally full. sl@0: GetAllPageInfo(); sl@0: zonesFound = EFalse; sl@0: for (index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iFreePages && sl@0: (gZoneUtilArray[index].iAllocUnknown || gZoneUtilArray[index].iAllocFixed)) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("Cannot find RAM zones to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: // Attempt to allocate the whole RAM zone. sl@0: r = Ldd.ZoneAllocDiscontiguous(gZoneConfigArray[index].iZoneId, gZoneUtilArray[index].iPhysPages); sl@0: sl@0: if (r != KErrNoMemory) sl@0: { sl@0: test.Printf(_L("FAIL: r %d index %d\n"), r, index); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test9: Test Epoc::ZoneAllocPhysicalRam() moves the required number of movable pages")); sl@0: TestStart(); sl@0: TUint allocFixedPages; sl@0: // Search for a RAM zone that has at least 2 movable pages allocated into it. sl@0: // Need 2 so that we can move one and leave one. sl@0: GetAllPageInfo(); sl@0: zonesFound = EFalse; sl@0: for (index = 0; index < gZoneCount; index++) sl@0: { sl@0: if (gZoneUtilArray[index].iAllocMovable > 1) sl@0: { sl@0: // Only use this zone if the other RAM zones have enough free space for sl@0: // the movable page in this zone to be moved to. sl@0: TUint freeInOther = 0; sl@0: for (TUint i = 0; i < gZoneCount && !zonesFound; i++) sl@0: { sl@0: if (i != index) sl@0: { sl@0: freeInOther += gZoneUtilArray[i].iFreePages; sl@0: } sl@0: } sl@0: if (freeInOther >= gZoneUtilArray[index].iAllocMovable) sl@0: { sl@0: zonesFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if (!zonesFound) sl@0: { sl@0: test.Printf(_L("No suitable RAM zone could be found - Skipping...\n")); sl@0: goto skipTest9; sl@0: } sl@0: sl@0: // Allocate up to one less than the RAM zone size. Do 2 stage fixed allocation sl@0: // to avoid kernel heap allocations spoiling test setup. sl@0: r = Ldd.AllocFixedArray(gZoneConfigArray[index].iPhysPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Not enough free RAM to perform test - Skipping...\n")); sl@0: goto skipTest9; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable < 2) sl@0: { sl@0: test.Printf(_L("Expanding kernel heap for phys address array spoiled RAM zone - Skipping...\n")); sl@0: goto skipTest9; sl@0: } sl@0: allocFixedPages = gZoneUtilArray[index].iAllocMovable + sl@0: gZoneUtilArray[index].iAllocDiscardable + sl@0: gZoneUtilArray[index].iFreePages - 1; sl@0: r = Ldd.ZoneAllocDiscontiguous2(gZoneConfigArray[index].iZoneId, allocFixedPages); sl@0: sl@0: if (r != KErrNone || !gZoneUtilArray[index].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Fixed not allocated or too many movable moved RAM zone ID%x\n"), sl@0: gZoneConfigArray[index].iZoneId); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: skipTest9 : sl@0: // This will clean up any fixed pages allocated. sl@0: TestEnd(); sl@0: sl@0: delete[] zoneIdArray; sl@0: sl@0: test.Next(_L("Test10: Test Epoc::ZoneAllocPhysicalRam() (Discontiguous) doesn't affect the allocation of movable pages")); sl@0: r = TestZoneAllocNoAffect(Z_ALLOC_DISC, BEST_MOVABLE); sl@0: if (r != KErrNone) sl@0: { sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: test.Next(_L("Test11: Test Epoc::ZoneAllocPhysicalRam() (Discontiguous) doesn't affect the allocation of discardable pages")); sl@0: r = TestZoneAllocNoAffect(Z_ALLOC_DISC, BEST_DISCARDABLE); sl@0: if (r != KErrNone) sl@0: { sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestFreeZone sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0537 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the function Epoc::FreePhysicalRam() sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Allocate fixed pages and call function to free all fixed pages allocated. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrNone sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestFreeZone() sl@0: { sl@0: TInt r = 0; sl@0: TUint zoneID = 0; sl@0: test.Start(_L("Test1: Free allocated pages")); sl@0: TestStart(); sl@0: sl@0: TInt pages = 50; sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && sl@0: (gZoneUtilArray[index].iAllocFixed != 0 || sl@0: gZoneUtilArray[index].iAllocUnknown != 0 || sl@0: (TInt)gZoneUtilArray[index].iFreePages < pages)) sl@0: { sl@0: -- index; sl@0: } sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && sl@0: (gZoneUtilArray[index].iAllocFixed != 0 || sl@0: gZoneUtilArray[index].iAllocUnknown != 0 || sl@0: (TInt)gZoneUtilArray[index].iFreePages < pages)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: TESTDEBUG(test.Printf(_L("Allocating 0x%x pages to zone ID 0x%x\n"), pages, zoneID)); sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, pages); sl@0: GetAllPageInfo(); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Freeing 0x%x fixed pages\n"), pages)); sl@0: if (r == KErrNone) sl@0: { sl@0: r = Ldd.FreeZone(pages); sl@0: } sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r == KErrNone) sl@0: { sl@0: test.Printf(_L("Pass: Correct return value\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestDefragSemMethod sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0538 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the semaphore versions of the various defrag methods sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this, call the semaphore variation of DefragRam. sl@0: //! 2. Fragment the memory. Following this, call the semaphore variation of EmptyRamZone sl@0: //! 3. Fragment the memory. Following this, call the semaphore variation of ClaimRamZone sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. 1 or more zones have been emptied sl@0: //! 2. Zone specified has been emptied sl@0: //! 3. Zone has been claimed sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestDefragSemMethod() sl@0: { sl@0: TInt r = 0; sl@0: sl@0: test.Start(_L("Test1: Call semaphore method of DefragRam")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SEM); sl@0: sl@0: sl@0: if (r != KErrNone ||(genSucceed && CheckZonesSwitchedOff() == EFalse)) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call semaphore method of EmptyRamZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: TUint defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SEM, defragZoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && (r != KErrNone || !CheckZoneIsOff(index))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zones has not been swtiched off\n"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: // This will free any allocated memory. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test3: Call semaphore method of ClaimRamZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 2; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SEM, defragZoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (CheckZoneIsOff(index) || sl@0: (freeInOthers && ( r != KErrNone || sl@0: gZoneUtilArray[index].iAllocFixed != gZoneConfigArray[index].iPhysPages))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zone ID 0x%x has not been claimed\n"), r, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: r = Ldd.FreeAllFixedPages(); sl@0: } sl@0: sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestDefragDfcMethod sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0539 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the Dfc versions of the various defrag methods sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory. Following this, call the Dfc variation of DefragRam. sl@0: //! 2. Fragment the memory. Following this, call the Dfc variation of EmptyRamZone sl@0: //! 3. Fragment the memory. Following this, call the Dfc variation of ClaimRamZone sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. 1 or more zones have been emptied sl@0: //! 2. Zone specified has been emptied sl@0: //! 3. Zone has been claimed sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestDefragDfcMethod() sl@0: { sl@0: TInt r = 0; sl@0: TRequestStatus req; sl@0: test.Start(_L("Test1: Call Dfc method of DefragRam")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetOriginalPageCount(); sl@0: TBool genSucceed = CanGenSucceed(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_DFC, 0, 0, -1, &req); sl@0: TESTDEBUG(test.Printf(_L("After queueing defrag r = %d\n"), r)); sl@0: User::WaitForRequest(req); sl@0: r = req.Int(); sl@0: sl@0: if (r != KErrNone || (genSucceed && CheckZonesSwitchedOff() == EFalse)) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Call Dfc method of EmptyRamZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint index = gZoneCount - 1; sl@0: while (index > 0 && sl@0: (gZoneUtilArray[index].iAllocMovable < 10 || sl@0: gZoneUtilArray[index].iAllocFixed != 0 || sl@0: gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: sl@0: TUint defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: test.Printf(_L("zone ID = 0x%x\n"), defragZoneID); sl@0: if (index == 0 && sl@0: (gZoneUtilArray[index].iAllocMovable < 10 || sl@0: gZoneUtilArray[index].iAllocFixed != 0 || sl@0: gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_DFC, defragZoneID, 0, -1, &req); sl@0: sl@0: User::WaitForRequest(req); sl@0: r = req.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && (r != KErrNone || CheckZoneIsOff(index) == EFalse)) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zones have not been swtiched off\n"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: // This will free any allocated memory sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Call Dfc method of ClaimRamZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = gZoneCount - 1; sl@0: while (index > 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: -- index; sl@0: } sl@0: defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: if (index == 0 && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_DFC, defragZoneID, 0, -1, &req); sl@0: User::WaitForRequest(req); sl@0: r = req.Int(); sl@0: sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (CheckZoneIsOff(index) || sl@0: (freeInOthers && (r != KErrNone || sl@0: gZoneUtilArray[index].iAllocFixed != gZoneConfigArray[index].iPhysPages))) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, or zone ID 0x%x has not been claimed\n"), r, defragZoneID); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: if (r == KErrNone) sl@0: { sl@0: CLEANUP(Ldd.FreeFromAddr( gZoneUtilArray[index].iAllocFixed, sl@0: gZoneConfigArray[index].iPhysBase)); sl@0: } sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: Ldd.FreeFromAddr( gZoneUtilArray[index].iAllocFixed, sl@0: gZoneConfigArray[index].iPhysBase); sl@0: } sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestPriorities sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0540 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying the priorities of the defrag methods sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Call DefragRam with a lower invalid priority value, e.g. -2 sl@0: //! 2. Call DefragRam with a lower invalid priority value, e.g. 100 sl@0: //! 3. Queue three asynchronous defrags using the Dfc method: sl@0: //! a. First one with the lowest priority, this will start the straight away sl@0: //! and will busy the defrag method, causing any other defrag requests to sl@0: //! be queued. sl@0: //! b. Queue a defrag with a relatively low priority sl@0: //! c. Queue a defrag with a higher priority than the one queued in (b) sl@0: //! Record the order in which the defrags are completed sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. KErrArgument sl@0: //! 2. KErrArgument sl@0: //! 3. (a) will complete first as it started straight away. sl@0: //! (b) and (c) were both queued whilst (a) was running, sl@0: //! however as (c) has a higher priority, it will complete first - sl@0: //! therefore the order returned would be "a,c,b" sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestPriorities() sl@0: { sl@0: test.Start(_L("Test1: Call defrag with an invalid lower priority")); sl@0: TestStart(); sl@0: sl@0: TInt r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, 0, -2); sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, not expected\n"), r); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test2: Call defrag with an invalid higher priority")); sl@0: TestStart(); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC, 0, 0, 100); sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: if (r != KErrArgument) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, not expected\n"), r); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0) == 1) sl@0: {// Only test priorities on single core system as this test is not smp safe. sl@0: test.Next(_L("Test3: Call Dfc method of EmptyRamZone to test priorities")); sl@0: TestStart(); sl@0: sl@0: sl@0: TRequestStatus req; sl@0: TRequestStatus req2; sl@0: TRequestStatus req3; sl@0: TInt expectedOrder = 132; // Priorities set in Device driver sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: TUint index = (gZoneCount + 1) / 2; sl@0: TUint defragZoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = Ldd.CheckPriorities(DEFRAG_TYPE_EMPTY, defragZoneID, &req, &req2, &req3); sl@0: sl@0: User::WaitForRequest(req); sl@0: User::WaitForRequest(req2); sl@0: User::WaitForRequest(req3); sl@0: sl@0: TInt order = Ldd.GetDefragOrder(); sl@0: if (order != expectedOrder) sl@0: { sl@0: test.Printf(_L("Fail: order = %d. expected = %d\n"), order, expectedOrder); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: // This will free any allocated memory sl@0: TestEnd(); sl@0: } sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestFlags sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0541 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying that when certain flags are set, sl@0: //! only certain types of pages can be allocated to the zone. sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Set the NoFixed flag in a zone and allocate movable pages sl@0: //! 2. Set the NoFixed flag in a zone and allocate fixed pages sl@0: //! 3. Set the NoFixed flag in a zone and allocate discardable pages sl@0: //! 4. Set the NoFixed flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() sl@0: //! 5. Set the NoFixed flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() sl@0: //! 6. Set the NoMovable flag in a zone and allocate movable pages sl@0: //! 7. Set the NoMovable flag in a zone and allocate fixed pages sl@0: //! 8. Set the NoMovable flag in a zone and allocate discardable pages sl@0: //! 9. Set the NoDiscardable flag in a zone and allocate movable pages sl@0: //! 10. Set the NoDiscardable flag in a zone and allocate fixed pages sl@0: //! 11. Set the NoDiscardable flag in a zone and allocate discardable pages sl@0: //! 12. Set the OnlyDiscardable flag in a zone and allocate movable pages sl@0: //! 13. Set the OnlyDiscardable flag in a zone and allocate fixed pages sl@0: //! 14. Set the OnlyDiscardable flag in a zone and allocate discardable pages sl@0: //! 15. Set the OnlyDiscardable flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() sl@0: //! 16. Set the OnlyDiscardable flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() sl@0: //! 17. Set the NoFurtherAlloc flag in a zone and allocate movable pages sl@0: //! 18. Set the NoFurtherAlloc flag in a zone and allocate fixed pages sl@0: //! 19. Set the NoFurtherAlloc flag in a zone and allocate discardable pages sl@0: //! 20. Set the NoFurtherAlloc flag in a zone and allocate fixed pages to that zone using Epoc::ZoneAllocPhysicalRam() sl@0: //! 21. Set the NoFurtherAlloc flag in a zone and allocate fixed pages by calling TRamDefragRequest::ClaimRamZone() sl@0: //! 22. Set up memory so that the least preferable RAM zone has movable pages + discardable pages > free pages in the most sl@0: //! preferable zone. Ensure that the discardable pages cannot be discarded and so must be moved. Now set the flag on sl@0: //! all zones barring the most preferable zone to KRamZoneFlagNoMovable, ensuring that most pref has no flags set. sl@0: //! Following this call a general defrag. sl@0: //! 23. Set up memory so that the least preferable RAM zone has movable pages + discardable pages > free pages in the most sl@0: //! preferable RAM zone. Ensure that the discardable pages cannot be discarded and so must be moved. sl@0: //! Now set the flag on all zones barring the most preferable zone to KRamZoneFlagNoDiscard, ensuring that sl@0: //! most preferable RAM zone has no flags set. Following this call a general defrag. sl@0: //! 24. Set up memory so that the least preferable RAM zone has movable pages and discardable pages. Set all the zone sl@0: //! flags to KRamZoneFlagNoMovable. Following this call a general defrag. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Movable pages are allocated and no fixed pages allocated sl@0: //! 2. No fixed pages have been allocated sl@0: //! 3. Discardable pages are allocated and no fixed pages allocated sl@0: //! 4. KErrNone, flag is ignored with zone specific allocation sl@0: //! 5. KErrNone, flag is ignored when claiming a zone sl@0: //! 6. No movable pages have been allocated sl@0: //! 7. Fixed pages allocated, no movable allocated sl@0: //! 8. Discardable pages allocated, no movable pages allocated sl@0: //! 9. Movable pages allocated, no discardable pages allocated sl@0: //! 10. Fixed pages allocated, no discardable allocated sl@0: //! 11. No discardable pages allocated sl@0: //! 12. No movable pages allocated sl@0: //! 13. No fixed pages allocated sl@0: //! 14. Discardable pages allocated, no movable or fixed allocated sl@0: //! 15. KErrNone, flag is ignored with zone specific allocation sl@0: //! 16. KErrNone, flag is ignored when claiming a zone sl@0: //! 17. No moving, fixed or discardable pages allocated sl@0: //! 18. No moving, fixed or discardable pages allocated sl@0: //! 19. No moving, fixed or discardable pages allocated sl@0: //! 20. KErrNoMemory, flag is obeyed with zone specific allocation sl@0: //! 21. KErrNone, flag is ignored when claiming a zone sl@0: //! 22. Movable pages moved to the most preferable zone, discardable pages moved to next most preferable zone sl@0: //! 23. Discardable pages moved to most preferable zone, movable pages moved to next next most preferable zone sl@0: //! 24. No pages are moved from the least preferable zone zone sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestFlags() sl@0: { sl@0: TInt r = 0; sl@0: TUint zoneDefragID = 0; sl@0: sl@0: test.Start(_L("Test1: No Fixed Flag, Alloc Movable")); sl@0: TestStart(); sl@0: sl@0: TInt index = GetBestZone(BEST_MOVABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: if (SpaceAvailForPageTables(index, KFillAllMovable)) sl@0: { sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable == gOriginalPageCountArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: 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); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Skipping...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: No Fixed Flag, Alloc Fixed")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: // find a zone that has free pages in it to block it sl@0: GetAllPageInfo(); sl@0: TUint i = 0; sl@0: for (; i < gZoneCount; i++) sl@0: { sl@0: if (gZoneUtilArray[i].iFreePages > 0) sl@0: { sl@0: index = i; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (i == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: sl@0: GetAllPageInfo(); sl@0: // Ensure that either zone does not contain extra fixed pages sl@0: if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have been allocated into the zone ID 0x%x r = %d\n"), zoneDefragID, r); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: No Fixed Flag, Alloc Discardable")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: index = GetBestZone(BEST_DISCARDABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: GetOriginalPageCount(); sl@0: sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: UpdateRamInfo(); sl@0: TInt discardablePages; sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have been allocated\n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test4: No Fixed Flag, Alloc Fixed using ZoneAllocPhyicalRam")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_FIXED); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: // Just need to try and allocate one page sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have not been allocated into the zone\n")); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: No Fixed Flag, Alloc Fixed by attempting to claim zone")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: index++; sl@0: } sl@0: sl@0: if ((TUint)index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_FIXED_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: sl@0: //------------------------------------------------------------ sl@0: test.Next(_L("Test6: No Movable Flag, Alloc Movable")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_MOVABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Fail: Movable pages have been allocated in the zone\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test7: No Movable Flag, Alloc Fixed")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: index = GetBestZone(BEST_FIXED); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: GetOriginalPageCount(); sl@0: // Fill up all of RAM with fixed pages. sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: test.Printf(_L("r = %d\n"), r); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocFixed <= gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: orig mov 0x%x fix 0x%x current mov 0x%x fix 0x%x\n"), gOriginalPageCountArray[index].iAllocMovable, sl@0: gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocMovable, gZoneUtilArray[index].iAllocFixed); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test8: No Movable Flag, Alloc Discardable")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: index = GetBestZone(BEST_DISCARDABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); sl@0: test_KErrNone(r) sl@0: UpdateRamInfo(); sl@0: TInt discardablePages; sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Fail: Movable pages have been allocated into the zone \n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: //----------------------------------------------------------------------------------------------- sl@0: sl@0: test.Next(_L("Test9: No Discardable Flag, Alloc Movable")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_MOVABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable); sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || sl@0: (gZoneUtilArray[index].iAllocMovable <= gOriginalPageCountArray[index].iAllocMovable && sl@0: gZoneUtilArray[index].iAllocFixed == gOriginalPageCountArray[index].iAllocFixed)) sl@0: { sl@0: test.Printf(_L("Fail: Either discardable pages have been allocated or movable pages have not been allocated\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test10: No Discardable Flag, Alloc Fixed")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: index = GetBestZone(BEST_FIXED); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: // Fill up all of RAM with fixed pages. sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || sl@0: gZoneUtilArray[index].iAllocFixed <= gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Discardable pages have been allocated or fixed pages have not been allocated\n")); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test11: No Discardable Flag, Alloc Discardable")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: index = GetBestZone(BEST_DISCARDABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: UpdateRamInfo(); sl@0: sl@0: TInt discardablePages; sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNoMemory) sl@0: {// Allocation should fail as no dis flag is set sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("Fail: Discardable pages have been allocated into the zone\n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: //----------------------------------------------------------------------------------------------- sl@0: sl@0: test.Next(_L("Test12: Only Discardable Flag, Alloc Movable")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_MOVABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable) sl@0: { sl@0: test.Printf(_L("Fail: Movable pages have been allocated\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test13: Only Discardable Flag, Alloc Fixed")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: index = GetBestZone(BEST_FIXED); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: // Fill up all of RAM with fixed pages. sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have been allocated\n")); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test14: Only Discardable Flag, Alloc Discardable")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: index = GetBestZone(BEST_DISCARDABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: UpdateRamInfo(); sl@0: sl@0: TInt discardablePages; sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Pages other than discardable have been allocated\n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test15: Only Discardable Flag, Alloc Fixed using ZoneAllocPhyicalRam")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_FIXED); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: // Just need to try and allocate one page sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have not been allocated into zone ID 0x%x\n"), zoneDefragID); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test16: Only Discardable Flag, Alloc Fixed by attempting to claim zone")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: index++; sl@0: } sl@0: sl@0: if ((TUint)index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, ONLY_DISCARD_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: //----------------------------------------------------------------------------------------------- sl@0: sl@0: test.Next(_L("Test17: No further alloc Flag, Alloc Movable")); sl@0: TestStart(); sl@0: sl@0: index = GetBestZone(BEST_MOVABLE); sl@0: sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); sl@0: test_KErrNone(r); sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KFillAllMovable, KChunkDefaultSize, EFalse); sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || sl@0: gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Pages been allocated\n")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test18: No further alloc Flag, Alloc Fixed")); sl@0: TestStart(); sl@0: sl@0: if(gPagedRom) sl@0: { sl@0: r = DPTest::SetCacheSize(gOriginalMinCacheSize, gOriginalMinCacheSize); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: // Find a zone with free pages and set the flag on this zone sl@0: // as it will ensure that you cannot fill all of free RAM with fixed pages sl@0: index = KErrNotFound; sl@0: GetAllPageInfo(); sl@0: for (TUint i = 0; i < gZoneCount; i++) sl@0: { sl@0: if (gZoneUtilArray[i].iFreePages != 0) sl@0: { sl@0: index = i; sl@0: break; sl@0: } sl@0: } sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.AllocateFixed(FILL_ALL_FIXED); sl@0: sl@0: // Ensure memory wasn't filled as it should have hit the blocked zone. sl@0: GetAllPageInfo(); sl@0: if (r != KErrNoMemory || gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: orig fix 0x%x current fix 0x%x\n"), gOriginalPageCountArray[index].iAllocFixed, gZoneUtilArray[index].iAllocFixed); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test19: No further alloc Flag, Alloc Discardable")); sl@0: TestStart(); sl@0: if (gPagedRom) sl@0: { sl@0: index = GetBestZone(BEST_DISCARDABLE); sl@0: sl@0: if (index == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); sl@0: test_KErrNone(r); sl@0: UpdateRamInfo(); sl@0: TInt discardablePages; sl@0: r = AllocDiscardable(discardablePages); sl@0: if (r != KErrNoMemory) sl@0: {// Allocation should fail as no alloc flag is set sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: GetAllPageInfo(); sl@0: sl@0: if (gZoneUtilArray[index].iAllocDiscardable > gOriginalPageCountArray[index].iAllocDiscardable || sl@0: gZoneUtilArray[index].iAllocMovable > gOriginalPageCountArray[index].iAllocMovable || sl@0: gZoneUtilArray[index].iAllocFixed > gOriginalPageCountArray[index].iAllocFixed) sl@0: { sl@0: test.Printf(_L("Fail: Pages have been allocated into the zone\n")); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping test step\n")); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test20: No Further Alloc Flag, Alloc Fixed using ZoneAllocPhyicalRam")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iFreePages == 0 || sl@0: gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: index++; sl@0: } sl@0: sl@0: if ((TUint)index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: // Just need to try and allocate one page sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneDefragID, 1); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNoMemory) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have been allocated into zone ID 0x%x\n"), zoneDefragID); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test21: No Further Alloc Flag, Alloc Fixed by attempting to claim zone")); sl@0: TestStart(); sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while ((TUint)index < gZoneCount && (gZoneUtilArray[index].iAllocFixed != 0 || gZoneUtilArray[index].iAllocUnknown != 0)) sl@0: { sl@0: index++; sl@0: } sl@0: sl@0: if ((TUint)index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneDefragID = gZoneConfigArray[index].iZoneId; sl@0: r = Ldd.SetZoneFlag(zoneDefragID, gZoneConfigArray[index].iFlags, NO_ALLOC_FLAG); sl@0: test_KErrNone(r); sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneDefragID); sl@0: GetAllPageInfo(); sl@0: TUint freeInOthers = gTotalPageCount.iFreePages - gZoneUtilArray[index].iFreePages; sl@0: if (freeInOthers && r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Claim zone ID 0x%x was unsuccessful, r = %d\n"), zoneDefragID, r); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: TUint mostPrefArrayIndex = 0; sl@0: TUint mostPrefIndex = 0; sl@0: TUint leastPrefIndex = 0; sl@0: const TUint KFreeMostPref = 10; sl@0: TUint flag = 0; sl@0: TUint prefIndex; sl@0: TUint totalFree; sl@0: sl@0: sl@0: for (TUint testStep = 0; testStep < 2; testStep++) sl@0: { sl@0: switch(testStep) sl@0: { sl@0: case 0: sl@0: test.Next(_L("Test22: Ensure that the General Defrag looks at the flags 1")); sl@0: break; sl@0: sl@0: case 1: sl@0: test.Next(_L("Test23: Ensure that the General Defrag looks at the flags 2")); sl@0: break; sl@0: } sl@0: sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: TUint freeNeededInMostPref = 0; sl@0: if (!gPagedRom) sl@0: { sl@0: test.Printf(_L("Not a paged ROM - Skipping...\n")); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // Find the most pref zone with free pages sl@0: r = FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot find zone with free pages - Skipping...\n")); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // Ensure that the least pref zone is empty sl@0: leastPrefIndex = gPrefArray[gZoneCount - 1]; sl@0: if (gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) sl@0: { sl@0: test.Printf(_L("Least pref zone is not empty - Skipping...\n")); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // Allocate 1 movable page to the least preferable zone sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, leastPrefIndex, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate movable r = %d - Skipping...\n"), r); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // Allocate 1 discardable page to the least preferable zone sl@0: if (gZoneUtilArray[leastPrefIndex].iFreePages != 0) sl@0: { sl@0: TInt disPages; sl@0: r = ZoneAllocDiscard(leastPrefIndex, 1, disPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate discardable pages r = %d - Skipping...\n"), r); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // up the minimum cache size so that the pages have to be moved - not discarded sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); sl@0: goto skipTest22; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Least pref zone has no free pages - Skipping...\n")); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: // Check that the least pref zone has movable and discardable pages in it sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[leastPrefIndex].iAllocMovable == 0 || sl@0: gZoneUtilArray[leastPrefIndex].iAllocDiscardable == 0) sl@0: { sl@0: test.Printf(_L("No movable or discardable in least pref zone\n")); sl@0: PrintPageInfo(); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: ResetRamZoneFlags(); sl@0: // if most pref zone has too many free pages fill up with fixed sl@0: if (gZoneUtilArray[mostPrefIndex].iFreePages > KFreeMostPref) sl@0: { sl@0: TUint allocPages = gZoneUtilArray[mostPrefIndex].iFreePages - KFreeMostPref; sl@0: r = Ldd.ZoneAllocToMany(mostPrefIndex, allocPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed allocate 0x%x fixed to index %d r = %d - Skipping...\n"), sl@0: allocPages, mostPrefIndex,r); sl@0: PrintPageInfo(); sl@0: goto skipTest22; sl@0: } sl@0: } sl@0: sl@0: sl@0: // if the no. of discardable pages is less than free in most pref increase the min cache size sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[leastPrefIndex].iAllocDiscardable < gZoneUtilArray[mostPrefIndex].iFreePages) sl@0: { sl@0: TUint discDiff = gZoneUtilArray[mostPrefIndex].iFreePages - gZoneUtilArray[leastPrefIndex].iAllocDiscardable; sl@0: test.Printf(_L("discDiff = 0x%x\n"), discDiff); sl@0: TInt disPages; sl@0: if (ZoneAllocDiscard(leastPrefIndex, discDiff, disPages) != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed allocate discardable to zone index %d- Skipping...\n"), leastPrefIndex); sl@0: goto skipTest22; sl@0: } sl@0: // up the minimum cache size by the difference as we don't want these pages to be discarded sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); sl@0: test.Printf(_L("r = %d\n"), r); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); sl@0: goto skipTest22; sl@0: } sl@0: } sl@0: ResetRamZoneFlags(); sl@0: sl@0: // if the rest of the zones are either full or empty put a fixed page into the next most pref empty zone sl@0: GetPrefOrder(); sl@0: prefIndex = 0; sl@0: totalFree = 0; sl@0: for (; prefIndex < gZoneCount && totalFree < gZoneUtilArray[leastPrefIndex].iAllocDiscardable; prefIndex++) sl@0: {// Look for zone that has enough free pages to fit all the discardable sl@0: TUint zoneIndex = gPrefArray[prefIndex]; sl@0: if (zoneIndex != mostPrefIndex && zoneIndex != leastPrefIndex) sl@0: { sl@0: if (gZoneUtilArray[zoneIndex].iFreePages != gZoneUtilArray[zoneIndex].iPhysPages) sl@0: { sl@0: totalFree += gZoneUtilArray[zoneIndex].iFreePages; sl@0: } sl@0: else sl@0: { sl@0: r = Ldd.ZoneAllocToMany(zoneIndex, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Couldn't alloc fixed to zone index %d - r = %d\n"), zoneIndex, r); sl@0: goto skipTest22; sl@0: } sl@0: GetAllPageInfo(); sl@0: totalFree += gZoneUtilArray[zoneIndex].iFreePages; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if (prefIndex >= gZoneCount) sl@0: { sl@0: test.Printf(_L("Couldn't find zone\n")); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: sl@0: sl@0: // If the most preferable zone does not have enough free pages, skip sl@0: freeNeededInMostPref = (testStep == 0) ? gZoneUtilArray[leastPrefIndex].iAllocMovable : gZoneUtilArray[leastPrefIndex].iAllocDiscardable; sl@0: if (gZoneUtilArray[mostPrefIndex].iFreePages < freeNeededInMostPref) sl@0: { sl@0: test.Printf(_L("Free needed in mostPref(%d) = %d, Free available in mostPref = %d - skipping...\n"), sl@0: mostPrefIndex,freeNeededInMostPref,gZoneUtilArray[mostPrefIndex].iFreePages); sl@0: goto skipTest22; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: // Set up the RAM zone flags for the test sl@0: flag = (testStep == 0)? NO_MOVE_FLAG: NO_DISCARD_FLAG; sl@0: // Set all zones except most pref to KRamZoneFlagNoMovable or KRamZoneFlagNoDiscard sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: if (index != mostPrefIndex) sl@0: { sl@0: r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, flag); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set flag r = %d - Skipping...\n"), r); sl@0: goto skipTest22; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: GetAllPageInfo(); sl@0: switch(testStep) sl@0: { sl@0: case 0: sl@0: if (r != KErrNone || sl@0: gOriginalPageCountArray[mostPrefIndex].iAllocMovable >= gZoneUtilArray[mostPrefIndex].iAllocMovable || sl@0: gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) sl@0: { sl@0: 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"), sl@0: r, mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, sl@0: leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: break; sl@0: sl@0: case 1: sl@0: if (r != KErrNone || sl@0: gOriginalPageCountArray[mostPrefIndex].iAllocDiscardable >= gZoneUtilArray[mostPrefIndex].iAllocDiscardable || sl@0: gZoneUtilArray[leastPrefIndex].iFreePages != gZoneUtilArray[leastPrefIndex].iPhysPages) sl@0: { sl@0: 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"), sl@0: r, mostPrefIndex, gOriginalPageCountArray[mostPrefIndex].iAllocMovable, gZoneUtilArray[mostPrefIndex].iAllocMovable, sl@0: leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: break; sl@0: } sl@0: sl@0: skipTest22: sl@0: TestEnd(); sl@0: } sl@0: sl@0: test.Next(_L("Test24: Ensure that the General Defrag doesnt move or discard pages if KRamZoneFlagNoMovable set on all zones ")); sl@0: TestStart(); sl@0: gChunkArray1 = new RChunk; sl@0: gChunkArraySize1 = 1; sl@0: // Find the most pref zone with free pages sl@0: GetPrefOrder(); sl@0: TInt disPages = 0; sl@0: if (FindMostPrefWithFree(mostPrefIndex, &mostPrefArrayIndex) != KErrNone) sl@0: { sl@0: test.Printf(_L("Cannot find zone with free pages - Skipping...\n")); sl@0: goto skipTest24; sl@0: } sl@0: sl@0: // Ensure that the least pref zone has free pages in it sl@0: leastPrefIndex = gPrefArray[gZoneCount-1]; sl@0: if (gZoneUtilArray[leastPrefIndex].iFreePages == 0) sl@0: { sl@0: test.Printf(_L("Least pref zone has no free pages - Skipping...\n")); sl@0: goto skipTest24; sl@0: } sl@0: sl@0: // Allocate 1 movable page to the least preferable zone sl@0: r = ZoneAllocMovable(gChunkArray1, gChunkArraySize1, leastPrefIndex, 1); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate movable page r = %d - Skipping...\n"), r); sl@0: goto skipTest24; sl@0: } sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: // Allocate 1 discardable page to the least preferable zone sl@0: if (gZoneUtilArray[leastPrefIndex].iFreePages != 0) sl@0: { sl@0: r = ZoneAllocDiscard(leastPrefIndex, 1, disPages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Discardable pages not allocated r= %d\n"), r); sl@0: } sl@0: sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: r = DPTest::SetCacheSize(currentCacheSize, currentCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); sl@0: goto skipTest24; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: // Check that the least pref zone has movable and discardable (if allocated) pages in it sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[leastPrefIndex].iAllocMovable == 0 || sl@0: gZoneUtilArray[leastPrefIndex].iAllocDiscardable < (TUint)disPages || sl@0: gZoneUtilArray[leastPrefIndex].iAllocMovable > gTotalPageCount.iFreePages - gZoneUtilArray[leastPrefIndex].iFreePages) sl@0: { sl@0: test.Printf(_L("No movable in least pref zone or no space for moveable pages to be moved to\n")); sl@0: PrintPageInfo(); sl@0: goto skipTest24; sl@0: } sl@0: sl@0: ResetRamZoneFlags(); sl@0: GetAllPageInfo(); sl@0: // Now set all zones to KRamZoneFlagNoMovable sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: r = Ldd.SetZoneFlag(zoneID, gZoneConfigArray[index].iFlags, NO_MOVE_FLAG); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to set cache size r = %d - Skipping...\n"), r); sl@0: goto skipTest24; sl@0: } sl@0: } sl@0: sl@0: GetOriginalPageCount(); sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocMovable != gZoneUtilArray[leastPrefIndex].iAllocMovable || sl@0: gZoneUtilArray[leastPrefIndex].iAllocDiscardable < gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable) sl@0: { sl@0: test.Printf(_L("FAIL:r=%d LeastPref(%d): origMov 0x%x curMov 0x%x origDis 0x%x curDis 0x%x\n"), sl@0: r,leastPrefIndex, gOriginalPageCountArray[leastPrefIndex].iAllocMovable, gZoneUtilArray[leastPrefIndex].iAllocMovable, sl@0: gOriginalPageCountArray[leastPrefIndex].iAllocDiscardable, gZoneUtilArray[leastPrefIndex].iAllocDiscardable); sl@0: CLEANUP(ResetRamZoneFlags()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: skipTest24: sl@0: TestEnd(); sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // Template functions encapsulating ControlIo magic sl@0: // sl@0: template sl@0: TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c) sl@0: { sl@0: TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C)); sl@0: sl@0: TInt r = fs.ControlIo(drv, fkn, ptrC); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // FormatMMC sl@0: // sl@0: // Formats the MMC card sl@0: // sl@0: void FormatMMC() sl@0: { sl@0: test.Printf(_L("Formatting MMC...\n")); sl@0: sl@0: RFs theFs; sl@0: TBuf<4> driveBuf = _L("D:\\"); sl@0: RFormat format; sl@0: TInt count; sl@0: TChar driveLet; sl@0: sl@0: TInt r = theFs.Connect(); sl@0: test_KErrNone(r); sl@0: sl@0: r = theFs.DriveToChar(gDrive, driveLet); sl@0: test_KErrNone(r); sl@0: sl@0: driveBuf[0] = driveLet; sl@0: test.Printf(_L("Formatting Drive: %C\n"),(TInt)driveLet); sl@0: sl@0: r = format.Open(theFs,driveBuf,EFullFormat,count); sl@0: test_KErrNone(r); sl@0: sl@0: while(count) sl@0: { sl@0: TInt r = format.Next(count); sl@0: test_KErrNone(r); sl@0: } sl@0: format.Close(); sl@0: theFs.Close(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // FileNameGen sl@0: // sl@0: // Generates file names to create the files sl@0: // sl@0: void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos) sl@0: { sl@0: TInt padding; sl@0: TInt i = 0; sl@0: TBuf16<10> tempbuf; sl@0: sl@0: _LIT(KNumber,"%d"); sl@0: tempbuf.Format(KNumber,aPos); sl@0: sl@0: padding = aLong-tempbuf.Size()/2; sl@0: aBuffer = _L(""); sl@0: sl@0: while(i < padding) sl@0: { sl@0: aBuffer.Append('F'); sl@0: i++; sl@0: } sl@0: aBuffer.Append(tempbuf); sl@0: sl@0: _LIT(KExtension1, ".TXT"); sl@0: aBuffer.Append(KExtension1); sl@0: } sl@0: sl@0: sl@0: // sl@0: // CreateFiles sl@0: // sl@0: // Creates the files to fill part of the read cache sl@0: // sl@0: void CreateFiles(TInt aFiles, TInt aFileSize) sl@0: { sl@0: TInt i = 0, r = 0; sl@0: RFile file; sl@0: TBuf16<50> directory; sl@0: sl@0: TBuf16<50> path; sl@0: TBuf16<50> buffer(50); sl@0: sl@0: directory = gSessionPath; sl@0: sl@0: test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), aFiles, aFileSize); sl@0: sl@0: // create a big buffer to speed things up sl@0: HBufC8* bigBuf = NULL; sl@0: const TInt KBigBufferSize = 32 * 1024; sl@0: TRAPD(res,bigBuf = HBufC8::NewL(KBigBufferSize)); sl@0: test(res == KErrNone && bigBuf != NULL); sl@0: sl@0: TPtr8 bigBufWritePtr(NULL, 0); sl@0: bigBufWritePtr.Set(bigBuf->Des()); sl@0: sl@0: // Fill the buffer sl@0: TChar aC = 'A'; sl@0: for(i = 0; i < KBigBufferSize; i++) sl@0: { sl@0: bigBufWritePtr.Append((i%32) + aC); sl@0: } sl@0: sl@0: sl@0: i = 0; sl@0: while(i < aFiles) sl@0: { sl@0: if (i % 10 == 0) sl@0: test.Printf(_L("Creating file %d of %d...\r"), i, aFiles); sl@0: FileNameGen(buffer, 8, i+3) ; sl@0: path = directory; sl@0: path.Append(buffer); sl@0: sl@0: // delete file first to ensure it's contents are not in the cache (file may be on the closed file queue) sl@0: r = gTheFs.Delete(path); sl@0: test(r == KErrNone || r == KErrNotFound); sl@0: sl@0: r = file.Create(gTheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); sl@0: if(r == KErrAlreadyExists) sl@0: r = file.Open(gTheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); sl@0: TInt j = 0; sl@0: i++; sl@0: while(j < aFileSize) sl@0: { sl@0: bigBufWritePtr.SetLength(Min(KBigBufferSize, aFileSize - j)); sl@0: r = file.Write(bigBufWritePtr); sl@0: // Running out of disk space is expected for the last file. sl@0: // Premature "disk full" conditions need to abort. sl@0: if (r == KErrDiskFull) sl@0: { sl@0: test(i == aFiles); sl@0: break; sl@0: } sl@0: test_KErrNone(r); sl@0: j += bigBufWritePtr.Length(); sl@0: } sl@0: sl@0: file.Close(); sl@0: } sl@0: test.Printf(_L("\nFiles created\n")); sl@0: delete bigBuf; sl@0: } sl@0: sl@0: sl@0: // sl@0: // FillCache sl@0: // sl@0: // Allocate discardable pages using file system caching sl@0: // sl@0: TInt FillCache(TInt aFiles, TInt aFileSize) sl@0: { sl@0: // Fail if files already open sl@0: test(!gFileCacheRun); sl@0: sl@0: sl@0: TInt i = 0, r = 0; sl@0: TBuf16<50> directory; sl@0: sl@0: TBuf16<50> path; sl@0: TBuf16<50> buffer(50); sl@0: HBufC8* buf = NULL; sl@0: TPtr8 bufPtr(NULL, 0); sl@0: sl@0: TRAPD(res,buf = HBufC8::NewL(2)); sl@0: test(res == KErrNone && buf != NULL); sl@0: bufPtr.Set(buf->Des()); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Filling the cache\n"))); sl@0: sl@0: directory = gSessionPath; sl@0: sl@0: i = 0; sl@0: sl@0: GetAllPageInfo(); sl@0: TESTDEBUG(test.Printf(_L("total disc pages = %d\n"), gTotalPageCount.iDiscardablePages)); sl@0: sl@0: sl@0: while(i < aFiles) sl@0: { sl@0: FileNameGen(buffer, 8, i+3) ; sl@0: path = directory; sl@0: path.Append(buffer); sl@0: r = gFile[i].Open(gTheFs,path,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); sl@0: test_KErrNone(r); sl@0: sl@0: TInt j = 0; sl@0: while(j < aFileSize) sl@0: { sl@0: r = gFile[i].Read(j,bufPtr); sl@0: test_KErrNone(r); sl@0: j += 4 * 1024; sl@0: } sl@0: i++; sl@0: } sl@0: gFileCacheRun = ETrue; sl@0: GetAllPageInfo(); sl@0: TESTDEBUG(test.Printf(_L("after - total disc pages = %d\n"), gTotalPageCount.iDiscardablePages)); sl@0: delete buf; sl@0: TESTDEBUG(test.Printf(_L("Cache filled\n"))); sl@0: sl@0: #if defined(_DEBUG) || defined(_DEBUG_RELEASE) sl@0: // get number of items on Page Cache sl@0: TFileCacheStats startPageCacheStats; sl@0: sl@0: r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); sl@0: test.Printf(_L("control stats r= %d\n"), r); sl@0: test(r==KErrNone || r == KErrNotSupported); sl@0: sl@0: TESTDEBUG(test.Printf(_L("Allocated segment count=%d\n"),startPageCacheStats.iAllocatedSegmentCount)); sl@0: #endif sl@0: // if we do not have any discardable pages then something went sl@0: // wrong with file caching sl@0: if (gTotalPageCount.iDiscardablePages == 0) sl@0: return KErrNotSupported; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // SetUpMMC sl@0: // sl@0: // Sets up the MMC to be used by the test by creating files on the MMC sl@0: // sl@0: void SetUpMMC() sl@0: { sl@0: FormatMMC(); sl@0: sl@0: TInt r = 0; sl@0: sl@0: TChar driveToTest; sl@0: sl@0: TVolumeInfo volInfo; sl@0: sl@0: r = gTheFs.DriveToChar(gDrive, driveToTest); sl@0: test_KErrNone(r); sl@0: sl@0: r = gTheFs.CharToDrive(driveToTest,gDrive); sl@0: test_KErrNone(r); sl@0: sl@0: gSessionPath = _L("?:\\F32-TST\\"); sl@0: gSessionPath[0] = (TUint16) driveToTest; sl@0: test.Printf(_L("Drive Letter=%C\n"),(TInt)driveToTest); sl@0: sl@0: TDriveInfo info; sl@0: r = gTheFs.Drive(info,gDrive); sl@0: test_KErrNone(r); sl@0: r = gTheFs.SetSessionPath(gSessionPath); sl@0: test_KErrNone(r); sl@0: r = gTheFs.MkDirAll(gSessionPath); sl@0: if (r != KErrNone && r != KErrAlreadyExists) sl@0: { sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: r = gTheFs.Volume(volInfo, gDrive); sl@0: test_KErrNone(r); sl@0: TInt64 gMediaSize = volInfo.iSize; sl@0: sl@0: // This calculation is approximate because the client cannot know sl@0: // internal allocation mechanisms of the filesystem, i.e. how much sl@0: // metadata is associated with a file of name X / size Y, whether sl@0: // space used by such metadata is reflected in TDriveInfo::iSize and sl@0: // what block/clustersize the filesystem will round filesizes to. sl@0: // The last file that fills up the drive may therefore be partial sl@0: // (smaller than this calculation predicts). sl@0: TInt maxPossibleFiles = gFilesNeededToFillCache; sl@0: test.Printf(_L("Original files needed = %d\n"), maxPossibleFiles); sl@0: if(gMediaSize < (KDefaultCacheSize * maxPossibleFiles)) sl@0: { sl@0: maxPossibleFiles = (gMediaSize - 10) / KDefaultCacheSize; sl@0: test.Printf(_L("Disk size is smaller - files needed = %d\n"), maxPossibleFiles); sl@0: } sl@0: gFilesNeededToFillCache = maxPossibleFiles; sl@0: CreateFiles(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestFileCaching sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0599 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying that when File System Caching allocates dicardable pages, sl@0: //! Defrag and allocation of fixed pages happens correctly. sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fill the file system cache to allocate discardable pages sl@0: //! following this call EmptyRamZone() in a zone with discardable pages. sl@0: //! 2. Fill the file system cache to allocate discardable pages sl@0: //! folling this allocate discontiguous fixed pages to a zone sl@0: //! 3. Fill the file system cache to allocate discardable pages sl@0: //! . following this allocate discontuguous fixed pages sl@0: //! 4. Fill the file system cache to allocate discardable pages sl@0: //! following this allocate less than 16 contiguous fixed pages sl@0: //! 5. Fill the file system cache to allocate discardable pages sl@0: //! following this allocate more than 16 contiguous fixed pages sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Discardable pages are removed sl@0: //! 2. KErrNone sl@0: //! 3. KErrNone sl@0: //! 4. KErrNone and numDiscardablePages != 0 sl@0: //! 5. KErrNone and numDiscardablePages = 0 sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestFileCaching() sl@0: { sl@0: const TUint KDisPagesReq = 1; sl@0: TInt r = KErrNone; sl@0: TInt allocSize = 0; sl@0: TUint zoneID = 0; sl@0: TUint index = 0; sl@0: TUint minDiscardPages = 0; sl@0: if (gDrive == KNoRemovableDrive) sl@0: { sl@0: test.Start(_L("Cannot find drive to write files to - Skipping FS Caching Tests\n")); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: r = gTheFs.Connect(); sl@0: test_KErrNone(r); sl@0: sl@0: SetUpMMC(); sl@0: sl@0: RRamDefragFuncTestLdd Ldd2; sl@0: r = Ldd2.Open(); sl@0: test_KErrNone(r); sl@0: sl@0: test.Start(_L("Test1: Test EmptyRamZone() clears file server cache pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); sl@0: goto skipFileCacheTests; sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) sl@0: { sl@0: ++ index; sl@0: } sl@0: sl@0: if (index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iAllocDiscardable != 0) sl@0: { sl@0: test.Printf(_L("Fail: Zone ID 0x%x has 0x%x discardable pages\n"), zoneID, gZoneUtilArray[index].iAllocDiscardable); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test2: Filling the FS Cache and allocating fixed pages to a zone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); sl@0: goto skipFileCacheTests; sl@0: } sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) sl@0: { sl@0: ++ index; sl@0: } sl@0: sl@0: if (index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: // Just need to attempt to allocate one more page than there is free in the zone sl@0: allocSize = gZoneUtilArray[index].iFreePages + 1; sl@0: sl@0: test.Printf(_L("Allocating 0x%x fixed pages to zone ID 0x%x.....\n"), allocSize, zoneID); sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, allocSize); sl@0: test.Printf(_L("r = %d\n"), r); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); sl@0: Ldd.FreeAllFixedPages(); sl@0: } sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test3: Filling the FS Cache and allocating fixed pages")); sl@0: TestStart(); sl@0: r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); sl@0: goto skipFileCacheTests; sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: index = 0; sl@0: while (index < gZoneCount && gZoneUtilArray[index].iAllocDiscardable < KDisPagesReq) sl@0: { sl@0: ++ index; sl@0: } sl@0: sl@0: if (index == gZoneCount) sl@0: { sl@0: test.Printf(_L("Cannot find zone to perform test on - Skipping test step...\n")); sl@0: } sl@0: else sl@0: { sl@0: zoneID = gZoneConfigArray[index].iZoneId; sl@0: sl@0: allocSize = 14; sl@0: sl@0: TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); sl@0: Ldd.AllocateFixed(gTotalPageCount.iFreePages); sl@0: sl@0: test.Printf(_L("Allocating 0x%x fixed pages to zone ID 0x%x.....\n"), allocSize, zoneID); sl@0: r = Ldd2.AllocateFixed(allocSize); sl@0: sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(Ldd2.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); sl@0: Ldd2.FreeAllFixedPages(); sl@0: } sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test4: Filling the FS Cache and allocating less than 16 contiguous fixed pages")); sl@0: TestStart(); sl@0: sl@0: r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); sl@0: goto skipFileCacheTests; sl@0: } sl@0: allocSize = 14 << gPageShift; sl@0: sl@0: TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); sl@0: GetAllPageInfo(); sl@0: // Allocate the fixed array before getting any page counts sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages) sl@0: { sl@0: r = Ldd.ZoneAllocToManyArray(index, gZoneUtilArray[index].iFreePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate fixed array Zone %d r = %d - Skipping...\n"), index, r); sl@0: goto SkipTest4; sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Now fill all zones with fixed pages, 1 zone at a time sl@0: // to avoid the discardable pages being disturbed sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages) sl@0: { sl@0: r = Ldd.ZoneAllocToMany2(index, gZoneUtilArray[index].iFreePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate %d fixed to Zone %d r = %d - Skipping...\n"), sl@0: gZoneUtilArray[index].iFreePages, index, r); sl@0: goto SkipTest4; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: test.Printf(_L("number of free pages = 0x%x\n"), gTotalPageCount.iFreePages); sl@0: if (gTotalPageCount.iFreePages || sl@0: gTotalPageCount.iDiscardablePages <= (TUint)(allocSize >> gPageShift)) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping...\n")); sl@0: goto SkipTest4; sl@0: } sl@0: sl@0: test.Printf(_L("Allocating 0x%x fixed pages.....\n"), allocSize >> gPageShift); sl@0: r = Ldd2.AllocContiguous(allocSize); sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || !gTotalPageCount.iDiscardablePages) sl@0: { sl@0: test.Printf(_L("Fail: Fixed pages have not been allocated, r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(Ldd2.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: sl@0: SkipTest4: sl@0: TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); sl@0: Ldd2.FreeAllFixedPages(); sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test5: Filling the FS Cache and allocating more than 16 contiguous fixed pages")); sl@0: TestStart(); sl@0: // TestEnd() will have reduced any cache pages to minimum so just get current sl@0: // count of discardable pages. sl@0: GetAllPageInfo(); sl@0: minDiscardPages = gTotalPageCount.iDiscardablePages; sl@0: sl@0: r = FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("File system caching failed - Skipping all file caching tests...\n")); sl@0: goto skipFileCacheTests; sl@0: } sl@0: sl@0: allocSize = 18 << gPageShift; sl@0: sl@0: TESTDEBUG(test.Printf(_L("Filling the remaining free pages with fixed pages.....\n"))); sl@0: GetAllPageInfo(); sl@0: sl@0: // Allocate the fixed array before getting any page counts sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages) sl@0: { sl@0: r = Ldd.ZoneAllocToManyArray(index, gZoneUtilArray[index].iFreePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate fixed array Zone %d r = %d - Skipping...\n"), index, r); sl@0: goto SkipTest5; sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Now fill all zones with fixed pages, 1 zone at a time sl@0: // to avoid the discardable pages being disturbed sl@0: for (TUint index = 0; index < gZoneCount; index++) sl@0: { sl@0: GetAllPageInfo(); sl@0: if (gZoneUtilArray[index].iFreePages) sl@0: { sl@0: r = Ldd.ZoneAllocToMany2(index, gZoneUtilArray[index].iFreePages); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Failed to allocate %d fixed to Zone %d r = %d - Skipping...\n"), sl@0: gZoneUtilArray[index].iFreePages, index, r); sl@0: goto SkipTest5; sl@0: } sl@0: } sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: test.Printf(_L("number of free pages = 0x%x\n"), gTotalPageCount.iFreePages); sl@0: if (gTotalPageCount.iFreePages) sl@0: { sl@0: test.Printf(_L("Setup failed - Skipping...\n")); sl@0: goto SkipTest5; sl@0: } sl@0: sl@0: test.Printf(_L("Allocating 0x%x fixed pages.....\n"), allocSize >> gPageShift); sl@0: r = Ldd2.AllocContiguous(allocSize); sl@0: TESTDEBUG(test.Printf(_L("r = %d\n"), r)); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNone || gTotalPageCount.iDiscardablePages != minDiscardPages) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = %d - Discardable Pages = 0x%x, expected = %d\n"), sl@0: r, KErrNone, gTotalPageCount.iDiscardablePages, minDiscardPages); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(Ldd2.FreeAllFixedPages()); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...\n")); sl@0: } sl@0: SkipTest5: sl@0: sl@0: skipFileCacheTests: sl@0: TestEnd(); sl@0: TESTDEBUG(test.Printf(_L("Freeing all Fixed Pages.....\n"))); sl@0: Ldd2.FreeAllFixedPages(); sl@0: Ldd2.Close(); sl@0: gTheFs.Close(); sl@0: FormatMMC(); sl@0: test.End(); sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestOneZoneConfig sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-t_ramdefrag-0600 sl@0: //! @SYMTestType CIT sl@0: //! @SYMTestCaseDesc Verifying that when only 1 zone is cofigured in the variant, that sl@0: //! the defrag and allocation of fixed pages happend correctly sl@0: //! @SYMPREQ PREQ308 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Fragment the memory and perform a DefragRam sl@0: //! 2. Fragment the memory and perform an EmptyZone sl@0: //! 3. Fragment the memory and perform a ClaimZone sl@0: //! 4. Call ZoneAllocPhysicalRam to allocate discontiguous fixed pages sl@0: //! 5. Call ZoneAllocPhysicalRam to allocate contiguous fixed pages sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Number of pages does not differ from the original sl@0: //! 2. KErrNoMemroy and discardable pages are discarded of sl@0: //! 3. KErrNoMemory sl@0: //! 4. KErrNone sl@0: //! 5. KErrNone sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: TInt TestOneZoneConfig() sl@0: { sl@0: TInt r = gTheFs.Connect(); sl@0: test_KErrNone(r); sl@0: sl@0: if (gDrive != KNoRemovableDrive) sl@0: { sl@0: SetUpMMC(); sl@0: } sl@0: sl@0: TUint index = 0; sl@0: GetAllPageInfo(); sl@0: TUint zoneID = gZoneConfigArray[index].iZoneId; sl@0: test.Printf(_L("Zone ID = 0x%x\n"), zoneID); sl@0: TUint minCacheSize = 0; sl@0: TUint maxCacheSize = 0; sl@0: TUint currentCacheSize = 0; sl@0: sl@0: sl@0: TUint origFree = 0; sl@0: TUint origUnknown = 0; sl@0: TUint origFixed = 0; sl@0: TUint origMovable = 0; sl@0: TUint origDiscard = 0; sl@0: TUint origOther = 0; sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: sl@0: TUint setMin = 60 << gPageShift; sl@0: TInt setMax = -1; sl@0: TInt r = DPTest::SetCacheSize(setMin, setMax); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("r = %d, expected = %d\n"), r, KErrNone); sl@0: CLEANUP(ResetDPCache()); sl@0: TEST_FAIL; sl@0: } sl@0: DPTest::CacheSize(minCacheSize,maxCacheSize,currentCacheSize); sl@0: TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), sl@0: minCacheSize >> gPageShift, maxCacheSize >> gPageShift, currentCacheSize >> gPageShift)); sl@0: } sl@0: sl@0: test.Start(_L("Test1: Fragmenting the memory and performing a general defrag")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (gDrive != KNoRemovableDrive) sl@0: { sl@0: FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: origFree = gTotalPageCount.iFreePages; sl@0: origUnknown = gTotalPageCount.iUnknownPages; sl@0: origFixed = gTotalPageCount.iFixedPages; sl@0: origMovable = gTotalPageCount.iMovablePages; sl@0: origDiscard = gTotalPageCount.iDiscardablePages; sl@0: origOther = gTotalPageCount.iOtherPages; sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: GetAllPageInfo(); sl@0: sl@0: if ((origUnknown != gTotalPageCount.iUnknownPages) || sl@0: (origFixed != gTotalPageCount.iFixedPages) || sl@0: (origMovable != gTotalPageCount.iMovablePages) || sl@0: (origDiscard != gTotalPageCount.iDiscardablePages) || sl@0: (origOther != gTotalPageCount.iOtherPages)) sl@0: { sl@0: test.Printf(_L("Fail: Pages after defrag are not equal to those before")); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: // This will free any allocated memory sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test2: Fragmenting the memory and performing an EmptyZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (gDrive != KNoRemovableDrive) sl@0: { sl@0: FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); sl@0: } sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_EMPTY, DEFRAG_VER_SYNC, zoneID); sl@0: sl@0: if (r != KErrNoMemory || CheckZoneIsOff(index)) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = -4"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: // This will free any allocated memory sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test3: Fragmenting the memory and performing a ClaimZone")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: if (gDrive != KNoRemovableDrive) sl@0: { sl@0: FillCache(gFilesNeededToFillCache, KDefaultCacheSize); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Cannot find drive to write files to - Not allocating discardable pages through FS Caching\n")); sl@0: } sl@0: sl@0: GetAllPageInfo(); sl@0: origMovable = gTotalPageCount.iMovablePages; sl@0: sl@0: r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID); sl@0: sl@0: GetAllPageInfo(); sl@0: if (r != KErrNoMemory || origMovable != gTotalPageCount.iMovablePages) sl@0: { sl@0: test.Printf(_L("Fail: r = %d, expected = -4"), r); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: // This will free any allocated memory. sl@0: TestEnd(); sl@0: sl@0: test.Next(_L("Test4: Calling ZoneAllocPhysicalRam to allocate discontiguous fixed pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: origFree = gTotalPageCount.iFreePages; sl@0: origUnknown = gTotalPageCount.iUnknownPages; sl@0: origFixed = gTotalPageCount.iFixedPages; sl@0: origMovable = gTotalPageCount.iMovablePages; sl@0: origDiscard = gTotalPageCount.iDiscardablePages; sl@0: origOther = gTotalPageCount.iOtherPages; sl@0: sl@0: r = Ldd.ZoneAllocDiscontiguous(zoneID, (TInt)(origFree / 2)); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iFixedPages < (origFixed + (origFree / 2))) sl@0: { sl@0: test.Printf(_L("Fail: fixed pages = 0x%x, expected >= 0x%x\n"), sl@0: gTotalPageCount.iFixedPages, (origFixed + (origFree / 2))); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: sl@0: test.Next(_L("Test5: Calling ZoneAllocPhysicalRam to allocate contiguous fixed pages")); sl@0: TestStart(); sl@0: sl@0: AllocMovable(gChunkArray1, gChunkArraySize1, KNumAllocChunks); sl@0: FreeMovable(gChunkArray1, gChunkArraySize1); sl@0: sl@0: GetAllPageInfo(); sl@0: origFree = gTotalPageCount.iFreePages; sl@0: origUnknown = gTotalPageCount.iUnknownPages; sl@0: origFixed = gTotalPageCount.iFixedPages; sl@0: origMovable = gTotalPageCount.iMovablePages; sl@0: origDiscard = gTotalPageCount.iDiscardablePages; sl@0: origOther = gTotalPageCount.iOtherPages; sl@0: sl@0: TInt allocSize = 50 << gPageShift; sl@0: sl@0: r = Ldd.ZoneAllocContiguous(zoneID, allocSize); sl@0: sl@0: GetAllPageInfo(); sl@0: if (gTotalPageCount.iFixedPages < (origFixed + (allocSize >> gPageShift))) sl@0: { sl@0: test.Printf(_L("Fail: fixed pages = 0x%x, expected >= 0x%x\n"), sl@0: gTotalPageCount.iFixedPages, (origFixed + (allocSize >> gPageShift))); sl@0: CLEANUP(Ldd.FreeAllFixedPages()); sl@0: CLEANUP(RemoveChunkAlloc(gChunkArray1, gChunkArraySize1)); sl@0: TEST_FAIL; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Passed...")); sl@0: } sl@0: Ldd.FreeAllFixedPages(); sl@0: RemoveChunkAlloc(gChunkArray1, gChunkArraySize1); sl@0: TestEnd(); sl@0: sl@0: if (gPagedRom) sl@0: { sl@0: test_KErrNone(DPTest::FlushCache()); sl@0: ResetDPCache(); sl@0: } sl@0: sl@0: gTheFs.Close(); sl@0: if (gDrive != KNoRemovableDrive) sl@0: { sl@0: FormatMMC(); sl@0: } sl@0: sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // sl@0: // RunDefragTests sl@0: // sl@0: // List of defrag tests to be run sl@0: // sl@0: void RunDefragTests() sl@0: { sl@0: test.Start(_L("Testing the moving of pages in a defrag")); sl@0: TestMovPgsDefrag(); sl@0: sl@0: test.Next(_L("Verifying the implementation of the function TRamDefragRequest::DefragRam() arg aMaxPages")); sl@0: TestDefragRamMaxPages(); sl@0: sl@0: test.Next(_L("Verifying the implementation of the function TRamDefragRequest::EmptyRamZone()")); sl@0: TestEmptyRamZone(); sl@0: sl@0: test.Next(_L("Verifying the implementation of the function Epoc::GetRamZonePageCount()")); sl@0: TestGetRamZonePageCount(); sl@0: sl@0: test.Next(_L("Verifying the implementation of the function TRamDefragRequest::ClaimRamZone()")); sl@0: TestClaimRamZone(); sl@0: sl@0: test.Next(_L("Verifying the implementation of the function TRamDefragRequest::Cancel()")); sl@0: TestCancelDefrag(); sl@0: sl@0: test.Next(_L("Verifying that pages are moved correctly")); sl@0: TestMovingPages(); sl@0: sl@0: test.Next(_L("Verifying Semaphore Methods of the Defrag")); sl@0: TestDefragSemMethod(); sl@0: sl@0: test.Next(_L("Verifying Dfc Methods of the Defrag")); sl@0: TestDefragDfcMethod(); sl@0: sl@0: test.Next(_L("Testing priorities")); sl@0: TestPriorities(); sl@0: sl@0: test.Next(_L("Testing File System Caching")); sl@0: if (!gPagedRom) sl@0: { sl@0: TestFileCaching(); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Skipping... \n")); sl@0: } sl@0: sl@0: test.Next(_L("Testing general RAM defrag implementation")); sl@0: TestGenDefrag(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // RunAllocTests sl@0: // sl@0: // List of allocating tests to be run sl@0: // These tests only need to be executed once sl@0: // sl@0: void RunAllocTests() sl@0: { sl@0: test.Start(_L("Verifying the allocating strategies")); sl@0: TestAllocStrategies(); sl@0: sl@0: test.Next(_L("Verifying the contiguous overload of Epoc::ZoneAllocPhysicalRam()")); sl@0: TestZoneAllocContiguous(); sl@0: sl@0: test.Next(_L("Verifying the discontiguous overload of Epoc::ZoneAllocPhysicalRam()")); sl@0: TestZoneAllocDiscontiguous(); sl@0: sl@0: test.Next(_L("Test Free Zone")); sl@0: TestFreeZone(); sl@0: sl@0: test.Next(_L("Testing zone flags")); sl@0: TestFlags(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // E32Main sl@0: // sl@0: // Main entry point. sl@0: // sl@0: TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: DeviceDriver(TEST_DRIVER_OPEN); sl@0: gTotalRamLost = 0; sl@0: sl@0: TInt r = TestSetup(); sl@0: if (r != KErrNone) sl@0: { sl@0: test.Printf(_L("Test Setup failed, r = %d\n"), r); sl@0: TestCleanup(); sl@0: return r; sl@0: } sl@0: sl@0: if (gZoneCount == 1) sl@0: { sl@0: GetAllPageInfo(); sl@0: sl@0: test.Start(_L("Zone Count 1...")); sl@0: TestOneZoneConfig(); sl@0: } sl@0: else sl@0: { sl@0: test.Start(_L("Running Alloc tests")); sl@0: RunAllocTests(); sl@0: sl@0: Ldd.ResetDriver(); sl@0: Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: sl@0: sl@0: test.Next(_L("Running Defrag tests")); sl@0: RunDefragTests(); sl@0: sl@0: Ldd.ResetDriver(); sl@0: Ldd.CallDefrag(DEFRAG_TYPE_GEN, DEFRAG_VER_SYNC); sl@0: } sl@0: sl@0: sl@0: test.Printf(_L("The total number of test steps failed = %d\n"), gTestStepFailed); sl@0: test_Equal(KErrNone, gTestStepFailed); sl@0: sl@0: TestCleanup(); sl@0: sl@0: DeviceDriver(TEST_DRIVER_CLOSE); sl@0: test.End(); sl@0: test.Close(); sl@0: sl@0: return 0; sl@0: }