Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / modules / egl / teglSyncTests.cpp
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 "deStringUtil.hpp"
27
28 #include "egluNativeWindow.hpp"
29 #include "egluStrUtil.hpp"
30 #include "egluUtil.hpp"
31
32 #include "eglwLibrary.hpp"
33 #include "eglwEnums.hpp"
34
35 #include "tcuTestLog.hpp"
36 #include "tcuCommandLine.hpp"
37
38 #include "gluDefs.hpp"
39
40 #include "glwFunctions.hpp"
41 #include "glwEnums.hpp"
42
43 #include <vector>
44 #include <string>
45 #include <sstream>
46 #include <set>
47
48 using std::vector;
49 using std::string;
50 using std::set;
51
52 using tcu::TestLog;
53
54 using namespace eglw;
55 using namespace glw;
56
57 namespace deqp
58 {
59 namespace egl
60 {
61
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         typedef EGLSync     (Library::*createSync)(EGLDisplay, EGLenum, const EGLAttrib *) const ;
78         typedef EGLSyncKHR  (Library::*createSyncKHR)(EGLDisplay, EGLenum, const EGLint *) const ;
79         typedef EGLint      (Library::*clientWaitSync)(EGLDisplay, EGLSync, EGLint, EGLTime) const ;
80         typedef EGLint      (Library::*clientWaitSyncKHR)(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR) const ;
81         typedef EGLBoolean  (Library::*getSyncAttrib)(EGLDisplay, EGLSync, EGLint, EGLAttrib *) const ;
82         typedef EGLBoolean  (Library::*getSyncAttribKHR)(EGLDisplay, EGLSyncKHR, EGLint, EGLint *) const ;
83         typedef EGLBoolean  (Library::*destroySync)(EGLDisplay, EGLSync) const ;
84         typedef EGLBoolean  (Library::*destroySyncKHR)(EGLDisplay, EGLSyncKHR) const ;
85         typedef EGLBoolean  (Library::*waitSync)(EGLDisplay, EGLSync, EGLint) const ;
86         typedef EGLint      (Library::*waitSyncKHR)(EGLDisplay, EGLSyncKHR, EGLint) const ;
87
88         enum FunctionName
89         {
90                 FUNC_NAME_CREATE_SYNC,
91                 FUNC_NAME_CLIENT_WAIT_SYNC,
92                 FUNC_NAME_GET_SYNC_ATTRIB,
93                 FUNC_NAME_DESTROY_SYNC,
94                 FUNC_NAME_WAIT_SYNC,
95                 FUNC_NAME_NUM_NAMES
96         };
97
98         enum Extension
99         {
100                 EXTENSION_NONE                          = 0,
101                 EXTENSION_WAIT_SYNC                     = (0x1 << 0),
102                 EXTENSION_FENCE_SYNC            = (0x1 << 1),
103                 EXTENSION_REUSABLE_SYNC         = (0x1 << 2)
104         };
105                                                                         SyncTest        (EglTestContext& eglTestCtx, EGLenum syncType, Extension extensions, bool useCurrentContext, const char* name, const char* description);
106                                                                         virtual ~SyncTest       (void);
107
108         void                                                    init            (void);
109         void                                                    deinit          (void);
110         bool                                                    hasRequiredEGLVersion(int requiredMajor, int requiredMinor);
111         bool                                                    hasEGLFenceSyncExtension(void);
112         bool                                                    hasEGLWaitSyncExtension(void);
113         EGLDisplay                                              getEglDisplay() {return m_eglDisplay;}
114
115 protected:
116         const EGLenum                                   m_syncType;
117         const bool                                              m_useCurrentContext;
118
119         glw::Functions                                  m_gl;
120
121         Extension                                               m_extensions;
122         EGLDisplay                                              m_eglDisplay;
123         EGLConfig                                               m_eglConfig;
124         EGLSurface                                              m_eglSurface;
125         eglu::NativeWindow*                             m_nativeWindow;
126         EGLContext                                              m_eglContext;
127         EGLSyncKHR                                              m_sync;
128         string                                                  m_funcNames[FUNC_NAME_NUM_NAMES];
129         string                                                  m_funcNamesKHR[FUNC_NAME_NUM_NAMES];
130 };
131
132 SyncTest::SyncTest (EglTestContext& eglTestCtx, EGLenum syncType, Extension extensions,  bool useCurrentContext, const char* name, const char* description)
133         : TestCase                              (eglTestCtx, name, description)
134         , m_syncType                    (syncType)
135         , m_useCurrentContext   (useCurrentContext)
136         , m_extensions                  (extensions)
137         , m_eglDisplay                  (EGL_NO_DISPLAY)
138         , m_eglConfig           (((eglw::EGLConfig)0))  // EGL_NO_CONFIG
139         , m_eglSurface                  (EGL_NO_SURFACE)
140         , m_nativeWindow                (DE_NULL)
141         , m_eglContext                  (EGL_NO_CONTEXT)
142         , m_sync                                (EGL_NO_SYNC_KHR)
143 {
144         m_funcNames[FUNC_NAME_CREATE_SYNC] = "eglCreateSync";
145         m_funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] = "eglClientWaitSync";
146         m_funcNames[FUNC_NAME_GET_SYNC_ATTRIB] = "eglGetSyncAttrib";
147         m_funcNames[FUNC_NAME_DESTROY_SYNC] = "eglDestroySync";
148         m_funcNames[FUNC_NAME_WAIT_SYNC] = "eglWaitSync";
149
150         m_funcNamesKHR[FUNC_NAME_CREATE_SYNC] = "eglCreateSyncKHR";
151         m_funcNamesKHR[FUNC_NAME_CLIENT_WAIT_SYNC] = "eglClientWaitSyncKHR";
152         m_funcNamesKHR[FUNC_NAME_GET_SYNC_ATTRIB] = "eglGetSyncAttribKHR";
153         m_funcNamesKHR[FUNC_NAME_DESTROY_SYNC] = "eglDestroySyncKHR";
154         m_funcNamesKHR[FUNC_NAME_WAIT_SYNC] = "eglWaitSyncKHR";
155 }
156
157 SyncTest::~SyncTest (void)
158 {
159         SyncTest::deinit();
160 }
161
162 bool SyncTest::hasRequiredEGLVersion (int requiredMajor, int requiredMinor)
163 {
164         const Library&  egl             = m_eglTestCtx.getLibrary();
165         TestLog&                log             = m_testCtx.getLog();
166         eglu::Version   version = eglu::getVersion(egl, m_eglDisplay);
167
168         if (version < eglu::Version(requiredMajor, requiredMinor))
169         {
170                 log << TestLog::Message << "Required EGL version is not supported. "
171                         "Has: " << version.getMajor() << "." << version.getMinor()
172                         << ", Required: " << requiredMajor << "." << requiredMinor << TestLog::EndMessage;
173                 return false;
174         }
175
176         return true;
177 }
178
179 bool SyncTest::hasEGLFenceSyncExtension (void)
180 {
181         TestLog&                log     = m_testCtx.getLog();
182
183         if (!eglu::hasExtension(m_eglTestCtx.getLibrary(), m_eglDisplay, "EGL_KHR_fence_sync"))
184         {
185                 log << TestLog::Message << "EGL_KHR_fence_sync not supported" << TestLog::EndMessage;
186                 return false;
187         }
188
189         return true;
190 }
191
192 bool SyncTest::hasEGLWaitSyncExtension (void)
193 {
194         TestLog&         log    = m_testCtx.getLog();
195
196         if (!eglu::hasExtension(m_eglTestCtx.getLibrary(), m_eglDisplay, "EGL_KHR_wait_sync"))
197         {
198                 log << TestLog::Message << "EGL_KHR_wait_sync not supported" << TestLog::EndMessage;
199                 return false;
200         }
201
202         return true;
203 }
204
205 void requiredGLESExtensions (const glw::Functions& gl)
206 {
207         bool                            found = false;
208         std::istringstream      extensionStream((const char*)gl.getString(GL_EXTENSIONS));
209         string                          extension;
210
211         GLU_CHECK_GLW_MSG(gl, "glGetString(GL_EXTENSIONS)");
212
213         while (std::getline(extensionStream, extension, ' '))
214         {
215                 if (extension == "GL_OES_EGL_sync")
216                         found = true;
217         }
218
219         if (!found)
220                 TCU_THROW(NotSupportedError, "GL_OES_EGL_sync not supported");
221 }
222
223 SyncTest::Extension getSyncTypeExtension (EGLenum syncType)
224 {
225         switch (syncType)
226         {
227                 case EGL_SYNC_FENCE_KHR:        return SyncTest::EXTENSION_FENCE_SYNC;
228                 case EGL_SYNC_REUSABLE_KHR:     return SyncTest::EXTENSION_REUSABLE_SYNC;
229                 default:
230                         DE_ASSERT(DE_FALSE);
231                         return SyncTest::EXTENSION_NONE;
232         }
233 }
234
235 void SyncTest::init (void)
236 {
237         const Library&                                          egl                             = m_eglTestCtx.getLibrary();
238         const eglu::NativeWindowFactory&        windowFactory   = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
239
240         const EGLint displayAttribList[] =
241         {
242                 EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
243                 EGL_SURFACE_TYPE,               EGL_WINDOW_BIT,
244                 EGL_ALPHA_SIZE,                 1,
245                 EGL_NONE
246         };
247
248         const EGLint contextAttribList[] =
249         {
250                 EGL_CONTEXT_CLIENT_VERSION, 2,
251                 EGL_NONE
252         };
253
254         m_eglDisplay    = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
255         m_eglConfig             = eglu::chooseSingleConfig(egl, m_eglDisplay, displayAttribList);
256
257         m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2,0));
258
259         m_extensions = (Extension)(m_extensions | getSyncTypeExtension(m_syncType));
260
261         if (m_useCurrentContext)
262         {
263                 // Create context
264                 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
265                 m_eglContext = egl.createContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAttribList);
266                 EGLU_CHECK_MSG(egl, "Failed to create GLES2 context");
267
268                 // Create surface
269                 m_nativeWindow = windowFactory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_eglDisplay, m_eglConfig, DE_NULL, eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
270                 m_eglSurface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_nativeWindow, m_eglDisplay, m_eglConfig, DE_NULL);
271
272                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
273
274                 requiredGLESExtensions(m_gl);
275         }
276
277         // Verify EXTENSION_REUSABLE_SYNC is supported before running the tests
278         if (m_syncType == EGL_SYNC_REUSABLE_KHR) {
279                 if (!eglu::hasExtension(m_eglTestCtx.getLibrary(), m_eglDisplay, "EGL_KHR_reusable_sync"))
280                 {
281                         TCU_THROW(NotSupportedError, "EGL_KHR_reusable_sync not supported");
282                 }
283         }
284 }
285
286 void SyncTest::deinit (void)
287 {
288         const Library&  egl             = m_eglTestCtx.getLibrary();
289
290         if (m_eglDisplay != EGL_NO_DISPLAY)
291         {
292                 if (m_sync != EGL_NO_SYNC_KHR)
293                 {
294                         EGLU_CHECK_CALL(egl, destroySyncKHR(m_eglDisplay, m_sync));
295                         m_sync = EGL_NO_SYNC_KHR;
296                 }
297
298                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
299
300                 if (m_eglContext != EGL_NO_CONTEXT)
301                 {
302                         EGLU_CHECK_CALL(egl, destroyContext(m_eglDisplay, m_eglContext));
303                         m_eglContext = EGL_NO_CONTEXT;
304                 }
305
306                 if (m_eglSurface != EGL_NO_SURFACE)
307                 {
308                         EGLU_CHECK_CALL(egl, destroySurface(m_eglDisplay, m_eglSurface));
309                         m_eglSurface = EGL_NO_SURFACE;
310                 }
311
312                 delete m_nativeWindow;
313                 m_nativeWindow = DE_NULL;
314
315                 egl.terminate(m_eglDisplay);
316                 m_eglDisplay = EGL_NO_DISPLAY;
317         }
318 }
319
320 class CreateNullAttribsTest : public SyncTest
321 {
322 public:
323                                         CreateNullAttribsTest   (EglTestContext& eglTestCtx, EGLenum syncType)
324                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "create_null_attribs", "create_null_attribs")
325         {
326         }
327
328         template <typename createSyncFuncType>
329         void test(string funcNames[FUNC_NAME_NUM_NAMES],
330                           createSyncFuncType createSyncFunc)
331         {
332                 // Reset before each test
333                 deinit();
334                 init();
335
336                 const Library&  egl             = m_eglTestCtx.getLibrary();
337                 TestLog&                log             = m_testCtx.getLog();
338                 string                  msgChk  = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
339
340                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
341                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] << "(" <<
342                         m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
343                         TestLog::EndMessage;
344                 EGLU_CHECK_MSG(egl, msgChk.c_str());
345         }
346
347         IterateResult iterate(void)
348         {
349                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
350
351                 if (hasRequiredEGLVersion(1, 5))
352                 {
353                         test<createSync>(m_funcNames, &Library::createSync);
354                 }
355                 if (hasEGLFenceSyncExtension())
356                 {
357                         test<createSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR);
358                 }
359                 else if (!hasRequiredEGLVersion(1, 5))
360                 {
361                         TCU_THROW(NotSupportedError, "Required extensions not supported");
362                 }
363
364                 return STOP;
365         }
366 };
367
368 class CreateEmptyAttribsTest : public SyncTest
369 {
370 public:
371                                         CreateEmptyAttribsTest  (EglTestContext& eglTestCtx, EGLenum syncType)
372                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "create_empty_attribs", "create_empty_attribs")
373         {
374         }
375
376         template <typename createSyncFuncType, typename attribType>
377         void test(string funcNames[FUNC_NAME_NUM_NAMES],
378                           createSyncFuncType createSyncFunc)
379         {
380                 // Reset before each test
381                 deinit();
382                 init();
383
384                 const Library&      egl                         = m_eglTestCtx.getLibrary();
385                 TestLog&                    log                         = m_testCtx.getLog();
386                 string              msgChk          = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
387                 const attribType    attribList[]        =
388                 {
389                         EGL_NONE
390                 };
391
392                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, attribList);
393                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
394                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) <<
395                         ", { EGL_NONE })" << TestLog::EndMessage;
396                 EGLU_CHECK_MSG(egl, msgChk.c_str());
397         }
398
399         IterateResult iterate (void)
400         {
401                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
402
403                 if (hasRequiredEGLVersion(1, 5))
404                 {
405                         test<createSync, EGLAttrib>(m_funcNames, &Library::createSync);
406                 }
407                 if (hasEGLFenceSyncExtension())
408                 {
409                         test<createSyncKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR);
410                 }
411                 else if (!hasRequiredEGLVersion(1, 5))
412                 {
413                         TCU_THROW(NotSupportedError, "Required extensions not supported");
414                 }
415
416                 return STOP;
417         }
418 };
419
420 class CreateInvalidDisplayTest : public SyncTest
421 {
422 public:
423                                         CreateInvalidDisplayTest        (EglTestContext& eglTestCtx, EGLenum syncType)
424                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "create_invalid_display", "create_invalid_display")
425         {
426         }
427
428         template <typename createSyncFuncType, typename syncType>
429         void test(string funcNames[FUNC_NAME_NUM_NAMES],
430                           createSyncFuncType createSyncFunc, syncType eglNoSync)
431         {
432                 // Reset before each test
433                 deinit();
434                 init();
435
436                 const Library&  egl             = m_eglTestCtx.getLibrary();
437                 TestLog&                log             = m_testCtx.getLog();
438
439                 m_sync = (egl.*createSyncFunc)(EGL_NO_DISPLAY, m_syncType, NULL);
440                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
441                         "(EGL_NO_DISPLAY, " << getSyncTypeName(m_syncType) << ", NULL)" <<
442                         TestLog::EndMessage;
443
444                 EGLint error = egl.getError();
445                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
446
447                 if (error != EGL_BAD_DISPLAY)
448                 {
449                         log << TestLog::Message << "Unexpected error '" <<
450                                 eglu::getErrorStr(error) << "' expected EGL_BAD_DISPLAY" <<
451                                 TestLog::EndMessage;
452                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
453                         return;
454                 }
455
456                 TCU_CHECK(m_sync == eglNoSync);
457         }
458
459         IterateResult   iterate                                         (void)
460         {
461                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
462
463                 if (hasRequiredEGLVersion(1, 5))
464                 {
465                         test<createSync, EGLSync>(m_funcNames, &Library::createSync, EGL_NO_SYNC);
466                 }
467                 if (hasEGLFenceSyncExtension())
468                 {
469                         test<createSyncKHR, EGLSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR, EGL_NO_SYNC_KHR);
470                 }
471                 else if (!hasRequiredEGLVersion(1, 5))
472                 {
473                         TCU_THROW(NotSupportedError, "Required extensions not supported");
474                 }
475
476                 return STOP;
477         }
478 };
479
480 class CreateInvalidTypeTest : public SyncTest
481 {
482 public:
483                                         CreateInvalidTypeTest   (EglTestContext& eglTestCtx, EGLenum syncType)
484                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "create_invalid_type", "create_invalid_type")
485         {
486         }
487
488         template <typename createSyncFuncType>
489         void test(string funcNames[FUNC_NAME_NUM_NAMES],
490                           createSyncFuncType createSyncFunc, EGLSyncKHR eglNoSync,
491                           EGLint syncError, string syncErrorName)
492         {
493                 // Reset before each test
494                 deinit();
495                 init();
496
497                 const Library&  egl             = m_eglTestCtx.getLibrary();
498                 TestLog&                log             = m_testCtx.getLog();
499
500                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, EGL_NONE, NULL);
501                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] << "(" <<
502                         m_eglDisplay << ", EGL_NONE, NULL)" << TestLog::EndMessage;
503
504                 EGLint error = egl.getError();
505                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
506
507                 if (error != syncError)
508                 {
509                         log << TestLog::Message << "Unexpected error '" <<
510                                 eglu::getErrorStr(error) << "' expected " << syncErrorName << " " <<
511                                 TestLog::EndMessage;
512                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
513                         return;
514                 }
515
516                 TCU_CHECK(m_sync == eglNoSync);
517         }
518
519         IterateResult   iterate                                 (void)
520         {
521                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
522
523                 if (hasRequiredEGLVersion(1, 5))
524                 {
525                         test<createSync>(m_funcNames, &Library::createSync, EGL_NO_SYNC,
526                                                          EGL_BAD_PARAMETER, "EGL_BAD_PARAMETER");
527                 }
528                 if (hasEGLFenceSyncExtension())
529                 {
530                         test<createSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR, EGL_NO_SYNC_KHR,
531                                                                 EGL_BAD_ATTRIBUTE, "EGL_BAD_ATTRIBUTE");
532                 }
533                 else if (!hasRequiredEGLVersion(1, 5))
534                 {
535                         TCU_THROW(NotSupportedError, "Required extensions not supported");
536                 }
537
538                 return STOP;
539         }
540 };
541
542 class CreateInvalidAttribsTest : public SyncTest
543 {
544 public:
545                                         CreateInvalidAttribsTest        (EglTestContext& eglTestCtx, EGLenum syncType)
546                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "create_invalid_attribs", "create_invalid_attribs")
547         {
548         }
549
550         template <typename createSyncFuncType, typename attribType>
551         void test(string funcNames[FUNC_NAME_NUM_NAMES],
552                           createSyncFuncType createSyncFunc, EGLSyncKHR eglNoSync)
553         {
554                 // Reset before each test
555                 deinit();
556                 init();
557
558                 const Library&  egl             = m_eglTestCtx.getLibrary();
559                 TestLog&                log             = m_testCtx.getLog();
560
561                 attribType attribs[] = {
562                         2, 3, 4, 5,
563                         EGL_NONE
564                 };
565
566                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, attribs);
567                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
568                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) <<
569                         ", { 2, 3, 4, 5, EGL_NONE })" << TestLog::EndMessage;
570
571                 EGLint error = egl.getError();
572                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
573
574                 if (error != EGL_BAD_ATTRIBUTE)
575                 {
576                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
577                                 "' expected EGL_BAD_ATTRIBUTE" << TestLog::EndMessage;
578                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
579                         return;
580                 }
581
582                 TCU_CHECK(m_sync == eglNoSync);
583         }
584
585         IterateResult   iterate                                         (void)
586         {
587                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
588
589                 if (hasRequiredEGLVersion(1, 5))
590                 {
591                         test<createSync, EGLAttrib>(m_funcNames, &Library::createSync, EGL_NO_SYNC);
592                 }
593                 if (hasEGLFenceSyncExtension())
594                 {
595                         test<createSyncKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR, EGL_NO_SYNC_KHR);
596                 }
597                 else if (!hasRequiredEGLVersion(1, 5))
598                 {
599                         TCU_THROW(NotSupportedError, "Required extensions not supported");
600                 }
601
602                 return STOP;
603         }
604 };
605
606 class CreateInvalidContextTest : public SyncTest
607 {
608 public:
609                                         CreateInvalidContextTest        (EglTestContext& eglTestCtx, EGLenum syncType)
610                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "create_invalid_context", "create_invalid_context")
611         {
612         }
613
614         template <typename createSyncFuncType>
615         void test(string funcNames[FUNC_NAME_NUM_NAMES],
616                           createSyncFuncType createSyncFunc, EGLSyncKHR eglNoSync)
617         {
618                 // Reset before each test
619                 deinit();
620                 init();
621
622                 const Library&  egl             = m_eglTestCtx.getLibrary();
623                 TestLog&                log             = m_testCtx.getLog();
624
625                 log << TestLog::Message << "eglMakeCurrent(" << m_eglDisplay <<
626                         ", EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)" << TestLog::EndMessage;
627                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE,
628                                                                                  EGL_NO_SURFACE, EGL_NO_CONTEXT));
629
630                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
631                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
632                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
633                         TestLog::EndMessage;
634
635                 EGLint error = egl.getError();
636                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
637
638                 if (error != EGL_BAD_MATCH)
639                 {
640                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
641                                 "' expected EGL_BAD_MATCH" << TestLog::EndMessage;
642                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
643                         return;
644                 }
645
646                 TCU_CHECK(m_sync == eglNoSync);
647         }
648
649         IterateResult   iterate                                         (void)
650         {
651                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
652
653                 if (hasRequiredEGLVersion(1, 5))
654                 {
655                         test<createSync>(m_funcNames, &Library::createSync, EGL_NO_SYNC);
656                 }
657                 if (hasEGLFenceSyncExtension())
658                 {
659                         test<createSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR, EGL_NO_SYNC_KHR);
660                 }
661                 else if (!hasRequiredEGLVersion(1, 5))
662                 {
663                         TCU_THROW(NotSupportedError, "Required extensions not supported");
664                 }
665
666                 return STOP;
667         }
668 };
669
670 class ClientWaitNoTimeoutTest : public SyncTest
671 {
672 public:
673                                         ClientWaitNoTimeoutTest (EglTestContext& eglTestCtx, EGLenum syncType)
674                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR,  "wait_no_timeout", "wait_no_timeout")
675         {
676         }
677
678         template <typename createSyncFuncType, typename clientWaitSyncFuncType>
679         void test(string funcNames[FUNC_NAME_NUM_NAMES],
680                           createSyncFuncType createSyncFunc,
681                           clientWaitSyncFuncType clientWaitSyncFunc)
682         {
683                 // Reset before each test
684                 deinit();
685                 init();
686
687                 const Library&  egl             = m_eglTestCtx.getLibrary();
688                 TestLog&                log             = m_testCtx.getLog();
689                 string          msgChk  = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
690
691                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
692                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
693                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
694                         TestLog::EndMessage;
695                 EGLU_CHECK_MSG(egl, msgChk.c_str());
696
697                 EGLint status = (egl.*clientWaitSyncFunc)(m_eglDisplay, m_sync, 0, 0);
698                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
699                         "(" << m_eglDisplay << ", " << m_sync << ", 0, 0)" << TestLog::EndMessage;
700
701                 if (m_syncType == EGL_SYNC_FENCE_KHR)
702                         TCU_CHECK(status == EGL_CONDITION_SATISFIED_KHR || status == EGL_TIMEOUT_EXPIRED_KHR);
703                 else if (m_syncType == EGL_SYNC_REUSABLE_KHR)
704                         TCU_CHECK(status == EGL_TIMEOUT_EXPIRED_KHR);
705                 else
706                         DE_ASSERT(DE_FALSE);
707         }
708
709         IterateResult   iterate                                 (void)
710         {
711                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
712
713                 if (hasRequiredEGLVersion(1, 5))
714                 {
715                         test<createSync, clientWaitSync>(m_funcNames, &Library::createSync,
716                                                                                          &Library::clientWaitSync);
717                 }
718                 if (hasEGLFenceSyncExtension())
719                 {
720                         test<createSyncKHR, clientWaitSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR,
721                                                                                                    &Library::clientWaitSyncKHR);
722                 }
723                 else if (!hasRequiredEGLVersion(1, 5))
724                 {
725                         TCU_THROW(NotSupportedError, "Required extensions not supported");
726                 }
727
728                 return STOP;
729         }
730
731 };
732
733 class ClientWaitForeverTest : public SyncTest
734 {
735 public:
736                                         ClientWaitForeverTest   (EglTestContext& eglTestCtx, EGLenum syncType)
737         : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "wait_forever", "wait_forever")
738         {
739         }
740
741         template <typename createSyncFuncType, typename clientWaitSyncFuncType>
742         void test(string funcNames[FUNC_NAME_NUM_NAMES],
743                           createSyncFuncType createSyncFunc,
744                           clientWaitSyncFuncType clientWaitSyncFunc,
745                           EGLTime eglTime, const string &eglTimeName,
746                           EGLint condSatisfied)
747         {
748                 // Reset before each test
749                 deinit();
750                 init();
751
752                 const Library&  egl                             = m_eglTestCtx.getLibrary();
753                 TestLog&                log                             = m_testCtx.getLog();
754                 string          createSyncMsgChk        = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
755                 string          clientWaitSyncMsgChk    = funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] + "()";
756
757                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
758                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
759                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
760                         TestLog::EndMessage;
761                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
762
763                 if (m_syncType == EGL_SYNC_REUSABLE_KHR)
764                 {
765                         EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
766                         log << TestLog::Message << ret << " = eglSignalSyncKHR(" <<
767                                 m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" <<
768                                 TestLog::EndMessage;
769                         EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
770                 }
771                 else if (m_syncType == EGL_SYNC_FENCE_KHR)
772                 {
773                         GLU_CHECK_GLW_CALL(m_gl, flush());
774                         log << TestLog::Message << "glFlush()" << TestLog::EndMessage;
775                 }
776                 else
777                         DE_ASSERT(DE_FALSE);
778
779                 EGLint status = (egl.*clientWaitSyncFunc)(m_eglDisplay, m_sync, 0, eglTime);
780                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
781                         "(" << m_eglDisplay << ", " << m_sync << ", 0, " << eglTimeName << ")" <<
782                         TestLog::EndMessage;
783
784                 TCU_CHECK(status == condSatisfied);
785                 EGLU_CHECK_MSG(egl, clientWaitSyncMsgChk.c_str());
786         }
787
788         IterateResult   iterate                                 (void)
789         {
790                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
791
792                 if (hasRequiredEGLVersion(1, 5))
793                 {
794                         test<createSync, clientWaitSync>(m_funcNames, &Library::createSync,
795                                                                                          &Library::clientWaitSync,
796                                                                                          EGL_FOREVER, "EGL_FOREVER",
797                                                                                          EGL_CONDITION_SATISFIED);
798                 }
799                 if (hasEGLFenceSyncExtension())
800                 {
801                         test<createSyncKHR, clientWaitSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR,
802                                                                                                    &Library::clientWaitSyncKHR,
803                                                                                                    EGL_FOREVER_KHR, "EGL_FOREVER_KHR",
804                                                                                                    EGL_CONDITION_SATISFIED_KHR);
805                 }
806                 else if (!hasRequiredEGLVersion(1, 5))
807                 {
808                         TCU_THROW(NotSupportedError, "Required extensions not supported");
809                 }
810
811                 return STOP;
812         }
813 };
814
815 class ClientWaitNoContextTest : public SyncTest
816 {
817 public:
818                                         ClientWaitNoContextTest (EglTestContext& eglTestCtx, EGLenum syncType)
819                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "wait_no_context", "wait_no_Context")
820         {
821         }
822
823         template <typename createSyncFuncType, typename clientWaitSyncFuncType>
824         void test(string funcNames[FUNC_NAME_NUM_NAMES],
825                           createSyncFuncType createSyncFunc,
826                           clientWaitSyncFuncType clientWaitSyncFunc,
827                           EGLint condSatisfied, EGLTime eglTime, const string &eglTimeName)
828         {
829                 // Reset before each test
830                 deinit();
831                 init();
832
833                 const Library&  egl                       = m_eglTestCtx.getLibrary();
834                 TestLog&                log                       = m_testCtx.getLog();
835                 string          createSyncMsgChk  = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
836
837                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
838                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
839                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
840                         TestLog::EndMessage;
841                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
842
843
844                 if (m_syncType == EGL_SYNC_REUSABLE_KHR)
845                 {
846                         EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
847                         log << TestLog::Message << ret << " = eglSignalSyncKHR(" <<
848                                 m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" <<
849                                 TestLog::EndMessage;
850                         EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
851                 }
852                 else if (m_syncType == EGL_SYNC_FENCE_KHR)
853                 {
854                         GLU_CHECK_GLW_CALL(m_gl, flush());
855                         log << TestLog::Message << "glFlush()" << TestLog::EndMessage;
856                 }
857                 else
858                         DE_ASSERT(DE_FALSE);
859
860                 log << TestLog::Message << "eglMakeCurrent(" << m_eglDisplay <<
861                         ", EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)" << TestLog::EndMessage;
862                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE,
863                                                                                  EGL_NO_SURFACE, EGL_NO_CONTEXT));
864
865                 EGLint result = (egl.*clientWaitSyncFunc)(m_eglDisplay, m_sync, 0, eglTime);
866                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
867                         "(" << m_eglDisplay << ", " << m_sync << ", 0, " << eglTimeName << ")" <<
868                         TestLog::EndMessage;
869
870                 TCU_CHECK(result == condSatisfied);
871         }
872
873         IterateResult   iterate                                 (void)
874         {
875                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
876
877                 if (hasRequiredEGLVersion(1, 5))
878                 {
879                         test<createSync, clientWaitSync>(m_funcNames, &Library::createSync,
880                                                                                          &Library::clientWaitSync,
881                                                                                          EGL_CONDITION_SATISFIED, EGL_FOREVER, "EGL_FOREVER");
882                 }
883                 if (hasEGLFenceSyncExtension())
884                 {
885                         test<createSyncKHR, clientWaitSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR,
886                                                                                                    &Library::clientWaitSyncKHR,
887                                                                                                    EGL_CONDITION_SATISFIED_KHR, EGL_FOREVER_KHR, "EGL_FOREVER_KHR");
888                 }
889                 else if (!hasRequiredEGLVersion(1, 5))
890                 {
891                         TCU_THROW(NotSupportedError, "Required extensions not supported");
892                 }
893
894                 return STOP;
895         }
896 };
897
898 class ClientWaitForeverFlushTest : public SyncTest
899 {
900 public:
901                                         ClientWaitForeverFlushTest      (EglTestContext& eglTestCtx, EGLenum syncType)
902                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "wait_forever_flush", "wait_forever_flush")
903         {
904         }
905
906         template <typename createSyncFuncType, typename clientWaitSyncFuncType>
907         void test(string funcNames[FUNC_NAME_NUM_NAMES],
908                           createSyncFuncType createSyncFunc,
909                           clientWaitSyncFuncType clientWaitSyncFunc,
910                           EGLint flags, const string &flagsName,
911                           EGLTime eglTime, const string &eglTimeName,
912                           EGLint condSatisfied)
913         {
914                 // Reset before each test
915                 deinit();
916                 init();
917
918                 const Library&  egl                         = m_eglTestCtx.getLibrary();
919                 TestLog&                log                         = m_testCtx.getLog();
920                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
921
922                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
923                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
924                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
925                         TestLog::EndMessage;
926                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
927
928                 if (m_syncType == EGL_SYNC_REUSABLE_KHR)
929                 {
930                         EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
931                         log << TestLog::Message << ret << " = eglSignalSyncKHR(" <<
932                                 m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" <<
933                                 TestLog::EndMessage;
934                         EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
935                 }
936
937                 EGLint status = (egl.*clientWaitSyncFunc)(m_eglDisplay, m_sync, flags, eglTime);
938                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
939                         "(" << m_eglDisplay << ", " << m_sync << ", " << flagsName << ", " <<
940                         eglTimeName << ")" << TestLog::EndMessage;
941
942                 TCU_CHECK(status == condSatisfied);
943
944         }
945
946         IterateResult   iterate                                         (void)
947         {
948                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
949
950                 if (hasRequiredEGLVersion(1, 5))
951                 {
952                         test<createSync, clientWaitSync>(m_funcNames, &Library::createSync,
953                                                                                          &Library::clientWaitSync,
954                                                                                          EGL_SYNC_FLUSH_COMMANDS_BIT, "EGL_SYNC_FLUSH_COMMANDS_BIT",
955                                                                                          EGL_FOREVER, "EGL_FOREVER",
956                                                                                          EGL_CONDITION_SATISFIED);
957                 }
958                 if (hasEGLFenceSyncExtension())
959                 {
960                         test<createSyncKHR, clientWaitSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR,
961                                                                                                    &Library::clientWaitSyncKHR,
962                                                                                                    EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, "EGL_SYNC_FLUSH_COMMANDS_BIT_KHR",
963                                                                                                    EGL_FOREVER_KHR, "EGL_FOREVER_KHR",
964                                                                                                    EGL_CONDITION_SATISFIED_KHR);
965                 }
966                 else if (!hasRequiredEGLVersion(1, 5))
967                 {
968                         TCU_THROW(NotSupportedError, "Required extensions not supported");
969                 }
970
971                 return STOP;
972         }
973 };
974
975 class ClientWaitInvalidDisplayTest : public SyncTest
976 {
977 public:
978                                         ClientWaitInvalidDisplayTest    (EglTestContext& eglTestCtx, EGLenum syncType)
979                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "wait_invalid_display", "wait_invalid_display")
980         {
981         }
982
983         template <typename createSyncFuncType, typename clientWaitSyncFuncType>
984         void test(string funcNames[FUNC_NAME_NUM_NAMES],
985                           createSyncFuncType createSyncFunc,
986                           clientWaitSyncFuncType clientWaitSyncFunc,
987                           EGLint flags, const string &flagsName,
988                           EGLTime eglTime, const string &eglTimeName)
989         {
990                 // Reset before each test
991                 deinit();
992                 init();
993
994                 const Library&  egl                         = m_eglTestCtx.getLibrary();
995                 TestLog&                log                         = m_testCtx.getLog();
996                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
997
998                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
999                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] << "(" <<
1000                         m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1001                         TestLog::EndMessage;
1002                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1003
1004                 EGLint status = (egl.*clientWaitSyncFunc)(EGL_NO_DISPLAY, m_sync, flags, eglTime);
1005                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
1006                         "(EGL_NO_DISPLAY, " << m_sync << ", " << flagsName << ", " <<
1007                         eglTimeName << ")" << TestLog::EndMessage;
1008
1009                 EGLint error = egl.getError();
1010                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1011
1012                 if (error != EGL_BAD_DISPLAY)
1013                 {
1014                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1015                                 "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
1016                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1017                         return;
1018                 }
1019
1020                 TCU_CHECK(status == EGL_FALSE);
1021         }
1022
1023         IterateResult   iterate                                                 (void)
1024         {
1025                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1026
1027                 if (hasRequiredEGLVersion(1, 5))
1028                 {
1029                         test<createSync, clientWaitSync>(m_funcNames, &Library::createSync,
1030                                                                                          &Library::clientWaitSync,
1031                                                                                          EGL_SYNC_FLUSH_COMMANDS_BIT, "EGL_SYNC_FLUSH_COMMANDS_BIT",
1032                                                                                          EGL_FOREVER, "EGL_FOREVER");
1033                 }
1034                 if (hasEGLFenceSyncExtension())
1035                 {
1036                         test<createSyncKHR, clientWaitSyncKHR>(m_funcNamesKHR, &Library::createSyncKHR,
1037                                                                                                    &Library::clientWaitSyncKHR,
1038                                                                                                    EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, "EGL_SYNC_FLUSH_COMMANDS_BIT_KHR",
1039                                                                                                    EGL_FOREVER_KHR, "EGL_FOREVER_KHR");
1040                 }
1041                 else if (!hasRequiredEGLVersion(1, 5))
1042                 {
1043                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1044                 }
1045
1046                 return STOP;
1047         }
1048 };
1049
1050 class ClientWaitInvalidSyncTest : public SyncTest
1051 {
1052 public:
1053                                         ClientWaitInvalidSyncTest       (EglTestContext& eglTestCtx, EGLenum syncType)
1054                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "wait_invalid_sync", "wait_invalid_sync")
1055         {
1056         }
1057
1058         template <typename clientWaitSyncFuncType>
1059         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1060                           clientWaitSyncFuncType clientWaitSyncFunc,
1061                           EGLSync sync, const string &syncName,
1062                           EGLTime eglTime, const string &eglTimeName)
1063         {
1064                 // Reset before each test
1065                 deinit();
1066                 init();
1067
1068                 const Library&  egl             = m_eglTestCtx.getLibrary();
1069                 TestLog&                log             = m_testCtx.getLog();
1070
1071                 EGLint status = (egl.*clientWaitSyncFunc)(m_eglDisplay, sync, 0, eglTime);
1072                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] <<
1073                         "(" << m_eglDisplay << ", " << syncName << ", 0, " << eglTimeName << ")" <<
1074                         TestLog::EndMessage;
1075
1076                 EGLint error = egl.getError();
1077                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1078
1079                 if (error != EGL_BAD_PARAMETER)
1080                 {
1081                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1082                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1083                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1084                         return;
1085                 }
1086
1087                 TCU_CHECK(status == EGL_FALSE);
1088         }
1089
1090         IterateResult   iterate                                         (void)
1091         {
1092                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1093
1094                 if (hasRequiredEGLVersion(1, 5))
1095                 {
1096                         test<clientWaitSync>(m_funcNames, &Library::clientWaitSync,
1097                                                                  EGL_NO_SYNC, "EGL_NO_SYNC",
1098                                                                  EGL_FOREVER, "EGL_FOREVER");
1099                 }
1100                 if (hasEGLFenceSyncExtension())
1101                 {
1102                         test<clientWaitSyncKHR>(m_funcNamesKHR, &Library::clientWaitSyncKHR,
1103                                                                         EGL_NO_SYNC_KHR, "EGL_NO_SYNC_KHR",
1104                                                                         EGL_FOREVER_KHR, "EGL_FOREVER_KHR");
1105                 }
1106                 else if (!hasRequiredEGLVersion(1, 5))
1107                 {
1108                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1109                 }
1110
1111                 return STOP;
1112         }
1113 };
1114
1115 class GetSyncTypeTest : public SyncTest
1116 {
1117 public:
1118                                         GetSyncTypeTest (EglTestContext& eglTestCtx, EGLenum syncType)
1119                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "get_type", "get_type")
1120         {
1121         }
1122
1123         template <typename createSyncFuncType, typename getSyncAttribFuncType, typename getSyncAttribValueType>
1124         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1125                           createSyncFuncType createSyncFunc,
1126                           getSyncAttribFuncType getSyncAttribFunc,
1127                           EGLint attribute, const string &attributeName)
1128         {
1129                 // Reset before each test
1130                 deinit();
1131                 init();
1132
1133                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1134                 TestLog&                log                         = m_testCtx.getLog();
1135                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1136
1137                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1138                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1139                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1140                         TestLog::EndMessage;
1141                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1142
1143                 getSyncAttribValueType type = 0;
1144                 EGLU_CHECK_CALL_FPTR(egl, (egl.*getSyncAttribFunc)(m_eglDisplay, m_sync,
1145                                                                                                                    attribute, &type));
1146                 log << TestLog::Message << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] << "(" << m_eglDisplay <<
1147                         ", " << m_sync << ", " << attributeName << ", {" << type << "})" <<
1148                         TestLog::EndMessage;
1149
1150                 TCU_CHECK(type == ((getSyncAttribValueType)m_syncType));
1151         }
1152
1153         IterateResult   iterate                 (void)
1154         {
1155                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1156
1157                 if (hasRequiredEGLVersion(1, 5))
1158                 {
1159                         test<createSync, getSyncAttrib, EGLAttrib>(m_funcNames, &Library::createSync,
1160                                                                                                            &Library::getSyncAttrib,
1161                                                                                                            EGL_SYNC_TYPE, "EGL_SYNC_TYPE");
1162                 }
1163                 if (hasEGLFenceSyncExtension())
1164                 {
1165                         test<createSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR,
1166                                                                                                                   &Library::getSyncAttribKHR,
1167                                                                                                                   EGL_SYNC_TYPE_KHR, "EGL_SYNC_TYPE_KHR");
1168                 }
1169                 else if (!hasRequiredEGLVersion(1, 5))
1170                 {
1171                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1172                 }
1173
1174                 return STOP;
1175         }
1176 };
1177
1178 class GetSyncStatusTest : public SyncTest
1179 {
1180 public:
1181                                         GetSyncStatusTest       (EglTestContext& eglTestCtx, EGLenum syncType)
1182                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "get_status", "get_status")
1183         {
1184         }
1185
1186         template <typename createSyncFuncType, typename getSyncAttribFuncType, typename getSyncAttribValueType>
1187         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1188                           createSyncFuncType createSyncFunc,
1189                           getSyncAttribFuncType getSyncAttribFunc,
1190                           EGLint attribute, const string &attributeName)
1191         {
1192                 // Reset before each test
1193                 deinit();
1194                 init();
1195
1196                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1197                 TestLog&                log                         = m_testCtx.getLog();
1198                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1199
1200                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1201                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1202                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1203                         TestLog::EndMessage;
1204                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1205
1206                 getSyncAttribValueType status = 0;
1207                 EGLU_CHECK_CALL_FPTR(egl, (egl.*getSyncAttribFunc)(m_eglDisplay, m_sync, attribute, &status));
1208                 log << TestLog::Message << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] << "(" <<
1209                         m_eglDisplay << ", " << m_sync << ", " << attributeName << ", {" <<
1210                         status << "})" << TestLog::EndMessage;
1211
1212                 if (m_syncType == EGL_SYNC_FENCE_KHR)
1213                         TCU_CHECK(status == EGL_SIGNALED_KHR || status == EGL_UNSIGNALED_KHR);
1214                 else if (m_syncType == EGL_SYNC_REUSABLE_KHR)
1215                         TCU_CHECK(status == EGL_UNSIGNALED_KHR);
1216         }
1217
1218         IterateResult   iterate                         (void)
1219         {
1220                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1221
1222                 if (hasRequiredEGLVersion(1, 5))
1223                 {
1224                         test<createSync, getSyncAttrib, EGLAttrib>(m_funcNames, &Library::createSync,
1225                                                                                                            &Library::getSyncAttrib,
1226                                                                                                            EGL_SYNC_STATUS, "EGL_SYNC_STATUS");
1227                 }
1228                 if (hasEGLFenceSyncExtension())
1229                 {
1230                         test<createSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR,
1231                                                                                                                   &Library::getSyncAttribKHR,
1232                                                                                                                   EGL_SYNC_STATUS_KHR, "EGL_SYNC_STATUS_KHR");
1233                 }
1234                 else if (!hasRequiredEGLVersion(1, 5))
1235                 {
1236                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1237                 }
1238
1239                 return STOP;
1240         }
1241 };
1242
1243 class GetSyncStatusSignaledTest : public SyncTest
1244 {
1245 public:
1246                                         GetSyncStatusSignaledTest       (EglTestContext& eglTestCtx, EGLenum syncType)
1247                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "get_status_signaled", "get_status_signaled")
1248         {
1249         }
1250
1251         template <typename createSyncFuncType,
1252                 typename clientWaitSyncFuncType,
1253                 typename getSyncAttribFuncType,
1254                 typename getSyncAttribValueType>
1255         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1256                           createSyncFuncType createSyncFunc,
1257                           clientWaitSyncFuncType clientWaitSyncFunc,
1258                           EGLint flags, const string &flagsName,
1259                           EGLTime eglTime, const string &eglTimeName,
1260                           EGLint condSatisfied,
1261                           getSyncAttribFuncType getSyncAttribFunc,
1262                           EGLint attribute, const string &attributeName,
1263                           getSyncAttribValueType statusVal)
1264         {
1265                 // Reset before each test
1266                 deinit();
1267                 init();
1268
1269                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1270                 TestLog&                log                         = m_testCtx.getLog();
1271                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1272
1273                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1274                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1275                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1276                         TestLog::EndMessage;
1277                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1278
1279                 if (m_syncType == EGL_SYNC_REUSABLE_KHR)
1280                 {
1281                         EGLBoolean ret = egl.signalSyncKHR(m_eglDisplay, m_sync, EGL_SIGNALED_KHR);
1282                         log << TestLog::Message << ret << " = eglSignalSyncKHR(" <<
1283                                 m_eglDisplay << ", " << m_sync << ", EGL_SIGNALED_KHR)" <<
1284                                 TestLog::EndMessage;
1285                         EGLU_CHECK_MSG(egl, "eglSignalSyncKHR()");
1286                 }
1287                 else if (m_syncType == EGL_SYNC_FENCE_KHR)
1288                 {
1289                         GLU_CHECK_GLW_CALL(m_gl, finish());
1290                         log << TestLog::Message << "glFinish()" << TestLog::EndMessage;
1291                 }
1292                 else
1293                         DE_ASSERT(DE_FALSE);
1294
1295                 {
1296                         EGLint status = (egl.*clientWaitSyncFunc)(m_eglDisplay, m_sync, flags, eglTime);
1297                         log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_CLIENT_WAIT_SYNC] << "(" <<
1298                                 m_eglDisplay << ", " << m_sync << ", " << flagsName << ", " <<
1299                                 eglTimeName << ")" << TestLog::EndMessage;
1300                         TCU_CHECK(status == condSatisfied);
1301                 }
1302
1303                 getSyncAttribValueType status = 0;
1304                 EGLU_CHECK_CALL_FPTR(egl, (egl.*getSyncAttribFunc)(m_eglDisplay, m_sync, attribute, &status));
1305                 log << TestLog::Message << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] << "(" <<
1306                         m_eglDisplay << ", " << m_sync << ", " << attributeName << ", {" <<
1307                         status << "})" << TestLog::EndMessage;
1308
1309                 TCU_CHECK(status == statusVal);
1310         }
1311
1312         IterateResult   iterate                                         (void)
1313         {
1314                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1315
1316                 if (hasRequiredEGLVersion(1, 5))
1317                 {
1318                         test<createSync, clientWaitSync, getSyncAttrib, EGLAttrib>(m_funcNames,
1319                                                                                                                                            &Library::createSync,
1320                                                                                                                                            &Library::clientWaitSync,
1321                                                                                                                                            EGL_SYNC_FLUSH_COMMANDS_BIT, "EGL_SYNC_FLUSH_COMMANDS_BIT",
1322                                                                                                                                            EGL_FOREVER, "EGL_FOREVER",
1323                                                                                                                                            EGL_CONDITION_SATISFIED,
1324                                                                                                                                            &Library::getSyncAttrib,
1325                                                                                                                                            EGL_SYNC_STATUS, "EGL_SYNC_STATUS",
1326                                                                                                                                            EGL_SIGNALED);
1327                 }
1328                 if (hasEGLFenceSyncExtension())
1329                 {
1330                         test<createSyncKHR, clientWaitSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR,
1331                                                                                                                                                          &Library::createSyncKHR,
1332                                                                                                                                                          &Library::clientWaitSyncKHR,
1333                                                                                                                                                          EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, "EGL_SYNC_FLUSH_COMMANDS_BIT_KHR",
1334                                                                                                                                                          EGL_FOREVER_KHR, "EGL_FOREVER_KHR",
1335                                                                                                                                                          EGL_CONDITION_SATISFIED_KHR,
1336                                                                                                                                                          &Library::getSyncAttribKHR,
1337                                                                                                                                                          EGL_SYNC_STATUS_KHR, "EGL_SYNC_STATUS_KHR",
1338                                                                                                                                                          EGL_SIGNALED_KHR);
1339                 }
1340                 else if (!hasRequiredEGLVersion(1, 5))
1341                 {
1342                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1343                 }
1344
1345                 return STOP;
1346         }
1347 };
1348
1349 class GetSyncConditionTest : public SyncTest
1350 {
1351 public:
1352                                         GetSyncConditionTest    (EglTestContext& eglTestCtx, EGLenum syncType)
1353                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "get_condition", "get_condition")
1354         {
1355         }
1356
1357         template <typename createSyncFuncType,
1358                 typename getSyncAttribFuncType,
1359                 typename getSyncAttribValueType>
1360         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1361                           createSyncFuncType createSyncFunc,
1362                           getSyncAttribFuncType getSyncAttribFunc,
1363                           EGLint attribute, const string &attributeName,
1364                           getSyncAttribValueType statusVal)
1365         {
1366                 // Reset before each test
1367                 deinit();
1368                 init();
1369
1370                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1371                 TestLog&                log                         = m_testCtx.getLog();
1372                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1373
1374                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1375                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1376                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1377                         TestLog::EndMessage;
1378                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1379
1380                 getSyncAttribValueType condition = 0;
1381                 EGLU_CHECK_CALL_FPTR(egl, (egl.*getSyncAttribFunc)(m_eglDisplay, m_sync,
1382                                                                                                                    attribute, &condition));
1383                 log << TestLog::Message << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] << "(" <<
1384                         m_eglDisplay << ", " << m_sync << ", " << attributeName << ", {" <<
1385                         condition << "})" << TestLog::EndMessage;
1386
1387                 TCU_CHECK(condition == statusVal);
1388         }
1389
1390         IterateResult   iterate                                 (void)
1391         {
1392                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1393
1394                 if (hasRequiredEGLVersion(1, 5))
1395                 {
1396                         test<createSync, getSyncAttrib, EGLAttrib>(m_funcNames, &Library::createSync,
1397                                                                                                            &Library::getSyncAttrib,
1398                                                                                                            EGL_SYNC_CONDITION, "EGL_SYNC_CONDITION",
1399                                                                                                            EGL_SYNC_PRIOR_COMMANDS_COMPLETE);
1400                 }
1401                 if (hasEGLFenceSyncExtension())
1402                 {
1403                         test<createSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR,
1404                                                                                                                   &Library::getSyncAttribKHR,
1405                                                                                                                   EGL_SYNC_CONDITION_KHR, "EGL_SYNC_CONDITION_KHR",
1406                                                                                                                   EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR);
1407                 }
1408                 else if (!hasRequiredEGLVersion(1, 5))
1409                 {
1410                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1411                 }
1412
1413                 return STOP;
1414         }
1415 };
1416
1417 class GetSyncInvalidDisplayTest : public SyncTest
1418 {
1419 public:
1420                                         GetSyncInvalidDisplayTest       (EglTestContext& eglTestCtx, EGLenum syncType)
1421                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"get_invalid_display", "get_invalid_display")
1422         {
1423         }
1424
1425         template <typename createSyncFuncType,
1426                 typename getSyncAttribFuncType,
1427                 typename getSyncAttribValueType>
1428         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1429                           createSyncFuncType createSyncFunc,
1430                           getSyncAttribFuncType getSyncAttribFunc,
1431                           EGLint attribute, const string &attributeName)
1432         {
1433                 // Reset before each test
1434                 deinit();
1435                 init();
1436
1437                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1438                 TestLog&                log                         = m_testCtx.getLog();
1439                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1440
1441                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1442                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1443                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1444                         TestLog::EndMessage;
1445                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1446
1447                 getSyncAttribValueType condition = 0xF0F0F;
1448                 EGLBoolean result = (egl.*getSyncAttribFunc)(EGL_NO_DISPLAY, m_sync, attribute, &condition);
1449                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] <<
1450                         "(EGL_NO_DISPLAY, " << m_sync << ", " << attributeName << ", {" <<
1451                         condition << "})" << TestLog::EndMessage;
1452
1453                 EGLint error = egl.getError();
1454                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1455
1456                 if (error != EGL_BAD_DISPLAY)
1457                 {
1458                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1459                                 "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
1460                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1461                         return;
1462                 }
1463
1464                 TCU_CHECK(result == EGL_FALSE);
1465                 TCU_CHECK(condition == 0xF0F0F);
1466         }
1467
1468         IterateResult   iterate                                         (void)
1469         {
1470                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1471
1472                 if (hasRequiredEGLVersion(1, 5))
1473                 {
1474                         test<createSync, getSyncAttrib, EGLAttrib>(m_funcNames, &Library::createSync,
1475                                                                                                            &Library::getSyncAttrib,
1476                                                                                                            EGL_SYNC_CONDITION, "EGL_SYNC_CONDITION");
1477                 }
1478                 if (hasEGLFenceSyncExtension())
1479                 {
1480                         test<createSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR, &Library::createSyncKHR,
1481                                                                                                                   &Library::getSyncAttribKHR,
1482                                                                                                                   EGL_SYNC_CONDITION_KHR, "EGL_SYNC_CONDITION_KHR");
1483                 }
1484                 else if (!hasRequiredEGLVersion(1, 5))
1485                 {
1486                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1487                 }
1488
1489                 return STOP;
1490         }
1491 };
1492
1493 class GetSyncInvalidSyncTest : public SyncTest
1494 {
1495 public:
1496                                         GetSyncInvalidSyncTest  (EglTestContext& eglTestCtx, EGLenum syncType)\
1497                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE, syncType != EGL_SYNC_REUSABLE_KHR, "get_invalid_sync", "get_invalid_sync")
1498         {
1499         }
1500
1501         template <typename getSyncAttribFuncType,
1502                 typename getSyncSyncValueType,
1503                 typename getSyncAttribValueType>
1504         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1505                           getSyncAttribFuncType getSyncAttribFunc,
1506                           getSyncSyncValueType syncValue, const string &syncName,
1507                           EGLint attribute, const string &attributeName)
1508         {
1509                 // Reset before each test
1510                 deinit();
1511                 init();
1512
1513                 const Library&  egl             = m_eglTestCtx.getLibrary();
1514                 TestLog&                log             = m_testCtx.getLog();
1515
1516                 getSyncAttribValueType condition = 0xF0F0F;
1517                 EGLBoolean result = (egl.*getSyncAttribFunc)(m_eglDisplay, syncValue,
1518                         attribute, &condition);
1519                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] <<
1520                         "(" << m_eglDisplay << ", " << syncName << ", " << attributeName << ", {" <<
1521                         condition << "})" << TestLog::EndMessage;
1522
1523                 EGLint error = egl.getError();
1524                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1525
1526                 if (error != EGL_BAD_PARAMETER)
1527                 {
1528                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1529                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1530                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1531                         return;
1532                 }
1533
1534                 TCU_CHECK(result == EGL_FALSE);
1535                 TCU_CHECK(condition == 0xF0F0F);
1536         }
1537
1538         IterateResult   iterate                                 (void)
1539         {
1540                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1541
1542                 if (hasRequiredEGLVersion(1, 5))
1543                 {
1544                         test<getSyncAttrib, EGLSync, EGLAttrib>(m_funcNames, &Library::getSyncAttrib,
1545                                                                                                         EGL_NO_SYNC, "EGL_NO_SYNC",
1546                                                                                                         EGL_SYNC_CONDITION, "EGL_SYNC_CONDITION");
1547                 }
1548                 if (hasEGLFenceSyncExtension())
1549                 {
1550                         test<getSyncAttribKHR, EGLSyncKHR, EGLint>(m_funcNamesKHR, &Library::getSyncAttribKHR,
1551                                                                                                            EGL_NO_SYNC_KHR, "EGL_NO_SYNC_KHR",
1552                                                                                                            EGL_SYNC_CONDITION_KHR, "EGL_SYNC_CONDITION_KHR");
1553                 }
1554                 else if (!hasRequiredEGLVersion(1, 5))
1555                 {
1556                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1557                 }
1558
1559                 return STOP;
1560         }
1561 };
1562
1563 class GetSyncInvalidAttributeTest : public SyncTest
1564 {
1565 public:
1566                                         GetSyncInvalidAttributeTest     (EglTestContext& eglTestCtx, EGLenum syncType)
1567                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"get_invalid_attribute", "get_invalid_attribute")
1568         {
1569         }
1570
1571         template <typename createSyncFuncType,
1572                 typename getSyncAttribFuncType,
1573                 typename getSyncAttribValueType>
1574         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1575                           createSyncFuncType createSyncFunc,
1576                           getSyncAttribFuncType getSyncAttribFunc)
1577         {
1578                 // Reset before each test
1579                 deinit();
1580                 init();
1581
1582                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1583                 TestLog&                log                         = m_testCtx.getLog();
1584                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1585
1586                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1587                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1588                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1589                         TestLog::EndMessage;
1590                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1591
1592                 getSyncAttribValueType condition = 0xF0F0F;
1593                 EGLBoolean result = (egl.*getSyncAttribFunc)(m_eglDisplay, m_sync, EGL_NONE, &condition);
1594                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] <<
1595                         "(" << m_eglDisplay << ", " << m_sync << ", EGL_NONE, {" << condition << "})" <<
1596                         TestLog::EndMessage;
1597
1598                 EGLint error = egl.getError();
1599                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1600
1601                 if (error != EGL_BAD_ATTRIBUTE)
1602                 {
1603                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1604                                 "' expected EGL_BAD_ATTRIBUTE" << TestLog::EndMessage;
1605                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1606                         return;
1607                 }
1608
1609                 TCU_CHECK(result == EGL_FALSE);
1610                 TCU_CHECK(condition == 0xF0F0F);
1611         }
1612
1613         IterateResult   iterate                                         (void)
1614         {
1615                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1616
1617                 if (hasRequiredEGLVersion(1, 5))
1618                 {
1619                         test<createSync, getSyncAttrib, EGLAttrib>(m_funcNames,
1620                                                                                                            &Library::createSync,
1621                                                                                                            &Library::getSyncAttrib);
1622                 }
1623                 if (hasEGLFenceSyncExtension())
1624                 {
1625                         test<createSyncKHR, getSyncAttribKHR, EGLint>(m_funcNamesKHR,
1626                                                                                                                   &Library::createSyncKHR,
1627                                                                                                                   &Library::getSyncAttribKHR);
1628                 }
1629                 else if (!hasRequiredEGLVersion(1, 5))
1630                 {
1631                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1632                 }
1633
1634                 return STOP;
1635         }
1636 };
1637
1638 class GetSyncInvalidValueTest : public SyncTest
1639 {
1640 public:
1641                                         GetSyncInvalidValueTest (EglTestContext& eglTestCtx, EGLenum syncType)
1642                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"get_invalid_value", "get_invalid_value")
1643         {
1644         }
1645
1646         template <typename createSyncFuncType,
1647                 typename getSyncAttribFuncType, typename valueType>
1648         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1649                           createSyncFuncType createSyncFunc,
1650                           getSyncAttribFuncType getSyncAttribFunc,
1651                           EGLint attribute, const string &attributeName,
1652                           valueType value)
1653         {
1654                 // Reset before each test
1655                 deinit();
1656                 init();
1657
1658                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1659                 TestLog&                log                         = m_testCtx.getLog();
1660                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1661
1662                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1663                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1664                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1665                         TestLog::EndMessage;
1666                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1667
1668                 EGLBoolean result = (egl.*getSyncAttribFunc)(m_eglDisplay, NULL, attribute, &value);
1669                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_GET_SYNC_ATTRIB] <<
1670                         "(" << m_eglDisplay << ", " << 0x0 << ", " << attributeName << ", " << &value << ")" <<
1671                         TestLog::EndMessage;
1672
1673                 EGLint error = egl.getError();
1674                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1675
1676                 if (error != EGL_BAD_PARAMETER)
1677                 {
1678                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1679                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1680                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1681                         return;
1682                 }
1683
1684                 TCU_CHECK(result == EGL_FALSE);
1685         }
1686
1687         IterateResult   iterate                                 (void)
1688         {
1689                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1690
1691                 if (hasRequiredEGLVersion(1, 5))
1692                 {
1693                         EGLAttrib value = 0;
1694                         test<createSync, getSyncAttrib>(m_funcNames, &Library::createSync,
1695                                                                                         &Library::getSyncAttrib,
1696                                                                                         EGL_SYNC_TYPE, "EGL_SYNC_TYPE", value);
1697                 }
1698                 if (hasEGLFenceSyncExtension())
1699                 {
1700                         EGLint value = 0;
1701                         test<createSyncKHR, getSyncAttribKHR>(m_funcNamesKHR, &Library::createSyncKHR,
1702                                                                                                   &Library::getSyncAttribKHR,
1703                                                                                                   EGL_SYNC_TYPE_KHR, "EGL_SYNC_TYPE_KHR", value);
1704                 }
1705                 else if (!hasRequiredEGLVersion(1, 5))
1706                 {
1707                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1708                 }
1709
1710                 return STOP;
1711         }
1712 };
1713
1714 class DestroySyncTest : public SyncTest
1715 {
1716 public:
1717                                         DestroySyncTest (EglTestContext& eglTestCtx, EGLenum syncType)
1718                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"destroy", "destroy")
1719         {
1720         }
1721
1722         template <typename createSyncFuncType,
1723                 typename destroySyncFuncType,
1724                 typename getSyncSyncValueType>
1725         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1726                           createSyncFuncType createSyncFunc,
1727                           destroySyncFuncType destroySyncFunc,
1728                           getSyncSyncValueType syncValue)
1729         {
1730                 // Reset before each test
1731                 deinit();
1732                 init();
1733
1734                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1735                 TestLog&                log                         = m_testCtx.getLog();
1736                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1737
1738                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1739                 log << TestLog::Message << funcNames[FUNC_NAME_CREATE_SYNC] << "(" <<
1740                         m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1741                         TestLog::EndMessage;
1742                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1743
1744                 log << TestLog::Message << funcNames[FUNC_NAME_DESTROY_SYNC] << "(" <<
1745                         m_eglDisplay << ", " << m_sync << ")" << TestLog::EndMessage;
1746                 EGLU_CHECK_CALL_FPTR(egl, (egl.*destroySyncFunc)(m_eglDisplay, m_sync));
1747                 m_sync = syncValue;
1748         }
1749
1750         IterateResult   iterate                 (void)
1751         {
1752                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1753
1754                 if (hasRequiredEGLVersion(1, 5))
1755                 {
1756                         test<createSync, destroySync, EGLSync>(m_funcNames,
1757                                                                                                    &Library::createSync,
1758                                                                                                    &Library::destroySync,
1759                                                                                                    EGL_NO_SYNC);
1760                 }
1761                 if (hasEGLFenceSyncExtension())
1762                 {
1763                         test<createSyncKHR, destroySyncKHR, EGLSyncKHR>(m_funcNamesKHR,
1764                                                                                                                         &Library::createSyncKHR,
1765                                                                                                                         &Library::destroySyncKHR,
1766                                                                                                                         EGL_NO_SYNC_KHR);
1767                 }
1768                 else if (!hasRequiredEGLVersion(1, 5))
1769                 {
1770                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1771                 }
1772
1773                 return STOP;
1774         }
1775 };
1776
1777 class DestroySyncInvalidDislayTest : public SyncTest
1778 {
1779 public:
1780                                         DestroySyncInvalidDislayTest    (EglTestContext& eglTestCtx, EGLenum syncType)
1781                 : SyncTest(eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"destroy_invalid_display", "destroy_invalid_display")
1782         {
1783         }
1784
1785         template <typename createSyncFuncType, typename destroySyncFuncType>
1786         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1787                           createSyncFuncType createSyncFunc,
1788                           destroySyncFuncType destroySyncFunc)
1789         {
1790                 // Reset before each test
1791                 deinit();
1792                 init();
1793
1794                 const Library&  egl                         = m_eglTestCtx.getLibrary();
1795                 TestLog&                log                         = m_testCtx.getLog();
1796                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1797
1798                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1799                 log << TestLog::Message << funcNames[FUNC_NAME_CREATE_SYNC] << "(" <<
1800                         m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1801                         TestLog::EndMessage;
1802                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
1803
1804                 EGLBoolean result = (egl.*destroySyncFunc)(EGL_NO_DISPLAY, m_sync);
1805                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_DESTROY_SYNC] <<
1806                         "(EGL_NO_DISPLAY, " << m_sync << ")" << TestLog::EndMessage;
1807
1808                 EGLint error = egl.getError();
1809                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1810
1811                 if (error != EGL_BAD_DISPLAY)
1812                 {
1813                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1814                                 "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
1815                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1816                         return;
1817                 }
1818
1819                 TCU_CHECK(result == EGL_FALSE);
1820         }
1821
1822         IterateResult   iterate                                                 (void)
1823         {
1824                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1825
1826                 if (hasRequiredEGLVersion(1, 5))
1827                 {
1828                         test<createSync, destroySync>(m_funcNames,
1829                                                                                   &Library::createSync,
1830                                                                                   &Library::destroySync);
1831                 }
1832                 if (hasEGLFenceSyncExtension())
1833                 {
1834                         test<createSyncKHR, destroySyncKHR>(m_funcNamesKHR,
1835                                                                                                 &Library::createSyncKHR,
1836                                                                                                 &Library::destroySyncKHR);
1837                 }
1838                 else if (!hasRequiredEGLVersion(1, 5))
1839                 {
1840                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1841                 }
1842
1843                 return STOP;
1844         }
1845 };
1846
1847 class DestroySyncInvalidSyncTest : public SyncTest
1848 {
1849 public:
1850                                         DestroySyncInvalidSyncTest      (EglTestContext& eglTestCtx, EGLenum syncType)
1851                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_NONE,  syncType != EGL_SYNC_REUSABLE_KHR,"destroy_invalid_sync", "destroy_invalid_sync")
1852         {
1853         }
1854
1855         template <typename destroySyncFuncType, typename getSyncSyncValueType>
1856         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1857                           destroySyncFuncType destroySyncFunc,
1858                           getSyncSyncValueType syncValue)
1859         {
1860                 // Reset before each test
1861                 deinit();
1862                 init();
1863
1864                 const Library&  egl             = m_eglTestCtx.getLibrary();
1865                 TestLog&                log             = m_testCtx.getLog();
1866
1867                 EGLBoolean result = (egl.*destroySyncFunc)(m_eglDisplay, syncValue);
1868                 log << TestLog::Message << result << " = " << funcNames[FUNC_NAME_DESTROY_SYNC] <<
1869                         "(" << m_eglDisplay << ", " << syncValue << ")" << TestLog::EndMessage;
1870
1871                 EGLint error = egl.getError();
1872                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
1873
1874                 if (error != EGL_BAD_PARAMETER)
1875                 {
1876                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
1877                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
1878                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1879                         return;
1880                 }
1881
1882                 TCU_CHECK(result == EGL_FALSE);
1883         }
1884
1885         IterateResult   iterate                                         (void)
1886         {
1887                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1888
1889                 if (hasRequiredEGLVersion(1, 5))
1890                 {
1891                         test<destroySync, EGLSync>(m_funcNames,
1892                                                                            &Library::destroySync,
1893                                                                            EGL_NO_SYNC);
1894                 }
1895                 if (hasEGLFenceSyncExtension())
1896                 {
1897                         test<destroySyncKHR, EGLSyncKHR>(m_funcNamesKHR,
1898                                                                                          &Library::destroySyncKHR,
1899                                                                                          EGL_NO_SYNC_KHR);
1900                 }
1901                 else if (!hasRequiredEGLVersion(1, 5))
1902                 {
1903                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1904                 }
1905
1906                 return STOP;
1907         }
1908 };
1909
1910 class WaitSyncTest : public SyncTest
1911 {
1912 public:
1913                                         WaitSyncTest    (EglTestContext& eglTestCtx, EGLenum syncType)
1914                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, true, "wait_server", "wait_server")
1915         {
1916         }
1917
1918         template <typename createSyncFuncType,
1919                 typename waitSyncFuncType,
1920                 typename waitSyncStatusType>
1921         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1922                           createSyncFuncType createSyncFunc,
1923                           waitSyncFuncType waitSyncFunc)
1924         {
1925                 // Reset before each test
1926                 deinit();
1927                 init();
1928
1929                 const Library&  egl     = m_eglTestCtx.getLibrary();
1930                 TestLog&                log     = m_testCtx.getLog();
1931                 string          msgChk  = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1932
1933                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1934                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
1935                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
1936                         TestLog::EndMessage;
1937                 EGLU_CHECK_MSG(egl, msgChk.c_str());
1938
1939                 waitSyncStatusType status = (egl.*waitSyncFunc)(m_eglDisplay, m_sync, 0);
1940                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_WAIT_SYNC] << "(" <<
1941                         m_eglDisplay << ", " << m_sync << ", 0, 0)" << TestLog::EndMessage;
1942
1943                 TCU_CHECK(status == EGL_TRUE);
1944
1945                 GLU_CHECK_GLW_CALL(m_gl, finish());
1946         }
1947
1948
1949         IterateResult   iterate                 (void)
1950         {
1951                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1952
1953                 if (hasRequiredEGLVersion(1, 5))
1954                 {
1955                         test<createSync, waitSync, EGLBoolean>(m_funcNames,
1956                                                                                                    &Library::createSync,
1957                                                                                                    &Library::waitSync);
1958                 }
1959                 if (hasEGLWaitSyncExtension())
1960                 {
1961                         test<createSyncKHR, waitSyncKHR, EGLint>(m_funcNamesKHR,
1962                                                                                                          &Library::createSyncKHR,
1963                                                                                                          &Library::waitSyncKHR);
1964                 }
1965                 else if (!hasRequiredEGLVersion(1, 5))
1966                 {
1967                         TCU_THROW(NotSupportedError, "Required extensions not supported");
1968                 }
1969
1970                 return STOP;
1971         }
1972
1973 };
1974
1975 class WaitSyncInvalidDisplayTest : public SyncTest
1976 {
1977 public:
1978                                         WaitSyncInvalidDisplayTest      (EglTestContext& eglTestCtx, EGLenum syncType)
1979                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, true, "wait_server_invalid_display", "wait_server_invalid_display")
1980         {
1981         }
1982
1983         template <typename createSyncFuncType,
1984                 typename waitSyncFuncType,
1985                 typename waitSyncStatusType>
1986         void test(string funcNames[FUNC_NAME_NUM_NAMES],
1987                           createSyncFuncType createSyncFunc,
1988                           waitSyncFuncType waitSyncFunc)
1989         {
1990                 // Reset before each test
1991                 deinit();
1992                 init();
1993
1994                 const Library&  egl     = m_eglTestCtx.getLibrary();
1995                 TestLog&                log     = m_testCtx.getLog();
1996                 string          msgChk  = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
1997
1998                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
1999                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
2000                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
2001                         TestLog::EndMessage;
2002                 EGLU_CHECK_MSG(egl, msgChk.c_str());
2003
2004                 waitSyncStatusType status = (egl.*waitSyncFunc)(EGL_NO_DISPLAY, m_sync, 0);
2005                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_WAIT_SYNC] <<
2006                         "(EGL_NO_DISPLAY, " << m_sync << ", 0)" << TestLog::EndMessage;
2007
2008                 EGLint error = egl.getError();
2009                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
2010
2011                 if (error != EGL_BAD_DISPLAY)
2012                 {
2013                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
2014                                 "' expected EGL_BAD_DISPLAY" << TestLog::EndMessage;
2015                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2016                         return;
2017                 }
2018
2019                 TCU_CHECK(status == EGL_FALSE);
2020         }
2021
2022         IterateResult   iterate                                         (void)
2023         {
2024                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2025
2026                 if (hasRequiredEGLVersion(1, 5))
2027                 {
2028                         test<createSync, waitSync, EGLBoolean>(m_funcNames,
2029                                                                                                    &Library::createSync,
2030                                                                                                    &Library::waitSync);
2031                 }
2032                 if (hasEGLWaitSyncExtension())
2033                 {
2034                         test<createSyncKHR, waitSyncKHR, EGLint>(m_funcNamesKHR,
2035                                                                                                          &Library::createSyncKHR,
2036                                                                                                          &Library::waitSyncKHR);
2037                 }
2038                 else if (!hasRequiredEGLVersion(1, 5))
2039                 {
2040                         TCU_THROW(NotSupportedError, "Required extensions not supported");
2041                 }
2042
2043                 return STOP;
2044         }
2045 };
2046
2047 class WaitSyncInvalidSyncTest : public SyncTest
2048 {
2049 public:
2050                                         WaitSyncInvalidSyncTest (EglTestContext& eglTestCtx, EGLenum syncType)
2051                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, true, "wait_server_invalid_sync", "wait_server_invalid_sync")
2052         {
2053         }
2054
2055         template <typename waitSyncFuncType, typename waitSyncSyncType>
2056         void test(string funcNames[FUNC_NAME_NUM_NAMES],
2057                           waitSyncFuncType waitSyncFunc,
2058                           waitSyncSyncType syncValue)
2059         {
2060                 // Reset before each test
2061                 deinit();
2062                 init();
2063
2064                 const Library&  egl             = m_eglTestCtx.getLibrary();
2065                 TestLog&                log             = m_testCtx.getLog();
2066
2067                 EGLint status = (egl.*waitSyncFunc)(m_eglDisplay, syncValue, 0);
2068                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_WAIT_SYNC] <<
2069                         "(" << m_eglDisplay << ", " << syncValue << ", 0)" << TestLog::EndMessage;
2070
2071                 EGLint error = egl.getError();
2072                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
2073
2074                 if (error != EGL_BAD_PARAMETER)
2075                 {
2076                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
2077                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
2078                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2079                         return;
2080                 }
2081
2082                 TCU_CHECK(status == EGL_FALSE);
2083         }
2084
2085         IterateResult   iterate                                 (void)
2086         {
2087                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2088
2089                 if (hasRequiredEGLVersion(1, 5))
2090                 {
2091                         test<waitSync, EGLSync>(m_funcNames,
2092                                                                         &Library::waitSync,
2093                                                                         EGL_NO_SYNC);
2094                 }
2095                 if (hasEGLWaitSyncExtension())
2096                 {
2097                         test<waitSyncKHR, EGLSyncKHR>(m_funcNamesKHR,
2098                                                                                   &Library::waitSyncKHR,
2099                                                                                   EGL_NO_SYNC_KHR);
2100                 }
2101                 else if (!hasRequiredEGLVersion(1, 5))
2102                 {
2103                         TCU_THROW(NotSupportedError, "Required extensions not supported");
2104                 }
2105
2106                 return STOP;
2107         }
2108 };
2109
2110 class WaitSyncInvalidFlagTest : public SyncTest
2111 {
2112 public:
2113                                         WaitSyncInvalidFlagTest (EglTestContext& eglTestCtx, EGLenum syncType)
2114                 : SyncTest      (eglTestCtx, syncType, SyncTest::EXTENSION_WAIT_SYNC, true, "wait_server_invalid_flag", "wait_server_invalid_flag")
2115         {
2116         }
2117
2118         template <typename createSyncFuncType, typename waitSyncFuncType>
2119         void test(string funcNames[FUNC_NAME_NUM_NAMES],
2120                           createSyncFuncType createSyncFunc,
2121                           waitSyncFuncType waitSyncFunc)
2122         {
2123                 // Reset before each test
2124                 deinit();
2125                 init();
2126
2127                 const Library&  egl                         = m_eglTestCtx.getLibrary();
2128                 TestLog&                log                         = m_testCtx.getLog();
2129                 string          createSyncMsgChk    = funcNames[FUNC_NAME_CREATE_SYNC] + "()";
2130
2131                 m_sync = (egl.*createSyncFunc)(m_eglDisplay, m_syncType, NULL);
2132                 log << TestLog::Message << m_sync << " = " << funcNames[FUNC_NAME_CREATE_SYNC] <<
2133                         "(" << m_eglDisplay << ", " << getSyncTypeName(m_syncType) << ", NULL)" <<
2134                         TestLog::EndMessage;
2135                 EGLU_CHECK_MSG(egl, createSyncMsgChk.c_str());
2136
2137                 EGLint status = (egl.*waitSyncFunc)(m_eglDisplay, m_sync, 0xFFFFFFFF);
2138                 log << TestLog::Message << status << " = " << funcNames[FUNC_NAME_WAIT_SYNC] <<
2139                         "(" << m_eglDisplay << ", " << m_sync << ", 0xFFFFFFFF)" << TestLog::EndMessage;
2140
2141                 EGLint error = egl.getError();
2142                 log << TestLog::Message << error << " = eglGetError()" << TestLog::EndMessage;
2143
2144                 if (error != EGL_BAD_PARAMETER)
2145                 {
2146                         log << TestLog::Message << "Unexpected error '" << eglu::getErrorStr(error) <<
2147                                 "' expected EGL_BAD_PARAMETER" << TestLog::EndMessage;
2148                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2149                         return;
2150                 }
2151
2152                 TCU_CHECK(status == EGL_FALSE);
2153         }
2154
2155         IterateResult   iterate                                 (void)
2156         {
2157                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2158
2159                 if (hasRequiredEGLVersion(1, 5))
2160                 {
2161                         test<createSync, waitSync>(m_funcNames,
2162                                                                            &Library::createSync,
2163                                                                            &Library::waitSync);
2164                 }
2165                 if (hasEGLWaitSyncExtension())
2166                 {
2167                         test<createSyncKHR, waitSyncKHR>(m_funcNamesKHR,
2168                                                                                          &Library::createSyncKHR,
2169                                                                                          &Library::waitSyncKHR);
2170                 }
2171                 else if (!hasRequiredEGLVersion(1, 5))
2172                 {
2173                         TCU_THROW(NotSupportedError, "Required extensions not supported");
2174                 }
2175
2176                 return STOP;
2177         }
2178 };
2179
2180 FenceSyncTests::FenceSyncTests (EglTestContext& eglTestCtx)
2181         : TestCaseGroup (eglTestCtx, "fence_sync", "EGL_KHR_fence_sync extension tests")
2182 {
2183 }
2184
2185 void FenceSyncTests::init (void)
2186 {
2187         // Add valid API test
2188         {
2189                 TestCaseGroup* const valid = new TestCaseGroup(m_eglTestCtx, "valid", "Valid function calls");
2190
2191                 // eglCreateSyncKHR tests
2192                 valid->addChild(new CreateNullAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2193                 valid->addChild(new CreateEmptyAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2194
2195                 // eglClientWaitSyncKHR tests
2196                 valid->addChild(new ClientWaitNoTimeoutTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2197                 valid->addChild(new ClientWaitForeverTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2198                 valid->addChild(new ClientWaitNoContextTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2199                 valid->addChild(new ClientWaitForeverFlushTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2200
2201                 // eglGetSyncAttribKHR tests
2202                 valid->addChild(new GetSyncTypeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2203                 valid->addChild(new GetSyncStatusTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2204                 valid->addChild(new GetSyncStatusSignaledTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2205                 valid->addChild(new GetSyncConditionTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2206
2207                 // eglDestroySyncKHR tests
2208                 valid->addChild(new DestroySyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2209
2210                 // eglWaitSyncKHR tests
2211                 valid->addChild(new WaitSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2212
2213                 addChild(valid);
2214         }
2215
2216         // Add negative API tests
2217         {
2218                 TestCaseGroup* const invalid = new TestCaseGroup(m_eglTestCtx, "invalid", "Invalid function calls");
2219
2220                 // eglCreateSyncKHR tests
2221                 invalid->addChild(new CreateInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2222                 invalid->addChild(new CreateInvalidTypeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2223                 invalid->addChild(new CreateInvalidAttribsTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2224                 invalid->addChild(new CreateInvalidContextTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2225
2226                 // eglClientWaitSyncKHR tests
2227                 invalid->addChild(new ClientWaitInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2228                 invalid->addChild(new ClientWaitInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2229
2230                 // eglGetSyncAttribKHR tests
2231                 invalid->addChild(new GetSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2232                 invalid->addChild(new GetSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2233                 invalid->addChild(new GetSyncInvalidAttributeTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2234                 invalid->addChild(new GetSyncInvalidValueTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2235
2236                 // eglDestroySyncKHR tests
2237                 invalid->addChild(new DestroySyncInvalidDislayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2238                 invalid->addChild(new DestroySyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2239
2240                 // eglWaitSyncKHR tests
2241                 invalid->addChild(new WaitSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2242                 invalid->addChild(new WaitSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2243                 invalid->addChild(new WaitSyncInvalidFlagTest(m_eglTestCtx, EGL_SYNC_FENCE_KHR));
2244
2245                 addChild(invalid);
2246         }
2247 }
2248
2249 ReusableSyncTests::ReusableSyncTests (EglTestContext& eglTestCtx)
2250         : TestCaseGroup (eglTestCtx, "reusable_sync", "EGL_KHR_reusable_sync extension tests")
2251 {
2252 }
2253
2254 void ReusableSyncTests::init (void)
2255 {
2256         // Add valid API test
2257         {
2258                 TestCaseGroup* const valid = new TestCaseGroup(m_eglTestCtx, "valid", "Valid function calls");
2259
2260                 // eglCreateSyncKHR tests
2261                 valid->addChild(new CreateNullAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2262                 valid->addChild(new CreateEmptyAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2263
2264                 // eglClientWaitSyncKHR tests
2265                 valid->addChild(new ClientWaitNoTimeoutTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2266                 valid->addChild(new ClientWaitForeverTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2267                 valid->addChild(new ClientWaitNoContextTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2268                 valid->addChild(new ClientWaitForeverFlushTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2269
2270                 // eglGetSyncAttribKHR tests
2271                 valid->addChild(new GetSyncTypeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2272                 valid->addChild(new GetSyncStatusTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2273                 valid->addChild(new GetSyncStatusSignaledTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2274
2275                 // eglDestroySyncKHR tests
2276                 valid->addChild(new DestroySyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2277
2278                 addChild(valid);
2279         }
2280
2281         // Add negative API tests
2282         {
2283                 TestCaseGroup* const invalid = new TestCaseGroup(m_eglTestCtx, "invalid", "Invalid function calls");
2284
2285                 // eglCreateSyncKHR tests
2286                 invalid->addChild(new CreateInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2287                 invalid->addChild(new CreateInvalidTypeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2288                 invalid->addChild(new CreateInvalidAttribsTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2289
2290                 // eglClientWaitSyncKHR tests
2291                 invalid->addChild(new ClientWaitInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2292                 invalid->addChild(new ClientWaitInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2293
2294                 // eglGetSyncAttribKHR tests
2295                 invalid->addChild(new GetSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2296                 invalid->addChild(new GetSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2297                 invalid->addChild(new GetSyncInvalidAttributeTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2298                 invalid->addChild(new GetSyncInvalidValueTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2299
2300                 // eglDestroySyncKHR tests
2301                 invalid->addChild(new DestroySyncInvalidDislayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2302                 invalid->addChild(new DestroySyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2303
2304                 // eglWaitSyncKHR tests
2305                 invalid->addChild(new WaitSyncInvalidDisplayTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2306                 invalid->addChild(new WaitSyncInvalidSyncTest(m_eglTestCtx, EGL_SYNC_REUSABLE_KHR));
2307
2308                 addChild(invalid);
2309         }
2310 }
2311
2312 } // egl
2313 } // deqp
2314