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 Test log parser for instrumentation 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypackage com.drawelements.deqp.testercore; 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport android.os.Build; 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport java.io.FileInputStream; 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport java.io.FileNotFoundException; 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport java.io.IOException; 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic class TestLogParser 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static { 3504d51263aaa058a4d7b7279c51b035f50aa4fdadPyry Haulos System.loadLibrary("deqp"); 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private long m_nativePointer; 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private DeqpInstrumentation m_instrumentation; 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private FileInputStream m_log; 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private String m_logFileName; 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private byte[] m_buffer; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private long m_logRead; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public TestLogParser () 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_nativePointer = 0; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_instrumentation = null; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_log = null; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_logRead = 0; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_buffer = null; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public void init (DeqpInstrumentation instrumentation, String logFileName, boolean logData) throws FileNotFoundException 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert instrumentation != null; 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_instrumentation == null; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_nativePointer == 0; 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_log == null; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_logFileName = logFileName; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_instrumentation = instrumentation; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_nativePointer = nativeCreate(logData); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_buffer = new byte[4*1024*1024]; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_log = new FileInputStream(m_logFileName); 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public void deinit () throws IOException 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_nativePointer != 0; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_instrumentation != null; 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_log != null; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry nativeDestroy(m_nativePointer); 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_log != null) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_log.close(); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_nativePointer = 0; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_instrumentation = null; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_log = null; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_buffer = null; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public boolean parse () throws IOException 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_nativePointer != 0; 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_instrumentation != null; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert m_log != null; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry boolean gotData = false; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (true) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9585a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos final int numAvailable = m_log.available(); 9685a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos 9785a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos if (numAvailable <= 0) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10085a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos final int numRead = m_log.read(m_buffer, 0, Math.min(numAvailable, m_buffer.length)); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10285a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos assert numRead > 0; 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10485a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos m_logRead += numRead; 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gotData = true; 10785a7efa09c2487d7a1907e4f70115fb7f579eca1Pyry Haulos nativeParse(m_nativePointer, m_instrumentation, m_buffer, numRead); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return gotData; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private static native long nativeCreate (boolean logData); 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private static native void nativeDestroy (long nativePointer); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private static native void nativeParse (long nativePointer, DeqpInstrumentation instrumentation, byte[] buffer, int size); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 117