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