Bug 752126 - Shorten remote (android) xpcshell command line with script; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Tue, 13 Nov 2012 16:37:51 -0700
changeset 117797 8d3046ee2f00483b95e6d8a75b11515a55bf5339
parent 117796 cc210f0643e120dff0c4d5a6f9e24a80d52c843a
child 117798 612765a8351166f5e653f074b9ed78a1c7d1efe4
push idunknown
push userunknown
push dateunknown
reviewersjmaher
bugs752126
milestone19.0a1
Bug 752126 - Shorten remote (android) xpcshell command line with script; r=jmaher
testing/xpcshell/remotexpcshelltests.py
--- a/testing/xpcshell/remotexpcshelltests.py
+++ b/testing/xpcshell/remotexpcshelltests.py
@@ -2,16 +2,17 @@
 #
 # 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/.
 
 import re, sys, os
 import subprocess
 import runxpcshelltests as xpcshell
+import tempfile
 from automationutils import *
 from mozdevice import devicemanager, devicemanagerADB, devicemanagerSUT
 
 # A specialization of XPCShellTests that runs tests on an Android device
 # via devicemanager.
 class XPCShellRemote(xpcshell.XPCShellTests, object):
 
     def __init__(self, devmgr, options, args):
@@ -104,18 +105,16 @@ class XPCShellRemote(xpcshell.XPCShellTe
         remoteFile = self.remoteJoin(self.remoteComponentsDir, "test_necko.xpt")
         self.device.pushFile(local, remoteFile)
 
         remoteFile = self.remoteJoin(self.remoteBinDir, os.path.basename(self.options.localAPK))
         self.device.pushFile(self.options.localAPK, remoteFile)
 
         self.pushLibs()
 
-        self.device.chmodDir(self.remoteBinDir)
-
     def pushLibs(self):
         if self.options.localAPK:
           localLib = os.path.join(self.options.objdir, "dist/fennec")
           if not os.path.exists(localLib):
             localLib = os.path.join(self.options.objdir, "fennec/lib")
             if not os.path.exists(localLib):
               print >>sys.stderr, "Error: could not find libs in objdir"
               sys.exit(1)
@@ -226,31 +225,55 @@ class XPCShellRemote(xpcshell.XPCShellTe
         # leakLogFile = self.remoteJoin(self.profileDir, filename)
         # self.env["XPCOM_MEM_LEAK_LOG"] = leakLogFile
         leakLogFile = ""
         return leakLogFile
 
     def setLD_LIBRARY_PATH(self, env):
         env["LD_LIBRARY_PATH"]=self.remoteBinDir
 
+    def pushWrapper(self):
+        # Rather than executing xpcshell directly, this wrapper script is
+        # used. By setting environment variables and the cwd in the script,
+        # the length of the per-test command line is shortened. This is
+        # often important when using ADB, as there is a limit to the length
+        # of the ADB command line.
+        localWrapper = tempfile.mktemp()
+        f = open(localWrapper, "w")
+        f.write("#!/system/bin/sh\n")
+        for envkey, envval in self.env.iteritems():
+            f.write("export %s=%s\n" % (envkey, envval))
+        f.write("cd $1\n")
+        f.write("echo xpcw: cd $1\n")
+        f.write("shift\n")
+        f.write("echo xpcw: xpcshell \"$@\"\n")
+        f.write("%s/xpcshell \"$@\"\n" % self.remoteBinDir)
+        f.close()
+        remoteWrapper = self.remoteJoin(self.remoteBinDir, "xpcw")
+        self.device.pushFile(localWrapper, remoteWrapper)
+        os.remove(localWrapper)
+        self.device.chmodDir(self.remoteBinDir)
+
     def buildEnvironment(self):
         self.env = {}
         self.setLD_LIBRARY_PATH(self.env)
         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
         self.env["TMPDIR"]=self.remoteTmpDir
         self.env["HOME"]=self.profileDir
+        self.pushWrapper()
 
     def launchProcess(self, cmd, stdout, stderr, env, cwd):
-        cmd[0] = self.remoteJoin(self.remoteBinDir, "xpcshell")
+        cmd[0] = self.remoteJoin(self.remoteBinDir, "xpcw")
+        cmd.insert(1, self.remoteHere)
         outputFile = "xpcshelloutput"
         f = open(outputFile, "w+")
-        self.shellReturnCode = self.device.shell(cmd, f, cwd=self.remoteHere, env=env)
+        self.shellReturnCode = self.device.shell(cmd, f)
         f.close()
         # 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(cmd[0])
         self.device.killProcess("xpcshell")
         return outputFile