Bug 1440714 - Convert Android xpcshell test harness to adb.py; r=bc
authorGeoff Brown <gbrown@mozilla.com>
Sat, 17 Mar 2018 09:28:23 -0600
changeset 408687 6ec4bc1d3720b22da681ba83b352b056909fb5a1
parent 408686 e4470b1b5108d0d7afde070920e48c2d185808ad
child 408688 79b40369822f20507569bacefd6a4ee6b8f29871
push id101004
push usergbrown@mozilla.com
push dateSat, 17 Mar 2018 15:28:39 +0000
treeherdermozilla-inbound@6ec4bc1d3720 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbc
bugs1440714
milestone61.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 1440714 - Convert Android xpcshell test harness to adb.py; r=bc
testing/xpcshell/mach_commands.py
testing/xpcshell/remotexpcshelltests.py
testing/xpcshell/xpcshellcommandline.py
--- a/testing/xpcshell/mach_commands.py
+++ b/testing/xpcshell/mach_commands.py
@@ -139,40 +139,25 @@ 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, adb_path):
-        import mozdevice
-        dm = None
-        if ip:
-            dm = mozdevice.DroidADB(ip, port, packageName=None, deviceRoot=remote_test_root,
-                                    adbPath=adb_path)
-        else:
-            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["adbPath"])
-
         log = kwargs.pop("log")
         self.log_manager.enable_unstructured()
 
         if kwargs["xpcshell"] is None:
             kwargs["xpcshell"] = "xpcshell"
 
         if not kwargs["objdir"]:
             kwargs["objdir"] = self.topobjdir
@@ -202,17 +187,17 @@ class AndroidXPCShellRunner(MozbuildObje
                     print ("using APK: %s" % kwargs["localAPK"])
                     break
             else:
                 raise Exception("APK not found in objdir. You must specify an APK.")
 
         if not kwargs["sequential"]:
             kwargs["sequential"] = True
 
-        xpcshell = remotexpcshelltests.XPCShellRemote(dm, kwargs, log)
+        xpcshell = remotexpcshelltests.XPCShellRemote(kwargs, log)
 
         result = xpcshell.runTests(kwargs, testClass=remotexpcshelltests.RemoteXPCShellTestThread,
                                    mobileArgs=xpcshell.mobileArgs)
 
         self.log_manager.disable_unstructured()
 
         return int(not result)
 
--- a/testing/xpcshell/remotexpcshelltests.py
+++ b/testing/xpcshell/remotexpcshelltests.py
@@ -1,57 +1,53 @@
 #!/usr/bin/env python
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function
 
-import logging
-import posixpath
+from argparse import Namespace
 import os
+import posixpath
+import shutil
+import subprocess
 import sys
-import subprocess
 import runxpcshelltests as xpcshell
 import tempfile
 import time
-from argparse import Namespace
 from zipfile import ZipFile
-from mozlog import commandline
-import shutil
-import mozdevice
+
+from mozdevice import ADBAndroid, ADBDevice
 import mozfile
 import mozinfo
+from mozlog import commandline
 
 from xpcshellcommandline import parser_remote
 
 here = os.path.dirname(os.path.abspath(__file__))
 
 
-def remoteJoin(path1, path2):
-    return posixpath.join(path1, path2)
-
-
 class RemoteXPCShellTestThread(xpcshell.XPCShellTestThread):
     def __init__(self, *args, **kwargs):
         xpcshell.XPCShellTestThread.__init__(self, *args, **kwargs)
 
         self.shellReturnCode = None
         # embed the mobile params from the harness into the TestThread
         mobileArgs = kwargs.get('mobileArgs')
         for key in mobileArgs:
             setattr(self, key, mobileArgs[key])
 
     def buildCmdTestFile(self, name):
         remoteDir = self.remoteForLocal(os.path.dirname(name))
         if remoteDir == self.remoteHere:
             remoteName = os.path.basename(name)
         else:
-            remoteName = remoteJoin(remoteDir, os.path.basename(name))
+            remoteName = posixpath.join(remoteDir, os.path.basename(name))
         return ['-e', 'const _TEST_FILE = ["%s"];' %
                 remoteName.replace('\\', '/')]
 
     def remoteForLocal(self, local):
         for mapping in self.pathMapping:
             if (os.path.abspath(mapping.local) == os.path.abspath(local)):
                 return mapping.remote
         return local
@@ -64,33 +60,33 @@ class RemoteXPCShellTestThread(xpcshell.
 
     def setupPluginsDir(self):
         if not os.path.isdir(self.pluginsPath):
             return None
 
         # making sure tmp dir is set up
         self.setupTempDir()
 
-        pluginsDir = remoteJoin(self.remoteTmpDir, "plugins")
-        self.device.pushDir(self.pluginsPath, pluginsDir)
+        pluginsDir = posixpath.join(self.remoteTmpDir, "plugins")
+        self.device.push(self.pluginsPath, pluginsDir)
         if self.interactive:
             self.log.info("plugins dir is %s" % pluginsDir)
         return pluginsDir
 
     def setupProfileDir(self):
         self.clearRemoteDir(self.profileDir)
         if self.interactive or self.singleFile:
             self.log.info("profile dir is %s" % self.profileDir)
         return self.profileDir
 
     def setupMozinfoJS(self):
         local = tempfile.mktemp()
         mozinfo.output_to_file(local)
-        mozInfoJSPath = remoteJoin(self.profileDir, "mozinfo.json")
-        self.device.pushFile(local, mozInfoJSPath)
+        mozInfoJSPath = posixpath.join(self.profileDir, "mozinfo.json")
+        self.device.push(local, mozInfoJSPath)
         os.remove(local)
         return mozInfoJSPath
 
     def logCommand(self, name, completeCmd, testdir):
         self.log.info("%s | full command: %r" % (name, completeCmd))
         self.log.info("%s | current directory: %r" % (name, self.remoteHere))
         self.log.info("%s | environment: %s" % (name, self.env))
 
@@ -100,34 +96,34 @@ class RemoteXPCShellTestThread(xpcshell.
         Obtains lists of head- files.  Returns a list of head files.
         """
         def sanitize_list(s, kind):
             for f in s.strip().split(' '):
                 f = f.strip()
                 if len(f) < 1:
                     continue
 
-                path = remoteJoin(self.remoteHere, f)
+                path = posixpath.join(self.remoteHere, f)
 
                 # skip check for file existence: the convenience of discovering
                 # a missing file does not justify the time cost of the round trip
                 # to the device
                 yield path
 
         self.remoteHere = self.remoteForLocal(test['here'])
 
         headlist = test.get('head', '')
         return list(sanitize_list(headlist, 'head'))
 
     def buildXpcsCmd(self):
         # change base class' paths to remote paths and use base class to build command
-        self.xpcshell = remoteJoin(self.remoteBinDir, "xpcw")
-        self.headJSPath = remoteJoin(self.remoteScriptsDir, 'head.js')
-        self.httpdJSPath = remoteJoin(self.remoteComponentsDir, 'httpd.js')
-        self.httpdManifest = remoteJoin(self.remoteComponentsDir, 'httpd.manifest')
+        self.xpcshell = posixpath.join(self.remoteBinDir, "xpcw")
+        self.headJSPath = posixpath.join(self.remoteScriptsDir, 'head.js')
+        self.httpdJSPath = posixpath.join(self.remoteComponentsDir, 'httpd.js')
+        self.httpdManifest = posixpath.join(self.remoteComponentsDir, 'httpd.manifest')
         self.testingModulesDir = self.remoteModulesDir
         self.testharnessdir = self.remoteScriptsDir
         xpcshell.XPCShellTestThread.buildXpcsCmd(self)
         # remove "-g <dir> -a <dir>" and add "--greomni <apk>"
         del(self.xpcsCmd[1:5])
         if self.options['localAPK']:
             self.xpcsCmd.insert(3, '--greomni')
             self.xpcsCmd.insert(4, self.remoteAPK)
@@ -140,142 +136,146 @@ class RemoteXPCShellTestThread(xpcshell.
               self.xpcsCmd]
 
     def killTimeout(self, proc):
         self.kill(proc)
 
     def launchProcess(self, cmd, stdout, stderr, env, cwd, timeout=None):
         self.timedout = False
         cmd.insert(1, self.remoteHere)
-        outputFile = "xpcshelloutput"
-        with open(outputFile, 'w+') as f:
-            try:
-                self.shellReturnCode = self.device.shell(cmd, f, timeout=timeout+10)
-            except mozdevice.DMError as e:
-                if self.timedout:
-                    # If the test timed out, there is a good chance the device
-                    # manager also timed out and raised DMError.
-                    # Ignore the DMError to simplify the error report.
-                    self.shellReturnCode = None
-                    pass
-                else:
-                    raise e
+        cmd = ADBDevice._escape_command_line(cmd)
+        try:
+            adb_process = self.device.shell(cmd, timeout=timeout+10)
+            output_file = adb_process.stdout_file
+            self.shellReturnCode = adb_process.exitcode
+        except Exception as e:
+            if self.timedout:
+                # If the test timed out, there is a good chance the shell
+                # call also timed out and raised this Exception.
+                # Ignore this exception to simplify the error report.
+                self.shellReturnCode = None
+            else:
+                raise e
         # The device manager may have timed out waiting for xpcshell.
         # Guard against an accumulation of hung processes by killing
         # them here. Note also that IPC tests may spawn new instances
         # of xpcshell.
-        self.device.killProcess("xpcshell", native=True)
-        return outputFile
+        self.device.pkill("xpcshell")
+        return output_file
 
     def checkForCrashes(self,
                         dump_directory,
                         symbols_path,
                         test_name=None):
-        if not self.device.dirExists(self.remoteMinidumpDir):
+        if not self.device.is_dir(self.remoteMinidumpDir):
             # The minidumps directory is automatically created when Fennec
             # (first) starts, so its lack of presence is a hint that
             # something went wrong.
             print("Automation Error: No crash directory (%s) found on remote device" %
                   self.remoteMinidumpDir)
             # Whilst no crash was found, the run should still display as a failure
             return True
         with mozfile.TemporaryDirectory() as dumpDir:
-            self.device.getDirectory(self.remoteMinidumpDir, dumpDir)
+            self.device.pull(self.remoteMinidumpDir, dumpDir)
             crashed = xpcshell.XPCShellTestThread.checkForCrashes(
                   self, dumpDir, symbols_path, test_name)
             self.clearRemoteDir(self.remoteMinidumpDir)
         return crashed
 
     def communicate(self, proc):
-        f = open(proc, "r")
+        f = proc
         contents = f.read()
         f.close()
-        os.remove(proc)
         return contents, ""
 
     def poll(self, proc):
-        if self.device.processExist("xpcshell") is None:
+        if not self.device.process_exist("xpcshell"):
             return self.getReturnCode(proc)
         # Process is still running
         return None
 
     def kill(self, proc):
-        return self.device.killProcess("xpcshell", native=True)
+        return self.device.pkill("xpcshell")
 
     def getReturnCode(self, proc):
         if self.shellReturnCode is not None:
             return self.shellReturnCode
         else:
             return -1
 
     def removeDir(self, dirname):
-        self.device.removeDir(dirname)
+        self.device.rm(dirname, recursive=True)
 
     def clearRemoteDir(self, remoteDir):
         out = ""
         try:
-            out = self.device.shellCheckOutput([self.remoteClearDirScript, remoteDir])
-        except mozdevice.DMError:
+            out = self.device.shell_output("%s %s" % (self.remoteClearDirScript, remoteDir))
+        except Exception:
             self.log.info("unable to delete %s: '%s'" % (remoteDir, str(out)))
             self.log.info("retrying after 10 seconds...")
             time.sleep(10)
             try:
-                out = self.device.shellCheckOutput([self.remoteClearDirScript, remoteDir])
-            except mozdevice.DMError:
+                out = self.device.shell_output("%s %s" % (self.remoteClearDirScript, remoteDir))
+            except Exception:
                 self.log.error("failed to delete %s: '%s'" % (remoteDir, str(out)))
 
     # TODO: consider creating a separate log dir.  We don't have the test file structure,
     # so we use filename.log.  Would rather see ./logs/filename.log
     def createLogFile(self, test, stdout):
         try:
             f = None
             filename = test.replace('\\', '/').split('/')[-1] + ".log"
             f = open(filename, "w")
             f.write(stdout)
 
         finally:
             if f is not None:
                 f.close()
 
 
-# A specialization of XPCShellTests that runs tests on an Android device
-# via devicemanager.
+# A specialization of XPCShellTests that runs tests on an Android device.
 class XPCShellRemote(xpcshell.XPCShellTests, object):
 
-    def __init__(self, devmgr, options, log):
+    def __init__(self, options, log):
         xpcshell.XPCShellTests.__init__(self, log)
 
+        self.options = options
+        verbose = False
+        if options['log_tbpl_level'] == 'debug' or options['log_mach_level'] == 'debug':
+            verbose = True
+        self.device = ADBAndroid(adb=options['adbPath'],
+                                 device=options['deviceSerial'],
+                                 test_root=options['remoteTestRoot'],
+                                 verbose=verbose)
+        self.remoteTestRoot = posixpath.join(self.device.test_root, "xpc")
         # Add Android version (SDK level) to mozinfo so that manifest entries
         # can be conditional on android_version.
-        androidVersion = devmgr.shellCheckOutput(['getprop', 'ro.build.version.sdk'])
+        androidVersion = self.device.get_prop('ro.build.version.sdk')
         mozinfo.info['android_version'] = androidVersion
 
         self.localLib = options['localLib']
         self.localBin = options['localBin']
-        self.options = options
-        self.device = devmgr
         self.pathMapping = []
-        self.remoteTestRoot = "%s/xpc" % self.device.deviceRoot
         # remoteBinDir contains xpcshell and its wrapper script, both of which must
         # be executable. Since +x permissions cannot usually be set on /mnt/sdcard,
         # and the test root may be on /mnt/sdcard, remoteBinDir is set to be on
         # /data/local, always.
-        self.remoteBinDir = "/data/local/xpcb"
+        self.remoteBinDir = posixpath.join("/data", "local", "xpcb")
         # Terse directory names are used here ("c" for the components directory)
         # to minimize the length of the command line used to execute
         # xpcshell on the remote device. adb has a limit to the number
         # of characters used in a shell command, and the xpcshell command
         # line can be quite complex.
-        self.remoteTmpDir = remoteJoin(self.remoteTestRoot, "tmp")
+        self.remoteTmpDir = posixpath.join(self.remoteTestRoot, "tmp")
         self.remoteScriptsDir = self.remoteTestRoot
-        self.remoteComponentsDir = remoteJoin(self.remoteTestRoot, "c")
-        self.remoteModulesDir = remoteJoin(self.remoteTestRoot, "m")
-        self.remoteMinidumpDir = remoteJoin(self.remoteTestRoot, "minidumps")
-        self.remoteClearDirScript = remoteJoin(self.remoteBinDir, "cleardir")
-        self.profileDir = remoteJoin(self.remoteTestRoot, "p")
+        self.remoteComponentsDir = posixpath.join(self.remoteTestRoot, "c")
+        self.remoteModulesDir = posixpath.join(self.remoteTestRoot, "m")
+        self.remoteMinidumpDir = posixpath.join(self.remoteTestRoot, "minidumps")
+        self.remoteClearDirScript = posixpath.join(self.remoteBinDir, "cleardir")
+        self.profileDir = posixpath.join(self.remoteTestRoot, "p")
         self.remoteDebugger = options['debugger']
         self.remoteDebuggerArgs = options['debuggerArgs']
         self.testingModulesDir = options['testingModulesDir']
 
         self.env = {}
 
         if options['objdir']:
             self.xpcDir = os.path.join(options['objdir'], "_tests/xpcshell")
@@ -289,17 +289,18 @@ class XPCShellRemote(xpcshell.XPCShellTe
             self.localAPKContents = ZipFile(options['localAPK'])
         if options['setup']:
             self.setupTestDir()
             self.setupUtilities()
             self.setupModules()
         self.setupMinidumpDir()
         self.remoteAPK = None
         if options['localAPK']:
-            self.remoteAPK = remoteJoin(self.remoteBinDir, os.path.basename(options['localAPK']))
+            self.remoteAPK = posixpath.join(self.remoteBinDir,
+                                            os.path.basename(options['localAPK']))
             self.setAppRoot()
 
         # data that needs to be passed to the RemoteXPCShellTestThread
         self.mobileArgs = {
             'device': self.device,
             'remoteBinDir': self.remoteBinDir,
             'remoteScriptsDir': self.remoteScriptsDir,
             'remoteComponentsDir': self.remoteComponentsDir,
@@ -331,36 +332,36 @@ class XPCShellRemote(xpcshell.XPCShellTe
             f.write("export %s=%s\n" % (envkey, envval))
         f.writelines([
             "cd $1\n",
             "echo xpcw: cd $1\n",
             "shift\n",
             "echo xpcw: xpcshell \"$@\"\n",
             "%s/xpcshell \"$@\"\n" % self.remoteBinDir])
         f.close()
-        remoteWrapper = remoteJoin(self.remoteBinDir, "xpcw")
-        self.device.pushFile(localWrapper, remoteWrapper)
+        remoteWrapper = posixpath.join(self.remoteBinDir, "xpcw")
+        self.device.push(localWrapper, remoteWrapper)
         os.remove(localWrapper)
 
         # Removing and re-creating a directory is a common operation which
         # can be implemented more efficiently with a shell script.
         localWrapper = tempfile.mktemp()
         f = open(localWrapper, "w")
         # The directory may not exist initially, so rm may fail. 'rm -f' is not
         # supported on some Androids. Similarly, 'test' and 'if [ -d ]' are not
         # universally available, so we just ignore errors from rm.
         f.writelines([
             "#!/system/bin/sh\n",
             "rm -r \"$1\"\n",
             "mkdir \"$1\"\n"])
         f.close()
-        self.device.pushFile(localWrapper, self.remoteClearDirScript)
+        self.device.push(localWrapper, self.remoteClearDirScript)
         os.remove(localWrapper)
 
-        self.device.chmodDir(self.remoteBinDir)
+        self.device.chmod(self.remoteBinDir, recursive=True)
 
     def buildEnvironment(self):
         self.buildCoreEnvironment()
         self.setLD_LIBRARY_PATH()
         self.env["MOZ_LINKER_CACHE"] = self.remoteBinDir
         if self.options['localAPK'] and self.appRoot:
             self.env["GRE_HOME"] = self.appRoot
         self.env["XPCSHELL_TEST_PROFILE_DIR"] = self.profileDir
@@ -375,163 +376,149 @@ class XPCShellRemote(xpcshell.XPCShellTe
         # Determine the application root directory associated with the package
         # name used by the Fennec APK.
         self.appRoot = None
         packageName = None
         if self.options['localAPK']:
             try:
                 packageName = self.localAPKContents.read("package-name.txt")
                 if packageName:
-                    self.appRoot = self.device.getAppRoot(packageName.strip())
+                    self.appRoot = posixpath.join("/data", "data", packageName.strip())
             except Exception as detail:
                 print("unable to determine app root: " + str(detail))
                 pass
         return None
 
     def setupUtilities(self):
-        if (not self.device.dirExists(self.remoteBinDir)):
-            # device.mkDir may fail here where shellCheckOutput may succeed -- see bug 817235
-            try:
-                self.device.shellCheckOutput(["mkdir", self.remoteBinDir])
-            except mozdevice.DMError:
-                # Might get a permission error; try again as root, if available
-                self.device.shellCheckOutput(["mkdir", self.remoteBinDir], root=True)
-                self.device.shellCheckOutput(["chmod", "777", self.remoteBinDir], root=True)
-
-        remotePrefDir = remoteJoin(self.remoteBinDir, "defaults/pref")
-        if (self.device.dirExists(self.remoteTmpDir)):
-            self.device.removeDir(self.remoteTmpDir)
-        self.device.mkDir(self.remoteTmpDir)
-        if (not self.device.dirExists(remotePrefDir)):
-            self.device.mkDirs(remoteJoin(remotePrefDir, "extra"))
-        if (not self.device.dirExists(self.remoteScriptsDir)):
-            self.device.mkDir(self.remoteScriptsDir)
-        if (not self.device.dirExists(self.remoteComponentsDir)):
-            self.device.mkDir(self.remoteComponentsDir)
+        self.device.rm(self.remoteTmpDir, force=True, recursive=True)
+        self.device.mkdir(self.remoteTmpDir)
+        self.device.rm(self.remoteBinDir, force=True, recursive=True)
+        remotePrefDir = posixpath.join(self.remoteBinDir, "defaults", "pref")
+        self.device.mkdir(posixpath.join(remotePrefDir, "extra"), parents=True)
+        self.device.mkdir(self.remoteScriptsDir, parents=True)
+        self.device.mkdir(self.remoteComponentsDir, parents=True)
 
         local = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'head.js')
-        remoteFile = remoteJoin(self.remoteScriptsDir, "head.js")
-        self.device.pushFile(local, remoteFile)
+        remoteFile = posixpath.join(self.remoteScriptsDir, "head.js")
+        self.device.push(local, remoteFile)
 
         # The xpcshell binary is required for all tests. Additional binaries
         # are required for some tests. This list should be similar to
         # TEST_HARNESS_BINS in testing/mochitest/Makefile.in.
         binaries = ["xpcshell",
                     "ssltunnel",
                     "certutil",
                     "pk12util",
                     "BadCertServer",
                     "OCSPStaplingServer",
                     "GenerateOCSPResponse",
                     "SymantecSanctionsServer"]
         for fname in binaries:
             local = os.path.join(self.localBin, fname)
             if os.path.isfile(local):
                 print("Pushing %s.." % fname, file=sys.stderr)
-                remoteFile = remoteJoin(self.remoteBinDir, fname)
-                self.device.pushFile(local, remoteFile)
+                remoteFile = posixpath.join(self.remoteBinDir, fname)
+                self.device.push(local, remoteFile)
             else:
                 print("*** Expected binary %s not found in %s!" %
                       (fname, self.localBin), file=sys.stderr)
 
         local = os.path.join(self.localBin, "components/httpd.js")
-        remoteFile = remoteJoin(self.remoteComponentsDir, "httpd.js")
-        self.device.pushFile(local, remoteFile)
+        remoteFile = posixpath.join(self.remoteComponentsDir, "httpd.js")
+        self.device.push(local, remoteFile)
 
         local = os.path.join(self.localBin, "components/httpd.manifest")
-        remoteFile = remoteJoin(self.remoteComponentsDir, "httpd.manifest")
-        self.device.pushFile(local, remoteFile)
+        remoteFile = posixpath.join(self.remoteComponentsDir, "httpd.manifest")
+        self.device.push(local, remoteFile)
 
         local = os.path.join(self.localBin, "components/test_necko.xpt")
-        remoteFile = remoteJoin(self.remoteComponentsDir, "test_necko.xpt")
-        self.device.pushFile(local, remoteFile)
+        remoteFile = posixpath.join(self.remoteComponentsDir, "test_necko.xpt")
+        self.device.push(local, remoteFile)
 
         if self.options['localAPK']:
-            remoteFile = remoteJoin(self.remoteBinDir, os.path.basename(self.options['localAPK']))
-            self.device.pushFile(self.options['localAPK'], remoteFile)
+            remoteFile = posixpath.join(self.remoteBinDir,
+                                        os.path.basename(self.options['localAPK']))
+            self.device.push(self.options['localAPK'], remoteFile)
 
         self.pushLibs()
 
     def pushLibs(self):
         pushed_libs_count = 0
         if self.options['localAPK']:
             try:
                 dir = tempfile.mkdtemp()
                 for info in self.localAPKContents.infolist():
                     if info.filename.endswith(".so"):
                         print("Pushing %s.." % info.filename, file=sys.stderr)
-                        remoteFile = remoteJoin(self.remoteBinDir, os.path.basename(info.filename))
+                        remoteFile = posixpath.join(self.remoteBinDir,
+                                                    os.path.basename(info.filename))
                         self.localAPKContents.extract(info, dir)
                         localFile = os.path.join(dir, info.filename)
                         with open(localFile) as f:
                             # Decompress xz-compressed file.
                             if f.read(5)[1:] == '7zXZ':
                                 cmd = ['xz', '-df', '--suffix', '.so', localFile]
                                 subprocess.check_output(cmd)
                                 # xz strips the ".so" file suffix.
                                 os.rename(localFile[:-3], localFile)
-                        self.device.pushFile(localFile, remoteFile)
+                        self.device.push(localFile, remoteFile)
                         pushed_libs_count += 1
             finally:
                 shutil.rmtree(dir)
             return pushed_libs_count
 
         for file in os.listdir(self.localLib):
             if (file.endswith(".so")):
                 print("Pushing %s.." % file, file=sys.stderr)
                 if 'libxul' in file:
                     print("This is a big file, it could take a while.", file=sys.stderr)
                 localFile = os.path.join(self.localLib, file)
-                remoteFile = remoteJoin(self.remoteBinDir, file)
-                self.device.pushFile(localFile, remoteFile)
+                remoteFile = posixpath.join(self.remoteBinDir, file)
+                self.device.push(localFile, remoteFile)
                 pushed_libs_count += 1
 
         # Additional libraries may be found in a sub-directory such as "lib/armeabi-v7a"
         localArmLib = os.path.join(self.localLib, "lib")
         if os.path.exists(localArmLib):
             for root, dirs, files in os.walk(localArmLib):
                 for file in files:
                     if (file.endswith(".so")):
                         print("Pushing %s.." % file, file=sys.stderr)
                         localFile = os.path.join(root, file)
-                        remoteFile = remoteJoin(self.remoteBinDir, file)
-                        self.device.pushFile(localFile, remoteFile)
+                        remoteFile = posixpath.join(self.remoteBinDir, file)
+                        self.device.push(localFile, remoteFile)
                         pushed_libs_count += 1
 
         return pushed_libs_count
 
     def setupModules(self):
         if self.testingModulesDir:
-            self.device.pushDir(self.testingModulesDir, self.remoteModulesDir)
+            self.device.push(self.testingModulesDir, self.remoteModulesDir)
 
     def setupTestDir(self):
         print('pushing %s' % self.xpcDir)
-        try:
-            # The tests directory can be quite large: 5000 files and growing!
-            # Sometimes - like on a low-end aws instance running an emulator - the push
-            # may exceed the default 5 minute timeout, so we increase it here to 10 minutes.
-            self.device.pushDir(self.xpcDir, self.remoteScriptsDir, timeout=600, retryLimit=10)
-        except TypeError:
-            # Foopies have an older mozdevice ver without retryLimit
-            self.device.pushDir(self.xpcDir, self.remoteScriptsDir)
+        # The tests directory can be quite large: 5000 files and growing!
+        # Sometimes - like on a low-end aws instance running an emulator - the push
+        # may exceed the default 5 minute timeout, so we increase it here to 10 minutes.
+        self.device.rm(self.remoteTestRoot, force=True, recursive=True)
+        self.device.push(self.xpcDir, self.remoteScriptsDir, timeout=600)
 
     def setupMinidumpDir(self):
-        if self.device.dirExists(self.remoteMinidumpDir):
-            self.device.removeDir(self.remoteMinidumpDir)
-        self.device.mkDir(self.remoteMinidumpDir)
+        self.device.rm(self.remoteMinidumpDir, force=True, recursive=True)
+        self.device.mkdir(self.remoteMinidumpDir)
 
     def buildTestList(self, test_tags=None, test_paths=None, verify=False):
         xpcshell.XPCShellTests.buildTestList(
             self, test_tags=test_tags, test_paths=test_paths, verify=verify)
         uniqueTestPaths = set([])
         for test in self.alltests:
             uniqueTestPaths.add(test['here'])
         for testdir in uniqueTestPaths:
             abbrevTestDir = os.path.relpath(testdir, self.xpcDir)
-            remoteScriptDir = remoteJoin(self.remoteScriptsDir, abbrevTestDir)
+            remoteScriptDir = posixpath.join(self.remoteScriptsDir, abbrevTestDir)
             self.pathMapping.append(PathMapping(testdir, remoteScriptDir))
 
 
 def verifyRemoteOptions(parser, options):
     if isinstance(options, Namespace):
         options = vars(options)
 
     if options['localLib'] is None:
@@ -591,34 +578,24 @@ def main():
             print("Error: please specify an APK", file=sys.stderr)
             sys.exit(1)
 
     options = verifyRemoteOptions(parser, options)
     log = commandline.setup_logging("Remote XPCShell",
                                     options,
                                     {"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'] = options['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"
 
-    xpcsh = XPCShellRemote(dm, options, log)
+    xpcsh = XPCShellRemote(options, log)
 
     # we don't run concurrent tests on mobile
     options['sequential'] = True
 
     if not xpcsh.runTests(options,
                           testClass=RemoteXPCShellTestThread,
                           mobileArgs=xpcsh.mobileArgs):
         sys.exit(1)
--- a/testing/xpcshell/xpcshellcommandline.py
+++ b/testing/xpcshell/xpcshellcommandline.py
@@ -132,29 +132,27 @@ def add_common_arguments(parser):
                              "ways, to see if there are intermittent failures.")
     parser.add_argument("--verify-max-time",
                         dest="verifyMaxTime",
                         type=int, default=3600,
                         help="Maximum time, in seconds, to run in --verify mode.")
 
 
 def add_remote_arguments(parser):
-    parser.add_argument("--deviceIP", action="store", type=str, dest="deviceIP",
-                        help="ip address of remote device to test")
-
-    parser.add_argument("--devicePort", action="store", type=str, dest="devicePort",
-                        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("--deviceSerial", action="store", type=str, dest="deviceSerial",
+                        help="serial ID of device")
+
     parser.add_argument("--adbPath", action="store", type=str, dest="adbPath",
+                        default="adb",
                         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")