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