• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Module
3  * ---------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief EGL EGL_KHR_fence_sync and EGL_KHR_reusable_sync tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglSyncTests.hpp"
25 
26 #include "egluNativeWindow.hpp"
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 
30 #include "eglwLibrary.hpp"
31 #include "eglwEnums.hpp"
32 
33 #include "tcuTestLog.hpp"
34 #include "tcuCommandLine.hpp"
35 
36 #include "gluDefs.hpp"
37 
38 #include "glwFunctions.hpp"
39 #include "glwEnums.hpp"
40 
41 #include <vector>
42 #include <string>
43 #include <sstream>
44 #include <set>
45 
46 using std::vector;
47 using std::string;
48 using std::set;
49 
50 using tcu::TestLog;
51 
52 using namespace eglw;
53 using namespace glw;
54 
55 namespace deqp
56 {
57 namespace egl
58 {
59 namespace
60 {
61 
getSyncTypeName(EGLenum syncType)62 const char* getSyncTypeName (EGLenum syncType)
63 {
64 	switch (syncType)
65 	{
66 		case EGL_SYNC_FENCE_KHR:	return "EGL_SYNC_FENCE_KHR";
67 		case EGL_SYNC_REUSABLE_KHR:	return "EGL_SYNC_REUSABLE_KHR";
68 		default:
69 			DE_ASSERT(DE_FALSE);
70 			return "<Unknown>";
71 	}
72 }
73 
74 class SyncTest : public TestCase
75 {
76 public:
77 	enum Extension
78 	{
79 		EXTENSION_NONE				= 0,
80 		EXTENSION_WAIT_SYNC			= (0x1 << 0),
81 		EXTENSION_FENCE_SYNC		= (0x1 << 1),
82 		EXTENSION_REUSABLE_SYNC		= (0x1 << 2)
83 	};
84 									SyncTest	(EglTestContext& eglTestCtx, EGLenum syncType, Extension extensions, const char* name, const char* description);
85 									~SyncTest	(void);
86 
87 	void							init		(void);
88 	void							deinit		(void);
89 
90 protected:
91 	const EGLenum					m_syncType;
92 	const Extension					m_extensions;
93 
94 	glw::Functions					m_gl;
95 
96 	EGLDisplay						m_eglDisplay;
97 	EGLConfig						m_eglConfig;
98 	EGLSurface						m_eglSurface;
99 	eglu::NativeWindow*				m_nativeWindow;
100 	EGLContext						m_eglContext;
101 	EGLSyncKHR						m_sync;
102 };
103 
SyncTest(EglTestContext & eglTestCtx,EGLenum syncType,Extension extensions,const char * name,const char * description)104 SyncTest::SyncTest (EglTestContext& eglTestCtx, EGLenum syncType, Extension extensions, const char* name, const char* description)
105 	: TestCase			(eglTestCtx, name, description)
106 	, m_syncType		(syncType)
107 	, m_extensions		(extensions)
108 	, m_eglDisplay		(EGL_NO_DISPLAY)
109 	, m_eglSurface		(EGL_NO_SURFACE)
110 	, m_nativeWindow	(DE_NULL)
111 	, m_eglContext		(EGL_NO_CONTEXT)
112 	, m_sync			(EGL_NO_SYNC_KHR)
113 {
114 }
115 
~SyncTest(void)116 SyncTest::~SyncTest (void)
117 {
118 	SyncTest::deinit();
119 }
120 
requiredEGLExtensions(const Library & egl,EGLDisplay display,SyncTest::Extension requiredExtensions)121 void requiredEGLExtensions (const Library& egl, EGLDisplay display, SyncTest::Extension requiredExtensions)
122 {
123 	SyncTest::Extension foundExtensions = SyncTest::EXTENSION_NONE;
124 	std::istringstream	extensionStream(egl.queryString(display, EGL_EXTENSIONS));
125 	string				extension;
126 
127 	EGLU_CHECK_MSG(egl, "eglQueryString(display, EGL_EXTENSIONS)");
128 
129 	while (std::getline(extensionStream, extension, ' '))
130 	{
131 		if (extension == "EGL_KHR_fence_sync")
132 			foundExtensions = (SyncTest::Extension)(foundExtensions | SyncTest::EXTENSION_FENCE_SYNC);
133 		else if (extension == "EGL_KHR_reusable_sync")
134 			foundExtensions = (SyncTest::Extension)(foundExtensions | SyncTest::EXTENSION_REUSABLE_SYNC);
135 		else if (extension == "EGL_KHR_wait_sync")
136 			foundExtensions = (SyncTest::Extension)(foundExtensions | SyncTest::EXTENSION_WAIT_SYNC);
137 	}
138 
139 	{
140 		const SyncTest::Extension missingExtensions = (SyncTest::Extension)((foundExtensions & requiredExtensions) ^ requiredExtensions);
141 
142 		if ((missingExtensions & SyncTest::EXTENSION_FENCE_SYNC) != 0)
143 			TCU_THROW(NotSupportedError, "EGL_KHR_fence_sync not supported");
144 
145 		if ((missingExtensions & SyncTest::EXTENSION_REUSABLE_SYNC) != 0)
146 			TCU_THROW(NotSupportedError, "EGL_KHR_reusable_sync not supported");
147 
148 		if ((missingExtensions & SyncTest::EXTENSION_WAIT_SYNC) != 0)
149 			TCU_THROW(NotSupportedError, "EGL_KHR_wait_sync not supported");
150 	}
151 }
152 
requiredGLESExtensions(const glw::Functions & gl)153 void requiredGLESExtensions (const glw::Functions& gl)
154 {
155 	bool				found = false;
156 	std::istringstream	extensionStream((const char*)gl.getString(GL_EXTENSIONS));
157 	string				extension;
158 
159 	GLU_CHECK_GLW_MSG(gl, "glGetString(GL_EXTENSIONS)");
160 
161 	while (std::getline(extensionStream, extension, ' '))
162 	{
163 		if (extension == "GL_OES_EGL_sync")
164 			found = true;
165 	}
166 
167 	if (!found)
168 		TCU_THROW(NotSupportedError, "GL_OES_EGL_sync not supported");
169 }
170 
getSyncTypeExtension(EGLenum syncType)171 SyncTest::Extension getSyncTypeExtension (EGLenum syncType)
172 {
173 	switch (syncType)
174 	{
175 		case EGL_SYNC_FENCE_KHR:	return SyncTest::EXTENSION_FENCE_SYNC;
176 		case EGL_SYNC_REUSABLE_KHR:	return SyncTest::EXTENSION_REUSABLE_SYNC;
177 		default:
178 			DE_ASSERT(DE_FALSE);
179 			return SyncTest::EXTENSION_NONE;
180 	}
181 }
182 
init(void)183 void SyncTest::init (void)
184 {
185 	const Library&						egl				= m_eglTestCtx.getLibrary();
186 	const eglu::NativeWindowFactory&	windowFactory	= eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
187 
188 	const EGLint displayAttribList[] =
189 	{
190 		EGL_RENDERABLE_TYPE,	EGL_OPENGL_ES2_BIT,
191 		EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
192 		EGL_ALPHA_SIZE,			1,
193 		EGL_NONE
194 	};
195 
196 	const EGLint contextAttribList[] =
197 	{
198 		EGL_CONTEXT_CLIENT_VERSION, 2,
199 		EGL_NONE
200 	};
201 
202 	m_eglDisplay	= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
203 	m_eglConfig 	= eglu::chooseSingleConfig(egl, m_eglDisplay, displayAttribList);
204 
205 	m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2,0));
206 
207 	{
208 		const Extension syncTypeExtension = getSyncTypeExtension(m_syncType);
209 		requiredEGLExtensions(egl, m_eglDisplay, (Extension)(m_extensions | syncTypeExtension));
210 	}
211 
212 	// Create context
213 	EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
214 	m_eglContext = egl.createContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAttribList);
215 	EGLU_CHECK_MSG(egl, "Failed to create GLES2 context");
216 
217 	// Create surface
218 	m_nativeWindow = windowFactory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_eglDisplay, m_eglConfig, DE_NULL, eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
219 	m_eglSurface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_nativeWindow, m_eglDisplay, m_eglConfig, DE_NULL);
220 
221 	EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
222 
223 	requiredGLESExtensions(m_gl);
224 }
225 
deinit(void)226 void SyncTest::deinit (void)
227 {
228 	const Library&	egl		= m_eglTestCtx.getLibrary();
229 
230 	if (m_eglDisplay != EGL_NO_DISPLAY)
231 	{
232 		if (m_sync != EGL_NO_SYNC_KHR)
233 		{
234 			EGLU_CHECK_CALL(egl, destroySyncKHR(m_eglDisplay, m_sync));
235 			m_sync = EGL_NO_SYNC_KHR;
236 		}
237 
238 		EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
239 
240 		if (m_eglContext != EGL_NO_CONTEXT)
241 		{
242 			EGLU_CHECK_CALL(egl, destroyContext(m_eglDisplay, m_eglContext));
243 			m_eglContext = EGL_NO_CONTEXT;
244 		}
245 
246 		if (m_eglSurface != EGL_NO_SURFACE)
247 		{
248 			EGLU_CHECK_CALL(egl, destroySurface(m_eglDisplay, m_eglSurface));
249 			m_eglSurface = EGL_NO_SURFACE;
250 		}
251 
252 		delete m_nativeWindow;
253 		m_nativeWindow = DE_NULL;
254 
255 		egl.terminate(m_eglDisplay);
256 		m_eglDisplay = EGL_NO_DISPLAY;
257 	}
258 }
259 
260 class CreateNullAttribsTest : public SyncTest
261 {
262 public:
CreateNullAttribsTest(EglTestContext & eglTestCtx,EGLenum syncType)263 					CreateNullAttribsTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_null_attribs", "create_null_attribs") {}
264 
iterate(void)265 	IterateResult	iterate					(void)
266 	{
267 		const Library&	egl		= m_eglTestCtx.getLibrary();
268 		TestLog&		log		= m_testCtx.getLog();
269 
270 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
271 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
272 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
273 
274 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
275 		return STOP;
276 	}
277 };
278 
279 class CreateEmptyAttribsTest : public SyncTest
280 {
281 public:
CreateEmptyAttribsTest(EglTestContext & eglTestCtx,EGLenum syncType)282 					CreateEmptyAttribsTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_empty_attribs", "create_empty_attribs") {}
283 
iterate(void)284 	IterateResult	iterate					(void)
285 	{
286 
287 		const Library&	egl				= m_eglTestCtx.getLibrary();
288 		TestLog&		log				= m_testCtx.getLog();
289 		const EGLint	attribList[]	=
290 		{
291 			EGL_NONE
292 		};
293 
294 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, attribList);
295 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", { EGL_NONE })" << TestLog::EndMessage;
296 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
297 
298 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
299 		return STOP;
300 	}
301 };
302 
303 class CreateInvalidDisplayTest : public SyncTest
304 {
305 public:
CreateInvalidDisplayTest(EglTestContext & eglTestCtx,EGLenum syncType)306 					CreateInvalidDisplayTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_invalid_display", "create_invalid_display") {}
307 
iterate(void)308 	IterateResult	iterate						(void)
309 	{
310 		const Library&	egl		= m_eglTestCtx.getLibrary();
311 		TestLog&		log		= m_testCtx.getLog();
312 
313 		m_sync = egl.createSyncKHR(EGL_NO_DISPLAY, m_syncType, NULL);
314 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(EGL_NO_DISPLAY, " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
315 
316 		EGLint error = egl.getError();
317 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
318 
319 		if (error != EGL_BAD_DISPLAY)
320 		{
321 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
322 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
323 			return STOP;
324 		}
325 
326 		TCU_CHECK(m_sync == EGL_NO_SYNC_KHR);
327 
328 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
329 		return STOP;
330 	}
331 };
332 
333 class CreateInvalidTypeTest : public SyncTest
334 {
335 public:
CreateInvalidTypeTest(EglTestContext & eglTestCtx,EGLenum syncType)336 					CreateInvalidTypeTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_invalid_type", "create_invalid_type") {}
337 
iterate(void)338 	IterateResult	iterate					(void)
339 	{
340 		const Library&	egl		= m_eglTestCtx.getLibrary();
341 		TestLog&		log		= m_testCtx.getLog();
342 
343 		m_sync = egl.createSyncKHR(m_eglDisplay, EGL_NONE, NULL);
344 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", EGL_NONE, NULL)" << TestLog::EndMessage;
345 
346 		EGLint error = egl.getError();
347 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
348 
349 		if (error != EGL_BAD_ATTRIBUTE)
350 		{
351 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_ATTRIBUTE" << TestLog::EndMessage;
352 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
353 			return STOP;
354 		}
355 
356 		TCU_CHECK(m_sync == EGL_NO_SYNC_KHR);
357 
358 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
359 		return STOP;
360 	}
361 };
362 
363 class CreateInvalidAttribsTest : public SyncTest
364 {
365 public:
CreateInvalidAttribsTest(EglTestContext & eglTestCtx,EGLenum syncType)366 					CreateInvalidAttribsTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_invalid_attribs", "create_invalid_attribs") {}
367 
iterate(void)368 	IterateResult	iterate						(void)
369 	{
370 		const Library&	egl		= m_eglTestCtx.getLibrary();
371 		TestLog&		log		= m_testCtx.getLog();
372 
373 		EGLint attribs[] = {
374 			2, 3, 4, 5,
375 			EGL_NONE
376 		};
377 
378 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, attribs);
379 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", { 2, 3, 4, 5, EGL_NONE })" << TestLog::EndMessage;
380 
381 		EGLint error = egl.getError();
382 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
383 
384 		if (error != EGL_BAD_ATTRIBUTE)
385 		{
386 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_ATTRIBUTE" << TestLog::EndMessage;
387 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
388 			return STOP;
389 		}
390 
391 		TCU_CHECK(m_sync == EGL_NO_SYNC_KHR);
392 
393 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
394 		return STOP;
395 	}
396 };
397 
398 class CreateInvalidContextTest : public SyncTest
399 {
400 public:
CreateInvalidContextTest(EglTestContext & eglTestCtx,EGLenum syncType)401 					CreateInvalidContextTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "create_invalid_context", "create_invalid_context") {}
402 
iterate(void)403 	IterateResult	iterate						(void)
404 	{
405 		const Library&	egl		= m_eglTestCtx.getLibrary();
406 		TestLog&		log		= m_testCtx.getLog();
407 
408 		log << TestLog::Message << "eglMakeCurrent(" << m_eglDisplay << ", EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)" << TestLog::EndMessage;
409 		EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
410 
411 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
412 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
413 
414 		EGLint error = egl.getError();
415 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
416 
417 		if (error != EGL_BAD_MATCH)
418 		{
419 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_MATCH" << TestLog::EndMessage;
420 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
421 			return STOP;
422 		}
423 
424 		TCU_CHECK(m_sync == EGL_NO_SYNC_KHR);
425 
426 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
427 		return STOP;
428 	}
429 };
430 
431 class ClientWaitNoTimeoutTest : public SyncTest
432 {
433 public:
ClientWaitNoTimeoutTest(EglTestContext & eglTestCtx,EGLenum syncType)434 					ClientWaitNoTimeoutTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_no_timeout", "wait_no_timeout") {}
435 
iterate(void)436 	IterateResult	iterate					(void)
437 	{
438 		const Library&	egl		= m_eglTestCtx.getLibrary();
439 		TestLog&		log		= m_testCtx.getLog();
440 
441 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
442 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
443 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
444 
445 		EGLint status = egl.clientWaitSyncKHR(m_eglDisplay, m_sync, 0, 0);
446 		log << TestLog::Message << status << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", 0, 0)" << TestLog::EndMessage;
447 
448 		if (m_syncType == EGL_SYNC_FENCE_KHR)
449 			TCU_CHECK(status == EGL_CONDITION_SATISFIED_KHR || status == EGL_TIMEOUT_EXPIRED_KHR);
450 		else if (m_syncType == EGL_SYNC_REUSABLE_KHR)
451 			TCU_CHECK(status == EGL_TIMEOUT_EXPIRED_KHR);
452 		else
453 			DE_ASSERT(DE_FALSE);
454 
455 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
456 		return STOP;
457 	}
458 
459 };
460 
461 class ClientWaitForeverTest : public SyncTest
462 {
463 public:
ClientWaitForeverTest(EglTestContext & eglTestCtx,EGLenum syncType)464 					ClientWaitForeverTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_forever", "wait_forever") {}
465 
iterate(void)466 	IterateResult	iterate					(void)
467 	{
468 		const Library&	egl		= m_eglTestCtx.getLibrary();
469 		TestLog&		log		= m_testCtx.getLog();
470 
471 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
472 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
473 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
474 
475 		if (m_syncType == EGL_SYNC_REUSABLE_KHR)
476 		{
477 			EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
478 			log << TestLog::Message << ret << " = eglSignalSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" << TestLog::EndMessage;
479 			EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
480 		}
481 		else if (m_syncType == EGL_SYNC_FENCE_KHR)
482 		{
483 			GLU_CHECK_GLW_CALL(m_gl, flush());
484 			log << TestLog::Message << "glFlush()" << TestLog::EndMessage;
485 		}
486 		else
487 			DE_ASSERT(DE_FALSE);
488 
489 		EGLint status = egl.clientWaitSyncKHR(m_eglDisplay, m_sync, 0, EGL_FOREVER_KHR);
490 		log << TestLog::Message << status << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", 0, EGL_FOREVER_KHR)" << TestLog::EndMessage;
491 
492 		TCU_CHECK(status == EGL_CONDITION_SATISFIED_KHR);
493 		EGLU_CHECK_MSG(egl, "eglClientWaitSyncKHR()");
494 
495 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
496 		return STOP;
497 	}
498 };
499 
500 class ClientWaitNoContextTest : public SyncTest
501 {
502 public:
ClientWaitNoContextTest(EglTestContext & eglTestCtx,EGLenum syncType)503 					ClientWaitNoContextTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_no_context", "wait_no_Context") {}
504 
iterate(void)505 	IterateResult	iterate					(void)
506 	{
507 		const Library&	egl		= m_eglTestCtx.getLibrary();
508 		TestLog&		log		= m_testCtx.getLog();
509 
510 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
511 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
512 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
513 
514 
515 		if (m_syncType == EGL_SYNC_REUSABLE_KHR)
516 		{
517 			EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
518 			log << TestLog::Message << ret << " = eglSignalSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" << TestLog::EndMessage;
519 			EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
520 		}
521 		else if (m_syncType == EGL_SYNC_FENCE_KHR)
522 		{
523 			GLU_CHECK_GLW_CALL(m_gl, flush());
524 			log << TestLog::Message << "glFlush()" << TestLog::EndMessage;
525 		}
526 		else
527 			DE_ASSERT(DE_FALSE);
528 
529 		log << TestLog::Message << "eglMakeCurrent(" << m_eglDisplay << ", EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)" << TestLog::EndMessage;
530 		EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
531 
532 		EGLint result = egl.clientWaitSyncKHR(m_eglDisplay, m_sync, 0, EGL_FOREVER_KHR);
533 		log << TestLog::Message << result << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", 0, EGL_FOREVER_KHR)" << TestLog::EndMessage;
534 
535 		TCU_CHECK(result == EGL_CONDITION_SATISFIED_KHR);
536 
537 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
538 		return STOP;
539 	}
540 };
541 
542 class ClientWaitForeverFlushTest : public SyncTest
543 {
544 public:
ClientWaitForeverFlushTest(EglTestContext & eglTestCtx,EGLenum syncType)545 					ClientWaitForeverFlushTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_forever_flush", "wait_forever_flush") {}
546 
iterate(void)547 	IterateResult	iterate						(void)
548 	{
549 		const Library&	egl		= m_eglTestCtx.getLibrary();
550 		TestLog&		log		= m_testCtx.getLog();
551 
552 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
553 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
554 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
555 
556 		if (m_syncType == EGL_SYNC_REUSABLE_KHR)
557 		{
558 			EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
559 			log << TestLog::Message << ret << " = eglSignalSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" << TestLog::EndMessage;
560 			EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
561 		}
562 
563 		EGLint status = egl.clientWaitSyncKHR(m_eglDisplay, m_sync, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR);
564 		log << TestLog::Message << status << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR)" << TestLog::EndMessage;
565 
566 		TCU_CHECK(status == EGL_CONDITION_SATISFIED_KHR);
567 
568 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
569 		return STOP;
570 	}
571 };
572 
573 class ClientWaitInvalidDisplayTest : public SyncTest
574 {
575 public:
ClientWaitInvalidDisplayTest(EglTestContext & eglTestCtx,EGLenum syncType)576 					ClientWaitInvalidDisplayTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_invalid_display", "wait_invalid_display") {}
577 
iterate(void)578 	IterateResult	iterate							(void)
579 	{
580 		const Library&	egl		= m_eglTestCtx.getLibrary();
581 		TestLog&		log		= m_testCtx.getLog();
582 
583 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
584 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
585 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
586 
587 		EGLint status = egl.clientWaitSyncKHR(EGL_NO_DISPLAY, m_sync, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR);
588 		log << TestLog::Message << status << " = eglClientWaitSyncKHR(EGL_NO_DISPLAY, " << m_sync << ", EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR)" << TestLog::EndMessage;
589 
590 		EGLint error = egl.getError();
591 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
592 
593 		if (error != EGL_BAD_DISPLAY)
594 		{
595 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
596 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
597 			return STOP;
598 		}
599 
600 		TCU_CHECK(status == EGL_FALSE);
601 
602 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
603 		return STOP;
604 	}
605 };
606 
607 class ClientWaitInvalidSyncTest : public SyncTest
608 {
609 public:
ClientWaitInvalidSyncTest(EglTestContext & eglTestCtx,EGLenum syncType)610 					ClientWaitInvalidSyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "wait_invalid_sync", "wait_invalid_sync") {}
611 
iterate(void)612 	IterateResult	iterate						(void)
613 	{
614 		const Library&	egl		= m_eglTestCtx.getLibrary();
615 		TestLog&		log		= m_testCtx.getLog();
616 
617 		EGLint status = egl.clientWaitSyncKHR(m_eglDisplay, EGL_NO_SYNC_KHR, 0, EGL_FOREVER_KHR);
618 		log << TestLog::Message << status << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", EGL_NO_SYNC_KHR, 0, EGL_FOREVER_KHR)" << TestLog::EndMessage;
619 
620 		EGLint error = egl.getError();
621 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
622 
623 		if (error != EGL_BAD_PARAMETER)
624 		{
625 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
626 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
627 			return STOP;
628 		}
629 
630 		TCU_CHECK(status == EGL_FALSE);
631 
632 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
633 		return STOP;
634 	}
635 };
636 
637 class GetSyncTypeTest : public SyncTest
638 {
639 public:
GetSyncTypeTest(EglTestContext & eglTestCtx,EGLenum syncType)640 					GetSyncTypeTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_type", "get_type") {}
641 
iterate(void)642 	IterateResult	iterate			(void)
643 	{
644 		const Library&	egl		= m_eglTestCtx.getLibrary();
645 		TestLog&		log		= m_testCtx.getLog();
646 
647 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
648 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
649 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
650 
651 		EGLint type = 0;
652 		EGLU_CHECK_CALL(egl, getSyncAttribKHR(m_eglDisplay, m_sync, EGL_SYNC_TYPE_KHR, &type));
653 		log << TestLog::Message << "eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_TYPE_KHR, {" << type << "})" << TestLog::EndMessage;
654 
655 		TCU_CHECK(type == ((EGLint)m_syncType));
656 
657 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
658 		return STOP;
659 	}
660 };
661 
662 class GetSyncStatusTest : public SyncTest
663 {
664 public:
GetSyncStatusTest(EglTestContext & eglTestCtx,EGLenum syncType)665 					GetSyncStatusTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_status", "get_status") {}
666 
iterate(void)667 	IterateResult	iterate				(void)
668 	{
669 		const Library&	egl		= m_eglTestCtx.getLibrary();
670 		TestLog&		log		= m_testCtx.getLog();
671 
672 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
673 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
674 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
675 
676 		EGLint status = 0;
677 		EGLU_CHECK_CALL(egl, getSyncAttribKHR(m_eglDisplay, m_sync, EGL_SYNC_STATUS_KHR, &status));
678 		log << TestLog::Message << "eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_STATUS_KHR, {" << status << "})" << TestLog::EndMessage;
679 
680 		if (m_syncType == EGL_SYNC_FENCE_KHR)
681 			TCU_CHECK(status == EGL_SIGNALED_KHR || status == EGL_UNSIGNALED_KHR);
682 		else if (m_syncType == EGL_SYNC_REUSABLE_KHR)
683 			TCU_CHECK(status == EGL_UNSIGNALED_KHR);
684 
685 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
686 		return STOP;
687 	}
688 };
689 
690 class GetSyncStatusSignaledTest : public SyncTest
691 {
692 public:
GetSyncStatusSignaledTest(EglTestContext & eglTestCtx,EGLenum syncType)693 					GetSyncStatusSignaledTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_status_signaled", "get_status_signaled") {}
694 
iterate(void)695 	IterateResult	iterate						(void)
696 	{
697 		const Library&	egl		= m_eglTestCtx.getLibrary();
698 		TestLog&		log		= m_testCtx.getLog();
699 
700 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
701 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
702 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
703 
704 		if (m_syncType == EGL_SYNC_REUSABLE_KHR)
705 		{
706 			EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
707 			log << TestLog::Message << ret << " = eglSignalSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" << TestLog::EndMessage;
708 			EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
709 		}
710 		else if (m_syncType == EGL_SYNC_FENCE_KHR)
711 		{
712 			GLU_CHECK_GLW_CALL(m_gl, finish());
713 			log << TestLog::Message << "glFinish()" << TestLog::EndMessage;
714 		}
715 		else
716 			DE_ASSERT(DE_FALSE);
717 
718 		{
719 			EGLint status = egl.clientWaitSyncKHR(m_eglDisplay, m_sync, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR);
720 			log << TestLog::Message << status << " = eglClientWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR)" << TestLog::EndMessage;
721 			TCU_CHECK(status == EGL_CONDITION_SATISFIED_KHR);
722 		}
723 
724 		EGLint status = 0;
725 		EGLU_CHECK_CALL(egl, getSyncAttribKHR(m_eglDisplay, m_sync, EGL_SYNC_STATUS_KHR, &status));
726 		log << TestLog::Message << "eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_STATUS_KHR, {" << status << "})" << TestLog::EndMessage;
727 
728 		TCU_CHECK(status == EGL_SIGNALED_KHR);
729 
730 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
731 		return STOP;
732 	}
733 };
734 
735 class GetSyncConditionTest : public SyncTest
736 {
737 public:
GetSyncConditionTest(EglTestContext & eglTestCtx,EGLenum syncType)738 					GetSyncConditionTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_condition", "get_condition") {}
739 
iterate(void)740 	IterateResult	iterate					(void)
741 	{
742 		const Library&	egl		= m_eglTestCtx.getLibrary();
743 		TestLog&		log		= m_testCtx.getLog();
744 
745 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
746 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
747 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
748 
749 		EGLint condition = 0;
750 		EGLU_CHECK_CALL(egl, getSyncAttribKHR(m_eglDisplay, m_sync, EGL_SYNC_CONDITION_KHR, &condition));
751 		log << TestLog::Message << "eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_CONDITION_KHR, {" << condition << "})" << TestLog::EndMessage;
752 
753 		TCU_CHECK(condition == EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR);
754 
755 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
756 		return STOP;
757 	}
758 };
759 
760 class GetSyncInvalidDisplayTest : public SyncTest
761 {
762 public:
GetSyncInvalidDisplayTest(EglTestContext & eglTestCtx,EGLenum syncType)763 					GetSyncInvalidDisplayTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_invalid_display", "get_invalid_display") {}
764 
iterate(void)765 	IterateResult	iterate						(void)
766 	{
767 		const Library&	egl		= m_eglTestCtx.getLibrary();
768 		TestLog&		log		= m_testCtx.getLog();
769 
770 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
771 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
772 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
773 
774 		EGLint condition = 0xF0F0F;
775 		EGLBoolean result = egl.getSyncAttribKHR(EGL_NO_DISPLAY, m_sync, EGL_SYNC_CONDITION_KHR, &condition);
776 		log << TestLog::Message << result << " = eglGetSyncAttribKHR(EGL_NO_DISPLAY, " << m_sync << ", EGL_SYNC_CONDITION_KHR, {" << condition << "})" << TestLog::EndMessage;
777 
778 		EGLint error = egl.getError();
779 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
780 
781 		if (error != EGL_BAD_DISPLAY)
782 		{
783 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
784 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
785 			return STOP;
786 		}
787 
788 		TCU_CHECK(result == EGL_FALSE);
789 		TCU_CHECK(condition == 0xF0F0F);
790 
791 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
792 		return STOP;
793 	}
794 };
795 
796 class GetSyncInvalidSyncTest : public SyncTest
797 {
798 public:
GetSyncInvalidSyncTest(EglTestContext & eglTestCtx,EGLenum syncType)799 					GetSyncInvalidSyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_invalid_sync", "get_invalid_sync") {}
800 
iterate(void)801 	IterateResult	iterate					(void)
802 	{
803 		const Library&	egl		= m_eglTestCtx.getLibrary();
804 		TestLog&		log		= m_testCtx.getLog();
805 
806 		EGLint condition = 0xF0F0F;
807 		EGLBoolean result = egl.getSyncAttribKHR(m_eglDisplay, EGL_NO_SYNC_KHR, EGL_SYNC_CONDITION_KHR, &condition);
808 		log << TestLog::Message << result << " = eglGetSyncAttribKHR(" << m_eglDisplay << ", EGL_NO_SYNC_KHR, EGL_SYNC_CONDITION_KHR, {" << condition << "})" << TestLog::EndMessage;
809 
810 		EGLint error = egl.getError();
811 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
812 
813 		if (error != EGL_BAD_PARAMETER)
814 		{
815 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
816 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
817 			return STOP;
818 		}
819 
820 		TCU_CHECK(result == EGL_FALSE);
821 		TCU_CHECK(condition == 0xF0F0F);
822 
823 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
824 		return STOP;
825 	}
826 };
827 
828 class GetSyncInvalidAttributeTest : public SyncTest
829 {
830 public:
GetSyncInvalidAttributeTest(EglTestContext & eglTestCtx,EGLenum syncType)831 					GetSyncInvalidAttributeTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_invalid_attribute", "get_invalid_attribute") {}
832 
iterate(void)833 	IterateResult	iterate						(void)
834 	{
835 		const Library&	egl		= m_eglTestCtx.getLibrary();
836 		TestLog&		log		= m_testCtx.getLog();
837 
838 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
839 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
840 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
841 
842 		EGLint condition = 0xF0F0F;
843 		EGLBoolean result = egl.getSyncAttribKHR(m_eglDisplay, m_sync, EGL_NONE, &condition);
844 		log << TestLog::Message << result << " = eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_NONE, {" << condition << "})" << TestLog::EndMessage;
845 
846 		EGLint error = egl.getError();
847 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
848 
849 		if (error != EGL_BAD_ATTRIBUTE)
850 		{
851 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_ATTRIBUTE" << TestLog::EndMessage;
852 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
853 			return STOP;
854 		}
855 
856 		TCU_CHECK(result == EGL_FALSE);
857 		TCU_CHECK(condition == 0xF0F0F);
858 
859 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
860 		return STOP;
861 	}
862 };
863 
864 class GetSyncInvalidValueTest : public SyncTest
865 {
866 public:
GetSyncInvalidValueTest(EglTestContext & eglTestCtx,EGLenum syncType)867 					GetSyncInvalidValueTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "get_invalid_value", "get_invalid_value") {}
868 
iterate(void)869 	IterateResult	iterate					(void)
870 	{
871 		const Library&	egl		= m_eglTestCtx.getLibrary();
872 		TestLog&		log		= m_testCtx.getLog();
873 
874 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
875 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
876 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
877 
878 		EGLBoolean result = egl.getSyncAttribKHR(m_eglDisplay, m_sync, EGL_SYNC_TYPE_KHR, NULL);
879 		log << TestLog::Message << result << " = eglGetSyncAttribKHR(" << m_eglDisplay << ", " << m_sync << ", EGL_SYNC_CONDITION_KHR, NULL)" << TestLog::EndMessage;
880 
881 		EGLint error = egl.getError();
882 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
883 
884 		if (error != EGL_BAD_PARAMETER)
885 		{
886 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
887 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
888 			return STOP;
889 		}
890 
891 		TCU_CHECK(result == EGL_FALSE);
892 
893 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
894 		return STOP;
895 	}
896 };
897 
898 class DestroySyncTest : public SyncTest
899 {
900 public:
DestroySyncTest(EglTestContext & eglTestCtx,EGLenum syncType)901 					DestroySyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "destroy", "destroy") {}
902 
iterate(void)903 	IterateResult	iterate			(void)
904 	{
905 		const Library&	egl		= m_eglTestCtx.getLibrary();
906 		TestLog&		log		= m_testCtx.getLog();
907 
908 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
909 		log << TestLog::Message << "eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
910 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
911 
912 		log << TestLog::Message << "eglDestroySyncKHR(" << m_eglDisplay << ", " << m_sync << ")" << TestLog::EndMessage;
913 		EGLU_CHECK_CALL(egl, destroySyncKHR(m_eglDisplay, m_sync));
914 		m_sync = EGL_NO_SYNC_KHR;
915 
916 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
917 		return STOP;
918 	}
919 };
920 
921 class DestroySyncInvalidDislayTest : public SyncTest
922 {
923 public:
DestroySyncInvalidDislayTest(EglTestContext & eglTestCtx,EGLenum syncType)924 					DestroySyncInvalidDislayTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "destroy_invalid_display", "destroy_invalid_display") {}
925 
iterate(void)926 	IterateResult	iterate							(void)
927 	{
928 		const Library&	egl		= m_eglTestCtx.getLibrary();
929 		TestLog&		log		= m_testCtx.getLog();
930 
931 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
932 		log << TestLog::Message << "eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
933 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
934 
935 		EGLBoolean result = egl.destroySyncKHR(EGL_NO_DISPLAY, m_sync);
936 		log << TestLog::Message << result << " = eglDestroySyncKHR(EGL_NO_DISPLAY, " << m_sync << ")" << TestLog::EndMessage;
937 
938 		EGLint error = egl.getError();
939 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
940 
941 		if (error != EGL_BAD_DISPLAY)
942 		{
943 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
944 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
945 			return STOP;
946 		}
947 
948 		TCU_CHECK(result == EGL_FALSE);
949 
950 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
951 		return STOP;
952 	}
953 };
954 
955 class DestroySyncInvalidSyncTest : public SyncTest
956 {
957 public:
DestroySyncInvalidSyncTest(EglTestContext & eglTestCtx,EGLenum syncType)958 					DestroySyncInvalidSyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE, "destroy_invalid_sync", "destroy_invalid_sync") {}
959 
iterate(void)960 	IterateResult	iterate						(void)
961 	{
962 		const Library&	egl		= m_eglTestCtx.getLibrary();
963 		TestLog&		log		= m_testCtx.getLog();
964 
965 		EGLBoolean result = egl.destroySyncKHR(m_eglDisplay, EGL_NO_SYNC_KHR);
966 		log << TestLog::Message << result << " = eglDestroySyncKHR(" << m_eglDisplay << ", EGL_NO_SYNC_KHR)" << TestLog::EndMessage;
967 
968 		EGLint error = egl.getError();
969 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
970 
971 		if (error != EGL_BAD_PARAMETER)
972 		{
973 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
974 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
975 			return STOP;
976 		}
977 
978 		TCU_CHECK(result == EGL_FALSE);
979 
980 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
981 		return STOP;
982 	}
983 };
984 
985 class WaitSyncTest : public SyncTest
986 {
987 public:
WaitSyncTest(EglTestContext & eglTestCtx,EGLenum syncType)988 					WaitSyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, "wait_server", "wait_server") {}
989 
iterate(void)990 	IterateResult	iterate			(void)
991 	{
992 		const Library&	egl		= m_eglTestCtx.getLibrary();
993 		TestLog&		log		= m_testCtx.getLog();
994 
995 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
996 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
997 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
998 
999 		EGLint status = egl.waitSyncKHR(m_eglDisplay, m_sync, 0);
1000 		log << TestLog::Message << status << " = eglWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", 0, 0)" << TestLog::EndMessage;
1001 
1002 		TCU_CHECK(status == EGL_TRUE);
1003 
1004 		GLU_CHECK_GLW_CALL(m_gl, finish());
1005 
1006 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1007 		return STOP;
1008 	}
1009 
1010 };
1011 
1012 class WaitSyncInvalidDisplayTest : public SyncTest
1013 {
1014 public:
WaitSyncInvalidDisplayTest(EglTestContext & eglTestCtx,EGLenum syncType)1015 					WaitSyncInvalidDisplayTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, "wait_server_invalid_display", "wait_server_invalid_display") {}
1016 
iterate(void)1017 	IterateResult	iterate						(void)
1018 	{
1019 		const Library&	egl		= m_eglTestCtx.getLibrary();
1020 		TestLog&		log		= m_testCtx.getLog();
1021 
1022 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
1023 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
1024 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
1025 
1026 		EGLint status = egl.waitSyncKHR(EGL_NO_DISPLAY, m_sync, 0);
1027 		log << TestLog::Message << status << " = eglWaitSyncKHR(EGL_NO_DISPLAY, " << m_sync << ", 0)" << TestLog::EndMessage;
1028 
1029 		EGLint error = egl.getError();
1030 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1031 
1032 		if (error != EGL_BAD_DISPLAY)
1033 		{
1034 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
1035 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1036 			return STOP;
1037 		}
1038 
1039 		TCU_CHECK(status == EGL_FALSE);
1040 
1041 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1042 		return STOP;
1043 	}
1044 };
1045 
1046 class WaitSyncInvalidSyncTest : public SyncTest
1047 {
1048 public:
WaitSyncInvalidSyncTest(EglTestContext & eglTestCtx,EGLenum syncType)1049 					WaitSyncInvalidSyncTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, "wait_server_invalid_sync", "wait_server_invalid_sync") {}
1050 
iterate(void)1051 	IterateResult	iterate					(void)
1052 	{
1053 		const Library&	egl		= m_eglTestCtx.getLibrary();
1054 		TestLog&		log		= m_testCtx.getLog();
1055 
1056 		EGLint status = egl.waitSyncKHR(m_eglDisplay, EGL_NO_SYNC_KHR, 0);
1057 		log << TestLog::Message << status << " = eglWaitSyncKHR(" << m_eglDisplay << ", EGL_NO_SYNC_KHR, 0)" << TestLog::EndMessage;
1058 
1059 		EGLint error = egl.getError();
1060 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1061 
1062 		if (error != EGL_BAD_PARAMETER)
1063 		{
1064 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1065 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1066 			return STOP;
1067 		}
1068 
1069 		TCU_CHECK(status == EGL_FALSE);
1070 
1071 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1072 		return STOP;
1073 	}
1074 };
1075 
1076 class WaitSyncInvalidFlagTest : public SyncTest
1077 {
1078 public:
WaitSyncInvalidFlagTest(EglTestContext & eglTestCtx,EGLenum syncType)1079 					WaitSyncInvalidFlagTest	(EglTestContext& eglTestCtx, EGLenum syncType) : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, "wait_server_invalid_flag", "wait_server_invalid_flag") {}
1080 
iterate(void)1081 	IterateResult	iterate					(void)
1082 	{
1083 		const Library&	egl		= m_eglTestCtx.getLibrary();
1084 		TestLog&		log		= m_testCtx.getLog();
1085 
1086 		m_sync = egl.createSyncKHR(m_eglDisplay, m_syncType, NULL);
1087 		log << TestLog::Message << m_sync << " = eglCreateSyncKHR(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" << TestLog::EndMessage;
1088 		EGLU_CHECK_MSG(egl, "eglCreateSyncKHR()");
1089 
1090 		EGLint status = egl.waitSyncKHR(m_eglDisplay, m_sync, 0xFFFFFFFF);
1091 		log << TestLog::Message << status << " = eglWaitSyncKHR(" << m_eglDisplay << ", " << m_sync << ", 0xFFFFFFFF)" << TestLog::EndMessage;
1092 
1093 		EGLint error = egl.getError();
1094 		log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1095 
1096 		if (error != EGL_BAD_PARAMETER)
1097 		{
1098 			log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) << "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1099 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1100 			return STOP;
1101 		}
1102 
1103 		TCU_CHECK(status == EGL_FALSE);
1104 
1105 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1106 		return STOP;
1107 	}
1108 };
1109 
1110 } // anonymous
1111 
FenceSyncTests(EglTestContext & eglTestCtx)1112 FenceSyncTests::FenceSyncTests (EglTestContext& eglTestCtx)
1113 	: TestCaseGroup	(eglTestCtx, "fence_sync", "EGL_KHR_fence_sync extension tests")
1114 {
1115 }
1116 
init(void)1117 void FenceSyncTests::init (void)
1118 {
1119 	// Add valid API test
1120 	{
1121 		TestCaseGroup* const valid = new TestCaseGroup(m_eglTestCtx, "valid", "Valid function calls");
1122 
1123 		// eglCreateSyncKHR tests
1124 		valid->addChild(new CreateNullAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1125 		valid->addChild(new CreateEmptyAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1126 
1127 		// eglClientWaitSyncKHR tests
1128 		valid->addChild(new ClientWaitNoTimeoutTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1129 		valid->addChild(new ClientWaitForeverTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1130 		valid->addChild(new ClientWaitNoContextTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1131 		valid->addChild(new ClientWaitForeverFlushTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1132 
1133 		// eglGetSyncAttribKHR tests
1134 		valid->addChild(new GetSyncTypeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1135 		valid->addChild(new GetSyncStatusTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1136 		valid->addChild(new GetSyncStatusSignaledTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1137 		valid->addChild(new GetSyncConditionTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1138 
1139 		// eglDestroySyncKHR tests
1140 		valid->addChild(new DestroySyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1141 
1142 		// eglWaitSyncKHR tests
1143 		valid->addChild(new WaitSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1144 
1145 		addChild(valid);
1146 	}
1147 
1148 	// Add negative API tests
1149 	{
1150 		TestCaseGroup* const invalid = new TestCaseGroup(m_eglTestCtx, "invalid", "Invalid function calls");
1151 
1152 		// eglCreateSyncKHR tests
1153 		invalid->addChild(new CreateInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1154 		invalid->addChild(new CreateInvalidTypeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1155 		invalid->addChild(new CreateInvalidAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1156 		invalid->addChild(new CreateInvalidContextTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1157 
1158 		// eglClientWaitSyncKHR tests
1159 		invalid->addChild(new ClientWaitInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1160 		invalid->addChild(new ClientWaitInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1161 
1162 		// eglGetSyncAttribKHR tests
1163 		invalid->addChild(new GetSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1164 		invalid->addChild(new GetSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1165 		invalid->addChild(new GetSyncInvalidAttributeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1166 		invalid->addChild(new GetSyncInvalidValueTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1167 
1168 		// eglDestroySyncKHR tests
1169 		invalid->addChild(new DestroySyncInvalidDislayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1170 		invalid->addChild(new DestroySyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1171 
1172 		// eglWaitSyncKHR tests
1173 		invalid->addChild(new WaitSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1174 		invalid->addChild(new WaitSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1175 		invalid->addChild(new WaitSyncInvalidFlagTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
1176 
1177 		addChild(invalid);
1178 	}
1179 }
1180 
ReusableSyncTests(EglTestContext & eglTestCtx)1181 ReusableSyncTests::ReusableSyncTests (EglTestContext& eglTestCtx)
1182 	: TestCaseGroup	(eglTestCtx, "reusable_sync", "EGL_KHR_reusable_sync extension tests")
1183 {
1184 }
1185 
init(void)1186 void ReusableSyncTests::init (void)
1187 {
1188 	// Add valid API test
1189 	{
1190 		TestCaseGroup* const valid = new TestCaseGroup(m_eglTestCtx, "valid", "Valid function calls");
1191 
1192 		// eglCreateSyncKHR tests
1193 		valid->addChild(new CreateNullAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1194 		valid->addChild(new CreateEmptyAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1195 
1196 		// eglClientWaitSyncKHR tests
1197 		valid->addChild(new ClientWaitNoTimeoutTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1198 		valid->addChild(new ClientWaitForeverTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1199 		valid->addChild(new ClientWaitNoContextTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1200 		valid->addChild(new ClientWaitForeverFlushTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1201 
1202 		// eglGetSyncAttribKHR tests
1203 		valid->addChild(new GetSyncTypeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1204 		valid->addChild(new GetSyncStatusTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1205 		valid->addChild(new GetSyncStatusSignaledTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1206 
1207 		// eglDestroySyncKHR tests
1208 		valid->addChild(new DestroySyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1209 
1210 		// eglWaitSyncKHR tests
1211 		valid->addChild(new WaitSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1212 
1213 		addChild(valid);
1214 	}
1215 
1216 	// Add negative API tests
1217 	{
1218 		TestCaseGroup* const invalid = new TestCaseGroup(m_eglTestCtx, "invalid", "Invalid function calls");
1219 
1220 		// eglCreateSyncKHR tests
1221 		invalid->addChild(new CreateInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1222 		invalid->addChild(new CreateInvalidTypeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1223 		invalid->addChild(new CreateInvalidAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1224 
1225 		// eglClientWaitSyncKHR tests
1226 		invalid->addChild(new ClientWaitInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1227 		invalid->addChild(new ClientWaitInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1228 
1229 		// eglGetSyncAttribKHR tests
1230 		invalid->addChild(new GetSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1231 		invalid->addChild(new GetSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1232 		invalid->addChild(new GetSyncInvalidAttributeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1233 		invalid->addChild(new GetSyncInvalidValueTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1234 
1235 		// eglDestroySyncKHR tests
1236 		invalid->addChild(new DestroySyncInvalidDislayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1237 		invalid->addChild(new DestroySyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1238 
1239 		// eglWaitSyncKHR tests
1240 		invalid->addChild(new WaitSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1241 		invalid->addChild(new WaitSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1242 		invalid->addChild(new WaitSyncInvalidFlagTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
1243 
1244 		addChild(invalid);
1245 	}
1246 }
1247 
1248 } // egl
1249 } // deqp
1250