testing/mach_commands.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 from __future__ import print_function, unicode_literals
michael@0 6
michael@0 7 import os
michael@0 8
michael@0 9 from mach.decorators import (
michael@0 10 CommandArgument,
michael@0 11 CommandProvider,
michael@0 12 Command,
michael@0 13 )
michael@0 14
michael@0 15 from mozbuild.base import MachCommandBase
michael@0 16
michael@0 17
michael@0 18 HANDLE_FILE_ERROR = '''
michael@0 19 %s is a file.
michael@0 20 However, I do not yet know how to run tests from files. You'll need to run
michael@0 21 the mach command for the test type you are trying to run. e.g.
michael@0 22 $ mach xpcshell-test path/to/file
michael@0 23 '''.strip()
michael@0 24
michael@0 25 HANDLE_DIR_ERROR = '''
michael@0 26 %s is a directory.
michael@0 27 However, I do not yet know how to run tests from directories. You can try
michael@0 28 running the mach command for the tests in that directory. e.g.
michael@0 29 $ mach xpcshell-test path/to/directory
michael@0 30 '''.strip()
michael@0 31
michael@0 32 UNKNOWN_TEST = '''
michael@0 33 I don't know how to run the test: %s
michael@0 34
michael@0 35 You need to specify a test suite name or abbreviation. It's possible I just
michael@0 36 haven't been told about this test suite yet. If you suspect that's the issue,
michael@0 37 please file a bug at https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=General
michael@0 38 and request support be added.
michael@0 39 '''.strip()
michael@0 40
michael@0 41 MOCHITEST_CHUNK_BY_DIR = 4
michael@0 42 MOCHITEST_TOTAL_CHUNKS = 5
michael@0 43
michael@0 44 TEST_SUITES = {
michael@0 45 'cppunittest': {
michael@0 46 'aliases': ('Cpp', 'cpp'),
michael@0 47 'mach_command': 'cppunittest',
michael@0 48 'kwargs': {'test_file': None},
michael@0 49 },
michael@0 50 'crashtest': {
michael@0 51 'aliases': ('C', 'Rc', 'RC', 'rc'),
michael@0 52 'mach_command': 'crashtest',
michael@0 53 'kwargs': {'test_file': None},
michael@0 54 },
michael@0 55 'crashtest-ipc': {
michael@0 56 'aliases': ('Cipc', 'cipc'),
michael@0 57 'mach_command': 'crashtest-ipc',
michael@0 58 'kwargs': {'test_file': None},
michael@0 59 },
michael@0 60 'jetpack': {
michael@0 61 'aliases': ('J',),
michael@0 62 'mach_command': 'jetpack-test',
michael@0 63 'kwargs': {},
michael@0 64 },
michael@0 65 'jittest': {
michael@0 66 'aliases': ('Jit', 'jit'),
michael@0 67 'mach_command': 'jittest',
michael@0 68 'kwargs': {'test_file': None},
michael@0 69 },
michael@0 70 'mochitest-a11y': {
michael@0 71 'mach_command': 'mochitest-a11y',
michael@0 72 'kwargs': {'test_file': None},
michael@0 73 },
michael@0 74 'mochitest-browser': {
michael@0 75 'aliases': ('bc', 'BC', 'Bc'),
michael@0 76 'mach_command': 'mochitest-browser',
michael@0 77 'kwargs': {'test_file': None},
michael@0 78 },
michael@0 79 'mochitest-chrome': {
michael@0 80 'mach_command': 'mochitest-chrome',
michael@0 81 'kwargs': {'test_file': None},
michael@0 82 },
michael@0 83 'mochitest-devtools': {
michael@0 84 'aliases': ('dt', 'DT', 'Dt'),
michael@0 85 'mach_command': 'mochitest-browser --subsuite=devtools',
michael@0 86 'kwargs': {'test_file': None},
michael@0 87 },
michael@0 88 'mochitest-ipcplugins': {
michael@0 89 'make_target': 'mochitest-ipcplugins',
michael@0 90 },
michael@0 91 'mochitest-plain': {
michael@0 92 'mach_command': 'mochitest-plain',
michael@0 93 'kwargs': {'test_file': None},
michael@0 94 },
michael@0 95 'reftest': {
michael@0 96 'aliases': ('RR', 'rr', 'Rr'),
michael@0 97 'mach_command': 'reftest',
michael@0 98 'kwargs': {'test_file': None},
michael@0 99 },
michael@0 100 'reftest-ipc': {
michael@0 101 'aliases': ('Ripc',),
michael@0 102 'mach_command': 'reftest-ipc',
michael@0 103 'kwargs': {'test_file': None},
michael@0 104 },
michael@0 105 'valgrind': {
michael@0 106 'aliases': ('V', 'v'),
michael@0 107 'mach_command': 'valgrind-test',
michael@0 108 'kwargs': {},
michael@0 109 },
michael@0 110 'xpcshell': {
michael@0 111 'aliases': ('X', 'x'),
michael@0 112 'mach_command': 'xpcshell-test',
michael@0 113 'kwargs': {'test_file': 'all'},
michael@0 114 },
michael@0 115 }
michael@0 116
michael@0 117 for i in range(1, MOCHITEST_TOTAL_CHUNKS + 1):
michael@0 118 TEST_SUITES['mochitest-%d' %i] = {
michael@0 119 'aliases': ('M%d' % i, 'm%d' % i),
michael@0 120 'mach_command': 'mochitest-plain',
michael@0 121 'kwargs': {
michael@0 122 'chunk_by_dir': MOCHITEST_CHUNK_BY_DIR,
michael@0 123 'total_chunks': MOCHITEST_TOTAL_CHUNKS,
michael@0 124 'this_chunk': i,
michael@0 125 'test_file': None,
michael@0 126 },
michael@0 127 }
michael@0 128
michael@0 129 TEST_HELP = '''
michael@0 130 Test or tests to run. Tests can be specified by test suite name or alias.
michael@0 131 The following test suites and aliases are supported: %s
michael@0 132 ''' % ', '.join(sorted(TEST_SUITES))
michael@0 133 TEST_HELP = TEST_HELP.strip()
michael@0 134
michael@0 135
michael@0 136 @CommandProvider
michael@0 137 class Test(MachCommandBase):
michael@0 138 @Command('test', category='testing', description='Run tests.')
michael@0 139 @CommandArgument('what', default=None, nargs='*', help=TEST_HELP)
michael@0 140 def test(self, what):
michael@0 141 status = None
michael@0 142 for entry in what:
michael@0 143 status = self._run_test(entry)
michael@0 144
michael@0 145 if status:
michael@0 146 break
michael@0 147
michael@0 148 return status
michael@0 149
michael@0 150 def _run_test(self, what):
michael@0 151 suite = None
michael@0 152 if what in TEST_SUITES:
michael@0 153 suite = TEST_SUITES[what]
michael@0 154 else:
michael@0 155 for v in TEST_SUITES.values():
michael@0 156 if what in v.get('aliases', []):
michael@0 157 suite = v
michael@0 158 break
michael@0 159
michael@0 160 if suite:
michael@0 161 if 'mach_command' in suite:
michael@0 162 return self._mach_context.commands.dispatch(
michael@0 163 suite['mach_command'], self._mach_context, **suite['kwargs'])
michael@0 164
michael@0 165 if 'make_target' in suite:
michael@0 166 return self._run_make(target=suite['make_target'],
michael@0 167 pass_thru=True)
michael@0 168
michael@0 169 raise Exception('Do not know how to run suite. This is a logic '
michael@0 170 'error in this mach command.')
michael@0 171
michael@0 172 if os.path.isfile(what):
michael@0 173 print(HANDLE_FILE_ERROR % what)
michael@0 174 return 1
michael@0 175
michael@0 176 if os.path.isdir(what):
michael@0 177 print(HANDLE_DIR_ERROR % what)
michael@0 178 return 1
michael@0 179
michael@0 180 print(UNKNOWN_TEST % what)
michael@0 181 return 1
michael@0 182
michael@0 183 @CommandProvider
michael@0 184 class MachCommands(MachCommandBase):
michael@0 185 @Command('cppunittest', category='testing',
michael@0 186 description='Run cpp unit tests.')
michael@0 187 @CommandArgument('test_files', nargs='*', metavar='N',
michael@0 188 help='Test to run. Can be specified as one or more files or ' \
michael@0 189 'directories, or omitted. If omitted, the entire test suite is ' \
michael@0 190 'executed.')
michael@0 191
michael@0 192 def run_cppunit_test(self, **params):
michael@0 193 import runcppunittests as cppunittests
michael@0 194 import logging
michael@0 195
michael@0 196 if len(params['test_files']) == 0:
michael@0 197 testdir = os.path.join(self.distdir, 'cppunittests')
michael@0 198 progs = cppunittests.extract_unittests_from_args([testdir], None)
michael@0 199 else:
michael@0 200 progs = cppunittests.extract_unittests_from_args(params['test_files'], None)
michael@0 201
michael@0 202 # See if we have crash symbols
michael@0 203 symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
michael@0 204 if not os.path.isdir(symbols_path):
michael@0 205 symbols_path = None
michael@0 206
michael@0 207 tester = cppunittests.CPPUnitTests()
michael@0 208 try:
michael@0 209 result = tester.run_tests(progs, self.bindir, symbols_path)
michael@0 210 except Exception, e:
michael@0 211 self.log(logging.ERROR, 'cppunittests',
michael@0 212 {'exception': str(e)},
michael@0 213 'Caught exception running cpp unit tests: {exception}')
michael@0 214 result = False
michael@0 215
michael@0 216 return 0 if result else 1
michael@0 217
michael@0 218 @CommandProvider
michael@0 219 class JittestCommand(MachCommandBase):
michael@0 220 @Command('jittest', category='testing', description='Run jit-test tests.')
michael@0 221 @CommandArgument('--valgrind', action='store_true', help='Run jit-test suite with valgrind flag')
michael@0 222
michael@0 223 def run_jittest(self, **params):
michael@0 224 import subprocess
michael@0 225 import sys
michael@0 226
michael@0 227 if sys.platform.startswith('win'):
michael@0 228 js = os.path.join(self.bindir, 'js.exe')
michael@0 229 else:
michael@0 230 js = os.path.join(self.bindir, 'js')
michael@0 231 cmd = [os.path.join(self.topsrcdir, 'js', 'src', 'jit-test', 'jit_test.py'),
michael@0 232 js, '--no-slow', '--no-progress', '--tinderbox', '--tbpl']
michael@0 233
michael@0 234 if params['valgrind']:
michael@0 235 cmd.append('--valgrind')
michael@0 236
michael@0 237 return subprocess.call(cmd)

mercurial