lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*-------------------------------------------------------------------------
 * drawElements Quality Program Tester Core
 * ----------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Render target info.
 *//*--------------------------------------------------------------------*/
 
#include "tcuApp.hpp"
#include "tcuPlatform.hpp"
#include "tcuTestContext.hpp"
#include "tcuTestSessionExecutor.hpp"
#include "tcuTestHierarchyUtil.hpp"
#include "tcuCommandLine.hpp"
#include "tcuTestLog.hpp"
 
#include "qpInfo.h"
#include "qpDebugOut.h"
 
#include "deMath.h"
 
#include <iostream>
 
namespace tcu
{
 
using std::string;
 
/*--------------------------------------------------------------------*//*!
 *  Writes all packages found stdout without any
 *  separations. Recommended to be used with a single package
 *  only. It's possible to use test selectors for limiting the export
 *  to one package in a multipackage binary.
 *//*--------------------------------------------------------------------*/
static void writeCaselistsToStdout (TestPackageRoot& root, TestContext& testCtx)
{
   DefaultHierarchyInflater            inflater        (testCtx);
   de::MovePtr<const CaseListFilter>    caseListFilter    (testCtx.getCommandLine().createCaseListFilter(testCtx.getArchive()));
   TestHierarchyIterator                iter            (root, inflater, *caseListFilter);
 
   while (iter.getState() != TestHierarchyIterator::STATE_FINISHED)
   {
       iter.next();
 
       while (iter.getNode()->getNodeType() != NODETYPE_PACKAGE)
       {
           if (iter.getState() == TestHierarchyIterator::STATE_ENTER_NODE)
               std::cout << (isTestNodeTypeExecutable(iter.getNode()->getNodeType()) ? "TEST" : "GROUP") << ": " << iter.getNodePath() << "\n";
           iter.next();
       }
 
       DE_ASSERT(iter.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
                 iter.getNode()->getNodeType() == NODETYPE_PACKAGE);
       iter.next();
   }
}
 
/*--------------------------------------------------------------------*//*!
 * \brief Construct test application
 *
 * If a fatal error occurs during initialization constructor will call
 * die() with debug information.
 *
 * \param platform Reference to platform implementation.
 *//*--------------------------------------------------------------------*/
App::App (Platform& platform, Archive& archive, TestLog& log, const CommandLine& cmdLine)
   : m_platform        (platform)
   , m_watchDog        (DE_NULL)
   , m_crashHandler    (DE_NULL)
   , m_crashed            (false)
   , m_testCtx            (DE_NULL)
   , m_testRoot        (DE_NULL)
   , m_testExecutor    (DE_NULL)
{
   print("dEQP Core %s (0x%08x) starting..\n", qpGetReleaseName(), qpGetReleaseId());
   print("  target implementation = '%s'\n", qpGetTargetName());
 
   if (!deSetRoundingMode(DE_ROUNDINGMODE_TO_NEAREST_EVEN))
       qpPrintf("WARNING: Failed to set floating-point rounding mode!\n");
 
   try
   {
       const RunMode    runMode    = cmdLine.getRunMode();
 
       // Initialize watchdog
       if (cmdLine.isWatchDogEnabled())
           TCU_CHECK_INTERNAL(m_watchDog = qpWatchDog_create(onWatchdogTimeout, this, WATCHDOG_TOTAL_TIME_LIMIT_SECS, WATCHDOG_INTERVAL_TIME_LIMIT_SECS));
 
       // Initialize crash handler.
       if (cmdLine.isCrashHandlingEnabled())
           TCU_CHECK_INTERNAL(m_crashHandler = qpCrashHandler_create(onCrash, this));
 
       // Create test context
       m_testCtx = new TestContext(m_platform, archive, log, cmdLine, m_watchDog);
 
       // Create root from registry
       m_testRoot = new TestPackageRoot(*m_testCtx, TestPackageRegistry::getSingleton());
 
       // \note No executor is created if runmode is not EXECUTE
       if (runMode == RUNMODE_EXECUTE)
           m_testExecutor = new TestSessionExecutor(*m_testRoot, *m_testCtx);
       else if (runMode == RUNMODE_DUMP_STDOUT_CASELIST)
           writeCaselistsToStdout(*m_testRoot, *m_testCtx);
       else if (runMode == RUNMODE_DUMP_XML_CASELIST)
           writeXmlCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
       else if (runMode == RUNMODE_DUMP_TEXT_CASELIST)
           writeTxtCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
       else
           DE_ASSERT(false);
   }
   catch (const std::exception& e)
   {
       cleanup();
       die("Failed to initialize dEQP: %s", e.what());
   }
}
 
App::~App (void)
{
   cleanup();
}
 
void App::cleanup (void)
{
   delete m_testExecutor;
   delete m_testRoot;
   delete m_testCtx;
 
   if (m_crashHandler)
       qpCrashHandler_destroy(m_crashHandler);
 
   if (m_watchDog)
       qpWatchDog_destroy(m_watchDog);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief Step forward test execution
 * \return true if application should call iterate() again and false
 *         if test execution session is complete.
 *//*--------------------------------------------------------------------*/
bool App::iterate (void)
{
   if (!m_testExecutor)
   {
       DE_ASSERT(m_testCtx->getCommandLine().getRunMode() != RUNMODE_EXECUTE);
       return false;
   }
 
   // Poll platform events
   const bool platformOk = m_platform.processEvents();
 
   // Iterate a step.
   bool testExecOk = false;
   if (platformOk)
   {
       try
       {
           testExecOk = m_testExecutor->iterate();
       }
       catch (const std::exception& e)
       {
           die("%s", e.what());
       }
   }
 
   if (!platformOk || !testExecOk)
   {
       if (!platformOk)
           print("\nABORTED!\n");
       else
           print("\nDONE!\n");
 
       const RunMode runMode = m_testCtx->getCommandLine().getRunMode();
       if (runMode == RUNMODE_EXECUTE)
       {
           const TestRunStatus& result = m_testExecutor->getStatus();
 
           // Report statistics.
           print("\nTest run totals:\n");
           print("  Passed:        %d/%d (%.1f%%)\n", result.numPassed,        result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numPassed            / (float)result.numExecuted) : 0.0f));
           print("  Failed:        %d/%d (%.1f%%)\n", result.numFailed,        result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numFailed            / (float)result.numExecuted) : 0.0f));
           print("  Not supported: %d/%d (%.1f%%)\n", result.numNotSupported,    result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numNotSupported    / (float)result.numExecuted) : 0.0f));
           print("  Warnings:      %d/%d (%.1f%%)\n", result.numWarnings,        result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numWarnings        / (float)result.numExecuted) : 0.0f));
           if (!result.isComplete)
               print("Test run was ABORTED!\n");
       }
   }
 
   return platformOk && testExecOk;
}
 
const TestRunStatus& App::getResult (void) const
{
   return m_testExecutor->getStatus();
}
 
void App::onWatchdogTimeout (qpWatchDog* watchDog, void* userPtr, qpTimeoutReason reason)
{
   DE_UNREF(watchDog);
   static_cast<App*>(userPtr)->onWatchdogTimeout(reason);
}
 
void App::onCrash (qpCrashHandler* crashHandler, void* userPtr)
{
   DE_UNREF(crashHandler);
   static_cast<App*>(userPtr)->onCrash();
}
 
void App::onWatchdogTimeout (qpTimeoutReason reason)
{
   if (!m_crashLock.tryLock() || m_crashed)
       return; // In crash handler already.
 
   m_crashed = true;
 
   m_testCtx->getLog().terminateCase(QP_TEST_RESULT_TIMEOUT);
   die("Watchdog timer timeout for %s", (reason == QP_TIMEOUT_REASON_INTERVAL_LIMIT ? "touch interval" : "total time"));
}
 
static void writeCrashToLog (void* userPtr, const char* infoString)
{
   // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
   TestLog* log = static_cast<TestLog*>(userPtr);
   log->writeMessage(infoString);
}
 
static void writeCrashToConsole (void* userPtr, const char* infoString)
{
   // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
   DE_UNREF(userPtr);
   qpPrint(infoString);
}
 
void App::onCrash (void)
{
   // \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
 
   if (!m_crashLock.tryLock() || m_crashed)
       return; // In crash handler already.
 
   m_crashed = true;
 
   bool isInCase = m_testExecutor ? m_testExecutor->isInTestCase() : false;
 
   if (isInCase)
   {
       qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToLog, &m_testCtx->getLog());
       m_testCtx->getLog().terminateCase(QP_TEST_RESULT_CRASH);
   }
   else
       qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToConsole, DE_NULL);
 
   die("Test program crashed");
}
 
} // tcu