2010-03-24 10:51:17 -07:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is mozilla.org code.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Joel Maher.
|
|
|
|
#
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Joel Maher <joel.maher@gmail.com> (Original Developer)
|
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import time
|
2010-05-27 13:02:15 -07:00
|
|
|
import tempfile
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0]))))
|
|
|
|
|
|
|
|
from automation import Automation
|
2010-06-24 02:32:01 -07:00
|
|
|
from remoteautomation import RemoteAutomation
|
2010-02-25 11:10:39 -08:00
|
|
|
from runtests import Mochitest
|
|
|
|
from runtests import MochitestOptions
|
2010-05-27 13:02:15 -07:00
|
|
|
from runtests import MochitestServer
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
import devicemanager
|
|
|
|
|
|
|
|
class RemoteOptions(MochitestOptions):
|
|
|
|
|
|
|
|
def __init__(self, automation, scriptdir, **kwargs):
|
|
|
|
defaults = {}
|
|
|
|
MochitestOptions.__init__(self, automation, scriptdir)
|
|
|
|
|
2010-06-24 02:32:01 -07:00
|
|
|
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
|
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
self.add_option("--deviceIP", action="store",
|
|
|
|
type = "string", dest = "deviceIP",
|
|
|
|
help = "ip address of remote device to test")
|
|
|
|
defaults["deviceIP"] = None
|
|
|
|
|
|
|
|
self.add_option("--devicePort", action="store",
|
|
|
|
type = "string", dest = "devicePort",
|
|
|
|
help = "port of remote device to test")
|
2010-05-27 13:02:15 -07:00
|
|
|
defaults["devicePort"] = 20701
|
2010-02-25 11:10:39 -08:00
|
|
|
|
2010-06-24 02:32:01 -07:00
|
|
|
self.add_option("--remote-product-name", action="store",
|
2010-02-25 11:10:39 -08:00
|
|
|
type = "string", dest = "remoteProductName",
|
2010-05-27 13:02:15 -07:00
|
|
|
help = "The executable's name of remote product to test - either fennec or firefox, defaults to fennec")
|
|
|
|
defaults["remoteProductName"] = "fennec"
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
self.add_option("--remote-logfile", action="store",
|
|
|
|
type = "string", dest = "remoteLogFile",
|
2010-05-27 13:02:15 -07:00
|
|
|
help = "Name of log file on the device relative to the device root. PLEASE ONLY USE A FILENAME.")
|
2010-02-25 11:10:39 -08:00
|
|
|
defaults["remoteLogFile"] = None
|
|
|
|
|
2010-03-13 10:34:19 -08:00
|
|
|
self.add_option("--remote-webserver", action = "store",
|
|
|
|
type = "string", dest = "remoteWebServer",
|
|
|
|
help = "ip address where the remote web server is hosted at")
|
|
|
|
defaults["remoteWebServer"] = None
|
|
|
|
|
|
|
|
self.add_option("--http-port", action = "store",
|
|
|
|
type = "string", dest = "httpPort",
|
|
|
|
help = "ip address where the remote web server is hosted at")
|
|
|
|
defaults["httpPort"] = automation.DEFAULT_HTTP_PORT
|
|
|
|
|
|
|
|
self.add_option("--ssl-port", action = "store",
|
|
|
|
type = "string", dest = "sslPort",
|
|
|
|
help = "ip address where the remote web server is hosted at")
|
|
|
|
defaults["sslPort"] = automation.DEFAULT_SSL_PORT
|
2010-02-25 11:10:39 -08:00
|
|
|
|
2011-04-19 15:17:01 -07:00
|
|
|
self.add_option("--pidfile", action = "store",
|
|
|
|
type = "string", dest = "pidFile",
|
|
|
|
help = "name of the pidfile to generate")
|
|
|
|
defaults["pidFile"] = ""
|
|
|
|
|
2010-05-27 13:02:15 -07:00
|
|
|
defaults["remoteTestRoot"] = None
|
2010-02-25 11:10:39 -08:00
|
|
|
defaults["logFile"] = "mochitest.log"
|
|
|
|
defaults["autorun"] = True
|
|
|
|
defaults["closeWhenDone"] = True
|
|
|
|
defaults["testPath"] = ""
|
2010-05-27 13:02:15 -07:00
|
|
|
defaults["app"] = None
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
self.set_defaults(**defaults)
|
|
|
|
|
2010-05-27 13:02:15 -07:00
|
|
|
def verifyRemoteOptions(self, options, automation):
|
|
|
|
options.remoteTestRoot = automation._devicemanager.getDeviceRoot()
|
2010-12-09 14:47:21 -08:00
|
|
|
productRoot = options.remoteTestRoot + "/" + automation._product
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2010-12-09 14:47:21 -08:00
|
|
|
if (options.utilityPath == self._automation.DIST_BIN):
|
|
|
|
options.utilityPath = productRoot + "/bin"
|
2010-03-13 10:34:19 -08:00
|
|
|
|
2010-12-09 14:47:21 -08:00
|
|
|
if options.remoteWebServer == None:
|
|
|
|
if os.name != "nt":
|
|
|
|
options.remoteWebServer = automation.getLanIp()
|
|
|
|
else:
|
|
|
|
print "ERROR: you must specify a --remote-webserver=<ip address>\n"
|
|
|
|
return None
|
2010-05-27 13:02:15 -07:00
|
|
|
|
|
|
|
options.webServer = options.remoteWebServer
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
if (options.deviceIP == None):
|
2010-06-24 02:32:01 -07:00
|
|
|
print "ERROR: you must provide a device IP"
|
|
|
|
return None
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
if (options.remoteLogFile == None):
|
2010-12-09 14:47:21 -08:00
|
|
|
options.remoteLogFile = options.remoteTestRoot + '/mochitest.log'
|
2010-09-29 16:20:33 -07:00
|
|
|
|
|
|
|
if (options.remoteLogFile.count('/') < 1):
|
2010-12-09 14:47:21 -08:00
|
|
|
options.remoteLogFile = options.remoteTestRoot + '/' + options.remoteLogFile
|
2010-06-15 13:02:17 -07:00
|
|
|
|
2010-06-24 02:32:01 -07:00
|
|
|
# remoteAppPath or app must be specified to find the product to launch
|
|
|
|
if (options.remoteAppPath and options.app):
|
|
|
|
print "ERROR: You cannot specify both the remoteAppPath and the app setting"
|
|
|
|
return None
|
|
|
|
elif (options.remoteAppPath):
|
|
|
|
options.app = options.remoteTestRoot + "/" + options.remoteAppPath
|
|
|
|
elif (options.app == None):
|
|
|
|
# Neither remoteAppPath nor app are set -- error
|
|
|
|
print "ERROR: You must specify either appPath or app"
|
|
|
|
return None
|
2010-05-27 13:02:15 -07:00
|
|
|
|
|
|
|
# Only reset the xrePath if it wasn't provided
|
|
|
|
if (options.xrePath == None):
|
2010-06-24 02:32:01 -07:00
|
|
|
if (automation._product == "fennec"):
|
|
|
|
options.xrePath = productRoot + "/xulrunner"
|
|
|
|
else:
|
|
|
|
options.xrePath = options.utilityPath
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2011-04-19 15:17:01 -07:00
|
|
|
if (options.pidFile != ""):
|
|
|
|
f = open(options.pidFile, 'w')
|
|
|
|
f.write("%s" % os.getpid())
|
|
|
|
f.close()
|
|
|
|
|
2010-05-27 13:02:15 -07:00
|
|
|
return options
|
|
|
|
|
|
|
|
def verifyOptions(self, options, mochitest):
|
|
|
|
# since we are reusing verifyOptions, it will exit if App is not found
|
|
|
|
temp = options.app
|
|
|
|
options.app = sys.argv[0]
|
|
|
|
tempPort = options.httpPort
|
|
|
|
tempSSL = options.sslPort
|
|
|
|
tempIP = options.webServer
|
|
|
|
options = MochitestOptions.verifyOptions(self, options, mochitest)
|
|
|
|
options.webServer = tempIP
|
|
|
|
options.app = temp
|
|
|
|
options.sslPort = tempSSL
|
|
|
|
options.httpPort = tempPort
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
class MochiRemote(Mochitest):
|
|
|
|
|
|
|
|
_automation = None
|
|
|
|
_dm = None
|
|
|
|
|
|
|
|
def __init__(self, automation, devmgr, options):
|
|
|
|
self._automation = automation
|
|
|
|
Mochitest.__init__(self, self._automation)
|
|
|
|
self._dm = devmgr
|
|
|
|
self.runSSLTunnel = False
|
2010-05-27 13:02:15 -07:00
|
|
|
self.remoteProfile = options.remoteTestRoot + "/profile"
|
2010-02-25 11:10:39 -08:00
|
|
|
self.remoteLog = options.remoteLogFile
|
|
|
|
|
|
|
|
def cleanup(self, manifest, options):
|
|
|
|
self._dm.getFile(self.remoteLog, self.localLog)
|
|
|
|
self._dm.removeFile(self.remoteLog)
|
|
|
|
self._dm.removeDir(self.remoteProfile)
|
2011-04-19 15:17:01 -07:00
|
|
|
if (options.pidFile != ""):
|
|
|
|
try:
|
|
|
|
os.remove(options.pidFile)
|
2011-05-12 09:47:38 -07:00
|
|
|
os.remove(options.pidFile + ".xpcshell.pid")
|
2011-04-19 15:17:01 -07:00
|
|
|
except:
|
|
|
|
print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % options.pidFile
|
2010-02-25 11:10:39 -08:00
|
|
|
|
2010-05-27 13:02:15 -07:00
|
|
|
def findPath(self, paths, filename = None):
|
2010-06-24 02:32:01 -07:00
|
|
|
for path in paths:
|
|
|
|
p = path
|
|
|
|
if filename:
|
|
|
|
p = os.path.join(p, filename)
|
|
|
|
if os.path.exists(self.getFullPath(p)):
|
|
|
|
return path
|
|
|
|
return None
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
def startWebServer(self, options):
|
2010-06-24 02:32:01 -07:00
|
|
|
""" Create the webserver on the host and start it up """
|
|
|
|
remoteXrePath = options.xrePath
|
|
|
|
remoteProfilePath = options.profilePath
|
|
|
|
remoteUtilityPath = options.utilityPath
|
|
|
|
localAutomation = Automation()
|
2011-02-24 11:45:42 -08:00
|
|
|
localAutomation.IS_WIN32 = False
|
|
|
|
localAutomation.IS_LINUX = False
|
|
|
|
localAutomation.IS_MAC = False
|
|
|
|
localAutomation.UNIXISH = False
|
|
|
|
hostos = sys.platform
|
|
|
|
if (hostos == 'mac' or hostos == 'darwin'):
|
|
|
|
localAutomation.IS_MAC = True
|
|
|
|
elif (hostos == 'linux' or hostos == 'linux2'):
|
|
|
|
localAutomation.IS_LINUX = True
|
|
|
|
localAutomation.UNIXISH = True
|
|
|
|
elif (hostos == 'win32' or hostos == 'win64'):
|
|
|
|
localAutomation.BIN_SUFFIX = ".exe"
|
|
|
|
localAutomation.IS_WIN32 = True
|
2010-06-24 02:32:01 -07:00
|
|
|
|
|
|
|
paths = [options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product)]
|
|
|
|
options.xrePath = self.findPath(paths)
|
|
|
|
if options.xrePath == None:
|
|
|
|
print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
|
|
|
|
sys.exit(1)
|
|
|
|
paths.append("bin")
|
|
|
|
paths.append(os.path.join("..", "bin"))
|
|
|
|
|
|
|
|
xpcshell = "xpcshell"
|
|
|
|
if (os.name == "nt"):
|
|
|
|
xpcshell += ".exe"
|
2010-06-24 02:32:01 -07:00
|
|
|
|
2010-06-24 02:32:01 -07:00
|
|
|
if (options.utilityPath):
|
|
|
|
paths.insert(0, options.utilityPath)
|
|
|
|
options.utilityPath = self.findPath(paths, xpcshell)
|
|
|
|
if options.utilityPath == None:
|
|
|
|
print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
options.profilePath = tempfile.mkdtemp()
|
|
|
|
self.server = MochitestServer(localAutomation, options)
|
|
|
|
self.server.start()
|
|
|
|
|
2011-05-12 09:47:38 -07:00
|
|
|
if (options.pidFile != ""):
|
|
|
|
f = open(options.pidFile + ".xpcshell.pid", 'w')
|
|
|
|
f.write("%s" % self.server._process.pid)
|
|
|
|
f.close()
|
2010-06-24 02:32:01 -07:00
|
|
|
self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
|
2011-05-12 09:47:38 -07:00
|
|
|
|
2010-06-24 02:32:01 -07:00
|
|
|
options.xrePath = remoteXrePath
|
|
|
|
options.utilityPath = remoteUtilityPath
|
|
|
|
options.profilePath = remoteProfilePath
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
def stopWebServer(self, options):
|
2010-05-27 13:02:15 -07:00
|
|
|
self.server.stop()
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
def buildProfile(self, options):
|
|
|
|
manifest = Mochitest.buildProfile(self, options)
|
|
|
|
self.localProfile = options.profilePath
|
2010-03-15 15:47:34 -07:00
|
|
|
if self._dm.pushDir(options.profilePath, self.remoteProfile) == None:
|
|
|
|
raise devicemanager.FileError("Unable to copy profile to device.")
|
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
options.profilePath = self.remoteProfile
|
|
|
|
return manifest
|
2010-06-24 02:32:01 -07:00
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
def buildURLOptions(self, options):
|
|
|
|
self.localLog = options.logFile
|
|
|
|
options.logFile = self.remoteLog
|
2010-11-04 17:01:12 -07:00
|
|
|
options.profilePath = self.localProfile
|
2010-02-25 11:10:39 -08:00
|
|
|
retVal = Mochitest.buildURLOptions(self, options)
|
2010-11-04 17:01:12 -07:00
|
|
|
#we really need testConfig.js (for browser chrome)
|
|
|
|
if self._dm.pushDir(options.profilePath, self.remoteProfile) == None:
|
|
|
|
raise devicemanager.FileError("Unable to copy profile to device.")
|
|
|
|
|
|
|
|
options.profilePath = self.remoteProfile
|
2010-02-25 11:10:39 -08:00
|
|
|
options.logFile = self.localLog
|
|
|
|
return retVal
|
|
|
|
|
|
|
|
def installChromeFile(self, filename, options):
|
2010-05-27 13:02:15 -07:00
|
|
|
parts = options.app.split('/')
|
|
|
|
if (parts[0] == options.app):
|
|
|
|
return "NO_CHROME_ON_DROID"
|
|
|
|
path = '/'.join(parts[:-1])
|
2010-03-15 15:47:34 -07:00
|
|
|
manifest = path + "/chrome/" + os.path.basename(filename)
|
2011-01-13 10:00:23 -08:00
|
|
|
if self._dm.pushFile(filename, manifest) == False:
|
2010-03-15 15:47:34 -07:00
|
|
|
raise devicemanager.FileError("Unable to install Chrome files on device.")
|
2010-02-25 11:10:39 -08:00
|
|
|
return manifest
|
|
|
|
|
|
|
|
def getLogFilePath(self, logFile):
|
|
|
|
return logFile
|
|
|
|
|
|
|
|
def main():
|
|
|
|
scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
|
2011-02-24 11:45:42 -08:00
|
|
|
dm_none = devicemanager.DeviceManager(None, None)
|
|
|
|
auto = RemoteAutomation(dm_none, "fennec")
|
2010-02-25 11:10:39 -08:00
|
|
|
parser = RemoteOptions(auto, scriptdir)
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
dm = devicemanager.DeviceManager(options.deviceIP, options.devicePort)
|
|
|
|
auto.setDeviceManager(dm)
|
2010-05-27 13:02:15 -07:00
|
|
|
options = parser.verifyRemoteOptions(options, auto)
|
|
|
|
if (options == None):
|
2010-06-24 02:32:01 -07:00
|
|
|
print "ERROR: Invalid options specified, use --help for a list of valid options"
|
|
|
|
sys.exit(1)
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
productPieces = options.remoteProductName.split('.')
|
|
|
|
if (productPieces != None):
|
2010-06-24 02:32:01 -07:00
|
|
|
auto.setProduct(productPieces[0])
|
2010-02-25 11:10:39 -08:00
|
|
|
else:
|
2010-06-24 02:32:01 -07:00
|
|
|
auto.setProduct(options.remoteProductName)
|
2010-02-25 11:10:39 -08:00
|
|
|
|
|
|
|
mochitest = MochiRemote(auto, dm, options)
|
|
|
|
|
|
|
|
options = parser.verifyOptions(options, mochitest)
|
|
|
|
if (options == None):
|
2010-06-24 02:32:01 -07:00
|
|
|
sys.exit(1)
|
2010-02-25 11:10:39 -08:00
|
|
|
|
2010-09-29 16:20:33 -07:00
|
|
|
auto.setRemoteLog(options.remoteLogFile)
|
2010-03-15 15:47:34 -07:00
|
|
|
auto.setServerInfo(options.webServer, options.httpPort, options.sslPort)
|
2011-02-23 11:38:56 -08:00
|
|
|
|
|
|
|
procName = options.app.split('/')[-1]
|
|
|
|
if (dm.processExist(procName)):
|
|
|
|
dm.killProcess(procName)
|
|
|
|
|
2010-02-25 11:10:39 -08:00
|
|
|
sys.exit(mochitest.runTests(options))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-06-24 02:32:01 -07:00
|
|
|
main()
|
2010-02-25 11:10:39 -08:00
|
|
|
|