1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 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 Boolean State Query tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fBooleanStateQueryTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "glsStateQueryUtil.hpp"
27 #include "gluRenderContext.hpp"
28 #include "tcuRenderTarget.hpp"
29 #include "glwEnums.hpp"
31 using namespace glw; // GLint and other GL types
32 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
40 namespace BooleanStateQueryVerifiers
45 class StateVerifier : protected glu::CallLogWrapper
48 StateVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
49 virtual ~StateVerifier (); // make GCC happy
51 const char* getTestNamePostfix (void) const;
53 virtual void verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference) = DE_NULL;
54 virtual void verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3) = DE_NULL;
55 virtual void verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name) = DE_NULL;
57 const char* const m_testNamePostfix;
60 StateVerifier::StateVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
61 : glu::CallLogWrapper (gl, log)
62 , m_testNamePostfix (testNamePostfix)
67 StateVerifier::~StateVerifier ()
71 const char* StateVerifier::getTestNamePostfix (void) const
73 return m_testNamePostfix;
78 class IsEnabledVerifier : public StateVerifier
81 IsEnabledVerifier (const glw::Functions& gl, tcu::TestLog& log);
82 void verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference);
83 void verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3);
84 void verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name);
87 IsEnabledVerifier::IsEnabledVerifier (const glw::Functions& gl, tcu::TestLog& log)
88 : StateVerifier(gl, log, "_isenabled")
92 void IsEnabledVerifier::verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference)
96 const GLboolean state = glIsEnabled(name);
97 const GLboolean expectedGLState = reference ? (GLboolean)GL_TRUE : (GLboolean)GL_FALSE;
99 if (state != expectedGLState)
101 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << (reference ? "GL_TRUE" : "GL_FALSE") << TestLog::EndMessage;
102 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
103 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
107 void IsEnabledVerifier::verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3)
111 DE_UNREF(reference0);
112 DE_UNREF(reference1);
113 DE_UNREF(reference2);
114 DE_UNREF(reference3);
115 DE_ASSERT(false && "not supported");
118 void IsEnabledVerifier::verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name)
122 DE_ASSERT(false && "not supported");
124 // GetBooleanVerifier
126 class GetBooleanVerifier : public StateVerifier
129 GetBooleanVerifier (const glw::Functions& gl, tcu::TestLog& log);
130 void verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference);
131 void verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3);
132 void verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name);
135 GetBooleanVerifier::GetBooleanVerifier (const glw::Functions& gl, tcu::TestLog& log)
136 : StateVerifier(gl, log, "_getboolean")
140 void GetBooleanVerifier::verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference)
144 StateQueryMemoryWriteGuard<GLboolean> state;
145 glGetBooleanv(name, &state);
147 if (!state.verifyValidity(testCtx))
150 const GLboolean expectedGLState = reference ? GL_TRUE : GL_FALSE;
152 if (state != expectedGLState)
154 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << (reference ? "GL_TRUE" : "GL_FALSE") << TestLog::EndMessage;
155 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
156 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
160 void GetBooleanVerifier::verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3)
164 StateQueryMemoryWriteGuard<GLboolean[4]> boolVector4;
165 glGetBooleanv(name, boolVector4);
167 if (!boolVector4.verifyValidity(testCtx))
170 const GLboolean referenceAsGLBoolean[] =
172 reference0 ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
173 reference1 ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
174 reference2 ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
175 reference3 ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
178 if (boolVector4[0] != referenceAsGLBoolean[0] ||
179 boolVector4[1] != referenceAsGLBoolean[1] ||
180 boolVector4[2] != referenceAsGLBoolean[2] ||
181 boolVector4[3] != referenceAsGLBoolean[3])
183 testCtx.getLog() << TestLog::Message << "// ERROR: expected "
184 << (referenceAsGLBoolean[0] ? "GL_TRUE" : "GL_FALSE") << " "
185 << (referenceAsGLBoolean[1] ? "GL_TRUE" : "GL_FALSE") << " "
186 << (referenceAsGLBoolean[2] ? "GL_TRUE" : "GL_FALSE") << " "
187 << (referenceAsGLBoolean[3] ? "GL_TRUE" : "GL_FALSE") << TestLog::EndMessage;
189 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
190 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
194 void GetBooleanVerifier::verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name)
198 StateQueryMemoryWriteGuard<GLboolean> state;
199 glGetBooleanv(name, &state);
201 state.verifyValidity(testCtx);
206 class GetIntegerVerifier : public StateVerifier
209 GetIntegerVerifier (const glw::Functions& gl, tcu::TestLog& log);
210 void verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference);
211 void verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3);
212 void verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name);
216 GetIntegerVerifier::GetIntegerVerifier (const glw::Functions& gl, tcu::TestLog& log)
217 : StateVerifier(gl, log, "_getinteger")
221 void GetIntegerVerifier::verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference)
225 StateQueryMemoryWriteGuard<GLint> state;
226 glGetIntegerv(name, &state);
228 if (!state.verifyValidity(testCtx))
231 const GLint expectedGLState = reference ? 1 : 0;
233 if (state != expectedGLState)
235 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << expectedGLState << TestLog::EndMessage;
236 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
237 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
241 void GetIntegerVerifier::verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3)
245 StateQueryMemoryWriteGuard<GLint[4]> boolVector4;
246 glGetIntegerv(name, boolVector4);
248 if (!boolVector4.verifyValidity(testCtx))
251 const GLint referenceAsGLint[] =
259 if (boolVector4[0] != referenceAsGLint[0] ||
260 boolVector4[1] != referenceAsGLint[1] ||
261 boolVector4[2] != referenceAsGLint[2] ||
262 boolVector4[3] != referenceAsGLint[3])
264 testCtx.getLog() << TestLog::Message << "// ERROR: expected "
265 << referenceAsGLint[0] << " "
266 << referenceAsGLint[1] << " "
267 << referenceAsGLint[2] << " "
268 << referenceAsGLint[3] << " " << TestLog::EndMessage;
270 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
271 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
275 void GetIntegerVerifier::verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name)
279 StateQueryMemoryWriteGuard<GLint> state;
280 glGetIntegerv(name, &state);
282 state.verifyValidity(testCtx);
287 class GetFloatVerifier : public StateVerifier
290 GetFloatVerifier (const glw::Functions& gl, tcu::TestLog& log);
291 void verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference);
292 void verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3);
293 void verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name);
296 GetFloatVerifier::GetFloatVerifier (const glw::Functions& gl, tcu::TestLog& log)
297 : StateVerifier(gl, log, "_getfloat")
301 void GetFloatVerifier::verifyBoolean (tcu::TestContext& testCtx, GLenum name, bool reference)
305 StateQueryMemoryWriteGuard<GLfloat> state;
306 glGetFloatv(name, &state);
308 if (!state.verifyValidity(testCtx))
311 const GLfloat expectedGLState = reference ? 1.0f : 0.0f;
313 if (state != expectedGLState)
315 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << expectedGLState << "; got " << state << TestLog::EndMessage;
316 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
317 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
321 void GetFloatVerifier::verifyBoolean4 (tcu::TestContext& testCtx, GLenum name, bool reference0, bool reference1, bool reference2, bool reference3)
325 StateQueryMemoryWriteGuard<GLfloat[4]> boolVector4;
326 glGetFloatv(name, boolVector4);
328 if (!boolVector4.verifyValidity(testCtx))
331 const GLfloat referenceAsGLfloat[] =
333 reference0 ? 1.0f : 0.0f,
334 reference1 ? 1.0f : 0.0f,
335 reference2 ? 1.0f : 0.0f,
336 reference3 ? 1.0f : 0.0f,
339 if (boolVector4[0] != referenceAsGLfloat[0] ||
340 boolVector4[1] != referenceAsGLfloat[1] ||
341 boolVector4[2] != referenceAsGLfloat[2] ||
342 boolVector4[3] != referenceAsGLfloat[3])
344 testCtx.getLog() << TestLog::Message << "// ERROR: expected "
345 << referenceAsGLfloat[0] << " "
346 << referenceAsGLfloat[1] << " "
347 << referenceAsGLfloat[2] << " "
348 << referenceAsGLfloat[3] << " " << TestLog::EndMessage;
350 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
351 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
355 void GetFloatVerifier::verifyBooleanAnything (tcu::TestContext& testCtx, GLenum name)
359 StateQueryMemoryWriteGuard<GLfloat> state;
360 glGetFloatv(name, &state);
362 state.verifyValidity(testCtx);
365 } // BooleanStateQueryVerifiers
370 using namespace BooleanStateQueryVerifiers;
372 class IsEnabledStateTestCase : public ApiCase
375 IsEnabledStateTestCase (Context& context, StateVerifier* verifier, const char* name, const char* description, GLenum targetName, bool initial)
376 : ApiCase (context, name, description)
377 , m_targetName (targetName)
378 , m_initial (initial)
379 , m_verifier (verifier)
385 // check inital value
386 m_verifier->verifyBoolean(m_testCtx, m_targetName, m_initial);
387 expectError(GL_NO_ERROR);
391 glEnable(m_targetName);
392 expectError(GL_NO_ERROR);
394 m_verifier->verifyBoolean(m_testCtx, m_targetName, true);
395 expectError(GL_NO_ERROR);
397 glDisable(m_targetName);
398 expectError(GL_NO_ERROR);
400 m_verifier->verifyBoolean(m_testCtx, m_targetName, false);
401 expectError(GL_NO_ERROR);
407 StateVerifier* m_verifier;
410 class DepthWriteMaskTestCase : public ApiCase
413 DepthWriteMaskTestCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
414 : ApiCase (context, name, description)
415 , m_verifier (verifier)
421 m_verifier->verifyBoolean(m_testCtx, GL_DEPTH_WRITEMASK, true);
422 expectError(GL_NO_ERROR);
424 glDepthMask(GL_FALSE);
425 m_verifier->verifyBoolean(m_testCtx, GL_DEPTH_WRITEMASK, false);
426 expectError(GL_NO_ERROR);
428 glDepthMask(GL_TRUE);
429 m_verifier->verifyBoolean(m_testCtx, GL_DEPTH_WRITEMASK, true);
430 expectError(GL_NO_ERROR);
433 StateVerifier* m_verifier;
436 class SampleCoverageInvertTestCase : public ApiCase
439 SampleCoverageInvertTestCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
440 : ApiCase (context, name, description)
441 , m_verifier (verifier)
447 m_verifier->verifyBoolean(m_testCtx, GL_SAMPLE_COVERAGE_INVERT, false);
448 expectError(GL_NO_ERROR);
450 glSampleCoverage(1.0f, GL_TRUE);
451 m_verifier->verifyBoolean(m_testCtx, GL_SAMPLE_COVERAGE_INVERT, true);
452 expectError(GL_NO_ERROR);
454 glSampleCoverage(1.0f, GL_FALSE);
455 m_verifier->verifyBoolean(m_testCtx, GL_SAMPLE_COVERAGE_INVERT, false);
456 expectError(GL_NO_ERROR);
459 StateVerifier* m_verifier;
462 class ShaderCompilerTestCase : public ApiCase
465 ShaderCompilerTestCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
466 : ApiCase (context, name, description)
467 , m_verifier (verifier)
473 m_verifier->verifyBooleanAnything(m_testCtx, GL_SHADER_COMPILER);
474 expectError(GL_NO_ERROR);
478 StateVerifier* m_verifier;
481 class ColorMaskTestCase : public ApiCase
484 ColorMaskTestCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
485 : ApiCase(context, name, description)
486 , m_verifier (verifier)
491 m_verifier->verifyBoolean4(m_testCtx, GL_COLOR_WRITEMASK, true, true, true, true);
492 expectError(GL_NO_ERROR);
494 const struct ColorMask
496 GLboolean r, g, b, a;
499 { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE },
500 { GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE },
501 { GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE },
502 { GL_TRUE, GL_TRUE, GL_FALSE, GL_FALSE },
503 { GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE },
504 { GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE },
505 { GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE },
506 { GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE },
507 { GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE },
508 { GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE },
509 { GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE },
510 { GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE },
511 { GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE },
512 { GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE },
513 { GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE },
514 { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE },
517 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(testMasks); ndx++)
519 glColorMask(testMasks[ndx].r, testMasks[ndx].g, testMasks[ndx].b, testMasks[ndx].a);
520 m_verifier->verifyBoolean4(m_testCtx, GL_COLOR_WRITEMASK, testMasks[ndx].r==GL_TRUE, testMasks[ndx].g==GL_TRUE, testMasks[ndx].b==GL_TRUE, testMasks[ndx].a==GL_TRUE);
521 expectError(GL_NO_ERROR);
525 StateVerifier* m_verifier;
528 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \
529 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
531 StateVerifier* verifier = (VERIFIERS)[_verifierNdx]; \
537 BooleanStateQueryTests::BooleanStateQueryTests (Context& context)
538 : TestCaseGroup (context, "boolean", "Boolean State Query tests")
539 , m_verifierIsEnabled (DE_NULL)
540 , m_verifierBoolean (DE_NULL)
541 , m_verifierInteger (DE_NULL)
542 , m_verifierFloat (DE_NULL)
546 BooleanStateQueryTests::~BooleanStateQueryTests (void)
551 void BooleanStateQueryTests::init (void)
553 DE_ASSERT(m_verifierIsEnabled == DE_NULL);
554 DE_ASSERT(m_verifierBoolean == DE_NULL);
555 DE_ASSERT(m_verifierInteger == DE_NULL);
556 DE_ASSERT(m_verifierFloat == DE_NULL);
558 m_verifierIsEnabled = new IsEnabledVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
559 m_verifierBoolean = new GetBooleanVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
560 m_verifierInteger = new GetIntegerVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
561 m_verifierFloat = new GetFloatVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
563 StateVerifier* isEnabledVerifiers[] = {m_verifierIsEnabled, m_verifierBoolean, m_verifierInteger, m_verifierFloat};
564 StateVerifier* normalVerifiers[] = { m_verifierBoolean, m_verifierInteger, m_verifierFloat};
569 const char* description;
573 const StateBoolean isEnableds[] =
575 { "cull_face", "CULL_FACE", GL_CULL_FACE, false},
576 { "polygon_offset_fill", "POLYGON_OFFSET_FILL", GL_POLYGON_OFFSET_FILL, false},
577 { "sample_alpha_to_coverage", "SAMPLE_ALPHA_TO_COVERAGE", GL_SAMPLE_ALPHA_TO_COVERAGE, false},
578 { "sample_coverage", "SAMPLE_COVERAGE", GL_SAMPLE_COVERAGE, false},
579 { "scissor_test", "SCISSOR_TEST", GL_SCISSOR_TEST, false},
580 { "stencil_test", "STENCIL_TEST", GL_STENCIL_TEST, false},
581 { "depth_test", "DEPTH_TEST", GL_DEPTH_TEST, false},
582 { "blend", "BLEND", GL_BLEND, false},
583 { "dither", "DITHER", GL_DITHER, true },
585 for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(isEnableds); testNdx++)
586 FOR_EACH_VERIFIER(isEnabledVerifiers, addChild(new IsEnabledStateTestCase(m_context, verifier, (std::string(isEnableds[testNdx].name) + verifier->getTestNamePostfix()).c_str(), isEnableds[testNdx].description, isEnableds[testNdx].targetName, isEnableds[testNdx].value)));
588 FOR_EACH_VERIFIER(normalVerifiers, addChild(new SampleCoverageInvertTestCase (m_context, verifier, (std::string("sample_coverage_invert") + verifier->getTestNamePostfix()).c_str(), "SAMPLE_COVERAGE_INVERT")));
589 FOR_EACH_VERIFIER(normalVerifiers, addChild(new ColorMaskTestCase (m_context, verifier, (std::string("color_writemask") + verifier->getTestNamePostfix()).c_str(), "COLOR_WRITEMASK")));
590 FOR_EACH_VERIFIER(normalVerifiers, addChild(new DepthWriteMaskTestCase (m_context, verifier, (std::string("depth_writemask") + verifier->getTestNamePostfix()).c_str(), "DEPTH_WRITEMASK")));
591 FOR_EACH_VERIFIER(normalVerifiers, addChild(new ShaderCompilerTestCase (m_context, verifier, (std::string("shader_compiler") + verifier->getTestNamePostfix()).c_str(), "SHADER_COMPILER")));
594 void BooleanStateQueryTests::deinit (void)
596 if (m_verifierIsEnabled)
598 delete m_verifierIsEnabled;
599 m_verifierIsEnabled = DE_NULL;
601 if (m_verifierBoolean)
603 delete m_verifierBoolean;
604 m_verifierBoolean = DE_NULL;
606 if (m_verifierInteger)
608 delete m_verifierInteger;
609 m_verifierInteger = DE_NULL;
613 delete m_verifierFloat;
614 m_verifierFloat = DE_NULL;
617 this->TestCaseGroup::deinit();