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