1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program Tester Core 3 * ---------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 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 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 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. 18 * 19 *//*! 20 * \file 21 * \brief Test log parser for instrumentation 22 *//*--------------------------------------------------------------------*/ 23 24 package com.drawelements.deqp.testercore; 25 26 import java.io.FileInputStream; 27 import java.io.FileNotFoundException; 28 import java.io.IOException; 29 30 public class TestLogParser 31 { 32 static { 33 System.loadLibrary("deqp"); 34 } 35 36 private long m_nativePointer; 37 private DeqpInstrumentation m_instrumentation; 38 private FileInputStream m_log; 39 private String m_logFileName; 40 private byte[] m_buffer; 41 private long m_logRead; 42 43 public TestLogParser () 44 { 45 m_nativePointer = 0; 46 m_instrumentation = null; 47 m_log = null; 48 m_logRead = 0; 49 m_buffer = null; 50 } 51 52 public void init (DeqpInstrumentation instrumentation, String logFileName, boolean logData) throws FileNotFoundException 53 { 54 assert instrumentation != null; 55 assert m_instrumentation == null; 56 assert m_nativePointer == 0; 57 assert m_log == null; 58 59 m_logFileName = logFileName; 60 m_instrumentation = instrumentation; 61 m_nativePointer = nativeCreate(logData); 62 m_buffer = new byte[4*1024*1024]; 63 m_log = new FileInputStream(m_logFileName); 64 } 65 66 public void deinit () throws IOException 67 { 68 assert m_nativePointer != 0; 69 assert m_instrumentation != null; 70 assert m_log != null; 71 72 nativeDestroy(m_nativePointer); 73 74 if (m_log != null) 75 m_log.close(); 76 77 m_nativePointer = 0; 78 m_instrumentation = null; 79 m_log = null; 80 m_buffer = null; 81 } 82 83 public boolean parse () throws IOException 84 { 85 assert m_nativePointer != 0; 86 assert m_instrumentation != null; 87 assert m_log != null; 88 89 boolean gotData = false; 90 91 while (true) 92 { 93 final int numAvailable = m_log.available(); 94 95 if (numAvailable <= 0) 96 break; 97 98 final int numRead = m_log.read(m_buffer, 0, Math.min(numAvailable, m_buffer.length)); 99 100 assert numRead > 0; 101 102 m_logRead += numRead; 103 104 gotData = true; 105 nativeParse(m_nativePointer, m_instrumentation, m_buffer, numRead); 106 } 107 108 return gotData; 109 } 110 111 private static native long nativeCreate (boolean logData); 112 private static native void nativeDestroy (long nativePointer); 113 private static native void nativeParse (long nativePointer, DeqpInstrumentation instrumentation, byte[] buffer, int size); 114 } 115