sl@0: // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "graphicsmemoryhogger.h" sl@0: sl@0: _LIT(KTGraphicsMemoryHoggerPanic, "TGfxMemHog"); sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: RDebug::Print(_L("Graphics Memory Hogger::E32Main - entry")); sl@0: sl@0: CTrapCleanup* TheTrapCleanup = CTrapCleanup::New(); sl@0: sl@0: TRAPD(err, StartTestL()); sl@0: if (err) sl@0: { sl@0: User::Panic(KTGraphicsMemoryHoggerPanic,err); sl@0: } sl@0: sl@0: delete TheTrapCleanup; sl@0: sl@0: RDebug::Print(_L("Graphics Memory Hogger::E32Main - exit")); sl@0: return KErrNone; sl@0: } sl@0: sl@0: LOCAL_C void StartTestL(void) sl@0: { sl@0: RDebug::Print(_L("Graphics Memory Hogger::StartTestL - entry")); sl@0: sl@0: TMemoryInfoV1Buf membuf; sl@0: UserHal::MemoryInfo(membuf); sl@0: const TReal maxmem = membuf().iTotalRamInBytes; sl@0: RDebug::Print(_L("GfxMemHog::TotalRamInBytes: %f"), maxmem); sl@0: sl@0: TInt pageSize = 0; sl@0: HAL::Get(HAL::EMemoryPageSize, pageSize); sl@0: RDebug::Print(_L("GfxMemHog::pageSize: %d"), pageSize); sl@0: sl@0: TInt maxHeap = 0; sl@0: HAL::Get(HALData::EMemoryRAM, maxHeap); sl@0: _LIT(KTGfxMemoryHogger, "GfxMemHog"); sl@0: sl@0: RHeap* myHeap; sl@0: myHeap = UserHeap::ChunkHeap(&KTGfxMemoryHogger, pageSize, maxmem); sl@0: sl@0: const TInt KOneSecond = 1000000; sl@0: sl@0: TInt newSize = pageSize; sl@0: // allocate an initial cell with size equal to the page size sl@0: TAny * myCell = myHeap->Alloc(newSize); sl@0: TAny * myCell2 = NULL; sl@0: sl@0: // for each cycle increase the memory allocated to the cell until sl@0: // the max is reached, at which point reset back to a cell of the sl@0: // size of a page. A second loop is used to write to memory locations sl@0: // in each page of the cell to ensure that the page is 'paged in' sl@0: FOREVER sl@0: { sl@0: newSize += pageSize*10; sl@0: TInt size = myHeap->Size(); sl@0: sl@0: myCell2 = myHeap->ReAlloc(myCell, newSize); sl@0: sl@0: if (myCell2 == NULL) sl@0: { sl@0: RDebug::Print(_L("GfxMemHog::ERROR: size reached = %d"), size); sl@0: newSize = pageSize; //reset sl@0: myCell = myHeap->ReAlloc(myCell, newSize); sl@0: sl@0: if (myCell == NULL) sl@0: { sl@0: RDebug::Print(_L("GfxMemHog::ERROR: Could not ReAlloc(myCell)")); sl@0: break; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("GfxMemHog::myHeap.Size() = %d"), myHeap->Size()); sl@0: sl@0: TInt index = 0; sl@0: TInt stop = (myHeap->AllocLen(myCell) - pageSize)/4; sl@0: RDebug::Print(_L("GfxMemHog::stop = %d"), stop); sl@0: RDebug::Print(_L("GfxMemHog::myCell.AllocLen() = %d"), myHeap->AllocLen(myCell)); sl@0: TInt loopCount = 0; sl@0: sl@0: // write to each page of memory in the heap sl@0: while(index