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