Bug 1434423 - Check for installation of correct test application when --app is passed to mach; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Fri, 09 Feb 2018 14:34:20 -0700
changeset 403167 026a0eec0d5f3d2adedcec61ebd72f2fc915ae26
parent 403166 784e9f86bb03fd3ddbfc94cbdf27c4777d65dcc8
child 403168 a824791e0d28623e928f9b5314cb6d948b2218ef
push id99739
push usergbrown@mozilla.com
push dateFri, 09 Feb 2018 21:34:41 +0000
treeherdermozilla-inbound@026a0eec0d5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1434423
milestone60.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 1434423 - Check for installation of correct test application when --app is passed to mach; r=jmaher
layout/tools/reftest/mach_commands.py
testing/mochitest/mach_commands.py
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
--- a/layout/tools/reftest/mach_commands.py
+++ b/layout/tools/reftest/mach_commands.py
@@ -226,11 +226,11 @@ class MachCommands(MachCommandBase):
         return self._run_reftest(**kwargs)
 
     def _run_reftest(self, **kwargs):
         kwargs["topsrcdir"] = self.topsrcdir
         process_test_objects(kwargs)
         reftest = self._spawn(ReftestRunner)
         if conditions.is_android(self):
             from mozrunner.devices.android_device import verify_android_device
-            verify_android_device(self, install=True, xre=True)
+            verify_android_device(self, install=True, xre=True, app=kwargs["app"])
             return reftest.run_android_test(**kwargs)
         return reftest.run_desktop_test(**kwargs)
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -228,17 +228,18 @@ def setup_argument_parser():
         from mochitest_options import MochitestArgumentParser
 
     if conditions.is_android(build_obj):
         # On Android, check for a connected device (and offer to start an
         # emulator if appropriate) before running tests. This check must
         # be done in this admittedly awkward place because
         # MochitestArgumentParser initialization fails if no device is found.
         from mozrunner.devices.android_device import verify_android_device
-        verify_android_device(build_obj, install=True, xre=True)
+        # verify device and xre
+        verify_android_device(build_obj, install=False, xre=True)
 
     global parser
     parser = MochitestArgumentParser()
     return parser
 
 
 # condition filters
 
@@ -386,16 +387,19 @@ class MachCommands(MachCommandBase):
                     reason = 'excluded by the command line'
                 msg.append('    mochitest -f {} ({})'.format(name, reason))
             print(SUPPORTED_TESTS_NOT_FOUND.format(
                 buildapp, '\n'.join(sorted(msg))))
             return 1
 
         if buildapp == 'android':
             from mozrunner.devices.android_device import grant_runtime_permissions
+            from mozrunner.devices.android_device import verify_android_device
+            # verify installation
+            verify_android_device(self, install=True, xre=False, app=kwargs['app'])
             grant_runtime_permissions(self)
             run_mochitest = mochitest.run_android_test
         else:
             run_mochitest = mochitest.run_desktop_test
 
         overall = None
         for (flavor, subsuite), tests in sorted(suites.items()):
             fobj = ALL_FLAVORS[flavor]
@@ -456,16 +460,19 @@ class RobocopCommands(MachCommandBase):
         driver.install_tests(tests)
 
         if len(tests) < 1:
             print(ROBOCOP_TESTS_NOT_FOUND.format('\n'.join(
                 sorted(list(test_paths)))))
             return 1
 
         from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path
+        from mozrunner.devices.android_device import verify_android_device
+        # verify installation
+        verify_android_device(self, install=True, xre=False, app=kwargs['app'])
         grant_runtime_permissions(self)
 
         if not kwargs['adbPath']:
             kwargs['adbPath'] = get_adb_path(self)
 
         mochitest = self._spawn(MochitestRunner)
         return mochitest.run_robocop_test(self._mach_context, tests, 'robocop', **kwargs)
 
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -172,17 +172,18 @@ def _maybe_update_host_utils(build_obj):
             if response.lower().startswith('y') or response == '':
                 parts = os.path.split(existing_path)
                 backup_dir = '_backup-' + parts[1]
                 backup_path = os.path.join(parts[0], backup_dir)
                 shutil.move(existing_path, backup_path)
                 _install_host_utils(build_obj)
 
 
-def verify_android_device(build_obj, install=False, xre=False, debugger=False, verbose=False):
+def verify_android_device(build_obj, install=False, xre=False, debugger=False,
+                          verbose=False, app=None):
     """
        Determine if any Android device is connected via adb.
        If no device is found, prompt to start an emulator.
        If a device is found or an emulator started and 'install' is
        specified, also check whether Firefox is installed on the
        device; if not, prompt to install Firefox.
        If 'xre' is specified, also check with MOZ_HOST_BIN is set
        to a valid xre/host-utils directory; if not, prompt to set
@@ -220,24 +221,32 @@ def verify_android_device(build_obj, ins
         # If Firefox is installed, there is no way to determine whether
         # the current build is installed, and certainly no way to
         # determine if the installed build is the desired build.
         # Installing every time is problematic because:
         #  - it prevents testing against other builds (downloaded apk)
         #  - installation may take a couple of minutes.
         installed = emulator.dm.shellCheckOutput(['pm', 'list',
                                                   'packages', 'org.mozilla.'])
-        if 'fennec' not in installed and 'firefox' not in installed:
-            response = raw_input(
-                "It looks like Firefox is not installed on this device.\n"
-                "Install Firefox? (Y/n) ").strip()
-            if response.lower().startswith('y') or response == '':
-                _log_info("Installing Firefox. This may take a while...")
-                build_obj._run_make(directory=".", target='install',
-                                    ensure_exit_code=False)
+        if not app:
+            app = build_obj.substs["ANDROID_PACKAGE_NAME"]
+        if app not in installed:
+            if 'fennec' not in app and 'firefox' not in app:
+                raw_input(
+                    "It looks like %s is not installed on this device,\n"
+                    "but I don't know how to install it.\n"
+                    "Install it now, then hit Enter " % app)
+            else:
+                response = raw_input(
+                    "It looks like %s is not installed on this device.\n"
+                    "Install Firefox? (Y/n) " % app).strip()
+                if response.lower().startswith('y') or response == '':
+                    _log_info("Installing Firefox. This may take a while...")
+                    build_obj._run_make(directory=".", target='install',
+                                        ensure_exit_code=False)
 
     if device_verified and xre:
         # Check whether MOZ_HOST_BIN has been set to a valid xre; if not,
         # prompt to install one.
         xre_path = os.environ.get('MOZ_HOST_BIN')
         err = None
         if not xre_path:
             err = "environment variable MOZ_HOST_BIN is not set to a directory " \