Bug 816630 - B2G xpcshell tests use wrong binary directory, r=jgriffin, DONTBUILD a=NPOTB,test-only
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 30 Nov 2012 12:19:20 -0500
changeset 117229 608c3308c5e16b13b7b771d948f031e4c6d41a94
parent 117228 fbf8dcadab61857bf4d9c0648d218044fc015ae4
child 117230 6cc72f5e8dc3fa1b7c85744f19055264b8befa97
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersjgriffin, DONTBUILD, NPOTB, test-only
bugs816630
milestone18.0
Bug 816630 - B2G xpcshell tests use wrong binary directory, r=jgriffin, DONTBUILD a=NPOTB,test-only
testing/xpcshell/remotexpcshelltests.py
testing/xpcshell/runtestsb2g.py
--- a/testing/xpcshell/remotexpcshelltests.py
+++ b/testing/xpcshell/remotexpcshelltests.py
@@ -13,18 +13,18 @@ from mozdevice import devicemanagerADB, 
 here = os.path.dirname(os.path.abspath(__file__))
 
 # A specialization of XPCShellTests that runs tests on an Android device
 # via devicemanager.
 class XPCShellRemote(xpcshell.XPCShellTests, object):
 
     def __init__(self, devmgr, options, args):
         xpcshell.XPCShellTests.__init__(self)
-        self.localLib = None
-        self.localBin = None
+        self.localLib = options.localLib
+        self.localBin = options.localBin
         self.options = options
         self.device = devmgr
         self.pathMapping = []
         self.remoteTestRoot = self.device.getTestRoot("xpcshell")
         # Terse directory names are used here ("b" for a binaries 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
@@ -88,24 +88,16 @@ class XPCShellRemote(xpcshell.XPCShellTe
         if (not self.device.dirExists(self.remoteScriptsDir)):
           self.device.mkDir(self.remoteScriptsDir)
         if (not self.device.dirExists(self.remoteComponentsDir)):
           self.device.mkDir(self.remoteComponentsDir)
 
         local = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'head.js')
         self.device.pushFile(local, self.remoteScriptsDir)
 
-        if not self.localBin:
-          self.localBin = os.path.join(self.options.objdir, "dist/bin")
-          if not os.path.exists(self.localBin):
-            self.localBin = os.path.join(self.options.objdir, "bin")
-            if not os.path.exists(self.localBin):
-              print >>sys.stderr, "Error: could not find bin in objdir"
-              sys.exit(1)
-
         local = os.path.join(self.localBin, "xpcshell")
         self.device.pushFile(local, self.remoteBinDir)
 
         local = os.path.join(self.localBin, "components/httpd.js")
         self.device.pushFile(local, self.remoteComponentsDir)
 
         local = os.path.join(self.localBin, "components/httpd.manifest")
         self.device.pushFile(local, self.remoteComponentsDir)
@@ -116,27 +108,16 @@ class XPCShellRemote(xpcshell.XPCShellTe
         if self.options.localAPK:
             self.device.pushFile(self.options.localAPK, self.remoteBinDir)
 
         self.pushLibs()
 
         self.device.chmodDir(self.remoteBinDir)
 
     def pushLibs(self):
-        if not self.localLib:
-          if self.options.localAPK:
-            self.localLib = os.path.join(self.options.objdir, "dist/fennec")
-            if not os.path.exists(self.localLib):
-              self.localLib = os.path.join(self.options.objdir, "fennec/lib")
-              if not os.path.exists(self.localLib):
-                print >>sys.stderr, "Error: could not find libs in objdir"
-                sys.exit(1)
-          else:
-            self.localLib = os.path.join(self.options.objdir, 'dist/bin')
-
         for file in os.listdir(self.localLib):
           if (file.endswith(".so")):
             print >> sys.stderr, "Pushing %s.." % file
             if 'libxul' in file:
               print >> sys.stderr, "This is a big file, it could take a while."
             self.device.pushFile(os.path.join(self.localLib, file), self.remoteBinDir)
 
         # Additional libraries may be found in a sub-directory such as "lib/armeabi-v7a"
@@ -324,28 +305,71 @@ class RemoteXPCShellOptions(xpcshell.XPC
                         help = "local path to Fennec APK")
         defaults["localAPK"] = 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("--local-lib-dir", action="store",
+                        type = "string", dest = "localLib",
+                        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.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):
+                        break
+                else:
+                    self.error("Couldn't find local library dir, specify --local-lib-dir")
+            elif options.objdir:
+                options.localLib = os.path.join(options.objdir, 'dist/bin')
+            elif os.path.isfile(os.path.join(here, '..', 'bin', 'xpcshell')):
+                # assume tests are being run from a tests.zip
+                options.localLib = os.path.abspath(os.path.join(here, '..', 'bin'))
+            else:
+                self.error("Couldn't find local library dir, specify --local-lib-dir")
+
+        if options.localBin is None:
+            if options.objdir:
+                for path in ['dist/bin', 'bin']:
+                    options.localBin = os.path.join(options.objdir, path)
+                    if os.path.isdir(options.localBin):
+                        break
+                else:
+                    self.error("Couldn't find local binary dir, specify --local-bin-dir")
+            elif os.path.isfile(os.path.join(here, '..', 'bin', 'xpcshell')):
+                # assume tests are being run from a tests.zip
+                options.localBin = os.path.abspath(os.path.join(here, '..', 'bin'))
+            else:
+                self.error("Couldn't find local binary dir, specify --local-bin-dir")
+        return options
+
 class PathMapping:
 
     def __init__(self, localDir, remoteDir):
         self.local = localDir
         self.remote = remoteDir
 
 def main():
 
     parser = RemoteXPCShellOptions()
     options, args = parser.parse_args()
+    options = parser.verifyRemoteOptions(options)
 
     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):
--- a/testing/xpcshell/runtestsb2g.py
+++ b/testing/xpcshell/runtestsb2g.py
@@ -13,25 +13,20 @@ from remotexpcshelltests import XPCShell
 from automationutils import *
 from mozdevice import devicemanagerADB
 
 DEVICE_TEST_ROOT = '/data/local/tests'
 
 
 from marionette import Marionette
 
-
 class B2GXPCShellRemote(XPCShellRemote):
 
     # Overridden
     def setupUtilities(self):
-        if self.options.xrePath:
-            self.localLib = self.options.xrePath
-            self.localBin = self.options.xrePath
-
         if self.options.clean:
             # Ensure a fresh directory structure for our tests
             self.clean()
             self.device.mkDir(DEVICE_TEST_ROOT)
 
         XPCShellRemote.setupUtilities(self)
 
     def clean(self):
@@ -142,32 +137,31 @@ class B2GOptions(RemoteXPCShellOptions):
         defaults['busybox'] = None
 
         defaults['dm_trans'] = 'adb'
         defaults['debugger'] = None
         defaults['debuggerArgs'] = None
 
         self.set_defaults(**defaults)
 
+    def verifyRemoteOptions(self, options):
+        if options.b2g_path is None:
+            self.error("Need to specify a --b2gpath")
+
+        if options.geckoPath and not options.emulator:
+            self.error("You must specify --emulator if you specify --gecko-path")
+
+        if options.logcat_dir and not options.emulator:
+            self.error("You must specify --emulator if you specify --logcat-dir")
+        return RemoteXPCShellOptions.verifyRemoteOptions(self, options)
 
 def main():
     parser = B2GOptions()
     options, args = parser.parse_args()
-
-    if options.b2g_path is None:
-        parser.error("Need to specify a --b2gpath")
-
-    if options.xrePath is None:
-        parser.error("Need to specify a --xre-path")
-
-    if options.geckoPath and not options.emulator:
-        self.error("You must specify --emulator if you specify --gecko-path")
-
-    if options.logcat_dir and not options.emulator:
-        self.error("You must specify --emulator if you specify --logcat-dir")
+    options = parser.verifyRemoteOptions(options)
 
     # Create the Marionette instance
     kwargs = {}
     if options.emulator:
         kwargs['emulator'] = options.emulator
         if options.no_window:
             kwargs['noWindow'] = True
         if options.geckoPath: