os/graphics/graphicstest/graphicstestharness/src/graphicsmemoryhogger.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/graphicstestharness/src/graphicsmemoryhogger.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +#include <e32debug.h>
    1.26 +#include <e32base.h>
    1.27 +#include <e32math.h>
    1.28 +#include <s32file.h>
    1.29 +#include <bautils.h>
    1.30 +#include <hal.h>
    1.31 +#include <e32hal.h>
    1.32 +#include "graphicsmemoryhogger.h"
    1.33 +
    1.34 +_LIT(KTGraphicsMemoryHoggerPanic, "TGfxMemHog");
    1.35 +
    1.36 +GLDEF_C TInt E32Main()
    1.37 +	{
    1.38 +	RDebug::Print(_L("Graphics Memory Hogger::E32Main - entry"));
    1.39 +
    1.40 +	CTrapCleanup* TheTrapCleanup = CTrapCleanup::New();
    1.41 +
    1.42 +	TRAPD(err, StartTestL());
    1.43 +	if (err)
    1.44 +		{
    1.45 +		User::Panic(KTGraphicsMemoryHoggerPanic,err);
    1.46 +		}
    1.47 +
    1.48 +    delete TheTrapCleanup;
    1.49 +
    1.50 +	RDebug::Print(_L("Graphics Memory Hogger::E32Main - exit"));
    1.51 +	return KErrNone;
    1.52 +	}
    1.53 +
    1.54 +LOCAL_C void StartTestL(void)
    1.55 +	{
    1.56 +	RDebug::Print(_L("Graphics Memory Hogger::StartTestL - entry"));
    1.57 +	
    1.58 +	TMemoryInfoV1Buf membuf;
    1.59 +	UserHal::MemoryInfo(membuf);
    1.60 +	const TReal maxmem = membuf().iTotalRamInBytes;
    1.61 +	RDebug::Print(_L("GfxMemHog::TotalRamInBytes: %f"), maxmem);
    1.62 +	
    1.63 +	TInt pageSize = 0;
    1.64 +	HAL::Get(HAL::EMemoryPageSize, pageSize);
    1.65 +	RDebug::Print(_L("GfxMemHog::pageSize: %d"), pageSize);
    1.66 +	
    1.67 +	TInt maxHeap = 0;
    1.68 +	HAL::Get(HALData::EMemoryRAM, maxHeap);
    1.69 +	_LIT(KTGfxMemoryHogger, "GfxMemHog");
    1.70 +
    1.71 +	RHeap* myHeap;
    1.72 +	myHeap = UserHeap::ChunkHeap(&KTGfxMemoryHogger, pageSize, maxmem);
    1.73 +
    1.74 +	const TInt KOneSecond = 1000000;
    1.75 +	
    1.76 +	TInt newSize = pageSize;
    1.77 +	// allocate an initial cell with size equal to the page size
    1.78 +	TAny * myCell = myHeap->Alloc(newSize);
    1.79 +	TAny * myCell2 = NULL;
    1.80 +	
    1.81 +	// for each cycle increase the memory allocated to the cell until
    1.82 +	// the max is reached, at which point reset back to a cell of the
    1.83 +	// size of a page. A second loop is used to write to memory locations
    1.84 +	// in each page of the cell to ensure that the page is 'paged in'
    1.85 +	FOREVER
    1.86 +		{
    1.87 +		newSize += pageSize*10;
    1.88 +		TInt size = myHeap->Size();
    1.89 +		
    1.90 +		myCell2 = myHeap->ReAlloc(myCell, newSize);
    1.91 +		
    1.92 +		if (myCell2 == NULL)
    1.93 +			{
    1.94 +			RDebug::Print(_L("GfxMemHog::ERROR: size reached = %d"), size);
    1.95 +			newSize = pageSize; //reset
    1.96 +			myCell = myHeap->ReAlloc(myCell, newSize);
    1.97 +			
    1.98 +			if (myCell == NULL)
    1.99 +				{
   1.100 +				RDebug::Print(_L("GfxMemHog::ERROR: Could not ReAlloc(myCell)"));
   1.101 +				break;
   1.102 +				}
   1.103 +			}
   1.104 +		else
   1.105 +			{
   1.106 +			RDebug::Print(_L("GfxMemHog::myHeap.Size() = %d"), myHeap->Size());
   1.107 +			
   1.108 +			TInt index = 0;
   1.109 +			TInt stop = (myHeap->AllocLen(myCell) - pageSize)/4;
   1.110 +			RDebug::Print(_L("GfxMemHog::stop = %d"), stop);
   1.111 +			RDebug::Print(_L("GfxMemHog::myCell.AllocLen() = %d"), myHeap->AllocLen(myCell));
   1.112 +			TInt loopCount = 0;
   1.113 +			
   1.114 +			// write to each page of memory in the heap
   1.115 +			while(index<stop)
   1.116 +				{
   1.117 +				loopCount++;
   1.118 +				TInt * myData = ((TInt *) myCell2) + index;
   1.119 +				*myData = index;
   1.120 +				index += pageSize/4;
   1.121 +				}
   1.122 +			RDebug::Print(_L("GfxMemHog::Loop count = %d"), loopCount);			
   1.123 +			}
   1.124 +		
   1.125 +		User::After(KOneSecond);
   1.126 +		}
   1.127 +	
   1.128 +		
   1.129 +	RDebug::Print(_L("Graphics Memory Hogger::StartTestL - exit"));
   1.130 +	}
   1.131 +