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