2012-09-26 09:43:53 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
2012-10-10 11:08:09 -07:00
|
|
|
# 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/.
|
2012-09-26 09:43:53 -07:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-04-04 15:17:23 -07:00
|
|
|
import logging
|
2013-03-28 09:23:03 -07:00
|
|
|
import mozpack.path
|
2012-10-02 14:03:31 -07:00
|
|
|
import os
|
2013-02-12 12:51:24 -08:00
|
|
|
import platform
|
2013-03-26 15:00:43 -07:00
|
|
|
import sys
|
2013-09-19 11:43:44 -07:00
|
|
|
import warnings
|
2013-08-29 11:23:07 -07:00
|
|
|
import which
|
2012-10-02 14:03:31 -07:00
|
|
|
|
2012-11-06 16:57:41 -08:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
2013-08-28 07:08:50 -07:00
|
|
|
MachCommandConditions as conditions,
|
2012-11-06 16:57:41 -08:00
|
|
|
MozbuildObject,
|
|
|
|
)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2012-11-06 16:57:41 -08:00
|
|
|
from mach.decorators import (
|
2012-10-10 11:08:09 -07:00
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2013-04-04 15:17:23 -07:00
|
|
|
from mach.logging import StructuredHumanFormatter
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
ADB_NOT_FOUND = '''
|
|
|
|
The %s command requires the adb binary to be on your path.
|
|
|
|
|
|
|
|
If you have a B2G build, this can be found in
|
|
|
|
'%s/out/host/<platform>/bin'.
|
|
|
|
'''.lstrip()
|
|
|
|
|
|
|
|
GAIA_PROFILE_NOT_FOUND = '''
|
|
|
|
The %s command requires a non-debug gaia profile. Either pass in --profile,
|
|
|
|
or set the GAIA_PROFILE environment variable.
|
|
|
|
|
|
|
|
If you do not have a non-debug gaia profile, you can build one:
|
|
|
|
$ git clone https://github.com/mozilla-b2g/gaia
|
|
|
|
$ cd gaia
|
|
|
|
$ make
|
|
|
|
|
|
|
|
The profile should be generated in a directory called 'profile'.
|
|
|
|
'''.lstrip()
|
|
|
|
|
|
|
|
GAIA_PROFILE_IS_DEBUG = '''
|
|
|
|
The %s command requires a non-debug gaia profile. The specified profile,
|
|
|
|
%s, is a debug profile.
|
|
|
|
|
|
|
|
If you do not have a non-debug gaia profile, you can build one:
|
|
|
|
$ git clone https://github.com/mozilla-b2g/gaia
|
|
|
|
$ cd gaia
|
|
|
|
$ make
|
|
|
|
|
|
|
|
The profile should be generated in a directory called 'profile'.
|
|
|
|
'''.lstrip()
|
|
|
|
|
|
|
|
MARIONETTE_DISABLED = '''
|
|
|
|
The %s command requires a marionette enabled build.
|
|
|
|
|
|
|
|
Add 'ENABLE_MARIONETTE=1' to your mozconfig file and re-build the application.
|
|
|
|
Your currently active mozconfig is %s.
|
|
|
|
'''.lstrip()
|
2013-04-04 15:17:23 -07:00
|
|
|
|
|
|
|
class UnexpectedFilter(logging.Filter):
|
|
|
|
def filter(self, record):
|
|
|
|
msg = getattr(record, 'params', {}).get('msg', '')
|
|
|
|
return 'TEST-UNEXPECTED-' in msg
|
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
class MochitestRunner(MozbuildObject):
|
2012-09-26 09:43:53 -07:00
|
|
|
"""Easily run mochitests.
|
|
|
|
|
|
|
|
This currently contains just the basics for running mochitests. We may want
|
|
|
|
to hook up result parsing, etc.
|
|
|
|
"""
|
2013-08-28 07:08:50 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
def get_webapp_runtime_path(self):
|
2013-09-24 13:44:23 -07:00
|
|
|
import mozinfo
|
2013-09-23 07:47:48 -07:00
|
|
|
appname = 'webapprt-stub' + mozinfo.info.get('bin_suffix', '')
|
|
|
|
if sys.platform.startswith('darwin'):
|
|
|
|
appname = os.path.join(self.distdir, self.substs['MOZ_MACBUNDLE_NAME'],
|
|
|
|
'Contents', 'MacOS', appname)
|
|
|
|
else:
|
|
|
|
appname = os.path.join(self.distdir, 'bin', appname)
|
|
|
|
return appname
|
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
MozbuildObject.__init__(self, *args, **kwargs)
|
|
|
|
|
|
|
|
# TODO Bug 794506 remove once mach integrates with virtualenv.
|
|
|
|
build_path = os.path.join(self.topobjdir, 'build')
|
|
|
|
if build_path not in sys.path:
|
|
|
|
sys.path.append(build_path)
|
|
|
|
|
|
|
|
self.tests_dir = os.path.join(self.topobjdir, '_tests')
|
|
|
|
self.mochitest_dir = os.path.join(self.tests_dir, 'testing', 'mochitest')
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
def run_b2g_test(self, test_file=None, b2g_home=None, xre_path=None, **kwargs):
|
2013-08-28 07:08:50 -07:00
|
|
|
"""Runs a b2g mochitest.
|
|
|
|
|
|
|
|
test_file is a path to a test file. It can be a relative path from the
|
|
|
|
top source directory, an absolute filename, or a directory containing
|
|
|
|
test files.
|
|
|
|
"""
|
2013-09-11 11:53:47 -07:00
|
|
|
# Need to call relpath before os.chdir() below.
|
|
|
|
test_path = ''
|
|
|
|
if test_file:
|
|
|
|
test_path = self._wrap_path_argument(test_file).relpath()
|
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
# TODO without os.chdir, chained imports fail below
|
|
|
|
os.chdir(self.mochitest_dir)
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
# The imp module can spew warnings if the modules below have
|
|
|
|
# already been imported, ignore them.
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.simplefilter('ignore')
|
2013-08-28 07:08:50 -07:00
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
import imp
|
|
|
|
path = os.path.join(self.mochitest_dir, 'runtestsb2g.py')
|
|
|
|
with open(path, 'r') as fh:
|
|
|
|
imp.load_module('mochitest', fh, path,
|
|
|
|
('.py', 'r', imp.PY_SOURCE))
|
|
|
|
|
|
|
|
import mochitest
|
|
|
|
from mochitest_options import B2GOptions
|
2013-08-28 07:08:50 -07:00
|
|
|
|
|
|
|
parser = B2GOptions()
|
|
|
|
options = parser.parse_args([])[0]
|
|
|
|
|
2013-09-11 11:53:47 -07:00
|
|
|
if test_path:
|
|
|
|
test_root_file = mozpack.path.join(self.mochitest_dir, 'tests', test_path)
|
|
|
|
if not os.path.exists(test_root_file):
|
|
|
|
print('Specified test path does not exist: %s' % test_root_file)
|
|
|
|
return 1
|
|
|
|
options.testPath = test_path
|
2013-08-28 07:08:50 -07:00
|
|
|
else:
|
|
|
|
options.testManifest = 'b2g.json'
|
|
|
|
|
|
|
|
for k, v in kwargs.iteritems():
|
|
|
|
setattr(options, k, v)
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
options.consoleLevel = 'INFO'
|
|
|
|
if conditions.is_b2g_desktop(self):
|
|
|
|
if self.substs.get('ENABLE_MARIONETTE') != '1':
|
|
|
|
print(MARIONETTE_DISABLED % ('mochitest-b2g-desktop',
|
|
|
|
self.mozconfig['path']))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
options.profile = options.profile or os.environ.get('GAIA_PROFILE')
|
|
|
|
if not options.profile:
|
|
|
|
print(GAIA_PROFILE_NOT_FOUND % 'mochitest-b2g-desktop')
|
|
|
|
return 1
|
|
|
|
|
|
|
|
if os.path.isfile(os.path.join(options.profile, 'extensions', \
|
|
|
|
'httpd@gaiamobile.org')):
|
|
|
|
print(GAIA_PROFILE_IS_DEBUG % ('mochitest-b2g-desktop',
|
|
|
|
options.profile))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
options.desktop = True
|
|
|
|
options.app = self.get_binary_path()
|
|
|
|
if not options.app.endswith('-bin'):
|
|
|
|
options.app = '%s-bin' % options.app
|
|
|
|
if not os.path.isfile(options.app):
|
|
|
|
options.app = options.app[:-len('-bin')]
|
|
|
|
|
|
|
|
return mochitest.run_desktop_mochitests(parser, options)
|
|
|
|
|
|
|
|
try:
|
|
|
|
which.which('adb')
|
|
|
|
except which.WhichError:
|
|
|
|
# TODO Find adb automatically if it isn't on the path
|
|
|
|
print(ADB_NOT_FOUND % ('mochitest-remote', b2g_home))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
options.b2gPath = b2g_home
|
|
|
|
options.logcat_dir = self.mochitest_dir
|
|
|
|
options.httpdPath = self.mochitest_dir
|
|
|
|
options.xrePath = xre_path
|
|
|
|
return mochitest.run_remote_mochitests(parser, options)
|
2013-08-28 07:08:50 -07:00
|
|
|
|
|
|
|
def run_desktop_test(self, suite=None, test_file=None, debugger=None,
|
2013-05-30 08:00:46 -07:00
|
|
|
debugger_args=None, shuffle=False, keep_open=False, rerun_failures=False,
|
2013-09-09 12:36:03 -07:00
|
|
|
no_autorun=False, repeat=0, run_until_failure=False, slow=False,
|
2013-10-28 12:24:55 -07:00
|
|
|
chunk_by_dir=0, total_chunks=None, this_chunk=None, jsdebugger=False,
|
|
|
|
start_at=None, end_at=None):
|
2012-09-26 09:43:53 -07:00
|
|
|
"""Runs a mochitest.
|
|
|
|
|
|
|
|
test_file is a path to a test file. It can be a relative path from the
|
|
|
|
top source directory, an absolute filename, or a directory containing
|
|
|
|
test files.
|
|
|
|
|
|
|
|
suite is the type of mochitest to run. It can be one of ('plain',
|
2013-02-12 12:51:24 -08:00
|
|
|
'chrome', 'browser', 'metro', 'a11y').
|
2012-12-05 14:27:54 -08:00
|
|
|
|
|
|
|
debugger is a program name or path to a binary (presumably a debugger)
|
|
|
|
to run the test in. e.g. 'gdb'
|
2013-03-26 15:00:43 -07:00
|
|
|
|
2013-05-30 08:00:46 -07:00
|
|
|
debugger_args are the arguments passed to the debugger.
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
shuffle is whether test order should be shuffled (defaults to false).
|
|
|
|
|
|
|
|
keep_open denotes whether to keep the browser open after tests
|
|
|
|
complete.
|
2012-09-26 09:43:53 -07:00
|
|
|
"""
|
2013-03-26 15:00:43 -07:00
|
|
|
if rerun_failures and test_file:
|
|
|
|
print('Cannot specify both --rerun-failures and a test path.')
|
|
|
|
return 1
|
|
|
|
|
2013-03-28 09:23:03 -07:00
|
|
|
# Need to call relpath before os.chdir() below.
|
|
|
|
test_path = ''
|
2013-03-26 15:00:43 -07:00
|
|
|
if test_file:
|
2013-03-28 09:23:03 -07:00
|
|
|
test_path = self._wrap_path_argument(test_file).relpath()
|
2013-03-26 15:00:43 -07:00
|
|
|
|
|
|
|
failure_file_path = os.path.join(self.statedir, 'mochitest_failures.json')
|
|
|
|
|
|
|
|
if rerun_failures and not os.path.exists(failure_file_path):
|
|
|
|
print('No failure file present. Did you run mochitests before?')
|
|
|
|
return 1
|
|
|
|
|
2013-04-04 15:17:23 -07:00
|
|
|
from StringIO import StringIO
|
2013-03-26 15:00:43 -07:00
|
|
|
|
|
|
|
# runtests.py is ambiguous, so we load the file/module manually.
|
|
|
|
if 'mochitest' not in sys.modules:
|
|
|
|
import imp
|
2013-08-28 07:08:50 -07:00
|
|
|
path = os.path.join(self.mochitest_dir, 'runtests.py')
|
2013-03-26 15:00:43 -07:00
|
|
|
with open(path, 'r') as fh:
|
|
|
|
imp.load_module('mochitest', fh, path,
|
|
|
|
('.py', 'r', imp.PY_SOURCE))
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
import mozinfo
|
2013-03-26 15:00:43 -07:00
|
|
|
import mochitest
|
|
|
|
|
|
|
|
# This is required to make other components happy. Sad, isn't it?
|
|
|
|
os.chdir(self.topobjdir)
|
|
|
|
|
2013-04-04 15:17:23 -07:00
|
|
|
# Automation installs its own stream handler to stdout. Since we want
|
|
|
|
# all logging to go through us, we just remove their handler.
|
|
|
|
remove_handlers = [l for l in logging.getLogger().handlers
|
|
|
|
if isinstance(l, logging.StreamHandler)]
|
|
|
|
for handler in remove_handlers:
|
|
|
|
logging.getLogger().removeHandler(handler)
|
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
runner = mochitest.Mochitest()
|
2013-03-26 15:00:43 -07:00
|
|
|
|
2013-09-23 07:47:48 -07:00
|
|
|
opts = mochitest.MochitestOptions()
|
2013-03-26 15:00:43 -07:00
|
|
|
options, args = opts.parse_args([])
|
|
|
|
|
2013-08-23 07:06:16 -07:00
|
|
|
|
2013-03-28 09:23:03 -07:00
|
|
|
# Need to set the suite options before verifyOptions below.
|
|
|
|
if suite == 'plain':
|
|
|
|
# Don't need additional options for plain.
|
|
|
|
pass
|
|
|
|
elif suite == 'chrome':
|
|
|
|
options.chrome = True
|
|
|
|
elif suite == 'browser':
|
|
|
|
options.browserChrome = True
|
|
|
|
elif suite == 'metro':
|
|
|
|
options.immersiveMode = True
|
|
|
|
options.browserChrome = True
|
|
|
|
elif suite == 'a11y':
|
|
|
|
options.a11y = True
|
2013-08-23 07:06:16 -07:00
|
|
|
elif suite == 'webapprt-content':
|
|
|
|
options.webapprtContent = True
|
2013-09-23 07:47:48 -07:00
|
|
|
options.app = self.get_webapp_runtime_path()
|
2013-08-23 07:06:16 -07:00
|
|
|
elif suite == 'webapprt-chrome':
|
|
|
|
options.webapprtChrome = True
|
2013-09-23 07:47:48 -07:00
|
|
|
options.app = self.get_webapp_runtime_path()
|
2013-08-23 07:06:16 -07:00
|
|
|
options.browserArgs.append("-test-mode")
|
2013-03-28 09:23:03 -07:00
|
|
|
else:
|
|
|
|
raise Exception('None or unrecognized mochitest suite type.')
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
options.autorun = not no_autorun
|
|
|
|
options.closeWhenDone = not keep_open
|
|
|
|
options.shuffle = shuffle
|
|
|
|
options.consoleLevel = 'INFO'
|
|
|
|
options.repeat = repeat
|
2013-05-24 12:03:50 -07:00
|
|
|
options.runUntilFailure = run_until_failure
|
2013-03-26 15:00:43 -07:00
|
|
|
options.runSlower = slow
|
2013-08-28 07:08:50 -07:00
|
|
|
options.testingModulesDir = os.path.join(self.tests_dir, 'modules')
|
2013-03-26 15:00:43 -07:00
|
|
|
options.extraProfileFiles.append(os.path.join(self.distdir, 'plugins'))
|
|
|
|
options.symbolsPath = os.path.join(self.distdir, 'crashreporter-symbols')
|
2013-09-09 12:36:03 -07:00
|
|
|
options.chunkByDir = chunk_by_dir
|
|
|
|
options.totalChunks = total_chunks
|
|
|
|
options.thisChunk = this_chunk
|
2013-10-21 09:12:12 -07:00
|
|
|
options.jsdebugger = jsdebugger
|
2013-10-28 12:24:55 -07:00
|
|
|
options.startAt = start_at
|
|
|
|
options.endAt = end_at
|
2013-03-26 15:00:43 -07:00
|
|
|
|
|
|
|
options.failureFile = failure_file_path
|
|
|
|
|
2013-03-28 09:23:03 -07:00
|
|
|
if test_path:
|
|
|
|
test_root = runner.getTestRoot(options)
|
2013-08-28 07:08:50 -07:00
|
|
|
test_root_file = mozpack.path.join(self.mochitest_dir, test_root, test_path)
|
2013-03-28 09:23:03 -07:00
|
|
|
if not os.path.exists(test_root_file):
|
|
|
|
print('Specified test path does not exist: %s' % test_root_file)
|
|
|
|
print('You may need to run |mach build| to build the test files.')
|
|
|
|
return 1
|
|
|
|
|
|
|
|
options.testPath = test_path
|
2012-09-26 09:43:53 -07:00
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
if rerun_failures:
|
|
|
|
options.testManifest = failure_file_path
|
2012-12-05 14:27:54 -08:00
|
|
|
|
|
|
|
if debugger:
|
2013-03-26 15:00:43 -07:00
|
|
|
options.debugger = debugger
|
|
|
|
|
2013-05-30 08:00:46 -07:00
|
|
|
if debugger_args:
|
|
|
|
if options.debugger == None:
|
|
|
|
print("--debugger-args passed, but no debugger specified.")
|
|
|
|
return 1
|
|
|
|
options.debuggerArgs = debugger_args
|
|
|
|
|
2013-05-24 12:03:50 -07:00
|
|
|
options = opts.verifyOptions(options, runner)
|
|
|
|
|
|
|
|
if options is None:
|
|
|
|
raise Exception('mochitest option validator failed.')
|
|
|
|
|
2013-04-04 15:17:23 -07:00
|
|
|
# We need this to enable colorization of output.
|
|
|
|
self.log_manager.enable_unstructured()
|
|
|
|
|
|
|
|
# Output processing is a little funky here. The old make targets
|
|
|
|
# grepped the log output from TEST-UNEXPECTED-* and printed these lines
|
|
|
|
# after test execution. Ideally the test runner would expose a Python
|
|
|
|
# API for obtaining test results and we could just format failures
|
|
|
|
# appropriately. Unfortunately, it doesn't yet do that. So, we capture
|
|
|
|
# all output to a buffer then "grep" the buffer after test execution.
|
|
|
|
# Bug 858197 tracks a Python API that would facilitate this.
|
|
|
|
test_output = StringIO()
|
|
|
|
handler = logging.StreamHandler(test_output)
|
|
|
|
handler.addFilter(UnexpectedFilter())
|
|
|
|
handler.setFormatter(StructuredHumanFormatter(0, write_times=False))
|
|
|
|
logging.getLogger().addHandler(handler)
|
|
|
|
|
|
|
|
result = runner.runTests(options)
|
|
|
|
|
|
|
|
# Need to remove our buffering handler before we echo failures or else
|
|
|
|
# it will catch them again!
|
|
|
|
logging.getLogger().removeHandler(handler)
|
|
|
|
self.log_manager.disable_unstructured()
|
|
|
|
|
|
|
|
if test_output.getvalue():
|
2013-05-23 10:13:54 -07:00
|
|
|
result = 1
|
2013-04-04 15:17:23 -07:00
|
|
|
for line in test_output.getvalue().splitlines():
|
|
|
|
self.log(logging.INFO, 'unexpected', {'msg': line}, '{msg}')
|
|
|
|
|
|
|
|
return result
|
2013-03-26 15:00:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
def MochitestCommand(func):
|
|
|
|
"""Decorator that adds shared command arguments to mochitest commands."""
|
2012-12-05 14:27:54 -08:00
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
# This employs light Python magic. Keep in mind a decorator is just a
|
|
|
|
# function that takes a function, does something with it, then returns a
|
|
|
|
# (modified) function. Here, we chain decorators onto the passed in
|
|
|
|
# function.
|
|
|
|
|
|
|
|
debugger = CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help='Debugger binary to run test in. Program name or path.')
|
|
|
|
func = debugger(func)
|
|
|
|
|
2013-05-30 08:00:46 -07:00
|
|
|
debugger_args = CommandArgument('--debugger-args',
|
|
|
|
metavar='DEBUGGER_ARGS', help='Arguments to pass to the debugger.')
|
|
|
|
func = debugger_args(func)
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
shuffle = CommandArgument('--shuffle', action='store_true',
|
|
|
|
help='Shuffle execution order.')
|
|
|
|
func = shuffle(func)
|
|
|
|
|
|
|
|
keep_open = CommandArgument('--keep-open', action='store_true',
|
|
|
|
help='Keep the browser open after tests complete.')
|
|
|
|
func = keep_open(func)
|
|
|
|
|
|
|
|
rerun = CommandArgument('--rerun-failures', action='store_true',
|
2013-08-23 07:06:16 -07:00
|
|
|
help='Run only the tests that failed during the last test run.')
|
2013-03-26 15:00:43 -07:00
|
|
|
func = rerun(func)
|
|
|
|
|
|
|
|
autorun = CommandArgument('--no-autorun', action='store_true',
|
|
|
|
help='Do not starting running tests automatically.')
|
|
|
|
func = autorun(func)
|
|
|
|
|
|
|
|
repeat = CommandArgument('--repeat', type=int, default=0,
|
|
|
|
help='Repeat the test the given number of times.')
|
|
|
|
func = repeat(func)
|
|
|
|
|
2013-05-24 12:03:50 -07:00
|
|
|
runUntilFailure = CommandArgument("--run-until-failure", action='store_true',
|
|
|
|
help='Run a test repeatedly and stops on the first time the test fails. ' \
|
|
|
|
'Only available when running a single test. Default cap is 30 runs, ' \
|
|
|
|
'which can be overwritten with the --repeat parameter.')
|
|
|
|
func = runUntilFailure(func)
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
slow = CommandArgument('--slow', action='store_true',
|
|
|
|
help='Delay execution between tests.')
|
|
|
|
func = slow(func)
|
|
|
|
|
2013-09-09 12:36:03 -07:00
|
|
|
chunk_dir = CommandArgument('--chunk-by-dir', type=int,
|
|
|
|
help='Group tests together in chunks by this many top directories.')
|
|
|
|
func = chunk_dir(func)
|
|
|
|
|
|
|
|
chunk_total = CommandArgument('--total-chunks', type=int,
|
|
|
|
help='Total number of chunks to split tests into.')
|
|
|
|
func = chunk_total(func)
|
|
|
|
|
|
|
|
this_chunk = CommandArgument('--this-chunk', type=int,
|
|
|
|
help='If running tests by chunks, the number of the chunk to run.')
|
|
|
|
func = this_chunk(func)
|
|
|
|
|
2013-10-21 09:12:12 -07:00
|
|
|
jsdebugger = CommandArgument('--jsdebugger', action='store_true',
|
|
|
|
help='Start the browser JS debugger before running the test. Implies --no-autorun.')
|
|
|
|
func = jsdebugger(func)
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
path = CommandArgument('test_file', default=None, nargs='?',
|
|
|
|
metavar='TEST',
|
|
|
|
help='Test to run. Can be specified as a single file, a ' \
|
|
|
|
'directory, or omitted. If omitted, the entire test suite is ' \
|
|
|
|
'executed.')
|
|
|
|
func = path(func)
|
|
|
|
|
|
|
|
return func
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
def B2GCommand(func):
|
|
|
|
"""Decorator that adds shared command arguments to b2g mochitest commands."""
|
|
|
|
|
|
|
|
busybox = CommandArgument('--busybox', default=None,
|
|
|
|
help='Path to busybox binary to install on device')
|
|
|
|
func = busybox(func)
|
|
|
|
|
|
|
|
logcatdir = CommandArgument('--logcat-dir', default=None,
|
|
|
|
help='directory to store logcat dump files')
|
|
|
|
func = logcatdir(func)
|
|
|
|
|
|
|
|
profile = CommandArgument('--profile', default=None,
|
|
|
|
help='for desktop testing, the path to the \
|
|
|
|
gaia profile to use')
|
|
|
|
func = profile(func)
|
|
|
|
|
|
|
|
geckopath = CommandArgument('--gecko-path', default=None,
|
|
|
|
help='the path to a gecko distribution that should \
|
|
|
|
be installed on the emulator prior to test')
|
|
|
|
func = geckopath(func)
|
|
|
|
|
|
|
|
nowindow = CommandArgument('--no-window', action='store_true', default=False,
|
|
|
|
help='Pass --no-window to the emulator')
|
|
|
|
func = nowindow(func)
|
|
|
|
|
|
|
|
sdcard = CommandArgument('--sdcard', default="10MB",
|
|
|
|
help='Define size of sdcard: 1MB, 50MB...etc')
|
|
|
|
func = sdcard(func)
|
|
|
|
|
|
|
|
emulator = CommandArgument('--emulator', default='arm',
|
|
|
|
help='Architecture of emulator to use: x86 or arm')
|
|
|
|
func = emulator(func)
|
|
|
|
|
|
|
|
marionette = CommandArgument('--marionette', default=None,
|
|
|
|
help='host:port to use when connecting to Marionette')
|
|
|
|
func = marionette(func)
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
chunk_total = CommandArgument('--total-chunks', type=int,
|
|
|
|
help='Total number of chunks to split tests into.')
|
|
|
|
func = chunk_total(func)
|
|
|
|
|
|
|
|
this_chunk = CommandArgument('--this-chunk', type=int,
|
|
|
|
help='If running tests by chunks, the number of the chunk to run.')
|
|
|
|
func = this_chunk(func)
|
|
|
|
|
2013-10-28 12:24:55 -07:00
|
|
|
start_at = CommandArgument('--start-at', type=str,
|
|
|
|
help='Start running the test sequence at this test.')
|
|
|
|
func = start_at(func)
|
|
|
|
|
|
|
|
end_at = CommandArgument('--end-at', type=str,
|
|
|
|
help='Stop running the test sequence at this test.')
|
|
|
|
func = end_at(func)
|
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
path = CommandArgument('test_file', default=None, nargs='?',
|
|
|
|
metavar='TEST',
|
|
|
|
help='Test to run. Can be specified as a single file, a ' \
|
|
|
|
'directory, or omitted. If omitted, the entire test suite is ' \
|
|
|
|
'executed.')
|
|
|
|
func = path(func)
|
|
|
|
|
|
|
|
return func
|
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
@CommandProvider
|
2012-11-06 16:57:41 -08:00
|
|
|
class MachCommands(MachCommandBase):
|
2013-05-08 17:56:30 -07:00
|
|
|
@Command('mochitest-plain', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-05-08 17:56:30 -07:00
|
|
|
description='Run a plain mochitest.')
|
2013-03-26 15:00:43 -07:00
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_plain(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'plain', **kwargs)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-05-08 17:56:30 -07:00
|
|
|
@Command('mochitest-chrome', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-05-08 17:56:30 -07:00
|
|
|
description='Run a chrome mochitest.')
|
2013-03-26 15:00:43 -07:00
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_chrome(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'chrome', **kwargs)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-05-08 17:56:30 -07:00
|
|
|
@Command('mochitest-browser', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-05-08 17:56:30 -07:00
|
|
|
description='Run a mochitest with browser chrome.')
|
2013-03-26 15:00:43 -07:00
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_browser(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'browser', **kwargs)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-05-08 17:56:30 -07:00
|
|
|
@Command('mochitest-metro', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-05-08 17:56:30 -07:00
|
|
|
description='Run a mochitest with metro browser chrome.')
|
2013-03-26 15:00:43 -07:00
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_metro(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'metro', **kwargs)
|
2013-02-12 12:51:24 -08:00
|
|
|
|
2013-05-08 17:56:30 -07:00
|
|
|
@Command('mochitest-a11y', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-05-08 17:56:30 -07:00
|
|
|
description='Run an a11y mochitest.')
|
2013-03-26 15:00:43 -07:00
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_a11y(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'a11y', **kwargs)
|
|
|
|
|
2013-08-23 07:06:16 -07:00
|
|
|
@Command('webapprt-test-chrome', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-08-23 07:06:16 -07:00
|
|
|
description='Run a webapprt chrome mochitest.')
|
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_webapprt_chrome(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'webapprt-chrome', **kwargs)
|
|
|
|
|
|
|
|
@Command('webapprt-test-content', category='testing',
|
2013-09-19 11:43:44 -07:00
|
|
|
conditions=[conditions.is_firefox],
|
2013-08-23 07:06:16 -07:00
|
|
|
description='Run a webapprt content mochitest.')
|
|
|
|
@MochitestCommand
|
|
|
|
def run_mochitest_webapprt_content(self, test_file, **kwargs):
|
|
|
|
return self.run_mochitest(test_file, 'webapprt-content', **kwargs)
|
|
|
|
|
2013-03-26 15:00:43 -07:00
|
|
|
def run_mochitest(self, test_file, flavor, **kwargs):
|
2013-10-01 09:36:44 -07:00
|
|
|
from mozbuild.controller.building import BuildDriver
|
|
|
|
|
2012-11-02 10:32:40 -07:00
|
|
|
self._ensure_state_subdir_exists('.')
|
|
|
|
|
2013-10-01 09:36:44 -07:00
|
|
|
driver = self._spawn(BuildDriver)
|
|
|
|
driver.install_tests(remove=False)
|
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
mochitest = self._spawn(MochitestRunner)
|
2013-09-19 11:43:44 -07:00
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
return mochitest.run_desktop_test(test_file=test_file, suite=flavor,
|
2013-03-26 15:00:43 -07:00
|
|
|
**kwargs)
|
2013-08-28 07:08:50 -07:00
|
|
|
|
|
|
|
|
|
|
|
# TODO For now b2g commands will only work with the emulator,
|
|
|
|
# they should be modified to work with all devices.
|
|
|
|
def is_emulator(cls):
|
|
|
|
"""Emulator needs to be configured."""
|
|
|
|
return cls.device_name in ('emulator', 'emulator-jb')
|
|
|
|
|
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class B2GCommands(MachCommandBase):
|
2013-09-19 11:43:44 -07:00
|
|
|
"""So far these are only mochitest plain. They are
|
|
|
|
implemented separately because their command lines
|
|
|
|
are completely different.
|
|
|
|
"""
|
2013-08-28 07:08:50 -07:00
|
|
|
def __init__(self, context):
|
|
|
|
MachCommandBase.__init__(self, context)
|
|
|
|
|
|
|
|
for attr in ('b2g_home', 'xre_path', 'device_name'):
|
|
|
|
setattr(self, attr, getattr(context, attr, None))
|
|
|
|
|
|
|
|
@Command('mochitest-remote', category='testing',
|
|
|
|
description='Run a remote mochitest.',
|
|
|
|
conditions=[conditions.is_b2g, is_emulator])
|
|
|
|
@B2GCommand
|
|
|
|
def run_mochitest_remote(self, test_file, **kwargs):
|
2013-10-01 09:36:44 -07:00
|
|
|
from mozbuild.controller.building import BuildDriver
|
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
self._ensure_state_subdir_exists('.')
|
|
|
|
|
2013-10-01 09:36:44 -07:00
|
|
|
driver = self._spawn(BuildDriver)
|
|
|
|
driver.install_tests(remove=False)
|
|
|
|
|
2013-08-28 07:08:50 -07:00
|
|
|
mochitest = self._spawn(MochitestRunner)
|
2013-09-19 11:43:44 -07:00
|
|
|
return mochitest.run_b2g_test(b2g_home=self.b2g_home,
|
|
|
|
xre_path=self.xre_path, test_file=test_file, **kwargs)
|
|
|
|
|
|
|
|
@Command('mochitest-b2g-desktop', category='testing',
|
|
|
|
conditions=[conditions.is_b2g_desktop],
|
|
|
|
description='Run a b2g desktop mochitest.')
|
|
|
|
@B2GCommand
|
|
|
|
def run_mochitest_b2g_desktop(self, test_file, **kwargs):
|
2013-10-01 09:36:44 -07:00
|
|
|
from mozbuild.controller.building import BuildDriver
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
self._ensure_state_subdir_exists('.')
|
|
|
|
|
2013-10-01 09:36:44 -07:00
|
|
|
driver = self._spawn(BuildDriver)
|
|
|
|
driver.install_tests(remove=False)
|
|
|
|
|
2013-09-19 11:43:44 -07:00
|
|
|
mochitest = self._spawn(MochitestRunner)
|
|
|
|
return mochitest.run_b2g_test(test_file=test_file, **kwargs)
|