os/graphics/graphicsresourceservices/graphicsresource/test/tgraphicsresourcesecondprocess.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresource/test/tgraphicsresourcesecondprocess.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,435 @@
     1.4 +// Copyright (c) 2007-2009 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 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +#include "tgraphicsresourcemultiprocessthread.h"
    1.26 +#include <e32debug.h>
    1.27 +#include <graphics/sgimage_sw.h>
    1.28 +
    1.29 +/**
    1.30 +Helper function to test the equivalence of two TSgImageInfo structures.
    1.31 +
    1.32 +@param   aInfo1 A TSgImageInfo structure to compare.
    1.33 +@param   aInfo2 A TSgImageInfo structure to compare.
    1.34 +
    1.35 +@return  ETrue if the two are identical, EFalse otherwise.
    1.36 +*/
    1.37 +TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
    1.38 +	{
    1.39 +	TBool result = EFalse;
    1.40 +	if(aInfo1.iCpuAccess == aInfo2.iCpuAccess 
    1.41 +		&& aInfo1.iPixelFormat == aInfo2.iPixelFormat
    1.42 +		&& aInfo1.iScreenId == aInfo2.iScreenId
    1.43 +		&& aInfo1.iShareable == aInfo2.iShareable
    1.44 +		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
    1.45 +		&& aInfo1.iUsage | aInfo2.iUsage
    1.46 +		&& aInfo1.iUserAttributeCount == aInfo2.iUserAttributeCount)
    1.47 +		{
    1.48 +		for(TInt i=0; i<aInfo1.iUserAttributeCount; ++i)
    1.49 +			{
    1.50 +			if(aInfo1.iUserAttributes[i].iUid != aInfo2.iUserAttributes[i].iUid)
    1.51 +				{
    1.52 +				break;
    1.53 +				}
    1.54 +			}
    1.55 +		result = ETrue;
    1.56 +		}
    1.57 +	return result;
    1.58 +	}
    1.59 +
    1.60 +/**
    1.61 +Opens an image in a different process.
    1.62 +@param aInfo The test information passed from outside the current thread
    1.63 +@return The test result indicating which tests passed
    1.64 +*/
    1.65 +TInt TestOpenImageL(TSgresTestInfo& aInfo)
    1.66 +	{
    1.67 +	TSgDrawableId id = aInfo.iDrawableId;
    1.68 +	TSgImageInfo imageInfo1 = aInfo.iImageInfo;
    1.69 +	
    1.70 +	RSgImage image;
    1.71 +	TInt result = 0;
    1.72 +	
    1.73 +	if(KErrNone == image.Open(id))
    1.74 +		{
    1.75 +		result |=  EFirstTestPassed;
    1.76 +		}
    1.77 +	
    1.78 +	TSgImageInfo imageInfo2;
    1.79 +	if(KErrNone == image.GetInfo(imageInfo2))
    1.80 +		{
    1.81 +		result |= ESecondTestPassed;
    1.82 +		}
    1.83 +	if(CompareInfos(imageInfo1, imageInfo2))
    1.84 +		{
    1.85 +		result |= EThirdTestPassed;
    1.86 +		}
    1.87 +	if(image.Id() == id)
    1.88 +		{
    1.89 +		result |= EFourthTestPassed;
    1.90 +		}
    1.91 +	
    1.92 +	image.Close();
    1.93 +	
    1.94 +	return result;
    1.95 +	}
    1.96 +
    1.97 +/**
    1.98 +Opens an image in a different process into a RSgDrawable object.
    1.99 +@param aInfo The test information passed from outside the current thread
   1.100 +@return The test result indicating which tests passed
   1.101 +*/
   1.102 +TInt TestOpenDrawableL(TSgresTestInfo& aInfo)
   1.103 +	{
   1.104 +	TSgDrawableId id = aInfo.iDrawableId;
   1.105 +	
   1.106 +	RSgDrawable drawable;
   1.107 +	TInt result = 0;
   1.108 +	
   1.109 +	if(KErrNone == drawable.Open(id))
   1.110 +		{
   1.111 +		result |=  EFirstTestPassed;
   1.112 +		}
   1.113 +	TSgDrawableId id2 = drawable.Id();
   1.114 +	if(id2 != KSgNullDrawableId)
   1.115 +		{
   1.116 +		result |= ESecondTestPassed;
   1.117 +		}
   1.118 +	if(id2 == id)
   1.119 +		{
   1.120 +		result |= EThirdTestPassed;
   1.121 +		}
   1.122 +
   1.123 +	drawable.Close();
   1.124 +	return result;
   1.125 +	}
   1.126 +
   1.127 +/**
   1.128 +Opens an image in a different process with different invalid operations.
   1.129 +@param aInfo The test information passed from outside the current thread
   1.130 +@return The test result indicating which tests passed
   1.131 +*/
   1.132 +TInt TestOpenImageInvalidL(TSgresTestInfo& aInfo)
   1.133 +	{	
   1.134 +	TSgDrawableId id = aInfo.iDrawableId;
   1.135 +	TSgImageInfo imageInfo = aInfo.iImageInfo;
   1.136 +	
   1.137 +	RSgImage image;
   1.138 +	TInt result = 0;
   1.139 +	
   1.140 +	//create image
   1.141 +	if(KErrNone == image.Create(imageInfo, NULL, 0))
   1.142 +		{
   1.143 +		result |= EFirstTestPassed;
   1.144 +		}
   1.145 +	//  non-empty handle
   1.146 +	if(KErrInUse == image.Open(id))
   1.147 +		{
   1.148 +		result |= ESecondTestPassed;
   1.149 +		}
   1.150 +	image.Close();
   1.151 +	
   1.152 +	//  null drawable id	
   1.153 +	if(KErrArgument == image.Open(KSgNullDrawableId))
   1.154 +		{
   1.155 +		result |= EThirdTestPassed;
   1.156 +		}
   1.157 +	image.Close();
   1.158 +	
   1.159 +	//  non-existing drawable id
   1.160 +	TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
   1.161 +	if(KErrNotFound == image.Open(fakeid))
   1.162 +		{
   1.163 +		result |= EFourthTestPassed;
   1.164 +		}
   1.165 +	image.Close();
   1.166 +	
   1.167 +	//  open a non-sharable image
   1.168 +	TInt openResult = image.Open(id);
   1.169 +	if(KErrPermissionDenied == openResult || KErrNotFound == openResult)
   1.170 +		{
   1.171 +		result |= EFifthTestPassed;
   1.172 +		}
   1.173 +	image.Close();
   1.174 +	
   1.175 +	return result;
   1.176 +	}
   1.177 +
   1.178 +/**
   1.179 +Calls SgDriver::AllocMarkEnd() without closing all the resources.
   1.180 +@param aInfo The test information passed from outside the current thread
   1.181 +@panic SGRES-ADAPTER 0
   1.182 +@return The test result indicating which tests passed
   1.183 +*/
   1.184 +TInt TestDriverMemoryLeakL(TSgresTestInfo& /*aInfo*/)
   1.185 +	{
   1.186 +	SgDriver::AllocMarkStart();
   1.187 +	TSgImageInfo info;
   1.188 +	info.iSizeInPixels = TSize(8, 8);
   1.189 +	info.iUsage = ESgUsageDirectGdiSource;
   1.190 +	info.iPixelFormat = EUidPixelFormatRGB_565;
   1.191 +	info.iCpuAccess = ESgCpuAccessReadWrite;
   1.192 +	info.iShareable = EFalse;
   1.193 +	info.iScreenId = 0;
   1.194 +	
   1.195 +	RSgImage image;
   1.196 +	image.Create(info, NULL, 0);
   1.197 +	SgDriver::AllocMarkEnd(0); //should panic here
   1.198 +	image.Close();
   1.199 +	return KErrNone;
   1.200 +	}
   1.201 +
   1.202 +/**
   1.203 +Shuts down the driver when there are still resources open.
   1.204 +@param aInfo The test information passed from outside the current thread
   1.205 +@panic SGRES 1
   1.206 +@return The test result indicating which tests passed
   1.207 +*/
   1.208 +TInt TestShutdownMemoryLeakL(TSgresTestInfo& /*aInfo*/)
   1.209 +	{
   1.210 +	TSgImageInfo info;
   1.211 +	info.iSizeInPixels = TSize(8, 8);
   1.212 +	info.iUsage = ESgUsageDirectGdiSource;
   1.213 +	info.iPixelFormat = EUidPixelFormatRGB_565;
   1.214 +	info.iCpuAccess = ESgCpuAccessReadWrite;
   1.215 +	info.iShareable = EFalse;
   1.216 +	info.iScreenId = 0;
   1.217 +	
   1.218 +	RSgImage image;
   1.219 +	TInt ret = image.Create(info, NULL, 0);
   1.220 +	if(KErrNone != ret)
   1.221 +		{
   1.222 +		return ret;
   1.223 +		}		
   1.224 +	SgDriver::Close(); //should panic here
   1.225 +	return KErrNone;
   1.226 +	}
   1.227 +
   1.228 +/**
   1.229 +Opens a drawable in a different process with different invalid operations.
   1.230 +@param aInfo The test information passed from outside the current thread
   1.231 +@return The test result indicating which tests passed
   1.232 +*/
   1.233 +TInt TestOpenDrawableInvalidL(TSgresTestInfo& aInfo)
   1.234 +	{	
   1.235 +	TSgDrawableId id = aInfo.iDrawableId;
   1.236 +	
   1.237 +	RSgDrawable  drawable;
   1.238 +	TInt result = 0;
   1.239 +	
   1.240 +	//null drawable id	
   1.241 +	if(KErrArgument == drawable.Open(KSgNullDrawableId))
   1.242 +		{
   1.243 +		result |= EFirstTestPassed;
   1.244 +		}
   1.245 +	drawable.Close();
   1.246 +	
   1.247 +	//non-existing drawable id
   1.248 +	TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
   1.249 +	if(KErrNotFound == drawable.Open(fakeid))
   1.250 +		{
   1.251 +		result |= ESecondTestPassed;
   1.252 +		}
   1.253 +	drawable.Close();
   1.254 +	
   1.255 +	//open a non-sharable image - should fail
   1.256 +	TInt openResult = drawable.Open(id);
   1.257 +	if(KErrPermissionDenied == openResult || KErrNotFound == openResult)
   1.258 +		{
   1.259 +		result |= EThirdTestPassed;
   1.260 +		}
   1.261 +	drawable.Close();
   1.262 +	
   1.263 +	//non-empty handle
   1.264 +	//create an image
   1.265 +	TSgImageInfo info1;
   1.266 +	info1.iSizeInPixels = TSize(8, 8);
   1.267 +	info1.iUsage = ESgUsageDirectGdiTarget;
   1.268 +	info1.iPixelFormat = EUidPixelFormatRGB_565;
   1.269 +	info1.iCpuAccess = ESgCpuAccessNone;
   1.270 +	info1.iShareable = ETrue;
   1.271 +	
   1.272 +	RSgImage image;
   1.273 +	TInt err = image.Create(info1, NULL, 0);
   1.274 +	if(KErrNoMemory == err)
   1.275 +		{
   1.276 +		result = KErrNoMemory;
   1.277 +		}
   1.278 +	else if(KErrNone != err)
   1.279 +		{
   1.280 +		result = err;
   1.281 +		}
   1.282 +	else
   1.283 +		{		
   1.284 +		if(KErrNone == drawable.Open(image.Id()))
   1.285 +			{
   1.286 +			result |= EFourthTestPassed;
   1.287 +			}		
   1.288 +		
   1.289 +		//handle is non-null now
   1.290 +		if(KErrInUse == drawable.Open(id))
   1.291 +			{
   1.292 +			result |= EFifthTestPassed;
   1.293 +			}
   1.294 +		drawable.Close();
   1.295 +		}
   1.296 +	image.Close();
   1.297 +	return result;
   1.298 +	}
   1.299 +
   1.300 +/**
   1.301 +Maps an image in a different process.
   1.302 +The operation should fail.
   1.303 +@param aInfo The test information passed from outside the current thread
   1.304 +@return The test result indicating which tests passed
   1.305 +*/
   1.306 +TInt TestMapImageNonOwnerL(TSgresTestInfo& aInfo)
   1.307 +	{
   1.308 +	TSgDrawableId id = aInfo.iDrawableId;
   1.309 +	
   1.310 +	RSgImage image;
   1.311 +	const TAny* dataAddressRead;
   1.312 +	TAny* dataAddressWrite;
   1.313 +	TInt dataStride;
   1.314 +	TInt result = 0;
   1.315 +	
   1.316 +	if(KErrNone == image.Open(id))
   1.317 +		{
   1.318 +		result |= EFirstTestPassed;
   1.319 +		}
   1.320 +	if(KErrPermissionDenied == image.MapReadOnly(dataAddressRead, dataStride))
   1.321 +		{
   1.322 +		result |= ESecondTestPassed;
   1.323 +		}
   1.324 +	if(KErrPermissionDenied == image.MapWriteOnly(dataAddressWrite, dataStride))
   1.325 +		{
   1.326 +		result |= EThirdTestPassed;
   1.327 +		}
   1.328 +	if(KErrPermissionDenied == image.MapReadWrite(dataAddressWrite, dataStride))
   1.329 +		{
   1.330 +		result |= EFourthTestPassed;
   1.331 +		}
   1.332 +
   1.333 +	TInt unmapResult = image.Unmap();
   1.334 +	if(KErrGeneral == unmapResult || KErrPermissionDenied == unmapResult)
   1.335 +		{
   1.336 +		result |= EFifthTestPassed;
   1.337 +		}
   1.338 +	
   1.339 +	image.Close();
   1.340 +	return result;
   1.341 +	}
   1.342 +
   1.343 +/**
   1.344 +Unmaps an image in another process.
   1.345 +@param aInfo The test information passed from outside the current thread
   1.346 +@return The test result indicating which tests passed
   1.347 +*/
   1.348 +TInt TestUnmapImageL(TSgresTestInfo& aInfo)
   1.349 +	{
   1.350 +	TSgDrawableId id = aInfo.iDrawableId;
   1.351 +	
   1.352 +	RSgImage image;
   1.353 +	TInt result = 0;
   1.354 +	
   1.355 +	if(KErrNone == image.Open(id))
   1.356 +		{
   1.357 +		result |= EFirstTestPassed;
   1.358 +		}
   1.359 +	if(KErrGeneral == image.Unmap())
   1.360 +		{
   1.361 +		result |= ESecondTestPassed;
   1.362 +		}
   1.363 +	image.Close();
   1.364 +	return result;
   1.365 +	}
   1.366 +
   1.367 +// Real main function
   1.368 +TInt MainL()
   1.369 +	{				
   1.370 +	TInt procHandles1  =0;
   1.371 +	TInt threadHandles1=0;
   1.372 +	RThread().HandleCount(procHandles1, threadHandles1);
   1.373 +	
   1.374 +	TPckgBuf<TSgresTestInfo> infoPkg;
   1.375 +	User::LeaveIfError(User::GetDesParameter(KSecondProcessParametersSlot, infoPkg));
   1.376 +	TSgresTestInfo& info = infoPkg();
   1.377 +	TSgresTestCase testCase = info.iTestCase;
   1.378 +	TInt result = 0;
   1.379 +
   1.380 +	if(KErrNone == SgDriver::Open())
   1.381 +		{
   1.382 +			switch(testCase)
   1.383 +			{
   1.384 +			case ESgresSecondProcessOpenImage:
   1.385 +				result = TestOpenImageL(info);
   1.386 +				break;
   1.387 +			case ESgresSecondProcessOpenDrawable:
   1.388 +				result = TestOpenDrawableL(info);
   1.389 +				break;
   1.390 +			case ESgresSecondProcessOpenImageInvalid:
   1.391 +				result = TestOpenImageInvalidL(info);
   1.392 +				break;
   1.393 +			case ESgresSecondProcessOpenDrawableInvalid:
   1.394 +				result = TestOpenDrawableInvalidL(info);
   1.395 +				break;
   1.396 +			case ESgresSecondProcessMapImage:
   1.397 +				result = TestMapImageNonOwnerL(info);
   1.398 +				break;
   1.399 +			case ESgresSecondProcessUnmapImage:
   1.400 +				result = TestUnmapImageL(info);
   1.401 +				break;
   1.402 +			case ESgresSecondProcessPanicDriverUnclosedResources:
   1.403 +				result = TestShutdownMemoryLeakL(info);
   1.404 +				break;
   1.405 +			case ESgresSecondProcessPanicMemoryLeak:
   1.406 +				result = TestDriverMemoryLeakL(info);
   1.407 +				break;
   1.408 +			}
   1.409 +		}	
   1.410 +	
   1.411 +	SgDriver::Close();
   1.412 +	
   1.413 +	// Handle check
   1.414 +	TInt procHandles2  =0;
   1.415 +	TInt threadHandles2=0;  
   1.416 +	RThread().HandleCount(procHandles2,threadHandles2);
   1.417 +	if (threadHandles1 != threadHandles2)
   1.418 +		{
   1.419 +		result = KErrBadHandle;  // Thread-owned handles not closed
   1.420 +		}
   1.421 +	
   1.422 +	return result;
   1.423 +	}
   1.424 +
   1.425 +GLDEF_C TInt E32Main()
   1.426 +	{
   1.427 +	__UHEAP_MARK;
   1.428 +	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   1.429 +	if(cleanupStack == NULL)
   1.430 +		{
   1.431 +			return KErrNoMemory;
   1.432 +		}
   1.433 +	TInt ret = 0;
   1.434 +	TRAP_IGNORE(ret=MainL());
   1.435 +	delete cleanupStack;
   1.436 +	__UHEAP_MARKEND;
   1.437 +	return ret;
   1.438 +	}