Home | History | Annotate | Download | only in parser
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.loganalysis.parser;
     17 
     18 import com.android.loganalysis.item.LogcatItem;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import java.io.BufferedReader;
     23 import java.io.FileNotFoundException;
     24 import java.io.FileReader;
     25 import java.io.IOException;
     26 
     27 /**
     28  * Functional tests for {@link LogcatParser}
     29  */
     30 public class LogcatParserFuncTest extends TestCase {
     31     // FIXME: Make logcat file configurable.
     32     private static final String LOGCAT_PATH = "/tmp/logcat.txt";
     33 
     34     /**
     35      * A test that is intended to force Brillopad to parse a logcat. The purpose of this is to
     36      * assist a developer in checking why a given logcat file might not be parsed correctly by
     37      * Brillopad.
     38      */
     39     public void testParse() {
     40         BufferedReader logcatReader = null;
     41         try {
     42             logcatReader = new BufferedReader(new FileReader(LOGCAT_PATH));
     43         } catch (FileNotFoundException e) {
     44             fail(String.format("File not found at %s", LOGCAT_PATH));
     45         }
     46         LogcatItem logcat = null;
     47         try {
     48             long start = System.currentTimeMillis();
     49             logcat = new LogcatParser().parse(logcatReader);
     50             long stop = System.currentTimeMillis();
     51             System.out.println(String.format("Logcat took %d ms to parse.", stop - start));
     52         } catch (IOException e) {
     53             fail(String.format("IOException: %s", e.toString()));
     54         } finally {
     55             if (logcatReader != null) {
     56                 try {
     57                     logcatReader.close();
     58                 } catch (IOException e) {
     59                     // Ignore
     60                 }
     61             }        }
     62 
     63         assertNotNull(logcat);
     64         assertNotNull(logcat.getStartTime());
     65         assertNotNull(logcat.getStopTime());
     66 
     67         System.out.println(String.format("Stats for logcat:\n" +
     68                 "  Start time: %s\n" +
     69                 "  Stop time: %s\n" +
     70                 "  %d ANR(s), %d Java Crash(es), %d Native Crash(es)",
     71                 logcat.getStartTime().toString(),
     72                 logcat.getStopTime().toString(),
     73                 logcat.getAnrs().size(),
     74                 logcat.getJavaCrashes().size(),
     75                 logcat.getNativeCrashes().size()));
     76     }
     77 }
     78 
     79