1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
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 Render target info.
22 *//*--------------------------------------------------------------------*/
23
24 #include "tcuApp.hpp"
25 #include "tcuPlatform.hpp"
26 #include "tcuTestContext.hpp"
27 #include "tcuTestSessionExecutor.hpp"
28 #include "tcuTestHierarchyUtil.hpp"
29 #include "tcuCommandLine.hpp"
30 #include "tcuTestLog.hpp"
31
32 #include "qpInfo.h"
33 #include "qpDebugOut.h"
34
35 #include "deMath.h"
36
37 #include <iostream>
38
39 namespace tcu
40 {
41
42 using std::string;
43
44 /*--------------------------------------------------------------------*//*!
45 * Writes all packages found stdout without any
46 * separations. Recommended to be used with a single package
47 * only. It's possible to use test selectors for limiting the export
48 * to one package in a multipackage binary.
49 *//*--------------------------------------------------------------------*/
writeCaselistsToStdout(TestPackageRoot & root,TestContext & testCtx)50 static void writeCaselistsToStdout (TestPackageRoot& root, TestContext& testCtx)
51 {
52 DefaultHierarchyInflater inflater (testCtx);
53 de::MovePtr<const CaseListFilter> caseListFilter (testCtx.getCommandLine().createCaseListFilter(testCtx.getArchive()));
54 TestHierarchyIterator iter (root, inflater, *caseListFilter);
55
56 while (iter.getState() != TestHierarchyIterator::STATE_FINISHED)
57 {
58 iter.next();
59
60 while (iter.getNode()->getNodeType() != NODETYPE_PACKAGE)
61 {
62 if (iter.getState() == TestHierarchyIterator::STATE_ENTER_NODE)
63 std::cout << (isTestNodeTypeExecutable(iter.getNode()->getNodeType()) ? "TEST" : "GROUP") << ": " << iter.getNodePath() << "\n";
64 iter.next();
65 }
66
67 DE_ASSERT(iter.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
68 iter.getNode()->getNodeType() == NODETYPE_PACKAGE);
69 iter.next();
70 }
71 }
72
73
74 /*--------------------------------------------------------------------*//*!
75 * Verifies that amber capability requirements in the .amber files
76 * match with capabilities defined on the CTS C code.
77 *//*--------------------------------------------------------------------*/
verifyAmberCapabilityCoherency(TestPackageRoot & root,TestContext & testCtx)78 static void verifyAmberCapabilityCoherency (TestPackageRoot& root, TestContext& testCtx)
79 {
80 DefaultHierarchyInflater inflater(testCtx);
81 de::MovePtr<const CaseListFilter> caseListFilter(testCtx.getCommandLine().createCaseListFilter(testCtx.getArchive()));
82 TestHierarchyIterator iter(root, inflater, *caseListFilter);
83 int count = 0;
84 int errorCount = 0;
85
86 bool ok = true;
87
88 while (iter.getState() != TestHierarchyIterator::STATE_FINISHED)
89 {
90 iter.next();
91
92 while (iter.getNode()->getNodeType() != NODETYPE_PACKAGE)
93 {
94 if (iter.getState() == TestHierarchyIterator::STATE_ENTER_NODE &&
95 isTestNodeTypeExecutable(iter.getNode()->getNodeType()))
96 {
97 std::cout << iter.getNodePath() << "\n";
98 testCtx.getLog() << tcu::TestLog::Message << iter.getNodePath() << tcu::TestLog::EndMessage;
99 if (!iter.getNode()->validateRequirements())
100 {
101 ok = false;
102 errorCount++;
103 }
104 count++;
105 }
106 iter.next();
107 }
108
109 DE_ASSERT(iter.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
110 iter.getNode()->getNodeType() == NODETYPE_PACKAGE);
111 iter.next();
112 }
113 std::cout << count << " amber tests, " << errorCount << " errors.\n";
114 if (!ok)
115 TCU_THROW(InternalError, "One or more CTS and Amber test requirements do not match; check log for details");
116
117 }
118
119 /*--------------------------------------------------------------------*//*!
120 * \brief Construct test application
121 *
122 * If a fatal error occurs during initialization constructor will call
123 * die() with debug information.
124 *
125 * \param platform Reference to platform implementation.
126 *//*--------------------------------------------------------------------*/
App(Platform & platform,Archive & archive,TestLog & log,const CommandLine & cmdLine)127 App::App (Platform& platform, Archive& archive, TestLog& log, const CommandLine& cmdLine)
128 : m_platform (platform)
129 , m_watchDog (DE_NULL)
130 , m_crashHandler (DE_NULL)
131 , m_crashed (false)
132 , m_testCtx (DE_NULL)
133 , m_testRoot (DE_NULL)
134 , m_testExecutor (DE_NULL)
135 {
136 print("dEQP Core %s (0x%08x) starting..\n", qpGetReleaseName(), qpGetReleaseId());
137 print(" target implementation = '%s'\n", qpGetTargetName());
138
139 if (!deSetRoundingMode(DE_ROUNDINGMODE_TO_NEAREST_EVEN))
140 qpPrintf("WARNING: Failed to set floating-point rounding mode!\n");
141
142 try
143 {
144 const RunMode runMode = cmdLine.getRunMode();
145
146 // Initialize watchdog
147 if (cmdLine.isWatchDogEnabled())
148 TCU_CHECK_INTERNAL(m_watchDog = qpWatchDog_create(onWatchdogTimeout, this, WATCHDOG_TOTAL_TIME_LIMIT_SECS, WATCHDOG_INTERVAL_TIME_LIMIT_SECS));
149
150 // Initialize crash handler.
151 if (cmdLine.isCrashHandlingEnabled())
152 TCU_CHECK_INTERNAL(m_crashHandler = qpCrashHandler_create(onCrash, this));
153
154 // Create test context
155 m_testCtx = new TestContext(m_platform, archive, log, cmdLine, m_watchDog);
156
157 // Create root from registry
158 m_testRoot = new TestPackageRoot(*m_testCtx, TestPackageRegistry::getSingleton());
159
160 // \note No executor is created if runmode is not EXECUTE
161 if (runMode == RUNMODE_EXECUTE)
162 m_testExecutor = new TestSessionExecutor(*m_testRoot, *m_testCtx);
163 else if (runMode == RUNMODE_DUMP_STDOUT_CASELIST)
164 writeCaselistsToStdout(*m_testRoot, *m_testCtx);
165 else if (runMode == RUNMODE_DUMP_XML_CASELIST)
166 writeXmlCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
167 else if (runMode == RUNMODE_DUMP_TEXT_CASELIST)
168 writeTxtCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
169 else if (runMode == RUNMODE_VERIFY_AMBER_COHERENCY)
170 verifyAmberCapabilityCoherency(*m_testRoot, *m_testCtx);
171 else
172 DE_ASSERT(false);
173 }
174 catch (const std::exception& e)
175 {
176 cleanup();
177 die("Failed to initialize dEQP: %s", e.what());
178 }
179 }
180
~App(void)181 App::~App (void)
182 {
183 cleanup();
184 }
185
cleanup(void)186 void App::cleanup (void)
187 {
188 delete m_testExecutor;
189 delete m_testRoot;
190 delete m_testCtx;
191
192 if (m_crashHandler)
193 qpCrashHandler_destroy(m_crashHandler);
194
195 if (m_watchDog)
196 qpWatchDog_destroy(m_watchDog);
197 }
198
199 /*--------------------------------------------------------------------*//*!
200 * \brief Step forward test execution
201 * \return true if application should call iterate() again and false
202 * if test execution session is complete.
203 *//*--------------------------------------------------------------------*/
iterate(void)204 bool App::iterate (void)
205 {
206 if (!m_testExecutor)
207 {
208 DE_ASSERT(m_testCtx->getCommandLine().getRunMode() != RUNMODE_EXECUTE);
209 return false;
210 }
211
212 // Poll platform events
213 const bool platformOk = m_platform.processEvents();
214
215 // Iterate a step.
216 bool testExecOk = false;
217 if (platformOk)
218 {
219 try
220 {
221 testExecOk = m_testExecutor->iterate();
222 }
223 catch (const std::exception& e)
224 {
225 die("%s", e.what());
226 }
227 }
228
229 if (!platformOk || !testExecOk)
230 {
231 if (!platformOk)
232 print("\nABORTED!\n");
233 else
234 print("\nDONE!\n");
235
236 const RunMode runMode = m_testCtx->getCommandLine().getRunMode();
237 if (runMode == RUNMODE_EXECUTE)
238 {
239 const TestRunStatus& result = m_testExecutor->getStatus();
240
241 // Report statistics.
242 print("\nTest run totals:\n");
243 print(" Passed: %d/%d (%.1f%%)\n", result.numPassed, result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numPassed / (float)result.numExecuted) : 0.0f));
244 print(" Failed: %d/%d (%.1f%%)\n", result.numFailed, result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numFailed / (float)result.numExecuted) : 0.0f));
245 print(" Not supported: %d/%d (%.1f%%)\n", result.numNotSupported, result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numNotSupported / (float)result.numExecuted) : 0.0f));
246 print(" Warnings: %d/%d (%.1f%%)\n", result.numWarnings, result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numWarnings / (float)result.numExecuted) : 0.0f));
247 print(" Waived: %d/%d (%.1f%%)\n", result.numWaived, result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numWaived / (float)result.numExecuted) : 0.0f));
248 if (!result.isComplete)
249 print("Test run was ABORTED!\n");
250 }
251 }
252
253 return platformOk && testExecOk;
254 }
255
getResult(void) const256 const TestRunStatus& App::getResult (void) const
257 {
258 return m_testExecutor->getStatus();
259 }
260
onWatchdogTimeout(qpWatchDog * watchDog,void * userPtr,qpTimeoutReason reason)261 void App::onWatchdogTimeout (qpWatchDog* watchDog, void* userPtr, qpTimeoutReason reason)
262 {
263 DE_UNREF(watchDog);
264 static_cast<App*>(userPtr)->onWatchdogTimeout(reason);
265 }
266
onCrash(qpCrashHandler * crashHandler,void * userPtr)267 void App::onCrash (qpCrashHandler* crashHandler, void* userPtr)
268 {
269 DE_UNREF(crashHandler);
270 static_cast<App*>(userPtr)->onCrash();
271 }
272
onWatchdogTimeout(qpTimeoutReason reason)273 void App::onWatchdogTimeout (qpTimeoutReason reason)
274 {
275 if (!m_crashLock.tryLock() || m_crashed)
276 return; // In crash handler already.
277
278 m_crashed = true;
279
280 m_testCtx->getLog().terminateCase(QP_TEST_RESULT_TIMEOUT);
281 die("Watchdog timer timeout for %s", (reason == QP_TIMEOUT_REASON_INTERVAL_LIMIT ? "touch interval" : "total time"));
282 }
283
writeCrashToLog(void * userPtr,const char * infoString)284 static void writeCrashToLog (void* userPtr, const char* infoString)
285 {
286 // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
287 TestLog* log = static_cast<TestLog*>(userPtr);
288 log->writeMessage(infoString);
289 }
290
writeCrashToConsole(void * userPtr,const char * infoString)291 static void writeCrashToConsole (void* userPtr, const char* infoString)
292 {
293 // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
294 DE_UNREF(userPtr);
295 qpPrint(infoString);
296 }
297
onCrash(void)298 void App::onCrash (void)
299 {
300 // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
301
302 if (!m_crashLock.tryLock() || m_crashed)
303 return; // In crash handler already.
304
305 m_crashed = true;
306
307 bool isInCase = m_testExecutor ? m_testExecutor->isInTestCase() : false;
308
309 if (isInCase)
310 {
311 qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToLog, &m_testCtx->getLog());
312 m_testCtx->getLog().terminateCase(QP_TEST_RESULT_CRASH);
313 }
314 else
315 qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToConsole, DE_NULL);
316
317 die("Test program crashed");
318 }
319
320 } // tcu
321