os/graphics/graphicshwdrivers/surfacemgr/test/src/tsurfacemanagermultithread.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicshwdrivers/surfacemgr/test/src/tsurfacemanagermultithread.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1849 @@
     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 +// Surface manager multi-threaded test code
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code
    1.25 +*/
    1.26 +
    1.27 +#include "tsurfacemanagermultithread.h"
    1.28 +#include <e32base.h>
    1.29 +#include <e32cons.h>
    1.30 +#include <e32test.h>
    1.31 +#include <e32std.h>
    1.32 +#include <e32cmn.h>
    1.33 +#include <e32def.h>	  
    1.34 +
    1.35 +static TSurfaceId globalSurfaceId;	
    1.36 +static TInt testResult;
    1.37 +
    1.38 +typedef CTSurfaceManagerMultiThread::TInfo TInfo;
    1.39 +
    1.40 +CTSurfaceManagerMultiThread::CTSurfaceManagerMultiThread(CTestStep* aStep):
    1.41 +	CTGraphicsBase(aStep)
    1.42 +	{
    1.43 +	
    1.44 +	}
    1.45 +
    1.46 +CTSurfaceManagerMultiThread::~CTSurfaceManagerMultiThread()
    1.47 +	{
    1.48 +	iSurfaceManager.Close();
    1.49 +	}
    1.50 +
    1.51 +void CTSurfaceManagerMultiThread::RunTestCaseL(TInt aCurTestCase)
    1.52 +	{
    1.53 +	TInt procHandles1  =0;
    1.54 +	TInt threadHandles1=0;
    1.55 +	RThread().HandleCount(procHandles1, threadHandles1);
    1.56 +	((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    1.57 +	switch(aCurTestCase)
    1.58 +		{
    1.59 +/**
    1.60 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0078
    1.61 +@SYMPREQ				PREQ1879, PREQ1007
    1.62 +@SYMREQ					REQ8222,REQ8223
    1.63 +@SYMTestPriority		High 
    1.64 +@SYMTestCaseDesc		Test accessing surface in another thread without opening it
    1.65 +						Thread 1: Create Surface 
    1.66 +						Thread 2: Map Surface - KErrNone (still accessible)
    1.67 +						Thread 2: SurfaceInfo - KErrNone (still accessible)
    1.68 +@SYMTestStatus			Implemented
    1.69 +@SYMTestActions			Call CreateSurface(),MapSurface(), SurfaceInfo()
    1.70 +@SYMTestExpectedResults The surface can be successfully accessed in other threads without first opening it.
    1.71 +*/
    1.72 +	case 1:
    1.73 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0078"));
    1.74 +		TestAccessSurfaceWithoutOpeningL();
    1.75 +		break;
    1.76 +/**
    1.77 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0079
    1.78 +@SYMPREQ				PREQ1879, PREQ1007
    1.79 +@SYMREQ					REQ8222,REQ8223
    1.80 +@SYMTestPriority		High 
    1.81 +@SYMTestCaseDesc		Test accessing a surface created in the existing shared chunk in another thread without opening it.
    1.82 +						Thread 1: Create a Surface in the new chunk with valid creation attributes
    1.83 +						Thread 1: Map the surface in the current process to get the chunk handle
    1.84 +						Thread 1: Create a new surface in the existing chunk with valid creation attributes
    1.85 +						Thread 2: Map the second Surface – KErrNone (still accessible)
    1.86 +						Thread 2: SurfaceInfo – KErrNone (still accessible)
    1.87 +@SYMTestStatus			Implemented
    1.88 +@SYMTestActions			Call CreateSurface(),MapSurface(), SurfaceInfo()
    1.89 +@SYMTestExpectedResults MapSurface, SurfaceInfo return KerrNone
    1.90 +*/	
    1.91 +	case 2:
    1.92 +        ((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0079"));
    1.93 +		TestAccessSurfaceInExistingSharedChunkL();
    1.94 +		break;
    1.95 +/**
    1.96 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0080
    1.97 +@SYMPREQ				PREQ1879, PREQ1007
    1.98 +@SYMREQ					REQ8222,REQ8223
    1.99 +@SYMTestPriority		High 
   1.100 +@SYMTestCaseDesc		Test closing surface in another thread without opening it
   1.101 +						Thread 1: Create Surface 
   1.102 +						Thread 2: Close Surface - KErrNone
   1.103 +@SYMTestStatus			Implemented
   1.104 +@SYMTestActions			Call CreateSurface(),CloseSurface()
   1.105 +@SYMTestExpectedResults The surface can be successfully closed in other threads without first opening it.
   1.106 +*/
   1.107 +	case 3:
   1.108 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0080"));
   1.109 +		TestCloseSurfaceWithoutOpeningL();
   1.110 +		break;
   1.111 +/**
   1.112 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0081
   1.113 +@SYMPREQ				PREQ1879, PREQ1007
   1.114 +@SYMREQ					REQ8222,REQ8223
   1.115 +@SYMTestPriority		High 
   1.116 +@SYMTestCaseDesc		Test accessing an surface which is created in another thread but closed in current thread 
   1.117 +						Thread 2: Create Surface
   1.118 +						Thread 1: Close Surface - KerrNone
   1.119 +						Thread 2: Map Surface - KErrArgument
   1.120 +						Thread 2: SurfaceInfo - KErrArgument
   1.121 +@SYMTestStatus			Implemented
   1.122 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo()
   1.123 +@SYMTestExpectedResults The surface cant be accessd even after it is closed in other threads.
   1.124 +*/
   1.125 +	case 4:
   1.126 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0081"));
   1.127 +		TestAccessSurfaceClosedThreadL();
   1.128 +		break;
   1.129 +/**
   1.130 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0067
   1.131 +@SYMPREQ				PREQ1879, PREQ1007
   1.132 +@SYMREQ					REQ8222,REQ8223
   1.133 +@SYMTestPriority		High 
   1.134 +@SYMTestCaseDesc		Test closing surface created in the existing chunk in another thread without opening it 
   1.135 +						Thread 1: Create a Surface in a new shared chunk with valid attributes
   1.136 +						Thread 1: Map the surface in the process to get the shared chunk handle
   1.137 +						Thread 1: Create a new surface in the existing shared chunk
   1.138 +						Thread 2: Close the second surface – KErrNone (the second surface is deleted)
   1.139 +						Thread 2: Call SurfaceInfo to the first surface and it returns KErrNone, but it returns KErrArgument to the second surface.
   1.140 +						Thread 2: Close the first surface and check it returns KErrNone (the first surface is deleted).
   1.141 +						Thread 1: Call SurfaceInfo to both surfaces and return KErrArgument
   1.142 +						Thread 1: Check the chunk is still accessible by calling RChunk::Base() 
   1.143 +						Thread 1: Close the chunk handle  
   1.144 +@SYMTestStatus			Implemented
   1.145 +@SYMTestActions			Call CreateSurface(),CloseSurface()
   1.146 +@SYMTestExpectedResults CloseSurface returns KErrNone. The chunk handle is not closed even when both surfaces are deleted.
   1.147 +*/		
   1.148 +	case 5:
   1.149 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0067"));
   1.150 +		TestCloseSurfaceExistingSharedChunkL();
   1.151 +		break;
   1.152 +
   1.153 +/**
   1.154 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0068
   1.155 +@SYMPREQ				PREQ1007
   1.156 +@SYMREQ					REQ8222,REQ8223
   1.157 +@SYMTestPriority		High 
   1.158 +@SYMTestCaseDesc		Test closing an surface which is already closed in other thread return KErrArgument 
   1.159 +						Thread 2: Create Surface
   1.160 +						Thread 1: Close Surface - KerrNone
   1.161 +						Thread 2: Close Surface - KErrArgument
   1.162 +@SYMTestStatus			Implemented
   1.163 +@SYMTestActions			Call CreateSurface(),CloseSurface()
   1.164 +@SYMTestExpectedResults The surface cant be closed again.
   1.165 +*/
   1.166 +	case 6:
   1.167 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0068"));
   1.168 +		TestCloseSurfaceClosedThreadL();
   1.169 +		break;
   1.170 +/**
   1.171 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0069
   1.172 +@SYMPREQ				PREQ1007
   1.173 +@SYMREQ					REQ8222,REQ8223
   1.174 +@SYMTestPriority		High 
   1.175 +@SYMTestCaseDesc		Test accessing an surface which is already opened and closed in another thread, given that the process still owns the surface 
   1.176 +						Thread 1: Create Surface
   1.177 +						Thread 2: Open Surface -- KErrNone
   1.178 +						Thread 2: Close Surface -- KErrNone
   1.179 +						Thread 1: Map Surface - KErrNone
   1.180 +						Thread 1: SurfaceInfo - KErrNone
   1.181 +@SYMTestStatus			Implemented
   1.182 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo, OpenSurface()
   1.183 +@SYMTestExpectedResults The surface is still accessible in the thread residing the owning process
   1.184 +*/
   1.185 +	case 7:
   1.186 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0069"));
   1.187 +		TestAccessSurfaceOpenedClosedThreadL();
   1.188 +		break;
   1.189 +/**
   1.190 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0070
   1.191 +@SYMPREQ				PREQ1007
   1.192 +@SYMREQ					REQ8222,REQ8223
   1.193 +@SYMTestPriority		High 
   1.194 +@SYMTestCaseDesc		Test closing an surface which is already opened and closed in another thread, given that the process still owns the surface
   1.195 +    					Thread 1: Create Surface
   1.196 +						Thread 2: Open Surface
   1.197 +						Thread 2: Close Surface
   1.198 +						Thread 1: Close Surface - KErrNone
   1.199 +@SYMTestStatus			Implemented
   1.200 +@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
   1.201 +@SYMTestExpectedResults The surface is still closible in the thread residing in the owning process
   1.202 +*/
   1.203 +	case 8:
   1.204 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0070"));
   1.205 +		TestCloseSurfaceOpenedClosedThreadL();
   1.206 +		break;
   1.207 +/**
   1.208 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0071
   1.209 +@SYMPREQ				PREQ1007
   1.210 +@SYMREQ					REQ8222,REQ8223
   1.211 +@SYMTestPriority		High 
   1.212 +@SYMTestCaseDesc		Test accessing surface in another thread when the opening thread is killed   
   1.213 +						Thread 1: Create Surface 
   1.214 +						Thread 2: Open Surface
   1.215 +						Thread 2: Kill the thread
   1.216 +						Thread 1: Map Surface - KErrNone
   1.217 +						Thread 1: Surface Info -- KErrNone
   1.218 +@SYMTestStatus			Implemented
   1.219 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(), OpenSurface()
   1.220 +@SYMTestExpectedResults The surface is accessible when the opening thread is killed
   1.221 +*/
   1.222 +	case 9:
   1.223 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0071"));
   1.224 +		TestAccessSurfaceOpenedKilledThreadL();
   1.225 +		break;
   1.226 +/**
   1.227 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0072
   1.228 +@SYMPREQ				PREQ1007
   1.229 +@SYMREQ					REQ8222,REQ8223
   1.230 +@SYMTestPriority		High 
   1.231 +@SYMTestCaseDesc		Test closing surface in another thread when the opening thread is killed   
   1.232 +						Thread 1: Create Surface 
   1.233 +						Thread 2: Open Surface
   1.234 +						Thread 2: Kill the thread
   1.235 +						Thread 1: Close Surface - KErrNone
   1.236 +@SYMTestStatus			Implemented
   1.237 +@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
   1.238 +@SYMTestExpectedResults The surface is closible when the opening thread is killed
   1.239 +*/
   1.240 +	case 10:
   1.241 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0072"));
   1.242 +		TestCloseSurfaceOpenedKilledThreadL();
   1.243 +		break;
   1.244 +/**
   1.245 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0073
   1.246 +@SYMPREQ				PREQ1007
   1.247 +@SYMREQ					REQ8222,REQ8223
   1.248 +@SYMTestPriority		High 
   1.249 +@SYMTestCaseDesc		Test accessing surface in another thread when the creating thread is killed and it is closed in other threads
   1.250 +						Thread 2: Create Surface
   1.251 +						Thread 1: Close Surface
   1.252 +						Thread 2: Kill Thread
   1.253 +						Thread 1: Map Surface - KErrArgument
   1.254 +						Thread 1: Surface Info - KErrArgument
   1.255 +@SYMTestStatus			Implemented
   1.256 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(),
   1.257 +@SYMTestExpectedResults The surface is accessible when the creating thread is killed and it is closed in other threads
   1.258 +*/
   1.259 +	case 11:
   1.260 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0073"));
   1.261 +		TestAccessSurfaceCreateKilledThreadL();
   1.262 +		break;
   1.263 +/**
   1.264 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0074
   1.265 +@SYMPREQ				PREQ1007
   1.266 +@SYMREQ					REQ8222,REQ8223
   1.267 +@SYMTestPriority		High 
   1.268 +@SYMTestCaseDesc		Test accessing surface in another thread when the creating thread is killed and it is closed in other threads
   1.269 +						Thread 2: Create Surface
   1.270 +						Thread 1: Close Surface
   1.271 +						Thread 2: Kill Thread
   1.272 +						Thread 1: Close Surface - KErrArgument
   1.273 +@SYMTestStatus			Implemented
   1.274 +@SYMTestActions			Call CreateSurface(),CloseSurface()
   1.275 +@SYMTestExpectedResults The surface is accessible when the creating thread is killed and it is closed in other threads
   1.276 +*/
   1.277 +	case 12:
   1.278 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0074"));
   1.279 +		TestCloseSurfaceCreateKilledThreadL();
   1.280 +		break;
   1.281 +/**
   1.282 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0075
   1.283 +@SYMPREQ				PREQ1007
   1.284 +@SYMREQ					REQ8222,REQ8223
   1.285 +@SYMTestPriority		High 
   1.286 +@SYMTestCaseDesc		Test closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface
   1.287 +    					Thread 1: Create Surface
   1.288 +						Thread 2: Open Surface
   1.289 +						Thread 2: Close Surface
   1.290 +						Thread 3: Open Surface - KerrNone
   1.291 +						Thread 3: Map Surface - KerrNone
   1.292 +						Thread 3: SurfaceInfo -- KErrNone
   1.293 +@SYMTestStatus			Implemented
   1.294 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(),
   1.295 +@SYMTestExpectedResults It is expected that closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface
   1.296 +*/
   1.297 +	case 13:
   1.298 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0075"));
   1.299 +		TestAccessSurfaceThreeThreadsL();
   1.300 +		break;	
   1.301 +/**
   1.302 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0076
   1.303 +@SYMPREQ				PREQ1007
   1.304 +@SYMREQ					REQ8222,REQ8223
   1.305 +@SYMTestPriority		High 
   1.306 +@SYMTestCaseDesc		Test surface can be accessed from third thread when creating thread dies and second thread closes
   1.307 +    					Thread 2: Create Surface
   1.308 +						Thread 1: Open Surface
   1.309 +						Thread 3: Open Surface
   1.310 +						Thread 1: Close Surface
   1.311 +						Thread 2: Kill Thread
   1.312 + 					 	Thread 3: Close Surface
   1.313 +						Thread 3: Map Surface - KerrNone
   1.314 +						Thread 3: SurfaceInfo -- KErrNone
   1.315 +@SYMTestStatus			Implemented
   1.316 +@SYMTestActions			Call CreateSurface(),CloseSurface(), MapSurface(), SurfaceInfo(), OpenSurface()
   1.317 +@SYMTestExpectedResults It is expected that surface can be accessed from third thread when creating thread dies and second thread closes
   1.318 +*/
   1.319 +	case 14:
   1.320 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0076"));
   1.321 +		TestAccessSurfaceDieCloseOtherThreadsL();
   1.322 +		break;
   1.323 +/**
   1.324 +@SYMTestCaseID			GRAPHICS-SURFACEMANAGER-0077
   1.325 +@SYMPREQ				PREQ1007
   1.326 +@SYMREQ					REQ8222,REQ8223
   1.327 +@SYMTestPriority		High 
   1.328 +@SYMTestCaseDesc		Test that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface
   1.329 +   						Thread 2: Create Surface
   1.330 +						Thread 1: Open Surface
   1.331 +						Thread 3: Open Surface
   1.332 +						Thread 1: Close Surface
   1.333 +						Thread 2: Kill Thread
   1.334 + 					    Thread 3: Close Surface
   1.335 +						Thread 3: Open Surface - KerrNone
   1.336 +@SYMTestStatus			Implemented
   1.337 +@SYMTestActions			Call CreateSurface(),CloseSurface(), OpenSurface()
   1.338 +@SYMTestExpectedResults It is expected that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface
   1.339 +*/
   1.340 +	case 15:
   1.341 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEMANAGER-0077"));
   1.342 +		TestOpenSurfaceDieCloseOtherThreadsL();
   1.343 +		break;
   1.344 +	default:
   1.345 +		((CTSurfaceManagerMultiThreadStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.346 +		((CTSurfaceManagerMultiThreadStep*)iStep)->CloseTMSGraphicsStep();
   1.347 +		TestComplete();
   1.348 +		break;
   1.349 +		}
   1.350 +	((CTSurfaceManagerMultiThreadStep*)iStep)->RecordTestResultL();
   1.351 +	// Handle check
   1.352 +	TInt procHandles2  =0;
   1.353 +	TInt threadHandles2=0;
   1.354 +	RThread().HandleCount(procHandles2,threadHandles2);
   1.355 +	if (threadHandles1 != threadHandles2)
   1.356 +		{
   1.357 +		User::Leave(KErrGeneral);  // Thread-owned handles not closed
   1.358 +		}
   1.359 + 	}
   1.360 +
   1.361 +void CTSurfaceManagerMultiThread::CloseSurfaceWhenLeave(TAny* aInfo) 
   1.362 +	{
   1.363 +	TInt err1 = ((TInfo*)aInfo)->iSurfaceManager.CloseSurface(((TInfo*)aInfo)->iSurfaceId);
   1.364 +	TInt err2 = ((TInfo*)aInfo)->iSurfaceManager.CloseSurface(((TInfo*)aInfo)->iSurfaceIdNew);
   1.365 +	if (err1!=KErrNone || err2!=KErrNone)
   1.366 +	   	RDebug::Print(_L("Error closing surfaces err1= %d, err2= %d\n"),err1,err2);	
   1.367 +	}
   1.368 +
   1.369 +void CTSurfaceManagerMultiThread::TestAccessSurfaceWithoutOpeningL()
   1.370 +	{
   1.371 +	User::LeaveIfError(iSurfaceManager.Open());
   1.372 +    
   1.373 +	// Setup attributes
   1.374 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.375 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.376 +	attributes.iSize = TSize(480,16);
   1.377 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.378 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
   1.379 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
   1.380 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
   1.381 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.382 +
   1.383 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
   1.384 +	attributes.iHintCount = 2;
   1.385 +	attributes.iSurfaceHints = hints;
   1.386 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.387 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.388 +	
   1.389 +	attributes.iContiguous = ETrue;
   1.390 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.391 +	attributes.iMappable = ETrue;
   1.392 +	
   1.393 +	// Test create surface doesn't return an error
   1.394 +	TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.395 +    // Logging info   
   1.396 +    INFO_PRINTF1(_L("Test accessing surface in another thread without opening it\r\n"));
   1.397 +    // Create a semaphore
   1.398 +	RSemaphore sem;
   1.399 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.400 +	CleanupClosePushL(sem);	
   1.401 +	
   1.402 +	// Create a second thread in the current process and opens the handle
   1.403 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.404 +	iInfo.iSurfaceId = iSurfaceId;
   1.405 +	iInfo.iSurfaceIdNew = TSurfaceId::CreateNullId();
   1.406 +	iInfo.iThreadTestCase = EMapSurfaceInfo;		
   1.407 +	// Create a TCleanupItem object
   1.408 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.409 +		
   1.410 +    RThread thread1;
   1.411 +    _LIT(KNameThreadSecond1, "Test_SurfaceManager_ThreadSecond1");
   1.412 +	User::LeaveIfError(thread1.Create(KNameThreadSecond1,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.413 +   	CleanupStack::Pop();
   1.414 +    // Launch second thread
   1.415 +	TRequestStatus statusThreadSecond;
   1.416 +	thread1.Logon(statusThreadSecond);
   1.417 +	thread1.SetPriority(EPriorityLess);
   1.418 +	thread1.Resume();	
   1.419 +	testResult = EAllZero;
   1.420 +	// Passes control to the second process
   1.421 +	sem.Wait();
   1.422 +	thread1.Suspend();
   1.423 +
   1.424 +	// Test results in second thread
   1.425 +	TEST (testResult = (EMapSurfaceTestPassed | ESurfaceInfoTestPassed));
   1.426 +
   1.427 +	// Pass control off to the second process again
   1.428 +	thread1.Resume();
   1.429 +
   1.430 +	// Wait for a second for the second thread to terminate
   1.431 +	User::WaitForRequest(statusThreadSecond);
   1.432 +
   1.433 +	//Close the handles
   1.434 +    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
   1.435 +    thread1.Close();
   1.436 +    iSurfaceManager.Close();
   1.437 +	}
   1.438 +
   1.439 +void CTSurfaceManagerMultiThread::TestAccessSurfaceInExistingSharedChunkL()
   1.440 +    {
   1.441 +    // Logging info   
   1.442 +    INFO_PRINTF1(_L("Test accessing a surface created in the existing shared chunk in another thread without opening it\r\n"));
   1.443 +
   1.444 +    User::LeaveIfError(iSurfaceManager.Open());
   1.445 +    
   1.446 +    // Setup attributes 
   1.447 +    
   1.448 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.449 +    RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.450 +
   1.451 +    attributes.iSize = TSize(100,100);
   1.452 +    attributes.iBuffers = 1;                // number of buffers in the surface
   1.453 +    attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;     // 2bpp
   1.454 +    attributes.iStride = 400;               // Number of bytes between start of one line and start of next
   1.455 +    attributes.iOffsetToFirstBuffer = 0;    // way of reserving space before the surface pixel data
   1.456 +    attributes.iAlignment = 2;          // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.457 +
   1.458 +    RSurfaceManager::THintPair hints[2];    // two hint pairs specified
   1.459 +    attributes.iHintCount = 2;
   1.460 +    attributes.iSurfaceHints = hints;
   1.461 +    hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.462 +    hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.463 +    
   1.464 +    attributes.iContiguous = ETrue;
   1.465 +    attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.466 +    attributes.iOffsetBetweenBuffers = 0;
   1.467 +    attributes.iMappable = ETrue;
   1.468 +
   1.469 +    // Test create surface doesn't return an error
   1.470 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.471 +    
   1.472 +    //Map the surface in the current processs
   1.473 +    RChunk handle;
   1.474 +    TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId,handle));
   1.475 +    
   1.476 +    // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
   1.477 +    RSurfaceManager::TSurfaceCreationAttributesBuf buff;
   1.478 +    RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
   1.479 +
   1.480 +    attributesNew.iSize = TSize(480,16);
   1.481 +    attributesNew.iBuffers = 2;             // number of buffers in the surface
   1.482 +    attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;        // 2bpp
   1.483 +    attributesNew.iStride = 1013;               // Number of bytes between start of one line and start of next
   1.484 +    attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
   1.485 +    
   1.486 +    attributesNew.iHintCount = 1;
   1.487 +    attributesNew.iSurfaceHints = hints;
   1.488 +    hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
   1.489 +    
   1.490 +    attributesNew.iAlignment = 2;
   1.491 +    attributesNew.iOffsetBetweenBuffers = 0;
   1.492 +    attributes.iMappable = ETrue;
   1.493 +    
   1.494 +    // Test create surface doesn't return an error
   1.495 +    // For the time being KErrArgument will be returned as the core codes are
   1.496 +    // not ready to check the passed in shared chunk handle.
   1.497 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buff, iSurfaceIdNew, handle));
   1.498 +
   1.499 +
   1.500 +    // Create a semaphore
   1.501 +    RSemaphore sem;
   1.502 +    TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.503 +    CleanupClosePushL(sem); 
   1.504 +    
   1.505 +    // Create a second thread in the current process and opens the handle
   1.506 +    iInfo.iSurfaceManager = iSurfaceManager;
   1.507 +    iInfo.iSurfaceId = iSurfaceIdNew;
   1.508 +    iInfo.iSurfaceIdNew = iSurfaceId;
   1.509 +    iInfo.iThreadTestCase = EMapSurfaceInfo;    
   1.510 +    // Create a TCleanupItem object
   1.511 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.512 +    
   1.513 +    RThread thread2;
   1.514 +    _LIT(KNameThreadSecond2, "Test_SurfaceManager_ThreadSecond2");
   1.515 +    User::LeaveIfError(thread2.Create(KNameThreadSecond2,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.516 + 
   1.517 +    CleanupStack::Pop();
   1.518 +    // Launch second thread
   1.519 +    TRequestStatus statusThreadSecond;
   1.520 +    thread2.Logon(statusThreadSecond);
   1.521 +    thread2.SetPriority(EPriorityLess);
   1.522 +    thread2.Resume();   
   1.523 +    testResult = EAllZero;
   1.524 +    // Passes control to the second process
   1.525 +    sem.Wait();
   1.526 +    thread2.Suspend();
   1.527 +
   1.528 +    // Test results in second thread
   1.529 +    TEST (testResult = (EMapSurfaceTestPassed | ESurfaceInfoTestPassed));
   1.530 +
   1.531 +    // Pass control off to the second process again
   1.532 +    thread2.Resume();
   1.533 +
   1.534 +    // Wait for a second for the second thread to terminate
   1.535 +    User::WaitForRequest(statusThreadSecond);
   1.536 +    
   1.537 +    //Close the handles
   1.538 +    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
   1.539 +    handle.Close();
   1.540 +    thread2.Close();
   1.541 +    iSurfaceManager.Close();
   1.542 +    
   1.543 +    }
   1.544 +
   1.545 +void CTSurfaceManagerMultiThread::TestCloseSurfaceWithoutOpeningL()
   1.546 +	{
   1.547 +	User::LeaveIfError(iSurfaceManager.Open());
   1.548 +    
   1.549 +	// Setup attributes
   1.550 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.551 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.552 +	
   1.553 +	attributes.iSize = TSize(480,16);
   1.554 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.555 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
   1.556 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
   1.557 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
   1.558 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.559 +
   1.560 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
   1.561 +	attributes.iHintCount = 2;
   1.562 +	attributes.iSurfaceHints = hints;
   1.563 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.564 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.565 +	
   1.566 +	attributes.iContiguous = ETrue;
   1.567 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.568 +	attributes.iMappable = ETrue;
   1.569 +	
   1.570 +	// Test create surface doesn't return an error
   1.571 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.572 +   
   1.573 +    INFO_PRINTF1(_L("Test closing surface in another thread without opening it\r\n"));
   1.574 +	
   1.575 +	// Create a semaphore
   1.576 +	RSemaphore sem;
   1.577 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.578 +   	CleanupClosePushL(sem);	
   1.579 +
   1.580 +  	// Creates a second thread in the current process and opens the handle
   1.581 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.582 +	iInfo.iSurfaceId = iSurfaceId;
   1.583 +	iInfo.iThreadTestCase = ECloseSurfaces;	
   1.584 +   	// Create a TCleanupItem object
   1.585 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.586 +
   1.587 +    RThread thread3;
   1.588 +    _LIT(KNameThreadSecond3, "Test_SurfaceManager_ThreadSecond3");
   1.589 +	User::LeaveIfError(thread3.Create(KNameThreadSecond3,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.590 +    CleanupStack::Pop();
   1.591 +    // Launch second thread to close the surface
   1.592 +	TRequestStatus statusThreadSecond;
   1.593 +	thread3.Logon(statusThreadSecond);
   1.594 +	thread3.SetPriority(EPriorityLess);
   1.595 +	thread3.Resume();	
   1.596 +	testResult = EAllZero;
   1.597 +	// Passes control to the second thread
   1.598 +	sem.Wait();
   1.599 +	thread3.Suspend();
   1.600 +
   1.601 +	// Test the results in the second thread
   1.602 +	TEST(testResult == ECloseSurfaceTestPassed);
   1.603 +	
   1.604 +	thread3.Resume();
   1.605 +	// Wait for a second for the second process to terminate
   1.606 +	User::WaitForRequest(statusThreadSecond);
   1.607 +	
   1.608 +	//Close the handle
   1.609 +    CleanupStack::PopAndDestroy(1, &sem);
   1.610 +    thread3.Close();
   1.611 +	iSurfaceManager.Close();
   1.612 +	}
   1.613 +
   1.614 +void CTSurfaceManagerMultiThread::TestAccessSurfaceClosedThreadL()
   1.615 +	{
   1.616 +	User::LeaveIfError(iSurfaceManager.Open());
   1.617 +    // Logging info
   1.618 +    INFO_PRINTF1(_L("Test accessing an surface which is created in another thread but closed in current thread\r\n"));
   1.619 +    
   1.620 +    // Create a semaphore
   1.621 +	RSemaphore sem;
   1.622 +	RSemaphore semMain;
   1.623 +	
   1.624 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.625 +    CleanupClosePushL(sem);	
   1.626 +    TEST(KErrNone == semMain.CreateGlobal(KMainThreadSemaphore, 0));
   1.627 +    CleanupClosePushL(semMain);	
   1.628 +
   1.629 +	// Creates a second thread in the current process and opens the handle
   1.630 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.631 +	iInfo.iSurfaceId = iSurfaceId;
   1.632 +	iInfo.iThreadTestCase = ECreateSurfaceMapInfo;	
   1.633 +	// Create a TCleanupItem object
   1.634 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.635 +
   1.636 +    RThread thread4;
   1.637 +    _LIT(KNameThreadSecond4, "Test_SurfaceManager_ThreadSecond4");
   1.638 +	User::LeaveIfError(thread4.Create(KNameThreadSecond4,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.639 +    CleanupStack::Pop();
   1.640 +    // Launch the second trhead
   1.641 +	TRequestStatus statusThreadSecond;
   1.642 +	thread4.Logon(statusThreadSecond);
   1.643 +	thread4.SetPriority(EPriorityLess);
   1.644 +	thread4.Resume();	
   1.645 +    
   1.646 +    testResult = EAllZero;
   1.647 +  	// Passes control to the second process
   1.648 +    sem.Wait(); 
   1.649 +	// Test creating surface in second thread
   1.650 +   	TEST(testResult == ECreateSurfaceTestPassed);
   1.651 +   	// Reset testResult
   1.652 +    testResult = EAllZero;
   1.653 +    // Test closing surface
   1.654 +    iSurfaceId = globalSurfaceId;
   1.655 +	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
   1.656 +	semMain.Signal();
   1.657 +    // Wait the second thread to terminate
   1.658 +    User::WaitForRequest(statusThreadSecond);
   1.659 +
   1.660 +	// Test mapsurface and surfaceinfo executed in the second thread
   1.661 +	TEST(testResult == (EMapSurfaceTestFailed|ESurfaceInfoTestFailed));
   1.662 +	// Close all the handles
   1.663 +    CleanupStack::PopAndDestroy(2, &sem);
   1.664 +    thread4.Close();
   1.665 +	iSurfaceManager.Close();
   1.666 +
   1.667 +	}
   1.668 +
   1.669 +void CTSurfaceManagerMultiThread::TestCloseSurfaceExistingSharedChunkL()
   1.670 +    {
   1.671 +    // Logging info   
   1.672 +    INFO_PRINTF1(_L("Test closing surface created in the existing chunk in another thread without opening it\r\n"));
   1.673 + 
   1.674 +    User::LeaveIfError(iSurfaceManager.Open());
   1.675 +    // Setup attributes 
   1.676 +    
   1.677 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.678 +    RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.679 +
   1.680 +    attributes.iSize = TSize(100,100);
   1.681 +    attributes.iBuffers = 1;                // number of buffers in the surface
   1.682 +    attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar;     // 2bpp
   1.683 +    attributes.iStride = 400;               // Number of bytes between start of one line and start of next
   1.684 +    attributes.iOffsetToFirstBuffer = 0;    // way of reserving space before the surface pixel data
   1.685 +    attributes.iAlignment = 2;          // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.686 +
   1.687 +    RSurfaceManager::THintPair hints[2];    // two hint pairs specified
   1.688 +    attributes.iHintCount = 2;
   1.689 +    attributes.iSurfaceHints = hints;
   1.690 +    hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.691 +    hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.692 +
   1.693 +    attributes.iContiguous = ETrue;
   1.694 +    attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.695 +    attributes.iOffsetBetweenBuffers = 0;
   1.696 +    attributes.iMappable = ETrue;
   1.697 +    
   1.698 +    // Test create surface doesn't return an error
   1.699 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.700 +    
   1.701 +    //Map the surface in the current processs
   1.702 +    RChunk handle;
   1.703 +    TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId,handle));
   1.704 +    
   1.705 +    // Cache, Contiguous and Alignment attributes are ignored for the already existing chunks
   1.706 +    RSurfaceManager::TSurfaceCreationAttributesBuf buff;
   1.707 +    RSurfaceManager::TSurfaceCreationAttributes& attributesNew = buff();
   1.708 +
   1.709 +    attributesNew.iSize = TSize(480,16);
   1.710 +    attributesNew.iBuffers = 2;             // number of buffers in the surface
   1.711 +    attributesNew.iPixelFormat = EUidPixelFormatYUV_422Reversed;        // 2bpp
   1.712 +    attributesNew.iStride = 1013;               // Number of bytes between start of one line and start of next
   1.713 +    attributesNew.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
   1.714 +    
   1.715 +    attributesNew.iHintCount = 1;
   1.716 +    attributesNew.iSurfaceHints = hints;
   1.717 +    hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
   1.718 +
   1.719 +    attributesNew.iAlignment = 2;
   1.720 +    attributesNew.iOffsetBetweenBuffers = 0;
   1.721 +    attributesNew.iMappable = ETrue;
   1.722 +
   1.723 +    // Test create surface doesn't return an error
   1.724 +    // For the time being KErrArgument will be returned as the core codes are
   1.725 +    // not ready to check the passed in shared chunk handle.
   1.726 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buff, iSurfaceIdNew, handle));
   1.727 +
   1.728 +    // Create a semaphore
   1.729 +    RSemaphore sem;
   1.730 +    TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.731 +    CleanupClosePushL(sem); 
   1.732 +    
   1.733 +    // Create a second thread in the current process and opens the handle
   1.734 +    iInfo.iSurfaceManager = iSurfaceManager;
   1.735 +    iInfo.iSurfaceId = iSurfaceId;
   1.736 +    iInfo.iSurfaceIdNew = iSurfaceIdNew;
   1.737 +    iInfo.iThreadTestCase = ECloseBothSurfaces; 
   1.738 +    // Create a TCleanupItem object
   1.739 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.740 +        
   1.741 +    RThread thread5;
   1.742 +    _LIT(KNameThreadSecond5, "Test_SurfaceManager_ThreadSecond5");
   1.743 +    User::LeaveIfError(thread5.Create(KNameThreadSecond5,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.744 +    CleanupStack::Pop();
   1.745 +    // Launch second thread
   1.746 +    TRequestStatus statusThreadSecond;
   1.747 +    thread5.Logon(statusThreadSecond);
   1.748 +    thread5.SetPriority(EPriorityLess);
   1.749 +    thread5.Resume();   
   1.750 +    testResult = EAllZero;
   1.751 +    // Passes control to the second process
   1.752 +    sem.Wait();
   1.753 +    thread5.Suspend();
   1.754 +
   1.755 +    // Test results in second thread
   1.756 +    TEST (testResult = (ECloseSurfaceTestPassed | ESurfaceInfoTestPassed | ESurfaceInfoTestPassed2));
   1.757 +    RSurfaceManager::TInfoBuf infoBuf;
   1.758 +    TEST (KErrArgument == iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
   1.759 +    TEST (KErrArgument == iSurfaceManager.SurfaceInfo(iSurfaceIdNew, infoBuf));
   1.760 +
   1.761 +    // Pass control off to the second process again
   1.762 +    thread5.Resume();
   1.763 +
   1.764 +    // Wait for a second for the second thread to terminate
   1.765 +    User::WaitForRequest(statusThreadSecond);
   1.766 +
   1.767 +    CleanupStack::PopAndDestroy(1, &sem);  //invoke surface manager to close the surface also close the handle to RSemaphore
   1.768 +    handle.Close();
   1.769 +    thread5.Close();
   1.770 +    iSurfaceManager.Close();
   1.771 +    }
   1.772 +
   1.773 +void CTSurfaceManagerMultiThread::TestCloseSurfaceClosedThreadL()
   1.774 +	{
   1.775 +	User::LeaveIfError(iSurfaceManager.Open());
   1.776 +    
   1.777 +	// Setup attributes
   1.778 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.779 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.780 +	
   1.781 +	attributes.iSize = TSize(480,16);
   1.782 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.783 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
   1.784 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
   1.785 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
   1.786 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.787 +
   1.788 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
   1.789 +	attributes.iHintCount = 2;
   1.790 +	attributes.iSurfaceHints = hints;
   1.791 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.792 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.793 +	
   1.794 +	attributes.iContiguous = ETrue;
   1.795 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.796 +	attributes.iOffsetBetweenBuffers = 0;
   1.797 +	attributes.iMappable = ETrue;
   1.798 +    // Logging info
   1.799 +    INFO_PRINTF1(_L("Test closing an surface which is already closed in other thread return KErrArgument\r\n"));
   1.800 +    // Create a semaphore
   1.801 +	RSemaphore sem;
   1.802 +	RSemaphore semMain;
   1.803 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.804 +    CleanupClosePushL(sem);	
   1.805 +    TEST(KErrNone == semMain.CreateGlobal(KMainThreadSemaphore, 0));
   1.806 +    CleanupClosePushL(semMain);	
   1.807 +
   1.808 + 	// Creates a second thread in the current process and opens the handle
   1.809 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.810 +	iInfo.iSurfaceId = iSurfaceId;
   1.811 +	iInfo.iThreadTestCase = ECreateSurfaceClose;	
   1.812 +	
   1.813 +	// Create a TCleanupItem object
   1.814 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.815 +
   1.816 +    RThread thread6;
   1.817 +    _LIT(KNameThreadSecond6, "Test_SurfaceManager_ThreadSecond6");
   1.818 +	User::LeaveIfError(thread6.Create(KNameThreadSecond6,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.819 +    CleanupStack::Pop();
   1.820 +    // Launch second thread
   1.821 +	TRequestStatus statusThreadSecond;
   1.822 +	thread6.Logon(statusThreadSecond);
   1.823 +	thread6.SetPriority(EPriorityLess);
   1.824 +	thread6.Resume();	
   1.825 +	testResult = EAllZero;
   1.826 +  	// Passes control to the second thread
   1.827 +    sem.Wait(); 
   1.828 +    // Test creating surface in second thread
   1.829 +   	TEST(testResult == ECreateSurfaceTestPassed);
   1.830 +   	testResult = EAllZero;
   1.831 +    // Test closing surface
   1.832 +    iSurfaceId = globalSurfaceId;
   1.833 +	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
   1.834 +    	
   1.835 +	semMain.Signal();
   1.836 +	// Wait for a second for the second process to terminate
   1.837 +    User::WaitForRequest(statusThreadSecond);
   1.838 +
   1.839 +    TEST(testResult == ECloseSurfaceTestFailed);
   1.840 +    // Close all the handles
   1.841 +    CleanupStack::PopAndDestroy(2, &sem);
   1.842 +    thread6.Close();
   1.843 +	iSurfaceManager.Close();
   1.844 +	}
   1.845 +
   1.846 +void CTSurfaceManagerMultiThread::TestAccessSurfaceOpenedClosedThreadL()
   1.847 +	{
   1.848 +	User::LeaveIfError(iSurfaceManager.Open());
   1.849 +    
   1.850 +	// Setup attributes
   1.851 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.852 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.853 +	
   1.854 +	attributes.iSize = TSize(480,16);
   1.855 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.856 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
   1.857 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
   1.858 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
   1.859 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.860 +
   1.861 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
   1.862 +	attributes.iHintCount = 2;
   1.863 +	attributes.iSurfaceHints = hints;
   1.864 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.865 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.866 +	
   1.867 +	attributes.iContiguous = ETrue;
   1.868 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.869 +	attributes.iOffsetBetweenBuffers = 0;
   1.870 +	attributes.iMappable = ETrue;
   1.871 +	
   1.872 +	// Test create surface doesn't return an error
   1.873 +	TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.874 +    // Logging info
   1.875 +    INFO_PRINTF1(_L("Test accessing an surface which is already opened and closed in another thread, given that the process still owns the surface\r\n"));
   1.876 + 	// Create a semaphore
   1.877 +	RSemaphore sem;
   1.878 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.879 +    CleanupClosePushL(sem);	
   1.880 +
   1.881 +	// Creates a second thread in the current process and opens the handle
   1.882 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.883 +	iInfo.iSurfaceId = iSurfaceId;
   1.884 +	iInfo.iThreadTestCase = EOpenCloseSurface;	
   1.885 + 	// Create a TCleanupItem object
   1.886 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.887 +	
   1.888 +    RThread thread7;
   1.889 +    _LIT(KNameThreadSecond7, "Test_SurfaceManager_ThreadSecond7");
   1.890 +	User::LeaveIfError(thread7.Create(KNameThreadSecond7,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.891 +   	CleanupStack::Pop();
   1.892 +   	
   1.893 +    // Launch the second thread
   1.894 +	TRequestStatus statusThreadSecond;
   1.895 +	thread7.Logon(statusThreadSecond);
   1.896 +	thread7.SetPriority(EPriorityLess);
   1.897 +	thread7.Resume();
   1.898 +	testResult = EAllZero;
   1.899 +	sem.Wait();	  
   1.900 +	
   1.901 +	thread7.Suspend();
   1.902 +	// Test open and close surface in the second thread
   1.903 +	TEST(testResult == (EOpenSurfaceTestPassed|ECloseSurfaceTestPassed));
   1.904 +	
   1.905 +	RChunk handle;
   1.906 +	// To prove killing threads doesnt affect the ref count...
   1.907 +	TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId, handle));
   1.908 +	handle.Close();
   1.909 +	
   1.910 +	RSurfaceManager::TInfoBuf infoBuf;
   1.911 +	TEST(KErrNone ==iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
   1.912 +	
   1.913 +	thread7.Resume();
   1.914 +	
   1.915 +	// Wait for a second for the second process to terminate
   1.916 +    User::WaitForRequest(statusThreadSecond);
   1.917 +
   1.918 +	// Close all the handles
   1.919 +    CleanupStack::PopAndDestroy(1, &sem);
   1.920 +    thread7.Close();
   1.921 +	iSurfaceManager.Close();
   1.922 +	}	
   1.923 +
   1.924 +void CTSurfaceManagerMultiThread::TestCloseSurfaceOpenedClosedThreadL()
   1.925 +	{
   1.926 +	User::LeaveIfError(iSurfaceManager.Open());
   1.927 +    
   1.928 +	// Setup attributes
   1.929 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.930 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.931 +	
   1.932 +	attributes.iSize = TSize(480,16);
   1.933 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.934 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
   1.935 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
   1.936 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
   1.937 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
   1.938 +
   1.939 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
   1.940 +	attributes.iHintCount = 2;
   1.941 +	attributes.iSurfaceHints = hints;
   1.942 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
   1.943 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
   1.944 +	
   1.945 +	attributes.iContiguous = ETrue;
   1.946 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
   1.947 +	attributes.iOffsetBetweenBuffers = 0;
   1.948 +	attributes.iMappable = ETrue;
   1.949 +
   1.950 +	// Test create surface doesn't return an error
   1.951 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
   1.952 +    
   1.953 +    INFO_PRINTF1(_L("Test closing an surface which is already opened and closed in another thread, given that the process still owns the surface\r\n"));
   1.954 +	RSemaphore sem;
   1.955 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
   1.956 +   	CleanupClosePushL(sem);
   1.957 +
   1.958 +	// Creates a second thread in the current process and opens the handle
   1.959 +	iInfo.iSurfaceManager = iSurfaceManager;
   1.960 +	iInfo.iSurfaceId = iSurfaceId;
   1.961 +	iInfo.iThreadTestCase = EOpenCloseSurface;	
   1.962 + 
   1.963 +	// Create a TCleanupItem object
   1.964 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
   1.965 +
   1.966 +    RThread thread8;
   1.967 +    _LIT(KNameThreadSecond8, "Test_SurfaceManager_ThreadSecond8");
   1.968 +	User::LeaveIfError(thread8.Create(KNameThreadSecond8,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
   1.969 +    CleanupStack::Pop();
   1.970 +	TRequestStatus statusThreadSecond;
   1.971 +	thread8.Logon(statusThreadSecond);
   1.972 +	thread8.SetPriority(EPriorityLess);
   1.973 +	thread8.Resume();
   1.974 +	testResult = EAllZero;
   1.975 +	sem.Wait();	
   1.976 +	thread8.Suspend();
   1.977 +	// Test open and close surface in the second thread
   1.978 +	TEST(testResult == (EOpenSurfaceTestPassed|ECloseSurfaceTestPassed));
   1.979 +
   1.980 +	thread8.Resume();
   1.981 +	// Wait for a second for the second process to terminate
   1.982 +    User::WaitForRequest(statusThreadSecond);
   1.983 +
   1.984 +	// Close all the handles 
   1.985 +    CleanupStack::PopAndDestroy(1, &sem);
   1.986 +    thread8.Close();
   1.987 +	iSurfaceManager.Close();
   1.988 +	}
   1.989 +
   1.990 +void CTSurfaceManagerMultiThread::TestAccessSurfaceOpenedKilledThreadL()
   1.991 +	{
   1.992 +	User::LeaveIfError(iSurfaceManager.Open());
   1.993 +    
   1.994 +	// Setup attributes
   1.995 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
   1.996 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
   1.997 +	attributes.iSize = TSize(480,16);
   1.998 +	attributes.iBuffers = 2;				// number of buffers in the surface
   1.999 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1000 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1001 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1002 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1003 +
  1.1004 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1005 +	attributes.iHintCount = 2;
  1.1006 +	attributes.iSurfaceHints = hints;
  1.1007 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1008 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1009 +	
  1.1010 +	attributes.iContiguous = ETrue;
  1.1011 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1012 +	attributes.iOffsetBetweenBuffers = 0;
  1.1013 +	attributes.iMappable = ETrue;
  1.1014 +
  1.1015 +	// Test create surface doesn't return an error
  1.1016 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
  1.1017 +    
  1.1018 +    INFO_PRINTF1(_L("Test accessing surface in another thread when the opening thread is killed\r\n"));
  1.1019 +    // Create a semaphore
  1.1020 +	RSemaphore sem;
  1.1021 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1022 +	CleanupClosePushL(sem);
  1.1023 +
  1.1024 +	// Creates a second thread in the current process and opens the handle
  1.1025 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1026 +	iInfo.iSurfaceId = iSurfaceId;
  1.1027 +	iInfo.iThreadTestCase = EOpenKillSurface;	
  1.1028 +	// Create a TCleanupItem object
  1.1029 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1030 +
  1.1031 +    RThread thread9;
  1.1032 +    _LIT(KNameThreadSecond9, "Test_SurfaceManager_ThreadSecond9");
  1.1033 +	User::LeaveIfError(thread9.Create(KNameThreadSecond9,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1034 +	CleanupStack::Pop();
  1.1035 +	// Launch the second thraed
  1.1036 +	TRequestStatus statusThreadSecond;
  1.1037 +	thread9.Logon(statusThreadSecond);
  1.1038 +	thread9.SetPriority(EPriorityLess);
  1.1039 +	thread9.Resume();
  1.1040 +	// Waiting the second thread to terminate
  1.1041 +    User::WaitForRequest(statusThreadSecond);
  1.1042 +
  1.1043 +   	RChunk handle;
  1.1044 +	// Test the surface is still accessible
  1.1045 +	TEST(KErrNone == iSurfaceManager.MapSurface(iSurfaceId, handle));
  1.1046 +	handle.Close();
  1.1047 +	
  1.1048 +	RSurfaceManager::TInfoBuf infoBuf;
  1.1049 +	TEST(KErrNone ==iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf));
  1.1050 +	
  1.1051 +    // Close all the handles
  1.1052 +    CleanupStack::PopAndDestroy(1, &sem);
  1.1053 +    thread9.Close();
  1.1054 +	iSurfaceManager.Close();
  1.1055 +	}
  1.1056 +
  1.1057 +void CTSurfaceManagerMultiThread::TestCloseSurfaceOpenedKilledThreadL()
  1.1058 +	{
  1.1059 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1060 +    
  1.1061 +	// Setup attributes
  1.1062 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1063 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1064 +	attributes.iSize = TSize(480,16);
  1.1065 +	attributes.iBuffers = 2;				// number of buffers in the surface
  1.1066 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1067 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1068 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1069 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1070 +
  1.1071 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1072 +	attributes.iHintCount = 2;
  1.1073 +	attributes.iSurfaceHints = hints;
  1.1074 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1075 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1076 +	
  1.1077 +	attributes.iContiguous = ETrue;
  1.1078 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1079 +	attributes.iOffsetBetweenBuffers = 0;
  1.1080 +	attributes.iMappable = ETrue;
  1.1081 +	
  1.1082 +	// Create a semaphore
  1.1083 +	RSemaphore sem;
  1.1084 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1085 +	CleanupClosePushL(sem);
  1.1086 +	
  1.1087 +	// Test create surface doesn't return an error
  1.1088 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
  1.1089 +    // Logging info
  1.1090 +    INFO_PRINTF1(_L("Test closing surface in another thread when the opening thread is killed\r\n"));
  1.1091 +  	// Creates a second thread in the current process and opens the handle
  1.1092 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1093 +	iInfo.iSurfaceId = iSurfaceId;
  1.1094 +	iInfo.iThreadTestCase = EOpenKillSurface;	
  1.1095 +
  1.1096 +	// Create a TCleanupItem object
  1.1097 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1098 +
  1.1099 +    RThread thread10;
  1.1100 +    _LIT(KNameThreadSecond10, "Test_SurfaceManager_ThreadSecond10");
  1.1101 +	User::LeaveIfError(thread10.Create(KNameThreadSecond10,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1102 +   	CleanupStack::Pop();
  1.1103 +	// Launch the second thread
  1.1104 +	TRequestStatus statusThreadSecond;
  1.1105 +	thread10.Logon(statusThreadSecond);
  1.1106 +	thread10.SetPriority(EPriorityLess);
  1.1107 +	thread10.Resume();
  1.1108 +	// Waiting the second thread to terminate
  1.1109 +    User::WaitForRequest(statusThreadSecond);
  1.1110 +
  1.1111 +    // Test closing surface
  1.1112 +	TEST(KErrNone ==iSurfaceManager.CloseSurface(iSurfaceId));
  1.1113 +	
  1.1114 +	// Close all the handles
  1.1115 +	CleanupStack::PopAndDestroy(1, &sem);
  1.1116 +	thread10.Close();
  1.1117 +	iSurfaceManager.Close();
  1.1118 +	}
  1.1119 +
  1.1120 +void CTSurfaceManagerMultiThread::TestAccessSurfaceCreateKilledThreadL()
  1.1121 +	{
  1.1122 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1123 +    
  1.1124 +	// Setup attributes
  1.1125 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1126 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1127 +	attributes.iSize = TSize(480,16);
  1.1128 +	attributes.iBuffers = 2;				// number of buffers in the surface
  1.1129 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1130 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1131 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1132 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1133 +
  1.1134 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1135 +	attributes.iHintCount = 2;
  1.1136 +	attributes.iSurfaceHints = hints;
  1.1137 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1138 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1139 +	
  1.1140 +	attributes.iContiguous = ETrue;
  1.1141 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1142 +	attributes.iOffsetBetweenBuffers = 0;
  1.1143 +	attributes.iMappable = ETrue;
  1.1144 +	
  1.1145 +    // Logging info
  1.1146 +    INFO_PRINTF1(_L("Test accessing surface in another thread when the creating thread is killed\r\n"));
  1.1147 +    // Create a semaphore
  1.1148 +	RSemaphore sem;
  1.1149 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1150 +	CleanupClosePushL(sem);
  1.1151 +
  1.1152 +  	// Creates a second thread in the current process and opens the handle
  1.1153 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1154 +	iInfo.iSurfaceId = iSurfaceId;
  1.1155 +	iInfo.iThreadTestCase = ECreateKillSurface;	
  1.1156 +
  1.1157 +	// Create a TCleanupItem object
  1.1158 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1159 +
  1.1160 +    RThread thread11;
  1.1161 +    _LIT(KNameThreadSecond11, "Test_SurfaceManager_ThreadSecond11");
  1.1162 +	User::LeaveIfError(thread11.Create(KNameThreadSecond11,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1163 +   	CleanupStack::Pop();
  1.1164 +    // Launch the second thread
  1.1165 +	TRequestStatus statusThreadSecond;
  1.1166 +	thread11.Logon(statusThreadSecond);
  1.1167 +	thread11.SetPriority(EPriorityLess);
  1.1168 +	thread11.Resume();
  1.1169 +	testResult = EAllZero;
  1.1170 +	sem.Wait();	
  1.1171 +	// Test creating surface in the second thread
  1.1172 +	TEST(testResult = ECreateSurfaceTestPassed);
  1.1173 +    // Test closing surface
  1.1174 +   	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
  1.1175 +    // Wait the second thread to terminate
  1.1176 +    User::WaitForRequest(statusThreadSecond);
  1.1177 +
  1.1178 +    // Test the surface is not accessible any more
  1.1179 +   	RChunk handle;
  1.1180 +	TEST(KErrArgument == iSurfaceManager.MapSurface(globalSurfaceId, handle));
  1.1181 +	handle.Close();
  1.1182 +	RSurfaceManager::TInfoBuf infoBuf;
  1.1183 +	TEST(KErrArgument ==iSurfaceManager.SurfaceInfo(globalSurfaceId, infoBuf));
  1.1184 + 	// Close all the handles
  1.1185 +	CleanupStack::PopAndDestroy(1, &sem);
  1.1186 +	thread11.Close();
  1.1187 +	iSurfaceManager.Close();
  1.1188 +    }
  1.1189 +	
  1.1190 +/**
  1.1191 +	210 Test closing surface in another thread when the creating thread is killed
  1.1192 +	Thread 2: Create Surface 
  1.1193 +	Thread 1: Close Surface
  1.1194 +	Thread 2: Kill the thread
  1.1195 +	Thread 1: Close Surface - KErrArgument
  1.1196 +*/
  1.1197 +void CTSurfaceManagerMultiThread::TestCloseSurfaceCreateKilledThreadL()
  1.1198 +	{
  1.1199 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1200 +    
  1.1201 +	// Setup attributes
  1.1202 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1203 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1204 +	attributes.iSize = TSize(480,16);
  1.1205 +	attributes.iBuffers = 2;				// number of buffers in the surface
  1.1206 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1207 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1208 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1209 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1210 +
  1.1211 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1212 +	attributes.iHintCount = 2;
  1.1213 +	attributes.iSurfaceHints = hints;
  1.1214 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1215 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1216 +		
  1.1217 +	attributes.iContiguous = ETrue;
  1.1218 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1219 +	attributes.iOffsetBetweenBuffers = 0;
  1.1220 +	attributes.iMappable = ETrue;
  1.1221 +
  1.1222 +    // Logging info
  1.1223 +    INFO_PRINTF1(_L("Test closing surface in another thread when the creating thread is killed\r\n"));
  1.1224 +    // Create a semaphore
  1.1225 +	RSemaphore sem;
  1.1226 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1227 +	CleanupClosePushL(sem);
  1.1228 +
  1.1229 +  	// Creates a second thread in the current process and opens the handle
  1.1230 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1231 +	iInfo.iSurfaceId = iSurfaceId;
  1.1232 +	iInfo.iThreadTestCase = ECreateKillSurface;	
  1.1233 +
  1.1234 +	// Create a TCleanupItem object
  1.1235 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1236 +
  1.1237 +    RThread thread12;
  1.1238 +    _LIT(KNameThreadSecond12, "Test_SurfaceManager_ThreadSecond12");
  1.1239 +	User::LeaveIfError(thread12.Create(KNameThreadSecond12,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1240 +   	CleanupStack::Pop();
  1.1241 +    // Launch the second thread
  1.1242 +	TRequestStatus statusThreadSecond;
  1.1243 +	thread12.Logon(statusThreadSecond);
  1.1244 +	thread12.SetPriority(EPriorityLess);
  1.1245 +	thread12.Resume();
  1.1246 +	sem.Wait();	
  1.1247 +	// Test creating surface in the second thread
  1.1248 +	TEST(testResult = ECreateSurfaceTestPassed);
  1.1249 +    // Test closing surface
  1.1250 +   	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
  1.1251 +    // Wait the second thread to terminate
  1.1252 +    User::WaitForRequest(statusThreadSecond);
  1.1253 +     
  1.1254 +	// Test the surface is removed and not closable   	
  1.1255 +	TEST(KErrArgument ==iSurfaceManager.CloseSurface(globalSurfaceId));
  1.1256 +    // Close the handles
  1.1257 +   	CleanupStack::PopAndDestroy(1, &sem);
  1.1258 +   	thread12.Close();
  1.1259 +	iSurfaceManager.Close();
  1.1260 +	}
  1.1261 +	
  1.1262 +void CTSurfaceManagerMultiThread::TestAccessSurfaceThreeThreadsL()
  1.1263 +	{
  1.1264 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1265 +    
  1.1266 +	// Setup attributes
  1.1267 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1268 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1269 +	attributes.iSize = TSize(480,16);
  1.1270 +	attributes.iBuffers = 2;				// number of buffers in the surface
  1.1271 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1272 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1273 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1274 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1275 +
  1.1276 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1277 +	attributes.iHintCount = 2;
  1.1278 +	attributes.iSurfaceHints = hints;
  1.1279 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1280 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1281 +	
  1.1282 +	attributes.iContiguous = ETrue;
  1.1283 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1284 +	attributes.iOffsetBetweenBuffers = 0;
  1.1285 +	attributes.iMappable = ETrue;
  1.1286 +	
  1.1287 +	// Test create surface doesn't return an error
  1.1288 +    TEST(KErrNone == iSurfaceManager.CreateSurface(buf, iSurfaceId));
  1.1289 +    // Logging info
  1.1290 +    INFO_PRINTF1(_L("Test closing on one thread doesn't prevent opening on other Threads, provided one Thread still owns surface\r\n"));
  1.1291 +    // Create a semaphore
  1.1292 +	RSemaphore sem;
  1.1293 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore,0));
  1.1294 +	CleanupClosePushL(sem);
  1.1295 +
  1.1296 +   	// Creates a second thread in the current process and opens the handle
  1.1297 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1298 +	iInfo.iSurfaceId = iSurfaceId;
  1.1299 +	iInfo.iThreadTestCase = EOpenCloseSurfaceMultiThread;	
  1.1300 +	// Create a TCleanupItem object
  1.1301 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1302 +
  1.1303 +    RThread thread13;
  1.1304 +    _LIT(KNameThreadSecond13, "Test_SurfaceManager_ThreadSecond13");
  1.1305 +	User::LeaveIfError(thread13.Create(KNameThreadSecond13,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1306 +   	CleanupStack::Pop();
  1.1307 +    // Launch the second thread
  1.1308 +	TRequestStatus statusThreadSecond;
  1.1309 +	thread13.Logon(statusThreadSecond);
  1.1310 +	thread13.SetPriority(EPriorityLess);
  1.1311 +	thread13.Resume();
  1.1312 +	testResult = EAllZero;
  1.1313 +	sem.Wait();	
  1.1314 +	TEST(testResult == EOpenSurfaceTestPassed);
  1.1315 +	testResult = EAllZero;
  1.1316 +
  1.1317 +	// Create a third thread in the same process and opens the handle
  1.1318 +	iInfo2 = iInfo;
  1.1319 +	iInfo2.iThreadTestCase = EOpenMapSurfaceInfoMultiThread;	
  1.1320 +	// Create a TCleanupItem object
  1.1321 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
  1.1322 +
  1.1323 +    RThread thread13_2;
  1.1324 +    _LIT(KNameThreadSecond13_2, "Test_SurfaceManager_ThreadSecond13_2");
  1.1325 +	User::LeaveIfError(thread13_2.Create(KNameThreadSecond13_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
  1.1326 +	CleanupStack::Pop();
  1.1327 +	// Launch the third thread
  1.1328 +	TRequestStatus statusThreadThird;
  1.1329 +	thread13_2.Logon(statusThreadThird);
  1.1330 +	thread13_2.SetPriority(EPriorityLess);
  1.1331 +	thread13_2.Resume();
  1.1332 +	sem.Wait();
  1.1333 +	TEST(testResult == EOpenSurfaceTestPassed);
  1.1334 +	testResult = EAllZero;
  1.1335 +	thread13.Resume();
  1.1336 +    User::WaitForRequest(statusThreadSecond);
  1.1337 +
  1.1338 +	TEST(testResult == ECloseSurfaceTestPassed);
  1.1339 +	testResult = EAllZero;
  1.1340 +
  1.1341 +	thread13_2.Resume();
  1.1342 +    User::WaitForRequest(statusThreadThird);
  1.1343 +
  1.1344 +	TEST(testResult == (EMapSurfaceTestPassed|ESurfaceInfoTestPassed));
  1.1345 +
  1.1346 +	// Close all the handles
  1.1347 +	CleanupStack::PopAndDestroy(1, &sem);
  1.1348 +
  1.1349 +	thread13.Close();
  1.1350 +	thread13_2.Close();
  1.1351 +	iSurfaceManager.Close();
  1.1352 +	}
  1.1353 +
  1.1354 +void CTSurfaceManagerMultiThread::TestAccessSurfaceDieCloseOtherThreadsL()
  1.1355 +	{
  1.1356 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1357 +    
  1.1358 +    // Logging info
  1.1359 +    INFO_PRINTF1(_L("Test surface can be accessed from third thread when creating thread dies and second thread closes\r\n"));
  1.1360 +    // Create a semaphore
  1.1361 +	RSemaphore sem;
  1.1362 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1363 +	CleanupClosePushL(sem);
  1.1364 +
  1.1365 +	// Create a second thread and opens the handle
  1.1366 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1367 +	iInfo.iSurfaceId = iSurfaceId;
  1.1368 +	iInfo.iThreadTestCase = ECreateKillSurface;	
  1.1369 +
  1.1370 +	// Create a TCleanupItem object
  1.1371 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1372 +
  1.1373 +    RThread thread14;
  1.1374 +    _LIT(KNameThreadSecond14, "Test_SurfaceManager_ThreadSecond14");
  1.1375 +	User::LeaveIfError(thread14.Create(KNameThreadSecond14,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1376 +   	CleanupStack::Pop();
  1.1377 +	// Launch the second thread
  1.1378 +	TRequestStatus statusThreadSecond;
  1.1379 +	thread14.Logon(statusThreadSecond);
  1.1380 +	thread14.SetPriority(EPriorityLess);
  1.1381 +	thread14.Resume();
  1.1382 +	testResult = EAllZero;
  1.1383 +	sem.Wait();	
  1.1384 +	//suspend the 2nd thread
  1.1385 +	thread14.Suspend(); 
  1.1386 +	
  1.1387 +	TEST(testResult == ECreateSurfaceTestPassed);
  1.1388 +	testResult = EAllZero;
  1.1389 +	
  1.1390 +	TEST(KErrNone == iSurfaceManager.OpenSurface(globalSurfaceId));
  1.1391 +
  1.1392 +    // Create a third thread in the current process and opens the handle 
  1.1393 +	iInfo2.iSurfaceManager = iSurfaceManager;
  1.1394 +	iInfo2.iSurfaceId = globalSurfaceId;
  1.1395 +	iInfo2.iSurfaceIdNew = iSurfaceId;
  1.1396 +	iInfo2.iThreadTestCase = EOpenCloseMapSurfaceInfoMultiThread;	
  1.1397 +	// Create a TCleanupItem object
  1.1398 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
  1.1399 +
  1.1400 +    RThread thread14_2;
  1.1401 +    _LIT(KNameThreadSecond14_2, "Test_SurfaceManager_ThreadSecond14_2");
  1.1402 +	User::LeaveIfError(thread14_2.Create(KNameThreadSecond14_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
  1.1403 +   	CleanupStack::Pop();
  1.1404 +    // Launch the third thread
  1.1405 +	TRequestStatus statusThreadThird;
  1.1406 +	thread14_2.Logon(statusThreadThird);
  1.1407 +	thread14_2.SetPriority(EPriorityLess);
  1.1408 +	thread14_2.Resume();
  1.1409 +	sem.Wait();
  1.1410 +	// Test opening the surface in the second thread
  1.1411 +	TEST(testResult == EOpenSurfaceTestPassed);
  1.1412 +	testResult = EAllZero;
  1.1413 +    // Test closing the surface in the main thread
  1.1414 +	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
  1.1415 +
  1.1416 +	thread14.Resume();
  1.1417 +    User::WaitForRequest(statusThreadSecond);
  1.1418 +
  1.1419 +    thread14_2.Resume();
  1.1420 +    User::WaitForRequest(statusThreadThird);
  1.1421 +
  1.1422 +	// Test the execution results in the third thread
  1.1423 +	TEST(testResult == (ECloseSurfaceTestPassed|EMapSurfaceTestPassed|ESurfaceInfoTestPassed));	
  1.1424 +
  1.1425 +    // Close all the handles
  1.1426 +    CleanupStack::PopAndDestroy(1, &sem);
  1.1427 +    thread14.Close();
  1.1428 +    thread14_2.Close();
  1.1429 +	iSurfaceManager.Close();
  1.1430 +
  1.1431 +	}
  1.1432 +
  1.1433 +void CTSurfaceManagerMultiThread::TestOpenSurfaceDieCloseOtherThreadsL()
  1.1434 +	{
  1.1435 +	User::LeaveIfError(iSurfaceManager.Open());
  1.1436 +    
  1.1437 +	// Setup attributes
  1.1438 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1439 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1440 +	attributes.iSize = TSize(480,16);
  1.1441 +	attributes.iBuffers = 2;				// number of buffers in the surface
  1.1442 +	attributes.iPixelFormat = EUidPixelFormatYUV_422Reversed;		// 2bpp
  1.1443 +	attributes.iStride = 1013;				// Number of bytes between start of one line and start of next
  1.1444 +	attributes.iOffsetToFirstBuffer = 0;	// way of reserving space before the surface pixel data
  1.1445 +	attributes.iAlignment = RSurfaceManager::EPageAligned;			// alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
  1.1446 +
  1.1447 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1448 +	attributes.iHintCount = 2;
  1.1449 +	attributes.iSurfaceHints = hints;
  1.1450 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1451 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1452 +		
  1.1453 +	attributes.iContiguous = ETrue;
  1.1454 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1455 +	attributes.iOffsetBetweenBuffers = 0;
  1.1456 +	attributes.iMappable = ETrue;
  1.1457 +
  1.1458 +    // Logging info
  1.1459 +    INFO_PRINTF1(_L("Test that the surface can be opened from the third Thread after creating thread dies and second and third thread close the surface\r\n"));
  1.1460 +    // Create a semaphore
  1.1461 +	RSemaphore sem;
  1.1462 +	TEST(KErrNone == sem.CreateGlobal(KMultiThreadSemaphore, 0));
  1.1463 +	CleanupClosePushL(sem);
  1.1464 +
  1.1465 +    // Create a second thread and opens the handle
  1.1466 +	iInfo.iSurfaceManager = iSurfaceManager;
  1.1467 +	iInfo.iSurfaceId = iSurfaceId;
  1.1468 +	iInfo.iThreadTestCase = ECreateKillSurface;	
  1.1469 +
  1.1470 +	// Create a TCleanupItem object
  1.1471 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo));
  1.1472 +    RThread thread15;
  1.1473 +    _LIT(KNameThreadSecond15, "Test_SurfaceManager_ThreadSecond15");
  1.1474 +	User::LeaveIfError(thread15.Create(KNameThreadSecond15,ThreadSecondStart, KDefaultStackSize, &User::Heap(), &iInfo));
  1.1475 +   	CleanupStack::Pop();
  1.1476 +   	// Launch the second thread
  1.1477 +	TRequestStatus statusThreadSecond;
  1.1478 +	thread15.Logon(statusThreadSecond);
  1.1479 +	thread15.SetPriority(EPriorityLess);
  1.1480 +	thread15.Resume();
  1.1481 +	testResult = EAllZero;
  1.1482 +	sem.Wait();	
  1.1483 +
  1.1484 +	thread15.Suspend(); //suspend the 2nd thread
  1.1485 +
  1.1486 +	TEST(testResult == ECreateSurfaceTestPassed);
  1.1487 +	testResult = EAllZero;
  1.1488 +	// Test creating the surface in the second thread	
  1.1489 +	TEST(KErrNone == iSurfaceManager.OpenSurface(globalSurfaceId));
  1.1490 +
  1.1491 +	// Create a third thread and opens the handle
  1.1492 +	iInfo2.iSurfaceManager = iSurfaceManager;
  1.1493 +	iInfo2.iSurfaceId = globalSurfaceId;
  1.1494 +	iInfo2.iSurfaceIdNew = iSurfaceId;
  1.1495 +	iInfo2.iThreadTestCase = EOpenCloseOpenMultiThread;	
  1.1496 +
  1.1497 +	// Create a TCleanupItem object
  1.1498 +    CleanupStack::PushL(TCleanupItem((TCleanupOperation)CloseSurfaceWhenLeave, &iInfo2));
  1.1499 +    RThread thread15_2;
  1.1500 +    _LIT(KNameThreadSecond15_2, "Test_SurfaceManager_ThreadSecond15_2");
  1.1501 +	User::LeaveIfError(thread15_2.Create(KNameThreadSecond15_2,ThreadThirdStart, KDefaultStackSize, &User::Heap(), &iInfo2));
  1.1502 +   	CleanupStack::Pop();
  1.1503 +	// Launch the third thread
  1.1504 +	TRequestStatus statusThreadThird;
  1.1505 +	thread15_2.Logon(statusThreadThird);
  1.1506 +	thread15_2.SetPriority(EPriorityLess);
  1.1507 +	thread15_2.Resume();
  1.1508 +	sem.Wait();
  1.1509 +	// Test opening the surface in the third thread
  1.1510 +	TEST(testResult == EOpenSurfaceTestPassed);
  1.1511 +	// Test closing the surface in the main thread	
  1.1512 +	TEST(KErrNone == iSurfaceManager.CloseSurface(globalSurfaceId));
  1.1513 +	thread15.Resume();
  1.1514 +    User::WaitForRequest(statusThreadSecond);
  1.1515 +
  1.1516 +    thread15_2.Resume();
  1.1517 +    User::WaitForRequest(statusThreadThird);
  1.1518 +
  1.1519 +    // Test the surface is still accessible in the third thread
  1.1520 +	TEST(testResult == (ECloseSurfaceTestPassed | EOpenSurfaceTestPassed));
  1.1521 +    // Close the handles
  1.1522 +	CleanupStack::PopAndDestroy(1, &sem);
  1.1523 +	thread15.Close();
  1.1524 +	thread15_2.Close();
  1.1525 +	iSurfaceManager.Close();
  1.1526 +
  1.1527 +	}
  1.1528 +	
  1.1529 +
  1.1530 +/**
  1.1531 +The second thread entry point
  1.1532 +*/
  1.1533 +TInt CTSurfaceManagerMultiThread::ThreadSecondStart(TAny* aInfo)
  1.1534 +	{
  1.1535 +	TInt procHandles1  =0;
  1.1536 +	TInt threadHandles1=0;
  1.1537 +	RThread().HandleCount(procHandles1, threadHandles1);
  1.1538 +	__UHEAP_MARK;
  1.1539 +		
  1.1540 +	CChildThreadWrapper* newThread = new CChildThreadWrapper(aInfo);
  1.1541 +	if (newThread==NULL)
  1.1542 +		{
  1.1543 +		return KErrNoMemory;
  1.1544 +		}
  1.1545 +
  1.1546 +    RSemaphore sem;
  1.1547 +    RSemaphore semMain;
  1.1548 + 	TInt ret = sem.OpenGlobal(KMultiThreadSemaphore);
  1.1549 +    if (ret == KErrNone)
  1.1550 +    	{
  1.1551 +   		TThreadTestCase testCase = newThread->iThreadTestCase;
  1.1552 +		switch (testCase)
  1.1553 +			{
  1.1554 +			case ECreateSurfaceMapInfo:
  1.1555 +				User::LeaveIfError(semMain.OpenGlobal(KMainThreadSemaphore));
  1.1556 +				newThread->CreateSurfaceThread();
  1.1557 +				sem.Signal();
  1.1558 +				semMain.Wait();
  1.1559 +				newThread->MapSurfaceInfo();
  1.1560 +				delete newThread;
  1.1561 +				semMain.Close();
  1.1562 +				break;
  1.1563 +			case ECreateSurfaceClose:
  1.1564 +				User::LeaveIfError(semMain.OpenGlobal(KMainThreadSemaphore));
  1.1565 +				newThread->CreateSurfaceThread();
  1.1566 +				sem.Signal();
  1.1567 +				semMain.Wait();
  1.1568 +				newThread->CloseSurface();
  1.1569 +				delete newThread;
  1.1570 +				semMain.Close();
  1.1571 +				break;
  1.1572 +			case EMapSurfaceInfo:
  1.1573 +		 		newThread->MapSurfaceInfo();
  1.1574 +		 		sem.Signal();
  1.1575 +				delete newThread;
  1.1576 +				break;
  1.1577 +			case ECloseSurfaces:
  1.1578 +				newThread->CloseSurface();
  1.1579 +				sem.Signal();
  1.1580 +				delete newThread;
  1.1581 +				break;
  1.1582 +			case EOpenCloseSurface:
  1.1583 +				newThread->OpenSurface();
  1.1584 +				newThread->CloseSurface();
  1.1585 +				sem.Signal();
  1.1586 +				delete newThread;
  1.1587 +				break;
  1.1588 +			case EOpenKillSurface:
  1.1589 +				newThread->OpenSurface();
  1.1590 +				delete newThread;
  1.1591 +    			sem.Close();
  1.1592 +    			RThread().Kill(ret);
  1.1593 +				break;
  1.1594 +			case ECreateKillSurface:
  1.1595 +				newThread->CreateSurfaceThread();
  1.1596 +				sem.Signal();
  1.1597 +				delete newThread;
  1.1598 +    			sem.Close();
  1.1599 +    			RThread().Kill(ret);
  1.1600 +				break;
  1.1601 +			case EOpenCloseSurfaceMultiThread:
  1.1602 +				newThread->OpenSurface(); 
  1.1603 +				sem.Signal();
  1.1604 +				RThread().Suspend();
  1.1605 +				newThread->CloseSurface();
  1.1606 +				delete newThread;
  1.1607 +				sem.Close();
  1.1608 +				return ret;
  1.1609 +			case ECloseBothSurfaces:
  1.1610 +				newThread->CloseBothSurfaces();
  1.1611 +				sem.Signal();
  1.1612 +				delete newThread;
  1.1613 +				break;
  1.1614 +			default:
  1.1615 +				break;
  1.1616 +			}
  1.1617 +
  1.1618 +		}
  1.1619 +
  1.1620 +	__UHEAP_MARKEND;
  1.1621 +     
  1.1622 +	sem.Close();	
  1.1623 +	TInt procHandles2  =0;
  1.1624 +	TInt threadHandles2=0;
  1.1625 +	RThread().HandleCount(procHandles2,threadHandles2);
  1.1626 +	if (threadHandles1 != threadHandles2)
  1.1627 +		{
  1.1628 +		ret = KErrGeneral;  // Thread-owned handles not closed
  1.1629 +		}
  1.1630 +
  1.1631 +	return ret;
  1.1632 +	}
  1.1633 +	
  1.1634 +// Implementation of CChildThreadWrapper class 
  1.1635 +CChildThreadWrapper::CChildThreadWrapper(TAny* aInfo) :
  1.1636 +	iSurfaceManager    (((TInfo*)aInfo)->iSurfaceManager),
  1.1637 +	iSurfaceId(((TInfo*)aInfo)->iSurfaceId),
  1.1638 +	iSurfaceIdNew(((TInfo*)aInfo)->iSurfaceIdNew),
  1.1639 +	iThreadTestCase(((TInfo*)aInfo)->iThreadTestCase)
  1.1640 +	{
  1.1641 +	}
  1.1642 +
  1.1643 +CChildThreadWrapper::~CChildThreadWrapper()
  1.1644 +	{
  1.1645 +	}
  1.1646 +
  1.1647 +void CChildThreadWrapper::CreateSurfaceThread()
  1.1648 +	{
  1.1649 +	// Setup attributes
  1.1650 +    RSurfaceManager::TSurfaceCreationAttributesBuf buf;
  1.1651 +	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
  1.1652 +	
  1.1653 +	attributes.iSize = TSize(200,200);
  1.1654 +	attributes.iBuffers = 1;				
  1.1655 +	attributes.iPixelFormat = EUidPixelFormatARGB_1555;		
  1.1656 +	attributes.iStride = 1024;				
  1.1657 +	attributes.iOffsetToFirstBuffer = 80;	
  1.1658 +	attributes.iAlignment = 8;			
  1.1659 +	attributes.iContiguous=ETrue;
  1.1660 +
  1.1661 +	RSurfaceManager::THintPair hints[2];	// two hint pairs specified
  1.1662 +	attributes.iHintCount = 2;
  1.1663 +	attributes.iSurfaceHints = hints;
  1.1664 +	hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
  1.1665 +	hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
  1.1666 +
  1.1667 +	attributes.iCacheAttrib = RSurfaceManager::ECached;
  1.1668 +	attributes.iOffsetBetweenBuffers = 0;
  1.1669 +	attributes.iMappable = ETrue;
  1.1670 +
  1.1671 +	if (KErrNone == iSurfaceManager.CreateSurface(buf,iSurfaceId))
  1.1672 +		{
  1.1673 +		testResult |= ECreateSurfaceTestPassed;
  1.1674 +		}
  1.1675 +    else
  1.1676 +    	{
  1.1677 +    	testResult |= ECreateSurfaceTestFailed;	
  1.1678 +	   	}
  1.1679 +		
  1.1680 +	// record the surfaceId as a global variable
  1.1681 +	globalSurfaceId = iSurfaceId;
  1.1682 +	}
  1.1683 +	
  1.1684 +void CChildThreadWrapper::MapSurfaceInfo()
  1.1685 +	{
  1.1686 +	// Access the surface and pass back the test results to the main thread
  1.1687 +	RChunk handle;
  1.1688 +	// Call Map Surface
  1.1689 +	if (iSurfaceManager.MapSurface(iSurfaceId,handle)== KErrNone)
  1.1690 +		{
  1.1691 +		testResult |= EMapSurfaceTestPassed;
  1.1692 +		}
  1.1693 +	else 
  1.1694 +		{
  1.1695 +		testResult |= EMapSurfaceTestFailed;
  1.1696 +		}
  1.1697 +	handle.Close();
  1.1698 +
  1.1699 +	RSurfaceManager::TInfoBuf infoBuf;
  1.1700 +	// Call Surface Info
  1.1701 +	if (iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf) == KErrNone)
  1.1702 +		{
  1.1703 +		testResult |= ESurfaceInfoTestPassed;
  1.1704 +		}
  1.1705 +	else 
  1.1706 +		{
  1.1707 +		testResult |= ESurfaceInfoTestFailed;
  1.1708 +		}
  1.1709 +	} 
  1.1710 +			   
  1.1711 +void CChildThreadWrapper::CloseSurface()
  1.1712 +	{
  1.1713 +	// Call close surface and pass back the results to the main thread
  1.1714 +	if (iSurfaceManager.CloseSurface(iSurfaceId) == KErrNone)
  1.1715 +		{
  1.1716 +		testResult |= ECloseSurfaceTestPassed;
  1.1717 +		}
  1.1718 +	else 
  1.1719 +		{
  1.1720 +		testResult |= ECloseSurfaceTestFailed;
  1.1721 +		}
  1.1722 +	} 
  1.1723 +
  1.1724 +void CChildThreadWrapper::OpenSurface()
  1.1725 +	{
  1.1726 +	// Call close surface and pass back the results to the main thread
  1.1727 +	if (iSurfaceManager.OpenSurface(iSurfaceId) == KErrNone)
  1.1728 +		{
  1.1729 +		testResult |= EOpenSurfaceTestPassed;
  1.1730 +		}
  1.1731 +	else
  1.1732 +		{
  1.1733 +		testResult |= EOpenSurfaceTestFailed;
  1.1734 +		}
  1.1735 +	} 
  1.1736 +		 
  1.1737 +void CChildThreadWrapper::CloseBothSurfaces()
  1.1738 +	{
  1.1739 +	// Call close surface and pass back the results to the main thread
  1.1740 +	if (iSurfaceManager.CloseSurface(iSurfaceIdNew) == KErrNone)
  1.1741 +		{
  1.1742 +		testResult |= ECloseSurfaceTestPassed;
  1.1743 +		}
  1.1744 +	else 
  1.1745 +		{
  1.1746 +		testResult |= ECloseSurfaceTestFailed;
  1.1747 +		}
  1.1748 +	RSurfaceManager::TInfoBuf infoBuf;
  1.1749 +	// Call Surface Info
  1.1750 +	if (iSurfaceManager.SurfaceInfo(iSurfaceId, infoBuf) == KErrNone)
  1.1751 +		{
  1.1752 +		testResult |= ESurfaceInfoTestPassed;
  1.1753 +		}
  1.1754 +	else 
  1.1755 +		{
  1.1756 +		testResult |= ESurfaceInfoTestFailed;
  1.1757 +		}
  1.1758 +	
  1.1759 +	if (iSurfaceManager.SurfaceInfo(iSurfaceIdNew, infoBuf) == KErrArgument)
  1.1760 +		{
  1.1761 +		testResult |= ESurfaceInfoTestPassed2;
  1.1762 +		}
  1.1763 +	else 
  1.1764 +		{
  1.1765 +		testResult |= ESurfaceInfoTestFailed2;
  1.1766 +		}
  1.1767 +	iSurfaceManager.CloseSurface(iSurfaceId);
  1.1768 +	}
  1.1769 +/**
  1.1770 +The third thread entry point
  1.1771 +*/
  1.1772 +TInt CTSurfaceManagerMultiThread::ThreadThirdStart(TAny* aInfo)
  1.1773 +	{
  1.1774 +	TInt procHandles1  =0;
  1.1775 +	TInt threadHandles1=0;
  1.1776 +	RThread().HandleCount(procHandles1, threadHandles1);
  1.1777 +	__UHEAP_MARK;
  1.1778 +	CTrapCleanup* cleanupStack=CTrapCleanup::New();
  1.1779 +	if (cleanupStack==NULL)
  1.1780 +		{
  1.1781 +		return KErrNoMemory;
  1.1782 +		}
  1.1783 +		
  1.1784 +	CChildThreadWrapper* newThread = new CChildThreadWrapper(aInfo);
  1.1785 +	if (newThread==NULL)
  1.1786 +		{
  1.1787 +		delete cleanupStack;
  1.1788 +		return KErrNoMemory;
  1.1789 +		}
  1.1790 +		
  1.1791 +	// Pass control back to the first process
  1.1792 +    RSemaphore sem;
  1.1793 +	TInt ret = sem.OpenGlobal(KMultiThreadSemaphore);
  1.1794 +	if (ret!=KErrNone)
  1.1795 +		return ret;
  1.1796 +		
  1.1797 +	TInt err = KErrNone;
  1.1798 +    TThreadTestCase testCase = newThread->iThreadTestCase;
  1.1799 +	switch (testCase)
  1.1800 +		{
  1.1801 +		case EOpenMapSurfaceInfoMultiThread:
  1.1802 +			newThread->OpenSurface();
  1.1803 +			sem.Signal();
  1.1804 +			RThread().Suspend();
  1.1805 +			newThread->MapSurfaceInfo();
  1.1806 +			break;
  1.1807 +		case EOpenCloseMapSurfaceInfoMultiThread:
  1.1808 +			newThread->OpenSurface();
  1.1809 +			sem.Signal();
  1.1810 +			RThread().Suspend();
  1.1811 +			newThread->CloseSurface();
  1.1812 +			newThread->MapSurfaceInfo();
  1.1813 +			break;
  1.1814 +		case EOpenCloseOpenMultiThread:
  1.1815 +			newThread->OpenSurface();
  1.1816 +			sem.Signal();
  1.1817 +			RThread().Suspend();
  1.1818 +			newThread->CloseSurface();
  1.1819 +			newThread->OpenSurface();
  1.1820 +			break;
  1.1821 +		default:
  1.1822 +			break;
  1.1823 +		}
  1.1824 +
  1.1825 +   	delete newThread;
  1.1826 +	delete cleanupStack;
  1.1827 +	__UHEAP_MARKEND;
  1.1828 +	
  1.1829 +    sem.Close();	
  1.1830 +	TInt procHandles2  =0;
  1.1831 +	TInt threadHandles2=0;
  1.1832 +	RThread().HandleCount(procHandles2,threadHandles2);
  1.1833 +	if (threadHandles1 != threadHandles2)
  1.1834 +		{
  1.1835 +		err = KErrGeneral;  // Thread-owned handles not closed
  1.1836 +		}
  1.1837 +
  1.1838 +	return err;
  1.1839 +	}
  1.1840 +
  1.1841 +
  1.1842 +	
  1.1843 +//--------------
  1.1844 +__CONSTRUCT_STEP__(SurfaceManagerMultiThread)
  1.1845 +
  1.1846 +void CTSurfaceManagerMultiThreadStep::TestSetupL()
  1.1847 +	{
  1.1848 +    }
  1.1849 +
  1.1850 +void CTSurfaceManagerMultiThreadStep::TestClose()
  1.1851 +	{
  1.1852 +	}