2008-01-28 19:48:34 -08:00
|
|
|
#
|
2012-05-21 04:12:37 -07:00
|
|
|
# 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/.
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
"""
|
|
|
|
Runs the Mochitest test harness.
|
|
|
|
"""
|
|
|
|
|
2010-09-30 17:10:19 -07:00
|
|
|
from __future__ import with_statement
|
2008-01-28 19:48:34 -08:00
|
|
|
from datetime import datetime
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
import time
|
2010-11-07 12:47:02 -08:00
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
|
|
|
|
sys.path.insert(0, SCRIPT_DIR);
|
|
|
|
|
2009-02-09 10:57:27 -08:00
|
|
|
import shutil
|
2008-01-28 19:48:34 -08:00
|
|
|
from urllib import quote_plus as encodeURIComponent
|
|
|
|
import urllib2
|
2008-02-06 13:30:24 -08:00
|
|
|
import commands
|
2010-01-15 09:22:54 -08:00
|
|
|
from automation import Automation
|
2009-10-19 16:12:09 -07:00
|
|
|
from automationutils import *
|
2010-01-19 11:45:04 -08:00
|
|
|
import tempfile
|
2008-02-24 16:54:31 -08:00
|
|
|
|
2010-03-15 14:44:29 -07:00
|
|
|
VMWARE_RECORDING_HELPER_BASENAME = "vmwarerecordinghelper"
|
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
#######################
|
|
|
|
# COMMANDLINE OPTIONS #
|
|
|
|
#######################
|
|
|
|
|
|
|
|
class MochitestOptions(optparse.OptionParser):
|
|
|
|
"""Parses Mochitest commandline options."""
|
2010-01-15 09:22:54 -08:00
|
|
|
def __init__(self, automation, scriptdir, **kwargs):
|
|
|
|
self._automation = automation
|
2008-01-28 19:48:34 -08:00
|
|
|
optparse.OptionParser.__init__(self, **kwargs)
|
|
|
|
defaults = {}
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
# we want to pass down everything from self._automation.__all__
|
|
|
|
addCommonOptions(self, defaults=dict(zip(self._automation.__all__,
|
|
|
|
[getattr(self._automation, x) for x in self._automation.__all__])))
|
|
|
|
self._automation.addCommonOptions(self)
|
2009-05-11 12:54:39 -07:00
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
self.add_option("--close-when-done",
|
|
|
|
action = "store_true", dest = "closeWhenDone",
|
|
|
|
help = "close the application when tests are done running")
|
|
|
|
defaults["closeWhenDone"] = False
|
|
|
|
|
|
|
|
self.add_option("--appname",
|
|
|
|
action = "store", type = "string", dest = "app",
|
|
|
|
help = "absolute path to application, overriding default")
|
2010-01-15 09:22:54 -08:00
|
|
|
defaults["app"] = os.path.join(scriptdir, self._automation.DEFAULT_APP)
|
2009-02-09 10:57:27 -08:00
|
|
|
|
|
|
|
self.add_option("--utility-path",
|
|
|
|
action = "store", type = "string", dest = "utilityPath",
|
|
|
|
help = "absolute path to directory containing utility programs (xpcshell, ssltunnel, certutil)")
|
2010-01-15 09:22:54 -08:00
|
|
|
defaults["utilityPath"] = self._automation.DIST_BIN
|
2009-02-09 10:57:27 -08:00
|
|
|
|
|
|
|
self.add_option("--certificate-path",
|
|
|
|
action = "store", type = "string", dest = "certPath",
|
|
|
|
help = "absolute path to directory containing certificate store to use testing profile")
|
2010-01-15 09:22:54 -08:00
|
|
|
defaults["certPath"] = self._automation.CERTS_SRC_DIR
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
self.add_option("--log-file",
|
2008-04-14 16:21:25 -07:00
|
|
|
action = "store", type = "string",
|
|
|
|
dest = "logFile", metavar = "FILE",
|
2008-01-28 19:48:34 -08:00
|
|
|
help = "file to which logging occurs")
|
2008-02-03 17:15:24 -08:00
|
|
|
defaults["logFile"] = ""
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
self.add_option("--autorun",
|
|
|
|
action = "store_true", dest = "autorun",
|
|
|
|
help = "start running tests when the application starts")
|
|
|
|
defaults["autorun"] = False
|
2009-10-16 13:23:30 -07:00
|
|
|
|
|
|
|
self.add_option("--timeout",
|
|
|
|
type = "int", dest = "timeout",
|
|
|
|
help = "per-test timeout in seconds")
|
|
|
|
defaults["timeout"] = None
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2009-09-22 06:12:58 -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")
|
|
|
|
defaults["thisChunk"] = None
|
|
|
|
|
|
|
|
self.add_option("--chunk-by-dir",
|
|
|
|
type = "int", dest = "chunkByDir",
|
|
|
|
help = "group tests together in the same chunk that are in the same top chunkByDir directories")
|
|
|
|
defaults["chunkByDir"] = 0
|
|
|
|
|
|
|
|
self.add_option("--shuffle",
|
|
|
|
dest = "shuffle",
|
|
|
|
action = "store_true",
|
|
|
|
help = "randomize test order")
|
|
|
|
defaults["shuffle"] = False
|
|
|
|
|
2008-04-14 16:21:25 -07:00
|
|
|
LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR", "FATAL")
|
|
|
|
LEVEL_STRING = ", ".join(LOG_LEVELS)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
self.add_option("--console-level",
|
|
|
|
action = "store", type = "choice", dest = "consoleLevel",
|
2008-04-14 16:21:25 -07:00
|
|
|
choices = LOG_LEVELS, metavar = "LEVEL",
|
|
|
|
help = "one of %s to determine the level of console "
|
|
|
|
"logging" % LEVEL_STRING)
|
2008-01-28 19:48:34 -08:00
|
|
|
defaults["consoleLevel"] = None
|
|
|
|
|
|
|
|
self.add_option("--file-level",
|
|
|
|
action = "store", type = "choice", dest = "fileLevel",
|
2008-04-14 16:21:25 -07:00
|
|
|
choices = LOG_LEVELS, metavar = "LEVEL",
|
|
|
|
help = "one of %s to determine the level of file "
|
|
|
|
"logging if a file has been specified, defaulting "
|
|
|
|
"to INFO" % LEVEL_STRING)
|
|
|
|
defaults["fileLevel"] = "INFO"
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
self.add_option("--chrome",
|
|
|
|
action = "store_true", dest = "chrome",
|
|
|
|
help = "run chrome Mochitests")
|
|
|
|
defaults["chrome"] = False
|
|
|
|
|
2011-05-13 07:06:35 -07:00
|
|
|
self.add_option("--ipcplugins",
|
|
|
|
action = "store_true", dest = "ipcplugins",
|
|
|
|
help = "run ipcplugins Mochitests")
|
|
|
|
defaults["ipcplugins"] = False
|
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
self.add_option("--test-path",
|
|
|
|
action = "store", type = "string", dest = "testPath",
|
|
|
|
help = "start in the given directory's tests")
|
|
|
|
defaults["testPath"] = ""
|
|
|
|
|
|
|
|
self.add_option("--browser-chrome",
|
|
|
|
action = "store_true", dest = "browserChrome",
|
|
|
|
help = "run browser chrome Mochitests")
|
|
|
|
defaults["browserChrome"] = False
|
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
self.add_option("--webapprt-content",
|
|
|
|
action = "store_true", dest = "webapprtContent",
|
|
|
|
help = "run WebappRT content tests")
|
|
|
|
defaults["webapprtContent"] = False
|
|
|
|
|
|
|
|
self.add_option("--webapprt-chrome",
|
|
|
|
action = "store_true", dest = "webapprtChrome",
|
|
|
|
help = "run WebappRT chrome tests")
|
|
|
|
defaults["webapprtChrome"] = False
|
|
|
|
|
2008-02-14 02:32:21 -08:00
|
|
|
self.add_option("--a11y",
|
|
|
|
action = "store_true", dest = "a11y",
|
|
|
|
help = "run accessibility Mochitests");
|
2010-06-24 13:30:50 -07:00
|
|
|
defaults["a11y"] = False
|
2008-02-14 02:32:21 -08:00
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
self.add_option("--setenv",
|
2008-04-14 16:21:25 -07:00
|
|
|
action = "append", type = "string",
|
|
|
|
dest = "environment", metavar = "NAME=VALUE",
|
|
|
|
help = "sets the given variable in the application's "
|
|
|
|
"environment")
|
2008-01-28 19:48:34 -08:00
|
|
|
defaults["environment"] = []
|
2012-07-19 10:31:51 -07:00
|
|
|
|
|
|
|
self.add_option("--exclude-extension",
|
|
|
|
action = "append", type = "string",
|
|
|
|
dest = "extensionsToExclude",
|
|
|
|
help = "excludes the given extension from being installed "
|
|
|
|
"in the test profile")
|
|
|
|
defaults["extensionsToExclude"] = []
|
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
self.add_option("--browser-arg",
|
2008-04-14 16:21:25 -07:00
|
|
|
action = "append", type = "string",
|
|
|
|
dest = "browserArgs", metavar = "ARG",
|
2008-01-28 19:48:34 -08:00
|
|
|
help = "provides an argument to the test application")
|
|
|
|
defaults["browserArgs"] = []
|
|
|
|
|
2008-02-24 16:54:31 -08:00
|
|
|
self.add_option("--leak-threshold",
|
2008-04-14 16:21:25 -07:00
|
|
|
action = "store", type = "int",
|
|
|
|
dest = "leakThreshold", metavar = "THRESHOLD",
|
2008-02-24 16:54:31 -08:00
|
|
|
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")
|
2009-02-25 07:25:05 -08:00
|
|
|
defaults["leakThreshold"] = 0
|
2008-02-24 16:54:31 -08:00
|
|
|
|
2008-05-06 10:40:41 -07:00
|
|
|
self.add_option("--fatal-assertions",
|
|
|
|
action = "store_true", dest = "fatalAssertions",
|
|
|
|
help = "abort testing whenever an assertion is hit "
|
|
|
|
"(requires a debug build to be effective)")
|
|
|
|
defaults["fatalAssertions"] = False
|
|
|
|
|
2009-02-09 10:57:27 -08:00
|
|
|
self.add_option("--extra-profile-file",
|
|
|
|
action = "append", dest = "extraProfileFiles",
|
|
|
|
help = "copy specified files/dirs to testing profile")
|
|
|
|
defaults["extraProfileFiles"] = []
|
|
|
|
|
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-13 09:56:24 -08:00
|
|
|
self.add_option("--profile-path", action = "store",
|
|
|
|
type = "string", dest = "profilePath",
|
|
|
|
help = "Directory where the profile will be stored."
|
|
|
|
"This directory will be deleted after the tests are finished")
|
|
|
|
defaults["profilePath"] = tempfile.mkdtemp()
|
|
|
|
|
2012-08-06 14:22:09 -07:00
|
|
|
self.add_option("--testing-modules-dir", action = "store",
|
|
|
|
type = "string", dest = "testingModulesDir",
|
|
|
|
help = "Directory where testing-only JS modules are "
|
|
|
|
"located.")
|
|
|
|
defaults["testingModulesDir"] = None
|
|
|
|
|
2010-03-15 14:44:29 -07:00
|
|
|
self.add_option("--use-vmware-recording",
|
|
|
|
action = "store_true", dest = "vmwareRecording",
|
|
|
|
help = "enables recording while the application is running "
|
|
|
|
"inside a VMware Workstation 7.0 or later VM")
|
|
|
|
defaults["vmwareRecording"] = False
|
|
|
|
|
2011-08-29 13:14:33 -07:00
|
|
|
self.add_option("--repeat",
|
2011-07-14 14:39:17 -07:00
|
|
|
action = "store", type = "int",
|
2011-08-29 13:14:33 -07:00
|
|
|
dest = "repeat", metavar = "REPEAT",
|
2011-09-26 04:41:17 -07:00
|
|
|
help = "repeats the test or set of tests the given number of times, ie: repeat=1 will run the test twice.")
|
2011-08-29 13:14:33 -07:00
|
|
|
defaults["repeat"] = 0
|
2011-07-14 14:39:17 -07:00
|
|
|
|
2011-09-26 04:41:17 -07:00
|
|
|
self.add_option("--run-only-tests",
|
|
|
|
action = "store", type="string", dest = "runOnlyTests",
|
2012-06-14 06:01:23 -07:00
|
|
|
help = "JSON list of tests that we only want to run, cannot be specified with --exclude-tests. [DEPRECATED- please use --test-manifest]")
|
2011-09-26 04:41:17 -07:00
|
|
|
defaults["runOnlyTests"] = None
|
|
|
|
|
|
|
|
self.add_option("--exclude-tests",
|
|
|
|
action = "store", type="string", dest = "excludeTests",
|
2012-06-14 06:01:23 -07:00
|
|
|
help = "JSON list of tests that we want to not run, cannot be specified with --run-only-tests. [DEPRECATED- please use --test-manifest]")
|
2011-09-26 04:41:17 -07:00
|
|
|
defaults["excludeTests"] = None
|
|
|
|
|
2012-06-14 06:01:23 -07:00
|
|
|
self.add_option("--test-manifest",
|
|
|
|
action = "store", type="string", dest = "testManifest",
|
|
|
|
help = "JSON list of tests to specify 'runtests' and 'excludetests'.")
|
|
|
|
defaults["testManifest"] = None
|
|
|
|
|
2012-02-20 06:59:04 -08:00
|
|
|
self.add_option("--failure-file",
|
|
|
|
action = "store", type="string", dest = "failureFile",
|
|
|
|
help = "Filename of the output file where we can store a .json list of failures to be run in the future with --run-only-tests.")
|
|
|
|
defaults["failureFile"] = None
|
|
|
|
|
2012-11-28 07:23:11 -08:00
|
|
|
self.add_option("--run-slower",
|
|
|
|
action = "store_true", dest = "runSlower",
|
|
|
|
help = "Delay execution between test files.")
|
|
|
|
defaults["runSlower"] = False
|
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
# -h, --help are automatically handled by OptionParser
|
|
|
|
|
|
|
|
self.set_defaults(**defaults)
|
|
|
|
|
|
|
|
usage = """\
|
|
|
|
Usage instructions for runtests.py.
|
|
|
|
All arguments are optional.
|
|
|
|
If --chrome is specified, chrome tests will be run instead of web content tests.
|
|
|
|
If --browser-chrome is specified, browser-chrome tests will be run instead of web content tests.
|
2008-04-14 16:21:25 -07:00
|
|
|
See <http://mochikit.com/doc/html/MochiKit/Logging.html> for details on the logging levels."""
|
2008-01-28 19:48:34 -08:00
|
|
|
self.set_usage(usage)
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
def verifyOptions(self, options, mochitest):
|
|
|
|
""" verify correct options and cleanup paths """
|
|
|
|
|
|
|
|
if options.totalChunks is not None and options.thisChunk is None:
|
|
|
|
self.error("thisChunk must be specified when totalChunks is specified")
|
|
|
|
|
|
|
|
if options.totalChunks:
|
|
|
|
if not 1 <= options.thisChunk <= options.totalChunks:
|
|
|
|
self.error("thisChunk must be between 1 and totalChunks")
|
|
|
|
|
|
|
|
if options.xrePath is None:
|
|
|
|
# default xrePath to the app path if not provided
|
|
|
|
# but only if an app path was explicitly provided
|
|
|
|
if options.app != self.defaults['app']:
|
|
|
|
options.xrePath = os.path.dirname(options.app)
|
|
|
|
else:
|
|
|
|
# otherwise default to dist/bin
|
|
|
|
options.xrePath = self._automation.DIST_BIN
|
|
|
|
|
|
|
|
# allow relative paths
|
|
|
|
options.xrePath = mochitest.getFullPath(options.xrePath)
|
|
|
|
|
|
|
|
options.profilePath = mochitest.getFullPath(options.profilePath)
|
|
|
|
|
|
|
|
options.app = mochitest.getFullPath(options.app)
|
|
|
|
if not os.path.exists(options.app):
|
|
|
|
msg = """\
|
|
|
|
Error: Path %(app)s doesn't exist.
|
2011-11-05 11:35:59 -07:00
|
|
|
Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
|
2010-03-13 09:56:24 -08:00
|
|
|
print msg % {"app": options.app}
|
|
|
|
return None
|
|
|
|
|
|
|
|
options.utilityPath = mochitest.getFullPath(options.utilityPath)
|
|
|
|
options.certPath = mochitest.getFullPath(options.certPath)
|
2010-05-06 05:06:09 -07:00
|
|
|
if options.symbolsPath and not isURL(options.symbolsPath):
|
2010-03-13 09:56:24 -08:00
|
|
|
options.symbolsPath = mochitest.getFullPath(options.symbolsPath)
|
|
|
|
|
|
|
|
options.webServer = self._automation.DEFAULT_WEB_SERVER
|
|
|
|
options.httpPort = self._automation.DEFAULT_HTTP_PORT
|
|
|
|
options.sslPort = self._automation.DEFAULT_SSL_PORT
|
2010-06-16 22:38:55 -07:00
|
|
|
options.webSocketPort = self._automation.DEFAULT_WEBSOCKET_PORT
|
2010-03-15 14:44:29 -07:00
|
|
|
|
|
|
|
if options.vmwareRecording:
|
|
|
|
if not self._automation.IS_WIN32:
|
|
|
|
self.error("use-vmware-recording is only supported on Windows.")
|
|
|
|
mochitest.vmwareHelperPath = os.path.join(
|
|
|
|
options.utilityPath, VMWARE_RECORDING_HELPER_BASENAME + ".dll")
|
|
|
|
if not os.path.exists(mochitest.vmwareHelperPath):
|
2010-05-17 11:00:13 -07:00
|
|
|
self.error("%s not found, cannot automate VMware recording." %
|
2010-03-15 14:44:29 -07:00
|
|
|
mochitest.vmwareHelperPath)
|
|
|
|
|
2011-09-26 04:41:17 -07:00
|
|
|
if options.runOnlyTests != None and options.excludeTests != None:
|
2012-06-14 06:01:23 -07:00
|
|
|
self.error("We can only support --run-only-tests OR --exclude-tests, not both. Please consider using --test-manifest instead.")
|
|
|
|
|
|
|
|
if options.testManifest != None and (options.runOnlyTests != None or options.excludeTests != None):
|
|
|
|
self.error("Please use --test-manifest only and not --run-only-tests or --exclude-tests.")
|
2011-09-26 04:41:17 -07:00
|
|
|
|
2012-02-20 06:59:04 -08:00
|
|
|
if options.runOnlyTests:
|
|
|
|
if not os.path.exists(os.path.abspath(options.runOnlyTests)):
|
|
|
|
self.error("unable to find --run-only-tests file '%s'" % options.runOnlyTests);
|
2012-06-14 06:01:23 -07:00
|
|
|
options.testManifest = options.runOnlyTests
|
|
|
|
options.runOnly = True
|
2011-09-26 04:41:17 -07:00
|
|
|
|
2012-02-20 06:59:04 -08:00
|
|
|
if options.excludeTests:
|
|
|
|
if not os.path.exists(os.path.abspath(options.excludeTests)):
|
|
|
|
self.error("unable to find --exclude-tests file '%s'" % options.excludeTests);
|
2012-06-14 06:01:23 -07:00
|
|
|
options.testManifest = options.excludeTests
|
|
|
|
options.runOnly = False
|
2011-09-26 04:41:17 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
if options.webapprtContent and options.webapprtChrome:
|
|
|
|
self.error("Only one of --webapprt-content and --webapprt-chrome may be given.")
|
|
|
|
|
2012-08-06 14:22:09 -07:00
|
|
|
# Try to guess the testing modules directory.
|
|
|
|
# This somewhat grotesque hack allows the buildbot machines to find the
|
|
|
|
# modules directory without having to configure the buildbot hosts. This
|
|
|
|
# code should never be executed in local runs because the build system
|
|
|
|
# should always set the flag that populates this variable. If buildbot ever
|
|
|
|
# passes this argument, this code can be deleted.
|
|
|
|
if options.testingModulesDir is None:
|
|
|
|
possible = os.path.join(os.getcwd(), os.path.pardir, 'modules')
|
|
|
|
|
|
|
|
if os.path.isdir(possible):
|
|
|
|
options.testingModulesDir = possible
|
|
|
|
|
|
|
|
# Even if buildbot is updated, we still want this, as the path we pass in
|
|
|
|
# to the app must be absolute and have proper slashes.
|
|
|
|
if options.testingModulesDir is not None:
|
|
|
|
options.testingModulesDir = os.path.normpath(options.testingModulesDir)
|
|
|
|
|
|
|
|
if not os.path.isabs(options.testingModulesDir):
|
|
|
|
options.testingModulesDir = os.path.abspath(testingModulesDir)
|
|
|
|
|
|
|
|
if not os.path.isdir(options.testingModulesDir):
|
|
|
|
self.error('--testing-modules-dir not a directory: %s' %
|
|
|
|
options.testingModulesDir)
|
|
|
|
|
|
|
|
options.testingModulesDir = options.testingModulesDir.replace('\\', '/')
|
|
|
|
if options.testingModulesDir[-1] != '/':
|
|
|
|
options.testingModulesDir += '/'
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
return options
|
|
|
|
|
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
#######################
|
|
|
|
# HTTP SERVER SUPPORT #
|
|
|
|
#######################
|
|
|
|
|
|
|
|
class MochitestServer:
|
|
|
|
"Web server used to serve Mochitests, for closer fidelity to the real web."
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
def __init__(self, automation, options):
|
2010-01-15 09:22:54 -08:00
|
|
|
self._automation = automation
|
2008-01-28 19:48:34 -08:00
|
|
|
self._closeWhenDone = options.closeWhenDone
|
2009-02-09 10:57:27 -08:00
|
|
|
self._utilityPath = options.utilityPath
|
|
|
|
self._xrePath = options.xrePath
|
2010-03-13 09:56:24 -08:00
|
|
|
self._profileDir = options.profilePath
|
|
|
|
self.webServer = options.webServer
|
|
|
|
self.httpPort = options.httpPort
|
|
|
|
self.shutdownURL = "http://%(server)s:%(port)s/server/shutdown" % { "server" : self.webServer, "port" : self.httpPort }
|
2012-06-29 15:52:43 -07:00
|
|
|
self.testPrefix = "'webapprt_'" if options.webapprtContent else "undefined"
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
def start(self):
|
|
|
|
"Run the Mochitest server, returning the process ID of the server."
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
env = self._automation.environment(xrePath = self._xrePath)
|
2009-10-08 11:10:47 -07:00
|
|
|
env["XPCOM_DEBUG_BREAK"] = "warn"
|
2010-01-15 09:22:54 -08:00
|
|
|
if self._automation.IS_WIN32:
|
2009-02-09 10:57:27 -08:00
|
|
|
env["PATH"] = env["PATH"] + ";" + self._xrePath
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2009-02-09 10:57:27 -08:00
|
|
|
args = ["-g", self._xrePath,
|
|
|
|
"-v", "170",
|
2008-01-28 19:48:34 -08:00
|
|
|
"-f", "./" + "httpd.js",
|
2012-09-18 16:28:39 -07:00
|
|
|
"-e", """const _PROFILE_PATH = '%(profile)s';const _SERVER_PORT = '%(port)s'; const _SERVER_ADDR = '%(server)s';
|
|
|
|
const _TEST_PREFIX = %(testPrefix)s; const _DISPLAY_RESULTS = %(displayResults)s;""" %
|
|
|
|
{"profile" : self._profileDir.replace('\\', '\\\\'), "port" : self.httpPort, "server" : self.webServer,
|
|
|
|
"testPrefix" : self.testPrefix, "displayResults" : str(not self._closeWhenDone).lower() },
|
2008-01-28 19:48:34 -08:00
|
|
|
"-f", "./" + "server.js"]
|
|
|
|
|
2009-02-09 10:57:27 -08:00
|
|
|
xpcshell = os.path.join(self._utilityPath,
|
2010-01-15 09:22:54 -08:00
|
|
|
"xpcshell" + self._automation.BIN_SUFFIX)
|
|
|
|
self._process = self._automation.Process([xpcshell] + args, env = env)
|
2008-01-28 19:48:34 -08:00
|
|
|
pid = self._process.pid
|
|
|
|
if pid < 0:
|
|
|
|
print "Error starting server."
|
|
|
|
sys.exit(2)
|
2010-01-15 09:22:54 -08:00
|
|
|
self._automation.log.info("INFO | runtests.py | Server pid: %d", pid)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
def ensureReady(self, timeout):
|
|
|
|
assert timeout >= 0
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
aliveFile = os.path.join(self._profileDir, "server_alive.txt")
|
2008-01-28 19:48:34 -08:00
|
|
|
i = 0
|
|
|
|
while i < timeout:
|
|
|
|
if os.path.exists(aliveFile):
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
i += 1
|
|
|
|
else:
|
|
|
|
print "Timed out while waiting for server startup."
|
|
|
|
self.stop()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
try:
|
2011-04-18 09:41:57 -07:00
|
|
|
with urllib2.urlopen(self.shutdownURL) as c:
|
|
|
|
c.read()
|
2010-06-24 02:32:01 -07:00
|
|
|
|
|
|
|
rtncode = self._process.poll()
|
2010-09-30 17:10:19 -07:00
|
|
|
if rtncode is None:
|
2010-06-24 02:32:01 -07:00
|
|
|
self._process.terminate()
|
2008-01-28 19:48:34 -08:00
|
|
|
except:
|
2008-04-07 22:18:45 -07:00
|
|
|
self._process.kill()
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2010-06-16 22:38:55 -07:00
|
|
|
class WebSocketServer(object):
|
|
|
|
"Class which encapsulates the mod_pywebsocket server"
|
|
|
|
|
2010-11-20 19:29:58 -08:00
|
|
|
def __init__(self, automation, options, scriptdir, debuggerInfo=None):
|
2010-06-16 22:38:55 -07:00
|
|
|
self.port = options.webSocketPort
|
|
|
|
self._automation = automation
|
|
|
|
self._scriptdir = scriptdir
|
2010-11-20 19:29:58 -08:00
|
|
|
self.debuggerInfo = debuggerInfo
|
2010-06-16 22:38:55 -07:00
|
|
|
|
|
|
|
def start(self):
|
2011-05-09 14:54:35 -07:00
|
|
|
# Invoke pywebsocket through a wrapper which adds special SIGINT handling.
|
|
|
|
#
|
|
|
|
# If we're in an interactive debugger, the wrapper causes the server to
|
|
|
|
# ignore SIGINT so the server doesn't capture a ctrl+c meant for the
|
|
|
|
# debugger.
|
|
|
|
#
|
|
|
|
# If we're not in an interactive debugger, the wrapper causes the server to
|
|
|
|
# die silently upon receiving a SIGINT.
|
|
|
|
scriptPath = 'pywebsocket_wrapper.py'
|
2010-11-20 19:29:58 -08:00
|
|
|
script = os.path.join(self._scriptdir, scriptPath)
|
2011-05-09 14:54:35 -07:00
|
|
|
|
|
|
|
cmd = [sys.executable, script]
|
|
|
|
if self.debuggerInfo and self.debuggerInfo['interactive']:
|
|
|
|
cmd += ['--interactive']
|
2011-12-20 00:20:12 -08:00
|
|
|
cmd += ['-p', str(self.port), '-w', self._scriptdir, '-l', \
|
|
|
|
os.path.join(self._scriptdir, "websock.log"), \
|
|
|
|
'--log-level=debug', '--allow-handlers-outside-root-dir']
|
2010-06-16 22:38:55 -07:00
|
|
|
|
|
|
|
self._process = self._automation.Process(cmd)
|
|
|
|
pid = self._process.pid
|
|
|
|
if pid < 0:
|
|
|
|
print "Error starting websocket server."
|
|
|
|
sys.exit(2)
|
|
|
|
self._automation.log.info("INFO | runtests.py | Websocket server pid: %d", pid)
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._process.kill()
|
2009-09-22 06:12:58 -07:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
class Mochitest(object):
|
|
|
|
# Path to the test script on the server
|
2011-08-25 11:35:35 -07:00
|
|
|
TEST_PATH = "tests"
|
|
|
|
CHROME_PATH = "redirect.html"
|
|
|
|
PLAIN_LOOP_PATH = "plain-loop.html"
|
2010-01-19 11:45:04 -08:00
|
|
|
urlOpts = []
|
|
|
|
runSSLTunnel = True
|
2010-03-15 14:44:29 -07:00
|
|
|
vmwareHelper = None
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
oldcwd = os.getcwd()
|
|
|
|
|
|
|
|
def __init__(self, automation):
|
|
|
|
self.automation = automation
|
|
|
|
|
|
|
|
# Max time in seconds to wait for server startup before tests will fail -- if
|
|
|
|
# this seems big, it's mostly for debug machines where cold startup
|
|
|
|
# (particularly after a build) takes forever.
|
|
|
|
if self.automation.IS_DEBUG_BUILD:
|
|
|
|
self.SERVER_STARTUP_TIMEOUT = 180
|
2009-04-06 04:33:27 -07:00
|
|
|
else:
|
2010-01-15 09:22:54 -08:00
|
|
|
self.SERVER_STARTUP_TIMEOUT = 90
|
|
|
|
|
|
|
|
self.SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
|
|
|
|
os.chdir(self.SCRIPT_DIRECTORY)
|
|
|
|
|
|
|
|
def getFullPath(self, path):
|
2010-03-13 09:56:24 -08:00
|
|
|
" Get an absolute path relative to self.oldcwd."
|
2010-01-15 09:22:54 -08:00
|
|
|
return os.path.normpath(os.path.join(self.oldcwd, os.path.expanduser(path)))
|
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
def buildTestPath(self, options):
|
2010-03-13 09:56:24 -08:00
|
|
|
""" Build the url path to the specific test harness and test file or directory """
|
|
|
|
testHost = "http://mochi.test:8888"
|
2011-08-25 11:35:35 -07:00
|
|
|
testURL = ("/").join([testHost, self.TEST_PATH, options.testPath])
|
2011-08-29 13:14:33 -07:00
|
|
|
if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.repeat > 0:
|
2011-08-25 11:35:35 -07:00
|
|
|
testURL = ("/").join([testHost, self.PLAIN_LOOP_PATH])
|
2011-05-17 10:10:37 -07:00
|
|
|
if options.chrome or options.a11y:
|
2011-08-25 11:35:35 -07:00
|
|
|
testURL = ("/").join([testHost, self.CHROME_PATH])
|
2010-01-19 11:45:04 -08:00
|
|
|
elif options.browserChrome:
|
|
|
|
testURL = "about:blank"
|
2011-05-13 07:06:35 -07:00
|
|
|
elif options.ipcplugins:
|
2011-08-25 11:35:35 -07:00
|
|
|
testURL = ("/").join([testHost, self.TEST_PATH, "dom/plugins/test"])
|
2010-01-19 11:45:04 -08:00
|
|
|
return testURL
|
|
|
|
|
2010-11-20 19:29:58 -08:00
|
|
|
def startWebSocketServer(self, options, debuggerInfo):
|
2010-06-16 22:38:55 -07:00
|
|
|
""" Launch the websocket server """
|
|
|
|
if options.webServer != '127.0.0.1':
|
|
|
|
return
|
|
|
|
|
2010-11-20 19:29:58 -08:00
|
|
|
self.wsserver = WebSocketServer(self.automation, options,
|
|
|
|
self.SCRIPT_DIRECTORY, debuggerInfo)
|
2010-06-16 22:38:55 -07:00
|
|
|
self.wsserver.start()
|
|
|
|
|
|
|
|
def stopWebSocketServer(self, options):
|
|
|
|
if options.webServer != '127.0.0.1':
|
|
|
|
return
|
|
|
|
|
|
|
|
self.wsserver.stop()
|
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
def startWebServer(self, options):
|
2010-03-13 09:56:24 -08:00
|
|
|
if options.webServer != '127.0.0.1':
|
|
|
|
return
|
|
|
|
|
|
|
|
""" Create the webserver and start it up """
|
|
|
|
self.server = MochitestServer(self.automation, options)
|
2010-01-19 11:45:04 -08:00
|
|
|
self.server.start()
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
# If we're lucky, the server has fully started by now, and all paths are
|
|
|
|
# ready, etc. However, xpcshell cold start times suck, at least for debug
|
|
|
|
# builds. We'll try to connect to the server for awhile, and if we fail,
|
|
|
|
# we'll try to kill the server and exit with an error.
|
|
|
|
self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
def stopWebServer(self, options):
|
2010-01-19 11:45:04 -08:00
|
|
|
""" Server's no longer needed, and perhaps more importantly, anything it might
|
|
|
|
spew to console shouldn't disrupt the leak information table we print next.
|
|
|
|
"""
|
2010-03-13 09:56:24 -08:00
|
|
|
if options.webServer != '127.0.0.1':
|
|
|
|
return
|
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
self.server.stop()
|
|
|
|
|
|
|
|
def getLogFilePath(self, logFile):
|
|
|
|
""" return the log file path relative to the device we are testing on, in most cases
|
|
|
|
it will be the full path on the local system
|
|
|
|
"""
|
|
|
|
return self.getFullPath(logFile)
|
|
|
|
|
|
|
|
def buildProfile(self, options):
|
|
|
|
""" create the profile and add optional chrome bits and files if requested """
|
2013-01-04 10:41:34 -08:00
|
|
|
self.automation.initializeProfile(options.profilePath,
|
|
|
|
options.extraPrefs,
|
|
|
|
useServerLocations=True)
|
2010-01-19 11:45:04 -08:00
|
|
|
manifest = self.addChromeToProfile(options)
|
|
|
|
self.copyExtraFilesToProfile(options)
|
2010-11-18 14:15:54 -08:00
|
|
|
self.installExtensionsToProfile(options)
|
2010-01-19 11:45:04 -08:00
|
|
|
return manifest
|
|
|
|
|
|
|
|
def buildBrowserEnv(self, options):
|
|
|
|
""" build the environment variables for the specific test and operating system """
|
2010-01-15 09:22:54 -08:00
|
|
|
browserEnv = self.automation.environment(xrePath = options.xrePath)
|
|
|
|
|
|
|
|
# These variables are necessary for correct application startup; change
|
|
|
|
# via the commandline at your own risk.
|
|
|
|
browserEnv["XPCOM_DEBUG_BREAK"] = "stack"
|
|
|
|
|
|
|
|
for v in options.environment:
|
|
|
|
ix = v.find("=")
|
|
|
|
if ix <= 0:
|
|
|
|
print "Error: syntax error in --setenv=" + v
|
2010-01-19 11:45:04 -08:00
|
|
|
return None
|
2010-01-15 09:22:54 -08:00
|
|
|
browserEnv[v[:ix]] = v[ix + 1:]
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
browserEnv["XPCOM_MEM_BLOAT_LOG"] = self.leak_report_file
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
if options.fatalAssertions:
|
|
|
|
browserEnv["XPCOM_DEBUG_BREAK"] = "stack-and-abort"
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
return browserEnv
|
|
|
|
|
2011-07-26 16:13:20 -07:00
|
|
|
def buildURLOptions(self, options, env):
|
2010-01-19 11:45:04 -08:00
|
|
|
""" Add test control options from the command line to the url
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
URL parameters to test URL:
|
|
|
|
|
|
|
|
autorun -- kick off tests automatically
|
2011-10-14 04:52:02 -07:00
|
|
|
closeWhenDone -- closes the browser after the tests
|
2011-07-26 16:13:20 -07:00
|
|
|
hideResultsTable -- hides the table of individual test results
|
2010-01-19 11:45:04 -08:00
|
|
|
logFile -- logs test run to an absolute path
|
|
|
|
totalChunks -- how many chunks to split tests into
|
|
|
|
thisChunk -- which chunk to run
|
|
|
|
timeout -- per-test timeout in seconds
|
2011-08-29 13:14:33 -07:00
|
|
|
repeat -- How many times to repeat the test, ie: repeat=1 will run the test twice.
|
2010-01-19 11:45:04 -08:00
|
|
|
"""
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
# allow relative paths for logFile
|
2008-01-28 19:48:34 -08:00
|
|
|
if options.logFile:
|
2010-03-13 09:56:24 -08:00
|
|
|
options.logFile = self.getLogFilePath(options.logFile)
|
2012-06-29 15:52:43 -07:00
|
|
|
if options.browserChrome or options.chrome or options.a11y or options.webapprtChrome:
|
2010-01-15 09:22:54 -08:00
|
|
|
self.makeTestConfig(options)
|
|
|
|
else:
|
|
|
|
if options.autorun:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("autorun=1")
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.timeout:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("timeout=%d" % options.timeout)
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.closeWhenDone:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("closeWhenDone=1")
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.logFile:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("logFile=" + encodeURIComponent(options.logFile))
|
|
|
|
self.urlOpts.append("fileLevel=" + encodeURIComponent(options.fileLevel))
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.consoleLevel:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("consoleLevel=" + encodeURIComponent(options.consoleLevel))
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.totalChunks:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("totalChunks=%d" % options.totalChunks)
|
|
|
|
self.urlOpts.append("thisChunk=%d" % options.thisChunk)
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.chunkByDir:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("chunkByDir=%d" % options.chunkByDir)
|
2010-01-15 09:22:54 -08:00
|
|
|
if options.shuffle:
|
2010-01-19 11:45:04 -08:00
|
|
|
self.urlOpts.append("shuffle=1")
|
2011-07-26 16:13:20 -07:00
|
|
|
if "MOZ_HIDE_RESULTS_TABLE" in env and env["MOZ_HIDE_RESULTS_TABLE"] == "1":
|
|
|
|
self.urlOpts.append("hideResultsTable=1")
|
2011-08-29 13:14:33 -07:00
|
|
|
if options.repeat:
|
|
|
|
self.urlOpts.append("repeat=%d" % options.repeat)
|
|
|
|
if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.repeat > 0:
|
2011-08-25 11:35:35 -07:00
|
|
|
self.urlOpts.append("testname=%s" % ("/").join([self.TEST_PATH, options.testPath]))
|
2012-06-14 06:01:23 -07:00
|
|
|
if options.testManifest:
|
|
|
|
self.urlOpts.append("testManifest=%s" % options.testManifest)
|
2012-08-10 09:44:50 -07:00
|
|
|
if hasattr(options, 'runOnly') and options.runOnly:
|
2012-06-14 06:01:23 -07:00
|
|
|
self.urlOpts.append("runOnly=true")
|
|
|
|
else:
|
|
|
|
self.urlOpts.append("runOnly=false")
|
2012-02-20 06:59:04 -08:00
|
|
|
if options.failureFile:
|
2012-08-14 15:27:26 -07:00
|
|
|
self.urlOpts.append("failureFile=%s" % self.getFullPath(options.failureFile))
|
2012-11-28 07:23:11 -08:00
|
|
|
if options.runSlower:
|
|
|
|
self.urlOpts.append("runSlower=true")
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
def cleanup(self, manifest, options):
|
2010-01-19 11:45:04 -08:00
|
|
|
""" remove temporary files and profile """
|
|
|
|
os.remove(manifest)
|
2010-03-13 09:56:24 -08:00
|
|
|
shutil.rmtree(options.profilePath)
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-05-17 11:00:13 -07:00
|
|
|
def startVMwareRecording(self, options):
|
2010-03-15 14:44:29 -07:00
|
|
|
""" starts recording inside VMware VM using the recording helper dll """
|
|
|
|
assert(self.automation.IS_WIN32)
|
|
|
|
from ctypes import cdll
|
|
|
|
self.vmwareHelper = cdll.LoadLibrary(self.vmwareHelperPath)
|
|
|
|
if self.vmwareHelper is None:
|
|
|
|
self.automation.log.warning("WARNING | runtests.py | Failed to load "
|
2010-05-17 11:00:13 -07:00
|
|
|
"VMware recording helper")
|
2010-03-15 14:44:29 -07:00
|
|
|
return
|
2010-05-17 11:00:13 -07:00
|
|
|
self.automation.log.info("INFO | runtests.py | Starting VMware recording.")
|
2010-03-15 14:44:29 -07:00
|
|
|
try:
|
|
|
|
self.vmwareHelper.StartRecording()
|
|
|
|
except Exception, e:
|
|
|
|
self.automation.log.warning("WARNING | runtests.py | Failed to start "
|
2010-05-17 11:00:13 -07:00
|
|
|
"VMware recording: (%s)" % str(e))
|
2010-03-15 14:44:29 -07:00
|
|
|
self.vmwareHelper = None
|
|
|
|
|
2010-05-17 11:00:13 -07:00
|
|
|
def stopVMwareRecording(self):
|
2010-03-15 14:44:29 -07:00
|
|
|
""" stops recording inside VMware VM using the recording helper dll """
|
|
|
|
assert(self.automation.IS_WIN32)
|
|
|
|
if self.vmwareHelper is not None:
|
2010-05-17 11:00:13 -07:00
|
|
|
self.automation.log.info("INFO | runtests.py | Stopping VMware "
|
2010-03-15 14:44:29 -07:00
|
|
|
"recording.")
|
|
|
|
try:
|
|
|
|
self.vmwareHelper.StopRecording()
|
|
|
|
except Exception, e:
|
|
|
|
self.automation.log.warning("WARNING | runtests.py | Failed to stop "
|
2010-05-17 11:00:13 -07:00
|
|
|
"VMware recording: (%s)" % str(e))
|
2010-03-15 14:44:29 -07:00
|
|
|
self.vmwareHelper = None
|
|
|
|
|
2013-01-04 10:41:34 -08:00
|
|
|
def runTests(self, options, onLaunch=None):
|
2010-01-19 11:45:04 -08:00
|
|
|
""" Prepare, configure, run tests and cleanup """
|
|
|
|
debuggerInfo = getDebuggerInfo(self.oldcwd, options.debugger, options.debuggerArgs,
|
|
|
|
options.debuggerInteractive);
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
self.leak_report_file = os.path.join(options.profilePath, "runtests_leaks.log")
|
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
browserEnv = self.buildBrowserEnv(options)
|
2010-09-30 17:10:19 -07:00
|
|
|
if browserEnv is None:
|
2010-01-19 11:45:04 -08:00
|
|
|
return 1
|
|
|
|
|
|
|
|
manifest = self.buildProfile(options)
|
2010-09-30 17:10:19 -07:00
|
|
|
if manifest is None:
|
|
|
|
return 1
|
2010-12-22 08:39:29 -08:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
self.startWebServer(options)
|
2010-11-20 19:29:58 -08:00
|
|
|
self.startWebSocketServer(options, debuggerInfo)
|
2010-01-19 11:45:04 -08:00
|
|
|
|
|
|
|
testURL = self.buildTestPath(options)
|
2011-07-26 16:13:20 -07:00
|
|
|
self.buildURLOptions(options, browserEnv)
|
2010-09-30 17:10:19 -07:00
|
|
|
if len(self.urlOpts) > 0:
|
2010-01-19 11:45:04 -08:00
|
|
|
testURL += "?" + "&".join(self.urlOpts)
|
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
if options.webapprtContent:
|
|
|
|
options.browserArgs.extend(('-test-mode', testURL))
|
|
|
|
testURL = None
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
# 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.
|
2010-03-13 09:56:24 -08:00
|
|
|
if os.path.exists(self.leak_report_file):
|
|
|
|
os.remove(self.leak_report_file)
|
2010-01-15 09:22:54 -08:00
|
|
|
|
|
|
|
# then again to actually run mochitest
|
|
|
|
if options.timeout:
|
2009-10-29 16:20:42 -07:00
|
|
|
timeout = options.timeout + 30
|
2010-01-22 11:24:01 -08:00
|
|
|
elif not options.autorun:
|
2009-10-30 10:00:19 -07:00
|
|
|
timeout = None
|
2010-01-15 09:22:54 -08:00
|
|
|
else:
|
2009-10-29 16:20:42 -07:00
|
|
|
timeout = 330.0 # default JS harness timeout is 300 seconds
|
2010-03-15 14:44:29 -07:00
|
|
|
|
|
|
|
if options.vmwareRecording:
|
2010-05-17 11:00:13 -07:00
|
|
|
self.startVMwareRecording(options);
|
2010-03-15 14:44:29 -07:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
self.automation.log.info("INFO | runtests.py | Running tests: start.\n")
|
2011-05-09 14:54:35 -07:00
|
|
|
try:
|
|
|
|
status = self.automation.runApp(testURL, browserEnv, options.app,
|
|
|
|
options.profilePath, options.browserArgs,
|
2013-01-04 10:41:34 -08:00
|
|
|
runSSLTunnel=self.runSSLTunnel,
|
|
|
|
utilityPath=options.utilityPath,
|
|
|
|
xrePath=options.xrePath,
|
2011-05-09 14:54:35 -07:00
|
|
|
certPath=options.certPath,
|
|
|
|
debuggerInfo=debuggerInfo,
|
|
|
|
symbolsPath=options.symbolsPath,
|
2013-01-04 10:41:34 -08:00
|
|
|
timeout=timeout,
|
|
|
|
onLaunch=onLaunch)
|
2011-05-09 14:54:35 -07:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.automation.log.info("INFO | runtests.py | Received keyboard interrupt.\n");
|
|
|
|
status = -1
|
2011-09-14 16:20:11 -07:00
|
|
|
except:
|
2012-05-02 04:15:07 -07:00
|
|
|
self.automation.log.exception("INFO | runtests.py | Received unexpected exception while running application\n")
|
2011-09-14 16:20:11 -07:00
|
|
|
status = 1
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2010-03-15 14:44:29 -07:00
|
|
|
if options.vmwareRecording:
|
2010-05-17 11:00:13 -07:00
|
|
|
self.stopVMwareRecording();
|
2010-03-15 14:44:29 -07:00
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
self.stopWebServer(options)
|
2010-06-16 22:38:55 -07:00
|
|
|
self.stopWebSocketServer(options)
|
2010-03-13 09:56:24 -08:00
|
|
|
processLeakLog(self.leak_report_file, options.leakThreshold)
|
2012-02-25 03:48:05 -08:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
self.automation.log.info("\nINFO | runtests.py | Running tests: end.")
|
|
|
|
|
2010-09-30 17:10:19 -07:00
|
|
|
if manifest is not None:
|
|
|
|
self.cleanup(manifest, options)
|
2010-01-15 09:22:54 -08:00
|
|
|
return status
|
|
|
|
|
|
|
|
def makeTestConfig(self, options):
|
|
|
|
"Creates a test configuration file for customizing test execution."
|
2011-05-17 10:10:37 -07:00
|
|
|
def jsonString(val):
|
|
|
|
if isinstance(val, bool):
|
|
|
|
if val:
|
|
|
|
return "true"
|
|
|
|
return "false"
|
|
|
|
elif val is None:
|
|
|
|
return '""'
|
|
|
|
elif isinstance(val, basestring):
|
|
|
|
return '"%s"' % (val.replace('\\', '\\\\'))
|
|
|
|
elif isinstance(val, int):
|
|
|
|
return '%s' % (val)
|
|
|
|
elif isinstance(val, list):
|
|
|
|
content = '['
|
|
|
|
first = True
|
|
|
|
for item in val:
|
|
|
|
if first:
|
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
content += ", "
|
|
|
|
content += jsonString(item)
|
|
|
|
content += ']'
|
|
|
|
return content
|
|
|
|
else:
|
|
|
|
print "unknown type: %s: %s" % (opt, val)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
options.logFile = options.logFile.replace("\\", "\\\\")
|
|
|
|
options.testPath = options.testPath.replace("\\", "\\\\")
|
|
|
|
testRoot = 'chrome'
|
|
|
|
if (options.browserChrome):
|
|
|
|
testRoot = 'browser'
|
|
|
|
elif (options.a11y):
|
|
|
|
testRoot = 'a11y'
|
2012-06-29 15:52:43 -07:00
|
|
|
elif (options.webapprtChrome):
|
|
|
|
testRoot = 'webapprtChrome'
|
|
|
|
|
2011-07-26 16:13:20 -07:00
|
|
|
if "MOZ_HIDE_RESULTS_TABLE" in os.environ and os.environ["MOZ_HIDE_RESULTS_TABLE"] == "1":
|
|
|
|
options.hideResultsTable = True
|
|
|
|
|
2011-05-17 10:10:37 -07:00
|
|
|
#TODO: when we upgrade to python 2.6, just use json.dumps(options.__dict__)
|
|
|
|
content = "{"
|
|
|
|
content += '"testRoot": "%s", ' % (testRoot)
|
|
|
|
first = True
|
|
|
|
for opt in options.__dict__.keys():
|
|
|
|
val = options.__dict__[opt]
|
|
|
|
if first:
|
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
content += ", "
|
|
|
|
|
|
|
|
content += '"' + opt + '": '
|
|
|
|
content += jsonString(val)
|
|
|
|
content += "}"
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
with open(os.path.join(options.profilePath, "testConfig.js"), "w") as config:
|
|
|
|
config.write(content)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
def addChromeToProfile(self, options):
|
|
|
|
"Adds MochiKit chrome tests to the profile."
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
# Create (empty) chrome directory.
|
2010-03-13 09:56:24 -08:00
|
|
|
chromedir = os.path.join(options.profilePath, "chrome")
|
2010-01-15 09:22:54 -08:00
|
|
|
os.mkdir(chromedir)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
# Write userChrome.css.
|
2010-01-15 09:22:54 -08:00
|
|
|
chrome = """
|
2008-01-28 19:48:34 -08:00
|
|
|
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
|
|
|
|
toolbar,
|
|
|
|
toolbarpalette {
|
|
|
|
background-color: rgb(235, 235, 235) !important;
|
|
|
|
}
|
|
|
|
toolbar#nav-bar {
|
|
|
|
background-image: none !important;
|
|
|
|
}
|
|
|
|
"""
|
2011-04-18 09:41:57 -07:00
|
|
|
with open(os.path.join(options.profilePath, "userChrome.css"), "a") as chromeFile:
|
|
|
|
chromeFile.write(chrome)
|
|
|
|
|
|
|
|
# Call copyTestsJarToProfile(), Write tests.manifest.
|
|
|
|
manifest = os.path.join(options.profilePath, "tests.manifest")
|
|
|
|
with open(manifest, "w") as manifestFile:
|
|
|
|
if self.copyTestsJarToProfile(options):
|
|
|
|
# Register tests.jar.
|
|
|
|
manifestFile.write("content mochitests jar:tests.jar!/content/\n");
|
|
|
|
else:
|
|
|
|
# Register chrome directory.
|
|
|
|
chrometestDir = os.path.abspath(".") + "/"
|
|
|
|
if self.automation.IS_WIN32:
|
|
|
|
chrometestDir = "file:///" + chrometestDir.replace("\\", "/")
|
|
|
|
manifestFile.write("content mochitests %s contentaccessible=yes\n" % chrometestDir)
|
|
|
|
|
2012-08-06 14:22:09 -07:00
|
|
|
if options.testingModulesDir is not None:
|
|
|
|
manifestFile.write("resource testing-common file:///%s\n" %
|
|
|
|
options.testingModulesDir)
|
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
# Call installChromeJar().
|
|
|
|
jarDir = "mochijar"
|
|
|
|
if not os.path.isdir(os.path.join(self.SCRIPT_DIRECTORY, jarDir)):
|
|
|
|
self.automation.log.warning("TEST-UNEXPECTED-FAIL | invalid setup: missing mochikit extension")
|
|
|
|
return None
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
# Support Firefox (browser), B2G (shell), SeaMonkey (navigator), and Webapp
|
|
|
|
# Runtime (webapp).
|
2011-04-18 09:50:04 -07:00
|
|
|
chrome = ""
|
2012-06-29 15:52:43 -07:00
|
|
|
if options.browserChrome or options.chrome or options.a11y or options.webapprtChrome:
|
2011-04-18 09:50:04 -07:00
|
|
|
chrome += """
|
2010-01-15 09:22:54 -08:00
|
|
|
overlay chrome://browser/content/browser.xul chrome://mochikit/content/browser-test-overlay.xul
|
2012-01-06 03:35:53 -08:00
|
|
|
overlay chrome://browser/content/shell.xul chrome://mochikit/content/browser-test-overlay.xul
|
2011-04-18 09:50:04 -07:00
|
|
|
overlay chrome://navigator/content/navigator.xul chrome://mochikit/content/browser-test-overlay.xul
|
2012-06-29 15:52:43 -07:00
|
|
|
overlay chrome://webapprt/content/webapp.xul chrome://mochikit/content/browser-test-overlay.xul
|
2011-04-18 09:50:04 -07:00
|
|
|
"""
|
2010-09-30 17:10:19 -07:00
|
|
|
|
2011-04-18 09:50:04 -07:00
|
|
|
self.installChromeJar(jarDir, chrome, options)
|
2010-10-21 13:15:57 -07:00
|
|
|
return manifest
|
2010-01-19 11:45:04 -08:00
|
|
|
|
2011-04-18 09:50:04 -07:00
|
|
|
def installChromeJar(self, jarDirName, chrome, options):
|
2010-09-30 17:10:19 -07:00
|
|
|
"""
|
|
|
|
copy mochijar directory to profile as an extension so we have chrome://mochikit for all harness code
|
|
|
|
"""
|
2011-04-18 09:41:57 -07:00
|
|
|
self.automation.installExtension(os.path.join(self.SCRIPT_DIRECTORY, jarDirName), \
|
|
|
|
options.profilePath, "mochikit@mozilla.org")
|
2010-09-30 17:10:19 -07:00
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
# Write chrome.manifest.
|
2011-10-22 11:37:15 -07:00
|
|
|
with open(os.path.join(options.profilePath, "extensions", "staged", "mochikit@mozilla.org", "chrome.manifest"), "a") as mfile:
|
2011-04-18 09:50:04 -07:00
|
|
|
mfile.write(chrome)
|
2010-09-30 17:10:19 -07:00
|
|
|
|
2011-04-18 09:41:57 -07:00
|
|
|
def copyTestsJarToProfile(self, options):
|
2010-09-30 17:10:19 -07:00
|
|
|
""" copy tests.jar to the profile directory so we can auto register it in the .xul harness """
|
2011-04-18 09:41:57 -07:00
|
|
|
testsJarFile = os.path.join(self.SCRIPT_DIRECTORY, "tests.jar")
|
|
|
|
if not os.path.isfile(testsJarFile):
|
|
|
|
return False
|
|
|
|
|
|
|
|
shutil.copy2(testsJarFile, options.profilePath)
|
|
|
|
return True
|
2010-09-30 17:10:19 -07:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
def copyExtraFilesToProfile(self, options):
|
|
|
|
"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, options.profilePath)
|
|
|
|
elif os.path.isdir(abspath):
|
|
|
|
dest = os.path.join(options.profilePath, 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 | runtests.py | Failed to copy %s to profile", abspath)
|
|
|
|
continue
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2011-10-14 08:53:06 -07:00
|
|
|
def installExtensionFromPath(self, options, path, extensionID = None):
|
|
|
|
extensionPath = self.getFullPath(path)
|
|
|
|
|
|
|
|
self.automation.log.info("INFO | runtests.py | Installing extension at %s to %s." %
|
|
|
|
(extensionPath, options.profilePath))
|
|
|
|
self.automation.installExtension(extensionPath, options.profilePath,
|
|
|
|
extensionID)
|
|
|
|
|
2010-11-18 14:15:54 -08:00
|
|
|
def installExtensionsToProfile(self, options):
|
2011-10-14 08:53:06 -07:00
|
|
|
"Install special testing extensions, application distributed extensions, and specified on the command line ones to testing profile."
|
|
|
|
extensionDirs = [
|
|
|
|
# Extensions distributed with the test harness.
|
|
|
|
os.path.normpath(os.path.join(self.SCRIPT_DIRECTORY, "extensions")),
|
|
|
|
# Extensions distributed with the application.
|
|
|
|
os.path.join(options.app[ : options.app.rfind(os.sep)], "distribution", "extensions")
|
|
|
|
]
|
|
|
|
|
|
|
|
for extensionDir in extensionDirs:
|
|
|
|
if os.path.isdir(extensionDir):
|
|
|
|
for dirEntry in os.listdir(extensionDir):
|
2012-07-19 10:31:51 -07:00
|
|
|
if dirEntry not in options.extensionsToExclude:
|
|
|
|
path = os.path.join(extensionDir, dirEntry)
|
|
|
|
if os.path.isdir(path) or (os.path.isfile(path) and path.endswith(".xpi")):
|
|
|
|
self.installExtensionFromPath(options, path)
|
2011-10-14 08:53:06 -07:00
|
|
|
|
|
|
|
# Install custom extensions passed on the command line.
|
|
|
|
for path in options.extensionsToInstall:
|
|
|
|
self.installExtensionFromPath(options, path)
|
2010-11-18 14:15:54 -08:00
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
def main():
|
|
|
|
automation = Automation()
|
|
|
|
mochitest = Mochitest(automation)
|
|
|
|
parser = MochitestOptions(automation, mochitest.SCRIPT_DIRECTORY)
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
options = parser.verifyOptions(options, mochitest)
|
|
|
|
if options == None:
|
2010-01-15 09:22:54 -08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2010-03-09 19:33:11 -08:00
|
|
|
options.utilityPath = mochitest.getFullPath(options.utilityPath)
|
|
|
|
options.certPath = mochitest.getFullPath(options.certPath)
|
2010-05-06 05:06:09 -07:00
|
|
|
if options.symbolsPath and not isURL(options.symbolsPath):
|
2010-03-09 19:33:11 -08:00
|
|
|
options.symbolsPath = mochitest.getFullPath(options.symbolsPath)
|
|
|
|
|
2010-06-16 22:38:55 -07:00
|
|
|
automation.setServerInfo(options.webServer,
|
|
|
|
options.httpPort,
|
|
|
|
options.sslPort,
|
2010-07-28 10:55:36 -07:00
|
|
|
options.webSocketPort)
|
2010-01-15 09:22:54 -08:00
|
|
|
sys.exit(mochitest.runTests(options))
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|