Bug 1410714 - Help mach tests find adb when running Android tests; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Tue, 24 Oct 2017 15:17:25 -0600
changeset 388068 4dfe93e7c0811d6c130e4e56c967909fec494b03
parent 388067 00bec72d17c4591f10e7dc7930637a2dded95975
child 388069 37db725b23082b69fdf4e3b08242e592a379b60e
push id32740
push useracraciun@mozilla.com
push dateWed, 25 Oct 2017 09:30:59 +0000
treeherdermozilla-central@e56ae7213756 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1410714
milestone58.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 1410714 - Help mach tests find adb when running Android tests; r=jmaher
layout/tools/reftest/mach_commands.py
layout/tools/reftest/reftestcommandline.py
testing/mach_commands.py
testing/mochitest/mach_commands.py
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
testing/remotecppunittests.py
testing/xpcshell/mach_commands.py
testing/xpcshell/remotexpcshelltests.py
testing/xpcshell/xpcshellcommandline.py
--- a/layout/tools/reftest/mach_commands.py
+++ b/layout/tools/reftest/mach_commands.py
@@ -131,19 +131,22 @@ class ReftestRunner(MozbuildObject):
             args.xrePath = os.environ.get("MOZ_HOST_BIN")
         if not args.app:
             args.app = self.substs["ANDROID_PACKAGE_NAME"]
         if not args.utilityPath:
             args.utilityPath = args.xrePath
         args.ignoreWindowSize = True
         args.printDeviceInfo = False
 
-        from mozrunner.devices.android_device import grant_runtime_permissions
+        from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path
         grant_runtime_permissions(self)
 
+        if not args.adb_path:
+            args.adb_path = get_adb_path(self)
+
         # A symlink and some path manipulations are required so that test
         # manifests can be found both locally and remotely (via a url)
         # using the same relative path.
         if args.suite == "jstestbrowser":
             staged_js_dir = os.path.join(self.topobjdir, "dist", "test-stage", "jsreftest")
             tests = os.path.join(self.reftest_dir, 'jsreftest')
             if not os.path.isdir(tests):
                 os.symlink(staged_js_dir, tests)
--- a/layout/tools/reftest/reftestcommandline.py
+++ b/layout/tools/reftest/reftestcommandline.py
@@ -413,17 +413,17 @@ class RemoteArgumentsParser(ReftestArgum
                           help="Path to remote executable relative to device root using only "
                                "forward slashes.  Either this or app must be specified, "
                                "but not both.")
 
         self.add_argument("--adbpath",
                           action="store",
                           type=str,
                           dest="adb_path",
-                          default="adb",
+                          default=None,
                           help="path to adb")
 
         self.add_argument("--deviceIP",
                           action="store",
                           type=str,
                           dest="deviceIP",
                           help="ip address of remote device to test")
 
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -391,16 +391,19 @@ class MachCommands(MachCommandBase):
     def run_android_test(self, tests, symbols_path, manifest_path, log):
         import remotecppunittests as remotecppunittests
         from mozlog import commandline
 
         parser = remotecppunittests.RemoteCPPUnittestOptions()
         commandline.add_logging_group(parser)
         options, args = parser.parse_args()
 
+        if not options.adb_path:
+            from mozrunner.devices.android_device import get_adb_path
+            options.adb_path = get_adb_path(self)
         options.symbols_path = symbols_path
         options.manifest_path = manifest_path
         options.xre_path = self.bindir
         options.local_lib = self.bindir.replace('bin', 'fennec')
         for file in os.listdir(os.path.join(self.topobjdir, "dist")):
             if file.endswith(".apk") and file.startswith("fennec"):
                 options.local_apk = os.path.join(self.topobjdir, "dist", file)
                 log.info("using APK: " + options.local_apk)
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -167,16 +167,20 @@ class MochitestRunner(MozbuildObject):
 
         import imp
         path = os.path.join(self.mochitest_dir, 'runtestsremote.py')
         with open(path, 'r') as fh:
             imp.load_module('runtestsremote', fh, path,
                             ('.py', 'r', imp.PY_SOURCE))
         import runtestsremote
 
+        from mozrunner.devices.android_device import get_adb_path
+        if not kwargs['adbPath']:
+            kwargs['adbPath'] = get_adb_path(self)
+
         options = Namespace(**kwargs)
 
         from manifestparser import TestManifest
         if tests and not options.manifestFile:
             manifest = TestManifest()
             manifest.tests.extend(tests)
             options.manifestFile = manifest
 
@@ -450,19 +454,22 @@ class RobocopCommands(MachCommandBase):
         driver = self._spawn(BuildDriver)
         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
+        from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path
         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)
 
 
 # NOTE python/mach/mach/commands/commandinfo.py references this function
 #      by name. If this function is renamed or removed, that file should
 #      be updated accordingly as well.
 def REMOVED(cls):
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -241,16 +241,20 @@ def verify_android_device(build_obj, ins
             _update_gdbinit(build_obj.substs, os.path.join(jimdb_utils_path, "gdbinit.local"))
             # ensure JimDB is in system path, so that mozdebug can find it
             bin_path = os.path.join(jimdb_path, 'bin')
             os.environ['PATH'] = "%s:%s" % (bin_path, os.environ['PATH'])
 
     return device_verified
 
 
+def get_adb_path(build_obj):
+    return _find_sdk_exe(build_obj.substs, 'adb', False)
+
+
 def run_firefox_for_android(build_obj, params):
     """
        Launch Firefox for Android on the connected device.
        Optional 'params' allow parameters to be passed to Firefox.
     """
     adb_path = _find_sdk_exe(build_obj.substs, 'adb', False)
     if not adb_path:
         adb_path = 'adb'
--- a/testing/remotecppunittests.py
+++ b/testing/remotecppunittests.py
@@ -173,16 +173,21 @@ class RemoteCPPUnittestOptions(cppunitte
                         help="ip address of remote device to test")
         defaults["device_ip"] = None
 
         self.add_option("--devicePort", action="store",
                         type="string", dest="device_port",
                         help="port of remote device to test")
         defaults["device_port"] = 20701
 
+        self.add_option("--adbPath", action="store",
+                        type="string", dest="adb_path",
+                        help="Path to adb")
+        defaults["adb_path"] = None
+
         self.add_option("--noSetup", action="store_false",
                         dest="setup",
                         help="do not copy any files to device (to be used only if "
                         "device is already setup)")
         defaults["setup"] = True
 
         self.add_option("--localLib", action="store",
                         type="string", dest="local_lib",
@@ -233,16 +238,18 @@ def run_test_harness(options, args):
     else:
         retryLimit = 5
     try:
         dm_args = {'deviceRoot': options.remote_test_root}
         dm_args['retryLimit'] = retryLimit
         if options.device_ip:
             dm_args['host'] = options.device_ip
             dm_args['port'] = options.device_port
+        if options.adb_path:
+            dm_args['adbPath'] = options.adb_path
         if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug':
             dm_args['logLevel'] = logging.DEBUG # noqa python 2 / 3
         dm = devicemanagerADB.DeviceManagerADB(**dm_args)
     except:
         if options.with_b2g_emulator:
             runner.cleanup()
             runner.wait()
         raise
--- a/testing/xpcshell/mach_commands.py
+++ b/testing/xpcshell/mach_commands.py
@@ -140,36 +140,36 @@ class XPCShellRunner(MozbuildObject):
         if not result and not xpcshell.sequential:
             print("Tests were run in parallel. Try running with --sequential "
                   "to make sure the failures were not caused by this.")
         return int(not result)
 
 
 class AndroidXPCShellRunner(MozbuildObject):
     """Get specified DeviceManager"""
-    def get_devicemanager(self, ip, port, remote_test_root):
+    def get_devicemanager(self, ip, port, remote_test_root, adb_path):
         import mozdevice
         dm = None
         if ip:
-            dm = mozdevice.DroidADB(ip, port, packageName=None, deviceRoot=remote_test_root)
+            dm = mozdevice.DroidADB(ip, port, packageName=None, deviceRoot=remote_test_root, adbPath=adb_path)
         else:
-            dm = mozdevice.DroidADB(packageName=None, deviceRoot=remote_test_root)
+            dm = mozdevice.DroidADB(packageName=None, deviceRoot=remote_test_root, adbPath=adb_path)
         return dm
 
     """Run Android xpcshell tests."""
     def run_test(self, **kwargs):
         # TODO Bug 794506 remove once mach integrates with virtualenv.
         build_path = os.path.join(self.topobjdir, 'build')
         if build_path not in sys.path:
             sys.path.append(build_path)
 
         import remotexpcshelltests
 
         dm = self.get_devicemanager(kwargs["deviceIP"], kwargs["devicePort"],
-                                    kwargs["remoteTestRoot"])
+                                    kwargs["remoteTestRoot"], kwargs["adbPath"])
 
         log = kwargs.pop("log")
         self.log_manager.enable_unstructured()
 
         if kwargs["xpcshell"] is None:
             kwargs["xpcshell"] = "xpcshell"
 
         if not kwargs["objdir"]:
@@ -250,18 +250,20 @@ class MachCommands(MachCommandBase):
                                                              params,
                                                              {"mach": sys.stdout},
                                                              {"verbose": True})
 
         if not params['threadCount']:
             params['threadCount'] = int((cpu_count() * 3) / 2)
 
         if conditions.is_android(self):
-            from mozrunner.devices.android_device import verify_android_device
+            from mozrunner.devices.android_device import verify_android_device, get_adb_path
             verify_android_device(self)
+            if not params['adbPath']:
+                params['adbPath'] = get_adb_path(self)
             xpcshell = self._spawn(AndroidXPCShellRunner)
         else:
             xpcshell = self._spawn(XPCShellRunner)
         xpcshell.cwd = self._mach_context.cwd
 
         try:
             return xpcshell.run_test(**params)
         except InvalidTestPathError as e:
--- a/testing/xpcshell/remotexpcshelltests.py
+++ b/testing/xpcshell/remotexpcshelltests.py
@@ -596,16 +596,18 @@ def main():
                                     {"tbpl": sys.stdout})
 
     dm_args = {'deviceRoot': options['remoteTestRoot']}
     if options['deviceIP']:
         dm_args['host'] = options['deviceIP']
         dm_args['port'] = options['devicePort']
     if options['log_tbpl_level'] == 'debug' or options['log_mach_level'] == 'debug':
         dm_args['logLevel'] = logging.DEBUG
+    if options['adbPath']:
+        dm_args['adbPath'] = adbPath
     dm = mozdevice.DroidADB(**dm_args)
 
     if options['interactive'] and not options['testPath']:
         print("Error: You must specify a test filename in interactive mode!", file=sys.stderr)
         sys.exit(1)
 
     if options['xpcshell'] is None:
         options['xpcshell'] = "xpcshell"
--- a/testing/xpcshell/xpcshellcommandline.py
+++ b/testing/xpcshell/xpcshellcommandline.py
@@ -144,16 +144,19 @@ def add_remote_arguments(parser):
                         default=20701, help="port of remote device to test")
 
     parser.add_argument("--objdir", action="store", type=str, dest="objdir",
                         help="local objdir, containing xpcshell binaries")
 
     parser.add_argument("--apk", action="store", type=str, dest="localAPK",
                         help="local path to Fennec APK")
 
+    parser.add_argument("--adbPath", action="store", type=str, dest="adbPath",
+                        help="Path to adb")
+
     parser.add_argument("--noSetup", action="store_false", dest="setup", default=True,
                         help="do not copy any files to device (to be used only if "
                              "device is already setup)")
 
     parser.add_argument("--local-lib-dir", action="store", type=str, dest="localLib",
                         help="local path to library directory")
 
     parser.add_argument("--local-bin-dir", action="store", type=str, dest="localBin",