sl@0: // Copyright (c) 2009-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: @file sl@0: @test sl@0: @internalComponent sl@0: */ sl@0: #include sl@0: #include "tgraphicsresourceinternalsecondprocesstesthandler.h" sl@0: #include "tgraphicsresourcemultiprocessthread.h" sl@0: #include "tgraphicsresourceinternalsecondprocessenums.h" sl@0: #include "tsgdrawablegeneric.h" sl@0: #include "tsgimagegeneric.h" sl@0: sl@0: CTSgResInternalSecondProcessTestHandler* CTSgResInternalSecondProcessTestHandler::NewLC() sl@0: { sl@0: CTSgResInternalSecondProcessTestHandler* self = new(ELeave) CTSgResInternalSecondProcessTestHandler(); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Runs the specified test sl@0: sl@0: @param TInt The test case to be run sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::RunTestCaseL(const TSgResIntTestInfo& aInfo) sl@0: { sl@0: RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL(%i)", aInfo.iTestCase); sl@0: TInt result = 0; sl@0: switch (aInfo.iTestCase) sl@0: { sl@0: case ESgResIntDriverMemoryLeak: sl@0: TestDriverMemoryLeakL(); sl@0: break; sl@0: case ESgResIntDrawableOOM: sl@0: result = TestDrawableOOM(); sl@0: break; sl@0: case ESgResIntImageOOM: sl@0: result = TestImageOOM(aInfo); sl@0: break; sl@0: case ESgResIntInitializeAndShutdown: sl@0: result = TestDriverInitializeAndShutdownL(); sl@0: break; sl@0: case ESgResIntInitializeAndShutdownManyTimes: sl@0: result = TestDriverInitializeAndShutdownManyTimes(); sl@0: break; sl@0: case ESgResIntResourceProfiling: sl@0: result = TestResourceProfiling(aInfo); sl@0: break; sl@0: default: sl@0: result = KErrNotFound; sl@0: break; sl@0: } sl@0: RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL result=%i", result); sl@0: return result; sl@0: } sl@0: sl@0: CTSgResInternalSecondProcessTestHandler::CTSgResInternalSecondProcessTestHandler() sl@0: { sl@0: } sl@0: sl@0: CTSgResInternalSecondProcessTestHandler::~CTSgResInternalSecondProcessTestHandler() sl@0: { sl@0: iSgDriver.Close(); sl@0: } sl@0: sl@0: /** sl@0: Opens the SgDriver and gets the test extension interfaces required for the sl@0: internal tests. sl@0: */ sl@0: void CTSgResInternalSecondProcessTestHandler::OpenDriverL() sl@0: { sl@0: User::LeaveIfError(iSgDriver.Open()); sl@0: User::LeaveIfError(iSgDriver.GetInterface(iTestExt)); sl@0: User::LeaveIfError(iSgDriver.GetInterface(iProfExt)); sl@0: } sl@0: sl@0: /** sl@0: Second process implementaion of the test ESgResIntDriverMemoryLeak. sl@0: sl@0: Memory leak detection is beun and an image opened. sl@0: The image is not closed before the memory leak checking is ended. sl@0: This should cause an SGALLOC panic. sl@0: */ sl@0: void CTSgResInternalSecondProcessTestHandler::TestDriverMemoryLeakL() sl@0: { sl@0: iTestExt->AllocMarkStart(); sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: sl@0: RSgImage image; sl@0: image.Create(info, NULL, 0); sl@0: iTestExt->AllocMarkEnd(0); //Expecting this to panic sl@0: sl@0: image.Close(); sl@0: } sl@0: sl@0: /** sl@0: Second process impementation of the test ESgResIntDrawableOOM. sl@0: sl@0: Tests RSgDrawable in a number of different situations with simulated sl@0: low memory conditions. sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::TestDrawableOOM() sl@0: { sl@0: TInt result = 0; sl@0: TInt err = KErrNone; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount); sl@0: TRAP(err, DoDrawableMemoryTestsL()); sl@0: } sl@0: while(err == KErrNoMemory); sl@0: sl@0: iTestExt->SetAllocFail(RAllocator::ENone, 0); sl@0: sl@0: result |= EFirstTestPassed; sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Second process implementation of the test ESgResTestImageOOM. sl@0: sl@0: Tests RSgImage in a number of different situations with simulated sl@0: low memory conditions. sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::TestImageOOM(const TSgResIntTestInfo& aInfo) sl@0: { sl@0: TInt result = 0; sl@0: TInt err = KErrNone; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount); sl@0: TRAP(err, DoImageMemoryTestsL(aInfo)); sl@0: } sl@0: while(err == KErrNoMemory); sl@0: sl@0: iTestExt->SetAllocFail(RAllocator::ENone, 0); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: result |= EFirstTestPassed; sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Performs the RSgDrawable low memory tests; checks for Heap and RSgDriver memory sl@0: leaks after each individual test. sl@0: */ sl@0: void CTSgResInternalSecondProcessTestHandler::DoDrawableMemoryTestsL() sl@0: { sl@0: //Construct the SgDrawable tests using EFalse to enable KErrNoMemory testing sl@0: CTSgDrawableGeneric* drawableTests = new(ELeave)CTSgDrawableGeneric(EFalse); sl@0: CleanupStack::PushL(drawableTests); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: drawableTests->TestOpenImageAsDrawableL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: drawableTests->TestGetDrawableDrawableIdL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: drawableTests->TestOpenDrawableInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: drawableTests->TestCloseDrawableWithoutOpenL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: CleanupStack::PopAndDestroy(drawableTests); sl@0: } sl@0: sl@0: /** sl@0: Performs the RSgImage low memory tests; checks for Heap and RSgDriver memory sl@0: leaks after each individual test. sl@0: */ sl@0: void CTSgResInternalSecondProcessTestHandler::DoImageMemoryTestsL(const TSgResIntTestInfo& aInfo) sl@0: { sl@0: // open image that is created in another process sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: TestOpenImageL(aInfo.iDrawableId); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: sl@0: //Construct the SgImage generic tests using EFalse to enable KErrNoMemory testing sl@0: CTSgImageGeneric* imageTests = new(ELeave)CTSgImageGeneric(EFalse); sl@0: CleanupStack::PushL(imageTests); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetPixelFormatsL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCreateImageUninitializedL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCreateImageL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCreateImageFromExistingImageL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetImageInfoL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetImageDrawableIdL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestOpenImageL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetInterfaceL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetPixelFormatsInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestOpenImageInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCloseImageManyTimesL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCloseImageWithoutOpenL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCreateImageInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetInfoImageInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestGetAttributesImageInvalidL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestCreateImageDataStrideL(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: __UHEAP_MARK; iTestExt->AllocMarkStart(); sl@0: imageTests->TestStress1L(); sl@0: __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0); sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(imageTests); sl@0: } sl@0: sl@0: /* sl@0: Used for OOM testing for opening an image in another process. For this purpose, sl@0: the image that is opened here must be created in another process. sl@0: */ sl@0: void CTSgResInternalSecondProcessTestHandler::TestOpenImageL(TSgDrawableId aId) sl@0: { sl@0: TSgDrawableId id = aId; sl@0: sl@0: RSgImage image; sl@0: sl@0: User::LeaveIfError(image.Open(id)); sl@0: sl@0: image.Close(); sl@0: } sl@0: sl@0: /** sl@0: Test the Local Reference count of RSgDriver when creating and destroying images sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownL() sl@0: { sl@0: TInt result = 0; sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: sl@0: RSgImage image; sl@0: User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride)); sl@0: sl@0: if (1 == iProfExt->LocalResourceCount()) sl@0: result |= EFirstTestPassed; sl@0: sl@0: image.Close(); sl@0: sl@0: User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride)); sl@0: image.Close(); sl@0: sl@0: if (KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride)) sl@0: result |= ESecondTestPassed; sl@0: image.Close(); sl@0: sl@0: if (0 == iProfExt->LocalResourceCount()) sl@0: result |= EThirdTestPassed; sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Test the Local Reference count of RSgDriver when creating and destroying images sl@0: with multiple driver sessions. sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownManyTimes() sl@0: { sl@0: TInt result = 0; sl@0: __UHEAP_MARK; sl@0: sl@0: TSgImageInfo info; sl@0: info.iSizeInPixels = TSize(8, 8); sl@0: info.iUsage = ESgUsageBitOpenVgImage; sl@0: info.iPixelFormat = EUidPixelFormatRGB_565; sl@0: sl@0: RSgImage image; sl@0: sl@0: if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride)) sl@0: result |= EFirstTestPassed; sl@0: sl@0: image.Close(); sl@0: sl@0: iSgDriver.Close(); sl@0: iSgDriver.Close(); sl@0: sl@0: if(KErrNone == iSgDriver.Open()) sl@0: result |= ESecondTestPassed; sl@0: sl@0: if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride)) sl@0: result |= EThirdTestPassed; sl@0: sl@0: image.Close(); sl@0: sl@0: if(0 == iProfExt->LocalResourceCount()) sl@0: result |= EFourthTestPassed; sl@0: sl@0: iSgDriver.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Test the SgDriver extension MSgDriver_Profiling is reporting the correct local and sl@0: global memory usage and resource counts, when another process has created images sl@0: and then called into this process. sl@0: */ sl@0: TInt CTSgResInternalSecondProcessTestHandler::TestResourceProfiling(const TSgResIntTestInfo& aInfo) sl@0: { sl@0: __UHEAP_MARK; sl@0: TInt result = 0; sl@0: const TSize KImageSize(8, 8); sl@0: sl@0: // Check that this process is reporting the same memory usage as the calling sl@0: // process, and is using zero local memory. sl@0: if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory) sl@0: result |= EFirstTestPassed; sl@0: if (iProfExt->LocalGraphicsMemoryUsed() == 0) sl@0: result |= ESecondTestPassed; sl@0: if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount) sl@0: result |= EThirdTestPassed; sl@0: sl@0: RSgImage image; sl@0: if (KErrNone == image.Create(TSgImageInfo(KImageSize, ESgPixelFormatARGB_8888, ESgUsageBitOpenVgImage))) sl@0: { sl@0: // Check that the local resource count is one, and the global resource count has sl@0: // incremented by one. sl@0: if (iProfExt->LocalResourceCount() == 1) sl@0: result |= EFourthTestPassed; sl@0: if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount+1) sl@0: result |= EFifthTestPassed; sl@0: sl@0: // Check that creating an image in this process increases the global and sl@0: // local memory usage reported by the extension, and destroying it will sl@0: // set it back to how it was. sl@0: TInt localGraphicsMemory = iProfExt->LocalGraphicsMemoryUsed(); sl@0: TInt globalGraphicsMemory = iProfExt->GlobalGraphicsMemoryUsed(); sl@0: if (localGraphicsMemory >= (KImageSize.iWidth * KImageSize.iHeight * 4)) sl@0: result |= ESixthTestPassed; sl@0: if (globalGraphicsMemory == (localGraphicsMemory + aInfo.iGlobalGraphicsMemory)) sl@0: result |= ESeventhTestPassed; sl@0: sl@0: image.Close(); sl@0: sl@0: // Check the local memory usage is the same as before the test started sl@0: if (iProfExt->LocalGraphicsMemoryUsed() == 0) sl@0: result |= EEighthTestPassed; sl@0: if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory) sl@0: result |= ENinthTestPassed; sl@0: // Check the local resource count is zero and the global count is the same sl@0: // as before the test started. sl@0: if (iProfExt->LocalResourceCount() == 0) sl@0: result |= ETenthTestPassed; sl@0: if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount) sl@0: result |= EEleventhTestPassed; sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: return result; sl@0: }