13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
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 Android JNI interface for instrumentations log parsing.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeTestResultParser.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeTestCaseResult.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeContainerFormatParser.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeTestLogWriter.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "xeXMLWriter.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <jni.h>
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <stdlib.h>
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <android/log.h>
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char*	TESTCASE_STYLESHEET	= "testlog.xsl";
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char*	LOG_TAG				= "dEQP-TestLog";
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestLogListener
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TestLogListener		(JNIEnv* env, jobject object);
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~TestLogListener	(void);
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				beginSession		(void);
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				endSession			(void);
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				sessionInfo			(const char* name, const char* value);
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				beginTestCase		(const char* testCasePath);
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				endTestCase			(void);
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				terminateTestCase	(const char* reason);
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				testCaseResult		(const char* statusCode, const char* details);
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				testLogData			(const char* data);
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	JNIEnv*				m_env;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jobject				m_object;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jclass				m_class;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_sessionInfoID;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_beginSessionID;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_endSessionID;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_beginTestCaseID;
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_endTestCaseID;
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_terminateTestCaseID;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_testCaseResultID;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jmethodID			m_testLogData;
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TestLogListener		(const TestLogListener&);
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLogListener&	operator=			(const TestLogListener&);
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogListener::TestLogListener (JNIEnv* env, jobject object)
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_env		(env)
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_object	(object)
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_class					= m_env->GetObjectClass(m_object);
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_sessionInfoID			= m_env->GetMethodID(m_class, "sessionInfo",		"(Ljava/lang/String;Ljava/lang/String;)V");
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_beginSessionID		= m_env->GetMethodID(m_class, "beginSession",		"()V");
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_endSessionID			= m_env->GetMethodID(m_class, "endSession",			"()V");
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_beginTestCaseID		= m_env->GetMethodID(m_class, "beginTestCase",		"(Ljava/lang/String;)V");
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_endTestCaseID			= m_env->GetMethodID(m_class, "endTestCase",		"()V");
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_terminateTestCaseID	= m_env->GetMethodID(m_class, "terminateTestCase",	"(Ljava/lang/String;)V");
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCaseResultID		= m_env->GetMethodID(m_class, "testCaseResult",		"(Ljava/lang/String;Ljava/lang/String;)V");
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testLogData			= m_env->GetMethodID(m_class, "testLogData",		"(Ljava/lang/String;)V");
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_beginSessionID);
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_endSessionID);
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_sessionInfoID);
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_beginTestCaseID);
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_endTestCaseID);
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_terminateTestCaseID);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_testCaseResultID);
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(m_testLogData);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogListener::~TestLogListener (void)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::beginSession (void)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1104adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_beginSessionID);
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::endSession (void)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1154adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_endSessionID);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::sessionInfo (const char* name, const char* value)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring jName	= m_env->NewStringUTF(name);
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring jValue	= m_env->NewStringUTF(value);
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1234adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_sessionInfoID, jName, jValue);
1244adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jName);
1254adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jValue);
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::beginTestCase (const char* testCasePath)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring jTestCasePath = m_env->NewStringUTF(testCasePath);
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1324adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_beginTestCaseID, jTestCasePath);
1334adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jTestCasePath);
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::endTestCase (void)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1384adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_endTestCaseID);
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::terminateTestCase (const char* reason)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring	 jReason = m_env->NewStringUTF(reason);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1454adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_terminateTestCaseID, jReason);
1464adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jReason);
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::testCaseResult (const char* statusCode, const char* details)
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring	 jStatusCode	= m_env->NewStringUTF(statusCode);
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring	 jDetails		= m_env->NewStringUTF(details);
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1544adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_testCaseResultID, jStatusCode, jDetails);
1554adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jStatusCode);
1564adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(jDetails);
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogListener::testLogData (const char* data)
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jstring logData = m_env->NewStringUTF(data);
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1634adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->CallVoidMethod(m_object, m_testLogData, logData);
1644adc1515f867b26c19c2f7498e9de93a230a234dPyry Haulos	m_env->DeleteLocalRef(logData);
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestLogParser
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TestLogParser	(bool logData);
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~TestLogParser	(void);
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						parse			(TestLogListener& listener, const char* buffer, size_t size);
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool					m_logData;
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						m_inTestCase;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						m_loggedResult;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	xe::ContainerFormatParser	m_containerParser;
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	xe::TestCaseResult			m_testCaseResult;
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	xe::TestResultParser		m_testResultParser;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TestLogParser	(const TestLogParser&);
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLogParser&				operator=		(const TestLogParser&);
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogParser::TestLogParser (bool logData)
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_logData			(logData)
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_inTestCase		(DE_FALSE)
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_loggedResult	(DE_FALSE)
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestLogParser::~TestLogParser (void)
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TestLogParser::parse (TestLogListener& listener, const char* buffer, size_t size)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_containerParser.feed((const deUint8*)buffer, size);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	while (m_containerParser.getElement() != xe::CONTAINERELEMENT_INCOMPLETE)
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (m_containerParser.getElement())
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_END_OF_STRING:
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Do nothing
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_BEGIN_SESSION:
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.beginSession();
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_END_SESSION:
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.endSession();
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_SESSION_INFO:
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.sessionInfo(m_containerParser.getSessionInfoAttribute(), m_containerParser.getSessionInfoValue());
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_BEGIN_TEST_CASE_RESULT:
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.beginTestCase(m_containerParser.getTestCasePath());
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_inTestCase		= DE_TRUE;
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_loggedResult		= DE_FALSE;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCaseResult	= xe::TestCaseResult();
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testResultParser.init(&m_testCaseResult);
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_END_TEST_CASE_RESULT:
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_testCaseResult.statusCode != xe::TESTSTATUSCODE_LAST && !m_loggedResult)
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					listener.testCaseResult(xe::getTestStatusCodeName(m_testCaseResult.statusCode), m_testCaseResult.statusDetails.c_str());
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_loggedResult = DE_TRUE;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_logData)
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					std::ostringstream	testLog;
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					xe::xml::Writer		xmlWriter(testLog);
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					testLog << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "<?xml-stylesheet href=\"" << TESTCASE_STYLESHEET << "\" type=\"text/xsl\"?>\n";
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					xe::writeTestResult(m_testCaseResult, xmlWriter);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					listener.testLogData(testLog.str().c_str());
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.endTestCase();
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_inTestCase = DE_FALSE;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_TERMINATE_TEST_CASE_RESULT:
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_logData)
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					std::ostringstream	testLog;
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					xe::xml::Writer		xmlWriter(testLog);
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					testLog << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							<< "<?xml-stylesheet href=\"" << TESTCASE_STYLESHEET << "\" type=\"text/xsl\"?>\n";
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					xe::writeTestResult(m_testCaseResult, xmlWriter);
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					listener.testLogData(testLog.str().c_str());
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_testCaseResult.statusCode != xe::TESTSTATUSCODE_LAST && !m_loggedResult)
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					listener.testCaseResult(xe::getTestStatusCodeName(m_testCaseResult.statusCode), m_testCaseResult.statusDetails.c_str());
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_loggedResult = DE_TRUE;
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				listener.terminateTestCase(m_containerParser.getTerminateReason());
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_inTestCase = DE_FALSE;
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case xe::CONTAINERELEMENT_TEST_LOG_DATA:
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_inTestCase)
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					std::vector<deUint8> data(m_containerParser.getDataSize());
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_containerParser.getData(&(data[0]), (int)data.size(), 0);
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					//tcu::print("%d %s :%s %s", __LINE__, std::string((const char*)&data[0], data.size()).c_str(), __func__, __FILE__);
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (m_testResultParser.parse(&(data[0]), (int)data.size()) == xe::TestResultParser::PARSERESULT_CHANGED)
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						if (m_testCaseResult.statusCode != xe::TESTSTATUSCODE_LAST && !m_loggedResult)
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						{
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							listener.testCaseResult(xe::getTestStatusCodeName(m_testCaseResult.statusCode), m_testCaseResult.statusDetails.c_str());
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							m_loggedResult = DE_TRUE;
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						}
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(DE_FALSE);
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_containerParser.advance();
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid throwJNIException (JNIEnv* env, const std::exception& e)
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jclass exClass;
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	exClass = env->FindClass("java/lang/Exception");
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(exClass != DE_NULL);
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(env->ThrowNew(exClass, e.what()) == 0);
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_BEGIN_EXTERN_C
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3280d71d061a51cfdcb78b44e10a5c9fac87eb16cf7Brian CarlstromJNIEXPORT jlong JNICALL Java_com_drawelements_deqp_testercore_TestLogParser_nativeCreate (JNIEnv* env, jclass, jboolean logData)
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(env);
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return (jlong)new TestLogParser(logData);
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const std::exception& e)
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", e.what());
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throwJNIException(env, e);
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return 0;
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3450d71d061a51cfdcb78b44e10a5c9fac87eb16cf7Brian CarlstromJNIEXPORT void JNICALL Java_com_drawelements_deqp_testercore_TestLogParser_nativeDestroy (JNIEnv* env, jclass, jlong nativePointer)
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(env);
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete ((TestLogParser*)nativePointer);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const std::exception& e)
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", e.what());
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throwJNIException(env, e);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3610d71d061a51cfdcb78b44e10a5c9fac87eb16cf7Brian CarlstromJNIEXPORT void JNICALL Java_com_drawelements_deqp_testercore_TestLogParser_nativeParse (JNIEnv* env, jclass, jlong nativePointer, jobject instrumentation, jbyteArray buffer, jint size)
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	jbyte* logData = DE_NULL;
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLogParser*	parser		= (TestLogParser*)nativePointer;
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLogListener	listener	(env, instrumentation);
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logData = env->GetByteArrayElements(buffer, NULL);
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		parser->parse(listener, (const char*)logData, (size_t)size);
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		env->ReleaseByteArrayElements(buffer, logData, JNI_ABORT);
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logData = DE_NULL;
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const std::exception& e)
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", e.what());
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (logData)
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			env->ReleaseByteArrayElements(buffer, logData, JNI_ABORT);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throwJNIException(env, e);
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_END_EXTERN_C
388