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