1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
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 Test executor.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuTestSessionExecutor.hpp"
25 #include "tcuTestLog.hpp"
34 static qpTestCaseType nodeTypeToTestCaseType (TestNodeType nodeType)
38 case NODETYPE_SELF_VALIDATE: return QP_TEST_CASE_TYPE_SELF_VALIDATE;
39 case NODETYPE_PERFORMANCE: return QP_TEST_CASE_TYPE_PERFORMANCE;
40 case NODETYPE_CAPABILITY: return QP_TEST_CASE_TYPE_CAPABILITY;
41 case NODETYPE_ACCURACY: return QP_TEST_CASE_TYPE_ACCURACY;
44 return QP_TEST_CASE_TYPE_LAST;
48 TestSessionExecutor::TestSessionExecutor (TestPackageRoot& root, TestContext& testCtx)
50 , m_inflater (testCtx)
51 , m_iterator (root, m_inflater, testCtx.getCommandLine())
52 , m_state (STATE_TRAVERSE_HIERARCHY)
53 , m_abortSession (false)
54 , m_isInTestCase (false)
59 TestSessionExecutor::~TestSessionExecutor (void)
63 bool TestSessionExecutor::iterate (void)
65 while (!m_abortSession)
69 case STATE_TRAVERSE_HIERARCHY:
71 const TestHierarchyIterator::State hierIterState = m_iterator.getState();
73 if (hierIterState == TestHierarchyIterator::STATE_ENTER_NODE ||
74 hierIterState == TestHierarchyIterator::STATE_LEAVE_NODE)
76 TestNode* const curNode = m_iterator.getNode();
77 const TestNodeType nodeType = curNode->getNodeType();
78 const bool isEnter = hierIterState == TestHierarchyIterator::STATE_ENTER_NODE;
82 case NODETYPE_PACKAGE:
84 TestPackage* const testPackage = static_cast<TestPackage*>(curNode);
85 isEnter ? enterTestPackage(testPackage) : leaveTestPackage(testPackage);
92 case NODETYPE_SELF_VALIDATE:
93 case NODETYPE_PERFORMANCE:
94 case NODETYPE_CAPABILITY:
95 case NODETYPE_ACCURACY:
97 TestCase* const testCase = static_cast<TestCase*>(curNode);
101 if (enterTestCase(testCase, m_iterator.getNodePath()))
102 m_state = STATE_EXECUTE_TEST_CASE;
103 // else remain in TRAVERSING_HIERARCHY => node will be exited from in the next iteration
106 leaveTestCase(testCase);
121 DE_ASSERT(hierIterState == TestHierarchyIterator::STATE_FINISHED);
122 m_status.isComplete = true;
127 case STATE_EXECUTE_TEST_CASE:
129 DE_ASSERT(m_iterator.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
130 isTestNodeTypeExecutable(m_iterator.getNode()->getNodeType()));
132 TestCase* const testCase = static_cast<TestCase*>(m_iterator.getNode());
133 const TestCase::IterateResult iterResult = iterateTestCase(testCase);
135 if (iterResult == TestCase::STOP)
136 m_state = STATE_TRAVERSE_HIERARCHY;
150 void TestSessionExecutor::enterTestPackage (TestPackage* testPackage)
152 // Create test case wrapper
153 DE_ASSERT(!m_caseExecutor);
154 m_caseExecutor = de::MovePtr<TestCaseExecutor>(testPackage->createExecutor());
157 void TestSessionExecutor::leaveTestPackage (TestPackage* testPackage)
159 DE_UNREF(testPackage);
160 m_caseExecutor.clear();
163 bool TestSessionExecutor::enterTestCase (TestCase* testCase, const std::string& casePath)
165 TestLog& log = m_testCtx.getLog();
166 const qpTestCaseType caseType = nodeTypeToTestCaseType(testCase->getNodeType());
169 print("\nTest case '%s'..\n", casePath.c_str());
171 m_testCtx.setTestResult(QP_TEST_RESULT_LAST, "");
172 m_testCtx.setTerminateAfter(false);
173 log.startCase(casePath.c_str(), caseType);
175 m_isInTestCase = true;
176 m_testStartTime = deGetMicroseconds();
180 m_caseExecutor->init(testCase, casePath);
183 catch (const std::bad_alloc&)
186 m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory in test case init");
187 m_testCtx.setTerminateAfter(true);
189 catch (const tcu::TestException& e)
192 DE_ASSERT(e.getTestResult() != QP_TEST_RESULT_LAST);
193 m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
194 m_testCtx.setTerminateAfter(e.isFatal());
197 catch (const tcu::Exception& e)
200 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
204 DE_ASSERT(initOk || m_testCtx.getTestResult() != QP_TEST_RESULT_LAST);
209 void TestSessionExecutor::leaveTestCase (TestCase* testCase)
211 TestLog& log = m_testCtx.getLog();
216 m_caseExecutor->deinit(testCase);
218 catch (const tcu::Exception& e)
220 log << e << TestLog::Message << "Error in test case deinit, test program will terminate." << TestLog::EndMessage;
221 m_testCtx.setTerminateAfter(true);
225 const deInt64 duration = deGetMicroseconds()-m_testStartTime;
227 m_testCtx.getLog() << TestLog::Integer("TestDuration", "Test case duration in microseconds", "us", QP_KEY_TAG_TIME, duration);
231 const qpTestResult testResult = m_testCtx.getTestResult();
232 const char* const testResultDesc = m_testCtx.getTestResultDesc();
233 const bool terminateAfter = m_testCtx.getTerminateAfter();
234 DE_ASSERT(testResult != QP_TEST_RESULT_LAST);
236 m_isInTestCase = false;
237 m_testCtx.getLog().endCase(testResult, testResultDesc);
239 // Update statistics.
240 print(" %s (%s)\n", qpGetTestResultName(testResult), testResultDesc);
242 m_status.numExecuted += 1;
245 case QP_TEST_RESULT_PASS: m_status.numPassed += 1; break;
246 case QP_TEST_RESULT_NOT_SUPPORTED: m_status.numNotSupported += 1; break;
247 case QP_TEST_RESULT_QUALITY_WARNING: m_status.numWarnings += 1; break;
248 case QP_TEST_RESULT_COMPATIBILITY_WARNING: m_status.numWarnings += 1; break;
249 default: m_status.numFailed += 1; break;
252 // terminateAfter, Resource error or any error in deinit means that execution should end
253 if (terminateAfter || testResult == QP_TEST_RESULT_RESOURCE_ERROR)
254 m_abortSession = true;
257 if (m_testCtx.getWatchDog())
258 qpWatchDog_reset(m_testCtx.getWatchDog());
261 TestCase::IterateResult TestSessionExecutor::iterateTestCase (TestCase* testCase)
263 TestLog& log = m_testCtx.getLog();
264 TestCase::IterateResult iterateResult = TestCase::STOP;
266 m_testCtx.touchWatchdog();
270 iterateResult = m_caseExecutor->iterate(testCase);
272 catch (const std::bad_alloc&)
274 m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory during test execution");
275 m_testCtx.setTerminateAfter(true);
277 catch (const tcu::TestException& e)
280 m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
281 m_testCtx.setTerminateAfter(e.isFatal());
283 catch (const tcu::Exception& e)
286 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
289 return iterateResult;