Backed out changesets c63eaabaefb1 and c14453ff8764 (bug 927685) due to frequent...
[gecko.git] / testing / mach_commands.py
blob2227f5edc369d717be6eca724a9763797c9d19e2
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import print_function, unicode_literals
7 import os
9 from mach.decorators import (
10 CommandArgument,
11 CommandProvider,
12 Command,
15 from mozbuild.base import MachCommandBase
18 HANDLE_FILE_ERROR = '''
19 %s is a file.
20 However, I do not yet know how to run tests from files. You'll need to run
21 the mach command for the test type you are trying to run. e.g.
22 $ mach xpcshell-test path/to/file
23 '''.strip()
25 HANDLE_DIR_ERROR = '''
26 %s is a directory.
27 However, I do not yet know how to run tests from directories. You can try
28 running the mach command for the tests in that directory. e.g.
29 $ mach xpcshell-test path/to/directory
30 '''.strip()
32 UNKNOWN_TEST = '''
33 I don't know how to run the test: %s
35 You need to specify a test suite name or abbreviation. It's possible I just
36 haven't been told about this test suite yet. If you suspect that's the issue,
37 please file a bug at https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=General
38 and request support be added.
39 '''.strip()
41 MOCHITEST_CHUNK_BY_DIR = 4
42 MOCHITEST_TOTAL_CHUNKS = 5
44 TEST_SUITES = {
45 'crashtest': {
46 'aliases': ('C', 'Rc', 'RC', 'rc'),
47 'mach_command': 'crashtest',
48 'kwargs': {'test_file': None},
50 'crashtest-ipc': {
51 'aliases': ('Cipc', 'cipc'),
52 'mach_command': 'crashtest-ipc',
53 'kwargs': {'test_file': None},
55 'jetpack': {
56 'aliases': ('J',),
57 'mach_command': 'jetpack-test',
58 'kwargs': {},
60 'mochitest-a11y': {
61 'mach_command': 'mochitest-a11y',
62 'kwargs': {'test_file': None},
64 'mochitest-browser': {
65 'aliases': ('bc', 'BC', 'Bc'),
66 'mach_command': 'mochitest-browser',
67 'kwargs': {'test_file': None},
69 'mochitest-chrome': {
70 'mach_command': 'mochitest-chrome',
71 'kwargs': {'test_file': None},
73 'mochitest-ipcplugins': {
74 'make_target': 'mochitest-ipcplugins',
76 'mochitest-plain': {
77 'mach_command': 'mochitest-plain',
78 'kwargs': {'test_file': None},
80 'reftest': {
81 'aliases': ('RR', 'rr', 'Rr'),
82 'mach_command': 'reftest',
83 'kwargs': {'test_file': None},
85 'reftest-ipc': {
86 'aliases': ('Ripc',),
87 'mach_command': 'reftest-ipc',
88 'kwargs': {'test_file': None},
90 'xpcshell': {
91 'aliases': ('X', 'x'),
92 'mach_command': 'xpcshell-test',
93 'kwargs': {'test_file': 'all'},
97 for i in range(1, MOCHITEST_TOTAL_CHUNKS + 1):
98 TEST_SUITES['mochitest-%d' %i] = {
99 'aliases': ('M%d' % i, 'm%d' % i),
100 'mach_command': 'mochitest-plain',
101 'kwargs': {
102 'chunk_by_dir': MOCHITEST_CHUNK_BY_DIR,
103 'total_chunks': MOCHITEST_TOTAL_CHUNKS,
104 'this_chunk': i,
105 'test_file': None,
109 TEST_HELP = '''
110 Test or tests to run. Tests can be specified by test suite name or alias.
111 The following test suites and aliases are supported: %s
112 ''' % ', '.join(sorted(TEST_SUITES))
113 TEST_HELP = TEST_HELP.strip()
116 @CommandProvider
117 class Test(MachCommandBase):
118 @Command('test', category='testing', description='Run tests.')
119 @CommandArgument('what', default=None, nargs='*', help=TEST_HELP)
120 def test(self, what):
121 status = None
122 for entry in what:
123 status = self._run_test(entry)
125 if status:
126 break
128 return status
130 def _run_test(self, what):
131 suite = None
132 if what in TEST_SUITES:
133 suite = TEST_SUITES[what]
134 else:
135 for v in TEST_SUITES.values():
136 if what in v.get('aliases', []):
137 suite = v
138 break
140 if suite:
141 if 'mach_command' in suite:
142 return self._mach_context.commands.dispatch(
143 suite['mach_command'], self._mach_context, **suite['kwargs'])
145 if 'make_target' in suite:
146 return self._run_make(target=suite['make_target'],
147 pass_thru=True)
149 raise Exception('Do not know how to run suite. This is a logic '
150 'error in this mach command.')
152 if os.path.isfile(what):
153 print(HANDLE_FILE_ERROR % what)
154 return 1
156 if os.path.isdir(what):
157 print(HANDLE_DIR_ERROR % what)
158 return 1
160 print(UNKNOWN_TEST % what)
161 return 1