xref: /aosp_15_r20/external/deqp/modules/egl/teglNegativeApiTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 Negative API Tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglNegativeApiTests.hpp"
25 #include "teglApiCase.hpp"
26 
27 #include "egluNativeDisplay.hpp"
28 #include "egluNativeWindow.hpp"
29 #include "egluUtil.hpp"
30 #include "egluUtil.hpp"
31 #include "egluUnique.hpp"
32 
33 #include "eglwLibrary.hpp"
34 
35 #include <memory>
36 
37 using tcu::TestLog;
38 
39 namespace deqp
40 {
41 namespace egl
42 {
43 
44 using namespace eglw;
45 
46 template <uint32_t Type>
renderable(const eglu::CandidateConfig & c)47 static bool renderable(const eglu::CandidateConfig &c)
48 {
49     return (c.renderableType() & Type) == Type;
50 }
51 
52 template <uint32_t Type>
notRenderable(const eglu::CandidateConfig & c)53 static bool notRenderable(const eglu::CandidateConfig &c)
54 {
55     return (c.renderableType() & Type) == 0;
56 }
57 
58 template <uint32_t Bits>
surfaceBits(const eglu::CandidateConfig & c)59 static bool surfaceBits(const eglu::CandidateConfig &c)
60 {
61     return (c.surfaceType() & Bits) == Bits;
62 }
63 
64 template <uint32_t Bits>
notSurfaceBits(const eglu::CandidateConfig & c)65 static bool notSurfaceBits(const eglu::CandidateConfig &c)
66 {
67     return (c.surfaceType() & Bits) == 0;
68 }
69 
NegativeApiTests(EglTestContext & eglTestCtx)70 NegativeApiTests::NegativeApiTests(EglTestContext &eglTestCtx)
71     : TestCaseGroup(eglTestCtx, "negative_api", "Negative API Tests")
72 {
73 }
74 
~NegativeApiTests(void)75 NegativeApiTests::~NegativeApiTests(void)
76 {
77 }
78 
init(void)79 void NegativeApiTests::init(void)
80 {
81     // \todo [2012-10-02 pyry] Add tests for EGL_NOT_INITIALIZED to all functions taking in EGLDisplay
82     // \todo [2012-10-02 pyry] Implement negative cases for following non-trivial cases:
83     //  * eglBindTexImage()
84     //    - EGL_BAD_ACCESS is generated if buffer is already bound to a texture
85     //    - EGL_BAD_MATCH is generated if the surface attribute EGL_TEXTURE_FORMAT is set to EGL_NO_TEXTURE
86     //    - EGL_BAD_MATCH is generated if buffer is not a valid buffer (currently only EGL_BACK_BUFFER may be specified)
87     //    - EGL_BAD_SURFACE is generated if surface is not a pbuffer surface supporting texture binding
88     //  * eglCopyBuffers()
89     //    - EGL_BAD_NATIVE_PIXMAP is generated if the implementation does not support native pixmaps
90     //    - EGL_BAD_NATIVE_PIXMAP may be generated if native_pixmap is not a valid native pixmap
91     //    - EGL_BAD_MATCH is generated if the format of native_pixmap is not compatible with the color buffer of surface
92     //  * eglCreateContext()
93     //    - EGL_BAD_MATCH is generated if the current rendering API is EGL_NONE
94     //      - EGL_BAD_MATCH is generated if the server context state for share_context exists in an address space which cannot be shared with the newly created context
95     //      - EGL_BAD_CONTEXT is generated if share_context is not an EGL rendering context of the same client API type as the newly created context and is not EGL_NO_CONTEXT
96     //  * eglCreatePbufferFromClientBuffer()
97     //    - various BAD_MATCH, BAD_ACCESS etc. conditions
98     //  * eglCreatePbufferSurface()
99     //    - EGL_BAD_MATCH is generated if the EGL_TEXTURE_FORMAT attribute is not EGL_NO_TEXTURE, and EGL_WIDTH and/or EGL_HEIGHT specify an invalid size
100     //  * eglCreatePixmapSurface()
101     //    - EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid pixmap attribute
102     //    - EGL_BAD_MATCH is generated if the attributes of native_pixmap do not correspond to config or if config does not support rendering to pixmaps
103     //    - EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute
104     //  * eglCreateWindowSurface()
105     //    - EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid window attribute
106     //    - EGL_BAD_MATCH is generated if the attributes of native_window do not correspond to config or if config does not support rendering to windows
107     //    - EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute
108     //  * eglMakeCurrent()
109     //    - EGL_BAD_MATCH is generated if draw or read are not compatible with context
110     //    - EGL_BAD_MATCH is generated if context is set to EGL_NO_CONTEXT and draw or read are not set to EGL_NO_SURFACE
111     //    - EGL_BAD_MATCH is generated if draw or read are set to EGL_NO_SURFACE and context is not set to EGL_NO_CONTEXT
112     //    - EGL_BAD_ACCESS is generated if context is current to some other thread
113     //    - EGL_BAD_NATIVE_PIXMAP may be generated if a native pixmap underlying either draw or read is no longer valid
114     //    - EGL_BAD_NATIVE_WINDOW may be generated if a native window underlying either draw or read is no longer valid
115     //  * eglReleaseTexImage()
116     //    - EGL_BAD_MATCH is generated if buffer is not a valid buffer (currently only EGL_BACK_BUFFER may be specified)
117     //  * eglSwapInterval()
118     //    - EGL_BAD_SURFACE is generated if there is no surface bound to the current context
119     //  * eglWaitNative()
120     //    - EGL_BAD_CURRENT_SURFACE is generated if the surface associated with the current context has a native window or pixmap, and that window or pixmap is no longer valid
121 
122     using namespace eglw;
123     using namespace eglu;
124 
125     static const EGLint s_emptyAttribList[]      = {EGL_NONE};
126     static const EGLint s_es1ContextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
127     static const EGLint s_es2ContextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
128 
129     static const EGLenum s_renderAPIs[]                  = {EGL_OPENGL_API, EGL_OPENGL_ES_API, EGL_OPENVG_API};
130     static const eglu::ConfigFilter s_renderAPIFilters[] = {renderable<EGL_OPENGL_BIT>, renderable<EGL_OPENGL_ES_BIT>,
131                                                             renderable<EGL_OPENVG_BIT>};
132 
133     TEGL_ADD_API_CASE(bind_api, "eglBindAPI() negative tests", {
134         TestLog &log = m_testCtx.getLog();
135         log << TestLog::Section("Test1", "EGL_BAD_PARAMETER is generated if api is not one of the accepted tokens");
136 
137         expectFalse(eglBindAPI(0));
138         expectError(EGL_BAD_PARAMETER);
139 
140         expectFalse(eglBindAPI(0xfdfdfdfd));
141         expectError(EGL_BAD_PARAMETER);
142 
143         expectFalse(eglBindAPI((EGLenum)0xffffffff));
144         expectError(EGL_BAD_PARAMETER);
145 
146         log << TestLog::EndSection;
147 
148         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if the specified client API is not supported "
149                                          "by the EGL display, or no configuration is provided for the specified API.");
150 
151         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderAPIs); ndx++)
152         {
153             if (!isAPISupported(s_renderAPIs[ndx]))
154             {
155                 if (!eglBindAPI(s_renderAPIs[ndx]))
156                     expectError(EGL_BAD_PARAMETER);
157                 else
158                 {
159                     EGLConfig eglConfig;
160                     expectFalse(getConfig(&eglConfig, FilterList() << s_renderAPIFilters[ndx]));
161                 }
162             }
163         }
164 
165         log << TestLog::EndSection;
166     });
167 
168     TEGL_ADD_API_CASE(bind_tex_image, "eglBindTexImage() negative tests", {
169         TestLog &log       = m_testCtx.getLog();
170         EGLDisplay display = getDisplay();
171 
172         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
173 
174         expectFalse(eglBindTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_BACK_BUFFER));
175         expectError(EGL_BAD_DISPLAY);
176 
177         expectFalse(eglBindTexImage((EGLDisplay)-1, EGL_NO_SURFACE, EGL_BACK_BUFFER));
178         expectError(EGL_BAD_DISPLAY);
179 
180         log << TestLog::EndSection;
181 
182         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
183 
184         expectFalse(eglBindTexImage(display, EGL_NO_SURFACE, EGL_BACK_BUFFER));
185         expectError(EGL_BAD_SURFACE);
186 
187         expectFalse(eglBindTexImage(display, (EGLSurface)-1, EGL_BACK_BUFFER));
188         expectError(EGL_BAD_SURFACE);
189 
190         log << TestLog::EndSection;
191     });
192 
193     static const EGLint s_validGenericPbufferAttrib[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
194 
195     TEGL_ADD_API_CASE(copy_buffers, "eglCopyBuffers() negative tests", {
196         TestLog &log             = m_testCtx.getLog();
197         const eglw::Library &egl = m_eglTestCtx.getLibrary();
198         EGLDisplay display       = getDisplay();
199         const eglu::NativePixmapFactory &factory =
200             eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
201         de::UniquePtr<eglu::NativePixmap> pixmap(factory.createPixmap(&m_eglTestCtx.getNativeDisplay(), 64, 64));
202         EGLConfig config;
203 
204         {
205             if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
206             {
207                 eglu::UniqueSurface surface(egl, display,
208                                             egl.createPbufferSurface(display, config, s_validGenericPbufferAttrib));
209 
210                 log << TestLog::Section("Test1",
211                                         "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
212 
213                 expectFalse(eglCopyBuffers(EGL_NO_DISPLAY, EGL_NO_SURFACE, pixmap->getLegacyNative()));
214                 expectError(EGL_BAD_DISPLAY);
215 
216                 expectFalse(eglCopyBuffers((EGLDisplay)-1, EGL_NO_SURFACE, pixmap->getLegacyNative()));
217                 expectError(EGL_BAD_DISPLAY);
218 
219                 log << TestLog::EndSection;
220             }
221         }
222 
223         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
224 
225         expectFalse(eglCopyBuffers(display, EGL_NO_SURFACE, pixmap->getLegacyNative()));
226         expectError(EGL_BAD_SURFACE);
227 
228         expectFalse(eglCopyBuffers(display, (EGLSurface)-1, pixmap->getLegacyNative()));
229         expectError(EGL_BAD_SURFACE);
230 
231         log << TestLog::EndSection;
232     });
233 
234     static const EGLint s_invalidChooseConfigAttribList0[]  = {0, EGL_NONE};
235     static const EGLint s_invalidChooseConfigAttribList1[]  = {(EGLint)0xffffffff};
236     static const EGLint s_invalidChooseConfigAttribList2[]  = {EGL_BIND_TO_TEXTURE_RGB, 4, EGL_NONE};
237     static const EGLint s_invalidChooseConfigAttribList3[]  = {EGL_BIND_TO_TEXTURE_RGBA, 5, EGL_NONE};
238     static const EGLint s_invalidChooseConfigAttribList4[]  = {EGL_COLOR_BUFFER_TYPE, 0, EGL_NONE};
239     static const EGLint s_invalidChooseConfigAttribList5[]  = {EGL_NATIVE_RENDERABLE, 6, EGL_NONE};
240     static const EGLint s_invalidChooseConfigAttribList6[]  = {EGL_TRANSPARENT_TYPE, 6, EGL_NONE};
241     static const EGLint *s_invalidChooseConfigAttribLists[] = {
242         &s_invalidChooseConfigAttribList0[0], &s_invalidChooseConfigAttribList1[0],
243         &s_invalidChooseConfigAttribList2[0], &s_invalidChooseConfigAttribList3[0],
244         &s_invalidChooseConfigAttribList4[0], &s_invalidChooseConfigAttribList5[0],
245         &s_invalidChooseConfigAttribList6[0]};
246 
247     TEGL_ADD_API_CASE(choose_config, "eglChooseConfig() negative tests", {
248         TestLog &log       = m_testCtx.getLog();
249         EGLDisplay display = getDisplay();
250         EGLConfig configs[1];
251         EGLint numConfigs;
252 
253         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
254 
255         expectFalse(
256             eglChooseConfig(EGL_NO_DISPLAY, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), &numConfigs));
257         expectError(EGL_BAD_DISPLAY);
258 
259         expectFalse(
260             eglChooseConfig((EGLDisplay)-1, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), &numConfigs));
261         expectError(EGL_BAD_DISPLAY);
262 
263         log << TestLog::EndSection;
264 
265         log << TestLog::Section("Test2", "EGL_BAD_ATTRIBUTE is generated if attribute_list contains an invalid frame "
266                                          "buffer configuration attribute");
267 
268         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidChooseConfigAttribLists); ndx++)
269         {
270             expectFalse(eglChooseConfig(display, s_invalidChooseConfigAttribLists[ndx], &configs[0],
271                                         DE_LENGTH_OF_ARRAY(configs), &numConfigs));
272             expectError(EGL_BAD_ATTRIBUTE);
273         }
274 
275         log << TestLog::EndSection;
276 
277         log << TestLog::Section("Test3", "EGL_BAD_PARAMETER is generated if num_config is NULL");
278 
279         expectFalse(eglChooseConfig(display, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), DE_NULL));
280         expectError(EGL_BAD_PARAMETER);
281 
282         log << TestLog::EndSection;
283     });
284 
285     static const EGLint s_invalidCreateContextAttribList0[] = {0, EGL_NONE};
286     static const EGLint s_invalidCreateContextAttribList1[] = {(EGLint)0xffffffff};
287 
288     TEGL_ADD_API_CASE(create_context, "eglCreateContext() negative tests", {
289         TestLog &log       = m_testCtx.getLog();
290         EGLDisplay display = getDisplay();
291 
292         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
293 
294         expectNoContext(eglCreateContext(EGL_NO_DISPLAY, DE_NULL, EGL_NO_CONTEXT, s_emptyAttribList));
295         expectError(EGL_BAD_DISPLAY);
296 
297         expectNoContext(eglCreateContext((EGLDisplay)-1, DE_NULL, EGL_NO_CONTEXT, s_emptyAttribList));
298         expectError(EGL_BAD_DISPLAY);
299 
300         log << TestLog::EndSection;
301 
302         log << TestLog::Section("Test2",
303                                 "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
304 
305         expectNoContext(eglCreateContext(display, (EGLConfig)-1, EGL_NO_CONTEXT, s_emptyAttribList));
306         expectError(EGL_BAD_CONFIG);
307 
308         log << TestLog::EndSection;
309 
310         log << TestLog::Section("Test3",
311                                 "EGL_BAD_CONFIG is generated if config does not support the current rendering API");
312 
313         if (isAPISupported(EGL_OPENGL_API))
314         {
315             EGLConfig es1OnlyConfig;
316             if (getConfig(&es1OnlyConfig, FilterList()
317                                               << renderable<EGL_OPENGL_ES_BIT> << notRenderable<EGL_OPENGL_BIT>))
318             {
319                 expectTrue(eglBindAPI(EGL_OPENGL_API));
320                 expectNoContext(eglCreateContext(display, es1OnlyConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
321                 expectError(EGL_BAD_CONFIG);
322             }
323 
324             EGLConfig es2OnlyConfig;
325             if (getConfig(&es2OnlyConfig, FilterList()
326                                               << renderable<EGL_OPENGL_ES2_BIT> << notRenderable<EGL_OPENGL_BIT>))
327             {
328                 expectTrue(eglBindAPI(EGL_OPENGL_API));
329                 expectNoContext(eglCreateContext(display, es2OnlyConfig, EGL_NO_CONTEXT, s_es2ContextAttribList));
330                 expectError(EGL_BAD_CONFIG);
331             }
332 
333             EGLConfig vgOnlyConfig;
334             if (getConfig(&vgOnlyConfig, FilterList() << renderable<EGL_OPENVG_BIT> << notRenderable<EGL_OPENGL_BIT>))
335             {
336                 expectTrue(eglBindAPI(EGL_OPENGL_API));
337                 expectNoContext(eglCreateContext(display, vgOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
338                 expectError(EGL_BAD_CONFIG);
339             }
340         }
341 
342         if (isAPISupported(EGL_OPENGL_ES_API))
343         {
344             EGLConfig glOnlyConfig;
345             if (getConfig(&glOnlyConfig,
346                           FilterList() << renderable<
347                                               EGL_OPENGL_BIT> << notRenderable<EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT>))
348             {
349                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
350                 expectNoContext(eglCreateContext(display, glOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
351                 expectError(EGL_BAD_CONFIG);
352             }
353 
354             EGLConfig vgOnlyConfig;
355             if (getConfig(&vgOnlyConfig,
356                           FilterList() << renderable<
357                                               EGL_OPENVG_BIT> << notRenderable<EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT>))
358             {
359                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
360                 expectNoContext(eglCreateContext(display, vgOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
361                 expectError(EGL_BAD_CONFIG);
362             }
363         }
364 
365         if (isAPISupported(EGL_OPENVG_API))
366         {
367             EGLConfig glOnlyConfig;
368             if (getConfig(&glOnlyConfig, FilterList() << renderable<EGL_OPENGL_BIT> << notRenderable<EGL_OPENVG_BIT>))
369             {
370                 expectTrue(eglBindAPI(EGL_OPENVG_API));
371                 expectNoContext(eglCreateContext(display, glOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
372                 expectError(EGL_BAD_CONFIG);
373             }
374 
375             EGLConfig es1OnlyConfig;
376             if (getConfig(&es1OnlyConfig, FilterList()
377                                               << renderable<EGL_OPENGL_ES_BIT> << notRenderable<EGL_OPENVG_BIT>))
378             {
379                 expectTrue(eglBindAPI(EGL_OPENVG_API));
380                 expectNoContext(eglCreateContext(display, es1OnlyConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
381                 expectError(EGL_BAD_CONFIG);
382             }
383 
384             EGLConfig es2OnlyConfig;
385             if (getConfig(&es2OnlyConfig, FilterList()
386                                               << renderable<EGL_OPENGL_ES2_BIT> << notRenderable<EGL_OPENVG_BIT>))
387             {
388                 expectTrue(eglBindAPI(EGL_OPENVG_API));
389                 expectNoContext(eglCreateContext(display, es2OnlyConfig, EGL_NO_CONTEXT, s_es2ContextAttribList));
390                 expectError(EGL_BAD_CONFIG);
391             }
392         }
393 
394         log << TestLog::EndSection;
395 
396         log << TestLog::Section("Test4",
397                                 "EGL_BAD_CONFIG or EGL_BAD_MATCH is generated if OpenGL ES 1.x context is requested "
398                                 "and EGL_RENDERABLE_TYPE attribute of config does not contain EGL_OPENGL_ES_BIT");
399 
400         if (isAPISupported(EGL_OPENGL_ES_API))
401         {
402             EGLConfig notES1Config;
403             if (getConfig(&notES1Config, FilterList() << notRenderable<EGL_OPENGL_ES_BIT>))
404             {
405                 // EGL 1.4, EGL 1.5, and EGL_KHR_create_context contain contradictory language about the expected error.
406                 Version version = eglu::getVersion(m_eglTestCtx.getLibrary(), display);
407                 bool hasKhrCreateContext =
408                     eglu::hasExtension(m_eglTestCtx.getLibrary(), display, "EGL_KHR_create_context");
409 
410                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
411                 expectNoContext(eglCreateContext(display, notES1Config, EGL_NO_CONTEXT, s_es1ContextAttribList));
412                 if (hasKhrCreateContext)
413                     expectEitherError(EGL_BAD_CONFIG, EGL_BAD_MATCH);
414                 else
415                 {
416                     if (version >= eglu::Version(1, 5))
417                         expectError(EGL_BAD_MATCH);
418                     else
419                         expectError(EGL_BAD_CONFIG);
420                 }
421             }
422         }
423 
424         log << TestLog::EndSection;
425 
426         log << TestLog::Section("Test5",
427                                 "EGL_BAD_CONFIG or EGL_BAD_MATCH is generated if OpenGL ES 2.x context is requested "
428                                 "and EGL_RENDERABLE_TYPE attribute of config does not contain EGL_OPENGL_ES2_BIT");
429 
430         if (isAPISupported(EGL_OPENGL_ES_API))
431         {
432             EGLConfig notES2Config;
433             if (getConfig(&notES2Config, FilterList() << notRenderable<EGL_OPENGL_ES2_BIT>))
434             {
435                 // EGL 1.4, EGL 1.5, and EGL_KHR_create_context contain contradictory language about the expected error.
436                 Version version = eglu::getVersion(m_eglTestCtx.getLibrary(), display);
437                 bool hasKhrCreateContext =
438                     eglu::hasExtension(m_eglTestCtx.getLibrary(), display, "EGL_KHR_create_context");
439 
440                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
441                 expectNoContext(eglCreateContext(display, notES2Config, EGL_NO_CONTEXT, s_es2ContextAttribList));
442                 if (hasKhrCreateContext)
443                     expectEitherError(EGL_BAD_CONFIG, EGL_BAD_MATCH);
444                 else
445                 {
446                     if (version >= eglu::Version(1, 5))
447                         expectError(EGL_BAD_MATCH);
448                     else
449                         expectError(EGL_BAD_CONFIG);
450                 }
451             }
452         }
453 
454         log << TestLog::EndSection;
455 
456         log << TestLog::Section("Test6",
457                                 "EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid context attribute");
458 
459         if (isAPISupported(EGL_OPENGL_API) &&
460             !eglu::hasExtension(m_eglTestCtx.getLibrary(), display, "EGL_KHR_create_context"))
461         {
462             EGLConfig glConfig;
463             if (getConfig(&glConfig, FilterList() << renderable<EGL_OPENGL_BIT>))
464             {
465                 expectTrue(eglBindAPI(EGL_OPENGL_API));
466                 expectNoContext(eglCreateContext(display, glConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
467                 expectError(EGL_BAD_ATTRIBUTE);
468             }
469         }
470 
471         if (isAPISupported(EGL_OPENVG_API))
472         {
473             EGLConfig vgConfig;
474             if (getConfig(&vgConfig, FilterList() << renderable<EGL_OPENVG_BIT>))
475             {
476                 expectTrue(eglBindAPI(EGL_OPENVG_API));
477                 expectNoContext(eglCreateContext(display, vgConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
478                 expectError(EGL_BAD_ATTRIBUTE);
479             }
480         }
481 
482         if (isAPISupported(EGL_OPENGL_ES_API))
483         {
484             bool gotConfig = false;
485             EGLConfig esConfig;
486 
487             gotConfig = getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT>) ||
488                         getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
489 
490             if (gotConfig)
491             {
492                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
493                 expectNoContext(eglCreateContext(display, esConfig, EGL_NO_CONTEXT, s_invalidCreateContextAttribList0));
494                 expectError(EGL_BAD_ATTRIBUTE);
495                 expectNoContext(eglCreateContext(display, esConfig, EGL_NO_CONTEXT, s_invalidCreateContextAttribList1));
496                 expectError(EGL_BAD_ATTRIBUTE);
497             }
498         }
499 
500         log << TestLog::EndSection;
501     });
502 
503     TEGL_ADD_API_CASE(create_pbuffer_from_client_buffer, "eglCreatePbufferFromClientBuffer() negative tests", {
504         TestLog &log       = m_testCtx.getLog();
505         EGLDisplay display = getDisplay();
506         EGLConfig anyConfig;
507         EGLint unused = 0;
508 
509         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
510 
511         expectNoSurface(eglCreatePbufferFromClientBuffer(EGL_NO_DISPLAY, EGL_OPENVG_IMAGE, 0, (EGLConfig)0, DE_NULL));
512         expectError(EGL_BAD_DISPLAY);
513 
514         expectNoSurface(eglCreatePbufferFromClientBuffer((EGLDisplay)-1, EGL_OPENVG_IMAGE, 0, (EGLConfig)0, DE_NULL));
515         expectError(EGL_BAD_DISPLAY);
516 
517         log << TestLog::EndSection;
518 
519         if (isAPISupported(EGL_OPENVG_API))
520         {
521             log << TestLog::Section("Test2", "EGL_BAD_CONFIG or EGL_BAD_PARAMETER is generated if config is not an EGL "
522                                              "frame buffer configuration and if buffer is not valid OpenVG image");
523 
524             expectNoSurface(eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE, (EGLClientBuffer)-1,
525                                                              (EGLConfig)-1, DE_NULL));
526             expectEitherError(EGL_BAD_CONFIG, EGL_BAD_PARAMETER);
527 
528             log << TestLog::EndSection;
529 
530             log << TestLog::Section("Test3", "EGL_BAD_PARAMETER is generated if buftype is not EGL_OPENVG_IMAGE");
531 
532             expectTrue(eglGetConfigs(display, &anyConfig, 1, &unused));
533 
534             log << TestLog::EndSection;
535 
536             log << TestLog::Section("Test4", "EGL_BAD_PARAMETER is generated if buffer is not valid OpenVG image");
537             expectNoSurface(
538                 eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE, (EGLClientBuffer)-1, anyConfig, DE_NULL));
539             expectError(EGL_BAD_PARAMETER);
540 
541             log << TestLog::EndSection;
542         }
543     });
544 
545     static const EGLint s_invalidGenericPbufferAttrib0[]        = {0, EGL_NONE};
546     static const EGLint s_invalidGenericPbufferAttrib1[]        = {(EGLint)0xffffffff};
547     static const EGLint s_negativeWidthPbufferAttrib[]          = {EGL_WIDTH, -1, EGL_HEIGHT, 64, EGL_NONE};
548     static const EGLint s_negativeHeightPbufferAttrib[]         = {EGL_WIDTH, 64, EGL_HEIGHT, -1, EGL_NONE};
549     static const EGLint s_negativeWidthAndHeightPbufferAttrib[] = {EGL_WIDTH, -1, EGL_HEIGHT, -1, EGL_NONE};
550     static const EGLint *s_invalidGenericPbufferAttribs[]       = {
551         s_invalidGenericPbufferAttrib0,
552         s_invalidGenericPbufferAttrib1,
553     };
554 
555     static const EGLint s_invalidNoEsPbufferAttrib0[] = {EGL_MIPMAP_TEXTURE, EGL_TRUE, EGL_WIDTH, 64,
556                                                          EGL_HEIGHT,         64,       EGL_NONE};
557     static const EGLint s_invalidNoEsPbufferAttrib1[] = {
558         EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
559     static const EGLint s_invalidNoEsPbufferAttrib2[] = {
560         EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
561     static const EGLint *s_invalidNoEsPbufferAttribs[] = {s_invalidNoEsPbufferAttrib0, s_invalidNoEsPbufferAttrib1,
562                                                           s_invalidNoEsPbufferAttrib2};
563 
564     static const EGLint s_invalidEsPbufferAttrib0[]  = {EGL_TEXTURE_FORMAT,
565                                                         EGL_NO_TEXTURE,
566                                                         EGL_TEXTURE_TARGET,
567                                                         EGL_TEXTURE_2D,
568                                                         EGL_WIDTH,
569                                                         64,
570                                                         EGL_HEIGHT,
571                                                         64,
572                                                         EGL_NONE};
573     static const EGLint s_invalidEsPbufferAttrib1[]  = {EGL_TEXTURE_FORMAT,
574                                                         EGL_TEXTURE_RGBA,
575                                                         EGL_TEXTURE_TARGET,
576                                                         EGL_NO_TEXTURE,
577                                                         EGL_WIDTH,
578                                                         64,
579                                                         EGL_HEIGHT,
580                                                         64,
581                                                         EGL_NONE};
582     static const EGLint *s_invalidEsPbufferAttribs[] = {s_invalidEsPbufferAttrib0, s_invalidEsPbufferAttrib1};
583 
584     static const EGLint s_vgPreMultAlphaPbufferAttrib[] = {
585         EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
586     static const EGLint s_vgLinearColorspacePbufferAttrib[] = {
587         EGL_COLORSPACE, EGL_VG_COLORSPACE_LINEAR, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
588 
589     TEGL_ADD_API_CASE(create_pbuffer_surface, "eglCreatePbufferSurface() negative tests", {
590         TestLog &log       = m_testCtx.getLog();
591         EGLDisplay display = getDisplay();
592 
593         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
594 
595         expectNoSurface(eglCreatePbufferSurface(EGL_NO_DISPLAY, DE_NULL, s_emptyAttribList));
596         expectError(EGL_BAD_DISPLAY);
597 
598         expectNoSurface(eglCreatePbufferSurface((EGLDisplay)-1, DE_NULL, s_emptyAttribList));
599         expectError(EGL_BAD_DISPLAY);
600 
601         log << TestLog::EndSection;
602 
603         log << TestLog::Section("Test2",
604                                 "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
605 
606         expectNoSurface(eglCreatePbufferSurface(display, (EGLConfig)-1, s_emptyAttribList));
607         expectError(EGL_BAD_CONFIG);
608 
609         log << TestLog::EndSection;
610 
611         log << TestLog::Section(
612             "Test3", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid pixel buffer attribute");
613 
614         // Generic pbuffer-capable config
615         EGLConfig genericConfig;
616         if (getConfig(&genericConfig, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
617         {
618             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidGenericPbufferAttribs); ndx++)
619             {
620                 expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_invalidGenericPbufferAttribs[ndx]));
621                 expectError(EGL_BAD_ATTRIBUTE);
622             }
623         }
624 
625         log << TestLog::EndSection;
626 
627         log << TestLog::Section("Test4",
628                                 "EGL_BAD_MATCH is generated if config does not support rendering to pixel buffers");
629 
630         EGLConfig noPbufferConfig;
631         if (getConfig(&noPbufferConfig, FilterList() << notSurfaceBits<EGL_PBUFFER_BIT>))
632         {
633             expectNoSurface(eglCreatePbufferSurface(display, noPbufferConfig, s_validGenericPbufferAttrib));
634             expectError(EGL_BAD_MATCH);
635         }
636 
637         log << TestLog::EndSection;
638 
639         log << TestLog::Section(
640             "Test5", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains any of the attributes EGL_MIPMAP_TEXTURE, "
641                      "EGL_TEXTURE_FORMAT, or EGL_TEXTURE_TARGET, and config does not support OpenGL ES rendering");
642 
643         EGLConfig noEsConfig;
644         if (getConfig(&noEsConfig, FilterList() << notRenderable<EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT>))
645         {
646             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidNoEsPbufferAttribs); ndx++)
647             {
648                 expectNoSurface(eglCreatePbufferSurface(display, noEsConfig, s_invalidNoEsPbufferAttribs[ndx]));
649                 expectError(EGL_BAD_MATCH);
650             }
651         }
652 
653         log << TestLog::EndSection;
654 
655         log << TestLog::Section("Test6",
656                                 "EGL_BAD_MATCH is generated if the EGL_TEXTURE_FORMAT attribute is EGL_NO_TEXTURE, and "
657                                 "EGL_TEXTURE_TARGET is something other than EGL_NO_TEXTURE; or, EGL_TEXTURE_FORMAT is "
658                                 "something other than EGL_NO_TEXTURE, and EGL_TEXTURE_TARGET is EGL_NO_TEXTURE");
659 
660         // ES1 or ES2 config.
661         EGLConfig esConfig;
662         bool gotEsConfig = getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT>) ||
663                            getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
664         if (gotEsConfig)
665         {
666             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidEsPbufferAttribs); ndx++)
667             {
668                 expectNoSurface(eglCreatePbufferSurface(display, esConfig, s_invalidEsPbufferAttribs[ndx]));
669                 expectError(EGL_BAD_MATCH);
670             }
671         }
672 
673         log << TestLog::EndSection;
674 
675         log << TestLog::Section("Test7", "EGL_BAD_MATCH is generated if config does not support the specified OpenVG "
676                                          "alpha format attribute or colorspace attribute");
677 
678         EGLConfig vgNoPreConfig;
679         if (getConfig(&vgNoPreConfig, FilterList()
680                                           << renderable<EGL_OPENVG_BIT> << notSurfaceBits<EGL_VG_ALPHA_FORMAT_PRE_BIT>))
681         {
682             expectNoSurface(eglCreatePbufferSurface(display, vgNoPreConfig, s_vgPreMultAlphaPbufferAttrib));
683             expectError(EGL_BAD_MATCH);
684         }
685 
686         EGLConfig vgNoLinearConfig;
687         if (getConfig(&vgNoLinearConfig,
688                       FilterList() << renderable<EGL_OPENVG_BIT> << notSurfaceBits<EGL_VG_COLORSPACE_LINEAR_BIT>))
689         {
690             expectNoSurface(eglCreatePbufferSurface(display, vgNoLinearConfig, s_vgLinearColorspacePbufferAttrib));
691             expectError(EGL_BAD_MATCH);
692         }
693 
694         log << TestLog::EndSection;
695 
696         log << TestLog::Section("Test8", "EGL_BAD_PARAMETER is generated if EGL_WIDTH or EGL_HEIGHT is negative");
697 
698         if (getConfig(&genericConfig, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
699         {
700             expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeWidthPbufferAttrib));
701             expectError(EGL_BAD_PARAMETER);
702 
703             expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeHeightPbufferAttrib));
704             expectError(EGL_BAD_PARAMETER);
705 
706             expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeWidthAndHeightPbufferAttrib));
707             expectError(EGL_BAD_PARAMETER);
708         }
709 
710         log << TestLog::EndSection;
711     });
712 
713     TEGL_ADD_API_CASE(create_pixmap_surface, "eglCreatePixmapSurface() negative tests", {
714         TestLog &log       = m_testCtx.getLog();
715         EGLDisplay display = getDisplay();
716 
717         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
718 
719         expectNoSurface(eglCreatePixmapSurface(EGL_NO_DISPLAY, DE_NULL, DE_NULL, s_emptyAttribList));
720         expectError(EGL_BAD_DISPLAY);
721 
722         expectNoSurface(eglCreatePixmapSurface((EGLDisplay)-1, DE_NULL, DE_NULL, s_emptyAttribList));
723         expectError(EGL_BAD_DISPLAY);
724 
725         log << TestLog::EndSection;
726 
727         log << TestLog::Section("Test2", "EGL_BAD_CONFIG or EGL_BAD_PARAMETER is generated if config is not an EGL "
728                                          "frame buffer configuration or if the PixmapSurface call is not supported");
729 
730         expectNoSurface(eglCreatePixmapSurface(display, (EGLConfig)-1, DE_NULL, s_emptyAttribList));
731         expectEitherError(EGL_BAD_CONFIG, EGL_BAD_PARAMETER);
732 
733         log << TestLog::EndSection;
734     });
735 
736     TEGL_ADD_API_CASE(create_window_surface, "eglCreateWindowSurface() negative tests", {
737         EGLConfig config = DE_NULL;
738         bool gotConfig =
739             getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << surfaceBits<EGL_WINDOW_BIT>);
740 
741         if (gotConfig)
742         {
743             TestLog &log       = m_testCtx.getLog();
744             EGLDisplay display = getDisplay();
745             const eglu::NativeWindowFactory &factory =
746                 eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
747             de::UniquePtr<eglu::NativeWindow> window(factory.createWindow(
748                 &m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL,
749                 eglu::WindowParams(256, 256, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
750 
751             log << TestLog::Section("Test1",
752                                     "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
753 
754             expectNoSurface(
755                 eglCreateWindowSurface(EGL_NO_DISPLAY, config, window->getLegacyNative(), s_emptyAttribList));
756             expectError(EGL_BAD_DISPLAY);
757 
758             expectNoSurface(
759                 eglCreateWindowSurface((EGLDisplay)-1, config, window->getLegacyNative(), s_emptyAttribList));
760             expectError(EGL_BAD_DISPLAY);
761 
762             log << TestLog::EndSection;
763         }
764     });
765 
766     TEGL_ADD_API_CASE(destroy_context, "eglDestroyContext() negative tests", {
767         TestLog &log       = m_testCtx.getLog();
768         EGLDisplay display = getDisplay();
769 
770         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
771 
772         expectFalse(eglDestroyContext(EGL_NO_DISPLAY, DE_NULL));
773         expectError(EGL_BAD_DISPLAY);
774 
775         expectFalse(eglDestroyContext((EGLDisplay)-1, DE_NULL));
776         expectError(EGL_BAD_DISPLAY);
777 
778         log << TestLog::EndSection;
779 
780         log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
781 
782         expectFalse(eglDestroyContext(display, DE_NULL));
783         expectError(EGL_BAD_CONTEXT);
784 
785         expectFalse(eglDestroyContext(display, (EGLContext)-1));
786         expectError(EGL_BAD_CONTEXT);
787 
788         log << TestLog::EndSection;
789     });
790 
791     TEGL_ADD_API_CASE(destroy_surface, "eglDestroySurface() negative tests", {
792         TestLog &log       = m_testCtx.getLog();
793         EGLDisplay display = getDisplay();
794 
795         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
796 
797         expectFalse(eglDestroySurface(EGL_NO_DISPLAY, DE_NULL));
798         expectError(EGL_BAD_DISPLAY);
799 
800         expectFalse(eglDestroySurface((EGLDisplay)-1, DE_NULL));
801         expectError(EGL_BAD_DISPLAY);
802 
803         log << TestLog::EndSection;
804 
805         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
806 
807         expectFalse(eglDestroySurface(display, DE_NULL));
808         expectError(EGL_BAD_SURFACE);
809 
810         expectFalse(eglDestroySurface(display, (EGLSurface)-1));
811         expectError(EGL_BAD_SURFACE);
812 
813         log << TestLog::EndSection;
814     });
815 
816     TEGL_ADD_API_CASE(get_config_attrib, "eglGetConfigAttrib() negative tests", {
817         TestLog &log       = m_testCtx.getLog();
818         EGLDisplay display = getDisplay();
819         EGLint value       = 0;
820 
821         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
822 
823         expectFalse(eglGetConfigAttrib(EGL_NO_DISPLAY, DE_NULL, EGL_RED_SIZE, &value));
824         expectError(EGL_BAD_DISPLAY);
825 
826         expectFalse(eglGetConfigAttrib((EGLDisplay)-1, DE_NULL, EGL_RED_SIZE, &value));
827         expectError(EGL_BAD_DISPLAY);
828 
829         log << TestLog::EndSection;
830 
831         log << TestLog::Section("Test2",
832                                 "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
833 
834         expectFalse(eglGetConfigAttrib(display, (EGLConfig)-1, EGL_RED_SIZE, &value));
835         expectError(EGL_BAD_CONFIG);
836 
837         log << TestLog::EndSection;
838 
839         // Any config.
840         EGLConfig config = DE_NULL;
841         bool hasConfig   = getConfig(&config, FilterList());
842 
843         log << TestLog::Section(
844             "Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid frame buffer configuration attribute");
845 
846         if (hasConfig)
847         {
848             expectFalse(eglGetConfigAttrib(display, config, 0, &value));
849             expectError(EGL_BAD_ATTRIBUTE);
850 
851             expectFalse(eglGetConfigAttrib(display, config, -1, &value));
852             expectError(EGL_BAD_ATTRIBUTE);
853         }
854 
855         log << TestLog::EndSection;
856     });
857 
858     TEGL_ADD_API_CASE(get_configs, "eglGetConfigs() negative tests", {
859         TestLog &log       = m_testCtx.getLog();
860         EGLDisplay display = getDisplay();
861         EGLConfig cfgs[1];
862         EGLint numCfgs = 0;
863 
864         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
865 
866         expectFalse(eglGetConfigs(EGL_NO_DISPLAY, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
867         expectError(EGL_BAD_DISPLAY);
868 
869         expectFalse(eglGetConfigs((EGLDisplay)-1, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
870         expectError(EGL_BAD_DISPLAY);
871 
872         log << TestLog::EndSection;
873 
874         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if num_config is NULL");
875 
876         expectFalse(eglGetConfigs(display, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), DE_NULL));
877         expectError(EGL_BAD_PARAMETER);
878 
879         log << TestLog::EndSection;
880     });
881 
882     TEGL_ADD_API_CASE(initialize, "eglInitialize() negative tests", {
883         TestLog &log = m_testCtx.getLog();
884         EGLint major = 0;
885         EGLint minor = 0;
886 
887         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
888 
889         expectFalse(eglInitialize(EGL_NO_DISPLAY, &major, &minor));
890         expectError(EGL_BAD_DISPLAY);
891 
892         expectFalse(eglInitialize((EGLDisplay)-1, &major, &minor));
893         expectError(EGL_BAD_DISPLAY);
894 
895         log << TestLog::EndSection;
896     });
897 
898     TEGL_ADD_API_CASE(make_current, "eglMakeCurrent() negative tests", {
899         TestLog &log       = m_testCtx.getLog();
900         EGLDisplay display = getDisplay();
901 
902         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
903 
904         expectFalse(eglMakeCurrent(EGL_NO_DISPLAY, DE_NULL, DE_NULL, DE_NULL));
905         expectError(EGL_BAD_DISPLAY);
906 
907         expectFalse(eglMakeCurrent((EGLDisplay)-1, DE_NULL, DE_NULL, DE_NULL));
908         expectError(EGL_BAD_DISPLAY);
909 
910         log << TestLog::EndSection;
911 
912         // Create simple pbuffer surface.
913         EGLSurface surface = EGL_NO_SURFACE;
914         {
915             EGLConfig config;
916             if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
917             {
918                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
919                 expectError(EGL_SUCCESS);
920             }
921         }
922 
923         // Create simple ES2 context
924         EGLContext context = EGL_NO_CONTEXT;
925         {
926             EGLConfig config;
927             if (getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT>))
928             {
929                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
930                 expectError(EGL_SUCCESS);
931             }
932         }
933 
934         if (surface != EGL_NO_SURFACE && context != EGL_NO_CONTEXT)
935         {
936             log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
937 
938             expectFalse(eglMakeCurrent(display, (EGLSurface)-1, (EGLSurface)-1, context));
939             expectError(EGL_BAD_SURFACE);
940 
941             expectFalse(eglMakeCurrent(display, surface, (EGLSurface)-1, context));
942             expectError(EGL_BAD_SURFACE);
943 
944             expectFalse(eglMakeCurrent(display, (EGLSurface)-1, surface, context));
945             expectError(EGL_BAD_SURFACE);
946 
947             log << TestLog::EndSection;
948         }
949 
950         if (surface)
951         {
952             log << TestLog::Section("Test3", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
953 
954             expectFalse(eglMakeCurrent(display, surface, surface, (EGLContext)-1));
955             expectError(EGL_BAD_CONTEXT);
956 
957             log << TestLog::EndSection;
958         }
959 
960         if (surface != EGL_NO_SURFACE)
961         {
962             log << TestLog::Section("Test4", "EGL_BAD_MATCH is generated if read or draw surface is not EGL_NO_SURFACE "
963                                              "and context is EGL_NO_CONTEXT");
964 
965             expectFalse(eglMakeCurrent(display, surface, EGL_NO_SURFACE, EGL_NO_CONTEXT));
966             expectError(EGL_BAD_MATCH);
967 
968             expectFalse(eglMakeCurrent(display, EGL_NO_SURFACE, surface, EGL_NO_CONTEXT));
969             expectError(EGL_BAD_MATCH);
970 
971             expectFalse(eglMakeCurrent(display, surface, surface, EGL_NO_CONTEXT));
972             expectError(EGL_BAD_MATCH);
973 
974             log << TestLog::EndSection;
975         }
976 
977         if (context)
978         {
979             eglDestroyContext(display, context);
980             expectError(EGL_SUCCESS);
981         }
982 
983         if (surface)
984         {
985             eglDestroySurface(display, surface);
986             expectError(EGL_SUCCESS);
987         }
988     });
989 
990     TEGL_ADD_API_CASE(get_current_context, "eglGetCurrentContext() negative tests", {
991         expectNoContext(eglGetCurrentContext());
992 
993         if (isAPISupported(EGL_OPENGL_ES_API))
994         {
995             expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
996             expectError(EGL_SUCCESS);
997 
998             expectNoContext(eglGetCurrentContext());
999             expectError(EGL_SUCCESS);
1000         }
1001     });
1002 
1003     TEGL_ADD_API_CASE(get_current_surface, "eglGetCurrentSurface() negative tests", {
1004         TestLog &log       = m_testCtx.getLog();
1005         EGLDisplay display = getDisplay();
1006         EGLConfig config   = DE_NULL;
1007         EGLContext context = EGL_NO_CONTEXT;
1008         EGLSurface surface = EGL_NO_SURFACE;
1009         bool gotConfig =
1010             getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << surfaceBits<EGL_PBUFFER_BIT>);
1011 
1012         if (gotConfig)
1013         {
1014             expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
1015             expectError(EGL_SUCCESS);
1016 
1017             context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
1018             expectError(EGL_SUCCESS);
1019 
1020             // Create simple pbuffer surface.
1021             surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1022             expectError(EGL_SUCCESS);
1023 
1024             expectTrue(eglMakeCurrent(display, surface, surface, context));
1025             expectError(EGL_SUCCESS);
1026 
1027             log << TestLog::Section("Test1",
1028                                     "EGL_BAD_PARAMETER is generated if readdraw is neither EGL_READ nor EGL_DRAW");
1029 
1030             expectNoSurface(eglGetCurrentSurface(EGL_NONE));
1031             expectError(EGL_BAD_PARAMETER);
1032 
1033             log << TestLog::EndSection;
1034 
1035             expectTrue(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1036             expectError(EGL_SUCCESS);
1037 
1038             if (surface != EGL_NO_SURFACE)
1039             {
1040                 expectTrue(eglDestroySurface(display, surface));
1041                 expectError(EGL_SUCCESS);
1042             }
1043 
1044             if (context != EGL_NO_CONTEXT)
1045             {
1046                 expectTrue(eglDestroyContext(display, context));
1047                 expectError(EGL_SUCCESS);
1048             }
1049         }
1050     });
1051 
1052     TEGL_ADD_API_CASE(query_context, "eglQueryContext() negative tests", {
1053         TestLog &log       = m_testCtx.getLog();
1054         EGLDisplay display = getDisplay();
1055         EGLint value       = 0;
1056 
1057         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1058 
1059         expectFalse(eglQueryContext(EGL_NO_DISPLAY, DE_NULL, EGL_CONFIG_ID, &value));
1060         expectError(EGL_BAD_DISPLAY);
1061 
1062         expectFalse(eglQueryContext((EGLDisplay)-1, DE_NULL, EGL_CONFIG_ID, &value));
1063         expectError(EGL_BAD_DISPLAY);
1064 
1065         log << TestLog::EndSection;
1066 
1067         log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
1068 
1069         expectFalse(eglQueryContext(display, DE_NULL, EGL_CONFIG_ID, &value));
1070         expectError(EGL_BAD_CONTEXT);
1071 
1072         expectFalse(eglQueryContext(display, DE_NULL, EGL_CONFIG_ID, &value));
1073         expectError(EGL_BAD_CONTEXT);
1074 
1075         log << TestLog::EndSection;
1076 
1077         // Create ES2 context.
1078         EGLConfig config   = DE_NULL;
1079         EGLContext context = DE_NULL;
1080         bool gotConfig     = getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
1081 
1082         if (gotConfig)
1083         {
1084             expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
1085             expectError(EGL_SUCCESS);
1086 
1087             context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
1088             expectError(EGL_SUCCESS);
1089         }
1090 
1091         log << TestLog::Section("Test3",
1092                                 "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid context attribute");
1093 
1094         if (context)
1095         {
1096             expectFalse(eglQueryContext(display, context, 0, &value));
1097             expectError(EGL_BAD_ATTRIBUTE);
1098             expectFalse(eglQueryContext(display, context, -1, &value));
1099             expectError(EGL_BAD_ATTRIBUTE);
1100             expectFalse(eglQueryContext(display, context, EGL_RED_SIZE, &value));
1101             expectError(EGL_BAD_ATTRIBUTE);
1102         }
1103 
1104         log << TestLog::EndSection;
1105 
1106         if (context)
1107         {
1108             expectTrue(eglDestroyContext(display, context));
1109             expectError(EGL_SUCCESS);
1110         }
1111     });
1112 
1113     TEGL_ADD_API_CASE(query_string, "eglQueryString() negative tests", {
1114         TestLog &log       = m_testCtx.getLog();
1115         EGLDisplay display = getDisplay();
1116 
1117         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1118 
1119         expectNull(eglQueryString(EGL_NO_DISPLAY, EGL_VENDOR));
1120         expectError(EGL_BAD_DISPLAY);
1121 
1122         expectNull(eglQueryString((EGLDisplay)-1, EGL_VENDOR));
1123         expectError(EGL_BAD_DISPLAY);
1124 
1125         log << TestLog::EndSection;
1126 
1127         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if name is not an accepted value");
1128 
1129         expectNull(eglQueryString(display, 0));
1130         expectError(EGL_BAD_PARAMETER);
1131         expectNull(eglQueryString(display, -1));
1132         expectError(EGL_BAD_PARAMETER);
1133 
1134         log << TestLog::EndSection;
1135     });
1136 
1137     TEGL_ADD_API_CASE(query_surface, "eglQuerySurface() negative tests", {
1138         TestLog &log       = m_testCtx.getLog();
1139         EGLDisplay display = getDisplay();
1140         EGLint value       = 0;
1141 
1142         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1143 
1144         expectFalse(eglQuerySurface(EGL_NO_DISPLAY, DE_NULL, EGL_CONFIG_ID, &value));
1145         expectError(EGL_BAD_DISPLAY);
1146 
1147         expectFalse(eglQuerySurface((EGLDisplay)-1, DE_NULL, EGL_CONFIG_ID, &value));
1148         expectError(EGL_BAD_DISPLAY);
1149 
1150         log << TestLog::EndSection;
1151 
1152         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1153 
1154         expectFalse(eglQuerySurface(display, DE_NULL, EGL_CONFIG_ID, &value));
1155         expectError(EGL_BAD_SURFACE);
1156 
1157         expectFalse(eglQuerySurface(display, (EGLSurface)-1, EGL_CONFIG_ID, &value));
1158         expectError(EGL_BAD_SURFACE);
1159 
1160         log << TestLog::EndSection;
1161 
1162         // Create pbuffer surface.
1163         EGLSurface surface = EGL_NO_SURFACE;
1164         {
1165             EGLConfig config;
1166             if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
1167             {
1168                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1169                 expectError(EGL_SUCCESS);
1170             }
1171             else
1172                 log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete"
1173                     << TestLog::EndMessage;
1174         }
1175 
1176         log << TestLog::Section("Test3",
1177                                 "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid surface attribute");
1178 
1179         if (surface)
1180         {
1181             expectFalse(eglQuerySurface(display, surface, 0, &value));
1182             expectError(EGL_BAD_ATTRIBUTE);
1183 
1184             expectFalse(eglQuerySurface(display, surface, -1, &value));
1185             expectError(EGL_BAD_ATTRIBUTE);
1186         }
1187 
1188         log << TestLog::EndSection;
1189 
1190         if (surface)
1191         {
1192             eglDestroySurface(display, surface);
1193             expectError(EGL_SUCCESS);
1194         }
1195     });
1196 
1197     TEGL_ADD_API_CASE(release_tex_image, "eglReleaseTexImage() negative tests", {
1198         TestLog &log       = m_testCtx.getLog();
1199         EGLDisplay display = getDisplay();
1200 
1201         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1202 
1203         expectFalse(eglReleaseTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1204         expectError(EGL_BAD_DISPLAY);
1205 
1206         expectFalse(eglReleaseTexImage((EGLDisplay)-1, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1207         expectError(EGL_BAD_DISPLAY);
1208 
1209         log << TestLog::EndSection;
1210 
1211         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1212 
1213         expectFalse(eglReleaseTexImage(display, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1214         expectError(EGL_BAD_SURFACE);
1215 
1216         expectFalse(eglReleaseTexImage(display, (EGLSurface)-1, EGL_BACK_BUFFER));
1217         expectError(EGL_BAD_SURFACE);
1218 
1219         log << TestLog::EndSection;
1220     });
1221 
1222     TEGL_ADD_API_CASE(surface_attrib, "eglSurfaceAttrib() negative tests", {
1223         TestLog &log       = m_testCtx.getLog();
1224         EGLDisplay display = getDisplay();
1225 
1226         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1227 
1228         expectFalse(eglSurfaceAttrib(EGL_NO_DISPLAY, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1229         expectError(EGL_BAD_DISPLAY);
1230 
1231         expectFalse(eglSurfaceAttrib((EGLDisplay)-1, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1232         expectError(EGL_BAD_DISPLAY);
1233 
1234         log << TestLog::EndSection;
1235 
1236         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1237 
1238         expectFalse(eglSurfaceAttrib(display, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1239         expectError(EGL_BAD_SURFACE);
1240 
1241         expectFalse(eglSurfaceAttrib(display, (EGLSurface)-1, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1242         expectError(EGL_BAD_SURFACE);
1243 
1244         log << TestLog::EndSection;
1245 
1246         {
1247             // Create pbuffer surface.
1248             EGLSurface surface = EGL_NO_SURFACE;
1249             {
1250                 EGLConfig config;
1251                 if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
1252                 {
1253                     surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1254                     expectError(EGL_SUCCESS);
1255                 }
1256                 else
1257                     log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete"
1258                         << TestLog::EndMessage;
1259             }
1260 
1261             log << TestLog::Section("Test3",
1262                                     "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid surface attribute");
1263 
1264             if (surface)
1265             {
1266                 expectFalse(eglSurfaceAttrib(display, surface, 0, 0));
1267                 expectError(EGL_BAD_ATTRIBUTE);
1268 
1269                 expectFalse(eglSurfaceAttrib(display, surface, -1, 0));
1270                 expectError(EGL_BAD_ATTRIBUTE);
1271             }
1272 
1273             log << TestLog::EndSection;
1274 
1275             if (surface)
1276             {
1277                 eglDestroySurface(display, surface);
1278                 expectError(EGL_SUCCESS);
1279             }
1280         }
1281 
1282         {
1283             // Create pbuffer surface without EGL_MULTISAMPLE_RESOLVE_BOX_BIT.
1284             EGLSurface surface = EGL_NO_SURFACE;
1285             {
1286                 EGLConfig config;
1287                 if (getConfig(&config,
1288                               FilterList()
1289                                   << surfaceBits<EGL_PBUFFER_BIT> << notSurfaceBits<EGL_MULTISAMPLE_RESOLVE_BOX_BIT>))
1290                 {
1291                     surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1292                     expectError(EGL_SUCCESS);
1293                 }
1294                 else
1295                     log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete"
1296                         << TestLog::EndMessage;
1297             }
1298 
1299             log << TestLog::Section("Test4",
1300                                     "EGL_BAD_MATCH is generated if attribute is EGL_MULTISAMPLE_RESOLVE, value is "
1301                                     "EGL_MULTISAMPLE_RESOLVE_BOX, and the EGL_SURFACE_TYPE attribute of the EGLConfig "
1302                                     "used to create surface does not contain EGL_MULTISAMPLE_RESOLVE_BOX_BIT");
1303 
1304             if (surface)
1305             {
1306                 expectFalse(eglSurfaceAttrib(display, surface, EGL_MULTISAMPLE_RESOLVE, EGL_MULTISAMPLE_RESOLVE_BOX));
1307                 expectError(EGL_BAD_MATCH);
1308             }
1309 
1310             log << TestLog::EndSection;
1311 
1312             if (surface)
1313             {
1314                 eglDestroySurface(display, surface);
1315                 expectError(EGL_SUCCESS);
1316             }
1317         }
1318 
1319         {
1320             // Create pbuffer surface without EGL_SWAP_BEHAVIOR_PRESERVED_BIT.
1321             EGLSurface surface = EGL_NO_SURFACE;
1322             {
1323                 EGLConfig config;
1324                 if (getConfig(&config,
1325                               FilterList()
1326                                   << surfaceBits<EGL_PBUFFER_BIT> << notSurfaceBits<EGL_SWAP_BEHAVIOR_PRESERVED_BIT>))
1327                 {
1328                     surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1329                     expectError(EGL_SUCCESS);
1330                 }
1331                 else
1332                     log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete"
1333                         << TestLog::EndMessage;
1334             }
1335 
1336             log << TestLog::Section("Test5",
1337                                     "EGL_BAD_MATCH is generated if attribute is EGL_SWAP_BEHAVIOR, value is "
1338                                     "EGL_BUFFER_PRESERVED, and the EGL_SURFACE_TYPE attribute of the EGLConfig used to "
1339                                     "create surface does not contain EGL_SWAP_BEHAVIOR_PRESERVED_BIT");
1340 
1341             if (surface)
1342             {
1343                 expectFalse(eglSurfaceAttrib(display, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
1344                 expectError(EGL_BAD_MATCH);
1345             }
1346 
1347             log << TestLog::EndSection;
1348 
1349             if (surface)
1350             {
1351                 eglDestroySurface(display, surface);
1352                 expectError(EGL_SUCCESS);
1353             }
1354         }
1355     });
1356 
1357     TEGL_ADD_API_CASE(swap_buffers, "eglSwapBuffers() negative tests", {
1358         TestLog &log       = m_testCtx.getLog();
1359         EGLDisplay display = getDisplay();
1360 
1361         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1362 
1363         expectFalse(eglSwapBuffers(EGL_NO_DISPLAY, DE_NULL));
1364         expectError(EGL_BAD_DISPLAY);
1365 
1366         expectFalse(eglSwapBuffers((EGLDisplay)-1, DE_NULL));
1367         expectError(EGL_BAD_DISPLAY);
1368 
1369         log << TestLog::EndSection;
1370 
1371         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1372 
1373         expectFalse(eglSwapBuffers(display, DE_NULL));
1374         expectError(EGL_BAD_SURFACE);
1375 
1376         expectFalse(eglSwapBuffers(display, (EGLSurface)-1));
1377         expectError(EGL_BAD_SURFACE);
1378 
1379         log << TestLog::EndSection;
1380     });
1381 
1382     TEGL_ADD_API_CASE(swap_interval, "eglSwapInterval() negative tests", {
1383         TestLog &log       = m_testCtx.getLog();
1384         EGLDisplay display = getDisplay();
1385 
1386         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1387 
1388         expectFalse(eglSwapInterval(EGL_NO_DISPLAY, 0));
1389         expectError(EGL_BAD_DISPLAY);
1390 
1391         expectFalse(eglSwapInterval((EGLDisplay)-1, 0));
1392         expectError(EGL_BAD_DISPLAY);
1393 
1394         log << TestLog::EndSection;
1395 
1396         log << TestLog::Section("Test2",
1397                                 "EGL_BAD_CONTEXT is generated if there is no current context on the calling thread");
1398 
1399         expectFalse(eglSwapInterval(display, 0));
1400         expectError(EGL_BAD_CONTEXT);
1401 
1402         log << TestLog::EndSection;
1403     });
1404 
1405     TEGL_ADD_API_CASE(terminate, "eglTerminate() negative tests", {
1406         TestLog &log = m_testCtx.getLog();
1407 
1408         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1409 
1410         expectFalse(eglTerminate(EGL_NO_DISPLAY));
1411         expectError(EGL_BAD_DISPLAY);
1412 
1413         expectFalse(eglTerminate((EGLDisplay)-1));
1414         expectError(EGL_BAD_DISPLAY);
1415 
1416         log << TestLog::EndSection;
1417     });
1418 
1419     TEGL_ADD_API_CASE(wait_native, "eglWaitNative() negative tests", {
1420         EGLConfig config = DE_NULL;
1421         bool gotConfig =
1422             getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << surfaceBits<EGL_WINDOW_BIT>);
1423 
1424         if (gotConfig)
1425         {
1426             TestLog &log       = m_testCtx.getLog();
1427             const Library &egl = m_eglTestCtx.getLibrary();
1428             EGLDisplay display = getDisplay();
1429             const eglu::NativeWindowFactory &factory =
1430                 eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
1431             de::UniquePtr<eglu::NativeWindow> window(factory.createWindow(
1432                 &m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL,
1433                 eglu::WindowParams(256, 256, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
1434             eglu::UniqueSurface surface(
1435                 egl, display,
1436                 eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, display, config, DE_NULL));
1437             EGLContext context = EGL_NO_CONTEXT;
1438 
1439             expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
1440             expectError(EGL_SUCCESS);
1441 
1442             context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
1443             expectError(EGL_SUCCESS);
1444 
1445             expectTrue(eglMakeCurrent(display, *surface, *surface, context));
1446             expectError(EGL_SUCCESS);
1447 
1448             log << TestLog::Section("Test1", "EGL_BAD_PARAMETER is generated if engine is not a recognized marking "
1449                                              "engine and native rendering is supported by current surface");
1450 
1451             eglWaitNative(-1);
1452             expectEitherError(EGL_BAD_PARAMETER, EGL_SUCCESS);
1453 
1454             log << TestLog::EndSection;
1455 
1456             expectTrue(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1457             expectError(EGL_SUCCESS);
1458 
1459             if (context != EGL_NO_CONTEXT)
1460             {
1461                 expectTrue(eglDestroyContext(display, context));
1462                 expectError(EGL_SUCCESS);
1463             }
1464         }
1465     });
1466 }
1467 
1468 } // namespace egl
1469 } // namespace deqp
1470