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;
107 // \todo [2012-06-09 pyry] What to do with unknown/duplicate attributes? Currently just ignored.
111 case CONTAINERELEMENT_BEGIN_TEST_CASE_RESULT:
114 throw Error("Unexpected #beginTestCaseResult");
116 const char* casePath = m_containerParser.getTestCasePath();
117 m_currentCaseData = m_handler->startTestCaseResult(casePath);
119 // Clear and set to running state.
120 m_currentCaseData->setDataSize(0);
121 m_currentCaseData->setTestResult(TESTSTATUSCODE_RUNNING, "Running");
123 m_handler->testCaseResultUpdated(m_currentCaseData);
127 case CONTAINERELEMENT_END_TEST_CASE_RESULT:
128 if (m_currentCaseData)
130 // \todo [2012-06-16 pyry] Parse status code already here?
131 m_currentCaseData->setTestResult(TESTSTATUSCODE_LAST, "");
132 m_handler->testCaseResultComplete(m_currentCaseData);
134 m_currentCaseData.clear();
137 case CONTAINERELEMENT_TERMINATE_TEST_CASE_RESULT:
138 if (m_currentCaseData)
140 TestStatusCode statusCode = TESTSTATUSCODE_CRASH;
141 const char* reason = m_containerParser.getTerminateReason();
144 statusCode = getTestStatusCode(reason);
146 catch (const xe::ParseError&)
148 // Could not map status code.
150 m_currentCaseData->setTestResult(statusCode, reason);
151 m_handler->testCaseResultComplete(m_currentCaseData);
153 m_currentCaseData.clear();
156 case CONTAINERELEMENT_END_OF_STRING:
157 if (m_currentCaseData)
159 // Terminate current case.
160 m_currentCaseData->setTestResult(TESTSTATUSCODE_TERMINATED, "Unexpected end of string");
161 m_handler->testCaseResultComplete(m_currentCaseData);
163 m_currentCaseData.clear();
166 case CONTAINERELEMENT_TEST_LOG_DATA:
167 if (m_currentCaseData)
169 int offset = m_currentCaseData->getDataSize();
170 int numDataBytes = m_containerParser.getDataSize();
172 m_currentCaseData->setDataSize(offset+numDataBytes);
173 m_containerParser.getData(m_currentCaseData->getData()+offset, numDataBytes, 0);
175 m_handler->testCaseResultUpdated(m_currentCaseData);
180 throw ContainerParseError("Unknown container element");
183 m_containerParser.advance();