os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceinternalsecondprocesstesthandler.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceinternalsecondprocesstesthandler.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,428 @@
1.4 +// Copyright (c) 2009-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 +@file
1.20 +@test
1.21 +@internalComponent
1.22 + */
1.23 +#include <e32debug.h>
1.24 +#include "tgraphicsresourceinternalsecondprocesstesthandler.h"
1.25 +#include "tgraphicsresourcemultiprocessthread.h"
1.26 +#include "tgraphicsresourceinternalsecondprocessenums.h"
1.27 +#include "tsgdrawablegeneric.h"
1.28 +#include "tsgimagegeneric.h"
1.29 +
1.30 +CTSgResInternalSecondProcessTestHandler* CTSgResInternalSecondProcessTestHandler::NewLC()
1.31 + {
1.32 + CTSgResInternalSecondProcessTestHandler* self = new(ELeave) CTSgResInternalSecondProcessTestHandler();
1.33 + CleanupStack::PushL(self);
1.34 + return self;
1.35 + }
1.36 +
1.37 +/**
1.38 +Runs the specified test
1.39 +
1.40 +@param TInt The test case to be run
1.41 + */
1.42 +TInt CTSgResInternalSecondProcessTestHandler::RunTestCaseL(const TSgResIntTestInfo& aInfo)
1.43 + {
1.44 + RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL(%i)", aInfo.iTestCase);
1.45 + TInt result = 0;
1.46 + switch (aInfo.iTestCase)
1.47 + {
1.48 + case ESgResIntDriverMemoryLeak:
1.49 + TestDriverMemoryLeakL();
1.50 + break;
1.51 + case ESgResIntDrawableOOM:
1.52 + result = TestDrawableOOM();
1.53 + break;
1.54 + case ESgResIntImageOOM:
1.55 + result = TestImageOOM(aInfo);
1.56 + break;
1.57 + case ESgResIntInitializeAndShutdown:
1.58 + result = TestDriverInitializeAndShutdownL();
1.59 + break;
1.60 + case ESgResIntInitializeAndShutdownManyTimes:
1.61 + result = TestDriverInitializeAndShutdownManyTimes();
1.62 + break;
1.63 + case ESgResIntResourceProfiling:
1.64 + result = TestResourceProfiling(aInfo);
1.65 + break;
1.66 + default:
1.67 + result = KErrNotFound;
1.68 + break;
1.69 + }
1.70 + RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL result=%i", result);
1.71 + return result;
1.72 + }
1.73 +
1.74 +CTSgResInternalSecondProcessTestHandler::CTSgResInternalSecondProcessTestHandler()
1.75 + {
1.76 + }
1.77 +
1.78 +CTSgResInternalSecondProcessTestHandler::~CTSgResInternalSecondProcessTestHandler()
1.79 + {
1.80 + iSgDriver.Close();
1.81 + }
1.82 +
1.83 +/**
1.84 +Opens the SgDriver and gets the test extension interfaces required for the
1.85 +internal tests.
1.86 + */
1.87 +void CTSgResInternalSecondProcessTestHandler::OpenDriverL()
1.88 + {
1.89 + User::LeaveIfError(iSgDriver.Open());
1.90 + User::LeaveIfError(iSgDriver.GetInterface(iTestExt));
1.91 + User::LeaveIfError(iSgDriver.GetInterface(iProfExt));
1.92 + }
1.93 +
1.94 +/**
1.95 +Second process implementaion of the test ESgResIntDriverMemoryLeak.
1.96 +
1.97 +Memory leak detection is beun and an image opened.
1.98 +The image is not closed before the memory leak checking is ended.
1.99 +This should cause an SGALLOC panic.
1.100 + */
1.101 +void CTSgResInternalSecondProcessTestHandler::TestDriverMemoryLeakL()
1.102 + {
1.103 + iTestExt->AllocMarkStart();
1.104 + TSgImageInfo info;
1.105 + info.iSizeInPixels = TSize(8, 8);
1.106 + info.iUsage = ESgUsageBitOpenVgImage;
1.107 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.108 +
1.109 + RSgImage image;
1.110 + image.Create(info, NULL, 0);
1.111 + iTestExt->AllocMarkEnd(0); //Expecting this to panic
1.112 +
1.113 + image.Close();
1.114 + }
1.115 +
1.116 +/**
1.117 +Second process impementation of the test ESgResIntDrawableOOM.
1.118 +
1.119 +Tests RSgDrawable in a number of different situations with simulated
1.120 +low memory conditions.
1.121 + */
1.122 +TInt CTSgResInternalSecondProcessTestHandler::TestDrawableOOM()
1.123 + {
1.124 + TInt result = 0;
1.125 + TInt err = KErrNone;
1.126 + TInt tryCount = 0;
1.127 + do
1.128 + {
1.129 + iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
1.130 + TRAP(err, DoDrawableMemoryTestsL());
1.131 + }
1.132 + while(err == KErrNoMemory);
1.133 +
1.134 + iTestExt->SetAllocFail(RAllocator::ENone, 0);
1.135 +
1.136 + result |= EFirstTestPassed;
1.137 + return result;
1.138 + }
1.139 +
1.140 +/**
1.141 +Second process implementation of the test ESgResTestImageOOM.
1.142 +
1.143 +Tests RSgImage in a number of different situations with simulated
1.144 +low memory conditions.
1.145 + */
1.146 +TInt CTSgResInternalSecondProcessTestHandler::TestImageOOM(const TSgResIntTestInfo& aInfo)
1.147 + {
1.148 + TInt result = 0;
1.149 + TInt err = KErrNone;
1.150 + TInt tryCount = 0;
1.151 + do
1.152 + {
1.153 + iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
1.154 + TRAP(err, DoImageMemoryTestsL(aInfo));
1.155 + }
1.156 + while(err == KErrNoMemory);
1.157 +
1.158 + iTestExt->SetAllocFail(RAllocator::ENone, 0);
1.159 +
1.160 + if(err == KErrNone)
1.161 + {
1.162 + result |= EFirstTestPassed;
1.163 + }
1.164 +
1.165 + return result;
1.166 + }
1.167 +
1.168 +/**
1.169 +Performs the RSgDrawable low memory tests; checks for Heap and RSgDriver memory
1.170 +leaks after each individual test.
1.171 + */
1.172 +void CTSgResInternalSecondProcessTestHandler::DoDrawableMemoryTestsL()
1.173 + {
1.174 + //Construct the SgDrawable tests using EFalse to enable KErrNoMemory testing
1.175 + CTSgDrawableGeneric* drawableTests = new(ELeave)CTSgDrawableGeneric(EFalse);
1.176 + CleanupStack::PushL(drawableTests);
1.177 +
1.178 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.179 + drawableTests->TestOpenImageAsDrawableL();
1.180 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.181 +
1.182 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.183 + drawableTests->TestGetDrawableDrawableIdL();
1.184 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.185 +
1.186 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.187 + drawableTests->TestOpenDrawableInvalidL();
1.188 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.189 +
1.190 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.191 + drawableTests->TestCloseDrawableWithoutOpenL();
1.192 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.193 +
1.194 + CleanupStack::PopAndDestroy(drawableTests);
1.195 + }
1.196 +
1.197 +/**
1.198 +Performs the RSgImage low memory tests; checks for Heap and RSgDriver memory
1.199 +leaks after each individual test.
1.200 + */
1.201 +void CTSgResInternalSecondProcessTestHandler::DoImageMemoryTestsL(const TSgResIntTestInfo& aInfo)
1.202 + {
1.203 + // open image that is created in another process
1.204 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.205 + TestOpenImageL(aInfo.iDrawableId);
1.206 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.207 +
1.208 +
1.209 + //Construct the SgImage generic tests using EFalse to enable KErrNoMemory testing
1.210 + CTSgImageGeneric* imageTests = new(ELeave)CTSgImageGeneric(EFalse);
1.211 + CleanupStack::PushL(imageTests);
1.212 +
1.213 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.214 + imageTests->TestGetPixelFormatsL();
1.215 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.216 +
1.217 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.218 + imageTests->TestCreateImageUninitializedL();
1.219 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.220 +
1.221 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.222 + imageTests->TestCreateImageL();
1.223 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.224 +
1.225 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.226 + imageTests->TestCreateImageFromExistingImageL();
1.227 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.228 +
1.229 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.230 + imageTests->TestGetImageInfoL();
1.231 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.232 +
1.233 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.234 + imageTests->TestGetImageDrawableIdL();
1.235 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.236 +
1.237 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.238 + imageTests->TestOpenImageL();
1.239 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.240 +
1.241 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.242 + imageTests->TestGetInterfaceL();
1.243 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.244 +
1.245 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.246 + imageTests->TestGetPixelFormatsInvalidL();
1.247 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.248 +
1.249 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.250 + imageTests->TestOpenImageInvalidL();
1.251 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.252 +
1.253 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.254 + imageTests->TestCloseImageManyTimesL();
1.255 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.256 +
1.257 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.258 + imageTests->TestCloseImageWithoutOpenL();
1.259 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.260 +
1.261 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.262 + imageTests->TestCreateImageInvalidL();
1.263 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.264 +
1.265 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.266 + imageTests->TestGetInfoImageInvalidL();
1.267 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.268 +
1.269 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.270 + imageTests->TestGetAttributesImageInvalidL();
1.271 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.272 +
1.273 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.274 + imageTests->TestCreateImageDataStrideL();
1.275 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.276 +
1.277 + __UHEAP_MARK; iTestExt->AllocMarkStart();
1.278 + imageTests->TestStress1L();
1.279 + __UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
1.280 +
1.281 +
1.282 + CleanupStack::PopAndDestroy(imageTests);
1.283 + }
1.284 +
1.285 +/*
1.286 + Used for OOM testing for opening an image in another process. For this purpose,
1.287 + the image that is opened here must be created in another process.
1.288 + */
1.289 +void CTSgResInternalSecondProcessTestHandler::TestOpenImageL(TSgDrawableId aId)
1.290 + {
1.291 + TSgDrawableId id = aId;
1.292 +
1.293 + RSgImage image;
1.294 +
1.295 + User::LeaveIfError(image.Open(id));
1.296 +
1.297 + image.Close();
1.298 + }
1.299 +
1.300 +/**
1.301 +Test the Local Reference count of RSgDriver when creating and destroying images
1.302 + */
1.303 +TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownL()
1.304 + {
1.305 + TInt result = 0;
1.306 + TSgImageInfo info;
1.307 + info.iSizeInPixels = TSize(8, 8);
1.308 + info.iUsage = ESgUsageBitOpenVgImage;
1.309 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.310 +
1.311 + RSgImage image;
1.312 + User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));
1.313 +
1.314 + if (1 == iProfExt->LocalResourceCount())
1.315 + result |= EFirstTestPassed;
1.316 +
1.317 + image.Close();
1.318 +
1.319 + User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));
1.320 + image.Close();
1.321 +
1.322 + if (KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
1.323 + result |= ESecondTestPassed;
1.324 + image.Close();
1.325 +
1.326 + if (0 == iProfExt->LocalResourceCount())
1.327 + result |= EThirdTestPassed;
1.328 +
1.329 + return result;
1.330 + }
1.331 +
1.332 +/**
1.333 +Test the Local Reference count of RSgDriver when creating and destroying images
1.334 +with multiple driver sessions.
1.335 + */
1.336 +TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownManyTimes()
1.337 + {
1.338 + TInt result = 0;
1.339 + __UHEAP_MARK;
1.340 +
1.341 + TSgImageInfo info;
1.342 + info.iSizeInPixels = TSize(8, 8);
1.343 + info.iUsage = ESgUsageBitOpenVgImage;
1.344 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.345 +
1.346 + RSgImage image;
1.347 +
1.348 + if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
1.349 + result |= EFirstTestPassed;
1.350 +
1.351 + image.Close();
1.352 +
1.353 + iSgDriver.Close();
1.354 + iSgDriver.Close();
1.355 +
1.356 + if(KErrNone == iSgDriver.Open())
1.357 + result |= ESecondTestPassed;
1.358 +
1.359 + if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
1.360 + result |= EThirdTestPassed;
1.361 +
1.362 + image.Close();
1.363 +
1.364 + if(0 == iProfExt->LocalResourceCount())
1.365 + result |= EFourthTestPassed;
1.366 +
1.367 + iSgDriver.Close();
1.368 +
1.369 + __UHEAP_MARKEND;
1.370 +
1.371 + return result;
1.372 + }
1.373 +
1.374 +/**
1.375 +Test the SgDriver extension MSgDriver_Profiling is reporting the correct local and
1.376 +global memory usage and resource counts, when another process has created images
1.377 +and then called into this process.
1.378 + */
1.379 +TInt CTSgResInternalSecondProcessTestHandler::TestResourceProfiling(const TSgResIntTestInfo& aInfo)
1.380 + {
1.381 + __UHEAP_MARK;
1.382 + TInt result = 0;
1.383 + const TSize KImageSize(8, 8);
1.384 +
1.385 + // Check that this process is reporting the same memory usage as the calling
1.386 + // process, and is using zero local memory.
1.387 + if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
1.388 + result |= EFirstTestPassed;
1.389 + if (iProfExt->LocalGraphicsMemoryUsed() == 0)
1.390 + result |= ESecondTestPassed;
1.391 + if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
1.392 + result |= EThirdTestPassed;
1.393 +
1.394 + RSgImage image;
1.395 + if (KErrNone == image.Create(TSgImageInfo(KImageSize, ESgPixelFormatARGB_8888, ESgUsageBitOpenVgImage)))
1.396 + {
1.397 + // Check that the local resource count is one, and the global resource count has
1.398 + // incremented by one.
1.399 + if (iProfExt->LocalResourceCount() == 1)
1.400 + result |= EFourthTestPassed;
1.401 + if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount+1)
1.402 + result |= EFifthTestPassed;
1.403 +
1.404 + // Check that creating an image in this process increases the global and
1.405 + // local memory usage reported by the extension, and destroying it will
1.406 + // set it back to how it was.
1.407 + TInt localGraphicsMemory = iProfExt->LocalGraphicsMemoryUsed();
1.408 + TInt globalGraphicsMemory = iProfExt->GlobalGraphicsMemoryUsed();
1.409 + if (localGraphicsMemory >= (KImageSize.iWidth * KImageSize.iHeight * 4))
1.410 + result |= ESixthTestPassed;
1.411 + if (globalGraphicsMemory == (localGraphicsMemory + aInfo.iGlobalGraphicsMemory))
1.412 + result |= ESeventhTestPassed;
1.413 +
1.414 + image.Close();
1.415 +
1.416 + // Check the local memory usage is the same as before the test started
1.417 + if (iProfExt->LocalGraphicsMemoryUsed() == 0)
1.418 + result |= EEighthTestPassed;
1.419 + if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
1.420 + result |= ENinthTestPassed;
1.421 + // Check the local resource count is zero and the global count is the same
1.422 + // as before the test started.
1.423 + if (iProfExt->LocalResourceCount() == 0)
1.424 + result |= ETenthTestPassed;
1.425 + if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
1.426 + result |= EEleventhTestPassed;
1.427 + }
1.428 +
1.429 + __UHEAP_MARKEND;
1.430 + return result;
1.431 + }