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
|
|
|
import os
|
|
|
|
import sys
|
2013-07-26 11:40:04 -07:00
|
|
|
SCRIPT_DIR = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
|
2010-11-07 12:47:02 -08:00
|
|
|
sys.path.insert(0, SCRIPT_DIR);
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
import json
|
|
|
|
import mozcrash
|
|
|
|
import mozinfo
|
|
|
|
import mozlog
|
|
|
|
import mozprocess
|
|
|
|
import mozrunner
|
|
|
|
import optparse
|
|
|
|
import re
|
2009-02-09 10:57:27 -08:00
|
|
|
import shutil
|
2013-09-23 07:47:48 -07:00
|
|
|
import signal
|
2013-10-01 15:09:46 -07:00
|
|
|
import subprocess
|
2013-09-23 07:47:48 -07:00
|
|
|
import tempfile
|
|
|
|
import time
|
|
|
|
import traceback
|
2008-01-28 19:48:34 -08:00
|
|
|
import urllib2
|
2013-09-23 07:47:48 -07:00
|
|
|
|
2013-11-20 12:53:08 -08:00
|
|
|
from automationutils import environment, getDebuggerInfo, isURL, KeyValueParseError, parseKeyValue, processLeakLog, systemMemory, dumpScreen, ShutdownLeaks
|
2013-09-23 07:47:48 -07:00
|
|
|
from datetime import datetime
|
2013-08-02 05:48:06 -07:00
|
|
|
from manifestparser import TestManifest
|
2013-09-23 07:47:48 -07:00
|
|
|
from mochitest_options import MochitestOptions
|
|
|
|
from mozprofile import Profile, Preferences
|
|
|
|
from mozprofile.permissions import ServerLocations
|
|
|
|
from urllib import quote_plus as encodeURIComponent
|
2013-08-02 05:48:06 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# This should use the `which` module already in tree, but it is
|
|
|
|
# not yet present in the mozharness environment
|
|
|
|
from mozrunner.utils import findInPath as which
|
|
|
|
|
|
|
|
# set up logging handler a la automation.py.in for compatability
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger()
|
|
|
|
def resetGlobalLog():
|
|
|
|
while log.handlers:
|
|
|
|
log.removeHandler(log.handlers[0])
|
|
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
|
|
log.setLevel(logging.INFO)
|
|
|
|
log.addHandler(handler)
|
|
|
|
resetGlobalLog()
|
|
|
|
|
|
|
|
####################
|
|
|
|
# PROCESS HANDLING #
|
|
|
|
####################
|
|
|
|
|
|
|
|
def call(*args, **kwargs):
|
|
|
|
"""front-end function to mozprocess.ProcessHandler"""
|
|
|
|
# TODO: upstream -> mozprocess
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=791383
|
|
|
|
process = mozprocess.ProcessHandler(*args, **kwargs)
|
|
|
|
process.run()
|
|
|
|
return process.wait()
|
|
|
|
|
|
|
|
def killPid(pid):
|
|
|
|
# see also https://bugzilla.mozilla.org/show_bug.cgi?id=911249#c58
|
|
|
|
try:
|
|
|
|
os.kill(pid, getattr(signal, "SIGKILL", signal.SIGTERM))
|
|
|
|
except Exception, e:
|
|
|
|
log.info("Failed to kill process %d: %s", pid, str(e))
|
|
|
|
|
|
|
|
if mozinfo.isWin:
|
|
|
|
import ctypes, ctypes.wintypes, time, msvcrt
|
|
|
|
|
|
|
|
def isPidAlive(pid):
|
|
|
|
STILL_ACTIVE = 259
|
|
|
|
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
|
|
|
pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
|
|
|
|
if not pHandle:
|
|
|
|
return False
|
|
|
|
pExitCode = ctypes.wintypes.DWORD()
|
|
|
|
ctypes.windll.kernel32.GetExitCodeProcess(pHandle, ctypes.byref(pExitCode))
|
|
|
|
ctypes.windll.kernel32.CloseHandle(pHandle)
|
|
|
|
return pExitCode.value == STILL_ACTIVE
|
2010-03-15 14:44:29 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
else:
|
|
|
|
import errno
|
2010-03-13 09:56:24 -08:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def isPidAlive(pid):
|
|
|
|
try:
|
|
|
|
# kill(pid, 0) checks for a valid PID without actually sending a signal
|
|
|
|
# The method throws OSError if the PID is invalid, which we catch below.
|
|
|
|
os.kill(pid, 0)
|
|
|
|
|
|
|
|
# Wait on it to see if it's a zombie. This can throw OSError.ECHILD if
|
|
|
|
# the process terminates before we get to this point.
|
|
|
|
wpid, wstatus = os.waitpid(pid, os.WNOHANG)
|
|
|
|
return wpid == 0
|
|
|
|
except OSError, err:
|
|
|
|
# Catch the errors we might expect from os.kill/os.waitpid,
|
|
|
|
# and re-raise any others
|
|
|
|
if err.errno == errno.ESRCH or err.errno == errno.ECHILD:
|
|
|
|
return False
|
|
|
|
raise
|
|
|
|
# TODO: ^ upstream isPidAlive to mozprocess
|
2010-03-13 09:56:24 -08:00
|
|
|
|
2008-01-28 19:48:34 -08:00
|
|
|
#######################
|
|
|
|
# HTTP SERVER SUPPORT #
|
|
|
|
#######################
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
class MochitestServer(object):
|
2008-01-28 19:48:34 -08:00
|
|
|
"Web server used to serve Mochitests, for closer fidelity to the real web."
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def __init__(self, options):
|
2013-07-26 11:40:04 -07:00
|
|
|
if isinstance(options, optparse.Values):
|
|
|
|
options = vars(options)
|
|
|
|
self._closeWhenDone = options['closeWhenDone']
|
|
|
|
self._utilityPath = options['utilityPath']
|
|
|
|
self._xrePath = options['xrePath']
|
|
|
|
self._profileDir = options['profilePath']
|
|
|
|
self.webServer = options['webServer']
|
|
|
|
self.httpPort = options['httpPort']
|
2010-03-13 09:56:24 -08:00
|
|
|
self.shutdownURL = "http://%(server)s:%(port)s/server/shutdown" % { "server" : self.webServer, "port" : self.httpPort }
|
2013-07-26 11:40:04 -07:00
|
|
|
self.testPrefix = "'webapprt_'" if options.get('webapprtContent') else "undefined"
|
|
|
|
|
|
|
|
if options.get('httpdPath'):
|
|
|
|
self._httpdPath = options['httpdPath']
|
2013-06-28 19:20:08 -07:00
|
|
|
else:
|
|
|
|
self._httpdPath = '.'
|
|
|
|
self._httpdPath = os.path.abspath(self._httpdPath)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
def start(self):
|
|
|
|
"Run the Mochitest server, returning the process ID of the server."
|
2013-07-26 11:40:04 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# get testing environment
|
|
|
|
env = environment(xrePath=self._xrePath)
|
2009-10-08 11:10:47 -07:00
|
|
|
env["XPCOM_DEBUG_BREAK"] = "warn"
|
2013-01-22 07:48:02 -08:00
|
|
|
|
|
|
|
# When running with an ASan build, our xpcshell server will also be ASan-enabled,
|
|
|
|
# thus consuming too much resources when running together with the browser on
|
|
|
|
# the test slaves. Try to limit the amount of resources by disabling certain
|
|
|
|
# features.
|
|
|
|
env["ASAN_OPTIONS"] = "quarantine_size=1:redzone=32"
|
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
if mozinfo.isWin:
|
2013-07-30 07:02:28 -07:00
|
|
|
env["PATH"] = env["PATH"] + ";" + str(self._xrePath)
|
2008-01-28 19:48:34 -08:00
|
|
|
|
2009-02-09 10:57:27 -08:00
|
|
|
args = ["-g", self._xrePath,
|
|
|
|
"-v", "170",
|
2013-06-26 20:42:46 -07:00
|
|
|
"-f", self._httpdPath + "/httpd.js",
|
2013-08-23 08:11:43 -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;""" %
|
2012-09-18 16:28:39 -07:00
|
|
|
{"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,
|
2013-07-26 11:40:04 -07:00
|
|
|
"xpcshell" + mozinfo.info['bin_suffix'])
|
2013-09-23 07:47:48 -07:00
|
|
|
command = [xpcshell] + args
|
|
|
|
self._process = mozprocess.ProcessHandler(command, env=env)
|
|
|
|
self._process.run()
|
|
|
|
log.info("%s : launching %s", self.__class__.__name__, command)
|
2008-01-28 19:48:34 -08:00
|
|
|
pid = self._process.pid
|
2013-07-26 11:40:04 -07:00
|
|
|
log.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:
|
2013-09-19 05:20:17 -07:00
|
|
|
log.error("TEST-UNEXPECTED-FAIL | runtests.py | Timed out while waiting for server startup.")
|
2008-01-28 19:48:34 -08:00
|
|
|
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
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# TODO: need ProcessHandler.poll()
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=912285
|
|
|
|
# rtncode = self._process.poll()
|
|
|
|
rtncode = self._process.proc.poll()
|
2010-09-30 17:10:19 -07:00
|
|
|
if rtncode is None:
|
2013-09-23 07:47:48 -07:00
|
|
|
# TODO: need ProcessHandler.terminate() and/or .send_signal()
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=912285
|
|
|
|
# self._process.terminate()
|
|
|
|
self._process.proc.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"
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def __init__(self, options, scriptdir, debuggerInfo=None):
|
2010-06-16 22:38:55 -07:00
|
|
|
self.port = options.webSocketPort
|
|
|
|
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']
|
2013-09-23 07:47:48 -07:00
|
|
|
# start the process
|
|
|
|
self._process = mozprocess.ProcessHandler(cmd)
|
|
|
|
self._process.run()
|
2010-06-16 22:38:55 -07:00
|
|
|
pid = self._process.pid
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Websocket server pid: %d", pid)
|
2010-06-16 22:38:55 -07:00
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._process.kill()
|
2009-09-22 06:12:58 -07:00
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
class MochitestUtilsMixin(object):
|
|
|
|
"""
|
|
|
|
Class containing some utility functions common to both local and remote
|
|
|
|
mochitest runners
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO Utility classes are a code smell. This class is temporary
|
|
|
|
# and should be removed when desktop mochitests are refactored
|
|
|
|
# on top of mozbase. Each of the functions in here should
|
|
|
|
# probably live somewhere in mozbase
|
|
|
|
|
|
|
|
oldcwd = os.getcwd()
|
|
|
|
jarDir = 'mochijar'
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
# Path to the test script on the server
|
2011-08-25 11:35:35 -07:00
|
|
|
TEST_PATH = "tests"
|
|
|
|
CHROME_PATH = "redirect.html"
|
2010-01-19 11:45:04 -08:00
|
|
|
urlOpts = []
|
2010-01-15 09:22:54 -08:00
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
def __init__(self):
|
|
|
|
os.chdir(SCRIPT_DIR)
|
2013-09-23 07:47:48 -07:00
|
|
|
self.update_mozinfo()
|
|
|
|
|
|
|
|
def update_mozinfo(self):
|
|
|
|
"""walk up directories to find mozinfo.json update the info"""
|
|
|
|
# TODO: This should go in a more generic place, e.g. mozinfo
|
|
|
|
|
2013-08-14 10:57:43 -07:00
|
|
|
path = SCRIPT_DIR
|
2013-09-23 07:47:48 -07:00
|
|
|
dirs = set()
|
2013-08-14 10:57:43 -07:00
|
|
|
while path != os.path.expanduser('~'):
|
|
|
|
if path in dirs:
|
|
|
|
break
|
2013-09-23 07:47:48 -07:00
|
|
|
dirs.add(path)
|
2013-08-14 10:57:43 -07:00
|
|
|
path = os.path.split(path)[0]
|
|
|
|
|
|
|
|
mozinfo.find_and_update_from_json(*dirs)
|
2010-01-15 09:22:54 -08:00
|
|
|
|
|
|
|
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)))
|
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
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 buildURLOptions(self, options, env):
|
|
|
|
""" Add test control options from the command line to the url
|
|
|
|
|
|
|
|
URL parameters to test URL:
|
|
|
|
|
|
|
|
autorun -- kick off tests automatically
|
|
|
|
closeWhenDone -- closes the browser after the tests
|
|
|
|
hideResultsTable -- hides the table of individual test results
|
|
|
|
logFile -- logs test run to an absolute path
|
|
|
|
totalChunks -- how many chunks to split tests into
|
|
|
|
thisChunk -- which chunk to run
|
2013-10-28 12:24:55 -07:00
|
|
|
startAt -- name of test to start at
|
|
|
|
endAt -- name of test to end at
|
2013-07-26 11:40:04 -07:00
|
|
|
timeout -- per-test timeout in seconds
|
|
|
|
repeat -- How many times to repeat the test, ie: repeat=1 will run the test twice.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# allow relative paths for logFile
|
|
|
|
if options.logFile:
|
|
|
|
options.logFile = self.getLogFilePath(options.logFile)
|
|
|
|
if options.browserChrome or options.chrome or options.a11y or options.webapprtChrome:
|
|
|
|
self.makeTestConfig(options)
|
|
|
|
else:
|
|
|
|
if options.autorun:
|
|
|
|
self.urlOpts.append("autorun=1")
|
|
|
|
if options.timeout:
|
|
|
|
self.urlOpts.append("timeout=%d" % options.timeout)
|
|
|
|
if options.closeWhenDone:
|
|
|
|
self.urlOpts.append("closeWhenDone=1")
|
|
|
|
if options.logFile:
|
|
|
|
self.urlOpts.append("logFile=" + encodeURIComponent(options.logFile))
|
|
|
|
self.urlOpts.append("fileLevel=" + encodeURIComponent(options.fileLevel))
|
|
|
|
if options.consoleLevel:
|
|
|
|
self.urlOpts.append("consoleLevel=" + encodeURIComponent(options.consoleLevel))
|
|
|
|
if options.totalChunks:
|
|
|
|
self.urlOpts.append("totalChunks=%d" % options.totalChunks)
|
|
|
|
self.urlOpts.append("thisChunk=%d" % options.thisChunk)
|
|
|
|
if options.chunkByDir:
|
|
|
|
self.urlOpts.append("chunkByDir=%d" % options.chunkByDir)
|
2013-10-28 12:24:55 -07:00
|
|
|
if options.startAt:
|
|
|
|
self.urlOpts.append("startAt=%s" % options.startAt)
|
|
|
|
if options.endAt:
|
|
|
|
self.urlOpts.append("endAt=%s" % options.endAt)
|
2013-07-26 11:40:04 -07:00
|
|
|
if options.shuffle:
|
|
|
|
self.urlOpts.append("shuffle=1")
|
|
|
|
if "MOZ_HIDE_RESULTS_TABLE" in env and env["MOZ_HIDE_RESULTS_TABLE"] == "1":
|
|
|
|
self.urlOpts.append("hideResultsTable=1")
|
|
|
|
if options.runUntilFailure:
|
|
|
|
self.urlOpts.append("runUntilFailure=1")
|
|
|
|
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:
|
|
|
|
self.urlOpts.append("testname=%s" % ("/").join([self.TEST_PATH, options.testPath]))
|
|
|
|
if options.testManifest:
|
|
|
|
self.urlOpts.append("testManifest=%s" % options.testManifest)
|
|
|
|
if hasattr(options, 'runOnly') and options.runOnly:
|
|
|
|
self.urlOpts.append("runOnly=true")
|
|
|
|
else:
|
|
|
|
self.urlOpts.append("runOnly=false")
|
2013-08-02 05:48:06 -07:00
|
|
|
if options.manifestFile:
|
|
|
|
self.urlOpts.append("manifestFile=%s" % options.manifestFile)
|
2013-07-26 11:40:04 -07:00
|
|
|
if options.failureFile:
|
|
|
|
self.urlOpts.append("failureFile=%s" % self.getFullPath(options.failureFile))
|
|
|
|
if options.runSlower:
|
|
|
|
self.urlOpts.append("runSlower=true")
|
2013-11-01 12:23:34 -07:00
|
|
|
if options.debugOnFailure:
|
|
|
|
self.urlOpts.append("debugOnFailure=true")
|
2013-11-21 08:33:43 -08:00
|
|
|
if options.dumpOutputDirectory:
|
|
|
|
self.urlOpts.append("dumpOutputDirectory=%s" % encodeURIComponent(options.dumpOutputDirectory))
|
|
|
|
if options.dumpAboutMemoryAfterTest:
|
|
|
|
self.urlOpts.append("dumpAboutMemoryAfterTest=true")
|
|
|
|
if options.dumpDMDAfterTest:
|
|
|
|
self.urlOpts.append("dumpDMDAfterTest=true")
|
2013-07-26 11:40:04 -07:00
|
|
|
|
2010-01-19 11:45:04 -08:00
|
|
|
def buildTestPath(self, options):
|
2013-08-02 05:48:06 -07:00
|
|
|
""" Build the url path to the specific test harness and test file or directory
|
|
|
|
Build a manifest of tests to run and write out a json file for the harness to read
|
|
|
|
"""
|
|
|
|
if options.manifestFile and os.path.isfile(options.manifestFile):
|
|
|
|
manifest = TestManifest(strict=False)
|
|
|
|
manifest.read(options.manifestFile)
|
2013-09-23 07:47:48 -07:00
|
|
|
# Bug 883858 - return all tests including disabled tests
|
2013-11-17 20:09:01 -08:00
|
|
|
tests = manifest.active_tests(disabled=True, **mozinfo.info)
|
2013-11-24 15:33:11 -08:00
|
|
|
# We need to ensure we match on a complete directory name matching the
|
|
|
|
# test root, and not a substring somewhere else in the path.
|
|
|
|
test_root = os.path.sep + self.getTestRoot(options) + os.path.sep
|
2013-08-02 05:48:06 -07:00
|
|
|
paths = []
|
|
|
|
for test in tests:
|
2013-11-24 15:33:11 -08:00
|
|
|
tp = test['path'].split(test_root, 1)[1].replace('\\', '/').strip('/')
|
2013-08-02 05:48:06 -07:00
|
|
|
|
|
|
|
# Filter out tests if we are using --test-path
|
|
|
|
if options.testPath and not tp.startswith(options.testPath):
|
|
|
|
continue
|
|
|
|
|
2013-11-06 15:49:41 -08:00
|
|
|
testob = {'path': tp}
|
|
|
|
if test.has_key('disabled'):
|
|
|
|
testob['disabled'] = test['disabled']
|
|
|
|
paths.append(testob)
|
2013-08-02 05:48:06 -07:00
|
|
|
|
|
|
|
# Bug 883865 - add this functionality into manifestDestiny
|
|
|
|
with open('tests.json', 'w') as manifestFile:
|
|
|
|
manifestFile.write(json.dumps({'tests': paths}))
|
|
|
|
options.manifestFile = 'tests.json'
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
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:
|
2013-10-10 17:29:06 -07:00
|
|
|
testURL = ("/").join([testHost, self.TEST_PATH, os.path.dirname(options.testPath)])
|
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
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
self.wsserver = WebSocketServer(options, SCRIPT_DIR, 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):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""Create the webserver and start it up"""
|
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
if options.webServer != '127.0.0.1':
|
|
|
|
return
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
self.server = MochitestServer(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()
|
|
|
|
|
2013-07-26 11:40:04 -07: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)
|
|
|
|
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))
|
|
|
|
shutil.copytree(abspath, dest)
|
|
|
|
else:
|
|
|
|
log.warning("runtests.py | Failed to copy %s to profile", abspath)
|
|
|
|
|
|
|
|
def installChromeJar(self, chrome, options):
|
2010-01-19 11:45:04 -08:00
|
|
|
"""
|
2013-07-26 11:40:04 -07:00
|
|
|
copy mochijar directory to profile as an extension so we have chrome://mochikit for all harness code
|
|
|
|
"""
|
|
|
|
# Write chrome.manifest.
|
|
|
|
with open(os.path.join(options.profilePath, "extensions", "staged", "mochikit@mozilla.org", "chrome.manifest"), "a") as mfile:
|
|
|
|
mfile.write(chrome)
|
|
|
|
|
|
|
|
def addChromeToProfile(self, options):
|
|
|
|
"Adds MochiKit chrome tests to the profile."
|
|
|
|
|
|
|
|
# Create (empty) chrome directory.
|
|
|
|
chromedir = os.path.join(options.profilePath, "chrome")
|
|
|
|
os.mkdir(chromedir)
|
|
|
|
|
|
|
|
# Write userChrome.css.
|
|
|
|
chrome = """
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
with open(os.path.join(options.profilePath, "userChrome.css"), "a") as chromeFile:
|
|
|
|
chromeFile.write(chrome)
|
|
|
|
|
|
|
|
manifest = os.path.join(options.profilePath, "tests.manifest")
|
|
|
|
with open(manifest, "w") as manifestFile:
|
2013-11-18 10:38:37 -08:00
|
|
|
# Register chrome directory.
|
|
|
|
chrometestDir = os.path.abspath(".") + "/"
|
|
|
|
if mozinfo.isWin:
|
|
|
|
chrometestDir = "file:///" + chrometestDir.replace("\\", "/")
|
|
|
|
manifestFile.write("content mochitests %s contentaccessible=yes\n" % chrometestDir)
|
2013-07-26 11:40:04 -07:00
|
|
|
|
|
|
|
if options.testingModulesDir is not None:
|
|
|
|
manifestFile.write("resource testing-common file:///%s\n" %
|
|
|
|
options.testingModulesDir)
|
|
|
|
|
|
|
|
# Call installChromeJar().
|
|
|
|
if not os.path.isdir(os.path.join(SCRIPT_DIR, self.jarDir)):
|
|
|
|
log.testFail("invalid setup: missing mochikit extension")
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Support Firefox (browser), B2G (shell), SeaMonkey (navigator), and Webapp
|
|
|
|
# Runtime (webapp).
|
|
|
|
chrome = ""
|
|
|
|
if options.browserChrome or options.chrome or options.a11y or options.webapprtChrome:
|
|
|
|
chrome += """
|
|
|
|
overlay chrome://browser/content/browser.xul chrome://mochikit/content/browser-test-overlay.xul
|
2013-08-28 14:35:34 -07:00
|
|
|
overlay chrome://browser/content/shell.xhtml chrome://mochikit/content/browser-test-overlay.xul
|
2013-07-26 11:40:04 -07:00
|
|
|
overlay chrome://navigator/content/navigator.xul chrome://mochikit/content/browser-test-overlay.xul
|
|
|
|
overlay chrome://webapprt/content/webapp.xul chrome://mochikit/content/browser-test-overlay.xul
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.installChromeJar(chrome, options)
|
|
|
|
return manifest
|
|
|
|
|
|
|
|
def getExtensionsToInstall(self, options):
|
|
|
|
"Return a list of extensions to install in the profile"
|
|
|
|
extensions = options.extensionsToInstall or []
|
|
|
|
appDir = options.app[:options.app.rfind(os.sep)] if options.app else options.utilityPath
|
|
|
|
|
|
|
|
extensionDirs = [
|
|
|
|
# Extensions distributed with the test harness.
|
|
|
|
os.path.normpath(os.path.join(SCRIPT_DIR, "extensions")),
|
|
|
|
]
|
|
|
|
if appDir:
|
|
|
|
# Extensions distributed with the application.
|
|
|
|
extensionDirs.append(os.path.join(appDir, "distribution", "extensions"))
|
|
|
|
|
|
|
|
for extensionDir in extensionDirs:
|
|
|
|
if os.path.isdir(extensionDir):
|
|
|
|
for dirEntry in os.listdir(extensionDir):
|
|
|
|
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")):
|
|
|
|
extensions.append(path)
|
|
|
|
|
|
|
|
# append mochikit
|
|
|
|
extensions.append(os.path.join(SCRIPT_DIR, self.jarDir))
|
|
|
|
return extensions
|
|
|
|
|
|
|
|
|
|
|
|
class Mochitest(MochitestUtilsMixin):
|
|
|
|
runSSLTunnel = True
|
|
|
|
vmwareHelper = None
|
2013-09-23 07:47:48 -07:00
|
|
|
DEFAULT_TIMEOUT = 60.0
|
|
|
|
|
|
|
|
# XXX use automation.py for test name to avoid breaking legacy
|
|
|
|
# TODO: replace this with 'runtests.py' or 'mochitest' or the like
|
|
|
|
test_name = 'automation.py'
|
2013-07-26 11:40:04 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def __init__(self):
|
2013-07-26 11:40:04 -07:00
|
|
|
super(Mochitest, self).__init__()
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# environment function for browserEnv
|
|
|
|
self.environment = environment
|
2013-07-26 11:40:04 -07:00
|
|
|
|
|
|
|
# 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.
|
2013-09-23 07:47:48 -07:00
|
|
|
self.SERVER_STARTUP_TIMEOUT = 180 if mozinfo.info.get('debug') else 90
|
|
|
|
|
|
|
|
# metro browser sub process id
|
|
|
|
self.browserProcessId = None
|
|
|
|
|
|
|
|
# cached server locations
|
|
|
|
self._locations = {}
|
|
|
|
|
|
|
|
self.haveDumpedScreen = False
|
|
|
|
|
|
|
|
def extraPrefs(self, extraPrefs):
|
|
|
|
"""interpolate extra preferences from option strings"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
return dict(parseKeyValue(extraPrefs, context='--setpref='))
|
|
|
|
except KeyValueParseError, e:
|
|
|
|
print str(e)
|
|
|
|
sys.exit(1)
|
2010-01-19 11:45:04 -08:00
|
|
|
|
|
|
|
def buildProfile(self, options):
|
|
|
|
""" create the profile and add optional chrome bits and files if requested """
|
2013-02-19 10:27:28 -08:00
|
|
|
if options.browserChrome and options.timeout:
|
|
|
|
options.extraPrefs.append("testing.browserTestHarness.timeout=%d" % options.timeout)
|
2013-11-03 15:07:49 -08:00
|
|
|
options.extraPrefs.append("browser.tabs.remote=%s" % ('true' if options.e10s else 'false'))
|
2013-07-30 05:30:40 -07:00
|
|
|
|
|
|
|
# get extensions to install
|
|
|
|
extensions = self.getExtensionsToInstall(options)
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# web apps
|
2013-07-30 05:30:40 -07:00
|
|
|
appsPath = os.path.join(SCRIPT_DIR, 'profile_data', 'webapps_mochitest.json')
|
2013-09-23 07:47:48 -07:00
|
|
|
if os.path.exists(appsPath):
|
|
|
|
with open(appsPath) as apps_file:
|
|
|
|
apps = json.load(apps_file)
|
|
|
|
else:
|
|
|
|
apps = None
|
|
|
|
|
|
|
|
# locations
|
|
|
|
locations_file = os.path.join(SCRIPT_DIR, 'server-locations.txt')
|
|
|
|
locations = ServerLocations(locations_file)
|
|
|
|
|
|
|
|
# preferences
|
2013-07-30 05:30:40 -07:00
|
|
|
prefsPath = os.path.join(SCRIPT_DIR, 'profile_data', 'prefs_general.js')
|
2013-09-23 07:47:48 -07:00
|
|
|
prefs = dict(Preferences.read_prefs(prefsPath))
|
|
|
|
prefs.update(self.extraPrefs(options.extraPrefs))
|
|
|
|
|
|
|
|
# interpolate preferences
|
|
|
|
interpolation = {"server": "%s:%s" % (options.webServer, options.httpPort)}
|
|
|
|
prefs = json.loads(json.dumps(prefs) % interpolation)
|
|
|
|
for pref in prefs:
|
|
|
|
prefs[pref] = Preferences.cast(prefs[pref])
|
|
|
|
# TODO: make this less hacky
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=913152
|
|
|
|
|
|
|
|
# proxy
|
|
|
|
proxy = {'remote': options.webServer,
|
|
|
|
'http': options.httpPort,
|
|
|
|
'https': options.sslPort,
|
|
|
|
# use SSL port for legacy compatibility; see
|
|
|
|
# - https://bugzilla.mozilla.org/show_bug.cgi?id=688667#c66
|
|
|
|
# - https://bugzilla.mozilla.org/show_bug.cgi?id=899221
|
|
|
|
# - https://github.com/mozilla/mozbase/commit/43f9510e3d58bfed32790c82a57edac5f928474d
|
|
|
|
# 'ws': str(self.webSocketPort)
|
|
|
|
'ws': options.sslPort
|
|
|
|
}
|
2013-07-30 05:30:40 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# create a profile
|
|
|
|
self.profile = Profile(profile=options.profilePath,
|
|
|
|
addons=extensions,
|
|
|
|
locations=locations,
|
|
|
|
preferences=prefs,
|
|
|
|
apps=apps,
|
|
|
|
proxy=proxy
|
|
|
|
)
|
|
|
|
|
|
|
|
# Fix options.profilePath for legacy consumers.
|
|
|
|
options.profilePath = self.profile.profile
|
2013-07-30 05:30:40 -07:00
|
|
|
|
|
|
|
manifest = self.addChromeToProfile(options)
|
2010-01-19 11:45:04 -08:00
|
|
|
self.copyExtraFilesToProfile(options)
|
2013-07-30 05:30:40 -07:00
|
|
|
return manifest
|
2010-01-19 11:45:04 -08:00
|
|
|
|
2013-09-16 11:44:25 -07:00
|
|
|
def buildBrowserEnv(self, options, debugger=False):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""build the environment variables for the specific test and operating system"""
|
2013-11-13 11:48:10 -08:00
|
|
|
browserEnv = self.environment(xrePath=options.xrePath, debugger=debugger,
|
|
|
|
dmdPath=options.dmdPath)
|
2010-01-15 09:22:54 -08:00
|
|
|
|
|
|
|
# These variables are necessary for correct application startup; change
|
|
|
|
# via the commandline at your own risk.
|
|
|
|
browserEnv["XPCOM_DEBUG_BREAK"] = "stack"
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# interpolate environment passed with options
|
|
|
|
try:
|
|
|
|
browserEnv.update(dict(parseKeyValue(options.environment, context='--setenv')))
|
|
|
|
except KeyValueParseError, e:
|
|
|
|
log.error(str(e))
|
|
|
|
return
|
2010-01-15 09:22:54 -08:00
|
|
|
|
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
|
|
|
|
|
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)
|
2013-09-23 07:47:48 -07:00
|
|
|
del self.profile
|
|
|
|
|
|
|
|
def dumpScreen(self, utilityPath):
|
|
|
|
if self.haveDumpedScreen:
|
|
|
|
log.info("Not taking screenshot here: see the one that was previously logged")
|
|
|
|
return
|
|
|
|
self.haveDumpedScreen = True
|
2013-10-05 15:28:34 -07:00
|
|
|
dumpScreen(utilityPath)
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
def killAndGetStack(self, processPID, utilityPath, debuggerInfo, dump_screen=False):
|
|
|
|
"""
|
|
|
|
Kill the process, preferrably in a way that gets us a stack trace.
|
|
|
|
Also attempts to obtain a screenshot before killing the process
|
|
|
|
if specified.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if dump_screen:
|
|
|
|
self.dumpScreen(utilityPath)
|
|
|
|
|
|
|
|
if mozinfo.info.get('crashreporter', True) and not debuggerInfo:
|
|
|
|
if mozinfo.isWin:
|
|
|
|
# We should have a "crashinject" program in our utility path
|
|
|
|
crashinject = os.path.normpath(os.path.join(utilityPath, "crashinject.exe"))
|
|
|
|
if os.path.exists(crashinject) and subprocess.Popen([crashinject, str(processPID)]).wait() == 0:
|
|
|
|
return
|
|
|
|
else:
|
2013-10-01 10:47:05 -07:00
|
|
|
try:
|
|
|
|
os.kill(processPID, signal.SIGABRT)
|
|
|
|
except OSError:
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=921509
|
|
|
|
log.info("Can't trigger Breakpad, process no longer exists")
|
2013-09-23 07:47:48 -07:00
|
|
|
return
|
|
|
|
log.info("Can't trigger Breakpad, just killing process")
|
|
|
|
killPid(processPID)
|
|
|
|
|
|
|
|
def checkForZombies(self, processLog, utilityPath, debuggerInfo):
|
|
|
|
"""Look for hung processes"""
|
|
|
|
|
|
|
|
if not os.path.exists(processLog):
|
|
|
|
log.info('Automation Error: PID log not found: %s', processLog)
|
|
|
|
# Whilst no hung process was found, the run should still display as a failure
|
|
|
|
return True
|
|
|
|
|
|
|
|
# scan processLog for zombies
|
|
|
|
log.info('INFO | zombiecheck | Reading PID log: %s', processLog)
|
|
|
|
processList = []
|
|
|
|
pidRE = re.compile(r'launched child process (\d+)$')
|
|
|
|
with open(processLog) as processLogFD:
|
|
|
|
for line in processLogFD:
|
|
|
|
log.info(line.rstrip())
|
|
|
|
m = pidRE.search(line)
|
|
|
|
if m:
|
|
|
|
processList.append(int(m.group(1)))
|
|
|
|
|
|
|
|
# kill zombies
|
|
|
|
foundZombie = False
|
|
|
|
for processPID in processList:
|
|
|
|
log.info("INFO | zombiecheck | Checking for orphan process with PID: %d", processPID)
|
|
|
|
if isPidAlive(processPID):
|
|
|
|
foundZombie = True
|
|
|
|
log.info("TEST-UNEXPECTED-FAIL | zombiecheck | child process %d still alive after shutdown", processPID)
|
|
|
|
self.killAndGetStack(processPID, utilityPath, debuggerInfo, dump_screen=not debuggerInfo)
|
|
|
|
|
|
|
|
return foundZombie
|
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 """
|
2013-09-23 07:47:48 -07:00
|
|
|
assert mozinfo.isWin
|
2010-03-15 14:44:29 -07:00
|
|
|
from ctypes import cdll
|
|
|
|
self.vmwareHelper = cdll.LoadLibrary(self.vmwareHelperPath)
|
|
|
|
if self.vmwareHelper is None:
|
2013-07-26 11:40:04 -07:00
|
|
|
log.warning("runtests.py | Failed to load "
|
|
|
|
"VMware recording helper")
|
2010-03-15 14:44:29 -07:00
|
|
|
return
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Starting VMware recording.")
|
2010-03-15 14:44:29 -07:00
|
|
|
try:
|
|
|
|
self.vmwareHelper.StartRecording()
|
|
|
|
except Exception, e:
|
2013-07-26 11:40:04 -07:00
|
|
|
log.warning("runtests.py | Failed to start "
|
|
|
|
"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 """
|
2013-09-23 07:47:48 -07:00
|
|
|
assert mozinfo.isWin
|
2010-03-15 14:44:29 -07:00
|
|
|
if self.vmwareHelper is not None:
|
2013-09-23 07:47:48 -07:00
|
|
|
log.info("runtests.py | Stopping VMware recording.")
|
2010-03-15 14:44:29 -07:00
|
|
|
try:
|
|
|
|
self.vmwareHelper.StopRecording()
|
|
|
|
except Exception, e:
|
2013-07-26 11:40:04 -07:00
|
|
|
log.warning("runtests.py | Failed to stop "
|
|
|
|
"VMware recording: (%s)" % str(e))
|
2010-03-15 14:44:29 -07:00
|
|
|
self.vmwareHelper = None
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def runApp(self,
|
|
|
|
testUrl,
|
|
|
|
env,
|
|
|
|
app,
|
|
|
|
profile,
|
|
|
|
extraArgs,
|
|
|
|
utilityPath,
|
|
|
|
xrePath,
|
|
|
|
certPath,
|
|
|
|
debuggerInfo=None,
|
|
|
|
symbolsPath=None,
|
|
|
|
timeout=-1,
|
2013-11-20 12:53:08 -08:00
|
|
|
onLaunch=None,
|
|
|
|
webapprtChrome=False):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""
|
|
|
|
Run the app, log the duration it took to execute, return the status code.
|
|
|
|
Kills the app if it runs for longer than |maxTime| seconds, or outputs nothing for |timeout| seconds.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# debugger information
|
|
|
|
interactive = False
|
|
|
|
debug_args = None
|
|
|
|
if debuggerInfo:
|
|
|
|
interactive = debuggerInfo['interactive']
|
|
|
|
debug_args = [debuggerInfo['path']] + debuggerInfo['args']
|
|
|
|
|
|
|
|
# ensure existence of required paths
|
|
|
|
required_paths = ('utilityPath', 'xrePath', 'certPath')
|
|
|
|
missing = [(path, locals()[path])
|
|
|
|
for path in required_paths
|
|
|
|
if not os.path.exists(locals()[path])]
|
|
|
|
if missing:
|
|
|
|
log.error("runtests.py | runApp called with missing paths: %s" % (
|
|
|
|
', '.join([("%s->%s" % (key, value)) for key, value in missing])))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# fix default timeout
|
|
|
|
if timeout == -1:
|
|
|
|
timeout = self.DEFAULT_TIMEOUT
|
|
|
|
|
|
|
|
# build parameters
|
|
|
|
is_test_build = mozinfo.info.get('tests_enabled', True)
|
|
|
|
bin_suffix = mozinfo.info.get('bin_suffix', '')
|
|
|
|
|
|
|
|
# copy env so we don't munge the caller's environment
|
|
|
|
env = env.copy()
|
|
|
|
|
|
|
|
# set process log environment variable
|
|
|
|
tmpfd, processLog = tempfile.mkstemp(suffix='pidlog')
|
|
|
|
os.close(tmpfd)
|
|
|
|
env["MOZ_PROCESS_LOG"] = processLog
|
|
|
|
|
|
|
|
if self.runSSLTunnel:
|
|
|
|
|
|
|
|
# create certificate database for the profile
|
|
|
|
# TODO: this should really be upstreamed somewhere, maybe mozprofile
|
|
|
|
certificateStatus = self.fillCertificateDB(self.profile.profile,
|
|
|
|
certPath,
|
|
|
|
utilityPath,
|
|
|
|
xrePath)
|
|
|
|
if certificateStatus:
|
|
|
|
log.info("TEST-UNEXPECTED-FAIL | runtests.py | Certificate integration failed")
|
|
|
|
return certificateStatus
|
|
|
|
|
|
|
|
# start ssltunnel to provide https:// URLs capability
|
|
|
|
ssltunnel = os.path.join(utilityPath, "ssltunnel" + bin_suffix)
|
|
|
|
ssltunnel_cfg = os.path.join(self.profile.profile, "ssltunnel.cfg")
|
|
|
|
ssltunnelProcess = mozprocess.ProcessHandler([ssltunnel, ssltunnel_cfg],
|
|
|
|
env=environment(xrePath=xrePath))
|
|
|
|
ssltunnelProcess.run()
|
|
|
|
log.info("INFO | runtests.py | SSL tunnel pid: %d", ssltunnelProcess.pid)
|
|
|
|
else:
|
|
|
|
ssltunnelProcess = None
|
|
|
|
|
|
|
|
if interactive:
|
|
|
|
# If an interactive debugger is attached,
|
|
|
|
# don't use timeouts, and don't capture ctrl-c.
|
|
|
|
timeout = None
|
|
|
|
signal.signal(signal.SIGINT, lambda sigid, frame: None)
|
|
|
|
|
|
|
|
# build command line
|
|
|
|
cmd = os.path.abspath(app)
|
|
|
|
args = list(extraArgs)
|
|
|
|
# TODO: mozrunner should use -foreground at least for mac
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=916512
|
|
|
|
args.append('-foreground')
|
|
|
|
if testUrl:
|
|
|
|
args.append(testUrl)
|
|
|
|
|
2013-11-20 12:53:08 -08:00
|
|
|
if mozinfo.info["debug"] and not webapprtChrome:
|
|
|
|
shutdownLeaks = ShutdownLeaks(log.info)
|
|
|
|
else:
|
|
|
|
shutdownLeaks = None
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# create an instance to process the output
|
|
|
|
outputHandler = self.OutputHandler(harness=self,
|
|
|
|
utilityPath=utilityPath,
|
|
|
|
symbolsPath=symbolsPath,
|
|
|
|
dump_screen_on_timeout=not debuggerInfo,
|
2013-11-20 12:53:08 -08:00
|
|
|
shutdownLeaks=shutdownLeaks,
|
2013-09-23 07:47:48 -07:00
|
|
|
)
|
|
|
|
|
2013-11-06 06:14:23 -08:00
|
|
|
def timeoutHandler():
|
|
|
|
browserProcessId = outputHandler.browserProcessId
|
|
|
|
self.handleTimeout(timeout, proc, utilityPath, debuggerInfo, browserProcessId)
|
|
|
|
kp_kwargs = {'kill_on_timeout': False,
|
|
|
|
'onTimeout': [timeoutHandler]}
|
2013-09-23 07:47:48 -07:00
|
|
|
# if the output handler is a pipe, it will process output via the subprocess
|
2013-11-06 06:14:23 -08:00
|
|
|
if not outputHandler.pipe:
|
|
|
|
kp_kwargs['processOutputLine'] = [outputHandler]
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# create mozrunner instance and start the system under test process
|
|
|
|
self.lastTestSeen = self.test_name
|
|
|
|
startTime = datetime.now()
|
2013-09-26 06:58:08 -07:00
|
|
|
|
|
|
|
# b2g desktop requires FirefoxRunner even though appname is b2g
|
|
|
|
if mozinfo.info.get('appname') == 'b2g' and mozinfo.info.get('toolkit') != 'gonk':
|
|
|
|
runner_cls = mozrunner.FirefoxRunner
|
|
|
|
else:
|
|
|
|
runner_cls = mozrunner.runners.get(mozinfo.info.get('appname', 'firefox'),
|
|
|
|
mozrunner.Runner)
|
2013-09-23 07:47:48 -07:00
|
|
|
runner = runner_cls(profile=self.profile,
|
|
|
|
binary=cmd,
|
|
|
|
cmdargs=args,
|
|
|
|
env=env,
|
|
|
|
process_class=mozprocess.ProcessHandlerMixin,
|
|
|
|
kp_kwargs=kp_kwargs,
|
|
|
|
)
|
|
|
|
|
|
|
|
# XXX work around bug 898379 until mozrunner is updated for m-c; see
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=746243#c49
|
|
|
|
runner.kp_kwargs = kp_kwargs
|
|
|
|
|
|
|
|
# start the runner
|
|
|
|
runner.start(debug_args=debug_args,
|
|
|
|
interactive=interactive,
|
|
|
|
outputTimeout=timeout)
|
|
|
|
proc = runner.process_handler
|
|
|
|
log.info("INFO | runtests.py | Application pid: %d", proc.pid)
|
|
|
|
|
|
|
|
# set process information on the output handler
|
2013-10-01 16:53:19 -07:00
|
|
|
outputHandler.setProcess(proc if interactive else proc.proc, timeout)
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
if onLaunch is not None:
|
|
|
|
# Allow callers to specify an onLaunch callback to be fired after the
|
|
|
|
# app is launched.
|
|
|
|
# We call onLaunch for b2g desktop mochitests so that we can
|
|
|
|
# run a Marionette script after gecko has completed startup.
|
|
|
|
onLaunch()
|
|
|
|
|
|
|
|
# wait until app is finished
|
|
|
|
# XXX copy functionality from
|
|
|
|
# https://github.com/mozilla/mozbase/blob/master/mozrunner/mozrunner/runner.py#L61
|
|
|
|
# until bug 913970 is fixed regarding mozrunner `wait` not returning status
|
|
|
|
# see https://bugzilla.mozilla.org/show_bug.cgi?id=913970
|
|
|
|
status = proc.wait()
|
|
|
|
runner.process_handler = None
|
|
|
|
|
2013-10-01 16:53:19 -07:00
|
|
|
if timeout is None:
|
|
|
|
didTimeout = False
|
|
|
|
else:
|
|
|
|
didTimeout = proc.didTimeout
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# finalize output handler
|
2013-10-01 16:53:19 -07:00
|
|
|
outputHandler.finish(didTimeout)
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# record post-test information
|
2013-10-21 04:46:49 -07:00
|
|
|
if status:
|
|
|
|
log.info("TEST-UNEXPECTED-FAIL | %s | application terminated with exit code %s", self.lastTestSeen, status)
|
|
|
|
else:
|
2013-09-23 07:47:48 -07:00
|
|
|
self.lastTestSeen = 'Main app process exited normally'
|
2013-10-21 04:46:49 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
log.info("INFO | runtests.py | Application ran for: %s", str(datetime.now() - startTime))
|
|
|
|
|
|
|
|
# Do a final check for zombie child processes.
|
|
|
|
zombieProcesses = self.checkForZombies(processLog, utilityPath, debuggerInfo)
|
|
|
|
|
|
|
|
# check for crashes
|
|
|
|
minidump_path = os.path.join(self.profile.profile, "minidumps")
|
|
|
|
crashed = mozcrash.check_for_crashes(minidump_path,
|
|
|
|
symbolsPath,
|
|
|
|
test_name=self.lastTestSeen)
|
|
|
|
|
|
|
|
if crashed or zombieProcesses:
|
|
|
|
status = 1
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
if os.path.exists(processLog):
|
|
|
|
os.remove(processLog)
|
|
|
|
if ssltunnelProcess:
|
|
|
|
ssltunnelProcess.kill()
|
|
|
|
|
|
|
|
return status
|
|
|
|
|
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 """
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# get debugger info, a dict of:
|
|
|
|
# {'path': path to the debugger (string),
|
|
|
|
# 'interactive': whether the debugger is interactive or not (bool)
|
|
|
|
# 'args': arguments to the debugger (list)
|
|
|
|
# TODO: use mozrunner.local.debugger_arguments:
|
|
|
|
# https://github.com/mozilla/mozbase/blob/master/mozrunner/mozrunner/local.py#L42
|
|
|
|
debuggerInfo = getDebuggerInfo(self.oldcwd,
|
|
|
|
options.debugger,
|
|
|
|
options.debuggerArgs,
|
|
|
|
options.debuggerInteractive)
|
2010-01-19 11:45:04 -08:00
|
|
|
|
2010-03-13 09:56:24 -08:00
|
|
|
self.leak_report_file = os.path.join(options.profilePath, "runtests_leaks.log")
|
|
|
|
|
2013-09-16 11:44:25 -07:00
|
|
|
browserEnv = self.buildBrowserEnv(options, debuggerInfo is not None)
|
2010-09-30 17:10:19 -07:00
|
|
|
if browserEnv is None:
|
2010-01-19 11:45:04 -08:00
|
|
|
return 1
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# buildProfile sets self.profile .
|
|
|
|
# This relies on sideeffects and isn't very stateful:
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=919300
|
2010-01-19 11:45:04 -08:00
|
|
|
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
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# start servers and set ports
|
|
|
|
# TODO: pass these values, don't set on `self`
|
|
|
|
self.webServer = options.webServer
|
|
|
|
self.httpPort = options.httpPort
|
|
|
|
self.sslPort = options.sslPort
|
|
|
|
self.webSocketPort = options.webSocketPort
|
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)
|
2013-09-23 07:47:48 -07:00
|
|
|
if self.urlOpts:
|
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
|
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
if options.immersiveMode:
|
2013-03-26 15:01:15 -07:00
|
|
|
options.browserArgs.extend(('-firefoxpath', options.app))
|
2013-02-12 12:51:24 -08:00
|
|
|
options.app = self.immersiveHelperPath
|
|
|
|
|
2013-10-21 09:12:12 -07:00
|
|
|
if options.jsdebugger:
|
|
|
|
options.browserArgs.extend(['-jsdebugger'])
|
|
|
|
|
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
|
2013-03-13 13:12:07 -07:00
|
|
|
elif options.debugger or 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
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Running tests: start.\n")
|
2011-05-09 14:54:35 -07:00
|
|
|
try:
|
2013-09-23 07:47:48 -07:00
|
|
|
status = self.runApp(testURL,
|
|
|
|
browserEnv,
|
|
|
|
options.app,
|
|
|
|
profile=self.profile,
|
|
|
|
extraArgs=options.browserArgs,
|
|
|
|
utilityPath=options.utilityPath,
|
|
|
|
xrePath=options.xrePath,
|
|
|
|
certPath=options.certPath,
|
|
|
|
debuggerInfo=debuggerInfo,
|
|
|
|
symbolsPath=options.symbolsPath,
|
|
|
|
timeout=timeout,
|
2013-11-20 12:53:08 -08:00
|
|
|
onLaunch=onLaunch,
|
|
|
|
webapprtChrome=options.webapprtChrome
|
2013-09-23 07:47:48 -07:00
|
|
|
)
|
2011-05-09 14:54:35 -07:00
|
|
|
except KeyboardInterrupt:
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Received keyboard interrupt.\n");
|
2011-05-09 14:54:35 -07:00
|
|
|
status = -1
|
2011-09-14 16:20:11 -07:00
|
|
|
except:
|
2013-07-26 11:40:04 -07:00
|
|
|
traceback.print_exc()
|
2013-09-19 05:20:17 -07:00
|
|
|
log.error("Automation Error: 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
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Running tests: end.")
|
2010-01-15 09:22:54 -08:00
|
|
|
|
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
|
|
|
|
|
2013-09-24 11:27:18 -07:00
|
|
|
def handleTimeout(self, timeout, proc, utilityPath, debuggerInfo, browserProcessId):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""handle process output timeout"""
|
|
|
|
# TODO: bug 913975 : _processOutput should call self.processOutputLine one more time one timeout (I think)
|
|
|
|
log.info("TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with no output", self.lastTestSeen, int(timeout))
|
|
|
|
browserProcessId = browserProcessId or proc.pid
|
|
|
|
self.killAndGetStack(browserProcessId, utilityPath, debuggerInfo, dump_screen=not debuggerInfo)
|
|
|
|
|
|
|
|
### output processing
|
|
|
|
|
|
|
|
class OutputHandler(object):
|
|
|
|
"""line output handler for mozrunner"""
|
2013-11-20 12:53:08 -08:00
|
|
|
def __init__(self, harness, utilityPath, symbolsPath=None, dump_screen_on_timeout=True, shutdownLeaks=None):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""
|
|
|
|
harness -- harness instance
|
|
|
|
dump_screen_on_timeout -- whether to dump the screen on timeout
|
|
|
|
"""
|
|
|
|
self.harness = harness
|
|
|
|
self.utilityPath = utilityPath
|
|
|
|
self.symbolsPath = symbolsPath
|
|
|
|
self.dump_screen_on_timeout = dump_screen_on_timeout
|
2013-11-20 12:53:08 -08:00
|
|
|
self.shutdownLeaks = shutdownLeaks
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# perl binary to use
|
|
|
|
self.perl = which('perl')
|
|
|
|
|
|
|
|
# With metro browser runs this script launches the metro test harness which launches the browser.
|
|
|
|
# The metro test harness hands back the real browser process id via log output which we need to
|
|
|
|
# pick up on and parse out. This variable tracks the real browser process id if we find it.
|
|
|
|
self.browserProcessId = None
|
|
|
|
|
|
|
|
# stack fixer function and/or process
|
|
|
|
self.stackFixerFunction, self.stackFixerCommand = self.stackFixer()
|
|
|
|
self.stackFixerProcess = None
|
|
|
|
|
|
|
|
# if there is a stack fixer subprocess, function as a pipe
|
|
|
|
self.pipe = bool(self.stackFixerCommand)
|
|
|
|
|
|
|
|
def processOutputLine(self, line):
|
|
|
|
"""per line handler of output for mozprocess"""
|
|
|
|
for handler in self.outputHandlers():
|
|
|
|
line = handler(line)
|
|
|
|
__call__ = processOutputLine
|
|
|
|
|
|
|
|
def outputHandlers(self):
|
|
|
|
"""returns ordered list of output handlers"""
|
|
|
|
return [self.fix_stack,
|
|
|
|
self.format,
|
|
|
|
self.record_last_test,
|
|
|
|
self.dumpScreenOnTimeout,
|
|
|
|
self.metro_subprocess_id,
|
2013-11-20 12:53:08 -08:00
|
|
|
self.trackShutdownLeaks,
|
2013-09-23 07:47:48 -07:00
|
|
|
self.log,
|
|
|
|
]
|
|
|
|
|
|
|
|
def stackFixer(self):
|
|
|
|
"""
|
|
|
|
return 2-tuple, (stackFixerFunction, StackFixerProcess),
|
|
|
|
if any, to use on the output lines
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not mozinfo.info.get('debug'):
|
|
|
|
return None, None
|
|
|
|
|
|
|
|
stackFixerFunction = stackFixerCommand = None
|
|
|
|
|
|
|
|
def import_stackFixerModule(module_name):
|
|
|
|
sys.path.insert(0, self.utilityPath)
|
|
|
|
module = __import__(module_name, globals(), locals(), [])
|
|
|
|
sys.path.pop(0)
|
|
|
|
return module
|
|
|
|
|
|
|
|
if self.symbolsPath and os.path.exists(self.symbolsPath):
|
|
|
|
# Run each line through a function in fix_stack_using_bpsyms.py (uses breakpad symbol files)
|
|
|
|
# This method is preferred for Tinderbox builds, since native symbols may have been stripped.
|
|
|
|
stackFixerModule = import_stackFixerModule('fix_stack_using_bpsyms')
|
|
|
|
stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line, self.symbolsPath)
|
|
|
|
|
|
|
|
elif mozinfo.isLinux and self.perl:
|
|
|
|
# Run logsource through fix-linux-stack.pl (uses addr2line)
|
|
|
|
# This method is preferred for developer machines, so we don't have to run "make buildsymbols".
|
|
|
|
|
|
|
|
stackFixerCommand = [self.perl, os.path.join(self.utilityPath, "fix-linux-stack.pl")]
|
|
|
|
|
|
|
|
return (stackFixerFunction, stackFixerCommand)
|
|
|
|
|
|
|
|
def setProcess(self, proc, outputTimeout=None):
|
|
|
|
if self.stackFixerCommand:
|
|
|
|
self.stackFixerProcess = mozprocess.ProcessHandler(self.stackFixerCommand,
|
2013-10-01 16:53:19 -07:00
|
|
|
stdin=proc.stdout,
|
2013-09-23 07:47:48 -07:00
|
|
|
processOutputLine=[self],
|
|
|
|
)
|
|
|
|
self.stackFixerProcess.run(outputTimeout=outputTimeout)
|
|
|
|
|
|
|
|
def finish(self, didTimeout):
|
|
|
|
if self.stackFixerProcess:
|
|
|
|
status = self.stackFixerProcess.wait()
|
|
|
|
if status and not didTimeout:
|
|
|
|
log.info("TEST-UNEXPECTED-FAIL | runtests.py | Stack fixer process exited with code %d during test run", status)
|
|
|
|
|
2013-11-20 12:53:08 -08:00
|
|
|
if self.shutdownLeaks:
|
|
|
|
self.shutdownLeaks.process()
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
# output line handlers:
|
|
|
|
# these take a line and return a line
|
|
|
|
|
|
|
|
def fix_stack(self, line):
|
|
|
|
if self.stackFixerFunction:
|
|
|
|
return self.stackFixerFunction(line)
|
|
|
|
return line
|
|
|
|
|
|
|
|
def format(self, line):
|
|
|
|
"""format the line"""
|
|
|
|
return line.rstrip().decode("UTF-8", "ignore")
|
|
|
|
|
|
|
|
def record_last_test(self, line):
|
|
|
|
"""record last test on harness"""
|
|
|
|
if "TEST-START" in line and "|" in line:
|
|
|
|
self.harness.lastTestSeen = line.split("|")[1].strip()
|
|
|
|
return line
|
|
|
|
|
|
|
|
def dumpScreenOnTimeout(self, line):
|
|
|
|
if self.dump_screen_on_timeout and "TEST-UNEXPECTED-FAIL" in line and "Test timed out" in line:
|
|
|
|
self.harness.dumpScreen(self.utilityPath)
|
|
|
|
return line
|
|
|
|
|
|
|
|
def metro_subprocess_id(self, line):
|
|
|
|
"""look for metro browser subprocess id"""
|
|
|
|
if "METRO_BROWSER_PROCESS" in line:
|
|
|
|
index = line.find("=")
|
|
|
|
if index != -1:
|
|
|
|
self.browserProcessId = line[index+1:].rstrip()
|
|
|
|
log.info("INFO | runtests.py | metro browser sub process id detected: %s", self.browserProcessId)
|
|
|
|
return line
|
|
|
|
|
2013-11-20 12:53:08 -08:00
|
|
|
def trackShutdownLeaks(self, line):
|
|
|
|
if self.shutdownLeaks:
|
|
|
|
self.shutdownLeaks.log(line)
|
|
|
|
return line
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def log(self, line):
|
|
|
|
log.info(line)
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
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("\\", "\\\\")
|
2013-03-28 09:23:03 -07:00
|
|
|
testRoot = self.getTestRoot(options)
|
2012-06-29 15:52:43 -07:00
|
|
|
|
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 = "{"
|
2013-07-26 11:40:04 -07:00
|
|
|
content += '"testRoot": "%s", ' % (testRoot)
|
2011-05-17 10:10:37 -07:00
|
|
|
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
|
|
|
|
2013-03-28 09:23:03 -07:00
|
|
|
def getTestRoot(self, options):
|
|
|
|
if (options.browserChrome):
|
|
|
|
if (options.immersiveMode):
|
|
|
|
return 'metro'
|
|
|
|
return 'browser'
|
|
|
|
elif (options.a11y):
|
|
|
|
return 'a11y'
|
|
|
|
elif (options.webapprtChrome):
|
|
|
|
return 'webapprtChrome'
|
|
|
|
elif (options.chrome):
|
|
|
|
return 'chrome'
|
|
|
|
return self.TEST_PATH
|
|
|
|
|
2013-03-28 13:42:49 -07:00
|
|
|
def installExtensionFromPath(self, options, path, extensionID = None):
|
2013-09-23 07:47:48 -07:00
|
|
|
"""install an extension to options.profilePath"""
|
|
|
|
|
|
|
|
# TODO: currently extensionID is unused; see
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=914267
|
|
|
|
# [mozprofile] make extensionID a parameter to install_from_path
|
|
|
|
# https://github.com/mozilla/mozbase/blob/master/mozprofile/mozprofile/addons.py#L169
|
|
|
|
|
2013-03-28 13:42:49 -07:00
|
|
|
extensionPath = self.getFullPath(path)
|
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
log.info("runtests.py | Installing extension at %s to %s." %
|
|
|
|
(extensionPath, options.profilePath))
|
2013-09-23 07:47:48 -07:00
|
|
|
|
|
|
|
addons = AddonManager(options.profilePath)
|
|
|
|
|
|
|
|
# XXX: del the __del__
|
|
|
|
# hack can be removed when mozprofile is mirrored to m-c ; see
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=911218 :
|
|
|
|
# [mozprofile] AddonManager should only cleanup on __del__ optionally:
|
|
|
|
# https://github.com/mozilla/mozbase/blob/master/mozprofile/mozprofile/addons.py#L266
|
|
|
|
if hasattr(addons, '__del__'):
|
|
|
|
del addons.__del__
|
|
|
|
|
|
|
|
addons.install_from_path(path)
|
2013-03-28 13:42:49 -07:00
|
|
|
|
|
|
|
def installExtensionsToProfile(self, options):
|
|
|
|
"Install special testing extensions, application distributed extensions, and specified on the command line ones to testing profile."
|
|
|
|
for path in self.getExtensionsToInstall(options):
|
2011-10-14 08:53:06 -07:00
|
|
|
self.installExtensionFromPath(options, path)
|
2010-11-18 14:15:54 -08:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def readLocations(self, locations_file):
|
|
|
|
"""
|
|
|
|
Reads the locations at which the Mochitest HTTP server is available from
|
|
|
|
`locations_file`.
|
|
|
|
"""
|
|
|
|
path = os.path.realpath(locations_file)
|
|
|
|
return self._locations.setdefault(path, ServerLocations(path))
|
|
|
|
|
|
|
|
def fillCertificateDB(self, profileDir, certPath, utilityPath, xrePath):
|
|
|
|
# TODO: move -> mozprofile:
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=746243#c35
|
|
|
|
|
|
|
|
pwfilePath = os.path.join(profileDir, ".crtdbpw")
|
|
|
|
with open(pwfilePath, "w") as pwfile:
|
|
|
|
pwfile.write("\n")
|
|
|
|
|
|
|
|
# Create head of the ssltunnel configuration file
|
|
|
|
sslTunnelConfigPath = os.path.join(profileDir, "ssltunnel.cfg")
|
|
|
|
sslTunnelConfig = open(sslTunnelConfigPath, "w")
|
|
|
|
sslTunnelConfig.write("httpproxy:1\n")
|
|
|
|
sslTunnelConfig.write("certdbdir:%s\n" % certPath)
|
|
|
|
sslTunnelConfig.write("forward:127.0.0.1:%s\n" % self.httpPort)
|
|
|
|
sslTunnelConfig.write("websocketserver:%s:%s\n" % (self.webServer, self.webSocketPort))
|
|
|
|
sslTunnelConfig.write("listen:*:%s:pgo server certificate\n" % self.sslPort)
|
|
|
|
|
|
|
|
# Configure automatic certificate and bind custom certificates, client authentication
|
|
|
|
locations = self.readLocations(os.path.join(SCRIPT_DIR, 'server-locations.txt'))
|
|
|
|
|
|
|
|
for loc in locations:
|
|
|
|
|
|
|
|
if loc.scheme == "https" and "nocert" not in loc.options:
|
|
|
|
customCertRE = re.compile("^cert=(?P<nickname>[0-9a-zA-Z_ ]+)")
|
|
|
|
clientAuthRE = re.compile("^clientauth=(?P<clientauth>[a-z]+)")
|
|
|
|
redirRE = re.compile("^redir=(?P<redirhost>[0-9a-zA-Z_ .]+)")
|
|
|
|
for option in loc.options:
|
|
|
|
match = customCertRE.match(option)
|
|
|
|
if match:
|
|
|
|
customcert = match.group("nickname");
|
|
|
|
sslTunnelConfig.write("listen:%s:%s:%s:%s\n" %
|
|
|
|
(loc.host, loc.port, self.sslPort, customcert))
|
|
|
|
|
|
|
|
match = clientAuthRE.match(option)
|
|
|
|
if match:
|
|
|
|
clientauth = match.group("clientauth");
|
|
|
|
sslTunnelConfig.write("clientauth:%s:%s:%s:%s\n" %
|
|
|
|
(loc.host, loc.port, self.sslPort, clientauth))
|
|
|
|
|
|
|
|
match = redirRE.match(option)
|
|
|
|
if match:
|
|
|
|
redirhost = match.group("redirhost")
|
|
|
|
sslTunnelConfig.write("redirhost:%s:%s:%s:%s\n" %
|
|
|
|
(loc.host, loc.port, self.sslPort, redirhost))
|
|
|
|
|
|
|
|
sslTunnelConfig.close()
|
|
|
|
|
|
|
|
# Pre-create the certification database for the profile
|
|
|
|
env = self.environment(xrePath=xrePath)
|
|
|
|
bin_suffix = mozinfo.info.get('bin_suffix', '')
|
|
|
|
certutil = os.path.join(utilityPath, "certutil" + bin_suffix)
|
|
|
|
pk12util = os.path.join(utilityPath, "pk12util" + bin_suffix)
|
|
|
|
|
|
|
|
status = call([certutil, "-N", "-d", profileDir, "-f", pwfilePath], env=env)
|
|
|
|
if status:
|
|
|
|
return status
|
|
|
|
|
|
|
|
# Walk the cert directory and add custom CAs and client certs
|
|
|
|
files = os.listdir(certPath)
|
|
|
|
for item in files:
|
|
|
|
root, ext = os.path.splitext(item)
|
|
|
|
if ext == ".ca":
|
|
|
|
trustBits = "CT,,"
|
|
|
|
if root.endswith("-object"):
|
|
|
|
trustBits = "CT,,CT"
|
|
|
|
call([certutil, "-A", "-i", os.path.join(certPath, item),
|
|
|
|
"-d", profileDir, "-f", pwfilePath, "-n", root, "-t", trustBits],
|
|
|
|
env=env)
|
|
|
|
elif ext == ".client":
|
|
|
|
call([pk12util, "-i", os.path.join(certPath, item), "-w",
|
|
|
|
pwfilePath, "-d", profileDir],
|
|
|
|
env=env)
|
|
|
|
|
|
|
|
os.unlink(pwfilePath)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2010-01-15 09:22:54 -08:00
|
|
|
def main():
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
# parse command line options
|
|
|
|
mochitest = Mochitest()
|
|
|
|
parser = MochitestOptions()
|
|
|
|
options, args = parser.parse_args()
|
2010-03-13 09:56:24 -08:00
|
|
|
options = parser.verifyOptions(options, mochitest)
|
2013-09-23 07:47:48 -07:00
|
|
|
if options is None:
|
|
|
|
# parsing error
|
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-01-15 09:22:54 -08:00
|
|
|
sys.exit(mochitest.runTests(options))
|
2008-01-28 19:48:34 -08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|