2009-02-12 05:49:53 -08: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
|
|
|
|
# Mozilla Foundation.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
2009-09-05 18:08:49 -07:00
|
|
|
# Serge Gautherie <sgautherie.bz@free.fr>
|
2009-02-12 05:49:53 -08:00
|
|
|
# Ted Mielczarek <ted.mielczarek@gmail.com>
|
|
|
|
#
|
|
|
|
# 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 *****
|
|
|
|
|
|
|
|
"""
|
|
|
|
Runs the reftest test harness.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys, shutil, os, os.path
|
|
|
|
SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
|
|
|
|
sys.path.append(SCRIPT_DIRECTORY)
|
2010-03-09 14:31:49 -08:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
from automation import Automation
|
2009-10-19 16:12:09 -07:00
|
|
|
from automationutils import *
|
2009-02-12 05:49:53 -08:00
|
|
|
from optparse import OptionParser
|
|
|
|
from tempfile import mkdtemp
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
class RefTest(object):
|
|
|
|
|
|
|
|
oldcwd = os.getcwd()
|
|
|
|
|
|
|
|
def __init__(self, automation):
|
|
|
|
self.automation = automation
|
|
|
|
|
|
|
|
def getFullPath(self, path):
|
|
|
|
"Get an absolute path relative to self.oldcwd."
|
|
|
|
return os.path.normpath(os.path.join(self.oldcwd, os.path.expanduser(path)))
|
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
def getManifestPath(self, path):
|
|
|
|
"Get the path of the manifest, and for remote testing this function is subclassed to point to remote manifest"
|
|
|
|
return self.getFullPath(path)
|
|
|
|
|
2011-03-11 06:15:33 -08:00
|
|
|
def createReftestProfile(self, options, profileDir, server='localhost'):
|
2010-01-15 09:22:54 -08:00
|
|
|
"Sets up a profile for reftest."
|
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
self.automation.setupPermissionsDatabase(profileDir,
|
2011-03-11 06:15:33 -08:00
|
|
|
{'allowXULXBL': [(server, True), ('<file>', True)]})
|
2010-08-19 16:12:46 -07:00
|
|
|
|
2011-01-24 16:23:07 -08:00
|
|
|
# Set preferences for communication between our command line arguments
|
|
|
|
# and the reftest harness. Preferences that are required for reftest
|
|
|
|
# to work should instead be set in reftest-cmdline.js .
|
2011-03-28 11:37:08 -07:00
|
|
|
prefsFile = open(os.path.join(profileDir, "user.js"), "a")
|
2010-01-15 09:22:54 -08:00
|
|
|
prefsFile.write('user_pref("reftest.timeout", %d);\n' % (options.timeout * 1000))
|
|
|
|
|
2010-03-29 10:57:51 -07:00
|
|
|
if options.totalChunks != None:
|
|
|
|
prefsFile.write('user_pref("reftest.totalChunks", %d);\n' % options.totalChunks)
|
|
|
|
if options.thisChunk != None:
|
|
|
|
prefsFile.write('user_pref("reftest.thisChunk", %d);\n' % options.thisChunk)
|
2010-07-26 18:43:33 -07:00
|
|
|
if options.logFile != None:
|
|
|
|
prefsFile.write('user_pref("reftest.logFile", "%s");\n' % options.logFile)
|
2010-03-29 10:57:51 -07:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
for v in options.extraPrefs:
|
|
|
|
thispref = v.split("=")
|
|
|
|
if len(thispref) < 2:
|
|
|
|
print "Error: syntax error in --setpref=" + v
|
|
|
|
sys.exit(1)
|
|
|
|
part = 'user_pref("%s", %s);\n' % (thispref[0], thispref[1])
|
|
|
|
prefsFile.write(part)
|
|
|
|
prefsFile.close()
|
|
|
|
|
|
|
|
# install the reftest extension bits into the profile
|
2010-06-24 02:32:01 -07:00
|
|
|
self.automation.installExtension(os.path.join(SCRIPT_DIRECTORY, "reftest"),
|
|
|
|
profileDir,
|
|
|
|
"reftest@mozilla.org")
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
def registerExtension(self, browserEnv, options, profileDir, extraArgs = ['-silent']):
|
|
|
|
# run once with -silent to let the extension manager do its thing
|
|
|
|
# and then exit the app
|
|
|
|
self.automation.log.info("REFTEST INFO | runreftest.py | Performing extension manager registration: start.\n")
|
|
|
|
# Don't care about this |status|: |runApp()| reporting it should be enough.
|
|
|
|
status = self.automation.runApp(None, browserEnv, options.app, profileDir,
|
|
|
|
extraArgs,
|
|
|
|
utilityPath = options.utilityPath,
|
|
|
|
xrePath=options.xrePath,
|
|
|
|
symbolsPath=options.symbolsPath)
|
|
|
|
# We don't care to call |processLeakLog()| for this step.
|
|
|
|
self.automation.log.info("\nREFTEST INFO | runreftest.py | Performing extension manager registration: end.")
|
|
|
|
|
|
|
|
# Remove the leak detection file so it can't "leak" to the tests run.
|
|
|
|
# The file is not there if leak logging was not enabled in the application build.
|
|
|
|
if os.path.exists(self.leakLogFile):
|
|
|
|
os.remove(self.leakLogFile)
|
|
|
|
|
|
|
|
def buildBrowserEnv(self, options, profileDir):
|
|
|
|
browserEnv = self.automation.environment(xrePath = options.xrePath)
|
|
|
|
browserEnv["XPCOM_DEBUG_BREAK"] = "stack"
|
|
|
|
|
|
|
|
# Enable leaks detection to its own log file.
|
|
|
|
self.leakLogFile = os.path.join(profileDir, "runreftest_leaks.log")
|
|
|
|
browserEnv["XPCOM_MEM_BLOAT_LOG"] = self.leakLogFile
|
|
|
|
return browserEnv
|
|
|
|
|
|
|
|
def cleanup(self, profileDir):
|
|
|
|
if profileDir:
|
|
|
|
shutil.rmtree(profileDir)
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
def runTests(self, manifest, options):
|
|
|
|
debuggerInfo = getDebuggerInfo(self.oldcwd, options.debugger, options.debuggerArgs,
|
|
|
|
options.debuggerInteractive);
|
|
|
|
|
|
|
|
profileDir = None
|
|
|
|
try:
|
|
|
|
profileDir = mkdtemp()
|
|
|
|
self.copyExtraFilesToProfile(options, profileDir)
|
2011-03-28 11:37:08 -07:00
|
|
|
self.createReftestProfile(options, profileDir)
|
2010-11-18 14:15:54 -08:00
|
|
|
self.installExtensionsToProfile(options, profileDir)
|
2010-03-04 10:02:33 -08:00
|
|
|
|
|
|
|
# browser environment
|
2010-03-09 14:31:49 -08:00
|
|
|
browserEnv = self.buildBrowserEnv(options, profileDir)
|
2010-03-04 10:02:33 -08:00
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
self.registerExtension(browserEnv, options, profileDir)
|
2010-01-15 09:22:54 -08:00
|
|
|
|
|
|
|
# then again to actually run reftest
|
|
|
|
self.automation.log.info("REFTEST INFO | runreftest.py | Running tests: start.\n")
|
2010-03-09 14:31:49 -08:00
|
|
|
reftestlist = self.getManifestPath(manifest)
|
2010-01-15 09:22:54 -08:00
|
|
|
status = self.automation.runApp(None, browserEnv, options.app, profileDir,
|
|
|
|
["-reftest", reftestlist],
|
|
|
|
utilityPath = options.utilityPath,
|
|
|
|
xrePath=options.xrePath,
|
|
|
|
debuggerInfo=debuggerInfo,
|
|
|
|
symbolsPath=options.symbolsPath,
|
|
|
|
# give the JS harness 30 seconds to deal
|
|
|
|
# with its own timeouts
|
|
|
|
timeout=options.timeout + 30.0)
|
2010-03-09 14:31:49 -08:00
|
|
|
processLeakLog(self.leakLogFile, options.leakThreshold)
|
2010-01-15 09:22:54 -08:00
|
|
|
self.automation.log.info("\nREFTEST INFO | runreftest.py | Running tests: end.")
|
|
|
|
finally:
|
2010-03-09 14:31:49 -08:00
|
|
|
self.cleanup(profileDir)
|
2010-01-15 09:22:54 -08:00
|
|
|
return status
|
|
|
|
|
|
|
|
def copyExtraFilesToProfile(self, options, profileDir):
|
|
|
|
"Copy extra files or dirs specified on the command line to the testing profile."
|
|
|
|
for f in options.extraProfileFiles:
|
|
|
|
abspath = self.getFullPath(f)
|
2011-04-18 09:41:57 -07:00
|
|
|
if os.path.isfile(abspath):
|
|
|
|
shutil.copy2(abspath, profileDir)
|
|
|
|
elif os.path.isdir(abspath):
|
|
|
|
dest = os.path.join(profileDir, os.path.basename(abspath))
|
2010-01-15 09:22:54 -08:00
|
|
|
shutil.copytree(abspath, dest)
|
|
|
|
else:
|
2011-04-18 09:41:57 -07:00
|
|
|
self.automation.log.warning("WARNING | runreftest.py | Failed to copy %s to profile", abspath)
|
|
|
|
continue
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-11-18 14:15:54 -08:00
|
|
|
def installExtensionsToProfile(self, options, profileDir):
|
2011-04-18 09:48:23 -07:00
|
|
|
"Install application distributed extensions and specified on the command line ones to testing profile."
|
|
|
|
# Install distributed extensions, if application has any.
|
|
|
|
distExtDir = os.path.join(options.app[ : options.app.rfind(os.sep)], "distribution", "extensions")
|
|
|
|
if os.path.isdir(distExtDir):
|
|
|
|
for f in os.listdir(distExtDir):
|
|
|
|
self.automation.installExtension(os.path.join(distExtDir, f), profileDir)
|
|
|
|
|
|
|
|
# Install custom extensions.
|
2010-11-18 14:15:54 -08:00
|
|
|
for f in options.extensionsToInstall:
|
2011-04-14 08:28:46 -07:00
|
|
|
self.automation.installExtension(self.getFullPath(f), profileDir)
|
2010-11-18 14:15:54 -08:00
|
|
|
|
2009-02-12 05:49:53 -08:00
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
class ReftestOptions(OptionParser):
|
2010-03-04 09:10:16 -08:00
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
def __init__(self, automation):
|
2010-06-24 02:32:01 -07:00
|
|
|
self._automation = automation
|
2010-03-09 14:31:49 -08:00
|
|
|
OptionParser.__init__(self)
|
|
|
|
defaults = {}
|
|
|
|
|
|
|
|
# we want to pass down everything from automation.__all__
|
|
|
|
addCommonOptions(self,
|
2010-06-24 02:32:01 -07:00
|
|
|
defaults=dict(zip(self._automation.__all__,
|
|
|
|
[getattr(self._automation, x) for x in self._automation.__all__])))
|
|
|
|
self._automation.addCommonOptions(self)
|
2010-03-09 14:31:49 -08:00
|
|
|
self.add_option("--appname",
|
2009-02-12 05:49:53 -08:00
|
|
|
action = "store", type = "string", dest = "app",
|
|
|
|
default = os.path.join(SCRIPT_DIRECTORY, automation.DEFAULT_APP),
|
|
|
|
help = "absolute path to application, overriding default")
|
2010-03-09 14:31:49 -08:00
|
|
|
self.add_option("--extra-profile-file",
|
2009-02-12 05:49:53 -08:00
|
|
|
action = "append", dest = "extraProfileFiles",
|
|
|
|
default = [],
|
|
|
|
help = "copy specified files/dirs to testing profile")
|
2010-03-09 14:31:49 -08:00
|
|
|
self.add_option("--timeout",
|
2009-06-19 11:17:55 -07:00
|
|
|
action = "store", dest = "timeout", type = "int",
|
2009-10-16 13:23:30 -07:00
|
|
|
default = 5 * 60, # 5 minutes per bug 479518
|
|
|
|
help = "reftest will timeout in specified number of seconds. [default %default s].")
|
2010-03-09 14:31:49 -08:00
|
|
|
self.add_option("--leak-threshold",
|
2009-04-05 06:03:46 -07:00
|
|
|
action = "store", type = "int", dest = "leakThreshold",
|
|
|
|
default = 0,
|
|
|
|
help = "fail if the number of bytes leaked through "
|
|
|
|
"refcounted objects (or bytes in classes with "
|
|
|
|
"MOZ_COUNT_CTOR and MOZ_COUNT_DTOR) is greater "
|
|
|
|
"than the given number")
|
2010-03-09 14:31:49 -08:00
|
|
|
self.add_option("--utility-path",
|
2009-09-29 05:31:49 -07:00
|
|
|
action = "store", type = "string", dest = "utilityPath",
|
2010-06-24 02:32:01 -07:00
|
|
|
default = self._automation.DIST_BIN,
|
2009-09-29 05:31:49 -07:00
|
|
|
help = "absolute path to directory containing utility "
|
|
|
|
"programs (xpcshell, ssltunnel, certutil)")
|
2010-06-24 02:32:01 -07:00
|
|
|
defaults["utilityPath"] = self._automation.DIST_BIN
|
2010-03-09 14:31:49 -08:00
|
|
|
|
2010-03-29 10:57:51 -07:00
|
|
|
self.add_option("--total-chunks",
|
|
|
|
type = "int", dest = "totalChunks",
|
|
|
|
help = "how many chunks to split the tests up into")
|
|
|
|
defaults["totalChunks"] = None
|
|
|
|
|
|
|
|
self.add_option("--this-chunk",
|
|
|
|
type = "int", dest = "thisChunk",
|
|
|
|
help = "which chunk to run between 1 and --total-chunks")
|
|
|
|
defaults["thisChunk"] = None
|
|
|
|
|
2010-07-26 18:43:33 -07:00
|
|
|
self.add_option("--log-file",
|
|
|
|
action = "store", type = "string", dest = "logFile",
|
|
|
|
default = None,
|
|
|
|
help = "file to log output to in addition to stdout")
|
|
|
|
defaults["logFile"] = None
|
|
|
|
|
2010-07-13 16:04:29 -07:00
|
|
|
self.add_option("--skip-slow-tests",
|
|
|
|
dest = "skipSlowTests", action = "store_true",
|
|
|
|
help = "skip tests marked as slow when running")
|
|
|
|
defaults["skipSlowTests"] = False
|
|
|
|
|
2010-11-18 14:15:54 -08:00
|
|
|
self.add_option("--install-extension",
|
|
|
|
action = "append", dest = "extensionsToInstall",
|
|
|
|
help = "install the specified extension in the testing profile."
|
|
|
|
"The extension file's name should be <id>.xpi where <id> is"
|
2011-04-14 08:28:46 -07:00
|
|
|
"the extension's id as indicated in its install.rdf."
|
|
|
|
"An optional path can be specified too.")
|
2010-11-18 14:15:54 -08:00
|
|
|
defaults["extensionsToInstall"] = []
|
|
|
|
|
2010-03-09 14:31:49 -08:00
|
|
|
self.set_defaults(**defaults)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
automation = Automation()
|
|
|
|
parser = ReftestOptions(automation)
|
|
|
|
reftest = RefTest(automation)
|
2009-04-05 06:03:46 -07:00
|
|
|
|
2009-02-12 05:49:53 -08:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
if len(args) != 1:
|
|
|
|
print >>sys.stderr, "No reftest.list specified."
|
|
|
|
sys.exit(1)
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
options.app = reftest.getFullPath(options.app)
|
2009-02-12 05:49:53 -08:00
|
|
|
if not os.path.exists(options.app):
|
|
|
|
print """Error: Path %(app)s doesn't exist.
|
|
|
|
Are you executing $objdir/_tests/reftest/runreftest.py?""" \
|
2010-01-15 09:22:54 -08:00
|
|
|
% {"app": options.app}
|
2009-02-12 05:49:53 -08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-03-21 08:21:07 -07:00
|
|
|
if options.xrePath is None:
|
|
|
|
options.xrePath = os.path.dirname(options.app)
|
|
|
|
else:
|
|
|
|
# allow relative paths
|
2010-01-15 09:22:54 -08:00
|
|
|
options.xrePath = reftest.getFullPath(options.xrePath)
|
2009-03-21 08:21:07 -07:00
|
|
|
|
2010-05-06 05:06:09 -07:00
|
|
|
if options.symbolsPath and not isURL(options.symbolsPath):
|
2010-01-15 09:22:54 -08:00
|
|
|
options.symbolsPath = reftest.getFullPath(options.symbolsPath)
|
|
|
|
options.utilityPath = reftest.getFullPath(options.utilityPath)
|
2009-02-12 05:49:53 -08:00
|
|
|
|
2010-03-29 10:57:51 -07:00
|
|
|
if options.totalChunks is not None and options.thisChunk is None:
|
|
|
|
print "thisChunk must be specified when totalChunks is specified"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if options.totalChunks:
|
|
|
|
if not 1 <= options.thisChunk <= options.totalChunks:
|
|
|
|
print "thisChunk must be between 1 and totalChunks"
|
|
|
|
sys.exit(1)
|
2010-07-26 18:43:33 -07:00
|
|
|
|
|
|
|
if options.logFile:
|
|
|
|
options.logFile = reftest.getFullPath(options.logFile)
|
2010-03-29 10:57:51 -07:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
sys.exit(reftest.runTests(args[0], options))
|
|
|
|
|
2009-02-12 05:49:53 -08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|