2013-09-09 12:37:38 -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/.
|
|
|
|
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
|
|
|
import os
|
2014-06-18 11:21:12 -07:00
|
|
|
import sys
|
2013-09-09 12:37:38 -07:00
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
|
|
|
from mozbuild.base import MachCommandBase
|
|
|
|
|
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
UNKNOWN_TEST = '''
|
|
|
|
I was unable to find tests in the argument(s) given.
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
You need to specify a test directory, filename, test suite name, or
|
|
|
|
abbreviation.
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
It's possible my little brain doesn't know about the type of test you are
|
|
|
|
trying to execute. If you suspect this, please request support by filing
|
|
|
|
a bug at
|
|
|
|
https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=General.
|
|
|
|
'''.strip()
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
UNKNOWN_FLAVOR = '''
|
|
|
|
I know you are trying to run a %s test. Unfortunately, I can't run those
|
|
|
|
tests yet. Sorry!
|
2013-09-09 12:37:38 -07:00
|
|
|
'''.strip()
|
|
|
|
|
|
|
|
MOCHITEST_CHUNK_BY_DIR = 4
|
|
|
|
MOCHITEST_TOTAL_CHUNKS = 5
|
|
|
|
|
|
|
|
TEST_SUITES = {
|
2014-01-02 07:19:35 -08:00
|
|
|
'cppunittest': {
|
|
|
|
'aliases': ('Cpp', 'cpp'),
|
|
|
|
'mach_command': 'cppunittest',
|
|
|
|
'kwargs': {'test_file': None},
|
|
|
|
},
|
2013-09-09 12:37:38 -07:00
|
|
|
'crashtest': {
|
|
|
|
'aliases': ('C', 'Rc', 'RC', 'rc'),
|
|
|
|
'mach_command': 'crashtest',
|
|
|
|
'kwargs': {'test_file': None},
|
|
|
|
},
|
|
|
|
'crashtest-ipc': {
|
|
|
|
'aliases': ('Cipc', 'cipc'),
|
|
|
|
'mach_command': 'crashtest-ipc',
|
|
|
|
'kwargs': {'test_file': None},
|
|
|
|
},
|
|
|
|
'jetpack': {
|
|
|
|
'aliases': ('J',),
|
|
|
|
'mach_command': 'jetpack-test',
|
|
|
|
'kwargs': {},
|
|
|
|
},
|
2014-04-29 07:22:50 -07:00
|
|
|
'check-spidermonkey': {
|
|
|
|
'aliases': ('Sm', 'sm'),
|
|
|
|
'mach_command': 'check-spidermonkey',
|
|
|
|
'kwargs': {'valgrind': False},
|
2014-03-27 07:16:14 -07:00
|
|
|
},
|
2013-09-09 12:37:38 -07:00
|
|
|
'mochitest-a11y': {
|
2014-06-17 16:03:49 -07:00
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'a11y', 'test_paths': None},
|
2013-09-09 12:37:38 -07:00
|
|
|
},
|
|
|
|
'mochitest-browser': {
|
|
|
|
'aliases': ('bc', 'BC', 'Bc'),
|
|
|
|
'mach_command': 'mochitest-browser',
|
2014-06-17 16:03:49 -07:00
|
|
|
'kwargs': {'flavor': 'browser-chrome', 'test_paths': None},
|
2013-09-09 12:37:38 -07:00
|
|
|
},
|
|
|
|
'mochitest-chrome': {
|
2014-06-17 16:03:49 -07:00
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'chrome', 'test_paths': None},
|
2013-09-09 12:37:38 -07:00
|
|
|
},
|
2014-03-25 09:52:53 -07:00
|
|
|
'mochitest-devtools': {
|
|
|
|
'aliases': ('dt', 'DT', 'Dt'),
|
2014-06-17 16:03:49 -07:00
|
|
|
'mach_command': 'mochitest-browser',
|
|
|
|
'kwargs': {'subsuite': 'devtools', 'test_paths': None},
|
2014-03-25 09:52:53 -07:00
|
|
|
},
|
2013-09-09 12:37:38 -07:00
|
|
|
'mochitest-ipcplugins': {
|
|
|
|
'make_target': 'mochitest-ipcplugins',
|
|
|
|
},
|
|
|
|
'mochitest-plain': {
|
2014-06-17 16:03:49 -07:00
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'mochitest', 'test_paths': None},
|
2013-09-09 12:37:38 -07:00
|
|
|
},
|
|
|
|
'reftest': {
|
|
|
|
'aliases': ('RR', 'rr', 'Rr'),
|
|
|
|
'mach_command': 'reftest',
|
|
|
|
'kwargs': {'test_file': None},
|
|
|
|
},
|
|
|
|
'reftest-ipc': {
|
|
|
|
'aliases': ('Ripc',),
|
|
|
|
'mach_command': 'reftest-ipc',
|
|
|
|
'kwargs': {'test_file': None},
|
|
|
|
},
|
2013-12-18 17:36:08 -08:00
|
|
|
'valgrind': {
|
|
|
|
'aliases': ('V', 'v'),
|
|
|
|
'mach_command': 'valgrind-test',
|
|
|
|
'kwargs': {},
|
|
|
|
},
|
2013-09-09 12:37:38 -07:00
|
|
|
'xpcshell': {
|
|
|
|
'aliases': ('X', 'x'),
|
|
|
|
'mach_command': 'xpcshell-test',
|
|
|
|
'kwargs': {'test_file': 'all'},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
# Maps test flavors to metadata on how to run that test.
|
|
|
|
TEST_FLAVORS = {
|
|
|
|
'a11y': {
|
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'a11y', 'test_paths': []},
|
|
|
|
},
|
|
|
|
'browser-chrome': {
|
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'browser-chrome', 'test_paths': []},
|
|
|
|
},
|
|
|
|
'chrashtest': { },
|
|
|
|
'chrome': {
|
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'chrome', 'test_paths': []},
|
|
|
|
},
|
|
|
|
'mochitest': {
|
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'mochitest', 'test_paths': []},
|
|
|
|
},
|
|
|
|
'reftest': { },
|
|
|
|
'steeplechase': { },
|
|
|
|
'webapprt-chrome': {
|
|
|
|
'mach_command': 'mochitest',
|
|
|
|
'kwargs': {'flavor': 'webapprt-chrome', 'test_paths': []},
|
|
|
|
},
|
|
|
|
'xpcshell': {
|
|
|
|
'mach_command': 'xpcshell-test',
|
|
|
|
'kwargs': {'test_paths': []},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-09 12:37:38 -07:00
|
|
|
for i in range(1, MOCHITEST_TOTAL_CHUNKS + 1):
|
|
|
|
TEST_SUITES['mochitest-%d' %i] = {
|
|
|
|
'aliases': ('M%d' % i, 'm%d' % i),
|
2014-06-17 16:03:49 -07:00
|
|
|
'mach_command': 'mochitest',
|
2013-09-09 12:37:38 -07:00
|
|
|
'kwargs': {
|
2014-06-17 16:03:49 -07:00
|
|
|
'flavor': 'mochitest',
|
2013-09-09 12:37:38 -07:00
|
|
|
'chunk_by_dir': MOCHITEST_CHUNK_BY_DIR,
|
|
|
|
'total_chunks': MOCHITEST_TOTAL_CHUNKS,
|
|
|
|
'this_chunk': i,
|
2014-06-17 16:03:49 -07:00
|
|
|
'test_paths': None,
|
2013-09-09 12:37:38 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_HELP = '''
|
2014-06-18 11:21:12 -07:00
|
|
|
Test or tests to run. Tests can be specified by filename, directory, suite
|
|
|
|
name or suite alias.
|
|
|
|
|
2013-09-09 12:37:38 -07:00
|
|
|
The following test suites and aliases are supported: %s
|
|
|
|
''' % ', '.join(sorted(TEST_SUITES))
|
|
|
|
TEST_HELP = TEST_HELP.strip()
|
|
|
|
|
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class Test(MachCommandBase):
|
2014-08-09 06:37:29 -07:00
|
|
|
@Command('test', category='testing', description='Run tests (detects the kind of test and runs it).')
|
2013-09-09 12:37:38 -07:00
|
|
|
@CommandArgument('what', default=None, nargs='*', help=TEST_HELP)
|
|
|
|
def test(self, what):
|
2014-06-18 11:21:12 -07:00
|
|
|
from mozbuild.testing import TestResolver
|
|
|
|
|
|
|
|
# Parse arguments and assemble a test "plan."
|
|
|
|
run_suites = set()
|
|
|
|
run_tests = []
|
|
|
|
resolver = self._spawn(TestResolver)
|
|
|
|
|
2013-09-09 12:37:38 -07:00
|
|
|
for entry in what:
|
2014-06-18 11:21:12 -07:00
|
|
|
# If the path matches the name or alias of an entire suite, run
|
|
|
|
# the entire suite.
|
|
|
|
if entry in TEST_SUITES:
|
|
|
|
run_suites.add(entry)
|
|
|
|
continue
|
|
|
|
suitefound = False
|
|
|
|
for suite, v in TEST_SUITES.items():
|
|
|
|
if entry in v.get('aliases', []):
|
|
|
|
run_suites.add(suite)
|
|
|
|
suitefound = True
|
|
|
|
if suitefound:
|
|
|
|
continue
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
# Now look for file/directory matches in the TestResolver.
|
2014-07-01 14:21:00 -07:00
|
|
|
relpath = self._wrap_path_argument(entry).relpath()
|
|
|
|
tests = list(resolver.resolve_tests(paths=[relpath]))
|
2014-06-18 11:21:12 -07:00
|
|
|
run_tests.extend(tests)
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
if not tests:
|
|
|
|
print('UNKNOWN TEST: %s' % entry, file=sys.stderr)
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
if not run_suites and not run_tests:
|
|
|
|
print(UNKNOWN_TEST)
|
|
|
|
return 1
|
|
|
|
|
|
|
|
status = None
|
|
|
|
for suite_name in run_suites:
|
|
|
|
suite = TEST_SUITES[suite_name]
|
2013-09-09 12:37:38 -07:00
|
|
|
|
|
|
|
if 'mach_command' in suite:
|
2014-06-18 11:21:12 -07:00
|
|
|
res = self._mach_context.commands.dispatch(
|
|
|
|
suite['mach_command'], self._mach_context,
|
|
|
|
**suite['kwargs'])
|
|
|
|
if res:
|
|
|
|
status = res
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
elif 'make_target' in suite:
|
|
|
|
res = self._run_make(target=suite['make_target'],
|
2013-09-09 12:37:38 -07:00
|
|
|
pass_thru=True)
|
2014-06-18 11:21:12 -07:00
|
|
|
if res:
|
|
|
|
status = res
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
flavors = {}
|
|
|
|
for test in run_tests:
|
|
|
|
flavors.setdefault(test['flavor'], []).append(test)
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
for flavor, tests in sorted(flavors.items()):
|
|
|
|
if flavor not in TEST_FLAVORS:
|
|
|
|
print(UNKNOWN_FLAVOR % flavor)
|
|
|
|
status = 1
|
|
|
|
continue
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-06-18 11:21:12 -07:00
|
|
|
m = TEST_FLAVORS[flavor]
|
|
|
|
if 'mach_command' not in m:
|
|
|
|
print(UNKNOWN_FLAVOR % flavor)
|
|
|
|
status = 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
res = self._mach_context.commands.dispatch(
|
|
|
|
m['mach_command'], self._mach_context,
|
|
|
|
test_objects=tests, **m['kwargs'])
|
|
|
|
if res:
|
|
|
|
status = res
|
|
|
|
|
|
|
|
return status
|
2013-09-09 12:37:38 -07:00
|
|
|
|
2014-01-02 07:19:35 -08:00
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command('cppunittest', category='testing',
|
2014-08-09 06:37:29 -07:00
|
|
|
description='Run cpp unit tests (C++ tests).')
|
2014-01-02 07:19:35 -08:00
|
|
|
@CommandArgument('test_files', nargs='*', metavar='N',
|
|
|
|
help='Test to run. Can be specified as one or more files or ' \
|
|
|
|
'directories, or omitted. If omitted, the entire test suite is ' \
|
|
|
|
'executed.')
|
|
|
|
|
|
|
|
def run_cppunit_test(self, **params):
|
2014-07-10 06:33:39 -07:00
|
|
|
from mozlog.structured import commandline
|
2014-01-02 07:19:35 -08:00
|
|
|
import runcppunittests as cppunittests
|
2014-07-10 06:33:39 -07:00
|
|
|
|
|
|
|
log = commandline.setup_logging("cppunittest",
|
|
|
|
{},
|
|
|
|
{"tbpl": sys.stdout})
|
2014-01-02 07:19:35 -08:00
|
|
|
|
|
|
|
if len(params['test_files']) == 0:
|
|
|
|
testdir = os.path.join(self.distdir, 'cppunittests')
|
|
|
|
progs = cppunittests.extract_unittests_from_args([testdir], None)
|
|
|
|
else:
|
|
|
|
progs = cppunittests.extract_unittests_from_args(params['test_files'], None)
|
|
|
|
|
|
|
|
# See if we have crash symbols
|
|
|
|
symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
|
|
|
|
if not os.path.isdir(symbols_path):
|
|
|
|
symbols_path = None
|
|
|
|
|
|
|
|
tester = cppunittests.CPPUnitTests()
|
|
|
|
try:
|
2014-07-10 06:33:39 -07:00
|
|
|
result = tester.run_tests(progs, self.bindir, symbols_path, interactive=True)
|
|
|
|
except Exception as e:
|
|
|
|
log.error("Caught exception running cpp unit tests: %s" % str(e))
|
2014-01-02 07:19:35 -08:00
|
|
|
result = False
|
|
|
|
|
|
|
|
return 0 if result else 1
|
2014-03-27 07:16:14 -07:00
|
|
|
|
|
|
|
@CommandProvider
|
2014-04-29 07:22:50 -07:00
|
|
|
class CheckSpiderMonkeyCommand(MachCommandBase):
|
2014-08-09 06:37:29 -07:00
|
|
|
@Command('check-spidermonkey', category='testing', description='Run SpiderMonkey tests (JavaScript engine).')
|
2014-03-27 07:16:14 -07:00
|
|
|
@CommandArgument('--valgrind', action='store_true', help='Run jit-test suite with valgrind flag')
|
|
|
|
|
2014-04-29 07:22:50 -07:00
|
|
|
def run_checkspidermonkey(self, **params):
|
2014-03-27 07:16:14 -07:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2014-04-29 07:22:50 -07:00
|
|
|
bin_suffix = ''
|
2014-03-27 07:16:14 -07:00
|
|
|
if sys.platform.startswith('win'):
|
2014-04-29 07:22:50 -07:00
|
|
|
bin_suffix = '.exe'
|
2014-03-27 07:16:14 -07:00
|
|
|
|
2014-04-29 07:22:50 -07:00
|
|
|
js = os.path.join(self.bindir, 'js%s' % bin_suffix)
|
|
|
|
|
|
|
|
print('Running jit-tests')
|
|
|
|
jittest_cmd = [os.path.join(self.topsrcdir, 'js', 'src', 'jit-test', 'jit_test.py'),
|
|
|
|
js, '--no-slow', '--tbpl']
|
2014-03-27 07:16:14 -07:00
|
|
|
if params['valgrind']:
|
2014-04-29 07:22:50 -07:00
|
|
|
jittest_cmd.append('--valgrind')
|
|
|
|
|
|
|
|
jittest_result = subprocess.call(jittest_cmd)
|
|
|
|
|
|
|
|
print('running jstests')
|
|
|
|
jstest_cmd = [os.path.join(self.topsrcdir, 'js', 'src', 'tests', 'jstests.py'),
|
|
|
|
js, '--tbpl']
|
|
|
|
jstest_result = subprocess.call(jstest_cmd)
|
|
|
|
|
|
|
|
print('running jsapi-tests')
|
|
|
|
jsapi_tests_cmd = [os.path.join(self.bindir, 'jsapi-tests%s' % bin_suffix)]
|
|
|
|
jsapi_tests_result = subprocess.call(jsapi_tests_cmd)
|
|
|
|
|
|
|
|
print('running check-style')
|
|
|
|
check_style_cmd = [sys.executable, os.path.join(self.topsrcdir, 'config', 'check_spidermonkey_style.py')]
|
|
|
|
check_style_result = subprocess.call(check_style_cmd, cwd=os.path.join(self.topsrcdir, 'js', 'src'))
|
|
|
|
|
|
|
|
all_passed = jittest_result and jstest_result and jsapi_tests_result and check_style_result
|
2014-03-27 07:16:14 -07:00
|
|
|
|
2014-04-29 07:22:50 -07:00
|
|
|
return all_passed
|