13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Test Executor
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test log parser.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeTestLogParser.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map;
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace xe
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogParser::TestLogParser (TestLogHandler* handler)
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_handler		(handler)
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_inSession	(false)
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogParser::~TestLogParser (void)
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogParser::reset (void)
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_containerParser.clear();
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_currentCaseData.clear();
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_sessionInfo	= SessionInfo();
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inSession		= false;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
521592f16d1fc9edde443474e1835746f705ed79a9Jarkko Pöyryvoid TestLogParser::parse (const deUint8* bytes, size_t numBytes)
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_containerParser.feed(bytes, numBytes);
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (;;)
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ContainerElement element = m_containerParser.getElement();
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (element == CONTAINERELEMENT_INCOMPLETE)
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (element)
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_BEGIN_SESSION:
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_inSession)
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					throw Error("Unexpected #beginSession");
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_handler->setSessionInfo(m_sessionInfo);
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_inSession = true;
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_END_SESSION:
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (!m_inSession)
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					throw Error("Unexpected #endSession");
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_inSession = false;
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_SESSION_INFO:
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_inSession)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					throw Error("Unexpected #sessionInfo");
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		attribute	= m_containerParser.getSessionInfoAttribute();
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		value		= m_containerParser.getSessionInfoValue();
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (deStringEqual(attribute, "releaseName"))
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.releaseName = value;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "releaseId"))
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.releaseId = value;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "targetName"))
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.targetName = value;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "candyTargetName"))
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.candyTargetName = value;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "configName"))
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.configName = value;
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "resultName"))
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.resultName = value;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (deStringEqual(attribute, "timestamp"))
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_sessionInfo.timestamp = value;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// \todo [2012-06-09 pyry] What to do with unknown/duplicate attributes? Currently just ignored.
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_BEGIN_TEST_CASE_RESULT:
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (!m_inSession)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					throw Error("Unexpected #beginTestCaseResult");
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char* casePath = m_containerParser.getTestCasePath();
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData = m_handler->startTestCaseResult(casePath);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Clear and set to running state.
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData->setDataSize(0);
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData->setTestResult(TESTSTATUSCODE_RUNNING, "Running");
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_handler->testCaseResultUpdated(m_currentCaseData);
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_END_TEST_CASE_RESULT:
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_currentCaseData)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// \todo [2012-06-16 pyry] Parse status code already here?
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_currentCaseData->setTestResult(TESTSTATUSCODE_LAST, "");
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_handler->testCaseResultComplete(m_currentCaseData);
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData.clear();
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_TERMINATE_TEST_CASE_RESULT:
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_currentCaseData)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TestStatusCode	statusCode	= TESTSTATUSCODE_CRASH;
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		reason		= m_containerParser.getTerminateReason();
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					try
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						statusCode = getTestStatusCode(reason);
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					catch (const xe::ParseError&)
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						// Could not map status code.
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_currentCaseData->setTestResult(statusCode, reason);
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_handler->testCaseResultComplete(m_currentCaseData);
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData.clear();
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_END_OF_STRING:
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_currentCaseData)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// Terminate current case.
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_currentCaseData->setTestResult(TESTSTATUSCODE_TERMINATED, "Unexpected end of string");
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_handler->testCaseResultComplete(m_currentCaseData);
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_currentCaseData.clear();
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CONTAINERELEMENT_TEST_LOG_DATA:
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_currentCaseData)
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					int offset			= m_currentCaseData->getDataSize();
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					int	numDataBytes	= m_containerParser.getDataSize();
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_currentCaseData->setDataSize(offset+numDataBytes);
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_containerParser.getData(m_currentCaseData->getData()+offset, numDataBytes, 0);
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_handler->testCaseResultUpdated(m_currentCaseData);
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw ContainerParseError("Unknown container element");
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_containerParser.advance();
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // xe
188