1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Test Executor
3*35238bceSAndroid Build Coastguard Worker * ------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Test batch executor.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "xeBatchExecutor.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "xeTestResultParser.hpp"
26*35238bceSAndroid Build Coastguard Worker
27*35238bceSAndroid Build Coastguard Worker #include <sstream>
28*35238bceSAndroid Build Coastguard Worker #include <cstdio>
29*35238bceSAndroid Build Coastguard Worker
30*35238bceSAndroid Build Coastguard Worker namespace xe
31*35238bceSAndroid Build Coastguard Worker {
32*35238bceSAndroid Build Coastguard Worker
33*35238bceSAndroid Build Coastguard Worker using std::string;
34*35238bceSAndroid Build Coastguard Worker using std::vector;
35*35238bceSAndroid Build Coastguard Worker
36*35238bceSAndroid Build Coastguard Worker enum
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker TEST_LOG_TMP_BUFFER_SIZE = 1024,
39*35238bceSAndroid Build Coastguard Worker INFO_LOG_TMP_BUFFER_SIZE = 256
40*35238bceSAndroid Build Coastguard Worker };
41*35238bceSAndroid Build Coastguard Worker
42*35238bceSAndroid Build Coastguard Worker // \todo [2012-11-01 pyry] Update execute set in handler.
43*35238bceSAndroid Build Coastguard Worker
isExecutedInBatch(const BatchResult * batchResult,const TestCase * testCase)44*35238bceSAndroid Build Coastguard Worker static inline bool isExecutedInBatch(const BatchResult *batchResult, const TestCase *testCase)
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker std::string fullPath;
47*35238bceSAndroid Build Coastguard Worker testCase->getFullPath(fullPath);
48*35238bceSAndroid Build Coastguard Worker
49*35238bceSAndroid Build Coastguard Worker if (batchResult->hasTestCaseResult(fullPath.c_str()))
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker ConstTestCaseResultPtr data = batchResult->getTestCaseResult(fullPath.c_str());
52*35238bceSAndroid Build Coastguard Worker return data->getStatusCode() != TESTSTATUSCODE_PENDING && data->getStatusCode() != TESTSTATUSCODE_RUNNING;
53*35238bceSAndroid Build Coastguard Worker }
54*35238bceSAndroid Build Coastguard Worker else
55*35238bceSAndroid Build Coastguard Worker return false;
56*35238bceSAndroid Build Coastguard Worker }
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker // \todo [2012-06-19 pyry] These can be optimized using TestSetIterator (once implemented)
59*35238bceSAndroid Build Coastguard Worker
computeExecuteSet(TestSet & executeSet,const TestNode * root,const TestSet & testSet,const BatchResult * batchResult)60*35238bceSAndroid Build Coastguard Worker static void computeExecuteSet(TestSet &executeSet, const TestNode *root, const TestSet &testSet,
61*35238bceSAndroid Build Coastguard Worker const BatchResult *batchResult)
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator iter = ConstTestNodeIterator::begin(root);
64*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator end = ConstTestNodeIterator::end(root);
65*35238bceSAndroid Build Coastguard Worker
66*35238bceSAndroid Build Coastguard Worker for (; iter != end; ++iter)
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker const TestNode *node = *iter;
69*35238bceSAndroid Build Coastguard Worker
70*35238bceSAndroid Build Coastguard Worker if (node->getNodeType() == TESTNODETYPE_TEST_CASE && testSet.hasNode(node))
71*35238bceSAndroid Build Coastguard Worker {
72*35238bceSAndroid Build Coastguard Worker const TestCase *testCase = static_cast<const TestCase *>(node);
73*35238bceSAndroid Build Coastguard Worker
74*35238bceSAndroid Build Coastguard Worker if (!isExecutedInBatch(batchResult, testCase))
75*35238bceSAndroid Build Coastguard Worker executeSet.addCase(testCase);
76*35238bceSAndroid Build Coastguard Worker }
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker }
79*35238bceSAndroid Build Coastguard Worker
computeBatchRequest(TestSet & requestSet,const TestSet & executeSet,const TestNode * root,int maxCasesInSet)80*35238bceSAndroid Build Coastguard Worker static void computeBatchRequest(TestSet &requestSet, const TestSet &executeSet, const TestNode *root, int maxCasesInSet)
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator iter = ConstTestNodeIterator::begin(root);
83*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator end = ConstTestNodeIterator::end(root);
84*35238bceSAndroid Build Coastguard Worker int numCases = 0;
85*35238bceSAndroid Build Coastguard Worker
86*35238bceSAndroid Build Coastguard Worker for (; (iter != end) && (numCases < maxCasesInSet); ++iter)
87*35238bceSAndroid Build Coastguard Worker {
88*35238bceSAndroid Build Coastguard Worker const TestNode *node = *iter;
89*35238bceSAndroid Build Coastguard Worker
90*35238bceSAndroid Build Coastguard Worker if (node->getNodeType() == TESTNODETYPE_TEST_CASE && executeSet.hasNode(node))
91*35238bceSAndroid Build Coastguard Worker {
92*35238bceSAndroid Build Coastguard Worker const TestCase *testCase = static_cast<const TestCase *>(node);
93*35238bceSAndroid Build Coastguard Worker requestSet.addCase(testCase);
94*35238bceSAndroid Build Coastguard Worker numCases += 1;
95*35238bceSAndroid Build Coastguard Worker }
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker
removeExecuted(TestSet & set,const TestNode * root,const BatchResult * batchResult)99*35238bceSAndroid Build Coastguard Worker static int removeExecuted(TestSet &set, const TestNode *root, const BatchResult *batchResult)
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker TestSet oldSet(set);
102*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator iter = ConstTestNodeIterator::begin(root);
103*35238bceSAndroid Build Coastguard Worker ConstTestNodeIterator end = ConstTestNodeIterator::end(root);
104*35238bceSAndroid Build Coastguard Worker int numRemoved = 0;
105*35238bceSAndroid Build Coastguard Worker
106*35238bceSAndroid Build Coastguard Worker for (; iter != end; ++iter)
107*35238bceSAndroid Build Coastguard Worker {
108*35238bceSAndroid Build Coastguard Worker const TestNode *node = *iter;
109*35238bceSAndroid Build Coastguard Worker
110*35238bceSAndroid Build Coastguard Worker if (node->getNodeType() == TESTNODETYPE_TEST_CASE && oldSet.hasNode(node))
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker const TestCase *testCase = static_cast<const TestCase *>(node);
113*35238bceSAndroid Build Coastguard Worker
114*35238bceSAndroid Build Coastguard Worker if (isExecutedInBatch(batchResult, testCase))
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker set.removeCase(testCase);
117*35238bceSAndroid Build Coastguard Worker numRemoved += 1;
118*35238bceSAndroid Build Coastguard Worker }
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker }
121*35238bceSAndroid Build Coastguard Worker
122*35238bceSAndroid Build Coastguard Worker return numRemoved;
123*35238bceSAndroid Build Coastguard Worker }
124*35238bceSAndroid Build Coastguard Worker
BatchExecutorLogHandler(BatchResult * batchResult)125*35238bceSAndroid Build Coastguard Worker BatchExecutorLogHandler::BatchExecutorLogHandler(BatchResult *batchResult) : m_batchResult(batchResult)
126*35238bceSAndroid Build Coastguard Worker {
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker
~BatchExecutorLogHandler(void)129*35238bceSAndroid Build Coastguard Worker BatchExecutorLogHandler::~BatchExecutorLogHandler(void)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker }
132*35238bceSAndroid Build Coastguard Worker
setSessionInfo(const SessionInfo & sessionInfo)133*35238bceSAndroid Build Coastguard Worker void BatchExecutorLogHandler::setSessionInfo(const SessionInfo &sessionInfo)
134*35238bceSAndroid Build Coastguard Worker {
135*35238bceSAndroid Build Coastguard Worker m_batchResult->getSessionInfo() = sessionInfo;
136*35238bceSAndroid Build Coastguard Worker }
137*35238bceSAndroid Build Coastguard Worker
startTestCaseResult(const char * casePath)138*35238bceSAndroid Build Coastguard Worker TestCaseResultPtr BatchExecutorLogHandler::startTestCaseResult(const char *casePath)
139*35238bceSAndroid Build Coastguard Worker {
140*35238bceSAndroid Build Coastguard Worker // \todo [2012-11-01 pyry] What to do with duplicate results?
141*35238bceSAndroid Build Coastguard Worker if (m_batchResult->hasTestCaseResult(casePath))
142*35238bceSAndroid Build Coastguard Worker return m_batchResult->getTestCaseResult(casePath);
143*35238bceSAndroid Build Coastguard Worker else
144*35238bceSAndroid Build Coastguard Worker return m_batchResult->createTestCaseResult(casePath);
145*35238bceSAndroid Build Coastguard Worker }
146*35238bceSAndroid Build Coastguard Worker
testCaseResultUpdated(const TestCaseResultPtr &)147*35238bceSAndroid Build Coastguard Worker void BatchExecutorLogHandler::testCaseResultUpdated(const TestCaseResultPtr &)
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker }
150*35238bceSAndroid Build Coastguard Worker
testCaseResultComplete(const TestCaseResultPtr & result)151*35238bceSAndroid Build Coastguard Worker void BatchExecutorLogHandler::testCaseResultComplete(const TestCaseResultPtr &result)
152*35238bceSAndroid Build Coastguard Worker {
153*35238bceSAndroid Build Coastguard Worker // \todo [2012-11-01 pyry] Remove from execute set here instead of updating it between sessions.
154*35238bceSAndroid Build Coastguard Worker printf("%s\n", result->getTestCasePath());
155*35238bceSAndroid Build Coastguard Worker }
156*35238bceSAndroid Build Coastguard Worker
BatchExecutor(const TargetConfiguration & config,CommLink * commLink,const TestNode * root,const TestSet & testSet,BatchResult * batchResult,InfoLog * infoLog)157*35238bceSAndroid Build Coastguard Worker BatchExecutor::BatchExecutor(const TargetConfiguration &config, CommLink *commLink, const TestNode *root,
158*35238bceSAndroid Build Coastguard Worker const TestSet &testSet, BatchResult *batchResult, InfoLog *infoLog)
159*35238bceSAndroid Build Coastguard Worker : m_config(config)
160*35238bceSAndroid Build Coastguard Worker , m_commLink(commLink)
161*35238bceSAndroid Build Coastguard Worker , m_root(root)
162*35238bceSAndroid Build Coastguard Worker , m_testSet(testSet)
163*35238bceSAndroid Build Coastguard Worker , m_logHandler(batchResult)
164*35238bceSAndroid Build Coastguard Worker , m_batchResult(batchResult)
165*35238bceSAndroid Build Coastguard Worker , m_infoLog(infoLog)
166*35238bceSAndroid Build Coastguard Worker , m_state(STATE_NOT_STARTED)
167*35238bceSAndroid Build Coastguard Worker , m_testLogParser(&m_logHandler)
168*35238bceSAndroid Build Coastguard Worker {
169*35238bceSAndroid Build Coastguard Worker }
170*35238bceSAndroid Build Coastguard Worker
~BatchExecutor(void)171*35238bceSAndroid Build Coastguard Worker BatchExecutor::~BatchExecutor(void)
172*35238bceSAndroid Build Coastguard Worker {
173*35238bceSAndroid Build Coastguard Worker }
174*35238bceSAndroid Build Coastguard Worker
run(void)175*35238bceSAndroid Build Coastguard Worker void BatchExecutor::run(void)
176*35238bceSAndroid Build Coastguard Worker {
177*35238bceSAndroid Build Coastguard Worker XE_CHECK(m_state == STATE_NOT_STARTED);
178*35238bceSAndroid Build Coastguard Worker
179*35238bceSAndroid Build Coastguard Worker // Check commlink state.
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker CommLinkState commState = COMMLINKSTATE_LAST;
182*35238bceSAndroid Build Coastguard Worker std::string stateStr = "";
183*35238bceSAndroid Build Coastguard Worker
184*35238bceSAndroid Build Coastguard Worker commState = m_commLink->getState(stateStr);
185*35238bceSAndroid Build Coastguard Worker
186*35238bceSAndroid Build Coastguard Worker if (commState == COMMLINKSTATE_ERROR)
187*35238bceSAndroid Build Coastguard Worker {
188*35238bceSAndroid Build Coastguard Worker // Report error.
189*35238bceSAndroid Build Coastguard Worker XE_FAIL((string("CommLink error: '") + stateStr + "'").c_str());
190*35238bceSAndroid Build Coastguard Worker }
191*35238bceSAndroid Build Coastguard Worker else if (commState != COMMLINKSTATE_READY)
192*35238bceSAndroid Build Coastguard Worker XE_FAIL("CommLink is not ready");
193*35238bceSAndroid Build Coastguard Worker }
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker // Compute initial execute set.
196*35238bceSAndroid Build Coastguard Worker computeExecuteSet(m_casesToExecute, m_root, m_testSet, m_batchResult);
197*35238bceSAndroid Build Coastguard Worker
198*35238bceSAndroid Build Coastguard Worker // Register callbacks.
199*35238bceSAndroid Build Coastguard Worker m_commLink->setCallbacks(enqueueStateChanged, enqueueTestLogData, enqueueInfoLogData, this);
200*35238bceSAndroid Build Coastguard Worker
201*35238bceSAndroid Build Coastguard Worker try
202*35238bceSAndroid Build Coastguard Worker {
203*35238bceSAndroid Build Coastguard Worker if (!m_casesToExecute.empty())
204*35238bceSAndroid Build Coastguard Worker {
205*35238bceSAndroid Build Coastguard Worker TestSet batchRequest;
206*35238bceSAndroid Build Coastguard Worker computeBatchRequest(batchRequest, m_casesToExecute, m_root, m_config.maxCasesPerSession);
207*35238bceSAndroid Build Coastguard Worker launchTestSet(batchRequest);
208*35238bceSAndroid Build Coastguard Worker
209*35238bceSAndroid Build Coastguard Worker m_state = STATE_STARTED;
210*35238bceSAndroid Build Coastguard Worker }
211*35238bceSAndroid Build Coastguard Worker else
212*35238bceSAndroid Build Coastguard Worker m_state = STATE_FINISHED;
213*35238bceSAndroid Build Coastguard Worker
214*35238bceSAndroid Build Coastguard Worker // Run handler loop until we are finished.
215*35238bceSAndroid Build Coastguard Worker while (m_state != STATE_FINISHED)
216*35238bceSAndroid Build Coastguard Worker m_dispatcher.callNext();
217*35238bceSAndroid Build Coastguard Worker }
218*35238bceSAndroid Build Coastguard Worker catch (...)
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker m_commLink->setCallbacks(DE_NULL, DE_NULL, DE_NULL, DE_NULL);
221*35238bceSAndroid Build Coastguard Worker throw;
222*35238bceSAndroid Build Coastguard Worker }
223*35238bceSAndroid Build Coastguard Worker
224*35238bceSAndroid Build Coastguard Worker // De-register callbacks.
225*35238bceSAndroid Build Coastguard Worker m_commLink->setCallbacks(DE_NULL, DE_NULL, DE_NULL, DE_NULL);
226*35238bceSAndroid Build Coastguard Worker }
227*35238bceSAndroid Build Coastguard Worker
cancel(void)228*35238bceSAndroid Build Coastguard Worker void BatchExecutor::cancel(void)
229*35238bceSAndroid Build Coastguard Worker {
230*35238bceSAndroid Build Coastguard Worker m_state = STATE_FINISHED;
231*35238bceSAndroid Build Coastguard Worker m_dispatcher.cancel();
232*35238bceSAndroid Build Coastguard Worker }
233*35238bceSAndroid Build Coastguard Worker
onStateChanged(CommLinkState state,const char * message)234*35238bceSAndroid Build Coastguard Worker void BatchExecutor::onStateChanged(CommLinkState state, const char *message)
235*35238bceSAndroid Build Coastguard Worker {
236*35238bceSAndroid Build Coastguard Worker switch (state)
237*35238bceSAndroid Build Coastguard Worker {
238*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_READY:
239*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_TEST_PROCESS_LAUNCHING:
240*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_TEST_PROCESS_RUNNING:
241*35238bceSAndroid Build Coastguard Worker break; // Ignore.
242*35238bceSAndroid Build Coastguard Worker
243*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_TEST_PROCESS_FINISHED:
244*35238bceSAndroid Build Coastguard Worker {
245*35238bceSAndroid Build Coastguard Worker // Feed end of string to parser. This terminates open test case if such exists.
246*35238bceSAndroid Build Coastguard Worker {
247*35238bceSAndroid Build Coastguard Worker uint8_t eos = 0;
248*35238bceSAndroid Build Coastguard Worker onTestLogData(&eos, 1);
249*35238bceSAndroid Build Coastguard Worker }
250*35238bceSAndroid Build Coastguard Worker
251*35238bceSAndroid Build Coastguard Worker int numExecuted = removeExecuted(m_casesToExecute, m_root, m_batchResult);
252*35238bceSAndroid Build Coastguard Worker
253*35238bceSAndroid Build Coastguard Worker // \note No new batch is launched if no cases were executed in last one. Otherwise excutor
254*35238bceSAndroid Build Coastguard Worker // could end up in infinite loop.
255*35238bceSAndroid Build Coastguard Worker if (!m_casesToExecute.empty() && numExecuted > 0)
256*35238bceSAndroid Build Coastguard Worker {
257*35238bceSAndroid Build Coastguard Worker // Reset state and start batch.
258*35238bceSAndroid Build Coastguard Worker m_testLogParser.reset();
259*35238bceSAndroid Build Coastguard Worker
260*35238bceSAndroid Build Coastguard Worker m_commLink->reset();
261*35238bceSAndroid Build Coastguard Worker XE_CHECK(m_commLink->getState() == COMMLINKSTATE_READY);
262*35238bceSAndroid Build Coastguard Worker
263*35238bceSAndroid Build Coastguard Worker TestSet batchRequest;
264*35238bceSAndroid Build Coastguard Worker computeBatchRequest(batchRequest, m_casesToExecute, m_root, m_config.maxCasesPerSession);
265*35238bceSAndroid Build Coastguard Worker launchTestSet(batchRequest);
266*35238bceSAndroid Build Coastguard Worker }
267*35238bceSAndroid Build Coastguard Worker else
268*35238bceSAndroid Build Coastguard Worker m_state = STATE_FINISHED;
269*35238bceSAndroid Build Coastguard Worker
270*35238bceSAndroid Build Coastguard Worker break;
271*35238bceSAndroid Build Coastguard Worker }
272*35238bceSAndroid Build Coastguard Worker
273*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_TEST_PROCESS_LAUNCH_FAILED:
274*35238bceSAndroid Build Coastguard Worker printf("Failed to start test process: '%s'\n", message);
275*35238bceSAndroid Build Coastguard Worker m_state = STATE_FINISHED;
276*35238bceSAndroid Build Coastguard Worker break;
277*35238bceSAndroid Build Coastguard Worker
278*35238bceSAndroid Build Coastguard Worker case COMMLINKSTATE_ERROR:
279*35238bceSAndroid Build Coastguard Worker printf("CommLink error: '%s'\n", message);
280*35238bceSAndroid Build Coastguard Worker m_state = STATE_FINISHED;
281*35238bceSAndroid Build Coastguard Worker break;
282*35238bceSAndroid Build Coastguard Worker
283*35238bceSAndroid Build Coastguard Worker default:
284*35238bceSAndroid Build Coastguard Worker XE_FAIL("Unknown state");
285*35238bceSAndroid Build Coastguard Worker }
286*35238bceSAndroid Build Coastguard Worker }
287*35238bceSAndroid Build Coastguard Worker
onTestLogData(const uint8_t * bytes,size_t numBytes)288*35238bceSAndroid Build Coastguard Worker void BatchExecutor::onTestLogData(const uint8_t *bytes, size_t numBytes)
289*35238bceSAndroid Build Coastguard Worker {
290*35238bceSAndroid Build Coastguard Worker try
291*35238bceSAndroid Build Coastguard Worker {
292*35238bceSAndroid Build Coastguard Worker m_testLogParser.parse(bytes, numBytes);
293*35238bceSAndroid Build Coastguard Worker }
294*35238bceSAndroid Build Coastguard Worker catch (const ParseError &e)
295*35238bceSAndroid Build Coastguard Worker {
296*35238bceSAndroid Build Coastguard Worker // \todo [2012-07-06 pyry] Log error.
297*35238bceSAndroid Build Coastguard Worker DE_UNREF(e);
298*35238bceSAndroid Build Coastguard Worker }
299*35238bceSAndroid Build Coastguard Worker }
300*35238bceSAndroid Build Coastguard Worker
onInfoLogData(const uint8_t * bytes,size_t numBytes)301*35238bceSAndroid Build Coastguard Worker void BatchExecutor::onInfoLogData(const uint8_t *bytes, size_t numBytes)
302*35238bceSAndroid Build Coastguard Worker {
303*35238bceSAndroid Build Coastguard Worker if (numBytes > 0 && m_infoLog)
304*35238bceSAndroid Build Coastguard Worker m_infoLog->append(bytes, numBytes);
305*35238bceSAndroid Build Coastguard Worker }
306*35238bceSAndroid Build Coastguard Worker
writeCaseListNode(std::ostream & str,const TestNode * node,const TestSet & testSet)307*35238bceSAndroid Build Coastguard Worker static void writeCaseListNode(std::ostream &str, const TestNode *node, const TestSet &testSet)
308*35238bceSAndroid Build Coastguard Worker {
309*35238bceSAndroid Build Coastguard Worker DE_ASSERT(testSet.hasNode(node));
310*35238bceSAndroid Build Coastguard Worker
311*35238bceSAndroid Build Coastguard Worker TestNodeType nodeType = node->getNodeType();
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker if (nodeType != TESTNODETYPE_ROOT)
314*35238bceSAndroid Build Coastguard Worker str << node->getName();
315*35238bceSAndroid Build Coastguard Worker
316*35238bceSAndroid Build Coastguard Worker if (nodeType == TESTNODETYPE_ROOT || nodeType == TESTNODETYPE_GROUP)
317*35238bceSAndroid Build Coastguard Worker {
318*35238bceSAndroid Build Coastguard Worker const TestGroup *group = static_cast<const TestGroup *>(node);
319*35238bceSAndroid Build Coastguard Worker bool isFirst = true;
320*35238bceSAndroid Build Coastguard Worker
321*35238bceSAndroid Build Coastguard Worker str << "{";
322*35238bceSAndroid Build Coastguard Worker
323*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < group->getNumChildren(); ndx++)
324*35238bceSAndroid Build Coastguard Worker {
325*35238bceSAndroid Build Coastguard Worker const TestNode *child = group->getChild(ndx);
326*35238bceSAndroid Build Coastguard Worker
327*35238bceSAndroid Build Coastguard Worker if (testSet.hasNode(child))
328*35238bceSAndroid Build Coastguard Worker {
329*35238bceSAndroid Build Coastguard Worker if (!isFirst)
330*35238bceSAndroid Build Coastguard Worker str << ",";
331*35238bceSAndroid Build Coastguard Worker
332*35238bceSAndroid Build Coastguard Worker writeCaseListNode(str, child, testSet);
333*35238bceSAndroid Build Coastguard Worker isFirst = false;
334*35238bceSAndroid Build Coastguard Worker }
335*35238bceSAndroid Build Coastguard Worker }
336*35238bceSAndroid Build Coastguard Worker
337*35238bceSAndroid Build Coastguard Worker str << "}";
338*35238bceSAndroid Build Coastguard Worker }
339*35238bceSAndroid Build Coastguard Worker }
340*35238bceSAndroid Build Coastguard Worker
launchTestSet(const TestSet & testSet)341*35238bceSAndroid Build Coastguard Worker void BatchExecutor::launchTestSet(const TestSet &testSet)
342*35238bceSAndroid Build Coastguard Worker {
343*35238bceSAndroid Build Coastguard Worker std::ostringstream caseList;
344*35238bceSAndroid Build Coastguard Worker XE_CHECK(testSet.hasNode(m_root));
345*35238bceSAndroid Build Coastguard Worker XE_CHECK(m_root->getNodeType() == TESTNODETYPE_ROOT);
346*35238bceSAndroid Build Coastguard Worker writeCaseListNode(caseList, m_root, testSet);
347*35238bceSAndroid Build Coastguard Worker
348*35238bceSAndroid Build Coastguard Worker m_commLink->startTestProcess(m_config.binaryName.c_str(), m_config.cmdLineArgs.c_str(), m_config.workingDir.c_str(),
349*35238bceSAndroid Build Coastguard Worker caseList.str().c_str());
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker
enqueueStateChanged(void * userPtr,CommLinkState state,const char * message)352*35238bceSAndroid Build Coastguard Worker void BatchExecutor::enqueueStateChanged(void *userPtr, CommLinkState state, const char *message)
353*35238bceSAndroid Build Coastguard Worker {
354*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = static_cast<BatchExecutor *>(userPtr);
355*35238bceSAndroid Build Coastguard Worker CallWriter writer(&executor->m_dispatcher, BatchExecutor::dispatchStateChanged);
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker writer << executor << state << message;
358*35238bceSAndroid Build Coastguard Worker
359*35238bceSAndroid Build Coastguard Worker writer.enqueue();
360*35238bceSAndroid Build Coastguard Worker }
361*35238bceSAndroid Build Coastguard Worker
enqueueTestLogData(void * userPtr,const uint8_t * bytes,size_t numBytes)362*35238bceSAndroid Build Coastguard Worker void BatchExecutor::enqueueTestLogData(void *userPtr, const uint8_t *bytes, size_t numBytes)
363*35238bceSAndroid Build Coastguard Worker {
364*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = static_cast<BatchExecutor *>(userPtr);
365*35238bceSAndroid Build Coastguard Worker CallWriter writer(&executor->m_dispatcher, BatchExecutor::dispatchTestLogData);
366*35238bceSAndroid Build Coastguard Worker
367*35238bceSAndroid Build Coastguard Worker writer << executor << numBytes;
368*35238bceSAndroid Build Coastguard Worker
369*35238bceSAndroid Build Coastguard Worker writer.write(bytes, numBytes);
370*35238bceSAndroid Build Coastguard Worker writer.enqueue();
371*35238bceSAndroid Build Coastguard Worker }
372*35238bceSAndroid Build Coastguard Worker
enqueueInfoLogData(void * userPtr,const uint8_t * bytes,size_t numBytes)373*35238bceSAndroid Build Coastguard Worker void BatchExecutor::enqueueInfoLogData(void *userPtr, const uint8_t *bytes, size_t numBytes)
374*35238bceSAndroid Build Coastguard Worker {
375*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = static_cast<BatchExecutor *>(userPtr);
376*35238bceSAndroid Build Coastguard Worker CallWriter writer(&executor->m_dispatcher, BatchExecutor::dispatchInfoLogData);
377*35238bceSAndroid Build Coastguard Worker
378*35238bceSAndroid Build Coastguard Worker writer << executor << numBytes;
379*35238bceSAndroid Build Coastguard Worker
380*35238bceSAndroid Build Coastguard Worker writer.write(bytes, numBytes);
381*35238bceSAndroid Build Coastguard Worker writer.enqueue();
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker
dispatchStateChanged(CallReader & data)384*35238bceSAndroid Build Coastguard Worker void BatchExecutor::dispatchStateChanged(CallReader &data)
385*35238bceSAndroid Build Coastguard Worker {
386*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = DE_NULL;
387*35238bceSAndroid Build Coastguard Worker CommLinkState state = COMMLINKSTATE_LAST;
388*35238bceSAndroid Build Coastguard Worker std::string message;
389*35238bceSAndroid Build Coastguard Worker
390*35238bceSAndroid Build Coastguard Worker data >> executor >> state >> message;
391*35238bceSAndroid Build Coastguard Worker
392*35238bceSAndroid Build Coastguard Worker executor->onStateChanged(state, message.c_str());
393*35238bceSAndroid Build Coastguard Worker }
394*35238bceSAndroid Build Coastguard Worker
dispatchTestLogData(CallReader & data)395*35238bceSAndroid Build Coastguard Worker void BatchExecutor::dispatchTestLogData(CallReader &data)
396*35238bceSAndroid Build Coastguard Worker {
397*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = DE_NULL;
398*35238bceSAndroid Build Coastguard Worker size_t numBytes;
399*35238bceSAndroid Build Coastguard Worker
400*35238bceSAndroid Build Coastguard Worker data >> executor >> numBytes;
401*35238bceSAndroid Build Coastguard Worker
402*35238bceSAndroid Build Coastguard Worker executor->onTestLogData(data.getDataBlock(numBytes), numBytes);
403*35238bceSAndroid Build Coastguard Worker }
404*35238bceSAndroid Build Coastguard Worker
dispatchInfoLogData(CallReader & data)405*35238bceSAndroid Build Coastguard Worker void BatchExecutor::dispatchInfoLogData(CallReader &data)
406*35238bceSAndroid Build Coastguard Worker {
407*35238bceSAndroid Build Coastguard Worker BatchExecutor *executor = DE_NULL;
408*35238bceSAndroid Build Coastguard Worker size_t numBytes;
409*35238bceSAndroid Build Coastguard Worker
410*35238bceSAndroid Build Coastguard Worker data >> executor >> numBytes;
411*35238bceSAndroid Build Coastguard Worker
412*35238bceSAndroid Build Coastguard Worker executor->onInfoLogData(data.getDataBlock(numBytes), numBytes);
413*35238bceSAndroid Build Coastguard Worker }
414*35238bceSAndroid Build Coastguard Worker
415*35238bceSAndroid Build Coastguard Worker } // namespace xe
416