1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicshwdrivers/surfacemgr/test/src/tsecondprocess.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,965 @@
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-processed 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 +#include <e32base.h>
1.27 +#include <e32cons.h>
1.28 +#include <e32test.h>
1.29 +#include <e32std.h>
1.30 +#include <e32debug.h>
1.31 +#include <e32def_private.h>
1.32 +#include <graphics/surface.h>
1.33 +#include <graphics/surfacemanager.h>
1.34 +#include "tsmgmultprocessshared.h"
1.35 +
1.36 +LOCAL_D RTest test(_L("TReceiveSurface"));
1.37 +
1.38 +
1.39 +class CTestDriverSecondProcess : public CTestDriver
1.40 +{
1.41 +public:
1.42 + CTestDriverSecondProcess();
1.43 + ~CTestDriverSecondProcess();
1.44 + void ConstructL();
1.45 + static CTestDriverSecondProcess* NewL();
1.46 +public:
1.47 + void TestMultipleChannelsInSecondProcess2();
1.48 + void TestMultipleChannelsInSecondProcess1();
1.49 + void TestCheckSyncOperation();
1.50 + void TestCheckHandleInSecondProcess();
1.51 + void TestSurfaceInfoUsingSurfaceId();
1.52 + void TestOpeningSurfaceUsingSurfaceId();
1.53 + void TestOpeningSurfaceInvalidParams();
1.54 + void OpenWaitMap();
1.55 + void CreateWaitKill();
1.56 + void OpenClose();
1.57 + void MapSurfaceInfoCantAccess();
1.58 + void TestReadFromBufferInSecondProcess();
1.59 + void TestGetSurfaceHint();
1.60 + void TestSetSurfaceHint();
1.61 + void TestAddSurfaceHint();
1.62 + void TestOutofMemory();
1.63 +private:
1.64 + RSurfaceManager iSurfaceManagerTwo;
1.65 +};
1.66 +
1.67 +CTestDriverSecondProcess::CTestDriverSecondProcess():CTestDriver()
1.68 + {
1.69 + }
1.70 +
1.71 +CTestDriverSecondProcess::~CTestDriverSecondProcess()
1.72 + {
1.73 + iSurfaceManagerTwo.Close();
1.74 + }
1.75 +
1.76 +void CTestDriverSecondProcess::ConstructL()
1.77 + {
1.78 + CTestDriver::ConstructL();
1.79 + User::LeaveIfError( iSurfaceManagerTwo.Open());
1.80 + }
1.81 +
1.82 +CTestDriverSecondProcess* CTestDriverSecondProcess::NewL()
1.83 +{
1.84 + CTestDriverSecondProcess * driver = new (ELeave) CTestDriverSecondProcess();
1.85 + CleanupStack::PushL(driver);
1.86 + driver->ConstructL();
1.87 + CleanupStack::Pop(driver);
1.88 + return driver;
1.89 +}
1.90 +
1.91 +void CTestDriverSecondProcess::TestMultipleChannelsInSecondProcess2()
1.92 + {
1.93 + // Store the attributes used to create the Surface
1.94 + RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1.95 + RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1.96 + attributes.iSize = TSize(280,301);
1.97 + attributes.iBuffers = 1;
1.98 + attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
1.99 + attributes.iStride = 1;
1.100 + attributes.iOffsetToFirstBuffer = 1;
1.101 + attributes.iAlignment = 1;
1.102 +
1.103 + RSurfaceManager::THintPair hints[2]; // two hint pairs specified
1.104 + attributes.iHintCount = 2;
1.105 + attributes.iSurfaceHints = hints;
1.106 + hints[0].Set(TUid::Uid(0x124578), 25, ETrue);
1.107 + hints[1].Set(TUid::Uid(0x237755), 50, ETrue);
1.108 +
1.109 + attributes.iContiguous = ETrue;
1.110 + attributes.iCacheAttrib = RSurfaceManager::ECached;
1.111 + attributes.iOffsetBetweenBuffers = 0;
1.112 + attributes.iMappable = ETrue;
1.113 +
1.114 + // Create the surface
1.115 + TSurfaceId surfaceIdOne;
1.116 + if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdOne))
1.117 + {
1.118 + iTestResult |= EFirstTestPassed;
1.119 + }
1.120 +
1.121 + // Create the surface
1.122 + TSurfaceId surfaceIdTwo;
1.123 + if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdTwo))
1.124 + {
1.125 + iTestResult |= ESecondTestPassed;
1.126 + }
1.127 +
1.128 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceIdTwo))
1.129 + {
1.130 + iTestResult |= EThirdTestPassed;
1.131 + }
1.132 +
1.133 + if(KErrNone == iSurfaceManagerTwo.OpenSurface(surfaceIdOne))
1.134 + {
1.135 + iTestResult |= EFourthTestPassed;
1.136 + }
1.137 +
1.138 + // Set the results so they can be read and tested by the first process
1.139 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.140 + // Put the surfaceId onto the shared chunk
1.141 + iChunkWrapper->SetId(surfaceIdOne);
1.142 +
1.143 +
1.144 + // Pass control back to the first process
1.145 + RSemaphore sem;
1.146 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.147 + {
1.148 + iTestResult |= EThirdTestPassed;
1.149 + }
1.150 +
1.151 + sem.Signal();
1.152 +
1.153 + RSemaphore sem2;
1.154 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.155 + {
1.156 + iTestResult |= EFourthTestPassed;
1.157 + }
1.158 + sem2.Wait();
1.159 +
1.160 + // Set the results so they can be read and tested by the first process
1.161 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.162 +// // Put the surfaceId onto the shared chunk
1.163 + iChunkWrapper->SetId(surfaceIdTwo);
1.164 +
1.165 + sem.Close();
1.166 + sem2.Close();
1.167 + }
1.168 +
1.169 +void CTestDriverSecondProcess::TestMultipleChannelsInSecondProcess1()
1.170 + {
1.171 + // Open the chunk wrapper and get the surfaceId
1.172 + TSurfaceId surfaceIdOne = iChunkWrapper->GetId();
1.173 +
1.174 + // Open the surface using the surfaceId - check that it returns KErrNone
1.175 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceIdOne))
1.176 + {
1.177 + iTestResult |= EFirstTestPassed;
1.178 + }
1.179 +
1.180 + // Pass control back to the first process
1.181 + RSemaphore sem;
1.182 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.183 + {
1.184 + iTestResult |= ESecondTestPassed;
1.185 + }
1.186 +
1.187 + RSemaphore sem2;
1.188 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.189 + {
1.190 + iTestResult |= EThirdTestPassed;
1.191 + }
1.192 +
1.193 + // Set the results so they can be read and tested by the first process
1.194 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.195 +
1.196 + sem.Signal();
1.197 + sem2.Wait();
1.198 +
1.199 + // Get the surface info
1.200 + RSurfaceManager::TInfoBuf infoBuf;
1.201 + if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdOne, infoBuf))
1.202 + {
1.203 + iTestResult |= EFourthTestPassed;
1.204 + }
1.205 + TSurfaceId surfaceIdTwo = iChunkWrapper->GetId();
1.206 +
1.207 + if(KErrArgument == iSurfaceManager.SurfaceInfo(surfaceIdTwo, infoBuf))
1.208 + {
1.209 + iTestResult |= EFifthTestPassed;
1.210 + }
1.211 + // Set the results so they can be read and tested by the first process
1.212 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.213 +
1.214 + sem.Close();
1.215 + sem2.Close();
1.216 + }
1.217 +
1.218 +void CTestDriverSecondProcess::TestCheckSyncOperation()
1.219 + {
1.220 + // Open the chunk wrapper and get the surfaceId
1.221 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.222 +
1.223 + // Check it returns KErrAccessDenied when the surface is not Open
1.224 + TInt bufferNo = 1;
1.225 +
1.226 + RSurfaceManager::TSyncOperation syncOperation = RSurfaceManager::ESyncBeforeNonCPURead;
1.227 +
1.228 + if(KErrAccessDenied == iSurfaceManager.SynchronizeCache(surfaceId, bufferNo,syncOperation))
1.229 + {
1.230 + iTestResult |= EFirstTestPassed;
1.231 + }
1.232 +
1.233 + // Open the surface using the surfaceId - check that it returns KErrNone
1.234 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.235 + {
1.236 + iTestResult |= ESecondTestPassed;
1.237 + }
1.238 +
1.239 + // Map the surface
1.240 + RChunk handle;
1.241 +
1.242 + if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle))
1.243 + {
1.244 + iTestResult |= EThirdTestPassed;
1.245 + }
1.246 +
1.247 + if(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId, bufferNo,syncOperation))
1.248 + {
1.249 + iTestResult |= EFourthTestPassed;
1.250 + }
1.251 + // Set the results so they can be read and tested by the first process
1.252 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.253 + // Close the chunkwrapper, handle and the surface manager
1.254 + handle.Close();
1.255 +
1.256 + }
1.257 +void CTestDriverSecondProcess::TestCheckHandleInSecondProcess()
1.258 + {
1.259 + // Open the chunk wrapper and get the surfaceId
1.260 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.261 +
1.262 + // Open the surface using the surfaceId - check that it returns KErrNone
1.263 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.264 + {
1.265 + iTestResult |= EFirstTestPassed;
1.266 + }
1.267 +
1.268 + // Map the surface
1.269 + RChunk handle;
1.270 +
1.271 + if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle))
1.272 + {
1.273 + iTestResult |= ESecondTestPassed;
1.274 + }
1.275 +
1.276 + // Get the surface info
1.277 + RSurfaceManager::TInfoBuf infoBuf;
1.278 + if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf))
1.279 + {
1.280 + iTestResult |= EThirdTestPassed;
1.281 + }
1.282 + RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1.283 + // Get the adress of this chunk of memory
1.284 + TUint8* surfaceAdd = handle.Base();
1.285 + TInt offsetToFirstBuffer;
1.286 + if(KErrNone == iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer))
1.287 + {
1.288 + iTestResult |= EFourthTestPassed;
1.289 + }
1.290 + TUint8* bufferAdd = surfaceAdd + offsetToFirstBuffer;
1.291 +
1.292 + // Write to the first buffer, and test the value is written
1.293 + *bufferAdd = 20;
1.294 + // Set the results so they can be read and tested by the first process
1.295 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.296 +
1.297 + // Close the chunkwrapper, handle and the surface manager
1.298 + handle.Close();
1.299 + }
1.300 +
1.301 +/**
1.302 +Test 18. Receiving a surface and querying SurfaceInfo for surface properties
1.303 +
1.304 +Process 1: Create the Surface
1.305 +Process 2: Receive the Surface Id
1.306 +Process 2: Receive the attributes used to create the surface
1.307 +Process 2: Open the surface using the id
1.308 +Process 2: Map the surface
1.309 +Process 2: Call SurfaceInfo to get the attributes of the Surface
1.310 +Check if these are equal to the ones received.
1.311 +
1.312 +@see TestSurfaceInfoUsingSurfaceIdL() in tsurfacemanager.cpp
1.313 +*/
1.314 +void CTestDriverSecondProcess::TestSurfaceInfoUsingSurfaceId()
1.315 + {
1.316 + // Set attributes for the surface - these are expected attributes in the second process
1.317 + RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1.318 + RSurfaceManager::TSurfaceCreationAttributes& attributes=buf();
1.319 + attributes.iSize = TSize(100,100);
1.320 + attributes.iBuffers = 1; // number of buffers in the surface
1.321 + attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
1.322 + attributes.iStride = 400; // Number of bytes between start of one line and start of next
1.323 + attributes.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
1.324 + attributes.iAlignment = 2; // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
1.325 + attributes.iContiguous=ETrue;
1.326 +
1.327 + RSurfaceManager::THintPair hints[2]; // two hint pairs specified
1.328 + attributes.iHintCount = 2;
1.329 + attributes.iSurfaceHints = hints;
1.330 + hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
1.331 + hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
1.332 +
1.333 + attributes.iOffsetBetweenBuffers = 0;
1.334 + attributes.iCacheAttrib = RSurfaceManager::ENotCached;
1.335 + attributes.iMappable = ETrue;
1.336 +
1.337 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.338 +
1.339 + // Open the surface using the surfaceId - check that it returns KErrNone
1.340 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.341 + {
1.342 + iTestResult |= EFirstTestPassed;
1.343 + }
1.344 +
1.345 + // Map the surface
1.346 + RChunk handle;
1.347 +
1.348 + if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle))
1.349 + {
1.350 + iTestResult |= ESecondTestPassed;
1.351 + }
1.352 +
1.353 + // Get the surface info
1.354 + RSurfaceManager::TInfoBuf infoBuf;
1.355 + if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf))
1.356 + {
1.357 + iTestResult |= EThirdTestPassed;
1.358 + }
1.359 + RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1.360 + TInt offsetToFirstBuffer;
1.361 + if(KErrNone == iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer))
1.362 + {
1.363 + iTestResult |= EFourthTestPassed;
1.364 + }
1.365 +
1.366 + if(info.iSize == attributes.iSize)
1.367 + {
1.368 + iTestResult |= EFifthTestPassed;
1.369 + }
1.370 + if(info.iBuffers == attributes.iBuffers)
1.371 + {
1.372 + iTestResult |= ESixthTestPassed;
1.373 + }
1.374 + if(info.iPixelFormat == attributes.iPixelFormat)
1.375 + {
1.376 + iTestResult |= ESeventhTestPassed;
1.377 + }
1.378 + if(info.iStride == attributes.iStride)
1.379 + {
1.380 + iTestResult |= EEighthTestPassed;
1.381 + }
1.382 + if(offsetToFirstBuffer >= attributes.iOffsetToFirstBuffer)
1.383 + {
1.384 + iTestResult |= ENinthTestPassed;
1.385 + }
1.386 + if(info.iContiguous == attributes.iContiguous)
1.387 + {
1.388 + iTestResult |= ETenthTestPassed;
1.389 + }
1.390 +
1.391 + // Set the results so they can be read and tested by the first process
1.392 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.393 +
1.394 + // Close handle
1.395 + handle.Close();
1.396 + }
1.397 +
1.398 +/**
1.399 +Test 19. Opening a surface using surfaceId
1.400 +
1.401 +Priocess 1: Create the surface
1.402 +Process 2: Receive the Surface id
1.403 +Process 2: Open the Surface using the stored Surface id
1.404 +Check OpenSurface returns KErrNone
1.405 +
1.406 +@see TestOpeningSurfaceUsingSurfaceIdL() in tsurfacemanager.cpp
1.407 +*/
1.408 +void CTestDriverSecondProcess::TestOpeningSurfaceUsingSurfaceId()
1.409 + {
1.410 + // Open the chunk wrapper and get the surfaceId
1.411 +// CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue);
1.412 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.413 +
1.414 + // Open the surface using the surfaceId - check that it returns KErrNone
1.415 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.416 + {
1.417 + iTestResult |= EFirstTestPassed;
1.418 + }
1.419 +
1.420 + // Set the results so they can be read and tested by the first process
1.421 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.422 +
1.423 + }
1.424 +
1.425 +/**
1.426 +Test 20. Opening a surface using invalid surfaceId
1.427 +
1.428 +Process 1:Create the surface
1.429 +Process 2: Receive a Surface Id
1.430 +Change Surface Id by
1.431 +1. adding 500 to the SurfaceId
1.432 +2. making the Surface ID negative
1.433 +3. converting the type of the Surface ID to EInvalidSurface
1.434 +Process 2: Call OpenSurface using the new SurfaceId
1.435 +Check that the return value of OpenSurface is KErrArgument
1.436 +
1.437 +@see TestOpenSurfaceInvalidParams() in tsurfacemanager.cpp
1.438 +*/
1.439 +void CTestDriverSecondProcess::TestOpeningSurfaceInvalidParams()
1.440 + {
1.441 +
1.442 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.443 +
1.444 + // Open Surface using the right Id
1.445 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.446 + {
1.447 + iTestResult |= EFirstTestPassed;
1.448 + }
1.449 + // Open the surface using the invalid surfaceId - check that it returns KErrArgument
1.450 + TSurfaceId invalidSurfaceId = surfaceId;
1.451 + //Add 500 to the first field of surfaceId
1.452 + invalidSurfaceId.iInternal[0] = surfaceId.iInternal[0]+500;
1.453 + if(KErrArgument == iSurfaceManager.OpenSurface(invalidSurfaceId))
1.454 + {
1.455 + iTestResult |= ESecondTestPassed;
1.456 + }
1.457 + // Change the surfaceId type to EInvalidSurface
1.458 + invalidSurfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ;
1.459 + if(KErrArgument == iSurfaceManager.OpenSurface(invalidSurfaceId))
1.460 + {
1.461 + iTestResult |= EThirdTestPassed;
1.462 + }
1.463 +
1.464 + // Set the results so they can be read and tested by the first process
1.465 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.466 +
1.467 + }
1.468 +
1.469 +/**
1.470 +Test 22: Create, Open and Close in 3 different processes,
1.471 + leaves surface accessible in first 2 processes
1.472 +
1.473 +...
1.474 +Process 2: Open Surface
1.475 +...
1.476 +Process 2: MapSurface - KErrNone (still accessible)
1.477 +...
1.478 +*/
1.479 +void CTestDriverSecondProcess::OpenWaitMap()
1.480 + {
1.481 +
1.482 + // Find the surfaceId
1.483 + TSurfaceId id = iChunkWrapper->GetId();
1.484 +
1.485 + // Open Surface
1.486 + if(KErrNone == iSurfaceManager.OpenSurface(id))
1.487 + {
1.488 + iTestResult |= EFirstTestPassed;
1.489 + }
1.490 +
1.491 + // Pass control back to the first process
1.492 + RSemaphore sem;
1.493 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.494 + {
1.495 + iTestResult |= ESecondTestPassed;
1.496 + }
1.497 + sem.Signal();
1.498 +
1.499 + RSemaphore sem2;
1.500 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.501 + {
1.502 + iTestResult |= EThirdTestPassed;
1.503 + }
1.504 + sem2.Wait();
1.505 +
1.506 + // Map surface
1.507 + RChunk handle;
1.508 + if(KErrNone == iSurfaceManager.MapSurface(id, handle))
1.509 + {
1.510 + iTestResult |= EFourthTestPassed;
1.511 + }
1.512 +
1.513 + // Set the results so they can be read and tested by the first process
1.514 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.515 +
1.516 + sem.Close();
1.517 + sem2.Close();
1.518 + handle.Close();
1.519 +
1.520 + }
1.521 +
1.522 +
1.523 +/**
1.524 +Test 23/24/25/26: Test surface can be accessed when creating process dies /
1.525 + Test surface can be closed when creating process dies /
1.526 + Test surface can be closed from third process when
1.527 + creating process dies and second process closes /
1.528 + Test surface can't be accessed in a second process when open
1.529 + and closed in the first process.
1.530 +
1.531 +Process 2: Create Surface
1.532 +...
1.533 +Process 2: Kill Process
1.534 +...
1.535 +*/
1.536 +void CTestDriverSecondProcess::CreateWaitKill()
1.537 + {
1.538 + // Setup attributes
1.539 + RSurfaceManager::TSurfaceCreationAttributesBuf buf;
1.540 + RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
1.541 +
1.542 + attributes.iSize = TSize(20,80); // w > 0, h > 0
1.543 + attributes.iBuffers = 12; // > 0
1.544 + attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp
1.545 + attributes.iStride = 250; // > 0, < width * bpp
1.546 + attributes.iOffsetToFirstBuffer = 200; // > 0, divisible by alignment
1.547 + attributes.iAlignment = 4; // 1 || 2 || 4 || 8
1.548 + attributes.iContiguous = ETrue;
1.549 +
1.550 + RSurfaceManager::THintPair hints[2]; // two hint pairs specified
1.551 + attributes.iHintCount = 2;
1.552 + attributes.iSurfaceHints = hints;
1.553 + hints[0].Set(TUid::Uid(0x124545), 50, EFalse);
1.554 + hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
1.555 +
1.556 + attributes.iOffsetBetweenBuffers = 0;
1.557 + attributes.iMappable = ETrue;
1.558 +
1.559 + // Create the surface
1.560 + TSurfaceId surfaceId;
1.561 + if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId))
1.562 + {
1.563 + iTestResult |= EFirstTestPassed;
1.564 + }
1.565 + // Put the surfaceId onto the shared chunk
1.566 + iChunkWrapper->SetId(surfaceId);
1.567 +
1.568 + // Pass control back to the first process
1.569 + RSemaphore sem;
1.570 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.571 + {
1.572 + iTestResult |= ESecondTestPassed;
1.573 + }
1.574 + sem.Signal();
1.575 +
1.576 + RSemaphore sem2;
1.577 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.578 + {
1.579 + iTestResult |= EThirdTestPassed;
1.580 + }
1.581 + sem2.Wait();
1.582 +
1.583 + // Set the results so they can be read and tested by the first process
1.584 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.585 +
1.586 +// CleanupStack::PopAndDestroy(2,&sem);
1.587 + sem.Close();
1.588 + sem2.Close();
1.589 + }
1.590 +
1.591 +/**
1.592 +Test 27/28/29: Test closing doesn't prevent opening on another process
1.593 + Test closing doesn't prevent access on another process
1.594 + Test closing a surface in the creating process
1.595 + when it has already been closed in a second process returns KErrNone
1.596 +
1.597 +...
1.598 +Process 2: Open Surface
1.599 +Process 2: Close Surface
1.600 +...
1.601 +*/
1.602 +void CTestDriverSecondProcess::OpenClose()
1.603 + {
1.604 +
1.605 + // Find the surfaceId
1.606 + TSurfaceId id = iChunkWrapper->GetId();
1.607 +
1.608 + // Open Surface
1.609 + if(KErrNone == iSurfaceManager.OpenSurface(id))
1.610 + {
1.611 + iTestResult |= EFirstTestPassed;
1.612 + }
1.613 +
1.614 + // Close Surface
1.615 + if(KErrNone == iSurfaceManager.CloseSurface(id))
1.616 + {
1.617 + iTestResult |= ESecondTestPassed;
1.618 + }
1.619 +
1.620 + // Pass control back to the first process
1.621 + RSemaphore sem;
1.622 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.623 + {
1.624 + iTestResult |= EThirdTestPassed;
1.625 + }
1.626 + sem.Signal();
1.627 +
1.628 + RSemaphore sem2;
1.629 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.630 + {
1.631 + iTestResult |= EFourthTestPassed;
1.632 + }
1.633 + sem2.Wait();
1.634 +
1.635 + // Set the results so they can be read and tested by the first process
1.636 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.637 +
1.638 + sem.Close();
1.639 + sem2.Close();
1.640 + }
1.641 +
1.642 +/**
1.643 +Test 30: Test a surface cannot be accessed in a second process if not opened
1.644 +
1.645 +...
1.646 +Process 2: Map Surface - KErrAccessDenied
1.647 +Process 2: Surface Info - KErrAccessDenied
1.648 +*/
1.649 +void CTestDriverSecondProcess::MapSurfaceInfoCantAccess()
1.650 + {
1.651 + // Find the surfaceId
1.652 + TSurfaceId id = iChunkWrapper->GetId();
1.653 +
1.654 + // Map surface
1.655 + RChunk handle;
1.656 + if(KErrAccessDenied == iSurfaceManager.MapSurface(id, handle))
1.657 + {
1.658 + iTestResult |= EFirstTestPassed;
1.659 + }
1.660 +
1.661 + // Surface Info
1.662 + RSurfaceManager::TInfoBuf infoBuf;
1.663 + if(KErrAccessDenied == iSurfaceManager.SurfaceInfo(id, infoBuf))
1.664 + {
1.665 + iTestResult |= ESecondTestPassed;
1.666 + }
1.667 +
1.668 + // Pass control back to the first process
1.669 + RSemaphore sem;
1.670 + if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore))
1.671 + {
1.672 + iTestResult |= EThirdTestPassed;
1.673 + }
1.674 + sem.Signal();
1.675 +
1.676 + RSemaphore sem2;
1.677 + if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2))
1.678 + {
1.679 + iTestResult |= EFourthTestPassed;
1.680 + }
1.681 + sem2.Wait();
1.682 +
1.683 + // Set the results so they can be read and tested by the first process
1.684 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.685 +
1.686 +// CleanupStack::PopAndDestroy(3,&handle);
1.687 + sem.Close();
1.688 + sem2.Close();
1.689 + handle.Close();
1.690 + }
1.691 +
1.692 +/**
1.693 +Test 31: Test that a buffer written to in one surface can be read from in another
1.694 +
1.695 +Process 1: Create Surface
1.696 +Process 1: Map Surface
1.697 +Process 1: Write to buffer
1.698 +Process 2: Open the surface
1.699 +Process 2: Read from buffer
1.700 +*/
1.701 +void CTestDriverSecondProcess::TestReadFromBufferInSecondProcess()
1.702 + {
1.703 + // Find the surfaceId
1.704 + TSurfaceId id = iChunkWrapper->GetId();
1.705 +
1.706 + // Open Surface
1.707 + if(KErrNone == iSurfaceManager.OpenSurface(id))
1.708 + {
1.709 + iTestResult |= EFirstTestPassed;
1.710 + }
1.711 +
1.712 + // Map surface
1.713 + RChunk handle;
1.714 + if(KErrNone == iSurfaceManager.MapSurface(id, handle))
1.715 + {
1.716 + iTestResult |= ESecondTestPassed;
1.717 + }
1.718 +
1.719 + // Read from the buffer
1.720 + RSurfaceManager::TInfoBuf infoBuf;
1.721 + if(KErrNone == iSurfaceManager.SurfaceInfo(id, infoBuf))
1.722 + {
1.723 + iTestResult |= EThirdTestPassed;
1.724 + }
1.725 + RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
1.726 + TUint8* surfaceAdd = handle.Base();
1.727 + TInt offsetToFirstBuffer;
1.728 + if(KErrNone == iSurfaceManager.GetBufferOffset(id, 0, offsetToFirstBuffer))
1.729 + {
1.730 + iTestResult |= EFourthTestPassed;
1.731 + }
1.732 + TUint8* bufferAdd = surfaceAdd + offsetToFirstBuffer;
1.733 + if(*bufferAdd == 134)
1.734 + {
1.735 + iTestResult |= EFifthTestPassed;
1.736 + }
1.737 +
1.738 + // Set the results so they can be read and tested by the first process
1.739 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.740 +
1.741 + handle.Close();
1.742 + }
1.743 +
1.744 +void CTestDriverSecondProcess::TestGetSurfaceHint()
1.745 + {
1.746 + // Open the chunk wrapper and get the surfaceId
1.747 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.748 +
1.749 + RSurfaceManager::THintPair hintPair;
1.750 + hintPair.iKey.iUid = 0x124578;
1.751 + if (KErrAccessDenied == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair))
1.752 + {
1.753 + iTestResult |= EFirstTestPassed;
1.754 + }
1.755 +
1.756 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.757 + {
1.758 + iTestResult |= ESecondTestPassed;
1.759 + }
1.760 +
1.761 + if (KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair))
1.762 + {
1.763 + iTestResult |= EThirdTestPassed;
1.764 + }
1.765 +
1.766 + // Set the results so they can be read and tested by the first process
1.767 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.768 +
1.769 + }
1.770 +
1.771 +
1.772 +void CTestDriverSecondProcess::TestSetSurfaceHint()
1.773 + {
1.774 + // Open the chunk wrapper and get the surfaceId
1.775 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.776 +
1.777 + RSurfaceManager::THintPair hintPair;
1.778 + hintPair.iKey.iUid = 0x124578;
1.779 + hintPair.iValue = 300;
1.780 +
1.781 + if (KErrAccessDenied == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair))
1.782 + {
1.783 + iTestResult |= EFirstTestPassed;
1.784 + }
1.785 +
1.786 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.787 + {
1.788 + iTestResult |= ESecondTestPassed;
1.789 + }
1.790 +
1.791 + if (KErrNone == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair))
1.792 + {
1.793 + iTestResult |= EThirdTestPassed;
1.794 + }
1.795 + RSurfaceManager::THintPair hintPairNew;
1.796 + hintPairNew.iKey.iUid = 0x124578;
1.797 +
1.798 + iSurfaceManager.GetSurfaceHint(surfaceId,hintPairNew);
1.799 + if (hintPairNew.iValue == hintPair.iValue)
1.800 + {
1.801 + iTestResult |= EFourthTestPassed;
1.802 + }
1.803 + // Set the results so they can be read and tested by the first process
1.804 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.805 +
1.806 + }
1.807 +
1.808 +
1.809 +void CTestDriverSecondProcess::TestAddSurfaceHint()
1.810 + {
1.811 + // Open the chunk wrapper and get the surfaceId
1.812 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.813 +
1.814 + RSurfaceManager::THintPair hintPair;
1.815 + hintPair.iKey.iUid = 0x124580;
1.816 + hintPair.iValue = 300;
1.817 + hintPair.iMutable = ETrue;
1.818 + if (KErrAccessDenied == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair))
1.819 + {
1.820 + iTestResult |= EFirstTestPassed;
1.821 + }
1.822 +
1.823 + if(KErrNone == iSurfaceManager.OpenSurface(surfaceId))
1.824 + {
1.825 + iTestResult |= ESecondTestPassed;
1.826 + }
1.827 +
1.828 + if (KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair))
1.829 + {
1.830 + iTestResult |= EThirdTestPassed;
1.831 + }
1.832 + RSurfaceManager::THintPair hintPairNew;
1.833 + hintPairNew.iKey.iUid = 0x124580;
1.834 +
1.835 + iSurfaceManager.GetSurfaceHint(surfaceId,hintPairNew);
1.836 + if (hintPairNew.iValue == hintPair.iValue)
1.837 + {
1.838 + iTestResult |= EFourthTestPassed;
1.839 + }
1.840 + // Set the results so they can be read and tested by the first process
1.841 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.842 +
1.843 + }
1.844 +
1.845 +
1.846 +void CTestDriverSecondProcess::TestOutofMemory()
1.847 + {
1.848 + // Open the chunk wrapper and get the surfaceId
1.849 + TSurfaceId surfaceId = iChunkWrapper->GetId();
1.850 + // Test OOM in OpenSurface()
1.851 + __KHEAP_SETFAIL(RHeap::EDeterministic, 1);
1.852 + if (KErrNoMemory == iSurfaceManager.OpenSurface(surfaceId))
1.853 + {
1.854 + iTestResult |= EFirstTestPassed;
1.855 + }
1.856 + __KHEAP_RESET;
1.857 + // Test OOM in AddConnection()
1.858 + RSurfaceManager surfaceManagerTest;
1.859 + __KHEAP_SETFAIL(RHeap::EDeterministic, 1);
1.860 + if (KErrNoMemory == surfaceManagerTest.Open())
1.861 + {
1.862 + iTestResult |= ESecondTestPassed;
1.863 + }
1.864 + __KHEAP_RESET;
1.865 + // Set the results so they can be read and tested by the first process
1.866 + iChunkWrapper->SetSecondProcessResults(iTestResult);
1.867 + }
1.868 +// Real main function
1.869 +void MainL()
1.870 + {
1.871 +
1.872 + test.Title();
1.873 + RDebug::Print(_L("marker"));
1.874 +
1.875 + test.Start(_L("Starting 2nd Process"));
1.876 + TInt testCase;
1.877 + User::GetTIntParameter(EMultiProcessSecondSlot, testCase);
1.878 + TInt procHandles1 =0;
1.879 + TInt threadHandles1=0;
1.880 + RThread().HandleCount(procHandles1, threadHandles1);
1.881 +
1.882 + CTestDriverSecondProcess* testDriver = CTestDriverSecondProcess::NewL();
1.883 + CleanupStack::PushL(testDriver);
1.884 +
1.885 + switch(testCase)
1.886 + {
1.887 + case ETestInfoReceivedSurface:
1.888 + testDriver->TestSurfaceInfoUsingSurfaceId();
1.889 + break;
1.890 + case ETestOpenReceivedSurface:
1.891 + testDriver->TestOpeningSurfaceUsingSurfaceId();
1.892 + break;
1.893 + case ETestOpenSurfaceInvalidParams:
1.894 + testDriver->TestOpeningSurfaceInvalidParams();
1.895 + break;
1.896 + case EOpenWaitMap:
1.897 + testDriver->OpenWaitMap();
1.898 + break;
1.899 + case ECreateWaitKill:
1.900 + testDriver->CreateWaitKill();
1.901 + break;
1.902 + case EOpenClose:
1.903 + testDriver->OpenClose();
1.904 + break;
1.905 + case EMapSurfaceInfoCantAccess:
1.906 + testDriver->MapSurfaceInfoCantAccess();
1.907 + break;
1.908 + case EReadFromBuffer:
1.909 + testDriver->TestReadFromBufferInSecondProcess();
1.910 + break;
1.911 + case ECheckHandle:
1.912 + testDriver->TestCheckHandleInSecondProcess();
1.913 + break;
1.914 + case ESyncOperation:
1.915 + testDriver->TestCheckSyncOperation();
1.916 + break;
1.917 + case ETestChannelMultiProcess1:
1.918 + testDriver->TestMultipleChannelsInSecondProcess1();
1.919 + break;
1.920 + case ETestChannelMultiProcess2:
1.921 + testDriver->TestMultipleChannelsInSecondProcess2();
1.922 + break;
1.923 + case EGetSurfaceHint:
1.924 + testDriver->TestGetSurfaceHint();
1.925 + break;
1.926 + case ESetSurfaceHint:
1.927 + testDriver->TestSetSurfaceHint();
1.928 + break;
1.929 + case EAddSurfaceHint:
1.930 + testDriver->TestAddSurfaceHint();
1.931 + break;
1.932 + case ECheckOutofMemory:
1.933 +#ifdef _DEBUG
1.934 + testDriver->TestOutofMemory();
1.935 +#endif
1.936 + break;
1.937 + default:
1.938 + User::Leave(KErrArgument);
1.939 + break;
1.940 + }
1.941 + CleanupStack::PopAndDestroy(testDriver);
1.942 +
1.943 + // Handle check
1.944 + TInt procHandles2 =0;
1.945 + TInt threadHandles2=0;
1.946 + RThread().HandleCount(procHandles2,threadHandles2);
1.947 + if (threadHandles1 != threadHandles2)
1.948 + {
1.949 + User::Leave(KErrGeneral); // Thread-owned handles not closed
1.950 + }
1.951 +
1.952 +
1.953 + test.End();
1.954 + test.Close();
1.955 + }
1.956 +
1.957 +// Cleanup stack harness
1.958 +GLDEF_C TInt E32Main()
1.959 + {
1.960 + __UHEAP_MARK;
1.961 + CTrapCleanup* cleanupStack = CTrapCleanup::New();
1.962 + TRAPD(error, MainL());
1.963 + _LIT(KTSecondProcessPanic,"tsecondprocessmain");
1.964 + __ASSERT_ALWAYS(!error, User::Panic(KTSecondProcessPanic, error));
1.965 + delete cleanupStack;
1.966 + __UHEAP_MARKEND;
1.967 + return 0;
1.968 + }