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
|
|
|
|
|
2012-10-02 14:03:31 -07:00
|
|
|
import os
|
2013-02-12 12:51:24 -08:00
|
|
|
import platform
|
2012-10-02 14:03:31 -07:00
|
|
|
|
2012-11-06 16:57:41 -08:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
generic_help = 'Test to run. Can be specified as a single file, a ' +\
|
|
|
|
'directory, or omitted. If omitted, the entire test suite is executed.'
|
|
|
|
|
2012-12-05 14:27:54 -08:00
|
|
|
debugger_help = 'Debugger binary to run test in. Program name or path.'
|
|
|
|
|
2012-09-26 09:43:53 -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.
|
|
|
|
"""
|
|
|
|
def run_plain_suite(self):
|
|
|
|
"""Runs all plain mochitests."""
|
|
|
|
# TODO hook up Python harness runner.
|
|
|
|
self._run_make(directory='.', target='mochitest-plain')
|
|
|
|
|
|
|
|
def run_chrome_suite(self):
|
|
|
|
"""Runs all chrome mochitests."""
|
|
|
|
# TODO hook up Python harness runner.
|
|
|
|
self._run_make(directory='.', target='mochitest-chrome')
|
|
|
|
|
|
|
|
def run_browser_chrome_suite(self):
|
|
|
|
"""Runs browser chrome mochitests."""
|
|
|
|
# TODO hook up Python harness runner.
|
|
|
|
self._run_make(directory='.', target='mochitest-browser-chrome')
|
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
def run_metro_chrome_suite(self):
|
|
|
|
"""Runs Windows 8 Metro browser chrome mochitests."""
|
|
|
|
# TODO hook up Python harness runner.
|
|
|
|
self._run_make(directory='.', target='mochitest-metro-chrome')
|
|
|
|
|
2012-09-26 09:43:53 -07:00
|
|
|
def run_all(self):
|
|
|
|
self.run_plain_suite()
|
|
|
|
self.run_chrome_suite()
|
|
|
|
self.run_browser_chrome_suite()
|
2013-02-12 12:51:24 -08:00
|
|
|
# Run Metro tests only on Windows 8 and higher
|
|
|
|
if platform.system() is 'Windows':
|
|
|
|
version = tuple(map(int, platform.version().split('.')))
|
|
|
|
if version >= (6, 2):
|
|
|
|
self.run_metro_chrome_suite()
|
2012-09-26 09:43:53 -07:00
|
|
|
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest_test(self, suite=None, test_file=None, debugger=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'
|
2012-09-26 09:43:53 -07:00
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO hook up harness via native Python
|
|
|
|
target = None
|
|
|
|
if suite == 'plain':
|
|
|
|
target = 'mochitest-plain'
|
|
|
|
elif suite == 'chrome':
|
|
|
|
target = 'mochitest-chrome'
|
|
|
|
elif suite == 'browser':
|
|
|
|
target = 'mochitest-browser-chrome'
|
2013-02-12 12:51:24 -08:00
|
|
|
elif suite == 'metro':
|
|
|
|
target = 'mochitest-metro-chrome'
|
2012-10-02 01:24:12 -07:00
|
|
|
elif suite == 'a11y':
|
|
|
|
target = 'mochitest-a11y'
|
2012-09-26 09:43:53 -07:00
|
|
|
else:
|
|
|
|
raise Exception('None or unrecognized mochitest suite type.')
|
|
|
|
|
2012-10-02 01:24:11 -07:00
|
|
|
if test_file:
|
2013-02-13 15:35:44 -08:00
|
|
|
if not os.path.exists(test_file):
|
|
|
|
raise Exception('No manifest file was found at %s.' % test_file)
|
|
|
|
env = {'TEST_PATH': test_file}
|
2012-10-02 01:24:11 -07:00
|
|
|
else:
|
|
|
|
env = {}
|
2012-09-26 09:43:53 -07:00
|
|
|
|
2012-12-05 14:27:54 -08:00
|
|
|
pass_thru = False
|
|
|
|
|
|
|
|
if debugger:
|
|
|
|
env[b'EXTRA_TEST_ARGS'] = '--debugger=%s' % debugger
|
|
|
|
pass_thru = True
|
|
|
|
|
2012-11-14 12:56:02 -08:00
|
|
|
return self._run_make(directory='.', target=target, append_env=env,
|
2012-12-05 14:27:54 -08:00
|
|
|
ensure_exit_code=False, pass_thru=pass_thru)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
@CommandProvider
|
2012-11-06 16:57:41 -08:00
|
|
|
class MachCommands(MachCommandBase):
|
2012-10-10 11:08:09 -07:00
|
|
|
@Command('mochitest-plain', help='Run a plain mochitest.')
|
2012-12-05 14:27:54 -08:00
|
|
|
@CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help=debugger_help)
|
2012-10-10 11:08:09 -07:00
|
|
|
@CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
|
|
|
|
help=generic_help)
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest_plain(self, test_file, debugger=None):
|
|
|
|
return self.run_mochitest(test_file, 'plain', debugger=debugger)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
|
|
|
@Command('mochitest-chrome', help='Run a chrome mochitest.')
|
2012-12-05 14:27:54 -08:00
|
|
|
@CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help=debugger_help)
|
2012-10-10 11:08:09 -07:00
|
|
|
@CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
|
|
|
|
help=generic_help)
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest_chrome(self, test_file, debugger=None):
|
|
|
|
return self.run_mochitest(test_file, 'chrome', debugger=debugger)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
|
|
|
@Command('mochitest-browser', help='Run a mochitest with browser chrome.')
|
2012-12-05 14:27:54 -08:00
|
|
|
@CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help=debugger_help)
|
2012-10-10 11:08:09 -07:00
|
|
|
@CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
|
|
|
|
help=generic_help)
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest_browser(self, test_file, debugger=None):
|
|
|
|
return self.run_mochitest(test_file, 'browser', debugger=debugger)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
@Command('mochitest-metro', help='Run a mochitest with metro browser chrome.')
|
|
|
|
@CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help=debugger_help)
|
|
|
|
@CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
|
|
|
|
help=generic_help)
|
|
|
|
def run_mochitest_metro(self, test_file, debugger=None):
|
|
|
|
return self.run_mochitest(test_file, 'metro', debugger=debugger)
|
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
@Command('mochitest-a11y', help='Run an a11y mochitest.')
|
2012-12-05 14:27:54 -08:00
|
|
|
@CommandArgument('--debugger', '-d', metavar='DEBUGGER',
|
|
|
|
help=debugger_help)
|
2012-10-10 11:08:09 -07:00
|
|
|
@CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
|
|
|
|
help=generic_help)
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest_a11y(self, test_file, debugger=None):
|
|
|
|
return self.run_mochitest(test_file, 'a11y', debugger=debugger)
|
2012-10-10 11:08:09 -07:00
|
|
|
|
2012-12-05 14:27:54 -08:00
|
|
|
def run_mochitest(self, test_file, flavor, debugger=None):
|
2012-11-02 10:32:40 -07:00
|
|
|
self._ensure_state_subdir_exists('.')
|
|
|
|
|
2012-10-10 11:08:09 -07:00
|
|
|
mochitest = self._spawn(MochitestRunner)
|
2012-12-05 14:27:54 -08:00
|
|
|
return mochitest.run_mochitest_test(test_file=test_file, suite=flavor,
|
|
|
|
debugger=debugger)
|