1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Test Executor
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 log parser.
22 *//*--------------------------------------------------------------------*/
24 #include "xeTestLogParser.hpp"
34 TestLogParser::TestLogParser (TestLogHandler* handler)
40 TestLogParser::~TestLogParser (void)
44 void TestLogParser::reset (void)
46 m_containerParser.clear();
47 m_currentCaseData.clear();
48 m_sessionInfo = SessionInfo();
52 void TestLogParser::parse (const deUint8* bytes, size_t numBytes)
54 m_containerParser.feed(bytes, numBytes);
58 ContainerElement element = m_containerParser.getElement();
60 if (element == CONTAINERELEMENT_INCOMPLETE)
65 case CONTAINERELEMENT_BEGIN_SESSION:
68 throw Error("Unexpected #beginSession");
70 m_handler->setSessionInfo(m_sessionInfo);
75 case CONTAINERELEMENT_END_SESSION:
78 throw Error("Unexpected #endSession");
84 case CONTAINERELEMENT_SESSION_INFO:
87 throw Error("Unexpected #sessionInfo");
89 const char* attribute = m_containerParser.getSessionInfoAttribute();
90 const char* value = m_containerParser.getSessionInfoValue();
92 if (deStringEqual(attribute, "releaseName"))
93 m_sessionInfo.releaseName = value;
94 else if (deStringEqual(attribute, "releaseId"))
95 m_sessionInfo.releaseId = value;
96 else if (deStringEqual(attribute, "targetName"))
97 m_sessionInfo.targetName = value;
98 else if (deStringEqual(attribute, "candyTargetName"))
99 m_sessionInfo.candyTargetName = value;
100 else if (deStringEqual(attribute, "configName"))
101 m_sessionInfo.configName = value;
102 else if (deStringEqual(attribute, "resultName"))
103 m_sessionInfo.resultName = value;
104 else if (deStringEqual(attribute, "timestamp"))
105 m_sessionInfo.timestamp = value;
106 else if (deStringEqual(attribute, "commandLineParameters"))
107 m_sessionInfo.qpaCommandLineParameters = value;
109 // \todo [2012-06-09 pyry] What to do with unknown/duplicate attributes? Currently just ignored.
113 case CONTAINERELEMENT_BEGIN_TEST_CASE_RESULT:
116 throw Error("Unexpected #beginTestCaseResult");
118 const char* casePath = m_containerParser.getTestCasePath();
119 m_currentCaseData = m_handler->startTestCaseResult(casePath);
121 // Clear and set to running state.
122 m_currentCaseData->setDataSize(0);
123 m_currentCaseData->setTestResult(TESTSTATUSCODE_RUNNING, "Running");
125 m_handler->testCaseResultUpdated(m_currentCaseData);
129 case CONTAINERELEMENT_END_TEST_CASE_RESULT:
130 if (m_currentCaseData)
132 // \todo [2012-06-16 pyry] Parse status code already here?
133 m_currentCaseData->setTestResult(TESTSTATUSCODE_LAST, "");
134 m_handler->testCaseResultComplete(m_currentCaseData);
136 m_currentCaseData.clear();
139 case CONTAINERELEMENT_TERMINATE_TEST_CASE_RESULT:
140 if (m_currentCaseData)
142 TestStatusCode statusCode = TESTSTATUSCODE_CRASH;
143 const char* reason = m_containerParser.getTerminateReason();
146 statusCode = getTestStatusCode(reason);
148 catch (const xe::ParseError&)
150 // Could not map status code.
152 m_currentCaseData->setTestResult(statusCode, reason);
153 m_handler->testCaseResultComplete(m_currentCaseData);
155 m_currentCaseData.clear();
158 case CONTAINERELEMENT_END_OF_STRING:
159 if (m_currentCaseData)
161 // Terminate current case.
162 m_currentCaseData->setTestResult(TESTSTATUSCODE_TERMINATED, "Unexpected end of string");
163 m_handler->testCaseResultComplete(m_currentCaseData);
165 m_currentCaseData.clear();
168 case CONTAINERELEMENT_TEST_LOG_DATA:
169 if (m_currentCaseData)
171 int offset = m_currentCaseData->getDataSize();
172 int numDataBytes = m_containerParser.getDataSize();
174 m_currentCaseData->setDataSize(offset+numDataBytes);
175 m_containerParser.getData(m_currentCaseData->getData()+offset, numDataBytes, 0);
177 m_handler->testCaseResultUpdated(m_currentCaseData);
182 throw ContainerParseError("Unknown container element");
185 m_containerParser.advance();