1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2016 Google Inc.
6  * Copyright (c) 2016 The Khronos Group Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */ /*!
21  * \file
22  * \brief OpenGL ES 2 Test Package.
23  */ /*-------------------------------------------------------------------*/
24 
25 #include "es2cTestPackage.hpp"
26 #include "es2cTexture3DTests.hpp"
27 #include "glcAggressiveShaderOptimizationsTests.hpp"
28 #include "glcInfoTests.hpp"
29 #include "glcInternalformatTests.hpp"
30 #include "glcShaderNegativeTests.hpp"
31 #include "gluRenderContext.hpp"
32 #include "gluStateReset.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36 #include "tcuWaiverUtil.hpp"
37 
38 namespace es2cts
39 {
40 
41 class TestCaseWrapper : public tcu::TestCaseExecutor
42 {
43 public:
44 	TestCaseWrapper(TestPackage& package, de::SharedPtr<tcu::WaiverUtil> waiverMechanism);
45 	~TestCaseWrapper(void);
46 
47 	void init(tcu::TestCase* testCase, const std::string& path);
48 	void deinit(tcu::TestCase* testCase);
49 	tcu::TestNode::IterateResult iterate(tcu::TestCase* testCase);
50 
51 private:
52 	es2cts::TestPackage& m_testPackage;
53 	de::SharedPtr<tcu::WaiverUtil> m_waiverMechanism;
54 };
55 
TestCaseWrapper(TestPackage& package, de::SharedPtr<tcu::WaiverUtil> waiverMechanism)56 TestCaseWrapper::TestCaseWrapper(TestPackage& package, de::SharedPtr<tcu::WaiverUtil> waiverMechanism)
57 	: m_testPackage(package)
58 	, m_waiverMechanism(waiverMechanism)
59 {
60 }
61 
~TestCaseWrapper(void)62 TestCaseWrapper::~TestCaseWrapper(void)
63 {
64 }
65 
init(tcu::TestCase* testCase, const std::string& path)66 void TestCaseWrapper::init(tcu::TestCase* testCase, const std::string& path)
67 {
68 	if (m_waiverMechanism->isOnWaiverList(path))
69 		throw tcu::TestException("Waived test", QP_TEST_RESULT_WAIVER);
70 
71 	glu::resetState(m_testPackage.getContext().getRenderContext(), m_testPackage.getContext().getContextInfo());
72 
73 	testCase->init();
74 }
75 
deinit(tcu::TestCase* testCase)76 void TestCaseWrapper::deinit(tcu::TestCase* testCase)
77 {
78 	testCase->deinit();
79 
80 	glu::resetState(m_testPackage.getContext().getRenderContext(), m_testPackage.getContext().getContextInfo());
81 }
82 
iterate(tcu::TestCase* testCase)83 tcu::TestNode::IterateResult TestCaseWrapper::iterate(tcu::TestCase* testCase)
84 {
85 	tcu::TestContext&			 testCtx   = m_testPackage.getContext().getTestContext();
86 	glu::RenderContext&			 renderCtx = m_testPackage.getContext().getRenderContext();
87 	tcu::TestCase::IterateResult result;
88 
89 	// Clear to black
90 	{
91 		const glw::Functions& gl = renderCtx.getFunctions();
92 		gl.clearColor(0.0f, 0.0f, 0.0f, 1.f);
93 		gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
94 	}
95 
96 	result = testCase->iterate();
97 
98 	// Call implementation specific post-iterate routine (usually handles native events and swaps buffers)
99 	try
100 	{
101 		renderCtx.postIterate();
102 		return result;
103 	}
104 	catch (const tcu::ResourceError& e)
105 	{
106 		testCtx.getLog() << e;
107 		testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Resource error in context post-iteration routine");
108 		testCtx.setTerminateAfter(true);
109 		return tcu::TestNode::STOP;
110 	}
111 	catch (const std::exception& e)
112 	{
113 		testCtx.getLog() << e;
114 		testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Error in context post-iteration routine");
115 		return tcu::TestNode::STOP;
116 	}
117 }
118 
119 class ShaderTests : public deqp::TestCaseGroup
120 {
121 public:
ShaderTests(deqp::Context& context)122 	ShaderTests(deqp::Context& context) : TestCaseGroup(context, "shaders", "Shading Language Tests")
123 	{
124 	}
125 
init(void)126 	void init(void)
127 	{
128 		addChild(new deqp::ShaderNegativeTests(m_context, glu::GLSL_VERSION_100_ES));
129 		addChild(new glcts::AggressiveShaderOptimizationsTests(m_context));
130 	}
131 };
132 
TestPackage(tcu::TestContext& testCtx, const char* packageName)133 TestPackage::TestPackage(tcu::TestContext& testCtx, const char* packageName)
134 	: deqp::TestPackage(testCtx, packageName, "OpenGL ES 2 Conformance Tests", glu::ContextType(glu::ApiType::es(2, 0)),
135 						"gl_cts/data/gles2/")
136 {
137 }
138 
~TestPackage(void)139 TestPackage::~TestPackage(void)
140 {
141 }
142 
init(void)143 void TestPackage::init(void)
144 {
145 	// Call init() in parent - this creates context.
146 	deqp::TestPackage::init();
147 
148 	try
149 	{
150 		addChild(new ShaderTests(getContext()));
151 		addChild(new Texture3DTests(getContext()));
152 		tcu::TestCaseGroup* coreGroup = new tcu::TestCaseGroup(getTestContext(), "core", "core tests");
153 		coreGroup->addChild(new glcts::InternalformatTests(getContext()));
154 		addChild(coreGroup);
155 	}
156 	catch (...)
157 	{
158 		// Destroy context.
159 		deqp::TestPackage::deinit();
160 		throw;
161 	}
162 }
163 
createExecutor(void) const164 tcu::TestCaseExecutor* TestPackage::createExecutor(void) const
165 {
166 	return new TestCaseWrapper(const_cast<TestPackage&>(*this), m_waiverMechanism);
167 }
168 
169 } // es2cts
170