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 "tcuCommandLine.hpp"
26 #include "tcuTestLog.hpp"
35 static qpTestCaseType nodeTypeToTestCaseType (TestNodeType nodeType)
39 case NODETYPE_SELF_VALIDATE: return QP_TEST_CASE_TYPE_SELF_VALIDATE;
40 case NODETYPE_PERFORMANCE: return QP_TEST_CASE_TYPE_PERFORMANCE;
41 case NODETYPE_CAPABILITY: return QP_TEST_CASE_TYPE_CAPABILITY;
42 case NODETYPE_ACCURACY: return QP_TEST_CASE_TYPE_ACCURACY;
45 return QP_TEST_CASE_TYPE_LAST;
49 TestSessionExecutor::TestSessionExecutor (TestPackageRoot& root, TestContext& testCtx)
51 , m_inflater (testCtx)
52 , m_caseListFilter (testCtx.getCommandLine().createCaseListFilter(testCtx.getArchive()))
53 , m_iterator (root, m_inflater, *m_caseListFilter)
54 , m_state (STATE_TRAVERSE_HIERARCHY)
55 , m_abortSession (false)
56 , m_isInTestCase (false)
61 TestSessionExecutor::~TestSessionExecutor (void)
65 bool TestSessionExecutor::iterate (void)
67 while (!m_abortSession)
71 case STATE_TRAVERSE_HIERARCHY:
73 const TestHierarchyIterator::State hierIterState = m_iterator.getState();
75 if (hierIterState == TestHierarchyIterator::STATE_ENTER_NODE ||
76 hierIterState == TestHierarchyIterator::STATE_LEAVE_NODE)
78 TestNode* const curNode = m_iterator.getNode();
79 const TestNodeType nodeType = curNode->getNodeType();
80 const bool isEnter = hierIterState == TestHierarchyIterator::STATE_ENTER_NODE;
84 case NODETYPE_PACKAGE:
86 TestPackage* const testPackage = static_cast<TestPackage*>(curNode);
87 isEnter ? enterTestPackage(testPackage) : leaveTestPackage(testPackage);
94 case NODETYPE_SELF_VALIDATE:
95 case NODETYPE_PERFORMANCE:
96 case NODETYPE_CAPABILITY:
97 case NODETYPE_ACCURACY:
99 TestCase* const testCase = static_cast<TestCase*>(curNode);
103 if (enterTestCase(testCase, m_iterator.getNodePath()))
104 m_state = STATE_EXECUTE_TEST_CASE;
105 // else remain in TRAVERSING_HIERARCHY => node will be exited from in the next iteration
108 leaveTestCase(testCase);
123 DE_ASSERT(hierIterState == TestHierarchyIterator::STATE_FINISHED);
124 m_status.isComplete = true;
129 case STATE_EXECUTE_TEST_CASE:
131 DE_ASSERT(m_iterator.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
132 isTestNodeTypeExecutable(m_iterator.getNode()->getNodeType()));
134 TestCase* const testCase = static_cast<TestCase*>(m_iterator.getNode());
135 const TestCase::IterateResult iterResult = iterateTestCase(testCase);
137 if (iterResult == TestCase::STOP)
138 m_state = STATE_TRAVERSE_HIERARCHY;
152 void TestSessionExecutor::enterTestPackage (TestPackage* testPackage)
154 // Create test case wrapper
155 DE_ASSERT(!m_caseExecutor);
156 m_caseExecutor = de::MovePtr<TestCaseExecutor>(testPackage->createExecutor());
159 void TestSessionExecutor::leaveTestPackage (TestPackage* testPackage)
161 DE_UNREF(testPackage);
162 m_caseExecutor.clear();
165 bool TestSessionExecutor::enterTestCase (TestCase* testCase, const std::string& casePath)
167 TestLog& log = m_testCtx.getLog();
168 const qpTestCaseType caseType = nodeTypeToTestCaseType(testCase->getNodeType());
171 print("\nTest case '%s'..\n", casePath.c_str());
173 m_testCtx.setTestResult(QP_TEST_RESULT_LAST, "");
174 m_testCtx.setTerminateAfter(false);
175 log.startCase(casePath.c_str(), caseType);
177 m_isInTestCase = true;
178 m_testStartTime = deGetMicroseconds();
182 m_caseExecutor->init(testCase, casePath);
185 catch (const std::bad_alloc&)
188 m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory in test case init");
189 m_testCtx.setTerminateAfter(true);
191 catch (const tcu::TestException& e)
194 DE_ASSERT(e.getTestResult() != QP_TEST_RESULT_LAST);
195 m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
196 m_testCtx.setTerminateAfter(e.isFatal());
199 catch (const tcu::Exception& e)
202 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
206 DE_ASSERT(initOk || m_testCtx.getTestResult() != QP_TEST_RESULT_LAST);
211 void TestSessionExecutor::leaveTestCase (TestCase* testCase)
213 TestLog& log = m_testCtx.getLog();
218 m_caseExecutor->deinit(testCase);
220 catch (const tcu::Exception& e)
222 log << e << TestLog::Message << "Error in test case deinit, test program will terminate." << TestLog::EndMessage;
223 m_testCtx.setTerminateAfter(true);
227 const deInt64 duration = deGetMicroseconds()-m_testStartTime;
229 m_testCtx.getLog() << TestLog::Integer("TestDuration", "Test case duration in microseconds", "us", QP_KEY_TAG_TIME, duration);
233 const qpTestResult testResult = m_testCtx.getTestResult();
234 const char* const testResultDesc = m_testCtx.getTestResultDesc();
235 const bool terminateAfter = m_testCtx.getTerminateAfter();
236 DE_ASSERT(testResult != QP_TEST_RESULT_LAST);
238 m_isInTestCase = false;
239 m_testCtx.getLog().endCase(testResult, testResultDesc);
241 // Update statistics.
242 print(" %s (%s)\n", qpGetTestResultName(testResult), testResultDesc);
244 m_status.numExecuted += 1;
247 case QP_TEST_RESULT_PASS: m_status.numPassed += 1; break;
248 case QP_TEST_RESULT_NOT_SUPPORTED: m_status.numNotSupported += 1; break;
249 case QP_TEST_RESULT_QUALITY_WARNING: m_status.numWarnings += 1; break;
250 case QP_TEST_RESULT_COMPATIBILITY_WARNING: m_status.numWarnings += 1; break;
251 default: m_status.numFailed += 1; break;
254 // terminateAfter, Resource error or any error in deinit means that execution should end
255 if (terminateAfter || testResult == QP_TEST_RESULT_RESOURCE_ERROR)
256 m_abortSession = true;
259 if (m_testCtx.getWatchDog())
260 qpWatchDog_reset(m_testCtx.getWatchDog());
263 TestCase::IterateResult TestSessionExecutor::iterateTestCase (TestCase* testCase)
265 TestLog& log = m_testCtx.getLog();
266 TestCase::IterateResult iterateResult = TestCase::STOP;
268 m_testCtx.touchWatchdog();
272 iterateResult = m_caseExecutor->iterate(testCase);
274 catch (const std::bad_alloc&)
276 m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory during test execution");
277 m_testCtx.setTerminateAfter(true);
279 catch (const tcu::TestException& e)
282 m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
283 m_testCtx.setTerminateAfter(e.isFatal());
285 catch (const tcu::Exception& e)
288 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
291 return iterateResult;