egl/egltest/src/egltest_syncobject.cpp
changeset 0 5d03bc08d59c
child 18 5e30ef2e26cb
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test 
       
    19 */
       
    20 #include "egltest_syncobject.h"
       
    21 #include <test/tefunit.h>
       
    22 #include <hal.h>
       
    23 #include <test/egltestcommonsgimageinfo.h>
       
    24 
       
    25 const TUint32  KThreshold = 0.5*1000*1000; // 0.5 sec
       
    26 const TUint32  KDelaySignalling = 2.5*1000*1000; // 2.5 sec
       
    27 const TUint32  KWaitSyncTimeout = 5*1000*1000; // 5 sec
       
    28 const TUint32  KLongDelaySignalling = 7.5*1000*1000; // 7.5 sec
       
    29 const TInt 	   KNumStressIterations = 1000;
       
    30 
       
    31 typedef void 	(*TEglDebugHeapMarkStartPtr)		(void);
       
    32 typedef EGLint	(*TEglDebugHeapMarkEndPtr)			(EGLint count);
       
    33 typedef void	(*TEglDebugSetBurstAllocFailPtr)	(EGLenum type, EGLint rate, EGLint burst);
       
    34 
       
    35 struct TSurfaceToDestroy
       
    36 	{
       
    37 	EGLSurface iSurface;
       
    38 	EGLDisplay	iDisplay;
       
    39 	};
       
    40 
       
    41 //the function clean up surface resource. Needs to be push into cleanup stack beforehand
       
    42 void DestroySurface(TAny* aAny)
       
    43 	{
       
    44 	TSurfaceToDestroy* surfaceToDestroy = (TSurfaceToDestroy*)aAny;
       
    45 	eglDestroySurface(surfaceToDestroy->iDisplay, surfaceToDestroy->iSurface);
       
    46 	}
       
    47 
       
    48 CEglTest_SyncObject_Base::CEglTest_SyncObject_Base() : 
       
    49 	iSyncObject(EGL_NO_SYNC_KHR), iSyncObject1(EGL_NO_SYNC_KHR), iSyncObject2(EGL_NO_SYNC_KHR), 
       
    50 	iThreshold(KThreshold), iDelaySignalling(KDelaySignalling),
       
    51 	iWaitSyncTimeout(KWaitSyncTimeout), iLongDelaySignalling(KLongDelaySignalling),
       
    52 	iNumStressIterations(KNumStressIterations)
       
    53 	{
       
    54 	}
       
    55 
       
    56 CEglTest_SyncObject_Base::~CEglTest_SyncObject_Base()
       
    57 	{
       
    58 	if(iPfnEglDestroySyncKHR)
       
    59 	    {
       
    60 	    iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
    61 	    iPfnEglDestroySyncKHR(iDisplay, iSyncObject1);
       
    62 	    iPfnEglDestroySyncKHR(iDisplay, iSyncObject2);
       
    63 	    }
       
    64 	CleanAll();
       
    65 	}
       
    66 
       
    67 // from CTestStep
       
    68 TVerdict CEglTest_SyncObject_Base::doTestStepPreambleL()
       
    69 	{
       
    70 	INFO_PRINTF1(_L("CEglTest_SyncObject_Base::doTestStepPreambleL()"));
       
    71 	CEglTestStep::doTestStepPreambleL();
       
    72 	TInt res = HAL::Get(HALData::ENanoTickPeriod, iTickPeriodMicroSeconds);
       
    73 	if(res != KErrNone)
       
    74 		{
       
    75 		ERR_PRINTF2(_L("Can't retrieve tick period, err %d"), res);
       
    76 		User::Leave(res);
       
    77 		}
       
    78 	INFO_PRINTF2(_L("Tick period in micro seconds %d"), iTickPeriodMicroSeconds);
       
    79 	
       
    80 	_LIT(KSectionSyncObject, "SyncObject");
       
    81 	_LIT(KKeyThreshold, "Threshold");
       
    82 	_LIT(KKeyDelaySignalling, "DelaySignalling");
       
    83 	_LIT(KKeyWaitSyncTimeout, "WaitSyncTimeout");
       
    84 	_LIT(KKeyLongDelaySignalling, "LongDelaySignalling");
       
    85 	_LIT(KKeyNumStressIterations, "NumIterations");
       
    86 
       
    87 	//retrive all setting from INI file
       
    88 	GetIntFromConfig(KSectionSyncObject, KKeyThreshold, iThreshold);
       
    89 	GetIntFromConfig(KSectionSyncObject, KKeyDelaySignalling, iDelaySignalling);
       
    90 	GetIntFromConfig(KSectionSyncObject, KKeyWaitSyncTimeout, iWaitSyncTimeout);
       
    91 	GetIntFromConfig(KSectionSyncObject, KKeyLongDelaySignalling, iLongDelaySignalling);
       
    92 	GetIntFromConfig(KSectionSyncObject, KKeyNumStressIterations, iNumStressIterations);
       
    93 	
       
    94 	INFO_PRINTF2(_L("Level of tolerance %d"), iThreshold);
       
    95 	INFO_PRINTF2(_L("Delay before the signal occurs  %d"), iDelaySignalling);
       
    96 	INFO_PRINTF2(_L("Timeout client waits on sync object %d"), iWaitSyncTimeout);
       
    97 	INFO_PRINTF2(_L("Long delay before signalling occurs %d"), iLongDelaySignalling);
       
    98 	INFO_PRINTF2(_L("Number of iterations before stress test exits %d"), iNumStressIterations);
       
    99 
       
   100 	INFO_PRINTF1(_L("Check if the Sync object Khronos extension is supported"));
       
   101 	iIsSyncObjectExtensionSupported = CheckForExtensionL(KEGL_KHR_reusable_sync);
       
   102 
       
   103     INFO_PRINTF1(_L("Check if the Sync object private extension is supported"));
       
   104 	iIsSyncObjectPrivateExtensionSupported = CheckForExtensionL(KEGL_NOK__private__signal_sync);
       
   105 	
       
   106 	CleanAll();
       
   107     TEST(GetProcAddress());
       
   108 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Base::doTestStepPreambleL()"));
       
   109 	return TestStepResult();
       
   110 	}
       
   111 
       
   112 void CEglTest_SyncObject_Base::CreateEglSessionL()
       
   113 	{
       
   114 	delete iEglSess; //just in case it was called twice
       
   115 	iEglSess = CTestEglSession::NewL(Logger(), iDisplay, 0);
       
   116 	}
       
   117 
       
   118 void CEglTest_SyncObject_Base::CheckSyncAttrib(EGLint aAttribute, EGLint aExpectedValue)
       
   119 	{
       
   120 	EGLint value;
       
   121 	EGLBoolean res = iPfnEglGetSyncAttribKHR(iDisplay,iSyncObject,aAttribute,&value);
       
   122 	TEST(res == EGL_TRUE);
       
   123 	TEST(value == aExpectedValue);
       
   124 	
       
   125 	switch(aAttribute)
       
   126 		{
       
   127 		case EGL_SYNC_TYPE_KHR:
       
   128 			{
       
   129 			if (value == EGL_SYNC_REUSABLE_KHR)
       
   130 				{
       
   131 				INFO_PRINTF1(_L("  EGL_SYNC_TYPE_KHR: EGL_SYNC_REUSABLE_KHR"));
       
   132 				}
       
   133 			else
       
   134 				{
       
   135 				ERR_PRINTF1(_L("  EGL_SYNC_TYPE_KHR: Invalid attribute"));
       
   136 				}
       
   137 			break;
       
   138 			}
       
   139 		case EGL_SYNC_STATUS_KHR:
       
   140 			{
       
   141 			if (value == EGL_SIGNALED_KHR)
       
   142 				{
       
   143 				INFO_PRINTF1(_L("  EGL_SYNC_STATUS_KHR: EGL_SIGNALED_KHR"));
       
   144 				}
       
   145 			else if (value == EGL_UNSIGNALED_KHR)
       
   146 				{
       
   147 				INFO_PRINTF1(_L("  EGL_SYNC_STATUS_KHR: EGL_UNSIGNALED_KHR"));
       
   148 				}
       
   149 			else
       
   150 				{
       
   151 				ERR_PRINTF1(_L("  EGL_SYNC_STATUS_KHR: Invalid attribute"));
       
   152 				}
       
   153 			break;
       
   154 			}
       
   155 		default:
       
   156 			{
       
   157 			ERR_PRINTF1(_L("  Invalid attribute"));
       
   158 			}
       
   159 		}
       
   160 	}
       
   161 
       
   162 /**
       
   163  Obtain extension functions for the sync object 
       
   164  */
       
   165 TBool CEglTest_SyncObject_Base::GetProcAddress()
       
   166 	{
       
   167     if(!iIsSyncObjectExtensionSupported)
       
   168         {
       
   169         INFO_PRINTF1(_L("Sync object extension is not defined in test INI file.\
       
   170 The retrieval of the pointers to the extension sync object function will be skipped"));
       
   171         return ETrue;
       
   172         }
       
   173 
       
   174     //retrieve the pointers to the EGL sync object extension functions 
       
   175     INFO_PRINTF1(_L("retrieve the pointers to the EGL sync object extension functions"));
       
   176     
       
   177 	iPfnEglCreateSyncKHR = reinterpret_cast <TFPtrEglCreateSyncKhr> (eglGetProcAddress("eglCreateSyncKHR"));
       
   178 	iPfnEglDestroySyncKHR = reinterpret_cast <TFPtrEglDestroySyncKhr> (eglGetProcAddress("eglDestroySyncKHR"));
       
   179 	iPfnEglClientWaitSyncKHR = reinterpret_cast <TFPtrEglClientWaitSyncKhr> (eglGetProcAddress("eglClientWaitSyncKHR"));
       
   180 	iPfnEglSignalSyncKHR = reinterpret_cast <TFPtrEglSignalSyncKhr> (eglGetProcAddress("eglSignalSyncKHR"));
       
   181 	iPfnEglGetSyncAttribKHR = reinterpret_cast <TFPtrEglGetSyncAttribKhr> (eglGetProcAddress("eglGetSyncAttribKHR"));
       
   182     if(iIsSyncObjectPrivateExtensionSupported)
       
   183         {
       
   184         iPfnEglPrivateSignalSyncNOK = reinterpret_cast <TFPtrEglPrivateSignalSyncNok> (eglGetProcAddress("egl_Private_SignalSyncNOK"));
       
   185         if(!iPfnEglPrivateSignalSyncNOK)
       
   186             {
       
   187             ERR_PRINTF1(_L("   Pointer to function \"egl_Private_SignalSyncNOK\" is not valid"));
       
   188             }
       
   189         }
       
   190 	if(!iPfnEglCreateSyncKHR)
       
   191 		{
       
   192 		ERR_PRINTF1(_L("   Pointer to function \"eglCreateSyncKHR\" is not valid"));
       
   193 		}
       
   194 	if(!iPfnEglDestroySyncKHR)
       
   195 		{
       
   196 		ERR_PRINTF1(_L("   Pointer to function \"eglDestroySyncKHR\" is not valid"));
       
   197 		}
       
   198 	if(!iPfnEglClientWaitSyncKHR)
       
   199 		{
       
   200 		ERR_PRINTF1(_L("   Pointer to function \"eglClientWaitSyncKHR\" is not valid"));
       
   201 		}
       
   202 	if(!iPfnEglSignalSyncKHR)
       
   203 		{
       
   204 		ERR_PRINTF1(_L("   Pointer to function \"eglSignalSyncKHR\" is not valid"));
       
   205 		}
       
   206 
       
   207 	if(!iPfnEglGetSyncAttribKHR)
       
   208 		{
       
   209 		ERR_PRINTF1(_L("   Pointer to function \"eglGetSyncAttribKHR\" is not valid"));
       
   210 		}
       
   211 
       
   212 	if(!(iPfnEglCreateSyncKHR && iPfnEglDestroySyncKHR && iPfnEglClientWaitSyncKHR 
       
   213 	        && iPfnEglSignalSyncKHR && iPfnEglGetSyncAttribKHR && 
       
   214 	        (!iIsSyncObjectPrivateExtensionSupported || (iPfnEglPrivateSignalSyncNOK))))
       
   215 		{//if the private extension is not declared in the test ini file, we won't signal the failure
       
   216 		return EFalse;
       
   217 		}
       
   218 	return ETrue;
       
   219 	}
       
   220 
       
   221 void CEglTest_SyncObject_Base::CleanAll()
       
   222 	{
       
   223 	if(iEglSess)
       
   224 		{
       
   225 		delete iEglSess;
       
   226 		iEglSess = NULL;
       
   227 		}
       
   228 	TRAPD(res, TerminateDisplayL());
       
   229 	TEST(res == KErrNone);
       
   230 	INFO_PRINTF2(_L("Display termination completed with error %d"), res);
       
   231 	
       
   232 	INFO_PRINTF1(_L("Main Thread: Calling eglReleaseThread()"));
       
   233 	ASSERT_EGL_TRUE(eglReleaseThread())
       
   234 	}
       
   235 
       
   236 /**
       
   237 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-001
       
   238 
       
   239 @SYMTestPriority 1
       
   240 
       
   241 @SYMPREQ 2400
       
   242 
       
   243 @SYMREQ 12326
       
   244 
       
   245 @SYMTestCaseDesc
       
   246 To check that current implementation support EGL sync object extension
       
   247 
       
   248 @SYMTestActions
       
   249 1.	Request supporting extension for the existing display by calling eglQueryString(...) and passing EGL_EXTENSIONS as a second parameter.
       
   250 2.	Obtain an EGL sync object extension functions by supplying the following procname to the function  void (*eglGetProcAddress(const char *procname)):
       
   251 "eglCreateSyncKHR"
       
   252 "eglDestroySyncKHR"
       
   253 "eglClientWaitSyncKHR"
       
   254 "eglSignalSyncKHR"
       
   255 "eglGetSyncAttribKHR"
       
   256 
       
   257 @SYMTestExpectedResults
       
   258 1. The function must return a string which includes space separated sub-string "EGL_KHR_reusable_sync".
       
   259 2. The pointer to the functions should be non zero.
       
   260 */
       
   261 TVerdict CEglTest_SyncObject_Positive_GetProcAddress::doTestStepL()
       
   262 	{
       
   263 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-001"));
       
   264 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_GetProcAddress::doTestStepL"));
       
   265 
       
   266    if(!iIsSyncObjectExtensionSupported)
       
   267         {
       
   268         INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   269         CleanAll();
       
   270         RecordTestResultL();
       
   271         CloseTMSGraphicsStep();
       
   272         return TestStepResult();
       
   273         }
       
   274 	
       
   275 	// check that extension "EGL_KHR_reusable_sync" is supported
       
   276 	INFO_PRINTF1(_L("Check that extension \"EGL_KHR_reusable_sync\" is supported"));
       
   277 	TEST(CheckForExtensionL(KEGL_KHR_reusable_sync));
       
   278 
       
   279 	INFO_PRINTF1(_L("Obtain EGL sync object extension functions"));
       
   280 	TEST(GetProcAddress());
       
   281 	
       
   282 	RecordTestResultL();
       
   283 	CloseTMSGraphicsStep();
       
   284 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Positive_GetProcAddress::doTestStepL"));
       
   285 	return TestStepResult();
       
   286 	}
       
   287 
       
   288 /**
       
   289 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-005
       
   290 
       
   291 @SYMTestPriority 1
       
   292 
       
   293 @SYMPREQ 2400
       
   294 
       
   295 @SYMREQ 12326
       
   296 
       
   297 @SYMTestCaseDesc
       
   298 To validate the creation and deletion of the sync object.
       
   299 
       
   300 @SYMTestActions
       
   301 1. Create sync object for the default display. NULL are specified in attribute_list. 
       
   302    The type parameter is set to EGL_SYNC_REUSABLE_KHR 
       
   303 2. Retrieve the following attributes of the sync object: EGL_SYNC_TYPE_KHR , 
       
   304    EGL_SYNC_STATUS_KHR
       
   305 3. Delete the sync object 
       
   306 4. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   307    The type parameter is set to EGL_SYNC_REUSABLE_KHR 
       
   308 5. Retrieve the following attributes of the sync object: EGL_SYNC_TYPE_KHR , 
       
   309    EGL_SYNC_STATUS_KHR
       
   310 6. Delete the sync object 
       
   311    
       
   312 @SYMTestExpectedResults
       
   313 1. Sync object handle doesn't equal to EGL_NO_SYNC_KHR 
       
   314 2. Sync object attribute EGL_SYNC_STATUS_KHR should be set to EGL_UNSIGNALED_KHR by default,  
       
   315    attribute EGL_SYNC_TYPE_KHR should be set to EGL_SYNC_REUSABLE_KHR
       
   316 4. Sync object handle doesn't equal to EGL_NO_SYNC_KHR 
       
   317 5. Sync object attribute EGL_SYNC_STATUS_KHR should be set to EGL_UNSIGNALED_KHR by default,  
       
   318    attribute EGL_SYNC_TYPE_KHR should be set to EGL_SYNC_REUSABLE_KHR
       
   319  */
       
   320 TVerdict CEglTest_SyncObject_Positive_CreateDestroy::doTestStepL()
       
   321 	{
       
   322 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-005"));
       
   323 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_CreateDestroy::doTestStepL"));
       
   324 	
       
   325 	if(!iIsSyncObjectExtensionSupported)
       
   326 		{
       
   327 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   328 		CleanAll();
       
   329 		RecordTestResultL();
       
   330 		CloseTMSGraphicsStep();
       
   331 		return TestStepResult();
       
   332 		}
       
   333 		
       
   334 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   335 	GetDisplayL();
       
   336 	CreateEglSessionL();
       
   337 	iEglSess->InitializeL();
       
   338 	
       
   339 	INFO_PRINTF1(_L("Create sync object - default display, NULL at attributes, type parameter set to EGL_SYNC_REUSABLE_KHR"));
       
   340 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, NULL);
       
   341 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   342 	
       
   343 	//check attributes of the sync object.
       
   344 	INFO_PRINTF1(_L("Check attributes of sync object"));	
       
   345 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR, EGL_SYNC_REUSABLE_KHR);
       
   346 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_UNSIGNALED_KHR);
       
   347 	
       
   348 	INFO_PRINTF1(_L("Delete sync object"));
       
   349 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   350 	TEST(res == EGL_TRUE);
       
   351 	
       
   352 	INFO_PRINTF1(_L("Create sync object - default display, no attribute specified, type parameter set to EGL_SYNC_REUSABLE_KHR "));
       
   353 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   354 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   355 	
       
   356 	INFO_PRINTF1(_L("Check attributes"));
       
   357 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR, EGL_SYNC_REUSABLE_KHR);
       
   358 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR);
       
   359 
       
   360 	INFO_PRINTF1(_L("Delete sync object"));
       
   361 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   362 	TEST(res == EGL_TRUE);
       
   363 	
       
   364 	CleanAll();
       
   365 	RecordTestResultL();
       
   366 	CloseTMSGraphicsStep();
       
   367 	return TestStepResult();
       
   368 	}
       
   369 
       
   370 /**
       
   371 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-010
       
   372 
       
   373 @SYMTestPriority 1
       
   374 
       
   375 @SYMPREQ 2400
       
   376 
       
   377 @SYMREQ 12326
       
   378 
       
   379 @SYMTestCaseDesc
       
   380 To check that transition from EGL_UNSIGNALED_KHR to EGL_SIGNALED_KHR state will trigger the signal and unblock the client thread  
       
   381 
       
   382 @SYMTestActions
       
   383 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   384    The type parameter is set to EGL_SYNC_REUSABLE_KHR  
       
   385 2. Launch thread A
       
   386 3. Wait on sync object by calling eglClientWaitSyncKHR  
       
   387 4. Signal on the sync object from thread A with the flag EGL_SIGNALED_KHR
       
   388 5. Retrieve EGL_SYNC_STATUS_KHR attribute
       
   389 6. Delete the sync object
       
   390    
       
   391 @SYMTestExpectedResults
       
   392 3. The main thread is blocked
       
   393 4. After the signal the main thread should be unblocked and the value returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR
       
   394 5. Status attribute is set to EGL_SIGNALED_KHR
       
   395 */
       
   396 TVerdict CEglTest_SyncObject_Positive_WaitSignal::doTestStepL()
       
   397 	{
       
   398 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-010"));
       
   399 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_WaitSignal::doTestStepL"));
       
   400 		
       
   401 	if(!iIsSyncObjectExtensionSupported)
       
   402 		{
       
   403 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   404 		CleanAll();
       
   405 		RecordTestResultL();
       
   406 		CloseTMSGraphicsStep();
       
   407 		return TestStepResult();
       
   408 		}
       
   409 
       
   410 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   411 	GetDisplayL();
       
   412 	CreateEglSessionL();
       
   413 	iEglSess->InitializeL();
       
   414 	
       
   415 	//create sync object
       
   416 	INFO_PRINTF1(_L("Create sync object"));
       
   417 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   418 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   419 	
       
   420 	//launch threadA
       
   421 	Test_MultiThreadL(1, EFalse);
       
   422 	
       
   423 	//Stall the main thread
       
   424 	TUint32 timestampBefore = User::NTickCount();	//microsecond
       
   425 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
   426 	TUint32 timestampAfter = User::NTickCount();
       
   427 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   428 	
       
   429 	INFO_PRINTF4(_L("Main thread waited on eglClientWaitSyncKHR for %d usec (threshold was [%d +- %d])"),timeElapsed, iDelaySignalling, iThreshold);
       
   430 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   431 	TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
   432 			
       
   433 	INFO_PRINTF1(_L("Check attributes of sync object"));	
       
   434 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
   435 
       
   436 	INFO_PRINTF1(_L("Delete sync object"));
       
   437 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   438 	TEST(res == EGL_TRUE);
       
   439 	
       
   440 	CleanAll();
       
   441 	RecordTestResultL();
       
   442 	CloseTMSGraphicsStep();
       
   443 	return TestStepResult();
       
   444 	}
       
   445 
       
   446 void CEglTest_SyncObject_Positive_WaitSignal::doThreadFunctionL(TInt aIdx)
       
   447 	{
       
   448 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_WaitSignal::doThreadFunctionL, Thread %d"),aIdx);
       
   449 	ASSERT_TRUE(aIdx==0);
       
   450 	
       
   451 	User::After(iDelaySignalling);
       
   452 	
       
   453 	INFO_PRINTF1(_L("signal sync object from thread A"));
       
   454 	EGLBoolean res = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,EGL_SIGNALED_KHR);
       
   455 	TEST(res == EGL_TRUE);
       
   456 	}
       
   457 
       
   458 /**
       
   459 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-015
       
   460 
       
   461 @SYMTestPriority 1
       
   462 
       
   463 @SYMPREQ 2400
       
   464 
       
   465 @SYMREQ 12326
       
   466 
       
   467 @SYMTestCaseDesc
       
   468 To check that the client will not be blocked by waiting on the sync object 
       
   469 if the latter is in EGL_SIGNALED_KHR state and will stay blocked until 
       
   470 transition from unsignal to signal state occurs.
       
   471 To check that eglSignalSyncKHR sets the state of the sync object correctly.
       
   472 
       
   473 @SYMTestActions
       
   474 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   475    The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
   476 2. Call eglSignalSyncKHR with EGL_SIGNALED_KHR as a parameter.
       
   477 3. Retrieve an EGL_SYNC_STATUS_KHR attribute.
       
   478 4. Try to wait on the sync object by calling eglClientWaitSyncKHR.
       
   479 5. Call eglSignalSyncKHR with EGL_UNSIGNALED_KHR as a parameter.
       
   480 6. Retrieve an EGL_SYNC_STATUS_KHR attribute. 
       
   481 7. Launch thread A.
       
   482 8. Waiting on the sync object by calling eglClientWaitSyncKHR.
       
   483 9. From thread A call eglSignalSyncKHR with EGL_UNSIGNALED_KHR as a parameter. 
       
   484 10. From thread A retrieve EGL_SYNC_STATUS_KHR attribute.
       
   485 11. From thread A call eglSignalSyncKHR with EGL_SIGNALED_KHR as a parameter.
       
   486 12. From thread A retrieve EGL_SYNC_STATUS_KHR attribute.
       
   487 13  Delete the sync object.
       
   488 
       
   489 @SYMTestExpectedResults
       
   490 3. EGL_SYNC_STATUS_KHR attribute is set to EGL_SIGNALED_KHR
       
   491 4. The thread is not blocked and an error code returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR
       
   492 6. EGL_SYNC_STATUS_KHR attribute is set to EGL_UNSIGNALED_KHR
       
   493 8. Main thread is blocked
       
   494 9. Main thread stays blocked
       
   495 10. EGL_SYNC_STATUS_KHR attribute is set to EGL_UNSIGNALED_KHR
       
   496 11. Main thread is unblocked
       
   497 12. EGL_SYNC_STATUS_KHR attribute is set to EGL_SIGNALED_KHR
       
   498 */
       
   499 TVerdict CEglTest_SyncObject_Positive_WaitSignal2::doTestStepL()
       
   500 	{
       
   501 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-015"));
       
   502 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_WaitSignal2::doTestStepL"));
       
   503 		
       
   504 	if(!iIsSyncObjectExtensionSupported)
       
   505 		{
       
   506 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   507 		CleanAll();
       
   508 		RecordTestResultL();
       
   509 		CloseTMSGraphicsStep();
       
   510 		return TestStepResult();
       
   511 		}
       
   512 
       
   513 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   514 	GetDisplayL();
       
   515 	CreateEglSessionL();
       
   516 	iEglSess->InitializeL();
       
   517 		
       
   518 	INFO_PRINTF1(_L("Create sync object"));
       
   519 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   520 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   521 
       
   522 	//set to signal state, basically we are not changing anything here 
       
   523 	EGLBoolean res = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,EGL_SIGNALED_KHR);
       
   524 	TEST(res = EGL_TRUE);
       
   525 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_SIGNALED_KHR);
       
   526 
       
   527 	INFO_PRINTF1(_L("Try to wait on the sync object by calling eglClientWaitSyncKHR"));
       
   528 	TUint32 timestampBefore = User::NTickCount();	//microsecond
       
   529 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
   530 	TUint32 timestampAfter = User::NTickCount();
       
   531 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   532 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   533 	INFO_PRINTF1(_L(" Check that main thread was not stalled at eglClientWaitSyncKHR()"));
       
   534 	TEST(timeElapsed <  iThreshold);
       
   535 
       
   536 	//set to unsignal state 
       
   537 	res = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,EGL_UNSIGNALED_KHR);
       
   538 	TEST(res == EGL_TRUE);
       
   539 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_UNSIGNALED_KHR);
       
   540 	
       
   541 	//launch threadA
       
   542 	Test_MultiThreadL(1, EFalse);
       
   543 	
       
   544 	//Stall the main thread
       
   545 	timestampBefore = User::NTickCount();
       
   546 	resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
   547 	timestampAfter = User::NTickCount();
       
   548 	timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   549 	
       
   550 	INFO_PRINTF5(_L("Main thread waited on eglClientWaitSyncKHR for %d usec (threshold was [%d + %d +- %d])"),timeElapsed, iDelaySignalling*2, iTimeOverhead, iThreshold);
       
   551 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   552 	TEST(Abs(timeElapsed - (iDelaySignalling*2 + iTimeOverhead)) < iThreshold);
       
   553 
       
   554 	INFO_PRINTF1(_L("Delete sync object"));
       
   555 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   556 	TEST(res == EGL_TRUE);
       
   557 	
       
   558 	CleanAll();
       
   559 	RecordTestResultL();
       
   560 	CloseTMSGraphicsStep();
       
   561 	return TestStepResult();
       
   562 	}
       
   563 
       
   564 void CEglTest_SyncObject_Positive_WaitSignal2::doThreadFunctionL(TInt aIdx)
       
   565 	{
       
   566 	TUint32 timeOverheadStart = User::NTickCount();
       
   567 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_WaitSignal2::doThreadFunctionL, Thread %d"),aIdx);
       
   568 	ASSERT_TRUE(aIdx==0);
       
   569 	
       
   570 	User::After(iDelaySignalling);
       
   571 	INFO_PRINTF1(_L("unsignal sync object from thread A"));
       
   572 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_UNSIGNALED_KHR);
       
   573 	TEST(resSignal == EGL_TRUE);
       
   574 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_UNSIGNALED_KHR);
       
   575 	
       
   576 	User::After(iDelaySignalling);
       
   577 	INFO_PRINTF1(_L("signal sync object from thread A"));
       
   578 	TUint32 timeOverheadEnd = User::NTickCount();
       
   579 	iTimeOverhead = ElapsedTime(timeOverheadEnd, timeOverheadStart) - iDelaySignalling*2;
       
   580 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
   581 	TEST(resSignal == EGL_TRUE);
       
   582 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_SIGNALED_KHR);
       
   583 	}
       
   584 
       
   585 /**
       
   586 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-020
       
   587 
       
   588 @SYMTestPriority 1
       
   589 
       
   590 @SYMPREQ 2400
       
   591 
       
   592 @SYMREQ 12326
       
   593 
       
   594 @SYMTestCaseDesc
       
   595 To check that the deletion of the sync object triggers the signalling 
       
   596 
       
   597 @SYMTestActions
       
   598 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   599    The type parameter is set to EGL_SYNC_REUSABLE_KHR 
       
   600 2. Launch a thread A
       
   601 3. Stall the main thread by calling eglClientWaitSyncKHR() on the sync object with timeout value EGL_FOREVER_KHR
       
   602 4. Delete the sync object from the thread A
       
   603    
       
   604 @SYMTestExpectedResults
       
   605 3. The main thread which waits for the signal must be stalled
       
   606 4. After the sync object has been deleted the main client thread will be unblocked and an error code returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR
       
   607 */
       
   608 TVerdict CEglTest_SyncObject_Positive_WaitDelete::doTestStepL()
       
   609     {
       
   610     SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-020"));
       
   611     INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_WaitDelete::doTestStepL"));
       
   612     
       
   613 	if(!iIsSyncObjectExtensionSupported)
       
   614 		{
       
   615 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   616 		CleanAll();
       
   617 		RecordTestResultL();
       
   618 		CloseTMSGraphicsStep();
       
   619 		return TestStepResult();
       
   620 		}
       
   621 
       
   622 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   623     GetDisplayL();
       
   624     CreateEglSessionL();
       
   625 	iEglSess->InitializeL();
       
   626     
       
   627     //create sync object
       
   628     INFO_PRINTF1(_L("Create sync object"));
       
   629     iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   630     TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   631 
       
   632     //launch threadA
       
   633     Test_MultiThreadL(1, EFalse);
       
   634  
       
   635     //Stall the main thread
       
   636     TUint32 timestampBefore = User::NTickCount();  //microsecond
       
   637     EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
   638     TUint32 timestampAfter = User::NTickCount();
       
   639     TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   640     
       
   641     INFO_PRINTF4(_L("Main thread waited on eglClientWaitSyncKHR for %d usec (threshold was [%d +- %d])"),timeElapsed, iDelaySignalling, iThreshold);
       
   642     TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   643     TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
   644     
       
   645     CleanAll();
       
   646     RecordTestResultL();
       
   647     CloseTMSGraphicsStep();
       
   648     return TestStepResult();
       
   649     }
       
   650 
       
   651 void CEglTest_SyncObject_Positive_WaitDelete::doThreadFunctionL(TInt aIdx)
       
   652     {
       
   653     INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_WaitDelete::doThreadFunctionL, Thread %d"),aIdx);
       
   654 	ASSERT_TRUE(aIdx==0);
       
   655     
       
   656     User::After(iDelaySignalling);
       
   657     INFO_PRINTF1(_L("Delete sync object from thread A"));
       
   658 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   659     TEST(res == EGL_TRUE);
       
   660     }
       
   661 
       
   662 /**
       
   663 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-025
       
   664 
       
   665 @SYMTestPriority 1
       
   666 
       
   667 @SYMPREQ 2400
       
   668 
       
   669 @SYMREQ 12326
       
   670 
       
   671 @SYMTestCaseDesc
       
   672 To check that client will be unblocked once the timeout has expired even if there is no signalling occurred.
       
   673 
       
   674 @SYMTestActions
       
   675 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   676     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
   677 2.	Take the start time stamp
       
   678 3.	Call eglClientWaitSyncKHR() on the sync object with timeout value equals five seconds
       
   679 4.	Take the end timestamp
       
   680 5.	Retrieve EGL_SYNC_STATUS attribute of the sync object
       
   681 6.	Destroy the sync object
       
   682 
       
   683 @SYMTestExpectedResults
       
   684 3. The client thread should stay blocked until timeout is expired
       
   685 4. Check that (timestamp End - timestamp Before)  equals (roughly) timeout and an error code returned by 
       
   686    eglClientWaitSyncKHR is EGL_TIMEOUTE_EXPIRED_KHR
       
   687 5. The sync object attribute EGL_SYNC_STATUS is set to EGL_UNSIGNALED_KHR   
       
   688 */
       
   689 TVerdict CEglTest_SyncObject_Positive_WaitWithTimeoutExpired::doTestStepL()
       
   690 	{
       
   691 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-025"));
       
   692 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_WaitWithTimeoutExpired::doTestStepL started...."));
       
   693 
       
   694 	if(!iIsSyncObjectExtensionSupported)
       
   695 		{
       
   696 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   697 		CleanAll();
       
   698 		RecordTestResultL();
       
   699 		CloseTMSGraphicsStep();
       
   700 		return TestStepResult();
       
   701 		}
       
   702 
       
   703 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   704 	GetDisplayL();
       
   705 	CreateEglSessionL();
       
   706 	iEglSess->InitializeL();
       
   707 	
       
   708 	INFO_PRINTF1(_L("Create sync object"));
       
   709 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   710 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   711 
       
   712 	// calling wait sync without signaling the object should hit the predefined timeout if set to anything different to EGL_FOREVER_KHR
       
   713 	INFO_PRINTF2(_L("Calling eglClientWaitSyncKHR on the object with a defined timeout of %d usec"), iWaitSyncTimeout);
       
   714 	EGLTimeKHR timeoutNano = (TUint64)iWaitSyncTimeout * 1000; // EGLTimeKHR is in nanoseconds!!
       
   715 	TUint32 timestampBefore = User::NTickCount();
       
   716 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,timeoutNano);
       
   717 	TUint32 timestampAfter = User::NTickCount();
       
   718 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   719 
       
   720 	INFO_PRINTF4(_L("Waited on eglClientWaitSyncKHR for %d usec (threshold was [%d +- %d])"),timeElapsed, iWaitSyncTimeout, iThreshold);
       
   721 	TEST(resClientWait == EGL_TIMEOUT_EXPIRED_KHR);
       
   722 	TEST (Abs(timeElapsed - timeoutNano/1000) < iThreshold);
       
   723 
       
   724 	INFO_PRINTF1(_L("Check attributes..."));
       
   725 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
   726 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR);
       
   727 
       
   728 	INFO_PRINTF1(_L("Delete sync object"));
       
   729 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   730 	TEST(res == EGL_TRUE);
       
   731 
       
   732 	CleanAll();
       
   733 	RecordTestResultL();
       
   734 	CloseTMSGraphicsStep();
       
   735 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_WaitWithTimeoutExpired::doTestStepL completed!"));
       
   736 	return TestStepResult();
       
   737 	}
       
   738 
       
   739 /**
       
   740 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-030
       
   741 
       
   742 @SYMTestPriority 1
       
   743 
       
   744 @SYMPREQ 2400
       
   745 
       
   746 @SYMREQ 12326
       
   747 
       
   748 @SYMTestCaseDesc
       
   749 To check that client will be unblocked once the signalling occurs even if the timeout is not expired
       
   750 
       
   751 @SYMTestActions
       
   752 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   753     The type parameter is set to EGL_SYNC_REUSABLE_KHR.
       
   754 2.	Launch thread A
       
   755 3.	Take the start time stamp
       
   756 4.	Call eglClientWaitSyncKHR() on the sync object with timeout value equals five seconds
       
   757 5.	Signal on the sync object from thread A before timeout is expired (after 2.5 seconds).
       
   758 6.	Takes the end timestamp
       
   759 7.	Retrieve EGL_SYNC_STATUS attribute of the sync object from thread A
       
   760 8.	Destroy the sync object
       
   761 
       
   762 @SYMTestExpectedResults
       
   763 4. The client thread should be blocked
       
   764 6. The main thread is unblocked. Check that (timestamp End - timestamp Before)  equals (roughly)
       
   765    2.5 seconds and an error code returned by eglClientWaitSyncKHR is EGL_CONDITION_SATISFIED_KHR
       
   766 7. The sync object attribute EGL_SYNC_STATUS is set to EGL_SIGNALED_KHR 
       
   767 */
       
   768 TVerdict CEglTest_SyncObject_Positive_SignalBeforeTimeoutExpired::doTestStepL()
       
   769 	{
       
   770 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-030"));
       
   771 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_SignalBeforeTimeoutExpired::doTestStepL started...."));
       
   772 
       
   773 	if(!iIsSyncObjectExtensionSupported)
       
   774 		{
       
   775 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   776 		CleanAll();
       
   777 		RecordTestResultL();
       
   778 		CloseTMSGraphicsStep();
       
   779 		return TestStepResult();
       
   780 		}
       
   781 
       
   782 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   783 	GetDisplayL();
       
   784 	CreateEglSessionL();
       
   785 	iEglSess->InitializeL();
       
   786 	
       
   787 	INFO_PRINTF1(_L("Create sync object"));
       
   788 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   789 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   790 
       
   791 	INFO_PRINTF1(_L("Launching thread A..."));
       
   792 	Test_MultiThreadL(1, EFalse);
       
   793 
       
   794 	INFO_PRINTF2(_L("Main thread waiting for thread A to signal with a defined timeout of %d usec"), iWaitSyncTimeout);
       
   795 	EGLTimeKHR timeoutNano = (TUint64)iWaitSyncTimeout * 1000; // EGLTimeKHR is in nanoseconds!!
       
   796 	TUint32 timestampBefore = User::NTickCount();
       
   797 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,timeoutNano);
       
   798 	TUint32 timestampAfter = User::NTickCount();
       
   799 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   800 
       
   801 	INFO_PRINTF4(_L("Main thread waited on eglClientWaitSyncKHR for %d usec (threshold was [%d +- %d])"),timeElapsed, iDelaySignalling, iThreshold);
       
   802 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   803 	TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
   804 
       
   805 	INFO_PRINTF1(_L("Check attributes..."));
       
   806 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
   807 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
   808 
       
   809 	INFO_PRINTF1(_L("Delete sync object"));
       
   810 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   811 	TEST(res == EGL_TRUE);
       
   812 
       
   813 	CleanAll();
       
   814 	RecordTestResultL();
       
   815 	CloseTMSGraphicsStep();
       
   816 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_SignalBeforeTimeoutExpired::doTestStepL completed!"));
       
   817 	return TestStepResult();
       
   818 	}
       
   819 
       
   820 void CEglTest_SyncObject_Positive_SignalBeforeTimeoutExpired::doThreadFunctionL(TInt aIdx)
       
   821 	{
       
   822 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_SignalBeforeTimeoutExpired::doThreadFunctionL, Thread %d"),aIdx);
       
   823 	ASSERT_TRUE(aIdx==0);
       
   824 
       
   825 	INFO_PRINTF2(_L("Wait for a bit before Signal sync object, Thread %d"),aIdx);
       
   826 	User::After(iDelaySignalling);
       
   827 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
   828 	TEST(resSignal == EGL_TRUE);
       
   829 	INFO_PRINTF2(_L("Signal sync object done, Thread %d"),aIdx);
       
   830 	}
       
   831 
       
   832 /**
       
   833 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-035
       
   834 
       
   835 @SYMTestPriority 1
       
   836 
       
   837 @SYMPREQ 2400
       
   838 
       
   839 @SYMREQ 12326
       
   840 
       
   841 @SYMTestCaseDesc
       
   842 To check that client will be unblocked once the sync object has been deleted  even if the timeout is not expired
       
   843 
       
   844 @SYMTestActions
       
   845 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   846     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
   847 2.	Launch thread A
       
   848 3.	Take the start time stamp
       
   849 4.	Stall the client thread by calling eglClientWaitSyncKHR() on the sync object with timeout value equals five seconds
       
   850 5.	Destroy the sync object from thread A before timeout is expired. (2.5 seconds)
       
   851 6.	Takes the end timestamp
       
   852 7.	Retrieve EGL_SYNC_STATUS attribute of the sync object
       
   853 8.	Destroy the sync object
       
   854 
       
   855 @SYMTestExpectedResults
       
   856 4. The main client thread should be blocked
       
   857 5. The main thread is unblocked. Check that (timestamp End - timestamp Before)  equals (roughly) 
       
   858    2.5 seconds and an error code returned by eglClientWaitSyncKHR is EGL_CONDITION_SATISFIED_KHR
       
   859 7. eglGetSyncAttribKHR() returns EGL_FALSE and EGL_BAD_PARAMETER is generated
       
   860 */
       
   861 TVerdict CEglTest_SyncObject_Positive_DeleteBeforeTimeoutExpired::doTestStepL()
       
   862 	{
       
   863 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-035"));
       
   864 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_DeleteBeforeTimeoutExpired::doTestStepL started...."));
       
   865 
       
   866 	if(!iIsSyncObjectExtensionSupported)
       
   867 		{
       
   868 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   869 		CleanAll();
       
   870 		RecordTestResultL();
       
   871 		CloseTMSGraphicsStep();
       
   872 		return TestStepResult();
       
   873 		}
       
   874 
       
   875 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   876 	GetDisplayL();
       
   877 	CreateEglSessionL();
       
   878 	iEglSess->InitializeL();
       
   879 	
       
   880 	INFO_PRINTF1(_L("Create sync object"));
       
   881     iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   882     TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   883 
       
   884 	INFO_PRINTF1(_L("Launching thread A..."));
       
   885 	Test_MultiThreadL(1, EFalse);
       
   886 
       
   887 	INFO_PRINTF2(_L("Main thread waiting for thread A to signal with a defined timeout of %d usec"), iWaitSyncTimeout);
       
   888 	EGLTimeKHR timeoutNano = (TUint64)iWaitSyncTimeout * 1000; // EGLTimeKHR is in nanoseconds!!
       
   889 	TUint32 timestampBefore = User::NTickCount();
       
   890 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,timeoutNano);
       
   891 	TUint32 timestampAfter = User::NTickCount();
       
   892 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
   893 
       
   894 	INFO_PRINTF4(_L("Main thread waited on eglClientWaitSyncKHR for %d usec before sync object was deleted (threshold was [%d +- %d])"),timeElapsed, iDelaySignalling, iThreshold);
       
   895 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
   896 	TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
   897 
       
   898 	INFO_PRINTF1(_L("Check attributes..."));
       
   899 	EGLint syncTypeValue=-1;
       
   900 	EGLBoolean ret = iPfnEglGetSyncAttribKHR(iDisplay,iSyncObject,EGL_SYNC_TYPE_KHR,&syncTypeValue);
       
   901 	TEST(ret == EGL_FALSE);
       
   902 	EGLint error = eglGetError();
       
   903 	TEST(error == EGL_BAD_PARAMETER);
       
   904 	TEST(syncTypeValue == -1); // due to the error, it wasn't properly retrieved
       
   905 
       
   906 	INFO_PRINTF1(_L("(attempt to) Delete sync object (was already deleted by a worker thread)"));
       
   907 	ret = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   908 	TEST(ret == EGL_FALSE);
       
   909 	error = eglGetError();
       
   910 	TEST(error == EGL_BAD_PARAMETER);
       
   911 
       
   912 	CleanAll();
       
   913 	RecordTestResultL();
       
   914 	CloseTMSGraphicsStep();
       
   915 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_DeleteBeforeTimeoutExpired::doTestStepL completed!"));
       
   916 	return TestStepResult();
       
   917 	}
       
   918 
       
   919 void CEglTest_SyncObject_Positive_DeleteBeforeTimeoutExpired::doThreadFunctionL(TInt aIdx)
       
   920 	{
       
   921 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_DeleteBeforeTimeoutExpired::doThreadFunctionL, Thread %d"),aIdx);
       
   922 	ASSERT_TRUE(aIdx==0);
       
   923 
       
   924 	INFO_PRINTF2(_L("Wait for a bit before destroying sync object, Thread %d"),aIdx);
       
   925 	User::After(iDelaySignalling);
       
   926 	TInt res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   927 	TEST(res == EGL_TRUE);
       
   928 	INFO_PRINTF2(_L("Delete sync object done, Thread %d"),aIdx);
       
   929 	}
       
   930 
       
   931 /**
       
   932 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-040
       
   933 
       
   934 @SYMTestPriority 1
       
   935 
       
   936 @SYMPREQ 2400
       
   937 
       
   938 @SYMREQ 12326
       
   939 
       
   940 @SYMTestCaseDesc
       
   941 To check that all threads waiting for the signal on the same sync object will be unblocked before the timeout has expired.
       
   942 
       
   943 @SYMTestActions
       
   944 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
   945     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
   946 2.	Launch two threads A and B.
       
   947 3.	Call eglClientWaitSyncKHR() (from threads A and B) on the sync object with timeout value equals five seconds 
       
   948     in thread A and EGL_FOREVER_KHR in thread B.
       
   949 4.	Signal on the sync object with the flag EGL_SIGNALED_KHR from the main thread before timeout expired (after 2.5 seconds)
       
   950 5.	Retrieve EGL_SYNC_STATUS attribute of the sync object from the main thread
       
   951 6.	Destroy the sync object
       
   952 
       
   953 @SYMTestExpectedResults
       
   954 3. Threads A and B will be stalled
       
   955 4. Both threads A and B will be unblocked and a value returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR.  
       
   956 5. The sync object attribute EGL_SYNC_STATUS is set to EGL_SIGNALED_KHR
       
   957 */
       
   958 TVerdict CEglTest_SyncObject_Positive_Multithread_SignalBeforeTimeout::doTestStepL()
       
   959 	{
       
   960 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-040"));
       
   961 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Multithread_SignalBeforeTimeout::doTestStepL started...."));
       
   962 
       
   963 	if(!iIsSyncObjectExtensionSupported)
       
   964 		{
       
   965 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
   966 		CleanAll();
       
   967 		RecordTestResultL();
       
   968 		CloseTMSGraphicsStep();
       
   969 		return TestStepResult();
       
   970 		}
       
   971 
       
   972 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   973 	GetDisplayL();
       
   974 	CreateEglSessionL();
       
   975 	iEglSess->InitializeL();
       
   976 
       
   977 	INFO_PRINTF1(_L("Create sync object"));
       
   978 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
   979 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
   980 
       
   981 	INFO_PRINTF1(_L("Launching threads A and B..."));
       
   982 	Test_MultiThreadL(2, EFalse);
       
   983 
       
   984 	INFO_PRINTF1(_L("Main thread, wait for a bit before Signal sync object"));
       
   985 	User::After(iDelaySignalling);
       
   986 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
   987 	TEST(resSignal == EGL_TRUE);
       
   988 	INFO_PRINTF1(_L("Main thread Signal sync object done"));
       
   989 
       
   990 	INFO_PRINTF1(_L("Check attributes..."));
       
   991 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
   992 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
   993 
       
   994 	INFO_PRINTF1(_L("Delete sync object"));
       
   995 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
   996 	TEST(res == EGL_TRUE);
       
   997 
       
   998 	CleanAll();
       
   999 	RecordTestResultL();
       
  1000 	CloseTMSGraphicsStep();
       
  1001 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_Multithread_SignalBeforeTimeout::doTestStepL completed!"));
       
  1002 	return TestStepResult();
       
  1003 	}
       
  1004 
       
  1005 void CEglTest_SyncObject_Positive_Multithread_SignalBeforeTimeout::doThreadFunctionL(TInt aIdx)
       
  1006 	{
       
  1007 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_Multithread_SignalBeforeTimeout::doThreadFunctionL, Thread %d"), aIdx);
       
  1008 	ASSERT_TRUE(aIdx==0 || aIdx==1);
       
  1009 
       
  1010 	//Thread 0 waits for the main thread to signal the sync object, and exits
       
  1011 	if(aIdx == 0)	
       
  1012 		{
       
  1013 		INFO_PRINTF2(_L("Thread %d waiting for main thread to signal with a timeout EGL_FOREVER_KHR"), aIdx);
       
  1014 		TUint32 timestampBefore = User::NTickCount();
       
  1015 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1016 		TUint32 timestampAfter = User::NTickCount();
       
  1017 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1018 
       
  1019 		INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was signaled (threshold was [%d +- %d])"), aIdx, timeElapsed, iDelaySignalling, iThreshold);
       
  1020 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1021 		TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1022 		}
       
  1023 	//Thread 1 waits for the main thread to signal the sync object, and exits
       
  1024 	else if(aIdx == 1)
       
  1025 		{
       
  1026 		INFO_PRINTF3(_L("Thread %d waiting for main thread to signal with a defined timeout of %d"), aIdx, iWaitSyncTimeout);
       
  1027 		EGLTimeKHR timeoutNano = (TUint64)iWaitSyncTimeout * 1000; // EGLTimeKHR is in nanoseconds!!
       
  1028 		TUint32 timestampBefore = User::NTickCount();
       
  1029 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,timeoutNano);
       
  1030 		TUint32 timestampAfter = User::NTickCount();
       
  1031 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1032 
       
  1033 		INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was signaled (threshold was [%d +- %d])"), aIdx, timeElapsed, iDelaySignalling, iThreshold);
       
  1034 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1035 		TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1036 		}
       
  1037 	}
       
  1038 
       
  1039 /**
       
  1040 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-045
       
  1041 
       
  1042 @SYMTestPriority 1
       
  1043 
       
  1044 @SYMPREQ 2400
       
  1045 
       
  1046 @SYMREQ 12326
       
  1047 
       
  1048 @SYMTestCaseDesc
       
  1049 To check that a thread resumed due to timeout will not unblock another thread waiting for the signal.
       
  1050 
       
  1051 @SYMTestActions
       
  1052 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1053    The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1054 2. Launch two threads A and B.
       
  1055 3. Call eglClientWaitSyncKHR() (from threads A and B) on the sync object with timeout value equals five seconds in thread A and EGL_FOREVER_KHR in thread B.
       
  1056 4. Wait for approximately 7.5 seconds
       
  1057 5. Retrieve EGL_SYNC_STATUS attribute of the sync object from the main thread
       
  1058 6. Signal on the sync object with the flag EGL_SIGNALED_KHR from the main thread
       
  1059 7. Retrieve EGL_SYNC_STATUS attribute of the sync object from the main thread
       
  1060 8. Destroy the sync object
       
  1061 
       
  1062 @SYMTestExpectedResults
       
  1063 3.Threads A and B will be stalled
       
  1064 4. Thread A will be unblocked after approximately 5 seconds and a value returned by eglClientWaitSyncKHR() is set to EGL_TIMEOUT_EXPIRED_KHR.
       
  1065 5. EGL_SYNC_STATUS attribute of the sync object is set to EGL_UNSIGNALED_KHR
       
  1066 6. Threads B will be unblocked and a value returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR.  
       
  1067 7. The sync object attribute EGL_SYNC_STATUS is set to EGL_SIGNALED_KHR
       
  1068 */
       
  1069 TVerdict CEglTest_SyncObject_Positive_Multithread_SignalAfterTimeout::doTestStepL()
       
  1070 	{
       
  1071 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-045"));
       
  1072 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Multithread_SignalAfterTimeout::doTestStepL started...."));
       
  1073 
       
  1074 	if(!iIsSyncObjectExtensionSupported)
       
  1075 		{
       
  1076 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1077 		CleanAll();
       
  1078 		RecordTestResultL();
       
  1079 		CloseTMSGraphicsStep();
       
  1080 		return TestStepResult();
       
  1081 		}
       
  1082 
       
  1083 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1084 	GetDisplayL();
       
  1085 	CreateEglSessionL();
       
  1086 	iEglSess->InitializeL();
       
  1087 	
       
  1088 	INFO_PRINTF1(_L("Create sync object"));
       
  1089 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1090 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1091 
       
  1092 	INFO_PRINTF1(_L("Launching threads A and B..."));
       
  1093 	Test_MultiThreadL(2, EFalse);
       
  1094 	TUint32 timeOverheadStart = User::NTickCount();
       
  1095 	
       
  1096 	INFO_PRINTF1(_L("Main thread, wait for a long time, no Signal sync object yet"));
       
  1097 	User::After(iLongDelaySignalling);
       
  1098 
       
  1099 	INFO_PRINTF1(_L("Check attributes..."));
       
  1100 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1101 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR);
       
  1102 
       
  1103 	INFO_PRINTF1(_L("Main thread, Signal sync object now"));
       
  1104 	TUint32 timeOverheadEnd = User::NTickCount();
       
  1105 	iTimeOverhead = ElapsedTime(timeOverheadEnd, timeOverheadStart) - iLongDelaySignalling;
       
  1106 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  1107 	TEST(resSignal == EGL_TRUE);
       
  1108 	INFO_PRINTF1(_L("Main thread, Signal sync object done"));
       
  1109 
       
  1110 	INFO_PRINTF1(_L("Check attributes..."));
       
  1111 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1112 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
  1113 
       
  1114 	INFO_PRINTF1(_L("Delete sync object"));
       
  1115 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1116 	TEST(res == EGL_TRUE);
       
  1117 
       
  1118 	CleanAll();
       
  1119 	RecordTestResultL();
       
  1120 	CloseTMSGraphicsStep();
       
  1121 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_Multithread_SignalAfterTimeout::doTestStepL completed!"));
       
  1122 	return TestStepResult();
       
  1123 	}
       
  1124 
       
  1125 void CEglTest_SyncObject_Positive_Multithread_SignalAfterTimeout::doThreadFunctionL(TInt aIdx)
       
  1126 	{
       
  1127 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_Multithread_SignalAfterTimeout::doThreadFunctionL, Thread %d"),aIdx);
       
  1128 	ASSERT_TRUE(aIdx==0 || aIdx==1);
       
  1129 
       
  1130 	//Thread 0 waits for the main thread to signal the sync object, and exits
       
  1131 	if(aIdx == 0)	
       
  1132 		{
       
  1133 		INFO_PRINTF2(_L("Thread %d waiting for main thread to signal with a timeout EGL_FOREVER_KHR"), aIdx);
       
  1134 		TUint32 timestampBefore = User::NTickCount();
       
  1135 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1136 		TUint32 timestampAfter = User::NTickCount();
       
  1137 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1138 
       
  1139 		INFO_PRINTF6(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was signaled (threshold was [%d + %d +- %d])"), aIdx, timeElapsed, iLongDelaySignalling, iTimeOverhead, iThreshold);
       
  1140 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1141 		TEST (Abs(timeElapsed - (iLongDelaySignalling + iTimeOverhead)) < iThreshold);
       
  1142 		}
       
  1143 	//Thread 1 waits for the main thread to signal the sync object, and exits
       
  1144 	else if(aIdx == 1)
       
  1145 		{
       
  1146 		INFO_PRINTF3(_L("Thread %d waiting for main thread to signal with a defined timeout of %d"), aIdx, iWaitSyncTimeout);
       
  1147 		EGLTimeKHR timeoutNano = (TUint64)iWaitSyncTimeout * 1000; // EGLTimeKHR is in nanoseconds!!
       
  1148 		TUint32 timestampBefore = User::NTickCount();
       
  1149 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,timeoutNano);
       
  1150 		TUint32 timestampAfter = User::NTickCount();
       
  1151 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1152 
       
  1153 		INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was timeout'ed (threshold was [%d +- %d])"), aIdx, timeElapsed, iWaitSyncTimeout, iThreshold);
       
  1154 		TEST(resClientWait == EGL_TIMEOUT_EXPIRED_KHR);
       
  1155 		TEST (Abs(timeElapsed - iWaitSyncTimeout) < iThreshold);
       
  1156 		}
       
  1157 	}
       
  1158 
       
  1159 /**
       
  1160 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-050
       
  1161 
       
  1162 @SYMTestPriority 1
       
  1163 
       
  1164 @SYMPREQ 2400
       
  1165 
       
  1166 @SYMREQ 12326
       
  1167 
       
  1168 @SYMTestCaseDesc
       
  1169 To check that signalling on one sync object won't unblock the thread waiting on another sync object.
       
  1170 
       
  1171 @SYMTestActions
       
  1172 1.	Create two sync objects (S1 and S2) for the default display with no attributes are specified and the type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1173 2.	Launch two threads A and B.
       
  1174 3.	Wait on the sync objects S1 and S2 from threads A and B respectively by calling eglClientWaitSyncKHR()  with timeout set to EGL_FOREVER_KHR.
       
  1175 4.	Signal on S1 with the flag EGL_SIGNALED_KHR from main thread
       
  1176 5.	Retrieve EGL_SYNC_STATUS attribute of S1 and S2 from main thread
       
  1177 6.	Signal on S2 with the flag EGL_SIGNALED_KHR from main thread
       
  1178 7.	Retrieve EGL_SYNC_STATUS attribute of S1 and S2 from main thread
       
  1179 8.	Destroy the sync objects
       
  1180 
       
  1181 @SYMTestExpectedResults
       
  1182 3. Threads A and B will be stalled
       
  1183 4. Thread A will be unblocked and an error code returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR.
       
  1184    Thread B stays blocked.  
       
  1185 5. The S1 attribute EGL_SYNC_STATUS is set to EGL_SIGNALED_KHR, S2 attribute EGL_SYNC_STATUS is set to EGL_UNSIGNALED_KHR
       
  1186 6. Thread B will be unblocked and an error code returned by eglClientWaitSyncKHR() is set to EGL_CONDITION_SATISFIED_KHR.
       
  1187 7. The S1 & S2 attribute EGL_SYNC_STATUS is set to EGL_SIGNALED_KHR
       
  1188 */
       
  1189 TVerdict CEglTest_SyncObject_Positive_Multithread_WaitOnTwoSyncObject::doTestStepL()
       
  1190 	{
       
  1191 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-050"));
       
  1192 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Multithread_WaitOnTwoSyncObject::doTestStepL started...."));
       
  1193 
       
  1194 	if(!iIsSyncObjectExtensionSupported)
       
  1195 		{
       
  1196 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1197 		CleanAll();
       
  1198 		RecordTestResultL();
       
  1199 		CloseTMSGraphicsStep();
       
  1200 		return TestStepResult();
       
  1201 		}
       
  1202 
       
  1203 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1204 	GetDisplayL();
       
  1205 	CreateEglSessionL();
       
  1206 	iEglSess->InitializeL();
       
  1207 
       
  1208 	INFO_PRINTF1(_L("Create two sync objects"));
       
  1209 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1210 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1211 	iSyncObject2 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1212 	TESTL(iSyncObject2 != EGL_NO_SYNC_KHR);
       
  1213 
       
  1214 	INFO_PRINTF1(_L("Launching threads A and B..."));
       
  1215 	Test_MultiThreadL(2, EFalse);
       
  1216 	TUint32 timeOverheadStart = User::NTickCount();
       
  1217 	
       
  1218 	INFO_PRINTF1(_L("Main thread, wait for a bit before Signal sync object number 1"));
       
  1219 	User::After(iDelaySignalling);
       
  1220 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  1221 	TEST(resSignal == EGL_TRUE);
       
  1222 	INFO_PRINTF1(_L("Main thread Signal sync object number 1 done"));
       
  1223 
       
  1224 	INFO_PRINTF1(_L("Check attributes for sync object number 1..."));
       
  1225 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1226 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
  1227 
       
  1228 	INFO_PRINTF1(_L("Check attributes for sync object number 2..."));
       
  1229 	// the CheckSyncAttrib uses iSyncObject, so we need to replace it, and restore it later
       
  1230 	EGLSyncKHR oldSyncObject=iSyncObject;
       
  1231 	iSyncObject=iSyncObject2;
       
  1232 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR, EGL_SYNC_REUSABLE_KHR);
       
  1233 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR);
       
  1234 	iSyncObject=oldSyncObject;
       
  1235 
       
  1236 	INFO_PRINTF1(_L("Main thread, wait for a bit before Signal sync object number 2"));
       
  1237 	User::After(iDelaySignalling);
       
  1238 	
       
  1239 	TUint32 timeOverheadEnd = User::NTickCount();
       
  1240 	iTimeOverhead = ElapsedTime(timeOverheadEnd, timeOverheadStart) - iDelaySignalling*2;
       
  1241 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject2, EGL_SIGNALED_KHR);
       
  1242 	TEST(resSignal == EGL_TRUE);
       
  1243 	INFO_PRINTF1(_L("Main thread Signal sync object number 2 done"));
       
  1244 
       
  1245 	INFO_PRINTF1(_L("Check attributes for sync object number 1..."));
       
  1246 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1247 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
  1248 
       
  1249 	INFO_PRINTF1(_L("Check attributes for sync object number 2..."));
       
  1250 	oldSyncObject=iSyncObject;
       
  1251 	iSyncObject=iSyncObject2;
       
  1252 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1253 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
  1254 	iSyncObject=oldSyncObject;
       
  1255 
       
  1256 	INFO_PRINTF1(_L("Delete both sync objects"));
       
  1257 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1258 	TEST(res == EGL_TRUE);
       
  1259 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject2);
       
  1260 	TEST(res == EGL_TRUE);
       
  1261 
       
  1262 	CleanAll();
       
  1263 	RecordTestResultL();
       
  1264 	CloseTMSGraphicsStep();
       
  1265 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_Multithread_WaitOnTwoSyncObject::doTestStepL completed!"));
       
  1266 	return TestStepResult();
       
  1267 	}
       
  1268 
       
  1269 void CEglTest_SyncObject_Positive_Multithread_WaitOnTwoSyncObject::doThreadFunctionL(TInt aIdx)
       
  1270 	{
       
  1271 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_Multithread_WaitOnTwoSyncObject::doThreadFunctionL, Thread %d"),aIdx);
       
  1272 	ASSERT_TRUE(aIdx==0 || aIdx==1);
       
  1273 
       
  1274 	//Thread 0 waits for the main thread to signal the sync object, and exits
       
  1275 	if(aIdx == 0)	
       
  1276 		{
       
  1277 		INFO_PRINTF2(_L("Thread %d waiting for main thread to signal object 1 with a timeout EGL_FOREVER_KHR"), aIdx);
       
  1278 		TUint32 timestampBefore = User::NTickCount();
       
  1279 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1280 		TUint32 timestampAfter = User::NTickCount();
       
  1281 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1282 
       
  1283 		INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was signaled (threshold was [%d +- %d])"), aIdx, timeElapsed, iDelaySignalling, iThreshold);
       
  1284 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1285 		TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1286 		}
       
  1287 	//Thread 1 waits for the main thread to signal the sync object, and exits
       
  1288 	else if(aIdx == 1)	
       
  1289 		{
       
  1290 		INFO_PRINTF2(_L("Thread %d waiting for main thread to signal object 2 with a timeout EGL_FOREVER_KHR"), aIdx);
       
  1291 		TUint32 timestampBefore = User::NTickCount();
       
  1292 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject2,0,EGL_FOREVER_KHR);
       
  1293 		TUint32 timestampAfter = User::NTickCount();
       
  1294 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1295 
       
  1296 		INFO_PRINTF6(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was signaled (threshold was [%d + %d +- %d])"), aIdx, timeElapsed, 2*iDelaySignalling, iTimeOverhead, iThreshold);
       
  1297 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1298 		TEST (Abs(timeElapsed - (2*iDelaySignalling + iTimeOverhead)) < iThreshold);
       
  1299 		}
       
  1300 	}
       
  1301 
       
  1302 /**
       
  1303 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-055
       
  1304 
       
  1305 @SYMTestPriority 1
       
  1306 
       
  1307 @SYMPREQ 2400
       
  1308 
       
  1309 @SYMREQ 12326
       
  1310 
       
  1311 @SYMTestCaseDesc
       
  1312 To check that if zero timeout is passed to eglClientWaitSyncKHR(), the function just test the current status without attempt to stall the client thread.
       
  1313 
       
  1314 @SYMTestActions
       
  1315 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1316     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1317 2.	Take timestamp before
       
  1318 3.	Call eglClientWaitSyncKHR() on the sync object with timeout value equals to zero
       
  1319 4.	Take timestamp after
       
  1320 5.	Call eglSignalSyncKHR on the sync object with the flag EGL_SIGNALED_KHR
       
  1321 6.	Repeat steps 2 to 4
       
  1322 7.	Destroy the sync object
       
  1323 
       
  1324 @SYMTestExpectedResults
       
  1325 3.  The client thread is not stalled.  The function eglClientWaitSyncKHR() should return EGL_TIMEOUT_EXPIRED_KHR. 
       
  1326 4.  The difference timestamp (after - before) should be less than a half second
       
  1327 3.1 The client thread is not stalled.  The function eglClientWaitSyncKHR() should return EGL_CONDITION_SATISFIED_KHR.    
       
  1328 4.1 The difference timestamp (after - before) should be less than a half second 
       
  1329 */
       
  1330 TVerdict CEglTest_SyncObject_Positive_Wait_TestMode::doTestStepL()
       
  1331 	{
       
  1332 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-055"));
       
  1333 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Wait_TestMode::doTestStepL started...."));
       
  1334 
       
  1335 	if(!iIsSyncObjectExtensionSupported)
       
  1336 		{
       
  1337 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1338 		CleanAll();
       
  1339 		RecordTestResultL();
       
  1340 		CloseTMSGraphicsStep();
       
  1341 		return TestStepResult();
       
  1342 		}
       
  1343 
       
  1344 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1345 	GetDisplayL();
       
  1346 	CreateEglSessionL();
       
  1347 	iEglSess->InitializeL();
       
  1348 
       
  1349 	INFO_PRINTF1(_L("Create sync object"));
       
  1350 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1351 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1352 
       
  1353 	// calling wait sync without signaling the object, but with timeout set to 0 ==> no stalling
       
  1354 	INFO_PRINTF1(_L("Calling eglClientWaitSyncKHR on the object, without signaling the object, but with timeout set to 0"));
       
  1355 	TUint32 timestampBefore = User::NTickCount();
       
  1356 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,0);
       
  1357 	TUint32 timestampAfter = User::NTickCount();
       
  1358 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1359 
       
  1360 	INFO_PRINTF3(_L("Check it didn't wait on eglClientWaitSyncKHR. Elapsed time was %d usec (threshold was [%d])"),timeElapsed, iThreshold);
       
  1361 	TEST(resClientWait == EGL_TIMEOUT_EXPIRED_KHR);
       
  1362 	TEST (timeElapsed < iThreshold);
       
  1363 
       
  1364 	INFO_PRINTF1(_L("Check attributes..."));
       
  1365 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1366 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR);
       
  1367 	
       
  1368 	INFO_PRINTF1(_L("Signal sync object"));
       
  1369 	EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  1370 	TEST(resSignal == EGL_TRUE);
       
  1371 
       
  1372 	INFO_PRINTF1(_L("Repeat same step,  calling eglClientWaitSyncKHR with timeout set to 0"));
       
  1373 	timestampBefore = User::NTickCount();
       
  1374 	resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,0);
       
  1375 	timestampAfter = User::NTickCount();
       
  1376 	timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1377 
       
  1378 	INFO_PRINTF3(_L("Check it didn't wait on eglClientWaitSyncKHR. Elapsed time was %d usec (threshold was [%d])"),timeElapsed, iThreshold);
       
  1379 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1380 	TEST (timeElapsed < iThreshold);
       
  1381 
       
  1382 	INFO_PRINTF1(_L("Check attributes..."));
       
  1383 	CheckSyncAttrib(EGL_SYNC_TYPE_KHR,EGL_SYNC_REUSABLE_KHR);
       
  1384 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_SIGNALED_KHR);
       
  1385 
       
  1386 	INFO_PRINTF1(_L("Delete sync object"));
       
  1387 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1388 	TEST(res == EGL_TRUE);
       
  1389 
       
  1390 	CleanAll();
       
  1391 	RecordTestResultL();
       
  1392 	CloseTMSGraphicsStep();
       
  1393 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_Wait_TestMode::doTestStepL completed!"));
       
  1394 	return TestStepResult();
       
  1395 	}
       
  1396 
       
  1397 /**
       
  1398 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-060
       
  1399 
       
  1400 @SYMTestPriority 1
       
  1401 
       
  1402 @SYMPREQ 2400
       
  1403 
       
  1404 @SYMREQ 12326
       
  1405 
       
  1406 @SYMTestCaseDesc
       
  1407 To check that deletion of the sync object will unblock all threads waiting for the signal.
       
  1408 
       
  1409 @SYMTestActions
       
  1410 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1411     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1412 2.	Launch threads A and B
       
  1413 3.	Call eglClientWaitSyncKHR() on the sync object in main thread and thread A.
       
  1414 4.	Destroy the sync object from thread B
       
  1415 
       
  1416 @SYMTestExpectedResults
       
  1417 3. Main thread and thread A will be stalled
       
  1418 4. All client threads which waited for the signal must be unblocked as if eglSignalSyncKHR() has been called. 
       
  1419    The function eglClientWaitSyncKHR should return EGL_CONDITION_SATISFIED_KHR
       
  1420 */
       
  1421 TVerdict CEglTest_SyncObject_Positive_Multithread_Deletion::doTestStepL()
       
  1422 	{
       
  1423 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-060"));
       
  1424 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Multithread_Deletion::doTestStepL started...."));
       
  1425 
       
  1426 	if(!iIsSyncObjectExtensionSupported)
       
  1427 		{
       
  1428 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1429 		CleanAll();
       
  1430 		RecordTestResultL();
       
  1431 		CloseTMSGraphicsStep();
       
  1432 		return TestStepResult();
       
  1433 		}
       
  1434 
       
  1435 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1436 	GetDisplayL();
       
  1437 	CreateEglSessionL();
       
  1438 	iEglSess->InitializeL();
       
  1439 	
       
  1440 	INFO_PRINTF1(_L("Create sync object"));
       
  1441 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1442 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1443 
       
  1444 	INFO_PRINTF1(_L("Launching threads A and B..."));
       
  1445 	Test_MultiThreadL(2, EFalse);
       
  1446 
       
  1447 	INFO_PRINTF1(_L("Main thread waiting for thread B to destroy the sync object, with timeout EGL_FOREVER_KHR"));
       
  1448 	TUint32 timestampBefore = User::NTickCount();
       
  1449 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1450 	TUint32 timestampAfter = User::NTickCount();
       
  1451 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1452 
       
  1453 	INFO_PRINTF4(_L("Main thread waited on eglClientWaitSyncKHR for %d usec before sync object was deleted (threshold was [%d +- %d])"),timeElapsed, iDelaySignalling, iThreshold);
       
  1454 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1455 	TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1456 
       
  1457 	INFO_PRINTF1(_L("Check attributes..."));
       
  1458 	EGLint syncTypeValue=-1;
       
  1459 	EGLBoolean ret = iPfnEglGetSyncAttribKHR(iDisplay,iSyncObject,EGL_SYNC_TYPE_KHR,&syncTypeValue);
       
  1460 	TEST(ret == EGL_FALSE);
       
  1461 	EGLint error = eglGetError();
       
  1462 	TEST(error == EGL_BAD_PARAMETER);
       
  1463 	TEST(syncTypeValue == -1); // due to the error, it wasn't properly retrieved
       
  1464 
       
  1465 	INFO_PRINTF1(_L("(attempt to) Delete sync object (was already deleted by a worker thread)"));
       
  1466 	ret = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1467 	TEST(ret == EGL_FALSE);
       
  1468 	error = eglGetError();
       
  1469 	TEST(error == EGL_BAD_PARAMETER);
       
  1470 
       
  1471 	CleanAll();
       
  1472 	RecordTestResultL();
       
  1473 	CloseTMSGraphicsStep();
       
  1474 	INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_Multithread_Deletion::doTestStepL completed!"));
       
  1475 	return TestStepResult();
       
  1476 	}
       
  1477 
       
  1478 void CEglTest_SyncObject_Positive_Multithread_Deletion::doThreadFunctionL(TInt aIdx)
       
  1479 	{
       
  1480 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_Multithread_Deletion::doThreadFunctionL, Thread %d"),aIdx);
       
  1481 	ASSERT_TRUE(aIdx==0 || aIdx==1);
       
  1482 
       
  1483 	//Thread 0 waits for a the thread B to delete the sync object, and exits
       
  1484 	if(aIdx == 0)	
       
  1485 		{
       
  1486 		INFO_PRINTF2(_L("Thread %d waiting for thread B to destroy the sync object, with timeout EGL_FOREVER_KHR"), aIdx);
       
  1487 		TUint32 timestampBefore = User::NTickCount();
       
  1488 		EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1489 		TUint32 timestampAfter = User::NTickCount();
       
  1490 		TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1491 
       
  1492 		INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was deleted (threshold was [%d +- %d])"), aIdx, timeElapsed, iDelaySignalling, iThreshold);
       
  1493 		TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1494 		TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1495 		}
       
  1496 	//Thread 1 waits for a certain amount of time, deletes the sync object and exits
       
  1497 	else if(aIdx == 1)	
       
  1498 		{
       
  1499 		INFO_PRINTF2(_L("Wait for a bit before destroying sync object, Thread %d"),aIdx);
       
  1500 		User::After(iDelaySignalling);
       
  1501 		TInt res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1502 		TEST(res == EGL_TRUE);
       
  1503 		INFO_PRINTF2(_L("Delete sync object done, Thread %d"),aIdx);
       
  1504 		//This Thread now will just exit
       
  1505 		}
       
  1506 	}
       
  1507 
       
  1508 /**
       
  1509 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-065
       
  1510 
       
  1511 @SYMTestPriority 1
       
  1512 
       
  1513 @SYMPREQ 2400
       
  1514 
       
  1515 @SYMREQ 12326
       
  1516 
       
  1517 @SYMTestCaseDesc
       
  1518 To exercise sync object functionality in stress conditions.
       
  1519 
       
  1520 @SYMTestActions
       
  1521 1. Create three sync objects (S1, S2, S3) for the default display with no attributes are specified (containing only EGL_NONE). 
       
  1522    The type parameter is set to EGL_SYNC_REUSABLE_KHR.
       
  1523 2. Launch 2 threads (A and B)
       
  1524 3. Make the threads A and B waiting on sync objects S2 and S3 respectively.
       
  1525 4. Make consequential signalling in that order: Client-> A->B->Client->... for some period of time. 
       
  1526    Each thread signals the next thread in the chain and then stalls itself on the corresponding sync object. 
       
  1527    (Whenever each thread is unstalled, corresponding sync object should be reset by unsignalling it.)
       
  1528    Main thread is waiting on S1 
       
  1529 5. When the number of iteration exceeds some predefined value (by default is 1000, but could be reconfigured in ini file) the sequence, defined in step 4 will stop executing
       
  1530 6. Delete the sync objects
       
  1531 
       
  1532 @SYMTestExpectedResults
       
  1533 4. The functionality is robust, transition from "unsignaled" to "signaled" 
       
  1534 state always unblocks the threads  
       
  1535 */
       
  1536 TVerdict CEglTest_SyncObject_Positive_Stress::doTestStepL()
       
  1537 	{
       
  1538 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-065"));
       
  1539 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Stress::doTestStepL"));
       
  1540 	
       
  1541 	if(!iIsSyncObjectExtensionSupported)
       
  1542 		{
       
  1543 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1544 		CleanAll();
       
  1545 		RecordTestResultL();
       
  1546 		CloseTMSGraphicsStep();
       
  1547 		return TestStepResult();
       
  1548 		}
       
  1549 
       
  1550 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1551 	GetDisplayL();
       
  1552 	CreateEglSessionL();
       
  1553 	iEglSess->InitializeL();
       
  1554 	
       
  1555 	INFO_PRINTF1(_L("Create sync objects"));
       
  1556 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1557 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1558 	iSyncObject1 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1559 	TESTL(iSyncObject1 != EGL_NO_SYNC_KHR);
       
  1560 	iSyncObject2 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1561 	TESTL(iSyncObject2 != EGL_NO_SYNC_KHR);
       
  1562 	
       
  1563 	iLastThreadToSignal = 2;
       
  1564 	
       
  1565 	//launch threadA & threadB
       
  1566 	Test_MultiThreadL(2, EFalse);
       
  1567 	User::After(iDelaySignalling); //to allow threads start up before we signal
       
  1568 	
       
  1569 	for(TInt index = 0; index < iNumStressIterations; index++)
       
  1570 		{
       
  1571 		iLastThreadToSignal = 2;
       
  1572 		EGLBoolean 	resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject1,EGL_SIGNALED_KHR );
       
  1573 		TEST(resSignal == EGL_TRUE);
       
  1574 		
       
  1575 		EGLint res = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1576 		TEST(iLastThreadToSignal == 1);
       
  1577 		TEST(res == EGL_CONDITION_SATISFIED_KHR);
       
  1578 		resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,EGL_UNSIGNALED_KHR );//to set the status of iSyncObject EGL_UNSIGNALED_KHR
       
  1579 		TEST(resSignal == EGL_TRUE);    	
       
  1580 		User::After(0);//to yield the processor 
       
  1581 		}
       
  1582 	iStopTest = ETrue;
       
  1583 	INFO_PRINTF2(_L("Threads have been signalling for %d times"), iNumStressIterations);
       
  1584 	INFO_PRINTF1(_L("Delete sync objects"));
       
  1585 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1586 	TEST(res == EGL_TRUE);
       
  1587 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject1);
       
  1588 	TEST(res == EGL_TRUE);
       
  1589 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject2);
       
  1590 	TEST(res == EGL_TRUE);
       
  1591 	
       
  1592 	CleanAll();
       
  1593 	RecordTestResultL();
       
  1594 	CloseTMSGraphicsStep();
       
  1595 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Positive_Stress::doTestStepL"));
       
  1596 	return TestStepResult();
       
  1597 	}
       
  1598 
       
  1599 void CEglTest_SyncObject_Positive_Stress::doThreadFunctionL(TInt aIdx)
       
  1600 	{
       
  1601 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_Stress::doThreadFunctionL, Thread %d"),aIdx);
       
  1602 	ASSERT_TRUE(aIdx==0 || aIdx==1);
       
  1603 	
       
  1604 	EGLint res;
       
  1605 	if(aIdx == 0)
       
  1606 		{
       
  1607 		while(!iStopTest)
       
  1608 			{
       
  1609 			res = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject1,0,EGL_FOREVER_KHR);
       
  1610 			TEST(res == EGL_CONDITION_SATISFIED_KHR);
       
  1611 			User::After(0); //to yield the processor 
       
  1612 			if(!iStopTest)
       
  1613 				{
       
  1614 				TEST(iLastThreadToSignal == 2);
       
  1615 				EGLBoolean resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject1,EGL_UNSIGNALED_KHR );//to reset the status of iSyncObject1 EGL_UNSIGNALED_KHR
       
  1616                 TEST(resSignal == EGL_TRUE);
       
  1617                 
       
  1618 				iLastThreadToSignal = 0;
       
  1619 				resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject2,EGL_SIGNALED_KHR );
       
  1620 				TEST(resSignal == EGL_TRUE);
       
  1621 				}
       
  1622 			}
       
  1623 		}
       
  1624 	else if(aIdx == 1)
       
  1625 		{
       
  1626 		while(!iStopTest)
       
  1627 			{
       
  1628 			res = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject2,0,EGL_FOREVER_KHR);
       
  1629 			TEST(res == EGL_CONDITION_SATISFIED_KHR);
       
  1630 			User::After(0); //to yield the processor  
       
  1631 			if(!iStopTest)
       
  1632 				{
       
  1633 				TEST(iLastThreadToSignal == 0);
       
  1634 	            EGLBoolean resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject2,EGL_UNSIGNALED_KHR );//to reset the status of iSyncObject2 EGL_UNSIGNALED_KHR
       
  1635 	            TEST(resSignal == EGL_TRUE); 
       
  1636 				
       
  1637 				iLastThreadToSignal = 1;
       
  1638 				resSignal = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,EGL_SIGNALED_KHR );
       
  1639 				TEST(resSignal == EGL_TRUE);
       
  1640 				}
       
  1641 			}
       
  1642 		}
       
  1643 	}
       
  1644 
       
  1645 /**
       
  1646 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-070
       
  1647 
       
  1648 @SYMTestPriority 1
       
  1649 
       
  1650 @SYMPREQ 2400
       
  1651 
       
  1652 @SYMREQ 12326
       
  1653 
       
  1654 @SYMTestCaseDesc
       
  1655 To check that flushing of the client API (bit EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set 
       
  1656 for eglClientWaitSyncKHR()) doesn't cause any problems.
       
  1657 
       
  1658 @SYMTestActions
       
  1659 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1660    The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1661 2. Bind Open VG API.
       
  1662 3. Create and make the context current for the bound API.
       
  1663 4. Launch the thread A.
       
  1664 5. Wait on sync object by calling eglClientWaitSyncKHR(), pass on EGL_SYNC_FLUSH_COMMANDS_BIT_KHR as a flag.
       
  1665 6. Signal "EGL_UNSIGNALED_KHR" to the sync object.
       
  1666 7. Bind Open GLES API.
       
  1667 8. Repeat steps 3-6.
       
  1668 9. Repeat step 5, but client waits in test mode (timeout is set to zero)
       
  1669 10. Make no context current
       
  1670 11. Repeat steps 3-5.
       
  1671 12. Delete the sync object.
       
  1672 
       
  1673 @SYMTestExpectedResults
       
  1674 All functions succeed. Setting the flag on step 5 doesn't cause any problem.
       
  1675 9. The function eglClientWaitSyncKHR()returns  EGL_TIMEOUT_EXPIRED_KHR 
       
  1676 */
       
  1677 TVerdict CEglTest_SyncObject_Positive_WaitFlush::doTestStepL()
       
  1678 	{
       
  1679 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-070"));
       
  1680 	INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_WaitFlush::doTestStepL"));
       
  1681 	
       
  1682 	if(!iIsSyncObjectExtensionSupported)
       
  1683 		{
       
  1684 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1685 		CleanAll();
       
  1686 		RecordTestResultL();
       
  1687 		CloseTMSGraphicsStep();
       
  1688 		return TestStepResult();
       
  1689 		}
       
  1690 
       
  1691 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1692 	GetDisplayL();
       
  1693 	CreateEglSessionL();
       
  1694 	iEglSess->InitializeL();
       
  1695 	
       
  1696 	INFO_PRINTF1(_L("Create sync object"));
       
  1697 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1698 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1699 
       
  1700 	INFO_PRINTF1(_L("bind OpenVG API"));
       
  1701 	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
       
  1702 	EGLConfig currentConfig = iEglSess->GetConfigExactMatchL(EPixmapAttribsColor64K);
       
  1703 	INFO_PRINTF1(_L("Create and make the context current for the bound  API"));
       
  1704 	EGLContext context = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
       
  1705 	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
       
  1706 	
       
  1707 	//Create an OffScreen Pixmap to be used as an OpenVg target
       
  1708 	TSgImageInfoTest imageInfo = TSgImageInfoTest();
       
  1709 	imageInfo.iSizeInPixels = TSize(200, 200);
       
  1710 	imageInfo.iPixelFormat = EUidPixelFormatRGB_565;
       
  1711 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1712 	imageInfo.iUsage = ESgUsageBitOpenVgSurface;
       
  1713 #else
       
  1714     imageInfo.iUsage = ESgUsageOpenVgTarget;
       
  1715 #endif	
       
  1716 	RSgImage sgImageTarget;
       
  1717 	CleanupClosePushL(sgImageTarget);
       
  1718 	TInt ret2 = sgImageTarget.Create(imageInfo, NULL, NULL);
       
  1719 	ASSERT_EQUALS(ret2, KErrNone);
       
  1720 	EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig,&sgImageTarget, KPixmapAttribsNone );
       
  1721 	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
       
  1722 	
       
  1723 	TSurfaceToDestroy surfaceToDestroy;
       
  1724 	surfaceToDestroy.iSurface = surface;
       
  1725 	surfaceToDestroy.iDisplay = iDisplay;
       
  1726 	CleanupStack::PushL(TCleanupItem(DestroySurface, &surfaceToDestroy));
       
  1727 
       
  1728 	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
       
  1729 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
       
  1730 
       
  1731 	//launch threadA
       
  1732 	Test_MultiThreadL(1, EFalse);
       
  1733 	INFO_PRINTF1(_L("Wait on sync object by calling eglClientWaitSyncKHR(), pass on EGL_SYNC_FLUSH_COMMANDS_BIT_KHR as a flag"));
       
  1734 	TUint32 timestampBefore = User::NTickCount();
       
  1735 	EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,EGL_FOREVER_KHR);
       
  1736 	TUint32 timestampAfter = User::NTickCount();
       
  1737 	TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1738 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1739 	TEST(Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1740 	EGLBoolean resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_UNSIGNALED_KHR);
       
  1741 	TEST(resSignal == EGL_TRUE); 
       
  1742 	
       
  1743 	//make no context current
       
  1744 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
       
  1745 	
       
  1746 	//Wait for the thread to finish before starting the next part of the test.
       
  1747 	Test_MultiThread_WaitL(ETrue, TThreadStatus::ELogin);
       
  1748 	
       
  1749 	//---- the same test but for OpenGLES	
       
  1750 	INFO_PRINTF1(_L("bind OpenGLES API"));
       
  1751 	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENGL_ES_API));
       
  1752 	EGLContext context1 = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
       
  1753 	ASSERT_EGL_TRUE(context1 != EGL_NO_CONTEXT);
       
  1754 	
       
  1755 	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
       
  1756 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context1));
       
  1757 	
       
  1758 	//launch threadA
       
  1759 	Test_MultiThreadL(1, EFalse);
       
  1760 	INFO_PRINTF1(_L("Wait on sync object by calling eglClientWaitSyncKHR(), pass on EGL_SYNC_FLUSH_COMMANDS_BIT_KHR as a flag"));
       
  1761 	timestampBefore = User::NTickCount();
       
  1762 	resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,EGL_FOREVER_KHR);
       
  1763 	timestampAfter = User::NTickCount();
       
  1764 	timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1765 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1766 	TEST(Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1767 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_UNSIGNALED_KHR);
       
  1768 	TEST(resSignal == EGL_TRUE);
       
  1769 	
       
  1770 	//repeat the same, but in test mode (timeout  is set to zero)
       
  1771 	INFO_PRINTF1(_L("Wait on sync object by calling eglClientWaitSyncKHR(), pass on EGL_SYNC_FLUSH_COMMANDS_BIT_KHR as a flag"));
       
  1772 	timestampBefore = User::NTickCount();
       
  1773 	resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,0);
       
  1774 	timestampAfter = User::NTickCount();
       
  1775 	timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1776 	TEST(resClientWait == EGL_TIMEOUT_EXPIRED_KHR);//the sync object is in "unsignaled" state
       
  1777 	TEST(timeElapsed < iThreshold);
       
  1778 	resSignal = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_UNSIGNALED_KHR);
       
  1779 	TEST(resSignal == EGL_TRUE);
       
  1780 	
       
  1781 	INFO_PRINTF1(_L("Make no context current"));
       
  1782 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
       
  1783 	
       
  1784 	//Wait for the thread to finish before starting the next part of the test.
       
  1785 	Test_MultiThread_WaitL(ETrue, TThreadStatus::ELogin);
       
  1786 	
       
  1787 	//now try to wait with flushing bit on (EGL_SYNC_FLUSH_COMMANDS_BIT_KHR). The flag will be ignored
       
  1788 	//launch threadA
       
  1789 	Test_MultiThreadL(1, EFalse);
       
  1790 	
       
  1791 	INFO_PRINTF1(_L("Wait on sync object by calling eglClientWaitSyncKHR(), pass on EGL_SYNC_FLUSH_COMMANDS_BIT_KHR as a flag, when no context is current"));
       
  1792 	timestampBefore = User::NTickCount();
       
  1793 	resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,EGL_FOREVER_KHR);
       
  1794 	timestampAfter = User::NTickCount();
       
  1795 	timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1796 	TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1797 	TEST(Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1798 	
       
  1799 	eglDestroyContext(iDisplay, context1);		//Closing eglContext
       
  1800 	eglDestroyContext(iDisplay, context);		//Closing eglContext
       
  1801 	CleanupStack::PopAndDestroy(2, &sgImageTarget);
       
  1802 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  1803 	TEST(res == EGL_TRUE);
       
  1804 	
       
  1805 	CleanAll();
       
  1806 	RecordTestResultL();
       
  1807 	CloseTMSGraphicsStep();
       
  1808 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Positive_WaitFlush::doTestStepL"));
       
  1809 	return TestStepResult();
       
  1810 	}
       
  1811 
       
  1812 void CEglTest_SyncObject_Positive_WaitFlush::doThreadFunctionL(TInt aIdx)
       
  1813 	{
       
  1814 	INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_WaitFlush::doThreadFunctionL, Thread %d"),aIdx);
       
  1815 	ASSERT_TRUE(aIdx==0);
       
  1816 
       
  1817 	User::After(TTimeIntervalMicroSeconds32(iDelaySignalling));
       
  1818 	EGLBoolean res = iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  1819 	TEST(res == EGL_TRUE); 
       
  1820 	}
       
  1821 
       
  1822 /**
       
  1823 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-075
       
  1824 
       
  1825 @SYMTestPriority 1
       
  1826 
       
  1827 @SYMPREQ 2400
       
  1828 
       
  1829 @SYMREQ 12326
       
  1830 
       
  1831 @SYMTestCaseDesc
       
  1832 To check that eglTerminate() destroys sync object associated with display.
       
  1833 
       
  1834 @SYMTestActions
       
  1835 1. Create sync object for the default display. NULL are specified in attribute_list. 
       
  1836    The type parameter is set to EGL_SYNC_REUSABLE_KHR.
       
  1837 2. Call eglTerminate() without deleting the sync objects.
       
  1838 
       
  1839 @SYMTestExpectedResults
       
  1840 1. Sync object handle doesn't equal to EGL_NO_SYNC_KHR.
       
  1841 2. Test completes without any error and panic. No memory leak.
       
  1842 */
       
  1843 
       
  1844 TVerdict CEglTest_SyncObject_Positive_Terminate::doTestStepL()
       
  1845     {
       
  1846     SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-075"));
       
  1847     INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_Terminate::doTestStepL"));
       
  1848     
       
  1849     if(!iIsSyncObjectExtensionSupported)
       
  1850         {
       
  1851         INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1852         CleanAll();
       
  1853         RecordTestResultL();
       
  1854         CloseTMSGraphicsStep();
       
  1855         return TestStepResult();
       
  1856         }
       
  1857         
       
  1858     ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1859     GetDisplayL();
       
  1860     CreateEglSessionL();
       
  1861 	iEglSess->InitializeL();
       
  1862     
       
  1863     INFO_PRINTF1(_L("Create sync object - default display, NULL at attributes, type parameter set to EGL_SYNC_REUSABLE_KHR"));
       
  1864     iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, NULL);
       
  1865     TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1866     
       
  1867     //check attributes of the sync object.
       
  1868     INFO_PRINTF1(_L("Check attributes of sync object"));    
       
  1869     CheckSyncAttrib(EGL_SYNC_TYPE_KHR, EGL_SYNC_REUSABLE_KHR);
       
  1870     CheckSyncAttrib(EGL_SYNC_STATUS_KHR, EGL_UNSIGNALED_KHR);
       
  1871     
       
  1872     TRAPD(result, TerminateDisplayL());
       
  1873     TEST(result == KErrNone);
       
  1874     
       
  1875     CleanAll();
       
  1876     RecordTestResultL();
       
  1877     CloseTMSGraphicsStep();
       
  1878     return TestStepResult();
       
  1879     }
       
  1880 
       
  1881 /**
       
  1882 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-080
       
  1883 
       
  1884 @SYMTestPriority 1
       
  1885 
       
  1886 @SYMPREQ 2400
       
  1887 
       
  1888 @SYMREQ 12326
       
  1889 
       
  1890 @SYMTestCaseDesc
       
  1891 To check that eglTerminate() destroys sync object and will unblock thread waiting for the signal.
       
  1892 
       
  1893 @SYMTestActions
       
  1894 1.  Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1895     The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1896 2.  Launch thread A
       
  1897 3.  Call eglClientWaitSyncKHR() on the sync object in thread A.
       
  1898 4.  Call eglTerminate() from main thread without deleting the sync object.
       
  1899 
       
  1900 @SYMTestExpectedResults
       
  1901 1. Sync object handle doesn't equal to EGL_NO_SYNC_KHR.
       
  1902 3. Thread A will be stalled
       
  1903 4. Thread A which waited for the signal must be unblocked as if eglSignalSyncKHR() has been called. 
       
  1904    The function eglClientWaitSyncKHR should return EGL_CONDITION_SATISFIED_KHR.
       
  1905    Test completes without any error and panic. No memory leak.
       
  1906 */
       
  1907 
       
  1908 TVerdict CEglTest_SyncObject_Positive_TerminateBeforeTimeoutExpired::doTestStepL()
       
  1909     {
       
  1910     SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-080"));
       
  1911     INFO_PRINTF1(_L("CEglTest_SyncObject_Positive_TerminateBeforeTimeoutExpired::doTestStepL started...."));
       
  1912 
       
  1913     if(!iIsSyncObjectExtensionSupported)
       
  1914         {
       
  1915         INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  1916         CleanAll();
       
  1917         RecordTestResultL();
       
  1918         CloseTMSGraphicsStep();
       
  1919         return TestStepResult();
       
  1920         }
       
  1921 
       
  1922     ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  1923     GetDisplayL();
       
  1924     CreateEglSessionL();
       
  1925 	iEglSess->InitializeL();
       
  1926     
       
  1927     INFO_PRINTF1(_L("Create sync object"));
       
  1928     iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  1929     TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  1930 
       
  1931     INFO_PRINTF1(_L("Launching threads A"));
       
  1932     Test_MultiThreadL(1, EFalse);
       
  1933 
       
  1934     INFO_PRINTF1(_L("Wait for a bit before eglTerminate"));
       
  1935     User::After(iDelaySignalling);
       
  1936 
       
  1937     TRAPD(result, TerminateDisplayL());
       
  1938     TEST(result == KErrNone);
       
  1939     
       
  1940     CleanAll();
       
  1941     RecordTestResultL();
       
  1942     CloseTMSGraphicsStep();
       
  1943     INFO_PRINTF1(_L("....CEglTest_SyncObject_Positive_TerminateBeforeTimeoutExpired::doTestStepL completed!"));
       
  1944     return TestStepResult();
       
  1945     }
       
  1946 
       
  1947 void CEglTest_SyncObject_Positive_TerminateBeforeTimeoutExpired::doThreadFunctionL(TInt aIdx)
       
  1948     {
       
  1949     INFO_PRINTF2(_L("CEglTest_SyncObject_Positive_TerminateBeforeTimeoutExpired::doThreadFunctionL, Thread %d"),aIdx);
       
  1950     ASSERT_TRUE(aIdx==0);
       
  1951 
       
  1952     INFO_PRINTF2(_L("Thread %d waiting for main thread to call eglTerminate(), with timeout EGL_FOREVER_KHR"), aIdx);
       
  1953     TUint32 timestampBefore = User::NTickCount();
       
  1954     EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  1955     TUint32 timestampAfter = User::NTickCount();
       
  1956     TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  1957 
       
  1958     INFO_PRINTF5(_L("Thread %d waited on eglClientWaitSyncKHR for %d usec before sync object was destroyed by eglTerminate() (threshold was [%d +- %d])"), aIdx, timeElapsed, iDelaySignalling, iThreshold);
       
  1959     TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);
       
  1960     TEST (Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  1961     }
       
  1962 
       
  1963 /**
       
  1964 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-100
       
  1965 
       
  1966 @SYMTestPriority 1
       
  1967 
       
  1968 @SYMPREQ 2400
       
  1969 
       
  1970 @SYMREQ 12326
       
  1971 
       
  1972 @SYMTestCaseDesc
       
  1973 To ensure that sync object API generates correct errors and returns correct 
       
  1974 value if wrong parameters supplied.
       
  1975 
       
  1976 @SYMTestActions
       
  1977 1. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  1978    The type parameter is set to EGL_SYNC_REUSABLE_KHR
       
  1979 2. Call all sync API for the display which doesn't exist in the system.
       
  1980 3. Call eglCreateSyncKHR() with unsupported type parameter.
       
  1981 4. Call eglCreateSyncKHR() with specified attributes, type parameter set to EGL_SYNC_REUSABLE_KHR
       
  1982 5. Call eglCreateSyncKHR() with unspecified attributes, type parameter set to EGL_SYNC_REUSABLE_KHR
       
  1983 6. Call all sync API (with the exception to eglCreateSyncKHR(...), providing invalid EGLSyncKHR as a parameter 
       
  1984 7. Call eglClientWaitSyncKHR(), providing unspecified flags.
       
  1985 8. Call eglSignalSyncKHR(), providing unspecified status.
       
  1986 9. Call eglGetSyncAttribSyncKHR(), providing unspecified attributes.
       
  1987 10. Destroy the sync object
       
  1988 
       
  1989 @SYMTestExpectedResults
       
  1990 2. eglCreateSyncKHR(...) should return EGL_NO_SYNC_KHR and EGL_BAD_DISPLAY error is generated. 
       
  1991    eglClientWaitSyncKHR(...), eglSignalSyncKHR(...), eglGetSyncAttribKHR(...) and eglDestroySyncKHR(...) 
       
  1992    should return EGL_FALSE and EGL_BAD_DISPLAY error is generated.
       
  1993 3. Should return EGL_NO_SYNC_KHR and EGL_BAD_ATTRIBUTE error is generated.
       
  1994 4.5 Should return EGL_NO_SYNC_KHR and EGL_BAD_ATTRIBUTE error is generated.
       
  1995 6, 7, 8. Should return EGL_FALSE and EGL_BAD_PARAMETER error is generated
       
  1996 9. Should return EGL_FALSE and EGL_BAD_ATTRIBUTE error is generated
       
  1997 */
       
  1998 TVerdict CEglTest_SyncObject_Negative_WrongParameters::doTestStepL()
       
  1999 	{
       
  2000 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-100"));
       
  2001 	INFO_PRINTF1(_L("CEglTest_SyncObject_Negative_WrongParameters::doTestStepL"));
       
  2002 	
       
  2003 	if(!iIsSyncObjectExtensionSupported)
       
  2004 		{
       
  2005 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  2006 		CleanAll();
       
  2007 		RecordTestResultL();
       
  2008 		CloseTMSGraphicsStep();
       
  2009 		return TestStepResult();
       
  2010 		}
       
  2011 
       
  2012 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  2013 	GetDisplayL();
       
  2014 	CreateEglSessionL();
       
  2015 	iEglSess->InitializeL();
       
  2016 
       
  2017 	//create a sync object
       
  2018 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  2019 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  2020 	TEST(eglGetError() == EGL_SUCCESS);
       
  2021 
       
  2022 	INFO_PRINTF1(_L("Call all sync API for the display which doesn't exist in the system"));
       
  2023 	EGLDisplay	invalidDisplay = iDisplay + 1;
       
  2024 	iSyncObject1 = iPfnEglCreateSyncKHR(invalidDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  2025 	TEST(iSyncObject1 == EGL_NO_SYNC_KHR);
       
  2026 	TEST(eglGetError() == EGL_BAD_DISPLAY);
       
  2027 	EGLBoolean res = iPfnEglSignalSyncKHR(invalidDisplay,iSyncObject,EGL_UNSIGNALED_KHR );
       
  2028 	TEST(res == EGL_FALSE);
       
  2029 	TEST(eglGetError() == EGL_BAD_DISPLAY);
       
  2030 	EGLint res1 = iPfnEglClientWaitSyncKHR(invalidDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  2031 	TEST(res1 == EGL_FALSE);
       
  2032 	TEST(eglGetError() == EGL_BAD_DISPLAY);
       
  2033 	EGLint value;
       
  2034 	res = iPfnEglGetSyncAttribKHR(invalidDisplay,iSyncObject,EGL_SYNC_STATUS_KHR, &value);
       
  2035 	TEST(res == EGL_FALSE);
       
  2036 	TEST(eglGetError() == EGL_BAD_DISPLAY);
       
  2037 	res = iPfnEglDestroySyncKHR(invalidDisplay, iSyncObject);
       
  2038 	TEST(res == EGL_FALSE);
       
  2039 	TEST(eglGetError() == EGL_BAD_DISPLAY);
       
  2040 	
       
  2041 	INFO_PRINTF1(_L("Call eglCreateSyncKHR() with unsupported type parameter."));
       
  2042 	const EGLint unsupportedType = 0x3fff;
       
  2043 	iSyncObject1 = iPfnEglCreateSyncKHR(iDisplay, unsupportedType, KEglSyncAttribsNone);
       
  2044 	TEST(iSyncObject1 == EGL_NO_SYNC_KHR);
       
  2045 	TEST(eglGetError() == EGL_BAD_ATTRIBUTE);
       
  2046 	
       
  2047 	const EGLint KSpecifiedAttrib[] = {
       
  2048 								EGL_SYNC_STATUS_KHR, EGL_UNSIGNALED_KHR,
       
  2049 								EGL_NONE
       
  2050 								};
       
  2051 	INFO_PRINTF1(_L("Call eglCreateSyncKHR() with specified condition, type parameter set to EGL_SYNC_REUSABLE_KHR"));
       
  2052 	iSyncObject1 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KSpecifiedAttrib);
       
  2053 	TEST(iSyncObject1 == EGL_NO_SYNC_KHR);
       
  2054 	TEST(eglGetError() == EGL_BAD_ATTRIBUTE);
       
  2055 	
       
  2056 	INFO_PRINTF1(_L("Call eglCreateSyncKHR() with unspecified attributes, type parameter set to EGL_SYNC_REUSABLE_KHR"));
       
  2057 	const TInt KUndefinedAttrib = 0x4000; 
       
  2058 	const EGLint KUnspecifiedAttrib1[] = {	
       
  2059 								KUndefinedAttrib, EGL_UNSIGNALED_KHR,
       
  2060 								EGL_NONE
       
  2061 								};
       
  2062 	iSyncObject1 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KUnspecifiedAttrib1);
       
  2063 	TEST(iSyncObject1 == EGL_NO_SYNC_KHR);
       
  2064 	TEST(eglGetError() == EGL_BAD_ATTRIBUTE);
       
  2065 	const EGLint KUnspecifiedAttrib2[] = {	
       
  2066 								EGL_SYNC_STATUS_KHR, KUndefinedAttrib,
       
  2067 								EGL_NONE
       
  2068 								};
       
  2069 	iSyncObject1 = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KUnspecifiedAttrib2);
       
  2070 	TEST(iSyncObject1 == EGL_NO_SYNC_KHR);
       
  2071 	TEST(eglGetError() == EGL_BAD_ATTRIBUTE);
       
  2072 	
       
  2073 	INFO_PRINTF1(_L("Call all sync API (with the exception to eglCreateSyncKHR(...), providing invalid EGLSyncKHR as a parameter"));
       
  2074 	res = iPfnEglSignalSyncKHR(iDisplay,iSyncObject1,EGL_UNSIGNALED_KHR );
       
  2075 	TEST(res == EGL_FALSE);
       
  2076 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2077 	res1 = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject1,0,EGL_FOREVER_KHR);
       
  2078 	TEST(res1 == EGL_FALSE);
       
  2079 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2080 	res = iPfnEglGetSyncAttribKHR(iDisplay,iSyncObject1,EGL_SYNC_STATUS_KHR, &value);
       
  2081 	TEST(res == EGL_FALSE);
       
  2082 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2083 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject1);
       
  2084 	TEST(res == EGL_FALSE);
       
  2085 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2086 	
       
  2087 	INFO_PRINTF1(_L("Call eglClientWaitSyncKHR(), providing unspecified flags"));
       
  2088 	const TInt KUnspecifiedFlags = 0x002;
       
  2089 	res1 = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,KUnspecifiedFlags,EGL_FOREVER_KHR);
       
  2090 	TEST(res1 == EGL_FALSE);
       
  2091 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2092 		
       
  2093 	INFO_PRINTF1(_L("Call eglSignalSyncKHR(), providing unspecified status"));
       
  2094 	const EGLint unspecifiedStatus = 0x3fff;
       
  2095 	res = iPfnEglSignalSyncKHR(iDisplay,iSyncObject,unspecifiedStatus);
       
  2096 	TEST(res == EGL_FALSE);
       
  2097 	TEST(eglGetError() == EGL_BAD_PARAMETER);
       
  2098 
       
  2099 	INFO_PRINTF1(_L("Call eglGetSyncAttribSyncKHR(), providing unspecified attributes"));
       
  2100 	const EGLint unspecifiedAttribute = 0x3fff;
       
  2101 	res = iPfnEglGetSyncAttribKHR(iDisplay,iSyncObject,unspecifiedAttribute, &value);
       
  2102 	TEST(res == EGL_FALSE);
       
  2103 	TEST(eglGetError() == EGL_BAD_ATTRIBUTE);
       
  2104 	//close sync object
       
  2105 	res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  2106 	TEST(res == EGL_TRUE);
       
  2107 
       
  2108 	CleanAll();
       
  2109 	RecordTestResultL();
       
  2110 	CloseTMSGraphicsStep();
       
  2111 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Negative_WrongParameters::doTestStepL"));
       
  2112 	return TestStepResult();
       
  2113 	}
       
  2114 
       
  2115 /**
       
  2116 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-105
       
  2117 
       
  2118 @SYMTestPriority 1
       
  2119 
       
  2120 @SYMPREQ 2400
       
  2121 
       
  2122 @SYMREQ 12326
       
  2123 
       
  2124 @SYMTestCaseDesc
       
  2125 To check that internal version of the signal function, which is accessible 
       
  2126 via extension mechanism, doesn't generate an error.
       
  2127 
       
  2128 @SYMTestActions
       
  2129 1.	Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  2130     The type parameter is set to EGL_SYNC_REUSABLE_KHR.
       
  2131 2.	Call egl_Private_SignalSyncNOK() on sync object supplying invalid status
       
  2132 3.	Call eglGetError()
       
  2133 4.	Call egl_Private_SignalSyncNOK() on sync object with EGL_SIGNALED_KHR flag supplying invalid display
       
  2134 5.	Call eglGetError()
       
  2135 6.	Retrieve status attribute 
       
  2136 7.	Call eglQueryString(..) supplying invalid name parameter (for instance, "OpenGL_Wrong" ).
       
  2137 8.	Call egl_Private_SignalSyncNOK() on sync object with EGL_SIGNALED_KHR flag supplying invalid display
       
  2138 9.	Call eglGetError()
       
  2139 10. Destroy the sync object
       
  2140 
       
  2141 @SYMTestExpectedResults
       
  2142 2. The function returns EGL_BAD_ PARAMETERS
       
  2143 3. An error is set to EGL_SUCCESS
       
  2144 4. The function returns EGL_BAD_DISPLAY.
       
  2145 5. An error is set to EGL_SUCCESS
       
  2146 6. The status attributes indicates that object is still in a signaled state (EGL_UNSIGNALED_KHR)
       
  2147 8. The function returns EGL_BAD_DISPLAY.
       
  2148 9. An error is set to EGL_BAD_PARAMETER
       
  2149 */
       
  2150 TVerdict CEglTest_SyncObject_Negative_SignalImpl::doTestStepL()
       
  2151 	{
       
  2152 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-105"));
       
  2153 	INFO_PRINTF1(_L("CEglTest_SyncObject_Negative_SignalImpl::doTestStepL"));
       
  2154 	
       
  2155 	if(!iIsSyncObjectExtensionSupported || !iIsSyncObjectPrivateExtensionSupported)
       
  2156 		{
       
  2157 		INFO_PRINTF1(_L("Sync object extensions (whether EGL_KHR_reusable_sync or EGL_NOK__private__signal_sync or both) \
       
  2158 are not supported, the test will not be executed"));
       
  2159 		CleanAll();
       
  2160 		RecordTestResultL();
       
  2161 		CloseTMSGraphicsStep();
       
  2162 		return TestStepResult();
       
  2163 		}
       
  2164 
       
  2165 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  2166 	GetDisplayL();
       
  2167 	CreateEglSessionL();
       
  2168 	iEglSess->InitializeL();
       
  2169 	
       
  2170 	INFO_PRINTF1(_L("Create the sync object"));
       
  2171 	iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  2172 	TESTL(iSyncObject != EGL_NO_SYNC_KHR);
       
  2173 	
       
  2174 	INFO_PRINTF1(_L("Call egl_Private_SignalSyncNOK() on sync object supplying invalid status"));
       
  2175 	const EGLint unspecifiedMode = 0x3fff;
       
  2176 	EGLint res1 = iPfnEglPrivateSignalSyncNOK(iDisplay, iSyncObject, unspecifiedMode);
       
  2177 	TEST(res1 == EGL_BAD_PARAMETER);
       
  2178 	TEST(eglGetError() == EGL_SUCCESS);
       
  2179 	
       
  2180 	INFO_PRINTF1(_L("Call egl_Private_SignalSyncNOK() on sync object with EGL_SIGNALED_KHR flag supplying invalid display"));
       
  2181 	const EGLDisplay invalidDisplay = iDisplay + 1;
       
  2182 	res1 = iPfnEglPrivateSignalSyncNOK(invalidDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  2183 	TEST(res1 == EGL_BAD_DISPLAY);
       
  2184 	TEST(eglGetError() == EGL_SUCCESS);
       
  2185 	CheckSyncAttrib(EGL_SYNC_STATUS_KHR,EGL_UNSIGNALED_KHR); //the status is still "unsignaled"
       
  2186 	
       
  2187 	INFO_PRINTF1(_L("Call eglQueryString(..) supplying invalid name parameter ")); //the actual API doesn't matter, we need to generate an error 
       
  2188 	const TInt invalidExtension = 0xffff;
       
  2189 	const char* extensionsString = eglQueryString(iDisplay, invalidExtension); //this should generate EGL_BAD_PARAMETER
       
  2190 	TEST(!extensionsString);
       
  2191 	
       
  2192 	res1 = iPfnEglPrivateSignalSyncNOK(invalidDisplay, iSyncObject, EGL_SIGNALED_KHR);
       
  2193 	TEST(res1 == EGL_BAD_DISPLAY);
       
  2194 	TEST(eglGetError() == EGL_BAD_PARAMETER); //check that error code was not overidden
       
  2195 	
       
  2196 	EGLBoolean res = iPfnEglDestroySyncKHR(iDisplay, iSyncObject);
       
  2197 	TEST(res == EGL_TRUE);	
       
  2198 	CleanAll();
       
  2199 	RecordTestResultL();
       
  2200 	CloseTMSGraphicsStep();
       
  2201 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Negative_SignalImpl::doTestStepL"));
       
  2202 	return TestStepResult();
       
  2203 	}
       
  2204 
       
  2205 /**
       
  2206 @SYMTestCaseID GRAPHICS-EGL-SYNC-OBJECT-110
       
  2207 
       
  2208 @SYMTestPriority 1
       
  2209 
       
  2210 @SYMPREQ 2400
       
  2211 
       
  2212 @SYMREQ 12326
       
  2213 
       
  2214 @SYMTestCaseDesc
       
  2215 To check that system correctly processing errors in the environment with shortage of memory.
       
  2216 
       
  2217 @SYMTestActions
       
  2218 1. Run a loop (step 2 to 7) with fail rate counting from 1 upward until 
       
  2219    the following operations succeed
       
  2220 2. Set heap failure with the fail rate specifying in step 1
       
  2221 3. Create sync object for the default display. No attributes are specified (containing only EGL_NONE). 
       
  2222    The type parameter is set to EGL_SYNC_REUSABLE_KHR. Skip the following test steps if operation doesn't succeed
       
  2223 4. Launch thread A
       
  2224 5. Wait on the sync object
       
  2225 6. Signal from thread A on the sync object the flag EGL_SIGNALED_KHR 
       
  2226 7. Destroy the sync object
       
  2227 8. Reset heap
       
  2228 
       
  2229 @SYMTestExpectedResults
       
  2230 3. If memory is not enough to fulfil an operation EGL_NO_SYNC_KHR is returned. Otherwise it should return a handle to a valid sync object
       
  2231 5. The main thread should be stalled
       
  2232 6. The main thread should be unblocked
       
  2233 */
       
  2234 TVerdict CEglTest_SyncObject_Negative_OOM::doTestStepL()
       
  2235 	{
       
  2236 	SetTestStepID(_L("GRAPHICS-EGL-SYNC-OBJECT-110"));
       
  2237 	INFO_PRINTF1(_L("CEglTest_SyncObject_Negative_OOM::doTestStepL"));
       
  2238 #ifndef _DEBUG
       
  2239 	WARN_PRINTF1(_L("CEglTest_SyncObject_Negative_OOM can only be run in debug mode"));
       
  2240 	RecordTestResultL();
       
  2241 	CloseTMSGraphicsStep();
       
  2242 	return TestStepResult();
       
  2243 #else
       
  2244 	
       
  2245 	if(!iIsSyncObjectExtensionSupported)
       
  2246 		{
       
  2247 		INFO_PRINTF1(_L("Sync object extension is not supported, the test will not be executed"));
       
  2248 		CleanAll();
       
  2249 		RecordTestResultL();
       
  2250 		CloseTMSGraphicsStep();
       
  2251 		return TestStepResult();
       
  2252 		}
       
  2253 
       
  2254 	ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
  2255 	GetDisplayL();
       
  2256 	CreateEglSessionL();
       
  2257 	iEglSess->InitializeL();
       
  2258  	
       
  2259 	INFO_PRINTF1(_L("Retrieving the heapMark functions for memory testing..."));
       
  2260 	TEglDebugHeapMarkStartPtr		heapMarkStart			= reinterpret_cast<TEglDebugHeapMarkStartPtr>(eglGetProcAddress("egliDebugHeapMarkStart"));
       
  2261 	TEglDebugHeapMarkEndPtr			heapMarkEnd				= reinterpret_cast<TEglDebugHeapMarkEndPtr>(eglGetProcAddress("egliDebugHeapMarkEnd"));
       
  2262 	TEglDebugSetBurstAllocFailPtr	setSyncObjectAllocFail	= reinterpret_cast<TEglDebugSetBurstAllocFailPtr>(eglGetProcAddress("egliDebugSetBurstAllocFail"));
       
  2263 	TESTL(heapMarkStart && heapMarkEnd && setSyncObjectAllocFail);
       
  2264 	
       
  2265 	EGLint err = EGL_BAD_ALLOC;
       
  2266 	for(TUint failAfter=1; (err == EGL_BAD_ALLOC); ++failAfter)
       
  2267 		{
       
  2268 		__UHEAP_MARK;
       
  2269 		heapMarkStart();
       
  2270 		
       
  2271 		// Set heap failure
       
  2272 		INFO_PRINTF2(_L("Set EGL heap to fail after %u allocations"), failAfter);
       
  2273 		setSyncObjectAllocFail(static_cast<EGLenum>(RHeap::EBurstFailNext), failAfter, 742);
       
  2274 
       
  2275 		INFO_PRINTF1(_L("Create sync object"));
       
  2276 		iSyncObject = iPfnEglCreateSyncKHR(iDisplay, EGL_SYNC_REUSABLE_KHR, KEglSyncAttribsNone);
       
  2277 		err = eglGetError();
       
  2278 		if(err == EGL_SUCCESS)
       
  2279 			{
       
  2280 			TEST(iSyncObject != EGL_NO_SYNC_KHR);
       
  2281 			//launch threadA
       
  2282 			Test_MultiThreadL(1, EFalse);
       
  2283 			TUint32 timestampBefore = User::NTickCount();
       
  2284 			EGLint resClientWait = iPfnEglClientWaitSyncKHR(iDisplay,iSyncObject,0,EGL_FOREVER_KHR);
       
  2285 			TUint32 timestampAfter = User::NTickCount();
       
  2286 			TInt timeElapsed = ElapsedTime(timestampAfter, timestampBefore);
       
  2287 			TEST(resClientWait == EGL_CONDITION_SATISFIED_KHR);//we do not expect failure here, as eglClientWaitSyncKHR function doesn't allocate any memory
       
  2288 			TEST(Abs(timeElapsed - iDelaySignalling) < iThreshold);
       
  2289 			//close sync object
       
  2290 			TEST(iPfnEglDestroySyncKHR(iDisplay, iSyncObject)== EGL_TRUE);
       
  2291 			
       
  2292 			//Wait for the thread to finish before launching the thread with the same index again.
       
  2293 			Test_MultiThread_WaitL(ETrue, TThreadStatus::ELogin);
       
  2294 			}
       
  2295 		else
       
  2296 			{
       
  2297 			TEST(iSyncObject == EGL_NO_SYNC_KHR);
       
  2298 			}
       
  2299 		// Unset heap failure
       
  2300 		setSyncObjectAllocFail(static_cast<EGLenum>(RHeap::ENone), 0, 0);
       
  2301 		(void)heapMarkEnd(0);
       
  2302 		__UHEAP_MARKEND;
       
  2303 		}
       
  2304 	TEST(err == EGL_SUCCESS);
       
  2305 	
       
  2306 	CleanAll();
       
  2307 	RecordTestResultL();
       
  2308 	CloseTMSGraphicsStep();
       
  2309 	INFO_PRINTF1(_L("End of CEglTest_SyncObject_Negative_OOM::doTestStepL"));
       
  2310 	return TestStepResult();
       
  2311 #endif	
       
  2312 	}
       
  2313 
       
  2314 void CEglTest_SyncObject_Negative_OOM::doThreadFunctionL(TInt aIdx)
       
  2315 	{
       
  2316 	INFO_PRINTF2(_L("CEglTest_SyncObject_Negative_OOM::doThreadFunctionL, Thread %d"),aIdx);
       
  2317 	ASSERT_TRUE(aIdx==0);
       
  2318 
       
  2319 	User::After(TTimeIntervalMicroSeconds32(iDelaySignalling));
       
  2320 	TEST(iPfnEglSignalSyncKHR(iDisplay, iSyncObject, EGL_SIGNALED_KHR) == EGL_TRUE); //we do not expect failure here, as eglSignalSyncKHR function doesn't allocate a memory
       
  2321 	}