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/.
8 from argparse
import Namespace
9 from functools
import partial
12 from mach
.decorators
import Command
14 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
19 def run_test(context
, is_junit
, **kwargs
):
20 from mochitest_options
import ALL_FLAVORS
21 from mozlog
.commandline
import setup_logging
23 if not kwargs
.get("log"):
24 kwargs
["log"] = setup_logging("mochitest", kwargs
, {"mach": sys
.stdout
})
26 logger
= kwargs
["log"]
28 flavor
= kwargs
.get("flavor") or "mochitest"
29 if flavor
not in ALL_FLAVORS
:
30 for fname
, fobj
in six
.iteritems(ALL_FLAVORS
):
31 if flavor
in fobj
["aliases"]:
34 fobj
= ALL_FLAVORS
[flavor
]
35 kwargs
.update(fobj
.get("extra_args", {}))
37 if kwargs
.get("allow_software_gl_layers"):
38 os
.environ
["MOZ_LAYERS_ALLOW_SOFTWARE_GL"] = "1"
39 del kwargs
["allow_software_gl_layers"]
40 if kwargs
.get("mochitest_suite"):
41 suite
= kwargs
["mochitest_suite"]
42 del kwargs
["mochitest_suite"]
43 elif kwargs
.get("test_suite"):
44 suite
= kwargs
["test_suite"]
45 del kwargs
["test_suite"]
46 if kwargs
.get("no_run_tests"):
47 del kwargs
["no_run_tests"]
49 args
= Namespace(**kwargs
)
50 args
.e10s
= context
.mozharness_config
.get("e10s", args
.e10s
)
51 args
.certPath
= context
.certs_dir
54 return run_geckoview_junit(context
, args
)
56 # subsuite mapping from mozharness configs
58 # --mochitest-suite -> --subsuite
59 "mochitest-chrome-gpu": "gpu",
60 "mochitest-plain-gpu": "gpu",
61 "mochitest-media": "media",
62 "mochitest-browser-screenshots": "screenshots",
63 "mochitest-webgl1-core": "webgl1-core",
64 "mochitest-webgl1-ext": "webgl1-ext",
65 "mochitest-webgl2-core": "webgl2-core",
66 "mochitest-webgl2-ext": "webgl2-ext",
67 "mochitest-webgl2-deqp": "webgl2-deqp",
68 "mochitest-webgpu": "webgpu",
69 "mochitest-devtools-chrome": "devtools",
70 "mochitest-browser-a11y": "a11y",
71 "mochitest-remote": "remote",
72 "mochitest-browser-media": "media-bc",
74 args
.subsuite
= subsuites
.get(suite
)
75 if args
.subsuite
== "devtools":
76 args
.flavor
= "browser"
77 if args
.subsuite
== "a11y":
78 args
.flavor
= "browser"
79 if args
.subsuite
== "media-bc":
80 args
.flavor
= "browser"
82 if not args
.test_paths
:
83 mh_test_paths
= json
.loads(os
.environ
.get("MOZHARNESS_TEST_PATHS", '""'))
85 logger
.info("Found MOZHARNESS_TEST_PATHS:")
86 logger
.info(str(mh_test_paths
))
88 for k
in mh_test_paths
:
89 args
.test_paths
.extend(mh_test_paths
[k
])
91 install_subdir
= fobj
.get("install_subdir", fobj
["suite"])
92 test_root
= os
.path
.join(context
.package_root
, "mochitest", install_subdir
)
93 normalize
= partial(context
.normalize_test_path
, test_root
)
94 # pylint --py3k: W1636
95 args
.test_paths
= list(map(normalize
, args
.test_paths
))
99 if mozinfo
.info
.get("buildapp") == "mobile/android":
100 return run_mochitest_android(context
, args
)
101 return run_mochitest_desktop(context
, args
)
104 def run_mochitest_desktop(context
, args
):
105 args
.app
= args
.app
or context
.firefox_bin
106 args
.utilityPath
= context
.bin_dir
107 args
.extraProfileFiles
.append(os
.path
.join(context
.bin_dir
, "plugins"))
108 args
.extraPrefs
.append("webgl.force-enabled=true")
110 args
.useTestMediaDevices
= True
111 args
.screenshotOnFail
= True
112 args
.cleanupCrashes
= True
113 args
.marionette_startup_timeout
= "180"
114 args
.sandboxReadWhitelist
.append(context
.mozharness_workdir
)
115 if args
.flavor
== "browser":
116 args
.chunkByRuntime
= True
120 from runtests
import run_test_harness
122 logger
.info("mach calling runtests with args: " + str(args
))
123 return run_test_harness(parser
, args
)
126 def set_android_args(context
, args
):
127 args
.app
= args
.app
or "org.mozilla.geckoview.test_runner"
128 args
.utilityPath
= context
.hostutils
129 args
.xrePath
= context
.hostutils
130 config
= context
.mozharness_config
132 host
= os
.environ
.get("HOST_IP", "10.0.2.2")
133 args
.remoteWebServer
= config
.get("remote_webserver", host
)
134 args
.httpPort
= config
.get("http_port", 8854)
135 args
.sslPort
= config
.get("ssl_port", 4454)
136 args
.adbPath
= config
["exes"]["adb"] % {
137 "abs_work_dir": context
.mozharness_workdir
139 args
.deviceSerial
= os
.environ
.get("DEVICE_SERIAL", "emulator-5554")
143 def run_mochitest_android(context
, args
):
144 args
= set_android_args(context
, args
)
145 args
.extraProfileFiles
.append(
146 os
.path
.join(context
.package_root
, "mochitest", "fonts")
149 from runtestsremote
import run_test_harness
151 logger
.info("mach calling runtestsremote with args: " + str(args
))
152 return run_test_harness(parser
, args
)
155 def run_geckoview_junit(context
, args
):
156 args
= set_android_args(context
, args
)
158 from runjunit
import run_test_harness
160 # Force fission disabled by default for android
161 args
["disable_fission"] = True
163 logger
.info("mach calling runjunit with args: " + str(args
))
164 return run_test_harness(parser
, args
)
167 def add_global_arguments(parser
):
168 parser
.add_argument("--test-suite")
169 parser
.add_argument("--mochitest-suite")
170 parser
.add_argument("--download-symbols")
171 parser
.add_argument("--allow-software-gl-layers", action
="store_true")
172 parser
.add_argument("--no-run-tests", action
="store_true")
175 def setup_mochitest_argument_parser():
178 mozinfo
.find_and_update_from_json(here
)
180 if mozinfo
.info
.get("buildapp") == "mobile/android":
183 from mochitest_options
import MochitestArgumentParser
186 parser
= MochitestArgumentParser(app
=app
)
187 add_global_arguments(parser
)
191 def setup_junit_argument_parser():
192 from runjunit
import JunitArgumentParser
195 parser
= JunitArgumentParser()
196 add_global_arguments(parser
)
203 description
="Run the mochitest harness.",
204 parser
=setup_mochitest_argument_parser
,
206 def mochitest(command_context
, **kwargs
):
207 command_context
._mach
_context
.activate_mozharness_venv()
208 return run_test(command_context
._mach
_context
, False, **kwargs
)
214 description
="Run the geckoview-junit harness.",
215 parser
=setup_junit_argument_parser
,
217 def geckoview_junit(command_context
, **kwargs
):
218 command_context
._mach
_context
.activate_mozharness_venv()
219 return run_test(command_context
._mach
_context
, True, **kwargs
)