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