Bug 1550052 - Ensure clean android app install via mach; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 08 May 2019 20:38:47 +0000
changeset 531936 7e3b4a30cfd741ff493ca9100bf82c4bb30fe31b
parent 531935 b54d90e1c6814f37918a8a6a1e6fc5054ea6e868
child 531937 efc907d677c24b15d2f652e41efa6bca3239fbcc
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1550052
milestone68.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 1550052 - Ensure clean android app install via mach; r=jmaher Uninstalling the test app before re-installing ensures a clean, predictable starting state for gtest. Differential Revision: https://phabricator.services.mozilla.com/D30407
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -209,68 +209,74 @@ def verify_android_device(build_obj, ins
     if device_verified and "DEVICE_SERIAL" not in os.environ:
         devices = adbhost.devices(timeout=10)
         for d in devices:
             if d['state'] == 'device':
                 os.environ["DEVICE_SERIAL"] = d['device_serial']
                 break
 
     if device_verified and install:
-        # Determine if Firefox is installed on the device; if not,
+        # Determine if test app is installed on the device; if not,
         # prompt to install. This feature allows a test command to
-        # launch an emulator, install Firefox, and proceed with testing
+        # launch an emulator, install the test app, and proceed with testing
         # in one operation. It is also a basic safeguard against other
-        # cases where testing is requested but Firefox installation has
+        # cases where testing is requested but test app installation has
         # been forgotten.
-        # If Firefox is installed, there is no way to determine whether
+        # If a test app 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 (without prompting) is problematic because:
         #  - it prevents testing against other builds (downloaded apk)
         #  - installation may take a couple of minutes.
         if not app:
             app = build_obj.substs["ANDROID_PACKAGE_NAME"]
         device = _get_device(build_obj.substs, device_serial)
         response = ''
         action = 'Re-install'
-        if not device.is_app_installed(app):
+        installed = device.is_app_installed(app)
+        if not installed:
             _log_info("It looks like %s is not installed on this device." % app)
             action = 'Install'
         if 'fennec' in app or 'firefox' in app:
             response = response = raw_input(
                 "%s Firefox? (Y/n) " % action).strip()
             if response.lower().startswith('y') or response == '':
+                if installed:
+                    device.uninstall_app(app)
                 _log_info("Installing Firefox. This may take a while...")
                 build_obj._run_make(directory=".", target='install',
                                     ensure_exit_code=False)
         elif app == 'org.mozilla.geckoview.test':
             response = response = raw_input(
                 "%s geckoview AndroidTest? (Y/n) " % action).strip()
             if response.lower().startswith('y') or response == '':
+                if installed:
+                    device.uninstall_app(app)
                 _log_info("Installing geckoview AndroidTest. This may take a while...")
                 sub = 'geckoview:installWithGeckoBinariesDebugAndroidTest'
                 build_obj._mach_context.commands.dispatch('gradle',
                                                           args=[sub],
                                                           context=build_obj._mach_context)
         elif app == 'org.mozilla.geckoview_example':
             response = response = raw_input(
                 "%s geckoview_example? (Y/n) " % action).strip()
             if response.lower().startswith('y') or response == '':
+                if installed:
+                    device.uninstall_app(app)
                 _log_info("Installing geckoview_example. This may take a while...")
                 sub = 'install-geckoview_example'
                 build_obj._mach_context.commands.dispatch('android',
                                                           subcommand=sub,
                                                           args=[],
                                                           context=build_obj._mach_context)
-        else:
-            if not device.is_app_installed(app):
-                response = 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)
+        elif not installed:
+            response = 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)
 
     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 " \