Bug 1319196 - Take screenshot when dumpsys fails; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Tue, 13 Dec 2016 11:28:06 -0700
changeset 325759 f21a93061f9a705e16606417b9ec0b4bebe0ac0c
parent 325758 c902a14dffee41d914e1b6bf613a9f5a093dd1e9
child 325760 6dfee6a56324feed0a4d80c1c448095e0891b76c
push id31073
push userphilringnalda@gmail.com
push dateWed, 14 Dec 2016 03:25:19 +0000
treeherdermozilla-central@1ea0c60db5d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1319196
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1319196 - Take screenshot when dumpsys fails; r=jmaher
build/mobile/remoteautomation.py
--- a/build/mobile/remoteautomation.py
+++ b/build/mobile/remoteautomation.py
@@ -11,16 +11,17 @@ import posixpath
 import tempfile
 import shutil
 import subprocess
 import sys
 
 from automation import Automation
 from mozdevice import DMError, DeviceManager
 from mozlog import get_default_logger
+from mozscreenshot import dump_screen
 import mozcrash
 
 # signatures for logcat messages that we don't care about much
 fennecLogcatFilters = [ "The character encoding of the HTML document was not declared",
                         "Use of Mutation Events is deprecated. Use MutationObserver instead.",
                         "Unexpected value from nativeGetEnabledTags: 0" ]
 
 class RemoteAutomation(Automation):
@@ -103,16 +104,17 @@ class RemoteAutomation(Automation):
 
         return env
 
     def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath, outputHandler=None):
         """ Wait for tests to finish.
             If maxTime seconds elapse or no output is detected for timeout
             seconds, kill the process and fail the test.
         """
+        proc.utilityPath = utilityPath
         # maxTime is used to override the default timeout, we should honor that
         status = proc.wait(timeout = maxTime, noOutputTimeout = timeout)
         self.lastTestSeen = proc.getLastTestSeen
 
         topActivity = self._devicemanager.getTopActivity()
         if topActivity == proc.procName:
             proc.kill(True)
         if status == 1:
@@ -279,16 +281,17 @@ class RemoteAutomation(Automation):
         dm = None
         def __init__(self, dm, cmd, stdout=None, stderr=None, env=None, cwd=None, app=None,
                      messageLogger=None):
             self.dm = dm
             self.stdoutlen = 0
             self.lastTestSeen = "remoteautomation.py"
             self.proc = dm.launchProcess(cmd, stdout, cwd, env, True)
             self.messageLogger = messageLogger
+            self.utilityPath = None
 
             if (self.proc is None):
                 if cmd[0] == 'am':
                     self.proc = stdout
                 else:
                     raise Exception("unable to launch process")
             self.procName = cmd[0].split('/')[-1]
             if cmd[0] == 'am' and cmd[1] in RemoteAutomation._specialAmCommands:
@@ -403,16 +406,23 @@ class RemoteAutomation(Automation):
                     status = 2
                     break
                 top = self.dm.getTopActivity()
             # Flush anything added to stdout during the sleep
             self.read_stdout()
             return status
 
         def kill(self, stagedShutdown = False):
+            if self.utilityPath:
+                # Take a screenshot to capture the screen state just before
+                # the application is killed. There are on-device screenshot
+                # options but they rarely work well with Firefox on the
+                # Android emulator. dump_screen provides an effective
+                # screenshot of the emulator and its host desktop.
+                dump_screen(self.utilityPath, get_default_logger())
             if stagedShutdown:
                 # Trigger an ANR report with "kill -3" (SIGQUIT)
                 self.dm.killProcess(self.procName, 3)
                 time.sleep(3)
                 # Trigger a breakpad dump with "kill -6" (SIGABRT)
                 self.dm.killProcess(self.procName, 6)
                 # Wait for process to end
                 retries = 0