Bug 926408 - Import mozcrash 0.9 from upstream
authorEd Morley <emorley>
Mon, 14 Oct 2013 07:24:00 +0100
changeset 151007 e788cc14a5d3577aa37267e95bd41519d8d3c175
parent 151006 68547b9ec03edaee78a54c8d94ba2dd3b419caf7
child 151008 fb35d633b2299442e1d0e1b20edd8e999dc90e99
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
bugs926408
milestone27.0a1
Bug 926408 - Import mozcrash 0.9 from upstream
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozbase/mozcrash/setup.py
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -1,28 +1,30 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-__all__ = ['check_for_crashes']
+__all__ = ['check_for_crashes',
+           'check_for_java_exception']
 
 import glob
 import mozlog
 import os
 import re
 import shutil
 import subprocess
 import sys
 import tempfile
 import urllib2
 import zipfile
 
 from mozfile import extract_zip
 from mozfile import is_url
 
+
 def check_for_crashes(dump_directory, symbols_path,
                       stackwalk_binary=None,
                       dump_save_path=None,
                       test_name=None,
                       quiet=False):
     """
     Print a stack trace for minidump files left behind by a crashing program.
 
@@ -147,8 +149,49 @@ def check_for_crashes(dump_directory, sy
             extra = os.path.splitext(d)[0] + ".extra"
             if os.path.exists(extra):
                 os.remove(extra)
     finally:
         if remove_symbols:
             shutil.rmtree(symbols_path)
 
     return True
+
+
+def check_for_java_exception(logcat):
+    """
+    Print a summary of a fatal Java exception, if present in the provided
+    logcat output.
+
+    Example:
+    PROCESS-CRASH | java-exception | java.lang.NullPointerException at org.mozilla.gecko.GeckoApp$21.run(GeckoApp.java:1833)
+
+    `logcat` should be a list of strings.
+
+    Returns True if a fatal Java exception was found, False otherwise.
+    """
+    found_exception = False
+
+    for i, line in enumerate(logcat):
+        # Logs will be of form:
+        #
+        # 01-30 20:15:41.937 E/GeckoAppShell( 1703): >>> REPORTING UNCAUGHT EXCEPTION FROM THREAD 9 ("GeckoBackgroundThread")
+        # 01-30 20:15:41.937 E/GeckoAppShell( 1703): java.lang.NullPointerException
+        # 01-30 20:15:41.937 E/GeckoAppShell( 1703): 	at org.mozilla.gecko.GeckoApp$21.run(GeckoApp.java:1833)
+        # 01-30 20:15:41.937 E/GeckoAppShell( 1703): 	at android.os.Handler.handleCallback(Handler.java:587)
+        if "REPORTING UNCAUGHT EXCEPTION" in line or "FATAL EXCEPTION" in line:
+            # Strip away the date, time, logcat tag and pid from the next two lines and
+            # concatenate the remainder to form a concise summary of the exception.
+            found_exception = True
+            if len(logcat) >= i + 3:
+                logre = re.compile(r".*\): \t?(.*)")
+                m = logre.search(logcat[i+1])
+                if m and m.group(1):
+                    exception_type = m.group(1)
+                m = logre.search(logcat[i+2])
+                if m and m.group(1):
+                    exception_location = m.group(1)
+                print "PROCESS-CRASH | java-exception | %s %s" % (exception_type, exception_location)
+            else:
+                print "Automation Error: Logcat is truncated!"
+            break
+
+    return found_exception
--- a/testing/mozbase/mozcrash/setup.py
+++ b/testing/mozbase/mozcrash/setup.py
@@ -1,15 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from setuptools import setup
 
-PACKAGE_VERSION = '0.8'
+PACKAGE_VERSION = '0.9'
 
 # dependencies
 deps = ['mozfile >= 0.3',
         'mozlog']
 
 setup(name='mozcrash',
       version=PACKAGE_VERSION,
       description="Library for printing stack traces from minidumps left behind by crashed processes",