Bug 1800546 Part 1 - Use the style given the first page name for setting default...
[gecko.git] / testing / mozharness / mach_commands.py
blobbfba74b977357d4715d6d244da1629a320a30ae5
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 absolute_import, print_function, unicode_literals
7 import argparse
8 import os
9 import re
10 import subprocess
11 import sys
13 import mozinfo
14 from six.moves.urllib.parse import urljoin
15 from six.moves.urllib.request import pathname2url
17 from mach.decorators import (
18 CommandArgument,
19 Command,
22 from mozbuild.base import MozbuildObject
23 from mozbuild.base import MachCommandConditions as conditions
24 from argparse import ArgumentParser
27 def get_parser():
28 parser = argparse.ArgumentParser()
29 parser.add_argument(
30 "suite_name",
31 nargs=1,
32 type=str,
33 action="store",
34 help="Suite to run in mozharness",
36 parser.add_argument(
37 "mozharness_args",
38 nargs=argparse.REMAINDER,
39 help="Extra arguments to pass to mozharness",
41 return parser
44 class MozharnessRunner(MozbuildObject):
45 def __init__(self, *args, **kwargs):
46 MozbuildObject.__init__(self, *args, **kwargs)
48 self.test_packages_url = self._test_packages_url()
49 self.installer_url = self._installer_url()
51 desktop_unittest_config = [
52 "--config-file",
53 lambda: self.config_path(
54 "unittests", "%s_unittest.py" % mozinfo.info["os"]
56 "--config-file",
57 lambda: self.config_path("developer_config.py"),
60 self.config = {
61 "__defaults__": {
62 "config": [
63 "--download-symbols",
64 "ondemand",
65 "--installer-url",
66 self.installer_url,
67 "--test-packages-url",
68 self.test_packages_url,
71 "mochitest-valgrind": {
72 "script": "desktop_unittest.py",
73 "config": desktop_unittest_config
74 + ["--mochitest-suite", "valgrind-plain"],
76 "mochitest": {
77 "script": "desktop_unittest.py",
78 "config": desktop_unittest_config + ["--mochitest-suite", "plain"],
80 "mochitest-chrome": {
81 "script": "desktop_unittest.py",
82 "config": desktop_unittest_config + ["--mochitest-suite", "chrome"],
84 "mochitest-browser-chrome": {
85 "script": "desktop_unittest.py",
86 "config": desktop_unittest_config
87 + ["--mochitest-suite", "browser-chrome"],
89 "mochitest-browser-a11y": {
90 "script": "desktop_unittest.py",
91 "config": desktop_unittest_config
92 + ["--mochitest-suite", "mochitest-browser-a11y"],
94 "mochitest-devtools-chrome": {
95 "script": "desktop_unittest.py",
96 "config": desktop_unittest_config
97 + ["--mochitest-suite", "mochitest-devtools-chrome"],
99 "mochitest-remote": {
100 "script": "desktop_unittest.py",
101 "config": desktop_unittest_config
102 + ["--mochitest-suite", "mochitest-remote"],
104 "crashtest": {
105 "script": "desktop_unittest.py",
106 "config": desktop_unittest_config + ["--reftest-suite", "crashtest"],
108 "jsreftest": {
109 "script": "desktop_unittest.py",
110 "config": desktop_unittest_config + ["--reftest-suite", "jsreftest"],
112 "reftest": {
113 "script": "desktop_unittest.py",
114 "config": desktop_unittest_config + ["--reftest-suite", "reftest"],
116 "reftest-no-accel": {
117 "script": "desktop_unittest.py",
118 "config": desktop_unittest_config
119 + ["--reftest-suite", "reftest-no-accel"],
121 "cppunittest": {
122 "script": "desktop_unittest.py",
123 "config": desktop_unittest_config
124 + ["--cppunittest-suite", "cppunittest"],
126 "xpcshell": {
127 "script": "desktop_unittest.py",
128 "config": desktop_unittest_config + ["--xpcshell-suite", "xpcshell"],
130 "xpcshell-addons": {
131 "script": "desktop_unittest.py",
132 "config": desktop_unittest_config
133 + ["--xpcshell-suite", "xpcshell-addons"],
135 "jittest": {
136 "script": "desktop_unittest.py",
137 "config": desktop_unittest_config + ["--jittest-suite", "jittest"],
139 "marionette": {
140 "script": "marionette.py",
141 "config": [
142 "--config-file",
143 self.config_path("marionette", "test_config.py"),
146 "web-platform-tests": {
147 "script": "web_platform_tests.py",
148 "config": [
149 "--config-file",
150 self.config_path("web_platform_tests", self.wpt_config),
155 def path_to_url(self, path):
156 return urljoin("file:", pathname2url(path))
158 def _installer_url(self):
159 package_re = {
160 "linux": re.compile("^firefox-\d+\..+\.tar\.bz2$"),
161 "win": re.compile("^firefox-\d+\..+\.installer\.exe$"),
162 "mac": re.compile("^firefox-\d+\..+\.mac(?:64)?\.dmg$"),
163 }[mozinfo.info["os"]]
164 dist_path = os.path.join(self.topobjdir, "dist")
165 filenames = [item for item in os.listdir(dist_path) if package_re.match(item)]
166 assert len(filenames) == 1
167 return self.path_to_url(os.path.join(dist_path, filenames[0]))
169 def _test_packages_url(self):
170 dist_path = os.path.join(self.topobjdir, "dist")
171 filenames = [
172 item
173 for item in os.listdir(dist_path)
174 if item.endswith("test_packages.json")
176 assert len(filenames) == 1
177 return self.path_to_url(os.path.join(dist_path, filenames[0]))
179 def config_path(self, *parts):
180 return self.path_to_url(
181 os.path.join(self.topsrcdir, "testing", "mozharness", "configs", *parts)
184 @property
185 def wpt_config(self):
186 return (
187 "test_config.py"
188 if mozinfo.info["os"] != "win"
189 else "test_config_windows.py"
192 def run_suite(self, suite, **kwargs):
193 default_config = self.config.get("__defaults__")
194 suite_config = self.config.get(suite)
196 if suite_config is None:
197 print("Unknown suite %s" % suite)
198 return 1
200 script = os.path.join(
201 self.topsrcdir, "testing", "mozharness", "scripts", suite_config["script"]
203 options = [
204 item() if callable(item) else item
205 for item in default_config["config"] + suite_config["config"]
208 cmd = [script] + options
210 rv = subprocess.call(cmd, cwd=os.path.dirname(script))
211 return rv
214 @Command(
215 "mozharness",
216 category="testing",
217 description="Run tests using mozharness.",
218 conditions=[conditions.is_firefox_or_android],
219 parser=get_parser,
221 def mozharness(command_context, **kwargs):
222 runner = command_context._spawn(MozharnessRunner)
223 return runner.run_suite(kwargs.pop("suite_name")[0], **kwargs)