graphicscomposition/openwfsupport/test/tstreamoperation/tnativestream.cpp
changeset 152 9f1c3fea0f87
parent 111 29ddb8a72f0e
equal deleted inserted replaced
111:29ddb8a72f0e 152:9f1c3fea0f87
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    21 #include <graphics/extensioncontainer.h>
    21 #include <graphics/extensioncontainer.h>
    22 #include <graphics/suerror.h>
    22 #include <graphics/suerror.h>
    23 #include <test/extendtef.h>
    23 #include <test/extendtef.h>
    24 #include <dispchannel.h>
    24 #include <dispchannel.h>
    25 #include <hal.h>
    25 #include <hal.h>
       
    26 #include <test/singletontestexithelper.inl>
    26 #include "tnativestream.h"
    27 #include "tnativestream.h"
    27 #include "surfaceutility.h"
    28 #include "surfaceutility.h"
    28 #include "owftestexithelper.inl"
    29 
       
    30 #ifdef EGLSYNCHELPER_INCLUDED
       
    31     #include <EGL/egl.h>
       
    32     #include "eglsynchelper.h"
       
    33 #endif
    29 
    34 
    30 #define BUFFER_READ_HANDLE_BASE  0x100
    35 #define BUFFER_READ_HANDLE_BASE  0x100
    31 #define BUFFER_WRITE_HANDLE_BASE 0x200
    36 #define BUFFER_WRITE_HANDLE_BASE 0x200
    32 #define INDEX_TO_READ_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_READ_HANDLE_BASE))
    37 #define INDEX_TO_READ_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_READ_HANDLE_BASE))
    33 #define INDEX_TO_WRITE_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_WRITE_HANDLE_BASE))
    38 #define INDEX_TO_WRITE_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_WRITE_HANDLE_BASE))
   241 	
   246 	
   242 	return ns;
   247 	return ns;
   243 	}
   248 	}
   244 
   249 
   245 RSemaphore      gSemaphore;
   250 RSemaphore      gSemaphore;
       
   251 RSemaphore      gSemaphore2;
   246 
   252 
   247 TGlobalNativeStreamVar	gVarInstance={0};
   253 TGlobalNativeStreamVar	gVarInstance={0};
   248 const TGlobalNativeStreamVar& TGlobalNativeStreamVar::Instance()
   254 const TGlobalNativeStreamVar& TGlobalNativeStreamVar::Instance()
   249 	{
   255 	{
   250 	return gVarInstance;
   256 	return gVarInstance;
   460 
   466 
   461 		// Test with 1, 2 and 3 buffers
   467 		// Test with 1, 2 and 3 buffers
   462 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0140L,1,4);
   468 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0140L,1,4);
   463 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0141L,1,4);
   469 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0141L,1,4);
   464 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0142L);
   470 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0142L);
       
   471         ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0143L);
       
   472         ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0144L);
   465 
   473 
   466 	END_SUITE;	
   474 	END_SUITE;	
   467 	
   475 	
   468 	}
   476 	}
   469 
   477 
   539     ASSERT_TRUE(err == KErrNone);
   547     ASSERT_TRUE(err == KErrNone);
   540     SymbianStreamReleaseReadBuffer(ns,bufferHandle);
   548     SymbianStreamReleaseReadBuffer(ns,bufferHandle);
   541 	gVarInstance.SetSurfaceID(*checkId);
   549 	gVarInstance.SetSurfaceID(*checkId);
   542     gSemaphore.CreateLocal(1);
   550     gSemaphore.CreateLocal(1);
   543     gSemaphore.Wait(); 
   551     gSemaphore.Wait(); 
       
   552     gSemaphore2.CreateLocal(1);
       
   553     gSemaphore2.Wait(); 
   544     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
   554     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
   545 	}
   555 	}
   546 
   556 
   547 void CTestNativeStream::DestroySharedNativeStreamL()
   557 void CTestNativeStream::DestroySharedNativeStreamL()
   548 	{
   558 	{
   549 	GrowCleanupStackL();
   559 	GrowCleanupStackL();
   550 	
   560 	
   551 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(COpenWfcStreamMap::InstanceL().GetMainHeap())));
   561 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(COpenWfcStreamMap::InstanceL().GetMainHeap())));
   552 	
   562 	
       
   563     gSemaphore2.Close();
   553 	gSemaphore.Close();
   564 	gSemaphore.Close();
   554 	TSurfaceId id = gVarInstance.SurfaceID();
   565 	TSurfaceId id = gVarInstance.SurfaceID();
   555 	SymbianStreamType ns;
   566 	SymbianStreamType ns;
   556 	TInt err = SymbianStreamFind(&id,&ns);
   567 	TInt err = SymbianStreamFind(&id,&ns);
   557 	ASSERT_TRUE(err == KErrNone);
   568 	ASSERT_TRUE(err == KErrNone);
   654     ASSERT_TRUE(err == KErrNone);
   665     ASSERT_TRUE(err == KErrNone);
   655     long bufferIndex;
   666     long bufferIndex;
   656     const TSurfaceId* getId = NULL;
   667     const TSurfaceId* getId = NULL;
   657     err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
   668     err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
   658     ASSERT_TRUE(err == KErrNone);
   669     ASSERT_TRUE(err == KErrNone);
       
   670     TInt ChunkHandle = 100;
       
   671     err = SymbianStreamGetChunkHandle(ns, &ChunkHandle);
       
   672     ASSERT_TRUE(err == KErrNone);    
   659     err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
   673     err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
   660     ASSERT_TRUE(err == KErrNone);
   674     ASSERT_TRUE(err == KErrNone);    
   661 	ASSERT_EQUALS(*getId,surface);
   675 	ASSERT_EQUALS(*getId,surface);
   662 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
   676 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
   663 	
   677 	
   664 	TSurfaceId surface2=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
   678 	TSurfaceId surface2=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
   665 	ASSERT_FALSE(surface2.IsNull());
   679 	ASSERT_FALSE(surface2.IsNull());
   667 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
   681 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
   668 	SymbianStreamType ns2;
   682 	SymbianStreamType ns2;
   669 	err = SymbianStreamAcquire(&surface2,&ns2);
   683 	err = SymbianStreamAcquire(&surface2,&ns2);
   670 	ASSERT_TRUE(err == KErrNone);
   684 	ASSERT_TRUE(err == KErrNone);
   671 	ASSERT_TRUE(ns2);
   685 	ASSERT_TRUE(ns2);
   672 	ASSERT_NOT_EQUALS(ns,ns2);
   686 	ASSERT_FALSE(SymbianStreamSame(ns, ns2));
   673 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 2);
   687 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 2);
   674 	err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
   688 	err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
   675 	ASSERT_TRUE(err == KErrNone);
   689 	ASSERT_TRUE(err == KErrNone);
   676     const TSurfaceId* getId2 = NULL;
   690     const TSurfaceId* getId2 = NULL;
   677     err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
   691     err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
  1341 	ASSERT_EQUALS(bufferIndex, (khronos_int32_t)1);
  1355 	ASSERT_EQUALS(bufferIndex, (khronos_int32_t)1);
  1342 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i acquired"), bufferIndex);
  1356 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i acquired"), bufferIndex);
  1343 	
  1357 	
  1344 	gSemaphore.Signal(2); // Thread 2 and 3 ready to run
  1358 	gSemaphore.Signal(2); // Thread 2 and 3 ready to run
  1345 	
  1359 	
  1346 	gSemaphore.Wait();
  1360 	gSemaphore2.Wait();
       
  1361     gSemaphore2.Wait();     // Wait for both threads to signal
  1347 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
  1362 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
  1348 	ASSERT_TRUE(err == KErrNone);
  1363 	ASSERT_TRUE(err == KErrNone);
  1349 	SymbianStreamRemoveReference(ns);
  1364 	SymbianStreamRemoveReference(ns);
  1350 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i released"), bufferIndex);
  1365 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i released"), bufferIndex);
  1351 
  1366 
  1373 	ASSERT_TRUE(err != KErrBadHandle);
  1388 	ASSERT_TRUE(err != KErrBadHandle);
  1374 	INFO_PRINTF1(_L("Thread 2 - Attempt to acquire the write buffer"));
  1389 	INFO_PRINTF1(_L("Thread 2 - Attempt to acquire the write buffer"));
  1375 	ASSERT_FALSE(writeBuffer1);
  1390 	ASSERT_FALSE(writeBuffer1);
  1376 	INFO_PRINTF1(_L("Thread 2 - Write buffer already in use by Thread 1!"));
  1391 	INFO_PRINTF1(_L("Thread 2 - Write buffer already in use by Thread 1!"));
  1377     
  1392     
  1378 	gSemaphore.Signal();
  1393 	gSemaphore2.Signal();
  1379 	
  1394 	
  1380 	gSemaphore.Wait();
  1395 	gSemaphore.Wait();
  1381 	
  1396 	
  1382 	khronos_int32_t writeBuffer2;
  1397 	khronos_int32_t writeBuffer2;
  1383 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
  1398 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
  1415  	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
  1430  	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
  1416  	ASSERT_TRUE(err != KErrBadHandle);
  1431  	ASSERT_TRUE(err != KErrBadHandle);
  1417  	INFO_PRINTF1(_L("Thread 3 - Attempt to acquire the write buffer"));
  1432  	INFO_PRINTF1(_L("Thread 3 - Attempt to acquire the write buffer"));
  1418 	ASSERT_FALSE(writeBuffer1);
  1433 	ASSERT_FALSE(writeBuffer1);
  1419 	INFO_PRINTF1(_L("Thread 3 - Write buffer already in use by Thread 1!"));
  1434 	INFO_PRINTF1(_L("Thread 3 - Write buffer already in use by Thread 1!"));
       
  1435 
       
  1436     gSemaphore2.Signal();
  1420 
  1437 
  1421     SymbianStreamRemoveReference(ns);
  1438     SymbianStreamRemoveReference(ns);
  1422     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
  1439     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
  1423 	}
  1440 	}
  1424 
  1441 
  4658     
  4675     
  4659     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
  4676     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
  4660 
  4677 
  4661     err = User::LoadLogicalDevice(KDisplayChannelLdd);
  4678     err = User::LoadLogicalDevice(KDisplayChannelLdd);
  4662     RDisplayChannel testChannel;
  4679     RDisplayChannel testChannel;
  4663     User::LeaveIfError(testChannel.Open(0));
  4680     if (err == KErrNone || err == KErrAlreadyExists)
       
  4681         {
       
  4682         User::LeaveIfError(testChannel.Open(0));
       
  4683         }
  4664     
  4684     
  4665     TSurfaceId testId;
  4685     TSurfaceId testId;
  4666     SymbianStreamType ns;
  4686     SymbianStreamType ns;
  4667     TUidPixelFormat testGuids[] = {EUidPixelFormatARGB_8888_PRE, EUidPixelFormatRGB_888, EUidPixelFormatRGB_565, EUidPixelFormatRGB_332};
  4687     TUidPixelFormat testGuids[] = {EUidPixelFormatARGB_8888_PRE, EUidPixelFormatRGB_888, EUidPixelFormatRGB_565, EUidPixelFormatRGB_332};
  4668     TInt size = sizeof(testGuids) / sizeof(testGuids[0]);
  4688     TInt size = sizeof(testGuids) / sizeof(testGuids[0]);
  4763         }
  4783         }
  4764     
  4784     
  4765     testChannel.Close();
  4785     testChannel.Close();
  4766     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
  4786     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
  4767     }
  4787     }
       
  4788 
       
  4789 /*
       
  4790 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0143
       
  4791 @SYMTestCaseDesc        Call eglsync helper functions
       
  4792 @SYMREQ                 
       
  4793 @SYMPREQ                
       
  4794 @SYMTestType            
       
  4795 @SYMTestPriority        Low
       
  4796 @SYMTestPurpose         Make calls of eglsync helper functions for coverage results                     
       
  4797 @SYMTestActions 
       
  4798         Make calls of eglsync helper functions 
       
  4799 @SYMTestExpectedResults
       
  4800         Test should pass without errors
       
  4801  */
       
  4802 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0143L()
       
  4803     {
       
  4804     // This test is commented out because it won't build for Bullseye.
       
  4805 #ifdef EGLSYNCHELPER_INCLUDED
       
  4806     INFO_PRINTF1(_L("Test of egl sync helper functions"));
       
  4807 
       
  4808     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4809     TRAPD(err, GrowCleanupStackL());
       
  4810     ASSERT_TRUE(err == KErrNone);
       
  4811     
       
  4812     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4813 
       
  4814     EGLDisplay eglDisplay;
       
  4815     eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
       
  4816     ASSERT_FALSE(eglDisplay == EGL_NO_DISPLAY);
       
  4817     ASSERT_FALSE(eglDisplay == EGL_BAD_ALLOC);
       
  4818     ASSERT_EQUALS(eglGetError(),EGL_SUCCESS);
       
  4819     eglInitialize(eglDisplay, NULL, NULL);
       
  4820     ASSERT_EQUALS(eglGetError(),EGL_SUCCESS);
       
  4821 
       
  4822     EGLint attrib_list[1] = {EGL_NONE};
       
  4823     EGLSyncKHR sync;
       
  4824     sync = eglCreateSyncKHR(eglDisplay,EGL_SYNC_REUSABLE_KHR, attrib_list);
       
  4825     ASSERT_NOT_EQUALS(sync,EGL_NO_SYNC_KHR);
       
  4826     ASSERT_EQUALS(eglGetError(),EGL_SUCCESS);
       
  4827 
       
  4828     eglSignalSyncKHR(eglDisplay, sync, EGL_SIGNALED_KHR);
       
  4829     eglGetSyncAttribKHR(eglDisplay, sync, NULL, NULL);
       
  4830     eglClientWaitSyncKHR(eglDisplay, sync, 0, 0);
       
  4831     
       
  4832     EGLBoolean eglSyncError = eglDestroySyncKHR(eglDisplay, sync);
       
  4833     sync = EGL_NO_SYNC_KHR;
       
  4834     if (eglSyncError != EGL_TRUE)
       
  4835         {
       
  4836         INFO_PRINTF2(_L("TearDown: eglSyncError line %d"),__LINE__);
       
  4837         }
       
  4838     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4839 #endif
       
  4840     }
       
  4841 
       
  4842 /*
       
  4843 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0144
       
  4844 @SYMTestCaseDesc        Panic test
       
  4845 @SYMREQ                 
       
  4846 @SYMPREQ                
       
  4847 @SYMTestType            
       
  4848 @SYMTestPriority        Low
       
  4849 @SYMTestPurpose         Test that will cause a panic.               
       
  4850 @SYMTestActions 
       
  4851         Aquire a symbian stream by passing in a NULL ns
       
  4852 @SYMTestExpectedResults
       
  4853         Test should panic with the expected panic code 1000008
       
  4854 */
       
  4855 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0144L()
       
  4856     {
       
  4857     INFO_PRINTF1(_L("Panic test. The expected panic code is 1000008"));
       
  4858     
       
  4859     SymbianStreamBuffer bufferHandle;
       
  4860     // Pass in a NULL ns will cause panic EOwfSymbianStreamBadArgument (1000008)
       
  4861     SymbianStreamAcquireReadBuffer(NULL, &bufferHandle);
       
  4862     }