Bug 1494437 - Support device screenshots in AndroidMixin; r=bc
authorGeoff Brown <gbrown@mozilla.com>
Wed, 24 Oct 2018 10:33:02 -0600
changeset 442774 79ef182cc44ef9bd252fb8c5b9c9f924690db75b
parent 442773 5671f49a7aa58b30a557cb965fe422a285613a2b
child 442775 1aa7374de7ee8e5810e89adfeb38f6d39f316bfa
push id109235
push usergbrown@mozilla.com
push dateWed, 24 Oct 2018 16:33:18 +0000
treeherdermozilla-inbound@be944769416f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbc
bugs1494437
milestone65.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 1494437 - Support device screenshots in AndroidMixin; r=bc
testing/mozharness/mozharness/mozilla/testing/android.py
--- a/testing/mozharness/mozharness/mozilla/testing/android.py
+++ b/testing/mozharness/mozharness/mozilla/testing/android.py
@@ -189,17 +189,17 @@ class AndroidMixin(object):
         if not boot_ok:
             self.warning('Unable to verify Android boot completion')
             return False
         return True
 
     def _verify_emulator_and_restart_on_fail(self):
         emulator_ok = self._verify_emulator()
         if not emulator_ok:
-            self.screenshot("emulator-startup-screenshot-")
+            self.device_screenshot()
             self.kill_processes(self.config["emulator_process_name"])
             subprocess.check_call(['ps', '-ef'])
             # remove emulator tmp files
             for dir in glob.glob("/tmp/android-*"):
                 self.rmtree(dir)
             time.sleep(5)
             self.emulator_proc = self._launch_emulator()
         return emulator_ok
@@ -330,33 +330,33 @@ class AndroidMixin(object):
         out = self.device.get_prop('sys.boot_completed', timeout=30)
         if out.strip() == '1':
             return True
         return False
 
     def shell_output(self, cmd):
         return self.device.shell_output(cmd, timeout=30)
 
-    def screenshot(self, prefix):
+    def device_screenshot(self):
         """
-           Save a screenshot of the entire screen to the blob upload directory.
+           On emulator, save a screenshot of the entire screen to the upload directory;
+           otherwise, save a screenshot of the device to the upload directory.
         """
-        dirs = self.query_abs_dirs()
-        utility = os.path.join(self.xre_path, "screentopng")
-        if not os.path.exists(utility):
-            self.warning("Unable to take screenshot: %s does not exist" % utility)
-            return
-        try:
-            tmpfd, filename = tempfile.mkstemp(prefix=prefix, suffix='.png',
-                                               dir=dirs['abs_blob_upload_dir'])
-            os.close(tmpfd)
-            self.info("Taking screenshot with %s; saving to %s" % (utility, filename))
-            subprocess.call([utility, filename], env=self.query_env())
-        except OSError, err:
-            self.warning("Failed to take screenshot: %s" % err.strerror)
+        from mozscreenshot import dump_screen, dump_device_screen
+        reset_dir = False
+        if not os.environ.get("MOZ_UPLOAD_DIR", None):
+            dirs = self.query_abs_dirs()
+            os.environ["MOZ_UPLOAD_DIR"] = dirs['abs_blob_upload_dir']
+            reset_dir = True
+        if self.is_emulator:
+            dump_screen(self.xre_path, self)
+        else:
+            dump_device_screen(self.device, self)
+        if reset_dir:
+            del os.environ["MOZ_UPLOAD_DIR"]
 
     def download_hostutils(self, xre_dir):
         """
            Download and install hostutils from tooltool.
         """
         xre_path = None
         self.rmtree(xre_dir)
         self.mkdir_p(xre_dir)