Bug 810347 - Provide option for setting remote test root; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Thu, 20 Dec 2012 09:11:11 -0700
changeset 125794 43dd443e1ba94663d0cbabceb8b912ead391e608
parent 125793 53ade07f41ce6eb177bf974a9a73cf1dae4f82c0
child 125795 4925a90ee7ffa212d5536ed23f8327d22a53a1ff
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersjmaher
bugs810347
milestone20.0a1
Bug 810347 - Provide option for setting remote test root; r=jmaher
layout/tools/reftest/remotereftest.py
layout/tools/reftest/runreftestb2g.py
testing/mochitest/runtestsb2g.py
testing/mochitest/runtestsremote.py
testing/xpcshell/remotexpcshelltests.py
testing/xpcshell/runtestsb2g.py
--- a/layout/tools/reftest/remotereftest.py
+++ b/layout/tools/reftest/remotereftest.py
@@ -19,17 +19,16 @@ from remoteautomation import RemoteAutom
 
 class RemoteOptions(ReftestOptions):
     def __init__(self, automation):
         ReftestOptions.__init__(self, automation)
 
         defaults = {}
         defaults["logFile"] = "reftest.log"
         # app, xrePath and utilityPath variables are set in main function
-        defaults["remoteTestRoot"] = None
         defaults["app"] = ""
         defaults["xrePath"] = ""
         defaults["utilityPath"] = ""
 
         self.add_option("--remote-app-path", action="store",
                     type = "string", dest = "remoteAppPath",
                     help = "Path to remote executable relative to device root using only forward slashes.  Either this or app must be specified, but not both.")
         defaults["remoteAppPath"] = None
@@ -82,23 +81,29 @@ class RemoteOptions(ReftestOptions):
                     help = "test with a bootstrap addon required for native Fennec")
         defaults["bootstrap"] = False
 
         self.add_option("--dm_trans", action="store",
                     type = "string", dest = "dm_trans",
                     help = "the transport to use to communicate with device: [adb|sut]; default=sut")
         defaults["dm_trans"] = "sut"
 
+        self.add_option("--remoteTestRoot", action = "store",
+                    type = "string", dest = "remoteTestRoot",
+                    help = "remote directory to use as test root (eg. /mnt/sdcard/tests or /data/local/tests)")
+        defaults["remoteTestRoot"] = None
+
         defaults["localLogName"] = None
 
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options):
         # Ensure our defaults are set properly for everything we can infer
-        options.remoteTestRoot = self._automation._devicemanager.getDeviceRoot() + '/reftest'
+        if not options.remoteTestRoot:
+            options.remoteTestRoot = self._automation._devicemanager.getDeviceRoot() + '/reftest'
         options.remoteProfile = options.remoteTestRoot + "/profile"
 
         # Verify that our remotewebserver is set properly
         if (options.remoteWebServer == None or
             options.remoteWebServer == '127.0.0.1'):
             print "ERROR: Either you specified the loopback for the remote webserver or ",
             print "your local IP cannot be detected.  Please provide the local ip in --remote-webserver"
             return None
@@ -372,21 +377,21 @@ def main(args):
 
     if (options.deviceIP == None):
         print "Error: you must provide a device IP to connect to via the --device option"
         return 1
 
     try:
         if (options.dm_trans == "adb"):
             if (options.deviceIP):
-                dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort)
+                dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
             else:
-                dm = devicemanagerADB.DeviceManagerADB(None, None)
+                dm = devicemanagerADB.DeviceManagerADB(None, None, deviceRoot=options.remoteTestRoot)
         else:
-            dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort)
+            dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
     except devicemanager.DMError:
         print "Error: exception while initializing devicemanager.  Most likely the device is not in a testable state."
         return 1
 
     automation.setDeviceManager(dm)
 
     if (options.remoteProductName != None):
         automation.setProduct(options.remoteProductName)
--- a/layout/tools/reftest/runreftestb2g.py
+++ b/layout/tools/reftest/runreftestb2g.py
@@ -104,26 +104,27 @@ class B2GOptions(ReftestOptions):
                         type="string", dest="geckoPath",
                         help="the path to a gecko distribution that should "
                         "be installed on the emulator prior to test")
         defaults["geckoPath"] = None
         self.add_option("--logcat-dir", action="store",
                         type="string", dest="logcat_dir",
                         help="directory to store logcat dump files")
         defaults["logcat_dir"] = None
-        defaults["remoteTestRoot"] = None
+        defaults["remoteTestRoot"] = "/data/local/tests"
         defaults["logFile"] = "reftest.log"
         defaults["autorun"] = True
         defaults["closeWhenDone"] = True
         defaults["testPath"] = ""
 
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options):
-        options.remoteTestRoot = self._automation._devicemanager.getDeviceRoot() + "/reftest"
+        if not options.remoteTestRoot:
+            options.remoteTestRoot = self._automation._devicemanager.getDeviceRoot() + "/reftest"
         options.remoteProfile = options.remoteTestRoot + "/profile"
 
         productRoot = options.remoteTestRoot + "/" + self._automation._product
         if options.utilityPath == self._automation.DIST_BIN:
             options.utilityPath = productRoot + "/bin"
 
         if options.remoteWebServer == None:
             if os.name != "nt":
@@ -212,17 +213,16 @@ class B2GReftest(RefTest):
         self.runSSLTunnel = False
         self.remoteTestRoot = options.remoteTestRoot
         self.remoteProfile = options.remoteProfile
         self._automation.setRemoteProfile(self.remoteProfile)
         self.localLogName = options.localLogName
         self.remoteLogFile = options.remoteLogFile
         self.bundlesDir = '/system/b2g/distribution/bundles'
         self.userJS = '/data/local/user.js'
-        self.testDir = '/data/local/tests'
         self.remoteMozillaPath = '/data/b2g/mozilla'
         self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini')
         self.originalProfilesIni = None
         self.scriptDir = scriptDir
         self.SERVER_STARTUP_TIMEOUT = 90
         if self._automation.IS_DEBUG_BUILD:
             self.SERVER_STARTUP_TIMEOUT = 180
 
@@ -490,17 +490,18 @@ def main(args=sys.argv[1:]):
     if options.marionette:
         host,port = options.marionette.split(':')
         kwargs['host'] = host
         kwargs['port'] = int(port)
     marionette = Marionette.getMarionetteOrExit(**kwargs)
     auto.marionette = marionette
 
     # create the DeviceManager
-    kwargs = {'adbPath': options.adbPath}
+    kwargs = {'adbPath': options.adbPath,
+              'deviceRoot': options.remoteTestRoot}
     if options.deviceIP:
         kwargs.update({'host': options.deviceIP,
                        'port': options.devicePort})
     dm = devicemanagerADB.DeviceManagerADB(**kwargs)
     auto.setDeviceManager(dm)
 
     options = parser.verifyRemoteOptions(options)
     if (options == None):
@@ -517,19 +518,16 @@ def main(args=sys.argv[1:]):
             return 1
 
     auto.setProduct("b2g")
     auto.test_script = os.path.join(SCRIPT_DIRECTORY, 'b2g_start_script.js')
     auto.test_script_args = [options.remoteWebServer, options.httpPort]
     auto.logFinish = "REFTEST TEST-START | Shutdown"
 
     reftest = B2GReftest(auto, dm, options, SCRIPT_DIRECTORY)
-    # Create /data/local/tests, to force its use by DeviceManagerADB;
-    # B2G won't run correctly with the profile installed to /mnt/sdcard.
-    dm.mkDirs(reftest.testDir)
 
     logParent = os.path.dirname(options.remoteLogFile)
     dm.mkDir(logParent);
     auto.setRemoteLog(options.remoteLogFile)
     auto.setServerInfo(options.webServer, options.httpPort, options.sslPort)
 
     # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot
     manifest = args[0]
--- a/testing/mochitest/runtestsb2g.py
+++ b/testing/mochitest/runtestsb2g.py
@@ -98,27 +98,28 @@ class B2GOptions(MochitestOptions):
                         help="the path to a gecko distribution that should "
                         "be installed on the emulator prior to test")
         defaults["geckoPath"] = None
         self.add_option("--logcat-dir", action="store",
                         type="string", dest="logcat_dir",
                         help="directory to store logcat dump files")
         defaults["logcat_dir"] = None
 
-        defaults["remoteTestRoot"] = None
+        defaults["remoteTestRoot"] = "/data/local/tests"
         defaults["logFile"] = "mochitest.log"
         defaults["autorun"] = True
         defaults["closeWhenDone"] = True
         defaults["testPath"] = ""
         defaults["extensionsToExclude"] = ["specialpowers"]
 
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options, automation):
-        options.remoteTestRoot = automation._devicemanager.getDeviceRoot()
+        if not options.remoteTestRoot:
+            options.remoteTestRoot = automation._devicemanager.getDeviceRoot()
         productRoot = options.remoteTestRoot + "/" + automation._product
 
         if options.utilityPath == self._automation.DIST_BIN:
             options.utilityPath = productRoot + "/bin"
 
         if options.remoteWebServer == None:
             if os.name != "nt":
                 options.remoteWebServer = automation.getLanIp()
@@ -195,17 +196,16 @@ class ProfileConfigParser(ConfigParser.R
             fp.write("\n")
 
 
 class B2GMochitest(Mochitest):
 
     _automation = None
     _dm = None
     localProfile = None
-    testDir = '/data/local/tests'
 
     def __init__(self, automation, devmgr, options):
         self._automation = automation
         Mochitest.__init__(self, self._automation)
         self._dm = devmgr
         self.runSSLTunnel = False
         self.remoteProfile = options.remoteTestRoot + '/profile'
         self._automation.setRemoteProfile(self.remoteProfile)
@@ -493,17 +493,17 @@ def main():
         kwargs['port'] = int(port)
 
     marionette = Marionette.getMarionetteOrExit(**kwargs)
 
     auto.marionette = marionette
 
     # create the DeviceManager
     kwargs = {'adbPath': options.adbPath,
-              'deviceRoot': B2GMochitest.testDir}
+              'deviceRoot': options.remoteTestRoot}
     if options.deviceIP:
         kwargs.update({'host': options.deviceIP,
                        'port': options.devicePort})
     dm = devicemanagerADB.DeviceManagerADB(**kwargs)
     auto.setDeviceManager(dm)
     options = parser.verifyRemoteOptions(options, auto)
     if (options == None):
         print "ERROR: Invalid options specified, use --help for a list of valid options"
--- a/testing/mochitest/runtestsremote.py
+++ b/testing/mochitest/runtestsremote.py
@@ -86,27 +86,32 @@ class RemoteOptions(MochitestOptions):
                     help = "Path to the folder where robocop.apk is located at.  Primarily used for ADB test running")
         defaults["robocopPath"] = ""
 
         self.add_option("--robocop-ids", action = "store",
                     type = "string", dest = "robocopIds",
                     help = "name of the file containing the view ID map (fennec_ids.txt)")
         defaults["robocopIds"] = ""
 
+        self.add_option("--remoteTestRoot", action = "store",
+                    type = "string", dest = "remoteTestRoot",
+                    help = "remote directory to use as test root (eg. /mnt/sdcard/tests or /data/local/tests)")
         defaults["remoteTestRoot"] = None
+
         defaults["logFile"] = "mochitest.log"
         defaults["autorun"] = True
         defaults["closeWhenDone"] = True
         defaults["testPath"] = ""
         defaults["app"] = None
 
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options, automation):
-        options.remoteTestRoot = automation._devicemanager.getDeviceRoot()
+        if not options.remoteTestRoot:
+            options.remoteTestRoot = automation._devicemanager.getDeviceRoot()
         productRoot = options.remoteTestRoot + "/" + automation._product
 
         if (options.utilityPath == self._automation.DIST_BIN):
             options.utilityPath = productRoot + "/bin"
 
         if options.remoteWebServer == None:
             if os.name != "nt":
                 options.remoteWebServer = automation.getLanIp()
@@ -434,21 +439,21 @@ class MochiRemote(Mochitest):
         
 def main():
     scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
     auto = RemoteAutomation(None, "fennec")
     parser = RemoteOptions(auto, scriptdir)
     options, args = parser.parse_args()
     if (options.dm_trans == "adb"):
         if (options.deviceIP):
-            dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort)
+            dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
         else:
-            dm = devicemanagerADB.DeviceManagerADB()
+            dm = devicemanagerADB.DeviceManagerADB(deviceRoot=options.remoteTestRoot)
     else:
-         dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort)
+         dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
     auto.setDeviceManager(dm)
     options = parser.verifyRemoteOptions(options, auto)
     if (options == None):
         print "ERROR: Invalid options specified, use --help for a list of valid options"
         sys.exit(1)
 
     productPieces = options.remoteProductName.split('.')
     if (productPieces != None):
--- a/testing/xpcshell/remotexpcshelltests.py
+++ b/testing/xpcshell/remotexpcshelltests.py
@@ -374,16 +374,21 @@ class RemoteXPCShellOptions(xpcshell.XPC
                         help = "local path to library directory")
         defaults["localLib"] = None
 
         self.add_option("--local-bin-dir", action="store",
                         type = "string", dest = "localBin",
                         help = "local path to bin directory")
         defaults["localBin"] = None
 
+        self.add_option("--remoteTestRoot", action = "store",
+                    type = "string", dest = "remoteTestRoot",
+                    help = "remote directory to use as test root (eg. /mnt/sdcard/tests or /data/local/tests)")
+        defaults["remoteTestRoot"] = None
+
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options):
         if options.localLib is None:
             if options.localAPK and options.objdir:
                 for path in ['dist/fennec', 'fennec/lib']:
                     options.localLib = os.path.join(options.objdir, path)
                     if os.path.isdir(options.localLib):
@@ -438,21 +443,21 @@ def main():
 
     if len(args) < 1 and options.manifest is None:
       print >>sys.stderr, """Usage: %s <test dirs>
            or: %s --manifest=test.manifest """ % (sys.argv[0], sys.argv[0])
       sys.exit(1)
 
     if (options.dm_trans == "adb"):
       if (options.deviceIP):
-        dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, packageName=None)
+        dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, packageName=None, deviceRoot=options.remoteTestRoot)
       else:
-        dm = devicemanagerADB.DeviceManagerADB(packageName=None)
+        dm = devicemanagerADB.DeviceManagerADB(packageName=None, deviceRoot=options.remoteTestRoot)
     else:
-      dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort)
+      dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
       if (options.deviceIP == None):
         print "Error: you must provide a device IP to connect to via the --device option"
         sys.exit(1)
 
     if options.interactive and not options.testPath:
       print >>sys.stderr, "Error: You must specify a test filename in interactive mode!"
       sys.exit(1)
 
--- a/testing/xpcshell/runtestsb2g.py
+++ b/testing/xpcshell/runtestsb2g.py
@@ -19,23 +19,23 @@ from marionette import Marionette
 
 class B2GXPCShellRemote(XPCShellRemote):
 
     # Overridden
     def setupUtilities(self):
         if self.options.clean:
             # Ensure a fresh directory structure for our tests
             self.clean()
-            self.device.mkDir(DEVICE_TEST_ROOT)
+            self.device.mkDir(self.options.remoteTestRoot)
 
         XPCShellRemote.setupUtilities(self)
 
     def clean(self):
         print >>sys.stderr, "\nCleaning files from previous run.."
-        self.device.removeDir(DEVICE_TEST_ROOT)
+        self.device.removeDir(self.options.remoteTestRoot)
 
     # Overriden
     def setupTestDir(self):
         if self.device._useZip:
             return XPCShellRemote.setupTestDir(self)
 
         push_attempts = 10
         for root, dirs, files in os.walk(self.xpcDir):
@@ -134,16 +134,17 @@ class B2GOptions(RemoteXPCShellOptions):
                         type="string", dest="logcat_dir",
                         help="directory to store logcat dump files")
         defaults["logcat_dir"] = None
         self.add_option('--busybox', action='store',
                         type='string', dest='busybox',
                         help="Path to busybox binary to install on device")
         defaults['busybox'] = None
 
+        defaults["remoteTestRoot"] = DEVICE_TEST_ROOT
         defaults['dm_trans'] = 'adb'
         defaults['debugger'] = None
         defaults['debuggerArgs'] = None
 
         self.set_defaults(**defaults)
 
     def verifyRemoteOptions(self, options):
         if options.b2g_path is None:
@@ -184,20 +185,21 @@ def main():
             kwargs['connectToRunningEmulator'] = True
     marionette = Marionette(**kwargs)
 
     # Create the DeviceManager instance
     kwargs = {'adbPath': options.adb_path}
     if options.deviceIP:
         kwargs['host'] = options.deviceIP
         kwargs['port'] = options.devicePort
-    kwargs['deviceRoot'] = DEVICE_TEST_ROOT
+    kwargs['deviceRoot'] = options.remoteTestRoot
     dm = devicemanagerADB.DeviceManagerADB(**kwargs)
 
-    options.remoteTestRoot = dm.getDeviceRoot()
+    if not options.remoteTestRoot:
+        options.remoteTestRoot = dm.getDeviceRoot()
     xpcsh = B2GXPCShellRemote(dm, options, args)
 
     try:
         success = xpcsh.runTests(xpcshell='xpcshell', testdirs=args[0:], **options.__dict__)
     except:
         print "Automation Error: Exception caught while running tests"
         traceback.print_exc()
         sys.exit(1)