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
14 from six
.moves
.urllib
.parse
import urljoin
15 from six
.moves
.urllib
.request
import pathname2url
17 from mach
.decorators
import (
22 from mozbuild
.base
import MozbuildObject
23 from mozbuild
.base
import MachCommandConditions
as conditions
24 from argparse
import ArgumentParser
28 parser
= argparse
.ArgumentParser()
34 help="Suite to run in mozharness",
38 nargs
=argparse
.REMAINDER
,
39 help="Extra arguments to pass to mozharness",
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
= [
53 lambda: self
.config_path(
54 "unittests", "%s_unittest.py" % mozinfo
.info
["os"]
57 lambda: self
.config_path("developer_config.py"),
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"],
77 "script": "desktop_unittest.py",
78 "config": desktop_unittest_config
+ ["--mochitest-suite", "plain"],
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"],
100 "script": "desktop_unittest.py",
101 "config": desktop_unittest_config
102 + ["--mochitest-suite", "mochitest-remote"],
105 "script": "desktop_unittest.py",
106 "config": desktop_unittest_config
+ ["--reftest-suite", "crashtest"],
109 "script": "desktop_unittest.py",
110 "config": desktop_unittest_config
+ ["--reftest-suite", "jsreftest"],
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"],
122 "script": "desktop_unittest.py",
123 "config": desktop_unittest_config
124 + ["--cppunittest-suite", "cppunittest"],
127 "script": "desktop_unittest.py",
128 "config": desktop_unittest_config
+ ["--xpcshell-suite", "xpcshell"],
131 "script": "desktop_unittest.py",
132 "config": desktop_unittest_config
133 + ["--xpcshell-suite", "xpcshell-addons"],
136 "script": "desktop_unittest.py",
137 "config": desktop_unittest_config
+ ["--jittest-suite", "jittest"],
140 "script": "marionette.py",
143 self
.config_path("marionette", "test_config.py"),
146 "web-platform-tests": {
147 "script": "web_platform_tests.py",
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
):
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")
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
)
185 def wpt_config(self
):
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
)
200 script
= os
.path
.join(
201 self
.topsrcdir
, "testing", "mozharness", "scripts", suite_config
["script"]
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
))
217 description
="Run tests using mozharness.",
218 conditions
=[conditions
.is_firefox_or_android
],
221 def mozharness(command_context
, **kwargs
):
222 runner
= command_context
._spawn
(MozharnessRunner
)
223 return runner
.run_suite(kwargs
.pop("suite_name")[0], **kwargs
)