• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2014-2016 The Khronos Group Inc.
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
22  */ /*-------------------------------------------------------------------*/
23 
24 #include "glcTestSubcase.hpp"
25 #include "glwEnums.hpp"
26 #include "glwFunctions.hpp"
27 #include "tcuCommandLine.hpp"
28 #include "tcuTestLog.hpp"
29 
30 namespace deqp
31 {
32 
33 namespace
34 {
35 static Context *current_context;
36 }
37 
GLWrapper()38 GLWrapper::GLWrapper()
39     : CallLogWrapper(current_context->getRenderContext().getFunctions(), current_context->getTestContext().getLog())
40     , m_context(*current_context)
41 {
42 }
43 
SubcaseBase()44 SubcaseBase::SubcaseBase()
45 {
46 }
47 
~SubcaseBase()48 SubcaseBase::~SubcaseBase()
49 {
50 }
51 
Setup()52 long SubcaseBase::Setup()
53 {
54     return NO_ERROR;
55 }
56 
Cleanup()57 long SubcaseBase::Cleanup()
58 {
59     return NO_ERROR;
60 }
61 
VertexShader()62 std::string SubcaseBase::VertexShader()
63 {
64     return "";
65 }
66 
VertexShader2()67 std::string SubcaseBase::VertexShader2()
68 {
69     return "";
70 }
71 
TessControlShader()72 std::string SubcaseBase::TessControlShader()
73 {
74     return "";
75 }
76 
TessControlShader2()77 std::string SubcaseBase::TessControlShader2()
78 {
79     return "";
80 }
81 
TessEvalShader()82 std::string SubcaseBase::TessEvalShader()
83 {
84     return "";
85 }
86 
TessEvalShader2()87 std::string SubcaseBase::TessEvalShader2()
88 {
89     return "";
90 }
91 
GeometryShader()92 std::string SubcaseBase::GeometryShader()
93 {
94     return "";
95 }
96 
GeometryShader2()97 std::string SubcaseBase::GeometryShader2()
98 {
99     return "";
100 }
101 
FragmentShader()102 std::string SubcaseBase::FragmentShader()
103 {
104     return "";
105 }
106 
FragmentShader2()107 std::string SubcaseBase::FragmentShader2()
108 {
109     return "";
110 }
111 
WriteField(tcu::TestLog & log,const char * title,std::string message)112 void WriteField(tcu::TestLog &log, const char *title, std::string message)
113 {
114     if (message == "")
115         return;
116     using namespace std;
117     using tcu::TestLog;
118     istringstream tokens(message);
119     string line;
120     log.startSection("Details", title);
121     while (getline(tokens, line))
122     {
123         log.writeMessage(line.c_str());
124     }
125     log.endSection();
126 }
127 
OutputNotSupported(std::string reason)128 void SubcaseBase::OutputNotSupported(std::string reason)
129 {
130     using tcu::TestLog;
131     TestLog &log    = m_context.getTestContext().getLog();
132     std::string msg = reason + ", test will not run.";
133     std::istringstream tokens(msg);
134     std::string line;
135     log.startSection("Not supported", "Reason");
136     while (getline(tokens, line))
137     {
138         log.writeMessage(line.c_str());
139     }
140     log.endSection();
141 }
142 
Documentation()143 void SubcaseBase::Documentation()
144 {
145     using namespace std;
146     using tcu::TestLog;
147     TestLog &log = m_context.getTestContext().getLog();
148 
149     WriteField(log, "Title", Title());
150     WriteField(log, "Purpose", Purpose());
151     WriteField(log, "Method", Method());
152     WriteField(log, "Pass Criteria", PassCriteria());
153 
154     //OpenGL fields
155     string vsh = VertexShader();
156     if (!vsh.empty())
157         WriteField(log, "OpenGL vertex shader", vsh);
158 
159     string vsh2 = VertexShader2();
160     if (!vsh2.empty())
161         WriteField(log, "OpenGL vertex shader 2", vsh2);
162 
163     string tcsh = TessControlShader();
164     if (!tcsh.empty())
165         WriteField(log, "OpenGL tessellation control shader", tcsh);
166 
167     string tcsh2 = TessControlShader();
168     if (!tcsh2.empty())
169         WriteField(log, "OpenGL tessellation control shader 2", tcsh2);
170 
171     string tesh = TessControlShader();
172     if (!tesh.empty())
173         WriteField(log, "OpenGL tessellation evaluation shader", tesh);
174 
175     string tesh2 = TessControlShader();
176     if (!tesh2.empty())
177         WriteField(log, "OpenGL tessellation evaluation shader 2", tesh2);
178 
179     string gsh = GeometryShader();
180     if (!gsh.empty())
181         WriteField(log, "OpenGL geometry shader", gsh);
182 
183     string gsh2 = GeometryShader2();
184     if (!gsh2.empty())
185         WriteField(log, "OpenGL geometry shader 2", gsh2);
186 
187     string fsh = FragmentShader();
188     if (!fsh.empty())
189         WriteField(log, "OpenGL fragment shader", fsh);
190 
191     string fsh2 = FragmentShader2();
192     if (!fsh2.empty())
193         WriteField(log, "OpenGL fragment shader 2", fsh2);
194 }
195 
TestSubcase(Context & context,const char * name,SubcaseBase::SubcaseBasePtr (* factoryFunc)())196 TestSubcase::TestSubcase(Context &context, const char *name, SubcaseBase::SubcaseBasePtr (*factoryFunc)())
197     : TestCase(context, name, "")
198     , m_factoryFunc(factoryFunc)
199     , m_iterationCount(context.getTestContext().getCommandLine().getTestIterationCount())
200 {
201     if (!m_iterationCount)
202         m_iterationCount = 1;
203 }
204 
~TestSubcase(void)205 TestSubcase::~TestSubcase(void)
206 {
207 }
208 
init(void)209 void TestSubcase::init(void)
210 {
211 }
212 
deinit(void)213 void TestSubcase::deinit(void)
214 {
215 }
216 
iterate(void)217 TestSubcase::IterateResult TestSubcase::iterate(void)
218 {
219     current_context = &m_context;
220     using namespace std;
221     using tcu::TestLog;
222     TestLog &log = m_testCtx.getLog();
223 
224     SubcaseBase::SubcaseBasePtr subcase = m_factoryFunc();
225     subcase->Documentation();
226     subcase->enableLogging(true);
227     //Run subcase
228     long subError = NO_ERROR;
229     // test case setup
230     try
231     {
232         subError = subcase->Setup();
233         if (subError == ERROR)
234             log.writeMessage("Test Setup() failed");
235     }
236     catch (const tcu::NotSupportedError &ex)
237     {
238         log.writeMessage(ex.what());
239         subError = NOT_SUPPORTED;
240     }
241     catch (const runtime_error &ex)
242     {
243         log.writeMessage(ex.what());
244         subError = ERROR;
245     }
246     catch (...)
247     {
248         log.writeMessage("Undefined exception.");
249         subError = ERROR;
250     }
251 
252     // test case run
253     if (subError == NO_ERROR)
254     {
255         try
256         {
257             subError = subcase->Run();
258             if (subError == ERROR)
259                 log.writeMessage("Test Run() failed");
260         }
261         catch (const tcu::NotSupportedError &ex)
262         {
263             log.writeMessage(ex.what());
264             subError = NOT_SUPPORTED;
265         }
266         catch (const runtime_error &ex)
267         {
268             log.writeMessage(ex.what());
269             subError = ERROR;
270         }
271         catch (...)
272         {
273             log.writeMessage("Undefined exception.");
274             subError = ERROR;
275         }
276     }
277 
278     // test case cleanup
279     try
280     {
281         if (subcase->Cleanup() == ERROR)
282         {
283             subError = ERROR;
284             log.writeMessage("Test Cleanup() failed");
285         }
286     }
287     catch (const runtime_error &ex)
288     {
289         log.writeMessage(ex.what());
290         subError = ERROR;
291     }
292     catch (...)
293     {
294         log.writeMessage("Undefined exception.");
295         subError = ERROR;
296     }
297     subcase->enableLogging(false);
298 
299     //check gl error state
300     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
301     glw::GLenum glError      = gl.getError();
302     for (int i = 0; i < 100 && gl.getError(); ++i)
303         ;
304     if (glError != GL_NO_ERROR)
305     {
306         const char *name = glu::getErrorName(glError);
307         if (name == nullptr)
308             name = "UNKNOWN ERROR";
309         log << TestLog::Message << "After test execution glGetError() returned: " << name
310             << ", forcing FAIL for subcase" << TestLog::EndMessage;
311         subError = ERROR;
312     }
313 
314     if (subError == ERROR)
315     {
316         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
317         return STOP;
318     }
319     else if (subError == NOT_SUPPORTED)
320     {
321         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
322         return STOP;
323     }
324     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
325 
326     if (--m_iterationCount)
327         return CONTINUE;
328     else
329         return STOP;
330 }
331 } // namespace deqp
332