1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Choose config tests.
22 *//*--------------------------------------------------------------------*/
24 #include "teglChooseConfigTests.hpp"
25 #include "teglChooseConfigReference.hpp"
26 #include "tcuTestLog.hpp"
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 #include "deRandom.hpp"
32 #include "deStringUtil.hpp"
50 using eglu::ConfigInfo;
56 string configListToString (const Library& egl, const EGLDisplay& display, const vector<EGLConfig>& configs)
59 for (vector<EGLConfig>::const_iterator cfgIter = configs.begin(); cfgIter != configs.end(); cfgIter++)
61 EGLConfig config = *cfgIter;
62 EGLint configId = eglu::getConfigID(egl, display, config);
64 if (str.length() != 0)
67 str += de::toString(configId);
72 void logConfigAttrib (TestLog& log, EGLenum attrib, EGLint value)
74 const std::string attribStr = eglu::getConfigAttribName(attrib);
76 if (value == EGL_DONT_CARE)
78 log << TestLog::Message << " " << attribStr << ": EGL_DONT_CARE" << TestLog::EndMessage;
82 log << TestLog::Message << " " << attribStr << ": " << eglu::getConfigAttribValueStr(attrib, value) << TestLog::EndMessage;
85 bool configListEqual (const Library& egl, const EGLDisplay& display, const vector<EGLConfig>& as, const vector<EGLConfig>& bs)
87 if (as.size() != bs.size())
90 for (int configNdx = 0; configNdx < (int)as.size(); configNdx++)
92 if (as[configNdx] != bs[configNdx])
94 // Allow lists to differ if both configs are non-conformant
95 const EGLint aCaveat = eglu::getConfigAttribInt(egl, display, as[configNdx], EGL_CONFIG_CAVEAT);
96 const EGLint bCaveat = eglu::getConfigAttribInt(egl, display, bs[configNdx], EGL_CONFIG_CAVEAT);
98 if (aCaveat != EGL_NON_CONFORMANT_CONFIG || bCaveat != EGL_NON_CONFORMANT_CONFIG)
108 class ChooseConfigCase : public TestCase
111 ChooseConfigCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool checkOrder, const EGLint* attributes)
112 : TestCase (eglTestCtx, name, description)
113 , m_checkOrder (checkOrder)
114 , m_display (EGL_NO_DISPLAY)
117 while (attributes[0] != EGL_NONE)
119 m_attributes.push_back(std::make_pair((EGLenum)attributes[0], (EGLint)attributes[1]));
124 ChooseConfigCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool checkOrder, const std::vector<std::pair<EGLenum, EGLint> >& attributes)
125 : TestCase (eglTestCtx, name, description)
126 , m_checkOrder (checkOrder)
127 , m_attributes (attributes)
128 , m_display (EGL_NO_DISPLAY)
134 DE_ASSERT(m_display == EGL_NO_DISPLAY);
135 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
140 m_eglTestCtx.getLibrary().terminate(m_display);
141 m_display = EGL_NO_DISPLAY;
144 IterateResult iterate (void)
146 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
147 executeTest(m_attributes, m_checkOrder);
152 ChooseConfigCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool checkOrder)
153 : TestCase (eglTestCtx, name, description)
154 , m_checkOrder (checkOrder)
155 , m_display (EGL_NO_DISPLAY)
159 void executeTest (const std::vector<std::pair<EGLenum, EGLint> >& attributes, bool checkOrder)
161 const Library& egl = m_eglTestCtx.getLibrary();
162 TestLog& log = m_testCtx.getLog();
164 // Build attributes for EGL
165 vector<EGLint> attribList;
166 for (vector<pair<EGLenum, EGLint> >::const_iterator i = attributes.begin(); i != attributes.end(); i++)
168 attribList.push_back(i->first);
169 attribList.push_back(i->second);
171 attribList.push_back(EGL_NONE);
173 // Print attribList to log
174 log << TestLog::Message << "Attributes:" << TestLog::EndMessage;
175 for (vector<pair<EGLenum, EGLint> >::const_iterator i = attributes.begin(); i != attributes.end(); i++)
176 logConfigAttrib(log, i->first, i->second);
178 std::vector<EGLConfig> resultConfigs;
179 std::vector<EGLConfig> referenceConfigs;
181 // Query from EGL implementation
183 EGLint numConfigs = 0;
184 EGLU_CHECK_CALL(egl, chooseConfig(m_display, &attribList[0], DE_NULL, 0, &numConfigs));
185 resultConfigs.resize(numConfigs);
188 EGLU_CHECK_CALL(egl, chooseConfig(m_display, &attribList[0], &resultConfigs[0], (EGLint)resultConfigs.size(), &numConfigs));
192 chooseConfigReference(egl, m_display, referenceConfigs, attributes);
194 log << TestLog::Message << "Expected:\n " << configListToString(egl, m_display, referenceConfigs) << TestLog::EndMessage;
195 log << TestLog::Message << "Got:\n " << configListToString(egl, m_display, resultConfigs) << TestLog::EndMessage;
197 bool isSetMatch = (set<EGLConfig>(resultConfigs.begin(), resultConfigs.end()) == set<EGLConfig>(referenceConfigs.begin(), referenceConfigs.end()));
198 bool isExactMatch = configListEqual(egl, m_display, resultConfigs, referenceConfigs);
199 bool isMatch = isSetMatch && (checkOrder ? isExactMatch : true);
202 log << TestLog::Message << "Pass" << TestLog::EndMessage;
203 else if (!isSetMatch)
204 log << TestLog::Message << "Fail, configs don't match" << TestLog::EndMessage;
205 else if (!isExactMatch)
206 log << TestLog::Message << "Fail, got correct configs but in invalid order" << TestLog::EndMessage;
209 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
212 void fillDontCare (std::vector<std::pair<EGLenum, EGLint> >& attributes)
214 static const EGLenum dontCareAttributes[] =
216 EGL_TRANSPARENT_TYPE,
217 EGL_COLOR_BUFFER_TYPE,
222 // Fill appropriate unused attributes with EGL_DONT_CARE
223 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(dontCareAttributes); ndx++)
226 for (size_t findNdx = 0; findNdx < attributes.size(); findNdx++)
227 if (attributes[findNdx].first == dontCareAttributes[ndx]) found = true;
229 if (!found) attributes.push_back(std::make_pair(dontCareAttributes[ndx], EGL_DONT_CARE));
233 const bool m_checkOrder;
234 vector<pair<EGLenum, EGLint> > m_attributes;
236 EGLDisplay m_display;
239 class ChooseConfigSimpleCase : public ChooseConfigCase
242 EGLint getValue (EGLenum name)
250 { EGL_BUFFER_SIZE, 0 },
252 { EGL_GREEN_SIZE, 0 },
253 { EGL_BLUE_SIZE, 0 },
254 { EGL_LUMINANCE_SIZE, 0 },
255 { EGL_ALPHA_SIZE, 0 },
256 { EGL_ALPHA_MASK_SIZE, 0 },
257 { EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE },
258 { EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE },
259 { EGL_COLOR_BUFFER_TYPE, EGL_DONT_CARE },
260 { EGL_CONFIG_CAVEAT, EGL_DONT_CARE },
261 //{ EGL_CONFIG_ID, EGL_DONT_CARE },
262 { EGL_DEPTH_SIZE, 0 },
264 { EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE },
265 { EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE },
266 { EGL_NATIVE_RENDERABLE, EGL_DONT_CARE },
267 { EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE },
268 { EGL_SAMPLE_BUFFERS, 0 },
270 { EGL_STENCIL_SIZE, 0 },
271 { EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB },
272 { EGL_TRANSPARENT_RED_VALUE, 0 },
273 { EGL_TRANSPARENT_GREEN_VALUE, 0 },
274 { EGL_TRANSPARENT_BLUE_VALUE, 0 },
275 { EGL_CONFORMANT, EGL_OPENGL_ES_BIT },
276 { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT },
277 { EGL_SURFACE_TYPE, EGL_WINDOW_BIT }
278 //{ EGL_CONFORMANT, EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT },
279 //{ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT },
280 //{ EGL_SURFACE_TYPE, EGL_WINDOW_BIT
283 // | EGL_MULTISAMPLE_RESOLVE_BOX_BIT
284 // | EGL_VG_ALPHA_FORMAT_PRE_BIT
285 // | EGL_SWAP_BEHAVIOR_PRESERVED_BIT
286 // | EGL_VG_COLORSPACE_LINEAR_BIT
290 if (name == EGL_CONFIG_ID)
293 vector<EGLConfig> configs = eglu::getConfigs(m_eglTestCtx.getLibrary(), m_display);
294 return eglu::getConfigID(m_eglTestCtx.getLibrary(), m_display, configs[rnd.getInt(0, (int)configs.size()-1)]);
298 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(attributes); ndx++)
300 if (attributes[ndx].name == name)
301 return attributes[ndx].value;
309 ChooseConfigSimpleCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLenum attribute, bool checkOrder)
310 : ChooseConfigCase(eglTestCtx, name, description, checkOrder)
311 , m_attribute(attribute)
315 TestCase::IterateResult iterate (void)
317 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
319 std::vector<std::pair<EGLenum, EGLint> > attributes;
320 attributes.push_back(std::pair<EGLenum, EGLint>(m_attribute, getValue(m_attribute)));
322 fillDontCare(attributes);
323 executeTest(attributes, m_checkOrder);
331 class ChooseConfigRandomCase : public ChooseConfigCase
334 ChooseConfigRandomCase (EglTestContext& eglTestCtx, const char* name, const char* description, const set<EGLenum>& attribSet)
335 : ChooseConfigCase (eglTestCtx, name, description, true)
336 , m_attribSet (attribSet)
344 ChooseConfigCase::init();
346 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
349 TestCase::IterateResult iterate (void)
351 m_testCtx.getLog() << TestLog::Message << "Iteration :" << m_iterNdx << TestLog::EndMessage;
354 // Build random list of attributes
355 de::Random rnd(m_iterNdx);
356 const int numAttribs = rnd.getInt(0, (int)m_attribSet.size()*2);
358 std::vector<std::pair<EGLenum, EGLint> > attributes = genRandomAttributes(m_attribSet, numAttribs, rnd);
360 fillDontCare(attributes);
361 executeTest(attributes, m_checkOrder);
363 return m_iterNdx < m_numIters ? CONTINUE : STOP;
366 template <int MinVal, int MaxVal> static EGLint getInt (de::Random& rnd)
368 return rnd.getInt(MinVal, MaxVal);
371 static EGLint getBool (de::Random& rnd)
373 return rnd.getBool() ? EGL_TRUE : EGL_FALSE;
376 static EGLint getBufferType (de::Random& rnd)
378 static const EGLint types[] = { EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER };
379 return rnd.choose<EGLint>(types, types+DE_LENGTH_OF_ARRAY(types));
382 static EGLint getConfigCaveat (de::Random& rnd)
384 static const EGLint caveats[] = { EGL_SLOW_CONFIG, EGL_NON_CONFORMANT_CONFIG };
385 return rnd.choose<EGLint>(caveats, caveats+DE_LENGTH_OF_ARRAY(caveats));
388 static EGLint getApiBits (de::Random& rnd)
391 api |= rnd.getBool() ? EGL_OPENGL_BIT : 0;
392 api |= rnd.getBool() ? EGL_OPENGL_ES_BIT : 0;
393 api |= rnd.getBool() ? EGL_OPENGL_ES2_BIT : 0;
394 api |= rnd.getBool() ? EGL_OPENVG_BIT : 0;
398 static EGLint getSurfaceType (de::Random& rnd)
401 bits |= rnd.getBool() ? EGL_WINDOW_BIT : 0;
402 bits |= rnd.getBool() ? EGL_PIXMAP_BIT : 0;
403 bits |= rnd.getBool() ? EGL_PBUFFER_BIT : 0;
410 EGLint (*getValue)(de::Random& rnd);
413 std::vector<std::pair<EGLenum, EGLint> > genRandomAttributes (const std::set<EGLenum>& attribSet, int numAttribs, de::Random& rnd)
415 static const struct AttribSpec attributes[] =
417 { EGL_BUFFER_SIZE, ChooseConfigRandomCase::getInt<0, 32>, },
418 { EGL_RED_SIZE, ChooseConfigRandomCase::getInt<0, 8>, },
419 { EGL_GREEN_SIZE, ChooseConfigRandomCase::getInt<0, 8>, },
420 { EGL_BLUE_SIZE, ChooseConfigRandomCase::getInt<0, 8>, },
421 { EGL_LUMINANCE_SIZE, ChooseConfigRandomCase::getInt<0, 1>, },
422 { EGL_ALPHA_SIZE, ChooseConfigRandomCase::getInt<0, 8>, },
423 { EGL_ALPHA_MASK_SIZE, ChooseConfigRandomCase::getInt<0, 1>, },
424 { EGL_BIND_TO_TEXTURE_RGB, ChooseConfigRandomCase::getBool, },
425 { EGL_BIND_TO_TEXTURE_RGBA, ChooseConfigRandomCase::getBool, },
426 { EGL_COLOR_BUFFER_TYPE, ChooseConfigRandomCase::getBufferType, },
427 { EGL_CONFIG_CAVEAT, ChooseConfigRandomCase::getConfigCaveat, },
428 // { EGL_CONFIG_ID, 0/*special*/, },
429 { EGL_CONFORMANT, ChooseConfigRandomCase::getApiBits, },
430 { EGL_DEPTH_SIZE, ChooseConfigRandomCase::getInt<0, 32>, },
431 { EGL_LEVEL, ChooseConfigRandomCase::getInt<0, 1>, },
432 // { EGL_MATCH_NATIVE_PIXMAP, EGL_NONE, },
433 { EGL_MAX_SWAP_INTERVAL, ChooseConfigRandomCase::getInt<0, 2>, },
434 { EGL_MIN_SWAP_INTERVAL, ChooseConfigRandomCase::getInt<0, 1>, },
435 { EGL_NATIVE_RENDERABLE, ChooseConfigRandomCase::getBool, },
436 // { EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE, },
437 { EGL_RENDERABLE_TYPE, ChooseConfigRandomCase::getApiBits, },
438 { EGL_SAMPLE_BUFFERS, ChooseConfigRandomCase::getInt<0, 1>, },
439 { EGL_SAMPLES, ChooseConfigRandomCase::getInt<0, 1>, },
440 { EGL_STENCIL_SIZE, ChooseConfigRandomCase::getInt<0, 1>, },
441 { EGL_SURFACE_TYPE, ChooseConfigRandomCase::getSurfaceType, },
442 // { EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB,},
443 // { EGL_TRANSPARENT_RED_VALUE, ChooseConfigRandomCase::getInt<0, 255>, },
444 // { EGL_TRANSPARENT_GREEN_VALUE, ChooseConfigRandomCase::getInt<0, 255>, },
445 // { EGL_TRANSPARENT_BLUE_VALUE, ChooseConfigRandomCase::getInt<0, 255>, }
448 std::vector<std::pair<EGLenum, EGLint> > out;
450 // Build list to select from
451 std::vector<AttribSpec> candidates;
452 for (int ndx = 0; ndx < (int)DE_LENGTH_OF_ARRAY(attributes); ndx++)
454 if (attribSet.find(attributes[ndx].attribute) != attribSet.end())
455 candidates.push_back(attributes[ndx]);
458 for (int attribNdx = 0; attribNdx < numAttribs; attribNdx++)
460 AttribSpec spec = rnd.choose<AttribSpec>(candidates.begin(), candidates.end());
461 out.push_back(std::make_pair(spec.attribute, spec.getValue(rnd)));
467 std::set<EGLenum> m_attribSet;
472 ChooseConfigTests::ChooseConfigTests (EglTestContext& eglTestCtx)
473 : TestCaseGroup(eglTestCtx, "choose_config", "eglChooseConfig() tests")
477 ChooseConfigTests::~ChooseConfigTests (void)
484 template <typename T, size_t N>
485 std::set<T> toSet (const T (&arr)[N])
488 for (size_t i = 0; i < N; i++)
495 void ChooseConfigTests::init (void)
502 const char* testName;
505 { EGL_BUFFER_SIZE, "buffer_size" },
506 { EGL_RED_SIZE, "red_size" },
507 { EGL_GREEN_SIZE, "green_size" },
508 { EGL_BLUE_SIZE, "blue_size" },
509 { EGL_LUMINANCE_SIZE, "luminance_size" },
510 { EGL_ALPHA_SIZE, "alpha_size" },
511 { EGL_ALPHA_MASK_SIZE, "alpha_mask_size" },
512 { EGL_BIND_TO_TEXTURE_RGB, "bind_to_texture_rgb" },
513 { EGL_BIND_TO_TEXTURE_RGBA, "bind_to_texture_rgba" },
514 { EGL_COLOR_BUFFER_TYPE, "color_buffer_type" },
515 { EGL_CONFIG_CAVEAT, "config_caveat" },
516 { EGL_CONFIG_ID, "config_id" },
517 { EGL_CONFORMANT, "conformant" },
518 { EGL_DEPTH_SIZE, "depth_size" },
519 { EGL_LEVEL, "level" },
520 { EGL_MAX_SWAP_INTERVAL, "max_swap_interval" },
521 { EGL_MIN_SWAP_INTERVAL, "min_swap_interval" },
522 { EGL_NATIVE_RENDERABLE, "native_renderable" },
523 { EGL_NATIVE_VISUAL_TYPE, "native_visual_type" },
524 { EGL_RENDERABLE_TYPE, "renderable_type" },
525 { EGL_SAMPLE_BUFFERS, "sample_buffers" },
526 { EGL_SAMPLES, "samples" },
527 { EGL_STENCIL_SIZE, "stencil_size" },
528 { EGL_SURFACE_TYPE, "surface_type" },
529 { EGL_TRANSPARENT_TYPE, "transparent_type" },
530 { EGL_TRANSPARENT_RED_VALUE, "transparent_red_value" },
531 { EGL_TRANSPARENT_GREEN_VALUE, "transparent_green_value" },
532 { EGL_TRANSPARENT_BLUE_VALUE, "transparent_blue_value" }
535 tcu::TestCaseGroup* simpleGroup = new tcu::TestCaseGroup(m_testCtx, "simple", "Simple tests");
536 addChild(simpleGroup);
538 tcu::TestCaseGroup* selectionGroup = new tcu::TestCaseGroup(m_testCtx, "selection_only", "Selection tests, order ignored");
539 simpleGroup->addChild(selectionGroup);
541 tcu::TestCaseGroup* sortGroup = new tcu::TestCaseGroup(m_testCtx, "selection_and_sort", "Selection and ordering tests");
542 simpleGroup->addChild(sortGroup);
544 for (int ndx = 0; ndx < (int)DE_LENGTH_OF_ARRAY(attributes); ndx++)
546 selectionGroup->addChild(new ChooseConfigSimpleCase(m_eglTestCtx, attributes[ndx].testName, "Simple config selection case", attributes[ndx].attribute, false));
547 sortGroup->addChild(new ChooseConfigSimpleCase(m_eglTestCtx, attributes[ndx].testName, "Simple config selection and sort case", attributes[ndx].attribute, true));
553 tcu::TestCaseGroup* randomGroup = new tcu::TestCaseGroup(m_testCtx, "random", "Random eglChooseConfig() usage");
554 addChild(randomGroup);
556 static const EGLenum rgbaSizes[] =
563 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "color_sizes", "Random color size rules", toSet(rgbaSizes)));
565 static const EGLenum colorDepthStencilSizes[] =
574 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "color_depth_stencil_sizes", "Random color, depth and stencil size rules", toSet(colorDepthStencilSizes)));
576 static const EGLenum bufferSizes[] =
584 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "buffer_sizes", "Various buffer size rules", toSet(bufferSizes)));
586 static const EGLenum surfaceType[] =
588 EGL_NATIVE_RENDERABLE,
591 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "surface_type", "Surface type rules", toSet(surfaceType)));
593 static const EGLenum sampleBuffers[] =
598 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "sample_buffers", "Sample buffer rules", toSet(sampleBuffers)));
600 // \note Not every attribute is supported at the moment
601 static const EGLenum allAttribs[] =
609 EGL_BIND_TO_TEXTURE_RGB,
610 EGL_BIND_TO_TEXTURE_RGBA,
611 EGL_COLOR_BUFFER_TYPE,
617 // EGL_MATCH_NATIVE_PIXMAP,
618 EGL_MAX_SWAP_INTERVAL,
619 EGL_MIN_SWAP_INTERVAL,
620 EGL_NATIVE_RENDERABLE,
621 EGL_NATIVE_VISUAL_TYPE,
627 EGL_TRANSPARENT_TYPE,
628 // EGL_TRANSPARENT_RED_VALUE,
629 // EGL_TRANSPARENT_GREEN_VALUE,
630 // EGL_TRANSPARENT_BLUE_VALUE
632 randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "all", "All attributes", toSet(allAttribs)));