graphicstest/graphicstestharness/src/graphicsmemoryhogger.cpp
changeset 0 5d03bc08d59c
child 11 fed1595b188e
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <e32debug.h>
       
    23 #include <e32base.h>
       
    24 #include <e32math.h>
       
    25 #include <s32file.h>
       
    26 #include <bautils.h>
       
    27 #include <hal.h>
       
    28 #include "graphicsmemoryhogger.h"
       
    29 
       
    30 _LIT(KTGraphicsMemoryHoggerPanic, "TGfxMemHog");
       
    31 
       
    32 GLDEF_C TInt E32Main()
       
    33 	{
       
    34 	RDebug::Print(_L("Graphics Memory Hogger::E32Main - entry"));
       
    35 
       
    36 	CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
       
    37 
       
    38 	TRAPD(err, StartTestL());
       
    39 	if (err)
       
    40 		{
       
    41 		User::Panic(KTGraphicsMemoryHoggerPanic,err);
       
    42 		}
       
    43 
       
    44     delete TheTrapCleanup;
       
    45 
       
    46 	RDebug::Print(_L("Graphics Memory Hogger::E32Main - exit"));
       
    47 	return KErrNone;
       
    48 	}
       
    49 
       
    50 LOCAL_C void StartTestL(void)
       
    51 	{
       
    52 	RDebug::Print(_L("Graphics Memory Hogger::StartTestL - entry"));
       
    53 	
       
    54 	TMemoryInfoV1Buf membuf;
       
    55 	UserHal::MemoryInfo(membuf);
       
    56 	const TReal maxmem = membuf().iTotalRamInBytes;
       
    57 	RDebug::Print(_L("GfxMemHog::TotalRamInBytes: %f"), maxmem);
       
    58 	
       
    59 	TInt pageSize = 0;
       
    60 	HAL::Get(HAL::EMemoryPageSize, pageSize);
       
    61 	RDebug::Print(_L("GfxMemHog::pageSize: %d"), pageSize);
       
    62 	
       
    63 	TInt maxHeap = 0;
       
    64 	HAL::Get(HALData::EMemoryRAM, maxHeap);
       
    65 	_LIT(KTGfxMemoryHogger, "GfxMemHog");
       
    66 
       
    67 	RHeap* myHeap;
       
    68 	myHeap = UserHeap::ChunkHeap(&KTGfxMemoryHogger, pageSize, maxmem);
       
    69 
       
    70 	const TInt KOneSecond = 1000000;
       
    71 	
       
    72 	TInt newSize = pageSize;
       
    73 	// allocate an initial cell with size equal to the page size
       
    74 	TAny * myCell = myHeap->Alloc(newSize);
       
    75 	TAny * myCell2 = NULL;
       
    76 	
       
    77 	// for each cycle increase the memory allocated to the cell until
       
    78 	// the max is reached, at which point reset back to a cell of the
       
    79 	// size of a page. A second loop is used to write to memory locations
       
    80 	// in each page of the cell to ensure that the page is 'paged in'
       
    81 	FOREVER
       
    82 		{
       
    83 		newSize += pageSize*10;
       
    84 		TInt size = myHeap->Size();
       
    85 		
       
    86 		myCell2 = myHeap->ReAlloc(myCell, newSize);
       
    87 		
       
    88 		if (myCell2 == NULL)
       
    89 			{
       
    90 			RDebug::Print(_L("GfxMemHog::ERROR: size reached = %d"), size);
       
    91 			newSize = pageSize; //reset
       
    92 			myCell = myHeap->ReAlloc(myCell, newSize);
       
    93 			
       
    94 			if (myCell == NULL)
       
    95 				{
       
    96 				RDebug::Print(_L("GfxMemHog::ERROR: Could not ReAlloc(myCell)"));
       
    97 				break;
       
    98 				}
       
    99 			}
       
   100 		else
       
   101 			{
       
   102 			RDebug::Print(_L("GfxMemHog::myHeap.Size() = %d"), myHeap->Size());
       
   103 			
       
   104 			TInt index = 0;
       
   105 			TInt stop = (myHeap->AllocLen(myCell) - pageSize)/4;
       
   106 			RDebug::Print(_L("GfxMemHog::stop = %d"), stop);
       
   107 			RDebug::Print(_L("GfxMemHog::myCell.AllocLen() = %d"), myHeap->AllocLen(myCell));
       
   108 			TInt loopCount = 0;
       
   109 			
       
   110 			// write to each page of memory in the heap
       
   111 			while(index<stop)
       
   112 				{
       
   113 				loopCount++;
       
   114 				TInt * myData = ((TInt *) myCell2) + index;
       
   115 				*myData = index;
       
   116 				index += pageSize/4;
       
   117 				}
       
   118 			RDebug::Print(_L("GfxMemHog::Loop count = %d"), loopCount);			
       
   119 			}
       
   120 		
       
   121 		User::After(KOneSecond);
       
   122 		}
       
   123 	
       
   124 		
       
   125 	RDebug::Print(_L("Graphics Memory Hogger::StartTestL - exit"));
       
   126 	}
       
   127