kerneltest/e32test/mmu/t_cachechunk.cpp
changeset 0 a41df078684a
child 97 41f0cfe18c80
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\mmu\t_chunk.cpp
       
    15 // Tests on RChunk objects in connection with demand paging.
       
    16 // Tests exercise the locking, unlocking, commiting and decommiting of 
       
    17 // pages to chunk objects.
       
    18 // 1  Check Unlocked page gets counted as free memory
       
    19 // 2  Check Unlock/Lock preserves page contents
       
    20 // 3  Tests at chunk offset '0'
       
    21 // 4    Check Lock is idempotent
       
    22 // 5    Check non page aligned Unlock/Lock
       
    23 // 6    Check unlocked pages get reclaimed for new memory allocation
       
    24 // 7    Check reclaimed memory is unmapped from original location
       
    25 // 8    Check Lock fails when memory is reclaimed
       
    26 // 9    Check Lock failure Decommits memory
       
    27 // 10   Recommit memory to chunk
       
    28 // 11   Check Commit on unlocked pages
       
    29 // 12   Check Commit on unlocked and reclaimed pages
       
    30 // 13   Restore chunk
       
    31 // 14 Tests at chunk offset 'PageSize'
       
    32 // 15   Check Lock is idempotent
       
    33 // 16   Check non page aligned Unlock/Lock
       
    34 // 17   Check unlocked pages get reclaimed for new memory allocation
       
    35 // 18   Check reclaimed memory is unmapped from original location
       
    36 // 19   Check Lock fails when memory is reclaimed
       
    37 // 20   Check Lock failure Decommits memory
       
    38 // 21   Recommit memory to chunk
       
    39 // 22   Check Commit on unlocked pages
       
    40 // 23   Check Commit on unlocked and reclaimed pages
       
    41 // 24   Restore chunk
       
    42 // 25 Tests at chunk offset '0x100000-PageSize'
       
    43 // 26   Check Lock is idempotent
       
    44 // 27   Check non page aligned Unlock/Lock
       
    45 // 28   Check unlocked pages get reclaimed for new memory allocation
       
    46 // 29   Check reclaimed memory is unmapped from original location
       
    47 // 30   Check Lock fails when memory is reclaimed
       
    48 // 31   Check Lock failure Decommits memory
       
    49 // 32   Recommit memory to chunk
       
    50 // 33   Check Commit on unlocked pages
       
    51 // 34   Check Commit on unlocked and reclaimed pages
       
    52 // 35   Restore chunk
       
    53 // 36 Tests at chunk offset '0x400000-PageSize'
       
    54 // 37   Check Lock is idempotent
       
    55 // 38   Check non page aligned Unlock/Lock
       
    56 // 39   Check unlocked pages get reclaimed for new memory allocation
       
    57 // 40   Check reclaimed memory is unmapped from original location
       
    58 // 41   Check Lock fails when memory is reclaimed
       
    59 // 42   Check Lock failure Decommits memory
       
    60 // 43   Recommit memory to chunk
       
    61 // 44 Check Commit on unlocked pages
       
    62 // 45 Check Commit on unlocked and reclaimed pages
       
    63 // 46 Restore chunk
       
    64 // 47 Big Unlock/Lock
       
    65 // 48 Benchmarks...
       
    66 // 49 Close chunk with unlocked pages which have been flushed
       
    67 // 
       
    68 //
       
    69 
       
    70 //! @SYMTestCaseID			KBASE-T_CACHECHUNK-0336
       
    71 //! @SYMTestType			UT
       
    72 //! @SYMPREQ				PREQ1110
       
    73 //! @SYMTestCaseDesc		Demand Paging Loader Stress Tests
       
    74 //! @SYMTestActions			0  Commit all of memory
       
    75 //! @SYMTestExpectedResults All tests should pass.
       
    76 //! @SYMTestPriority        High
       
    77 //! @SYMTestStatus          Implemented
       
    78 
       
    79 #define __E32TEST_EXTENSION__
       
    80 
       
    81 #include <e32test.h>
       
    82 #include <e32panic.h>
       
    83 #include <e32svr.h>
       
    84 #include <hal.h>
       
    85 #include "mmudetect.h"
       
    86 #include "d_memorytest.h"
       
    87 #include "d_gobble.h"
       
    88 #include <dptest.h>
       
    89 #include "freeram.h"
       
    90 
       
    91 LOCAL_D RTest test(_L("T_CACHECHUNK"));
       
    92 
       
    93 RMemoryTestLdd MemoryTest;
       
    94 
       
    95 RChunk TestChunk;
       
    96 TUint8* TestChunkBase;
       
    97 TInt CommitEnd;
       
    98 TInt PageSize;
       
    99 TInt NoFreeRam;
       
   100 RTimer Timer;
       
   101 
       
   102 
       
   103 
       
   104 void FillPage(TUint aOffset)
       
   105 	{
       
   106 	TUint8* ptr = TestChunkBase+aOffset;
       
   107 	TUint8* ptrEnd = ptr+PageSize;
       
   108 	do *((TUint32*&)ptr)++ = aOffset+=4;
       
   109 	while(ptr<ptrEnd);
       
   110 	}
       
   111 
       
   112 
       
   113 TBool CheckPage(TUint aOffset)
       
   114 	{
       
   115 	TUint8* ptr = TestChunkBase+aOffset;
       
   116 	TUint8* ptrEnd = ptr+PageSize;
       
   117 	do if(*((TUint32*&)ptr)++ != (aOffset+=4)) break;
       
   118 	while(ptr<ptrEnd);
       
   119 	return ptr==ptrEnd;
       
   120 	}
       
   121 
       
   122 
       
   123 TBool CheckPages(TUint aOffset, TInt aNumPages)
       
   124 	{
       
   125 	while(aNumPages--)
       
   126 		if(!CheckPage(aOffset+=PageSize))
       
   127 			return EFalse;
       
   128 	return ETrue;
       
   129 	}
       
   130 
       
   131 
       
   132 TBool IsPageMapped(TUint aOffset)
       
   133 	{
       
   134 	TUint32 value;
       
   135 	TInt r=MemoryTest.ReadMemory(TestChunkBase+aOffset,value);
       
   136 	return r==KErrNone;
       
   137 	}
       
   138 
       
   139 
       
   140 void Tests(TInt aOffset)
       
   141 	{
       
   142 	if(aOffset+5*PageSize>=CommitEnd)
       
   143 		{
       
   144 		test.Start(_L("TEST NOT RUN - Not enough system RAM"));
       
   145 		test.End();
       
   146 		return;
       
   147 		}
       
   148 	TInt r;
       
   149 	TInt freeRam;
       
   150 
       
   151 	TUint origChunkSize = TestChunk.Size();
       
   152 
       
   153 	test.Start(_L("Check Unlock is idempotent"));
       
   154 	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
       
   155 	test_KErrNone(r);
       
   156 	freeRam = FreeRam();
       
   157 	test(freeRam==NoFreeRam+PageSize);
       
   158 	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
       
   159 	test_KErrNone(r);
       
   160 	test_Equal(FreeRam(), freeRam);
       
   161 	// Ensure unlock on reclaimed pages is idempotent
       
   162 	TInt flushSupported = UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
       
   163 	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
       
   164 	test_KErrNone(r);
       
   165 	test_Equal(FreeRam(), freeRam);
       
   166 	test_Equal(origChunkSize, TestChunk.Size());
       
   167 	
       
   168 	if (flushSupported == KErrNotSupported)
       
   169 		{// Flush cache not supported so lock won't fail so no need to recommit the pages.
       
   170 		test_KErrNone(TestChunk.Lock(aOffset+PageSize,PageSize));
       
   171 		}
       
   172 	else
       
   173 		{// Recommit the reclaimed pages.
       
   174 		test_KErrNone(flushSupported);
       
   175 		test_Equal(KErrNotFound, TestChunk.Lock(aOffset+PageSize,PageSize));
       
   176 		test_KErrNone(TestChunk.Commit(aOffset+PageSize,PageSize));
       
   177 		}
       
   178 
       
   179 	test.Next(_L("Check Lock is idempotent"));
       
   180 	r = TestChunk.Lock(aOffset,3*PageSize);
       
   181 	test_KErrNone(r);
       
   182 	freeRam = FreeRam();
       
   183 	test(freeRam==NoFreeRam);
       
   184 	CheckPages(aOffset,3);
       
   185 	r = TestChunk.Lock(aOffset,3*PageSize);
       
   186 	test_KErrNone(r);
       
   187 	CheckPages(aOffset,3);
       
   188 	freeRam = FreeRam();
       
   189 	test(freeRam==NoFreeRam);
       
   190 	test_Equal(origChunkSize, TestChunk.Size());
       
   191 
       
   192 	test.Next(_L("Check non page aligned Unlock/Lock"));
       
   193 	r = TestChunk.Unlock(aOffset+PageSize-1,1);
       
   194 	test_KErrNone(r);
       
   195 	freeRam = FreeRam();
       
   196 	test(freeRam==NoFreeRam+PageSize);
       
   197 	r = TestChunk.Lock(aOffset+PageSize-1,1);
       
   198 	test_KErrNone(r);
       
   199 	freeRam = FreeRam();
       
   200 	test(freeRam==NoFreeRam);
       
   201 	r = TestChunk.Unlock(aOffset+PageSize-1,2);
       
   202 	test_KErrNone(r);
       
   203 	freeRam = FreeRam();
       
   204 	test(freeRam==NoFreeRam+PageSize*2);
       
   205 	r = TestChunk.Lock(aOffset+PageSize-1,2);
       
   206 	test_KErrNone(r);
       
   207 	freeRam = FreeRam();
       
   208 	test(freeRam==NoFreeRam);
       
   209 	test_Equal(origChunkSize, TestChunk.Size());
       
   210 
       
   211 	test.Next(_L("Check unlocked pages get reclaimed for new memory allocation"));
       
   212 	r=TestChunk.Commit(CommitEnd,PageSize);
       
   213 	test(r==KErrNoMemory);
       
   214 	r = TestChunk.Unlock(aOffset,4*PageSize);
       
   215 	test_KErrNone(r);
       
   216 	freeRam = FreeRam();
       
   217 	test(freeRam==NoFreeRam+PageSize*4);
       
   218 	r=TestChunk.Commit(CommitEnd,PageSize);
       
   219 	test_KErrNone(r);
       
   220 	freeRam = FreeRam();
       
   221 	test(freeRam<NoFreeRam+PageSize*4);
       
   222 	r=TestChunk.Decommit(CommitEnd,PageSize);
       
   223 	test_KErrNone(r);
       
   224 	freeRam = FreeRam();
       
   225 	test(freeRam==NoFreeRam+PageSize*4);
       
   226 	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
       
   227 	freeRam = FreeRam();
       
   228 	test(freeRam==NoFreeRam+PageSize*4);
       
   229 
       
   230 #ifndef __WINS__ // wins fakery doesn't actually do this
       
   231 	test.Next(_L("Check reclaimed memory is unmapped and decommitted from original location"));
       
   232 	TInt mappedPages = IsPageMapped(aOffset+PageSize*0);
       
   233 	mappedPages += IsPageMapped(aOffset+PageSize*1);
       
   234 	mappedPages += IsPageMapped(aOffset+PageSize*2);
       
   235 	mappedPages += IsPageMapped(aOffset+PageSize*3);
       
   236 	test(mappedPages<4);
       
   237 #endif
       
   238 	if(aOffset>PageSize)
       
   239 		{
       
   240 		test(CheckPage(aOffset+PageSize*-1)); // should be left mapped
       
   241 		}
       
   242 	test(CheckPage(aOffset+PageSize*4)); // should be left mapped
       
   243 
       
   244 	test.Next(_L("Check Lock fails when memory is reclaimed"));
       
   245 	r = TestChunk.Lock(aOffset,4*PageSize);
       
   246 	test(r==KErrNotFound);
       
   247 	freeRam = FreeRam();
       
   248 	test(freeRam==NoFreeRam+PageSize*4);
       
   249 
       
   250 	test.Next(_L("Check Lock failure Decommits memory"));
       
   251 	test(!IsPageMapped(aOffset+PageSize*0));
       
   252 	test(!IsPageMapped(aOffset+PageSize*1));
       
   253 	test(!IsPageMapped(aOffset+PageSize*2));
       
   254 	test(!IsPageMapped(aOffset+PageSize*3));
       
   255 	test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
       
   256 
       
   257 	test.Next(_L("Recommit memory to chunk"));
       
   258 	TInt offset;
       
   259 	for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
       
   260 		{
       
   261 		r=TestChunk.Commit(offset,PageSize);
       
   262 		test_KErrNone(r);
       
   263 		FillPage(offset);
       
   264 		}
       
   265 	freeRam = FreeRam();
       
   266 	test(freeRam==NoFreeRam);
       
   267 	test_Equal(origChunkSize, TestChunk.Size());
       
   268 
       
   269 	test.Next(_L("Check Commit on unlocked pages"));
       
   270 	r = TestChunk.Unlock(aOffset,4*PageSize);
       
   271 	test_KErrNone(r);
       
   272 	freeRam = FreeRam();
       
   273 	test(freeRam>=NoFreeRam+PageSize*4);
       
   274 	r=TestChunk.Commit(aOffset,4*PageSize);
       
   275 	test(r==KErrAlreadyExists);
       
   276 	freeRam = FreeRam();
       
   277 	test(freeRam>=NoFreeRam+PageSize*4);
       
   278 	test_Equal(origChunkSize, TestChunk.Size());
       
   279 
       
   280 	test.Next(_L("Check Commit on unlocked and reclaimed pages"));
       
   281 	// unlock and force a page to be reclaimed...
       
   282 	r=TestChunk.Commit(CommitEnd,PageSize);
       
   283 	test_KErrNone(r);
       
   284 	r=TestChunk.Decommit(CommitEnd,PageSize);
       
   285 	test_KErrNone(r);
       
   286 	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
       
   287 	freeRam = FreeRam();
       
   288 	test(freeRam>=NoFreeRam+PageSize*4);
       
   289 	// check can't commit any pages (because they are unlocked, not decommitted)...
       
   290 	r=TestChunk.Commit(aOffset+PageSize*0,PageSize);
       
   291 	test(r==KErrAlreadyExists);
       
   292 	r=TestChunk.Commit(aOffset+PageSize*1,PageSize);
       
   293 	test(r==KErrAlreadyExists);
       
   294 	r=TestChunk.Commit(aOffset+PageSize*2,PageSize);
       
   295 	test(r==KErrAlreadyExists);
       
   296 	r=TestChunk.Commit(aOffset+PageSize*3,PageSize);
       
   297 	test(r==KErrAlreadyExists);
       
   298 	freeRam = FreeRam();
       
   299 	test(freeRam>=NoFreeRam+PageSize*4);
       
   300 	test_Equal(origChunkSize, TestChunk.Size());
       
   301 	// Restore the chunk to original size.
       
   302 	r = TestChunk.Lock(aOffset,4*PageSize);
       
   303 	test_Equal(r, KErrNotFound);
       
   304 	freeRam = FreeRam();
       
   305 	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
       
   306 	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
       
   307 	r = TestChunk.Commit(aOffset, PageSize*4);
       
   308 	test_KErrNone(r);
       
   309 
       
   310 	test.Next(_L("Check Decommit on unlocked pages"));
       
   311 	r = TestChunk.Unlock(aOffset,PageSize*4);
       
   312 	test_KErrNone(r);
       
   313 	test(FreeRam() >= NoFreeRam+PageSize*4);
       
   314 	r=TestChunk.Decommit(aOffset, PageSize*4);
       
   315 	test_KErrNone(r);
       
   316 	freeRam = FreeRam();
       
   317 	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
       
   318 	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
       
   319 	// Restore chunk back to original state
       
   320 	r = TestChunk.Commit(aOffset, PageSize*4);
       
   321 	test_KErrNone(r);
       
   322 	test(FreeRam() == NoFreeRam);
       
   323 
       
   324 	test.Next(_L("Check Decommit on unlocked and reclaimed pages"));
       
   325 	r = TestChunk.Unlock(aOffset,PageSize*4);
       
   326 	test_KErrNone(r);
       
   327 	freeRam = FreeRam();
       
   328 	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
       
   329 	r=TestChunk.Commit(CommitEnd,PageSize);
       
   330 	test_KErrNone(r);
       
   331 	r=TestChunk.Decommit(CommitEnd,PageSize);
       
   332 	test_KErrNone(r);
       
   333 	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
       
   334 	freeRam = FreeRam();
       
   335 	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
       
   336 	r=TestChunk.Decommit(aOffset, PageSize*4);
       
   337 	test_KErrNone(r);
       
   338 	freeRam = FreeRam();
       
   339 	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
       
   340 	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
       
   341 
       
   342 	test.Next(_L("Restore chunk"));
       
   343 	test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
       
   344 	for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
       
   345 		{
       
   346 		r=TestChunk.Commit(offset,PageSize);
       
   347 		test_KErrNone(r);
       
   348 		FillPage(offset);
       
   349 		}
       
   350 	freeRam = FreeRam();
       
   351 	test(freeRam==NoFreeRam);
       
   352 	test_Equal(origChunkSize, TestChunk.Size());
       
   353 
       
   354 	test.End();
       
   355 	}
       
   356 
       
   357 
       
   358 
       
   359 void TestBenchmarks()
       
   360 	{
       
   361 	TInt r = TestChunk.Unlock(0,CommitEnd); // start with everthing unlocked
       
   362 	test_KErrNone(r);
       
   363 	TInt testSizes[] = { PageSize,1<<16,1<<20,0 };
       
   364 	TInt* sizes = testSizes;
       
   365 	TInt size;
       
   366 	while((size=*sizes++)!=0)
       
   367 		{
       
   368 		TRequestStatus status;
       
   369 		Timer.After(status,1);
       
   370 		User::WaitForRequest(status);
       
   371 		TInt KRunTime = 1*1000*1000;
       
   372 		Timer.After(status,KRunTime);
       
   373 		TInt count = 0;
       
   374 		while(status==KRequestPending)
       
   375 			{
       
   376 			r = TestChunk.Lock(0,size);
       
   377 			test_KErrNone(r);
       
   378 			r = TestChunk.Unlock(0,size);
       
   379 			test_KErrNone(r);
       
   380 			++count;
       
   381 			}
       
   382 		User::WaitForRequest(status);
       
   383 		test.Printf(_L("Unlock/Lock of %d kB takes %d us\n"),size>>10,KRunTime/count);
       
   384 		}
       
   385 	}
       
   386 
       
   387 
       
   388 
       
   389 void TestUnlockOld()
       
   390 	{
       
   391 	// we start with TestChunk being locked and no or little free RAM
       
   392 	// (hence live list should be close to minimum size.)
       
   393 
       
   394 	// get sizes...
       
   395 	TUint min = 0;
       
   396 	TUint max = 0;
       
   397 	TUint cur = 0;
       
   398 	TInt r = DPTest::CacheSize(min,max,cur);
       
   399 
       
   400 	// manipulate demand paging live list so we end up with zero old pages...
       
   401 
       
   402 	r = TestChunk.Unlock(0,min*2); // dump 2*min bytes at start of live list
       
   403 	test_KErrNone(r);
       
   404 	// live list now cur+2*min bytes
       
   405 
       
   406 	r = TestChunk.Commit(CommitEnd,cur); // use up 'cur' bytes of RAM from end of live list
       
   407 	test_KErrNone(r);
       
   408 	// live list now 2*min bytes of pages which were unlocked from our test chunk
       
   409 
       
   410 	// lock pages until free RAM is <= 2 pages.
       
   411 	// this should remove all of the 'old' pages
       
   412 	TUint i = 0;
       
   413 	while(FreeRam()>2*PageSize)
       
   414 		{
       
   415 		TestChunk.Lock(i,PageSize);
       
   416 		i += PageSize;
       
   417 		test(i<=min);
       
   418 		}
       
   419 	// live list now min+2*PageSize bytes, with no old pages
       
   420 
       
   421 	// now commit memory, which forces allocation from the demand paging live list
       
   422 	// which doesn't have any old pages (the purpose of this test)...
       
   423 	TUint extra = 0;
       
   424 	for(;;)
       
   425 		{
       
   426 		r = TestChunk.Commit(CommitEnd+min+extra,PageSize);
       
   427 		if(r==KErrNoMemory)
       
   428 			break;
       
   429 		extra += PageSize;
       
   430 		}
       
   431 	test(extra>0);
       
   432 
       
   433 	// restore commit state...
       
   434 	r = TestChunk.Decommit(CommitEnd,min+extra);
       
   435 	test_KErrNone(r);
       
   436 	r = TestChunk.Decommit(0,min*2);
       
   437 	test_KErrNone(r);
       
   438 	r = TestChunk.Commit(0,min*2);
       
   439 	test_KErrNone(r);
       
   440 	}
       
   441 
       
   442 
       
   443 
       
   444 TInt E32Main()
       
   445 	{
       
   446 	test.Title();
       
   447 
       
   448 	if (!HaveVirtMem())
       
   449 		{
       
   450 		test.Printf(_L("This test requires an MMU\n"));
       
   451 		return KErrNone;
       
   452 		}
       
   453 	test.Start(_L("Initialise test"));
       
   454 	test.Next(_L("Load gobbler LDD"));
       
   455 	TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
       
   456 	test(r==KErrNone || r==KErrAlreadyExists);
       
   457 	RGobbler gobbler;
       
   458 	r = gobbler.Open();
       
   459 	test(r==KErrNone);
       
   460 	TUint32 taken = gobbler.GobbleRAM(496*1024*1024);
       
   461 	test.Printf(_L("Gobbled: %dK\n"), taken/1024);
       
   462 	test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());
       
   463 
       
   464 	test_KErrNone(HAL::Get(HAL::EMemoryPageSize,PageSize));
       
   465 	TInt totalRAM;
       
   466 	test_KErrNone(HAL::Get(HAL::EMemoryRAM, totalRAM));
       
   467 	totalRAM -= taken;
       
   468 	test.Printf(_L("totalRAM=%dK\n"), totalRAM/1024);
       
   469 
       
   470 	test(KErrNone==MemoryTest.Open());
       
   471 	// Create the test chunk.  It must not be paged otherwise
       
   472 	// unlocking its pages will have no effect.
       
   473 	TChunkCreateInfo createInfo;
       
   474 	createInfo.SetCache(totalRAM);
       
   475 	test_KErrNone(TestChunk.Create(createInfo));
       
   476 	TestChunkBase = TestChunk.Base();
       
   477 
       
   478 	test(KErrNone==Timer.CreateLocal());
       
   479 	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
       
   480 
       
   481 	test.Next(_L("Commit all of memory"));
       
   482 	CommitEnd = 0;
       
   483 	while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize)))
       
   484 		{
       
   485 		FillPage(CommitEnd);
       
   486 		CommitEnd += PageSize;
       
   487 		}
       
   488 	test(r==KErrNoMemory);
       
   489 	NoFreeRam = FreeRam();
       
   490 	test(NoFreeRam<=PageSize);
       
   491 
       
   492 	test.Next(_L("Check Unlocked page gets counted as free memory"));
       
   493 	r = TestChunk.Unlock(0,PageSize);
       
   494 	test_KErrNone(r);
       
   495 	TInt freeRam = FreeRam();
       
   496 	test(freeRam==NoFreeRam+PageSize);
       
   497 	r = TestChunk.Lock(0,PageSize);
       
   498 	test_KErrNone(r);
       
   499 	freeRam = FreeRam();
       
   500 	test(freeRam==NoFreeRam);
       
   501 
       
   502 	test.Next(_L("Check Unlock/Lock preserves page contents"));
       
   503 	TInt offset;
       
   504 	for(offset=0; offset<CommitEnd; offset+=PageSize)
       
   505 		{
       
   506 		test(CheckPage(offset));
       
   507 		r = TestChunk.Unlock(offset,PageSize);
       
   508 		test_KErrNone(r);
       
   509 		r = TestChunk.Lock(offset,PageSize);
       
   510 		test_KErrNone(r);
       
   511 		test(CheckPage(offset));
       
   512 		freeRam = FreeRam();
       
   513 		test(freeRam==NoFreeRam);
       
   514 		}
       
   515 
       
   516 	test.Next(_L("Tests at chunk offset '0'"));
       
   517 	Tests(0);
       
   518 	test.Next(_L("Tests at chunk offset 'PageSize'"));
       
   519 	Tests(PageSize);
       
   520 	test.Next(_L("Tests at chunk offset '0x100000-PageSize'"));
       
   521 	Tests(0x100000-PageSize);
       
   522 	test.Next(_L("Tests at chunk offset '0x400000-PageSize'"));
       
   523 	Tests(0x400000-PageSize);
       
   524 
       
   525 	// Remove limit on max size of live list
       
   526 	TUint originalMin = 0;
       
   527 	TUint originalMax = 0;
       
   528 	TUint currentSize = 0;
       
   529 	r = DPTest::CacheSize(originalMin, originalMax, currentSize);
       
   530 	test(r == KErrNone || r == KErrNotSupported);
       
   531 	TBool resizeCache = r == KErrNone;
       
   532 	if (resizeCache)
       
   533 		test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint));
       
   534 
       
   535 	test.Next(_L("Big Unlock/Lock"));
       
   536 	r = TestChunk.Unlock(0,CommitEnd);
       
   537 	test_KErrNone(r);
       
   538 	freeRam = FreeRam();
       
   539 	test(freeRam>=NoFreeRam+CommitEnd);
       
   540 	r = TestChunk.Lock(0,CommitEnd);
       
   541 	test_KErrNone(r);
       
   542 	freeRam = FreeRam();
       
   543 	test_Equal(NoFreeRam, freeRam);
       
   544 
       
   545 	if (resizeCache)
       
   546 		{
       
   547 		test.Next(_L("Check Unlock of old pages doesn't cause problems"));
       
   548 		TestUnlockOld();
       
   549 		}
       
   550 
       
   551 	test.Next(_L("Benchmarks..."));
       
   552 	TestBenchmarks();
       
   553 
       
   554 	test.Next(_L("Close chunk with unlocked pages which have been flushed"));
       
   555 	r = TestChunk.Unlock(0,CommitEnd);
       
   556 	test_KErrNone(r);
       
   557 	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
       
   558 	TestChunk.Close();
       
   559 
       
   560 	test.Next(_L("Check can't lock/unlock non-cache chunks"));
       
   561 	RChunk chunk;
       
   562 	test_KErrNone(chunk.CreateDisconnectedLocal(0,PageSize,2*PageSize));
       
   563 	test_Equal(KErrGeneral,chunk.Lock(PageSize,PageSize));
       
   564 	test_Equal(KErrGeneral,chunk.Unlock(0,PageSize));
       
   565 	chunk.Close();
       
   566 
       
   567 	// Restore original settings for live list size
       
   568 	if (resizeCache)
       
   569 		test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax));
       
   570 
       
   571 	// end...
       
   572 	test.End();
       
   573 	MemoryTest.Close();
       
   574 	gobbler.Close();
       
   575 	test.Close();
       
   576 
       
   577 	return KErrNone;
       
   578 	}