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/.
12 from six
.moves
.urllib
.parse
import urljoin
13 from six
.moves
.urllib
.request
import pathname2url
15 from mach
.decorators
import (
20 from mozbuild
.base
import MozbuildObject
21 from mozbuild
.base
import MachCommandConditions
as conditions
22 from argparse
import ArgumentParser
26 parser
= argparse
.ArgumentParser()
32 help="Suite to run in mozharness",
36 nargs
=argparse
.REMAINDER
,
37 help="Extra arguments to pass to mozharness",
42 class MozharnessRunner(MozbuildObject
):
43 def __init__(self
, *args
, **kwargs
):
44 MozbuildObject
.__init
__(self
, *args
, **kwargs
)
46 self
.test_packages_url
= self
._test
_packages
_url
()
47 self
.installer_url
= self
._installer
_url
()
49 desktop_unittest_config
= [
51 lambda: self
.config_path(
52 "unittests", "%s_unittest.py" % mozinfo
.info
["os"]
55 lambda: self
.config_path("developer_config.py"),
65 "--test-packages-url",
66 self
.test_packages_url
,
69 "mochitest-valgrind": {
70 "script": "desktop_unittest.py",
71 "config": desktop_unittest_config
72 + ["--mochitest-suite", "valgrind-plain"],
75 "script": "desktop_unittest.py",
76 "config": desktop_unittest_config
+ ["--mochitest-suite", "plain"],
79 "script": "desktop_unittest.py",
80 "config": desktop_unittest_config
+ ["--mochitest-suite", "chrome"],
82 "mochitest-browser-chrome": {
83 "script": "desktop_unittest.py",
84 "config": desktop_unittest_config
85 + ["--mochitest-suite", "browser-chrome"],
87 "mochitest-browser-a11y": {
88 "script": "desktop_unittest.py",
89 "config": desktop_unittest_config
90 + ["--mochitest-suite", "mochitest-browser-a11y"],
92 "mochitest-browser-media": {
93 "script": "desktop_unittest.py",
94 "config": desktop_unittest_config
95 + ["--mochitest-suite", "mochitest-browser-media"],
97 "mochitest-devtools-chrome": {
98 "script": "desktop_unittest.py",
99 "config": desktop_unittest_config
100 + ["--mochitest-suite", "mochitest-devtools-chrome"],
102 "mochitest-remote": {
103 "script": "desktop_unittest.py",
104 "config": desktop_unittest_config
105 + ["--mochitest-suite", "mochitest-remote"],
108 "script": "desktop_unittest.py",
109 "config": desktop_unittest_config
+ ["--reftest-suite", "crashtest"],
112 "script": "desktop_unittest.py",
113 "config": desktop_unittest_config
+ ["--reftest-suite", "jsreftest"],
116 "script": "desktop_unittest.py",
117 "config": desktop_unittest_config
+ ["--reftest-suite", "reftest"],
119 "reftest-no-accel": {
120 "script": "desktop_unittest.py",
121 "config": desktop_unittest_config
122 + ["--reftest-suite", "reftest-no-accel"],
125 "script": "desktop_unittest.py",
126 "config": desktop_unittest_config
127 + ["--cppunittest-suite", "cppunittest"],
130 "script": "desktop_unittest.py",
131 "config": desktop_unittest_config
+ ["--xpcshell-suite", "xpcshell"],
134 "script": "desktop_unittest.py",
135 "config": desktop_unittest_config
136 + ["--xpcshell-suite", "xpcshell-addons"],
139 "script": "desktop_unittest.py",
140 "config": desktop_unittest_config
+ ["--jittest-suite", "jittest"],
143 "script": "marionette.py",
146 self
.config_path("marionette", "test_config.py"),
149 "web-platform-tests": {
150 "script": "web_platform_tests.py",
153 self
.config_path("web_platform_tests", self
.wpt_config
),
158 def path_to_url(self
, path
):
159 return urljoin("file:", pathname2url(path
))
161 def _installer_url(self
):
163 "linux": re
.compile(r
"^firefox-\d+\..+\.tar\.bz2$"),
164 "win": re
.compile(r
"^firefox-\d+\..+\.installer\.exe$"),
165 "mac": re
.compile(r
"^firefox-\d+\..+\.mac(?:64)?\.dmg$"),
166 }[mozinfo
.info
["os"]]
167 dist_path
= os
.path
.join(self
.topobjdir
, "dist")
168 filenames
= [item
for item
in os
.listdir(dist_path
) if package_re
.match(item
)]
169 assert len(filenames
) == 1
170 return self
.path_to_url(os
.path
.join(dist_path
, filenames
[0]))
172 def _test_packages_url(self
):
173 dist_path
= os
.path
.join(self
.topobjdir
, "dist")
176 for item
in os
.listdir(dist_path
)
177 if item
.endswith("test_packages.json")
179 assert len(filenames
) == 1
180 return self
.path_to_url(os
.path
.join(dist_path
, filenames
[0]))
182 def config_path(self
, *parts
):
183 return self
.path_to_url(
184 os
.path
.join(self
.topsrcdir
, "testing", "mozharness", "configs", *parts
)
188 def wpt_config(self
):
191 if mozinfo
.info
["os"] != "win"
192 else "test_config_windows.py"
195 def run_suite(self
, suite
, **kwargs
):
196 default_config
= self
.config
.get("__defaults__")
197 suite_config
= self
.config
.get(suite
)
199 if suite_config
is None:
200 print("Unknown suite %s" % suite
)
203 script
= os
.path
.join(
204 self
.topsrcdir
, "testing", "mozharness", "scripts", suite_config
["script"]
207 item() if callable(item
) else item
208 for item
in default_config
["config"] + suite_config
["config"]
211 cmd
= [script
] + options
213 rv
= subprocess
.call(cmd
, cwd
=os
.path
.dirname(script
))
220 description
="Run tests using mozharness.",
221 conditions
=[conditions
.is_firefox_or_android
],
224 def mozharness(command_context
, **kwargs
):
225 runner
= command_context
._spawn
(MozharnessRunner
)
226 return runner
.run_suite(kwargs
.pop("suite_name")[0], **kwargs
)