kerneltest/e32test/defrag/t_ramdefrag.cpp
changeset 132 e4a7b1cbe40c
parent 90 947f0dc9f7a8
child 176 af6ec97d9189
equal deleted inserted replaced
131:e880629062dd 132:e4a7b1cbe40c
    31 #include <e32svr.h>
    31 #include <e32svr.h>
    32 #include <e32msgqueue.h>
    32 #include <e32msgqueue.h>
    33 #include <e32math.h>
    33 #include <e32math.h>
    34 #include <hal.h>
    34 #include <hal.h>
    35 #include "testdefs.h"
    35 #include "testdefs.h"
       
    36 #include "..\mmu\mmudetect.h"
    36 
    37 
    37 
    38 
    38 #include <dptest.h>
    39 #include <dptest.h>
    39 
    40 
    40 #include "t_ramdefrag.h"
    41 #include "t_ramdefrag.h"
   126 LOCAL_D RFile gFile[KNumFilesOrig];
   127 LOCAL_D RFile gFile[KNumFilesOrig];
   127 
   128 
   128 LOCAL_D TInt* gCandList1;											// Array of zones that have the same preference and the same
   129 LOCAL_D TInt* gCandList1;											// Array of zones that have the same preference and the same
   129 LOCAL_D TInt* gCandList2;											// amount of free pages
   130 LOCAL_D TInt* gCandList2;											// amount of free pages
   130 const TInt KInvalidCandIndex = -1;
   131 const TInt KInvalidCandIndex = -1;
       
   132 LOCAL_D TUint gMemModel;
   131 
   133 
   132 //
   134 //
   133 // GetDrive
   135 // GetDrive
   134 //
   136 //
   135 // Gets the removable drive number
   137 // Gets the removable drive number
   487 		TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), 
   489 		TESTDEBUG(test.Printf(_L("Original CacheSize: minCacheSize = 0x%x, maxCacheSize = 0x%x, currentCacheSize = 0x%x\n"), 
   488 									gOriginalMinCacheSize >> gPageShift, gOriginalMaxCacheSize >> gPageShift, 
   490 									gOriginalMinCacheSize >> gPageShift, gOriginalMaxCacheSize >> gPageShift, 
   489 									currentCacheSize >> gPageShift));
   491 									currentCacheSize >> gPageShift));
   490 		}
   492 		}
   491 
   493 
       
   494 	// Get the memory model of the kernel that this test is running on.
       
   495 	gMemModel = MemModelType();
   492 	return KErrNone;
   496 	return KErrNone;
   493 	}
   497 	}
   494 
   498 
   495 
   499 
   496 // 
   500 // 
  1534 		test.Printf(_L("No in use RAM zones found????\n"));
  1538 		test.Printf(_L("No in use RAM zones found????\n"));
  1535 		return KErrNotFound;
  1539 		return KErrNotFound;
  1536 		}
  1540 		}
  1537 
  1541 
  1538 	if (totalMorePrefInUse > requiredMovDis)
  1542 	if (totalMorePrefInUse > requiredMovDis)
  1539 		{// There enough allocatable pages in the RAM zones below the currently 
  1543 		{// There are enough allocatable pages in the RAM zones below the currently 
  1540 		// least preferable RAM in use.
  1544 		// least preferable RAM in use.
  1541 		test.Printf(_L("Memory is spread out totalMorePref 0x%x required 0x%x\n"), totalMorePrefInUse, requiredMovDis);
  1545 		test.Printf(_L("Memory is spread out totalMorePref 0x%x required 0x%x\n"), totalMorePrefInUse, requiredMovDis);
  1542 		if (verifySpread)
  1546 		if (verifySpread)
  1543 			return KErrGeneral;
  1547 			return KErrGeneral;
  1544 		}
  1548 		}
  7071 //! @SYMTestType				CIT
  7075 //! @SYMTestType				CIT
  7072 //! @SYMTestCaseDesc			Verifying the function Epoc::FreePhysicalRam()
  7076 //! @SYMTestCaseDesc			Verifying the function Epoc::FreePhysicalRam()
  7073 //! @SYMPREQ					PREQ308
  7077 //! @SYMPREQ					PREQ308
  7074 //! @SYMTestPriority			High
  7078 //! @SYMTestPriority			High
  7075 //! @SYMTestActions				
  7079 //! @SYMTestActions				
  7076 //! 	1.	Allocate fixed pages and call function to free all fixed pages allocated.  
  7080 //! 	1.	Allocate fixed pages and call function to free all fixed pages allocated.
       
  7081 //!		2.	Claim a RAM zone and then free it via Epoc::FreeRamZone().
       
  7082 //!		3.	Invoke Epoc::FreeRamZone() with an invalid RAM zone ID.
  7077 //! 
  7083 //! 
  7078 //! @SYMTestExpectedResults
  7084 //! @SYMTestExpectedResults
  7079 //! 	1.	KErrNone
  7085 //! 	1.	KErrNone
       
  7086 //!		2.	KErrNone
       
  7087 //!		3.	KErrArgument
  7080 //---------------------------------------------------------------------------------------------------------------------
  7088 //---------------------------------------------------------------------------------------------------------------------
  7081 TInt TestFreeZone()
  7089 TInt TestFreeZone()
  7082 	{
  7090 	{
  7083 	TInt r = 0;
  7091 	TInt r = 0;
  7084 	TUint zoneID = 0;
  7092 	TUint zoneID = 0;
  7085 	test.Start(_L("Test1: Free allocated pages"));	
  7093 	test.Start(_L("Test1: Freeing allocated pages"));	
  7086 	TestStart();	
  7094 	TestStart();	
  7087 	
  7095 	
  7088 	TInt pages = 50;
  7096 	TInt pages = 50;
  7089 
  7097 
  7090 	GetAllPageInfo();
  7098 	GetAllPageInfo();
  7126 			test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone);
  7134 			test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone);
  7127 			TEST_FAIL;
  7135 			TEST_FAIL;
  7128 			}
  7136 			}
  7129 		}
  7137 		}
  7130 	TestEnd();
  7138 	TestEnd();
  7131 
  7139 	test.End();
       
  7140 
       
  7141 	test.Start(_L("Test2: Epoc::FreeRamZone() on a claimed RAM zone"));
       
  7142 	TestStart();
       
  7143 	GetAllPageInfo();
       
  7144 	TUint zoneIndex = 0;
       
  7145 	while (zoneIndex < gZoneCount)
       
  7146 		{
       
  7147 		if (gZoneUtilArray[zoneIndex].iFreePages == gZoneUtilArray[zoneIndex].iPhysPages)
       
  7148 			break;
       
  7149 		zoneIndex++;
       
  7150 		}
       
  7151 	if (zoneIndex >= gZoneCount)
       
  7152 		{
       
  7153 		test.Printf(_L("Cannot find zone to perform test, Skipping test step...\n"));
       
  7154 		goto Test2End;
       
  7155 		}
       
  7156 	zoneID = gZoneConfigArray[zoneIndex].iZoneId;
       
  7157 	r = Ldd.CallDefrag(DEFRAG_TYPE_CLAIM, DEFRAG_VER_SYNC, zoneID);
       
  7158 	if (r != KErrNone)
       
  7159 		{
       
  7160 		test.Printf(_L("Fail: r = %d, expected = %d\n"), r, KErrNone);
       
  7161 		TEST_FAIL;
       
  7162 		}
       
  7163 	GetAllPageInfo();
       
  7164 	if (gZoneUtilArray[zoneIndex].iPhysPages != gZoneUtilArray[zoneIndex].iAllocFixed)
       
  7165 		{
       
  7166 		test.Printf(_L("Fail: RAM zone ID %d not claimed successfully"), zoneID);
       
  7167 		TEST_FAIL;
       
  7168 		}
       
  7169 	r = Ldd.FreeZoneId(zoneID);
       
  7170 	GetAllPageInfo();
       
  7171 	if (r != KErrNone ||
       
  7172 		gZoneUtilArray[zoneIndex].iPhysPages != gZoneUtilArray[zoneIndex].iFreePages)
       
  7173 		{
       
  7174 		test.Printf(_L("Fail: RAM zone ID %d not freed successfully r=%d"), zoneID, r);
       
  7175 		TEST_FAIL;
       
  7176 		}
       
  7177 Test2End:
       
  7178 	TestEnd();
       
  7179 	test.End();
       
  7180 
       
  7181 	test.Start(_L("Test2: Epoc::FreeRamZone() on an invalid RAM zone"));
       
  7182 	TestStart();
       
  7183 	r = Ldd.FreeZoneId(KInvalidZoneID);
       
  7184 	if (r != KErrArgument)
       
  7185 		{
       
  7186 		test.Printf(_L("Fail: Error RAM zone ID %d r=%d"), KInvalidZoneID, r);
       
  7187 		TEST_FAIL;
       
  7188 		}
       
  7189 	
       
  7190 	TestEnd();
  7132 	test.End();
  7191 	test.End();
  7133 	return KErrNone;
  7192 	return KErrNone;
  7134 	}
  7193 	}
  7135 
  7194 
  7136 
  7195 
  9382 	Ldd2.FreeAllFixedPages();
  9441 	Ldd2.FreeAllFixedPages();
  9383 	TestEnd();
  9442 	TestEnd();
  9384 
  9443 
  9385 	test.Next(_L("Test5: Filling the FS Cache and allocating more than 16 contiguous fixed pages"));	
  9444 	test.Next(_L("Test5: Filling the FS Cache and allocating more than 16 contiguous fixed pages"));	
  9386 	TestStart();
  9445 	TestStart();
       
  9446 
       
  9447 	if (gMemModel >= EMemModelTypeFlexible)
       
  9448 		{// The flexible memory model won't flush the whole paging cache for 
       
  9449 		// contiguous allocations >16 pages so skip the next test.
       
  9450 		test.Printf(_L("This memory model won't flush the cache - Skipping...\n"));
       
  9451 		goto SkipTest5;
       
  9452 		}
       
  9453 
  9387 	// TestEnd() will have reduced any cache pages to minimum so just get current 
  9454 	// TestEnd() will have reduced any cache pages to minimum so just get current 
  9388 	// count of discardable pages.
  9455 	// count of discardable pages.
  9389 	GetAllPageInfo();
  9456 	GetAllPageInfo();
  9390 	minDiscardPages = gTotalPageCount.iDiscardablePages;
  9457 	minDiscardPages = gTotalPageCount.iDiscardablePages;
  9391 	
  9458