os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourcesecondprocess.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) 2007-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
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Graphics Resource API Conformance Test Suite
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <e32debug.h>
sl@0
    23
#include "tgraphicsresourcemultiprocessthread.h"
sl@0
    24
#include "tgraphicsresourceteststepbase.h"
sl@0
    25
sl@0
    26
/**
sl@0
    27
Helper function to test the equivalence of two TSgImageInfo structures.
sl@0
    28
sl@0
    29
@param   aInfo1 A TSgImageInfo structure to compare.
sl@0
    30
@param   aInfo2 A TSgImageInfo structure to compare.
sl@0
    31
sl@0
    32
@return  ETrue if the two are identical, EFalse otherwise.
sl@0
    33
*/
sl@0
    34
TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
sl@0
    35
	{
sl@0
    36
	TBool result = EFalse;
sl@0
    37
	if(aInfo1.iPixelFormat == aInfo2.iPixelFormat
sl@0
    38
		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
sl@0
    39
		&& aInfo1.iUsage == aInfo2.iUsage)
sl@0
    40
		{
sl@0
    41
		result = ETrue;
sl@0
    42
		}
sl@0
    43
	return result;
sl@0
    44
	}
sl@0
    45
sl@0
    46
/**
sl@0
    47
Opens an image in a different process.
sl@0
    48
@param aInfo The test information passed from outside the current thread
sl@0
    49
@return The test result indicating which tests passed
sl@0
    50
*/
sl@0
    51
TInt TestOpenImageL(TSgProcessTestInfo& aInfo)
sl@0
    52
	{
sl@0
    53
	TSgDrawableId id = aInfo.iDrawableId;
sl@0
    54
	TSgImageInfo imageInfo1 = aInfo.iImageInfo;
sl@0
    55
	
sl@0
    56
	RSgImage image;
sl@0
    57
	TInt result = 0;
sl@0
    58
sl@0
    59
	if(KErrNone == image.Open(id))
sl@0
    60
		{
sl@0
    61
		result |=  EFirstTestPassed;
sl@0
    62
		}
sl@0
    63
	
sl@0
    64
	TSgImageInfo imageInfo2;
sl@0
    65
	TInt attribVal = KMaxTInt;
sl@0
    66
	if(KErrNone == image.GetInfo(imageInfo2))
sl@0
    67
		{
sl@0
    68
		result |= ESecondTestPassed;
sl@0
    69
		}
sl@0
    70
	if(CompareInfos(imageInfo1, imageInfo2))
sl@0
    71
		{
sl@0
    72
		result |= EThirdTestPassed;
sl@0
    73
		}
sl@0
    74
	if (image.Id() != KSgNullDrawableId)
sl@0
    75
		{
sl@0
    76
		result |= EFourthTestPassed;
sl@0
    77
		}
sl@0
    78
	if(image.Id() == id)
sl@0
    79
		{
sl@0
    80
		result |= EFifthTestPassed;
sl@0
    81
		}
sl@0
    82
	TUid uid = { 0x12345678 };
sl@0
    83
	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
sl@0
    84
	    {
sl@0
    85
	    result |= ESixthTestPassed;
sl@0
    86
	    }
sl@0
    87
	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
sl@0
    88
	    {
sl@0
    89
	    result |= ESeventhTestPassed;
sl@0
    90
	    }
sl@0
    91
	image.Close();
sl@0
    92
sl@0
    93
	return result;
sl@0
    94
	}
sl@0
    95
sl@0
    96
/**
sl@0
    97
Opens an image in a different process into a RSgDrawable object.
sl@0
    98
@param aInfo The test information passed from outside the current thread
sl@0
    99
@return The test result indicating which tests passed
sl@0
   100
*/
sl@0
   101
TInt TestOpenDrawableL(TSgProcessTestInfo& aInfo)
sl@0
   102
	{
sl@0
   103
	TSgDrawableId id = aInfo.iDrawableId;
sl@0
   104
	
sl@0
   105
	RSgDrawable drawable;
sl@0
   106
	TInt result = 0;
sl@0
   107
	
sl@0
   108
	if(KErrNone == drawable.Open(id))
sl@0
   109
		{
sl@0
   110
		result |=  EFirstTestPassed;
sl@0
   111
		}
sl@0
   112
	TSgDrawableId id2 = drawable.Id();
sl@0
   113
	if(id2 != KSgNullDrawableId)
sl@0
   114
		{
sl@0
   115
		result |= ESecondTestPassed;
sl@0
   116
		}
sl@0
   117
	if(id2 == id)
sl@0
   118
		{
sl@0
   119
		result |= EThirdTestPassed;
sl@0
   120
		}
sl@0
   121
sl@0
   122
	drawable.Close();
sl@0
   123
	return result;
sl@0
   124
	}
sl@0
   125
sl@0
   126
/**
sl@0
   127
Opens an image in a different process with different invalid operations.
sl@0
   128
@param aInfo The test information passed from outside the current thread
sl@0
   129
@return The test result indicating which tests passed
sl@0
   130
*/
sl@0
   131
TInt TestOpenImageInvalidL(TSgProcessTestInfo& aInfo)
sl@0
   132
	{	
sl@0
   133
	TSgDrawableId id = aInfo.iDrawableId;
sl@0
   134
	TSgImageInfo imageInfo = aInfo.iImageInfo;
sl@0
   135
	
sl@0
   136
	RSgImage image;
sl@0
   137
	TInt result = 0;
sl@0
   138
	
sl@0
   139
	//create image
sl@0
   140
	if(KErrNone == image.Create(imageInfo, NULL, 0))
sl@0
   141
		{
sl@0
   142
		result |= EFirstTestPassed;
sl@0
   143
		}
sl@0
   144
	//  non-empty handle
sl@0
   145
	if(KErrInUse == image.Open(id))
sl@0
   146
		{
sl@0
   147
		result |= ESecondTestPassed;
sl@0
   148
		}
sl@0
   149
	image.Close();
sl@0
   150
	
sl@0
   151
	//  null drawable id	
sl@0
   152
	if(KErrArgument == image.Open(KSgNullDrawableId))
sl@0
   153
		{
sl@0
   154
		result |= EThirdTestPassed;
sl@0
   155
		}
sl@0
   156
	image.Close();
sl@0
   157
	
sl@0
   158
	//  non-existing drawable id
sl@0
   159
	TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
sl@0
   160
	if(KErrNotFound == image.Open(fakeid))
sl@0
   161
		{
sl@0
   162
		result |= EFourthTestPassed;
sl@0
   163
		}
sl@0
   164
	image.Close();
sl@0
   165
	
sl@0
   166
	//Valid Drawable Id
sl@0
   167
	if (KErrNone == image.Open(id))
sl@0
   168
		{
sl@0
   169
		result |= EFifthTestPassed;
sl@0
   170
		}
sl@0
   171
	image.Close();
sl@0
   172
	return result;
sl@0
   173
	}
sl@0
   174
sl@0
   175
/**
sl@0
   176
Opens a drawable in a different process with different invalid operations.
sl@0
   177
@param aInfo The test information passed from outside the current thread
sl@0
   178
@return The test result indicating which tests passed
sl@0
   179
*/
sl@0
   180
TInt TestOpenDrawableInvalidL()
sl@0
   181
	{	
sl@0
   182
	RSgDrawable  drawable;
sl@0
   183
	TInt result = 0;
sl@0
   184
	
sl@0
   185
	//null drawable id	
sl@0
   186
	if(KErrArgument == drawable.Open(KSgNullDrawableId))
sl@0
   187
		{
sl@0
   188
		result |= EFirstTestPassed;
sl@0
   189
		}
sl@0
   190
	drawable.Close();
sl@0
   191
	
sl@0
   192
	//non-existing drawable id
sl@0
   193
	TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
sl@0
   194
	if(KErrNotFound == drawable.Open(fakeid))
sl@0
   195
		{
sl@0
   196
		result |= ESecondTestPassed;
sl@0
   197
		}
sl@0
   198
	drawable.Close();
sl@0
   199
		
sl@0
   200
	//non-empty handle
sl@0
   201
	//create an image
sl@0
   202
	TSgImageInfo info1;
sl@0
   203
	info1.iSizeInPixels = TSize(8, 8);
sl@0
   204
	info1.iUsage = ESgUsageBitOpenVgImage;
sl@0
   205
	info1.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   206
sl@0
   207
	
sl@0
   208
	RSgImage image;
sl@0
   209
	TInt err = image.Create(info1, NULL, 0);
sl@0
   210
	if(KErrNoMemory == err)
sl@0
   211
		{
sl@0
   212
		result = KErrNoMemory;
sl@0
   213
		}
sl@0
   214
	else if(KErrNone != err)
sl@0
   215
		{
sl@0
   216
		result = err;
sl@0
   217
		}
sl@0
   218
	else
sl@0
   219
		{		
sl@0
   220
		if(KErrNone == drawable.Open(image.Id()))
sl@0
   221
			{
sl@0
   222
			result |= EThirdTestPassed;
sl@0
   223
			
sl@0
   224
			if (KErrInUse == drawable.Open(image.Id()))
sl@0
   225
				{
sl@0
   226
				result |= EFourthTestPassed;
sl@0
   227
				}
sl@0
   228
			}		
sl@0
   229
		drawable.Close();
sl@0
   230
		}
sl@0
   231
	image.Close();
sl@0
   232
	return result;
sl@0
   233
	}
sl@0
   234
sl@0
   235
TInt TestCloseDriverOpenResources(RSgDriver& aDriver)
sl@0
   236
	{
sl@0
   237
	RSgImage image;
sl@0
   238
	TSgImageInfo info1;
sl@0
   239
	info1.iSizeInPixels = TSize(8, 8);
sl@0
   240
	info1.iUsage = ESgUsageBitOpenVgImage;
sl@0
   241
	info1.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   242
	
sl@0
   243
	TInt result = image.Create(info1, KCrossImageData, KCrossImageDataStride);
sl@0
   244
	
sl@0
   245
	if (result == KErrNone)
sl@0
   246
		{
sl@0
   247
		//Close the driver without closing the image.
sl@0
   248
		aDriver.Close(); //Should panic with SGRES2
sl@0
   249
		}
sl@0
   250
	
sl@0
   251
	return result;
sl@0
   252
	}
sl@0
   253
sl@0
   254
/**
sl@0
   255
Method executed by secondary thread for test TestOpenImageMulththreadedL
sl@0
   256
*/
sl@0
   257
_LIT(KTestOpenImageMultithreadedSem1, "TestOpenImageMultithreadedSem1");
sl@0
   258
_LIT(KTestOpenImageMultithreadedSem2, "TestOpenImageMultithreadedSem2");
sl@0
   259
sl@0
   260
TInt OpenImageMultiSecondThread(TAny* aAny)
sl@0
   261
	{
sl@0
   262
	TInt err = KErrNone;
sl@0
   263
	TSgProcessTestInfo* info = static_cast<TSgProcessTestInfo*>(aAny);	
sl@0
   264
sl@0
   265
	RSemaphore sem[2];
sl@0
   266
	err = sem[0].OpenGlobal(KTestOpenImageMultithreadedSem1, EOwnerThread);
sl@0
   267
	if (err != KErrNone)
sl@0
   268
		{
sl@0
   269
		return err;
sl@0
   270
		}
sl@0
   271
	err = sem[1].OpenGlobal(KTestOpenImageMultithreadedSem2, EOwnerThread);
sl@0
   272
	if (err != KErrNone)
sl@0
   273
		{
sl@0
   274
		sem[0].Close();
sl@0
   275
		return err;
sl@0
   276
		}
sl@0
   277
sl@0
   278
	RSgImage sgImage; 
sl@0
   279
	err = sgImage.Open(info->iDrawableId);
sl@0
   280
sl@0
   281
	sem[0].Signal();
sl@0
   282
	sem[1].Wait();
sl@0
   283
sl@0
   284
	sgImage.Close();	
sl@0
   285
	sem[0].Signal();
sl@0
   286
	return err;	
sl@0
   287
	}
sl@0
   288
sl@0
   289
/**
sl@0
   290
Creates a second thread which will initially open a handle to the passed TSgDrawableId.
sl@0
   291
The main thread then opens a new handle to the image.
sl@0
   292
The second thread will then close its handle to the image.
sl@0
   293
The main thread will then attempt to access the data of the image.
sl@0
   294
 */
sl@0
   295
TInt TestOpenImageMultithreadedL(TSgProcessTestInfo& aInfo)
sl@0
   296
	{
sl@0
   297
	TInt result = 0;
sl@0
   298
	
sl@0
   299
	//create two semaphores
sl@0
   300
	RSemaphore sem[2];
sl@0
   301
	User::LeaveIfError(sem[0].CreateGlobal(KTestOpenImageMultithreadedSem1, 0, EOwnerThread));
sl@0
   302
	CleanupClosePushL(sem[0]);
sl@0
   303
	User::LeaveIfError(sem[1].CreateGlobal(KTestOpenImageMultithreadedSem2, 0, EOwnerThread));
sl@0
   304
	CleanupClosePushL(sem[1]);
sl@0
   305
		
sl@0
   306
	//create secondary thread
sl@0
   307
	_LIT(KSecondaryThreadName, "TestOpenImageMultithreadedL");
sl@0
   308
	RThread thread;
sl@0
   309
	User::LeaveIfError(thread.Create(KSecondaryThreadName, OpenImageMultiSecondThread, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aInfo));
sl@0
   310
	thread.Resume();
sl@0
   311
	
sl@0
   312
	// Make the second thread open the image before this thread.
sl@0
   313
	sem[0].Wait();
sl@0
   314
sl@0
   315
	// Second thread has opened image, now primary thread opens image
sl@0
   316
	RSgImage sgImage;
sl@0
   317
	TInt err = sgImage.Open(aInfo.iDrawableId);
sl@0
   318
	CleanupClosePushL(sgImage);
sl@0
   319
	sem[1].Signal();
sl@0
   320
	sem[0].Wait();
sl@0
   321
		
sl@0
   322
	// Second thread has closed image and terminated, now wait for thread to clean-up
sl@0
   323
	User::After(100000);
sl@0
   324
sl@0
   325
	if (err == KErrNone)
sl@0
   326
		{
sl@0
   327
		// Do something that requires data access of sgImage, in this case, creating a copy.
sl@0
   328
		result |= EFirstTestPassed;
sl@0
   329
		RSgImage sgImageCopy;
sl@0
   330
		err = sgImageCopy.Create(aInfo.iImageInfo, sgImage);
sl@0
   331
		sgImageCopy.Close();
sl@0
   332
		if (err == KErrNone)
sl@0
   333
			{
sl@0
   334
			result |= ESecondTestPassed;
sl@0
   335
			}	
sl@0
   336
		}
sl@0
   337
	
sl@0
   338
	CleanupStack::PopAndDestroy(3); // sgImage, sem[0], sem[1]		
sl@0
   339
	return result;	
sl@0
   340
	}
sl@0
   341
sl@0
   342
TInt MainL()
sl@0
   343
	{				
sl@0
   344
	TPckgBuf<TSgProcessTestInfo> infoPkg;
sl@0
   345
	User::LeaveIfError(User::GetDesParameter(KSecondProcessParametersSlot, infoPkg));
sl@0
   346
	TSgProcessTestInfo& info = infoPkg();
sl@0
   347
	TSgresTestCase testCase = info.iTestCase;
sl@0
   348
	TInt result = 0;
sl@0
   349
sl@0
   350
	RSgDriver sgDriver;
sl@0
   351
	CleanupClosePushL(sgDriver);
sl@0
   352
	
sl@0
   353
	if(KErrNone == sgDriver.Open())
sl@0
   354
		{
sl@0
   355
		switch(testCase)
sl@0
   356
			{
sl@0
   357
			case ESgresSecondProcessOpenImage:
sl@0
   358
				result = TestOpenImageL(info);
sl@0
   359
				break;
sl@0
   360
			case ESgresSecondProcessOpenDrawable:
sl@0
   361
				result = TestOpenDrawableL(info);
sl@0
   362
				break;
sl@0
   363
			case ESgresSecondProcessOpenImageInvalid:
sl@0
   364
				result = TestOpenImageInvalidL(info);
sl@0
   365
				break;
sl@0
   366
			case ESgresSecondProcessOpenDrawableInvalid:
sl@0
   367
				result = TestOpenDrawableInvalidL();
sl@0
   368
				break;
sl@0
   369
			case ESgresSecondProcessPanicDriverCloseOpenResources:
sl@0
   370
				result = TestCloseDriverOpenResources(sgDriver);
sl@0
   371
				break;
sl@0
   372
			case ESgresSecondProcessOpenImageMultithreaded:
sl@0
   373
				result = TestOpenImageMultithreadedL(info);
sl@0
   374
				break;
sl@0
   375
			}
sl@0
   376
		}	
sl@0
   377
	
sl@0
   378
	CleanupStack::PopAndDestroy(&sgDriver);
sl@0
   379
	
sl@0
   380
	return result;
sl@0
   381
	}
sl@0
   382
sl@0
   383
GLDEF_C TInt E32Main()
sl@0
   384
	{
sl@0
   385
	__UHEAP_MARK;
sl@0
   386
	CTrapCleanup* cleanupStack = CTrapCleanup::New();
sl@0
   387
	if(cleanupStack == NULL)
sl@0
   388
		{
sl@0
   389
		return KErrNoMemory;
sl@0
   390
		}
sl@0
   391
	TInt ret = 0;
sl@0
   392
	TRAP_IGNORE(ret=MainL());
sl@0
   393
	delete cleanupStack;
sl@0
   394
	__UHEAP_MARKEND;
sl@0
   395
	return ret;
sl@0
   396
	}