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