Home | History | Annotate | Download | only in common
      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 Test Case Wrapper.
     23  */ /*-------------------------------------------------------------------*/
     24 
     25 #include "glcTestCaseWrapper.hpp"
     26 #include "gluStateReset.hpp"
     27 #include "glwEnums.hpp"
     28 #include "glwFunctions.hpp"
     29 #include "tcuTestLog.hpp"
     30 
     31 namespace deqp
     32 {
     33 
     34 using tcu::TestLog;
     35 
     36 TestCaseWrapper::TestCaseWrapper(Context& context) : m_testCtx(context.getTestContext()), m_context(context)
     37 {
     38 }
     39 
     40 TestCaseWrapper::~TestCaseWrapper(void)
     41 {
     42 }
     43 
     44 bool TestCaseWrapper::initTestCase(tcu::TestCase* testCase)
     45 {
     46 	TestLog& log	 = m_testCtx.getLog();
     47 	bool	 success = false;
     48 
     49 	try
     50 	{
     51 		// Clear state to defaults
     52 		glu::resetState(m_context.getRenderContext(), m_context.getContextInfo());
     53 	}
     54 	catch (const std::exception& e)
     55 	{
     56 		log << e;
     57 		log << TestLog::Message << "Error in state reset, test program will terminate." << TestLog::EndMessage;
     58 		return false;
     59 	}
     60 
     61 	try
     62 	{
     63 		testCase->init();
     64 		success = true;
     65 	}
     66 	catch (const std::bad_alloc&)
     67 	{
     68 		DE_ASSERT(!success);
     69 		m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory in test case init");
     70 	}
     71 	catch (const tcu::ResourceError& e)
     72 	{
     73 		DE_ASSERT(!success);
     74 		m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Resource error in test case init");
     75 		log << e;
     76 	}
     77 	catch (const tcu::NotSupportedError& e)
     78 	{
     79 		DE_ASSERT(!success);
     80 		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
     81 		log << e;
     82 	}
     83 	catch (const tcu::InternalError& e)
     84 	{
     85 		DE_ASSERT(!success);
     86 		m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Internal error in test case init");
     87 		log << e;
     88 	}
     89 	catch (const tcu::Exception& e)
     90 	{
     91 		DE_ASSERT(!success);
     92 		log << e;
     93 	}
     94 
     95 	if (!success)
     96 	{
     97 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_LAST)
     98 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Error in test case init");
     99 		return false;
    100 	}
    101 
    102 	return true;
    103 }
    104 
    105 bool TestCaseWrapper::deinitTestCase(tcu::TestCase* testCase)
    106 {
    107 	TestLog& log = m_testCtx.getLog();
    108 
    109 	try
    110 	{
    111 		testCase->deinit();
    112 	}
    113 	catch (const tcu::Exception& e)
    114 	{
    115 		log << e;
    116 		log << TestLog::Message << "Error in test case deinit, test program will terminate." << TestLog::EndMessage;
    117 		return false;
    118 	}
    119 
    120 	try
    121 	{
    122 		// Clear state to defaults
    123 		glu::resetState(m_context.getRenderContext(), m_context.getContextInfo());
    124 	}
    125 	catch (const std::exception& e)
    126 	{
    127 		log << e;
    128 		log << TestLog::Message << "Error in state reset, test program will terminate." << TestLog::EndMessage;
    129 		return false;
    130 	}
    131 
    132 	return true;
    133 }
    134 
    135 tcu::TestNode::IterateResult TestCaseWrapper::iterateTestCase(tcu::TestCase* testCase)
    136 {
    137 	// Iterate the sub-case.
    138 	TestLog&					 log		   = m_testCtx.getLog();
    139 	tcu::TestCase::IterateResult iterateResult = tcu::TestCase::STOP;
    140 
    141 	try
    142 	{
    143 		iterateResult = testCase->iterate();
    144 	}
    145 	catch (const std::bad_alloc&)
    146 	{
    147 		m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory during test execution");
    148 	}
    149 	catch (const tcu::ResourceError& e)
    150 	{
    151 		log << e;
    152 		m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Resource error during test execution");
    153 	}
    154 	catch (const tcu::NotSupportedError& e)
    155 	{
    156 		log << e;
    157 		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
    158 	}
    159 	catch (const tcu::InternalError& e)
    160 	{
    161 		log << e;
    162 		m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Internal error in test execution");
    163 	}
    164 	catch (const tcu::Exception& e)
    165 	{
    166 		log << e;
    167 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Error in test execution");
    168 	}
    169 
    170 	// Clear buffers
    171 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
    172 	gl.clearColor(0.f, 0.f, 0.f, 1.f);
    173 	gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    174 
    175 	tcu::TestCase::IterateResult result = iterateResult;
    176 
    177 	// Call implementation specific post-iterate routine (usually handles native events and swaps buffers)
    178 	try
    179 	{
    180 		m_context.getRenderContext().postIterate();
    181 	}
    182 	catch (const std::exception& e)
    183 	{
    184 		m_testCtx.getLog() << e;
    185 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Error in context post-iteration routine");
    186 		return tcu::TestNode::STOP;
    187 	}
    188 
    189 	return result;
    190 }
    191 
    192 } // deqp
    193