graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourceinternalsecondprocesstesthandler.cpp
changeset 36 01a6848ebfd7
child 103 2717213c588a
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 /**
       
    16 @file
       
    17 @test
       
    18 @internalComponent
       
    19  */
       
    20 #include <e32debug.h>
       
    21 #include "tgraphicsresourceinternalsecondprocesstesthandler.h"
       
    22 #include "tgraphicsresourcemultiprocessthread.h"
       
    23 #include "tgraphicsresourceinternalsecondprocessenums.h"
       
    24 #include "tsgdrawablegeneric.h"
       
    25 #include "tsgimagegeneric.h"
       
    26 
       
    27 CTSgResInternalSecondProcessTestHandler* CTSgResInternalSecondProcessTestHandler::NewLC()
       
    28 	{
       
    29 	CTSgResInternalSecondProcessTestHandler* self = new(ELeave) CTSgResInternalSecondProcessTestHandler();
       
    30 	CleanupStack::PushL(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 /**
       
    35 Runs the specified test
       
    36 
       
    37 @param TInt The test case to be run
       
    38  */
       
    39 TInt CTSgResInternalSecondProcessTestHandler::RunTestCaseL(TInt aTestCase, TSgResIntTestInfo& aInfo)
       
    40 	{
       
    41 	RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL(%i)", aTestCase);
       
    42 	TInt result = 0;
       
    43 	switch (aTestCase)
       
    44 		{
       
    45 		case ESgResIntDriverMemoryLeak:
       
    46 			TestDriverMemoryLeakL();
       
    47 			break;
       
    48 		case ESgResIntDrawableOOM:
       
    49 			result = TestDrawableOOM();
       
    50 			break;
       
    51 		case ESgResIntImageOOM:
       
    52 			result = TestImageOOM(aInfo);
       
    53 			break;
       
    54 		case ESgResIntInitializeAndShutdown:
       
    55 			result = TestDriverInitializeAndShutdownL();
       
    56 			break;
       
    57 		case ESgResIntInitializeAndShutdownManyTimes:
       
    58 			result = TestDriverInitializeAndShutdownManyTimes();
       
    59 			break;
       
    60 		case ESgResIntResourceProfiling:
       
    61 			result = TestResourceProfiling(aInfo);
       
    62 			break;
       
    63 		default:
       
    64 			result = KErrNotFound;
       
    65 			break;
       
    66 		}
       
    67 	RDebug::Printf("CTSgResSecondProcessTestHandler::RunTestCaseL result=%i", result);
       
    68 	return result;
       
    69 	}
       
    70 
       
    71 CTSgResInternalSecondProcessTestHandler::CTSgResInternalSecondProcessTestHandler()
       
    72 	{
       
    73 	}
       
    74 
       
    75 CTSgResInternalSecondProcessTestHandler::~CTSgResInternalSecondProcessTestHandler()
       
    76 	{
       
    77 	iSgDriver.Close();
       
    78 	}
       
    79 
       
    80 /**
       
    81 Opens the SgDriver and gets the test extension interfaces required for the
       
    82 internal tests.
       
    83  */
       
    84 void CTSgResInternalSecondProcessTestHandler::OpenDriverL()
       
    85 	{
       
    86 	User::LeaveIfError(iSgDriver.Open());
       
    87 	User::LeaveIfError(iSgDriver.GetInterface(iTestExt));
       
    88 	User::LeaveIfError(iSgDriver.GetInterface(iProfExt));
       
    89 	}
       
    90 
       
    91 /**
       
    92 Second process implementaion of the test ESgResIntDriverMemoryLeak.
       
    93 
       
    94 Memory leak detection is beun and an image opened.
       
    95 The image is not closed before the memory leak checking is ended.
       
    96 This should cause an SGALLOC panic.
       
    97  */
       
    98 void CTSgResInternalSecondProcessTestHandler::TestDriverMemoryLeakL()
       
    99 	{
       
   100 	iTestExt->AllocMarkStart();
       
   101 	TSgImageInfo info;
       
   102 	info.iSizeInPixels = TSize(8, 8);
       
   103 	info.iUsage = ESgUsageBitOpenVgImage;
       
   104 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   105 	
       
   106 	RSgImage image;
       
   107 	image.Create(info, NULL, 0);
       
   108 	iTestExt->AllocMarkEnd(0); //Expecting this to panic
       
   109 
       
   110 	image.Close();
       
   111 	}
       
   112 
       
   113 /**
       
   114 Second process impementation of the test ESgResIntDrawableOOM.
       
   115 
       
   116 Tests RSgDrawable in a number of different situations with simulated
       
   117 low memory conditions.
       
   118  */
       
   119 TInt CTSgResInternalSecondProcessTestHandler::TestDrawableOOM()
       
   120 	{
       
   121 	TInt result = 0;
       
   122 	TInt err = KErrNone;
       
   123 	TInt tryCount = 0;
       
   124 	do
       
   125 		{
       
   126 		iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
       
   127 		TRAP(err, DoDrawableMemoryTestsL());
       
   128 		} 
       
   129 	while(err == KErrNoMemory);
       
   130 
       
   131 	iTestExt->SetAllocFail(RAllocator::ENone, 0);
       
   132 
       
   133 	result |= EFirstTestPassed;
       
   134 	return result;
       
   135 	}
       
   136 
       
   137 /**
       
   138 Second process implementation of the test ESgResTestImageOOM.
       
   139 
       
   140 Tests RSgImage in a number of different situations with simulated
       
   141 low memory conditions.
       
   142  */
       
   143 TInt CTSgResInternalSecondProcessTestHandler::TestImageOOM(const TSgResIntTestInfo& aInfo)
       
   144 	{
       
   145 	TInt result = 0;
       
   146 	TInt err = KErrNone;
       
   147 	TInt tryCount = 0;
       
   148 	do
       
   149 		{
       
   150 		iTestExt->SetAllocFail(RAllocator::EFailNext, ++tryCount);
       
   151 		TRAP(err, DoImageMemoryTestsL(aInfo));
       
   152 		} 
       
   153 	while(err == KErrNoMemory);
       
   154 
       
   155 	iTestExt->SetAllocFail(RAllocator::ENone, 0);
       
   156 
       
   157 	if(err == KErrNone)
       
   158 	    {
       
   159 	    result |= EFirstTestPassed;
       
   160 	    }
       
   161 	
       
   162 	return result;
       
   163 	}
       
   164 
       
   165 /**
       
   166 Performs the RSgDrawable low memory tests; checks for Heap and RSgDriver memory
       
   167 leaks after each individual test.
       
   168  */
       
   169 void CTSgResInternalSecondProcessTestHandler::DoDrawableMemoryTestsL()
       
   170 	{
       
   171 	//Construct the SgDrawable tests using EFalse to enable KErrNoMemory testing
       
   172 	CTSgDrawableGeneric* drawableTests = new(ELeave)CTSgDrawableGeneric(EFalse);
       
   173 	CleanupStack::PushL(drawableTests);
       
   174 	
       
   175 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   176 	drawableTests->TestOpenImageAsDrawableL();
       
   177 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   178 	
       
   179 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   180 	drawableTests->TestGetDrawableDrawableIdL();
       
   181 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   182 	
       
   183 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   184 	drawableTests->TestOpenDrawableInvalidL();
       
   185 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   186 	
       
   187 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   188 	drawableTests->TestCloseDrawableWithoutOpenL();
       
   189 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   190 	
       
   191 	CleanupStack::PopAndDestroy(drawableTests);
       
   192 	}
       
   193 
       
   194 /**
       
   195 Performs the RSgImage low memory tests; checks for Heap and RSgDriver memory
       
   196 leaks after each individual test.
       
   197  */
       
   198 void CTSgResInternalSecondProcessTestHandler::DoImageMemoryTestsL(const TSgResIntTestInfo& aInfo)
       
   199 	{
       
   200 	// open image that is created in another process
       
   201 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   202 	TestOpenImageL(aInfo.iDrawableId);
       
   203 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   204 	
       
   205 	
       
   206 	//Construct the SgImage generic tests using EFalse to enable KErrNoMemory testing
       
   207 	CTSgImageGeneric* imageTests = new(ELeave)CTSgImageGeneric(EFalse);
       
   208 	CleanupStack::PushL(imageTests);
       
   209 	
       
   210 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   211 	imageTests->TestGetPixelFormatsL();
       
   212 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   213 	
       
   214 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   215 	imageTests->TestCreateImageUninitializedL();
       
   216 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   217 	
       
   218 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   219 	imageTests->TestCreateImageL();
       
   220 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   221 	
       
   222 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   223 	imageTests->TestCreateImageFromExistingImageL();
       
   224 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   225 	
       
   226 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   227 	imageTests->TestGetImageInfoL();
       
   228 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   229 	
       
   230 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   231 	imageTests->TestGetImageDrawableIdL(); 
       
   232 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   233 
       
   234 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   235 	imageTests->TestOpenImageL();
       
   236 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   237 	
       
   238 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   239 	imageTests->TestGetInterfaceL();
       
   240 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   241 	
       
   242 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   243 	imageTests->TestGetPixelFormatsInvalidL();
       
   244 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   245 	
       
   246 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   247 	imageTests->TestOpenImageInvalidL();
       
   248 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   249 	
       
   250 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   251 	imageTests->TestCloseImageManyTimesL();
       
   252 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   253 	
       
   254 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   255 	imageTests->TestCloseImageWithoutOpenL();
       
   256 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   257 	
       
   258 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   259 	imageTests->TestCreateImageInvalidL();
       
   260 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   261 
       
   262 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   263 	imageTests->TestGetInfoImageInvalidL();
       
   264 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   265 
       
   266 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   267 	imageTests->TestGetAttributesImageInvalidL();
       
   268 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   269 
       
   270 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   271 	imageTests->TestCreateImageDataStrideL();
       
   272 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   273 
       
   274 	__UHEAP_MARK; iTestExt->AllocMarkStart();
       
   275 	imageTests->TestStress1L();
       
   276 	__UHEAP_MARKEND; iTestExt->AllocMarkEnd(0);
       
   277 	
       
   278 	
       
   279 	CleanupStack::PopAndDestroy(imageTests);
       
   280 	}
       
   281 
       
   282 /*
       
   283  Used for OOM testing for opening an image in another process. For this purpose,
       
   284  the image that is opened here must be created in another process.
       
   285  */
       
   286 void CTSgResInternalSecondProcessTestHandler::TestOpenImageL(TSgDrawableId aId)
       
   287     {
       
   288     TSgDrawableId id = aId;
       
   289     
       
   290     RSgImage image;
       
   291 
       
   292     User::LeaveIfError(image.Open(id));
       
   293     
       
   294     image.Close();
       
   295     }
       
   296 
       
   297 /**
       
   298 Test the Local Reference count of RSgDriver when creating and destroying images
       
   299  */
       
   300 TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownL()
       
   301 	{
       
   302 	TInt result = 0;
       
   303 	TSgImageInfo info;
       
   304 	info.iSizeInPixels = TSize(8, 8);
       
   305 	info.iUsage = ESgUsageBitOpenVgImage;
       
   306 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   307 
       
   308 	RSgImage image;	
       
   309 	User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));	
       
   310 
       
   311 	if (1 == iProfExt->LocalResourceCount())
       
   312 		result |= EFirstTestPassed;
       
   313 
       
   314 	image.Close();
       
   315 
       
   316 	User::LeaveIfError(image.Create(info, KCrossImageData, KCrossImageDataStride));	
       
   317 	image.Close();
       
   318 
       
   319 	if (KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
       
   320 		result |= ESecondTestPassed;
       
   321 	image.Close();
       
   322 
       
   323 	if (0 == iProfExt->LocalResourceCount())
       
   324 		result |= EThirdTestPassed;
       
   325 
       
   326 	return result;
       
   327 	}
       
   328 
       
   329 /**
       
   330 Test the Local Reference count of RSgDriver when creating and destroying images
       
   331 with multiple driver sessions.
       
   332  */
       
   333 TInt CTSgResInternalSecondProcessTestHandler::TestDriverInitializeAndShutdownManyTimes()
       
   334 	{
       
   335 	TInt result = 0;
       
   336 	__UHEAP_MARK;
       
   337 	
       
   338 	TSgImageInfo info;
       
   339 	info.iSizeInPixels = TSize(8, 8);
       
   340 	info.iUsage = ESgUsageBitOpenVgImage;
       
   341 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   342 	
       
   343 	RSgImage image;
       
   344 	
       
   345 	if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
       
   346 		result |= EFirstTestPassed;
       
   347 	
       
   348 	image.Close();
       
   349 	
       
   350 	iSgDriver.Close();
       
   351 	iSgDriver.Close();
       
   352 	
       
   353 	if(KErrNone == iSgDriver.Open())
       
   354 		result |= ESecondTestPassed;
       
   355 	
       
   356 	if(KErrNone == image.Create(info, KCrossImageData, KCrossImageDataStride))
       
   357 		result |= EThirdTestPassed;
       
   358 	
       
   359 	image.Close();
       
   360 	
       
   361 	if(0 == iProfExt->LocalResourceCount())
       
   362 		result |= EFourthTestPassed;
       
   363 	
       
   364 	iSgDriver.Close();
       
   365 	
       
   366 	__UHEAP_MARKEND;
       
   367 	
       
   368 	return result;
       
   369 	}
       
   370 
       
   371 /**
       
   372 Test the SgDriver extension MSgDriver_Profiling is reporting the correct local and 
       
   373 global memory usage and resource counts, when another process has created images 
       
   374 and then called into this process.
       
   375  */
       
   376 TInt CTSgResInternalSecondProcessTestHandler::TestResourceProfiling(TSgResIntTestInfo& aInfo)
       
   377 	{
       
   378 	__UHEAP_MARK;
       
   379 	TInt result = 0;
       
   380 	const TSize KImageSize(8, 8);
       
   381 	
       
   382 	// Check that this process is reporting the same memory usage as the calling
       
   383 	// process, and is using zero local memory.
       
   384 	if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
       
   385 		result |= EFirstTestPassed;
       
   386 	if (iProfExt->LocalGraphicsMemoryUsed() == 0)
       
   387 		result |= ESecondTestPassed;
       
   388 	if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
       
   389 		result |= EThirdTestPassed;
       
   390 	
       
   391 	RSgImage image;
       
   392 	if (KErrNone == image.Create(TSgImageInfo(KImageSize, ESgPixelFormatARGB_8888, ESgUsageBitOpenVgImage)))
       
   393 		{
       
   394 		// Check that the local resource count is one, and the global resource count has
       
   395 		// incremented by one.
       
   396 		if (iProfExt->LocalResourceCount() == 1)
       
   397 			result |=  EFourthTestPassed;
       
   398 		if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount+1)
       
   399 			result |= EFifthTestPassed;
       
   400 		
       
   401 		// Check that creating an image in this process increases the global and
       
   402 		// local memory usage reported by the extension, and destroying it will
       
   403 		// set it back to how it was.
       
   404 		TInt localGraphicsMemory = iProfExt->LocalGraphicsMemoryUsed();
       
   405 		TInt globalGraphicsMemory = iProfExt->GlobalGraphicsMemoryUsed();
       
   406 		if (localGraphicsMemory >= (KImageSize.iWidth * KImageSize.iHeight * 4))
       
   407 			result |= ESixthTestPassed;
       
   408 		if (globalGraphicsMemory == (localGraphicsMemory + aInfo.iGlobalGraphicsMemory))
       
   409 			result |= ESeventhTestPassed;
       
   410 		
       
   411 		image.Close();
       
   412 		
       
   413 		// Check the local memory usage is the same as before the test started
       
   414 		if (iProfExt->LocalGraphicsMemoryUsed() == 0)
       
   415 			result |= EEighthTestPassed;
       
   416 		if (iProfExt->GlobalGraphicsMemoryUsed() == aInfo.iGlobalGraphicsMemory)
       
   417 			result |= ENinthTestPassed;		
       
   418 		// Check the local resource count is zero and the global count is the same
       
   419 		// as before the test started.
       
   420 		if (iProfExt->LocalResourceCount() == 0)
       
   421 			result |= ETenthTestPassed;
       
   422 		if (iProfExt->GlobalResourceCount() == aInfo.iGlobalResourceCount)
       
   423 			result |= EEleventhTestPassed;
       
   424 		}
       
   425 	
       
   426 	__UHEAP_MARKEND;
       
   427 	return result;
       
   428 	}